Commit Graph

19 Commits

Author SHA1 Message Date
Zoltan Somogyi
a4a1a7788c Add support for taking the addresses of words on the heap as well as on
Estimated hours taken: 7

Add support for taking the addresses of words on the heap as well as on
on either stack. This will be used later to support tail recursion modulo
constructor application as well as parallelism.

The support provided is a first draft. Since nothing in the compiler
currently generates code that uses the new facilities, they have not been
tested yet beyond ensuring that they don't interfere with the old functionality
of the compiler.

llds:
	Add a new type, mem_ref, that denotes a reference to a stackvar,
	a framevar, or to a field of a cell on the heap.

	Add a new function symbol to the type rval: mem_addr(mem_ref),
	which represents the address of the word denoted by the mem_ref.

	Add a new function symbol to the type lval: mem_ref(rval).
	Given that Rval is an address, mem_ref(Rval) denotes the word
	at that address. The value of Rval should have originally come from
	a mem_addr(_) type rval, but that value could have been store in
	registers, stack slots etc since then.

code_exprn, code_info, dupelim, exprn_aux, garbage_out, livemap, llds_common,
llds_out, middle_rec, opt_debug, opt_util, vn_cost, vn_filter:
	Added code to handle the new mem_ref type and the new alternatives
	in lval and rval.

exprn_aux:
	Make exprn_aux__substitute_lval_in_lval more thorough.

vn_type:
	Add vn shadows of the new things in llds.

vn_flush, vn_order, vn_util:
	Handle the new things in llds and/or their vn shadows.
1997-01-21 05:05:31 +00:00
Zoltan Somogyi
54bb1c4a67 Move the code that generates code for pragma_c_codes to a new module.
Estimated hours taken: 3

code_gen, pragma_c_code:
	Move the code that generates code for pragma_c_codes to a new module.

llds:
	Change the representation of reg and temp lvals, in order to create
	the concept of a "register type" and to reduce memory requirements.

	Also add a comment indicating a possible future extension dealing with
	model_non pragma_c_codes.

code_exprn, code_info:
	Add the ability to request registers of a given type, or a specific
	register, when acquiring registers.

bytecode, bytecode_gen, call_gen, dupelim, exprn_aux, follow_vars, frameopt,
garbage_out, jumpopt, llds_out, middle_rec, opt_debug, opt_util, store_alloc,
string_switch, tag_switch, unify_gen, vn_block, vn_cost, vn_filter, vn_flush,
vn_order, vn_temploc, vn_type, vn_util, vn_verify:
	Small changes to accommodate the new register representation.

hlds_goal:
	Add a comment indicating a possible future extension dealing with
	model_non pragma_c_codes.

inlining:
	Add a comment indicating a how to deal with a possible future extension
	dealing with model_non pragma_c_codes.
1996-12-31 09:58:59 +00:00
Fergus Henderson
07635fbf96 Fix things so that we can now generate unboxed floats as
Estimated hours taken: 24

Fix things so that we can now generate unboxed floats as
static constants.  We do this by generating static constants
as structs rather than as arrays.

Reorganize the way llds_out.m handles types to simplify the code
and eliminate unnecessary casts in the generated C code.

