Commit Graph

82 Commits

Author SHA1 Message Date
Oliver Hutchison
bcf7dbf9f8 Add support for tabling.
Estimated hours taken: 250

Add support for tabling.

This change allows for model_det, model_semidet and model_non memoing,
minimal model and loop detection tabling.

compiler/base_type_layout.m:
	Update comments to reflect new runtime naming standard.

compiler/det_analysis.m:
	Allow tabling to change the result of det analysis. This is
	necessary in the case of minimal model tabling which can
	turn a det procedure into a semidet one.

compiler/det_report.m:
compiler/hlds_data.m:
	Add code to report error messages for various non compatible
	tabling methods and determinism.

compiler/hlds_out.m:
compiler/modules.m:
	Remove reference to the old memo marker.

compiler/hlds_pred.m:
	Create new type (eval_method) to define which of the available
	evaluation methods should be used each procedure.
	Add new field to the proc_info structure.
	Add several new predicates relating to the new eval_method type.

compiler/inlining.m:
compiler/intermod.m:
	Make sure only procedures with normal evaluation are inlined.

compiler/make_hlds.m:
	Add code to process new tabling pragmas.

compiler/mercury_compile.m:
	Call the tabling transformation code.

compiler/modes.m:
	Make sure that all procedures with non normal evaluation have
	no unique/partially instantiated modes. Produce error messages
	if they do. Support for partially instantiated modes is currently
	missing as it represents a large amount of work for a case that
	is currently not used.

compiler/module_qual.m:
compile/prog_data.m:
compiler/prog_io_pragma.m:
	Add three new pragma types:
		`memo'
		`loop_check'
		`minimal_model'
	and code to support them.

compiler/simplify.m:
	Don't report infinite recursion warning if a procedure has
	minimal model evaluation.

compiler/stratify.m:
	Change the stratification analyser so that it reports cases of
	definite non-stratification. Rather than reporting warnings for
	any code that is not definitely stratified.
	Remove reference to the old memo marker.

compiler/switch_detection.m:
	Fix a small bug where goal were being placed in reverse order.
	Call list__reverse on the list of goals.

compiler/table_gen.m:
	New module to do the actual tabling transformation.

compiler/notes/compiler_design.html:
	Document addition of new tabling pass to the compiler.

doc/reference_manual.texi:
	Fix mistake in example.

library/mercury_builtin.m:
	Add many new predicates for support of tabling.

library/std_util.m:
library/store.m:
	Move the functions :
		ML_compare_type_info
		ML_collapse_equivalences
		ML_create_type_info
	to the runtime.

runtime/mercury_deep_copy.c:
runtime/mercury_type_info.h:
runtime/mercury_type_info.c:
	Move the make_type_info function into the mercury_type_info module
	and make it public.

runtime/Mmakefile:
runtime/mercury_imp.h:
	Add references to new files added for tabling support.

runtime/mercury_string.h:
	Change hash macro so it does not cause a name clash with any
	variable called "hash".

runtime/mercury_type_info.c:
runtime/mercury_type_info.h:
	Add three new functions taken from the library :
		MR_compare_type_info
		MR_collapse_equivalences
		MR_create_type_info.

runtime/mercury_table_any.c:
runtime/mercury_table_any.h:
runtime/mercury_table_enum.c:
runtime/mercury_table_enum.h:
runtime/mercury_table_int_float_string.c:
runtime/mercury_table_int_float_string.h:
runtime/mercury_table_type_info.c:
runtime/mercury_table_type_info.h:
runtime/mercury_tabling.h:
	New modules for the support of tabling.
1998-05-15 07:09:29 +00:00
Fergus Henderson
49c25842cf Fix a problem reported by Baudouin Le Charlier <ble@info.fundp.ac.be>
where switch detection was getting confused by explicit existential
quantifications.

compiler/switch_detection.m:
	When detecting switches, traverse through some/2 goals.
	Also simplify the code a bit.

tests/valid/Mmakefile:
tests/valid/some_switch.m:
	Regression test for the above change.
1998-05-12 17:05:04 +00:00
Simon Taylor
d0085d8119 Assorted changes to make the HLDS type and mode correct
Estimated hours taken: 45

Assorted changes to make the HLDS type and mode correct
after lambda expansion. The HLDS is still not unique mode
correct after common structure elimination.

compiler/det_analysis.m
	Make sure the inferred_determinism field of the proc_info is filled
	in correctly for imported procedures and class methods.

compiler/mode_util.m
	Fix a bug in recompute_instmap_delta_call to do with unreachable
	instmaps. This caused an abort a couple of months ago when
	compiling with --deforestation (not yet committed), but
	can't currently be reproduced.

compiler/hlds_pred.m
compiler/lambda.m
	Add a field to the proc_info to record which args_method
	should be used for this procedure. Procedures directly
	called by do_call_*_closure must be compiled with
	the `compact' argument convention to avoid the need to permute
	the arguments so inputs come before outputs.

compiler/lambda.m
compiler/higher_order.m
	Remove permutation of argument variables of lambda expressions
	so the HLDS is type and mode correct and mode analysis can
	be rerun. Otherwise, rerunning mode analysis will fail on
	tests/hard_coded/ho_order.m.

