Commit Graph

88 Commits

Author SHA1 Message Date
Zoltan Somogyi
f007b45df8 Implement the infrastructure for term size profiling.
Estimated hours taken: 400
Branches: main

Implement the infrastructure for term size profiling. This means adding two
new grade components, tsw and tsc, and implementing them in the LLDS code
generator. In grades including tsw (term size words), each term is augmented
with an extra word giving the number of heap words it contains; in grades
including tsc (term size cells), each term is augmented with an extra word
giving the number of heap cells it contains. The extra word is at the start,
at offset -1, to leave almost all of the machinery for accessing the heap
unchanged.

For now, the only way to access term sizes is with a new mdb command,
"term_size <varspec>". Later, we will use term sizes in conjunction with
deep profiling to do experimental complexity analysis, but that requires
a lot more research. This diff is a necessary first step.

The implementation of term size profiling consists of three main parts:

- a source-to-source transform that computes the size of each heap cell
  when it is constructed (and increments it in the rare cases when a free
  argument of an existing heap cell is bound),

- a relatively small change to the code generator that reserves the extra
  slot in new heap cells, and

- extensions to the facilities for creating cells from C code to record
  the extra information we now need.

The diff overhauls polymorphism.m to make the source-to-source transform
possible. This overhaul includes separating type_ctor_infos and type_infos
as strictly as possible from each other, converting type_ctor_infos into
type_infos only as necessary. It also includes separating type_ctor_infos,
type_infos, base_typeclass_infos and typeclass_infos (as well as voids,
for clarity) from plain user-defined type constructors in type categorizations.
This change needs this separation because values of those four types do not
have size slots, but they ought to be treated specially in other situations
as well (e.g. by tabling).

The diff adds a new mdb command, term_size. It also replaces the proc_body
mdb command with new ways of using the existing print and browse commands
("print proc_body" and "browse proc_body") in order to make looking at
procedure bodies more controllable. This was useful in debugging the effect
of term size profiling on some test case outputs. It is not strictly tied
to term size profiling, but turns out to be difficult to disentangle.

compiler/size_prof.m:
	A new module implementing the source-to-source transform.

compiler/notes/compiler_design.html:
	Mention the new module.

compiler/transform_hlds.m:
	Include size_prof as a submodule of transform_hlds.

compiler/mercury_compile.m:
	If term size profiling is enabled, invoke its source-to-source
	transform.

compiler/hlds_goal.m:
	Extend construction unifications with an optional slot for recording
	the size of the term if the size is a constant, or the identity of the
	variable holding the size, if the size is not constant. This is
	needed by the source-to-source transform.

compiler/quantification.m:
	Treat the variable reference that may be in this slot as a nonlocal
	variable of construction unifications, since the code generator needs
	this.

compiler/compile_target_code.m:
	Handle the new grade components.

compiler/options.m:
	Implement the options that control term size profiling.

doc/user_guide.texi:
	Document the options and grade components that control term size
	profiling, and the term_size mdb command. The documentation is
	commented out for now.

	Modify the wording of the 'u' HLDS dump flag to include other details
	of unifications (e.g. term size info) rather than just unification
	categories.

	Document the new alternatives of the print and browse commands. Since
	they are for developers only, the documentation is commented out.

compiler/handle_options.m:
	Handle the implications of term size profiling grades.

	Add a -D flag value to print HLDS components relevant to HLDS
	transformations.

compiler/modules.m:
	Import the new builtin library module that implements the operations
	needed by term size profiling automatically in term size profiling
	grades.

	Switch the predicate involved to use state var syntax.

compiler/prog_util.m:
	Add predicates and functions that return the sym_names of the modules
	needed by term size profiling.

compiler/code_info.m:
compiler/unify_gen.m:
compiler/var_locn.m:
 	Reserve an extra slot in heap cells and fill them in in unifications
	marked by size_prof.

compiler/builtin_ops.m:
	Add term_size_prof_builtin.term_size_plus as a builtin, with the same
	implementation as int.+.

compiler/make_hlds.m:
	Disable warnings about clauses for builtins while the change to
	builtin_ops is bootstrapped.

compiler/polymorphism.m:
	Export predicates that generate goals to create type_infos and
	type_ctor_infos to add_to_construct.m. Rewrite their documentation
	to make it more detailed.

	Make orders of arguments amenable to the use of state variable syntax.

	Consolidate knowledge of which type categories have builtin unify and
	compare predicates in one place.

	Add code to leave the types of type_ctor_infos alone: instead of
	changing their types to type_info when used as arguments of other
	type_infos, create a new variable of type type_info instead, and
	use an unsafe_cast. This would make the HLDS closer to being type
	correct, but this new code is currently commented out, for two
	reasons. First, common.m is currently not smart enough to figure out
	that if X and Y are equal, then similar unsafe_casts of X and Y
	are also equal, and this causes the compiler do not detect some
	duplicate calls it used to detect. Second, the code generators
	are also not smart enough to know that if Z is an unsafe_cast of X,
	then X and Z do not need separate stack slots, but can use the same
	slot.

compiler/type_util.m:
	Add utility predicates for returning the types of type_infos and
	type_ctor_infos, for use by new code in polymorphism.m.

	Move some utility predicates here from other modules, since they
	are now used by more than one module.

	Rename the type `builtin_type' as `type_category', to better reflect
	what it does. Extend it to put the type_info, type_ctor_info,
	typeclass_info, base_typeclass_info and void types into categories
	of their own: treating these types as if they were a user-defined
	type (which is how they used to be classified) is not always correct.
	Rename the functor polymorphic_type to variable_type, since types
	such as list(T) are polymorphic, but they fall into the user-defined
	category. Rename user_type as user_ctor_type, since list(int) is not
	wholly user-defined but falls into this category. Rename pred_type
	as higher_order_type, since it also encompasses functions.

	Replace code that used to check for a few of the alternatives
	of this type with code that does a full switch on the type,
	to ensure that they are updated if the type definition ever
	changes again.

compiler/pseudo_type_info.m:
	Delete a predicate whose updated implementation is now in type_util.m.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
	Still treat type_infos, type_ctor_infos, typeclass_infos and
	base_typeclass_infos as user-defined types, but prepare for when
	they won't be.

compiler/hlds_pred.m:
	Require interface typeinfo liveness when term size profiling is
	enabled.

	Add term_size_profiling_builtin.increase_size as a
	no_type_info_builtin.

compiler/hlds_out.m:
	Print the size annotations on unifications if HLDS dump flags call
	for unification details. (The flag test is in the caller of the
	modified predicate.)

compiler/llds.m:
	Extend incr_hp instructions and data_addr_consts with optional fields
	that allow the code generator to refer to N words past the start of
	a static or dynamic cell. Term size profiling uses this with N=1.

compiler/llds_out.m:
	When allocating memory on the heap, use the macro variants that
	specify an optional offset, and specify the offset when required.

compiler/bytecode_gen.m:
compiler/dense_switch.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/goal_form.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_match.m:
compiler/intermod.m:
compiler/jumpopt.m:
compiler/lambda.m:
compiler/livemap.m:
compiler/ll_pseudo_type_info.m:
compiler/lookup_switch.m:
compiler/magic_util.m:
compiler/middle_rec.m:
compiler/ml_code_util.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modecheck_unify.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/post_typecheck.m:
compiler/reassign.m:
compiler/rl.m:
compiler/rl_key.m:
compiler/special_pred.m:
compiler/stack_layout.m:
compiler/static_term.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
	Minor updates to conform to the changes above.

library/term_size_prof_builtin.m:
	New module containing helper predicates for term size profiling.
	size_prof.m generates call to these predicates.

library/library.m:
	Include the new module in the library.

doc/Mmakefile:
	Do not include the term_size_prof_builtin module in the library
	documentation.

library/array.m:
library/benchmarking.m:
library/construct.m:
library/deconstruct.m:
library/io.m:
library/sparse_bitset.m:
library/store.m:
library/string.m:
	Replace all uses of MR_incr_hp with MR_offset_incr_hp, to ensure
	that we haven't overlooked any places where offsets may need to be
	specified.

	Fix formatting of foreign_procs.

	Use new macros defined by the runtime system when constructing
	terms (which all happen to be lists) in C code. These new macros
	specify the types of the cell arguments, allowing the implementation
	to figure out the size of the new cell based on the sizes of its
	fields.

library/private_builtin.m:
	Define some constant type_info structures for use by these macros.
	They cannot be defined in the runtime, since they refer to types
	defined in the library (list.list and std_util.univ).

util/mkinit.c:
	Make the addresses of these type_info structures available to the
	runtime.

runtime/mercury_init.h:
	Declare these type_info structures, for use in mkinit-generated
	*_init.c files.

runtime/mercury_wrapper.[ch]:
	Declare and define the variables that hold these addresses, for use
	in the new macros for constructing typed lists.

	Since term size profiling can refer to a memory cell by a pointer
	that is offset by one word, register the extra offsets with the Boehm
	collector if is being used.

	Document the incompatibility of MR_HIGHTAGS and the Boehm collector.

runtime/mercury_tags.h:
	Define new macros for constructing typed lists.

	Provide macros for preserving the old interface presented by this file
	to the extent possible. Uses of the old MR_list_cons macro will
	continue to work in grades without term size profiling. In term
	size profiling grades, their use will get a C compiler error.

	Fix a bug caused by a missing backslash.

runtime/mercury_heap.h:
	Change the basic macros for allocating new heap cells to take
	an optional offset argument. If this is nonzero, the macros
	increment the returned address by the given number of words.
	Term size profiling specifies offset=1, reserving the extra
	word at the start (which is ignored by all components of the
	system except term size profiling) for holding the size of the term.

	Provide macros for preserving the old interface presented by this file
	to the extent possible. Since the old MR_create[123] and MR_list_cons
	macros did not specify type information, they had to be changed
	to take additional arguments. This affects only hand-written C code.

	Call new diagnostic macros that can help debug heap allocations.

	Document why the macros in this files must expand to expressions
	instead of statements, evn though the latter would be preferable
	(e.g. by allowing them to declare and use local variables without
	depending on gcc extensions).

runtime/mercury_debug.[ch]:
	Add diagnostic macros to debug heap allocations, and the functions
	behind them if MR_DEBUG_HEAP_ALLOC is defined.

	Update the debugging routines for hand-allocated cells to print the
	values of the term size slot as well as the other slots in the relevant
	grades.

runtime/mercury_string.h:
	Provide some needed variants of the macro for copying strings.

runtime/mercury_deconstruct_macros.h:
runtime/mercury_type_info.c:
	Supply type information when constructing terms.

runtime/mercury_deep_copy_body.h:
	Preserve the term size slot when copying terms.

runtime/mercury_deep_copy_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_ml_expand_body.h:
	Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
	that allocate cells also allocate space for the term size slot if
	necessary.

	Reduce code duplication by using a now standard macro for copying
	strings.

runtime/mercury_grade.h:
	Handle the two new grade components.

runtime/mercury_conf_param.h:
	Document the C macros used to control the two new grade components,
	as well as MR_DEBUG_HEAP_ALLOC.

	Detect incompatibilities between high level code and profiling.

runtime/mercury_term_size.[ch]:
	A new module to house a function to find and return term sizes
	stored in heap cells.

runtime/mercury_proc_id.h:
runtime/mercury_univ.h:
	New header files. mercury_proc_id.h contains the (unchanged)
	definition of MR_Proc_Id, while mercury_univ.h contains the
	definitions of the macros for manipulating univs that used to be
	in mercury_type_info.h, updated to use the new macros for allocating
	memory.

	In the absence of these header files, the following circularity
	would ensue:

	mercury_deep_profiling.h includes mercury_stack_layout.h
		- needs definition of MR_Proc_Id
	mercury_stack_layout.h needs mercury_type_info.h
		- needs definition of MR_PseudoTypeInfo
	mercury_type_info.h needs mercury_heap.h
		- needs heap allocation macros for MR_new_univ_on_hp
	mercury_heap.h includes mercury_deep_profiling.h
		- needs MR_current_call_site_dynamic for recording allocations

	Breaking the circular dependency in two places, not just one, is to
	minimize similar problems in the future.

runtime/mercury_stack_layout.h:
	Delete the definition of MR_Proc_Id, which is now in mercury_proc_id.h.

runtime/mercury_type_info.h:
	Delete the macros for manipulating univs, which are now in
	mercury_univ.h.

runtime/Mmakefile:
	Mention the new files.

runtime/mercury_imp.h:
runtime/mercury.h:
runtime/mercury_construct.c:
runtime/mercury_deep_profiling.h:
	Include the new files at appropriate points.

runtime/mercury.c:
	Change the names of the functions that create heap cells for
	hand-written code, since the interface to hand-written code has
	changed to include type information.

runtime/mercury_tabling.h:
	Delete some unused macros.

runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
	Use the new macros supplying type information when constructing lists.

scripts/canonical_grade_options.sh-subr:
	Fix an undefined sh variable bug that could cause error messages
	to come out without identifying the program they were from.

scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade_options.sh-subr:
scripts/mgnuc.in:
	Handle the new grade components and the options controlling them.

trace/mercury_trace_internal.c:
	Implement the mdb command "term_size <varspec>", which is like
	"print <varspec>", but prints the size of a term instead of its value.
	In non-term-size-profiling grades, it prints an error message.

	Replace the "proc_body" command with optional arguments to the "print"
	and "browse" commands.