llds.m, vn_type.m:
	Change `llds_type' to be more precise, by adding two new
	alternatives (data_ptr and code_ptr) to the categories,
	and modifying the various type predicates accordingly.

llds.m, base_type_info.m, base_type_layout.m, garbage_out.m,
llds_common.m, opt_debug.m, unify_gen.m.
	Remove the "has pointers?" field from the `c_data' and
	`data_addr' types in llds.m and from the `cell_info' type
	in llds_common.m, since they're not needed anymore.
	(Instead llds_out.m uses `llds__rval_type' etc. to figure out
	whether something has pointers.)

base_type_info.m, base_type_layout.m:
	Fix a bug: the `exported' field in the `c_data' type
	needs to be set to yes for `Status = abstract_exported' types
	as well as for `Status = exported' types.

exprn_aux.m:
	If unboxed_float is yes, then floats are now considered constants.

llds_out.m:
	Change `output_rval' and `output_lval' so that they output a value
	as its natural type, rather than cast to Integer or Word.
	Add a new predicate `output_rval_as_type(Rval, Type)',
	and change most of the calls to `output_rval' to instead
	call `output_rval_as_type' specifying the appropriate type.
	Similarly add `output_lval_as_word' and change some of the
	calls to `output_lval' to call `output_lval_as_word' instead.
	Eliminate `output_rval_as_float', since its functionality
	has been folded into `output_rval' and `output_rval_as_type'.
	Delete `output_rval_lval', since it's not needed anymore.
	Neither is the `args_have_pointers' predicate.

	Merge the shared code in for handling `c_data' modules and `create'
	rvals into a new predicate output_const_term_decl; this predicate
	outputs struct declarations for the generated terms, so we can
	now output floats in such terms without needing to do type punning
	in static constants.

options.m:
	`--single-prec-float' is no longer an alias for `--unboxed-float'.
	Also fix a couple of other parts of the help message.
1996-12-19 08:15:04 +00:00
Thomas Conway
8e4e537a38 These changes have 2 parts:
Estimated hours taken: 3

These changes have 2 parts:
	* Fix a bug in unify_gen triggered by zoltans fix to a
	  bug triggered by dmo's graphics project and add a test
	  case for it.
	* Fix a couple of small bugs in the testing procedures where
	  they required you to have . in your path.


mercury/compiler/code_exprn.m,
mercury/compiler/code_info.m:
	add the predicate
		code_{exprn,info}__materialize_vars_in_rval/5
	which generates code to materialize the vars in an rval and
	updates the exprn info appropriately.
	This predicate was added because it is needed for generating
	the sub-unifications where a deconstruction has assignments
	into the term (ie field(....) = var; rather than the other
	way around).

mercury/compiler/exprn_aux.m:
	export exprn_aux__vars_in_rval.

mercury/compiler/follow_vars.m:
	fix a singleton variable warning.

mercury/compiler/unify_gen.m:
	When generating code to assign into the fields of a term
	within a deconstruction, materialize any variables in the
	the field expression (into which you are going to assign)
	before doing the assignment. Before this fix, the code generator
	was emitting code that contained var(M), which with certain
	combinations of opt flags was causing an abort in llds_out.

tests/runtests:
	tiny bugfix so that runtests works for people who don't have `.'
	in their path.

tests/valid/Mmake:
	enable `two_way_unif' which tests the bugfix in unify_gen shown above

mercury/tools/bootcheck:
	tiny bugfix so that runtests works for people who don't have `.'
	in their path.
1996-11-05 07:10:51 +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
Zoltan Somogyi
40e727614d Add a boolean argument to the create rval, which should be set to true
Estimated hours taken: 2

llds.m:
	Add a boolean argument to the create rval, which should be set to true
	if the cell created must have a unique reference.

vn_type.m:
	Add a corresponding argument to vn_create.

others:
	Fix references to creates and vn_creates.
1996-08-04 23:18:56 +00:00
Zoltan Somogyi
9e31ef9baa Split llds into two parts. llds.m defines the data types, while llds_out.m
Estimated hours taken: 1.5

Split llds into two parts. llds.m defines the data types, while llds_out.m
has the predicates for printing the code.

Removed the call_closure instruction. Instead, we use calls to the
system-defined addresses do_call_{det,semidet,nondet}_closure. This is
how call_closure was implemented already. The advantage of the new
implementation is that it allows jump optimization of what used to be
call_closures, without new code in jumpopt.
1996-04-24 08:59:06 +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
Fergus Henderson
974d3b9247 Do some more work on improving floating-point performance:
Estimated hours taken: 2

Do some more work on improving floating-point performance:
emit boxed floating point constants as static ground terms.

options.m:
	Add new option --unboxed-float.

exprn_aux.m
	Add --unboxed-float to the `exprn_opts' that affect whether
	or not things can be static constants.  If --unboxed-float
	is not set, and --static-ground-terms is, then consider
	float_consts to be constant.

code_exprn.m, lookup_switch.m:
	Trivial changes to handle new arity of exprn_opts type.

llds.m:
	If --unboxed-float is not set, and --static-ground-terms is, then
	output `static const Float mercury_float_const_...' declarations
	for float_consts.
1996-04-07 07:41:52 +00:00
Fergus Henderson
1bf905b515 Fix a second occurrence of the problem with casts in the initializers
Estimated hours taken: 1
	(plus lots of time debugging the problem via email)

Fix a second occurrence of the problem with casts in the initializers
of static constants causing gcc to generate non-position-independent code.
This prevented the use of gcc on AIX RS/6000 systems, and was also
preventing us from creating genuinely shared shared libraries on Solaris.

compiler/llds.m:
	Emit static constants as `const Word * mercury_const_n [] = { ... }'
	rather than `const Word mercury_const_n [] = { ... }' not just
	in the case when the constant contains code addresses, but also
	when it contains data addresses, including addresses of other
	static constants and/or string literals.

exprn_aux.m:
	Add nondet (in, out) modes to the ..._contain_rval predicates,
	which nondeterministically generate all the contained rvals,
	and export args_contain_rval.  For use by llds.m as required
	by the above change.
1996-04-06 19:00:24 +00:00
Zoltan Somogyi
c8da041006 Made a start towards getting better code generated for nested creates
Estimated hours taken: 4

code_exprn:
	Made a start towards getting better code generated for nested creates
	and towards getting rid of useless "shuffle lval" instructions.
	Also, some minor cleanup.

exprn_aux:
	Add some auxiliary predicates for the new code_exprn.

delay_info:
	Remove a useless import of hlds, which is now empty.
1996-04-05 08:27:21 +00:00
Zoltan Somogyi
b4f71d7b53 Both code_exprn and lookup_switch had code to check whether an
Estimated hours taken: 2

exprn_aux:
	Both code_exprn and lookup_switch had code to check whether an
	expression is constant or not. Some of the code is different
	due to different handling of variables in rvals, but exprn_aux
	now contains the common subset.

	This common subset used to treat some address constants incorrectly,
	simply by not considering them; they are now considered and treated
	properly.

code_exprn, lookup_switch, exprn_aux:
	Remove redundant option lookups in the process of checking for
	constant expressions.

code_exprn:
	Other minor cleanups, including removal of a block of code Tom
	says was "deep magic" (but which turns out to be unnecessary).

code_info:
	Removed some dead code.

options:
	Added real support for --opt-level, in the form of a table of
	default values of options for each optimization level between
	0 and 5 (both inclusive). This needs a new form of documentation.
	How do you do tables in texinfo?
1996-03-11 10:32:20 +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
Zoltan Somogyi
693543830f Added last call optimization for nondet predicates.
jumpopt:
	Added last call optimization for nondet predicates.

llds:
	Added a new lval type to represent the succip slot of nondet
	stack frames.

other files:
	Changes required by the change to llds (there is a minor unrelated
	change in vn_cost as well).

	Tyson: please check my changes to code_info__get_shape_num and
	garbage_out__write_liveval.
1995-09-06 02:22:24 +00:00
Fergus Henderson
fdb97147c7 Export a pred for use by llds.m.
exprn_aux.m:
	Export a pred for use by llds.m.

llds.m:
	Write out static constants with type `const Word * []' rather
	than `const Word []' if they contain code addresses, since for
	shared libraries on Irix 5, gcc does not support casting code
	addresses to words in the initializers for static constants
1995-05-27 18:10:00 +00:00
Fergus Henderson
f7e5d837e1 A bunch of bug fixes!
code_info.m:
	Bug fix: change generate_pre_commit and generate_commit so that
	the values which need to be saved and restored are always pushed
	onto the det stack, even in nondet predicates.  The reason is
	that if the committed goal fails, curfr is not valid, so we
	can't restore the fields from the nondet stack.
	(This way may well be more efficient anyway.)

disj_gen.m, ite_gen.m:
	Handle the case when the current failure continuation is unknown
	on entry to the disjunction or nondet if-then-else by creating
	a new frame on the nondet stack.  (Originally we just aborted
	in this case; recently we "fixed" this, but it turned out that
	the fix was not correct, for the same reason as the above-mentioned
	bug in pre_commit/commit.

llds.m:
	Add succfr/1 and prevfr/1 to the rval type in llds.m,
	since they were needed by the above bug fixes.
	(This caused dozens of changes elsewhere to handle the
	new types.)
	Also fix a trivial bug that I recently introduced which
	prevented --mod-comments from working.

live_vars.m:
	Fix bug in allocation of stack slots for nondet code.
	(This is the one that caused the bug that ksiew and I found
	when writing a calculator program.)

peephole.m:
	Disable the succeed_discard() optimization, since it
	causes incorrect code to be generated.  It was replacing
	modframe(do_fail) ... succeed() with
	modframe(do_fail) ... succeed_discard() even when there were
	instructions such as mkframe() in between.

modes.m, hlds.m:
	When modechecking switches, record the binding of the switch variable
	as we enter each case, so that we get the determinism analysis
	right.

mercury_compile.pp:
	Make sure that we set the exit status to be non-zero if we
	find any errors.

typecheck.m, modes.m, undef_types.m, undef_modes.m:
	Don't invoke type-checking if there are undefined types.
	Don't invoke mode-checking if there are undefined modes.
	This avoids the problem of the compiler aborting with an
	internal error if there are undefined types/modes.
1995-05-12 13:44:58 +00:00
Fergus Henderson
ac4f8ba0fb Add copyright messages.
compiler/*:
	Add copyright messages.
	Change all occurences of *.nl in comments to *.m.

compiler/mercury_compile.pp:
	Change the output to the .dep files to use *.m rather than *.nl.
	(NOTE: this means that `mmake' will not work any more if you
	call your files *.nl!!!)
1995-03-30 21:03:41 +00:00
Fergus Henderson
c9b3ccbd2e label_opt was erroneously optimizing away code which was not dead,
opt_util.m, exprn_aux.m:
	label_opt was erroneously optimizing away code which was not dead,
	because it was not considering references to the code via
	address_consts in rvals.  So I've changed opt_util__instr_labels
	to return those labels too, and added some new utility preds in
	exprn_aux to deal with that.

exprn_aux.m:
	Remove expr_aux__expr_is_constant/1, since it was not used
	(and it was broken anyway).
1995-03-21 09:44:38 +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