Commit Graph

68 Commits

Author SHA1 Message Date
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
Andrew Bromage
d7319104f9 Making the types pred_id and proc_id (almost) abstract.
Estimated hours taken: 7

Making the types pred_id and proc_id (almost) abstract.

compiler/code_util.m:
        Changed the type of several predicates:
                code_util__make_uni_label/4 (arg 3 was int, now proc_id)
                code_util__inline_builtin/4 (arg 3 was proc_id, now int)
        Added predicate code_util__translate_builtin_2/6.

compiler/hlds_module.m:
        Moved invalid_pred_id/1 to hlds_pred.m

compiler/hlds_pred.m:
        Types pred_id/0 and proc_id are now abstract.
        Added predicates:
                hlds_pred__initial_pred_id/1, hlds_pred__initial_proc_id/1,
                hlds_pred__next_pred_id/2, hlds_pred__next_proc_id/2,
                pred_id_to_int/2, proc_id_to_int/2,
                hlds_pred__in_in_unification_proc_id/1
        Moved predicate invalid_pred_id/1 (from hlds_module.m).

compiler/*.m:
        Miscellaneous minor changes to cast pred/proc_ids to ints
        where appropriate.
1997-03-06 05:09:54 +00:00
Tyson Dowd
9bc2c0f235 Create new `base_type_functors' data structures, that describe the
Estimated hours taken: 16

Create new `base_type_functors' data structures, that describe the
functors of discriminated union types.

This is stage 1 of changes designed to allow io__read/3 to be
implemented. It will also allow the other code dealing with
runtime type information to be significantly simplified.
(Stage 2 will be to implement predicates to find information about
the functors of discriminated union types, and construct such types, then
stage 3 will be to implement io__read/3 using these predicates).

compiler/base_type_info.m:
	- Make the base_type_info reference the base_type_functors.

compiler/base_type_layout.m:
	- Clean up header documentation, fix inaccuracies.
	- Add support for creation of base_type_functors tables,
	  document the tables created.
	- Add a representation of the primary and secondary tag
	  to the descriptions created for functors.
	- Rename predicates since this module now creates two
	  tables.
	- Split some predicates so that code can be re-used.

compiler/llds.m:
	- Instead of
	  	base_type_info(string, arity),
	  	base_type_layout(string, arity) and the new
	  	base_type_functors(string, arity),
	  use
	  	base_type(base_data, string, arity)
	  where base_data is one of
	  	info, layout or functors

compiler/llds_out.m:
	- Add llds_out__make_base_type_name, which generates identifier
	  names for base_data data items.

compiler/opt_debug.m:
compiler/unify_gen.m:
	- Use new base_data type.

library/io.m:
	- Define io__stream as a c_pointer, so it has base_type_layout
	  and base_type_functors generated for it.

library/mercury_builtin.m:
library/std_util.m:
library/uniq_arry.m:
	- Add definitions for base_type_functors for builtin types, and
	  types defined in C.

runtime/type_info.h:
	- Add definitions for base_type_functors.
	- Modify existing #defines (in particular, offset for type name).
1997-02-23 01:14:20 +00:00
Simon Taylor
857ce0c472 Cleaned up the handling of labels for specialized versions of predicates
Estimated hours taken: 3

Cleaned up the handling of labels for specialized versions of predicates
from other modules.

compiler/llds.m:
        Changed the representation of proc_label slightly.
        Each proc_label now contains the name of the module producing the
        code for a predicate as well as the module containing the declaration
        for the predicate.

compiler/code_util.m:
compiler/llds_out.m:
        Fixed a bug in my last change that resulted in duplicate label
        names for specialized versions of predicates.
        The name of the module producing the code for the predicate
        is added as an extra qualifier in the label for specialised
        versions of predicates from other modules.

compiler/base_type_info.m:
compiler/opt_util.m:
compiler/opt_debug.m:
compiler/shapes.m:
        Fixed uses of proc_label.
1997-01-29 00:48:13 +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
19504f598f Add an extra argument to pragma_c to hold the context of the pragma
Estimated hours taken: 1.5

llds:
	Add an extra argument to pragma_c to hold the context of the pragma
	definition.

llds_out:
	Add code to print the context as a #line directive. This code is
	commented out, since it leads to mysterious crashes on some tests.

pragma_c_gen:
	Fill in the context field in pragma_cs.

dupelim, frameopt, livemap, llds_common, middle_rec, opt_debug, opt_util,
value_number, vn_block, vn_filter, vn_verify:
	Trivial changes to handle the extra argument in pragma_cs.
1997-01-15 01:10:54 +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
Tyson Dowd
1b37ada23c Create base_type_layout structures, which store information about how
Estimated hours taken: 50

Create base_type_layout structures, which store information about how
Mercury data is represented in memory.

compiler/base_type_layout.m:
    Generate base_gen_layouts from HLDS.
    Pass over base_gen_layouts after code generation, create layout
    tables, and pseudo-typeinfos as needed.

compiler/base_type_info.m, compiler/dead_proc_elim.m:
    Allow base_type_infos to be `neutered' rather than eliminated
    by dead_proc_elim. This just removes references to compiler
    generated preds, and replaces them with references to an
    'unused' pred in mercury_builtin, which prints an error
    message if ever used. (The base_type_infos are always needed,
    even if the generated preds aren't, because the layout tables
    refer to them).

compiler/hlds_module.m:
    Add marker for procs eliminated in base_type_infos.
    Add base_gen_layout structure, and access predicates to HLDS.

compiler/llds.m, compiler/llds_out.m, compiler/opt_debug.m:
    Add a base_type_layout data_name, for storing references to
    base_type_layouts. Add output code.

compiler/llds_common.m:
    Get llds_common to process c_data structures given to it.
    (We'll give it the base_type_layouts).

compiler/mercury_compile.m:
    Add a pass to generate and process the base_type_gens.
    Fix a newline in a ... done message.
    Let llds_common work on the base_type_layouts.

compiler/type_util.m:
    Add type_util__var, which returns the type variable of a type
    (if it is a variable at the top level).
1996-12-09 13:50:10 +00:00
Zoltan Somogyi
3aff9711dd Fix a bug triggered the conjunction of (1) value numbering being
Estimated hours taken: 12

value_number, opt_util:
	Fix a bug triggered the conjunction of (1) value numbering being
	repeated in -O5 (2) middle recursion optimization and (3) the
	current code of modules.m. The problem was that although value
	numbering was producing correct code, the livevals annotations
	in the generated code were left unchange although they were
	no longer correct.

	The fix is a new predicate in opt_util to update the annotations
	and to call it in value numbering.

vn_util:
	Fix the bug reported by Tom in compiling scene.m: simplify
	several kinds of patterns involving floats. These assume that
	floats obey the laws of reals. Later we will have to add a mechanism
	to prevent such simplication and reordering. (We already assume
	that integers obey the laws of whole numbers.)

opt_debug, vn_debug:
	Make the format of debugging output more suitable.
1996-11-06 13:01:13 +00:00
Fergus Henderson
c9887d16ea Mangle function names differently, so that we don't get
Estimated hours taken: 2.5

Mangle function names differently, so that we don't get
symbol name clashes between a function of arity N and
a predicate of arity N+1.  (This fixes a bug which resulted
in error messages from the assembler.)

compiler/llds.m:
	Add a new pred_or_func field to the proc/4 functor in
	the proc_label type.
compiler/code_util.m:
	Initialize this new field.
compiler/llds.m:
	Use this new field when printing out labels.
compiler/{opt_debug.m,opt_util.m}:
	Ignore this new field.
1996-10-24 06:07:23 +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
a15c032df7 Flesh out the code already here for traversing module_infos,
Estimated hours taken: 4

passes_aux:
	Flesh out the code already here for traversing module_infos,
	making it suitable to handle all the passes of the back end.

mercury_compile:
	Use the traversal code in passes_aux to invoke the back end passes
	over each procvedure in turn. Print a one-line message for each
	predicate if -v is given (this fixes a long-standing bug).

excess.m, follow_code.m, follow_vars.m, live_vars.m, lveness.m, store_alloc.m:
	Remove the code to traverse module_infos, since it is now unnecessary.

export.m:
	Remove an unused argument from export__produce_header_file_2.

others:
	Move imports from interfaces to implementations, or in some cases
	remove them altogether.
1996-08-03 12:06:26 +00:00
Zoltan Somogyi
5f37b61f79 Add support for det stack trace dumps in debugging grades, so programmers
Estimated hours taken: 2

Add support for det stack trace dumps in debugging grades, so programmers
can find out which predicates are causing det stack overflows.

llds.m:
	Add an extra argument to the llds instruction incr_sp.
	This argument says what predicate the stack frame belongs to.

vn_type.m:
	Add a corresponding argument to the control node vn_incr_sp.

the other files:
	Handle the extra argument of incr_sp or vn_incr_sp.
1996-08-03 09:31:35 +00:00
Simon Taylor
5d9e4158f7 Module qualification of types, insts and modes.
Estimated hours taken: 45

Module qualification of types, insts and modes.

Added a new interface file - <module>.int3. This contains the
short interface qualified as much as possible given the information
in the current module.

When producing the .int and .int2 files for a module, the compiler uses
the information in the .int3 files of modules imported in the interface
to fully module qualify all items. The .int2 file is just a fully
qualified version of the .int3 file. The .int3 file cannot be overwritten
by the fully qualified version in the .int2 file because then mmake would
not be able to tell when the interface files that depend on that .int3
file really need updating.

The --warn-interface-imports option can be used to check whether
a module imported in the interface really needs to be imported in
the interface.


compiler/module_qual.m
Module qualify all types, insts and modes. Also checks for modules
imported in the interface of a module that do not need to be.

compiler/modules.m
The .int file for a module now depends on the .int3 files of imported
modules. Added code to generate the make rule for the .int file in the
.d file. There is now a file .date2 which records the last time the
.int2 file was updated.
The .int3 files are made using the --make-short-interface option
introduced a few weeks ago.

compiler/options.m
Added option --warn-interface-imports to enable warning about interface
imports which need not be in the interface. This is off by default
because a lot of modules in the library import list.m when they only
need the type list, which is defined in mercury_builtin.m.
Removed option --builtin-module, since the mercury_builtin name is wired
into the compiler in a large number of places.

compiler/prog_util.m
Added a predicates construct_qualified_term/3 and construct_qualfied_term/4
which take a sym_name, a list of argument term and a context for the /4
version and give a :/2 term.

compiler/type_util.m
Modified type_to_type_id to handle qualified types. Also added predicates
construct_type/3 and construct_type/4 which take a sym_name and a list of
types and return a type by calling prog_util:construct_qualified_term.

compiler/modes.m
On the first iteration of mode analysis, module qualify the modes of
lambda expressions.

compiler/mode_info.m
Added field to mode_info used to decide whether or not to module qualify
lambda expressions.

compiler/mode_errors.m
Added dummy mode error for when module qualification fails so that mode
analysis will stop.
Added code to strip mercury_builtin qualifiers from error messages to
improve readability.

compiler/typecheck.m
Strip builtin qualifiers from error messages.

compiler/llds.m
compiler/llds_out.m
compiler/opt_util.m
compiler/opt_debug.m
Change the format of labels produced for the predicates to use the
qualified version of the type name.

compiler/mercury_compile.pp
Call module_qual__module_qualify_items and make_short_interface.
Remove references to undef_modes.m and undef_types.m

compiler/undef_modes.m
compiler/undef_types.m
Removed, since their functionality is now in module_qual.m.

compiler/prog_io.m
Changed to qualify the subjects of type, mode and inst declarations.

compiler/*.m
Changes to stop various parts of the compiler from throwing away
module qualifiers.
Qualified various mercury_builtin builtins, e.g. in, out, term etc.
where they are wired in to the compiler.

compiler/hlds_data.m
The mode_table and user_inst_table are now abstract types each
storing the {mode | inst}_id to hlds__{mode | inst}_defn maps
and a list of mode_ids or inst_ids. This was done to improve the
efficiency of module qualifying the modes of lambda expressions
during mode analysis.
module_info_optimize/2 now sorts the lists of ids.
The hlds_module interface to the mode and inst tables has not changed.

compiler/hlds_module.m
Added yet another predicate to search the predicate table.
predicate_table_search_pf_sym_arity searches for predicates or
functions matching the given sym_name, arity and pred_or_func.

compiler/higher_order.m
Changed calls to solutions/2 to list__filter/3. Eliminated unnecessary
requantification of goals.

compiler/unused_args.m
Improved abstraction slightly.
1996-06-11 06:30:10 +00:00
Zoltan Somogyi
7956003f22 Remove the now unnecessary special handling of assignments to curfr.
Estimated hours taken: 0.2

vn*, opt_debug:
	Remove the now unnecessary special handling of assignments to curfr.
1996-05-31 02:11:17 +00:00
Zoltan Somogyi
cac7d6a246 Fix allocation to work properly for --args compact.
Estimated hours taken: 30+

arg_info:
	Fix allocation to work properly for --args compact.

bytecode*:
	Handle complex deconstruction unifications. Not really tested because
	I can't find a test case.

bytecode_gen, call_gen, code_util:
	Use the new method to handle builtin predicates/functions. We now
	handle reverse mode arithmetic and unary plus/minus as builtins.

code_gen, code_init, follow_vars, hlds_pred:
	Put back the initial follow_vars field of the proc_info, since this
	may allow the code generator to emit better code at the starts of
	of predicates.

inlining:
	Don't inline recursive predicates.

goals_util:
	Add a predicate to find out if a goal calls a particular predicate.
	Used in inlining to find out if a predicate is recursive.

unused_args:
	Remove code that used to set the mode of unused args to free->free.
	Since this changes the arg from top_in to top_unused *without* code
	in other modules being aware of the change, this screws up --args
	compact.

llds, llds_out, garbage_out:
	Prepare for the move to the new type_info structure by adding a new
	"module" type for defining structures holding type_infos. Not
	currently generated or output.

llds, opt_debug, opt_util, vn_type, vn_cost, vn_temploc:
	Change the argument of temp to be a reg, not an int, allowing
	floating point temporaries.

vn_type:
	Add information about the number of floating point registers and
	temporaries to the parameter structure (these are currently unused).

llds, dupelim, frameopt, livemap, middle_rec, value_number, vn_filter,
vn_verify:
	Add an extra field to blocks giving the number of float temporaries.

options:
	Add parameters to configure the number of floating point registers
	and temporaries.

mercury_compile:
	Add an extra excess assign phase at the start of the middle pass.
	This should reduce the size of the code manipulated by the other
	phases, and gives more accurate size information to inlining.
	(The excess assign phase before code generation is I think still
	needed since optimizations can introduce such assignments.)

value_number:
	Optimize code sequences before and after assignments to curfr
	separately, since such assignments change the meaning of framevars.
	This fixes the bug that caused singleton variable warnings to contain
	garbage.

vn_block, vn_flush, vn_order, vn_util:
	Add special handling of assignments to curfr. This is probably
	unnecessary after my change to value_number, and will be removed
	again shortly :-(

vn_flush:
	Improve the code generated by value numbering (1) by computing values
	into the place that needs them in some special circumstances, and
	(2) by fixing a bug that did not consider special registers to be
	as fast as r1 etc.

vn_util:
	Improve the code generated by value numbering by removing duplicates
	from the list of uses of a value before trying to find out if there
	is more than one use.

simplify:
	Avoid overzealous optimization of main --> { ..., error(...) }.

handle_options:
	Fix an error message.

code_aux:
	Break an excessive long line.
1996-05-29 10:56:45 +00:00
Zoltan Somogyi
89644bebb2 Fixed a bug that caused restores of succip to be put in the wrong
Estimated hours taken: 5

peephole:
	Fixed a bug that caused restores of succip to be put in the wrong
	place, but only after predicate-wide value numbering.

opt_debug:
	Added a couple of debugging predicates used in tracking down this bug.

value_number:
	Fix a bug that left a livevals pseudo-op in the wrong place if a
	single instruction sequence contained more than one such pseudo-op.

options:
	Add --debug-opt. Rename --vndebug to --debug-vn.
	Add --generate-bytecode.

optimize, vn_debug:
	Use the new routines in opt_debug, and use the new/renamed options.

store_alloc:
	Don't thread follow_vars through the module, since the follow_vars
	information is not attached directly to branched structures. We
	now also use the same slot to hold the store map computed by this
	pass; this should allow the later deletion of the store map slot
	from goal_infos.

follow_code:
	Removed dead predicate.

livemap:
	Added a comment.
1996-05-12 04:51:14 +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
1c90f19e02 Fix a typo which reflected a fundamental design error.
Estimated hours taken: 20

vn_block:
	Fix a typo which reflected a fundamental design error. When finding
	cheaper copies of live lvals, for use in creating specialized copies
	(parallels) of blocks jumped to from the current location, we used
	to use the map reflecting the contents of lvals at the start of the
	block, not at the point of the jump.

	--pred-value-number, which uses the information computed by the
	buggy predicate, actually bootstrapped some time ago despite
	this fundamental bug!

value_number:
	Fix a bug in the creation of parallel code sequences for computed
	gotos. Add some more opprtunities for printing diagnostics.
	Move code concerning final verification to vn_verify.

vn_verify:
	Move the remaining code concerned with final verification from
	value_number to vn_verify.

peephole:
	Add a new pattern, which transforms the sequence

	incr_sp N; goto L2; L1; incr_sp N; L2

	into just

	L1; incr_sp N; L2

	The pattern is of course more broadly applicable, but I have seen
	it only when it involves a single incr_sp between the two labels.
	(The longer pattern can be introduced by frameopt.)

opt_util:
	Look inside blocks when checking whether an instruction can fall
	through. This improves the performance of labelopt.

vn_table:
	Make the type vn_table abstract; add, export and use access functions.

vn_util:
	Remove a noop predicate, since now it won't ever be made to do
	anything.

vn_cost:
	Refine debugging output.

vn_debug:
	Add some more debugging routines.

opt_debug:
	Add some more debugging routines.

det_analysis:
	Remove an unused argument.

labelopt:
	Formatting change.
1996-04-11 01:02:48 +00:00
David Jeffery
126b5c3d64 CLP(R) productions, in conjunction with Arth Guinness productions presents...
A Constraint Solver Interface For Mercury
<thunderous applause>

Estimated hours taken: 1 summer studentship

This is the implementation of a fairly general constraint solver interface. If
using a library grade *.cnstr, we emit C instructions to keep track of the
solver's implicit state. This is done by storing and restoring 'tickets' -
abstract handles on the solver's state.

We emit a store_ticket() macro:
	-when entering the first disjunct of a disjunction
	-when entering the condition of an if-then-else
We emit a restore_ticket() macro:
	-when entering a disjunct other than the first of a disjunction
	-when entering the else part of an if-then-else
We emit a discard_ticket() macro:
	-after the restore_ticket() in the final disjunct of a disjunction
	-at the start of the 'then' part of an if-then-else

The rules for emitting the macros is slightly more complicated than that shown
above for if-then-elses (determinism of the parts must be taken into account).

compiler/code_info.m:
	Get an llds store_ticket/restore_ticket etc. instruction
compiler/disj_gen.m:
	Emit ticket macros in the appropriate places in a disjunction.
compiler/dupelim.m:
	Handle the new llds instruction.
compiler/frameopt.m:
	Handle the new llds instruction.
compiler/handle_options.m:
	If the grade is *.cnstr, set the constraints option on.
compiler/ite_gen.m:
	Emit ticket macros in the appopriate places in an if-then-else.
compiler/livemap.m:
	Handle the new llds instruction.
compiler/llds.m:
	Output the ticket macros.
compiler/make_hlds.m:
	An irrelevant tidy-up.
compiler/mercury_compile.pp:
	If the grade is *.cnstr, pass -DCONSTRAINTS to mgnuc
compiler/middle_rec.m:
	Handle the new llds instruction.
compiler/opt_*.m:
	Handle the new llds instruction.
compiler/options.m:
	Introduce a new boolean option 'constraints'.
compiler/shapes.m:
	Output a new shape - 'ticket'.
compiler/unify_proc.m:
	Handle the new llds instruction.
compiler/v*.m:
	Handle the new llds instruction.
1996-03-26 16:45:12 +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
Zoltan Somogyi
3224e94532 A new pass to remove unnecessary assignment unifications.
excess:
	A new pass to remove unnecessary assignment unifications.

mercury_compile:
	Call the new excess assignment module.

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

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

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

vn_debug:
	Modify an information message.

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

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

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

goal_util:
	Add a new predicate for use by cse_detection.

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

code_info:
	Make an error message more explicit.

det_analysis:
	Restrict import list to the needed modules.

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

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

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

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

*.m: 	handle the new pragma_c_code in the hlds or the new pragma_c in the llds
1995-10-17 11:13:13 +00:00
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
Zoltan Somogyi
eef27b6a67 Removed the caller argument from the call, call_closure and goto LLDS
instructions, and the last argument from local labels. All these were
placeholders for info put in there by prof.m and used when emitting C
code.

The set of labels that serve as return points are now calculated in llds.m
just before each procedure has its C code generated. This set is passed to
output_instruction along with the label at the start of the procedure.
1995-09-05 10:16:19 +00:00
Fergus Henderson
760b99015c Another big batch of changes for higher-order predicates.
This set of changes includes most of the work necessary for
mode and determinism checking of higher-order predicates.

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

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

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

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

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

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

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

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

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

mercury_to_mercury.m:
	Export mercury_output_det for use by hlds_out.m.
1995-08-26 20:04:46 +00:00
Zoltan Somogyi
1708fd6adc Make the teardown map bidirectional, and export it.
frameopt:
	Make the teardown map bidirectional, and export it.

peephole:
	Add a new pattern to handle cases generated by fulljump optimization.
	This pattern uses the teardownmap, but it is disabled for the moment.

optimize:
	Pass the teardown map where it is needed, and make sure we do a
	peephole pass immediately after frameopt to use the teardownmap
	while it is still valid.

jumpopt:
	Rename a variable.

labelopt:
	A block being eliminated may have the last remaining reference
	to the label starting another block. Therefore on the last invocation
	of labelopt, we iterate to a fixpoint before returning.

opt_debug:
	Add a predicate to help debug bidirectional teardown maps.

opt_util:
	Liberalized some optimizations, but the changes are disabled for the
	moment.

value_number:
	Pass an empty teardown map to peephole. Loosen the sanity check on
	tags a bit.

vn_order:
	If the new value of a location depends on its old value,
	avoid creating a circularity in the preferred order relation.
	Such circularity may be broken arbitrarily, even though we have
	a clear preference.

vn_flush:
	Modify the criteria for saving the old value stored in a location
	about to be overwritten, in an effort to eliminate useless copies
	of old values.

vn_util:
	Tighten the requirement for classifying a use as a "real" use,
	also in the effort to eliminate useless saves of old values.
	Recognize some more expression patterns as yieldsing known
	results. Move some functionality from vn_flush to vn_util,
	since it is needed by the other modification.
1995-08-25 12:56:54 +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
Zoltan Somogyi
7a3e35af3b Sort the list of interface files before printing them to a .d file.
mercury_compile:
	Sort the list of interface files before printing them to a .d file.

opt_util, peephole:
	Fix a bug tickled by value numbering. Some sequences of code were
	recognized as having no access to nondet stack control slots even
	in the presence of such accesses, which lead to the incorrect
	introduction of succeed_discards.

value_number:
	Loosen the value correspondence sanity check, which was failing
	needlessly, and tighten the tag sanity check, which was passing
	incorrect code.

	Do not try value numbering on blocks containing structures such as
	"if (tag(x) == X && field(X, x, X) == X) goto X", since these will
	definitely lead to tag sanity check violations.

vn_flush:
	If a shared node has no uses left when flushed, leave it be.
	When generating a mkframe, reflect its update of the top redoip slot
	in the data structures.

vn_order:
	Some hacks to get the relmaps partway to where I want them. This
	code needs cleaning up.

vn_debug:
	New debugging routines to support my changes to vn_order.

vn_type:
	Deleted the vn_modframe vn_instr, since its role has been taken over
	by assignments to redoip(maxfr).

opt_debug:
	Reflect the change to vn_type, print address constants in vn_rvals,
	and fix a typo.

vn_block, vn_util:
	Reflect the change to vn_type.
1995-06-22 01:44:11 +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
07d8bcb6c3 Implement solutions/2. (We still haven't implemented mode/determinism
arg_info.m call_gen.m hlds.m hlds_out.m llds.m opt_debug.m vn_type.m:
  Implement solutions/2.  (We still haven't implemented mode/determinism
  checking for higher-order preds, though, so the compiler doesn't
  diagnose errors correctly - if you use the wrong mode you will probably
  just get a core dump.)

  This required moving the definition of code_model from hlds.m to llds.m.

mercury_to_goedel.m:
  Avoid determinism warning.
1995-04-18 04:00:37 +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
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
77b16b11d9 Implement floating point.
code_util.nl, float.nl, llds.nl, mercury_builtin.nl, opt_debug.nl,
parser.nl, polymorphism.nl, sp_lib.nl, string.nl, string.nu.nl,
type_util.nl, typecheck.nl, unify_gen.nl:
	Implement floating point.

Makefile.common:
	Remove `-include test.dep' line.  Use Mmake.

int.nl:
	Update a few of the comments.

io.nu.nl:
	For Sicstus Prolog, if main/2 is not defined then enter the
	debugger.
1995-03-15 14:28:24 +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
10ca65a82c Removed the predicates that need NU-Prolog, both the definitions
opt_debug, jumpopt, vn_order:
	Removed the predicates that need NU-Prolog, both the definitions
	and the (already commented out) calls to them.

value_number:
	Updated the comments.

vn_block:
	When creating parallels, ordered the rval list corresponding to an
	lval by the cost of the rvals.
1995-03-13 00:23:13 +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
a985616b96 Replaced curredoip with redoip(rval) to make references to other
llds, code_info, opt_*, vn*:
	Replaced curredoip with redoip(rval) to make references to other
	redoips more efficient. Also, by turning modframe(L) into
	redoip(curfr) = const(address_const(L)), value_number can now
	optimize hijacking code better.

vn*:
	If a disagreement on the desired value of an lvalue prevents value
	number, try again after skipping to the first control point, since
	this may cure the problem.

peephole, opt_util:
	Now looking for successive modframes to optimize out.

disj_gen:
	Put deterministic alternatives before others, mainly to make
	the back mode of append easier to explain in the paper. :-(

mode_util:
	Fixed scope error.

garbage_out:
	Fixed some spelling and formatting errors.
1995-02-20 07:54:00 +00:00
Fergus Henderson
79c214bb50 Handle the `curfr' register (which was recently added to llds.nl).
opt_debug.nl vn_flush.nl vn_temploc.nl vn_type.nl vn_util.nl:
	Handle the `curfr' register (which was recently added to llds.nl).
1995-02-16 05:55:46 +00:00
Fergus Henderson
56c4d2cbc4 The fields in a `type_info' structure should be just
code_info.nl hlds.nl hlds_out.nl io.nl llds.int llds.nl opt_debug.nl
polymorphism.nl shapes.nl switch_gen.nl unify_gen.nl:
	The fields in a `type_info' structure should be just
	procedure addresses, not closures.
1995-02-08 19:09:41 +00:00
Peter Ross
73f5a811a5 Added an extra argument for profiling to call in llds.nl and
*.nl :
	Added an extra argument for profiling to call in llds.nl and
	propogated this throught out all the necessary files.
1995-02-08 05:14:13 +00:00
Fergus Henderson
f862db3245 Lots of changes to implement compare/3.
*.nl:
	Lots of changes to implement compare/3.
1995-02-07 07:48:28 +00:00
Fergus Henderson
62fa8be865 Add new targets `mercury_compile.sicstus' (the Mercury compiler
Makefile.common:
	Add new targets `mercury_compile.sicstus' (the Mercury compiler
	compiled with Sicstus) and `mercury_compile.sicstus.debug'
	(debugging version of the above).

*.nl:
	Use Sicstus-compatible char and string escapes.
	Avoid the use of explicit existential quantification.
	Various other hacks to get things to parse correctly under Sicstus.

prog_io.nl:
	Don't allow (A -> B) in DCGs, since NU-Prolog and Mercury give
	it different semantics to Sicstus.

sp_builtin.nl, sp_lib.nl:
	Split sp_builtin.nl into sp_builtin.nl and sp_lib.nl.

sp_conv.sed:
	Add sed script which converts some character escapes so that
	they work with Sicstus.

term_io.nl:
	Remove term_io__prefix_op etc. since they aren't used anymore.
1995-01-31 06:00:16 +00:00
Zoltan Somogyi
20b4534e38 Got value numbering working. Isolated diagnostic messages in separate
vn_*:
	Got value numbering working. Isolated diagnostic messages in separate
	file.

llds:
	During output, transform x + -const into x - const, since some
	compilers may not recognize the pattern and may use several
	instructions to build up a negative constant.

atsort:
	Added predicates for transitive closure.

frameopt:
	Fixed a performance bug introduced by previous change.
1995-01-28 04:44:13 +00:00
Zoltan Somogyi
b1168dab5e Divided value_number and vn_util into several smaller modules, since they
were getting too big.
1995-01-26 05:34:16 +00:00
Zoltan Somogyi
0d8fccaecc Fixed a bug with allowed incr_hp to overwrite its target without saving
value_number, vn_util, opt_util, opt_debug:
	Fixed a bug with allowed incr_hp to overwrite its target without saving
	it. Reorganized the handling of incr_sp and decr_sp to make sure they
	never get reordered with respect to control flow instructions.

llds:
	Fixed the output of temp declarations for blocks.

frameopt:
	Generalized the set up patterns accepted as starting a det procedure.

labelopt:
	Added a source-level option to remove eliminated instructions instead
	of turning them into comments, and made it the default.

optimize:
	After value numbering, perform jump optimization as well as peepholing
	and label optimization.
1995-01-25 10:30:42 +00:00