doc/user_guide.tex:
	Add documentation of the term_size mdb command. Since the command is
	for implementors only, and works only in grades that are not yet ready
	for public consumption, the documentation is commented out.

	Add documentation of the new arguments of the print and browse mdb
	commands. Since they are for implementors only, the documentation
	is commented out.

trace/mercury_trace_vars.[ch]:
	Add the functions needed to implement the term_size command, and
	factor out the code common to the "size" and "print"/"browse" commands.

	Decide whether to print the name of a variable before invoking the
	supplied print or browse predicate on it based on a flag design for
	this purpose, instead of overloading the meaning of the output FILE *
	variable. This arrangement is much clearer.

trace/mercury_trace_browse.c:
trace/mercury_trace_external.c:
trace/mercury_trace_help.c:
	Supply type information when constructing terms.

browser/program_representation.m:
	Since the new library module term_size_prof_builtin never generates
	any events, mark it as such, so that the declarative debugger doesn't
	expect it to generate any.

	Do the same for the deep profiling builtin module.

tests/debugger/term_size_words.{m,inp,exp}:
tests/debugger/term_size_cells.{m,inp,exp}:
	Two new test cases, each testing one of the new grades.

tests/debugger/Mmakefile:
	Enable the two new test cases in their grades.

	Disable the tests sensitive to stack frame sizes in term size profiling
	grades.

tests/debugger/completion.exp:
	Add the new "term_size" mdb command to the list of command completions,
	and delete "proc_body".

tests/debugger/declarative/dependency.{inp,exp}:
	Use "print proc_body" instead of "proc_body".

tests/hard_coded/nondet_c.m:
tests/hard_coded/pragma_inline.m:
	Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
	that allocate cells also allocate space for the term size slot if
	necessary.

tests/valid/Mmakefile:
	Disable the IL tests in term size profiling grades, since the term size
	profiling primitives haven't been (and probably won't be) implemented
	for the MLDS backends, and handle_options causes a compiler abort
	for grades that combine term size profiling and any one of IL, Java
	and high level C.
2003-10-20 07:29:59 +00:00
Zoltan Somogyi
32c03c9b41 Fix repeated words.
Estimated hours taken: 0.1
Branches: main

compiler/notes/compiler_design.html:
	Fix repeated words.
2003-09-23 04:28:21 +00:00
Fergus Henderson
cf55e41289 Update to reflect the fact that we are now using sub-modules.
Estimated hours taken: 3.5
Branches: main

compiler/notes/compiler_design.html:
	Update to reflect the fact that we are now using sub-modules.
	this required a bit of reorganization in some places.
	Also, document some modules that were previously not mentioned.
2003-06-04 10:58:02 +00:00
Zoltan Somogyi
20d0a371e4 Document a module.
Estimated hours taken: 0.2
Branches: main

compiler/notes/compiler_design.html:
	Document a module.
2003-05-07 06:32:34 +00:00
Zoltan Somogyi
cbd6a7c56a Delete the old, lazy LLDS code generator, since we won't be maintaining it
Estimated hours taken: 3
Branches: main

Delete the old, lazy LLDS code generator, since we won't be maintaining it
anymore. Its deletion speeds up the compiler by 0.2% when using the LLDS
back end.

compiler/code_exprn.m:
	Delete the module.

compiler/ll_backend.m:
	Delete code_exprn from the list of submodules of this module.

compiler/notes/compiler_design.html:
	Delete the documentation of code_exprn.m, and update the documentation
	of var_locn.m.

compiler/options.m:
	Delete the --lazy-code option that used to select code_exprn over
	var_locn.

	Delete the follow_vars option, since the LLDS backend now always
	executes the follow_vars pass.

compiler/handle_options.m:
	Delete the code setting the follow_vars option.

	Make the setting of static_ground_terms conditional on the use of the
	LLDS backend (which now implies the eager code generator).

compiler/code_info.m:
	Delete lots of code that switches between code_exprn.m and var_locn.m.

	Simplify the data structures accordingly.

compiler/store_alloc.m:
	Delete the code and data structures required to cater for the case
	where the follow_vars pass isn't run.

compiler/pragma_c_gen.m:
compiler/var_locn.m:
compiler/hlds_goal.m:
compiler/lookup_switch.m:
	Update a comment.

doc/user_guide.texi:
	Delete the documentation of --follow-vars. --lazy-code was already
	undocumented.

tests/valid/Mercury.options:
	Delete a setting of --no-follow-vars.
2003-05-07 00:50:34 +00:00
Simon Taylor
82a950c0d9 Make Aditi work with `--highlevel-code'.
Estimated hours taken: 80
Branches: main

Make Aditi work with `--highlevel-code'.

(Note that this doesn't work with the current CVS version
of Aditi. The Aditi developers have rewritten the Aditi client
API, and haven't maintained the old version of the API, so Mercury
queries don't work at the moment. extras/aditi will be updated to
use the new interface as a separate change.)

extras/aditi/aditi_private_builtin.m:
extras/aditi/aditi.m:
	Move code to implement Aditi calls and updates into
	a aditi_private_builtin.m. These operations are now
	implemented using ordinary Mercury foreign procedures,
	rather than hand-coded C modules.

compiler/magic.m:
	Use calls to ordinary calls to predicates defined in
	extras/aditi/aditi_private_builtin.m to implement the
	procedures which interface between top-down Mercury
	code and Aditi procedures.

compiler/aditi_backend.pp:
compiler/aditi_builtin_ops.m:
compiler/mercury_compile.m:
compiler/notes/compiler_design.html:
	Add a pass to convert Aditi builtins (calls and updates)
	into ordinary calls to predicates defined in
	extras/aditi/aditi_private_builtin.m.

compiler/hlds_goal.m:
compiler/hlds_pred.m:
	Add a new generic_call type -- `unsafe_cast'.
	aditi_builtin_ops.m needs to be able to cast
	closures from one type and inst to another.

	Delete the `aditi_call' alternative for `aditi_builtin',
	which is not needed after the change to magic.m described
	above.

	Add predicates `construct_tuple' and `deconstruct_tuple'.

