Commit Graph

37 Commits

Author SHA1 Message Date
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
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
Fergus Henderson
97a24d95a4 Fix another bug in the handling of `any' insts.
Estimated hours taken: 1

Fix another bug in the handling of `any' insts.

cse_detection.m:
	Hoist common sub-expressions that involve `any' insts, not
	just those that involve ground insts.  (We still can't hoist them
	if they involve `free' insts, since that would create aliasing
	which the current mode system can't handle.)
1996-07-18 16:11:05 +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
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
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
Fergus Henderson
db1113562b Import `int' for '<'/2.
Estimated hours taken: 0.1

compiler/cse_detection.m:
	Import `int' for '<'/2.
1996-04-15 07:48:22 +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
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
48c6589b6e Fix a bug which caused the compiler to miscompile
Estimated hours taken: 8

Fix a bug which caused the compiler to miscompile
value_number__substitute_access_vns.

compiler/cse_detection.m:
	In find_bind_var_for_cse, ensure that if the variable which
	we are trying to hoist is bound to a different functor than
	the one we're searching for, then we stop searching for
	a match.  This is necessary, because the code that checks
	for a match assumes that the variable we're trying to hoist
	has not yet been bound.
1996-02-07 06:00:26 +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
0669cdd93a Fix design error which led to the bug reported by Philip Dart:
Estimated hours taken: 15
	(Debugging 3 people * 3 hours, design 2 hours, coding 4 hours.)

Fix design error which led to the bug reported by Philip Dart:
cse_detection was reinvoking mode analysis, which converted
higher-order pred terms into lambda expressions, but was
not reinvoking polymorphism.m, and so they remained as
lambda expressions, which caused the code generator to generate
incorrect code.

compiler/polymorphism.m:
	Move the stuff for handling lambda expressions into
	a new file lambda.m.

compiler/lambda.m:
	New file.  Contains the lambda expression handling
	stuff from polymorphism.m, plus new code to traverse
	the HLDS for a predicate applying this transformation
	to each lambda expression in the procedure bodies
	for that predicate.

compiler/cse_detection.m:
	After re-running mode analysis, invoke lambda__process_pred
	to transform away lambda expressions.
1995-11-04 15:38:59 +00:00
Zoltan Somogyi
9f824bc268 Rename a function symbol.
Estimated hours taken: 0.1

compiler/cse_detection.m:
	Rename a function symbol.

compiler/middle_rec.m:
	Fix earlier overhast commit.

compiler/options.m:
	Change help message for --num-real-regs.
1995-10-28 09:43:30 +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
Fergus Henderson
97946d39be This commit included two groups of changes:
1. A bug fix and a new warning for quantification

	quantification.m:
		Fix bug in renaming apart of lambda goals: it used to
		sort the lambda variables.  Improve efficiency slightly.
		Add some comments for quantification__rename_apart.
		Use more informative variable names in a couple of places.

	quantification.m, make_hlds.m, mercury_to_mercury.pp, options.m:
		Add code to quantification.m to detect variables with
		overlapping scopes, and pass back a list of warnings.
		Add code to make_hlds.m to print out the warnings, if
		the new option warn_overlapping_scopes was enabled (as
		it is by default).  Add code to options.m and
		mercury_to_mercury.pp to handle the new warning
		option.

	common.m, cse_detection.m, follow_code.m, unify_proc.m,
		Add an extra argument `_Warnings' to calls to
		`implicitly_quantify_clause_body', as required by the
		above change.

	goal_util.m:
		Export the predicate goal_util__rename_var_list for use by
		quantification.m.

2. A (very incomplete) start to a new backend which will generate
high-level, debuggable C code.

	options.m:
		Add new option --high-level-C.

	mercury_to_mercury.pp:
		Handle new option.

	mercury_to_c.m:
		New file.

	llds.m, hlds_out.m:
		Export predicates for use by mercury_to_c.m.
1995-10-26 13:06:45 +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
Thomas Conway
6248b4b93b Make implicit quantification rename apart vars that
quantification.m:
	Make implicit quantification rename apart vars that
	are local to distinct scopes. This will help in the
	singleton variable warning pass once the latter has
	been changed to work on the HLDS.

	These changes also allow goals of the form:
		.... X ....,
		some [X] Goal
	which were previously not allowed.

cse_detection.m:
	A 1 line bugfix from Zoltan.

det_analysis.m:
	Rather than redoing quantification, construct
	a correct goal_info directly in det__disj_to_ite/3.

