Commit Graph

28 Commits

Author SHA1 Message Date
Fergus Henderson
73131e8df3 Undo Zoltan's bogus update of all the copyright dates.
Estimated hours taken: 0.75

library/*.m:
compiler/*.m:
	Undo Zoltan's bogus update of all the copyright dates.
	The dates in the copyright header should reflect the years
	in which the file was modified (and no, changes to the
	copyright header itself don't count as modifications).
1998-01-23 12:57:08 +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
Zoltan Somogyi
42c540ad67 Give duplicate code elimination more teeth in dealing with similar arguments
Estimated hours taken: 20

Give duplicate code elimination more teeth in dealing with similar arguments
of different function symbols. For the source code

	:- type t1	--->	f(int)
			;	g(int, int).

	:- pred p1(t1::in, int::out) is det.

	p1(f(Y), Y).
	p1(g(Y, _), Y).

we now generate the C code

	Define_entry(mercury__xdup__p1_2_0);
		r1 = const_mask_field(r1, (Integer) 0);
		proceed();

thus avoiding the cost of testing the function symbol.

runtime/mercury_tags.h:
	Add two new macros, mask_field and const_mask_field, that behave
	just like field and const_field except that instead of stripping
	off a known tag from the pointer, they strip (mask) off an unknown
	tag.

compiler/llds.m:
	Change the first argument of the lval field/3 from tag to maybe(tag).

	Make the comments on some types more readable.

compiler/llds_out.m:
	If the first arg of the lval field/3 is no, emit a (const_)mask_field
	macro; otherwise, emit a (const_)field macro.

compiler/basic_block.m:
	New module to convert sequences of instructions to sequences of
	basic blocks and vice versa. Used in the new dupelim.m.

compiler/dupelim.m:
	Complete rewrite to give duplicate code elimination more teeth.
	Whereas previously we eliminated blocks of code only if they exactly
	duplicated other blocks of code, we now look for blocks that can be
	"anti-unified". For example, the blocks

	r1 = field(mktag(0), r2, 0)
	goto L1

	and

	r1 = field(mktag(1), r2, 0)
	<fall through to L1>

	anti-unify, with the most specific common generalization being

	r1 = mask_field(r2, 0)
	goto L1

	If several basic blocks antiunify, we replace one copy with the
	antiunified block and try to eliminate the others. We do not
	eliminate blocks that can be fallen into, since eliminating them
	would require introducing a goto, which would slow the code down.

compiler/peephole,m:
	If a conditional branch to a label is followed by that label or
	by an unconditional branch to that label, eliminate the branch.
	Dupelim produces this kind of code.

compiler/{code_exprn,exprn_aux,lookup_switch,opt_debug,unify_gen}.m:
	Minor changes required by the change to field/3.

compiler/{frameopt,jumpopt,labelopt,mercury_compile,optimize,value_number}.m:
	s/__main/_main/ in predicate names.

compiler/jumpopt.m:
	Add some documentation.

compiler/unify_gen.m:
	Fix a module qualified predicate name reference that would not
	work in Prolog.

compiler/notes/compiler_design.html:
	Document the new file basic_block.m.
1997-12-22 06:59:25 +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
05267d2834 Add support for memory profiling.
Estimated hours taken: 40 (+ unknown time by Zoltan)

Add support for memory profiling.

(A significant part of this change is actuallly Zoltan's work.  Zoltan
did the changes to the compiler and a first go at the changes to the
runtime and library.  I rewrote much of Zoltan's changes to the runtime
and library, added support for the new options/grades, added code to
interface with mprof, did the changes to the profiler, and wrote the
documentation.)

[TODO: add test cases.]

NEWS:
	Mention support for memory profiling.

runtime/mercury_heap_profile.h:
runtime/mercury_heap_profile.c:
	New files.  These contain code to record heap profiling information.

runtime/mercury_heap.h:
	Add new macros incr_hp_msg(), tag_incr_hp_msg(),
	incr_hp_atomic_msg(), and tag_incr_hp_atomic_msg().
	These are like the non-`msg' versions, except that if
	PROFILE_MEMORY is defined, they also call MR_record_allocation()
	from mercury_heap_profile.h to record heap profiling information.
	Also, fix up the indentation in lots of places.

runtime/mercury_prof.h:
runtime/mercury_prof.c:
	Added code to dump out memory profiling information to files
	`Prof.MemoryWords' and `Prof.MemoryCells' (for use by mprof).
	Change the format of the `Prof.Counts' file so that the
	first line says what it is counting, the units, and a scale
	factor.  Prof.MemoryWords and Prof.MemoryCells can thus have
	exactly the same format as Prof.Counts.
	Also cleaned up the interface to mercury_prof.c a bit, and did
	various other minor cleanups -- indentation changes, changes to
	use MR_ prefixes, additional comments, etc.

runtime/mercury_prof_mem.h:
runtime/mercury_prof_mem.c:
	Rename prof_malloc() as MR_prof_malloc().
	Rename prof_make() as MR_PROF_NEW() and add MR_PROF_NEW_ARRAY().

runtime/mercury_wrapper.h:
	Minor modifications to reflect the new interface to mercury_prof.c.

runtime/mercury_wrapper.c:
runtime/mercury_label.c:
	Rename the old `-p' (primary cache size) option as `-C'.
	Add a new `-p' option to disable profiling.

runtime/Mmakefile:
	Add mercury_heap_profile.[ch].
	Put the list of files in alphabetical order.
	Delete some obsolete stuff for supporting `.mod' files.
	Mention that libmer_dll.h and libmer_globals.h are
	produced by Makefile.DLLs.

runtime/mercury_imp.h:
	Mention that libmer_dll.h is produced by Makefile.DLLs.

runtime/mercury_dummy.c:
	Change a comment to refer to libmer_dll.h rather than
	libmer_globals.h.

compiler/llds.m:
	Add a new field to `create' and `incr_hp' instructions
	holding the name of the type, for heap profiling.

compiler/unify_gen.m:
	Initialize the new field of `create' instructions with
	the appropriate type name.

compiler/llds_out.m:
	Output incr_hp_msg() / tag_incr_hp_msg() instead of
	incr_hp() / tag_incr_hp().

compiler/*.m:
	Minor changes to most files in the compiler back-end to
	accomodate the new field in `incr_hp' and `create' instructions.

library/io.m:
	Add `io__report_full_memory_stats'.

library/benchmarking.m:
	Add `report_full_memory_stats'.  This uses the information saved
	by runtime/mercury_heap_profile.{c,h} to print out a report
	of memory usage by procedures and by types.
	Also modify `report_stats' to print out some of that information.

compiler/mercury_compile.m:
	If `--statistics' is enabled, call io__report_full_memory_stats
	at the end of main/2.  This will print out full memory statistics,
	if the compiler was compiled with memory profiling enabled.

compiler/options.m:
compiler/handle_options.m:
runtime/mercury_grade.h:
scripts/ml.in:
scripts/mgnuc.in:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
	Add new option `--memory-profiling' and new grade `.memprof'.
	Add `--time-profiling' as a new synonym for `--profiling'.
	Also add `--profile-memory' for more fine-grained control:
	`--memory-profiling' implies both `--profile-memory' and
	`--profile-calls'.

scripts/mprof_merge_runs:
	Update to handle the new format of Prof.Counts and to
	also merge Prof.MemoryWords and Prof.MemoryCells.

profiler/options.m:
profiler/mercury_profile.m:
	Add new options `--profile memory-words' (`-m'),
	`--profile memory-cells' (`-M') and `--profile time' (`-t').
	Thes options make the profiler select a different count file,
	Prof.MemoryWords or Prof.MemoryCells instead of Prof.Counts.
	specific to time profiling.

profiler/read.m:
profiler/process_file.m:
profiler/prof_info.m:
profiler/generate_output.m:
	Update to handle the new format of the counts file.
	When reading the counts file, look at the first line of
	the file to determine what is being profiled.

profiler/globals.m:
	Add a new global variable `what_to_profile' that records
	what is being profiled.

profiler/output.m:
	Change the headings to reflect what is being profiled.

doc/user_guide.texi:
	Document memory profiling.
	Document new options.

doc/user_guide.texi:
compiler/options.m:
	Comment out the documentation for `.proftime'/`--profile-time',
	since doing time and call profiling seperately doesn't work,
	because the code addresses change when you recompile with a
	different grade.  Ditto for `.profmem'/`--profile-memory'.
	Also comment out the documentation for
	`.profcalls'/`--profile-calls', since it is redundant --
	`.memprof' produces the same information and more.

configure.in:
	Build a `.memprof' grade.  (Hmm, should we do this only
	if `--enable-all-grades' is specified?)
	Don't ever build a `.profcalls' grade.
1997-12-05 15:49:06 +00:00
Tyson Dowd
2a97f96d1a Generate stack layouts for accurate garbage collection.
Estimated hours taken: 50

Generate stack layouts for accurate garbage collection.

compiler/base_type_layout.m:
	Change the order of some arguments so that threaded data
	structures are more often in the final two arguments (allows
	easy use of higher order predicates).
	Simplify some code using higher order preds.
	Export base_type_layout__construct_pseudo_type_info, as
	stack_layout.m needs to be able to generate pseudo_type_infos
	too.
	Fix problems with cell numbers being re-used -- get the next
	cell number from module_info, and update module_info
	after processing base_type_layouts.

compiler/code_gen.m:
	Add information about each procedure to the continuation info.
	Handle new field in c_procedure.

compiler/continuation_info.m:
	Redesign most of this module to deal with labels
	that are continuation points for multiple calls.
	Change the order of some arguments so that threaded data
	structures are in the final two arguments.
	Cleaned up and documented code.

compiler/dupelim.m:
compiler/exprn_aux.m:
	Handle new label_entry data type.

compiler/export.m:
compiler/opt_debug.m:
	Handle new label_entry and general data types.

compiler/llds_out.m:
	Add an argument to get_proc_label to control whether a
	"mercury_" prefix is wanted.
	Handle new label_entry and general data types.

compiler/llds.m:
	Add a new alternative for data_const - a label_entry.
	Add a new alternative for data_name - general, which
	allows any sort of data, with names generated elsewhere.
	Add the pred_proc_id as a field of c_procedure.

compiler/optimize.m:
compiler/llds_common.m:
compiler/optimize.m:
	Handle new field in c_procedure.

compiler/mercury_compile.m:
	Generate layout information after code has been generated,
	and output stack layouts.

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

compiler/stack_layout.m:
	New file - generates the LLDS code that defines
	global constants to hold the stack_layout structures.

compiler/options.m:
compiler/handle_options.m:
	Add --stack-layout option which outputs stack layouts.
	Make accurate gc imply stack_layout.
1997-11-08 13:12:08 +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
Simon Taylor
27d156bbb5 Implemented a :- use_module directive. This is the same as
Estimated hours taken: 14

Implemented a :- use_module directive. This is the same as
:- import_module, except all uses of the imported items
must be explicitly module qualified.

:- use_module is implemented by ensuring that unqualified versions
of items only get added to the HLDS symbol tables if they were imported
using import_module.

Indirectly imported items (from `.int2' files) and items declared in `.opt'
files are treated as if they were imported with use_module, since all uses
of them should be module qualified.

compiler/module_qual.m
	Keep two sets of type, mode and inst ids, those which can
	be used without qualifiers and those which can't.

	Renamed some predicates which no longer have unique names since
	'__' became a synonym for ':'.

	Made mq_info_set_module_used check whether the current item is in
	the interface, rather than relying on its caller to do the check.

	Removed init_mq_info_module, since make_hlds.m now uses the
	mq_info built during the module qualification pass.

compiler/prog_data.m
	Added a pseudo-declaration `used', same as `imported' except uses of
	the following items must be module qualified.

	Added a type need_qualifier to describe whether uses of an item
	need to be module qualified.

compiler/make_hlds.m
	Keep with the import_status whether current item was imported
	using a :- use_module directive.

	Use the mq_info structure passed in instead of building a new one.

	Ensure unqualified versions of constructors only get added to the
	cons_table if they can be used without qualification.

compiler/hlds_module.m
	Added an extra argument to predicate_table_insert of type
	need_qualifier.

	Only add predicates to the name and name-arity indices if they
	can be used without qualifiers.

	Changed the structure of the module-name-arity index, so that
	lookups can be made without an arity, such as when type-checking
	module qualified higher-order predicate constants. This does not
	change the interface to the module_name_arity index.

	Factored out some common code in predicate_table_insert which
	applies to both predicates and functions.

compiler/hlds_pred.m
	Removed the opt_decl import_status. It isn't needed any more
	since all uses of items declared in .opt files must now be
	module qualified.

	Added some documentation about when the clauses_info is valid.

compiler/intermod.m
	Ensure that predicate and function calls in the `.opt' file are
	module qualified. Use use_module instead of import_module in
	`.opt' files.

compiler/modules.m
	Handle use_module directives.

	Report a warning if both use_module and import_module declarations
	exist for the same module.

compiler/mercury_compile.m
	Collect inter-module optimization information before module
	qualification, since it can't cause conflicts any more. This means
	that the mq_info structure built in module_qual.m can be reused in
	make_hlds.m, instead of building a new one.

compiler/prog_out.m
	Add a predicate prog_out__write_module_list, which was moved
	here from module_qual.m.

compiler/typecheck.m
	Removed code to check that predicates declared in `.opt' files
	were being used appropriately, since this is now handled by
	use_module.

compiler/*.m
	Added missing imports, mostly for prog_data and term.

NEWS
compiler/notes/todo.html
doc/reference_manual.texi
	Document `:- use_module'.

tests/valid/intermod_lambda_test.m
tests/valid/intermod_lambda_test2.m
tests/invalid/errors.m
tests/invalid/errors2.m
	Test cases.
1997-06-29 23:11:42 +00:00
Fergus Henderson
8c60f93849 Fix a bug where tag_switch.m was generating references to non-existent
Estimated hours taken: 4

Fix a bug where tag_switch.m was generating references to non-existent
labels for det switches that don't cover the full range of the type.

llds.m:
	Add new alternative `do_not_reached' to the code_addr type.

exprn_aux.m:
dupelim.m:
livemap.m:
llds_out.m:
opt_util.m:
opt_debug.m:
	Add new code to handle `do_not_reached'.

tag_switch.m:
	When generating tag switch jump tables for det switches that do
	not cover the whole type, which can happen if the initial inst of
	the switch variable is a bound(...) inst that represents a
	subtype, make sure that we don't generate references to
	undefined labels for cases that occur in the switch var's type
	but not in the switch var's initial inst.  Instead, make such
	references refer to a label that jumps to `do_not_reached'.
1997-04-17 07:49:11 +00:00
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