mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-12 20:34:19 +00:00
f08f93af2f0d74a236b06f5ed780ededdaa4f5a1
119 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
fa9ca36d03 |
This diff makes several files easier to read and to maintain (as well as
Estimated hours taken: 5 Branches: main This diff makes several files easier to read and to maintain (as well as more than 400 lines shorter), but contains no changes in algorithms whatsoever. compiler/deep_profiling.m: compiler/foreign.m: compiler/hlds_module.m: compiler/hlds_data.m: compiler/make_hlds.m: compiler/post_typecheck.m: compiler/prog_data.m: compiler/purity.m: compiler/type_util.m: Bring these modules into line with our current coding standards. Use predmode declarations and state variable syntax when appropriate. Reorder arguments of predicates where necessary for the use of state variable syntax, and where this improves readability. Replace predicates with functions where appropriate. Standardize indentation. compiler/*.m: Conform to the changes above. |
||
|
|
b39a3d855f |
This diff makes hlds_module.m and many callers of its predicates easier to read
Estimated hours taken: 6 Branches: main This diff makes hlds_module.m and many callers of its predicates easier to read and to maintain, but contains no changes in algorithms whatsoever. compiler/hlds_module.m: Bring (most of) this module into line with our current coding standards. Use predmode declarations, functions, and state variable syntax when appropriate. (The 'most of' is because I left the part of the module dealing with predicate tables alone, not wishing to cause a conflict for Pete.) Reorder arguments of predicates where necessary for the use of state variable syntax, and where this improves readability. Replace old-style lambdas with new-style lambdas or with partially applied named procedures. compiler/*.m: Conform to the changes in hlds_module.m. This mostly means using the new argument orders of predicates exported by hlds_module.m, and switching to state variable notation. Replace old-style lambdas with new-style lambdas or with partially applied named procedures in updated code. Replace unnecessary occurrences of four-space indentation with standard indentation in updated code. library/list.m: library/map.m: library/tree234.m: Add list__foldl4 and map__foldl3, since in some compiler modules, state variable notation is more convenient (and the code more efficient) if we don't have to bundle up several data structures into a tuple just to iterate over them. Change the fold predicates to use state variable notation. NEWS: Mention the new library functions. |
||
|
|
c8e4004825 |
This diff makes code_info.m and many callers of its predicates easier to read
Estimated hours taken: 4 Branches: main This diff makes code_info.m and many callers of its predicates easier to read and to maintain, but contains no changes in algorithms whatsoever. compiler/code_info.m: Bring this module into line with our current coding standards. Use predmode declarations, functions, and state variable syntax when appropriate. Reorder arguments of predicates where necessary for the use of state variable syntax, and where this improves readability. Where a predicate returned its input code_info unchanged, purely to allow the convenient use of DCG notation in the caller, delete the unnecessary output argument. This should make the caller somewhat more efficient, since it can avoid updating the stack slot holding the current code_info. Replace old-style lambdas with new-style lambdas or with partially applied named procedures. compiler/*.m: Conform to the changes in code_info.m. This mostly means using the new argument orders of predicates exported by hlds_pred.m, and using state variable notation. |
||
|
|
8693e293a2 |
This diff makes hlds_pred.m and many callers of its predicates easier to read
Estimated hours taken: 4 Branches: main This diff makes hlds_pred.m and many callers of its predicates easier to read and to maintain, but contains no changes in algorithms whatsoever. compiler/hlds_pred.m: Bring this module into line with our current coding standards. Use predmode declarations, functions, and state variable syntax when appropriate. Reorder arguments of predicates where necessary for the use of state variable syntax, and where this improves readability. Replace old-style lambdas with new-style lambdas or with partially applied named procedures. Standardize indentation. compiler/*.m: Conform to the changes in hlds_pred.m. This mostly means using the new argument orders of predicates exported by hlds_pred.m. Where this is now conveniently possible, change predicates to use state variable notation. In some modules, using state variable notation required changing the orders of arguments in the module's top predicate. compiler/passes_aux.m: Change the order of arguments in the calls this module makes to allow the callees to use state variable notation. Convert this module to state variable notation too. |
||
|
|
599ef915d9 |
Instead of being relied on all over the place, centralize the compiler's
Estimated hours taken: 16 Branches: main Instead of being relied on all over the place, centralize the compiler's knowledge of the names of unify, compare and index predicates in one place, special_pred.m. This should make it easy to change the naming scheme once we switch over to compiler-generated type_ctor_infos for builtin types, which will eliminate the runtime system's knowledge of the naming scheme. compiler/hlds_pred.m: Add a field to pred_infos that says whether the predicate is a unify, compare or index predicate, and if so, for which type constructor. Code that used to test the predicate's name for __Unify__ etc now tests this field instead. Similarly the code that used to employ devious tricks to find out the type the unify/compare/index predicate is for. compiler/rtti.m: Include this field in rtti_proc_labels as well as pred_infos. compiler/make_hlds.m: Fill in this field as appropriate. compiler/proc_label.m: Replace the predicate name with special_pred_id in the proc_labels of unify, index and compare preds. compiler/special_pred.m: Narrow the interface to prevent reliance on the naming scheme for compiler-generated unify, compare and index predicates, except when absolutely necessary, i.e. when creating names for them. Narrow the mechanism required to reverse-engineer the type constructor a unify/compare/index predicate is for from the types to the functionality required by higher_order.m. compiler/code_gen.m: compiler/det_report.m: compiler/higher_order.m: compiler/intermod.m: compiler/layout_out.m: compiler/magic_util.m: compiler/ml_code_util.m: compiler/name_mangle.m: compiler/opt_debug.m: compiler/opt_util.m: compiler/optimize.m: compiler/polymorphism.m: compiler/post_typecheck.m: compiler/proc_label.m: compiler/rl_exprn.m: compiler/rl_key.m: compiler/simplify.m: compiler/termination.m: compiler/typecheck.m: compiler/unify_proc.m: compiler/unused_args.m: Update code and comments to conform to the changes above. compiler/hlds_out.m: Don't refer to the 'type' that a unify, compare or index predicate is for; refer to the type *constructor*. compiler/mlds_to_java.m: Delete an unused predicate. tests/invalid/purity/purity.err_exp: Update this expected output for the change in hlds_out.m. |
||
|
|
6554ef7daa |
Replace "is" with "=".
Estimated hours taken: 2 Branches: main Replace "is" with "=". Add field names where relevant. Replace integers with counters where relevant. |
||
|
|
d63cd1d055 |
Fix test case failures in tests/tabling in asm_fast.gc.mm.
Estimated hours taken: 0.5 Branches: main Fix test case failures in tests/tabling in asm_fast.gc.mm. These were caused by the fact that my recent change to table_gen.m always stored the call table tip variable in proc_infos, not just when debugging was enabled; however we reserved a stack slot for this variable only when debugging was enabled. compiler/code_gen.m: Change the code to avoid relying the call table tip slot in proc_infos being set only when debugging is enabled. compiler/hlds_pred.m: Change the documentation of the slot to allow it to be set even if debugging is not enabled, since this may come in handy in the future. |
||
|
|
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. |
||
|
|
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. |
||
|
|
f7dba9b8f8 |
Change "compiler_generated" in predicate names and field names
Estimated hours taken: 0.5 Branches: main compiler/*.m: Change "compiler_generated" in predicate names and field names to "is_unify_or_compare_pred", because that is the actual meaning of those predicates and fields. Delete the XXXs warning about the old misleading name. |
||
|
|
4954da84cc |
Reduce the dependence of the MLDS backend on the LLDS backend by moving
Estimated hours taken: 2 Branches: main Reduce the dependence of the MLDS backend on the LLDS backend by moving functionality dealing with proc_labels from the LLDS backend (code_util.m) to a new module, proc_label.m, which is part of backend_libs. compiler/code_util.m: compiler/proc_label.m: Move a type and some code from code_util to the new module. Convert predicates to functions as relevant. (The old code was written before functions were available). compiler/backend_libs.m: Add proc_label to the list of submodules. compiler/rtti.m: Rename a function to avoid a name clash with a function in proc_label.m. compiler/*.m: Conform to the changes above. Ensure that all imports of modules in the compiler directory are on lines of their own, to make CVS merges easier. Sort the imports. |
||
|
|
9aeb2516ec |
Avoid dependencies on ll_backend.code_util in *hlds.*.
Estimated hours taken: 1 Branches: main Avoid dependencies on ll_backend.code_util in *hlds.*. compiler/code_util.m: compiler/hlds_pred.m: Move the predicates to identify builtins into hlds_pred.m. compiler/*.m: Update calls and remove unnecessary imports. |
||
|
|
a8ffd3680c |
Change the compiler and tools so that .' and not :' is now used as the
Estimated hours taken: 14 Branches: main Change the compiler and tools so that `.' and not `:' is now used as the module separator in all output. Infix `.' now has associativity yfx and priority 10. NEWS: Report the change. configure.in: Amend the test for an up-to-date Mercury compiler to check whether it recognises `.' as a module qualifier. compiler/code_gen.m: compiler/error_util.m: compiler/hlds_out.m: compiler/prog_out.m: compiler/prog_util.m: compiler/rl_exprn.m: compiler/rl_gen.m: compiler/source_file_map.m: compiler/unused_args.m: library/io.m: library/rtti_implementation.m: library/type_desc.m: runtime/mercury_debug.c: runtime/mercury_deconstruct.c: runtime/mercury_stack_trace.c: Change `:' to `.' as module separator for output. compiler/mercury_to_mercury.m: compiler/prog_io_typeclass.m: As above. Fixed a bug where `.' was not being recognised as a module separator. doc/reference_manual.texi: Report the change. library/term_io.m: Ensure that infix `.' is written without surrounding spaces. tests/hard_coded/dot_separator.m: tests/hard_coded/dot_separator.exp: tests/hard_coded/Mmakefile: Test case added. |
||
|
|
2bef47ce85 |
Extend the information we record about procedures when debugging is enabled
Estimated hours taken: 20
Branches: main (for now, after more testing, on release branch too)
Extend the information we record about procedures when debugging is enabled
to include information about the tabling transformation, if the procedure
in question is tabled. This is useful to developers in debugging the tabling
mechanism, and can be useful to general users by helping them understand the
space (and hence time) costs of tabling.
Add a new mdb command "table" that uses this information to print
programmer-selected subsets of the tables of a tabled procedure.
compiler/hlds_pred.m:
Generalize the existing field in procedures that used to hold
information about I/O tabling to contain information about tabling
in general, including forms other than I/O tabling.
compiler/continuation_info.m:
compiler/code_gen.m:
compiler/stack_layout.m:
Conform to the changes in hlds_pred.m.
compiler/layout.m:
Provide Mercury parallels for the new data structures in
mercury_stack_layout.h.
compiler/layout_out.m:
Generate the new data structures in mercury_stack_layout.h.
compiler/table_gen.m:
Generate the new data structures in hlds_pred.m.
compiler/llds_common.m:
compiler/opt_debug.m:
Conform to the changes in layout.m
compiler/llds_out.m:
Abstract out existing code into a new procedure to make it available
to layout_out.m.
Make tabling pointer variables their natural type.
compiler/modules.m:
Fix an old bug: implicitly import table_builtin.m in .mm grades.
doc/mdb_categories:
doc/user_guide.texi:
Document the new mdb command "table".
runtime/mercury_types.h:
Move some type definitions here from mercury_tabling.h and
mercury_stack_layout.h. This was necessary to avoid problems with
circular #includes, in which a.h #includes b.h to get access to a
definition, but b.h #includes a.h, which is prevented by the macro
guarding against duplicate definition, which causes syntax errors
in the rest of b.h because the rest of b.h depends on typedefs in
a.h that occur in a.h *after* the #include of b.h.
runtime/mercury_label.h:
Adjust the list of #includes after the change to mercury_types.h.
runtime/mercury_stack_layout.h:
Extend the debugging data structures with constructs that describe
the call tables, answer tables and answer blocks of tabled procedures.
Delete typedefs that are now in mercury_types.h.
runtime/mercury_tabling.[ch]:
Add new functions to allow lookups without insertions in hash tables
containing ints, floats and strings.
Add new functions to return the entire contents of these hash tables.
Change to four-space indentation where this wasn't done previously.
runtime/mercury_grade.h:
Increment the binary compatbility version number, partially to
account for the change to mercury_stack_layout.h in this diff, but
mostly to account for all the other diffs to mercury_stack_layout.h
since the last released version.
trace/mercury_trace_tables.[ch]:
Rename MR_print_proc_id_for_debugger as MR_print_proc_id_and_nl,
since this better describes what the function does.
trace/mercury_trace_util.[ch]:
Add a new function MR_trace_is_integer that reads in signed integers.
Rename MR_trace_is_number as MR_trace_is_natural_number, since the
former would now be ambiguous.
Add a new function MR_trace_is_float that reads in floating point
values.
library/string.m:
Document that MR_trace_is_float uses the same logic as
MR_trace_is_float.
trace/mercury_trace_browse.c:
trace/mercury_trace_vars.c:
Update calls to MR_trace_is_number.
trace/mercury_trace_internal.c:
Implement the new mdb command "table".
Update calls to MR_trace_is_number and to
MR_print_proc_id_for_debugger.
tests/debugger/print_table.{m,inp,exp}:
New test case to test the new mdb command.
tests/debugger/Mmakefile:
Enable the new test case.
Disable the sensitive test cases in .mm grades.
tests/debugger/completion.exp:
Update the expected output to include the new mdb command.
tests/debugger/mdb_command_test.inp:
Update this automatically generated file to include the new mdb
command.
|
||
|
|
d869c5505b |
Hide the events associated with the goals inserted by tabling transformations,
Estimated hours taken: 2 Branches: main Hide the events associated with the goals inserted by tabling transformations, since ordinary programmers shouldn't be exposed to the details of the transformation. (A later diff will adjust the goal paths of the events associated with the original code back to what they would have been without the transformation.) Add a new mdb command, unhide_events, that allows the programmer to expose hidden events. This is intended for implementors only. compiler/hlds_goal.m: Add a new goal feature, hide_debug_event. If a nonatomic goal has this feature, then the associated trace events will be hidden. compiler/trace.m: Respect the new goal feature. compiler/table_gen.m: Add the new goal feature to the compound goals created by tabling transformations. compiler/code_gen.m: compiler/dense_switch.m: compiler/disj_gen.m: compiler/ite_gen.m: compiler/string_switch.m: compiler/switch_gen.m: compiler/tag_switch.m: Pass the required goal_info to trace.m, to allow it to hide events as required. runtime/mercury_trace_base.[ch]: Add two global boolean variables. One says whether we are exposing hidden events, the other says whether we have ever exposed hidden events. trace/mercury_trace.c: Hide hidden events, unless the programmer has asked for them to be exposed. trace/mercury_trace_internal.c: Implement the unhide_events command. Make "dd" check whether we have ever exposed hidden events. Fix some unclear code in "print_optionals". doc/user_guide.texi: Doument the unhide_events command. doc/mdb_categories: Mention the unhide_events command. tests/debugger/mdb_command_test.inp: Test the documentation of the unhide_events command. |
||
|
|
d531fc48d5 |
Fix a bug that prevented the tools/extract_incr_sp script from working.
Estimated hours taken: 0.1 Branches: main Fix a bug that prevented the tools/extract_incr_sp script from working. compiler/code_gen.m: Add a missing space in the comments attached to incr_sp operations. library/builtin.m: Add a missing pred/func indication to the comment of an incr_sp operation. |
||
|
|
ed83fe4623 |
Optimize shallow traced modules by not adding calls to MR_trace to shallow
Estimated hours taken: 12
Branches: main
Optimize shallow traced modules by not adding calls to MR_trace to shallow
traced procedures which cannot be called from a deep traced environment.
A shallow traced procedure can be optimized in this way if it is neither
exported from its defining module nor has its address taken.
The main purpose of this optimization is not the avoidance of the cost of the
MR_trace calls as much as it is the restoration of tail recursion optimization.
Previously, compiling a program in a debug grade would disable all tail
recursion in the program (since debug grades require at least shallow tracing
every module). This was a problem because it limited the sizes of the inputs
the debugged program could process before running out of memory. As long as
the procedures that recurse on the input are in the implementation section
of a shallow traced module, this should no longer happen.
compiler/trace_params.m:
Introduce the concept of a procedure's effective trace level. This is
identical to the global trace level, except if the procedure is not
exported and doesn't have its address taken, and the global trace level
is shallow. In that case, we say that the procedure's effective trace
level is none.
Computing a procedure's effective trace level requires its proc_info
and its parent pred_info, so require callers to supply these as
parameters.
compiler/code_info.m:
Store the current pred_info as well as the current proc_info, for
trace parameter lookups.
compiler/continuation_info.m:
compiler/code_gen.m:
Record the required trace parameters of a procedure in its layout
structure, since it can no longer be computed from the global trace
level.
compiler/stack_layout.m:
Use the trace parameters in procedures' layout structures, instead of
trying to compute them from the global trace level.
compiler/inlining.m:
compiler/liveness.m:
compiler/stack_alloc.m:
compiler/store_alloc.m:
compiler/trace.m:
Use procedures' effective trace level instead of the global trace level
where relevant.
compiler/llds.m:
Record the required trace parameter of a procedure in its c_procedure
representation, since it can no longer be computed from the global
trace level.
Delete an obsolete field.
compiler/optimize.m:
compiler/jumpopt.m:
Use a required trace parameter of a procedure in its c_procedure
representation, since it can no longer be computed from the global
trace level.
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/llds_out.m:
compiler/mercury_compile.m:
Trivial changes to conform to updated interfaces.
compiler/stack_opt.m:
Use the option opt_no_return_calls, instead of approximating it
with the trace level. (The old code was a holdover from before the
creation of the option.)
tests/debugger/shallow.m:
tests/debugger/shallow2.m:
tests/debugger/shallow.{inp,exp*}:
Divide the old test case in shallow.m in two. The top level predicates
stay in shallow.m and continue to be shallow traced. The two bottom
predicates move to shallow2.m and are now deep traced.
The new test input checks whether the debugger can walk across the
stack frames of procedures in shallow traced modules whose effective
trace level is "none" (such as queen/2).
|
||
|
|
d6fbaa2161 |
Add two pieces of information that will be needed to an upcoming change
Estimated hours taken: 2 Branches: main Add two pieces of information that will be needed to an upcoming change to the representation of procedure bodies in the declarative debugger. The first piece is the full list of head vars. This is needed now because the debugger no longer ignores variables of type type_info, and thus the Nth headvar is no longer guaranteed to be variable number N. The second piece is a cut/no_cut indicator in `some' goals. This is needed to allow us to reconstruct goal paths exactly as we traverse goal representations. browser/program_representation.m: Make the two data structure changes described above. browser/*.m: Trivial changes to conform to the new data structures. compiler/prog_rep.m: Create the updated data procedure representation. compiler/*.m: Record and transmit the information needed by the updated procedure representation. runtime/mercury_stack_layout.h: Update the documentation of the relevant field in proc_layouts. |
||
|
|
189b9215ae |
This diff implements stack slot optimization for the LLDS back end based on
Estimated hours taken: 400
Branches: main
This diff implements stack slot optimization for the LLDS back end based on
the idea that after a unification such as A = f(B, C, D), saving the
variable A on the stack indirectly also saves the values of B, C and D.
Figuring out what subset of {B,C,D} to access via A and what subset to access
via their own stack slots is a tricky optimization problem. The algorithm we
use to solve it is described in the paper "Using the heap to eliminate stack
accesses" by Zoltan Somogyi and Peter Stuckey, available in ~zs/rep/stackslot.
That paper also describes (and has examples of) the source-to-source
transformation that implements the optimization.
The optimization needs to know what variables are flushed at call sites
and at program points that establish resume points (e.g. entries to
disjunctions and if-then-elses). We already had code to compute this
information in live_vars.m, but this code was being invoked too late.
This diff modifies live_vars.m to allow it to be invoked both by the stack
slot optimization transformation and by the code generator, and allows its
function to be tailored to the requirements of each invocation.
The information computed by live_vars.m is specific to the LLDS back end,
since the MLDS back ends do not (yet) have the same control over stack
frame layout. We therefore store this information in a new back end specific
field in goal_infos. For uniformity, we make all the other existing back end
specific fields in goal_infos, as well as the similarly back end specific
store map field of goal_exprs, subfields of this new field. This happens
to significantly reduce the sizes of goal_infos.
To allow a more meaningful comparison of the gains produced by the new
optimization, do not save any variables across erroneous calls even if
the new optimization is not enabled.
compiler/stack_opt.m:
New module containing the code that performs the transformation
to optimize stack slot usage.
compiler/matching.m:
New module containing an algorithm for maximal matching in bipartite
graphs, specialized for the graphs needed by stack_opt.m.
compiler/mercury_compile.m:
Invoke the new optimization if the options ask for it.
compiler/stack_alloc.m:
New module containing code that is shared between the old,
non-optimizing stack slot allocation system and the new, optimizing
stack slot allocation system, and the code for actually allocating
stack slots in the absence of optimization.
Live_vars.m used to have two tasks: find out what variables need to be
saved on the stack, and allocating those variables to stack slots.
Live_vars.m now does only the first task; stack_alloc.m now does
the second, using code that used to be in live_vars.m.
compiler/trace_params:
Add a new function to test the trace level, which returns yes if we
want to preserve the values of the input headvars.
compiler/notes/compiler_design.html:
Document the new modules (as well as trace_params.m, which wasn't
documented earlier).
compiler/live_vars.m:
Delete the code that is now in stack_alloc.m and graph_colour.m.
Separate out the kinds of stack uses due to nondeterminism: the stack
slots used by nondet calls, and the stack slots used by resumption
points, in order to allow the reuse of stack slots used by resumption
points after execution has left their scope. This should allow the
same stack slots to be used by different variables in the resumption
point at the start of an else branch and nondet calls in the then
branch, since the resumption point of the else branch is not in effect
when the then branch is executed.
If the new option --opt-no-return-calls is set, then say that we do not
need to save any values across erroneous calls.
Use type classes to allow the information generated by this module
to be recorded in the way required by its invoker.
Package up the data structures being passed around readonly into a
single tuple.
compiler/store_alloc.m:
Allow this module to be invoked by stack_opt.m without invoking the
follow_vars transformation, since applying follow_vars before the form
of the HLDS code is otherwise final can be a pessimization.
Make the module_info a part of the record containing the readonly data
passed around during the traversal.
compiler/common.m:
Do not delete or move around unifications created by stack_opt.m.
compiler/call_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/var_locn.m:
Allow the code generator to delete its last record of the location
of a value when generating code to make an erroneous call, if the new
--opt-no-return-calls option is set.
compiler/code_gen.m:
Use a more useful algorithm to create the messages/comments that
we put into incr_sp instructions, e.g. by distinguishing between
predicates and functions. This is to allow the new scripts in the
tool directory to gather statistics about the effect of the
optimization on stack frame sizes.
library/exception.m:
Make a hand-written incr_sp follow the new pattern.
compiler/arg_info.m:
Add predicates to figure out the set of input, output and unused
arguments of a procedure in several different circumstances.
Previously, variants of these predicates were repeated in several
places.
compiler/goal_util.m:
Export some previously private utility predicates.
compiler/handle_options.m:
Turn off stack slot optimizations when debugging, unless
--trace-optimized is set.
Add a new dump format useful for debugging --optimize-saved-vars.
compiler/hlds_llds.m:
New module for handling all the stuff specific to the LLDS back end
in HLDS goal_infos.
compiler/hlds_goal.m:
Move all the relevant stuff into the new back end specific field
in goal_infos.
compiler/notes/allocation.html:
Update the documentation of store maps to reflect their movement
into a subfield of goal_infos.
compiler/*.m:
Minor changes to accomodate the placement of all back end specific
information about goals from goal_exprs and individual fields of
goal_infos into a new field in goal_infos that gathers together
all back end specific information.
compiler/use_local_vars.m:
Look for sequences in which several instructions use a fake register
or stack slot as a base register pointing to a cell, and make those
instructions use a local variable instead.
Without this, a key assumption of the stack slot optimization,
that accessing a field in a cell costs only one load or store
instruction, would be much less likely to be true. (With this
optimization, the assumption will be false only if the C compiler's
code generator runs out of registers in a basic block, which for
the code we generate should be unlikely even on x86s.)
compiler/options.m:
Make the old option --optimize-saved-vars ask for both the old stack
slot optimization (implemented by saved_vars.m) that only eliminates
the storing of constants in stack slots, and the new optimization.
Add two new options --optimize-saved-vars-{const,cell} to turn on
the two optimizations separately.
Add a bunch of options to specify the parameters of the new
optimizations, both in stack_opt.m and use_local_vars.m. These are
for implementors only; they are deliberately not documented.
Add a new option, --opt-no-return-cells, that governs whether we avoid
saving variables on the stack at calls that cannot return, either by
succeeding or by failing. This is for implementors only, and thus
deliberately documented only in comments. It is enabled by default.
compiler/optimize.m:
Transmit the value of a new option to use_local_vars.m.
doc/user_guide.texi:
Update the documentation of --optimize-saved-vars.
library/tree234.m:
Undo a previous change of mine that effectively applied this
optimization by hand. That change complicated the code, and now
the compiler can do the optimization automatically.
tools/extract_incr_sp:
A new script for extracting stack frame sizes and messages from
stack increment operations in the C code for LLDS grades.
tools/frame_sizes:
A new script that uses extract_incr_sp to extract information about
stack frame sizes from the C files saved from a stage 2 directory
by makebatch and summarizes the resulting information.
tools/avg_frame_size:
A new script that computes average stack frame sizes from the files
created by frame_sizes.
tools/compare_frame_sizes:
A new script that compares the stack frame size information
extracted from two different stage 2 directories by frame_sizes,
reporting on both average stack frame sizes and on specific procedures
that have different stack frame sizes in the two versions.
|
||
|
|
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. |
||
|
|
13f0e7610a |
A large step towards declarative debugging of goals that do I/O.
Estimated hours taken: 40
Branches: main
A large step towards declarative debugging of goals that do I/O. This step
does everything needed for that except modify the declarative debugger itself;
that is for Mark to do.
If you give the new option --trace-table-io-decl, the transformation performed
by the compiler on I/O primitives will preserve not just the output arguments
of the primitive, so that the primitive can be "reexecuted" without performing
any side-effects, but also the input arguments and the identity of the I/O
primitive itself. The I/O table therefore will contain a list of the I/O
primitives executed by the program after I/O tabling is started.
You can test this via the new debugger commands "print action <action-number>"
and "browse action <action-number>".
The new option is currently not documented, because the declarative debugger
does not yet use the information it provides. The new debugger commands are
not documented because they are meant only for implementors, at least for
now.
Since this change adds a field to proc_layout structures, any workspaces
compiled with debugging enabled will need to do a cvs update when this change
is installed.
compiler/options.m:
Add the option --trace-table-io-decl. When set, this causes the
compiler to transform I/O action primitives to allow declarative
debugging of I/O actions.
compiler/handle_options.m:
Make --trace-table-io-decl imply --trace-table-io.
compiler/table_gen.m:
Perform the transformation, which is similar to the existing
--trace-table-io transformation, but preserves the identity of all
non-io-state arguments (not just the outputs) and the identity
of the I/O primitive itself.
Provide better names for variables generated by tabling
transformations.
compiler/hlds_goal.m:
Add extra parameters to procedures whose job it is to create new
goals to name the variables in those goals.
compiler/layout.m:
Add a new layout structure to contain the information the runtime
system needs to interpret the information saved by the new
transformation.
compiler/layout_out.m:
Output the new layout structure.
compiler/continuation_info.m:
Add a field to proc_layouts to point to the declarative I/O tabling
structure, and another to identify the proc_layout without using LLDS
types.
compiler/code_gen.m:
Provide the definition of this field when appropriate.
compiler/hlds_pred.m:
Add a field to proc_infos to store the information from the tabling
transformation until code generation.
compiler/stack_layout.m:
Add a mechanism for transforming the high level description of I/O
action tabling data in proc_infos to the low level description we need
to generate C data structures.
compiler/hlds_data.m:
Add a new cons_id and a new cons_tag; they are used to refer to I/O
tabling structures in code generated by the new transformation.
compiler/*.m:
Handle the updates to global data types above.
library/table_builtin.m:
Modernize some old code.
Fix an old off-by-one error: make I/O tabling use the first slot
in the I/O action table.
library/varset.m:
Add a mechanism for creating a variable that is named iff the caller
has a name for it.
runtime/mercury_layout_util.[ch]:
Add a function for materializing type parameters from an answer block,
not from registers or a closure.
runtime/mercury_stack_layout.h:
Declare a C type for the data structure holding information about
I/O primitives transformed by --trace-table-io-decl, and add a field
to proc_layout structures to point to these new structures.
Add a new evaluation method for --trace-table-io-decl.
runtime/mercury_tabling_macros.h:
Add some conditionally-compiled debugging code to the primitive for
saving answers.
trace/mercury_trace_vars.[ch]:
Add functions for printing I/O action goals.
trace/mercury_trace_internal.c:
Add code for recognizing and implementing commands to print I/O
action goals.
trace/mercury_trace.c:
Add code for handling the new eval method.
tests/debugger/tabled_read.{m,inp,exp*}:
Add a polymorphic I/O action primitive, add calls to it, and test
the printing of both monomorphic and polymorphic action goals.
tests/debugger/tabled_read_decl.{m,inp,exp*,data}:
A new test case. It does the same things as the new version of
tabled_read, but it is compiled with --trace-table-io-decl, not
just --trace-table-io. It therefore can (and does) test the printing
of tabled I/O actions.
tests/debugger/Mmakefile:
Add the new test case.
|
||
|
|
b7c4a317e9 |
Add MR_ prefixes to the remaining non-prefixed symbols.
Estimated hours taken: 4 Branches: main Add MR_ prefixes to the remaining non-prefixed symbols. This change will require all workspaces to be updated The compiler will start generating references to MR_TRUE, MR_bool, etc., which are not defined in the old runtime header files. runtime/mercury_std.h: Add MR_ prefixes to bool, TRUE, FALSE, max, min, streq, strdiff, strtest, strntest, strneq, strndiff, strntest, NO_RETURN. Delete a commented out definition of `reg'. runtime/mercury_tags.h: Add an MR_ prefix to TAGBITS. configure.in: runtime/mercury_goto.h: runtime/machdeps/i386_regs.h/mercury_goto.h: Add an MR_ prefix to PIC. runtime/mercury_conf_param.h: Allow non-prefixed PIC and HIGHTAGS to be defined on the command line. runtime/mercury_bootstrap.h: Add backwards compatibility definitions. RESERVED_MACRO_NAMES: Remove the renamed macros. compiler/export.m: compiler/ml_code_gen.m: Use MR_bool rather than MR_Bool (MR_Bool is meant to be for references to the Mercury type bool__bool). runtime/mercury_types.h: Add a comment the MR_Bool is for references to bool__bool. */*.c: */*.h: */*.m: Add MR_ prefixes. |
||
|
|
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. |
||
|
|
1c65d003f7 |
Add the shorthand_goal_expr wrapper type to ease hlds->hlds transformations.
Estimated hours taken: 4.5
Branches: main
Add the shorthand_goal_expr wrapper type to ease hlds->hlds transformations.
compiler/hlds_goal.m
Create a new type, the `shorthand_goal_expr', for goals kinds that
are implemented by a (ordinary_hlds + shorthand) -> (ordinary_hlds)
transformation. At present, bi_implication is the only kind of
of goal that is implemented in this way.
Moved bi_implication functor from the type goal_expr to the new
shorthand_goal_expr type.
Added the functor shorthand to the goal_expr type.
compiler/*.m
Change switches on hlds_goal_expr that call error when they recognise
`bi_implication' from calling error when they recognise
`bi_implication' to calling error when they recognise `shorthand'.
For all predicates K that
a) switch on hlds_goal_expr and
b) perform non-trivial processing when they recognise
`bi_implication'
change K such that it now calls K_shorthand upon recognising the
functor `shorthand'. Define K_shorthand to switch on
shorthand_goal_expr, where the code for the `bi_implication' case
formerly contained in K is now contained in K_shorthand.
|
||
|
|
711da78188 |
Rename foreign_code as foreign_proc where appropriate in the compiler.
Estimated hours taken: 4.0 Branches: main Rename foreign_code as foreign_proc where appropriate in the compiler. The rationale for this change is that it makes maintaining the code much simpler because it is clear whether `foreign' refers to a slab of code (foreign_code) or a procedure (foreign_proc). :- type pragma_foreign_code_attributes :- type pragma_foreign_proc_attributes The functors for pragma_type foreign(Lang, BodyCode) foreign(Attributes, Name, PredOrFunc, Vars, Varset, Impl) become foreign_code(Lang, BodyCode) foreign_proc(Attributes, Name, PredOrFunc, Vars, Varset, Impl) And the HLDS goal `pragma_foreign_code' becomes `foreign_proc'. compiler/*.m: Update the compiler to use the new names. |
||
|
|
0921310ca5 |
More work on the bytecode interpreter.
With these changes, it now passes all tests/general/* test cases
except those with floats.
Changes to the compiler:
- Added extra argument to test instruction (string comparisons were
being treated as integer comparisons; properly deals with different
atomic type unifications now)
- Changed bytecode stub functions
Changes to the bytecode interpreter:
- Cleaned up comments
- Forked part of mb_machine to mb_exec
- Added support for submodules
- Added support for nondet procedures
- Added support for cc_xxx procedures
- Finished higher order calls
- Added (very basic) debug interface
- Added support for type information
- Added memory corruption checking
- Changed machine state dump formatting
- Fixed bug in nested switches
- Resolved builtin__unify and builtin_compare failures
- Modified bytecode tags generation so .c & .m tag files are separate
- Header usage rationalised
Changes to test suite:
- Added test cases for the bytecode interpreter.
- More work on the bytecode interpreter.
bytecode/Mmakefile:
Modified bytecode tags generation so .c & .m tag files are separate.
mb_machine split into mb_exec.
test file renamed to simple.m (copy over tests/simple??.m to test).
bytecode/TODO:
Updated.
bytecode/mb_basetypes.h:
Removed redundant MB_WORD_BITS (use MR_WORDBITS instead).
bytecode/mb_bytecode.h:
bytecode/mpb_bytecode.c:
Formatting changes
Third test instruction argument added.
bytecode/mb_disasm.h:
bytecode/mb_disasm.c:
Formatting changes.
Third test instruction argument added.
Added MB_FMT_INTWIDE.
bytecode/mb_exec.h:
bytecode/mb_exec.c:
bytecode/mb_machine.h:
bytecode/mb_machine.c:
mb_machine* split into mb_exec* and mb_machine*.
Almost all instructions now work (see important changes above).
bytecode/mb_interface.h:
bytecode/mb_interface.c:
Added nondet stub functions.
Added functions to lookup builtin compiler procedures:
do_redo, do_fail, __unify, __compare.
Removed old debugging code.
Stack layout changed to support nondet procedures.
bytecode/mb_interface_stub.c:
bytecode/mb_interface_stub.h:
Split off bare minimum of includes for bytecode stubs.
Added nondet stubs.
bytecode/mb_machine_show.c:
Made code cleaner (added subfunctions for MB_show_state).
Added variable names to machine state dump.
bytecode/mb_mem.h:
bytecode/mb_mem.c:
Added limited memory corruption checking.
bytecode/mb_module.h:
bytecode/mb_module.c:
Swapped order of temps & vars on stack.
Fixed nested switches causing random crashes.
Added nested module support.
bytecode/test/simple??.m:
Various test files - just to check that it doesn't crash.
(Most do not output anything & must be verified by stepping through
manually).
compiler/bytecode.m:
compiler/bytecode_gen.m:
Added extra argument to test instruction (otherwise
string comparisons would be treated as integer comparisons).
compiler/code_gen.m:
Changed call structure name in bytecode stub to resolve
issues with illegal characters in C structure names.
Changed bytecode stub header file name.
|
||
|
|
cfd7bd279a |
Changed code generator to output bytecode stubs as needed
Estimated hours taken: 4
Changed code generator to output bytecode stubs as needed
Will not output stubs for compiler generated procedures
or for procedures with foreign code
bytecode/code_gen.m:
Changed code generator to output bytecode call stub if
procedure contains no foreign code and procedure was
not automatically generated by the compiler
bytecode/hlds_util.m:
Added predicates to determine if a goal tree contains
any foreign code.
bytecode/llds_out.m:
Added a #include to modules generating bytecode
|
||
|
|
2498d9d3fd |
Instead of generating the layout structures of labels, procs and modules
Estimated hours taken: 36 Instead of generating the layout structures of labels, procs and modules as rvals, generate them almost entirely as C structures. This will make future modifications much easier, since mismatches between what the runtime expects and what the compiler generates will now be pointed out by the C compiler. (It also reduces the size of the C source files generated with debugging enabled by about 5%.) Layout structures contain a few components that are not well-typed in C; we continue to generate these as rvals. Closure layout structures used to have a well-typed part and a non-well-typed part. We now generate the well-typed part as a separate structure, pointed to from the other. We also extend the well-typed part, so that instead of just giving the name the called procedure, it also identifies the source location where the closure was constructed. This could be useful for the debugger and for deep profiling. This diff also includes a change to get the compiler to bootstrap with lcc in grade none.gc.debug.tr: initializing the string tables in module layouts not as a string but as an array of characters. runtime/mercury_stack_layout.h: Reorganize the definitions of layout structures. Rename Stack_Layout_Entry structures as Proc_Layout structures, and Stack_Layout_Label structures as Label_Layout structures. (The debugger paper refers to the structures by the new names.) Fold the Stack_Layout_Vars structure into the structure that contains it, the Label_Layout structure. Add a Closure_Id structure that contains a Proc_Id structure as well as extra information identifying the source location where the closure was created. Create "short" versions of the Proc_Layout structures, which contain only the first one or two of the three groups of fields. Previously, the Mercury compiler would define new C types when it generated such short structures. Since we are not defining new C types anymore, there must be a C type for every kind of structure the Mercury compiler can generate. We now also have separate variants for the layouts of user-defined and compiler-generated procedures, since the format of their procedure id information is different. While the runtime system refers to their procedure id information through a union, the C types of the structures generated by the Mercury compiler do not use a union, since a union cannot be initialized through its second member. Make the constant fields of structures const, since we now generate values of those structure types, and initialize them with constant data. Move the documentation of layout structures here from stack_layout.m. runtime/mercury_ho_call.h: Instead of bodily including an MR_Proc_Id structure in closures, include a pointer to the more detailed MR_Closure_Id structure. runtime/mercury_accurate_gc.c: runtime/mercury_agc_debug.c: runtime/mercury_init.h: runtime/mercury_label.[ch]: runtime/mercury_layout_util.[ch]: Minor updates to conform to changes in mercury_stack_layout.h. runtime/mercury_goto.h: Use separate naming schemes for label layout structures and proc layout structures. library/exception.m: Minor updates to conform to changes in mercury_stack_layout.h. compiler/layout.m: A new module that defines data structures for label, proc and module layout structures and for closure id structures. compiler/layout_out.m: A new module that converts the Mercury data structures of layout.m into declarations and definitions of C data structures. compiler/stack_layout.m: Generate the new layout structures instead of rvals. Move the documentation of layout structures from here to runtime/mercury_stack_layout.h, since this module is no longer aware of some of their details. compiler/llds.m: Make layout structures a separate kind of compiler-generated data. compiler/llds_out.m: Remove the code for the output of layout structures; call layout_out.m instead. compiler/llds_out.m: compiler/rtti_out.m: Turn some predicates into functions. compiler/code_gen.m: compiler/code_info.m: compiler/llds.m: compiler/mercury_compile.m: compiler/unify_gen.m: Instead of handling closure layouts like other static data, handle them separately. Add a counter to the code_info structure in order to allow closure id structures to be identified uniquely by a pair consisting of the id of the procedure that generates them and a closure sequence number within that procedure. compiler/llds_common.m: Look for common rvals among the rvals in layout structures. compiler/opt_debug.m: Generate developer-friendly names for layout structure references. browser/dl.m: Update the code for constructing closure layouts. |
||
|
|
8ba2487901 |
Fix a bug in my previous change: it was generating duplicate label names.
Estimated hours taken: 0.5 compiler/code_gen.m: Fix a bug in my previous change: it was generating duplicate label names. |
||
|
|
b782090418 |
Fix a bug reported by Warwick Harvey: the code that we
Estimated hours taken: 2 compiler/code_gen.m: Fix a bug reported by Warwick Harvey: the code that we generated for procedures compiled with `--trace shallow' was allocating ticket counters conditionally (iff MR_trace_from_full was true on entry), but was deallocating them unconditionally. The fix was to only deallocate them if they were allocated. |
||
|
|
4be69fa961 |
Eliminated a lot of the dependencies on the the `code_model' type,
Estimated hours taken: 6 Eliminated a lot of the dependencies on the the `code_model' type, and move that type from llds.m into a new module `code_model'. The aim of this change is to improve the modularity of the compiler by reducing the number of places in the compiler front-end that depend on back-end concepts and the number of places in the MLDS back-end which depend on the LLDS. compiler/code_model.m: New module. Contains the code_model type and associated procedures. compiler/llds.m: Move the code_model type into code_model.m. compiler/hlds_goal.m: Move the goal_info_get_code_model procedure into code_model.m, to avoid having the HLDS modules import code_model. compiler/hlds_out.m: Delete `hlds_out__write_code_model', since it wasn't being used. compiler/hlds_pred.m: Move the proc_info_interface_code_model procedure into code_model.m, to avoid having the HLDS modules import code_model. compiler/goal_path.m: When computing the `maybe_cut' field for `some' goals, compute it by comparing the determinism rather than by comparing the goal_infos. compiler/unique_modes.m: Use determinism and test for soln_count = at_most_many rather than using code_model and testing for model_non. compiler/inlining.m: Test for determinism nondet/multi rather than testing for code_model model_non. compiler/hlds_pred.m: compiler/det_report.m: Change valid_code_model_for_eval_method, which succeeded unless the eval_method was minimal_model and the code_model was model_det, to valid_determinism_for_eval_method, which succeeds unless the eval_method is minimal_model and the determinism cannot fail. As well as avoiding a dependency on code_model in the HLDS modules, this also fixes a bug where det_report could give misleading error messages, saying that `multi' was a valid determinism for `minimal_model' predicates, when in fact the compiler will always report a determinism error if you declare a `minimal_model' predicate with determinism `multi'. (Actually the code in which this bug occurs is in fact unreachable, but this is no doubt also a bug... I'll address that one in a separate change.) compiler/lookup_switch.m: Simplify the code a bit by using globals__lookup_*_option rather than globals__get_option and then getopt__lookup_option. compiler/*.m: Add `import_module' declarations for `code_model', and in some cases remove `import_module' declarations for `llds'. |
||
|
|
477ecb18f6 |
Implement pragma foreign_code for Managed C++.
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. |
||
|
|
82378c381b |
Allow polymorphic ground insts. This change assumes that all inst
Estimated hours taken: 80 Allow polymorphic ground insts. This change assumes that all inst parameters in the mode declaration for a predicate or function are constrained to be ground-shared. This is a temporary measure until we work out a nice syntax to allow the programmer to tell the compiler that certain inst parameters may be treated as ground insts. Since we don't currently support unconstrained inst parameters anyway, this shouldn't cause a problem. TODO: - Add syntax, something like `:- mode p(in(I)) <= ground(I).', to specify that an inst parameter represents a ground inst. - Allow abstract ground insts that are treated in a similar way to what we've done here with ground inst parameters. - Make mode checking more efficient (i.e. rewrite the mode system). compiler/inst.m: Add a new alternative for ground insts: `constrained_inst_var(inst_var)'. Define the type `inst_var_sub'. compiler/inst_match.m: Change inst_matches_initial so that it: - handles constrained_inst_vars correctly; - returns the inst_var substitutions necessary for the call; - handles inst_matches_initial(ground(...), bound(...), ...) properly (this requires knowing the type of the variable). The last change has also been made for inst_matches_final and inst_matches_binding. However, the check is disabled for now because, without alias tracking, the mode checker becomes too conservative. compiler/hlds_pred.m: compiler/mode_info.m: compiler/simplify.m: compiler/det_util.m: Include the inst_varset in the proc_info, mode_info and simplify_info. Add a vartypes field to the det_info. Remove the vartypes field from the simplify_info since it is now in the det_info. Use record syntax for these data structures and their access predicates to make future changes easier. compiler/prog_io.m: When processing pred and func mode declarations, convert all inst_var(V) insts to ground(shared, constrained_inst_var(V)). compiler/prog_data.m: compiler/hlds_data.m: compiler/make_hlds.m: compiler/mode_util.m: Use inst_vars instead of inst_params. compiler/modes.m: compiler/modecheck_call.m: compiler/unique_modes.m: compiler/mode_util.m: When checking or recomputing initial insts of a call, build up an inst_var substitution (using the modified inst_matches_initial) and apply this to the final insts of the called procedure before checking/recomputing them. compiler/mode_util.m: Make sure that recompute_instmap_delta recomputes the instmap_deltas for lambda_goals even when RecomputeAtomic = no. compiler/type_util.m: Add a new predicate, type_util__cons_id_arg_types which nondeterministically returns the cons_ids and argument types for a given type. Add a new predicate type_util__get_consid_non_existential_arg_types which is the same as type_util__get_existential_arg_types except that it fails rather than aborting for existenially typed arguments. compiler/accumulator.m: compiler/check_typeclass.m: compiler/clause_to_proc.m: compiler/common.m: compiler/continuation_info.m: compiler/deforest.m: compiler/det_analysis.m: compiler/det_report.m: compiler/det_util.m: compiler/dnf.m: compiler/follow_code.m: compiler/goal_store.m: compiler/goal_util.m: compiler/higher_order.m: compiler/inst_util.m: compiler/instmap.m: compiler/lambda.m: compiler/magic.m: compiler/magic_util.m: compiler/mercury_to_mercury.m: compiler/modecheck_unify.m: compiler/module_qual.m: compiler/pd_info.m: compiler/pd_util.m: compiler/polymorphism.m: compiler/post_typecheck.m: compiler/prog_io_util.m: compiler/prog_rep.m: compiler/saved_vars.m: compiler/stack_layout.m: compiler/table_gen.m: compiler/unify_proc.m: compiler/unneeded_code.m: compiler/unused_args.m: Pass inst_varsets and types where needed. Changes to reflect change in definition of the inst data type. compiler/inlining.m: Recompute the instmap deltas for a procedure after inlining. This bug showed up compiling tests/hard_coded/lp.m with inlining and deforestation turned on: deforestation was getting incorrect instmap deltas from inlining, causing the transformation to break mode-correctness. It has only just shown up because of the added call to `inst_matches_initial' from within `recompute_instmap_delta'. tests/invalid/Mmakefile: tests/invalid/unbound_inst_var.m: tests/invalid/unbound_inst_var.err_exp: tests/valid/Mmakefile: tests/valid/unbound_inst_var.m: Move the `unbound_inst_var' test case from `invalid' to `valid' and extend its coverage a bit. |
||
|
|
fdccd65e30 |
The debugger's retry command at the moment works only from a final port for
Estimated hours taken: 60
The debugger's retry command at the moment works only from a final port for
the call to be retried, the reason being that the RTTI does not have the
information required to make sure that the state of the stacks is reset
correctly. If you invoke retry from a non-final port, the current
implementation skips forward to a final port and then does the retry;
this does not work if you get a core dump or a infinite loop during the forward
skip. This change adds the required info to the RTTI and thus enables
direct retries from the middle of calls.
The information added has two components. First, if a procedure that lives on
the nondet stack allocates any temporary nondet stack frames, then it must
record the old value of maxfr in a stack slot so that retry can restore it.
Second, if a procedure is tabled, then it must record the call table tip node
corresponding to the actual input arguments, so we can reset this node to
uninitialized (if we don't, then the retried call will find the active call
marker and report an infinite loop error).
The support for retries across minimal model calls is not finished yet.
Finding out what the right thing to do in such cases is a research project,
one that cannot even be started until minimal model tabling works reliably
in the *absence* of retries. However, such retries do grossly wrong things
at the moment; this change is a definite improvement. It attempts to perform
the retry from the fail port, since that is the only time when the minimal
model tabling data structures are quiescent. The "fail" command I added to
the debugger command set to let this be done is not complete yet and is
therefore undocumented; the problem is that a call to a model_non predicate
in a committed choice context will not get to the fail port. I added goal paths
to return layouts so that we will eventually be able to tell when execution
leaves a committed choice context surrounding an ancestor of a model_non
predicate call, but this functionality is not yet implemented.
compiler/stack_layout.m:
Generate the three new fields: the evaluation method, (maybe) the id
of the stack slot containing the saved value of maxfr, and (maybe)
the id of the stack slot containing the call table tip.
compiler/continuation_info.m:
Record the information about the new fields for later use by
stack_layout.m.
Add a new field to record the goal path of calls for their return
layouts.
Fix a screwed comment for the continuation_info data structure.
compiler/llds.m:
Add a new field to call() instructions to hold the goal path of the
call.
Add a utility function for use by trace.m.
compiler/call_gen.m:
Fill in this new field.
compiler/trace.m:
compiler/live_vars.m:
Reserve the fixed stack slot for the saved maxfr if necessary,
and if the call table tip node is needed, make sure that the variable
holding its address is allocated a low-numbered stack slot (otherwise,
its number may not fit into the MR_int_least8_t field in the
proc_layout).
compiler/trace.m:
If necessary, fill in the saved maxfr slot.
If necessary, initialize the call table tip slot.
compiler/hlds_goal.m:
Add a goal feature which marks its goal as defining the variable
representing the call table tip node.
Add a field to the goal path step representing quantification;
the field says whether the quantification changes the determinism of
the goal (i.e. whether it cuts away solutions).
compiler/hlds_pred.m:
compiler/hlds_out.m:
Add two fields to proc_infos which (a) record which variable, if any,
holds the call table tip node, and (b) record whether the procedure's
layout structure needs to reserve a slot for the saved value of maxfr.
compiler/table_gen.m:
Put this feature on the appropriate goal.
Also, rename a predicate to make it reflect its purpose better.
compiler/code_gen.m:
Generate code to put the call table tip variable in its stack slot
immediately after it has been generated.
Add a sanity check to ensure that if a procedure that lives on the det
stack can create a temporary nondet frame, and debugging is enabled,
then it did have a stack slot reserved for the saved maxfr.
compiler/code_util.m:
Add a predicate to make a conservative prediction of whether a
procedure may allocate a temporary nondet stack frame. We cannot
just generate the code and see, because the code generator needs to
know which variables live in which stack slots, and we cannot decide
that until we know whether we need a stack slot for the saved value of
maxfr.
Make an unrelated predicate semidet procedure use a det helper, in
order to make it more robust in the face of changes to the HLDS
(e.g. it was missing code for handling bi_implications).
compiler/code_info.m:
Record whether a procedure has in fact created a temporary nondet stack
frame.
compiler/handle_options.m:
Disable hijacks if debugging is enabled. The code we now use to
restore the stacks for direct retries works only if the retry does not
"backtrack" over a hijacked nondet stack frame whose hijack has not
been undone. Note that code compiled without debugging may still hijack
nondet stack frames. Execution may reemerge from the nondebugged region
in one of two ways. If the nondebugged code returns, then it will have
undone hijack, and the retry code will work. If the nondebugged code
calls debugged code, there will be a region on the stacks containing
no debugging information, and the retry command will refuse to perform
retries that go into or beyond this region. Both cases preserve
correctness.
compiler/*.m:
Trivial changes to conform to changes in data structures.
runtime/mercury_stack_layout.h:
Add three new fields to proc layouts: the numbers of the stack slots
(if any) storing the saved maxfr and the call table tip, and a
representation of the procedure's evaluation method.
runtime/mercury_stack_trace.[ch]:
Now that return layouts contain goal paths, print them in stack dumps
only if the include_trace_data flag is set (in mdb, this requires the
-d flag of the "stack" command).
Pass this flag around directly, instead of encoding its value in
the NULL vs non-NULL values of sp and curfr.
runtime/mercury_regorder.h:
Provide a mechanism to access the values of the first few rN registers
from a save area, for use in debugging low-level C code in the runtime
and the trace directories.
trace/mercury_trace.[ch]:
Reimplement MR_trace_retry to allow retries from the middle.
If the stack segment being retried over contains minimal model
procedures, we must still arrange to skip to the end of the retried
call. If this call is a minimal model generator, skipping to just any
final port is not sufficient to guarantee correctness on retry; to
ensure that subgoal is complete, we must skip to a fail port.
trace/mercury_trace.[ch]:
trace/mercury_trace_internal.c:
Implement a debugger command, "fail", which skips to the fail port or
the exception port of the specified ancestor. Since procedures that are
not model_non are not guaranteed to get to such a port, this
command reports an error if the specified call is not model_non.
Actually, even calls to model_non procedures may not get to the fail
port, as explained above; this is why the command is not yet
documented.
trace/mercury_trace.c:
trace/mercury_trace_util.[ch]:
Move some functions to print parts of the Mercury abstract machine
state from mercury_trace to mercury_trace_util, so that they are
available for use in debugging e.g. mercury_trace_declarative.
trace/mercury_trace_internal.c:
trace/mercury_trace_external.c:
trace/mercury_trace_declarative.c:
Use the new implementation of retries. At the moment, only the
internal debugger implements the full functionality. The declarative
debugger issues retry commands only from situations where the missing
functionality is not (yet) needed. The external debugger should
continue to work correctly, but Erwan may wish to update it to
exploit the availability of the fail command.
trace/mercury_trace*.[ch]:
Fix MR_prefixes, and a signed/unsigned mismatch.
doc/user_guide.texi:
Document the new "fail" command, but comment it out for now.
tests/debugger/retry.{m,inp,exp,exp2}:
A new test case for exercising retry.
tests/debugger/Mmakefile:
Enable the new test case.
tests/debugger/*.exp:
Update the expected output, given the extra info now output e.g. for
exception events and detailed stack traces.
|
||
|
|
07d6517521 |
Implement a general mechanism for suppressing selected aspects of 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.) |
||
|
|
36fc174bed |
Make declarative debugging a trace level, not a separate option.
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. |
||
|
|
3ce3b14c84 |
Make procedure bodies available to the declarative debugger.
Estimated hours taken: 20 Make procedure bodies available to the declarative debugger. browser/program_representation.m: Add _rep suffixes to the function symbols, to make iit easier to distinguish HLDS goals and goal representations. compiler/static_layout.m: If --trace-decl is specified, include a representation of the procedure body in the procedure's layout structure. compiler/prog_rep.m: A new module, containing the code that converts goals from HLDS to a term in the format we want to put in the layout structure. compiler/static_term.m: A new module, containing the code that converts Mercury terms to the LLDS rval we need to give to llds_out.m. compiler/code_gen.m: compiler/continuation_info.m: Preserve the information needed by prog_rep compiler/Mmakefile: Extend the search path to the browser directory, since the new file prog_rep.m imports one of the submodules of mdb.m stored there. compiler/notes/compiler_desigm.html: Document the new modules. library/std_util.m: Add a mechanism for static_term.m to use in converting terms into rvals. This mechanism uses RTTI information to deconstruct terms, and return not only their arguments, but also information about how the term can be constructed from its arguments. runtime/mercury_type_info.h: Add a couple of macros to make construction and deconstruction of univs easier, for use in std_util.m. trace/mercury_trace_internal.c: Add a new command, "proc_body", that prints out the representation of the body of the current procedure. This is meant only for developers to use to check that the procedure body representation is OK; it is deliberately not documented. Also fix a bug: make sure that we do not pass a NULL pointer to fputs when echoing a line of input that isn't there (because we got EOF). |
||
|
|
c014e2a20b |
Store the offsets leading to the names of variables in a central location.
Estimated hours taken: 8 Store the offsets leading to the names of variables in a central location. Previously, each label layout included offsets for the variables live at that label; now we store the offsets of variables in the proc layout. The new data structure will soon be required by the declarative debugger for displaying contours through representations of HLDS goals. compiler/code_gen.m: Preserve the varset of every procedure for use by stack_layout.m. compiler/continuation_info.m: Add a field to the cell from which proc layouts are derived to hold the varset. compiler/stack_layout.m: Delete the offsets from label layouts and add them to proc layouts. The var name offsets array will always contain meaningful offsets for every variable that is live at a label with a label layout; with --trace-decl, it will also contain meaningful offsets for all the other variables in the procedure body. runtime/mercury_stack_layout.h: Reflect the change in the types of the label and proc layout structures. trace/mercury_trace.c: trace/mercury_trace_vars.c: Look up variable names using the new location of the offsets leading to them. |
||
|
|
dd7f3e80d1 |
Unify the code that performs the three kinds of data movements
Estimated hours taken: 20
Unify the code that performs the three kinds of data movements
required for calls:
(1) putting forward live variables to be saved across the call
into their stack slots
(2) putting variables protected by enclosing resumption points
into their stack slots
(3) putting input arguments into their registers
By using the same code (code_info__setup_call) for all three, we gain
two benefits:
(1) This code can also compute the live lval set we must put into
a livevals LLDS instruction before the call to describe the
locations that must be preserved by value numbering. Previously,
this set was computed by other algorithms, raising the possibility
of a discrepancy. Such discrepancies would cause value numbering
to generate incorrect code.
(2) The eager back end is more efficient when given a single list
of data placements to perform instead of three lists, because
it can reorder operations more freely when required.
compiler/call_gen.m:
Make the change described above.
Factor out more code that is common between ordinary and generic calls.
compiler/code_info.m:
Provide the infrastructure for the change above.
compiler/arg_info.m:
Concentrate predicates dealing with arg_infos and parameter passing
conventions in general in this module. Previously, call_gen.m and
code_util.m also contained such code.
compiler/bytecode_gen.m:
compiler/pragma_c_gen.m:
compiler/disj_gen.m:
compiler/follow_vars.m:
compiler/middle_rec.m:
Small changes to conform to changes in interfaces of the modules above.
compiler/code_util.m:
Remove a now redundant predicate.
|
||
|
|
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. |
||
|
|
12af7b3793 |
Consistently use counters to allocate label numbers and cell numbers
Estimated hours taken: 12 Consistently use counters to allocate label numbers and cell numbers throughout the LLDS backend. compiler/hlds_module.m: Change the module_info structure to store a counter instead of an integer for cell numbers. compiler/llds.m: Change the c_procedure structure to include a proc_label and a counter, to allow LLDS to LLDS optimizations to use this counter to allocate new label numbers. (The labels also include the proc_label.) compiler/code_info.m: Change the code_info structure to store counters instead of integers for both label numbers and cell numbers. compiler/code_gen.m: When creating the c_procedure, copy the final value of the counter from code_info to the c_procedure. compiler/opt_util.m: Delete the existing, inefficient procedure for allocating label numbers, and modify the interface of the get_prologue predicate to no longer return the proc_label (since it can now be looked up more directly). compiler/*.m: Minor changes to conform to the new data structures and to use counters instead of direct addition. |
||
|
|
c192d50143 |
Add preliminary support for a new pragma:
Estimated hours taken: 15 Add preliminary support for a new pragma: :- pragma foreign_code(LanguageString, .... <same args as c_code>). This is intended to be the eventual replacement of pragma c_code. Presently the only valid language is "C". The existing pragma c_code is simply turned into pragma foreign_code. pragma foreign_code is not a supported pragma at the moment. There are several other changes that are intended (for example, foreign_code will be impure by default). This change also changes the HLDS goal pragma_c_code/7 to pragma_foreign_code/8 where the extra argument is the foreign language. Any code currently generating output for pragma C code simply checks that the foreign language is set to "c". Since this is the only alternative of the type foreign_language, it will always succeed. However when new alternatives are added it should be fairly easy to find where the changes need to be made. Some type names and predicate names have also been updated, however there are many more that haven't yet been touched. compiler/prog_io_pragma.m: Accept the new syntax. Turn the old syntax into the new item. compiler/hlds_goal.m: Change pragma_c_code/7 to pragma_foreign_code/8. Define the foreign_language type. compiler/llds.m: Change user_c_code/2 to user_foreign_code/3. compiler/*.m: Update the rest of the compiler to handle these types. Make a few small changes to update variable names, predicate names and type names. |
||
|
|
78e4768104 |
Fix a bug that was causing the compiler to output bogus declarations
Estimated hours taken: 4 Fix a bug that was causing the compiler to output bogus declarations of nonexistent layout structures, using undefined C structure tags. For some reason, gcc accepted these declarations on all our platforms except taifun. compiler/llds.m: We used to have one field in pragma_c instructions that could name a label that cannot be renamed by optimizations. In some instructions, this label had a layout structure, in others it didn't. We now have two fields, one for labels that have layout structures and one for labels that don't. compiler/llds_out.m: Declare the C global variable holding the layout structure of a fixed (non-renamable) label referred to by a pragma_c instruction only if that label does have a layout structure. compiler/*.m: Minor changes to conform to the changes to pragma_c instructions. |
||
|
|
e46e2d5eb1 |
Remove calls to !.
Estimated hours taken: 0.5 library/*.m: compiler/*.m: Remove calls to !. |
||
|
|
84c8146d0d |
Fix several bugs in the trail handling.
Estimated hours taken: 20
Fix several bugs in the trail handling.
Also improve the documentation of trailing, and add a new macro
MR_choicepoint_newer() to the public trailing interface.
The bugs which this change fixes are:
- choice point ids were being reused after commits,
rather than only after backtracking;
- for if-then-elses with nondet conditions, the generated code was
using MR_commit rather than MR_solve as the MR_untrail_reason;
- for semidet disjunctions, when committing to a particular disjunct
the generated code was not calling MR_reset_ticket(..., MR_commit)
to invoke function trail entries, and was also leaking a trail ticket
- the all-solutions predicates in std_util.m were leaking trail
tickets (i.e. allocating them but not pruning or discarding them).
runtime/mercury_trail.h:
runtime/mercury_regorder.h:
runtime/mercury_regs.h:
runtime/mercury_wrapper.c:
runtime/mercury_context.h:
runtime/mercury_engine.h:
A bunch of changes to add a new virtual register
`MR_ticket_high_water':
- in mercury_trail.h, add MR_ticket_high_water_var variable;
- in mercury_regorder.h, add MR_ticket_high_water macro;
- in mercury_regs.h, add MR_TICKET_HIGH_WATER_RN macro;
- in mercury_wrapper.c, change
print_register_usage_counts() to handle
MR_TICKET_HIGH_WATER_RN.
- in mercury_context.h and mercury_engine.h,
add code to save/restore this new register when
appropriate.
runtime/mercury_trail.h:
- Change MR_store_ticket() so that it does
`MR_ticket_counter = ++MR_ticket_high_water'
rather than just `MR_ticket_counter++'.
- Add new macros MR_prune_ticket() and MR_prune_tickets_to(),
which only reset MR_ticket_counter, not MR_ticket_high_water.
- Change the old macros MR_discard_ticket() and MR_discard_tickets_to()
so that they reset both MR_ticket_high_water and MR_ticket_counter.
- Add new macro MR_choicepoint_newer().
- Enclose macro arguments in parentheses.
- Some minor changes to the documentation.
doc/reference_manual.texi:
Document MR_choicepoint_newer().
Update the documentation to reflect the fact that exceptions
are now a standard part of Mercury.
Clarify the documentation in the "Avoiding Redundant Trailing"
section, and add a longish example.
compiler/notes/trailing.html:
Add some documentation on the trail and how we manage it.
compiler/llds.m:
compiler/mlds.m:
Add new `prune_ticket' and `prune_tickets_to' instructions,
corresponding to the new macros defined in runtime/mercury_trail.h.
Comment out the `discard_tickets_to' instruction, since it
is no longer used in the compiler (the MR_discard_tickets_to()
macro is only used by library/exception.m and the debugger's
retry command).
Replace the duplicated documentation in mlds.m with a pointer
to llds.m.
compiler/ite_gen.m:
compiler/code_gen.m:
compiler/code_info.m:
Change the trail handling code generated after commits
so that the ticket is pruned rather than discarded.
compiler/ite_gen.m:
When generating the reset_ticket instruction for
if-then-elses with nondet conditions, use `solve'
rather than `commit' as the reset_trail_reason.
compiler/disj_gen.m:
Add code to generate a reset_ticket(..., commit)
instruction at the end of every non-last disjunct
in semidet disjunctions.
compiler/dupelim.m:
compiler/livemap.m:
compiler/llds_common.m:
compiler/llds_out.m:
compiler/ml_elim_nested.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/value_number.m:
compiler/vn_*.m:
Trivial modifications to handle the changes to the
trailing instructions.
library/exception.m:
Change the trail handling code so that when the goal in an
exception handler succeeds (rather than failing or throwing an
exception), the trail ticket we created on entry to the
handler is pruned rather than discarded.
library/std_util.m:
Add a new impure predicate `discard_trail_ticket', which calls
MR_discard_ticket(), and call it in `builtin_aggregate' and
`do_while' to discard the ticket that gets allocated by the
call to MR_store_ticket() in `get_registers'.
|
||
|
|
6feb0b95f2 |
Make a separate enquiry function for each possible semantic test on
Estimated hours taken: 1 Make a separate enquiry function for each possible semantic test on eval_methods. The answers are the same now, but will be different when tabled I/O is implemented. compiler/hlds_pred.m: Make a separate enquiry function for each possible semantic test on eval_methods. compiler/code_gen.m: compiler/ml_code_gen.m: compiler/make_hlds.m: compiler/modes.m: compiler/table_gen.m: Use the new functions. |
||
|
|
17c24d9cf9 |
Restrict value numbering on procedures containing reconstructions.
Estimated hours taken: 1 Restrict value numbering on procedures containing reconstructions. Without this change, value numbering could reorder instructions which extract fields from a cell with the instructions which update the values of those fields. compiler/llds.m: Add a field to each `c_procedure' to record whether the procedure contains a reconstruction. compiler/code_gen.m: Fill in the field. compiler/value_number.m: Wrap labels around all field assignments in procedures which contain reconstructions. compiler/*.m: Handle the extra field of the `c_procedure' constructor. |
||
|
|
d43750667c |
Add a new function eval_method_uses_table/1.
Estimated hours taken: 0.75 compiler/hlds_pred.m: Add a new function eval_method_uses_table/1. compiler/code_gen.m: compiler/ml_code_gen.m: compiler/modes.m: compiler/table_gen.m: Use eval_method_uses_table, rather than just assuming that every eval method other than eval_normal uses a table. |
||
|
|
0642a10ff8 |
Reduce the number of arguments of MR_trace() to one.
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. |
||
|
|
f0964815a3 |
Support line numbers in the debugger. You now get contexts (filename:lineno
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.
|