Commit Graph

193 Commits

Author SHA1 Message Date
Peter Wang
b86f973fa9 Allow the use of Mercury abstract machine float registers for passing
Branches: main

Allow the use of Mercury abstract machine float registers for passing
double-precision float arguments in higher order calls.

In of itself this is not so useful for typical Mercury code.  However, as
all non-local procedures are potentially the targets of higher order calls,
without this change first order calls to non-local procedures could not use
float registers either.  That is the actual motivation for this change.

The basic mechanism is straightforward.  As before, do_call_closure_* is
invoked to place the closure's hidden arguments into r1, ..., rN, and extra
input arguments shifted into rN+1, etc.  With float registers, extra input
arguments may also be in f1, f2, etc. and the closure may also have hidden
float arguments.  Optimising for calls, we order the closure's hidden
arguments so that all float register arguments come after all regular
register arguments in the vector.  Having the arguments out of order does
complicate code which needs to deconstruct closures, but that is not so
important.

Polymorphism complicates things.  A closure with type pred(float) may be
passed to a procedure expecting pred(T).  Due to the `float' argument type,
the closure expects its argument in a float register.  But when passed to the
procedure, the polymorphic argument type means it would be called with the
argument in a regular register.

Higher-order insts already contain information about the calling convention,
without which a higher-order term cannot be called.  We extend higher-order
insts to include information about the register class required for each
argument.  For example, we can distinguish between:

	pred(in) is semidet /* arg regs: [reg_f] */
and
	pred(in) is semidet /* arg regs: [reg_r] */

Using this information, we can create a wrapper around a higher-order
variable if it appears in a context requiring a different calling convention.
We do this in a new HLDS pass, called float_regs.m.

Note: Mercury code has a tendency to lose insts for higher-order terms, then
"recover" them by hacky means.  The float_regs pass depends on higher-order
insts; it is impossible to create a wrapper for a procedure without knowing
how to call it.  The float_regs pass will report errors which we otherwise
accepted, due to higher-order insts being unavailable.  It should be possible
for the user to adjust the code to satisfy the pass, though the user may not
understand why it should be necessary.  In most cases, it probably really
*is* unnecessary.  We may be able to make the float_regs pass more tolerant
of missing higher-order insts in the future.

Class method calls do not use float registers because I didn't want to deal
with them yet.


compiler/options.m:
compiler/handle_options.m:
	Always enable float registers in low-level C grades when floats are
	wider than a word.

compiler/make_hlds_passes.m:
	Always allow double word floats to be stored unboxed in cells on C
	grades.

compiler/hlds_goal.m:
	Add an extra field to `generic_call' which gives the register class
	to use for each argument.  This is set by the float_regs pass.

compiler/prog_data.m:
	Add an extra field to `pred_inst_info' which records the register class
	to use for each argument.  This is set by the float_regs pass.

compiler/hlds_pred.m:
	Add a field to `proc_sub_info' which lists the headvars which must be
	passed via regular registers despite their types.

	Add a field to `pred_sub_info' to record the original unsubstituted
	argument types for instance method predicates.

compiler/check_typeclass.m:
	In the pred_info of an instance method predicate, record the original
	argument types before substituting the type variables for the instance.

compiler/float_regs.m:
compiler/transform_hlds.m:
	Add the new HLDS pass.

compiler/mercury_compile_middle_passes.m:
	Run the new pass if float registers are enabled.

compiler/lambda.m:
	Export the predicate to produce a predicate from a lambda.
	This is reused by float_regs.m to create wrapper closures.

	Add an argument to `expand_lambda' to set the reg_r_headvars field on
	the newly created procedure.

	Delete some unused fields from `lambda_info'.

compiler/arg_info.m:
	Make `generate_proc_arg_info' no longer always use regular registers
	for calls to exported procedures.  Do always use regular registers for
	class methods calls.

	Add a version of `make_arg_infos' which takes an explicit list of
	argument registers.  Rename the previous version.

	Add `generic_call_arg_reg_types' to return the argument registers
	for a generic call.

	Add a version of `compute_in_and_out_vars' which additionally separates
	arguments for float and regular registers.

compiler/call_gen.m:
	Use float registers for argument passing in higher-order calls, as
	directed by the new field in `generic_call'.

compiler/code_util.m:
	Add a function to encode the number of regular and float register
	arguments when making a higher-order call.

compiler/llds.m:
	Say that the `do_call_closure_N' functions only work for zero float
	register arguments.

compiler/follow_vars.m:
compiler/interval.m:
	Account for the use of float registers by generic call goals in these
	passes.

compiler/unify_gen.m:
	Move float register arguments to the end of a closure's hidden
	arguments vector, after regular register arguments.

	Count hidden regular and float register arguments separately, but
	encode them in the same word in the closure.  This is preferable to
	using two words because it reduces the differences between grades
	with and without float registers present.

	Disable generating code which creates a closure from an existing
	closure, if float registers exist.  That code does not understand the
	reordered hidden arguments vector yet.

compiler/continuation_info.m:
	Replace an argument's type_info in the closure layout if the argument
	is a float *and* is passed via a regular register, when floats are
	normally passed via float registers.  Instead, give it the type_info
	for `private_builtin.float_box'.

compiler/builtin_lib_types.m:
	Add function to return the type of `private_builtin.float_box/0'.

compiler/hlds_out_goal.m:
compiler/hlds_out_pred.m:
compiler/mercury_to_mercury.m:
	Dump the new fields added to `generic_call', `pred_inst_info' and
	`proc_sub_info'.

compiler/prog_type.m:
	Add helper predicate.

compiler/*.m:
	Conform to changes.

library/private_builtin.m:
	Add a type `float_box'.

runtime/mercury_ho_call.h:
	Describe the modified closure representation.

	Rename the field which counts the number of hidden arguments to prevent
	it being used incorrectly, as it now encodes two numbers (potentially).

	Add macros to unpack the encoded field.

runtime/mercury_ho_call.c:
	Update the description of how higher-order calls work.

	Update code which extracts closure arguments to take account the
	arguments being reordered in the hidden arguments vector.

runtime/mercury_deep_copy.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_layout_util.c:
runtime/mercury_ml_expand_body.h:
	Update code which extracts closure arguments to take account the
	arguments being reordered in the hidden arguments vector.

runtime/mercury_type_info.c:
runtime/mercury_type_info.h:
	Add helper function.

tools/make_spec_ho_call:
	Update the generated do_call_closure_* functions to place float
	register arguments.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/ho_float_reg.exp:
tests/hard_coded/ho_float_reg.m:
	Add new test case.

tests/hard_coded/copy_pred.exp:
tests/hard_coded/copy_pred.m:
tests/hard_coded/deconstruct_arg.exp:
tests/hard_coded/deconstruct_arg.exp2:
tests/hard_coded/deconstruct_arg.m:
	Extend test cases with float arguments in closures.

tests/debugger/higher_order.exp2:
	Add alternative output, changed due to closure wrapping.

tests/hard_coded/ho_univ_to_type.m:
	Adjust test case so that the float_regs pass does not report errors
	about missing higher-order insts.

compiler/notes/compiler_design.html:
	Describe the new module.

	Delete a duplicated paragraph.

compiler/notes/todo.html:
TODO:
	Delete one hundred billion year old todos.
2012-02-13 00:11:57 +00:00
Paul Bone
0c0e5486c9 Fix a number of bugs in dependent parallel conjunctions and loop control.
Don't transform left-recursive parallel loops into right-recursive loops when
loop control is enabled.

compiler/par_conj_gen.m:
    If a loop control scope instantiates a non-local variable that is not
    protected by a future ensure that it has a stack slot allocated, and that
    the code_info state (used by the code generator) knows where this variable
    will be on the stack so that once it is needed it can be used.
    An example of this is the variable Y in list.map.

    Use a correctly-sized (but not compressed) stack frame for the spawned off
    code.

    Fix a silly typeo that prevented get_future goals from being added when
    they where needed.

    Tidy up some code.

compiler/code_util.m:
compiler/opt_util.m:
    Move instr_get_rvals_and_lvals from opt_util.m to code_util.m and export it
    so that it can be used by par_conj_gen.  Modify this predicate so that it
    stores rvals and lvals in sets, hopefully reducing the number of rvals and
    lvals that need to be represented.

compiler/dep_par_conj.m:
    Because left recursion has historically been faster than right recursion,
    we used to detect when it was possible to transform right into left
    recursion (by swapping the conjuncts in a parallel conjunction).  Now that
    loop control is effective we disable this hack when loop control is
    enabled.

    This change made it easy for me to test non tail-recursive loop control
    cases like list.map

compiler/live_vars.m:
    When a parallel conjunction is transformed into a loop control scope and
    then liveness analysis is applied it mis-calculates the death of variables
    that die in the loop control scope.

    map_foldl(M, F, [X | Xs], !Acc) :-
        spawn_off(
            M(X, Y),
            F(Y, !Acc)
        ),
        ...
        some_other_code_that_needs_stack_slots,
        ...
        map_foldl(M, F, Xs, !Acc).

    X dies after the call to M (post death), Similarly Y dies after the call to
    F, depending on dep_par_conj.m Y may also need a stack slot.  However,
    since M is executing in parallel with
    some_other_code_that_needs_stack_slots, the stack slots used by X and Y are
    still being used by the spawned off code.  And they may continue to be used
    up to the recursive call.  It is okay if they die within the spawned off
    scope, but according to the some_other_code_that_needs_stack_slots, they
    need to be alive.  so that they have correctly allocated stack slots.  They
    may then die after the recursive call (at which point the barrier for the
    spawned off code will have completed).

    live_vars.m therefore tracks these variables and delays their death (after
    resurrecting them at the end of the scope) until the recursive call.

    Part of this should probably be handled in liveness.m, however the loop
    control scope will still need to resurrect these variables.  Additionally
    there is already code in live_vars to recognize loop control scopes and
    their implicit barriers.
2011-10-21 00:16:21 +00:00
Peter Wang
2ccac171dd Add float registers to the Mercury abstract machine, implemented as an
Branches: main

Add float registers to the Mercury abstract machine, implemented as an
array of MR_Float in the Mercury engine structure.

Float registers are only useful if a Mercury `float' is wider than a word
(i.e. when using double precision floats on 32-bit platforms) so we let them
exist only then.  In other cases floats may simply be passed via the regular
registers, as before.

Currently, higher order calls still require the use of the regular registers
for all arguments.  As all exported procedures are potentially the target of
higher order calls, exported procedures must use only the regular registers for
argument passing.  This can lead to more (un)boxing than if floats were simply
always boxed.  Until this is solved, float registers must be enabled explicitly
with the developer only option `--use-float-registers'.

The other aspect of this change is using two consecutive stack slots to hold a
single double variable.  Without that, the benefit of passing unboxed floats
via dedicated float registers would be largely eroded.


compiler/options.m:
	Add developer option `--use-float-registers'.

compiler/handle_options.m:
	Disable `--use-float-registers' if floats are not wider than words.

compiler/make_hlds_passes.m:
	If `--use-float-registers' is in effect, enable a previous change that
	allows float constructor arguments to be stored unboxed in structures.

compiler/hlds_llds.m:
	Move `reg_type' here from llds.m and `reg_f' option.

	Add stack slot width to `stack_slot' type.

	Add register type and stack slot width to `abs_locn' type.

	Remember next available float register in `abs_follow_vars'.

compiler/hlds_pred.m:
	Add register type to `arg_loc' type.

compiler/llds.m:
	Add a new kind of lval: double-width stack slots.
	These are used to hold double-precision floating point values only.

	Record setting of `--use-float-registers' in exprn_opts.

	Conform to addition of float registers and double stack slots.

compiler/code_info.m:
	Make predicates take the register type as an argument,
	where it can no longer be assumed.

	Remember whether float registers are being used.

	Remember max float register for calls to MR_trace.

	Count double width stack slots as two slots.

compiler/arg_info.m:
	Allocate float registers for procedure arguments when appropriate.

	Delete unused predicates.

compiler/var_locn.m:
	Make predicates working with registers either take the register type as
	an argument, or handle both register types at once.

	Select float registers for variables when appropriate.

compiler/call_gen.m:
	Explicitly use regular registers for all higher-order calls,
	which was implicit before.

compiler/pragma_c_gen.m:
	Use float registers, when available, at the interface between Mercury
	code and C foreign_procs.

compiler/export.m:
	Whether a float rval needs to be boxed/unboxed when assigned to/from a
	register depends on the register type.

compiler/fact_table.m:
	Use float registers for arguments to predicates defined by fact tables.

compiler/stack_alloc.m:
	Allocate two consecutive stack slots for float variables when
	appropriate.

compiler/stack_layout.m:
	Represent double-width stack slots in procedure layout structures.

	Conform to changes.

compiler/store_alloc.m:
	Allocate float registers (if they exist) for float variables.

compiler/use_local_vars.m:
	Substitute float abstract machine registers with MR_Float local
	variables.

compiler/llds_out_data.m:
compiler/llds_out_instr.m:
	Output float registers and double stack slots.

compiler/code_util.m:
compiler/follow_vars.m:
	Count float registers separately from regular registers.

compiler/layout.m:
compiler/layout_out.m:
compiler/trace_gen.m:
	Remember the max used float register for calls to MR_trace().

compiler/builtin_lib_types.m:
	Fix incorrect definition of float_type_ctor.

compiler/bytecode_gen.m:
compiler/continuation_info.m:
compiler/disj_gen.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/hlds_out_goal.m:
compiler/jumpopt.m:
compiler/llds_to_x86_64.m:
compiler/lookup_switch.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/proc_gen.m:
compiler/string_switch.m:
compiler/tag_switch.m:
compiler/tupling.m:
compiler/x86_64_regs.m:
	Conform to changes.

runtime/mercury_engine.h:
	Add an array of fake float "registers" to the Mercury engine structure,
	when MR_Float is wider than MR_Word.

runtime/mercury_regs.h:
	Document float registers in the Mercury abstract machine.

	Add macros to access float registers in the Mercury engine.

runtime/mercury_stack_layout.h:
	Add new MR_LongLval cases to represent double-width stack slots.

	MR_LONG_LVAL_TAGBITS had to be increased to accomodate the new cases,
	which increases the number of integers in [0, 2^MR_LONG_LVAL_TAGBITS)
	equal to 0 modulo 4.  These are the new MR_LONG_LVAL_TYPE_CONS_n cases.

	Add max float register field to MR_ExecTrace.

runtime/mercury_layout_util.c:
runtime/mercury_layout_util.h:
	Extend MR_copy_regs_to_saved_regs and MR_copy_saved_regs_to_regs
	for float registers.

	Understand how to look up new kinds of MR_LongLval: MR_LONG_LVAL_TYPE_F
	(previously unused), MR_LONG_LVAL_TYPE_DOUBLE_STACKVAR,
	MR_LONG_LVAL_TYPE_DOUBLE_FRAMEVAR.

	Conform to the new MR_LONG_LVAL_TYPE_CONS_n cases.

runtime/mercury_float.h:
	Delete redundant #ifdef.

runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
	Conform to changes (untested).

trace/mercury_trace.c:
trace/mercury_trace.h:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
trace/mercury_trace_spy.c:
trace/mercury_trace_vars.c:
trace/mercury_trace_vars.h:
	Handle float registers in the trace subsystem.  This is mostly a matter
	of saving/restoring them as with regular registers.
2011-10-17 04:31:33 +00:00
Peter Wang
4c2846593a Make it possible to store double-precision `float' constructor arguments in
Branches: main

Make it possible to store double-precision `float' constructor arguments in
unboxed form, in low-level C grades on 32-bit platforms, i.e. `float' (and
equivalent) arguments may occupy two machine words. However, until we implement
float registers, this does more harm than good so it remains disabled.

compiler/llds.m:
	Add a type `cell_arg' to hold information about an argument of a cell
	being constructed.

	Change `heap_ref' so that we can refer to a pointer with an unknown
	tag.

compiler/unify_gen.m:
	Use the `cell_arg' type to simplify code related to generating
	constructions.

	Handle double word arguments in constructions and deconstructions.

	Update enumeration packing code to account for the presence of double
	width arguments and the `cell_arg' type.

	Take double width arguments into account when generating ground terms.

compiler/code_info.m:
	Extend `assign_field_lval_expr_to_var' to work for expressions
	involving multiple field lvals of the same variable.

	Make `assign_cell_to_var' conform to changes.

compiler/code_util.m:
	Add a predicate to calculate the size of a cell given its cell_args.

compiler/var_locn.m:
	Conform to the use of the `cell_arg' type and the presense of double
	width arguments.

	Calculate cell size correctly in places.

	Move sanity checking from `var_locn_assign_field_lval_expr_to_var'
	to `code_info.assign_field_lval_expr_to_var'.

compiler/global_data.m:
	Make `rval_type_as_arg' take into account the width of the argument.

	Conform to changes.

compiler/c_util.m:
	Add a new binop category.  Unlike the existing macro_binop category,
	the arguments of macros in this category cannot all be assumed to be
	of integral types.

compiler/llds_out_data.m:
compiler/llds_out_instr.m:
	Output calls to the macros `MR_float_word_bits', `MR_float_from_dword'
	and `MR_float_from_dword_ptr' which were introduced previously.

	When a `heap_ref' has an unknown tag, make the generated code mask off
	the tag bits.

compiler/lco.m:
	Disable the optimisation when float arguments are present, on the basis
	of whether Mercury floats are wider than a machine word.  The comments
	about when floats are stored in boxed form are out of date.

compiler/arg_pack.m:
	Rename a predicate.

compiler/make_hlds_passes.m:
	Update a comment.

compiler/disj_gen.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/llds_to_x86_64.m:
compiler/lookup_switch.m:
compiler/mlds_to_c.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/stack_layout.m:
compiler/string_switch.m:
	Conform to changes.

