Commit Graph

36 Commits

Author SHA1 Message Date
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
Fergus Henderson
ea9c17ee54 Include the library .m files in the tags file.
compiler/Mmake:
	Include the library .m files in the tags file.

hlds.m and lots of other places:
	Change the type of the argument list of a HLDS `call' from
	`list(term)' to `list(var)'.
1995-06-06 01:22:10 +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
Zoltan Somogyi
0f46c5d4e7 Merged in changes from the pass_str_branch. 1995-05-06 07:29:58 +00:00
Fergus Henderson
c767fd5341 A bunch of changes to implement the procs-per-c-function option.
options.m call_gen.m code_gen.pp code_info.m code_util.m llds.m unify_gen.m:
	A bunch of changes to implement the procs-per-c-function option.
	This default is now `--procs-per-c-function 1', for reasonable
	efficiency of compilation, but for efficiency of generated code
	(e.g. when compiling benchmarks!)
	use `--procs-per-c-function 0' (0 really means infinity).

	I haven't tested this in any mode except asm_fast, so it's possible
	that this change might break the other modes.  If that turns out
	to be the case, let me know.  The symptom will be an error from
	the C compiler or linker.
1995-04-13 19:17:48 +00:00
Zoltan Somogyi
389599b337 Revamped the determinism system.
prog_io, hlds:	Added the functor "multidet" to the type determinism.
		Added types and predicates to relate determinism to its
		two components, can_fail and soln_count.

		Removed the functor "unspecified" from the type determinism,
		substituting maybe(determinism) for determinism in proc_info.

		Replaced the type category with the type code_model,
		and added predicates to compute it from determinism.

det_analysis:	Redone the analyses to work with determinism, not category
		(or code_model). This should enable programmers to write
		their own erroneous (and failure) predicates.

other files:	Use the new and renamed types and access predicates.
1995-04-06 02:13:05 +00:00
Zoltan Somogyi
1780579b73 fix the problem with destroying stack frames and creating
frameopt:
	fix the problem with destroying stack frames and creating
	them again later, accessing detstackvars that were earlier
	nominally destroyed.

vn_livemap:
	renamed it to livemap since frameopt now uses it also.

value_number, vn_*:
	Fixed some bugs. Reorganized the handling of blocks: they are now
	put in at the last minute before llds writes out the code.
	Made a start towards exploiting info about cheaper copies of
	values.

optimize, options:
	Made value_numbering an iterated optimization. Added a new
	option to control how many times it is iterated together
	with other the jumpopt, peephole and labelopt.

llds, call_gen, code_gen, code_info, middle_rec, opt_debug:
	changed type of the argument of livevals to plain set.

