Estimated hours taken: 0.25
Address juliensf's review comments on my recent change to add an MLDS
optimization to convert assignments into initializers.
compiler/ml_optimize.m:
doc/user_guide.texi:
Fix some typos.
compiler/options.m:
Wrap some long lines.
Estimated hours taken: 1.5
Add an MLDS optimization to convert assignments into
initializers.
compiler/options.m:
doc/user_guide.texi:
Add new option `--optimize-initializations'.
compiler/ml_optimize.m:
Implement the new optimization.
compiler/ml_elim_nested.m:
compiler/ml_util.m:
Move initializer_contains_var, rval_contains_var and related
predicates from ml_elim_nested.m to ml_util.m, for use by
ml_optimize.m.
Estimated hours taken: 1.
Added an option `--optimize-tailcalls' which makes optimization of
tailcalls in the MLDS backend optional. This is turned off in
optimization levels -1 and 0 and when the Java grade is being used; for
other optimization levels it is on.
compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/options.m:
doc/user_guide.texi:
Added new option `--optimize-tailcalls'.
Estimated hours taken: 4
Added new compiler options to support the Java backend and
updated documentation to reflect this.
compiler/globals.m:
Removed comment about Java backend not being implemented.
Replaced it by one say that it is work in progress.
compiler/mercury_compile.m:
If Target = java then call the Java backend.
compiler/options.m:
Added new options for compiling Java files:
`--java'
`--java-only'
`--java-compiler' ('--javac')
`--java-flags'
`--java-classpath'
`--java-object-file-extension'
compiler/handle_options.m:
If compiling to Java then don't link.
Added "java" grade.
compiler/mlds_to_java.m
New file.
XXX Currently just prints an error message about
the Java backend not being implemented.
doc/user_guide.texi:
Documented new options for compiling Java files.
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/final_grade_options.sh-subr:
Added support for "java" grade.
Estimated hours taken: 8
If the trace level is `deep' or some level (e.g. `decl') whose functionality
includes the functionality of `deep', then by default delay the deaths of
named variables until as late as possible, in order to make their values
accessible in the debugger at as many events as possible. Add an option,
--no-delay-death, to preserve the old behavior.
This change increases the runtime of a compiler compiled in the debugging grade
by about 2.3%, and increases its size by 20.5%, from 27.2 to 32.7 Mb. The size
increase is mostly to read-only data increasing from 10.2 to 15.5 Mb, though
the code size also increases a bit, from 16.8 to 17.5 Mb, due to the larger
number of stores onto the stack.
I expect that the space penalty will be substantially reduced when I move
variable type information from label layouts to procedure layouts, since
at present the type of a variable that is live at many labels is recorded
many times.
compiler/liveness.m:
Add an optional pass after the initial computation of deadness to
delays deaths as late as possible.
compiler/trace_params.m:
Add a predicate to test whether delaying deaths make sense.
compiler/options.m:
doc/user_guide.texi:
Add the new option.
Estimated hours taken: 12
Fix a bug with the handling of commits in the high-level C back-end.
It was implementing commits via calls to setjmp()/longjmp(),
but ANSI/ISO C says that longjmp() is allowed to clobber the values
of any non-volatile local variables in the function that called setjmp()
which have been modified between the setjmp() and the longjmp().
The fix is that whenever we generate a commit, we put it in its own
nested function, with the local variables (e.g. `succeeded',
plus any outputs from the goal that we're committing over)
remaining in the containing function. This ensures that
none of the variables which get modified between the setjmp()
and the longjmp() and which get referenced after the longjmp()
are local variables in the function containing the setjmp().
[The obvious alternative of declaring the local variables in the
function containing setjmp() as `volatile' doesn't work, since
the assignments to those output variables may be deep in some
function called indirectly from the goal that we're committing
across, and assigning to a volatile-qualified variable via a
non-volatile pointer is undefined behaviour. The only way to
make it work would be to be to declare *every* output argument
that we pass by reference as `volatile T *'. But that would
impose distributed fat and would make interoperability difficult.]
compiler/options.m:
Add a new option `--put-commits-in-own-function'.
compiler/handle_options.m:
If the target is high-level C, set the
`--put-commits-in-own-function' option.
compiler/ml_code_util.m:
Add a routine for accessing the new option.
compiler/ml_code_gen.m:
If the new option is set, generate each commit in its own
nested function.
tests/hard_coded/Mmakefile:
tests/hard_coded/setjmp_test.m:
tests/hard_coded/setjmp_test.exp:
A regression test.
Previous versions of the compiler generated code for this test
case that did the wrong thing on *some* systems.
Estimated hours taken: 16
compiler/cse_detection.m:
Put back the earlier clarification of cse_detection code, but without
the bug this time :-( The bug was that cse_detection did not insist
on all branches of the branched control structure containing a copy
of the "common" deconstruction unification. By hoisting that
unification before the branched control structure, cse_detection
was effectively adding a test into some computation paths.
Fix common subexpression elimination so that it works when the
deconstruction it hoists out of a branched control structure
involves a functor with existentially typed arguments.
compiler/switch_detection.m:
Modify the code called by cse_detection to look for deconstruction
unifications to make it explicit whether the search was successful.
compiler/options.m:
Put the default value of --compare-specialization back to 4, now
that the bug that prevented it from working at levels above 1 (in the
presence of existentially typed arguments) has been fixed.
Estimated hours taken: 80
Add tabling of I/O actions for the debugger.
compiler/options.m:
Add a new option, --trace-table-io, that enables the tabling of I/O
actions, and another, --trace-table-io-states, that governs whether the
tabling includes the I/O state variables themselves. (You want to table
these variables iff they contain meaningful information that is not
stored in global variables.) These options are for developers only
for now.
compiler/modules.m:
Implicitly import table_builtin if --trace-table-io is specified.
compiler/prog_data.m:
Add eval_table_io as a new eval method.
compiler/hlds_pred.m:
Add a mechanism for checking whether a predicate has an input/output
pair of io__state args.
Extend the tables indexed by eval_method to handle eval_table_io.
compiler/hlds_out.m:
Print the eval method in HLDS dumps.
compiler/table_gen.m:
If a procedure has a pair of I/O state args and is defined using pragma
C code that has the tabled_for_io marker, and --trace-table-io is
specified, then perform I/O tabling on it and mark it as tabled.
compiler/notes/compiler_design.m:
Document that table_gen.m can now change the evaluation methods of
procedures (to eval_table_io).
compiler/stack_layout.m:
runtime/mercury_stack_layout.h:
Add an extra field to proc layouts. If debugging is enabled and a
procedure has I/O state arguments, this field gives the number of the
stack slot which will be filled with the I/O action counter at the
time of the call, so that on retry the debugger can reset the I/O
action counter to this value.
compiler/trace.m:
Add code to reserve and fill this stack slot.
Make the order of fields in the trace_slots structure match the order
in proc layouts.
compiler/code_info.m:
compiler/live_vars.m:
Pass a module_info to trace__setup and trace__reserved_slots.
library/io.m:
Mark the I/O primitives (i.e. procedures that are defined by pragma C
code and do I/O) with the tabled_for_io feature. (See the discussion
of I/O primitives in compiler/table_gen.m.)
Standardize the formatting of predicates defined by pragma C codes.
library/table_builtin.m:
Define the predicates that perform I/O tabling, to which calls are
inserted in I/O tabled predicates. These depend on knowing what the
maximum MR_Unsigned value is.
library/table_builtin.m:
runtime/mercury_tabling_macros.h:
Table nodes implementing a simple kind of trie, which can also be
viewed as a hash table with the hash function hash(n) = hash - start
were already supported by mercury_tabling.c. They are used to
implement I/O tabling, since I/O the tabled action numbers form a
contiguous sequence. Now allow that functionality to be accessed
from the library through macros.
runtime/mercury_trace_base.[ch]:
Add the global variables required by I/O tabling.
trace/mercury_trace.c:
Implement retry across I/O by resetting the I/O counter to the value
it had on entry to the retried call. However, since this is not safe
in general, ask the user for permission first.
trace/mercury_trace.h:
Add two extra arguments to MR_trace_retry to specify the input and
output streams on which to ask permission.
trace/mercury_trace_internal.c:
Add commands to start and stop I/O tabling. For now, they are for use
by developers only and are undocumented; I expect they will change
significantly before being let loose on users.
trace/mercury_trace_external.c:
trace/mercury_trace_declarative.c:
Pass extra arguments to MR_trace_retry to indicate that these modules
are not interested (at least for now) in retry across I/O, since they
do not (yet) have mechanisms for asking the user for permission.
tests/debugger/tabled_read.{m,inp,exp,data}:
A new test case to check retry across tabled and non-tabled I/O.
tests/debugger/Mmakefile:
Enable the new test case.
Estimated hours taken: 60
Implement pragma foreign_code for Managed C++.
Currently you can only write MC++ code if your backend is capable of
generating use MC++ as its "native" foreign language. The IL backend is
the only backend that does this at the moment (the other backends have C
as their "native" foreign language).
Most of the machinery is in place to call from C to (normal) C++
but there is little work done on actually spitting out the C++ code into
a separate file. The IL backend does this step already with managed C++.
The intention is to turn foreign_code for C++ into a pragma import
(which imports the C++ function from a separate file) and
foreign_code for C (which calls the imported function). The C++ code
will be inserted into a separate file that is compiled using C linkage.
The important improvement this change gives is that you can write a
module with a C and a MC++ implementations side-by-side. The target
backend will select the most appropriate foreign language to use.
You can override its choice using --use-foreign-language. Later on
we will probably want more flexibility than just a single language
selection option).
This change also implements :- pragma foreign_decl, which allows header
file style declarations to be written in languages other than C.
compiler/code_gen.m:
Reject code that is not C when generating LLDS.
compiler/export.m:
Start renaming C as foreign.
Reject code that is not C when generating exports.
compiler/foreign.m:
A new module to handle foreign language interfacing.
The bulk of the code for pragma import has been moved here from
make_hlds.
compiler/globals.m:
Convert foreign language names to foreign_language.
This code has been moved closer to the similar conversion we do
for target language names.
Add globals__io_lookup_foreign_language_option to make it easier
to deterministically lookup the options relating to foreign
languages.
compiler/hlds_module.m:
Move module_add_foreign_decl and module_add_foreign_body_code
from make_hlds.m (where they were called module_add_c_header and
module_add_c_code).
compiler/hlds_out.m:
Write the foreign language out in HLDS dumps.
compiler/llds.m:
Change foreign_header_info to foreign_decl_info.
Change definitions of foreign_decl_code and foreign_body_code to
include the language.
compiler/llds_out.m:
Reject code that is not C when writing out LLDS.
compiler/make_hlds.m:
Add foreign language information to the bodys and decls when
creating them.
Update error messages to refer to foreign code instead of C
code.
Use foreign.m to generate interfaces from the backend language
to the foreign language.
Hardcode C as the language for fact tables.
compiler/mercury_compile.m:
Collect the appropriate foreign language code together for
output to the backend.
compiler/intermod.m:
compiler/mercury_to_mercury.m:
Output the foreign language string.
Change a few names to foreign_code instead of c_code.
compiler/ml_code_gen.m:
Filter the foreign language bodys and decls so that we only get
the ones we are in (given by the use-foreign-language option).
compiler/mlds_to_c.m:
Abort if we are given non C foreign language code to output
(we might handle it here in future, or we might handle it
elsewhere).
compiler/mlds_to_ilasm.m:
Abort if we are given non MC++ foreign language code to output
(we might handle it here in future, or we might handle it
elsewhere).
compiler/options.m:
compiler/handle_options.m:
Add --use-foreign-language as a user option to control the
preferred foreign language to use as the implementation of this
module.
Add backend_foreign_language as an internal option which stores
the foreign language that the compiler will use as a default
(e.g. the natural foreign language for the backend to use).
Set the preferred backend foreign language depending on the
target.
compiler/prog_data.m:
Add managedcplusplus as a new alternative for the
foreign_language type.
Make c_header_code into foreign_decl.
Give the foreign language for foreign_code as an attribute of
the code.
Write code to turn attributes into a list of strings (suitable
for writing out by mercury_to_mercury). This fixes what appears
to be a bug in tabled_for_io -- the tabled_for_io attribute was not
being written out. Structure the code so this bug is
difficult to repeat in future.
compiler/prog_io_pragma.m:
Parse foreign_decl.
Turn c_header_code into a special case of foreign_decl.
compiler/*.m:
Remove the language field from pragma_foreign_code, it is now an
attribute of the code.
Various type and variable renamings.
tests/invalid/pragma_c_code_and_clauses1.err_exp:
tests/invalid/pragma_c_code_dup_var.err_exp:
tests/warnings/singleton_test.exp:
Update the tests to reflect the new error messages talking
about :- pragma foreign_code rather than :- pragma c_code.
Estimated hours taken: 7
Fix some problems with intermodule higher-order specialization that
were preventing the compiler from properly specializing calls
to list__sort/3, even at the highest optimization level.
compiler/intermod.m:
Allow procedures which are called from exported procedures
to be put in the `.opt' files. This is needed e.g. for
list__hosort.
compiler/options.m:
Increase the --higher-order-size-limit at higher optimization
levels. --optimize-higher-order is enabled at -O3, with a
default size limit of 20. I changed the limit at higher
optimization levels: at -O4, the limit is set to 30, and at
-O5, it is set to 40.
Estimated hours taken: 0.1
compiler/options.m:
Set the default value of --compare-specialization back to 1 as a
workaround for a bug in cse_detection.m.
Estimated hours taken: 8
Get the MLDS back-end to generate better code for switches.
It now compiles Mercury switches on int/char/enums into C switches.
compiler/mlds.m:
Add `switch' as a new alternative in the `mlds__stmt' type.
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_util.m:
Minor changes to handle the new `switch' statement.
compiler/ml_code_gen.m:
Move the code for handling switches to ml_switch_gen.m.
Export `ml_gen_goal', for use in ml_switch_gen.m.
compiler/ml_switch_gen.m:
compiler/ml_dense_switch.m:
New files, adapted from switch_gen.m and dense_switch.m, but
with significant changes. These now handle three forms of switch:
- dense switches, implemented as computed gotos;
- "direct mapped" switches, which get implemented using the
MLDS switch statement, which in turn gets mapped to the
target language's switch statement;
- if-then-else chains
compiler/ml_code_util.m:
Add a label counter to the ml_gen_info, and define predicates
for allocating new labels.
compiler/mlds_to_c.m:
Output switch statements. Also fix a layout bug in the output:
make sure we output newlines at the end of comments.
compiler/mlds_to_il.m:
Call error/1 for MLDS switch statements. The code generator
will generate MLDS computed_gotos (which map to IL `switch'
instructions) rather than MLDS switch statements, so we should
never get MLDS switch statements here.
compiler/options.m:
Add a new option `--prefer-switch', defaulting to enabled,
which says to generate switches rather than computed gotos
where possible.
Estimated hours taken: 8
compiler/unify_proc.m:
Generate specialized comparison predicates for types with at most
N functors, for 0 <= N <= 3. This should speed up comparisons
on such types, and reduce code size, since we can dispense with
an if-then else, several calls (e.g. to index and error) and the
index predicate itself.
compiler/options.m:
Add the option that specifies N, the max number of function symbols
for which we will generate specialized comparison predicates.
compiler/handle_options.m:
Clip the value of this option to the maximum supported by unify_proc.m.
compiler/make_hlds.m:
Use the (clipped and therefore accurate) value of this option to decide
which types have specialized comparison predicates and thus can
dispense with an index predicate.
tests/hard_coded/comparison.{m,exp}:
A test case for specialized comparisons.
tests/hard_coded/Mmakefile:
Enable the test case, and sort the list of test cases.
Estimated hours taken: 0.1
compiler/options.m:
Add an option `--fixed-user-guided-type-specialization',
which is only intended to be used in configure.in to
check whether the installed compiler has some recent bug
fixes for type specialization. This will be needed
when I add `:- pragma type_spec' declarations to the
library.
Estimated hours taken: 0.5
compiler/options.m:
doc/user_guide.texi:
Document that the `--high-level-code' back-end doesn't support
`--split-c-files'.
tests/hard_coded/Mmakefile:
Don't run the --split-c-files test in hl* grades.
Estimated hours taken: 220
The .NET MSIL (Microsoft Intermediate Language) backend.
While not complete, this backend implements enough of Mercury to run
programs such as eliza (with an appropriate runtime, which is not part
of this change). The IL backend TODO list is in mlds_to_il.m.
We generate IL "assembler" from MLDS. The IL assembler (ILASM) then
turns this into bytecode in a .DLL or .EXE file.
Pragma C code is put into a separate .cpp file and compiled using the managed
C++ compiler.
compiler/il_peephole.m:
Peephole optimize the IL.
compiler/ilasm.m:
Generate IL assembler from IL.
Also a representation of the entities in the IL assembler
syntax.
compiler/ilds.m:
The IL instruction set.
compiler/mercury_compile.m:
Generate IL if --target il is set.
Define mercury_compile__mlds_has_main/1.
Assemble the IL if --target-code-only is not set.
Use "target_debug" option instead of "c_debug".
compiler/ml_code_gen.m:
If the target is IL and we are generating MLDS for foreign code
that calls continuations (that is, model_non pragma C code),
create a nested function (not implemented in foreign code) to
call the continuation. This is because in managed C++ it isn't
possible to call a continuation, but it's fine to call a method
written in IL that calls the continuation instead.
compiler/ml_code_util.m:
Add unexpected/1 as another error message handler.
Add code for generating indirect calls to success continutation
(via a nested function).
compiler/ml_elim_nested.m:
Generate slightly different code for IL environments. We don't
use the address of the environment variable (like in the C
backend) but use the environment variable directly. We also
have to initialize the environment as a new object.
This is because we use a class to represent the environment,
whereas the C backend uses a struct.
Also, if there is no environment required for nested functions
(that is, the nested functions don't use any of the local
variables of the parent), don't generate an environment.
This is important for the nested functions generated in mangaged
C++ -- otherwise have to be able to handle defining and
initializing environments in managed C++ just to do the continuation
calls for model non pragma C code.
Add field names to elim_info.
compiler/mlds_to_il.m:
The IL code generator.
Also contains the mapping from MLDS type to IL types (which
is useful when generating forieng language stubs to interface
with IL).
compiler/options.m:
Add a debugging option for IL assember -- it prints out each
line of assembler before it executes. This is very much a
developer only option.
Make a "target_debug" option -- the old "c_debug" option is just
an alias for this option. If the target it IL, "target_debug"
can also turn on debugging for IL, allowing the IL debugger to
display IL instructions as it traces execution.
Estimated hours taken: 8
Implement a general mechanism for suppressing selected aspects of execution
tracing.
compiler/trace_params.m:
This new file contains two abstract data types that define the
parameters of the execution tracing system, and the operations
on them.
The two ADTs are the trace level (moved from globals.m) and a new one,
trace_suppress_items, which replaces --no-trace-internal,
--no-trace-redo and --no-trace-return, and provides additional
capabilities requested by Erwan.
Basically any given port can now be suppressed, with the exception of
call (because the call event's layout structure is needed for
implementing redo from any other event) and excp (because they are
created on the fly by exception.m, and are not put into object
code in the first place).
compiler/globals.m:
Delete the stuff now migrated to trace_params.m. Make
trace_suppress_items part of the globals structure.
compiler/code_gen.m:
compiler/trace.m:
Allow the suppression of individual ports.
compiler/stack_layout.m:
Allow the suppression of parts of layout structures.
compiler/*.m:
Minor changes, mainly importing trace_params, to conform to the main
modifications.
compiler/options.m:
Delete --no-trace-internal, --no-trace-redo and --no-trace-return.
Add --suppress-trace, but do not document it, since it is really
intended only for implementors.
doc/user_guide.texi:
Delete the documentation of --no-trace-internal, --no-trace-redo and
--no-trace-return. Do not document it --suppress-trace, since it is
really intended only for implementors. (The only reason why other three
were documented is that most consumers of the users' guide then *were*
implementors.)
Estimated hours taken: 0.2
Enable the eager code generator where appropriate.
compiler/options.m:
Make eager code generation the default; switch back to laxy code
generation at optimization levels 4 and higher.
compiler/handle_options.m:
Regardless of optimization level, use eager code generation
if debugging is enabled.
Estimated hours taken: 2
Make declarative debugging a trace level, not a separate option.
compiler/globals.m:
Make trace_level an abstract data type. Define and export several
functions that check whether the current trace level requires
particular kinds of treatment.
compiler/options.m:
Remove --trace-decl as an option.
compiler/*.m:
Instead of checking for particular values of the trace level, use
the functions now exported by globals.m.
tests/debugger/declarative/Mmakefile:
Use the trace level to ask for declarative debugging.
Estimated hours taken: 0.5
Various fixes for problems fjh pointed out in a review.
compiler/ml_code_util.m:
Fix a typo.
compiler/ml_optimize.m:
compiler/mlds_to_c.m:
Move some comments from mlds_output_assign_args to
generate_assign_args.
Remove mlds_output_assign_args as it is now dead code.
compiler/options.m:
Fix a typo, llds-optimize should be mlds-optimize.
doc/user_guide.texi:
Document --no-mlds-optimize.
Estimated hours taken: 2
Fix a bug: mmc wasn't passing the right flags to the C compiler
when `--parallel' was specified.
configure.in:
Set CFLAGS_FOR_THREADS, using code adopted from the code
in scripts/mgnuc.in.
scripts/mgnuc.in:
Use CFLAGS_FOR_THREADS rather than doing the case analysis
here.
scripts/mmc.in:
Pass `--cflags-for-threads $CFLAGS_FOR_THREADS' to mercury_compile.
compiler/options.m:
Add a new option `--cflags-for-threads', for use by scripts/mmc.in.
compiler/mercury_compile.m:
If --parallel is enabled, pass the --cflags-for-threads
options to the C compiler.
bindist/bindist.build_vars.in:
Pass on CFLAGS_FOR_THREADS.
Estimated hours taken: 24 (by fjh)
Add new options and grades for the IL back-end.
Implement an option to handle output parameters for nondeterministic
procedures by passing the outputs (by value) to the continuation,
rather than using pass-by-reference. This is needed for IL
because IL does not allow managed pointers (which we used to
implement pass-by-refernece) to be stored as fields of environment
structs.
Also add an option to return outputs by value in det/semidet code.
This is not yet tested, since none of our target languages support
returning multiple values.
(Note that the IL backend is not activated by these changes -- it
hasn't been checked in).
compiler/globals.m:
Use field names for the globals structure.
Add new `target' field to the globals.
compiler/options.m:
compiler/handle_options.m:
Add new options `--target', `--target-only', `--il', and `--il-only'.
`--target' specifies the output langauge (e.g. C or IL).
`--target-only' says to only compile to the output language
(e.g. similar to -C or --compile-to-c option).
`--il' sets target to IL.
`--il-only' sets target to IL and specifies --target-only.
Add new grades `il' and `ilc'.
These grades are used for compiling to il grades. `il' is the
normal `il' grade, while `ilc' uses low-level (C-like) data
representations.
Change `--compile-to-c' from a boolean option to an abbreviation
for `--target c --target-only', and move it from the "Output options"
section to the "Compilation model options" section.
Comment out the documentation for `--generate-prolog' and
`--prolog-dialect', since those options are not yet implemented.
Document the `--infer-all' option.
compiler/mercury_compile.m:
Check the `target_code_only' option rather than `compile_to_c',
since the latter is just an abbreviation now, not a real option.
compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_unify_gen.m:
Use the `--det-copy-out' option to decide whether to pass
output arguments for model_det/model_semi procedures by
reference, or whether to just return multiple values.
Use the `--nondet-copy-out' option to decide whether to pass
output arguments for model_non procedures by reference, or
whether to just pass them to the continuation.
compiler/mlds.m:
Change the mlds__cont_type so that it includes a list of
the continuation's argument types (if any).
compiler/mlds_to_c.m:
Update to reflect the change to mlds.m.
doc/user_guide.texi:
Update the documentation to reflect the above changes.
scripts/parse_grade_options.sh-subr:
Add new options `--target' and `--il'.
scripts/init_grade_options.sh-subr
Add new grades `il' and `ilc'.
scripts/final_grade_options.sh-subr
Make `--target il' imply `--high-level-code'.
Estimated hours taken: 5
Do the transformation of self-tailcalls into loops as an MLDS->MLDS
transformation (instead of during mlds_to_c.m). Both the IL and C
backends for MLDS use this transformation.
Also, we transform into label/goto instead of for/continue. This is
because IL doesn't have a for/continue construct. It may be worth
revisiting this decision in future and performing benchmarks.
compiler/mercury_compile.m:
Add an optimization phase to the MLDS end of the compiler.
compiler/ml_optimize.m:
New file that performs MLDS->MLDS optimizations such as turning
self-tail calls into loops.
compiler/ml_tailcall.m:
Use ml_util.
compiler/ml_util.m:
New file containing generic MLDS utilities.
Contents are can_optimize_tailcall and statements_contain_statements.
This code was in mlds_to_c but will be used by more than just
this backend.
compiler/mlds_to_c.m:
Delete old tailcall transformation code (it is either moved into
ml_optimize, ml_util or it is no longer needed).
Only handle general tailcalls.
Estimated hours taken: 1
Add options for
unboxed_enums - turns on unboxed enums (default is yes)
unboxed_no_tag_types - turns on unboxed no-tag-types (default is yes)
Currently every grade uses these representations.
We will set these to `no' on the IL backend (and probably the Java
backend) if using a simple implementation of the the Array of Object
representation for Mercury data structures.
compiler/make_tags.m:
Check for these options when creating representations.
compiler/options.m:
Add the new options.
compiler/type_util.m:
Make sure type_is_no_tag_type checks the appropriate option.
Add a new predicate type_constructors_are_no_tag_type which just
does a check of the structure of the constructors (you have to
do the option checking yourself).
compiler/higher_order.m:
compiler/mode_util.m:
Use the new type_is_no_tag_type (this actually simplifies the
code).
compiler/type_ctor_info.m:
Use type_constructors_are_no_tag_type and check the globals.
Estimated hours taken: 40
Add a new optimization, enabled by the option --unneeded-code. This
optimization removes goals whose outputs are not used at all, and moves goals
whose outputs are only used on some computation branches to the starts of
those branches, so they do not need to be executed on other branches.
Such deletions/movements are done only when the semantic switches and the
properties of the relevant goal together permit it.
compiler/unneeded_code.m:
A new module to perform the goal rearrangement.
compiler/hlds_goal.m:
The new optimization needs to know how many functors the switched-on
variable can be bound to, so it can check whether a given number of
switch arms covers all alternatives or not. To make access to this
information convenient, we add a field to the goal_path_step
alternative for switch arm entry that records this number.
compiler/goal_path.m:
Fill in this number.
To make this possible, we thread the necessary information through the
predicates in this module.
compiler/type_util.m:
Add a utility predicate type_util__switch_type_num_functors, for use
by the new code in goal_path.m.
compiler/switch_detection.m:
Avoid duplicated code by using type_util__switch_type_num_functors
where relevant.
compiler/code_aux.m:
Add three new auxiliary predicate, code_aux__goal_cannot_loop_or_throw,
code_aux__goal_can_loop_or_throw and code_aux__goal_can_loop, to the
existing code_aux__goal_cannot_loop. code_aux__goal_cannot_loop
now checks only what its name says.
compiler/trace.m:
Ignore the new field when generating goal paths strings.
compiler/mercury_compile.m:
Invoke unneeded_code.m if required.
compiler/hlds_pred.m:
Add some utility predicates for use by unneeded_code.m.
compiler/unused_args.m:
Use the new utility predicates instead of reimplementing them.
compiler/options.m:
Define the --unneeded-code option, and its auxiliary,
--unneeded-code-copy-limit.
doc/user_guide.texi:
Document the new options.
Estimated hours taken: 0.1
compiler/options.m:
Disable the accumulator introduction optimization at -O3, as it
causes a compiler abort in extras/trailed_update/var.m.
Estimated hours taken: 4
Introduce accumulators into predicates which have if-then-elses and
disjunctions.
mercury/compiler/accumulator.m:
Introduce accumulators into predicates which have if-then-elses and
disjunctions.
mercury/compiler/options.m:
Add the --introduce-accumulators option at -O3.
tests/general/accumulator/Mmakefile:
The tests no longer require that unused arg elimination needs to be
turned off.
Add the two new tests.
tests/general/accumulator/func.m:
tests/general/accumulator/func.exp:
Add a test case, which makes sure that functions can have
accumulators introduced.
tests/general/accumulator/ite.m:
tests/general/accumulator/ite.exp:
Add a test case for if-then-elses.
tests/general/accumulator/runtests:
Modify the runtests script so that we cut out line number
information from the predicate names. This should mean that the
INTRODUCED file should change less often.
tests/general/accumulator/INTRODUCED:
Add the two new tests results, and cut the line numbers out of all
the old results.
Estimated hours taken: 16
Changes needed to get
mmc --grade hlc.gc file.m
producing an executable, using MSVC as the compiler.
compiler/options.m:
Add the flags --c-flag-to-name-object-file and
--object-file-extension. --c-flag-to-name-object-file is the flag
the C compiler uses to name object files (ie -o for gcc, /Fo for
MSVC). --object-file-extension is the extension used by object
files on the current system.
compiler/mercury_compile.m:
Use the values of --c-flag-to-name-object-file and
--object-file-extension to generate the command line to compile
C files.
scripts/mmc.in:
Set the default values of the two new flags from the autoconfed
settings.
configure.in:
Set the value for CYGPATH, a utility which transforms between unix
and window paths. This is just echo under unix.
scripts/ml.in:
Use the autoconfed extension for the library files.
Use the autoconfed flag to add a path to list of directories to be
searched for libraries.
Make static libraries the default on cygwin systems.
Factor out the code which determines all the flags to be passed to
the linker.
Add an autoconfed variable LINK_OPT_SET which is the flag used to
indicate that all the options following this flag are to be passed
on to the linker.
Use the autoconfed setting for CYGPATH to transform the path to
static libraries into the correct format.
Estimated hours taken: 1
compiler/options.m:
doc/user_guide.texi:
scripts/init_grade_options.sh-subr:
Document the -H and --high-level-code options and the
associated `hlc' grade.
NEWS:
Document the MLDS back-end.
HISTORY:
Add a section on "MLDS back-end history".
Estimated hours taken: 1
Add support for dumping the MLDS.
XXX Currently the formatting is extremely primitive.
compiler/options.m:
Add a new option `--dump-mlds'.
Also delete the unused `--verbose_hlds_dump' option,
and allow `-H' as an alias for `--high-level-code'.
compiler/mercury_compile.m:
Implement the new `--dump-mlds' option, using `io__print'.
(I wanted to use the pretty printer in library/pprint.m,
but that has a performance problem when printing large
structures such as the MLDS.)
Estimated hours taken: 0.75
Change the `--c-include-directory' option so that multiple
occurrences of this option accumulate, rather than each
one overriding the previous one.
This change is needed because the use of the MERCURY_MC_ALL_C_INCL_DIRS
environment variable in tools/bootcheck and scripts/mmc.in
(which I recently added to fix a bug that broke tests/hard_coded/split_c_files)
assumes that multiple such options will accumulate. It also makes it more
consistent with the handling of the `-I' option in gcc.
compiler/options.m:
Change c_include_directory from a string option
to an accumulating option (i.e. a list of strings).
compiler/mercury_compile.m:
Modify to reflect the change to options.m.
compiler/options.m:
doc/user_guide.texi:
Update the documentation for --c-include-directory to reflect its new
semantics. Also document the MERCURY_MC_ALL_C_INCL_DIRS environment
variable.
Estimated hours taken: 35
Recognise associativity assertions, and use them to introduce
accumulators.
mercury/compiler/assertion.m:
Add assertion__is_associativity_assertion, which for an assert_id
determines whether the assertion is associative.
mercury/compiler/accumulator.m:
Call assertion__is_associativity_assertion to determine whether a
call is associative.
Rather than failing if a call is associative and nothing is known
about the effect of rearranging the argument order, report a
suppressible warning.
Fix a bug where the mode of the introduced pred wasn't correct.
mercury/compiler/mercury_compile.m:
Move accumulator introduction before inlining and unused_args, as
inlining can inline an associative call making it unrecognisable and
unused_args eliminates arguments which make it difficult to relate
the assertion with the actual call.
mercury/compiler/notes/compiler_design.html:
Document the constraints on when the module accumulator.m can be
called for it to be effective.
mercury/compiler/options.m:
Add the new option "--inhibit-accumulator-warnings".
mercury/doc/user_guide.texi:
Document "--inhibit-accumulator-warnings".
mercury/library/list.m:
Declare list__append to be associative.
tests/general/accumulator/runtests:
Turn the tests back on, they *should* work under different
optimization levels now.
tests/warnings/Mmakefile:
tests/warnings/arg_order_rearrangment.exp:
tests/warnings/arg_order_rearrangment.m:
Test that a warning is output when accumulator introduction reorders
the arguments to a call without knowing the performance
implications.
Estimated hours taken: 3
Implement new grades and options for the MLDS back-end.
compiler/options.m:
Rename --highlevel-c as --highlevel-code.
Add new option --highlevel-data.
compiler/mercury_compile.m:
scripts/mgnuc.in:
Convert the grade options --highlevel-code,
--highlevel-data, and --gcc-nested-functions
into C flags -DMR_HIGHLEVEL_CODE, -DMR_HIGHLEVEL_DATA,
and -DMR_USE_GCC_NESTED_FUNCTIONS respectively.
compiler/handle_options.m:
scripts/parse_grade_options.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/ml.in:
Add new grades `hl', `hlc', `hl_nest', and `hlc_nest'.
Add code to handle the new options and grades.
scripts/ml.in:
If --high-level-code is set, then don't invoke the
demangler, since it doesn't (yet) understand the new
name mangling scheme.
Estimated hours taken: 24
WARNING: this change affects binary compatibility for debuggable code;
the debuggable modules of the program and the runtime linked into the
executable must either all come from before this change, or they must all
come from after this change. However, this change does *not* affect binary
compatibility for non-debuggable executables.
Reduce the number of arguments of MR_trace() to one. Two of the arguments,
the port and the goal path, move into the label layout structure, as 16-bit
numbers; the port as a simple enumeration type, and the goal path as an
index into the module-wide string table. (The latter will eventually allow the
debugger to support the placement of breakpoints on labels with specific goal
paths.) The third argument, the number of the highest-numbered rN register in
use at the label, has been moved into the proc layout structure. In theory,
this will require more register saves and restores, since the number in the
proc layout is conservative (it is the max of the numbers that would be
required at the individual labels). However, this is not important, for two
reasons. First, we always save and restore all the rM registers that
appear in the mrM array before the last special-purpose register, and in
most cases this dictates how many registers we save/restore. Second, we
save/restore registers only when the debugger starts interaction, so
save/restore is a time critical activity only for the external debugger.
This change reduces the execution time of debuggable executables by about
4-5% when executing outside mdb and 3-4% when executing under mdb. It also
reduces executable sizes, but only by about 0.7% on x86.
This change eliminates the --trace-just-in-case compiler option, since
we now have the best of both --trace-just-in-case and --no-trace-just-in-case.
The drawback of this scheme is slightly increased executable size with the
accurage garbage collector, but that seems a small enough price to pay.
compiler/code_gen.m:
compiler/code_info.m:
Record the number of the highest numbered rN register live at a trace
label.
compiler/continuation_info.m:
Record the number of the highest numbered rN register live at a trace
label, and the port and goal path associated with the labels of trace
events.
compiler/stack_layout.m:
Put the number of the highest numbered rN register live at a trace
label into proc layouts, and the port and goal path into label layouts.
Since we are breaking binary compatibility with old debuggable modules
anyway, compress the procedure id parts of proc layouts by using
only 16 bits to store the procedure's arity and mode number, instead
of 32 or 64.
compiler/trace.m:
Update the handling of ports, goal paths and max live register numbers,
so that instead of being passed as MR_trace arguments, they are
recorded in data structures.
Generate separate labels and layouts for the fail and redo events.
Although they still have the same layout information, they now record
different ports.
compiler/llds.m:
Since trace.m now generates a label layout structure for the redo
event, we must include redo events in the llds goal path type.
compiler/hlds_goal.m:
Since the code for handling the port type for nondet pragma events
has moved from the nondet-pragma-specific to the generic part of
trace.m, we must now include their event types in the hlds goal path
type.
compiler/llds_out.m:
Add a predicate for converting ports into numbers, now that we
must store ports in static data. Using their symbolic names would
be better, but that would require complications in the llds type
system, which would be inadvisable just before the release.
compiler/options.m:
compiler/handle_options.m:
doc/user_guide.texi:
Eliminate --trace-just-in-case.
compiler/llds.m:
compiler/llds_common.m:
compiler/llds_out.m:
Eliminate the data structure needed by --trace-just-in-case.
compiler/optimize.m:
Trivial update to conform to data structure changes.
library/exception.m:
Update the call to MR_trace.
runtime/mercury_stack_layout.h:
Update the C structure declarations for the layout structures
as discussed above.
runtime/mercury_init.h:
Update the declarations of MR_trace_real and MR_trace_fake
to use only one argument.
runtime/mercury_wrapper.[ch]:
Update the declaration of MR_trace_func to use only one argument.
runtime/mercury_trace_base.[ch]:
Update the declarations of MR_trace, MR_trace_real and MR_trace_fake
to use only one argument.
Delete MR_trace_struct(); since we deleted --trace-just-in-case, there
will not be calls to it anymore.
Since we are breaking binary compatibility anyway, move the exception
port to be with the other interface ports. This should speed up a
frequently executed test in the debugger.
Update the handling of redo events.
trace/mercury_trace.h:
Simplify and speed up the macro that tests a port for being an
interface port, now that exceptions are grouped with other interface
events.
trace/mercury_trace.c:
Update the definition of MR_trace_real to use only one argument.
The port is pulled out of the label layout structure only when
needed to perform the termination tests for the current debugger
command, and the goal path and the max live register number are
looked up only when the termination test succeeds.
Estimated hours taken: 0.5
Rename --call-trace-struct as --trace-just-in-case, and document it for
use by non-developers.
doc/user_guide.texi:
compiler/options.m:
Rename the option, reclassify it as a debugging option,
and document it properly.
compiler/handle_options.m:
compiler/trace.m:
Conform to the name change.
Estimated hours taken: 40
Support line numbers in the debugger. You now get contexts (filename:lineno
pairs) printed in several circumstances, and you can put breakpoints on
contexts, when they correspond to trace events or to calls. The latter are
implemented as breakpoints on the label layouts of the return sites.
This required extending the debugging RTTI, so that associated with each
module there is now a new data structure listing the source file names that
contribute labels with layout structures to the code of the module. For each
such source file, this table gives a list of all such labels arising from
that file. The table entry for a label gives the line number within the file,
and the pointer to the label layout structure.
compiler/llds.m:
Add a context field to the call instruction.
compiler/continuation_info.m:
Instead of the old division of continuation info about labels into
trace ports and everything else, divide them into trace ports, resume
points and return sites. Record contexts with trace ports, and record
contexts and called procedure information with return sites.
compiler/code_info.m:
Conform to the changes in continuation_info.m.
compiler/options.m:
Add a new option that allows us to disable the generation of line
number information for size benchmarking (it has no other use).
compiler/stack_layout.m:
Generate the new components of the RTTI, unless the option says not to.
compiler/code_gen.m:
compiler/pragma_c_gen.m:
compiler/trace.m:
Include contexts in the information we gather for the layouts
associated with the events we generate.
compiler/call_gen.m:
Include contexts in the call LLDS instructions, for association
with the return site's label layout structure (which is done after
code generation is finished).
compiler/handle_options.m:
Delete the code that tests or sets the deleted options.
compiler/mercury_compile.m:
Delete the code that tests the deleted options.
compiler/basic_block.m:
compiler/dupelim.m:
compiler/frameopt.m:
compiler/livemap.m:
compiler/llds_common.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/value_number.m:
compiler/vn_*.m:
Trivial changes to conform to the changes to llds.m.
compiler/jumpopt.m:
Do not optimize away jumps to labels with layout structures.
The jumps we are particularly concerned about now are the jumps
that return from procedure calls. Previously, it was okay to redirect
returns from several calls so that all go to the same label, since
the live variable information associated with the labels could be
merged. However, we now also associate line numbers with calls, and
these cannot be usefully merged.
compiler/optimize.m:
Pass the information required by jumpopt to it.
doc/user_guide.texi:
Document that you can now break at line numbers.
Document the new "context" command, and the -d or --detailed option
of the stack command and the commands that set ancestor levels.
runtime/mercury_stack_layout.h:
Extend the module layout structure definition with the new tables.
Remove the conditional facility for including label numbers in label
layout structures. It hasn't been used in a long time, and neither
Tyson or me expect to use it to debug either gc or the debugger itself,
so it has no uses left; the line numbers have superseded it.
runtime/mercury_stack_trace.[ch]:
Extend the code to print stack traces to also optionally print
contexts.
Add some utility predicates currently used by the debugger that could
also be use for debugging gc or for more detailed stack traces.
trace/mercury_trace_internal.c:
Implement the "break <context>" command, the "context" command, and
the -d or --detailed option of the stack command and the commands
that set ancestor levels.
Conditionally define a conditionally used variable.
trace/mercury_trace_external.c:
Minor changes to keep up with the changes to stack traces.
Delete an unused variable.
trace/mercury_trace_spy.[ch]:
Check for breakpoints on contexts.
trace/mercury_trace_tables.[ch]:
Add functions to search the RTTI data structures for labels
corresponding to a given context.
trace/mercury_trace_vars.[ch]:
Remember the context of the current environment.
tests/debugger/queen.{inp,exp}:
Test the new capabilities of the debugger.
tests/debugger/*.{inp,exp}:
Update the expected output of the debugger to account for contexts.
In some cases, modify the input script to put contexts where they don't
overflow lines.
Estimated hours taken: 2
Fix two bugs in intermodule optimization reported by Warwick Harvey.
compiler/intermod.m:
Don't read `.opt' files for nested modules. The compiler
currently doesn't read in the `.int0' files for parent modules
of modules for which `.opt' files are read, resulting in
undefined symbol errors.
Export predicate `update_error_status' for use by trans_opt.m.
compiler/trans_opt.m:
Use intermod__update_error_status to check whether an
error should be reported if a `.trans_opt' file is not found.
This is difficult to write a test case for because it would
be spread across multiple directories.
compiler/options.m:
doc/user_guide.texi:
Add option --warn-missing-trans-opt-files.
compiler/handle_options:
--check-termination implies --warn-missing-trans-opt-files.
tests/valid/Mmakefile:
tests/valid/intermod_nested_module.m:
tests/valid/intermod_nested_module2.m:
Test case.
Estimated hours taken: 2
Add options to eliminate some of the dependencies on GNU C
in the MLDS back-end.
compiler/options.m:
Add new options `--gcc-nested-functions' and `--gcc-local-labels';
the documentation for these options is commented out for now.
Also add commented out documentation for `--high-level-c'.
compiler/mlds_to_c.m:
Implement the --no-gcc-local-labels option.
compiler/mercury_compile.m:
Add a stub implementation for the --no-gcc-nested-functions option:
if --high-level-c is set and --no-gcc-nested-functions is not set,
then call `error("Sorry, not implemented: --no-gcc-nested-functions")'.
Estimated hours taken: 0.75
Make the llds_common.m optimization disable-able.
compiler/options.m:
Add a new option `--common-data' which enables that
optimization; this option is set at `-O2' and higher.
compiler/mercury_compile.m:
Only invoke llds_common if --common-data is set.
doc/user_guide.texi:
Document the new option.
Estimated hours taken: 8
Add a new option, --checked-nondet-tailcalls, that enables the use of
Prolog style nondet tail calls (which check whether the current frame is
on top of the nondet stack and only do a tail call if it is).
This option is not likely to help Mercury code, since most of the time
the test will fail, which means we incurred its cost and did not gain
the benefit of the tailcall. However, HAL often has predicates that are
declared nondet but are det or semidet most of the time, and these can
benefit.
compiler/options.m:
doc/user_guide.texi:
Add the new option, which is not on by default and is not turned on
at any optimization level; you have to give it explicitly.
compiler/llds.m:
Modify the call_model type to distinguish the new style nondet tail
call from the old (which does not do a runtime test).
compiler/code_info.m:
Check the fail state whether it is suitable for new style nondet
tail calls.
compiler/call_gen.m:
Put the result from code_info.m into the generated LLDS.
compiler/jumpopt.m:
Use the new status field in the LLDS to perform the optimization,
if the option is given.
Document the main predicate and its new argument.
compiler/optimize.m:
Pass the value of the new option to jumpopt.
tests/hard_coded/checked_nondet_tailcall.{m,exp}:
A new test case to check that the code we generate with the new
option works correctly. (Checking whether it actually reduces
nondet stack usage would be harder.)
Estimated hours taken: 0.5
Add a new option for deep profiling to the compiler and the scripts.
compiler/options.m:
Add the new profiling options `profile-deep' and `deep-profiling'.
compiler/handle_options.m:
Add code to handle the above options.
scripts/init_grade_options.sh-subr:
Initialize the profile_deep option to false.
scripts/parse_grade_options.sh-subr:
Add code handle the deep-profiling options.
Estimated hours taken: 51
Make closures always include layout information, not just in grades in which
typeinfo liveness is turned on. This requires separating two notions,
which were previously combined:
- Body typeinfo liveness means that when a variable X is live, any
typeinfo variables describing type variables that occur in the type
of X must also be live.
- Interface typeinfo liveness means that when the input arguments
of a procedure include a polymorphically typed variable (e.g. X),
typeinfo variables describing type variables that occur in the type
of X must also be among the arguments.
This change turns on interface typeinfo liveness for procedures that either
have their address taken in the current module, or are exported and thus may
have their address taken in some other module.
compiler/hlds_pred.m:
Centralize decisions wrt whether procedure interfaces and bodies
use typeinfo liveness here.
compiler/options.m:
Rename the typeinfo_liveness option as body_typeinfo_liveness,
since this reflects its new function.
compiler/call_gen.m:
compiler/higher_order.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/unused_args.m:
Use hlds_pred.m to make decisions about liveness.
compiler/lambda.m:
Always include the relevant typeinfos in the interfaces of procedures
created for lambdas.
compiler/continuation_info.m:
compiler/stack_layout.m:
compiler/unify_gen.m:
Modify the predicates that record and use layout information about
closures to always do so, since the necessary information is now
always available about the interfaces of procedures which can be
put into closures. Previously, they only did so if typeinfo_liveness
was set.
Also, generate information about the types of the variables in a
closure from the pred_info's arg types field, not from the proc_info's
var types field, because unlike the latter, it is valid even for
imported predicates.
compiler/hlds_out.m:
Print the non-clause-related information in the clauses_info part
of a pred_info (e.g. the type parameters) even if the predicate
has no actual clauses. Simplify the code a bit by getting rid of
a duplicate test.
compiler/middle_rec.m:
Require that the code generated for the base case not refer to any
stack slots if this way of generating code is to be used. This is
necessary because the base case is executed when the current procedure
has no stack frame, and thus any references to stack slots would
refer to and possibly overwrite the data in another procedure's frame.
In the absence of requiring body typeinfo liveness for exported
procedures, such references were not generated; in its presence,
they were. However, we now require only interface liveness for
exported procedures, so we can still use middle recursion for them.
compiler/handle_options.m:
Do not turn off middle_rec if (body) typeinfo liveness is turned on,
now that the bug has been fixed. For polymorphic predicates, the base
case will still contain references to stack slots, and thus the
middle-rec optimization will not applied for them, but the optimization
may apply to monomorphic predicates.
compiler/passes_aux.m:
Add the ability to call compiler passes with the procedure id
as well as the predicate id of the procedure they are passed.
tests/hard_coded/typeclasses/Mmakefile:
Refer to --body-typeinfo-liveness instead of --typeinfo-liveness.
Estimated hours taken: 500
Add a new pass to the compiler, that attempts to introduce accumulators
into a procedure so as to make that procedure tail recursive.
WORK_IN_PROGRESS:
Document that the transformation now exists.
compiler/goal_util.m:
Create goal_util__can_reorder_goals, which is a version of
pd_util__can_reorder_goals that will work on the alias branch.
compiler/instmap.m:
Add instmap__changed_vars. This predicate is meant to provide the
same functionality as instmap_delta_changed_vars, but work on the
alias branch.
Also add comment to instmap_delta_changed_vars about using
instmap_changed_vars
compiler/accumulator.m:
The transformation.
compiler/mercury_compile.m:
Call the transformation.
compiler/options.m:
Add the option to turn the transformation on.
doc/user_guide.texi:
Document the option.
profiler/demangle.m:
util/mdemangle.c:
Demangle the accumulator version of the procedure labels.
compiler/notes/compiler_design.html:
Add the new pass to the documentation.
Estimated hours taken: 4.5
Remove support for --args simple. We don't use it, we won't use it even for
experiments, and it is unnecessary complication.
If anybody were using --args simple, this would need bootstrapping, but
since nobody does, there is no need, and this can be committed as an
ordinary change.
compiler/options.m:
doc/user_guide.texi:
scripts/*.in:
scripts/*.sh-subr:
Remove the --args option.
compiler/globals.m:
Remove the args_method global and its access predicates.
compiler/handle_options.m:
Don't set the args_method global from the option.
compiler/arg_info.m:
Remove support for --args simple. This allows us to remove a now
redundant argument from an exported predicate.
compiler/mercury_compile.m:
Remove the code for passing -DCOMPACT_ARGS to the C compiler.
compiler/bytecode_gen.m:
compiler/fact_table.m:
compiler/follow_vars.m:
compiler/live_vars.m:
compiler/call_gen.m:
Don't pass the unnecessary argument to arg_info.
compiler/call_gen.m:
compiler/unify_gen.m:
Remove now unnecessary assertions.
compiler/hlds_pred.m:
Don't include an args_method in proc_infos; instead, include
a slot that says whether the procedure's address is taken or not.
(In most cases, this determined whether the args_method was
simple or compact.) We will need this bool in the near future
(when we generate layout structures for procedures whose address
is taken).
Modify the signatures of exported predicates to accommodate
this change to the data structure.
compiler/hlds_out.m:
Print the new slot, not the args_method.
compiler/lambda.m:
When creating procedures from lambdas, set the address-taken slot
to address_is_taken instead of setting up its args_method.
compiler/make_hlds.m:
Minor changes to conform to the changes in the signatures of
the predicates exported from hlds_pred.m.
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/dnf.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/modecheck_call.m:
compiler/pd_info.m:
compiler/post_typecheck.m:
compiler/unify_gen.m:
Minor changes to conform to the changes in the signatures of
the predicates exported from hlds_pred.m and make_hlds.m.
runtime/mercury_type_info.h:
Remove the conditional definition of the macros that provided
an argument-method-independent way of referring to the registers
holding the inputs and outputs of e.g. unification procedures.
We don't need the independence anymore, and using registers instead
of macros in the code ensures that maintainers are aware of register
reuse issues (e.g. they copy an input from r1 before overwriting it
with an output).
runtime/mercury_conf_param.h:
runtime/mercury_grade.h:
Remove support for the args method component of the grade.
runtime/mercury_ho_call.c:
runtime/mercury_tabling.c:
library/*.m:
Conform to the changes in runtime/mercury_type_info.h by effectively
applying the #defines appropriate to compact args by hand.
Remove code and data structures only needed for simple args.
Remove comments needed only in the presence of uncertainty about
the args method.
Estimated hours taken: 5
Add options to turn off various RTTI features. Also switch off the
generation of variable names for accurate GC (this should be the default
unless we are tracing).
These new options are for space measurement only. There is little
chance the code will link or work if the options are used.
compiler/base_type_layout.m:
Let --type-ctor-layout and --type-ctor-functors control the
generation of layout and functors.
compiler/mercury_compile.m:
Let --type-ctor-info control the generation of type_ctor_info
structures.
compiler/stack_layout.m:
Turn off the generation of variable names structures unless
tracing.
compiler/unify_proc.m:
Use --special-preds to control the generation of unify and
compare predicates.
compiler/options.m:
Add the new options (as internal use only options).
Estimated hours taken: 8
Add an option that causes the compiler to pass information to the
execution tracing system in one struct, rather than four separate arguments.
Two of these arguments are pointers, which each require two instructions
to set up on SPARC, MIPS and other RISCs that do not use a global pool.
The other two arguments are small constants. Therefore on 32-bit RISCs,
replacing MR_trace/4 with MR_trace_struct/1 will probably replace
six instructions with two, which saves four instructions' worth
of time and 16 bytes of code, at the cost of 12 bytes of data,
and possibly the cost of some instructions later loading the info
from the struct into registers. However, this loading cost does not have
to be paid if tracing is not enabled, and other optimizations may
reduce the cost even if tracing is enabled. For example, I strongly suspect
that on out-of-order machines, which means most CPUs you can buy today,
the load instructions are effectively free, because they happen while
the indirect jump to MR_trace_real takes place.
I intend to benchmark this option on our various platforms,
and have autoconfigure set it on the machines in which it is beneficial.
doc/user_guide.texi:
Document the new --call-trace-struct option, and say it is not
for general use.
compiler/options.m:
Add the new option.
compiler/trace.m:
If the option is set, call MR_trace_struct instead of MR_trace,
and create a new kind of static (in both senses) global data structure
to hold the arguments.
Move the definition of trace_port to llds.m, and the procedure to
convert it to string to llds_out.m
compiler/code_info.m:
Add an extra code_info slot to hold this new kind of global data,
and its access predicates.
compiler/code_gen.m:
Transfer this new kind of global data from code_info to the global_data
part of module_info.
compiler/hlds_module.m:
Add a new field to the global_data data structure to hold this data.
compiler/mercury_compile.m:
Include the new global data in the list of things we give to llds_out.
compiler/llds.m:
Add a new kind of comp_gen_c_data to hold MR_trace_struct arguments.
Also move the definition of trace_port from trace.m to here,
since the new kind of comp_gen_c_data refers to this type.
compiler/llds_out.m:
Add code to print the new kind of comp_gen_c_data.
Move the code to print trace_ports from trace.m to here.
compiler/llds_common.m:
Ignore the new kind of comp_gen_c_data, since by construction
its contents are never common with anything else.
runtime/mercury_trace_base.[ch]:
Add a new variant of MR_trace, MR_trace_struct, that consolidates
the arguments into a single MR_Trace_Call_Info struct.
Fix a bad variable name: the int argument to MR_trace is a max r
register number, not a max mr register number.
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.