runtime/mercury_float.h:
	Add a cast to `MR_float_word_bits' to avoid a gcc error.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/heap_ref_mask_tag.exp:
tests/hard_coded/heap_ref_mask_tag.m:
tests/hard_coded/reuse_double.exp:
tests/hard_coded/reuse_double.m:
	Add test cases.

tests/hard_coded/lookup_disj.exp:
tests/hard_coded/lookup_disj.m:
	Extend existing test case.
2011-09-16 07:03:36 +00:00
Zoltan Somogyi
295415090e Convert almost all remaining modules in the compiler to use
Estimated hours taken: 6
Branches: main

compiler/*.m:
	Convert almost all remaining modules in the compiler to use
	"$module, $pred" instead of "this_file" in error messages.

	In a few cases, the old error message was misleading, since it
	contained an incorrect, out-of-date or cut-and-pasted predicate name.

tests/invalid/unresolved_overloading.err_exp:
	Update an expected output containing an updated error message.
2011-05-23 05:08:24 +00:00
Zoltan Somogyi
1c3bc03415 Make the system compiler with --warn-unused-imports.
Estimated hours taken: 2
Branches: main, release

Make the system compiler with --warn-unused-imports.

browser/*.m:
library/*.m:
compiler/*.m:
	Remove unnecesary imports as flagged by --warn-unused-imports.

	In some files, do some minor cleanup along the way.
2010-12-30 11:18:04 +00:00
Zoltan Somogyi
8a28e40c9b Add the predicates sorry, unexpected and expect to library/error.m.
Estimated hours taken: 2
Branches: main

Add the predicates sorry, unexpected and expect to library/error.m.

compiler/compiler_util.m:
library/error.m:
	Move the predicates sorry, unexpected and expect from compiler_util
	to error.

	Put the predicates in error.m into the same order as their
	declarations.

compiler/*.m:
	Change imports as needed.

compiler/lp.m:
compiler/lp_rational.m:
	Change imports as needed, and some minor cleanups.

deep_profiler/*.m:
	Switch to using the new library predicates, instead of calling error
	directly. Some other minor cleanups.

NEWS:
	Mention the new predicates in the standard library.
2010-12-15 06:30:36 +00:00
Zoltan Somogyi
d4bbcda309 Move all the frequently occurring layout structures and components of layout
Estimated hours taken: 40
Branches: main

Move all the frequently occurring layout structures and components of layout
structures into arrays where possible. By replacing N global variables holding
individual layout structures or layout structure components with one global
variable holding an array of them, we reduce the sizes of the symbol tables
stored in object files, which should speed up both the C compiler and the
linker.

Measured on the modules of the library, mdbcomp and compiler directories
compiled in grade asm_fast.gc.debug, this diff reduces the size of the
generated C source files by 7.8%, the size of the generated object files
by 10.4%, and the number of symbols in the symbol tables of those object files
by a whopping 42.8%. (These improvements include, and are not on top of,
the improvements in my previous similar diff.)

runtime/mercury_stack_layout.h:
	Each label layout structure has information about the type and
	location of every variable that is live at that label. We store
	this information in three arrays: an array of pseudo-typeinfos giving
	the types of all these variables, and two arrays MR_ShortLvals and
	MR_LongLvals respectively giving their locations. (Most of the time,
	the location's encoded form fits into one byte (the MR_ShortLval)
	but sometimes it needs more bits (this is when we use MR_LongLval)).

	We used to store these three arrays, whose elements are different
	types, in a single occurrence-specific common structure,
	one after the other, with a cumbersome mechanism being required
	to access them. We now store them as segments of three separate arrays,
	of pseudo-typeinfos, MR_ShortLvals and MR_LongLvals respectively.
	This makes access simpler and faster (which will matter more to any
	accurate garbage collector than it does to the debugger). It also
	allows more scope for compression, since reusing an existing segment of
	one of the three arrays is easier than reusing an entire common
	structure, which would require the equivalent of exact matches
	on all three arrays.

	Since most label layout structures that have information about
	variables can encode the variables' locations using only MR_ShortLvals,
	create a version of the label layout structure type that omits the
	field used to record the whereabouts of the long location descriptors.

	Add macros now generated by the compiler to initialize layout
	structures.

	Simplify a one-field struct.

runtime/mercury_grade.h:
	Increment the binary compatibility version number for debuggable
	executables, since .c and .o files from before and after the change
	to label layout structures are NOT compatible.

runtime/mercury_type_info.h:
	Fix some binary-compatibility-related bit rot.

runtime/mercury_misc.h:
	Move here the existing macros used by the compiler when generating
	references to layout arrays, and add new ones.

runtime/mercury_goto.h:
	Delete the macros moved to mercury_misc.h.
	Conform to the changes in mercury_stack_layout.h.

runtime/Mmakefile:
	Prevent the unnecessary rebuilding of mercury_conf.h.

runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
runtime/mercury_layout_util.c:
runtime/mercury_stack_trace.c:
runtime/mercury_types.h:
trace/mercury_trace.c:
trace/mercury_trace_vars.c:
	Conform to the changes in mercury_stack_layout.h.

runtime/mercury_wrapper.c:
	Improve the debug support a bit.

runtime/mercury_engine.h:
	Fix style.

compiler/layout.m:
	Make the change described at the top. Almost all layout structures
	are now in arrays. The only exceptions are those that occur rarely,
	and proc layouts, whose names need to be derivable from the name
	of the procedure itself.

	Instead of having a single type "layout_data" that can represent
	different kinds of single global variables (not array slots), have
	different kinds for different purposes. This makes the code clearer
	and allows traversals that do not have to skip over inapplicable kinds
	of layout structures.

compiler/layout_out.m:
	Output the new arrays.

compiler/stack_layout.m:
	Generate the new arrays. Previously, an individual term generated by
	stack_layout.m could represent several components of a layout
	structure, with the components separated by layout_out.m. We now
	do the separation in stack_layout.m itself, adding each component
	to the array to which it belongs.

	Instead of passing around a single stack_layout_info structure,
	pass around several smaller one. This is preferable, since I found out
	the hard way that including everything in one structure would give the
	structure 51 fields. Most parts of the module work with only one
	or two of these structures, which makes their role clearer.

	Cluster related predicates together.

compiler/options.m:
doc/user_guide.texi:
	Add an option that control whether stack_layout.m will attempt to
	compress the layout arrays that can meaningfully be comressed.

compiler/llds.m:
	Remove the old distinction between a data_addr and a data_name,
	replacing both types with a single new one: data_id. Since different
	kinds of data_names were treated differently in many places,
	the distinction in types (which was intended to allow us to process
	data_addrs that wrapped data_names differently from other kinds of
	data_addrs) wasn't buying us anything anymore.

	The new data_id type allows for the possibility that the code generator
	wants to generate a reference to an address it does not know yet,
	because it is a slot in a layout array, and the slot has not been
	allocated yet.

	Add the information from which the new layout array structures
	will be generated to the LLDS.

compiler/llds_out.m:
	Call layout_out.m to output the new layout arrays.

	Adapt the decl_id type to the replacement of data_addrs by data_ids.
	Don't both keeping track of the have-vs-have-not-declared status
	of structures that are always declared at the start.

	When writing out a data_addr, for some kinds of data_addr, llds_out.m
	would write out the name of the relevant variable, while for some other
	kinds, it would write out its address. This diff separates out those
	those things into separate predicates, each of which behaves
	consistently.

compiler/mercury_compile_llds_back_end.m:
	Convey the intended contents of the new layout arrays from
	stack_layout.m to llds_out.m.

compiler/continuation_info.m:
	Add a type required by the way we now generate proc_static structures
	for deep profiling.

compiler/hlds_rtti.m:
	Add distinguishing prefixes to the field names of the rtti_proc_label
	type.

compiler/code_info.m:
compiler/code_util.m:
compiler/erl_rtti.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/ll_pseudo_type_info.m:
compiler/ml_code_util.m:
compiler/opt_debug.m:
compiler/proc_gen.m:
compiler/prog_rep.m:
compiler/rtti_out.m:
compiler/unify_gen.m:
	Conform to the changes above.

tests/debugger/declarative/track_through_catch.exp:
	Expect procedures to be listed in the proper order.

tests/EXPECT_FAIL_TESTS.asm_fast.gc.debug:
tests/EXPECT_FAIL_TESTS.asm_fast.gc.profdeep:
	Add these files to ignore expected failues in these grades.
2009-10-30 03:33:34 +00:00
Zoltan Somogyi
c58fd846d4 A temporary fix Mantis bug #87, which caused all programs compiled with
Estimated hours taken: 12 (mostly in diagnosis)
Branches: main

A temporary fix Mantis bug #87, which caused all programs compiled with
deep profiling to get a sanity check violation when writing out the deep
profiling data.

My detective work tracked the first reported call site that got this violation,
which is in integer.m in the library, where the predicate integer.to_string
calls the function string.++.

(a) String.++ is marked (correctly) as opt_imported.
(b) The test predicate pred_info_is_imported FAILS for opt_imported predicates.
(c) This causes make_rtti_proc_label to put "no" into the pred_is_imported
    field of the rtti_proc_label for string.++.
(d) This rtti_proc_label is put into the element of the call_site_static_data
    list for integer.to_string that corresponds to the call to string.++
    as the rtti_proc_label of the callee.
(e) When the time comes to write out the call_site_static structures,
    layout_out.m invokes make_proc_label_from_rtti to convert this
    rtti_proc_label in the call_site_static_data to a plain, non-RTTI
    proc_label. However, since the current module name ("integer") does not
    match the name of the module that defines the function ("string") AND
    the function is not marked as imported, make_user_proc_label (invoked
    from make_proc_label_from_rtti) believes that this means that this module
    generates code for the callee (as we do for some opt_imported procedures).
(f) For procedures for which we generate target code in a different module
    than their defining module, we generate different labels for them
    than the label for the code for the procedure in its own module.
    We derive the name of a procedure's proc_static structure directly from
    its label, so this difference holds for the names of proc_static structures
    as well as for labels.
(g) This lead to the problem, which was that the call_site_static for this call
    site referred to the proc_static for string.++ defined in integer.c
    (as opposed to string.++ defined in string.c), since integer.c did not
    actually generate code for string.++, there was no such proc_static.
    This should be a link error, but it isn't, due to the requirement on unix
    linkers of being compatible with Fortran's ancient semantics (specifically,
    Fortran's common areas). Instead, the C compiler happily allocates memory
    for the undefined symbol and fills it with zeros as if it were a
    proc_static structure.
(h) The assertion violation in mercury_deep_profiling.c occurs because the
    call_site_static refers to this bogus proc_static, but of course no module
    writes out this proc_static.

It turns out that deep_profiling.m and the code generator both use the same
algorithm to turn the pred_proc_id of string.++ into a label, but the relevant
input to this algorithm, the import_status of string.++, changes between
the invocation of the deep_profiling transformation and the code generator.
The import_status is changed by the dead procedure elimination pass;
it shouldn't be, but it is. The reason why the bug started showing up recently
is my recent diff that moved the dead_procedure elimination pass after the deep
profiling pass.

The temporary fix is to make sure that the deep profiling pass sees the same
status for each procedure as the code generator, by making it invoke the dead
procedure elimination pass itself.

The right fix is to change the representation of import_status, designing it
properly for the first time, but that will take more time. This redesign should
eliminate the need for the dead procedure eliminate pass to change any
statuses.

compiler/deep_profiling.m:
	Make the fix described above.

	Print progress message only with -V, not -v, since this is what
	all the other passes do.

compiler/hlds_out.m:
	When writing out a procedure's deep profiling information, include
	the data structures from which we later construct the procedure's
	proc_static and call_site_static structures.

compiler/code_util.m:
	Replace some if-then-elses with switches.

compiler/proc_label.m:
	Don't export a function that is not used anywhere else.

compiler/type_ctor_info.m:
	Delete a predicate to avoid an ambiguity.
2008-11-03 03:08:02 +00:00
Zoltan Somogyi
0c5c99ee07 Convert some predicates into functions, to make them easier to use.
Estimated hours taken: 0.5
Branches: main

compiler/code_util.m:
	Convert some predicates into functions, to make them easier to use.

compiler/code_info.m:
compiler/reassign.m:
compiler/use_local_vars.m:
compiler/var_locn.m:
	Conform to the change in code_util.m.
2008-09-03 03:32:19 +00:00
Zoltan Somogyi
b000cb322e Provide compiler support for Software Transactional Memory through the new
Estimated hours taken: 80 by zs, and lots more by lmika
Branches: main

Provide compiler support for Software Transactional Memory through the new
atomic goal. This work was done by Leon Mika; I merely brought it up to date,
resolved conflicts, and cleaned up a few things. There are still several
aspects that are as yet incomplete.

library/ops.m:
	Add the operators needed for the syntax of atomic scopes.

library/stm_builtin.m:
	Add the builtin operations needed for the implementation of atomic
	goals.

compiler/hlds_goal.m:
	Add a new HLDS goal type, which represents an atomic goal and its
	possible fallbacks (in case an earlier goal throws an exception).

	Rename the predicate goal_is_atomic as goal_expr_has_subgoals,
	since now its old name would be misleading.

compiler/prog_data.m:
compiler/prog_item.m:
	Add a parse tree representation of the new kind of goal.

compiler/prog_io_goal.m:
	Parse the new kind of goal.

compiler/add_clause.m:
	Translate atomic goals from parse tree form to HLDS.

compiler/typecheck.m:
compiler/typecheck_errors.m:
	Do type checking of atomic goals.

compiler/modes.m:
	Do mode checking of atomic goals, and determine whether they are nested
	or not.

compiler/unique_modes.m:
	Do unique mode checking of atomic goals.

compiler/stm_expand.m:
	New module to expand atomic goals into sequences of simpler goals.

library/stm_builtin.m:
	Add the primitives needed by the transformation.

	Improve the existing debugging support.

mdbcomp/prim_data.m:
	Add utility functions to allow stm_expand.m to refer to modules in the
	library.

mdbcomp/program_representation.m:
	Expand the goal_path type to allow the representation of components of
	atomic goals.

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

compiler/transform_hlds.m:
	Include the new module in the compiler.

compiler/mercury_compile.m:
	Invoke the STM transformation.

compiler/hlds_module.m:
	Add an auxiliary counter used by the STM transformation.

compiler/hlds_pred.m:
	Add a new predicate origin: the STM transformation.

compiler/modules.m:
	Import the STM builtin module automatically if the module contains any
	atomic goals.

compiler/assertion.m:
compiler/bytecode_gen.m:
compiler/clause_to_proc.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/code_util.m:
compiler/constraint.m:
compiler/cse_detection.m:
compiler/deep_profiling.m:
compiler/code_util.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/distance_granularity.m:
compiler/equiv_type_hlds.m:
compiler/erl_code_gen.m:
compiler/exception_analysis.m:
compiler/follow_code.m:
compiler/format_call.m:
compiler/goal_form.m:
compiler/goal_path.m:
compiler/goal_util.m:
compiler/granularity.m:
compiler/hlds_out.m:
compiler/implicit_parallelism.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/layout_out.m:
compiler/lco.m:
compiler/lookup_switch.m:
compiler/make_hlds_warn.m:
compiler/mark_static_terms.m:
compiler/mercury_to_mercury.m:
compiler/middle_rec.m:
compiler/ml_code_gen.m:
compiler/mode_constraint_robdd.m:
compiler/mode_constraints.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/mode_util.m:
compiler/ordering_mode_constraints.m:
compiler/pd_cost.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/prog_rep.m:
compiler/prog_type.m:
compiler/prop_mode_constraints.m:
compiler/rbmm.actual_region_arguments.m:
compiler/rbmm.add_rbmm_goal_info.m:
compiler/rbmm.condition_renaming.m:
compiler/rbmm.execution_path.m:
compiler/rbmm.points_to_analysis.m:
compiler/rbmm.region_transformation.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/size_prog.m:
compiler/smm_common.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.indirect.m:
compiler/structure_reuse.lbu.m:
compiler/structure_reuse.lfu.m:
compiler/structure_reuse.versions.m:
compiler/structure_sharing.analysis.m:
compiler/switch_detection.m:
compiler/unused_imports.m:
compiler/granularity.m:
compiler/granularity.m:
	Conform to the changes above. Mostly this means handling the new
	kind of goal.

compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/build_mode_constraints.m:
compiler/closure_analysis.m:
compiler/dead_proc_elim.m:
compiler/deforest.m:
compiler/follow_vars.m:
compiler/higher_order.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/loop_inv.m:
compiler/module_qual.m:
compiler/prog_util.m:
compiler/purity.m:
compiler/quantification.m:
compiler/store_alloc.m:
compiler/stratify.m:
compiler/tabling_analysis.m:
compiler/term_constr_build.m:
compiler/term_pass1.m:
compiler/term_traversal.m:
compiler/trailing_analysis.m:
	Conform to the changes above. Mostly this means handling the new
	kind of goal.

	Switch syntax from clauses to disj.

runtime/mercury_stm.[ch]:
	Implement the primitives needed by the STM transformation.

	Add more debugging support to the existing primitives.

library/term.m:
	Generalize get_term_context to work on terms of all kinds.
2008-02-27 07:23:57 +00:00
Zoltan Somogyi
cc88711d63 Implement true multi-cons_id arm switches, i.e. switches in which we associate
Estimated hours taken: 40
Branches: main

Implement true multi-cons_id arm switches, i.e. switches in which we associate
more than one cons_id with a switch arm. Previously, for switches like this:

	(
		X = a,
		goal1
	;
		( X = b
		; X = c
		),
		goal2
	)

we duplicated goal2. With this diff, goal2 won't be duplicated. We still
duplicate goals when that is necessary, i.e. in cases which the inner
disjunction contains code other than a functor test on the switched-on var,
like this:

	(
		X = a,
		goal1
	;
		(
			X = b,
			goalb
		;
			X = c
			goalc
		),
		goal2
	)

For now, true multi-cons_id arm switches are supported only by the LLDS
backend. Supporting them on the MLDS backend is trickier, because some MLDS
target languages (e.g. Java) don't support the concept at all. So when
compiling to MLDS, we still duplicate the goal in switch detection (although
we could delay the duplication to just before code generation, if we wanted.)

compiler/options.m:
	Add an internal option that tells switch detection whether to look for
	multi-cons_id switch arms.

compiler/handle_options.m:
	Set this option based on the back end.

	Add a version of the "trans" dump level that doesn't print unification
	details.

compiler/hlds_goal.m:
	Extend the representation of switch cases to allow more than one
	cons_id for a switch arm.

	Add a type for representing switches that also includes tag information
	(for use by the backends).

compiler/hlds_data.m:
	For du types, record whether it is possible to speed up tests for one
	cons_id (e.g. cons) by testing for the other (nil) and negating the
	result. Recording this information once is faster than having
	unify_gen.m trying to compute it from scratch for every single
	tag test.

	Add a type for representing a cons_id together with its tag.

compiler/hlds_out.m:
	Print out the cheaper_tag_test information for types, and possibly
	several cons_ids for each switch arm.

	Add some utility predicates for describing switch arms in terms of
	which cons_ids they are for.

	Replace some booleans with purpose-specific types.

	Make hlds_out honor is documentation, and not print out detailed
	information about unifications (e.g. uniqueness and static allocation)
	unless the right character ('u') is present in the control string.

compiler/add_type.m:
	Fill in the information about cheaper tag tests when adding a du type.

compiler/switch_detection.m:
	Extend the switch detection algorithm to detect multi-cons_id switch
	arms.

	When entering a switch arm, update the instmap to reflect that the
	switched-on variable can now be bound only to the cons_ids that this
	switch arm is for. We now need to do this, because if the arm contains
	another switch on the same variable, computing the can_fail field of
	that switch correctly requires us to know this information.
	(Obviously, an arm for a single cons_id is unlikely to have switch on
	the same variable, and for arms for several cons_ids, we previously
	duplicated the arm and left the unification with the cons_id in each
	copy, and this unification allowed the correct handling of any later
	switches. However, the code of a multi-cons_id switch arm obviously
	cannot have a unification with each cons_id in it, which is why
	we now need to get the binding information from the switch itself.)

	Replace some booleans with purpose-specific types, and give some
	predicates better names.

compiler/instmap.m:
	Provide predicates for recording that a switched-on variable has
	one of several given cons_ids, for use at the starts of switch arms.

	Give some predicates better names.

compiler/modes.m:
	Provide predicates for updating the mode_info at the start of a
	multi-cons_id switch arm.

compiler/det_report.m:
	Handle multi-cons_id switch arms.

	Update the instmap when entering each switch arm, since this is needed
	to provide good (i.e. non-misleading) error messages when one switch on
	a variable exists inside another switch on the same variable.

	Since updating the instmap requires updating the module_info (since
	the new inst may require a new entry in an inst table), thread the
	det_info through as updateable state.

	Replace some multi-clause predicate definitions with single clauses,
	to make it easier to print the arguments in mdb.

	Fix some misleading variable names.

compiler/det_analysis.m:
	Update the instmap when entering each switch arm and thread the
	det_info through as updateable state, since the predicates we call
	in det_report.m require this.

compiler/det_util.m:
	Handle multi-cons_id switch arms.

	Rationalize the argument order of some access predicates.

compiler/switch_util.m:
	Change the parts of this module that deal with string and tag switches
	to optionally convert each arm to an arbitrary representation of the
	arm. In the LLDS backend, the conversion process generated code for
	the arm, and the arm's representation is the label at the start of
	this code. This way, we can duplicate the label without duplicating
	the code.

	Add a new part of this module that associates each cons_id with its
	tag, and (during the same pass) checks whether all the cons_ids are
	integers, and if so what are min and max of these integers (needed
	for dense switches). This scan is needed because the old way of making
	this test had single-cons_id switch arms as one of its basic
	assumptions, and doing it while adding tags to each case reduces
	the number of traversals required.

	Give better names to some predicates.

compiler/switch_case.m:
	New module to handle the tasks associated with managing multi-cons_id
	switch arms, including representing them for switch_util.m.

compiler/ll_backend.m:
	Include the new module.

compiler/notes/compiler_design.html:
	Note the new module.

compiler/llds.m:
	Change the computed goto instruction to take a list of maybe labels
	instead of a list of labels, with any missing labels meaning "not
	reached".

compiler/string_switch.m:
compiler/tag_switch.m:
	Reorganize the way these modules work. We can't generate the code of
	each arm in place anymore, since it is now possible for more than one
	cons_id to call for the execution of the same code. Instead, in
	string_switch.m, we generate the codes of all the arms all at once,
	and construct the hash index afterwards. (This approach simplifies
	the code significantly.)

	In tag switches (unlike string switches), we can get locality benefits
	if the code testing for a cons_id is close to the code for that
	cons_id, so we still try to put them next to each other when such
	a locality benefit is available.

	In both modules, the new approach uses a utility predicate in
	switch_case.m to actually generate the code of each switch arm,
	eliminating several copies the same code in the old versions of these
	modules.

	In tag_switch.m, don't create a local label that simply jumps to the
	code address do_not_reached. Previously, we had to do this for
	positions in jump tables that corresponded to cons_ids that the switch
	variable could not be bound to. With the change to llds.m, we now
	simply generate a "no" instead.

compiler/lookup_switch.m:
	Get the info about int switch limits from our caller; don't compute it
	here.

	Give some variables better names.

compiler/dense_switch.m:
	Generate the codes of the cases all at once, then assemble the table,
	duplicate the labels as needed. This separation of concerns allows
	significant simplifications.

	Pack up all the information shared between the predicate that detects
	whether a dense switch is appropriate and the predicate that actually
	generates the dense switch.

	Move some utility predicates to switch_util.

compiler/switch_gen.m:
	Delete the code for tagging cons_ids, since that functionality is now
	in switch_util.m.

	The old version of this module could call the code generator to produce
	(i.e. materialize) the switched-on variable repeatedly. We now produce
	the variable once, and do the switch on the resulting rval.

compiler/unify_gen.m:
	Use the information about cheaper tag tests in the type constructor's
	entry in the HLDS type table, instead of trying to recompute it
	every time.

	Provide the predicates switch_gen.m now needs to perform tag tests
	on rvals, as opposed to variables, and against possible more than one
	cons_id.

	Allow the caller to provide the tag corresponding to the cons_id(s)
	in tag tests, since when we are generating code for switches, the
	required computations have already been done.

	Factor out some code to make all this possible.

	Give better names to some predicates.

compiler/code_info.m:
	Provide some utility predicates for the new code in other modules.
	Give better names to some existing predicates.

compiler/hlds_code_util.m:
	Rationalize the argument order of some predicates.

	Replace some multi-clause predicate definitions with single clauses,
	to make it easier to print the arguments in mdb.

compiler/accumulator.m:
compiler/add_heap_ops.m:
compiler/add_pragma.m:
compiler/add_trail_ops.m:
compiler/assertion.m:
compiler/build_mode_constraints.m:
compiler/check_typeclass.m:
compiler/closure_analysis.m:
compiler/code_util.m:
compiler/constraint.m:
compiler/cse_detection.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/distance_granularity.m:
compiler/dupproc.m:
compiler/equiv_type_hlds.m:
compiler/erl_code_gen.m:
compiler/exception_analysis.m:
compiler/export.m:
compiler/follow_code.m:
compiler/follow_vars.m:
compiler/foreign.m:
compiler/format_call.m:
compiler/frameopt.m:
compiler/goal_form.m:
compiler/goal_path.m:
compiler/goal_util.m:
compiler/granularity.m:
compiler/hhf.m:
compiler/higher_order.m:
compiler/implicit_parallelism.m:
compiler/inlining.m:
compiler/inst_check.m:
compiler/intermod.m:
compiler/interval.m:
compiler/lambda.m:
compiler/lambda.m:
compiler/lambda.m:
compiler/lco.m:
compiler/live_vars.m:
compiler/livemap.m:
compiler/liveness.m:
compiler/llds_out.m:
compiler/llds_to_x86_64.m:
compiler/loop_inv.m:
compiler/make_hlds_warn.m:
compiler/mark_static_terms.m:
compiler/middle_rec.m:
compiler/ml_tag_switch.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mode_constraints.m:
compiler/mode_errors.m:
compiler/mode_util.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/pd_cost.m:
compiler/pd_into.m:
compiler/pd_util.m:
compiler/peephole.m:
compiler/polymorphism.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/purity.m:
compiler/quantification.m:
compiler/rbmm.actual_region_arguments.m:
compiler/rbmm.add_rbmm_goal_infos.m:
compiler/rbmm.condition_renaming.m:
compiler/rbmm.execution_paths.m:
compiler/rbmm.points_to_analysis.m:
compiler/rbmm.region_transformation.m:
compiler/recompilation.usage.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/ssdebug.m:
compiler/store_alloc.m:
compiler/stratify.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/structure_reuse.indirect.m:
compiler/structure_reuse.lbu.m:
compiler/structure_reuse.lfu.m:
compiler/structure_reuse.versions.m:
compiler/structure_sharing.analysis.m:
compiler/table_gen.m:
compiler/tabling_analysis.m:
compiler/term_constr_build.m:
compiler/term_norm.m:
compiler/term_pass1.m:
compiler/term_traversal.m:
compiler/trailing_analysis.m:
compiler/transform_llds.m:
compiler/tupling.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unneeded_code.m:
compiler/untupling.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
	Make the changes necessary to conform to the changes above, principally
	to handle multi-cons_id arm switches.

compiler/ml_string_switch.m:
	Make the changes necessary to conform to the changes above, principally
	to handle multi-cons_id arm switches.

	Give some predicates better names.

compiler/dependency_graph.m:
	Make the changes necessary to conform to the changes above, principally
	to handle multi-cons_id arm switches. Change the order of arguments
	of some predicates to make this easier.

compiler/bytecode.m:
compiler/bytecode_data.m:
compiler/bytecode_gen.m:
	Make the changes necessary to conform to the changes above, principally
	to handle multi-cons_id arm switches. (The bytecode interpreter
	has not been updated.)

compiler/prog_rep.m:
mdbcomp/program_representation.m:
	Change the byte sequence representation of goals to allow switch arms
	with more than one cons_id. compiler/prog_rep.m now writes out the
	updated representation, while mdbcomp/program_representation.m reads in
	the updated representation.

deep_profiler/mdbprof_procrep.m:
	Conform to the updated program representation.

tools/binary:
	Fix a bug: if the -D option was given, the stage 2 directory wasn't
	being initialized.

	Abort if users try to give that option more than once.

compiler/Mercury.options:
	Work around bug #32 in Mantis.
2007-12-30 08:24:23 +00:00
Zoltan Somogyi
672f77c4ec Add a new compiler option. --inform-ite-instead-of-switch.
Estimated hours taken: 20
Branches: main

Add a new compiler option. --inform-ite-instead-of-switch. If this is enabled,
the compiler will generate informational messages about if-then-elses that
it thinks should be converted to switches for the sake of program reliability.

Act on the output generated by this option.

compiler/simplify.m:
	Implement the new option.

	Fix an old bug that could cause us to generate warnings about code
	that was OK in one duplicated copy but not in another (where a switch
	arm's code is duplicated due to the case being selected for more than
	one cons_id).

compiler/options.m:
	Add the new option.

	Add a way to test for the bug fix in simplify.

doc/user_guide.texi:
	Document the new option.

NEWS:
	Mention the new option.

library/*.m:
mdbcomp/*.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
	Convert if-then-elses to switches at most of the sites suggested by the
	new option. At the remaining sites, switching to switches would have
	nontrivial downsides. This typically happens with the switched-on type
	has many functors, and we treat one or two specially (e.g. cons/2 in
	the cons_id type).

	Perform misc cleanups in the vicinity of the if-then-else to switch
	conversions.

	In a few cases, improve the error messages generated.

compiler/accumulator.m:
compiler/hlds_goal.m:
	(Rename and) move insts for particular kinds of goal from
	accumulator.m to hlds_goal.m, to allow them to be used in other
	modules. Using these insts allowed us to eliminate some if-then-elses
	entirely.

compiler/exprn_aux.m:
	Instead of fixing some if-then-elses, delete the predicates containing
	them, since they aren't used, and (as pointed out by the new option)
	would need considerable other fixing if they were ever needed again.

compiler/lp_rational.m:
	Add prefixes to the names of the function symbols on some types,
	since without those prefixes, it was hard to figure out what type
	the switch corresponding to an old if-then-else was switching on.

tests/invalid/reserve_tag.err_exp:
	Expect a new, improved error message.
2007-11-23 07:36:01 +00:00
Zoltan Somogyi
fcf0847a91 My previous fix to dead proc elimination helped fixed some compiler aborts,
Estimated hours taken: 8
Branches: main

My previous fix to dead proc elimination helped fixed some compiler aborts,
but a related problem remained.

The problem involved an unused procedure that was kept around so that the code
generator would create the table associated with it. Since the procedure was
unused, its body was thought to be unused too. If it contained a reference to a
procedure that wasn't referred to from anywhere else, that procedure would be
removed, leaving a dangling reference. This would cause a code generator abort.

We can't fix the abort by replacing the kept-around procedure's body with
"true", since that would cause a different code generator abort when moving the
(now unbound) output variables to their argument registers. We could avoid
generating any code for the procedure at all by e.g. marking it as
opt_imported, but this would (a) be inconsistent and (b) require special case
coding to still generate the table structure.

The fix is to generate the global variable used for tabling *independently* of
the procedure that enters things in the table.

compiler/hlds_module.m:
	Add a field to the module_info (actually module_sub_info) that records
	the information the backends need to create the global variables
	representing call tables.

	Name all the fields of the module_info and module_sub_info during
	initialization, to make it easier to know where to add a new field.
	Put the initializations of the fields in the same order as the fields
	themselves.

compiler/hlds_pred.m:
	Keep only the info for I/O tabling in procedures, since such tabling
	does not require defining a per-procedure global variable.

	Since the info for the forms of tabling that *do* require a
	per-procedure global variable are now divorced from the procedure,
	change their definition to avoid storing prog_vars in them, since
	those prog_vars would be separated from their varset. Instead, we
	record their numbers and their names (both are used only for debug
	support).

	On the other hand, some info from the pred_info and proc_info are
	to create the global variable; copy them into the data structure stored
	in hlds_module.

	Rename some fields to avoid ambiguities.

compiler/table_gen.m:
	Continue to record information about I/O tabling in the proc_info,
	but record information about other forms of tabling in the new field
	in the module_info.

compiler/rtti.m:
compiler/hlds_rtti.m:
	Move the functions for constructing and deconstructing rtti_proc_labels
	from rtti.m (which is in backend_libs) to hlds_rtti.m (which is in
	hlds); the definition of rtti_proc_label was already in hlds_rtti.m.
	The move is needed to allow table_gen to put an rtti_proc_label
	in the data structures it puts in the module_info.

compiler/hlds_out.m:
	Print out the new module_info field, and conform to the change to
	hlds_pred and table_arg_info.

	Always print variable numbers for type variables in table_arg_infos.

compiler/continuation_info.m:
	Make room for either kind of tabling info for a procedure.
	(While the LLDS code generator doesn't need to know about the global
	variable representing the call table in order to create it, it does
	need to know about it in order to describe it to the debugger.)

	Conform to the change in table_arg_info.

	Rename some fields to avoid ambiguities.

compiler/proc_gen.m:
	When generating code for procedures, do not try to create a
	per-procedure tabling struct, but do fill in the slot describing it
	in the continuation_info.

	Add a predicate to define all the tabling structs in a module.

compiler/mercury_compile.m:
	Call proc_gen separately to define all the tabling structs.

compiler/ml_code_gen.m:
	As with proc_gen, define tabling structs directly from the module_info
	and not when generating code from each proc_info.

	(The code for handling each proc is now logically not contiguous;
	I will address that in a separate change, to make the diff for this one
	easier to read.)

compiler/dead_proc_elim.m:
	Don't keep unused tabled procedures alive, since that leads to the
	problem described up top.

	Keep track of which tabling structs are live, but don't yet act on that
	information, since some uses are hidden (for now).

	Add conditionally compiled tracing code that helped me trace down the
	problem.

	Fix an oversight in the severity level of an error spec.

compiler/base_typeclass_info.m:
compiler/code_util.m:
compiler/deep_profiling.m:
compiler/ml_code_util.m:
compiler/proc_label.m:
compiler/type_ctor_info.m:
	Conform to the move of make_rtti_proc_label.

compiler/optimize.m:
	Conform to the change to continuation_info.

compiler/stack_layout.m:
	Conform to the data structure changes above.

doc/user_guide.texi:
	Document 'Z' as the character in -D arguments that tells hlds_out
	to dump the global structures needed for tabling.

	Fix an old oversight: document 'S' as the character in -D arguments
	that tells hlds_out to dump info about structure sharing.

compiler/handle_options.m:
	Include 'Z' in -DALL -and -Dall.

tests/tabling/mercury_java_parser_dead_proc_elim_bug.{m,exp}:
	Move this test case here from valid, since compiling all the way to
	executable doesn't work in valid (in yields link errors unrelated to
	the bug we are testing for).

tests/tabling/mercury_java_parser_dead_proc_elim_bug2.{m,exp}:
	Add this new test case that in unfixed compilers gives the problem
	described up top.

tests/tabling/Mmakefile:
	Enable the new tests.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
tests/valid/mercury_java_parser_dead_proc_elim_bug.m:
	Remove references to the moved test and the test itself.
2007-08-13 03:02:02 +00:00
Zoltan Somogyi
168f531867 Add new fields to the goal_info structure for region based memory management.
Estimated hours taken: 4
Branches: main

Add new fields to the goal_info structure for region based memory management.
The fields are currently unused, but (a) Quan will add the code to fill them
in, and then (b) I will modify the code generator to use the filled in fields.

compiler/hlds_goal.m:
	Make the change described above.

	Group all the procedures that access goal_info components together.
	Some of the getters were predicates while some were functions, so
	this diff changes them all to be functions. (The setters remain
	predicates.)

compiler/*.m:
	Trivial changes to conform to the change in hlds_goal.m.

	In simplify.m, break up a huge (800+ line) predicate into smaller
	pieces.
2007-08-07 07:10:09 +00:00
Zoltan Somogyi
ba93a52fe7 This diff changes a few types from being defined as equivalent to a pair
Estimated hours taken: 10
Branches: main

This diff changes a few types from being defined as equivalent to a pair
to being discriminated union types with their own function symbol. This
was motivated by an error message (one of many, but the one that broke
the camel's back) about "-" being used in an ambiguous manner. It will
reduce the number of such messages in the future, and will make compiler
data structures easier to inspect in the debugger.

The most important type changed by far is hlds_goal, whose function symbol
is now "hlds_goal". Second and third in importance are llds.instruction
(function symbol "llds_instr") and prog_item.m's item_and_context (function
symbol "item_and_context"). There are some others as well.

In several places, I rearranged predicates to factor the deconstruction of
goals into hlds_goal_expr and hlds_goal_into out of each clause into a single
point. In many places, I changed variable names that used "Goal" to refer
to just hlds_goal_exprs to use "GoalExpr" instead. I also changed variable
names that used "Item" to refer to item_and_contexts to use "ItemAndContext"
instead. This should make reading such code less confusing.

I renamed some function symbols and predicates to avoid ambiguities.

I only made one algorithmic change (at least intentionally).
In assertion.m, comparing two goals for equality now ignores goal_infos
for all kinds of goals, whereas previously it ignored them for most kinds
of goals, but for shorthand goals it was insisting on them being equal.
This seemed to me to be a bug. Pete, can you confirm this?
2007-01-06 09:23:59 +00:00
Julien Fischer
b4c3bb1387 Clean up in unused module imports in the Mercury system detected
Estimated hours taken: 3
Branches: main

Clean up in unused module imports in the Mercury system detected
by --warn-unused-imports.

analysis/*.m:
browser/*.m:
deep_profiler/*.m:
compiler/*.m:
library/*.m:
mdbcomp/*.m:
profiler/*.m:
slice/*.m:
	Remove unused module imports.

	Fix some minor departures from our coding standards.

analysis/Mercury.options:
browser/Mercury.options:
deep_profiler/Mercury.options:
compiler/Mercury.options:
library/Mercury.options:
mdbcomp/Mercury.options:
profiler/Mercury.options:
slice/Mercury.options:
	Set --no-warn-unused-imports for those modules that are used as
	packages or otherwise break --warn-unused-imports, e.g. because they
	contain predicates with both foreign and Mercury clauses and some of
	the imports only depend on the latter.
2006-12-01 15:04:40 +00:00
Zoltan Somogyi
e21193c283 Rename a bunch of predicates and function symbols to eliminate
Estimated hours taken: 6
Branches: main

browser/*.m:
compiler/*.m:
	Rename a bunch of predicates and function symbols to eliminate
	ambiguities.

	The only real change is factoring out some common code in the mlds
	and llds code generators, replacing them with single definitions
	in switch_util.m.
2006-10-15 23:26:56 +00:00
Peter Wang
712027f307 This patch changes the parallel execution mechanism in the low level backend.
Estimated hours taken: 100
Branches: main

This patch changes the parallel execution mechanism in the low level backend.
The main idea is that, even in programs with only moderate parallelism, we
won't have enough processors to exploit it all.  We should try to reduce the
cost in the common case, i.e. when a parallel conjunction gets executed
sequentially.  This patch does two things along those lines:

(1) Instead of unconditionally executing all parallel conjuncts (but the last)
in separate Mercury contexts, we allow a context to continue execution of the
next conjunct of a parallel conjunction if it has just finished executing the
previous conjunct.  This saves on allocating unnecessary contexts, which can
be a big reduction in memory usage.

We also try to execute conjuncts left-to-right so as to minimise the
need to suspend contexts when there are dependencies between conjuncts.

(2) Conjuncts that *are* executed in parallel still need separate contexts.
We used to pass variable bindings to those conjuncts by flushing input
variable values to stack slots and copying the procedure's stack frame to the
new context.  When the conjunct finished, we would copy new variable bindings
back to stack slots in the original context.

What happens now is that we don't do any copying back and forth.  We introduce
a new abstract machine register `parent_sp' which points to the location of
the stack pointer at the time that a parallel conjunction began.  In parallel
conjuncts we refer to all stack slots via the `parent_sp' pointer, since we
could be running on a different context altogether and `sp' would be pointing
into a new detstack.  Since parallel conjuncts now share the procedure's stack
frame, we have to allocate stack slots such that all parallel conjuncts in a
procedure that could be executing simultaneously have distinct sets of stack
slots.  We currently use the simplest possible strategy, i.e. don't allow
variables in parallel conjuncts to reuse stack slots.

