Commit Graph

82 Commits

Author SHA1 Message Date
Quan Phan
d4818a3ca4 Modify the code generator so that it recognizes construct_in_region and
Estimated hours taken: 35.
Branch: main.

Modify the code generator so that it recognizes construct_in_region and
generates suitable code when RBMM is used. The main
changes are in unify_gen.m. incr_hp is also changed to receive one more
(maybe) argument for region.

compiler/unify_gen.m:
	Make it aware of HowToConstruct. This is the starting point of the
	changes in the code generator so that it can generate code which
	constructs terms in regions.

compiler/code_info.m:
compiler/var_locn.m:
        Change in accordance with the introduction of how_to_construct in
	unify_gen.m.

compiler/llds.m:
	Add one extra argument to incr_hp for the region to construct terms
	in.

compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_to_x86_64.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/reassign.m:
compiler/use_local_vars.m:
	Change to deal with the extra maybe region argument in incr_hp.

compiler/llds_out.m:
	Modify so that when RBMM is used it generates suitable call to
	the region runtime for allocating terms in regions. The region
	runtime (in C code) will be posted in anothe email.

compiler/hlds_data.m:
	Fix a typo.

compiler/rbmm.interproc_region_lifetime.m:
	Change to comply with coding standard.
2007-07-09 13:28:36 +00:00
Simon Taylor
5647714667 Make all functions which create strings from characters throw an exception
Estimated hours taken: 15
Branches: main

Make all functions which create strings from characters throw an exception
or fail if the list of characters contains a null character.