Warning: in more than a week I haven't been able to fully test this change,
dur to kryten's flakiness and bugs upstream of the optimizer.
1995-04-02 11:19:07 +00:00
Fergus Henderson
cea38722e4 Add copyright notices.
compiler/*.pp:
	Add copyright notices.
1995-03-30 21:42:13 +00:00
Fergus Henderson
4361aeb281 Oops, back out previous change, since it didn't quite work
code_gen.pp:
	Oops, back out previous change, since it didn't quite work
	properly (need to change things so that it doesn't do a
	localcall to procedures that are not in the same C function).
1995-03-27 18:16:08 +00:00
Fergus Henderson
949037ca75 Generate N procedures per C function.
code_gen.pp, options.m:
	Generate N procedures per C function.
1995-03-27 16:51:16 +00:00
Thomas Conway
56185418db a new module for manipulating rvals and lvals.
exprn_aux.nl:
	a new module for manipulating rvals and lvals.

code_exprn.nl:
	the new bottom level of the new code generator. This replaces
	a large chunk of code_info.

*code* & *gen*:
	various small changes to use the new bottom level of the
	code generator.
1995-03-15 08:07:56 +00:00
Peter Ross
d9865c2fc1 Introduced a new predicate which ignore's any whitespace in the input.
io.nl:
	Introduced a new predicate which ignore's any whitespace in the input.
	Needs to have all the whitespace character's added to it.

*.nl and *.pp:
	Changed the implementation of time profiling.  Now during a compile,
	the compiler identifies all the internal labels which can be accessed
	externally, and marks them.  At the moment, these are the continuation
	labels of calls and the next disjunct in nondet disjunctions.  Then
	at the .mod output, it places a macro 'update_prof_current_proc' to
	restore the profiling counter.
1995-03-13 17:09:01 +00:00
Zoltan Somogyi
2d0f72076b Whenever we do a test of a variable against a non-constant functor,
unify_gen:
	Whenever we do a test of a variable against a non-constant functor,
	we now try to turn it into a negated test on a constant functor.
	This is possible if these two functors are the only ones.

code_aux:
	Added an extra predicate to look up type definitions to make the
	previous change easier.

llds, code_gen, opt_util, opt_debug, frameopt, jumpopt, peephole:
	Added a boolean argument to do_succeed to say whether the nondet
	frame should be discarded on success or not. The default is no,
	but peephole has an optimization that tries to turn on this flag.

optimize, value_number, vn*:
	Restructured the top level of value numbering as part of an effort
	to identify blocks that could be optimized further given our knowledge
	that the contents of e.g. stackvars is also in registers when we
	jump to those blocks. Redone the interface between value_number and
	frameopt to allow value_number to be iterated, which is necessary
	to take advantage of the previously mentioned capability. Threated
	the I/O state through the relevant predicates; value numbering doesn't
	use non-logical I/O any more.
1995-03-06 09:42:39 +00:00
Peter Ross
fcc624ae6b Introduced an extra argument to the LLDS goto.
llds.nl:
	Introduced an extra argument to the LLDS goto.  It is the label
	address of the Caller and is used for the profiling of tailcall's.

*.nl and *.pp:
	Propagated the extra argument to all the appropiate files.
1995-02-28 04:20:27 +00:00
Zoltan Somogyi
2e64d7bc0f Added a target to make the library as a shared library, not just as
Makefile.*:
	Added a target to make the library as a shared library, not just as
	an archive.

code_gen, options:
	Introduced a new option to disable middle recursion optimization.
	This is needed to generate the right example code for section 3 of
	the JLP paper.

jumpopt:
	Factored some code.

frameopt:
	Put back a most of an optimization lost by a previous change.

vn_order:
	Changed the computation of desired dependencies; the new method should
	lead to improvements more frequently.
1995-02-13 06:38:49 +00:00
Thomas Conway
c48b5f6fcf Fix a long-known undocumented bug in which preds for which
code_gen.{nl,pp}:
	Fix a long-known undocumented bug in which preds for which
	the main conj has inst 'unreachable' aborted.

	Before generating a negated goal, save live variables onto
	the stack so we can find them again later.

ite_gen.nl:
	Before generating the condition of an if-then-else, save the
	live variables onto the stack so that we can find them in the
	else clause.

live_vars.nl:
	Add interference for the cases where live vars are saved before
	negations and ite conditions.
1995-02-12 00:56:42 +00:00
Fergus Henderson
5624cad430 Reapply earlier change which I had accidentally applied to
code_gen.pp:
	Reapply earlier change which I had accidentally applied to
	code_gen.nl rather than code_gen.pp.
1995-02-11 15:00:20 +00:00
Tyson Dowd
742193b4c4 Fixed a reference to constructor call/3 -- was supposed to be
code_gen.pp:
	Fixed a reference to constructor call/3 -- was supposed to be
	call/4 but code_gen.nl was committed (during all the profiling
	changes).
1995-02-10 03:19:08 +00:00
Thomas Conway
b759b4436a change occurences of is_builtin and not_builtin to abstract
various:
	change occurences of is_builtin and not_builtin to abstract
	calls.

code_info.nl:
	perform transitive checking for variable dependencies.
1995-02-07 07:39:13 +00:00
Thomas Conway
3632d6c749 added a few livevals where they should be.
middle_rec.nl:
	added a few livevals where they should be.

code_gen.nl:
	fixed a few bits and pieces. Added output variables to
	call/N.
1995-01-24 04:17:31 +00:00
Tyson Dowd
31dfac230c New module to handle shape information collection.
shapes:
	New module to handle shape information collection.

call_gen, code_gen, code_info, hlds, mercury_compile:
	Modifications to call the shapes module, and keep a shape
	table in the module_info structure.
1995-01-23 03:18:36 +00:00
Thomas Conway
b0d5adfae4 changed the epilogue for semidet prcs so that hte livevals
code_gen.nl:
	changed the epilogue for semidet prcs so that hte livevals
	for the failure proceed contains only r1.

bintree_set.nl:
	added bintree_set_singleton_set/2.
1995-01-23 01:06:51 +00:00
Fergus Henderson
ef46405b26 Generate code for predicates even if they have been inlined,
code_gen.pp:
	Generate code for predicates even if they have been inlined,
	since we may have taken their address.
1995-01-20 14:13:18 +00:00
Zoltan Somogyi
4e0d9a8367 Value numbering should now work with code that allocates memory.
value_number, vn_util:
	Value numbering should now work with code that allocates memory.

frameopt:
	Create a stack frame before an if_val if both continuations need one.

optimize, mercury_compile:
	-V now prints a message for each optimization pass for each proc.

llds, call_gen, code_gen, middle_rec etc:
	Change livevals/2 back into livevals1.

jumpopt:
	Rename instmap to instrmap at fjh's request.
1995-01-20 11:53:20 +00:00
Fergus Henderson
e947ea74cd Print out memory usage statistics more often.
code_gen.pp:
	Print out memory usage statistics more often.
1995-01-17 22:43:00 +00:00
Thomas Conway
ea86bc1f63 Updated some comments.
code_info.nl:
	Updated some comments.

code_gen.{pp,nl}:
	Fixed the generation of semidet epilogues so that r1
	is marked as live.
1995-01-17 01:59:48 +00:00
Thomas Conway
d639b6029c Lots of changes checked in slightly prematurely so that fjh doesn't
think I have forgotten ;-)

live_vars.nl:
	Fixed the stackslot sharing problem.
	Still need to fix the instmap problem.

code_*.nl:
	Bits and pieces of higher order stuff, threading the
	instmap through code generation.

hlds_out.nl:
	Write out the stack allocations (with var numbers).
1995-01-15 13:09:39 +00:00
Fergus Henderson
1a977ea19a Replace all occurrences of `not(Vars, Goal)' with just
*.nl:
	Replace all occurrences of `not(Vars, Goal)' with just
	plain `not(Goal)'.

type_util.nl, switch_gen.nl:
	Higher-order pred types are not user-defined types.
	Add a `predtype' type category for them.

call_gen.nl:
	Change call_closure/2 to call_closure/3 (with liveinfo).
	Plus a little bit of random hacking.
1995-01-10 18:35:59 +00:00
Thomas Conway
8755f26838 changed call/2 to call/3 to include gc information about
llds.nl:
	changed call/2 to call/3 to include gc information about
	what registers and stack locations are live, and what their
	`shape numbers' are. Currently all the shape numbers are -1
	because the shape table stuff hasn't been implemented.

*	The changes made are only cosmetic as far as everything else
*	is concerned.

*.nl, etc:
	changes related to the above.
1995-01-10 15:04:41 +00:00
Fergus Henderson
c074b02970 In term__create_var, use bit reversals rather than random numbers
term.nl:
	In term__create_var, use bit reversals rather than random numbers
	to ensure that the binary trees remain balanced.

call_gen.nl:
	For polymorphic unifications, generate a call to fatal_error().

code_gen.nl, hlds.nl, make_hlds.nl, modes.nl, unify_proc.nl:
	Move the unify_request data structure from code_info to the HLDS,
	and move the unify_request handling from code_gen.nl to modes.nl.
	This is because we now generate HLDS code rather than LLDS code
	for complicated unifications.

code_util.nl, hlds_out.nl:
	Do some special name mangling for =/2.

float.nl, typecheck.nl, undef_types.nl, term.nl, hlds.nl:
	Until we implement `float' properly, define it as an abstract type
	in float.nl.

hlds.nl, make_hlds.nl:
	Rename `local_pred, imported_pred, exported_pred' to just
	`local, imported, exported' since they also apply to types, etc.,
	not just to preds.

mercury_compile.pp, mercury_to_goedel.nl, prog_util.nl:
	Replace to goedel__ prefixes in prog_util.nl with prog_util__.

std_util.nl:
	Change the code for semidet_succeed to avoid determinism warning.
1994-12-29 01:12:12 +00:00
Thomas Conway
fa26defe30 don't generate code for non-exported inlined procs.
code_gen.*:
	don't generate code for non-exported inlined procs.

mercury_compile.*:
	be a bit smarter about when we do inlining.
1994-12-10 05:01:29 +00:00
Zoltan Somogyi
0fc3a66c85 prepared then for middle_rec.
code_gen, opt_util:
	prepared then for middle_rec.

peephole, opt_debug:
	old changes.

printlist.int:
	shouldn't have been here in the first place.

source_stats.awk:
	turned comments into awk syntax.
1994-12-01 04:50:13 +00:00
Thomas Conway
e348822bb0 unify procs were creating problems.
llds.nl :	primitive name mangling for '='
misc:		patches so that the benchmarks compile:
		unify procs were creating problems.
1994-11-08 04:36:04 +00:00
Thomas Conway
989d341554 Now I know that if you are editing code_gen or mercury_compile,
code_gen.pp:
	Now I know that if you are editing code_gen or mercury_compile,
	you have to edit the .pp file: how intuitive :-)
1994-11-02 06:52:05 +00:00
Zoltan Somogyi
6df9d73fa9 a lot less functionality is missing now :-)
value_number.nl:
	a lot less functionality is missing now :-)

atsort.nl:
	approximate topological sort for value numbering

opt_*.nl:
	changes to supprt value numbering

llds.nl, *_gen.nl:
	changed livevals/1 into livevals/2 to support value numbering

list.nl:
	added a predicate to delete a list (set) of items from a list

peephole.nl:
	implement shortcircuiting inside computed goto label lists. Not tested
	since the only place we use computed gotos has no opportunities for
	short circuiting.

options.nl:
	added option to control the maximum number of repetitions of
	the peephole optimizations; default value is 2.

dir.nl:
	fixed spelling error
1994-10-13 08:39:01 +00:00
Fergus Henderson
fd2470dd0a Add some more stuff for compiling to .o
Makefile*:
	Add some more stuff for compiling to .o

Makefile*, mercury_compile*, code_gen*:
	Add some stuff for handling `.pp' files.
	`.pp' files are Mercury source code containing
	NU-Prolog hacks inside

		#if NU_PROLOG
		...
		#endif

	These hacks are preprocessed out (using sed, not cpp)
	except when compiling with `mnc'.

term_io.nl, term_io.nu.nl, interpreter.nl, prog_out.nl:
	Make sure all the predicates in term_io.nl are
	prefixed with `term_io__', not `io__'.

term_io.nl, require.nl:
	Add some `external' declarations.

call_gen.nl, unify_gen.nl:
	A temporary hack - generate incorrect code for complicated/polymorphic
	unifications, rather than aborting.

random.nl:
	Make the code more efficient.

hlds.nl, term.nl:
	Allocate pred_ids and variable numbers randomly rather than
	sequentially, so that the binary trees remain reasonably balanced.

code_info.nl, unify_gen.nl, hlds_out.nl:
	Generate informative comments for tag tests: say the name of
	the variable being tested, and which constructor we are testing for.

llds.nl:
	Cast field() expressions to (int) when used as rvals, so
	that comparisons work as expected.

make_hlds.nl:
	Improve error reporting.
1994-10-09 18:26:41 +00:00