Note: in effect parent_sp is a frame pointer which is only set for and used by
the code of parallel conjuncts.  We don't call it a frame pointer as it can be
confused with "frame variables" which have to do with the nondet stack.


compiler/code_info.m:
	Add functionality to keep track of how deep inside of nested parallel
	conjunctions the code generator is.

	Add functionality to acquire and release "persistent" temporary stack
	slots.  Unlike normal temporary stack slots, these don't get implicitly
	released when the code generator's location-dependent state is reset.

	Conform to additions of `parent_sp' and parent stack variables.

compiler/exprn_aux.m:
	Generalise the `substitute_lval_in_*' predicates by
	`transform_lval_in_*' predicates.  Instead of performing a fixed
	substitution, these take a higher order predicate which performs some
	operation on each lval.  Redefine the substitution predicates in terms
	of the transformation predicates.

	Conform to changes in `fork', `join_and_terminate' and
	`join_and_continue' instructions.

	Conform to additions of `parent_sp' and parent stack variables.

	Remove `substitute_rval_in_args' and `substitute_rval_in_arg' which
	were unused.

compiler/live_vars.m:
	Introduce a new type `parallel_stackvars' which is threaded through
	`build_live_sets_in_goal'.  We accumulate the sets of variables which
	are assigned stack slots in each parallel conjunct.  At the end of
	processing a parallel conjunction, use this information to force
	variables which are assigned stack slots to have distinct slots.