compiler/*hlds.*.m:
compiler/call_gen.m:
compiler/ml_call_gen.m:
	Handle unsafe cast goals.

compiler/common.m:
compiler/higher_order.m:
compiler/unify_proc.m:
	Generate unsafe_cast goals instead of calls to
	private_builtin.unsafe_type_cast.

compiler/purity.m:
compiler/notes/compiler_design.html:
	Convert calls to private_builtin.unsafe_type_cast into
	unsafe_cast goals.

compiler/ml_code_gen.m:
	Don't attempt to generate code for Aditi procedures.

	Remove special case handling of calls to
	private_builtin.unsafe_type_cast -- such
	calls are now transformed away.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/maybe_mlds_to_gcc.m:
	Add the RL code to the generated C file.

compiler/llds_out.m:
compiler/c_util.m:
compiler/compile_target_code.m:
	Move code to generate a `.rlo' file and work out the
	name of the RL constant embeeded in the C file for
	a module into c_util.m, for use by the MLDS backend.

compiler/modules.m:
	Automatically import aditi_private_builtin when compiling
	with `--aditi'.

	We generate a C constant for the RL code for each module,
	so modules compiled with `--aditi' need to be treated
	by the build system as if they contain foreign code.

compiler/polymorphism.m:
	Tuple insertion and deletion no longer need special treatment.

compiler/llds.m:
compiler/ll_backend.*.m:
	Delete the Aditi alternatives of the `code_addr' type.

compiler/mode_util.m:
	Add function versions of in_mode, out_mode, etc.

compiler/prog_util.m:
	Add aditi_public_builtin_module (returns `aditi') and
	aditi_private_builtin_module (returns `aditi_private_builtin').

tests/valid/aditi_private_builtin.m:
tests/invalid/aditi_private_builtin.m:
tests/valid/Mercury.options:
tests/invalid/Mercury.options:
	Add a cut down version of extras/aditi/aditi_private_builtin.m
	for use in running the tests.
2003-03-18 02:43:52 +00:00
Fergus Henderson
5823c8a2e3 Perform loop invariant hoisting after inlining, since inlining
Estimated hours taken: 2
Branches: main

compiler/mercury_compile.m:
compiler/notes/compiler_design.html:
	Perform loop invariant hoisting after inlining, since inlining
	can create opportunities for loop invariant hoisting.

library/string.m:
	Implement string__index in Mercury, in terms of string__length,
	string__unsafe_index, and a new procedure string__index_check,
	rather than implementing in C.  string__index_check contains
	just the index checking code from the old string__index implementation.
	Implementing string__index in Mercury like this should allow the
	Mercury compiler to do loop invariant hoisting on the calls to
	string__length.

	Declare the output argument for string__unsafe_index
	and string__index_det with mode `uo', to match string__index.
	For unsafe__index, this change was needed now that string__index is
	implemented in terms of string__unsafe_index.
2003-02-22 13:54:45 +00:00
Fergus Henderson
b39fcee35d Trivial comment changes.
Estimated hours taken: 0.25
Branches: main

Trivial comment changes.

compiler/inst_match.m:
	Update some obsolete comments to match the current interface.
	Add a comment about contravariance/covariance in
	pred_inst_argmodes_matches.

compiler/java_util.m:
compiler/notes/compiler_design.html:
	Fix typos.
2003-01-10 10:45:02 +00:00
Fergus Henderson
5b8eef87b5 Fix a bug where the compiler was going into an infinite loop for
Estimated hours taken: 16
Branches: main, release

Fix a bug where the compiler was going into an infinite loop for
insts and modes that are infinitely recursive at the top level,
e.g. `:- inst foo == foo.' or `:- mode foo == foo'.

compiler/make_hlds.m:
	Check for circular insts and modes, and report an error if any occur.

	Also, pass back a boolean from pass 1 indicating whether or not
	any cyclic insts and modes.  Rename the "UndefModes" argument
	for parse_tree_to_hlds as "InvalidModes", and set it to yes
	if there were any circular insts or modes, to ensure that
	mercury_compile.m will not run mode analysis.  This is needed
	to avoid infinite loops in mode analysis when processing
	circular

compiler/notes/compiler_design.html:
	Mention that make_hlds.m checks for circular insts and modes.
	Also mention that it expands state variable syntax.

compiler/mercury_compile.m:
	Add a comment about circular insts and modes to the list of
	reasons why we might need to stop before running mode analysis.

tests/invalid/circ_inst2.m:
	Fix a misleading comment.

tests/invalid/Mmakefile:
tests/invalid/circ_inst.err_exp:
tests/invalid/circ_inst2.err_exp:
tests/invalid/circ_inst3.err_exp:
tests/invalid/circ_inst4.err_exp:
tests/invalid/circ_mode.err_exp:
tests/invalid/circ_mode2.err_exp:
tests/invalid/circ_mode3.err_exp:
tests/invalid/circ_mode4.err_exp:
	Enable these test cases, and add expected output files for them.

tests/invalid/Mmakefile:
tests/invalid/circ_type3.m:
tests/invalid/circ_type3.err_exp:
	Add another test for circular equivalence types.
2002-11-22 13:44:32 +00:00
Ralph Becket
b75b17bba3 Added loop-invariant hoisting optimization.
Estimated hours taken: 900
Branches: main

Added loop-invariant hoisting optimization.

liveness.m:
	Improved the debugging output to show HLDS before and after
	liveness analysis.

loop_inv.m:
	New module containing the implementation of the loop invariant
	hoisting optimization.

mercury_compile.m:
	Added loop_inv at step 34, moving inlining to step 35.

options.m:
	Added bool option --loop-invariants (default `no').
	This optimization is set at -O4.

passes_aux.m:
	Minor changes to support introduction of the loop
	invariant hoisting optmimization.

follow_code.m:
	Updated to reflect the new interface to passes_aux.m.

transform_hlds.m:
	Added include_module declaration for loop_inv.
2002-10-31 05:48:00 +00:00
Simon Taylor
fc8725fc3c Allow arbitrary mappings from source file name to module name.
Estimated hours taken: 8
Branches: main

Allow arbitrary mappings from source file name to module name.
The mapping is created using the command `mmc -f *.m', which must
be run before `mmake depend'.

compiler/parse_tree.m:
compiler/source_file_map.m:
compiler/notes/compiler_design.html:
	Add a new module to read, write and search the mapping.

compiler/modules.m:
	Use the source file map when searching for source files.

	Export `make_directory' for use by source_file_map.m.

	Use the module name rather than the source file name to
	generate the executable name. This matches the documentation
	in the User's Guide, and it's needed to make the tests work.

compiler/prog_io.m:
	Separate out the code to read the first item in a module to
	find the module name into a new predicate, `find_module_name'.

compiler/handle_options.m:
	Don't complain about the module name not matching the file
	name when generating the Mercury.modules file -- the file
	only needs to be generated when the module name doesn't
	match the file name.

compiler/llds_out.m:
	Remove a duplicate copy of `make_directory'.

compiler/options.m:
compiler/mercury_compile.m:
doc/user_guide.texi:
	Add the `--generate-source-file-mapping' (-f) option
	to generate the mapping.

NEWS:
	Document the change.

tests/hard_coded/Mmakefile:
tests/hard_coded/source_file_map.m:
tests/hard_coded/mapped_module.exp:
	Test case.
2002-04-15 05:04:23 +00:00
Simon Taylor
811c0af920 Make inter-module optimization work properly with sub-modules.
Estimated hours taken: 15
Branches: main

Make inter-module optimization work properly with sub-modules.

compiler/intermod.m:
	Write `exported_to_submodules' predicates to the `.opt' file.

	Read `.int0' files needed by the `.opt' files.

compiler/make.dependencies.m:
compiler/modules.m:
	Handle dependencies on the extra `.int0' files when compiling
	with `--intermodule-optimization'.

compiler/modules.m:
compiler/prog_io.m:
compiler/*.m:
	Handle partially qualified file names when searching for
	the `.m' file for a module when checking whether there
	should be a dependency on the `.opt' file for the module.

	Separate out the code to find for the source file for a module
	from the code to read the source file for a module.

	Remove an unnecessary argument from prog_io__read_opt_file
	(`.opt' files are always searched for).

compiler/modules.m:
	Export process_module_private_interfaces, for use by intermod.m.

	Remove process_module_indirect_imports, which isn't used anywhere.

	Change get_ancestors from a predicate to a function.

compiler/make_hlds.m:
	Don't report duplicate declaration errors for items imported
	for inter-module optimization. Sometimes both the `.int' and
	`.int0' file for a module are read, and the `.int0' file contains
	everything in the `.int' file..

compiler/modes.m:
compiler/post_typecheck.m:
	Don't report errors for duplicate mode declarations for imported
	predicates when performing inter-module optimization. If the
	`.int' and `.int0' files for a module are both read, the mode
	declarations for a predicate can be read twice.

	Where there are duplicate mode declarations, remove the
	duplicate procedures.

	Move the code to check for indistinguishable modes into
	post_typecheck.m. It only needs to be done once, not
	on every iteration of mode inference.

compiler/hlds_pred.m:
	Add a predicate pred_info_remove_procid, for use by post_typecheck.m.

compiler/mercury_to_mercury.m:
	Improve the comment generated for module_defn items which shouldn't
	appear in Mercury source.

compiler/notes/compiler_design.html:
	Improve the documentation of post_typecheck.m.

tests/invalid/qualified_cons_id2.err_exp:
	Update expected output.
2002-04-07 10:23:06 +00:00
Zoltan Somogyi
189b9215ae This diff implements stack slot optimization for the LLDS back end based on
Estimated hours taken: 400
Branches: main

This diff implements stack slot optimization for the LLDS back end based on
the idea that after a unification such as A = f(B, C, D), saving the
variable A on the stack indirectly also saves the values of B, C and D.

Figuring out what subset of {B,C,D} to access via A and what subset to access
via their own stack slots is a tricky optimization problem. The algorithm we
use to solve it is described in the paper "Using the heap to eliminate stack
accesses" by Zoltan Somogyi and Peter Stuckey, available in ~zs/rep/stackslot.
That paper also describes (and has examples of) the source-to-source
transformation that implements the optimization.

The optimization needs to know what variables are flushed at call sites
and at program points that establish resume points (e.g. entries to
disjunctions and if-then-elses). We already had code to compute this
information in live_vars.m, but this code was being invoked too late.
This diff modifies live_vars.m to allow it to be invoked both by the stack
slot optimization transformation and by the code generator, and allows its
function to be tailored to the requirements of each invocation.

The information computed by live_vars.m is specific to the LLDS back end,
since the MLDS back ends do not (yet) have the same control over stack
frame layout. We therefore store this information in a new back end specific
field in goal_infos. For uniformity, we make all the other existing back end
specific fields in goal_infos, as well as the similarly back end specific
store map field of goal_exprs, subfields of this new field. This happens
to significantly reduce the sizes of goal_infos.

To allow a more meaningful comparison of the gains produced by the new
optimization, do not save any variables across erroneous calls even if
the new optimization is not enabled.

compiler/stack_opt.m:
	New module containing the code that performs the transformation
	to optimize stack slot usage.

compiler/matching.m:
	New module containing an algorithm for maximal matching in bipartite
	graphs, specialized for the graphs needed by stack_opt.m.

compiler/mercury_compile.m:
	Invoke the new optimization if the options ask for it.

compiler/stack_alloc.m:
	New module containing code that is shared between the old,
	non-optimizing stack slot allocation system and the new, optimizing
	stack slot allocation system, and the code for actually allocating
	stack slots in the absence of optimization.

	Live_vars.m used to have two tasks: find out what variables need to be
	saved on the stack, and allocating those variables to stack slots.
	Live_vars.m now does only the first task; stack_alloc.m now does
	the second, using code that used to be in live_vars.m.

compiler/trace_params:
	Add a new function to test the trace level, which returns yes if we
	want to preserve the values of the input headvars.

compiler/notes/compiler_design.html:
	Document the new modules (as well as trace_params.m, which wasn't
	documented earlier).

compiler/live_vars.m:
	Delete the code that is now in stack_alloc.m and graph_colour.m.

	Separate out the kinds of stack uses due to nondeterminism: the stack
	slots used by nondet calls, and the stack slots used by resumption
	points, in order to allow the reuse of stack slots used by resumption
	points after execution has left their scope. This should allow the
	same stack slots to be used by different variables in the resumption
	point at the start of an else branch and nondet calls in the then
	branch, since the resumption point of the else branch is not in effect
	when the then branch is executed.

	If the new option --opt-no-return-calls is set, then say that we do not
	need to save any values across erroneous calls.

	Use type classes to allow the information generated by this module
	to be recorded in the way required by its invoker.

	Package up the data structures being passed around readonly into a
	single tuple.

compiler/store_alloc.m:
	Allow this module to be invoked by stack_opt.m without invoking the
	follow_vars transformation, since applying follow_vars before the form
	of the HLDS code is otherwise final can be a pessimization.

	Make the module_info a part of the record containing the readonly data
	passed around during the traversal.

compiler/common.m:
	Do not delete or move around unifications created by stack_opt.m.

compiler/call_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/var_locn.m:
	Allow the code generator to delete its last record of the location
	of a value when generating code to make an erroneous call, if the new
	--opt-no-return-calls option is set.

compiler/code_gen.m:
	Use a more useful algorithm to create the messages/comments that
	we put into incr_sp instructions, e.g. by distinguishing between
	predicates and functions. This is to allow the new scripts in the
	tool directory to gather statistics about the effect of the
	optimization on stack frame sizes.

library/exception.m:
	Make a hand-written incr_sp follow the new pattern.

compiler/arg_info.m:
	Add predicates to figure out the set of input, output and unused
	arguments of a procedure in several different circumstances.
	Previously, variants of these predicates were repeated in several
	places.

compiler/goal_util.m:
	Export some previously private utility predicates.

compiler/handle_options.m:
	Turn off stack slot optimizations when debugging, unless
	--trace-optimized is set.

	Add a new dump format useful for debugging --optimize-saved-vars.

compiler/hlds_llds.m:
	New module for handling all the stuff specific to the LLDS back end
	in HLDS goal_infos.

compiler/hlds_goal.m:
	Move all the relevant stuff into the new back end specific field
	in goal_infos.

compiler/notes/allocation.html:
	Update the documentation of store maps to reflect their movement
	into a subfield of goal_infos.

compiler/*.m:
	Minor changes to accomodate the placement of all back end specific
	information about goals from goal_exprs and individual fields of
	goal_infos into a new field in goal_infos that gathers together
	all back end specific information.

compiler/use_local_vars.m:
	Look for sequences in which several instructions use a fake register
	or stack slot as a base register pointing to a cell, and make those
	instructions use a local variable instead.

	Without this, a key assumption of the stack slot optimization,
	that accessing a field in a cell costs only one load or store
	instruction, would be much less likely to be true. (With this
	optimization, the assumption will be false only if the C compiler's
	code generator runs out of registers in a basic block, which for
	the code we generate should be unlikely even on x86s.)

compiler/options.m:
	Make the old option --optimize-saved-vars ask for both the old stack
	slot optimization (implemented by saved_vars.m) that only eliminates
	the storing of constants in stack slots, and the new optimization.

	Add two new options --optimize-saved-vars-{const,cell} to turn on
	the two optimizations separately.

	Add a bunch of options to specify the parameters of the new
	optimizations, both in stack_opt.m and use_local_vars.m. These are
	for implementors only; they are deliberately not documented.

	Add a new option, --opt-no-return-cells, that governs whether we avoid
	saving variables on the stack at calls that cannot return, either by
	succeeding or by failing. This is for implementors only, and thus
	deliberately documented only in comments. It is enabled by default.

compiler/optimize.m:
	Transmit the value of a new option to use_local_vars.m.

doc/user_guide.texi:
	Update the documentation of --optimize-saved-vars.

library/tree234.m:
	Undo a previous change of mine that effectively applied this
	optimization by hand. That change complicated the code, and now
	the compiler can do the optimization automatically.

tools/extract_incr_sp:
	A new script for extracting stack frame sizes and messages from
	stack increment operations in the C code for LLDS grades.

tools/frame_sizes:
	A new script that uses extract_incr_sp to extract information about
	stack frame sizes from the C files saved from a stage 2 directory
	by makebatch and summarizes the resulting information.

tools/avg_frame_size:
	A new script that computes average stack frame sizes from the files
	created by frame_sizes.

tools/compare_frame_sizes:
	A new script that compares the stack frame size information
	extracted from two different stage 2 directories by frame_sizes,
	reporting on both average stack frame sizes and on specific procedures
	that have different stack frame sizes in the two versions.
2002-03-28 03:44:41 +00:00
Simon Taylor
a719e74ee9 Rearrange some code after the `--make' change.
Estimated hours taken: 1.5
Branches: main

Rearrange some code after the `--make' change. This was not done
as part of that change for ease of reviewing.

compiler/mercury_compile.m:
compiler/compile_target_code.m:
compiler/make.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
	Move code to compile the generated code into compile_target_code.m.

compiler/make.util.m:
compiler/passes_aux.m:
compiler/process_util.m:
	Move process and signal handling functionality into process_util.m.

compiler/Mmakefile:
	Compile process_util.c with `--no-ansi' so that the declarations
	of `struct sigaction' and `kill' are available on Linux.

compiler/notes/compiler_design.html:
	Document compile_target_code.m and process_util.m.
	Move timestamp.m into the "Miscellaneous" section (it's
	used by make as well as smart recompilation).
	Fix the documentation of options_file.m.
2002-03-18 04:44:16 +00:00
Simon Taylor
d96f7a9bd5 Allow declarations of the form
Estimated hours taken: 40
Branches: main

Allow declarations of the form
:- pred p `with_type` higher_order_type `with_inst` higher_order_inst.

XXX We should allow `with_inst` annotations on higher-order terms.

compiler/prog_data.m:
	Add fields to `pred_or_func' and `pred_or_func_mode'
	items to hold the `with_type` and `with_inst` annotations.

compiler/prog_io.m:
compiler/prog_io_typeclass.m:
	Parse the annotations.

compiler/module_qual.m:
	Module qualify the annotations.

compiler/equiv_type.m:
	Expand away `with_type` and `with_inst`. Report errors.

	Strip items containing errors from the item list.

	Record smart recompilation dependencies on the types and
	modes expanded. Also record a dependency on the arity of
	predicate and function declarations before expansion.

	Use error_util for error messages.

compiler/mercury_to_mercury.m:
	Write `with_type` and `with_inst` annotations to interface files.

compiler/make_hlds.m:
	Ignore `with_type` and `with_inst` fields in predicate and
	function declarations.

compiler/recompilation.m:
	Changes to allow equiv_type.m to record dependencies on
	arbitrary items, not just types.

compiler/recompilation_usage.m:
compiler/recompilation_check.m:
	Allow searches in the sets of used predicates and functions using
	name, not name and arity, as the key. This is needed because
	the actual arity of a predicate defined using `with_type` is
	not known when writing the interface files.

compiler/recompilation_version.m:
	Handle `with_inst` and `with_type`.

	Pragmas now need to be recorded in the version_numbers even
	if there is no matching `:- pred' or `:- func' declaration --
	the pragma may apply to a predicate or function declared using
	`with_type`.

compiler/mode_util.m:
	Export inst_subsitute_arg_list for use by equiv_type.m.

compiler/error_util.m:
	Add predicate `pred_or_func_to_string'.

library/std_util.m:
	Add std_util__map_foldl_maybe and std_util__map_foldl2_maybe,
	which are like list__map_foldl and list__map_foldl2, but
	apply to the item stored in a value of type std_util__maybe.

NEWS:
doc/reference_manual.texi:
	Document the new syntax and library predicates.

tests/invalid/Mmakefile:
tests/invalid/with_type.m:
tests/invalid/with_type.err_exp:
tests/invalid/constrained_poly_insts.err_exp:
tests/recompilation/TESTS:
tests/recompilation/unchanged_with_type_nr*:
tests/recompilation/with_type_re*:
	Test cases.

tests/invalid/errors1.err_exp:
tests/invalid/type_loop.err_exp:
tests/invalid/vars_in_wrong_places.err_exp:
	Update expected output.
2002-03-15 07:32:27 +00:00
Zoltan Somogyi
2980737352 A new LLDS->LLDS transformation that optimizes instruction sequences such
Estimated hours taken: 24
Branches: main

A new LLDS->LLDS transformation that optimizes instruction sequences such
as the following extract from tree234__search:

	MR_r1 = MR_stackvar(3);
	MR_r2 = MR_stackvar(4);
	MR_r3 = MR_const_field(MR_mktag(1), MR_stackvar(1), (MR_Integer) 2);
	MR_r4 = MR_stackvar(2);
	MR_succip = (MR_Code *) MR_stackvar(5);
	if ((MR_tag(MR_r3) != MR_mktag((MR_Integer) 1))) {
		MR_GOTO_LABEL(mercury__x3__search_3_0_i1);
	}
	MR_stackvar(1) = MR_r3;
	MR_stackvar(2) = MR_r4;
	MR_stackvar(3) = MR_r1;
	MR_stackvar(4) = MR_r2;
	MR_r2 = MR_r4;
	MR_r3 = MR_const_field(MR_mktag(1), MR_r3, (MR_Integer) 0);
	MR_call_localret(...)

The code before the if-then-else is part of the procedure epilogue; the code
after it is the code from the initial part of the procedure that fulljump
optimization replaces the self-tail-call with.

The transformation deletes the redundant assignments to stackvars 2, 3 and 4.
It reduces both the size and the runtime of the compiler by about 0.5%.

compiler/reassign.m:
	The new module that does the work.

compiler/optimize.m:
	Invoke the new module if the optimization is enabled. Invoke it after
	most other optimizations have been run, since they may create more
	opportunities for it.

compiler/option.m:
	Add a new option to control whether the new optimization is enabled.
	Turn on the new optimization at optimization level 3.

doc/user_guide.texi:
	Document the new option.

compiler/notes/compiler_design.html:
	Document the new module.
2002-03-13 01:01:15 +00:00
Simon Taylor
9c9601808d Add an alternative implementation of Mmake as part of the compiler.
Estimated hours taken: 500

Add an alternative implementation of Mmake as part of the compiler.
The advantages of this are
	- more accurate dependencies
	- no `mmake depend' step
	- less process creation (no processes are created to
		build interface files).

Still to do:
	- handle --split-c-files
	- handle the IL backend properly
	- library installation
	- allow the compiler to be built and the nightly tests
	  to be run with `mmc --make'

compiler/make.m:
	Control the build process.

compiler/make.program_target.m:
	Build executables and libraries.

compiler/make.module_target.m:
	Build C files, object files, interface files etc.

compiler/make.dependencies.m:
	Work out the depenendencies between targets.

compiler/make.module_dep_file.m:
	Record the inter-module dependencies between invocations of mmc.

compiler/make.util.m:
	Utility predicates used by `mmc --make'.

compiler/compile_target_code.m:
	This module will eventually contain the predicates used
	to compile the target code files generated by the compiler
	which are now in mercury_compile.m. (That will be done
	as a separate change for ease of reviewing).

	For now compile_target_code.m

compiler/mercury_compile.m:
	Export the predicates used to compile target code.

	Call make.m.

	Pass the name of the top-level module in the source file to modules.m.
	It is needed when generating the `.module_dep' files.

	Lookup the option defaults (which will eventually be stored in
	DEFAULT_MCFLAGS by the mmc script) before compiling. Up until now
	the option defaults have been passed on the command line by the
	mmc script, but with `mmc --make' the default options need
	to be overridden by the value of the MCFLAGS make variable, but
	the MCFLAGS make variable is overridden by command line options.

	Pass the value of `--link-flags' to c2init.

	Remove some uninformative messages printed when a C, IL, etc.
	compilation fails.

compiler/options_file.m:
	Read files containing Make style variable assignments.

compiler/options.m:
doc/user_guide.texi:
	Add a new options category: build system options.

	Add some extra options:
	--warn-undefined-options-variables - like mmake --warn-undefined-vars
	--verbose-commands - print commands that the user might be
		interested in, like C compilation, but not things
		like mercury_update_interface.
	--output-compile-error-lines - print the first n lines
		of the error file generated by a command.
	--generate-mmc-make-modules-dependencies - generate dependencies
		for use by `mmc --make' even when using Mmake.

	--il-assembler, --ilasm-flags, --mcpp-compiler, --mcpp-flags,
	--csharp-compiler, --csharp-flags, --install-prefix,
	--install-command, --libgrades, --options-files,
	--options-search-directories.

compiler/modules.m:
	Add fields to the `module_imports' type for use by make.*m.

	Don't try to fill in fields of the module_imports structure
	lazily. It's error prone, and probably doesn't save much
	anyway.

	Clean up the code to compute what foreign languages
	are used by a list of item.

	Simplify the handling of fact tables by recording that a module
	containing fact tables has foreign code to implement them,
	rather than requiring separate checks everywhere.

	Generalise predicates like get_interface so that they
	work even after the imported items have been read.

	Fix the handling of header files with the LLDS backend.

	Install the `.module_dep' files created for use by
	`mmc --make'.

compiler/*.m:
	Use record syntax rather than explicit deconstruction to
	refer to fields of the `module_imports' type.

compiler/*.m:
	Be more careful about where output goes.
	mercury_compile.m sets the output stream to be io__stderr_stream
	at the start of compilation, so remove all explicit writes to
	io__stderr_stream (with `--make' the error output stream may be
	a `.err' file, not io__stderr_stream).

	Change all occurrences of io__tell/io__told to use
	io__open_output/io__close_output (io__told restores the current
	output stream to io__stdout_stream, not the previous value).

compiler/passes_aux.m:
	Make the output from system commands go to the current
	output stream, not C stdout and stderr.

	Allow commands to be printed with `--verbose-commands'.

	Remove uninformative error messages when a command fails.

compiler/timestamp.m:
	Add functions oldest_timestamp and newest_timestamp.

compiler/llds_out.m:
	Record the number of C files written with `--split-c-files'
	in <module>.num_split.

compiler/prog_io.m:
compiler/*.m:
	`search_for_file' now returns the directory in which the
	file was found.

compiler/foreign.m:
	Use sub-typing to make some calls to predicates in this
	module `det' rather than `semidet'.

compiler/handle_options.m:
	Return the option arguments.

compiler/Mmakefile:
	make.util.m refers to kill() and `struct sigaction' which
	are not exported from <signal.h> unless `--no-ansi' is
	passed to gcc.

compiler/notes/compiler_design.html:
	Document the new modules.

runtime/mercury_signal.h:
runtime/mercury_signal.c:
	Add a function MR_signal_should_restart() which alters
	whether a signal restarts or interrupts system calls.
	In general restarting is the preferred behaviour, but
	the wait() for a child process needs to be interruptible.

scripts/Mmake.vars.in:
	Add subdirs for `.module_dep', `.err_date'
	and `.num_split' files.

library/io.m:
	Add a version of io_call_system which returns the signal
	that killed the command rather than converting it into
	an error message.

	Add a predicate to interpret the result of system() or wait().

library/list.m:
	Add list__map_foldl2 and a unique mode for list__foldl3.

NEWS:
	Document the new library predicates.

configure.in:
runtime/mercury_conf.h.in:
	Check for siginterrupt().

doc/user_guide.texi:
	Document the new options.

	Add a description of `mmc --make' to the "Using Mmake" chapter.
2002-03-12 16:33:37 +00:00
Fergus Henderson
fc8b0fe968 Move the code for constructing closures from ml_unify_gen.m
Estimated hours taken: 1
Branches: main

Move the code for constructing closures from ml_unify_gen.m
into a new module ml_closure_gen.m.

compiler/ml_unify_gen.m:
compiler/ml_code_util.m:
	Move ml_make_boxed_types and fixup_builtin_module from
	ml_unify_gen.m to ml_code_util.m, for use by ml_closure_gen.m.

compiler/ml_unify_gen.m:
	Export ml_gen_new_object, for use by ml_closure_gen.m.

compiler/rtti_to_mlds.m:
	Import ml_closure_gen.m, for ml_gen_closure_wrapper.

compiler/ml_unify_gen.m:
compiler/ml_closure_gen.m:
	Move the code for constructing closures from ml_unify_gen.m
	into a new module ml_closure_gen.m.

compiler/notes/compiler_design.html:
	Mention the new module.
2002-03-04 07:31:38 +00:00
Fergus Henderson
6d9448c654 Implement a new option `--warn-non-tail-recursion'.
Estimated hours taken: 1
Branches: main

Implement a new option `--warn-non-tail-recursion'.

compiler/ml_tailcall.m:
	Add a pass to warn about directly recursive calls that are not
	tail calls.

compiler/options.m:
doc/user_guide.texi:
	Add a new option to enable the new pass.

compiler/mercury_compile.m:
	Add code to invoke the new pass.

compiler/handle_options.m:
	If --warn-non-tail-recursion is set, then report an error
	if either --high-level-code or --optimize-tailcalls is not,
	or if --error-check-only is set.

compiler/notes/compiler_design.html:
	Mention the new functionality in ml_tailcall.m.
2002-02-12 16:38:16 +00:00
Fergus Henderson
f08b29edc9 Some more bug fixes for accurate GC with the MLDS->C back-end.
Estimated hours taken: 2
Branches: main

Some more bug fixes for accurate GC with the MLDS->C back-end.

With these changes, and a few hacks (see http://www.cs.mu.oz.au/research/
mercury/mailing-lists/mercury-reviews/mercury-reviews.0201/0188.html),
I was able to build all of the programs in tests/benchmarks in grade hlc.agc,
with `EXTRA_MCFLAGS = -O5 --no-deforestation --no-reclaim-heap-on-failure'.

compiler/ml_elim_nested.m:
	- Use an assignment rather than an initializer when
	  saving the stack chain; this is needed because
	  the hoist_nested_funcs pass (which gets run next)
	  assumes that the MLDS doesn't have any initializers
	  for local variables.
	- Include a counter in the ml_elim_info, and use it to ensure that
	  all the saved stack chain variables get named differently;
	  this is needed because the hoist_nested_funcs pass doesn't
	  handle variables with overlapping scopes.
	- Move the code for generating the code to save/restore
	  the stack chain into a separate function.

compiler/notes/compiler_design.html:
	Mention the accurate GC pass in ml_elim_nested.m.
2002-02-04 07:01:29 +00:00
Zoltan Somogyi
d6fa030ee9 Fix an omission.
Estimated hours taken: 0.1
Branches: main

compiler/notes/compiler_desigm.html:
	Fix an omission.
2001-12-31 06:07:25 +00:00
Fergus Henderson
95acb0d8a2 Implement heap reclamation on failure for the MLDS back-end.
Branches: main
Estimated hours taken: 8

Implement heap reclamation on failure for the MLDS back-end.

library/private_builtin.m:
	Add impure procedures for saving and restoring the heap pointer.

compiler/add_heap_ops.m:
	New file, similar to add_trail_ops.m.
	An HLDS->HLDS transformation to add heap reclamation operations.

compiler/mercury_compile.m:
	Call the new pass.

compiler/notes/compiler_design.html:
	Mention the new pass.

compiler/add_trail_ops.m:
compiler/table_gen.m:
compiler/goal_util.m:
	Abstract out the common code from `generate_call' in table_gen.m,
	add_trail_ops.m, and add_heap_ops.m, and put it in a new procedure
	`generate_simple_goal' in goal_util.m.

compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
	Apply a review suggestion from Peter Ross: when putting code
	in places that should not be reachable, insert code that calls
	private_builtin__unused (which calls error/1) rather
	than just inserting `true'.
2001-11-26 09:31:06 +00:00
Simon Taylor
311d0af1e5 Constraint propagation.
Estimated hours taken: 90

Constraint propagation.

compiler/constraint.m:
	Push constraints left and inwards as much as possible
	within a goal. This module has been completely rewritten.

compiler/deforest.m:
	Push constraints within a goal before processing it.

	Make specialized versions for calls with constrained outputs.

	Rerun determinism inference on specialized versions
	when constraint propagation has been run, because the
	determinism can change from nondet to semidet.

compiler/pd_util.m:
	Add pd_util__propagate_constraints, which uses constraint.m
	to push constraints within a goal.

	Add some documentation for the exported predicates.

compiler/pd_term.m:
	Add support for checking termination of the optimization process
	for constraint propagation, which differs from deforestation
	in that the conjunctions selected for optimization don't
	necessarily have a call at both ends.

compiler/pd_debug.m:
	Print some extra information when `--debug-pd' is enabled.

compiler/mercury_compile.m:
	Check whether constraint propagation should be performed when
	working out whether to run the deforestation pass.

compiler/make_hlds.m:
	Add `no_inline' markers to the "recursive" procedures
	introduced for builtins to stop constraint propagation
	attempting to specialize such procedures.

compiler/hlds_pred.m:
	Don't fill in the declared determinism field of the predicates
	introduced by `hlds_pred__define_new_pred', so that rerunning
	determinism inference will compute a more accurate determinism.

compiler/inlining.m:
	Requantify before recomputing instmap_deltas, not after.

compiler/det_report.m:
	Add predicates to disable warnings when rerunning
	determinism analysis after constraint propagation.

compiler/options.m:
	Add documentation for `--constraint-propagation'.

	Add option `--local-constraint-propagation', which makes
	deforestation call constraint.m to move constraints within
	a goal, but does not create specialized versions of procedures
	for which there are calls with constrained outputs.

compiler/handle_options.m:
	`--constraint-propagation' implies `--local-constraint-propagation'.

compiler/notes/compiler_design.html:
	Change the documentation to show that constraint.m is now part
	of the deforestation pass.

NEWS:
	Announce the new transformation.

doc/user_guide.texi:
	Document the new options.

tests/hard_coded/Mmakefile:
tests/hard_coded/constraint.{m,exp}:
tests/hard_coded/constraint_order.{m,exp}:
	Test cases.
2001-08-11 14:09:57 +00:00
Simon Taylor
9dd11b2fc6 Smart recompilation. Record version numbers for each item
Estimated hours taken: 400

Smart recompilation. Record version numbers for each item
in interface files. Record which items are used in each compilation.
Only recompile a module if the output file does not exist or
nothing has changed.

There is still some work to do on this:
- it doesn't work with inter-module optimization.
- it doesn't work when the module name doesn't match the file name.
  (this problem will go away when mmake functionality is moved into
  the compiler.

I'll hold off documenting this change in the NEWS file and
on the web page for a month or so, until I've had a bit more
experience using it.

compiler/options.m:
compiler/handle_options.m:
doc/user_guide.texi:
	Add an option `--smart-recompilation', currently off by default.

	Add an internal option `--generate-version-numbers' to control
	whether version numbers are written to the interface files. If
	`--smart-recompilation' is disabled because the module
	is being compiled with `--intermodule-optimization' (e.g. in the
	standard library), we still want to write the version numbers
	to the interface files.

	Add an option `--verbose-recompilation' (default off)
	to write messages describing why recompilation is needed.

	Add an option `--warn-smart-recompilation' (default on)
	to control warnings relating to the smart recompilation
	system. Warn if smart recompilation will not work with
	the output and inter-module optimization options given.

compiler/recompilation.m:
	Type declarations for smart recompilation.
	Predicates to record program items used by compilation.

compiler/recompilation_version.m:
	Compute version numbers for program items in interface files.

compiler/recompilation_usage.m:
	Find all items used by a compilation.

compiler/recompilation_check.m:
	Check whether recompilation is necessary.

compiler/timestamp.m:
	Timestamp ADT for smart recompilation.

compiler/mercury_compile.m:
	Invoke the smart recompilation passes.

compiler/modules.m:
compiler/prog_io.m:
	Return timestamps for modules read.

	When reading a module make sure the current input stream
	is reset to its old value, not stdin.

	Handle version number items in interface files.

compiler/module_qual.m:
compiler/unify_proc.m:
compiler/make_hlds.m:
	Record all items used by local items.

compiler/make_hlds.m:
	Process `:- pragma type_spec' declarations in
	add_item_list_clauses. The qual_info is needed
	when processing `:- pragma type_spec' declarations
	so that any equivalence types used by the declaration
	can be recorded as used by the predicate or function to
	which the `:- pragma type_spec' applies.

compiler/equiv_type.m:
	For each imported item, record which equivalence types
	are used by that item.

compiler/hlds_module.m:
	Add a field to the module_info to store information about
	items used during compilation of a module.

compiler/check_typeclass.m:
	Make sure any items used in clauses for typeclass method
	implementations are recorded in the `.used' file.

compiler/prog_data.m:
compiler/*.m:
	Factor out some duplicated code by combining the
	pred and func, and pred_mode and func_mode items.

	Make it easier to extract the name of a type, inst or mode
	from its declaration.

	Add an item type to hold the version numbers for an interface file.

	Allow warnings to be reported for `nothing' items (used for
	reporting when version numbers are written using an
	obsolete format).

compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/typecheck.m:
compiler/type_util.m:
compiler/*.m:
	Strip contexts from all types, not just those in class constraints.
	This makes it possible to use ordinary unification to check
	whether items have changed (with the exception of clauses).

	Remove code to create types with contexts in typechecking.

	Remove code scattered through the compiler to remove contexts
	from types in class constraints.

compiler/hlds_pred.m:
compiler/prog_util.m:
	Move hlds_pred__adjust_func_arity to prog_util, so that it
	can be used by the pre-hlds passes.

compiler/typecheck.m:
compiler/hlds_module.m:
	Move typecheck__visible_modules to hlds_module.m, so it can
	be used by recompilation_usage.m.

compiler/typecheck.m:
	Add a comment telling where updates may be required if the
	code to typecheck a var-functor unification changes.

compiler/error_util.m:
	Allow writing messages without contexts (used for the verbose
	recompilation messages).

	Add functions to format sym_name and sym_name_and_arity,
	and to add punctuation to the end of an error message
	without unwanted line breaks before the punctuation.

scripts/Mmake.rules:
compiler/modules.m:
	Don't remove the output file before running the compiler. We need
	to leave the old output file intact if smart recompilation detects
	that recompilation is not needed.

compiler/notes/compiler_design.html:
	Document the new modules.

library/io.m:
NEWS:
	Add predicates to find the modification time of files
	and input_streams.

library/set.m:
NEWS:
	Add a predicate version of set__fold

	Don't sort the output of set__filter, it's already sorted.

library/std_util.m:
NEWS:
	Add a predicate `std_util__map_maybe/3' and a function
  	`std_util__map_maybe/2' to apply a predicate or a function to
    	a value stored in a term of type `std_util__maybe'.

configure.in:
runtime/mercury_conf.h.in:
runtime/RESERVED_MACRO_NAMES:
	When checking whether the compiler is recent enough, check for
	the --warn-smart-recompilation option.

	Check for stat().

library/Mmakefile:
	Disable warnings about smart recompilation not working with
	`--intermodule-optimization'.

browser/Mmakefile:
	Disable warnings about smart recompilation not working when
	the module name doesn't match the file name.

runtime/mercury_string.h:
	Add a macro MR_make_string_const() which automates computation
	of the length of string argument to MR_string_const().

tests/recompilation/Mmakefile:
tests/recompilation/runtests:
tests/recompilation/test_functions:
tests/recompilation/TESTS:
tests/recompilation/README:
	A framework for testing smart recompilation.
	The option currently only works for the recompilation directory.

tests/recompilation/TEST.m.{1,2}:
tests/recompilation/TEST_2.m.{1,2}:
tests/recompilation/TEST.exp.{1,2}:
tests/recompilation/TEST.err_exp.2:
	Test cases, where TEST is one of add_constructor_r, add_instance_r,
	add_instance_2_r, add_type_nr, change_class_r, change_instance_r,
	change_mode_r, field_r, func_overloading_nr, func_overloading_r,
	lambda_mode_r, nested_module_r, no_version_numbers_r,
	pragma_type_spec_r, pred_ctor_ambiguity_r, pred_overloading_r,
	add_type_re, remove_type_re, type_qual_re.

tests/handle_options:
	Add an option `-e' to generate any missing expected output files.
2001-06-27 05:05:21 +00:00
Zoltan Somogyi
04e614485d Implement deep profiling; merge the changes on the deep2 branch back
Estimated hours taken: 500
Branches: main

Implement deep profiling; merge the changes on the deep2 branch back
onto the trunk.

The main documentation on the general architecture of the deep profiler
is the deep profiling paper.

doc/user_guide.texi:
	Document how to use the deep profiler.

deep_profiler:
deep_profiler/Mmakefile:
	A new directory holding the deep profiler and its mmakefile.

Mmakefile:
	Add targets for the new directory.

	Add support for removing inappropriate files from directories.

deep_profiler/interface.m:
	The deep profiler consists of two programs: mdprof_cgi.m, which acts
	as a CGI "script", and mdprof_server.m, which implements the server
	process that the CGI script talks to. Interface.m defines the
	interface between them.

script/mdprof.in:
	A shell script template. ../configure uses it to generate mdprof,
	which is a wrapper around mdprof_cgi that tells it how to find
	mdprof_server.

deep_profiler/mdprof_cgi.m:
	The CGI "script" program.

deep_profiler/mdprof_server.m:
	The top level predicates of the server.

deep_profiler/profile.m:
	The main data structures of the server and their operations.

deep_profiler/read_profile.m:
	Code for reading in profiling data files.

deep_profiler/startup.m:
	Code for post-processing the information in profiling data files,
	propagating costs from procedures to their ancestors and performing
	various kinds of summaries.

deep_profiler/server.m:
	Code for responding to requests from the CGI script.

deep_profiler/cliques.m:
	Code to find cliques in graphs.

deep_profiler/array_util.m:
deep_profiler/util.m:
	Utility predicates.

deep_profiler/dense_bitset.m:
	An implementation of (part of) the set ADT with dense bit vectors.

deep_profiler/measurements.m:
	Operations on profiling measurements.

deep_profiler/timeout.m:
	An implementation of a timeout facility.

deep_profiler/conf.m:
	Functions that depend on autoconfigured settings.

configure.in:
	Find out what command to use to find the name of the local host.

	Install deep profiling versions of the standard library along with the
	other profiling versions.

runtime/mercury_conf.h.in:
	Add some macros for deep_profiler/conf.m to use.

library/profiling_builtin.m:
runtime/mercury_deep_call_port_body.h:
runtime/mercury_deep_leave_port_body.h:
runtime/mercury_deep_redo_port_body.h:
	A new library module that implements deep profiling primitives.
	Some of these primitives have many versions, whose common code is
	factor is factored out in three new include files in the runtime.

compiler/deep_profiling.m:
	New module to perform the program transformations described in the
	paper.

compiler/notes/compiler_design.html:
	Document the new compiler module.

compiler/mercury_compiler.m:
	Invoke the new module in deep profiling grades. Allow global static
	data to be generated by deep_profiling.m.

compiler/options.m:
	Add options to turn on deep profiling and (for benchmarking purposes)
	control its implementation.

	Add an optiooption disable tailcall optimization in the LLDS backend,
	to help benchmarking deep profiling.

compiler/jumpopt.m:
compiler/optimize.m:
	Obey the option to disable tailcalls.

compiler/handle_options.m:
	Handle the implications of deep profiling.

compiler/modules.m:
	In deep profiling grades, automatically import profiling_builtin.m.

compiler/prog_util.m:
doc/Makefile:
library/library.m:
	Handle the new builtin module.

compiler/export.m:
	In deep profiling grades, wrap deep profiling code around exported
	procedures to handle the "unscheduled call" aspects of callbacks to
	Mercury from the foreign language.

compiler/higher_order.m:
profiler/demangle.m:
util/demangle.c:
	When creating a name for a higher-order-specialized predicate, include
	the mode number in the name.

compiler/add_trail_ops.m:
compiler/type_util.m:
	Move c_pointer_type from add_trail_ops to type_util, so it can also be
	used by deep_profiling.m.

compiler/hlds_goal.m:
	Add a new goal feature that marks a tail call, for use by
	deep_profiling.m.

compiler/hlds_pred.m:
	Add a new field to proc_info structures for use by deep_profiling.m.

	Add a mechanism for getting proc_ids for procedure clones.

	Remove next_proc_id, an obsolete and unused predicate.

compiler/hlds_data.m:
	Add a new cons_id to refer to the proc_static structure of a procedure.

compiler/bytecode_gen.m:
compiler/code_util.m:
compiler/dependency_graph.m:
compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
compiler/ml_unify_gen.m:
compiler/opt_debug.m:
compiler/prog_rep.m:
compiler/rl_exprn.m:
compiler/switch_util.m:
compiler/unify_gen.m:
	Trivial changes to handle the new cons_id, goal feature and/or
	proc_info argument.

compiler/rtti.m:
	Add a utility predicate for extracting pred_id and proc_id from an
	rtti_proc_label, for use by hlds_out.m

compiler/layout.m:
compiler/layout_out.m:
compiler/llds.m:
compiler/llds_common.m:
	Add support for proc_static and call_site_static structures.

compiler/layout_out.m:
compiler/llds_out.m:
	Add code for the output of proc_static structures.

compiler/code_util.m:
	Make code_util__make_proc_label_from_rtti a function, and export it.

util/mkinit.c:
compiler/llds_out.m:
compiler/layout.m:
compiler/modules.m:
	Add support for a fourth per-module C function, for writing out
	proc_static structures (and the call_site_static structures they
	contains).

	Since proc_static structures can be referred to from LLDS code (and not
	just from other static structures and compiler-generated C code),
	reorganize the declarations of static structures slightly.

	Change the schema for the name of the first per-module C function
	slightly, to make it the addition of the fourth function easier.
	The scheme now is:

		mercury__<modulename>__init
		mercury__<modulename>__init_type_tables
		mercury__<modulename>__init_debugger
		mercury__<modulename>__write_out_proc_statics

	Improve formatting of the generated C code.

library/*.m:
runtime/mercury.c:
runtime/mercury_context.c:
runtime/mercury_engine.c:
runtime/mercury_ho_call.c:
runtime/mercury_tabling.c:
runtime/mercury_trace_base.c:
runtime/mercury_wrapper.c:
trace/mercrury_trace.[ch]:
trace/mercrury_trace_declarative.c:
trace/mercrury_trace_external.c:
trace/mercrury_trace_internal.c:
	Conform to the new scheme for initialization functions for hand-written
	modules.

compiler/mercury_compile.m:
library/benchmarking.m:
runtime/mercury_conf_param.h:
runtime/mercury.h:
runtime/mercury_engine.c:
runtime/mercury_goto.c:
runtime/mercury_grade.h:
runtime/mercury_ho_call.c:
runtime/mercury_label.[ch]:
runtime/mercury_prof.[ch]:
	Add an MR_MPROF_ prefix in front of the C macros used to control the
	old profiler.

compiler/handle_options.m:
runtime/mercury_grade.h:
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
	Make deep profiling completely separate from the old profiling system,
	by making the deep profiling grade independent of MR_MPROF_PROFILE_TIME
	and the compiler option --profile-time.

library/array.m:
library/builtin.m:
library/std_util.m:
runtime/mercury_hand_unify_body.h:
runtime/mercury_hand_compare_body.h:
	In deep profiling grades, wrap the deep profiling call, exit, fail
	and redo codes around the bodies of hand-written unification
	and comparison procedures.

	Make the reporting of array bounds violations switchable between
	making them fatal errors, as we currently, and reporting them by
	throwing an exception. Throwing an exception makes debugging code
	using arrays easier, but since exceptions aren't (yet) propagated
	across engine boundaries, we keep the old behaviour as the default;
	the new behaviour is for implementors.

runtime/mercury_deep_profiling_hand.h:
	New file that defines macros for use in Mercury predicates whose
	definition is in hand-written C code.

library/exception.m:
runtime/mercury_exception_catch_body.h:
runtime/mercury_stacks.h:
	In deep profiling grades, wrap the deep profiling call, exit, fail
	and redo codes around the bodies of the various modes of builtin_catch.

	Provide a function that C code can use to throw exceptions.

library/benchmarking.m:
library/exception.m:
library/gc.m:
library/std_util.m:
runtime/mercury_context.[ch]:
runtime/mercury_engine.[ch]:
runtime/mercury_debug.c:
runtime/mercury_deep_copy.c:
runtime/mercury_overflow.h:
runtime/mercury_regs.h:
runtime/mercury_stacks.h:
runtime/mercury_thread.c:
runtime/mercury_wrapper.c:
	Add prefixes to the names of the fields in the engine and context
	structures, to make code using them easier to understand and modify.

runtime/mercury_deep_profiling.[ch]:
	New module containing support functions for deep profiling and
	functions for writing out a deep profiling data file at the end of
	execution.

runtime/mercury_debug.[ch]:
	Add support for debugging deep profiling.

	Add support for watching the value at a given address.

	Make the buffered/unbuffered nature of debugging output controllable
	via the -du option.

	Print register contents only if -dr is specified.

runtime/mercury_goto.h:
runtime/mercury_std.h:
	Use the macros in mercury_std.h instead of defining local variants.

runtime/mercury_goto.h:
runtime/mercury_stack_layout.h:
runtime/mercury_stack_trace.c:
runtime/mercury_tabling.c:
trace/mercury_trace.c:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_vars.c:
	Standardize some of the macro names with those used in the debugger
	paper.

runtime/mercury_heap.h:
	Add support for memory profiling with the deep profiler.

runtime/mercury_prof.[ch]:
runtime/mercury_prof_time.[ch]:
	Move the functionality that both the old profiler and the deep profiler
	need into the new module mercury_prof_time. Leave mercury_prof
	containing stuff that is only relevant to the old profiler.

runtime/mercury_prof.[ch]:
runtime/mercury_strerror.[ch]:
	Move the definition of strerror from mercury_prof to its own file.

runtime/mercury_wrapper.[ch]:
	Add support for deep profiling.

	Add suppory for controlling whether debugging output is buffered or
	not.

	Add support for watching the value at a given address.

runtime/Mmakefile:
	Mention all the added files.

scripts/mgnuc.in:
	Add an option for turning on deep profiling.

	Add options for controlling the details of deep profiling. These
	are not documented because they are intended only for benchmarking
	the deep profiler itself, for the paper; they are not for general use.

tools/bootcheck:
	Compile the deep_profiler directory as well as the other directories
	containing Mercury code.

	Turn off the creation of deep profiling data files during bootcheck,
	since all but one of these in each directory will be overwritten
	anyway.

	Add support for turning on --keep-objs by default in a workspace.

tools/speedtest:
	Preserve any deep profiling data files created by the tests.

trace/mercury_trace.c:
	Trap attempts to perform retries in deep profiling grades, since they
	would lead to core dumps otherwise.

util/Mmakefile:
	Avoid compile-time warnings when compiling getopt.

tests/*/Mmakefile:
tests/*/*/Mmakefile:
	In deep profiling grades, switch off the tests that test features
	that don't work with deep profiling, either by design or because
	the combination hasn't been implemented yet.