compiler/arg_info.m
	Added arg_info__ho_call_args_method which returns
	an args_method which can always be directly called by
	do_call_*_closure (`compact').
	Added arg_info__args_method_is_ho_callable to check that
	a given args_method can be directly called.

compiler/unify_gen.m
	Abort if a closure is created for a procedure compiled
	with the simple argument convention.

compiler/hlds_goal.m
compiler/lambda.m
	Mode analysis was not storing the non-locals list on which the
	uni_modes field of the construction of a lambda goal was computed.
	If the nonlocals were renamed, the sort order could change, and
	the non-locals could be incorrectly matched with the arguments
	of the introduced lambda expression, causing a mode error. The
	argument list is now stored.
	This caused rerunning mode-checking on tests/valid/lazy_list.m
	after polymorphism to fail.

compiler/*.m
	Fill in the args_method field of proc_infos with the value
	from the globals.
	Handle the extra argument to the lambda_goal unify_rhs.

compiler/follow_vars.m
	Remove code to handle complicated unifications, since
	they should be removed by polymorphism.m.

compiler/special_pred.m
library/mercury_builtin.m
	Make the uniqueness of the comparison_result argument
	of builtin_compare_* and the automatically generated
	comparison procedures match that of compare/3. Unique mode
	errors will still be introduced if polymorphism.m specializes
	calls to any of the unique modes of compare/3 and then mode analysis
	is rerun, since the compiler-generated comparison procedures
	only implement the (uo, in, in) mode. (This is not yet a problem
	because currently we don't rerun mode analysis.)

runtime/mercury_ho_call.c
	Remove code in do_call_*_closure to deal with the
	`simple' args_method. Since the output arguments no longer
	need to be moved, the closure call is now a tailcall.
	Remove some magic numbers.

compiler/modecheck_unify.m
	Avoid some aborts and mode errors when rerunning mode analysis,
	especially those resulting from not_reached insts being treated
	as bound.
	Avoid aborting on higher-order predicate constants with multiple
	modes if lambda expansion has already been run.

tests/valid/higher_order.m
        Add a test case for an abort in mode analysis when
	compiling with --deforestation (not yet committed),
	due to a predicate constant for a procedure with multiple
	modes.

tests/valid/unreachable_code.m
	Add a test case for bogus higher-order unification
	mode errors in unreachable code.
1998-02-12 01:17:56 +00:00
Zoltan Somogyi
5013dd9c76 Implement nondet pragma C codes.
Estimated hours taken: 40

Implement nondet pragma C codes.

runtime/mercury_stacks.h:
	Define a new macro, mkpragmaframe, for use in the implementation
	of nondet pragma C codes. This new macro includes space for a
	struct with a given sruct tag in the nondet stack frame being created.

compiler/{prog_data.m,hlds_goal.m}:
	Revise the representation of pragma C codes, both as the item and
	in the HLDS.

compiler/prog_io_pragma.m:
	Parse nondet pragma C declarations.

	Fix the indentation in some places.

compiler/llds.m:
	Include an extra argument in mkframe instructions. This extra argument
	gives the details of the C structure (if any) to be included in the
	nondet stack frame to be created.

	Generalize the LLDS representation of pragma C codes. Instead of a
	fixed sequence of <assign from inputs, user c code, assign to outputs>,
	let the sequence contain these elements, as well as arbitrary
	compiler-generated C code, in any order and possibly with repetitions.
	This flexibility is needed for nondet pragma C codes.

	Add a field to pragma C codes to say whether they can call Mercury.
	Some optimizations can do a better job if they know that a pragma C
	code cannot call Mercury.

	Add another field to pragma C codes to give the name of the label
	they refer to (if any). This is needed to prevent labelopt from
	incorrectly optimizing away the label definition.

	Add a new alternative to the type pragma_c_decl, to describe the
	declaration of the local variable that points to the save struct.

compiler/llds_out.m:
	Output mkframe instructions that specify a struct as invoking the new
	mkpragmaframe macro, and make sure that the struct is declared just
	before the procedure that uses it.

	Other minor changes to keep up with the changes to the representation
	of pragma C code in the LLDS, and to make the output look a bit nicer.

compiler/pragma_c_gen.m:
	Add code to generate code for nondet pragma C codes. Revise the utility
	predicates and their data structures a bit to make this possible.

compiler/code_gen.m:
	Add code for the necessary special handling of prologs and epilogs
	of procedures defined by nondet pragma C codes. The prologs need
	to be modified to include a programmer-defined C structure in the
	nondet stack frame and to communicate the location of this structure
	to the pragma C code, whereas the functionality of the epilog is
	taken care of by the pragma C code itself.

compiler/make_hlds.m:
	When creating a proc_info for a procedure defined by a pragma C code,
	we used to insert unifications between the headvars and the vars of
	the pragma C code into the body goal. We now perform substitutions
	instead. This removes a factor that would complicate the generation
	of code for nondet pragma C codes.

	Pass a moduleinfo down the procedures that warn about singletons
	(and other basic scope errors). When checking whether to warn about
	an argument of a pragma C code not being mentioned in the C code
	fragment, we need to know whether the argument is input or output,
	since input variables should appear in some code fragments in a
	nondet pragma C code and must not appear in others. The
	mode_is_{in,out}put checks need the moduleinfo.

	(We do not need to check for any variables being mentioned where
	they shouldn't be. The C compiler will fail in the presence of any
	errors of that type, and since those variables could be referred
	to via macros whose definitions we do not see, we couldn't implement
	a reliable test anyway.)

compiler/opt_util.m:
	Recognize that some sorts of pragma_c codes cannot affect the data
	structures that control backtracking. This allows peepholing to
	do a better job on code sequences produced for nondet pragma C codes.

	Recognize that the C code strings inside some pragma_c codes refer to
	other labels in the procedure. This prevents labelopt from incorrectly
	optimizing away these labels.

compiler/dupelim.m:
	If a label is referred to from within a C code string, then do not
	attempt to optimize it away.

compiler/det_analysis.m:
	Remove a now incorrect part of an error message.

compiler/*.m:
	Minor changes to conform to changes to the HLDS and LLDS data
	structures.
1998-01-13 10:14:23 +00:00
Zoltan Somogyi
bb4442ddc1 Update copyright dates for 1998.
Estimated hours taken: 0.5

compiler/*.m:
	Update copyright dates for 1998.
1998-01-13 10:06:08 +00:00
David Jeffery
7406335105 This change implements typeclasses. Included are the necessary changes to
Estimated hours taken: 500 or so

This change implements typeclasses. Included are the necessary changes to
the compiler, runtime and library.

compiler/typecheck.m:
	Typecheck the constraints on a pred by adding constraints for each
	call to a pred/func with constraints, and eliminating constraints
	by applying context reduction.

	While reducing the constraints, keep track of the proofs so that
	polymorphism can produce the tyepclass_infos for eliminated
	constraints.

compiler/polymorphism.m:
	Perform the source-to-source transformation which turns code with
	typeclass constraints into code without constraints, but with extra
	"typeclass_info", or "dictionary" parameters.

	Also, rather than always having a type_info directly for each type
	variable, sometimes the type_info is hidden inside a typeclass_info.

compiler/bytecode*.m:
	Insert some code to abort if bytecode generation is used when
	typeclasses are used.
compiler/call_gen.m:
	Generate code for a class_method_call, which forms the body of a class
	method (by selecting the appropriate proc from the typeclass_info).
compiler/dead_proc_elim.m:
	Don't eliminate class methods if they are potentially used outside
	the module
compiler/hlds_data.m:
	Define data types to store:
		- the typeclass definitions
		- the instances of a class
		- "constraint_proof". ie. the proofs of redundancy of a
		  constraint. This info is used by polymorphism to construct the
		  typeclass_infos for a constraint.
		- the "base_tyepclass_info_constant", which is analagous the
		  the base_type_info_constant
compiler/hlds_data.m:
	Define the class_method_call goal. This goal is inserted into the
	body of class method procs, and is responsible for selecting the
	appropriate part of the typeclass_info to call.
compiler/hlds_data.m:
	Add the class table and instance table to the module_info.
compiler/hlds_out.m:
	Output info about base_typeclass_infos and class_method_calls
compiler/hlds_pred.m:
	Change the representation of the locations of type_infos from "var"
	to type_info_locn, which is either a var, or part of a typeclass_info,
	since now the typeclass_infos contain the type_infos for the type that
	they constrain.

	Add constraints to the pred_info.

	Add constraint_proofs to the pred_info (so that typeclass.m can
	annotate the pred_info with the reasons that constraints were
	eliminated, so that polymorphism.m can in turn generate the
	typeclass_infos for the constraints).

	Add the "class_method" marker.

compiler/lambda.m:
	A feable attempt at adding class ontexts to lambda expressions,
	untested and almost certainly not working.
compiler/llds_out.m:
	Output the code addresses for do_*det_class_method, and output
	appropriately mangled symbol names for base_typeclass_infos.
compiler/make_hlds.m:
	Add constraints to the types on pred and func decls, and add
	class and instance declarations to the class_table and instance_table
	respectively.
compiler/mercury_compile.m:
	Add the check_typeclass pass.
compiler/mercury_to_mercury.m:
	Output constraints of pred and funcs, and output typeclass and instance
	declarations.
compiler/module_qual.m:
	Module qualify typeclass names in pred class contexts, and qualify the
	typeclass and instance decls themselves.
compiler/modules.m:
	Output typeclass declarations in the short interface too.
compiler/prog_data.m:
	Add the "typeclass" and "instance" items. Define the types to store
	information about the declarations, including class contexts on pred
	and func decls.
compiler/prog_io.m:
	Parse constraints on pred and func declarations.
compiler/prod_out.m:
	Output class contexts on pred and func decls.
compiler/type_util.m:
	Add preds to apply a substitution to a class_constraint, and to
	a list of class constraints. Add type_list_matches_exactly/2. Also
	add typeclass_info and base_typeclass_info as types which should not
	be optimised as no_tag types (seeing that we cheat a bit about their
	representation).
compiler/notes/compiler_design.html:
	Add notes on module qualification of class contexts. Needs expansion
	to include more stuff on typeclasses.
compiler/*.m:
	Various minor changes.

New Files:
compiler/base_typeclass_info.m:
	Produce one base_typeclass_info for each instance declaration.
compiler/prog_io_typeclass.m:
	Parse typeclass and instance declarations.
compiler/check_typeclass.m:
	Check the conformance of an instance declaration to the typeclass
	declaration, including building up a proof of how superclass
	constraints are satisfied so that polymorphism.m is able to construct
	the typeclass_info, including the superclass typeclass_infos.

library/mercury_builtin.m:
	Implement that base_typeclass_info and typeclass_info types, as
	well as the predicates type_info_from_typeclass_info/3 to extract
	a type_info from a typeclass_info, and superclass_from_typeclass_info/3
	for extracting superclasses.
library/ops.m:
	Add "typeclass" and "instance" as operators.
library/string.m:
	Add a (in, uo) mode for string__length/3.

runtime/mercury_ho_call.c:
	Implement do_call_*det_class_method, which are the pieces of code
	responsible for extracting the correct code address from the
	typeclass_info, setting up the arguments correctly, then executing
	the code.
runtime/mercury_type_info.h:
	Macros for accessing the typeclass_info structure.
1997-12-19 03:10:47 +00:00
Fergus Henderson
5976f769f7 Fix a bug for the case of a higher-order function call in code
Estimated hours taken: 1

Fix a bug for the case of a higher-order function call in code
with common sub-expression; mercury 0.7 failed this test, reporting
"Software Error: modecheck fails when repeated", due to confusion
between h.o. _function_ call and h.o. _predicate_ call.

compiler/hlds_goal.m:
	Add `pred_or_func' field to HLDS higher_order_calls.

compiler/modes.m:
compiler/modecheck_call.m:
compiler/hlds_out.m:
compiler/*.m:
	Add code to handle new field for higher_order_call goals.

tests/valid/Mmake:
tests/valid/ho_func_call.m:
	Regression test for the above-mentioned bug.
1997-09-01 14:05:44 +00:00
Fergus Henderson
99184d3578 Implement support for types with user-defined equality predicates.
Estimated hours taken: 30

Implement support for types with user-defined equality predicates.

Types with user-defined equality predicates are called "non-canonical types";
they may have more than one representation for the same abstract value.
That means that any attempt to deconstruct a value of a non-canonical
type, i.e. any attempt to peek at the representation, must be cc_multi.

This also implies that conceptually speaking, non-canonical types are not
members of the type classes `comparable' (compare/3) or `deconstructible'
(index/2, argument/3, functor/3, deconstruct/5).  Since we don't support
type classes yet, that just means that the type-class checking is done
at runtime, i.e. any call to one of those functions for a non-canonical
type will call error/1 or fatal_error().

To make non-canonical types useful, we really need type classes,
so that the user can provide instance definitions for `comparable'
and `deconstructible' for such types.  It might also be a good idea
to have a type-class `canonicalizable' which provides a function
to convert its argument to some canonical type (that would
require existential types to do nicely, but alternatively we could
just use `univ').

Note that currently the only mechanism for promising that things are
unique is via the C interface.

compiler/det_analysis.m:
	Add code to check unifications that examine the
	representation of a type with a user-defined equality predicate.
	Any such unification must occur in a single-solution context and
	must not be able to fail.  Such unifications determinism have
	determinism cc_multi.

compiler/det_report.m:
	Add code to report errors for misuse of types with user-defined
	equality predicates.  (Also some other stylistic improvements:
	split up a complicated predicate into subroutines, and
	avoid some unnecessary code duplication.)

compiler/prog_data.m:
compiler/hlds_data.m:
	Add a new `maybe(sym_name)' field to the du_type/3 constructor
	to hold the name of the user-defined equality pred for the
	type, if any.

compiler/prog_io.m:
	Add code to parse the new `... where equality is <name>.' syntax.
	Delete the old support for `... where <condition>'.

compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
compiler/mercury_to_goedel.m:
	Print out the new field.

compiler/base_type_layout.m:
compiler/code_util.m:
compiler/dense_switch.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/make_hlds.m:
compiler/mode_util.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/switch_detection.m:
compiler/tag_switch.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
	Trivial changes to ignore (or leave unchanged)
	the new field in `du_type'.

compiler/modecheck_unify.m:
	Pass the term__context to unify_proc__request_unify.

compiler/typecheck.m:
	Typecheck the compiler-generated unify predicates for types
	with user-defined equality preds.

compiler/unify_proc.m:
	For d.u. types, if the type has a user-defined equality predicate
	then generate code for the compiler-generated unify predicate
	that just calls the specified predicate, and generate
	code for the compiler-generated compare and index predicates
	that just calls some procedures in mercury_builtin.m that
	report appropriate error messages.
	Ensure that the automatically-generated predicates
	have appropriate term__contexts everywhere, so that if
	the user-defined equality predicate name is ambiguous,
	non-existent, or has the wrong type, mode, or determinism,
	then the error messages from type checking, mode checking,
	or determinism checking refer to the type declaration.

library/mercury_builtin.m:
	Add predicates builtin_index_non_canonical_type/2
	and builtin_compare_non_canonical_type/2, used by
	the code generated by compiler/unify_proc.m.

doc/reference_manual.texi:
	Document the support for user-defined equality predicates.

library/std_util.m:
	Change ML_expand() to return an indication of whether or not
	the type is a non-canonical type (one with a user-defined
	equality predicate).  Change argument/2, functor/2, and
	deconstruct/4 to abort if called for a non-canonical type.
1997-08-22 13:57:43 +00:00
Fergus Henderson
04b720630b Update the copyright messages so that (a) they contain the correct years
and (b) they say "Copyright (C) ... _The_ University of Melbourne".
1997-07-27 15:09:59 +00:00
Andrew Bromage
9b7f11c6dd Reorganisation of modules to do with the inst data type.
Estimated hours taken: 20

Reorganisation of modules to do with the inst data type.

This is actually the first installment of the alias tracking mode
checker in disguise.  A very good disguise.  The rationale for
this reorganisation is to reduce coupling in the part of the mode
checker which is _not_ in this change (ie most of it).

Alias tracking requires a new kind of inst, alias(inst_key), where
an inst_key is a handle on some other sub-inst.  With it goes a
data structure in which to store dereferenced insts and all the
operations which go with it.  This code will go in the new module
inst.m so that it doesn't have to go in prog_data.m.  (I briefly
considered putting it in instmap.m however this introduces some
bad coupling since instmap.m imports hlds_module.m.  Putting it
in prog_data.m would cause hlds_*.m to depend on prog_data.m,
but we have designed things so that the dependencies go in the
other direction.)

The remainder of the reorganisation is a general cleanup: the
inst testing predicates (inst_is_*) have been moved out of
mode_util because they are not actually operations on modes at
all, and have been moved into inst_match.  inst_match has then
been split because otherwise it would be 2000 lines long and
will get significantly bigger when aliasing is added.  Roughly
speaking, any operations which create new insts from old ones
have been moved into a new module, inst_util while any operations
which test the values of insts remain in inst_match.

Also included are the removal of some NU-Prologisms since the
NU-Prolog version of the compiler is no longer supported.  Two
changes here:

	- Removal of some when declarations.
	- A gross hack in inst_is_*_2, where two copies of
	  the same inst were passed into the predicate so that
	  one could be switched on.  Thank NU-Prolog's lack of
	  common subexpression elimination.

compiler/inst.m:
	New module which contains the data types inst, uniqueness,
	pred_inst_info, bound_inst.

compiler/inst_util.m:
	New module which contains predicates which perform mode
	checking-like operations on insts.

	Moved in:
		abstractly_unify_inst, abstractly_unify_inst_functor,
		inst_merge, make_mostly_uniq_inst (from inst_match.m)

compiler/inst_match.m:
	Moved out:
		inst_merge, make_mostly_uniq_inst,
		abstractly_unify_inst, abstractly_unify_inst_functor
			(to inst_util.m)

	Moved in:
		inst_is_*, inst_list_is_*, bound_inst_list_is_*
			(from mode_util.m)

	Now exported:
		unique_matches_initial/2, unique_matches_final/2
		inst_contains_instname/3, pred_inst_matches/3
		(They are required by inst_util.m, and they are
		useful in their own right.)

compiler/instmap.m:
	instmap_delta_lookup_var/3 reincarnated as
	instmap_delta_search_var/3.  The reason for this change is
	that previously, instmap_delta_lookup_var simply returned
	`free' if the searched-for var did not occur in the
	instmap_delta.  This is somewhat non-obvious behaviour.
	instmap_delta_search_var/3 fails in such a situation.

compiler/mode_util.m:
	Moved out:
		inst_is_*, inst_list_is_*, bound_inst_list_is_*
			(to inst_match.m)
		(These are not really operations on modes.)

compiler/modecheck_call.m:
	Moved in modecheck_higher_order_func_call/5, from modecheck_unify.m

compiler/modecheck_unify.m:
	Moved out modecheck_higher_order_func_call/5, to modecheck_call.m
	where it should have been all along.

compiler/prog_data.m:
	Moved out the types inst, uniqueness, pred_inst_info,
	bound_inst (to inst.m).

compiler/common.m:
compiler/cse_detection.m:
compiler/fact_table.m:
compiler/higher_order.m:
compiler/hlds_data.m:
compiler/hlds_goal.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/liveness.m:
compiler/llds.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/mode_debug.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/modes.m:
compiler/module_qual.m:
compiler/polymorphism.m:
compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/prog_util.m:
compiler/simplify.m:
compiler/switch_detection.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
	Miscellaneous minor changes to cope with the above changes.

compiler/notes/compiler_design.html:
	Document the new modules.
1997-07-24 01:27:21 +00:00
Fergus Henderson
1c0dd039c4 Fix a problem with my last change to output verbose progress
Estimated hours taken: 0.25

compiler/switch_detection.m:
	Fix a problem with my last change to output verbose progress
	messages during switch detection: the messages were a bit *too*
	verbose.
1997-07-08 05:46:01 +00:00
Fergus Henderson
7d5136b303 Output verbose progress messages during switch detection.
Estimated hours taken: 0.25

compiler/switch_detection.m:
compiler/mercury_compile.m:
	Output verbose progress messages during switch detection.
1997-07-07 12:05:04 +00:00
Fergus Henderson
365d737a15 Fix a bug. It was preferring incomplete switches to
Estimated hours taken: 8

compiler/switch_detection.m:
	Fix a bug.  It was preferring incomplete switches to
	complete one-case switches, which lead to spurious determinism
	errors in some cases.
1997-05-11 10:52:53 +00:00
Simon Taylor
ce9ef7ebbb Fix a determinism analysis abort which was caused by det_analysis.m not
Estimated hours taken: 1.5

Fix a determinism analysis abort which was caused by det_analysis.m not
updating the instmap to include the initial insts of the lambda variables
before processing a lambda goal. This problem was also present in
cse_detection.m and simplify.m.

compiler/cse_detection.m
compiler/det_analysis.m
compiler/simplify.m
	Make sure that the instmap is updated before processing a lambda goal.

compiler/switch_detection.m
compiler/instmap.m
	Move some code to update the instmap before a lambda goal from
	switch_detection.m into a new predicate
	instmap__update_for_lambda_modes/5.

tests/valid/Mmake
tests/valid/lambda_instmap_bug.m
	Regression test.
1997-05-08 06:46:56 +00:00
Fergus Henderson
e3471f333f Fix a bug in inlining of polymorphic pragma c_code procedures.
Estimated hours taken: 3

Fix a bug in inlining of polymorphic pragma c_code procedures.

The bug was that if the actual argument type has a specific type
of say `float', then the C variable for the corresponding formal
parameter will be declared to have type `Float', whereas without
inlining the argument type would have been polymorphic and so
the C variable would have been declared to have type `Word'.
Hence we need to keep track of the original argument types,
before any inlining or specialization has occurred, and use
these original argument types to determine how to declare
the C variables, rather than using the actual argument types
for this particular specialization.

compiler/hlds_goal.m:
	Add a new field to pragma_c_code goals, holding the
	original argument types (before any inlining or specialization)
	of the pragma_c_code procedure.

compiler/make_hlds.m:
	Initialize this field with the declared argument types for
	the pragma c_code procedure.

compiler/polymorphism.m:
	Update this field to account for the inserted type_info variables.

compiler/code_gen.m:
	Pass this field to pragma_c_gen.m.

compiler/pragma_c_gen.m:
	Use the original argument types field for the pragma variable
	declarations, rather than looking up the actual types of the
	arguments.

compiler/*.m:
	Trivial changes to handle new field.

compiler/live_vars.m:
	Comment out some code to avoid a warning about `fail'
	in the condition of an if-then-else.
1997-05-05 11:17:40 +00:00
Zoltan Somogyi
4c3b0ecb09 Replace calls to map__set with calls to either map__det_insert or
Estimated hours taken: 3

Replace calls to map__set with calls to either map__det_insert or
map__det_update. In some cases this required a small amount of code
reorganization.
1997-04-07 05:39:59 +00:00
Fergus Henderson
3ec8a17ffc Enable the code to treat `__' as an alternative syntax for module
Estimated hours taken: 8

Enable the code to treat `__' as an alternative syntax for module
qualification, after fixing various places in the compiler where
we use `__' in ways that are incompatible with this.

compiler/prog_io.m:
compiler/prog_io_goal.m:
	Uncomment the code to handle `__' as module qualification.

compiler/intermod.m:
compiler/hlds_module.m:
compiler/modecheck_unify.m:
	Fix bugs in the handling of module qualified higher-order terms.

compiler/*.m:
	s/hlds__/hlds_/g

compiler/passes_aux.m:
	s/process__/process_/g

compiler/pragma_c_gen.m:
compiler/code_gen.m:
	s/code_gen__/pragma_c_gen__/ for the predicates defined in
	pragma_c_gen.m (this ought to have been done when the code
	was first moved from code_gen.m to pragma_c_gen.m).

compiler/llds.m:
	s/llds__proc_id/llds_proc_id/g
	The reason for this was to avoid ambiguity between proc_id
	in hlds_pred.m and llds__proc_id in llds.m.

compiler/quantification.m:
compiler/make_hlds.m:
compiler/mercury_to_c.m:
	s/goal_vars/quantification__goal_vars/g
	The reason for this was to avoid ambiguity between goal_vars
	in quantification.m and goal_util__goal_vars in goal_util.m.

compiler/dupelim.m:
compiler/optimize.m:
	s/dupelim__main/dupelim_main/g
	The reason for this change is that a program can only
	have one main/2 predicate.

compiler/prog_io_dcg.m:
	Remove the old "temporary hack" to strip off and ignore
	io__gc_call/1, since the new handling of `__' broke it.
	It was only useful for optimizing NU-Prolog performance,
	which we don't care about anymore.

compiler/mercury_compile.m:
compiler/modules.m:
compiler/intermod.m:
compiler/prog_io.m:
	Remove occurrences of io__gc_call.

compiler/llds_out.m:
compiler/base_type_info.m:
	Ensure that we properly handle the special hacks in mercury_builtin
	where predicates from other modules (e.g. term__context_init)
	are defined in mercury_builtin because they are needed for
	type_to_term and term_to_type.  llds_out.m: don't put
	`mercury_builtin' in the mangled names for those symbols.
	base_type_info.m: handle types whose status is "imported"
	in their own module.
1997-02-23 06:08:34 +00:00
Fergus Henderson
7b687a4a71 Support 8-bit characters, including '\0'. (Previously we didn't
support them because NU-Prolog couldn't support them.)
This required two main changes:
(a) eliminating places where we explicitly assumed that character codes
    ranged from 1 to 127.
(b) making sure that all conversions from `Char' to `Integer' are done
    by first explicitly casting to `UnsignedChar'.  This is necessary
    to avoid potential problems on C compilers for which `char' is signed.

library/char.m:
library/char.nu.nl:
	Replace the implementation of char__to_int as a big table
	with an implementation using pragma c_code, so that it doesn't
	assume that character codes range from 1 to 127.
	Move the old implementation into a new file char.nu.nl,
	since it's still needed for Prolog support.
	Add new predicates char__min_char_value/1 and char__max_char_value/1.

library/Mmakefile:
	Add char.nu.nl to the list of files needed for Prolog support.

library/lexer.m:
	Rewrite io__get_token_[12] in the original (less efficient) way
	that they were written before conway's change in revision 1.17,
	to avoid assuming anything about the range of character codes.
	(Once this change has bootstrapped, it might be worth going back
	to the efficient version, modified of course to assume that
	character codes range from 0..255 rather than 1..127.
	However, at least for bootstrapping we need to use the less
	efficient version.)

runtime/mercury_string.h:
	Add `UnsignedChar' typedef.

library/string.m:
	In string__to_int_list, make sure that the conversion from
	`Char' to `Integer' is done by first explicitly casting to
	`UnsignedChar'.
	Also a few other minor fixes:
		- remove an old XXX by using make_aligned_string()
		- use `size_t' rather than `Word' for a string length;
		- add a missing `const'
		- remove an unnecessary cast to (char)
		- change a `while (--p >= Str) { ...' to
		  `while (p > Str) { p--; ...', because pointing to
		  one before the start of an array is not strictly
		  ANSI-conformant.

compiler/switch_detection.m:
compiler/dense_switch.m:
	Use char__min_char_value and char__max_char_value to avoid
	assuming 7-bit chars.  (We still don't get cross-compilation
	between platforms with different size characters right yet,
	but that's not a major issue right now.)

compiler/export.m:
	Make sure that conversions from `Char' to `Word'
	are done by first explicitly casting to `UnsignedChar'.

NEWS:
	Mention that we now support 8-bit characters.
	Mention the new predicates char__min_char_value/1 and
	char__max_char_value/1, as well as int__int_min, int__int_max,
	int__bits_per_int (which were added previously, with different
	names, but not mentioned in the NEWS file).
	Also make minor cleanups to a few of the other messages.
1997-02-19 05:36:24 +00:00
Zoltan Somogyi
91c4330db7 The first half of a change to introduce nondet pragma C goals.
Estimated hours taken: 12

The first half of a change to introduce nondet pragma C goals.
This half makes the necessary modifications to the HLDS; the next
half will modify the LLDS and emit it.

prog_data:
	Add a new pragma type for nondet pragma c_codes; these specify
	the names of a a bunch of variables to save across backtracking,
	and a list of label names to which backtracking may take place.

	Rename is_recursive to may_call_mercury, since this is a more
	direct expression of the meaning.

prog_io:
	Move much of the functionality to new files.

prog_io_dcg, prog_io_goal, prog_io_pragma, prog_io_util:
	New files, made up of pieces of prog_io.

hlds_goal:
	Add an extra argument to the pragma_c_goals to store the extra
	information present in the new type of pragma c_codes.

det_analysis:
	Take into account that the new type of pragma_c goal may have
	more than one solution.

goal_util:
	Rename variables in the new field of pragma_cs.

live_vars:
	Allocate stack slots to the saved variables in the new type of pragma_c
	goals.

make_hlds:
	Handle the new type of pragma_c goals.

mercury_output, hlds_out:
	Output the new type of pragma_c goals.

garbage_out:
	Rename type "det" to "frame_type".

others:
	Ignore one more arg of pragma_c goals or import prog_io_util.
1997-01-27 07:45:40 +00:00
Simon Taylor
bb2b816787 * Inter-module unused argument removal.
Estimated hours taken: 100

* Inter-module unused argument removal.

* Allow the user to specify which directories should be searched
for .opt files.

* Enhancements to simplify.m and common.m which will be useful for
partial deduction.

compiler/options.m
	Added and documented options:
	--intermod-unused-args to enable inter-module unused argument removal.
	--intermod-directory <dir>, same as --search-directory except used
		to locate .opt files.
	--use-search-directories-for-intermod - use the search directories
		for .opt files as well.
	--warn-simple-code - a flag to control the warnings produced by
		simplify.m so that they respect --inhibit-warnings.

compiler/unused_args.m
	Use the unused argument info from the .opt file.
	Clobber the dependency_info if any new preds were added.

compiler/hlds_module.m
	Added a field to the module_info to store unused argument
	information from .opt files.

compiler/prog_data.m
	Add :- pragma unused_args to hold unused argument information.
	This should only be used in .opt files.

compiler/make_hlds.m
	Build the unused_arg_info field in the module_info.
	Check that pragma unused_args only appears in .opt files.
	Fill in the non-locals field in the goal_info for the builtin
	stubs so that mode analysis computes the correct instmap delta.

compiler/intermod.m
	Read in the unused argument information for the current module when
	compiling to C. This is used to ensure that clauses are produced with
	the correct number of removed arguments (it may be possible to remove
	more arguments with the information from other modules).
	Fix a bug in the handling of module qualified function calls and
	higher-order predicate constants.

compiler/handle_options.m
	Handle --intermod-unused-args and
	--use-search-directories-for-intermod.

compiler/mercury_compile.m
	Run the entire front end and polymorphism (not just up to
	typechecking) when building the .opt file with
	--intermod-unused-args.
	Use the new interface to simplify.m, remove calls to excess.m
	and common.m.

compiler/code_util.m
compiler/llds_out.m
	When generating local code for a specialized version of a predicate
	from another module, put this module's name on the label to avoid
	link errors.

compiler/higher_order.m
	Don't add the originating module name to the name of the specialized
	version, since that is now done in code_util.m.
	Clobber the dependency graph so that inlining will work on the
	specialized versions in profiling grades (this will cause slightly
	slower compilation in profiling grades, something I need to fix).

compiler/simplify.m
	Merge a branching goal and an adjacent switch where the branches
	of the first goal contain extra information about the switched
	on variable of the second goal.
	Merge the excess assignments and common subexpression elimination
	passes into simplify.m.

compiler/excess.m
	The functionality of this module is now in simplify.m, but I'll
	leave it here for now.

compiler/instmap.m
	Added predicates instmap__bind_var_to_functor and
	instmap_delta_bind_var_functor to which take a var, cons_id
	and an instmap and adjust the inst of the var. This is used to
	update the instmap at the beginning of each case in a switch.
	Fix a bug in merge_instmap_delta where variables whose inst had
	information added in one branch of a switch, disj, or ite had that
	changed inst included in the instmap_delta for the entire
	branched goal.

compiler/mode_util.m
	Use instmap_delta_bind_var_to_functor in recompute_instmap_delta.
	Added predicate bind_inst_to_functor which takes a ground or bound
	inst and a cons_id and adjusts the top level of the inst to be bound
	to that cons_id. Other types of inst are left unchanged.
	Change recompute_instmap_delta so that the switched on variable of
	a switch is bound to the functor in each case even if the binding
	unification has been removed. Added a boolean argument to request
	recomputation of instmap_deltas for atomic goals.

compiler/modes.m
compiler/unique_modes.m
	Make sure that the instmap_delta for each branch of a switch
	includes the extra information added by the functor test.

compiler/common.m
	Removed the goal traversal. Leave preds to be called by simplify.m
	to optimise common unifications and calls.
	Warn about and eliminate multiple calls to a predicate with the same
	input arguments.
	Replace deconstructions of known terms with assignments to the output
	variables where this would not make more variables live at stack
	flushes.

compiler/follow_code.m
	Exported move_follow_code_select.
	Don't move follow code into erroneous branches.

library/string.nu.nl
	Added string__contains_char/2.

compiler/base_type_layout.m
compiler/special_pred.m
compiler/vn_order.m
library/mercury_builtin.m
	Removed duplicate calls.

doc/user_guide.texi
	Documented options.

tests/warnings/duplicate_call.m
tests/warnings/duplicate_call.exp
	Test duplicate call warning.
1997-01-20 03:27:59 +00:00
Fergus Henderson
2af7e75639 Fix a bug that Philip reported to Zoltan regarding
Estimated hours taken: 0.5

Fix a bug that Philip reported to Zoltan regarding
spurious determinism errors in lambda expressions.

compiler/switch_detection.m:
	When detecting switches in lambda expressions, we need to insert
	the initial insts for the lambda variables in the instmap
	before processing the lambda goal.
1996-12-10 13:14:12 +00:00
Zoltan Somogyi
ee24e66a71 Switch from using a stack of store_maps in the code_info to govern what
Estimated hours taken: 2.5

Switch from using a stack of store_maps in the code_info to govern what
goes where at the end of each branched structure to using the store map
fields of the goal expressions of those structures.

Fix variable names where they resembled the wrong kind of map(var, lval).

code_info:
	Remove the operations on stacks of store maps.
	Modify the generate_forced_saves and remake_with_store_map operations
	to take a store_map parameter.

	When making variables magically live, pick random unused variables
	to hold them, since we can no longer use the guidance of the top
	store map stack entry. This may lead to the generation of some
	excess move instructions at non-reachable points in the code;
	this will be fixed later.

code_gen:
	Remove the store map push and pop invocations.
	Modify the generate_forced_goal operation to take a store_map parameter.

code_exprn:
	Export a predicate for use by code_info.

middle_rec, disj_gen, ite_gen, switch_gen,
dense_switch, lookup_switch, string_switch, tag_switch:
	Pass the store map around to get it to invocations of the primitives
	in code_gen and code_info that now need it.

goal_util:
	Name apart the new follow_vars field in hlds__goal_infos.
	(This should have been in the change that introduced that field.)

common, constraint, cse_detection, det_analysis, dnf, excess, follow_code,
intermod, lambda, lco, liveness, make_hlds, mode_util, modes, polymorphism,
quantification, simplify, switch_detection, typecheck, unique_modes,
unused_args:
	Fix variable names.

follow_vars, store_alloc:
	Add comments.
1996-11-23 10:39:02 +00:00
Andrew Bromage
06e05928e1 Makes instmap and instmap_delta into ADTs.
Estimated hours taken: 38

Makes instmap and instmap_delta into ADTs.

compiler/code_gen.m:
compiler/code_info.m:
compiler/cse_detection.m:
compiler/det_analysis.m:
compiler/dnf.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_goal.m:
compiler/hlds_out.m:
compiler/hlds_pred.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/lookup_switch.m:
compiler/mode_debug.m:
compiler/mode_info.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/polymorphism.m:
compiler/simplify.m:
compiler/store_alloc.m:
compiler/switch_detection.m:
compiler/transform.m:
compiler/uniq_modes.m:
compiler/unused_args.m:
	Miscellaneous minor changes to use the new instmap.m

compiler/constraint.m:
	Removed unnecessary duplication of code in constraint__checkpoint/4
	and constraint__no_output_vars/2.

compiler/det_util.m:
	Changed no_output_vars/4 to det_no_output_vars/4, moved body
	of code to instmap.m.

compiler/instmap.m:
	Added abstract types instmap/0, instmap_delta/0.

	Added predicates:
		instmap__init_reachable/1, instmap__init_unreachable/1,
		instmap_delta_init_reachable/1,
		instmap_delta_init_unreachable/1, instmap__is_reachable/1,
		instmap__is_unreachable/1, instmap_delta_is_reachable/1,
		instmap_delta_is_unreachable/1, instmap__from_assoc_list/2,
		instmap_delta_from_assoc_list/2, instmap__vars/2,
		instmap__vars_list/2, instmap_delta_changed_vars/2,
		instmap_delta_lookup_var/3, instmap__set/3,
		instmap_delta_insert/4, instmap_delta_apply_instmap_delta/3,
		instmap_delta_restrict/3, instmap_delta_delete_vars/3,
		instmap__no_output_vars/4, instmap_delta_apply_sub/4,
		instmap__to_assoc_list/2, instmap_delta_to_assoc_list/2.

	Renamed predicates:
		instmap__lookup_var/3 (was instmap_lookup_var/3)
		instmap__lookup_vars/3 (was instmap_lookup_vars/3)
		instmap__apply_instmap_delta/3 (was apply_instmap_delta/3)
		instmap__merge/5 (was instmap_merge/5)
		instmap__restrict/3 (was instmap_restrict/3)

	Moved predicates:
		merge_instmap_delta/5 (from mode_util.m)

	Removed predicates:
		instmapping_lookup_var/3

compiler/mode_util.m:
	Moved merge_instmap_delta/5 to instmap.m
1996-11-19 01:18:24 +00:00
Zoltan Somogyi
0632ae69dd Fix a long-standing bug that caused all fixpoint iterations to stop
Estimated hours taken: 8

livemap:
	Fix a long-standing bug that caused all fixpoint iterations to stop
	too early. By causing value_numbering to miscompile the predicate
	mercury_compile__maybe_unused_args, this bug caused the unwanted
	printing of statistics for tests/warnings/unused_args_test.

	Fix also another bug: we did not process the control rval in
	computed gotos. To my knowledge this has never been tickled.

	Redesign the interface of the exported predicate slightly to
	make it more robust.

frameopt, value_number:
	Use the modified interface of livemap.

switch_detection:
	For a while now we have removed arms from switches if we knew from
	the instantiation of the control variable that those arms could not be
	executed. Sometimes this results in switches with no arms. If the
	control variable of the switch is never used after the switch,
	liveness won't see the occurrence in the switch construct as a use,
	and will kill the variable too early, cause the code generator to
	abort.

	We now turn switches with no arms into "fail"; this improves the
	code generated and avoids the bug. However, liveness should still
	be changed to consider the occurrence of a variable in the first
	arg of a switch a use.

code_gen, vn_block:
	Formatting changes.
1996-11-16 03:07:50 +00:00
Zoltan Somogyi
5d64b759db The main changes are
Estimated hours taken: 12

The main changes are

1	associating a name with the arguments of constructors

2	removing the follow_vars field from calls, higher-order calls
	and complicated unifications, since they are not used

3	merging the follow_vars and store_alloc passes, since they logically
	belong together

4	add a new module, lco, for detecting opportunities for last
	call optimization modulo constructor application; it won't
	actually apply the optimization until the mode system becomes
	expressive enough to handle it (this module detects 529 opportunities
	in the compiler and library)

5	make "-O3 --optimize-value-number" do the right thing; previously,
	it used not to apply value numbering because the vnrepeat option
	defaulted to zero

6	don't refer to .err2 files anymore; use .err instead.

prog_data:
	The list associated with each value of type "constructor" now
	contains not only the types of the arguments but their names as well.

equiv_type, hlds_data, hlds_out, make_hlds, mercury_to_{goedel,mercury},
mode_util, module_qual, shapes, type_util, unify_proc:
	Modify the traversal of type definitions to account for the names
	in the lists inside values of type "constructor".

prog_io:
	Parse argument names. An unrelated change is that we now
	check whether :- pred declarations give modes to some of their
	arguments but not to all, in which case we return an error.

hlds_goal:
	Remove the follow_vars field from calls, higher-order calls
	and complicated unifications.

*.m:
	Handle the new arities of calls, higher order calls and complicated
	unifications.

mercury_compile:
	Don't call follow_vars directly anymore, but do call lco if its option
	is set. Also flush the main output before a call to maybe_report_stats
	to prevent ugly output.

store_alloc:
	Call follow_vars directly.

follow_vars:
	Expose the initialization and traversal predicates for store_alloc.

lco:
	Find opportunities for last call optimization modulo constructor
	application.

passes_aux:
	Add a HLDS traversal type for lco.

optimize:
	Consider the vnrepeat count to be zero unless value numbering is on.

options:
	Set the default value of vnrepeat to 1.

modules:
	Don't refer to .err2 files.
1996-11-04 06:26:51 +00:00
Andrew Bromage
5c149e55b2 Mode analyser reorganisation.
Estimated hours taken: 20

Mode analyser reorganisation.

compiler/mode_util.m:
	Removed: instmap_init/1,  apply_instmap_delta/3, instmap_lookup_var/3,
	instmapping_lookup_var/3, instmap_restrict/3, map_restrict/3 (all
	moved to instmap.m).

compiler/hlds_goal.m:
	Removed the declarations of instmap_delta, instmap and instmapping.

compiler/mode_errors.m:
	Added report_mode_errors/2 (was modecheck_report_errors, from
	modes.m).

compiler/modes.m:
	Predicates now exported:
		modecheck_goal/4
		modecheck_goal_expr/5 (previously named modecheck_goal_2/5)
		handle_extra_goals/8
		mode_context_to_unify_context/3

	Moved to mode_errors.m:
		modecheck_report_errors/2

	Moved to instmap.m:
		compute_instmap_delta/4
		instmap_merge/3
		instmap_lookup_vars (was instmap_lookup_arg_list/3)
		compute_instmap_delta/4

	Moved to mode_debug.m:
		Type port/0
		mode_checkpoint/4

	Moved to modecheck_call.m:
		modecheck_call_pred/7
		modecheck_higher_order_call/10
		modecheck_higher_order_pred_call/4
		modecheck_higher_order_func_call/7

	Moved to modecheck_unify.m:
		modecheck_unification/9
		categorize_unify_var_var/12
		categorize_unify_var_functor/11
		categorize_unify_var_lambda/9

	Moved to mode_info.m:
		mode_info_error/4
		mode_info_add_error/3

compiler/code_gen.pp, compiler/code_info.m, compiler/constraint.m,
compiler/cse_detection.m, compiler/det_analysis.m, compiler/det_util.m,
compiler/dnf.m, compiler/goal_util.m, compiler/higher_order.m,
compiler/hlds_out.m, compiler/hlds_pred.m, compiler/live_vars.m,
compiler/liveness.m, compiler/lookup_switch.m, compiler/polymorphism.m,
compiler/simplify.m, compiler/store_alloc.m, compiler/switch_detection.m,
compiler/transform.m, compiler/unused_args.m:
	Imported instmap.m

New files:

compiler/instmap.m:
	Handle operations associated with instmaps.

compiler/modecheck_unify.m:
	Handle mode checking of unifications.

compiler/modecheck_call.m:
	Handle mode checking of calls

compiler/mode_debug.m:
        Code to trace the actions of the mode checker.
1996-10-17 05:28:01 +00:00
Zoltan Somogyi
8bd1aaa9de Rename address_const to code_addr_const, and add base_type_info_const
Estimated hours taken: 15

hlds_data:
	Rename address_const to code_addr_const, and add base_type_info_const
	as a new alternative in cons_id, and make corresponding changes
	to cons_tag.

	Make hlds_type__defn an abstract type.

llds:
	Rename address_const to code_addr_const, and add data_addr_const
	as a new alternative in rval_const.

	Change type "label" to have four alternatives, not three:
	local/2 (for internal labels),  c_local (local to a C module),
	local/1 (local a Mercury module but not necessarily to a C module,
	and exported.

llds_out:
	Keep track of the things declared previously, and don't declare them
	again unnecessarily. Associate indentation with the following item
	rather than the previous item (the influence of 244); this results
	in braces being put in different places than previously, but should be
	easier to maintain. Handle the new forms of addresses and labels.
	Refer to c_local labels as STATIC when not using --split-c-files.

code_info:
	Use a presently junk field to store a cell counter, which is used
	to allocate distinguishing numbers to create'd cells. Previously
	we used the label counter, which meant that label numbers changed
	when we optimized away some creates. Handle the new forms of
	addresses and labels.

exprn_aux:
	Handle the new forms of addresses and labels. We are now more
	precise in figuring out what label address forms will be considered
	constants by the C compilers.

others:
	Changes to handle the new forms of addresses and labels, and/or to
	access hlds_type__defn as an abstract type.
1996-08-05 12:05:14 +00:00
Fergus Henderson
0e1e0b0b91 Implement recursive' and non_recursive' pragma c_code declarations.
Estimated hours taken: 4

Implement `recursive' and `non_recursive' pragma c_code declarations.
This allows the compiler to optimize cases when the C code
is known to not call Mercury code.  It's also necessary
to allow C code which modifies the hp register to work
(such code must be declared `non_recursive', otherwise
the registers will be saved and restored over it).
To make things bootstrap OK, the old pragma c_code declarations
default to `non_recursive'.

prog_data.m, hlds_goal.m:
	Add new field c_is_recursive to pragma c_code goals.

prog_io.m:
	Parse the new `recursive' and `non_recursive' pragma c_code
	declarations.

make_hlds.m:
	Pass the c_is_recursive field from the parse tree to the HLDS.

live_vars.m:
	For non-recursive C code, don't save variables on the stack.

code_gen.pp:
	For non-recursive C code, don't save variables on the stack,
	don't mark the succip as needing to be saved, and don't
	call save_registers() and restore_registers().

*.m:
	Change c_code/5 to c_code/6.
1996-06-10 17:18:50 +00:00
Fergus Henderson
60b9fa83b6 Implement higher-order functions.
Estimated hours taken: 12

Implement higher-order functions.

Add higher-order function terms
(function lambda expressions, e.g. `Func = (func(X) = Y :- Y is 2 * X)'
and higher-order function calls (apply/N, e.g. `Z = apply(Func, 42)').
Add higher-order function insts and modes.

hlds_goal.m:
	Add a new field pred_or_func to lambda_goal.

prog_data.m:
	Add a new field pred_or_func to pred_inst_info.

prog_io.m:
	Add support for parsing higher-order function terms and
	higher-order function insts and modes.

make_hlds.m:
	Add support for parsing higher-order function terms.

typecheck.m:
	Add support for type-checking higher-order function calls
	and higher-order function terms.

modes.m, mode_errors.m:
	Add support for mode-checking higher-order function calls
	and higher-order function terms.

higher_order.m:
	Handle higher-order function types and insts.

hlds_pred.m:
	Add new predicate pred_args_to_func_args, for extracting the
	function arguments and function return from the arguments
	of a predicate that is really a function.

*.m:
	Minor changes to handle new pred_or_func field in lambda_goals
	and pred_inst_infos.
1996-05-14 10:07:46 +00:00
Zoltan Somogyi
99e729814f Make sure we don't change the goal being analyzed except possibly
Estimated hours taken: 20

det_analysis:
	Make sure we don't change the goal being analyzed except possibly
	for the introduction of `some's (which should not hurt anything).

	Make sure we don't print any error messages except in the final
	iteration, when all the inputs to the inference are stable.

	If the --debug-detism options is set, print messages about the
	progress of inference and checking.

	Also moved some code around.

det_report:
	Distinguish the handling of warning messages and error messages.

simplify:
	Use the new ability of det_report to separate warnings and errors.

passes_aux:
	Add a new generic pass form, for use by simplify.

option:
	Add --debug-detism (as above), --aditi, which at the moment
	only enables the disjunctive normal form transformation, and
	--inlining/--no-inlining, which set the other three flags
	involved in inlining depending on whether you want standard
	inlining or none at all.

	Follow_code used to be set twice and follow_vars not at all;
	I fixed this.

	Reenabled optimize_higher_order at -O3.

	Moved value numbering to -O4 and pred_value_number to -O5.
	This makes it easier to separate value numbering from the
	other optimizations (which are likely to be more effective).

	Divided options_help into sections to avoid excessive
	compilation times.

store_alloc:
	Base the store map on the follow_vars info attached to the
	branched structure which I added recently, and not on the
	follow_vars map being passed around, since it will be more accurate.

hlds_out:
	Print information about follow_vars and store_maps when -D is given.

follow_code:
	Undo an old hack that change to follow_vars has made counterproductive.

middle_rec:
	Fix a bug uncovered by the change to follow_code. When looking for a
	register to hold the counter, it is not enough to avoid picking a
	register that appears in the recursive case; we must also avoid
	registers that occur only in the base case.

livemap:
	Mentioning the code address succip now causes the succip to be
	considered live. This may or may not fix the bug with pred_value_number
	miscompiling unused_args.m; the other changes have caused the input
	to value numbering to change, and they no longer trigger the problem.
	(Will try to test this later.)

mercury_compile:
	Try to make sure that we print statistics only after passes that
	were actually executed. Also, reduce the number of lookups of the
	verbose option. Move some predicates so that the order of their
	appearance matches the current order of invocation.

vn_table:
	Loosen a sanity check to let xnuc2 pass through it.

code_exprn, switch_detection:
	Minor changes.
1996-05-10 09:49:17 +00:00
Fergus Henderson
9a7da88ce0 Treat higher-order predicate calls as a new sort of goal,
Estimated hours taken: 24

Treat higher-order predicate calls as a new sort of goal,
rather than as calls to the special predicate call/N, in order to
remove the fixed limit on the number of arguments and on the modes
for call/N.

Also, remove the restriction on output arguments preceding input arguments
in lambda expressions.

hlds_goal.m:
	Add new functor higher_order_call/6 to the hlds__goal type.

*.m:
	Handle new functor higher_order_call/6.

arg_info.m:
	Abstract things a bit more: the argument passing convention
	for a procedure may be affected by that procedure's types,
	modes, and code_model, as well as the arg_method.

follow_vars.m:
	Pass down the args_method, since it is now needed for figuring
	out the arg_info for unifications and higher-order calls.

follow_code.m:
	Treat complicated unifications in the same way as calls.

lambda.m:
	When creating lambda predicates, permute the arguments so
	that all input arguments come before all output arguments.

call_gen.m:
	When generating higher-order predicate calls, don't abort
	if outputs precede inputs; instead, generate code assuming
	that the called predicate's args have been permuted so that
	the inputs to come before all the outputs.
1996-05-02 22:44:50 +00:00
Zoltan Somogyi
e04067b552 A large step in cleaning up the determinism system.
Estimated hours taken: 8

A large step in cleaning up the determinism system.

simplify:
	Determinism analysis should not modify the code of the procedures it
	checks, yet we need to massage some goals to make them acceptable to
	the code generator. The obvious solution is to perform this massaging
	after analysis is finished. This is what this new module does.

det_util:
	New module to hold types and predicates used in more than one module
	involved with the determinism system. Some types and/or predicates
	used to be in switch_detection, det_analysis, det_report, but the
	misc_info type has been expanded and renamed det_info.

det_analysis:
	Don't modify the goal being analyzed except to insert "some" goals.
	This is important because the relevant part of det_analysis knows
	only the current inferred determinism of the goal, not its final
	determinism. The modification code is now in simplify (after some
	fixes).

	Import det_util. Move some utility preds to det_util.
	Export more of the determinism tables; some are needed in simplify.

det_report:
	Import det_util. Move some utility preds to det_util.
	Add some more warning messages.

cse_detection:
	Import det_util.

switch_detection:
	Import det_util. Move some utility preds to det_util.

passes_aux:
	Defined a predicate for traversing the HLDS hierarchy for processing
	all the non-imported procedures.

	Defined write_proc_progress_message to complement
	write_progress_message (which has been renamed
	write_pred_progress_message).

dead_proc_elim, modes, typecheck, unique_modes:
	Use write_{proc/pred}_progress_message as appropriate.

hlds_out:
	Add a new predicate hlds_out__write_pred_proc_id.

hlds_module:
	Improve an abort message.

llds_out:
	Formatting changes.

mercury_compile:
	Call simplify__proc through the new traversal predicate in passes_aux.
1996-04-28 07:25:49 +00:00
Zoltan Somogyi
649b6908c3 Rename branch_delay_slot to have_delay_slot.
Estimated hours taken: 8

options.m:
	Rename branch_delay_slot to have_delay_slot.
	Set optimize_delay_slot in -O2 only if have_delay_slot was set earlier.
	This is possible now because the default optimization level is now
	set in mc.

mercury_compile:
	Change verbose output a bit to be more consistent.

dead_proc_elim:
	Export the predicates that will eventually be needed by inlining.m.

inlining.m:
	Use the information about the number of times each procedure is called
	to inline local nonrecursive procedures that are called exactly once.
	EXCEPT that this is turned off at the moment, since the inlining of
	parse_dcg_goal_2 in prog_io, which this change enables, causes the
	compiler to emit incorrect code.

prog_io:
	Moved the data type definitions to prog_data. (Even though prog_io.m
	is ten times the size of prog_data.m, the sizes of the .c files are
	not too dissimilar.)
1996-04-24 01:00:23 +00:00
Zoltan Somogyi
d344165793 Add a new option, --branch-delay-slot, intended for use by mc on
Estimated hours taken: 3

options:
	Add a new option, --branch-delay-slot, intended for use by mc on
	the basis of the configuattion script. It says whether the machine
	architecture has delays slots on branches.

	The setting of option should affect whether we set
	--optimize-delay-slots at -O2, but this doesn't work yet.

hlds_goal:
	Add an extra field to hold follow_vars infromation to disjunctions,
	switches and if-then-elses. I intend to use this information to
	generate better code.

*.m:
	Changes to accommodate the extra field.
1996-04-20 08:37:36 +00:00
Zoltan Somogyi
faf96105bb Replace the word_size option with the two options bits_per_word and
Estimated hours taken: 16

options:
	Replace the word_size option with the two options bits_per_word and
	bytes_per_word. The former is needed by lookup_switch, the latter by
	value numbering.

lookup_switch:
	Use the new option instead of word_size.

vn_type, vn_cost, vn_block, value_number:
	Add a new type, vn_params, containing information such as the number
	of bytes per word (from the option) and cost parameters. Use these
	cost parameters to make more realistic decisions.

vn_filter:
	New module to filter out unnecessary uses of temporary variables,
	which gcc does unnecessarily badly on.

value_number, vn_verify:
	Move verification completely to vn_verify. Tighten the verification
	rules relating to tags where it concerns code sequences in which
	the tag of an rval is taken in a statement before an if_val, but
	loosen them to avoid spurious rejections of code sequences containing
	arithmetic comparisons. Fix some missing cases from semidet switches
	that may have lead to overly conservative decisions.

value_number, vn_order:
	Vn_order was making an overly conservative assumption about where
	to split an extended basic block if it couldn't be optimized together.
	Move the decision to value_number and try to make it better. The new
	heuristic is not enabled yet.

vn_debug:
	Change the conditions under which one type of message is printed.

vn_flush:
	Wrap some too long lines.

llds:
	Fix a bug that would prevent profiling from working correctly on
	value numbered code: we weren't scanning instructions inside blocks
	when looking for return addresses.

peephole:
	Enable an optimization previously left disabled by accident.

switch_detection, tag_switch:
	Eliminate an unused argument.
1996-04-16 06:03:45 +00:00
Fergus Henderson
3f56a2b75a Add `import_module int', for '<'/2.
Estimated hours taken: 0.1

compiler/switch_detection.m:
	Add `import_module int', for '<'/2.
1996-04-12 23:24:50 +00:00
Zoltan Somogyi
2833bfffb7 Divided the old hlds.m into four files:
Estimated hours taken: 10

hlds, hlds_module, hlds_pred, hlds_goal, hlds_data:
	Divided the old hlds.m into four files:

	hlds_module.m defines the data structures that deal with issues
	that are wider than a single predicate. These data structures are
	the module_info structure, dependency_info, the predicate table
	and the shape table.

	hlds_pred.m defined pred_info and proc_info, pred_id and proc_id.

	hlds_goal.m defines hlds__goal, hlds__goal_{expr,info}, and the
	other parts of goal structures.

	hlsd_data.m defines the HLDS types that deal with issues related
	to data and its representation: function symbols, types, insts, modes.
	It also defines the types related to determinism.

	hlds.m is now an empty module. I have not removed it from CVS
	because we may need the name hlds.m again, and CVS does not like
	the reuse of a name once removed.

other modules:
	Import the necessary part of hlds.

det_analysis:
	Define a type that was up to now improperly defined in hlds.m.

prog_io:
	Move the definition of type determinism to hlds_data. This decision
	may need to be revisited when prog_io is broken up.

dnf, lambda:
	Simplify the task of defining predicates.

llds:
	Fix some comments.

mercury_compile:
	If the option -d all is given, dump all HLDS stages.

shape, unused_args:
	Fix formatting.
1996-04-02 12:12:24 +00:00
Zoltan Somogyi
3e4a019dcc Fix the pass structure, and start using a loose sequence of stage
Estimated hours taken: 8

mercury_compile:
	Fix the pass structure, and start using a loose sequence of stage
	numbers, to make it easier to add new stages without having to fiddle
	stage numbers.

	THIS DOES MEAN THAT ALL STAGE NUMBERS HAVE CHANGED NOW.

	The stage number assignment scheme assigns 1 to 25 to the front end,
	26 to 50 to the middle passes, and 51 to 99 to the back end.

hlds:
	We had two types that combined a pred_id and a proc_id. One,
	pred_proc_id, used a simple pair; the other, procedure_id, had a better
	definition using a specific function symbol but was not used
	anywhere else. I standardized on the name pred_proc_id, but using the
	definition with a dedicated function symbol (proc).

	I also defined a type pred_proc_list as a list of pred_proc_id.

	To prepare for memoing, I added a new field to pred_info, which is
	a list of markers, each requesting a specific transformation on the
	predicate or indicating that the transformation has been done.
	The inline request is now represented using such a marker. However,
	the interface is backwards compatible.

constraint, dead_proc_elim, dependency_graph, det_analysis, det_report,
higher_order, unused_args:
	Changes to conform to the new definition of pred_proc_id.
	In two places removed definitions of predproclist, whose
	equivalent pred_proc_list is now defined in hlds.m.

hlds_out, make_hlds, mercury_to_mercury, prog_io:
	Add code to handle memo pragma declarations, using whenever possible
	a version of the existing code for handling inline requests, but
	generalized for handling any pragma that sets a marker.

switch_detection:
	Rename the type cases_list to sorted_cases_list. This avoids a
	name clash that creates a duplicate label and therefore screws up
	the profiler, and is a better name anyway.

options:
	Add a new option, --opt-space, that turns on optimizations that save
	space and turns off optimizations that squander space.

handle_options:
	Pass the special option handler to getopt.

frameopt:
	For each labelled code sequence that tears down the stack frame but
	does not use it, we used to create a parallel code sequence that omits
	the teardown code, for use by gotos from locations that did not have
	a stack frame. However, peepholing may discover that it is better
	not to tear down the stack frame at the site of the goto after all,
	so we need the original code sequence as well.

	The current change fixes a bug that occurs if the original code
	sequence is modified by another part of frameopt to omit teardown
	code. In such cases, which are produced by --pred-value-number,
	peepholing redirects a goto to a code sequence that it thinks tears
	down the stack frame, but actually doesn't.

	With this change, --pred-value-number now works.

llds:
	Fix typos in a comment.
1996-03-24 06:39:33 +00:00
Fergus Henderson
bd2093d8b4 Fixes for two bugs in mode analysis, and
Estimated hours taken: 12

Fixes for two bugs in mode analysis, and
a first cut at support for `any' insts.
(The support for `any' is very preliminary,
has had only the most minimal of testing, and
doubtless has some bugs.)

inst_match.m mercury_to_mercury.m mode_util.m modes.m undef_modes.m
unique_modes.m prog_io.m:
	Add new type of inst `any(uniqueness)' to prog_io.m, and
	change inst_match.m, mode_util.m, and other places to handle
	handle `any' insts.

inst_match.m:
	Fix bug in inst_merge: when merging `unique(f(ground)) and `unique',
	the result should be `ground', not `unique', since part of the
	data structure may be shared.  (This fix required adding several
	new predicates: `merge_uniq_bound' etc.)

inst_match.m mercury_to_mercury.m mode_util.m modes.m polymorphism.m
prog_io.m switch_detection.m unique_modes.m:
	Fix a design bug: in a `bound' inst, the list of bound_insts
	must be sorted on the name+arity, not on the name+arg_insts.
	To achieve this, I changed the type of the first argument of
	functor/2 in the type bound_inst from `const' (just name) to
	`cons_id' (name+arity).
1996-03-09 16:04:29 +00:00
Zoltan Somogyi
ffaff45236 A new pass to eliminate any procedures not reachable from the
Estimated hours taken: 7

dead_proc_elim:
	A new pass to eliminate any procedures not reachable from the
	exported modes of the exported predicates, either via calls or
	by being mentioned in a higher order construct. Useful after
	inlining and specialization passes have created orphan procedures.

options:
	Added new option for enabling dead procedure elimination.

mercury_compile:
	Call dead procedure elimination if its option is set.
	This change displaces dump numbers after 13.
	Also cleaned up the format of some of the verbose messages,
	and removed some old, commented out code that isn't useful anymore.
	Further work on the pass structure is required.

unused_args:
	Cleaned up the format of some of the verbose messages,

hlds_out:
	Print out the pred_id and status of each predicate; useful in looking
	at what dead_proc_elim is doing.

hlds:
	Added a predicate to return the exported procs of a pred.
	Removed the randomization of pred_id's, which hasn't been required
	for along time.
	Exported the type pred_id for use by hlds_out. (This last may be
	a temporary change.)

llds:
	Make the extern declarations to the various bunch functions into
	ANSI prototypes.

det_analysis:
	Changes to make the cc component of at_most_many_cc "sticky" in the
	various tables, i.e. if a goal is in a one solution context, any
	conjunction, disjunction or switch containing it is also in a one
	solution context. This need not propagate beyond quantification.

switch_detection:
	Undid the unnecessary export of a predicate.
	Updated a comment.
1996-02-25 08:40:13 +00:00
Fergus Henderson
befa3da8e1 Fix bugs which lead to the wrong unification being hoisted
Estimated hours taken: 3

compiler/{cse,switch}_detection.m:
	Fix bugs which lead to the wrong unification being hoisted
	(cse_detection.m) or the wrong unification being marked
	as never-failing (switch_detection.m).  Make sure the difficult
	cases are rejected as determinism errors rather than causing
	incorrect code to be generated.
1996-02-08 18:28:38 +00:00
Fergus Henderson
6d7f4b9b30 Undo dylan's changes in the names of some library entities,
Estimated hours taken: 1.5

Undo dylan's changes in the names of some library entities,
by applying the following sed script

	s/term_atom/term__atom/g
	s/term_string/term__string/g
	s/term_integer/term__integer/g
	s/term_float/term__float/g
	s/term_context/term__context/g
	s/term_functor/term__functor/g
	s/term_variable/term__variable/g
	s/_term__/_term_/g
	s/std_util__bool_/bool__/g

to all the `.m' and `.pp' files in the compiler and library directories.
The reason for undoing these changes was to minimize incompatibilities
with 0.4 (and besides, the changes were not a really good idea in the first
place).

I also moved `bool' to a separate module.
The main reason for that change is to ensure that the `__' prefix is
only used when it genuinely represents a module qualifier.
(That's what dylan's changes were trying to acheive, but `term__'
does genuinely represent a module qualifier.)

compiler/*.m:
	Apply sed script above;
	where appropriate, add `bool' to the list of imported modules.
1996-02-03 17:30:14 +00:00
Fergus Henderson
c66a0cd903 More changes to finally fix the compiler so that it handles
Estimated hours taken: 4

More changes to finally fix the compiler so that it handles
Simon Taylor's nasty test case correctly.

Change unique_modes.m to invoke modecheck_unify_procs in unify_procs.m,
in case unique_modes.m adds new unify_requests for unification predicates
with `mostly_unique' modes.

switch_detection.m, cse_detection.m, det_analysis, unique_modes:
	Export new predicates to process a single procedure at a time.

cse_detection.m:
	Rearrange things so that it only redoes mode checking and switch
	detection for the single procedure, not for a every mode of a predicate,
	by calling `modecheck_proc' and `detect_switches_in_proc'.

hlds.m:
	Add new field `can_process' to the proc_info.

modes.m, unique_modes.m:
	Don't modecheck a procedure if its can_process field = no.

unify_proc.m:
	Set the can_process field to `no' when adding unify procs after
	a call to unify_proc__request_unify, and then back to yes again
	when we are ready to process them in modecheck_unify_procs.
	Add a new parameter to modecheck_unify_procs which specifies
	whether we need to do ordinary mode checking or unique mode
	checking.  If we need to do unique mode checking, then after
	doing ordinary mode checking, invoke `detect_switches_in_proc',
	`cse_detect_in_proc', `determinism_check_proc', and
	`unique_modes__check_proc' on the procedure.

unique_modes.m:
	After checking ordinary predicates, invoke modecheck_unify_procs.
	Add very_verbose progress messages.
1996-01-22 05:07:39 +00:00
Fergus Henderson
729c0a941c Rearrange the ordering of the different phases in the compiler.
Estimated hours taken: 6

Rearrange the ordering of the different phases in the compiler.

Moved lambda elimination (lambda.m) after unique_modes.m,
because mode analysis must have been fully completed before lambda
elimination, so that we get the right mode on the introduced
predicates.  Also moved inlining.m and common.m after unique modes,
since they are optimization passes, not semantic checking passes.

The cse_detection.m, switch_detection.m, and determinism.m passes now
need to recursively traverse lambda goals.  (Previously they assumed
that lambda goals had already been eliminated.)

mercury_compile.pp:
	Move the inlining.m and common.m passes from semantic_phases
	to middle_phases.

polymorphism.m:
	Remove the code which called lambda.m.

switch_detection.m:
	Recursively traverse lambda goals.

cse_detection.m:
	Recursively traverse lambda goals.
	Also, when redoing mode analysis and switch detection,
	we shouldn't reinvoke lambda.m.

det_analysis.m, det_report.m:
	Recursively traverse lambda goals, check for determinism
	errors in them, and report them.
	Also, print the calling predicate name & mode in the error
	message for calls to predicates with cc_* determinism in
	all-solutions contexts.

modes.m:
	Add an extra argument to modecheck_unification that specifies
	how we should recursively process lambda goals, so that we
	can do the right thing when called from unique_modes.m.
	The right thing in this case is to call unique_modes__check_goal
	instead of modecheck_goal, and to then invoke lambda__transform_lambda
	on the result.

unique_modes.m:
	Make sure we don't clobber the predicate table, since we now
	indirectly call lambda__transform_lambda, which inserts new
	predicates into the table.
	Also, simplify the code a little and add a sanity check.

lambda.m:
	Make some changes that were needed because lambda.m now comes
	directly after (unique_)modes.m not after polymorphism.m.
1996-01-19 06:02:08 +00:00
Dylan Shuttleworth
3ab8d92226 Change names with badly placed double underscores (ie where the part of
Estimated hours taken: _2___

Change names with badly placed double underscores (ie where the part of
a name before a double underscore is not the same as the module name.)

Reflect changes in the library interface.

compiler/*:
	Use the newer, more correct form of the term and bool names.
	Predicates "bool__" are now "std_util__bool" and labels of
	the term ADT are now "term_" instead of "term__".

compiler/vn*.m:
	change all names "vn__*" to a correct module prefix.  All the
	names remain qualified.

compiler/hlds.m:
	s/\<is_builtin__/hlds__is_builtin_/g
	s/\<dependency_info__/hlds__dependency_info_/g

compiler/unify_proc.m:
	s/\<unify_proc_info__/unify_proc__info_/g

compiler/transform.m:
	s/\<reschedule__conj/transform__reschedule_conj/g
1995-12-29 03:45:20 +00:00
Fergus Henderson
0be8c51b22 When creating switch statements, check the inst of the variable.
Estimated hours taken: 2

compiler/switch_detection.m:
	When creating switch statements, check the inst of the variable.
	If it is known to be bound to a particular set of functors,
	then delete unreachable cases, and then use those set of
	functors to check against, rather than checking against all the
	possible for functors for the type, to determine whether
	or not the switch covers all possible cases.
1995-12-28 03:30:56 +00:00
Zoltan Somogyi
3224e94532 A new pass to remove unnecessary assignment unifications.
excess:
	A new pass to remove unnecessary assignment unifications.

mercury_compile:
	Call the new excess assignment module.

options:
	Add a new option, excess_assign, to control the new optimization.
	Add another, num-real-regs, to specify how many of r1, r2 etc are
	actually real registers. The default is now set to 5 for kryten;
	later it should be supplied by the mc script, with a value determined
	at configuration time.

tag_switch:
	Use num-real-regs to figure out whether it is likely to be worthwhile
	to eliminate the common subexpression of taking the primary tag of
	a variable. Also fix an old performance bug: the test for when a
	jump table is worthwhile was reversed.

value_number, vn_block:
	Do value numbering on extended basic blocks, not basic blocks.

vn_debug:
	Modify an information message.

labelopt:
	Clean up an export an internal predicate for value numbering. Replace
	bintree_set with set.

middle_rec:
	Prepare for the generalization of middle recursion optimization
	to include predicates with an if-then-else structure.

cse_detection:
	Fix a bug: when hoisting a common desconstruction X = f(Yi), create
	new variables for the Yi. This avoids problems with any of the Yis
	appearing in other branches of the code.

goal_util:
	Add a new predicate for use by cse_detection.

common:
	Fix a bug: recompute instmap deltas, since they may be affected by the
	optimization of common structures.

code_info:
	Make an error message more explicit.

det_analysis:
	Restrict import list to the needed modules.

*.m:
	Import assoc_list.
1995-10-27 09:39:28 +00:00
David Jeffery
f75693e80a The C interface.
The changes made allow declarations of the form:

:- pragma(c_code, predname(Varname1::mode1, Varname2::mode2, ...),
	"Some C code to execute instead of a mercury clause;").

There are still a couple of minor problems to be fixed in the near future:
If there is a regular clause given as well as a pragma(c_code, ...) dec, it
is not handled well, and variables names '_' are not handled well.

prog_io.m:
	parse the pragma(c_code, ...) dec.
hlds.m:
	define a new hlds__goal_expr 'pragma_c_code'.
make_hlds.m:
	insert the pragma(c_code, ...) dec. as a pragma_c_code into the hlds.
det_analysis.m:
	infer that pragma_c_code goals are det.
modes.m:
	convince the mode checker that the correct pragma variables are bound
	etc.
quantification.m:
	quantify the variables in the pragma(c_code, ...) dec.
code_gen.pp:
	convert pragma_c_code into pragma_c (in the llds).
llds.m:
	define a new instr, pragma_c. Output the pragma_c
hlds_out.m:
mercury_to_mercury.m:
mercury_to_goedel.m:
	spit out pragma(c_code, ...) decs properly

*.m: 	handle the new pragma_c_code in the hlds or the new pragma_c in the llds
1995-10-17 11:13:13 +00:00
Fergus Henderson
760b99015c Another big batch of changes for higher-order predicates.
This set of changes includes most of the work necessary for
mode and determinism checking of higher-order predicates.

prog_io.m:
	Change the syntax for lambda expressions: they need
	to have a determinism declaration.  Lambda
	expressions must now look like this:

		lambda([X::in, Y::out] is det, ...goal...).
				       ^^^^^^

	Note that both the modes and the determinism are mandatory,
	not optional.

hlds.m:
	Insert a determinism field in the lambda_goal structure.

hlds_out.m, inlining.m, make_hlds.m, modes.m, polymorphism.m, quantification.m,
switch_detection.m, typecheck.m:
	Modified to use lambda_goal/4 rather than lambda_goal/3.

prog_io.m:
	Add a new field to the `ground' inst, of type `maybe(pred_inst_info)'.
	We use this to store the modes and determinism of higher-order
	predicate terms.

code_info.m, inst_match.m, mercury_to_mercury.m, mode_util.m, modes.m,
polymorphism.m, shapes.m, undef_modes.m:
	Modified to handle higher-order pred modes:
	use ground/2 rather than ground/1.
	(Note that modes.m still requires a bit more work on this.)

llds.m:
	Add a new field to the call_closure/3 instruction to hold the
	caller address for use with profiling, since the C macros
	require a caller address.

dup_elim.m, frame_opt.m, garbage_out.m, live_map.m, middle_rec.m, opt_debug.m,
opt_util.m, value_number.m, vn_*.m:
	Modified to use call_closure/4 rather than call_closure/3.

mercury_to_mercury.m:
	Export mercury_output_det for use by hlds_out.m.
1995-08-26 20:04:46 +00:00
Fergus Henderson
160a32038a More work on lambda expressions.
hlds.m:
	Insert new `list(mode)' field in the lambda_goal/2 structure.

hlds_out.m, inlining.m, quantification.m, switch_detection.m,
	Use lambda_goal/3 instead of lambda_goal/2.

parser.m, make_hlds.m, typecheck.m, modes.m:
	Parse, typecheck, and modecheck lambda expressions.

mercury_to_mercury.m:
	Export mercury_output_mode/4 for use by hlds_out.m.
1995-08-20 18:17:36 +00:00