compiler/llds.m:
	Change the semantics of the `fork' instruction.  It now takes a single
	argument: the label of the next conjunct after the current one.  The
	instruction now "sparks" the next conjunct to be run, either in a
	different context (possibly in parallel, on another Mercury engine) or
	is queued to be executed in the current context after the current
	conjunct is finished.

	Change the semantics of the `join_and_continue' instruction.  This
	instruction now serves to end all parallel conjuncts, not just the
	last one in a parallel conjunction.

	Remove the `join_and_terminate' instruction (no longer used).

	Add the new abstract machine register `parent_sp'.

	Introduce "parent stack slots", which are similar to normal stack
	slots but relative to the `parent_sp' register.

compiler/par_conj_gen.m:
	Change the code generated for parallel conjunctions.  That is:

	- use the new `fork' instruction at the beginning of a parallel
	  conjunct;

	- use the `join_and_continue' instruction at the end of all parallel
	  conjuncts;

	- keep track of how deep the code generator currently is in parallel
	  conjunctions;

	- set and restore the `parent_sp' register when entering a non-nested
	  parallel conjunction;

	- after generating the code of a parallel conjunct, replace all
	  references to stack slots by parent stack slots;

	- remove code to copy back output variables when a parallel conjunct
	  finishes.

	Update some comments.