2001-05-31 06:00:27 +00:00
Simon Taylor
cddde72b73 Remove the `--convert-to-goedel' option. It doesn't really work
Estimated hours taken: 0.5

Remove the `--convert-to-goedel' option. It doesn't really work
and it's a hassle to maintain.

Remove the `--generate-prolog' and `--prolog-dialect' options.
They aren't implemented, and now that we have a proper debugger
they probably never will be.

compiler/mercury_to_goedel.m:
	Removed.

compiler/notes/compiler_design.html:
	Remove mercury_to_goedel.m.

compiler/globals.m:
compiler/handle_options.m:
	Remove code dealing with Prolog dialects.

compiler/options.m:
doc/user_guide.texi:
	Remove the options.

compiler/prog_io.m:
	Delete a comment referring to Mercury-to-Goedel converters.

compiler/mercury_compile.m:
	Don't call convert_to_goedel.

NEWS:
	Document the removal of the `--convert-to-goedel' option.

WORK_IN_PROGRESS:
	Remove a reference to the `--generate-prolog' option.
2001-05-24 06:07:40 +00:00
Simon Taylor
028211a6b5 Remove compiler/excess.m. Its functionality has been included in
Estimated hours taken: 0.2

Remove compiler/excess.m. Its functionality has been included in
simplify.m. The rationale for leaving it lying around was that it
may have been necessary to provide a version which maintains
superhomogeneous form. Experience has shown that when a compiler
pass requires strict superhomogeneous form (e.g. magic.m)
it's simpler to add back the extra assignments where needed.