optimize.pp:
	Fix a singleton variable. Zoltan, there is an
	XXX for you to read and remove if the fix is
	correct.

common.m, cse_detection.m, det_analysis.m,
follow_code.m, make_hlds.m, polymorphism.m,
unify_proc.m:
	Fix the calls to implicitly_quantify_clause_body and
	implicity_quantify_goal.

TODO:
	Update a couple of things.

parser.m:
	Add a map(string, var) to the state so that varset
	can be simplified.

varset.m:
	Simplfy the varset structure so that the binding
	of names to variables is cheaper.
1995-09-01 07:56:00 +00:00
Fergus Henderson
b87de68334 Implement unique modes. We do not handle local aliasing yet, so this
-------------------------------------------------------

Implement unique modes.  We do not handle local aliasing yet, so this
is still not very useful, except for io__state.  Destructive update is
not yet implemented.  Also note that this really only implements
"mostly unique" variables that may be non-unique on backtracking - we
don't check that you don't backtrack over I/O, for example.

prog_io.m, mode_util.m, modes.m, inst_match.m:
	Major changes to Handle unique modes.

mercury_to_mercury.m, polymorphism.m, prog_out.m, undef_modes.m:
	Use `ground(Uniqueness)' rather than just `ground'.

compiler/*.m:
	Fix compile errors now that unique modes are enforced: add a
	few calls to copy/2, and comment out lots of unique mode
	declarations that caused problems.

typecheck.m, mode_info.m:
	Hack around the use of unique modes, which doesn't work
	because we don't allow local aliasing yet: make the insts
	`uniq_type_info' and `uniq_mode_info' not unique at all,
	and add a call to copy/2 when extracting the io_state from
	type_info or mode_info.

-------------------------------------------------------

Plus a couple of unrelated changes:

hlds.m:
	Change the modes for the special predicates from `ground -> ground'
	to `in', so that any error messages that show those modes
	come out looking nicer.

	Add a new shared_inst_table for shared versions of user-defined
	insts.

mercury_to_goedel.m:
	Use string__is_alnum_or_underscore.
1995-08-02 07:53:53 +00:00
Fergus Henderson
0bbf5def61 Fix obscure "map_lookup failed" bug triggered by a partially
modes.m, unify_proc.m:
	Fix obscure "map_lookup failed" bug triggered by a partially
	instantiated mode of a complicated unification predicate, whose
	procedure body contained a call the the same complicated
	unification predicate in a different partially instantiated
	mode.

constraint.m, cse_detection.m:
	Change calls to modecheck to match new simplified interface.
1995-08-01 13:16:45 +00:00
Zoltan Somogyi
b905b2f4d8 Added an extra argument to call, which contains a maybe of the unification
context of the unification from which call was made. We we use this to generate
significantly better error messages. (There should be no more messages of the
form "call to __Unify__(blah blah blah) can fail".) Most of the files are
changed just to reflect this.

An unrelated change in det_analysis is that we now ensure the absence of
cycles by modifying the new inferred determinism in the light of the old
one, ensuring that any changes are monotonic.

In hlds_out, inhibit the printing of pseudo-imported predicates (unifications)
since nobody cares about them except sometimes Fergus.
1995-07-31 08:35:41 +00:00
Zoltan Somogyi
109d17e10b Removed the notion of "internal determinism"; commits are now indicated
hlds:
	Removed the notion of "internal determinism"; commits are now indicated
	through "some" goals. Renamed the predicate module_info_shapes to
	module_info_get_shapes. Will later change other predicates also to
	get consistent naming.

hlds_out:
	Removed printing of internal determinisms.

det_analysis:
	Changes to accommodate the new way of signalling commits. The comments
	on optimizations have been modified to reflect the need for information
	about whether goals can raise exceptions. Exported two predicates for
	use by follow_code.

live_vars:
	Changes to accommodate the new way of signalling commits.

code_gen:
	Shift the handling of commits to "some" goals. Some predicates
	had three versions, one for each code model; these have been
	simplified significantly. The sequence of predicates has also
	been rationalised a bit. There is still room for improvement
	on both fronts.

disj_gen, ite_gen, middle_rec:
	Changed calls to modified predicates in code_gen.

common:
	When this pass changes A == f(B, C), D := f(B, C) into A == f(B, C),
	D := A, it can change the scopes of A, B and C. The pass did not
	take this into account; now it does. The pass is still disabled
	until it has been more adequately tested.

mercury_compile:
	Moved followcode into the back end. We now thread ModuleInfo through
	the backend instead of Shapes, since follow_code modifies other parts
	of ModuleInfo as well. Rationalised the stage numbers, WHICH MEANS
	-d NUMBERS HAVE CHANGED.

follow_code:
	Follow_code is now after determinism analysis, so that we can check
	that it does not change the determinism of the branched structure
	we are pushing code into. We now push not just builtins but also the
	first call after the branched structure into the branched structure,
	since this will reduce register shuffling. Made a start on pushing code
	into the fronts of branched structures, when some code before the branch
	point is useful only in one branch.

options:
	Added an option prev_code for the (incomplete) functionality in
	follow_code.

vn_flush:
	Moved a comment about future functionality to where it now belongs.

cse_detection:
	Removed obsolete debugging predicate.
1995-07-27 02:00:19 +00:00
Fergus Henderson
36878440a1 This batch of changes implements complicated modes of complicated
unifications.  See the comments at the top of unify_proc.m for
details of how it's done.

hlds.m:
	Add new export statuses `pseudo_imported' and `pseudo_exported'
	to handle unification predicates, which can now have complicated
	modes.

code_gen.pp, code_info.m, common.m, constraint.m, cse_detection.m,
follow_code.m, follow_vars.m, hlds_out.m, inlining.m, live_vars,
make_hlds.m, mercury_compile.pp, modes.m, store_alloc.m,
switch_detection.m:
	Handle pseudo_imported predicates.

modes.m, constraint.m:
	Change modecheck to return an updated module_info, since
	modechecking may insert new entries into the unify_requests
	queue in the module_info.  Make sure that modechecking
	never inserts requests into the unify_requests queue
	for code that has mode errors (or needs rescheduling).

call_gen.m, polymorphism.m:
	Move duplicated code into unify_proc.m.

clause_to_proc.m:
	Add new predicate clauses_to_proc for use by unify_proc.m.

unify_proc.m:
	Implement complicated unifications with complicated modes.
1995-07-20 13:32:36 +00:00
Zoltan Somogyi
0bc196dbdd Cleanup of the option set. Main change is making linking the default,
options:
	Cleanup of the option set. Main change is making linking the default,
	and the replacement of -g, --compile and --link by -e, -C and -c.
	WARNING: this makes the compiler inconsistent with the standard mmake
	configuration, so don't do a cvs update yet unless you know what you
	are doing.

conf:
	Find out at configuration time how many bits the --tags low option
	uses.

mercury_compile:
	With the help of conf, we now make sure --tags and --num-tag-bits
	are consistent. We use the new set of options. We also generate
	program-specific .clean rules in .dep files.

make_tags:
	Mercury_compile now makes sure that --tags and --num-tag-bits are
	consistent, so make_tags need not do it.

mode_errors:
	Use the new set of options.

llds:
	Changes to introduce the new option use_macro_for_redo_fail and
	change --mod-comments into --auto-comments.

cse_detection:
	We now print the messages about redoing mode analysis, switch detection
	and cse detection only if very verbose is on.

typecheck:
	The error message for wrong number of arguments now gives the actual
	number and the right number(s).

value_number:
	Tighten the sanity check; theold version wasn't tight enough for
	the code generated for prof.m.
1995-07-12 15:11:00 +00:00
Andrew Bromage
9dddf14a3f OK, finally, everything should be back in order. 1995-07-05 23:38:32 +00:00
Andrew Bromage
fda56846cb With any luck, this should be the call_graph branch successfully
merged.  Do not use --constraint-propagation, because it doesn't
schedule conjunctions properly yet.
1995-07-04 03:15:30 +00:00
Fergus Henderson
0713ab1575 Change the type of the first two arguments of unify/5 in
hlds.m and lots of other files:
	Change the type of the first two arguments of unify/5 in
	hlds__goal_expr from `term, term' to `var, unify_rhs'
	where unify_rhs is given by

		:- type unify_rhs
			--->	var(var)
			;	functor(const, list(var))
			;	lambda_goal(list(var), hlds__goal).

	This change was for two reasons: firstly, it simplifies the
	code in a lot of places, and secondly, it is a step towards
	implementing lambda closures and higher-order predicates
	properly.
1995-06-25 13:47:14 +00:00
Zoltan Somogyi
15b8ea11d0 Put the comment about the contents of stack slots before the initial
code_gen.pp:
	Put the comment about the contents of stack slots before the initial
	label, since this way it will be preserved by optimizations.

cse_detection.m:
	Extended the search to look for cses in if-then-elses and switches
	as well as disjunctions. Removed InstmapDelta from preds in which it
	was not being used.

det_analysis.m:
	Make the diagnosis routines more robust. The changes here avoid the
	Philip's problems with lexical.m.

jumpopt.m:
	Minor formatting changes.

livemap.m:
	Avoid duplicating livevals instructions when optimizations are
	repeated, since this can confuse some optimizations.

llds.m:
	Minor documentation change.

make_hlds.m:
	Minor formatting change.

mercury_compile.pp:
	Do not map arguments to registers if any semantic errors have been
	found.

middle_rec.m and code_aux.m:
	Apply middle recursion only if tail recursion is not possible,
	since tail recursion yields more efficient code.

opt_util.m:
	Added a predicate to recognize constant conditions in if_vals.
	Modified a predicate to make it better suited for frameopt.

optimize.pp:
	Changed the way optimizations were repeated to allow better control.
	Repeat peephole once more after frameopt, since the new frameopt
	can benefit from this.

options.m:
	Removed the --compile-to-c option, which was obsolete. Added an
	option for predicate-wide value numbering, which is off by default.
	Changed some of the default values of optimization flags to reduce
	compilation time while holding the loss of speed of generated code
	to a minimum.

peephole.m:
	Look for if_vals whose conditions are constants, and eliminate the
	if_val or turn it into a goto depending on the value of the constant.
	Generalized the condition for optimizing incr_sp/decr_sp pairs.

value_number.m:
	Added a prepass to separate primary tag tests in if-then-elses from
	the test of the secondary tag, which requires dereferencing the
	pointer.

	Added sanity check routines to test two aspects of the generated code.
	First, whether it produces the same values for the live variables as
	the original code, and second, whether it has moved any dereferences
	of a pointer before a test of the tag of that pointer. If either test
	fails, we use the old instruction sequence.

vn_debug.m:
	New messages to announce the failure of the sanity checks. They are
	enabled by default, but of course can only appear if value numbering
	is turned on (it is still off by default).

vn_flush.m:
	Threaded a list of forbidden lvals (lvals that may not be assigned to)
	through the flushing routines. When saving the old value of an lval
	that is being assigned to, we use this list to avoid modifying any of
	the values used on the right hand side of the assignment, even if the
	saving of an old value results in assignment that requires another
	save, and so on recursively.

	When the flushing of a node_lval referred to a shared vn, the uses of
	the access vns of the node_lvals were not being adjusted properly.
	Now they are.

vn_order.m:
	The ctrl_vn phase of the ordering was designed to ensure that all
	nodes that need not come before a control node come after it. However,
	nodes were created after this phase operated, causing leakage of some
	value nodes in front of control nodes. Some of these led to pointer
	dereferences before tag tests, causing bus errors. The ctrl_vn phase
	is now last to avoid this problem.

vn_table.m:
	Added an extra interface predicate to support the sanity checks in
	value_number.

vn_util.m:
	The transformation of c1-e2 into (0-e2)+c1 during vnrval simplification
	could lead to an infinite loop in the compiler if c1 was zero. A test
	for this case now prevents the loop.
1995-06-17 06:08:09 +00:00
Zoltan Somogyi
f7d2f8bebb Detect partial switches, i.e. disjunctions in which not all
switch_detection:
	Detect partial switches, i.e. disjunctions in which not all
	disjuncts form part of the switch. We give preference to full
	switches, and failing that, to partial switches with the most arms.

peephole, opt_util:
	Fixed the code for the introduction of succeed_discard.

code_gen:
	Fixed spelling error in error message.

code_info:
	Made error message somewhat more informative.

cse_detection:
	Removed debugging code; we now always repeat cse detection after
	finding some cses.

det_analysis:
	Added some comments.

value_number, vn_debug, vn_flush:
	Changes to make debugging easier.
1995-05-29 02:27:41 +00:00
Fergus Henderson
7be5e14982 Only print the messages if --verbose option was set.
cse_detection.m:
	Only print the messages if --verbose option was set.
	(Hmm... perhaps we should only do it with --very-verbose?)
1995-05-28 05:45:25 +00:00
Zoltan Somogyi
f86b10982e check in forgotten files.
cs_detection, passes_aux:
	check in forgotten files.

hlds, modes:
	resolve minor CVS conflicts.

mercury_compile:
	improve progress message.
1995-05-06 10:38:40 +00:00