runtime/mercury_context.c:
runtime/mercury_context.h:
	Add the type `MR_Spark'.  Sparks are allocated on the heap and contain
	enough information to begin execution of a single parallel conjunct.

	Add globals `MR_spark_queue_head' and `MR_spark_queue_tail'.  These
	are pointers to the start and end of a global queue of sparks.  Idle
	engines can pick up work from this queue in the same way that they can
	pick up work from the global context queue (the "run queue").

	Add new fields to the MR_Context structure.  `MR_ctxt_parent_sp' is a
	saved copy of the `parent_sp' register for when the context is
	suspended.  `MR_ctxt_spark_stack' is a stack of sparks that we decided
	not to put on the global spark queue.

	Update `MR_load_context' and `MR_save_context' to save and restore
	`MR_ctxt_parent_sp'.

	Add the counters `MR_num_idle_engines' and
	`MR_num_outstanding_contexts_and_sparks'.  These are used to decide,
	when a `fork' instruction is reached, whether a spark should be put on
	the global spark queue (with potential for parallelism but also more
	overhead) or on the calling context's spark stack (no parallelism and
	less overhead).

	Rename `MR_init_context' to `MR_init_context_maybe_generator'.  When
	initialising contexts, don't reset redzones of already allocated
	stacks.  It seems to be unnecessary (and the reset implementation is
	buggy anyway, though it's fine on Linux).

	Rename `MR_schedule' to `MR_schedule_context'.  Add new functions
	`MR_schedule_spark_globally' and `MR_schedule_spark_locally'.

	In `MR_do_runnext', add code for idle engines to get work from the
	global spark queue.  Resuming contexts are prioritised over sparks.

	Rename `MR_fork_new_context' to `MR_fork_new_child'.  Change the
	definitions of `MR_fork_new_child' and `MR_join_and_continue' as per
	the new behaviour of the `fork' and `join_and_continue' instructions.
	Delete `MR_join_and_terminate'.

	Add a new field `MR_st_orig_context' to the MR_SyncTerm structure to
	record which context originated the parallel conjunction instance
	represented by a MR_SyncTerm instance, and update `MR_init_sync_term'.
	This is needed by the new behaviour of `MR_join_and_continue'.

	Update some comments.

runtime/mercury_engine.h:
runtime/mercury_regs.c:
runtime/mercury_regs.h:
runtime/mercury_stacks.h:
	Add the abstract machine register `parent_sp' and code to copy it to
	and from the fake_reg array.

	Add a macro `MR_parent_sv' to access stack slots via `parent_sp'.

	Add `MR_eng_parent_sp' to the MercuryEngine structure.

runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
	Add Mercury runtime option `--max-contexts-per-thread' which is saved
	in the global variable `MR_max_contexts_per_thread'.  The number
	`MR_max_outstanding_contexts' is derived from this.  It sets a soft
	limit on the number of sparks we put in the global spark queue,
	relative to the number of threads we are running.  We don't want to
	put too many sparks on the global queue if there are plenty of ready
	contexts or sparks already on the global queues, as they are likely to
	result in new contexts being allocated.

	When initially creating worker engines, wait until all the worker
	engines have acknowledged that they are idle before continuing.  This
	is mainly so programs (especially benchmarks and test cases) with only
	a few fork instructions near the beginning of the program don't
	execute the forks before any worker engines are ready, resulting in no
	parallelism.

runtime/mercury_engine.c:
runtime/mercury_thread.c:
	Don't allocate a context at the time a Mercury engine is created.  An
	engine only needs a new context when it is about to pick up a spark.

configure.in:
compiler/options.m:
scripts/Mercury.config.in:
	Update to reflect the extra field in MR_SyncTerm.

	Add the option `--sync-term-size' and actually make use the result of
	the sync term size calculated during configuration.

compiler/code_util.m:
compiler/continuation_info.m:
compiler/dupelim.m:
compiler/dupproc.m:
compiler/global_data.m:
compiler/hlds_llds.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/reassign.m:
compiler/stack_layout.m:
compiler/use_local_vars.m:
compiler/var_locn.m:
	Conform to changes in `fork', `join_and_terminate' and
	`join_and_continue' instructions.

	Conform to additions of `parent_sp' and parent stack variables.

	XXX not sure about the changes in stack_layout.m

library/par_builtin.m:
	Conform to changes in the runtime system.
2006-09-26 03:53:23 +00:00
Zoltan Somogyi
00741b0162 This diff contains no algorithmic changes.
Estimated hours taken: 6
Branches: main

This diff contains no algorithmic changes. It merely renames apart a bunch more
function symbols to reduce ambiguity.

After this diff, the summary line from the mdb command "ambiguity -f" is

	Total: 351 names used 975 times, maximum 31, average: 2.78

browser/*.m:
compiler/*.m:
	Rename function symbols to eliminate ambiguities.

tests/debugger/declarative/dependency.exp:
tests/debugger/declarative/dependency2.exp:
	Update the expected out where some internal function symbol names
	appear in the output of the debugger. (This output is meant for
	implementors only.)
2006-08-22 05:04:29 +00:00
Julien Fischer
aeeedd2c13 Standardize formatting of comments at the beginning of modules.
compiler/*.m:
	Standardize formatting of comments at the beginning of modules.
2006-07-31 08:32:11 +00:00
Zoltan Somogyi
9d23d8e2e7 Implement the trace goal construct we discussed, for now for the LLDS backends
Estimated hours taken: 70
Branches: main

Implement the trace goal construct we discussed, for now for the LLDS backends
only.

Since the syntax of trace goals is non-trivial, useful feedback on syntax
errors inside trace goal attributes is essential. With the previous setup, this
wasn't possible, since the code that turned terms into parse tree goals turned
*all* terms into goals; it couldn't recognize any errors, sweeping them under
the rug as calls. This diff changes that. Now, if this code recognizes a
keyword that indicates a particular construct, it insists on the rest of the
code following the syntax required for that construct, and returns error
messages if it doesn't.

We handle the trace goal attributes that specify state variables to be threaded
through the trace goal (either the I/O state or a mutable variable) in
add_clause.m, at the point at which we transform the list of items to the HLDS.
We handle the compile-time condition on trace goals in the invocation of
simplify at the end of semantics analysis, by eliminating the goal if the
compile-time condition isn't met. We handle run-time conditions on trace goals
partially in the same invocation of simplify: we transform trace goals with
runtime conditions into an if-then-else with the trace goal as the then part
and `true' as the else part, the condition being a foreign_proc that is handled
specially by the code generator, that special handling being to replace
the actual code of the foreign_proc (which is a dummy) with the evaluation of
the runtime condition.

Since these changes require significant changes to some of our key data
structures, I took the liberty of doing some renaming of function symbols
at the same time to avoid using ambiguities with respect to language keywords.

library/ops.m:
	Add "trace" as an operator.

compiler/prog_data.m:
	Define data types to represent the various attributes of trace goals.

	Rename some function symbols to avoid ambiguities.

compiler/prog_item.m:
	Extend the parse tree representation of goals with a trace goal.

compiler/mercury_to_mercury.m:
	Output the new kind of goal and its components.

compiler/hlds_goal.m:
	Extend the HLDS representation of scopes with a scope_reason
	representing trace goals.

	Add a mechanism (an extra argument in foreign_procs) to allow
	the representation of goals that evaluate runtime trace conditions.

	Since this requires modifying all code that traverses the HLDS,
	do some renames that were long overdue: rename not as negation,
	rename call as plain_call, and rename foreign_proc as
	call_foreign_proc. These renames all avoid using language keywords
	as function symbols.

	Change the way we record goals' purities. Instead of optional features
	to indicate impure or semipure, which is error-prone, use a plain
	field in the goal_info, accessed in the usual way.

	Add a way to represent that a goal contains a trace goal, and should
	therefore be treated as if it were impure when considering whether to
	optimize it away.

	Reformat some comments describing function symbols.

compiler/hlds_out.m:
	Output the new construct in the HLDS.

compiler/prog_io_util.m:
	Generalize the maybe[123] types to allow the representation of more
	than one error message. Add functions to extract the error messages.
	Add a maybe4 type. Rename the function symbols of these types to
	avoid massive ambiguity.

	Change the order of some predicates to bring related predicates
	next to each other.

compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_goal.m:
compiler/prog_io_pragma.m:
	Rework these modules almost completely to find and accumulate syntax
	errors as terms are being parsed. In some cases, this allowed us to
	replace "XXX this is a hack" markers with meaningful error-reporting
	code.

	In prog_io_goal.m, add code for parsing trace goals.

	In a bunch of places, update obsolete coding practices, such as using
	nested chains of closures instead of simple sequential code, and
	using A0 and A to refer to values of different types (terms and goals
	respectively). Use more meaningful variable names.

	Break up some too-large predicates.

compiler/superhomogeneous.m:
	Find and accumulate syntax errors as terms are being parsed.

compiler/add_clause.m:
	Add code to transform trace goals from the parse tree to the HLDS.
	This is where the IO state and mutable variable attributes of trace
	goals are handled.

	Eliminate the practice of using the naming scheme Body0 and Body
	to refer to values of different types (prog_item.goal and hlds_goal
	respectively).

	Use error_util for some error messages.

library/private_builtin.m:
	Add the predicates referred to by the transformation in add_clause.m.

compiler/goal_util.m:
	Rename a predicate to avoid ambiguity.

compiler/typecheck.m:
	Do not print error messages about missing clauses if some errors have
	been detected previously.

compiler/purity.m:
	Instead of just computing purity, compute (and record) also whether
	a goal contains a trace goal. However, treat trace goals as pure.

compiler/mode_info.m:
	Add trace goals as a reason for locking variables.

	Rename some function symbols to avoid ambiguity.

compiler/modes.m:
	When analyzing trace goal scopes, lock the scope's nonlocal variables
	to prevent them from being further instantiated.

compiler/det_analysis.m:
	Insist on the code in trace goal scopes being det or cc_multi.

compiler/det_report.m:
	Generate the error message if the code in a trace goal scope isn't det
	or cc_multi.

compiler/simplify.m:
	At the end of the front end, eliminate trace goal scopes if their
	compile-time condition is false. Transform trace goals with runtime
	conditions as described at the top.

	Treat goals that contain trace goals as if they were impure when
	considering whether to optimize them away.

compiler/mercury_compile.m:
	Tell simplify when it is being invoked at the end of the front end.

	Rename a predicate to avoid ambiguity.

compiler/trace_params.m:
	Provide the predicates simplify.m need to be able to evaluate the trace
	goal conditions regarding trace levels.

compiler/trace.m:
compiler/trace_gen.m:
	Rename the trace module as trace_gen, since "trace" is now an operator.

	Rename some predicates exported by the module, now that it is no longer
	possible to preface calls with "trace." as a module qualifier.

compiler/notes/compiler_design.html:
	Document this name change.

compiler/options.m:
	Rename the trace option as trace_level internally, since "trace"
	is now an operator. The user-visible name remains the same.

	Add the new --trace-flag option.

	Delete an obsolete option.

compiler/handle_options.m:
	Rename the function symbols of the grade_component type,
	since "trace" is now an operator.

compiler/llds.m:
	Extend the LLDS with a mechanism to refer to C global variables.
	For now, these are used to refer to C globals that will be created
	by mkinit to represent the initial values of the environment variables
	referred to by trace goals.

compiler/commit_gen.m:
	Check that no trace goal with a runtime condition survives to code
	generation; they should have been transformed by simplify.m.

compiler/code_gen.m:
	Tell commit_gen.m what kind of scope it is generating code for.

compiler/pragma_c_gen.m:
	Generate code for runtime conditions when handling the foreign_procs
	created by simplify.m.

compiler/code_info.m:
	Allow pragma_c_gen.m to record what environment variables it has
	generated references to.

compiler/proc_gen.m:
	Record the set of environment variables a procedure refers to
	in the LLDS procedure header, for efficient access by llds_out.m.

compiler/llds_out.m:
	Handle the new LLDS construct, and tell mkinit which environment
	variables need C globals created for them.

compiler/pd_util.m:
	Rename some predicates to avoid ambiguity.

compiler/*.m:
	Conform to the changes above, mainly the renames of function symbols
	and predicates, the changed signatures of some predicates, and the new
	handling of purity.

util/mkinit.c:
	Generate the definitions and the initializations of any C globals
	representing the initial status (set or not set) of environment
	variables needed by trace goals.

library/assoc_list.m:
	Add some predicates that are useful in prog_io*.m.

library/term_io.m:
	Minor cleanup.

tests/hard_coded/trace_goal_{1,2}.{m,exp}:
	New test cases to test the new construct, identical except for whether
	the trace goal is enabled at compile time.

tests/hard_coded/trace_goal_env_{1,2}.{m,exp}:
	New test cases to test the new construct, identical except for whether
	the trace goal is enabled at run time.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
	Enable the new test cases.

tests/invalid/*.err_exp:
	Update the expected output for the new versions of the error messages
	now being generated.
2006-07-27 05:03:54 +00:00
Zoltan Somogyi
d5d5986472 Implement lookup switches in which a switch arm may contain more than one
Estimated hours taken: 40
Branches: main

Implement lookup switches in which a switch arm may contain more than one
solution, such as this code here:

	p(d, "four", f1, 4.4).
	p(e, "five", f2, 5.5).
	p(e, "five2", f3(5), 55.5).
	p(f, "six", f4("hex"), 6.6).
	p(g, "seven", f5(77.7), 7.7).
	p(g, "seven2", f1, 777.7).
	p(g, "seven3", f2, 7777.7).

Such code occurs frequently in benchmark programs used to evaluate the
performance of tabled logic programming systems.

Change frameopt.m, which previously worked only on det and semidet code,
to also work for nondet code. For predicates such as the one above, frameopt
can now arrange for the predicate's nondet stack frame to be created only
when a switch arm that has more than one solution is selected.

compiler/lookup_switch.m:
	Extend the existing code for recognizing and implementing lookup
	switches to recognize and implement them even if they are model_non.

compiler/lookup_util.m:
	New module containing utility predicates useful for implementing
	both lookup switches, and in the future, lookup disjunctions (i.e.
	disjunctions that correspond to a nondet arm of a lookup switch).

compiler/ll_backend.m:
	Include the new module.

compiler/notes/compiler_design.html:
	Mention the new module.

compiler/global_data.m:
	Move the job of filling in dummy slots to our caller, in this case
	lookup_switch.m.

compiler/frameopt.m:
	Generalize the existing code for delaying stack frame creation,
	which worked only on predicates that live on the det stack, to work
	also on predicates that live on the nondet stack. Without this,
	predicates whose bodies are model_non lookup switches would create
	a nonstack stack frame before the switch is ever entered, which
	is wasteful if the selected switch arm has at most one solution.

	Since the structure of model_non predicates is more complex (you can
	cause a branch to a label by storing its address in a redoip slot,
	you can succeed from the frame without removing the frame), this
	required considerable extra work. To make the new code debuggable,
	record, for each basic block that needs a stack frame, *why* it
	needs that stack frame.

compiler/opt_util.m:
	Be more conservative about what refers to the stack. Export some
	previously internal functionality for frameopt. Turn some predicates
	into functions, and rename them to better reflect their purpose.

compiler/opt_debug.m:
	Print much more information about pragma_c and call LLDS instructions.

compiler/prog_data.m:
	Add an extra attribute to foreign_procs that says that the code
	of the foreign_proc assumes the existence of a stack frame.
	This is needed to avoid frameopt optimizing the stack frame away.

compiler/add_pragma.m:
	When processing fact tables, we create foreign_procs that assume
	the existence of the stack frame, so set the new attribute.

compiler/pragma_c_gen.m:
	When processing foreign_procs, transmit the information in the
	attribute to the generated LLDS code.

compiler/llds.m:
	Rename the function symbols referring to the fixed slots in nondet
	stack frames to make them clearer and to avoid overloading function
	symbols such as curfr and succip.

	Rename the function symbols of the call_model type to avoid overloading
	the function symbols of the code_model type.

	Add a new field to the c_procedure type giving the code_model of the
	procedure, and give names to all the fields.

	Describe the stack slots used by lookup switches to the debugger
	and native gc.

compiler/options.m:
doc/user_guide.texi:
	Add a new option, --debug-opt-pred-name, that does when the existing
	--debug-opt-pred-id options does, but taking a user-friendly predicate
	name rather than a pred_id as its argument.

compiler/handle_options.m:
	Process --debug-opt-pred-name, and make --frameopt-comments imply
	--auto-comments, since it is not useful without it.

	Reformat some existing comments that were written in the days of
	8-space indentation.

compiler/optimize.m:
	Implement the new option.

	Use the new field of the c_procedure type to try only the version
	of frameopt appropriate for the code model of the current procedure.

	Do a peephole pass after frameopt, since frameopt can generate code
	sequences that peephole can optimize.

	Make the mechanism for recording the process of optimizing procedure
	bodies more easily usable by including the name of the optimization
	that created a given version of the code in the name of the file
	that contains that version of the code, and ensuring that all numbers
	are two characters long, so that "vi procname*.opt*" looks at the
	relevant files in the proper chronological sequence, instead of having
	version 11 appear before version 2.

compiler/peephole.m:
	Add a new optimization pattern: a "mkframe, goto fail" pair (which
	can be generated by frameopt) should be replaced by a simple "goto
	redo".

compiler/code_gen.m:
	Factor out some common code.

compiler/llds_out.m:
	Ensure that C comments nested inside comment(_) LLDS instructions
	aren't emitted as nested C comments, since C compilers cannot handle
	these.

compiler/code_info.m:
compiler/code_util.m:
compiler/continuation_info.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/mercury_compile.m:
compiler/middle_rec.m:
compiler/ml_code_gen.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/peephole.m:
compiler/stack_layout.m:
compiler/transform_llds.m:
compiler/var_locn.m:
	Conform to the change to prog_data.m, opt_util.m and/or llds.m.

compiler/handle_options.m:
	Don't execute the code in stdlabel.m if doing so would cause a compiler
	abort.

tests/hard_coded/dense_lookup_switch_non.{m,exp}:
	New test case to exercise the new algorithm.

tests/hard_coded/Mmakefile:
	Enable the new test case.

tests/hard_coded/cycles.m:
	Make this test case conform to our coding convention.
2006-04-26 03:06:29 +00:00
Zoltan Somogyi
90f2724738 Don't test whether we are emitting trail operations when generating
Estimated hours taken: 0.5
Branches: main

compiler/code_gen.m:
	Don't test whether we are emitting trail operations when generating
	*every* goal; test it only when generating goals that may want to
	emit trailing operations. Make the test itself more efficient
	by doing option lookups and boolean operations on option values
	once per procedure rather than once per affected goal.

compiler/code_info.m:
	Extend the code_info structure to provide storage space for the
	result of this per-procedure computation.

compiler/code_util.m:
	Delete a function whose functionality is now in code_info.m.

compiler/goal_form.m:
	Turn the predicates that test whether a goal can modify the trail
	into functions, since that is how they were being used. Make them
	take only the goal_info as the argument, since the goal expression
	isn't needed, and creating the expression/goal_info pair would be
	an unnecessary cost on the code generator.

compiler/add_trail_ops.m:
compiler/disj_gen.m:
	Conform to the change in goal_form.m.

compiler/mercury_compile.m:
	Fix formatting.

compiler/assertion.m:
	Address some old review comments: fix some bad predicate names,
	and put some predicate's arguments into a more conventional order.

	Remove some redundant and slightly inconsistent documentation.

compiler/accumulator.m:
compiler/typecheck.m:
	Conform to the change in assertion.m.
2006-03-31 03:32:11 +00:00
Zoltan Somogyi
4fe703c7b9 Implement a more cache-friendly translation of lookup switches.
Estimated hours taken: 8
Branches: main

Implement a more cache-friendly translation of lookup switches. Previously,
for a switch such as the one in

	:- pred p(foo::in, string::out, bar::out, float::out) is semidet.

	p(d, "four", f1, 4.4).
	p(e, "five", f2, 5.5).
	p(f, "six", f4("hex"), 6.6).
	p(g, "seven", f5(77.7), 7.7).

we generated three static cells, one for each argument, and then indexed
into each one in turn to get the values of HeadVar__2, HeadVar__3 and
HeadVar__4. The different static cells each represent a column here.
Each of the loads accessing the columns will access a different cache block,
so with this technique we expect to get as many cache misses as there are
output variables.

This diff changes the code we generate to use a vector of static cells
where each cell represents a row. The assignments to the output variables
will now access the different fields of a row, which will be next to each
other. We thus expect only one cache miss irrespective of the number of output
variables, at least up to the number of variables that actually fit into one
cache block.

compiler/global_data.m:
	Provide a mechanism for creating not just single (scalar) static cells,
	but arrays (vectors) of them.

compiler/lookup_switch.m:
	Use the new mechanism to generate code along the lines described above.

	Put the information passed between the two halves of the lookup switch
	implementation (detection and code generation) into an opaque data
	structure.

compiler/switch_gen.m:
	Conform to the new interface of lookup_switch.m.

compiler/ll_pseudo_type_info.m:
compiler/stack_layout.m:
compiler/string_switch.m:
compiler/unify_gen.m:
compiler/var_locn.m:
	Conform to the change to global_data.m.

compiler/llds.m:
	Define the data structures for holding vectors of static cells. Rename
	the function symbols we used to use to refer to static cells to make
	clear that they apply to scalar cells only. Provide similar mechanisms
	for representing static cell vectors and references to them.

	Generalize heap_ref heap references to allow the index to be computed
	at runtime, not compile time. For symmetry's sake, do likewise
	for stack references.

compiler/llds_out.m:
	Add the code required to write out static cell vectors.

	Rename decl_ids to increase clarity and avoid ambiguity.

compiler/code_util.m:
compiler/exprn_aux.m:
	Modify code that traverses rvals to now also traverse the new rvals
	inside memory references.

compiler/name_mangle.m:
	Provide the prefix for static cell vectors.

compiler/layout_out.m:
compiler/rtti_out.m:
compiler/opt_debug.m:
	Conform to the change to data_addrs and decl_ids.

compiler/code_info.m:
	Provide access to the new functionality in global_data.m, and conform
	to the change to llds.m.

	Provide a utility predicate needed by lookup_switch.m.

compiler/hlds_llds.m:
	Fix the formatting of some comments.

tools/binary:
tools/binary_step:
	Fix the bit rot that has set in since they were last used (the rest
	of the system has changed quite a lot since then). I had to do so
	to debug one part of this change.

tests/hard_coded/dense_lookup_switch2.{m,exp}:
tests/hard_coded/dense_lookup_switch3.{m,exp}:
	New test cases to exercise the new algorithm.

tests/hard_coded/Mmakefile:
	Enable the new test cases, as well as an old one (from 1997!)
	that seems never to have been enabled.
2006-03-30 02:46:08 +00:00
Julien Fischer
459847a064 Move the univ, maybe, pair and unit types from std_util into their own
Estimated hours taken: 18
Branches: main

Move the univ, maybe, pair and unit types from std_util into their own
modules.  std_util still contains the general purpose higher-order programming
constructs.

library/std_util.m:
	Move univ, maybe, pair and unit (plus any other related types
	and procedures) into their own modules.

library/maybe.m:
	New module.  This contains the maybe and maybe_error types and
	the associated procedures.

library/pair.m:
	New module.  This contains the pair type and associated procedures.

library/unit.m:
	New module. This contains the types unit/0 and unit/1.

library/univ.m:
	New module. This contains the univ type and associated procedures.

library/library.m:
	Add the new modules.

library/private_builtin.m:
	Update the declaration of the type_ctor_info struct for univ.

runtime/mercury.h:
	Update the declaration for the type_ctor_info struct for univ.

runtime/mercury_mcpp.h:
runtime/mercury_hlc_types.h:
	Update the definition of MR_Univ.

runtime/mercury_init.h:
	Fix a comment: ML_type_name is now exported from type_desc.m.

compiler/mlds_to_il.m:
	Update the the name of the module that defines univs (which are
	handled specially by the il code generator.)

library/*.m:
compiler/*.m:
browser/*.m:
mdbcomp/*.m:
profiler/*.m:
deep_profiler/*.m:
	Conform to the above changes.  Import the new modules where they
	are needed; don't import std_util where it isn't needed.

	Fix formatting in lots of modules.  Delete duplicate module
	imports.

tests/*:
	Update the test suite to confrom to the above changes.
2006-03-29 08:09:58 +00:00
Zoltan Somogyi
12deb40264 Rename all the get access predicates in these modules that don't
Estimated hours taken: 0.1
Branches: main

compiler/hlds_clauses.m:
compiler/hlds_pred.m:
	Rename all the get access predicates in these modules that don't
	already have put "get" in their name. (The names of the set access
	predicates were OK already.)

compiler/*.m:
	Conform to the above.

All this was done by this sed script:

s/clauses_info_varset/clauses_info_get_varset/
s/clauses_info_explicit_vartypes/clauses_info_get_explicit_vartypes/
s/clauses_info_vartypes/clauses_info_get_vartypes/
s/clauses_info_headvars/clauses_info_get_headvars/
s/clauses_info_clauses_rep/clauses_info_get_clauses_rep/
s/clauses_info_rtti_varmaps/clauses_info_get_rtti_varmaps/
s/pred_info_import_status/pred_info_get_import_status/
s/pred_info_arg_types/pred_info_get_arg_types/
s/pred_info_typevarset/pred_info_get_typevarset/
s/pred_info_tvar_kinds/pred_info_get_tvar_kinds/
s/pred_info_procedures/pred_info_get_procedures/
s/proc_info_context/proc_info_get_context/
s/proc_info_varset/proc_info_get_varset/
s/proc_info_vartypes/proc_info_get_vartypes/
s/proc_info_headvars/proc_info_get_headvars/
s/proc_info_inst_varset/proc_info_get_inst_varset/
s/proc_info_maybe_declared_argmodes/proc_info_get_maybe_declared_argmodes/
s/proc_info_argmodes/proc_info_get_argmodes/
s/proc_info_maybe_arglives/proc_info_get_maybe_arglives/
s/proc_info_declared_determinism/proc_info_get_declared_determinism/
s/proc_info_inferred_determinism/proc_info_get_inferred_determinism/
s/proc_info_goal/proc_info_get_goal/
s/proc_info_can_process/proc_info_get_can_process/
s/proc_info_rtti_varmaps/proc_info_get_rtti_varmaps/
s/proc_info_eval_method/proc_info_get_eval_method/
s/proc_info_is_address_taken/proc_info_get_is_address_taken/
s/proc_info_stack_slots/proc_info_get_stack_slots/
s/proc_info_liveness_info/proc_info_get_liveness_info/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
s/proc_info_context/proc_info_get_context/
2006-03-27 09:36:34 +00:00
Zoltan Somogyi
3ebda6545f Move the stuff currently in hlds_pred.m that deals with clauses into a new
Estimated hours taken: 1.5
Branches: main

Move the stuff currently in hlds_pred.m that deals with clauses into a new
module, hlds_clauses.m.

Move the stuff currently in hlds_pred.m that deals with RTTI into a new
module, hlds_rtti.m.

Move the stuff currently in hlds_module.m that deals with predicate tables
into a new module, pred_table.m.

These changes make hlds_pred.m and hlds_module.m much more cohesive, but there
are no changes in algorithms.

compiler/hlds_clauses.m:
compiler/hlds_rtti.m:
compiler/pred_table.m:
	New modules as described above. In some cases, fix mixleading or
	ambiguous predicate names in the process, and convert a few predicates
	to functions.

compiler/hlds_pred.m:
compiler/hlds_module.m:
	Delete the stuff moved to other modules.

compiler/*.m:
	In modules that need the functionality moved a new module, import
	the new module. It is rare for all the new modules to be needed,
	and many modules don't need any of the new modules at all. (For
	example, of the 200+ modules that import hlds_module.m, only about 40
	need pred_table.m.)

	Conform to the few minor changes to e.g. predicate names.

compiler/notes/compiler_design.html:
	Document the new modules.
2006-03-24 03:04:20 +00:00
Zoltan Somogyi
be5b71861b Convert almost all the compiler modules to use . instead of __ as
Estimated hours taken: 6
Branches: main

compiler/*.m:
	Convert almost all the compiler modules to use . instead of __ as
	the module qualifier.

	In some cases, change the names of predicates and types to make them
	meaningful without the module qualifier. In particular, most of the
	types that used to be referred to with an "mlds__" prefix have been
	changed to have a "mlds_" prefix instead of changing the prefix to
	"mlds.".

	There are no algorithmic changes.
2006-03-17 01:40:46 +00:00
Zoltan Somogyi
5b8f96f61d Prepare for an extension of promise_equivalent_solutions that will allow us
Estimated hours taken: 5
Branches: main

Prepare for an extension of promise_equivalent_solutions that will allow us
to better handle values of user-defined types. The problem is that currently,
the deconstruction of a value of such a type can be followed only by code that
cannot fail, otherwise the cc_multi deconstruction is not in the required
single-solution context. If the following code is naturally semidet, this
can be worked around by turning it into det code returning a maybe and testing
the maybe outside the promise_equivalent_solutions, but this is inefficient,
and in any case it does not generalize to nondet code without even more
horrendous inefficiency and inconvenience. (You have to create a nondet closure
and call it outside the promise_equivalent_solutions.)

The solution I came up with is something is to have a construct that contains

	- a list of deconstructions on types with user-defined equality,
	- a goal, and
	- the list of outputs of that goal.

The idea is that this would be transformed into a conjunction of the first and
second items, and wrapped inside a special kind of conj that provides a scope
for the implicit promise, which is that the set of solutions of the goal in
the second item doesn't depend on what concrete terms the deconstructions
in the first item return out of the set of concrete terms they *could* return.
The deconstructions in the first item would be marked to tell determinism
analysis to effectively ignore the fact that they involve user-defined
equality.

The actual addition of that construct is left for a future change, after we
agree on the syntax.

compiler/hlds_goal.m:
	Generalize the existing promise_equivalent_solutions scope to a
	promise_solutions scope with a flag that says whether in the source
	code it was originally the existing "promise_equivalent_solutions"
	construct or the new construct (which doesn't exist yet, but is
	indicated by the symbol "same_solutions" for now).

	Replace the conj and par_conj hlds_goal_exprs with a single goal
	expression: conj with an additional argument which is either plain_conj
	or parallel_conj. This was part of an earlier design in which a third
	kind of disjunction took the role now assigned to the new kind of
	promise_solutions scope, but turned out to be a good idea anyway,
	since in many places the compiler does treat the two kinds of
	conjunctions the same. This part of the change is responsible for the
	fact that this change results in a net *reduction* of about 40 lines.

	Move the most frequently used kinds of goal expressions to the front
	of the type declaration to allow the compiler to make better decisions
	about tag allocation.

	Add the goal marker we will add to the deconstructions in the first
	item.

	Replace the true_goal and fail_goal predicates with functions to make
	them easier to use, and rename their variants that take a context
	argument to avoid unnecessary ambiguity.

compiler/*.m:
	Conform to the change in hlds_goal.m.

	Misc changes to make code more robust, e.g. replacing semidet
	predicates on goal expressions with functions returning bool.

	Misc cleanups, e.g. removal of unnecessary module qualifications
	that made lines too long, renaming predicates whose names include
	"disj" if they are also used to process parallel conjunctions (since in
	both parallel conjunctions and in disjunctions the goals are
	independent), and turning semidet predicates that switch on goal
	expressions into bool functions (to make similar changes more rebust
	in the future).
2006-02-24 05:49:43 +00:00
Julien Fischer
89287a4206 Add a new developer-only option, `--disable-trail-ops', that disables the
Estimated hours taken: 0.5
Branches: main

Add a new developer-only option, `--disable-trail-ops', that disables the
output of trailing operations.  This is intended for analysing the performance
impact of trailing and is not otherwise useful.

compiler/options.m:
	Add the new option.

compiler/code_util.m:
compiler/mercury_compile.m:
	Support the new option in the code generators.
2006-01-03 04:07:50 +00:00
Julien Fischer
6129c79d03 Attach trail usage information to the goal_info rather than recomputing it on
Estimated hours taken: 10
Branches: main

Attach trail usage information to the goal_info rather than recomputing it on
demand.  This avoids repeated traversals of the goal structure during trail
usage optimization.

compiler/trailing_analysis.m:
	Add an optional second pass to trail usage analysis that annotates
	goals with trail usage information.  The second pass is optional
	because we only run it when we are generating code; when building the
	optimization interfaces we don't run it.

	Factor out code that is common to both passes into separate
	procedures.

	Fix some problems with the documentation in this module.

	Update the TODO list in this module.

	Add exception.rethrow/1 to the known procedures table.

compiler/hlds_goal.m:
	Add a new goal feature `will_not_modify_trail' that can be used to
	mark goals that will not modify the trail.

compiler/goal_form.m:
	Instead of traversing the a goal to work out if it may modify the
	trail, just look for the will_not_modify_trail feature in the
	goal_info.

compiler/saved_vars.m:
compiler/add_trail_ops.m:
compiler/code_gen.m:
compiler/code_util.m:
compiler/disj_gen.m:
	Minor change to conform to the above.
2005-12-06 06:26:07 +00:00
Julien Fischer
45fdb6c451 Use expect/3 in place of require/2 throughout most of the
Estimated hours taken: 4
Branches: main

compiler/*.m:
	Use expect/3 in place of require/2 throughout most of the
	compiler.

	Use unexpected/2 (or sorry/2) in place of error/1 in more
	places.

	Fix more dodgy assertion error messages.

	s/map(prog_var, mer_type)/vartypes/ where the latter is meant.
2005-11-28 04:11:59 +00:00
Julien Fischer
dae82a8409 Implement trail usage optimization for the lowlevel backend.
Estimated hours taken: 5
Branches: main

Implement trail usage optimization for the lowlevel backend.

compiler/code_gen.m:
	As we generate code for each HLDS goal check if it is safe to omit
	trailing operations.  Do so, if trail usage optimization is enabled.

	Reformat some code for the purposes of readability.

compiler/commit_gen.m:
compiler/disj_gen.m:
compiler/ite_gen.m:
compiler/code_info.m:
	Thread the above information down to the relevant parts of the code
	generator.

	Misc. cleanups: reduce unnecessary module qualification and minor
	layout fixes.

compiler/code_util.m:
	Add a utility predicate the tests if we are allowed to omit trailing
	primitives for a given HLDS goal.

compiler/llds.m:
	Add the equivalence type: add_trail_ops == bool.

compiler/hlds_goal.m:
compiler/prog_data.m:
	Unrelated changes: fix typos in comments.

	Add an end_module declaration to the former.
2005-11-17 04:38:44 +00:00
Zoltan Somogyi
f9fe8dcf61 Improve the error messages generated for determinism errors involving committed
Estimated hours taken: 8
Branches: main

Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.

The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.

compiler/det_analysis.m:
	Keep track of goals to the right of the current goal that could fail,
	and include them in the error representation if required.

compiler/det_report.m:
	Include the list of failing goals to the right in the representations
	of determinism errors involving committed committed choice goals.

	Convert the last part of this module that wasn't using error_util
	to use error_util. Make most parts of this module just construct
	error message specifications; print those specifications (using
	error_util) in only a few places.

compiler/hlds_out.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
	Add a function for use by the new code in det_report.m.

compiler/error_util.m:
compiler/compiler_util.m:
	Error_util is still changing reasonably often, and yet it is
	included in lots of modules, most of which need only a few simple
	non-parse-tree-related predicates from it (e.g. unexpected).
	Move those predicates to a new module, compiler_util.m. This also
	eliminates some undesirable dependencies from libs to parse_tree.

compiler/libs.m:
	Include compiler_util.m.

compiler/notes/compiler_design.html:
	Document compiler_util.m, and fix the documentation of some other
	modules.

compiler/*.m:
	Import compiler_util instead of or in addition to error_util.
	To make this easier, consistently use . instead of __ for module
	qualifying module names.

tests/invalid/det_errors_cc.{m,err_exp}:
	Add this new test case to test the error messages for cc contexts.

tests/invalid/det_errors_deet.{m,err_exp}:
	Add this new test case to test the error messages for unifications
	inside function symbols.

tests/invalid/Mmakefile:
	Add the new test cases.

tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
	Change the expected output to conform to the change in det_report.m,
	which is now more consistent.
2005-10-28 02:11:03 +00:00
Zoltan Somogyi
b2012c0c0e Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
Estimated hours taken: 8
Branches: main

compiler/*.m:
	Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
	and 'mer_mode'. This is to avoid the need to parenthesize these type
	names in some contexts, and to prepare for the possibility of a parser
	that considers those words to be reserved words.

	Rename some other uses of those names (e.g. as item types in
	recompilation.m).

	Delete some redundant synonyms (prog_type, mercury_type) for mer_type.

	Change some type names (e.g. mlds__type) and predicate names (e.g.
	deforest__goal) to make them unique even without module qualification.

	Rename the function symbols (e.g. pure, &) that need to be renamed
	to avoid the need to parenthesize them. Make their replacement names
	more expressive.

	Convert some more modules to four space indentation.

	Avoid excessively long lines, such as those resulting from the
	automatic substitution of 'mer_type' for 'type'.
2005-10-24 04:14:34 +00:00
Zoltan Somogyi
905e4a114f Convert a bunch of modules to four-space indentation.
Estimated hours taken: 4
Branches: main

compiler/*.m:
	Convert a bunch of modules to four-space indentation.
	In the process, fix departures from our coding standards.

	In some cases, do minor other cleanups such as changing argument orders
	to be friendly to state variables.

	There are no algorithmic changes.
2005-10-12 23:51:38 +00:00
Zoltan Somogyi
8b8b3b7d3f Replace the some() HLDS goal with a more general scope() goal, which can be
Estimated hours taken: 12
Branches: main

Replace the some() HLDS goal with a more general scope() goal, which can be
used not just for existential quantification but also for other purposes.

The main such purposes are new goal types that allow the programmer
to annotate arbitrary goals, and not just whole procedure bodies, with the
equivalents of promise_pure/promise_semipure and promise_only_solution:

	promise_pure ( <impure/semipure goal> )
	promise_semipure ( <impure goal> )

	promise_equivalent_solutions [OutVar1, OutVar2] (
		<cc_multi/cc_nondet goal that computed OutVar1 & OutVar2>
	)

Both are intended to be helpful in writing constraint solvers, as well as in
other situations.

doc/reference_manual.texi:
	Document the new constructs.

library/ops.m:
	Add the keywords of the new constructs to the list of operators.
	Since they work similarly to the "some" operator, they have the same
	precedence.

compiler/hlds_goal.m:
	Replace the some(Vars, SubGoal) HLDS construct, with its optional
	keep_this_commit attribute, with the new scope(Reason, SubGoal)
	construct. The Reason argument may say that this scope is an
	existential quantification, but it can also say that it represents
	a purity promise, the introduction of a single-solution context
	with promise_equivalent_solutions, or a decision by a compiler pass.

	It can also say that the scope represents a set of goals that all arise
	from the unraveling of a unification between a variable and a ground
	term. This was intended to speed up mode checking by significantly
	reducing the number of delays and wakeups, but the cost of the scopes
	themselves turned out to be bigger than the gain in modechecking speed.

	Update the goal_path_step type to refer to scope goals instead of just
	existential quantification.

compiler/prog_data.m:
	Add new function symbols to the type we use to represent goals in items
	to stand for the new Mercury constructs.

compiler/prog_io_goal.m:
	Add code to read in the new language constructs.

compiler/prog_io_util.m:
	Add a utility predicate for use by the new code in prog_io_goal.m.

compiler/make_hlds.m:
	Convert the item representation of the new constructs to the HLDS
	representation.

	Document how the from_ground_term scope reason would work, but do not
	enable the code.

compiler/purity.m:
	When checking the purity of goals, respect the new promise_pure and
	promise_semipure scopes. Generate warnings if such scopes are
	redundant.

compiler/det_analysis.m:
	Make the insides of promise_equivalent_solutions goals single solution
	contexts.

compiler/det_report.m:
	Provide mechanisms for reporting inappropriate usage of
	promise_equivalent_solutions goals.

compiler/instmap.m:
	Add a utility predicate for use by one of the modules above.

compiler/deep_profiling.m:
	Use one of the new scope reasons to prevent simplify from optimizing
	away commits of goals that have been made impure, instead of the old
	keep_this_commit goal feature.

compiler/modes.m:
	Handle from_ground_term scopes when present; for now, they won't be
	present, since make_hlds isn't creating them.

compiler/options.m:
	Add two new compiler options, for use by implementors only, to allow
	finer control over the amount of output one gets with --debug-modes.
	(I used them when debugging the performance of the from_ground_term
	scope reason.) The options are --debug-modes-minimal and
	--debug-modes-verbose.

compiler/handle_options.m:
	Make the options that are meaningful only in the presence of
	--debug-modes imply --debug-modes, since this allows more convenient
	(shorter) invocations.

compiler/mode_debug.m:
	Respect the new options when deciding how much data to print
	when debugging of the mode checking process is enabled.

compiler/switch_detect.m:
	Rename a predicate to make it differ from another predicate by more
	than just its arity.

compiler/passes_aux.m:
	Bring this module up to date with our current style guidelines,
	by using state variable syntax where appropriate.

compiler/*.m:
	Minor changes to conform to the change in the HLDS and/or parse tree
	goal type.

mdbcomp/program_representation.m:
	Rename the some goal to the scope goal, and the same for path steps,
	to keep them in sync with the HLDS.

browser/declarative_tree.m:
	Conform to the change in goal representations.

tests/hard_coded/promise_equivalent_solutions_test.{m,exp}:
	A new test case to test the handling of the
	promise_equivalent_solutions construct.

tests/hard_coded/Mmakefile:
	Enable the new test.

tests/hard_coded/purity/promise_pure_test.{m,exp}:
	A new test case to test the handling of the promise_pure and
	promise_semipure constructs.

tests/hard_coded/purity/Mmakefile:
	Enable the new test.

tests/invalid/promise_equivalent_solutions.{m,err_exp}:
	A new test case to test the error messages for improper use of the
	promise_pure and promise_semipure constructs.

tests/invalid/Mmakefile:
	Enable the new test.
2005-03-24 05:34:41 +00:00
Zoltan Somogyi
c08ca7fbc8 Import only one module per line in the modules of the compiler
Estimated hours taken: 3
Branches: main

compiler/*.m:
	Import only one module per line in the modules of the compiler
	where my previous diff did not already do so.

	Misc other cleanups.

	Where relevant, use the new mechanism in tree.m.

compiler/tree.m:
	Fix a performance problem I noticed while update :- import_module
	items. Instead of supplying a function to convert lists of trees
	to a tree, make the tree data structure able to hold a list of
	subtrees directly. This reduces the number of times where we have to
	convert list of trees to trees that are sticks just to stay within
	the old definition of what a tree is.
2005-03-24 02:00:43 +00:00
Peter Wang
59d2d4a573 This adds a module mdbcomp__trace_counts that reads in the
Estimated hours taken: 17
Branches: main

This adds a module mdbcomp__trace_counts that reads in the
.mercury_trace_counts files produced by the compiler's trace mechanism.
The format of said files was slightly changed.

As the new module is to be used by the compiler and the debugger, it is
placed in the mdbcomp module.  This required bringing some types from the
compiler into a new module within mdbcomp.

browser/trace_counts.m:
	New module for reading execution trace summaries.

browser/prim_data.m:
	New module holding types and predicates moved in from the compiler.
	Types:
		pred_or_func, sym_name, module_name, proc_label,
		special_pred_id, trace_port
	Predicates:
		string_to_sym_name, insert_module_qualifier

	The mode field of proc_label is now an int instead of a proc_id
	to avoid pulling proc_id into mdbcomp.

browser/mdbcomp.m:
	Add trace_counts and prim_data to the mdbcomp module.

browser/declarative_execution.m:
	Renamed mdb's definition of module_name to flat_module_name
	to avoid conflicts with the definition in mdbcomp__prim_data.

runtime/mercury_trace_base.c:
	In the format of .mercury_trace_counts, write module and predicate
	names now use quoted atom syntax so that names with spaces and
	non-printable characters can be machine-parsed.

browser/:
compiler/:
	Many changes to account for movement of types, and the change to
	proc_label.
2005-01-19 03:11:22 +00:00
Zoltan Somogyi
885fd4a387 Remove almost all dependencies by the modules of parse_tree.m on the modules
Estimated hours taken: 12
Branches: main

Remove almost all dependencies by the modules of parse_tree.m on the modules
of hlds.m. The only such dependencies remaining now are on type_util.m.

compiler/hlds_data.m:
compiler/prog_data.m:
	Move the cons_id type from hlds_data to prog_data, since several parts
	of the parse tree data structure depend on it (particularly insts).
	Remove the need to import HLDS modules in prog_data.m by making the
	cons_ids that refer to procedure ids refer to them via a new type
	that contains shrouded pred_ids and proc_ids. Since pred_ids and
	proc_ids are abstract types in hlds_data, add predicates to hlds_data
	to shroud and unshroud them.

	Also move some other types, e.g. mode_id and class_id, from hlds_data
	to prog_data.

compiler/hlds_data.m:
compiler/prog_util.m:
	Move predicates for manipulating cons_ids from hlds_data to prog_util.

compiler/inst.m:
compiler/prog_data.m:
	Move the contents of inst.m to prog_data.m, since that is where it
	belongs, and since doing so eliminates a circular dependency.
	The separation doesn't serve any purpose any more, since we don't
	need to import hlds_data.m anymore to get access to the cons_id type.

compiler/mode_util.m:
compiler/prog_mode.m:
compiler/parse_tree.m:
	Move the predicates in mode_util that don't depend on the HLDS to a new
	module prog_mode, which is part of parse_tree.m.

compiler/notes/compiler_design.m:
	Mention prog_mode.m, and delete the mention of inst.m.

compiler/mercury_to_mercury.m:
compiler/hlds_out.m:
	Move the predicates that depend on HLDS out of mercury_to_mercury.m
	to hlds_out.m. Export from mercury_to_mercury.m the predicates needed
	by the moved predicates.

compiler/hlds_out.m:
compiler/prog_out.m:
	Move predicates for printing parts of the parse tree out of hlds_out.m
	to prog_out.m, since mercury_to_mercury.m needs to use them.

compiler/purity.m:
compiler/prog_out.m:
	Move predicates for printing purities from purity.m, which is part
	of check_hlds.m, to prog_out.m, since mercury_to_mercury.m needs to use
	them.

compiler/passes_aux.m:
compiler/prog_out.m:
	Move some utility predicates (e.g. for printing progress messages) from
	passes_aux.m to prog_out.m, since some predicates in submodules of
	parse_tree.m need to use them.

compiler/foreign.m:
compiler/prog_data.m:
	Move some types from foreign.m to prog_data.m to allow the elimination
	of some dependencies on foreign.m from submodules of parse_tree.m.

compiler/*.m:
	Conform to the changes above, mostly by updating lists of imported
	modules and module qualifications. In some cases, also do some local
	cleanups such as converting predicate declarations to predmode syntax
	and fixing white space.
2004-06-14 04:17:03 +00:00
Zoltan Somogyi
7bf0cd03af Reduce the overhead of all forms of tabling by eliminating in many cases
Estimated hours taken: 32
Branches: main

Reduce the overhead of all forms of tabling by eliminating in many cases
the overhead of transferring data across the C/Mercury boundary. These
involve lots of control transfers as well as assignments to and from
Mercury abstract machine registers, which are not real machine registers
on x86 machines. Benchmarking in Uppsala revealed this overhead to be
a real problem.

The way we do that is by changing the tabling transformation so that instead
of generating sequences of calls to predicates from library/table_builtin.m,
we generate sequences of calls to C macros from runtime/mercury_tabling_pred.h,
and emit the resulting code string as the body of a foreign_proc goal.
(The old transformation is still available via a new option,
--no-tabling-via-extra-args.)

Since the number of inputs and outputs of the resulting C code sequences
are not always fixed (they can depend on the number of input or output
arguments of predicate being transformed), implementing this required
adding to foreign_procs a new field that allows the specification of extra
arguments to be passed to and from the given foreign code fragment. For now,
this mechanism is implemented only by the C backends, since it is needed
only by the C backends. (We don't support yet tabling on other backends.)

To simplify the new implementation of the field on foreign_procs, consolidate
three existing fields into one. Each of these fields was a list with one
element per argument, so turning them into a single list with a combined record
per argument should also improve reliability, since it reduces the likelyhood
of updates leaving the data structure inconsistent.

The goal paths of components of a tabled predicate depend on whether
-no-tabling-via-extra-args was specified. To enable the expected outputs
of the debugger test cases testing tabling, we add a new mdb command,
goal_paths, that controls whether goal paths are printed by the debugger
at events, and turn off the printing of events in the relevant test cases.

Also, prepare for a future change to optimize the trie structure for
user-defined types by handling type_infos (and once we support them,
typeclass_infos) specially.

compiler/table_gen.m:
	Change the tabling transformation along the lines described above.

	To allow us to factor out as much of the new code as possible,
	we change the meaning of the call_table_tip variable for minimal
	model subgoals: instead of the trie node at the end of the answer
	table, it is not now the subgoal reachable from it. This change
	has no effect as yet, because we use call_table_tip variables
	only to perform resets across retries in the debugger, and we
	don't do retries across calls to minimal model tabled predicates.

	Put predicates into logical groups.

library/table_builtin.m:
runtime/mercury_tabling_preds.h:
	When the new transformations in table_gen.m generate foreign_procs
	with variable numbers of arguments, the interfaces of those
	foreign_procs often do not match the interfaces of the existing
	library predicates at their core: they frequently have one more
	or one fewer argument. To prevent any possible confusion, in such
	cases we add a new variant of the predicate. These predicates
	have the suffix _shortcut in their name. Their implementations
	are dummy macros that do nothing; they serve merely as placeholders
	before or after which the macros that actually do the work are
	inserted.

	Move the definitions of the lookup, save and restore predicates
	into mercury_tabling_preds.h. Make the naming scheme of their
	arguments more regular.

runtime/mercury_minimal_model.c:
runtime/mercury_tabling_preds.h:
	Move the definition of a predicate from mercury_minimal_model.c
	to mercury_tabling_preds.h, since the compiler now needs to be
	able to generate an inlined version of it.

compiler/hlds_goal.m:
	Replace the three existing fields describing the arguments of
	foreign_procs with one, and add a new field describing the extra
	arguments that may be inserted by table_gen.m.

	Add utility predicates for processing the arguments of foreign_procs.

	Change the order of some existing groups of declarations make it
	more logical.

compiler/hlds_pred.m:
runtime/mercury_stack_layout.h:
	Extend the data structures recording the structure of tabling tries
	to allow the representation of trie steps for type_infos and
	typeclass_infos.

runtime/mercury_tabling_macros.c:
	Fix a bug regarding the tabling of typeclass_infos, which is now
	required for a clean compile.

compiler/pragma_c_gen.m:
compiler/ml_code_gen.m:
	Modify the generation of code for foreign_procs to handle extra
	arguments, and to conform to the new data structures for foreign_proc
	arguments.

compiler/llds.m:
	The tabling transformations can now generate significantly sized
	foreign_procs bodies, which the LLDS code generator translates to
	pragma_c instructions. Duplicating these by jump optimization
	may lose more by worsening locality than it gains in avoiding jumps,
	so we add an extra field to pragma_c instructions that tells jumpopt
	not to duplicate code sequences containing such pragma_cs.

compiler/jumpopt.m:
	Respect the new flag on pragma_cs.

compiler/goal_util.m:
	Add a predicate to create foreign_procs with specified contents,
	modelled on the existing predicate to create calls.

	Change the order of the arguments of that existing predicate
	to make it more logical.

compiler/polymorphism.m:
	Conform to the new definition of foreign_procs. Try to simplify
	the mechanism for generating the type_info and typeclass_info
	arguments of foreign_proc goals, but it is not clear that this
	code is even ever executed.

compiler/aditi_builtin_ops.m:
compiler/assertion.m:
compiler/bytecode_gen.m:
compiler/clause_to_proc.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/code_util.m:
compiler/constraint.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/dnf.m:
compiler/dupelim.m:
compiler/equiv_type_hlds.m:
compiler/exprn_aux.m:
compiler/follow_code.m:
compiler/follow_vars.m:
compiler/frameopt.m:
compiler/goal_form.m:
compiler/goal_path.m:
compiler/higher_order.m:
compiler/higher_order.m:
compiler/hlds_module.m:
compiler/hlds_out.m:
compiler/inlining.m:
compiler/ite_gen.m:
compiler/layout_out.m:
compiler/livemap.m:
compiler/liveness.m:
compiler/llds_out.m:
compiler/loop_inv.m:
compiler/magic.m:
compiler/make_hlds.m:
compiler/mark_static_terms.m:
compiler/middle_rec.m:
compiler/modes.m:
compiler/modules.m:
compiler/opt_debug.m:
compiler/pd_cost.m:
compiler/prog_rep.m:
compiler/purity.m:
compiler/quantification.m:
compiler/reassign.m:
compiler/rl_exprn.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/store_alloc.m:
compiler/stratify.m:
compiler/switch_detection.m:
compiler/term_pass1.m:
compiler/term_traversal.m:
compiler/termination.m:
compiler/trace.m:
compiler/typecheck.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unneeed_code.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
	Conform to the new definition of foreign_procs, pragma_cs and/or
	table trie steps, or to changed argument orders.

compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/cse_detection.m:
compiler/dead_proc_elim.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/lco.m:
compiler/module_util.m:
compiler/opt_util.m:
compiler/stack_opt.m:
compiler/trans_opt.m:
	Conform to the new definition of foreign_procs.

	Bring these modules up to date with our current code style guidelines,
	using predmode declarations, state variable syntax and unification
	expressions as appropriate.

compiler/mercury_compile.m:
	Conform to the changed argument order of a predicate in trans_opt.m.

compiler/options.m:
	Add the --no-tabling-via-extra-args option, but leave the
	documentation commented out since the option is for developers only.

doc/user_guide.texi:
	Document --no-tabling-via-extra-args option, though leave the
	documentation commented out since the option is for developers only.

doc/user_guide.texi:
doc/mdb_categories:
	Document the new goal_paths mdb command.

trace/mercury_trace_internals.c:
	Implement the new goal_paths mdb command.

tests/debugger/completion.exp:
	Conform to the presence of the goal_paths mdb command.

tests/debugger/mdb_command_test.inp:
	Test the existence of documentation for the goal_paths mdb command.

tests/debugger/print_table.{inp,exp*}:
tests/debugger/retry.{inp,exp*}:
	Use the goal_paths command to avoid having the expected output
	depend on the presence or absence of --tabling-via-extra-args.

tests/tabling/table_foreign_output.{m,exp}:
	Add a new test case to test the save/restore of arguments of foreign
	types.

tests/tabling/Mmakefile:
	Enable the new test case.

tests/tabling/test_tabling:
	Make this script more robust.

	Add an option for testing only the standard model forms of tabling.
2004-06-07 09:07:23 +00:00
Zoltan Somogyi
cc508c83de Perform frame optimization on nondet predicates.
Estimated hours taken: 6
Branches: main

Perform frame optimization on nondet predicates. The need for this was revealed
by benchmarking in Uppsala, which initially showed Mercury to take three to
five times as long as XSB on some tabling benchmarks. One major contributor
was the fact that the predicate returning answers out of answer table
was creating and destroying a nondet stack frame for every answer it returned.

To make this change easier, make the representation of labels more reader
friendly, classifying them primarily on whether they represent entry or
internal labels, and only secondarily on the scope in which they represent
valid references to the label.

compiler/frameopt.m:
	Add a predicate to perform frame optimization on model_non predicates.
	This optimization involves separating the steps of creating the frame
	(done once) and setting the redoip (potentially done on every
	iteration).

compiler/optimize.m:
	Invoke this new predicate. Reorder the arguments of predicates in this
	file, and the top level predicates of the optimizations it invokes,
	to allow the use of state variable notation.

runtime/mercury_stacks.h:
	Provide macros for creating nondet stack frames that do not fill in the
	redoip slot.

compiler/llds.m:
	Make the setting of redoip optional in mkframe operations.

	Make the representation of labels more reader friendly.

compiler/layout_out.m:
	Change the representation of label layouts to enforce the invariant
	that these can refer only to internal labels. (The layout structures
	of entry labels are proc layout structures, whose design enforces the
	relevant invariant already.)

compiler/jumpopt.m:
	Add an optimization that improves code that matches a new pattern:

	% Attempt to transform code such as
	%
	%       if (Cond) L1
	%       goto L2
	%
	% into
	%
	%       if (! Cond) L2
	%       <code at L1>
	%
	% when we know the code at L1 and don't know the code at L2.

	The new frame optimization creates instances of this pattern, usually
	with L2 being do_fail.

compiler/*.m:
	Minor diffs to conform to the changes above.
2004-05-23 23:14:37 +00:00
Zoltan Somogyi
c80d143cc8 The following change is only 98% complete, not 100%.
Estimated hours taken: 120
Branches: main

The following change is only 98% complete, not 100%. I am committing it in
this state because (1) we pass many more test cases in deep profiling grade
with it than without it, and (2) the double maintanance involved in fixing
CVS conflicts is preventing me from doing the last 2%.

Get the deep profiler to work for code that sets up to catch exceptions,
which for the last year or more has included the compiler, and to get it
almost working for code that actually catching exceptions.

The basic problem is that code that throws exceptions will in general cause
several calls to "return" without executing the exit or fail port codes that
the deep profiling transformation inserted into their bodies, and this leaves
the data structure being built by the deep profiling inconsistent. The solution
uses the same approach as we have adopted for the debugger: have the code that
handles the throwing of exceptions simulate a return from each call between
the throw and the catch, updating the deep profiling data structures as needed.

This requires us to be able to walk the stack at runtime not just in debugging
grades but also in deep profiling grades. Since the debugger already has the
mechanisms required for this, we reuse them. The procedure layouts used by the
debugger were designed to have three segments: the procedure stack walk
information, the procedure id, and the execution tracing information. We now
modify this design to make the third segment contain two pointers: to the
execution tracing information (for use by the debugger), and to the procedure's
proc_static structure (for use by deep profiling). Each pointer will be null
unless the pointed-to structure is required by compile-time options.

This common use by the debugger and by deep profiling of the stack-walk
structure and the procedure id structure (which deep profiling used to
generate independently and possibly redundantly) required some rearrangement
of the compiler's version of these data structures.

To make this rearrangement simpler, this diff removes a capability that
we theoretically supported but never used: turning on stack traces without
turning on execution tracing and vice versa. After this diff, stack tracing
is enabled if and only if either execution tracing or deep profiling is
enabled.

The diff also includes improvements in the debugging infrastructure for
debugging deep profiling, which were necessary for the implementation of the
rest of the changes.

compiler/deep_profiling.m:
	The code in exception.m needs to know the locations of the variables
	that we would pass to the exit or fail port code, so it can simulate
	leaving the procedure invocation through the exception port. Without
	this information, throwing an exception leaves the deep profiling
	data structures of the procedure invocations between throw and catch
	in an inconsistent state.

	Deep_profiling.m creates these variables, but it doesn't know where
	they will be at runtime, so it records their identities; the code
	generator will allocate them stack slots and record the numbers of
	these stack slots for placement in the now expanded proc layout
	structures. Deep profiling used to generate static data structures
	separately from the HLDS, but since the code generator now needs
	access to them, we store their information in proc_infos in the HLDS.

	Instead of passing the addresses of proc_static structures to the deep
	profiling port procedures, pass the address of proc_layout structures,
	since the information about the identities of procedures are now stored
	not in the proc_static structure, but in the proc_layout structure
	that points to the proc_static structure.

compiler/hlds_pred.m:
compiler/layout.m:
	Move the definitions of the static data structures generated by deep
	profiling from layout.m to hlds_pred.m, to allow deep_profiling.m
	to store them in proc_infos.

compiler/hlds_pred.m:
compiler/rtti.m:
	Move the definition of rtti_proc_label from rtti.m to hlds_pred.m,
	since some of the new data structures in hlds_pred.m need it. Despite
	its name, the rtti_proc_label type doesn't contain any info that
	doesn't belong in the HLDS.

	Add some information to the rtti_proc_label type that is now needed
	by deep profiling, e.g. record determinisms instead of just code
	models. Record explicitly the outcome of some tests that used to be
	duplicated in more than one place in the compiler, e.g. for whether
	the procedure (as opposed to the predicate) is imported. Change some
	of the field names to be more precise about the field's meaning.

compiler/code_gen.m:
	Transmit the contents of the deep profiling data structures stored in
	the proc_info by deep_profiling.m to continuation_info.m, together
	with the layout structures created for execution tracing and the
	identities of the variables needed for handling exceptions,
	when code generation for a procedure is complete.

	After the goal that generates these variables, save them to stack
	for use by the exception handler.

compiler/hlds_goal.m:
	Add a feature to mark the goal that generates the deep profiling
	variables needed by the exception handler.

compiler/hlds_llds.m:
	Add a utility predicate for new code in code_gen.m

compiler/continuation_info.m:
	Hold the deep profiling information computed by code_gen.m for use by
	stack_layout.m.

compiler/layout.m:
compiler/layout_out.m:
	Update the definitions of the data structures describing procedure
	layouts, and the code writing them out, to reflect the use of some
	parts of procedure layouts by deep profiling as well as debugging.

	Change the layout structures generated by deep profiling to use
	rtti_proc_labels, which are backend independent, instead of
	proc_labels, which are specific to the LLDS backend.

	Conform to the changes in runtime/mercury_stack_layout.h.

compiler/stack_layout.m:
	Generate the updated version of proc_layout structures.

compiler/mercury_compile.m:
compiler/global_data.m:
	Conform to the fact that deep profiling no longer generates layout
	structures separate from proc_infos.

compiler/llds_out.m:
	Register proc_layout structures instead of proc_static structures
	for use by runtime/mercury_deep_profiling.c.

compiler/options.m:
compiler/handle_options.m:
	Rename the require_tracing option as exec_trace, since this more
	directly reflects its meaning.

	Instead of having --debug set both require_tracing and stack_trace,
	make it set (be the user-visible name of) just exec_trace;
	the value of stack_trace is implied.

	Turn off the specialization of deep profiling for self-tail-recursive
	procedures for now. Due to the changes made by this diff in the data
	structures involved in debugging, it cannot be debugged until this
	change has been installed. Handling the full language is more important
	than a specialization that reduces only stack space overheads, not
	runtime overheads.

compiler/compile_target_code.m:
	Conform to the changes in options.m and runtime/mercury_grade.h.

compiler/hlds_data.m:
	Replace the deep_profiling_proc_static cons_id, and its associated tag,
	to deep_profiling_proc_layout, since we now generate addresses of proc
	layout structures, not of proc_static structures.

compiler/code_util.m:
	Simplify some code based on the new info in rtti_proc_labels.

compiler/bytecode_gen.m:
compiler/dependency_graph.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
compiler/ml_code_util.m:
compiler/ml_unify_gen.m:
compiler/opt_debug.m:
compiler/proc_label.m:
compiler/prog_rep.m:
compiler/rl_exprn.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/saved_vars.m:
compiler/switch_util.m:
compiler/unify_gen.m:
	Minor changes to conform to the change from deep_profiling_proc_static
	to deep_profiling_proc_layout, to the change in the structure of
	rtti_proc_labels, to the changes in types of layout.m, and/or to the
	new goal feature.

deep_profiler/measurements.m:
	Reserve space for exception counts.

deep_profiler/html_format.m:
	Add a column for exception counts.

deep_profiler/profile.m:
deep_profiler/read_profile.m:
	Rename the data structures referring to compiler generated unify,
	compare and index predicates to avoid misleading names: they are
	not the only compiler generated predicates.

deep_profiler/read_profile.m:
runtime/mercury_deep_profiling.c:
	Update the string that identifies deep profiling data files.
	This is necessary because the format has changed: it now includes
	information about exception port counts.

library/exception.m:
	In deep profiling grades, execute the exception port code for every
	procedure invocation between a throw and a catch, using the procedure
	layout structures now generated by the compiler for every procedure.
	Rename the function involved to reflect its new, more general purpose.

	Update the definitions of the hand-written proc_static and proc_layout
	structures for the procedures implemented via hand-written C code.

	Indent C preprocessor directives and foreign_procs according to our
	coding standards.

library/profiling_builtin.m:
	Change the parameters of the call port code procedures from proc_static
	to proc_layout. Reach the proc_static structure from the proc_layout
	structure when needed. Include the proc_layout structure in any
	messages from assertion failures.

	Add some conditionally compiled debugging code.

	Give some variables better names.

runtime/mercury_type_info.h:
runtime/mercury_builtin_types.c:
	Move the macros required to create the proc_static structures
	of unify and compare predicates from mercury_type_info.h
	to mercury_builtin_types.c, since the latter is the only file
	that needs them.

	Use the same macros for creating the proc_static structures
	of hand-written unify, compare and compare_reprentation predicates
	as for user defined predicates. This required changing their naming
	scheme.

runtime/mercury_unify_compare_body.h:
	Conform to the new naming scheme.

runtime/mercury_ho_call.c:
	Provide the mechanism for mercury_unify_compare_body.h to conform
	to the new naming scheme.

	Remove the definitions of the proc_static structures for
	hand-written unify, compare and compare_reprentation predicates,
	since these now have to be defined together with the corresponding
	proc_layout structures in mercury_builtin_types.c.

runtime/mercury_builtin_types.[ch]:
	Update the definitions of the hand-written proc_static and proc_layout
	structures for the procedures implemented via hand-written C code,
	and add the required declarations first.

	Handle deep profiling of compare_representation as well as unify
	and compare predicates on builtin types.

	Handle deep profiling of compare_representation on user-defined types,
	since this is done entirely in the runtime, not by compiler generated
	predicates.

runtime/mercury_builtin_types_proc_layouts.h:
	New header file containing the declarations of the proc layout
	structures of the unify, compare and index predicates of builtin types.
	Logically, these declarations belong in mercury_builtin_types.h,
	but putting them there causes problems for the linker; the details
	are explained in the file itself.

runtime/Mmakefile:
	Add the new header file.

runtime/mercury_minimal_model.[ch]:
	Update the definitions of the hand-written proc_static and proc_layout
	structures for the procedures implemented via hand-written C code,
	and add the required declarations first.

runtime/mercury_grade.h:
	Replace the MR_REQUIRE_TRACING grade option with MR_EXEC_TRACING.
	Besides being better named, the MR_EXEC_TRACING option implies
	MR_STACK_TRACE.

	Besides the overall binary compatibility version number, add subsidiary
	version numbers for binary compatibility in deep profiling and
	debugging grades. These will make it easier to bootstrap changes
	(such as this) that affect binary compatibility only in such grades.

runtime/mercury_trace_base.c:
trace/mercury_trace.c:
	Conform to the new names of the configuration parameters.

runtime/mercury_hand_compare_body.h:
runtime/mercury_hand_unify_body.h:
runtime/mercury_hand_unify_compare_body.h:
runtime/mercury_ho_call.c:
tools/make_port_code:
	Pass proc_layout structures instead of proc_static structures
	to deep profiling port routines.

runtime/mercury_conf_param.h:
	Make MR_DEEP_PROFILING as well as MR_EXEC_TRACING imply MR_STACK_TRACE,
	since deep profiling now needs stack tracing. (MR_STACK_TRACE needs
	to be set in this file, because tests in this file depend on knowing
	its value, and this file is among the first files included (in this
	case indirectly) in mercury_imp.h.)

	Document the macros controlling the debugging of deep profiling.

	Enable printing of label names when the relevant deep profiling
	debugging macro is set.

runtime/mercury_debug.c:
runtime/mercury_deep_rec_depth_actions.h:
runtime/mercury_deep_rec_depth_body.h:
runtime/mercury_exception_catch_body.h:
	Get to proc_statics via proc_layouts.

runtime/mercury_deep_call_port_body.c:
runtime/mercury_deep_leave_port_body.c:
	Get to proc_statics via proc_layouts.

	Allow the debugger to disable deep profiling in Mercury code that is
	part of the debugger, not of the user program being executed.

	Add some more assertions.

runtime/mercury_engine.[ch]:
	Add a new debugging flag that controls at runtime whether we generate
	a human readable Deep.debug equivalent to the binary Deep.data files.
	(We already had a mechanism for controlling this at compile time,
	but this isn't flexible enough.)

runtime/mercury_wrapper.c:
	Allow this new debugging flag to be set from MERCURY_OPTIONS.

runtime/mercury_deep_profiling.[ch]:
	Respect this new debugging flag.

	Update the hand-written proc_static structures representing the runtime
	system.

	Print out addresses of proc_layout as well as proc_static structures
	when assertions fail.

	Add a field to the measurement structure for exception port counts,
	and write out this field with the other port counts.

	Remove procedure id information from proc_static structures,
	deep profiling now uses the procedure id in the proc_layout structure.

	Add to proc_static structures fields that specify where, if anywhere,
	the variables needed by exception.m to executed the exception port code
	are in the procedure's stack frame.

	Define a global flag that allows the debugger to disable deep
	profiling in Mercury code that is part of the debugger, not of the
	user program being executed.

	Increase type safety by providing two versions of the function
	for registering proc_layouts, one for the proc_layout structures
	of user-defined predicates and one for unify, compare and index
	predicates.

	Fix a bug that occurs only if MR_DEEP_PROFILING_EXPLICIT_CALL_COUNTS is
	defined (which it usually isn't): the initial call count was wrong.

runtime/mercury_deep_profiling_hand.h:
	Fix a bug: the handwritten code saving deep profiling variables was
	saving them in slots that didn't belong to the relevant stack frame.

	Update to conform to the modified definitions of proc_static structures
	and the fact that we now reach them via proc_layout structures.

runtime/mercury_exception_catch_body.h:
runtime/mercury_stacks.h:
	Fix the other side of the bug in mercury_deep_profiling_hand.h
	by reserving the right number of stack slots in the stack frames
	of the various modes of exception__catch. Make it harder to make
	the same bug in the future by getting the needed info from the
	place in mercury_stacks.h that defines the structure of the relevant
	stack frame.

runtime/mercury_proc_id.h:
	Rename the procedure id structure fields referring to compiler
	generated unify, compare and index predicates: they are not the only
	compiler-generated predicates.

runtime/mercury_stack_layout.h:
	Change procedure layout structures to allow them to be used for deep
	profiling as well as for debugging, as described in the prologue above.

	We don't need the capability to support label layout structures with
	links to misnamed proc layout structures, and supporting it is
	inconvenient, so delete the capability.

runtime/mercury_debug.c:
runtime/mercury_deep_profiling_hand.h:
runtime/mercury_layout_util.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_stack_trace.c:
runtime/mercury_types.h:
trace/mercury_trace_external.c:
	Conform to the new names of the procedure id structure fields.

runtime/mercury_std.h:
	Add some more arities for MR_PASTE for use in some of the modified
	modules in the runtime.

trace/mercury_trace_internal.c:
	Disable deep profiling actions in Mercury code that is part of the
	debugger, not of the program being debugged.

scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
	Make changes parallel to the ones in runtime/mercury_grade.h: delete
	--stack-trace as an independent option, and make --debug set its
	own option, not --require-tracing.

scripts/canonical_grade.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/c2init.in:
scripts/mgnuc.in:
scripts/ml.in:
	Conform to the changes in grade options for debugging and for deep
	profiling.

tools/bootcheck:
	If Mmake.stage.{browser,deep,library,runtime,trace}.params exist,
	copy them to become the file Mmake.$dir.params in stage2/$dir
	(where dir is derived from the name of the original file in the obvious
	way). This allows more flexibility in the creation of the stage2;
	for example, it allows some directories (e.g. runtime or library)
	to be compiled with more debugging than other directories (e.g.
	compiler). This may be required because compiling all directories
	with lots of debugging may cause the linker to thrash.

	Add an option, --disable-debug-libs, that clobbers the libraries
	that should be linked in only in debugging grades.

	To conserve disk space, remove Deep.data files created by the bootcheck
	by default. Add an option, --keep-deep-data, to preserve these files.

	Use a consistent mechanism (test -f) for testing the existence of
	all files whose existence is tested.

	When recording modification times, record the modification times
	of some more files.

tests/hard_coded/Mmakefile:
	In deep profiling grades, disable the test cases that we don't now
	pass in such grades, and document the reasons for their failure.

	Fix the misclassification of the write_binary test case.
2004-05-19 04:00:01 +00:00
Zoltan Somogyi
bd1ea24cc3 Remove the dependence of this module on ll_backend.llds by defining
Estimated hours taken: 6
Branches: main

compiler/hlds_llds.m:
	Remove the dependence of this module on ll_backend.llds by defining
	types using abstract descriptions of LLDS storage locations. These
	have the added advantage that they express the intent of the affected
	data structures more directly. For example, the stack slot type used
	to be able to map a variable to a register or to a field of a cell
	on the heap, which doesn't make sense. This is no longer the case.
	The cost of the conversion operations now required is partly paid for
	by our new ability to avoid some old sanity checks.

compiler/llds.m:
compiler/code_util.m:
	Add some utility predicates to operate on the new data structures.

compiler/code_aux.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/follow_vars.m:
compiler/lookup_switch.m:
compiler/par_conj_gen.m:
compiler/stack_alloc.m:
compiler/store_alloc.m:
compiler/var_locn.m:
	Conform to the changes in hlds_llds.m. In some cases, improve the
	style of the affected predicates, e.g. by introducing state variable
	syntax.

compiler/hlds_out.m:
	Conform to the changes in hlds_llds.m, and avoid importing ll_backend.
2004-04-10 10:33:02 +00:00
Zoltan Somogyi
5d6fd3bd6f Reduce the dependence of earlier parts of the compiler on the later ones.
Estimated hours taken: 4
Branches: main

Reduce the dependence of earlier parts of the compiler on the later ones.
Unnecessary import_module declarations in top level modules such as hlds.m
cause unnecessary recompilations when adding new types in later modules,
such as submodules of ll_backend.m. This change reduces the number of such
unnecessary imports.

There are no changes in algorithms, only functionality being moved around.

compiler/code_model.m:
	Change this module from being a submodule of backend_libs.m to being a
	submodule of hlds.m, since nothing in it is dependent on any backend.

compiler/arg_info.m:
compiler/code_util.m:
	Change arg_info.m from being a submodule of ll_backend.m to being a
	submodule of hlds.m, since most of it is applicable to all current
	and foreseeable backends. Move the one exported predicate that is
	ll_backend dependent, and its support predicates, to code_util.m.

compiler/backend_libs.m:
compiler/ll_backend.m:
compiler/hlds.m:
	Update include_module declarations in accordance with the above.

compiler/prog_data.m:
compiler/term_util.m:
	Instead of defining two separate types for holding argument size and
	termination information, one including HLDS-specific information (in
	term_util.m) and one not (in prog_data.m), use a polymorphic type
	defined in prog_data.m and two monomorphic instances.

compiler/termination.m:
compiler/mercury_to_mercury.m:
	Change the predicates for writing out argument size and termination
	information to handle the polymorphic type (we don't need special
	handling of the monomorphic versions), and move them from termination.m
	to mercury_to_mercury.m, since this allows us to avoid some
	undesirable dependencies.

compiler/base_typeclass_info.m:
compiler/hlds_code_util.m:
	Move the predicate make_instance_string from base_typeclass_info.m
	to hlds_code_util.m, again because it allows us to remove some
	undesirable dependencies.

compiler/top_level.m:
compiler/backend_libs.m:
compiler/check_hlds.m:
compiler/hlds.m:
compiler/ll_backend.m:
compiler/parse_tree.m:
compiler/transform_hlds.m:
	Delete some import_module declarations of other top level modules
	in these top level modules. Some imports were totally unnecessary.
	Some imports were useful in only a small minority of submodules;
	those submodules now import the necessary top level modules directly.

	Move remaining import_module declarations to the implementation section
	where this is feasible.

	Where we still need to import modules we ideally shouldn't, note why.

compiler/*.m:
	Update imports of code_util and arg_info.

	In some cases, import top level modules no longer imported by the
	parent module.

	In some cases, delete unnecessary imports.
2004-03-23 10:52:14 +00:00
Zoltan Somogyi
6ac84aac9f Bring these modules up to date with our current code style.
Estimated hours taken: 4
Branches: main

compiler/code_util.m:
compiler/fact_table.m:
compiler/make_tags.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
	Bring these modules up to date with our current code style.

	Use predmode declarations and state variable syntax where appropriate,
	and reorder arguments where this is needed to use state variable
	syntax.

	Break up excessively large and/or excessively indented predicates.
	Factor out common code and fix indentation.

	Use error_util to print error messages where appropriate.

	In fact_util.m, change predicates that took I/O state arguments to
	print error messages to return a list of error reports instead,
	to be printed by an ancestor. This makes it clearer which parts of the
	module actually have file I/O as part of their main job.

compiler/special_pred.m:
	Shorten an excessively long predicate name, since without this some of
	the above modules cannot be indented properly.

compiler/make_hlds.m:
	Use the new shorter predicate name.

compiler/code_gen.m:
compiler/ml_code_util.m:
	Fix indentation.

compiler/hlds_out.m:
	Add a predicate for use by the new version of fact_table.m
2004-03-23 06:56:42 +00:00
Zoltan Somogyi
92045bdc78 Simplify the handling of static ground terms in the LLDS backend.
Estimated hours taken: 5
Branches: main

Simplify the handling of static ground terms in the LLDS backend. Instead of
creating code, rtti and layout structures all containing create rvals and then
converting those rvals to static cells, create the static cells directly.

compiler/llds.m:
	Remove the create alternative from rvals, and the types used only by
	create.

	Delete the code handling the global_data type, which has been moved to
	global_data.m.

compiler/global_data.m:
	A new module handling static data structures for the LLDS backend.
	The basis of this module is the code that used to be in llds.m handling
	the global_data type, but this has been augmented to manage static
	cells as well as the data structures defined in rtti.m and layout.m.

	Also, rename the non_common_data field of global_data, which no longer
	makes sense, to refer to deep profiling, since it holds deep profiling
	data structures.

compiler/llds_common.m:
	Delete this file, since it is no longer needed. The operative part
	is now in global data.m; the rest (including the code to traverse code
	and data structures looking for create rvals) is no longer needed.

compiler/ll_backend.m:
	Delete the deleted module, and add the added module.
	XXX These changes should be also be documented in
	notes/compiler_design.html when Fergus finishes his changes
	to that file.

compiler/code_info.m:
	Add the database of static cells to the code generator state.

compiler/code_gen.m:
compiler/ll_pseudo_type_info.m:
compiler/lookup_switch.m:
compiler/mercury_compile.m:
compiler/stack_layout.m:
compiler/static_term.m:
compiler/string_switch.m:
compiler/unify_gen.m:
compiler/var_locn.m:
	Instead of creating create rvals, create static cells and return
	references to those cells. The static cell database ensures that we
	never create duplicate cells (unless --no-common-data forces us
	to do so). Pass around the static cell database.

compiler/code_util.m:
compiler/continuation_info.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/optimize.m:
	Minor changes to conform to the above, mostly consisting of the
	deletion of code that handled create rvals.
2003-05-09 05:51:52 +00:00
Zoltan Somogyi
9b0aa613c4 Delete the cell number field from create rvals, since we don't need
Estimated hours taken: 1
Branches: main

compiler/llds.m:
	Delete the cell number field from create rvals, since we don't need
	it anymore.

compiler/*.m:
	Conform to the change above, and simplify predicate interfaces by
	deleting arguments whose sole purpose was the allocation of cell
	numbers.
2003-05-01 22:50:50 +00:00
Zoltan Somogyi
d3e315ffd2 Move functionality that is not part of the LLDS backend from
Estimated hours taken: 1
Branches: main

compiler/code_util.m:
compiler/goal_form.m:
compiler/hlds_code_util.m:
	Move functionality that is not part of the LLDS backend from
	ll_backend__code_util to hlds__goal_form and to hlds__hlds_code_util.

	Turn some predicates into functions.

compiler/*.m:
	Conform to the changes above.
2003-03-15 07:11:56 +00:00