compiler/excess.m:
	Removed.

compiler/dnf.m:
	Remove the last import of excess.m.

compiler/notes/compiler_design.html
	Remove description of excess.m.
2001-05-24 05:47:09 +00:00
Fergus Henderson
b973fb0b9d Add support for using different clauses for different modes of a
Estimated hours taken: 8
Branches: main

Add support for using different clauses for different modes of a
predicate or function, using mode annotations on the clauses.

compiler/make_hlds.m:
	Add support for mode annotations on clauses.

compiler/module_qual.m:
	Add new routine qualify_clause_mode_list, for use by make_hlds.m.

compiler/mode_errors.m:
	Export output_mode_decl, for use by make_hlds.m

compiler/purity.m:
	Treat procedures with different clauses for different modes
	as impure, unless promised pure.

compiler/notes/compiler_design.html:
	Specify when module qualification of modes in
	clause mode annotations is done (in make_hlds.m).

NEWS:
doc/reference_manual.texi:
	Document the new feature.
2001-05-16 04:51:04 +00:00
Zoltan Somogyi
7add5e0b0d Disable value numbering, now that it is no longer needed.
Estimated hours taken: 0.5
Branches: main

Disable value numbering, now that it is no longer needed. The value numbering
source files are not deleted from the CVS repository, since that would make
their restoration (in the unlikely event that this is needed) inconvenient,
but they will no longer be compiled or included in compiler executables.