This removes a potential source of security vulnerabilities where one
part of the program performs checks against the whole of a string passed
in by an attacker (processing the string as a list of characters or using
`unsafe_index' to look past the null character), but then passes the string
to another part of the program or an operating system call that only sees
up to the first null character.  Even if Mercury stored the length with
the string, allowing the creation of strings containing nulls would be a
bad idea because it would be too easy to pass a string to foreign code
without checking.

For examples see:
<http://insecure.org/news/P55-07.txt>
<http://www.securiteam.com/securitynews/5WP0B1FKKQ.html>
<http://www.securityfocus.com/archive/1/445788>
<http://www.securityfocus.com/archive/82/368750>
<http://secunia.com/advisories/16420/>

NEWS:
	Document the change.

library/string.m:
	Throw an exception if null characters are found in
	string.from_char_list and string.from_rev_char_list.

	Add string.from_char_list_semidet and string.from_rev_char_list_semidet
	which fail rather throwing an exception.  This doesn't match the
	normal naming convention, but string.from_{,rev_}char_list are widely
	used, so changing their determinism would be a bit too disruptive.

	Don't allocate an unnecessary extra word for each string created by
	from_char_list and from_rev_char_list.

	Explain that to_upper and to_lower only work on un-accented
	Latin letters.

library/lexer.m:
	Check for invalid characters when reading Mercury strings and
	quoted names.

	Improve error messages by skipping to the end of any string
	or quoted name containing an error.  Previously we just stopped
	processing at the error leaving an unmatched quote.

library/io.m:
	Make io.read_line_as_string and io.read_file_as_string return
	an error code if the input file contains a null character.

	Fix an XXX: '\0\' is not recognised as a character constant,
	but char.det_from_int can be used to make a null character.

library/char.m:
	Explain the workaround for '\0\' not being accepted as a char
	constant.

	Explain that to_upper and to_lower only work on un-accented
	Latin letters.

compiler/layout.m:
compiler/layout_out.m:
compiler/c_util.m:
compiler/stack_layout.m:
compiler/llds.m:
compiler/mlds.m:
compiler/ll_backend.*.m:
compiler/ml_backend.*.m:
	Don't pass around strings containing null characters (the string
	tables for the debugger).  This doesn't cause any problems now,
	but won't work with the accurate garbage collector.  Use lists
	of strings instead, and add the null characters when writing the
	strings out.

tests/hard_coded/null_char.{m,exp}:
	Change an existing test case to test that creation of a string
	containing a null throws an exception.

tests/hard_coded/null_char.exp2:
	Deleted because alternative output is no longer needed.

tests/invalid/Mmakefile:
tests/invalid/null_char.m:
tests/invalid/null_char.err_exp:
	Test error messages for construction of strings containing null
	characters by the lexer.

tests/invalid/unicode{1,2}.err_exp:
	Update the expected output after the change to the handling of
	invalid quoted names and strings.
2007-03-18 23:35:04 +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
Zoltan Somogyi
d66ed699a1 Add fields to structures representing the C code itself that says whether
Estimated hours taken: 4
Branches: main

Add fields to structures representing the C code itself that says whether
or not the C code affects the liveness of lvals. This is intended as the basis
for future improvements in the optimization of such code.

Implement a new foreign_proc attribute that allows programmers to set
the value of this field.

Eliminate names referring to `pragma c_code' in the LLDS backend in favor
of names referring to foreign_procs.

compiler/llds.m:
	Make the changes described above.

	Consistently put the field containing C code last in the function
	symbols that contain them.

compiler/prog_data.m:
	Make the changes described above.

	Rename some other function symbols to avoid ambiguity.

compiler/prog_io_pragma.m:
	Parse the new foreign_proc attribute.

doc/reference_manual.texi:
	Document the new attribute.

compiler/pragma_c_gen.m:
	Rename the main predicates.

compiler/opt_util.m:
	Change some predicates into functions, for more convenient invocation.

compiler/livemap.m:
	Rename the predicates in this module to avoid ambiguity and the need
	for module qualification.

compiler/*.m:
	Conform to the changes above.
2007-01-03 07:20:47 +00:00
Zoltan Somogyi
ecf1ee3117 Add a mechanism for growing the stacks on demand by adding new segments
Estimated hours taken: 20
Branches: main

Add a mechanism for growing the stacks on demand by adding new segments
to them. You can ask for the new mechanism via a new grade component, stseg
(short for "stack segments").

The mechanism works by adding a test to each increment of a stack pointer (sp
or maxfr). If the test indicates that we are about to run out of stack, we
allocate a new stack segment, allocate a placeholder frame on the new segment,
and then allocate the frame we wanted in the first place on top of the
placeholder. We also override succip to make it point code that will (1)
release the new segment when the newly created stack frame returns, and then
(2) go to the place indicated by the original, overridden succip.

For leaf procedures on the det stack, we optimize away the check of the stack
pointer. We can do this because we reserve some space on each stack for the
use of such stack frames.

My intention is that doc/user_guide.texi and NEWS will be updated once we have
used the feature ourselves for a while and it seems to be stable.

runtime/mercury_grade.h:
	Add the new grade component.

runtime/mercury_conf_param.h:
	Document the new grade component, and the option used to debug stack
	segments.

runtime/mercury_context.[ch]:
	Add new fields to contexts to hold the list of previous segments of the
	det and nondet stacks.

runtime/mercury_memory_zones.[ch]:
	Include a threshold in all zones, for use in stack segments.
	Set it when a zone is allocated.

	Restore the previous #ifdef'd out function MR_unget_zone, for use
	when freeing stack segments execution has fallen out of.

runtime/mercury_debug.[ch]:
	When printing the offsets of pointers into the det and nondet stacks,
	print the number of the segment the pointer points into (unless it is
	the first, in which case we suppress this in the interest of brevity
	and simplicity).

	Make all the functions in this module take a FILE * as an input
	argument; don't print to stdout by default.

runtime/mercury_stacks.[ch]:
	Modify the macros that allocate stack frames to invoke the code for
	adding new stack segments when we are about to run out of stack.

	Standardize on "nondet" over "nond" as the abbreviation referring to
	the nondet stack.

	Conform to the changes in mercury_debug.c.

runtime/mercury_stack_trace.c:
	When traversing the stack, step over the placeholder stack frames
	at the bottoms of stack segments.

	Conform to the changes in mercury_debug.c.

runtime/mercury_wrapper.[ch]:
	Make the default stack size small in grades that support stack
	segments.

	Standardize on "nondet" over "nond" as the abbreviation referring to
	the nondet stack.

	Conform to the changes in mercury_debug.c.

runtime/mercury_memory.c:
	Standardize on "nondet" over "nond" as the abbreviation referring to
	the nondet stack.

runtime/mercury_engine.[ch]:
runtime/mercury_overflow.h:
	Standardize on "nondet" over "nond" as the abbreviation referring to
	the nondet stack.

	Convert these files to four-space indentation.

runtime/mercury_minimal_model.c:
trace/mercury_trace.c:
trace/mercury_trace_util.c:
	Conform to the changes in mercury_debug.c.

compiler/options.m:
	Add the new grade option for stack segments.

compiler/compile_target_code.m:
compiler/handle_options.m:
	Add the new grade component, and handle its exclusions with other grade
	components and optimizations.

compiler/llds.m:
	Extend the incr_sp instruction to record whether the stack frame
	is for a leaf procedure.

compiler/llds_out.m:
	Output the extended incr_sp instruction.

compiler/proc_gen.m:
	Fill in the extra slot in incr_sp instructions.

compiler/goal_util.m:
	Provide a predicate for testing whether a procedure body is a leaf.

compiler/delay_slot.m:
compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/frameopt.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/peephole.m:
compiler/reassign.m:
compiler/use_local_vars.m:
	Conform to the change in llds.m.

scripts/canonicate_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/mgnuc.in:
	Handle the new grade component.

	Convert parse_grade_options.sh-subr to four-space indentation.

Mmake.workspace:
	Fix an old bug that prevented bootcheck from working in the new grade:
	when computing the gc grade, use the workspace's version of ml (which
	in this case understands the new grade components), rather than the
	installed ml (which does not).

	(This was a devil to track down, because neither make --debug nor
	strace on make revealed how the installed ml was being invoked,
	and there was no explicit invocation in the Makefile either; the error
	message appeared to come out of thin air just before the completion
	of the stage 2 library. It turned out the invocation happened
	implicitly, as a result of expanding a make variable.)
2006-11-01 02:31:19 +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
Zoltan Somogyi
4924dfb1c9 One of Hans Boehm's papers says that heap cells allocated by GC_MALLOC_ATOMIC
Estimated hours taken: 5
Branches: main

One of Hans Boehm's papers says that heap cells allocated by GC_MALLOC_ATOMIC
are grouped together into pages, and these pages aren't scanned during the
sweep phase of the garbage collector. I therefore modified the compiler
to use GC_MALLOC_ATOMIC instead of GC_MALLOC whereever possible, i.e
when the cell being allocated is guaranteed not to have any pointer to
GCable memory inside it.

My first benchmarking run showed a speedup of 4.5% in asm_fast.gc:

EXTRA_MCFLAGS = --use-atomic-cells
mercury_compile.01 average of 6 with ignore=1     18.30
EXTRA_MCFLAGS = --no-use-atomic-cells
mercury_compile.02 average of 6 with ignore=1     19.17

However, later benchmarks, after the upgrade to version 7.0 of boehm_gc,
show a less favourable and more mixed picture, with e.g. a 4% speedup
in hlc.gc at -O3, a 3% slowdown in asm_fast.gc at -O4, and little effect
otherwise:

EXTRA_MCFLAGS = -O1 --use-atomic-cells
GRADE = asm_fast.gc
mercury_compile.01 average of 6 with ignore=1     23.30
EXTRA_MCFLAGS = -O1 --no-use-atomic-cells
GRADE = asm_fast.gc
mercury_compile.02 average of 6 with ignore=1     23.28

EXTRA_MCFLAGS = -O2 --use-atomic-cells
GRADE = asm_fast.gc
mercury_compile.03 average of 6 with ignore=1     18.51
EXTRA_MCFLAGS = -O2 --no-use-atomic-cells
GRADE = asm_fast.gc
mercury_compile.04 average of 6 with ignore=1     18.66

EXTRA_MCFLAGS = -O3 --use-atomic-cells
GRADE = asm_fast.gc
mercury_compile.05 average of 6 with ignore=1     18.44
EXTRA_MCFLAGS = -O3 --no-use-atomic-cells
GRADE = asm_fast.gc
mercury_compile.06 average of 6 with ignore=1     18.48

EXTRA_MCFLAGS = -O4 --use-atomic-cells
GRADE = asm_fast.gc
mercury_compile.07 average of 6 with ignore=1     18.28
EXTRA_MCFLAGS = -O4 --no-use-atomic-cells
GRADE = asm_fast.gc
mercury_compile.08 average of 6 with ignore=1     17.70

EXTRA_MCFLAGS = -O1 --use-atomic-cells
GRADE = hlc.gc
mercury_compile.09 average of 6 with ignore=1     24.78
EXTRA_MCFLAGS = -O1 --no-use-atomic-cells
GRADE = hlc.gc
mercury_compile.10 average of 6 with ignore=1     24.69

EXTRA_MCFLAGS = -O2 --use-atomic-cells
GRADE = hlc.gc
mercury_compile.11 average of 6 with ignore=1     19.36
EXTRA_MCFLAGS = -O2 --no-use-atomic-cells
GRADE = hlc.gc
mercury_compile.12 average of 6 with ignore=1     19.26

EXTRA_MCFLAGS = -O3 --use-atomic-cells
GRADE = hlc.gc
mercury_compile.13 average of 6 with ignore=1     18.64
EXTRA_MCFLAGS = -O3 --no-use-atomic-cells
GRADE = hlc.gc
mercury_compile.14 average of 6 with ignore=1     19.38

EXTRA_MCFLAGS = -O4 --use-atomic-cells
GRADE = hlc.gc
mercury_compile.15 average of 6 with ignore=1     19.39
EXTRA_MCFLAGS = -O4 --no-use-atomic-cells
GRADE = hlc.gc
mercury_compile.16 average of 6 with ignore=1     19.41

runtime/mercury_heap.h:
	Define atomic equivalents of the few heap allocation macros
	that didn't already have one. These macros are used by the LLDS
	backend.

runtime/mercury.h:
	Define an atomic equivalent of the MR_new_object macro.
	These macros are used by the MLDS backend.

	Use MR_new_object_atomic instead of MR_new_object to box floats.

compiler/hlds_data.m:
compiler/llds.m:
compiler/mlds.m:
	Modify the representations of the heap allocations constructs
	to include a flag that says whether we should use the atomic variants
	of the heap allocation macros.

compiler/llds_out.m:
compiler/mlds_to_c.m:
	Respect this extract flag when emitting C code.

	In mlds_to_c.m, also add some white space that makes the code easier
	for humans to read.

compiler/type_util.m:
	Add a mechanism for finding out whether we can put a value of a given
	type into an atomic cell.

	Put the definitions of functions and predicates in this module
	in the same order as their declarations.

	Turn some predicates into functions. Change the argument order of
	some predicates to conform to our usual conventions.

compiler/unify_gen.m:
compiler/ml_unify_gen.m:
	Use the new mechanism in type_util.m to generate code that creates
	atomic heap cells if this is possible and is requested.

compiler/code_info.m:
compiler/var_locn.m:
	Act on the information provided by unify_gen.m.

compiler/options.m:
doc/user_guide.texi:
	Add an option to control whether the compiler should try to use
	atomic cells.

compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/higher_order.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/middle_rec.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_util.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modecheck_unify.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/polymorphism.m:
compiler/reassign.m:
compiler/size_prof.m:
compiler/structure_sharing.domain.m:
compiler/use_local_vars.m:
	Minor diffs to conform to the changes above.

compiler/structure_reuse.direct.choose_reuse.m:
	Add an XXX comment about the interaction of the new capability
	with structure reuse.
2006-08-20 05:01:48 +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
469f1dc09b This diff contains no algorithmic changes.
Estimated hours taken: 1.5
Branches: main

This diff contains no algorithmic changes.

compiler/llds.m:
compiler/mlds.m:
	Rename some function symbols and field names to avoid ambiguities
	with respect to language keywords.

compiler/*.m:
	Conform to the changes in llds.m and mlds.m.
2006-07-28 05:08:15 +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
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
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
4d377aba26 Fix a bug reported by Greg Duck. The bug was that the compiler always generated
Estimated hours taken: 5
Branches: main

Fix a bug reported by Greg Duck. The bug was that the compiler always generated
a global variable of type MR_Word for each mutable, but could then assign
variables of other types to and from this global. If this other type is
float, the assignments discard the fractional part. If this other type
is something else, the result can be even worse.

There are two ways to fix this discrepancy. One is to change the type of the
global, and the other is to change the type of the variables it is assigned
to and from. The former looks cleaner, but it would mean that every call
to the get predicate would require a boxing operation, and that can be
relatively slow, since (e.g. for floats) it may require allocating a heap cell.
This diff implements both solutions.

We use the second solution on the LLDS backend because of its better
performance. We have to use the first solution on the MLDS backend,
because on that backend the type of the mutable variable is reflected
in the signature of the getter and setter predicates (whereas on the
LLDS backend all arguments are always MR_Words).

compiler/options.m:
	Add an internal-only option that controls whether we use the first
	solution or the second.

compiler/handle_options.m:
	Make the MLDS backend imply the first solution.

compiler/prog_data.m:
	For each argument of a foreign_proc item, record whether we want to
	keep it boxed in the foreign code.

	Add a foreign_proc attribute that asks for every arg to be kept boxed.
	We can attach this to the mutable implementation foreign_procs we write
	out to .opt files. This attribute is deliberately undocumented since
	users should never use it.

compiler/make_hlds_passes.m:
	For each argument of the get and set foreign_procs we create for
	mutables, record that we do want to keep it boxed.

	Move the action of creating the foreign code for the mutable's
	declaration and definition to the third pass, since during the second
	pass we don't necessarily know yet what its foreign type is (we may not
	have processed a foreign_type declaration affecting it). Move the code
	for creating the foreign code here from prog_mutable, since it depends
	on the HLDS (and prog_mutable.m is in the parse_tree package).

	Hoist some error handling code to put it where it belongs,
	and to avoid some errors being reported twice.

compiler/hlds_goal.m:
	For each argument of a foreign_proc goal, record whether we want to
	keep it boxed in the foreign code.

compiler/llds_out.m:
compiler/pragma_c_gen.m:
compiler/ml_code_gen.m:
compiler/ml_call_gen.m:
	If a foreign_proc argument is noted as being kept boxed in the
	foreign_proc code, then keep it that way.

compiler/prog_io_pragma.m:
	Parse the new foreign_proc annotation.

compiler/simplify.m:
	If a foreign_proc has the always_boxed annotation, attach this info
	to each of its args. We do this here because simplify is guaranteed
	to be executed before all the code that may inspect these arguments.
	Since nothing ever deletes an always_boxed annotation of a foreign_proc
	arg, the code that attaches the annotation is idempotent, so the fact
	that the compiler executes simplify twice is not a problem.

compiler/*.m:
	Minor changes to conform to the changes in data structures above.

compiler/prog_type.m:
	Move a function definition from prog_mutable to prog_type, and
	fix the lack of abstraction in its code.

compiler/prog_mutable.m:
	Delete the code moved to make_hlds_passes.m and prog_type.m.

compiler/notes/compiler_design.html:
	Make the documentation of prog_mutable.m easier to read in source.

tests/hard_coded/float_gv.{m,exp}:
	An extended version of Greg's code as a new test case.

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

tests/hard_coded/sub-modules/non_word_mutable.{m,exp}:
tests/hard_coded/sub-modules/non_word_mutable.child.m:
	A version of the float_gv test case in which the compiler-generated
	get and set foreign_procs should end up in .opt files.

tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/Mercury_options:
	Enable the new test case, and make it execute with intermodule
	optimization.

tests/invalid/bad_mutable.err_exp:
	Expect the new output (in which an error is reported just once,
	not twice).
2006-02-24 01:42:19 +00:00
Julien Fischer
5f589e98fb Various cleanups for the modules in the compiler directory.
Estimated hours taken: 4
Branches: main

Various cleanups for the modules in the compiler directory.  The are
no changes to algorithms except the replacement of some if-then-elses
that would naturally be switches with switches and the replacement of
most of the calls to error/1.

compiler/*.m:
	Convert calls to error/1 to calls to unexpected/2 or sorry/2 as
	appropriate throughout most or the compiler.

	Fix inaccurate assertion failure messages, e.g. identifying the
	assertion failure as taking place in the wrong module.

	Add :- end_module declarations.

	Fix formatting problems and bring the positioning of comments
	into line with our current coding standards.

	Fix some overlong lines.

	Convert some more modules to 4-space indentation.  Fix some spots
	where previous conversions to 4-space indentation have stuffed
	the formatting of the code up.

	Fix a bunch of typos in comments.

	Use state variables in more places; use library predicates
	from the sv* modules where appropriate.

	Delete unnecessary and duplicate module imports.

	Misc. other small cleanups.
2005-11-17 15:57:34 +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
d609181cb9 Consider types of the form
Estimated hours taken: 30
Branches: main

Consider types of the form

	:- type x ---> f.

to be dummy types, since they contain no information. Optimize them the same
way we currently optimize io.state and store.store.

runtime/mercury_type_info.h:
	Add a new type_ctor_rep for dummy types.

runtime/mercury_tabling.h:
	Add a representation for "tabled" dummy types, which don't actually
	have a level in the trie, so that the runtime system can handle that
	fact.

runtime/mercury_ml_expand_body.h:
	When deconstructing a value of a dummy type, ignore the actual value
	(since it will contain garbage) and instead return the only possible
	value of the type.

runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.c:
runtime/mercury_tabling.c:
runtime/mercury_unify_compare_body.h:
library/rtti_implementation.m:
	Handle the type_ctor_rep of dummy types.

runtime/mercury_builtin_types.c:
	Provide a place to record profiling information about unifications and
	comparisons for dummy types.

runtime/mercury_mcpp.h:
java/runtime/TypeCtorRep.java:
library/private_builtin.m:
	Add a new type_ctor_rep for dummy types, and fix some previous
	discrepancies in type_ctor_reps.

mdbcomp/prim_data.m:
	Move a bunch of predicates for manipulating special_pred_ids here from
	the browser and compiler directories.

	Rename the function symbols of the special_pred_id type to avoid the
	need to parenthesize the old `initialise' function symbol.

	Convert to four-space indentation.

mdbcomp/rtti_access.m:
	Don't hardcode the names of special preds: use the predicates in
	prim_data.m.

	Convert to four-space indentation.

browser/declarative_execution.m:
	Delete some predicates whose functionality is now in
	mdbcomp/prim_data.m.

compiler/hlds_data.m:
	Replace the part of du type that says whether a type an enum, which
	used to be a bool, with something that also says whether the type is a
	dummy type.

	Convert to four-space indentation.

compiler/make_tags.m:
	Compute the value for the new field of du type definitions.

compiler/hlds_out.m:
	Write out the new field of du type definitions.

compiler/rtti.m:
	Modify the data structures we use to create type_ctor_infos to allow
	for dummy types.

	Convert to four-space indentation.

compiler/type_ctor_info.m:
	Modify the code that generates type_ctor_infos to handle dummy types.

compiler/type_util.m:
	Provide predicates for recognizing dummy types.

	Convert to four-space indentation.

compiler/unify_proc.m:
	Generate the unify and compare predicates of dummy types using a new
	code scheme that avoids referencing arguments that contain garbage.

	When generating code for unifying or comparing other types, ignore
	any arguments of function symbols that are dummy types.

	Don't use DCG style access predicates.

compiler/higher_order.m:
	Specialize the unification and comparison of values of dummy types.

	Break up an excessively large predicate, and factor out common code
	from the conditions of a chain of if-then-elses.

compiler/llds.m:
	For each input and output of a foreign_proc, include a field saying
	whether the value is of a dummy type.

compiler/pragma_c_gen.m:
	Fill in the new fields in foreign_proc arguments.

compiler/hlds_goal.m:
	Rename some predicates for constructing unifications to avoid
	unnecessary ad-hoc overloading. Clarify their documentation.

	Rename a predicate to make clear the restriction on its use,
	and document the restriction.

	Add a predicate for creating simple tests.

	Add a utility predicate for setting the context of a goal directly.

compiler/modules.m:
	Include dummy types interface files, even if they are private to the
	module. This is necessary because with the MLDS backend, the generated
	code inside the module and outside the module must agree whether a
	function returning a value of the type returns a real value or a void
	value, and this requires them to agree on whether the type is dummy
	or not.

	The impact on interface files is minimal, since very few types are
	dummy types, and changing a type from a dummy type to a non-dummy type
	or vice versa is an ever rarer change.

compiler/hlds_pred.m:
	Provide a representation in the compiler of the trie step for dummy
	types.

compiler/layout_out.m:
	Print the trie step for dummy types.

compiler/table_gen.m:
	Don't table values of dummy types, and record the fact that we don't
	by including a dummy trie step in the list of trie steps.

compiler/add_pragma.m:
compiler/add_special_pred.m:
compiler/add_type.m:
compiler/aditi_builtin_ops.m:
compiler/bytecode.m:
compiler/bytecode_gen.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/cse_detection.m:
compiler/det_report.m:
compiler/exception_analysis.m:
compiler/inst_match.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_il.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/opt_util.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/qual_info.m:
compiler/rl.m:
compiler/rl_exprn.m:
compiler/rl_key.m:
compiler/rtti_out.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/term_constr_initial.m:
compiler/term_constr_util.m:
compiler/term_norm.m:
compiler/termination.m:
compiler/trace.m:
compiler/typecheck.m:
compiler/unify_gen.m:
	Conform to the changes above.

compiler/export.m:
compiler/exprn_aux.m:
compiler/foreign.m:
compiler/polymorphism.m:
compiler/proc_label.m:
compiler/rtti_to_mlds.m:
compiler/special_pred.m:
compiler/stack_alloc.m:
compiler/stack_layout.m:
compiler/state_var.m:
compiler/switch_util.m:
compiler/trace_params.m:
	Conform to the changes above.

	Convert to four-space indentation.

compiler/mlds_to_java.m:
compiler/var_locn.m:
	Conform to the changes above, which requires threading the module_info
	through the module.

	Convert to four-space indentation.

compiler/mercury_compile.m:
	Pass the module_info to mlds_to_java.m.

compiler/ml_util.m:
compiler/polymorphism.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
	Delete some previously missed references to the temporary types used
	to bootstrap the change to the type_info type's arity.

compiler/polymorphism.m:
	Turn back on an optimization that avoids passing parameters (such as
	type_infos) to foreign_procs if they are not actually referred to.

compiler/prog_data.m:
	Convert to four-space indentation.

library/svvarset.m:
	Add a missing predicate.

trace/mercury_trace.c:
	Delete the unused function that used to check for dummy types.

tests/debugger/field_names.{m,inp,exp}:
	Add to this test case a test of the handling of dummy types. Check that
	their values can be printed out during normal execution, and that the
	debugger doesn't consider them live nondummy variables, just as it
	doesn't consider I/O states live nondummy variables.
2005-10-05 06:34:27 +00:00
Zoltan Somogyi
753d9755ae When returning from det and semidet predicates, load the return address into a
Estimated hours taken: 3
Branches: main

When returning from det and semidet predicates, load the return address into a
local C variable instead of the succip abstract machine "register" before
popping the stack frame and returning. This gives the C compiler more freedom
to reorder instructions.

This diff gets a 1.4% speed increase on the compiler.

runtime/mercury_stacks.h:
	Provide a new macro, MR_decr_sp_and_return, to do the combined job that
	its name describes.

compiler/llds.m:
	Add a new LLDS instruction that corresponds to the new macro.

compiler/llds_out.m:
	Output the new LLDS instruction.

compiler/peephole.m:
	Add a predicate that looks for and exploits opportunities for using
	the new instruction.

compiler/optimize.m:
	Invoke the new peephole predicate as the next-to-last optimization
	pass. (The last is wrapping up blocks created by --use-local-vars.)

compiler/*.m:
	Minor changes to handle the new instruction.
2005-09-14 01:29:21 +00:00
Zoltan Somogyi
1ed891b7b1 Introduce a mechanism for extending the det and nondet stacks when needed.
Estimated hours taken: 24
Branches: main

Introduce a mechanism for extending the det and nondet stacks when needed.
The mechanism takes the form of a new grade component, .exts ("extend stacks").

While the new mechanism may be useful in its own right, it is intended mainly
to support a new implementation of minimal model tabling, which will use a
separate Mercury context for each distinct subgoal. Each context has its own
det and nondet stack. Clearly, we can't have hundreds of contexts each with
megabyte sized det stacks. The intention is that the stacks of the subgoals
will start small, and be expanded when needed.

The runtime expansion of stacks doesn't work yet, but it is unnecessarily
hard to debug without an installed compiler that understands the new grade
component, which is why this diff will be committed before that is fixed.

compiler/handle_options.m:
compiler/options.m:
runtime/mercury_grade.h:
scripts/canonical_grade.sh-subr
scripts/init_grade_options.sh-subr
scripts/parse_grade_options.sh-subr
scripts/mgnuc.in
	Handle the new grade component.

runtime/mercury_memory_zones.h:
	Add MR_ prefixes to the names of the fields of the zone structure.

	Record not just the actual size of each zone, which includes various
	kinds of buffers, but also the desired size of the zone exclusive of
	buffers.

	Format the documentation of the zone structure fields more
	comprehensibly.

runtime/mercury_memory_zones.c:
	Instead of implementing memalign if it is not provided by the operating
	system, implement a function that allows us to reallocate the returned
	area of memory.

	Provide a prototype implementation of memory zone extension. It doesn't
	work yet.

	Factor out the code for setting up redzones, since it is now needed
	in more than place.

	Convert to four space indentation.

	Make the debugging functions a bit more flexible.

runtime/mercury_wrapper.c:
	Conform to the improved interface of the debugging functions.

runtime/mercury_overflow.h:
runtime/mercury_std.h:
	Move a generally useful macro from mercury_overflow.h to mercury_std.h.

runtime/mercury_stacks.c:
	Add functions to extend the stacks.

runtime/mercury_stacks.h:
	Add the tests required to invoke the functions that extend the stacks.

	Add the macros needed by the change to compiler/llds.m.

	Convert to four space indentation.

runtime/mercury_conf.h.in:
	Prepare for the use of the posix_memalign function, which is the
	current replacement of the obsolete memalign library function.
	We don't yet use it.

runtime/mercury_context.h:
	Format the documentation of the context structure fields more
	comprehensibly.

	Put MR_ prefixes on the names of the fields of some structures
	that didn't previously have them.

	Conform to the new names of the fields of the zone structure.

runtime/mercury_context.c:
runtime/mercury_debug.c:
runtime/mercury_deep_copy.c:
runtime/mercury_engine.c:
runtime/mercury_memory_handlers.c:
library/benchmarking.m:
library/exception.m:
	Conform to the new names of the fields of the zone structure.

	In some cases, add missing MR_ prefixes to function names
	and/or convert to four space indentation.

runtime/mercury_engine.h:
	Add a new low level debug flag for debugging stack extensions.

	Format the documentation of the engine structure fields more
	comprehensibly.

	Convert to four space indentation.

runtime/mercury_conf_param.h:
	Document a new low level debug flag for debugging stack extensions.

compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/options.m:
	Handle the new grade component.

compiler/llds.m:
	Add two new kinds of LLDS instructions, save_maxfr and restore_maxfr.
	These are needed because the nondet stack may be relocated between
	saving and the restoring of maxfr, and the saved maxfr may point to
	the old stack. In .exts grades, these instructions will save not a
	pointer but the offset of maxfr from the start of the nondet stack,
	since offsets are not affected by the movement of the nondet stack.

compiler/code_info.m:
	Use the new instructions where relevant. (Some more work may be
	needed on this score; the relevant places are marked with XXX.)

compiler/dupelim.m:
compiler/dupproc.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/reassign.m:
compiler/use_local_vars.m:
	Handle the new LLDS instructions.

tools/bootcheck:
	Provide a mechanism for setting the initial stack sizes for a
	bootcheck.
2005-09-13 08:25:44 +00:00
Zoltan Somogyi
f0dbbcaa34 Generate better code for base relations such as the ones in the transitive
Estimated hours taken: 16
Branches: main

Generate better code for base relations such as the ones in the transitive
closure benchmarkings in the paper on minimal model tabling. These improvements
yield speedups ranging from 5 to 25% on those benchmarks.

compiler/use_local_vars.m:
	Make this optimization operate on extended basic blocks instead of
	plain basic blocks. The greater length of extended basic blocks
	allows the local variables to have maximum scope possible. The price
	is that the test for whether assignment to a given lvalue can be
	avoided or not is now dependent on which of the constituent basic
	blocks of extended basic block contains the assignment, and thus the
	test has to be evaluate once for each assignment we try to optimize
	instead of once per block.

	Don't allocate temporary variables if the optimization they are
	intended for turns out not to be allowed. This change avoids having
	declarations for unused temporary variables in the resulting C code.

	If --auto-comments is set, insert use_local_vars.m's main data
	structure, the livemap, into the generated LLDS code as a comment.

compiler/peephole.m:
	Look for the pattern

		mkframe(Size, Redoip)
		<straight line instructions that don't use stack slots>
		succeed

	and optimize away the mkframe. This pattern always arises for
	procedures that are actually semidet but are declared nondet (such
	as the base relations in the tabling benchmarks), and may also arise
	for semidet branches of nondet procedures.

compiler/llds.m:
	Allow an existing peephole pattern to work better. The pattern is

		mkframe(Seize, do_fail)
		<straight line instructions>
		redoip(curfr) = Redoip

	Previously, if some compiler-generated C code was among the straight
	line instructions, the pattern couldn't be applied, since peephole.m
	couldn't know whether it branched away through the redoip slot of the
	frame. This diff adds an extra slot to the relevant pragma_c component
	that tells peephole.m (actually, the predicate in opt_util.m that
	peephole relies on) whether this is the case.

compiler/basic_block.m:
	Provide functionality for merging basic blocks into extended basic
	blocks.

compiler/dupelim.m:
	Conform to the change in basic_block.m's interface.

	Convert to four-space indentation, and fix departures from our style
	guidelines.

compiler/opt_util.m:
	Provide extra information now needed by use_local_vars.

	Convert to four-space indentation, and fix departures from our style
	guidelines.

compiler/opt_debug.m:
	Show the user friendly versions of label names when dumping livemaps
	and instructions.

	Shorten the dumped descriptions of registers and stack slots.

	Dump instructions inside blocks.

compiler/frameopt.m:
	Conform to the changes in opt_util and opt_debug's interfaces.

compiler/optimize.m:
	Use the facilities of opt_debug instead of llds_out when dumping the
	LLDS after each optimization, since these are now more compact and
	thus reader friendly.

	Print unmangled names when writing progress messages.

	Put the dump files we generate with --opt-debug in a separate
	subdirectory, since when compiling e.g. tree234.m, the process
	can generate more than a thousand files. Give the dump files
	minimally mangled names.

compiler/code_gen.m:
compiler/pragma_c_gen.m:
	Convert to four-space indentation, and fix departures from our style
	guidelines.

	Conform to the change in llds.m.

compiler/code_info.m:
compiler/exprn_aux.m:
compiler/ite_gen.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/trace.m:
	Conform to the change in llds.m.
2005-09-07 06:51:57 +00:00
Zoltan Somogyi
5b105a0968 Optimize higher order calls by providing variants of the relevant code that
Estimated hours taken: 6
Branches: main

Optimize higher order calls by providing variants of the relevant code that
are specialized to a given number of explicitly given arguments.

runtime/mercury_ho_call.[ch]:
	Define variants of do_call_closure and do_call_class_method
	specialized to 0, 1, 2 or 3 explicit input arguments. Apart from
	not needing to be passed the number of explicit input arguments
	in a register, these avoid some runtime tests and unroll loops.

	Harmonize the variable names used in the do_call_closure and
	do_call_class_method variants. Since they are near-copies of each
	other, factor out their documentation. (Factoring out the code itself
	would be possible, but would not make maintenance easier and would make
	the code harder to read.)

	Provide a mechanism to gather statistics about the numbers of hidden
	and explicit arguments if the macro MR_DO_CALL_STATS is set.

compiler/options.m:
	Add options that specify how many of these variants exist. These
	provide the necessary synchronization between the runtime and the
	compiler. They are not meant to be set from the command line, even by
	implementors.

runtime/mercury_conf_params.h:
	Document MR_DO_CALL_STATS.

runtime/mercury_wrapper.c:
	If MR_DO_CALL_STATS is set, print the gathered statistics when
	execution ends.

runtime/mecury_mm_own_stack.c:
	Fix a typo that prevented the stage2 library from linking in jump.gc
	grade.

compiler/llds.m:
	Provide a way to represent the labels of the new specialized variants.

compiler/llds__out.m:
	Output the labels of the new specialized variants if required.

	Convert to four-space indentation.

compiler/call_gen.m:
	Call the specialized variants of do_call_closure or
	do_call_class_method if they are applicable.

code_info/follow_vars.m:
code_info/interval.m:
code_info/tupling.m:
	Conform to the change in call_gen.m.

code_info/dupproc.m:
code_info/exprn_aux.m:
code_info/livemap.m:
code_info/opt_util.m:
	Conform to the change in llds.m.

compiler/code_info.m:
	Minor style cleanups.

tools/bootcheck:
	Enable the collection of statistics from the compilation of stage 3
	and the test cases, for use when the stage 2 is built with
	MR_DO_CALL_STATS enabled.

tools/ho_call_stats:
	A new script to analyze the statistics collected.

tools/makebatch:
	Add a new option --save-stage2-on-no-compiler, which is a variant of
	the existing option --save-stage2-on-error.
2005-08-29 15:44:32 +00:00
Zoltan Somogyi
68b1a6c0ea Add a new LLDS optimization we discussed on thursday: elimination of procedures
Estimated hours taken: 4
Branches: main

Add a new LLDS optimization we discussed on thursday: elimination of procedures
whose code is an exact copy of the code of another mode of the same predicate.
This happens with in,out vs di,uo and also possibly with in,out vs any,any.
The new optimization reduces the compiler's code size by 0.6%.

compiler/dupproc.m:
	A new module implementing the new optimization.

compiler/ll_backend.m:
	Add dupproc.m as a new submodule.

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

compiler/options.m:
	Add an option, --optimize-proc-dups, enabling the new optimization.
	Make --opt-space imply the new option.

doc/user_guide.texi:
	Document the new option.

compiler/mercury_compile.m:
	Invoke the new optimization when compiling by predicates.

	Move the imports of library modules to their own section.

compiler/handle_options.m:
	Make --optimize-proc-dups imply compiling by predicates.

The rest of these changes are cosmetic only.

compiler/llds.m:
	Delete an obsolete form of constant we haven't used in a long time.

compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/llds_out.m:
compiler/opt_debug.m:
compiler/opt_util.m:
	Conform to the change in llds.m.

compiler/dependency_graph.m:
	Clean up some comments.

compiler/dupelim.m:
	Fix some variable names.

compiler/hlds_module.m:
compiler/hlds_pred.m:
	Minor cleanups.
2005-07-08 04:22:13 +00:00
Zoltan Somogyi
6d627726a8 Use state variables to represent substitution counts.
Estimated hours taken: 0.5
Branches: main

compiler/exprn_aux.m:
	Use state variables to represent substitution counts.

compiler/unify_gen.m:
	Switch to four-space indentation to avoid lots of code being squeezed
	against the right margin. Make other changes to conform to our coding
	standards.

compiler/var_locn.m:
	Make comments conform to our coding standards.
2005-05-04 07:42:43 +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
Zoltan Somogyi
763d6f2eff Import getopt_io instead instead of getopt, to allow Mmakefiles
Estimated hours taken: 0.5
Branches: main

compiler/*.m:
	Import getopt_io instead instead of getopt, to allow Mmakefiles
	to specify that some options come from files.
2005-01-27 03:38:10 +00:00
Zoltan Somogyi
0786d5b00a Fix a code generator bug that manifested itself in profiling grades with
Estimated hours taken: 3
Branches: main

Fix a code generator bug that manifested itself in profiling grades with
(intermodule) inlining, the symptom being a compiler abort due to a stackvar
out of range (negative slot number). The problem was that we use the type of a
variable to decide whether the variable has a real stack slot or not, but
we were using the original type of an argument of a foreign_proc to decide
whether the argument should be passed or not. Inlining could cause an argument
whose original type is T (e.g. the arguments of cc_multi_equal) to be
instantiated, e.g. to io__state. Since the type of the variable is io__state,
it gets a dummy stack slot; since the original type of the argument is T,
we pass the variable and thus refer to the dummy stack slot.

The fix is the use the actual type of the variable to make the decision,
not the original type of the argument.

This fix fixes the failures of the deforest_cc_bug.m test case in deep
profiling grades and the tricky_try_store.m test case in profiling grades.

compiler/llds.m:
	Add an extra argument to the pragma_c_{in,out}put function symbols
	to hold the actual type of the variable being passed.

	Add field names to those function symbols.

compiler/pragma_c_gen.m:
	Fill in the new argument.

	Clean up some code, mostly by factoring out duplicate code fragments.

compiler/llds_out.m:
	Handle the new argument to decide whether to pass the argument.

compiler/exprn_aux.m:
compiler/livemap.m:
compiler/middle_rec.m:
compiler/opt_util.m:
	Handle the new argument in pragma_c_{in,out}puts.
2004-12-09 02:02:23 +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
f007b45df8 Implement the infrastructure for term size profiling.
Estimated hours taken: 400
Branches: main

Implement the infrastructure for term size profiling. This means adding two
new grade components, tsw and tsc, and implementing them in the LLDS code
generator. In grades including tsw (term size words), each term is augmented
with an extra word giving the number of heap words it contains; in grades
including tsc (term size cells), each term is augmented with an extra word
giving the number of heap cells it contains. The extra word is at the start,
at offset -1, to leave almost all of the machinery for accessing the heap
unchanged.

For now, the only way to access term sizes is with a new mdb command,
"term_size <varspec>". Later, we will use term sizes in conjunction with
deep profiling to do experimental complexity analysis, but that requires
a lot more research. This diff is a necessary first step.

The implementation of term size profiling consists of three main parts:

- a source-to-source transform that computes the size of each heap cell
  when it is constructed (and increments it in the rare cases when a free
  argument of an existing heap cell is bound),

- a relatively small change to the code generator that reserves the extra
  slot in new heap cells, and

- extensions to the facilities for creating cells from C code to record
  the extra information we now need.

The diff overhauls polymorphism.m to make the source-to-source transform
possible. This overhaul includes separating type_ctor_infos and type_infos
as strictly as possible from each other, converting type_ctor_infos into
type_infos only as necessary. It also includes separating type_ctor_infos,
type_infos, base_typeclass_infos and typeclass_infos (as well as voids,
for clarity) from plain user-defined type constructors in type categorizations.
This change needs this separation because values of those four types do not
have size slots, but they ought to be treated specially in other situations
as well (e.g. by tabling).

The diff adds a new mdb command, term_size. It also replaces the proc_body
mdb command with new ways of using the existing print and browse commands
("print proc_body" and "browse proc_body") in order to make looking at
procedure bodies more controllable. This was useful in debugging the effect
of term size profiling on some test case outputs. It is not strictly tied
to term size profiling, but turns out to be difficult to disentangle.

compiler/size_prof.m:
	A new module implementing the source-to-source transform.

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

compiler/transform_hlds.m:
	Include size_prof as a submodule of transform_hlds.

compiler/mercury_compile.m:
	If term size profiling is enabled, invoke its source-to-source
	transform.

compiler/hlds_goal.m:
	Extend construction unifications with an optional slot for recording
	the size of the term if the size is a constant, or the identity of the
	variable holding the size, if the size is not constant. This is
	needed by the source-to-source transform.

compiler/quantification.m:
	Treat the variable reference that may be in this slot as a nonlocal
	variable of construction unifications, since the code generator needs
	this.

compiler/compile_target_code.m:
	Handle the new grade components.

compiler/options.m:
	Implement the options that control term size profiling.

doc/user_guide.texi:
	Document the options and grade components that control term size
	profiling, and the term_size mdb command. The documentation is
	commented out for now.

	Modify the wording of the 'u' HLDS dump flag to include other details
	of unifications (e.g. term size info) rather than just unification
	categories.

	Document the new alternatives of the print and browse commands. Since
	they are for developers only, the documentation is commented out.

compiler/handle_options.m:
	Handle the implications of term size profiling grades.

	Add a -D flag value to print HLDS components relevant to HLDS
	transformations.

compiler/modules.m:
	Import the new builtin library module that implements the operations
	needed by term size profiling automatically in term size profiling
	grades.

	Switch the predicate involved to use state var syntax.

compiler/prog_util.m:
	Add predicates and functions that return the sym_names of the modules
	needed by term size profiling.

compiler/code_info.m:
compiler/unify_gen.m:
compiler/var_locn.m:
 	Reserve an extra slot in heap cells and fill them in in unifications
	marked by size_prof.

compiler/builtin_ops.m:
	Add term_size_prof_builtin.term_size_plus as a builtin, with the same
	implementation as int.+.

compiler/make_hlds.m:
	Disable warnings about clauses for builtins while the change to
	builtin_ops is bootstrapped.

compiler/polymorphism.m:
	Export predicates that generate goals to create type_infos and
	type_ctor_infos to add_to_construct.m. Rewrite their documentation
	to make it more detailed.

	Make orders of arguments amenable to the use of state variable syntax.

	Consolidate knowledge of which type categories have builtin unify and
	compare predicates in one place.

	Add code to leave the types of type_ctor_infos alone: instead of
	changing their types to type_info when used as arguments of other
	type_infos, create a new variable of type type_info instead, and
	use an unsafe_cast. This would make the HLDS closer to being type
	correct, but this new code is currently commented out, for two
	reasons. First, common.m is currently not smart enough to figure out
	that if X and Y are equal, then similar unsafe_casts of X and Y
	are also equal, and this causes the compiler do not detect some
	duplicate calls it used to detect. Second, the code generators
	are also not smart enough to know that if Z is an unsafe_cast of X,
	then X and Z do not need separate stack slots, but can use the same
	slot.

compiler/type_util.m:
	Add utility predicates for returning the types of type_infos and
	type_ctor_infos, for use by new code in polymorphism.m.

	Move some utility predicates here from other modules, since they
	are now used by more than one module.

	Rename the type `builtin_type' as `type_category', to better reflect
	what it does. Extend it to put the type_info, type_ctor_info,
	typeclass_info, base_typeclass_info and void types into categories
	of their own: treating these types as if they were a user-defined
	type (which is how they used to be classified) is not always correct.
	Rename the functor polymorphic_type to variable_type, since types
	such as list(T) are polymorphic, but they fall into the user-defined
	category. Rename user_type as user_ctor_type, since list(int) is not
	wholly user-defined but falls into this category. Rename pred_type
	as higher_order_type, since it also encompasses functions.

	Replace code that used to check for a few of the alternatives
	of this type with code that does a full switch on the type,
	to ensure that they are updated if the type definition ever
	changes again.

compiler/pseudo_type_info.m:
	Delete a predicate whose updated implementation is now in type_util.m.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
	Still treat type_infos, type_ctor_infos, typeclass_infos and
	base_typeclass_infos as user-defined types, but prepare for when
	they won't be.

compiler/hlds_pred.m:
	Require interface typeinfo liveness when term size profiling is
	enabled.

	Add term_size_profiling_builtin.increase_size as a
	no_type_info_builtin.

compiler/hlds_out.m:
	Print the size annotations on unifications if HLDS dump flags call
	for unification details. (The flag test is in the caller of the
	modified predicate.)

compiler/llds.m:
	Extend incr_hp instructions and data_addr_consts with optional fields
	that allow the code generator to refer to N words past the start of
	a static or dynamic cell. Term size profiling uses this with N=1.

compiler/llds_out.m:
	When allocating memory on the heap, use the macro variants that
	specify an optional offset, and specify the offset when required.

compiler/bytecode_gen.m:
compiler/dense_switch.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/goal_form.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_match.m:
compiler/intermod.m:
compiler/jumpopt.m:
compiler/lambda.m:
compiler/livemap.m:
compiler/ll_pseudo_type_info.m:
compiler/lookup_switch.m:
compiler/magic_util.m:
compiler/middle_rec.m:
compiler/ml_code_util.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modecheck_unify.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/post_typecheck.m:
compiler/reassign.m:
compiler/rl.m:
compiler/rl_key.m:
compiler/special_pred.m:
compiler/stack_layout.m:
compiler/static_term.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
	Minor updates to conform to the changes above.

library/term_size_prof_builtin.m:
	New module containing helper predicates for term size profiling.
	size_prof.m generates call to these predicates.

library/library.m:
	Include the new module in the library.

doc/Mmakefile:
	Do not include the term_size_prof_builtin module in the library
	documentation.

library/array.m:
library/benchmarking.m:
library/construct.m:
library/deconstruct.m:
library/io.m:
library/sparse_bitset.m:
library/store.m:
library/string.m:
	Replace all uses of MR_incr_hp with MR_offset_incr_hp, to ensure
	that we haven't overlooked any places where offsets may need to be
	specified.

	Fix formatting of foreign_procs.

	Use new macros defined by the runtime system when constructing
	terms (which all happen to be lists) in C code. These new macros
	specify the types of the cell arguments, allowing the implementation
	to figure out the size of the new cell based on the sizes of its
	fields.

library/private_builtin.m:
	Define some constant type_info structures for use by these macros.
	They cannot be defined in the runtime, since they refer to types
	defined in the library (list.list and std_util.univ).

util/mkinit.c:
	Make the addresses of these type_info structures available to the
	runtime.

runtime/mercury_init.h:
	Declare these type_info structures, for use in mkinit-generated
	*_init.c files.

runtime/mercury_wrapper.[ch]:
	Declare and define the variables that hold these addresses, for use
	in the new macros for constructing typed lists.

	Since term size profiling can refer to a memory cell by a pointer
	that is offset by one word, register the extra offsets with the Boehm
	collector if is being used.

	Document the incompatibility of MR_HIGHTAGS and the Boehm collector.

runtime/mercury_tags.h:
	Define new macros for constructing typed lists.

	Provide macros for preserving the old interface presented by this file
	to the extent possible. Uses of the old MR_list_cons macro will
	continue to work in grades without term size profiling. In term
	size profiling grades, their use will get a C compiler error.

	Fix a bug caused by a missing backslash.

runtime/mercury_heap.h:
	Change the basic macros for allocating new heap cells to take
	an optional offset argument. If this is nonzero, the macros
	increment the returned address by the given number of words.
	Term size profiling specifies offset=1, reserving the extra
	word at the start (which is ignored by all components of the
	system except term size profiling) for holding the size of the term.

	Provide macros for preserving the old interface presented by this file
	to the extent possible. Since the old MR_create[123] and MR_list_cons
	macros did not specify type information, they had to be changed
	to take additional arguments. This affects only hand-written C code.

	Call new diagnostic macros that can help debug heap allocations.

	Document why the macros in this files must expand to expressions
	instead of statements, evn though the latter would be preferable
	(e.g. by allowing them to declare and use local variables without
	depending on gcc extensions).

runtime/mercury_debug.[ch]:
	Add diagnostic macros to debug heap allocations, and the functions
	behind them if MR_DEBUG_HEAP_ALLOC is defined.

	Update the debugging routines for hand-allocated cells to print the
	values of the term size slot as well as the other slots in the relevant
	grades.

runtime/mercury_string.h:
	Provide some needed variants of the macro for copying strings.

runtime/mercury_deconstruct_macros.h:
runtime/mercury_type_info.c:
	Supply type information when constructing terms.

runtime/mercury_deep_copy_body.h:
	Preserve the term size slot when copying terms.

runtime/mercury_deep_copy_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_ml_expand_body.h:
	Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
	that allocate cells also allocate space for the term size slot if
	necessary.

	Reduce code duplication by using a now standard macro for copying
	strings.

runtime/mercury_grade.h:
	Handle the two new grade components.

runtime/mercury_conf_param.h:
	Document the C macros used to control the two new grade components,
	as well as MR_DEBUG_HEAP_ALLOC.

	Detect incompatibilities between high level code and profiling.

runtime/mercury_term_size.[ch]:
	A new module to house a function to find and return term sizes
	stored in heap cells.

runtime/mercury_proc_id.h:
runtime/mercury_univ.h:
	New header files. mercury_proc_id.h contains the (unchanged)
	definition of MR_Proc_Id, while mercury_univ.h contains the
	definitions of the macros for manipulating univs that used to be
	in mercury_type_info.h, updated to use the new macros for allocating
	memory.

	In the absence of these header files, the following circularity
	would ensue:

	mercury_deep_profiling.h includes mercury_stack_layout.h
		- needs definition of MR_Proc_Id
	mercury_stack_layout.h needs mercury_type_info.h
		- needs definition of MR_PseudoTypeInfo
	mercury_type_info.h needs mercury_heap.h
		- needs heap allocation macros for MR_new_univ_on_hp
	mercury_heap.h includes mercury_deep_profiling.h
		- needs MR_current_call_site_dynamic for recording allocations

	Breaking the circular dependency in two places, not just one, is to
	minimize similar problems in the future.

runtime/mercury_stack_layout.h:
	Delete the definition of MR_Proc_Id, which is now in mercury_proc_id.h.

runtime/mercury_type_info.h:
	Delete the macros for manipulating univs, which are now in
	mercury_univ.h.

runtime/Mmakefile:
	Mention the new files.

runtime/mercury_imp.h:
runtime/mercury.h:
runtime/mercury_construct.c:
runtime/mercury_deep_profiling.h:
	Include the new files at appropriate points.

runtime/mercury.c:
	Change the names of the functions that create heap cells for
	hand-written code, since the interface to hand-written code has
	changed to include type information.

runtime/mercury_tabling.h:
	Delete some unused macros.

runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
	Use the new macros supplying type information when constructing lists.

scripts/canonical_grade_options.sh-subr:
	Fix an undefined sh variable bug that could cause error messages
	to come out without identifying the program they were from.

scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade_options.sh-subr:
scripts/mgnuc.in:
	Handle the new grade components and the options controlling them.

trace/mercury_trace_internal.c:
	Implement the mdb command "term_size <varspec>", which is like
	"print <varspec>", but prints the size of a term instead of its value.
	In non-term-size-profiling grades, it prints an error message.

	Replace the "proc_body" command with optional arguments to the "print"
	and "browse" commands.

doc/user_guide.tex:
	Add documentation of the term_size mdb command. Since the command is
	for implementors only, and works only in grades that are not yet ready
	for public consumption, the documentation is commented out.

	Add documentation of the new arguments of the print and browse mdb
	commands. Since they are for implementors only, the documentation
	is commented out.

trace/mercury_trace_vars.[ch]:
	Add the functions needed to implement the term_size command, and
	factor out the code common to the "size" and "print"/"browse" commands.

	Decide whether to print the name of a variable before invoking the
	supplied print or browse predicate on it based on a flag design for
	this purpose, instead of overloading the meaning of the output FILE *
	variable. This arrangement is much clearer.

trace/mercury_trace_browse.c:
trace/mercury_trace_external.c:
trace/mercury_trace_help.c:
	Supply type information when constructing terms.

browser/program_representation.m:
	Since the new library module term_size_prof_builtin never generates
	any events, mark it as such, so that the declarative debugger doesn't
	expect it to generate any.

	Do the same for the deep profiling builtin module.

tests/debugger/term_size_words.{m,inp,exp}:
tests/debugger/term_size_cells.{m,inp,exp}:
	Two new test cases, each testing one of the new grades.

tests/debugger/Mmakefile:
	Enable the two new test cases in their grades.

	Disable the tests sensitive to stack frame sizes in term size profiling
	grades.

tests/debugger/completion.exp:
	Add the new "term_size" mdb command to the list of command completions,
	and delete "proc_body".

tests/debugger/declarative/dependency.{inp,exp}:
	Use "print proc_body" instead of "proc_body".

tests/hard_coded/nondet_c.m:
tests/hard_coded/pragma_inline.m:
	Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
	that allocate cells also allocate space for the term size slot if
	necessary.

tests/valid/Mmakefile:
	Disable the IL tests in term size profiling grades, since the term size
	profiling primitives haven't been (and probably won't be) implemented
	for the MLDS backends, and handle_options causes a compiler abort
	for grades that combine term size profiling and any one of IL, Java
	and high level C.
2003-10-20 07:29:59 +00:00
Zoltan Somogyi
6554ef7daa Replace "is" with "=".
Estimated hours taken: 2
Branches: main

Replace "is" with "=".
Add field names where relevant.
Replace integers with counters where relevant.
2003-05-26 09:01:46 +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
Simon Taylor
82a950c0d9 Make Aditi work with `--highlevel-code'.
Estimated hours taken: 80
Branches: main

Make Aditi work with `--highlevel-code'.

(Note that this doesn't work with the current CVS version
of Aditi. The Aditi developers have rewritten the Aditi client
API, and haven't maintained the old version of the API, so Mercury
queries don't work at the moment. extras/aditi will be updated to
use the new interface as a separate change.)

extras/aditi/aditi_private_builtin.m:
extras/aditi/aditi.m:
	Move code to implement Aditi calls and updates into
	a aditi_private_builtin.m. These operations are now
	implemented using ordinary Mercury foreign procedures,
	rather than hand-coded C modules.

compiler/magic.m:
	Use calls to ordinary calls to predicates defined in
	extras/aditi/aditi_private_builtin.m to implement the
	procedures which interface between top-down Mercury
	code and Aditi procedures.

compiler/aditi_backend.pp:
compiler/aditi_builtin_ops.m:
compiler/mercury_compile.m:
compiler/notes/compiler_design.html:
	Add a pass to convert Aditi builtins (calls and updates)
	into ordinary calls to predicates defined in
	extras/aditi/aditi_private_builtin.m.

compiler/hlds_goal.m:
compiler/hlds_pred.m:
	Add a new generic_call type -- `unsafe_cast'.
	aditi_builtin_ops.m needs to be able to cast
	closures from one type and inst to another.

	Delete the `aditi_call' alternative for `aditi_builtin',
	which is not needed after the change to magic.m described
	above.

	Add predicates `construct_tuple' and `deconstruct_tuple'.

compiler/*hlds.*.m:
compiler/call_gen.m:
compiler/ml_call_gen.m:
	Handle unsafe cast goals.

compiler/common.m:
compiler/higher_order.m:
compiler/unify_proc.m:
	Generate unsafe_cast goals instead of calls to
	private_builtin.unsafe_type_cast.

compiler/purity.m:
compiler/notes/compiler_design.html:
	Convert calls to private_builtin.unsafe_type_cast into
	unsafe_cast goals.

compiler/ml_code_gen.m:
	Don't attempt to generate code for Aditi procedures.

	Remove special case handling of calls to
	private_builtin.unsafe_type_cast -- such
	calls are now transformed away.

compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/maybe_mlds_to_gcc.m:
	Add the RL code to the generated C file.

compiler/llds_out.m:
compiler/c_util.m:
compiler/compile_target_code.m:
	Move code to generate a `.rlo' file and work out the
	name of the RL constant embeeded in the C file for
	a module into c_util.m, for use by the MLDS backend.

compiler/modules.m:
	Automatically import aditi_private_builtin when compiling
	with `--aditi'.

	We generate a C constant for the RL code for each module,
	so modules compiled with `--aditi' need to be treated
	by the build system as if they contain foreign code.

compiler/polymorphism.m:
	Tuple insertion and deletion no longer need special treatment.

compiler/llds.m:
compiler/ll_backend.*.m:
	Delete the Aditi alternatives of the `code_addr' type.

compiler/mode_util.m:
	Add function versions of in_mode, out_mode, etc.

compiler/prog_util.m:
	Add aditi_public_builtin_module (returns `aditi') and
	aditi_private_builtin_module (returns `aditi_private_builtin').

tests/valid/aditi_private_builtin.m:
tests/invalid/aditi_private_builtin.m:
tests/valid/Mercury.options:
tests/invalid/Mercury.options:
	Add a cut down version of extras/aditi/aditi_private_builtin.m
	for use in running the tests.
2003-03-18 02:43:52 +00:00
Zoltan Somogyi
1cb657b998 Reduce inappropriate dependencies on ll_backend modules.
Estimated hours taken: 3
Branches: main

Reduce inappropriate dependencies on ll_backend modules. Except for
simplification of unnecessarily complicated logic in dependency_graph.m,
this change only moves functionality around.

compiler/llds_out.m:
compiler/c_util.m:
compiler/name_mangle.m:
	Move predicates that are used by multiple backends from
	ll_backend__llds_out to backend_libs__c_util and to a new module
	backend_libs__name_mangle. Make the relevant ones functions,
	and give some of them more meaningful names.

compiler/trace.m:
compiler/hlds_goal.m:
	Move a backend-independent predicate from ll_backend__trace
	to hlds__hlds_goal.

compiler/llds.m:
compiler/trace_params.m:
	Move the definition of the trace_port type from ll_backend__llds
	to libs__trace_params to avoid having libs__trace_params depend on
	ll_backend.

compiler/exprn_aux.m:
compiler/globals.m:
	Move the definition of the imported_is_constant from
	ll_backend__exprn_aux to libs__globals to avoid having libs__globals
	depend on ll_backend.

compiler/*.m:
	Conform to the above changes. This removes many inappropriate
	dependencies on the LLDS backend.
2003-03-16 08:01:31 +00:00
Zoltan Somogyi
9551640f55 Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2
Branches: main

compiler/*.m:
	Import only one compiler module per line. Sort the blocks of imports.
	This makes it easier to merge in changes.

	In a couple of places, remove unnecessary imports.
2003-03-15 03:09:14 +00:00
Peter Ross
ddd77f6f0e Get pragma foreign_type working for the C backend.
Estimated hours taken: 16
Branches: main

Get pragma foreign_type working for the C backend.

doc/reference_manual.texi:
    Document C pragma foreign_types.

compiler/prog_data.m:
    Add il_foreign_type and c_foreign_type which contain all the
    necessary data to output a foreign_type on the respective backends.
    Change foreign_language_type to refer to these new types.

compiler/prog_io_pragma.m:
    Handle the changes to foreign_language_type, and parse C
    foreign_type declarations.

compiler/hlds_data.m:
    Change the hlds_data__foreign_type type so that it records both the
    C and IL foreign types.  This will allow one to output both foreign
    type declarations when doing intermodule optimization.

compiler/make_hlds.m:
    Changes so that we store both the IL and C foreign types in
    hlds_data__foreign_type.
    Also add an error checking pass where we check that there is a
    foreign type for the back-end we are currently compiling to.

compiler/foreign.m:
    Change to_exported_type so that it works for both the C and IL
    backends by getting either the C or IL foreign_type definition.

compiler/llds.m:
compiler/pragma_c_gen.m:
    Change pragma_c_input and pragma_c_output so that they record
    whether or not a type is a foreign_type and if so what is the string
    which represents that foreign_type.

compiler/llds_out.m:
    When outputting pragma c_code variables that represent foreign_types
    get the casts correct.  Note that this adds the constraint on C
    foreign types that they are word sized, as all we are doing is
    casts, not boxing and unboxing.

compiler/mlds.m:
    Change mlds__foreign_type so that we store whether a type is an IL
    type or a C type.  It is the responsibility of the code generator
    that we never create a reference to a IL foreign type when on the C
    back-end, and vice versa.

compiler/mercury_to_mercury.m:
    Handle changes to prog_data__foreign_type.

compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_type_gen.m:
compiler/recompilation_usage.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
    Handle changes to hlds_data__foreign_type.

compiler/exprn_aux.m:
compiler/livemap.m:
compiler/middle_rec.m:
compiler/opt_util.m:
    Handle changes to the pragma_c_input and pragma_c_output types.

compiler/ml_code_util.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_c.m:
    Handle changes to mlds__foreign_type.
2002-05-07 11:03:17 +00:00
Fergus Henderson
7597790760 Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.

compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
	New files.  One module for each of the major components of the
	Mercury compiler.  These modules contain (as separate sub-modules)
	all the other modules in the Mercury compiler, except gcc.m and
	mlds_to_gcc.m.

Mmakefile:
compiler/Mmakefile:
	Handle the fact that the top-level module is now `top_level',
	not `mercury_compile' (since `mercury_compile' is a sub-module
	of `top_level').

compiler/Mmakefile:
	Update settings of *FLAGS-<modulename> to use the appropriate
	nested module names.

compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
	Convert the `recompilation_*' modules into sub-modules of the
	`recompilation' module.

compiler/*.m:
compiler/*.pp:
	Module-qualify the module names in `:- module', `:- import_module',
	and `:- use_module' declarations.

compiler/base_type_info.m:
compiler/base_type_layout.m:
	Deleted these unused empty modules.

compiler/prog_data.m:
compiler/globals.m:
	Move the `foreign_language' type from prog_data to globals.

compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
	Import `globals', for `foreign_language'.

Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
	Rename the %.check.c targets as %.check_hdr.c,
	to avoid conflicts with compiler/recompilation.check.c.
2002-03-20 12:37:56 +00:00
Zoltan Somogyi
9c58f97e3b Add a new optimization, --use-local-vars, to the LLDS backend.
Estimated hours taken: 20
Branches: main

Add a new optimization, --use-local-vars, to the LLDS backend. This
optimization is intended to replace references to fake registers and stack
slots with references to temporary variables in C code, since accessing these
should be cheaper.

With this optimization and one for delaying construction unifications,
the eager code generator should generate code at least good as that produced by
the old value numbering pass. This should make it possible to get rid of value
numbering, which is much harder to maintain.

compiler/use_local_vars.m:
	New module containing the optimization.

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

compiler/exprn_aux.m:
	Add new utility predicates for use by use_local_vars.

	If --debug-opt is specified, do not dump instruction sequences to
	standard output. Instead, put them in separate files, where they can be
	compared more easily.

compiler/options.m:
	Add the --use-local-vars option to control whether the use_local_vars
	pass gets run.

compiler/llds.m:
	Add liveness information to the c_code and pragma_foreign_code LLDS
	instructions, in order to allow use_local_vars to work in the presence
	of automatically-generated C code (e.g. by debugging).

compiler/livemap.m:
	Use the new liveness information to generate useful livemap information
	even in the presence of automatically generated C code.

compiler/code_gen.m:
compiler/code_info.m:
compiler/dupelim.m:
compiler/frameopt.m:
compiler/llds_common.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/pragma_c_gen.m:
compiler/trace.m:
compiler/vn_block.m:
compiler/vn_cost.m:
compiler/vn_filter.m:
compiler/vn_verify.m:
	Provide and/or ignore this additional liveness information.

compiler/wrap_block.m:
	The post_value_number pass wraps LLDS instruction sequences
	using temporaries in a block instruction which actually declares
	those temporaries. It used to be used only by value numbering;
	it is now also used by use_local_vars. It has therefore been renamed
	and put in its own file.

compiler/optimize.m:
	Invoke use_local_vars if required, and call wrap_blocks instead of
	post_value_number.

compiler/value_number.m:
	Since the value numbering pass still cannot handle automatically
	generated C code, check for it explicitly now that livemap carries out
	only a weaker check.

compiler/basic_block.m:
	Add a module qualification.

library/set.m:
library/set_bbbtree.m:
library/set_ordlist.m:
library/set_unordlist.m:
	Add a new predicate, union_list, to each implementation of sets,
	for use by some of the new code above.

tests/general/array_test.m:
	Print out the result of each operation as soon as it is done, so that
	if you get a seg fault, you know which operations have completed and
	which haven't.
2001-04-24 03:59:13 +00:00
Zoltan Somogyi
a1f326f4e9 Add an alternative to code_exprn that does eager code generation (code_exprn
Estimated hours taken: 140

Add an alternative to code_exprn that does eager code generation (code_exprn
always does lazy code generation). Its main advantages are that the new code
is significantly simpler, and that it does not generate unnecessary shuffling
code. Its main disadvantage, which is that it does not eliminate the creation
of unneeded cells, can be eliminated by switching on --unneeded-code.

For now, you can select the use of the new code generator with the
--no-lazy-code option (which was previously present but unused).
This will be made the default later, after I do more performance tests.

Var_locn contains stricter self-checks than code_exprn does. This required
modifications to some other parts of the code generator to ensure that the
self-checks do not fail unnecessarily. (This mostly took the form of explicitly
killing off dead variables before calling code_info__clear_all_registers, which
would complain about losing the last record of the value of a variable that was
alive as far as it knew.) To make my changes simpler, also took the opportunity
to simplify parts of the code generator which were handing around rvals that
in fact had to be wrappers around lvals, by handing around the lvals directly.

Testing this change also required fixing an old bug which prevented compiling
the library with -O1 --trace deep, together with the usual intermodule
optimization. The bug is that a library module reads predicates from
builtin.opt or private_builtin.opt, does not eliminate them because of the -O1,
and then tries to generate traced code for them. However, this fails because
the builtin modules contain some predicates that cannot be made to conform to
typeinfo-liveness, which is required by tracing.

compiler/var_locn.m:
	The new module that implements eager code generation.

compiler/follow_vars.m:
	Improve the follow_vars pass, since eager code generation requires
	better follow_vars information. We now generate correct information
	for generic calls, and record not only where some vars (e.g. those
	which appear as input arguments of following calls) should be put,
	but also which registers are not reserved for those variables and
	are thus available for other variables.

compiler/hlds_goal.m:
	Modify the follow_vars field of the goal_info to record the number
	of the first non-reserved register.

compiler/code_info.m:
 	Replace the general-purpose predicate code_info__cache_exprn, which
	associated a variable with an rval without generating code, with a set
	of special-purpose predicates such as code_info__assign_const_to_var
	and code_info__assign_cell_to_var, some of which can generate code.

	These new predicates and some older ones (e.g. code_info__setup_call)
	now choose at runtime whether to call code_exprn or var_locn. The
	basis for the decision is checking whether the code_info structure
	contains an exprn_info or a var_locn_info. This is decided in
	code_info__init based on the value of the lazy_code option, and
	maintained unchanged from then on.

	Rename some predicates to better reflect their current possible
	behaviors.

compiler/unify_gen.m:
	Call the new special-purpose predicates in code_info instead of
	code_info__cache_exprn.

	Replace an incorrect clause with a call to error, since that clause
	could never be invoked.

compiler/call_gen.m:
	Hand over the task of generating the args of generic calls to
	code_info, since it already has code to do the right thing, which
	includes reserving the registers to be used for the input args.

	Notify the rest of the code generator after the last use of
	non-forward-live variables, in order to avoid spurious calls to error
	(it is an error to clobber the last location of a live variable).

	Notify the rest of the code generator when generic calls overwrite
	registers, to allow the proper consistency checks to be made.

	If an output variable is singleton, then do not make it known to the
	code generator. It never will never become dead, and may thus cause a
	spurious compiler abort if its storage is ever clobbered.

	Export a predicate for use by follow_vars.

	Factor out some common code.

	Call the new preds in code_info where necessary.

compiler/pragma_c_gen.m:
	Notify the rest of the code generator after the last use of
	non-forward-live variables, in order to avoid spurious calls to error
	(it is an error to clobber the last location of a live variable).

	If an output variable is singleton, then do not make it known to the
	code generator. It never will never become dead, and may thus cause a
	spurious compiler abort if its storage is ever clobbered.

	When using var_locn, ensure that none of the input arguments of a
	model_semi pragma_c_code is assigned to r1. If we did, and the last
	reference to the value of that argument was after an assignment to
	SUCCESS_INDICATOR, the C compiler would be forced to generate code
	to shuffle the value of the argument out of the way.

compiler/code_exprn.m:
	Minor changes to return lvals directly instead of lvals wrapped inside
	rvals and to conform the new format of follow_vars.

	Do not include the registers reserved by follow_vars in the
	search for a spare register.

compiler/lookup_switch.m:
compiler/switch_gen.m:
	Fix an old bug that did not matter with code_exprn but does matter with
	var_locn: the branch end structure was being computed in the wrong
	place.

compiler/disj_gen.m:
	At the ends of non-last disjuncts, kill off the variables that we
	needed to know inside the disjunct but won't need to know after the
	disjunct, in order to avoid error messages about throwing away their
	state. The variables affected are those which are needed only by the
	resumption point of the next disjunct, not by enclosing resumption
	points or forward execution.

compiler/arg_info.m:
	Associate an lval, not an rval, with each argument.

compiler/*.m:
	Minor changes to conform to (a) the new format of follow_vars, (b)
	the replacement of rvals containing lvals by lvals.

compiler/code_util.m:
	Add some utility predicates for var_locn.m.

compiler/exprn_aux.m:
	Add some utility functions for var_locn.m.

	Export a predicate for var_locn.m.

compiler/handle_options.m:
	If --no-lazy-code is set, switch on the "optimizations" on whose
	presence it depends.

compiler/mercury_compile.m:
compiler/code_gen.m:
	Turn off tracing for predicates that don't obey typeinfo liveness
	for backend_by_preds and backend_by_phases respectively.

	Look up options in the globals structure in the module_info, not in the
	globals structure in the I/O state, since this is where we turn off
	tracing. (We should later make sure that other parts of the compiler
	are also consistent on this issue.)

compiler/stack_layout.m:
	Throw away any continuation_info structures that belong to predicates
	that don't obey typeinfo liveness.
2000-09-16 00:08:27 +00:00
Simon Taylor
7622eb1d36 Finish the implementation of Aditi updates.
Estimated hours taken: 120

Finish the implementation of Aditi updates.

compiler/hlds_goal.m:
	Refactor the aditi_builtin type so that operations with
	similar syntax and implementations are grouped together.

	Add operations to delete a single tuple (`aditi_delete') and
	to modify tuples (`aditi_bulk_modify').

compiler/*.m:
	Minor changes required by refactoring the aditi_builtin type.

compiler/make_hlds.m:
	Parse `aditi_delete' and `aditi_bulk_modify' goals.

	Parse a nicer syntax for `aditi_bulk_delete' and
	`aditi_bulk_insert' goals
	(e.g. aditi_bulk_delete(p(_, X, _) :- X > 2)).

compiler/rl_out.pp:
	For each base relation, generate RL procedures to apply
	deletions and modifications to the relation. `aditi_bulk_modify'
	takes a closure which produces tuples which contain both the
	attributes of the tuple to delete and the tuple to insert. The
	modification RL procedure performs two projections on the
	closure result to produce the tuples to delete and the tuples
	to delete.

	The input stream to the rl_PROC_delete RL instruction must contain
	only tuples taken from the relation to delete from -- the deletion
	is done using the tuple-id rather than the tuple contents.
	The generated deletion procedure performs a semi-join of the
	relation to delete from with the relation containing the
	tuples to delete.

compiler/rl.m:
	Add predicates to generate the names of the modification
	and deletion RL procedures generated for each base relation.

compiler/rl_exprn.m:
	Generate the projection expressions required by the modification
	RL procedures generated for each base relation.

	Generate the equi-join expressions required by the modification
	and deletion RL procedures generated for each base relation.

compiler/unify_gen.m:
	Implement code generation for `aditi_bottom_up' closures.

compiler/rl.m:
compiler/magic.m:
	Factor out the code used to create the name of the RL procedure
	used to interface top-down Mercury to Aditi, for use by unify_gen.m
	to generate `aditi_bottom_up' closures.

compiler/code_util.m:
	Add predicate code_util__make_user_proc_label, which constructs
	a label name from the given all the individual pieces of information
	used to construct it, rather than just a pred_id and proc_id.
	This is used to produce the RL procedure name for an `aditi_bottom_up'
	closure, so that the code doesn't have to work out what the pred_id
	of the magic sets transformed procedure is.

compiler/magic.m:
	Always create new procedures to interface Mercury to Aditi,
	to make it easier for unify_gen.m to work out what the name
	of the interface procedure is -- don't optimize the case of
	a predicate with no input arguments.

	Alter the goal generated for the interface procedures so
	that it doesn't matter whether the interface procedure
	and the procedure it interfaces to are compiled together
	by rl_gen.m -- the old code generated for these procedures
	assumed they were compiled separately, which wasn't always the
	case.

	Don't pass a `magic_info' through the code to generate the
	C interface procedures -- only the module_info field was
	required.

compiler/magic_util.m:
compiler/magic.m:
compiler/context.m:
	Don't pass a `magic_info' through
	magic_util__create_input_test_unifications --
	only the module_info and proc_info fields were used.

compiler/post_typecheck.m:
compiler/magic_util.m:
	Don't report errors for the second `aditi__state' argument
	of the closure passed to `aditi_bulk_modify'.

compiler/purity.m:
	Change the mode of the second `aditi__state' argument
	of the closure passed to `aditi_bulk_modify' to `unused'.

compiler/call_gen.m:
	Generate `aditi_delete' and `aditi_bulk_modify'.

	Remove the `aditi__state' from the tuple to insert passed
	to an `aditi_insert' or `aditi_delete' operation -- the relation
	on disk does not contain the `aditi__state' attribute.

extras/aditi/aditi.m:
	Implement the updates.

	Allocate all memory on the Mercury heap to avoid memory
	leaks when a transaction aborts.

	Uncaught exceptions within a transaction now cause
	the transaction to abort, and the exception is rethrown
	to the caller.

	If using trailing, add trail entries for the output relation
	and cursor created for a call to an Aditi procedure, so that
	they will be cleaned up if only one solution of the call
	is needed or if an exception is thrown.

	Include line numbers in the debugging messages if an Aditi API
	function fails.

compiler/llds.m:
compiler/*.m:
	Rename the `do_aditi_modify' label to `do_aditi_bulk_modify' -- we
	may eventually want to implement a modification goal type which
	doesn't produce all modified tuples before applying the update.

doc/reference_manual.texi:
	Document `aditi_delete' and `aditi_bulk_modify'.

	Add some extra spacing in the Aditi update section to
	improve readability.

tests/valid/aditi_update.m:
tests/invalid/aditi_update_errors.m:
tests/invalid/aditi_update_errors.err_exp:
tests/invalid/aditi_update_mode_errors.m:
tests/invalid/aditi_update_mode_errors.err_exp:
	Changed to fit in with the new syntax.

tests/valid/Mmakefile:
	Code generation for Aditi updates now works, so enable full
	compilation of the aditi_update.m test case, rather than
	just checking for errors.
2000-04-14 08:39:24 +00:00
Simon Taylor
3a26ad82d5 Add information required for structure reuse and compile time garbage
Estimated hours taken: 2

Add information required for structure reuse and compile time garbage
collection to the LLDS. The code generator does not yet generate
this information.

This will be committed to the main branch to avoid CVS conflicts.

compiler/llds.m:
	Add an LLDS instruction `free_heap(rval)', which applies the
	MR_free_heap macro to its argument.

	Add a `maybe(rval)' field to `create' rvals to hold the address
	of a cell to reuse. This field should always be `no' after
	code generation, because all non-constant creates are converted
	into lower-level operations during code generation.

compiler/value_number.m:
	Don't reorder instructions around a `free_heap' instruction
	to avoid generating code which looks at deallocated memory.

compiler/*.m:
	Handle the new instruction and field.
2000-01-14 01:11:11 +00:00
Zoltan Somogyi
5aa3e6134c Shallow traced procedures do not fill in most of their stack slots holding
Estimated hours taken: 6

Shallow traced procedures do not fill in most of their stack slots holding
debugging information unless they are called from deep traced code, yet the
code in the runtime that handles redo events for such procedures was using
the values in those slots. This changes fixes that problem, by adding another
piece of code in the runtime for handling redo events for shallow traced
procedures.

compiler/llds.m:
	Rename do_trace_redo_fail as do_trace_redo_fail_deep and add a new
	label, do_trace_redo_fail_shallow.

compiler/trace.m:
	Select which label gets included as the redoip in the temporary frame
	that generates redo events, and document the assumptions about stack
	slots used by the new label.

compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/opt_debug.m:
compiler/opt_util.m:
	Conform to the changes in llds.m.

runtime/mercury_trace_base.c:
	Add the label and code for handling redo events in shallow traced
	procedures.

runtime/mercury_stack_layout.h:
	Add a macro used by mercury_trace_base.c.

tests/debugger/shallow.{m,inp,exp}:
	New test case. It is the same code as queens.m, but compiled with
	shallow tracing. It segfaults before but not after this change.

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

	Comment out a rule for a disabled test case, to avoid make warnings.
1999-08-24 08:52:06 +00:00
Simon Taylor
2725b1a331 Aditi update syntax, type and mode checking.
Estimated hours taken: 220

Aditi update syntax, type and mode checking.

Change the hlds_goal for constructions in preparation for
structure reuse to avoid making multiple conflicting changes.

compiler/hlds_goal.m:
	Merge `higher_order_call' and `class_method_call' into a single
	`generic_call' goal type. This also has alternatives for the
	various Aditi builtins for which type declarations can't
	be written.

	Remove the argument types field from higher-order/class method calls.
	It wasn't used often, and wasn't updated by optimizations
	such as inlining. The types can be obtained from the vartypes
	field of the proc_info.

	Add a `lambda_eval_method' field to lambda_goals.

	Add a field to constructions to identify which RL code fragment should
	be used for an top-down Aditi closure.

	Add fields to constructions to hold structure reuse information.
	This is currently ignored -- the changes to implement structure
	reuse will be committed to the alias branch.
	This is included here to avoid lots of CVS conflicts caused by
	changing the definition of `hlds_goal' twice.

	Add a field to `some' goals to specify whether the quantification
	can be removed. This is used to make it easier to ensure that
	indexes are used for updates.

	Add a field to lambda_goals to describe whether the modes were
	guessed by the compiler and may need fixing up after typechecking
	works out the argument types.

	Add predicate `hlds_goal__generic_call_id' to work out a call_id
	for a generic call for use in error messages.

compiler/purity.m:
compiler/post_typecheck.m:
	Fill in the modes of Aditi builtin calls and closure constructions.
	This needs to know which are the `aditi__state' arguments, so
	it must be done after typechecking.

compiler/prog_data.m:
	Added `:- type sym_name_and_arity ---> sym_name/arity'.

	Add a type `lambda_eval_method', which describes how a closure
	is to be executed. The alternatives are normal Mercury execution,
	bottom-up execution by Aditi and top-down execution by Aditi.

compiler/prog_out.m:
	Add predicate `prog_out__write_sym_name_and_arity', which
	replaces duplicated inline code in a few places.

compiler/hlds_data.m:
	Add a `lambda_eval_method' field to `pred_const' cons_ids and
	`pred_closure_tag' cons_tags.

compiler/hlds_pred.m:
	Remove type `pred_call_id', replace it with type `simple_call_id',
	which combines a `pred_or_func' and a `sym_name_and_arity'.

	Add a type `call_id' which describes all the different types of call,
	including normal calls, higher-order and class-method calls
	and Aditi builtins.

	Add `aditi_top_down' to the type `marker'.

	Remove `aditi_interface' from type `marker'. Interfacing to
	Aditi predicates is now handled by `generic_call' hlds_goals.

	Add a type `rl_exprn_id' which identifies a predicate to
	be executed top-down by Aditi.
	Add a `maybe(rl_exprn_id)'  field to type `proc_info'.

	Add predicate `adjust_func_arity' to convert between the arity
	of a function to its arity as a predicate.

	Add predicates `get_state_args' and `get_state_args_det' to
	extract the DCG state arguments from an argument list.

	Add predicate `pred_info_get_call_id' to get a `simple_call_id'
	for a predicate for use in error messages.

compiler/hlds_out.m:
	Write the new representation for call_ids.

	Add a predicate `hlds_out__write_call_arg_id' which
	replaces similar code in mode_errors.m and typecheck.m.

compiler/prog_io_goal.m:
	Add support for `aditi_bottom_up' and `aditi_top_down' annotations
	on pred expressions.

compiler/prog_io_util.m:
compiler/prog_io_pragma.m:
	Add predicates
	- `prog_io_util:parse_name_and_arity' to parse `SymName/Arity'
		(moved from prog_io_pragma.m).
	- `prog_io_util:parse_pred_or_func_name_and_arity to parse
		`pred SymName/Arity' or `func SymName/Arity'.
	- `prog_io_util:parse_pred_or_func_and_args' to parse terms resembling
		a clause head (moved from prog_io_pragma.m).

compiler/type_util.m:
	Add support for `aditi_bottom_up' and `aditi_top_down' annotations
	on higher-order types.

	Add predicates `construct_higher_order_type',
	`construct_higher_order_pred_type' and
	`construct_higher_order_func_type' to avoid some code duplication.

compiler/mode_util.m:
	Add predicate `unused_mode/1', which returns `builtin:unused'.
	Add functions `aditi_di_mode/0', `aditi_ui_mode/0' and
	`aditi_uo_mode/0' which return `in', `in', and `out', but will
	be changed to return `di', `ui' and `uo' when alias tracking
	is implemented.

compiler/goal_util.m:
	Add predicate `goal_util__generic_call_vars' which returns
	any arguments to a generic_call which are not in the argument list,
	for example the closure passed to a higher-order call or
	the typeclass_info for a class method call.

compiler/llds.m:
compiler/exprn_aux.m:
compiler/dupelim.m:
compiler/llds_out.m:
compiler/opt_debug.m:
	Add builtin labels for the Aditi update operations.

compiler/hlds_module.m:
	Add predicate predicate_table_search_pf_sym, used for finding
	possible matches for a call with the wrong number of arguments.

compiler/intermod.m:
	Don't write predicates which build `aditi_top_down' goals,
	because there is currently no way to tell importing modules
	which RL code fragment to use.

compiler/simplify.m:
	Obey the `cannot_remove' field of explicit quantification goals.

compiler/make_hlds.m:
	Parse Aditi updates.

	Don't typecheck clauses for which syntax errors in Aditi updates
	are found - this avoids spurious "undefined predicate `aditi_insert/3'"
	errors.

	Factor out some common code to handle terms of the form `Head :- Body'.
	Factor out common code in the handling of pred and func expressions.

compiler/typecheck.m:
	Typecheck Aditi builtins.

	Allow the argument types of matching predicates to be adjusted
	when typechecking the higher-order arguments of Aditi builtins.

	Change `typecheck__resolve_pred_overloading' to take a list of
	argument types rather than a `map(var, type)' and a list of
	arguments to allow a transformation to be performed on the
	argument types before passing them.

compiler/error_util.m:
	Move the part of `report_error_num_args' which writes
	"wrong number of arguments (<x>; expected <y>)" from
	typecheck.m for use by make_hlds.m when reporting errors
	for Aditi builtins.

compiler/modes.m:
compiler/unique_modes.m:
compiler/modecheck_call.m:
	Modecheck Aditi builtins.

compiler/lambda.m:
	Handle the markers for predicates introduced for
	`aditi_top_down' and `aditi_bottom_up' lambda expressions.

compiler/polymorphism.m:
	Add extra type_infos to `aditi_insert' calls
	describing the tuple to insert.

compiler/call_gen.m:
	Generate code for Aditi builtins.

compiler/unify_gen.m:
compiler/bytecode_gen.m:
	Abort on `aditi_top_down' and `aditi_bottom_up' lambda
	expressions - code generation for them is not yet implemented.

compiler/magic.m:
	Use the `aditi_call' generic_call rather than create
	a new procedure for each Aditi predicate called from C.

compiler/rl_out.pp:
compiler/rl_gen.m:
compiler/rl.m:
	Move some utility code used by magic.m and call_gen.m into rl.m.

	Remove an XXX comment about reference counting being not yet
	implemented - Evan has fixed that.

library/ops.m:
compiler/mercury_to_mercury.m:
doc/transition_guide.texi:
	Add unary prefix operators `aditi_bottom_up' and `aditi_top_down',
	used as qualifiers on lambda expressions.
	Add infix operator `==>' to separate the tuples in an
	`aditi_modify' call.

compiler/follow_vars.m:
	Thread a `map(prog_var, type)' through, needed because
	type information is no longer held in higher-order call goals.

compiler/table_gen.m:
	Use the `make_*_construction' predicates in hlds_goal.m
	to construct constants.

compiler/*.m:
	Trivial changes to add extra fields to hlds_goal structures.

doc/reference_manual.texi:
	Document Aditi updates.

	Use @samp{pragma base_relation} instead of
	@samp{:- pragma base_relation} throughout the Aditi documentation
	to be consistent with other parts of the reference manual.

tests/valid/Mmakefile:
tests/valid/aditi_update.m:
tests/valid/aditi.m:
	Test case.

tests/valid/Mmakefile:
	Remove some hard-coded --intermodule-optimization rules which are
	no longer needed because `mmake depend' is now run in this directory.

tests/invalid/*.err_exp:
	Fix expected output for changes in reporting of call_ids
	in typecheck.m.

tests/invalid/Mmakefile
tests/invalid/aditi_update_errors.{m,err_exp}:
tests/invalid/aditi_update_mode_errors.{m,err_exp}:
	Test error messages for Aditi updates.

tests/valid/aditi.m:
tests/invalid/aditi.m:
	Cut down version of extras/aditi/aditi.m to provide basic declarations
	for Aditi compilation such as `aditi__state' and the modes
	`aditi_di', `aditi_uo' and `aditi_ui'. Installing extras/aditi/aditi.m
	somewhere would remove the need for these.
1999-07-13 08:55:28 +00:00
Zoltan Somogyi
e3232306cb Add a module layout structure containing a string table and a table of
Estimated hours taken: 14

Add a module layout structure containing a string table and a table of
pointers to the proc layouts of the module's procedures. This speeds up
debugger initialization, and reduces the executable size of the compiler
by almost 1.2 Mb (about 3.7%) when compiled with debugging.

Instead of representing variables names as strings (32 or 64 bit pointers)
in the debugger's static data structures, with the string's prefix representing
the variable's number (e.g. "5:X"), represent them as a 16-bit variable number
and a 16 bit offset into the module-wide string table. This gains simplicity
of processing (no more search for the ":") and reduces the amount of storage
required, a bit on 32-bit platforms (we don't have to store "5:ModuleInfo"
and "10:ModuleInfo" strings separately, and there are no string prefixes to
store) and more on 64-bit platforms.

The 16-bit limits are generous. A procedure with more than 64K variables will
take forever to compile (that is why we impose a 4K limit on the number
of variables in inlining), and even the string tables of typecheck.m and
make_hlds require less than four kilobytes each. Exceeding the limits
would require code no human would write. Automatically generated code may
be a problem, but the help the debugger can give on such code is limited
already. In any case, we detect overflows and handle them sensibly.

This change does not enhance the debugger to take advantage of the easier
availability of variable numbers, except to improve the implementation
of retry; that will come later.

The inclusion of the procedure table in the module layout structure
reduces the cost of registering all procedures in all modules,
a task usually performed at the time of the setting of the first breakpoint.
This used to require processing all the internal labels in the label table,
and thus used to take a few seconds for large executables. The sweep of
all internal labels is no longer required, so registering is now much faster.

runtime/mercury_stack_layout.h:
	Add the definition of MR_Module_Layout.

	Modify label layouts to represent names as offsets in the string table,
	not as raw character pointers. This required modifing proc layouts
	to include a pointer to the module's layout, so you can find the
	string table.

	Update the macros that look up variable names.

runtime/mercury_layout_util.h:
	Use the updated macros for looking up variable names.

runtime/mercury_wrapper.[ch]:
	Add a new indirect pointer, MR_register_module_layout, which points
	to a function that registers a module layout, or is NULL if debugging
	is not enabled.

runtime/mercury_init.h:
	Declare the function whose address may be assigned to
	MR_register_module_layout in a <main>_init.c file.

util/mkinit.c:
	Initialize MR_register_module_layout with either the address of
	MR_register_module_layout_real or NULL, depending on whether
	debugging is enabled or not.

compiler/continuation_info.m:
	Don't give names (V_n) to nameless variables, because we don't want
	them to be included in the variables debugging knows about.

compiler/llds.m:
	Add a new function symbol to the type data_addr, which stands for
	the module layout structure of the named (now always the current)
	module.

	Add a new function symbol to the type rval_const. The new function
	symbols, multi_string_const, contains an array of characters of an
	explicitly given length, which consists of several strings, each
	terminated by a null character.

compiler/llds_out.m:
	Accommodate the changes to llds.m, and expand the module initialization
	code to register the module layout structure, if the pointer to the
	registration function is not NULL.

compiler/stack_layout.m:
	Generate the new data structures for representing variable names,
	as well as the module layout.

compiler/mercury_compile.m:
	Rename some variables to reflect the fact that stack_layout.m can
	now include a module layout structure in the list of static layout
	structures it returns.

compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/opt_debug.m:
	Minor changes to accommodate multi_string_consts.

trace/mercury_trace_tables.[ch]:
	Replace the old data structures for recording information about
	each debuggable module with the module layout structure, and
	register module layout structures directly, instead of trying
	to discover them through the internal label table.

trace/mercury_trace.[ch]:
	Now that it is more easily accessible, use variable numbers
	instead of variable names to find the current locations of
	the input arguments when implementing retry. Unlike our previous
	method, this works even if the user names some variables HeadVar__1,
	etc.

	Remove an unnecessary export of an internal function.

trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
runtime/mercury_layout_util.c:
	Use the updated macros for looking up variable names.
1999-05-28 05:29:51 +00:00
Zoltan Somogyi
c2da42e6d0 Allow the compiler to handle create rvals whose arguments have a size
Estimated hours taken: 16

Allow the compiler to handle create rvals whose arguments have a size
which is different from the size of a word. Use this capability to reduce
the size of RTTI information, in two ways.

The first way is by rearranging the way in which we represent information
about the live values at a label. Instead of an array with an entry for
each live value, the entry being a pair of Words containing a shape
representation and a location description respectively, use an array
of shape representations (still Words), followed by an array of 32-bit ints
(which may be smaller than Word) describing locations whose descriptions
don't fit into 8 bits, followed by an array of 8-bit ints describing
locations whose descriptions do fit into 8 bits.

The second way is by reducing the sizes of some fields in the C structs
used for RTTI. Several of these had to be bigger than necessary in the
past because their fields were represented by the args of a create rval.

On cyclone, this reduces the size of the object file for queens.m by 2.8%.

IMPORTANT
Until this change is reflected in the installed compiler, you will not be
able to use any modules compiled with debugging in your workspaces if the
workspace has been updated to include this change. This is because the RTTI
data structures generated by the old installed compiler will not be compatible
with the new structure definitions.

The workaround is simple: if your workspace contains modules compiled with
debugging, don't do a cvs update until this change has been installed.

configure.in:
	Check whether <stdint.h> is present. If not, autoconfigure
	types that are at least 16 and 32 bits in size.

runtime/mercury_conf.h.in:
	Mention the macros used by the configure script, MR_INT_LEAST32_TYPE
	and MR_INT_LEAST16_TYPE.

runtime/mercury_conf_param.h:
	Document the macros used by the configure script, MR_INT_LEAST32_TYPE
	and MR_INT_LEAST16_TYPE.

runtime/mercury_types.h:
	If <stdint.h> is available, get the basic integer types (intptr_t,
	int_least8_t, etc) from there. Otherwise, get them from the
	autoconfigure script. Define types such as Word in terms of these
	(eventually) standard types.

runtime/mercury_stack_layout.h:
	Add macros for manipulating short location descriptions, update the
	types and macros for manipulating long location descriptions.
	Modify the way the variable count is represented (since it now must
	count locations with long and short descriptions separately),
	and move it to the structure containing the arrays it describes.

	Reduce the size of the some fields in structs. This required some
	reordering of fields to avoid the insertion of padding by the compiler,
	and changes to the definitions of some types (e.g. MR_determinism).

runtime/mercury_layout_util.[ch]:
runtime/mercury_stack_trace.c:
runtime/mercury_accurate_gc.c:
trace/mercury_trace.c:
trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
	Update the code to conform to the changes to stack_layout.h.

compiler/llds.m:
	Modify the create rval in two ways. First, add an extra argument to
	represent the types of the arguments, which used to always be implicit
	always a word in size, but may now be explicit and possibly smaller
	(e.g. uint_least8). Second, since the code generator would do the wrong
	thing with creates with smaller than wordsize arguments, replace
	the old must-be-unique vs may-be-nonunique bool with a three-valued
	marker, must_be_dynamic vs must_be_static vs can_be_either.

	Add uint_least8, uint_least16, uint_least32 (and their signed variants)
	and string as llds_types.

	Add a couple of utility predicates for checking whether an llds_type
	denotes a type whose size is the same as word.

compiler/llds_out.m:
	Use explicitly given argument types when declaring and initializing
	the arguments of a cell, if they are given.

compiler/llds_common.m:
	Don't conflate creates with identical argument values but different
	C-level argument types. The probability of a match is minuscule anyway.

compiler/stack_layout.m:
	Use the new representation of creates to generate the new versions of
	RTTI data structures.

compiler/code_exprn.m:
	If a create is marked must_be_static, don't inspect the arguments
	to decide whether it can be static or not. If it can't, we'll get
	an abort later on in llds_out or during C compilation anyway.

compiler/base_type_layout.m:
	When creating pseudo typeinfos, return the llds_type of the resulting
	rval.

	Minor changes required by the change in create.

compiler/base_type_info.m:
compiler/base_typeclass_info.m.m:
compiler/code_util.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/lookup_switch.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/string_switch.m:
compiler/unify_gen.m:
compiler/vn_cost.m:
compiler/vn_filter.m:
compiler/vn_flush.m:
compiler/vn_order.m:
compiler/vn_type.m:
compiler/vn_util.m:
compiler/vn_verify.m:
	Minor changes required by the change in create.

library/benchmarking.m:
library/std_util.m:
	Use the new macros in hand-constructing proc layout structures.

library/Mmakefile:
	Add explicit dependencies for benchmarking.o and std_util.o
	on ../runtime/mercury_stack_layout.h. Although this is only a subset
	of the truth (in reality, all library objects depend on most of the
	runtime headers), it is a good tradeoff between safety and efficiency.
	The other runtime header files tend not to change in incompatible ways.

trace/Mmakefile:
	Add explicit dependencies for all the object files on
	../runtime/mercury_stack_layout.h, for similar reasons.
1999-04-30 06:21:49 +00:00
Zoltan Somogyi
3bf462e0b7 Switch to a closure representation that includes runtime type and procedure id
Estimated hours taken: 36

Switch to a closure representation that includes runtime type and procedure id
information, so that closures can be copied, garbage collected, printed, etc.

This RTTI information is not yet used. Adding code to use it would be futile
until Tyson finishes his changes to the other RTTI data structures.

Note also that this change provides the information required for solving the
problem of trying to deep copy closures only for grades that include
--typeinfo-liveness. Providing this info for other grades is future work.

configure.in:
	Find out what the right way to refer to a variable-sized array
	at the end of a struct is.

runtime/mercury_ho_call.h:
	New file to define the structure of closures and macros for accessing
	closures.

runtime/Mmakefile:
	Add the new header file.

runtime/mercury_ho_call.c:
	Add an entry point to handle calls to new-style closures. The code
	to handle old-style closures, which was unnecessarily duplicated for
	each code model, stays until all the installed compilers use the new
	closure representation.

	Until that time, the new entry point will contain code to detect
	the use of old-style closures and invoke the old code instead.
	This allows stage1s compiled with old compilers to use the old style
	and stage2 to use the new style without any special tricks anywhere
	else.

	Add a new entry point to handle method calls of all code models.
	The old entry points, which had the same code, will also be deleted
	after this change has been bootstrapped.

runtime/mercury_calls.h:
	Remove the macros that call closures. Their interface sucked, they
	were not used, and their implementation is now out of date.

runtime/mercury_stack_layout.h:
	Add a new type, MR_Type_Param_Locns, for use by the C type
	representing closures. Since MR_Stack_Layout_Vars has a field,
	MR_slvs_tvars, which references a data structure identical
	in every way to MR_Type_Param_Locns, change the type of that field
	to this new type, instead of the previous cheat.

runtime/mercury_layout_util.h:
	Minor update to conform to the new type of the MR_slvs_tvars field.
	(This is the only use of that field in the system.)

runtime/mercury_type_info.h:
	Add new types MR_TypeInfo and MR_PseudoTypeInfo. For now, they
	are just Word, but later we can make them more accurate.
	In the meantime, we can refer to them instead of to Word,
	making code clearer. One such reference is now in mercury_ho_call.h.

compiler/notes/release_checklist.html:
	Add a reminder to remove the redundant code from mercury_ho_call.c
	after bootstrapping.

compiler/llds.m:
	Replace three code addresses for calling closures and another three
	for calling methods with one each.

compiler/call_gen.m:
compiler/dupelim.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/llds_out.m:
	Trivial updates in accordance with the change to llds.m

compiler/code_info.m:
	Move the code to handle layouts to continuation_info.m,
	since that's where it belongs. Leave only the code for picking
	up parameters from code_infos and for putting results back in there.

	Remove the redundant arguments of code_info__init, and extract
	them from ProcInfo, to make clear that they are related.

compiler/code_gen.m:
	Since we pass ProcInfo to code_info__init, don't pass its components.

compiler/continuation_info.m:
	Add the code moved from code_info.m, in a form which takes explicit
	arguments for things that used be hidden in the code_info.

	Add new code, closely related to the moved code, that creates
	layout info from a procedure's argument info, rather than from a
	(part of) the current code generator state. This way, it can be
	invoked from places that don't have a code_info for the procedure
	for which they want to generate layouts. This is the case when
	we generate layouts for closures.

compiler/par_conj_gen.m:
compiler/trace.m:
	Minor changes required by the move of stuff from code_info to
	continuation_info.

compiler/stack_layout.m:
	Export some predicates for use by unify_gen.

compiler/unify_gen.m:
	Switch to creating new style closures, complete with layout info.

	Optimize the code for extending closures a bit. By copying the
	fixed words of the closure outside the loop, we avoid incurring
	the loop overhead twice.

compiler/code_util.m:
	Add a couple of utility predicates for continuation_info.m and
	unify_gen.m

library/benchmarking.m:
library/std_util.m:
	Refer to the new entry point for handling closures.

browser/dl.m:
	Use the new closure representation.

	Note that extras/dynamic_linking/dl.m, which is supposed to be
	the same as browser/dl.m but is not, should also be updated, but
	this will be handled later by Fergus.

tests/hard_coded/closure_extension.{m,exp}:
	A new test case to exercise the code for extending closures.

tests/hard_coded/Mmakefile:
	Enable the new test case.
1999-04-16 06:05:49 +00:00