doc/user_guide.texi:
compiler/options.m:
	Delete the options dealing with value numbering.

compiler/optimize.m:
	Do not invoke value numbering.

compiler/handle_options.m:
	Delete code that handles implications involving value numbering.

compiler/opt_debug.m:
	Delete code for debugging value numbering, since leaving it in
	would require importing value numbering modules and would thus drag
	them into the compiler executable.

compiler/value_number.m:
compiler/vn_block.m:
compiler/vn_cost.m:
compiler/vn_debug.m:
compiler/vn_filter.m:
compiler/vn_flush.m:
compiler/vn_order.m:
compiler/vn_table.m:
compiler/vn_temploc.m:
compiler/vn_type.m:
compiler/vn_util.m:
compiler/vn_verify.m:
	Delete these now obsolete modules.

compiler/notes/compiler_design.html:
	Delete mentions of value numbering and its modules.

tests/general/accumulator/Mmakefile:
tests/hard_coded/Mmakefile:
	Remove references to options removed by this change.
2001-05-15 07:12:04 +00:00
Zoltan Somogyi
9c58f97e3b Add a new optimization, --use-local-vars, to the LLDS backend.
Estimated hours taken: 20
Branches: main

Add a new optimization, --use-local-vars, to the LLDS backend. This
optimization is intended to replace references to fake registers and stack
slots with references to temporary variables in C code, since accessing these
should be cheaper.

With this optimization and one for delaying construction unifications,
the eager code generator should generate code at least good as that produced by
the old value numbering pass. This should make it possible to get rid of value
numbering, which is much harder to maintain.

compiler/use_local_vars.m:
	New module containing the optimization.

compiler/notes/compiler_design.html:
	Mention the new module.

compiler/exprn_aux.m:
	Add new utility predicates for use by use_local_vars.

	If --debug-opt is specified, do not dump instruction sequences to
	standard output. Instead, put them in separate files, where they can be
	compared more easily.

compiler/options.m:
	Add the --use-local-vars option to control whether the use_local_vars
	pass gets run.

compiler/llds.m:
	Add liveness information to the c_code and pragma_foreign_code LLDS
	instructions, in order to allow use_local_vars to work in the presence
	of automatically-generated C code (e.g. by debugging).

compiler/livemap.m:
	Use the new liveness information to generate useful livemap information
	even in the presence of automatically generated C code.

compiler/code_gen.m:
compiler/code_info.m:
compiler/dupelim.m:
compiler/frameopt.m:
compiler/llds_common.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/pragma_c_gen.m:
compiler/trace.m:
compiler/vn_block.m:
compiler/vn_cost.m:
compiler/vn_filter.m:
compiler/vn_verify.m:
	Provide and/or ignore this additional liveness information.

compiler/wrap_block.m:
	The post_value_number pass wraps LLDS instruction sequences
	using temporaries in a block instruction which actually declares
	those temporaries. It used to be used only by value numbering;
	it is now also used by use_local_vars. It has therefore been renamed
	and put in its own file.

compiler/optimize.m:
	Invoke use_local_vars if required, and call wrap_blocks instead of
	post_value_number.

compiler/value_number.m:
	Since the value numbering pass still cannot handle automatically
	generated C code, check for it explicitly now that livemap carries out
	only a weaker check.

compiler/basic_block.m:
	Add a module qualification.

library/set.m:
library/set_bbbtree.m:
library/set_ordlist.m:
library/set_unordlist.m:
	Add a new predicate, union_list, to each implementation of sets,
	for use by some of the new code above.

tests/general/array_test.m:
	Print out the result of each operation as soon as it is done, so that
	if you get a seg fault, you know which operations have completed and
	which haven't.
2001-04-24 03:59:13 +00:00
Zoltan Somogyi
afd6568f4e A new module for delaying construction unifications past builtins in
Estimated hours taken: 8
Branches: main

compiler/delay_construct.m:
	A new module for delaying construction unifications past builtins in
	conjunctions that can fail. The idea is to incur the cost of memory
	allocation only if those tests succeed. This can speed up code (e.g.
	tests/benchmarks/query) by integer factors.

compiler/notes/compiler_design.m:
	Mention the new module.

compiler/options.m:
doc/user_guide.texi:
	Add a new option, --delay-construct, that switches on the new
	optimization.

compiler/mercury_compile.m:
	Invoke the new optimization if the option calls for it.
2001-04-24 03:39:43 +00:00
Zoltan Somogyi
8b98304a37 Add back a line I deleted by accident.
Estimated hours taken: 0.1

compiler/notes/compiler_design.html:
	Add back a line I deleted by accident.
2001-01-19 01:50:32 +00:00
Zoltan Somogyi
ccf4e35bb5 Document unneeded_code.m.
Estimated hours taken: 0.1

compiler/notes/compiler_design.html:
	Document unneeded_code.m.
2001-01-19 01:42:29 +00:00
Fergus Henderson
e07e1cd1da Implement trailing for the MLDS back-end.
Estimated hours taken: 16

Implement trailing for the MLDS back-end.

library/private_builtin.m:
	Define impure Mercury procedures corresponding to the
	trailing operations in runtime/mercury_trail.h.

compiler/add_trail_ops.m:
	A new HLDS->HLDS pass.
	This implements trailing by inserting calls to the
	trailing primitives declared in library/private_builtin.m.

compiler/notes/compiler_design.html:
	Document the new pass.

compiler/mercury_compile.m:
	Change the code for mercury_compile__mlds_backend so that
	if trailing is enabled, it invokes the new add_trail_ops pass.

runtime/mercury_wrapper.c:
	For high-level C grades, call MR_init_memory() (which sets up
	the redzone signal handlers, etc.) and if trailing is enabled,
	initialize the trail.

library/benchmarking.m:
	Change the code in report_stats for printing out the size of
	the trail so that it gets the trail zone from MR_trail_zone
	rather than via the MercuryEngine, so that it works in
	high-level C grades (which don't have any MercuryEngine).

extras/trailed_update/tr_array.m:
extras/trailed_update/var.m:
	Add missing `#includes' to make these files work with the
	MLDS back-end.
2000-12-13 12:13:09 +00:00
Zoltan Somogyi
ebe9f9a3ec Add tabling of I/O actions for the debugger.
Estimated hours taken: 80

Add tabling of I/O actions for the debugger.

compiler/options.m:
	Add a new option, --trace-table-io, that enables the tabling of I/O
	actions, and another, --trace-table-io-states, that governs whether the
	tabling includes the I/O state variables themselves. (You want to table
	these variables iff they contain meaningful information that is not
	stored in global variables.) These options are for developers only
	for now.

compiler/modules.m:
	Implicitly import table_builtin if --trace-table-io is specified.

compiler/prog_data.m:
	Add eval_table_io as a new eval method.

compiler/hlds_pred.m:
	Add a mechanism for checking whether a predicate has an input/output
	pair of io__state args.

	Extend the tables indexed by eval_method to handle eval_table_io.

compiler/hlds_out.m:
	Print the eval method in HLDS dumps.

compiler/table_gen.m:
	If a procedure has a pair of I/O state args and is defined using pragma
	C code that has the tabled_for_io marker, and --trace-table-io is
	specified, then perform I/O tabling on it and mark it as tabled.

compiler/notes/compiler_design.m:
	Document that table_gen.m can now change the evaluation methods of
	procedures (to eval_table_io).

compiler/stack_layout.m:
runtime/mercury_stack_layout.h:
	Add an extra field to proc layouts. If debugging is enabled and a
	procedure has I/O state arguments, this field gives the number of the
	stack slot which will be filled with the I/O action counter at the
	time of the call, so that on retry the debugger can reset the I/O
	action counter to this value.

compiler/trace.m:
	Add code to reserve and fill this stack slot.

	Make the order of fields in the trace_slots structure match the order
	in proc layouts.

compiler/code_info.m:
compiler/live_vars.m:
	Pass a module_info to trace__setup and trace__reserved_slots.

library/io.m:
	Mark the I/O primitives (i.e. procedures that are defined by pragma C
	code and do I/O) with the tabled_for_io feature. (See the discussion
	of I/O primitives in compiler/table_gen.m.)

	Standardize the formatting of predicates defined by pragma C codes.

library/table_builtin.m:
	Define the predicates that perform I/O tabling, to which calls are
	inserted in I/O tabled predicates. These depend on knowing what the
	maximum MR_Unsigned value is.

library/table_builtin.m:
runtime/mercury_tabling_macros.h:
	Table nodes implementing a simple kind of trie, which can also be
	viewed as a hash table with the hash function hash(n) = hash - start
	were already supported by mercury_tabling.c. They are used to
	implement I/O tabling, since I/O the tabled action numbers form a
	contiguous sequence. Now allow that functionality to be accessed
	from the library through macros.

runtime/mercury_trace_base.[ch]:
	Add the global variables required by I/O tabling.

trace/mercury_trace.c:
	Implement retry across I/O by resetting the I/O counter to the value
	it had on entry to the retried call. However, since this is not safe
	in general, ask the user for permission first.

trace/mercury_trace.h:
	Add two extra arguments to MR_trace_retry to specify the input and
	output streams on which to ask permission.

trace/mercury_trace_internal.c:
	Add commands to start and stop I/O tabling. For now, they are for use
	by developers only and are undocumented; I expect they will change
	significantly before being let loose on users.

trace/mercury_trace_external.c:
trace/mercury_trace_declarative.c:
	Pass extra arguments to MR_trace_retry to indicate that these modules
	are not interested (at least for now) in retry across I/O, since they
	do not (yet) have mechanisms for asking the user for permission.

tests/debugger/tabled_read.{m,inp,exp,data}:
	A new test case to check retry across tabled and non-tabled I/O.

tests/debugger/Mmakefile:
	Enable the new test case.
2000-12-06 06:06:06 +00:00
Fergus Henderson
d9c0475e4a Reorganize the code for handling switches in the MLDS and
Estimated hours taken: 2

Reorganize the code for handling switches in the MLDS and
LLDS back-ends to reduce code duplication.

compiler/switch_util.m:
	New file.  Contains stuff for switches that is shared
	between the MLDS and LLDS back-ends.

compiler/ml_switch_gen.m:
compiler/ml_string_switch.m:
compiler/ml_tag_switch.m:
compiler/switch_gen.m:
compiler/string_switch.m:
compiler/tag_switch.m:
	Move code that was duplicated in the LLDS and MLDS back-ends
	into string_util.m.  Change some names and import_module
	declarations to match the new organization.

compiler/notes/compiler_design.html:
	Document the new module switch_util.m.
	Also mention ml_tag_switch.m.
2000-11-16 08:45:48 +00:00
Fergus Henderson
612865de05 Get the MLDS back-end to generate better code for string switches.
Estimated hours taken: 8

Get the MLDS back-end to generate better code for string switches.

compiler/ml_code_util.m:
compiler/ml_unify_gen.m:
	Move the routines for generating static constants from
	ml_unify_gen.m to ml_code_util.m, for use by ml_string_switch.m.

compiler/ml_string_switch.m:
	New file, adapted from string_switch.m.
	This handles generation of string switches for the MLDS back-end.
	It generates string switches using string hashing and either
	computed gotos or int switches.

compiler/ml_switch_gen.m:
	Add support for string switches.
	Export the target_supports_* predicates, for use in ml_string_switch.m.
	(Perhaps these predicates should be moved into a different module?)
	Add `target_supports_goto'.

compiler/notes/compiler_design.html:
	Mention the new module.  Also mention other MLDS modules that
	have been recently added and not yet documented here.
2000-11-09 04:08:31 +00:00
Tyson Dowd
169db1b8fd The .NET MSIL (Microsoft Intermediate Language) backend.
Estimated hours taken: 220

The .NET MSIL (Microsoft Intermediate Language) backend.

While not complete, this backend implements enough of Mercury to run
programs such as eliza (with an appropriate runtime, which is not part
of this change).  The IL backend TODO list is in mlds_to_il.m.

We generate IL "assembler" from MLDS.  The IL assembler (ILASM) then
turns this into bytecode in a .DLL or .EXE file.

Pragma C code is put into a separate .cpp file and compiled using the managed
C++ compiler.

compiler/il_peephole.m:
	Peephole optimize the IL.

compiler/ilasm.m:
	Generate IL assembler from IL.
	Also a representation of the entities in the IL assembler
	syntax.

compiler/ilds.m:
	The IL instruction set.

compiler/mercury_compile.m:
	Generate IL if --target il is set.
	Define mercury_compile__mlds_has_main/1.
	Assemble the IL if --target-code-only is not set.
	Use "target_debug" option instead of "c_debug".

compiler/ml_code_gen.m:
	If the target is IL and we are generating MLDS for foreign code
	that calls continuations (that is, model_non pragma C code),
	create a nested function (not implemented in foreign code) to
	call the continuation.  This is because in managed C++ it isn't
	possible to call a continuation, but it's fine to call a method
	written in IL that calls the continuation instead.

compiler/ml_code_util.m:
	Add unexpected/1 as another error message handler.
	Add code for generating indirect calls to success continutation
	(via a nested function).

compiler/ml_elim_nested.m:
	Generate slightly different code for IL environments.  We don't
	use the address of the environment variable (like in the C
	backend) but use the environment variable directly.  We also
	have to initialize the environment as a new object.
	This is because we use a class to represent the environment,
	whereas the C backend uses a struct.

	Also, if there is no environment required for nested functions
	(that is, the nested functions don't use any of the local
	variables of the parent), don't generate an environment.
	This is important for the nested functions generated in mangaged
	C++ -- otherwise have to be able to handle defining and
	initializing environments in managed C++ just to do the continuation
	calls for model non pragma C code.

	Add field names to elim_info.

compiler/mlds_to_il.m:
	The IL code generator.
	Also contains the mapping from MLDS type to IL types (which
	is useful when generating forieng language stubs to interface
	with IL).

compiler/options.m:
	Add a debugging option for IL assember -- it prints out each
	line of assembler before it executes.  This is very much a
	developer only option.
	Make a "target_debug" option -- the old "c_debug" option is just
	an alias for this option.  If the target it IL, "target_debug"
	can also turn on debugging for IL, allowing the IL debugger to
	display IL instructions as it traces execution.
2000-10-14 04:00:46 +00:00
Zoltan Somogyi
3ce3b14c84 Make procedure bodies available to the declarative debugger.
Estimated hours taken: 20

Make procedure bodies available to the declarative debugger.

browser/program_representation.m:
	Add _rep suffixes to the function symbols, to make iit easier to
	distinguish HLDS goals and goal representations.

compiler/static_layout.m:
	If --trace-decl is specified, include a representation of the procedure
	body in the procedure's layout structure.

compiler/prog_rep.m:
	A new module, containing the code that converts goals from HLDS
	to a term in the format we want to put in the layout structure.

compiler/static_term.m:
	A new module, containing the code that converts Mercury terms
	to the LLDS rval we need to give to llds_out.m.

compiler/code_gen.m:
compiler/continuation_info.m:
	Preserve the information needed by prog_rep

compiler/Mmakefile:
	Extend the search path to the browser directory, since the new file
	prog_rep.m imports one of the submodules of mdb.m stored there.

compiler/notes/compiler_desigm.html:
	Document the new modules.

library/std_util.m:
	Add a mechanism for static_term.m to use in converting terms into
	rvals. This mechanism uses RTTI information to deconstruct terms,
	and return not only their arguments, but also information about how
	the term can be constructed from its arguments.

runtime/mercury_type_info.h:
	Add a couple of macros to make construction and deconstruction of univs
	easier, for use in std_util.m.

trace/mercury_trace_internal.c:
	Add a new command, "proc_body", that prints out the representation
	of the body of the current procedure. This is meant only for developers
	to use to check that the procedure body representation is OK; it is
	deliberately not documented.

	Also fix a bug: make sure that we do not pass a NULL pointer to fputs
	when echoing a line of input that isn't there (because we got EOF).
2000-09-25 04:37:26 +00:00
Fergus Henderson
76b98ac506 Add some more documentation to compiler/notes.
Estimated hours taken: 2

Add some more documentation to compiler/notes.

compiler/notes/overall_design.html:
	New file.  Contains a list of the major sub-systems
	in the compiler, and a description of how we handle
	some of the dependency issues that arise.

compiler/notes/compiler_design.html:
	Add a link to overall_design.html.
2000-08-21 14:49:50 +00:00
Fergus Henderson
99e86ef46d Mention the new ml_type_gen.m module.
Estimated hours taken: 0.1

compiler/notes/compiler_design.html:
	Mention the new ml_type_gen.m module.
2000-06-01 08:48:26 +00:00
Fergus Henderson
79d7e7aa02 Document the mark_static_terms module.
Estimated hours taken: 0.25

compiler/notes/compiler_design.html:
	Document the mark_static_terms module.
2000-05-22 20:31:05 +00:00
Fergus Henderson
4bb527330e Implement typeclasses for the MLDS back-end.
Estimated hours taken: 15

Implement typeclasses for the MLDS back-end.

compiler/rtti.m:
	Add base_typeclass_info as a new alternative in the
	rtti_name and rtti_data types.

compiler/base_typeclass_info.m:
	Change it to define base_typeclass_infos as rtti_data
	rather than comp_gen_c_data.

compiler/mercury_compile.m:
	Modify to reflect the changes to base_typeclass_info.m's
	interface.
	Also change the order in which we run the MLDS passes: make
	sure to generate all the MLDS, including that generated by
	rtti_to_mlds.m, before running the MLDS transformation passes
	ml_tailcall.m and ml_elim_nested.m, since the wrapper
	functions that rtti_to_mlds.m generates for typeclass methods
	can contain code which those two MLDS transformation passes
	need to transform.

compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/mlds_to_c.m:
compiler/opt_debug.m:
	Handle base_typeclass_infos.

compiler/mlds_to_c.m:
	Fix a bug where it was not properly mangling variable names.
	Note that polymorphism.m can introduce variable names
	that contain operators, e.g. `TypeClassInfo_for_+'.
	This bug broke tests/hard_coded/operator_classname.m.
	I also changed it to mangle label names.

compiler/rtti_to_mlds.m:
	Pass down the module_info, so that ml_gen_init_method
	can use it when generate wrapper functions for type
	class methods.

compiler/ml_unify_gen.m:
	Export the ml_gen_closure_wrapper procedure, for use by
	rtti_to_mlds for type class methods.

compiler/ml_code_util.m:
	Add a new predicate `ml_gen_info_bump_func_label',
	for use by rtti_to_mlds.m when generating wrapper
	Add some functions defining magic numbers related to
	the representation of type_infos, base_typeclass_infos,
	and closures.

compiler/ml_call_gen.m:
	Handle type class method calls.

compiler/llds_out.m:
	Split the code for outputting a base_typeclass_info name
	into a separate subroutine, and export that subroutine,
	for use by rtti_out.m.

compiler/llds_out.m:
compiler/rtti_out.m:
	Change llds_out.m so that it calls a new predicate
	output_base_typeclass_info_storage_type_name, defined in
	rtti_out.m, when outputting base_typeclass_info declarations.
	This is needed because base_typeclass_infos are now defined
	as RTTI constants with type `Code * []', and so need to be
	handled as such by rtti_out.m rather than being assumed to
	be structs like the other LLDS data_names.
	Also move the code for handling dynamic initialization of
	method pointers from llds_out.m to rtti_out.m,
	at the same time changing it to handle their new definitions
	as rtti_data rather than comp_gen_c_data.

compiler/mlds.m:
	Delete the type `base_data', since it is no longer needed.

compiler/notes/type_class_transformation.html:
	Fix a documentation bug: the second field of
	base_typeclass_infos is the number of instance constraints,
	not the number of unconstrained type variables.

compiler/notes/compiler_design.html:
	Document the use of the rtti modules in the MLDS back-end,
	and improve the documentation of their use in the LLDS back-end.

runtime/mercury.h:
	Add a typedef for `MR_BaseTypeclassInfo', for use by the
	code generated by rtti_to_mlds.m and mlds_to_c.m
	for base_typeclass_infos.

	Also add another work-around declaration of an MR_TypeCtorInfo;
	with this, the browser directory now compiles.
2000-05-10 18:09:45 +00:00
Zoltan Somogyi
4ccc3b32ac Cleanup of the type_ctor_infos and their components, to achieve two goals.
Estimated hours taken: 65

Cleanup of the type_ctor_infos and their components, to achieve two goals.
First, the new data structure is defined in strongly typed C, with only
two unions, whereas the old data structure was defined by a bunch of macros
that used casts all over the place. The new design should therefore make it
significantly easier to debug code that uses RTTI, and to get it right in
the first place. Second, the new data structures are logically organized,
whereas the old ones had several bad features (such as fixed fields coming
after variable-length arrays in "structures") required by backward
compatibility.

For the time being, the runtime system will be able to handle type_ctor_infos
using both the old and the new data structures, which are distinguished by
the type_ctor_info's version number.

To minimize the disruption caused by such bootstrapping, this change also
incorporates an improvement in the RTTI: for most pseudo_type_infos included
in the RTTI, it records information that allows the runtime system to tell
whether the pseudo_type_info is ground or not; if it is, then the runtime
need not scan the pseudo_type_info looking for type parameters to expand.
Based on statistics I have gathered, this will eliminate between half and two
thirds of all such scans when we do unification and comparison by RTTI.

This change does not impact the structures of typeinfos, base_typeclass_infos
or typeclass_infos.

runtime/mercury_type_info.h:
	Define the C types for the new type_ctor_info components.

	Update the C type for type_ctor_infos themselves, and the macros
	that act on it.

	Centralize the list of files that depend on type info representation
	here.

	Make the names of the two macros that give the number of (all kinds of)
	type info vars and the number of existential type info vars consistent.

runtime/mercury_std.h:
	Change a comment to refer to one of these renamed macros by its new
	name.

compiler/rtti.m:
compiler/rtti_out.m:
	New files: rtti.m defines new types that allow us to construct
	Mercury representations of the C structures we want to emit,
	and rtti_out.m converts those representations to C definitions.
	These files are intended to be independent of whether the backend
	is LLDS or MLDS. At the moment, there are several vestiges that
	tie them to LLDS, mostly due to (a) the lack of a shared common
	infrastructure between llds_out.m and mlds_to_c.m, and (b)
	the continued use of the old representation of (pseudo-) typeinfos
	as rvals. These concerns will be addressed in a future change.

compiler/llds.m:
	Update the definition of the comp_gen_c_data and data_addr types
	to account for the new RTTI structures.

compiler/llds_out.m:
	Update the code to output comp_gen_c_data and data_addr values
	to account for the new RTTI structures.

	Make some parts of the code more modular, so that rtti_out.m
	can use what used to be selected parts of predicates.

	Export several predicates for use by rtti_out.m. Some of these
	should later be moved to a file for infrastructure shared by
	llds_out.m and mlds_to_*.m. Others should be made internal again
	when the representation of typeinfos is made independent of the LLDS.

	Rename some predicates to better reflect their purpose.

compiler/base_type_layout.m:
compiler/base_type_info.m:
	These files are obsoleted by this change. They remain in CVS, but
	are no longer used. All of base_type_info.m has been moved into
	type_ctor_info.m, and so have the parts of base_type_layout.m
	that create the functors and layout structures inside type_ctor_infos;
	the remaining part of base_type_layout.m is now in pseudo_type_info.m.

compiler/pseudo_type_info.m:
	New file containing the code to create pseudo_type_infos from
	base_type_layout.m, slightly updated for the new compiler structure.

compiler/type_ctor_info.m:
        New module: almost total rewrite of the base_type_info.m and the
	relevant part of base_type_layout.m for the new data structure.

	Do not invoke base_typeclass_info.m, since the structures it creates
	are not parts of the type_ctor_infos.

compiler/ml_base_type_info.m:
	Comment out obsolete unfinished code. It should be replaced by
	calls to type_ctor_info, once type_ctor_info's dependence on LLDS
	has been eliminated.

compiler/hlds_module.m:
	Rename the data structure from which type_ctor_infos are generated.
	Delete the data structure from which type_ctor_layouts were generated,
	since it is redundant.

	Switch to using field names.

compiler/make_tags.m:
compiler/hlds_data.m:
	make_tags.m had code that duplicated much of the the functionality
	of an existing predicate in hlds_data.m. This change moves that
	predicate to hlds_data where it belongs, and gives it an appropriate
	name.

compiler/mercury_compile.m:
	Do not invoke the predicates that used to be in base_type_layouts
	directly; let type_ctor_info do it for the types for which it is
	appropriate.

	Do invoke base_typeclass_info directly.

compiler/dead_proc_elim.m:
compiler/llds_common.m:
compiler/opt_debug.m:
compiler/stack_layout.m:
compiler/unify_gen.m:
	Trivial changes to conform to the changes in the representation of
	compiler-generated C data.

compiler/notes/compiler_design.html:
	Updates to reflect the new files.

runtime/mercury_deep_copy_body.h:
runtime/mercury_tabling.c:
runtime/mercury_type_info.c:
	Provide alternate implementations of functionality that used the
	old functors and layout structures, to use the new ones instead
	if the relevant type_ctor_info's version number calls for it.
	In many cases, doing this cleanly required reducing the scopes of
	variables.

runtime/mercury_tabling.[ch]:
	Note where additional work on tabling of typeclass infos is needed,
	but do not do the work yet, since it would conflict with DJ's coming
	change.

library/std_util.m:
	Provide alternate implementations of functionality that used the
	old functors and layout structures, to use the new ones instead
	if the relevant type_ctor_info's version number calls for it.
	In many cases, doing this cleanly required reducing the scopes of
	variables.

	The predicates get_functor and construct take an integer argument
	that identifies a functor of a du type. The integer used to be
	the functor's ordinal number in the type definition, but this
	was not documented. It is now the functor's position in the list
	of the type's functors sorted first on name and then on arity.
	This functionality is potentially more useful, since io__read
	could do binary instead of linear search when looking for a given
	functor. This is an incompatibility, but a very minor one.

	Add a new predicate, get_functor_ordinal, to provide a way
	to convert lexicographic position into ordinal position.
	This is not used yet.

	Rename the two different kinds of variables named "info" so that
	one can tell them apart.

tests/hard_coded/construct.exp:
	Update the expected output of this test based on the new definition
	of the meaning of functor numbers in the get_functor and construct
	predicates in std_util.

tests/hard_coded/deep_copy.{m,exp}:
	Add some code to test the "type contains var" bit vector in du
	functor descriptions.

tests/hard_coded/existential_rtti.{m,exp}:
	Make the test case print out results as it goes along, to make it
	easier which subtask a core dump is coming from. Update the expected
	output accordingly.
2000-03-10 13:38:21 +00:00
Peter Ross
d79cc30587 Recognise associativity assertions, and use them to introduce
Estimated hours taken: 35

Recognise associativity assertions, and use them to introduce
accumulators.

mercury/compiler/assertion.m:
    Add assertion__is_associativity_assertion, which for an assert_id
    determines whether the assertion is associative.

mercury/compiler/accumulator.m:
    Call assertion__is_associativity_assertion to determine whether a
    call is associative.
    Rather than failing if a call is associative and nothing is known
    about the effect of rearranging the argument order, report a
    suppressible warning.
    Fix a bug where the mode of the introduced pred wasn't correct.

mercury/compiler/mercury_compile.m:
    Move accumulator introduction before inlining and unused_args, as
    inlining can inline an associative call making it unrecognisable and
    unused_args eliminates arguments which make it difficult to relate
    the assertion with the actual call.

mercury/compiler/notes/compiler_design.html:
    Document the constraints on when the module accumulator.m can be
    called for it to be effective.

mercury/compiler/options.m:
    Add the new option "--inhibit-accumulator-warnings".

mercury/doc/user_guide.texi:
    Document "--inhibit-accumulator-warnings".

mercury/library/list.m:
    Declare list__append to be associative.

tests/general/accumulator/runtests:
    Turn the tests back on, they *should* work under different
    optimization levels now.

tests/warnings/Mmakefile:
tests/warnings/arg_order_rearrangment.exp:
tests/warnings/arg_order_rearrangment.m:
    Test that a warning is output when accumulator introduction reorders
    the arguments to a call without knowing the performance
    implications.
2000-01-10 00:44:07 +00:00
Fergus Henderson
0cb9cf89fd Document stratify.m and trans_opt.m.
Estimated hours taken: 0.25

compiler/notes/compiler_design.html:
	Document stratify.m and trans_opt.m.
1999-12-20 18:08:39 +00:00
Fergus Henderson
28f0898dda Implement the generation of base_type_info structures
Estimated hours taken: 3

Implement the generation of base_type_info structures
for the MLDS back-end.  (Generation of base_type_functors
and base_type_layouts is still not yet implemented, though.)

compiler/ml_base_type_info.m:
	New file.  This generates the base_type_info structures.
	It is similar to base_type_info.m, but for the MLDS back-end.

compiler/ml_code_gen.m:
	Change ml_gen_types to call ml_base_type_info__generate_mlds.
	Export ml_gen_pred_label, for use by ml_base_type_info.m.

compiler/mlds.m:
	Add a new MLDS type `mlds__base_type_info_type',
	for base_type_infos.

compiler/mlds_to_c.m:
	Add code to handle `mlds__base_type_info_type'.
	Handle complex initializers.
	Generate proper module qualifiers for data names.

compiler/base_type_info.m:
	Delete an obsolete comment.
	Add a comment warning that any changes here may also require
	changes to ml_base_type_info.m.

compiler/notes/compiler_design.html:
        Mention the new module.
1999-12-02 05:48:24 +00:00
Fergus Henderson
8079645f11 Modify the MLDS back-end to support the `--no-gcc-nested-functions' option.
Estimated hours taken: 30

Modify the MLDS back-end to support the `--no-gcc-nested-functions' option.

compiler/ml_elim_nested.m:
	New module.  Contains an MLDS->MLDS transformation pass
	to eliminated nested functions.

compiler/mercury_compile.m:
	Call the new pass.

compiler/notes/compiler_design.html:
	Mention the new module.

compiler/ml_code_gen.m:
	If --no-gcc-nested-functions is specified, then pass
	environment pointers to the nested continuation functions.

	Note that most of the work of converting nested functions
	into non-nested functions is deferred to the ml_elim_nested
	pass.  But the passing of environment pointers affects the
	calling convention, and so it really needs to be done
	here -- it can't be done in any semantics-preserving
	MLDS transformation later one.  Also it is easier to do
	it in this pass anyway.

	Also fix a bug where it was miscalculating the set of
	variables to declare.

compiler/mlds.m:
	- Add a new alternative `mlds__generic_env_ptr_type',
	  used for environment pointers.
	- Add a new alternative `mlds__class_type' to the
	  `mlds__type' discriminated union, so that types
	  can include user-defined types.  This is needed so
	  that we can define struct types for the nested
	  function enviroments.
	  As part of that change, rename `mlds__class' as `mlds__class_defn'.
	- Change the argument type for the `do_commit' and `try_commit'
	  instructions from `var' to `rval'/`lval'.  This is needed so that
	  these instructions can refer to references defined in the
	  containing function via the environment pointer.

compiler/mlds_to_c.m:
	- Changed to reflect the renaming of `mlds__class'
	  as `mlds__class_defn'.
	- Changed to reflect the change to the `do_commit' and `try_commit'
	  argument types.
	- For the `mlds__cont_type' type, output it as either
	  `MR_NestedCont' or `MR_Cont', depending on whether
	  the `--gcc-nested-functions' option is enabled.
	- Fix a bug where it would incorrectly parenthesizing
	  the left-hand operand of `->'.
	- Insert some additional blank lines in the output,
	  for readability.

runtime/mercury_types.h:
	- Rename the old `Cont' type as `MR_NestedCont',
	  and add a new `MR_Cont' type.
1999-11-08 22:28:05 +00:00
Fergus Henderson
d551dd1dc9 Handle quantification analysis of bi-implication (`<=>') goals correctly.
Estimated hours taken: 10

Handle quantification analysis of bi-implication (`<=>') goals correctly.
Previously we used to expand bi-implications before doing quantification
analysis, which stuffed up the results of quantification analysis for
those goals.  We need to do quantification analysis first, and only
then can we expand bi-implications.  In addition, elimination of double
negation needs to come after expansion of bi-implication, so I moved
that from make_hlds.m to purity.m.

compiler/hlds_goal.m:
	Add a new alternative to the HLDS goal type for bi-implications.
        Also add a new predicate negate_goal, for use by purity.m.

compiler/make_hlds.m:
	Don't expand bi-implication here, instead just use the new
	bi_implication/2 HLDS goal type.
	Don't eliminated double negation here.

compiler/quantification.m:
	Handle quantification for bi-implications.
	Expand bi-implications.

compiler/purity.m:
	Eliminate double negation.

compiler/hlds_out.m:
	Add code to print out bi-implication goals.

compiler/*.m:
	Trivial changes to handle the new bi_implication/2
	alternative in the HLDS goal type.

compiler/notes/compiler_design.html:
	Document the above changes.

tests/hard_coded/Mmakefile:
tests/hard_coded/quantifier2.m:
tests/hard_coded/quantifier2.exp:
	A regression test for the above change.
1999-10-25 03:53:14 +00:00
Thomas Conway
86cfbfc660 Add some documentation in the compiler notes.
Estimated hours taken: 0.25


Add some documentation in the compiler notes.

compiler/notes/compiler_design.html:
	Mention lp.m in the termination analysis section.
	Mention par_conj.m in the parallel conjunction section.
1999-10-14 05:27:35 +00:00