mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 14:57:03 +00:00
be5b71861b3d74c8cb4caa85a098d41b986a5c3e
314 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
be5b71861b |
Convert almost all the compiler modules to use . instead of __ as
Estimated hours taken: 6 Branches: main compiler/*.m: Convert almost all the compiler modules to use . instead of __ as the module qualifier. In some cases, change the names of predicates and types to make them meaningful without the module qualifier. In particular, most of the types that used to be referred to with an "mlds__" prefix have been changed to have a "mlds_" prefix instead of changing the prefix to "mlds.". There are no algorithmic changes. |
||
|
|
fc5159db46 |
Improve trail usage optimization of disjunctions for the LLDS backend.
Estimated hours taken: 6 Branches: main Improve trail usage optimization of disjunctions for the LLDS backend. Fix a bug in my previous change which implemented this for the MLDS backend. compiler/disj_gen.m: Improve the trail usage optimization of disjunctions for the LLDS backend. Reformat some comments to take advantage of the extra space provided by the conversion to four-space indentation. compiler/code_info.m: Add some utility predicates for use by the above. compiler/add_trail_ops.m: Fix a bug where we weren't emitting instructions to prune the trail ticket in model_semi and model_det disjunctions. compiler/handle_options.m: `--analyse-trail-usage' implies `--optimize-trail-usage' because the analysis results assume that the redundant trailing instructions are removed. The reverse implication is not true but trying to optimize trail usage without running the analysis won't have any effect. |
||
|
|
45fdb6c451 |
Use expect/3 in place of require/2 throughout most of the
Estimated hours taken: 4 Branches: main compiler/*.m: Use expect/3 in place of require/2 throughout most of the compiler. Use unexpected/2 (or sorry/2) in place of error/1 in more places. Fix more dodgy assertion error messages. s/map(prog_var, mer_type)/vartypes/ where the latter is meant. |
||
|
|
dae82a8409 |
Implement trail usage optimization for the lowlevel backend.
Estimated hours taken: 5 Branches: main Implement trail usage optimization for the lowlevel backend. compiler/code_gen.m: As we generate code for each HLDS goal check if it is safe to omit trailing operations. Do so, if trail usage optimization is enabled. Reformat some code for the purposes of readability. compiler/commit_gen.m: compiler/disj_gen.m: compiler/ite_gen.m: compiler/code_info.m: Thread the above information down to the relevant parts of the code generator. Misc. cleanups: reduce unnecessary module qualification and minor layout fixes. compiler/code_util.m: Add a utility predicate the tests if we are allowed to omit trailing primitives for a given HLDS goal. compiler/llds.m: Add the equivalence type: add_trail_ops == bool. compiler/hlds_goal.m: compiler/prog_data.m: Unrelated changes: fix typos in comments. Add an end_module declaration to the former. |
||
|
|
f9fe8dcf61 |
Improve the error messages generated for determinism errors involving committed
Estimated hours taken: 8
Branches: main
Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.
The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.
compiler/det_analysis.m:
Keep track of goals to the right of the current goal that could fail,
and include them in the error representation if required.
compiler/det_report.m:
Include the list of failing goals to the right in the representations
of determinism errors involving committed committed choice goals.
Convert the last part of this module that wasn't using error_util
to use error_util. Make most parts of this module just construct
error message specifications; print those specifications (using
error_util) in only a few places.
compiler/hlds_out.m:
Add a function for use by the new code in det_report.m.
compiler/error_util.m:
Add a function for use by the new code in det_report.m.
compiler/error_util.m:
compiler/compiler_util.m:
Error_util is still changing reasonably often, and yet it is
included in lots of modules, most of which need only a few simple
non-parse-tree-related predicates from it (e.g. unexpected).
Move those predicates to a new module, compiler_util.m. This also
eliminates some undesirable dependencies from libs to parse_tree.
compiler/libs.m:
Include compiler_util.m.
compiler/notes/compiler_design.html:
Document compiler_util.m, and fix the documentation of some other
modules.
compiler/*.m:
Import compiler_util instead of or in addition to error_util.
To make this easier, consistently use . instead of __ for module
qualifying module names.
tests/invalid/det_errors_cc.{m,err_exp}:
Add this new test case to test the error messages for cc contexts.
tests/invalid/det_errors_deet.{m,err_exp}:
Add this new test case to test the error messages for unifications
inside function symbols.
tests/invalid/Mmakefile:
Add the new test cases.
tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
Change the expected output to conform to the change in det_report.m,
which is now more consistent.
|
||
|
|
b2012c0c0e |
Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
Estimated hours taken: 8 Branches: main compiler/*.m: Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst' and 'mer_mode'. This is to avoid the need to parenthesize these type names in some contexts, and to prepare for the possibility of a parser that considers those words to be reserved words. Rename some other uses of those names (e.g. as item types in recompilation.m). Delete some redundant synonyms (prog_type, mercury_type) for mer_type. Change some type names (e.g. mlds__type) and predicate names (e.g. deforest__goal) to make them unique even without module qualification. Rename the function symbols (e.g. pure, &) that need to be renamed to avoid the need to parenthesize them. Make their replacement names more expressive. Convert some more modules to four space indentation. Avoid excessively long lines, such as those resulting from the automatic substitution of 'mer_type' for 'type'. |
||
|
|
d609181cb9 |
Consider types of the form
Estimated hours taken: 30
Branches: main
Consider types of the form
:- type x ---> f.
to be dummy types, since they contain no information. Optimize them the same
way we currently optimize io.state and store.store.
runtime/mercury_type_info.h:
Add a new type_ctor_rep for dummy types.
runtime/mercury_tabling.h:
Add a representation for "tabled" dummy types, which don't actually
have a level in the trie, so that the runtime system can handle that
fact.
runtime/mercury_ml_expand_body.h:
When deconstructing a value of a dummy type, ignore the actual value
(since it will contain garbage) and instead return the only possible
value of the type.
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.c:
runtime/mercury_tabling.c:
runtime/mercury_unify_compare_body.h:
library/rtti_implementation.m:
Handle the type_ctor_rep of dummy types.
runtime/mercury_builtin_types.c:
Provide a place to record profiling information about unifications and
comparisons for dummy types.
runtime/mercury_mcpp.h:
java/runtime/TypeCtorRep.java:
library/private_builtin.m:
Add a new type_ctor_rep for dummy types, and fix some previous
discrepancies in type_ctor_reps.
mdbcomp/prim_data.m:
Move a bunch of predicates for manipulating special_pred_ids here from
the browser and compiler directories.
Rename the function symbols of the special_pred_id type to avoid the
need to parenthesize the old `initialise' function symbol.
Convert to four-space indentation.
mdbcomp/rtti_access.m:
Don't hardcode the names of special preds: use the predicates in
prim_data.m.
Convert to four-space indentation.
browser/declarative_execution.m:
Delete some predicates whose functionality is now in
mdbcomp/prim_data.m.
compiler/hlds_data.m:
Replace the part of du type that says whether a type an enum, which
used to be a bool, with something that also says whether the type is a
dummy type.
Convert to four-space indentation.
compiler/make_tags.m:
Compute the value for the new field of du type definitions.
compiler/hlds_out.m:
Write out the new field of du type definitions.
compiler/rtti.m:
Modify the data structures we use to create type_ctor_infos to allow
for dummy types.
Convert to four-space indentation.
compiler/type_ctor_info.m:
Modify the code that generates type_ctor_infos to handle dummy types.
compiler/type_util.m:
Provide predicates for recognizing dummy types.
Convert to four-space indentation.
compiler/unify_proc.m:
Generate the unify and compare predicates of dummy types using a new
code scheme that avoids referencing arguments that contain garbage.
When generating code for unifying or comparing other types, ignore
any arguments of function symbols that are dummy types.
Don't use DCG style access predicates.
compiler/higher_order.m:
Specialize the unification and comparison of values of dummy types.
Break up an excessively large predicate, and factor out common code
from the conditions of a chain of if-then-elses.
compiler/llds.m:
For each input and output of a foreign_proc, include a field saying
whether the value is of a dummy type.
compiler/pragma_c_gen.m:
Fill in the new fields in foreign_proc arguments.
compiler/hlds_goal.m:
Rename some predicates for constructing unifications to avoid
unnecessary ad-hoc overloading. Clarify their documentation.
Rename a predicate to make clear the restriction on its use,
and document the restriction.
Add a predicate for creating simple tests.
Add a utility predicate for setting the context of a goal directly.
compiler/modules.m:
Include dummy types interface files, even if they are private to the
module. This is necessary because with the MLDS backend, the generated
code inside the module and outside the module must agree whether a
function returning a value of the type returns a real value or a void
value, and this requires them to agree on whether the type is dummy
or not.
The impact on interface files is minimal, since very few types are
dummy types, and changing a type from a dummy type to a non-dummy type
or vice versa is an ever rarer change.
compiler/hlds_pred.m:
Provide a representation in the compiler of the trie step for dummy
types.
compiler/layout_out.m:
Print the trie step for dummy types.
compiler/table_gen.m:
Don't table values of dummy types, and record the fact that we don't
by including a dummy trie step in the list of trie steps.
compiler/add_pragma.m:
compiler/add_special_pred.m:
compiler/add_type.m:
compiler/aditi_builtin_ops.m:
compiler/bytecode.m:
compiler/bytecode_gen.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/cse_detection.m:
compiler/det_report.m:
compiler/exception_analysis.m:
compiler/inst_match.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_il.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/opt_util.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/qual_info.m:
compiler/rl.m:
compiler/rl_exprn.m:
compiler/rl_key.m:
compiler/rtti_out.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/term_constr_initial.m:
compiler/term_constr_util.m:
compiler/term_norm.m:
compiler/termination.m:
compiler/trace.m:
compiler/typecheck.m:
compiler/unify_gen.m:
Conform to the changes above.
compiler/export.m:
compiler/exprn_aux.m:
compiler/foreign.m:
compiler/polymorphism.m:
compiler/proc_label.m:
compiler/rtti_to_mlds.m:
compiler/special_pred.m:
compiler/stack_alloc.m:
compiler/stack_layout.m:
compiler/state_var.m:
compiler/switch_util.m:
compiler/trace_params.m:
Conform to the changes above.
Convert to four-space indentation.
compiler/mlds_to_java.m:
compiler/var_locn.m:
Conform to the changes above, which requires threading the module_info
through the module.
Convert to four-space indentation.
compiler/mercury_compile.m:
Pass the module_info to mlds_to_java.m.
compiler/ml_util.m:
compiler/polymorphism.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
Delete some previously missed references to the temporary types used
to bootstrap the change to the type_info type's arity.
compiler/polymorphism.m:
Turn back on an optimization that avoids passing parameters (such as
type_infos) to foreign_procs if they are not actually referred to.
compiler/prog_data.m:
Convert to four-space indentation.
library/svvarset.m:
Add a missing predicate.
trace/mercury_trace.c:
Delete the unused function that used to check for dummy types.
tests/debugger/field_names.{m,inp,exp}:
Add to this test case a test of the handling of dummy types. Check that
their values can be printed out during normal execution, and that the
debugger doesn't consider them live nondummy variables, just as it
doesn't consider I/O states live nondummy variables.
|
||
|
|
9d87810ae7 |
Fix an optimization that tries to turn MR_succeed() into MR_succeed_discard(),
Estimated hours taken: 2 Branches: main Fix an optimization that tries to turn MR_succeed() into MR_succeed_discard(), which throws away nondet stack frames at the last success of the relevant procedure. compiler/opt_util.m: Fix the overly conservative approximation here that prevented peephole.m from applying that optimization. It was considering livevals() instructions as potentially affecting redoip slots, which cannot be farther from the truth. Change the relevant predicate from an if-then-else with a default to a switch, to prevent similar problems in future. compiler/peephole.m: Don't apply the existing transformation pattern unless we find an assertion that no other stack frame exists on top of the current one, since it isn't valid then. compiler/code_util.m: Include that assertion in the comment of the instruction that assigns to the redoip slot, which is where peephole.m looks for it. We could store the assertion in an extra slot to assignment statements in the LLDS, but that would require changes in lots of places and lead to significant space overhead. This way is simpler, and has no overhead to speak of. Any LLDS transformation that modifies the comment may destroy the assertion, but the chance that it will incorrectly add or even keep the assertion is about zero. |
||
|
|
b54ab42d70 |
A simple tool for performing substitutions on the source files of the
Estimated hours taken: 0.5 Branches: main tools/subst: A simple tool for performing substitutions on the source files of the compiler. compiler/*.m: Change the names of the get predicates operating on module_infos to include "get" in the name, for uniformity. This was done mostly by the following sed script, with some manual cleanup afterwards to reduce excessive line lengths. s/module_info_types/module_info_get_type_table/ s/module_info_set_types/module_info_set_type_table/ s/module_info_insts/module_info_get_inst_table/ s/module_info_set_insts/module_info_set_inst_table/ s/module_info_modes/module_info_get_mode_table/ s/module_info_set_modes/module_info_set_mode_table/ s/module_info_ctors/module_info_get_cons_table/ s/module_info_set_ctors/module_info_set_cons_table/ s/module_info_classes/module_info_get_class_table/ s/module_info_set_classes/module_info_set_class_table/ s/module_info_instances/module_info_get_instance_table/ s/module_info_set_instances/module_info_set_instance_table/ s/module_info_superclasses/module_info_get_superclass_table/ s/module_info_set_superclasses/module_info_set_superclass_table/ s/module_info_assertion_table/module_info_get_assertion_table/ s/module_info_exclusive_table/module_info_get_exclusive_table/ s/module_info_ctor_field_table/module_info_get_ctor_field_table/ s/module_info_name/module_info_get_name/ s/module_info_globals/module_info_get_globals/ s/module_info_contains_foreign_types/module_info_get_contains_foreign_types/ s/module_info_num_errors/module_info_get_num_errors/ s/module_info_type_ctor_gen_infos/module_info_get_type_ctor_gen_infos/ s/module_info_stratified_preds/module_info_get_stratified_preds/ s/module_info_unused_arg_info/module_info_get_unused_arg_info/ s/module_info_exception_info/module_info_get_exception_info/ s/module_info_type_spec_info/module_info_get_type_spec_info/ s/module_info_no_tag_types/module_info_get_no_tag_types/ s/module_info_analysis_info/module_info_get_analysis_info/ s/module_info_aditi_top_down_procs/module_info_get_aditi_top_down_procs/ |
||
|
|
1ed891b7b1 |
Introduce a mechanism for extending the det and nondet stacks when needed.
Estimated hours taken: 24
Branches: main
Introduce a mechanism for extending the det and nondet stacks when needed.
The mechanism takes the form of a new grade component, .exts ("extend stacks").
While the new mechanism may be useful in its own right, it is intended mainly
to support a new implementation of minimal model tabling, which will use a
separate Mercury context for each distinct subgoal. Each context has its own
det and nondet stack. Clearly, we can't have hundreds of contexts each with
megabyte sized det stacks. The intention is that the stacks of the subgoals
will start small, and be expanded when needed.
The runtime expansion of stacks doesn't work yet, but it is unnecessarily
hard to debug without an installed compiler that understands the new grade
component, which is why this diff will be committed before that is fixed.
compiler/handle_options.m:
compiler/options.m:
runtime/mercury_grade.h:
scripts/canonical_grade.sh-subr
scripts/init_grade_options.sh-subr
scripts/parse_grade_options.sh-subr
scripts/mgnuc.in
Handle the new grade component.
runtime/mercury_memory_zones.h:
Add MR_ prefixes to the names of the fields of the zone structure.
Record not just the actual size of each zone, which includes various
kinds of buffers, but also the desired size of the zone exclusive of
buffers.
Format the documentation of the zone structure fields more
comprehensibly.
runtime/mercury_memory_zones.c:
Instead of implementing memalign if it is not provided by the operating
system, implement a function that allows us to reallocate the returned
area of memory.
Provide a prototype implementation of memory zone extension. It doesn't
work yet.
Factor out the code for setting up redzones, since it is now needed
in more than place.
Convert to four space indentation.
Make the debugging functions a bit more flexible.
runtime/mercury_wrapper.c:
Conform to the improved interface of the debugging functions.
runtime/mercury_overflow.h:
runtime/mercury_std.h:
Move a generally useful macro from mercury_overflow.h to mercury_std.h.
runtime/mercury_stacks.c:
Add functions to extend the stacks.
runtime/mercury_stacks.h:
Add the tests required to invoke the functions that extend the stacks.
Add the macros needed by the change to compiler/llds.m.
Convert to four space indentation.
runtime/mercury_conf.h.in:
Prepare for the use of the posix_memalign function, which is the
current replacement of the obsolete memalign library function.
We don't yet use it.
runtime/mercury_context.h:
Format the documentation of the context structure fields more
comprehensibly.
Put MR_ prefixes on the names of the fields of some structures
that didn't previously have them.
Conform to the new names of the fields of the zone structure.
runtime/mercury_context.c:
runtime/mercury_debug.c:
runtime/mercury_deep_copy.c:
runtime/mercury_engine.c:
runtime/mercury_memory_handlers.c:
library/benchmarking.m:
library/exception.m:
Conform to the new names of the fields of the zone structure.
In some cases, add missing MR_ prefixes to function names
and/or convert to four space indentation.
runtime/mercury_engine.h:
Add a new low level debug flag for debugging stack extensions.
Format the documentation of the engine structure fields more
comprehensibly.
Convert to four space indentation.
runtime/mercury_conf_param.h:
Document a new low level debug flag for debugging stack extensions.
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/options.m:
Handle the new grade component.
compiler/llds.m:
Add two new kinds of LLDS instructions, save_maxfr and restore_maxfr.
These are needed because the nondet stack may be relocated between
saving and the restoring of maxfr, and the saved maxfr may point to
the old stack. In .exts grades, these instructions will save not a
pointer but the offset of maxfr from the start of the nondet stack,
since offsets are not affected by the movement of the nondet stack.
compiler/code_info.m:
Use the new instructions where relevant. (Some more work may be
needed on this score; the relevant places are marked with XXX.)
compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/reassign.m:
compiler/use_local_vars.m:
Handle the new LLDS instructions.
tools/bootcheck:
Provide a mechanism for setting the initial stack sizes for a
bootcheck.
|
||
|
|
df0d9036cf |
Optimize calls that would be tail calls in Prolog but are followed by
Estimated hours taken: 40 Branches: main Optimize calls that would be tail calls in Prolog but are followed by construction unifications in Mercury: last call modulo construction. For now, the optimization is available only for the LLDS backend. compiler/lco.m: Turn this module from a placeholder to a real implementation of the optimization. compiler/hlds_goal.m: Allow lco.m to attach to construction unifications a note that says that certain arguments, instead of being filled in by the unification, should have their addresses taken and stored in the corresponding variables. Group this note together with the note that asks for term size profiling to avoid an increase in the sizes of goals in the compiler in most cases. compiler/hlds_pred.m: Provide a predicate for setting the name of a predicate after its creation. This functionality is used by lco.m. Extend the pred_transformation part of the pred_origin type to allow it to express that a procedure was created by lco.m. List the new primitive store_at_ref as a no-typeinfo builtin. Fix some problems with indentation. compiler/layout_out.m: Handle the new pred_transformation. compiler/unify_gen.m: When processing construction unifications that have the new feaure turned on, perform the requested action. Fix some departures from coding style. Shorten lines by deleting unnecessary module qualifications. Add some auxiliary predicates to make the code easier to read. compiler/var_locn.m: Fix an earlier oversight: when materializing variables inside rvals and lvals, look inside memory references too. Previously, the omission didn't matter, since we didn't generate such references, but now we do. Fix some departures from coding style. compiler/llds_out.m: Fix some old XXXs in code handling memory references. We didn't use to generate such references, but now we do. Move some functionality here from code_aux.m. compiler/code_info.m: Provide some primitive operations needed by the new code in var_locn.m. Delete an unneeded predicate. compiler/options.m: Rename the existing option optimize_constructor_last_call as optimize_constructor_last_call_accumulator, since that optimization is done by accumulator.m. Make optimize_constructor_last_call be the option that calls for the new optimization. compiler/handle_options.m: Handle the implications of the new option. compiler/mercury_compile.m: Invoke the lco module by its new interface. librrary/private_builtin.m: Add a new primitive operation, store_at_ref, for use by the new optimization. Switch the module to four-space indentation. compiler/add_clause.m: Comment out the warning for clauses for builtin, since this is needed to bootstrap the addition of the new builtin. compiler/term_constr_initial.m: Handle the new builtin. compiler/accumulator.m: Conform to the change in options. compiler/builtin_ops.m: Provide a third template for builtins, for use by store_at_ref. Convert the file to four-space indentation. compiler/call_gen.m: Generate code following the new builtin template. compiler/rl_exprn.m: Minor changes to conform to the changes in builtin templates. compiler/quantification.m: Minor changes to conform to the changes in construct unifications. Don't make the "get" predicates operating on quantification_infos to return the "new" quantification_info: it is always the same as the old one. compiler/aditi_builtin_ops.m: compiler/common.m: compiler/deep_profiling.m: compiler/higher_order.m: compiler/hlds_out.m: compiler/lambda.m: compiler/magic_util.m: compiler/ml_unify_gen.m: compiler/modecheck_unify.m: compiler/polymorphism.m: compiler/size_prof.m: Minor changes to conform to the changes in construct unifications. compiler/dependency_graph.m: Add a new predicate to recompute the dependency information, even if a previous (and possibly now inaccurate) version is present. Change the interface to make it clearer, by changing bools into types specific to the situation. Convert the file to four-space indentation. compiler/mode_constraints.m: Minor changes to conform to the changes in dependency_graph.m. compiler/code_aux.m: Delete this module. Half its functionality has been moved into llds_out.m, half to middle_rec.m (its only user). compiler/goal_form.m: Move the predicates in this module that are used only by middle_rec.m to middle_rec.m. Convert the file to four-space indentation. compiler/goal_util.m: compiler/det_util.m: Move update_instmap from det_util to goal_util, since it is usefulness extends beyond determinism analysis. Convert det_util.m to four-space indentation. compiler/middle_rec.m: Move here the code required only here from code_aux and goal_form. Update the moved code for the changes in construct unifications. The updates are specific to middle_rec.m: they wouldn't be of use to other modules. They basically say that any code that takes the addresses of fields cannot be handled by middle_rec.m. compiler/code_gen.m: compiler/det_analysis.m: compiler/live_vars.m: compiler/ll_backend.m: compiler/loop_inv.m: compiler/switch_detection.m: compiler/switch_gen.m: compiler/notes/compiler_design.html: Minor changes to conform to the deletion of code_aux.m and/or the movement of code from det_util to goal_util.m. compiler/opt_debug.m: Print info for vars in rvals. compiler/hlds_module.m: Convert a lambda to an explicit predicate to make some code easier to read. Switch the module to four-space indentation. |
||
|
|
f0dbbcaa34 |
Generate better code for base relations such as the ones in the transitive
Estimated hours taken: 16 Branches: main Generate better code for base relations such as the ones in the transitive closure benchmarkings in the paper on minimal model tabling. These improvements yield speedups ranging from 5 to 25% on those benchmarks. compiler/use_local_vars.m: Make this optimization operate on extended basic blocks instead of plain basic blocks. The greater length of extended basic blocks allows the local variables to have maximum scope possible. The price is that the test for whether assignment to a given lvalue can be avoided or not is now dependent on which of the constituent basic blocks of extended basic block contains the assignment, and thus the test has to be evaluate once for each assignment we try to optimize instead of once per block. Don't allocate temporary variables if the optimization they are intended for turns out not to be allowed. This change avoids having declarations for unused temporary variables in the resulting C code. If --auto-comments is set, insert use_local_vars.m's main data structure, the livemap, into the generated LLDS code as a comment. compiler/peephole.m: Look for the pattern mkframe(Size, Redoip) <straight line instructions that don't use stack slots> succeed and optimize away the mkframe. This pattern always arises for procedures that are actually semidet but are declared nondet (such as the base relations in the tabling benchmarks), and may also arise for semidet branches of nondet procedures. compiler/llds.m: Allow an existing peephole pattern to work better. The pattern is mkframe(Seize, do_fail) <straight line instructions> redoip(curfr) = Redoip Previously, if some compiler-generated C code was among the straight line instructions, the pattern couldn't be applied, since peephole.m couldn't know whether it branched away through the redoip slot of the frame. This diff adds an extra slot to the relevant pragma_c component that tells peephole.m (actually, the predicate in opt_util.m that peephole relies on) whether this is the case. compiler/basic_block.m: Provide functionality for merging basic blocks into extended basic blocks. compiler/dupelim.m: Conform to the change in basic_block.m's interface. Convert to four-space indentation, and fix departures from our style guidelines. compiler/opt_util.m: Provide extra information now needed by use_local_vars. Convert to four-space indentation, and fix departures from our style guidelines. compiler/opt_debug.m: Show the user friendly versions of label names when dumping livemaps and instructions. Shorten the dumped descriptions of registers and stack slots. Dump instructions inside blocks. compiler/frameopt.m: Conform to the changes in opt_util and opt_debug's interfaces. compiler/optimize.m: Use the facilities of opt_debug instead of llds_out when dumping the LLDS after each optimization, since these are now more compact and thus reader friendly. Print unmangled names when writing progress messages. Put the dump files we generate with --opt-debug in a separate subdirectory, since when compiling e.g. tree234.m, the process can generate more than a thousand files. Give the dump files minimally mangled names. compiler/code_gen.m: compiler/pragma_c_gen.m: Convert to four-space indentation, and fix departures from our style guidelines. Conform to the change in llds.m. compiler/code_info.m: compiler/exprn_aux.m: compiler/ite_gen.m: compiler/jumpopt.m: compiler/livemap.m: compiler/llds_out.m: compiler/middle_rec.m: compiler/trace.m: Conform to the change in llds.m. |
||
|
|
5b105a0968 |
Optimize higher order calls by providing variants of the relevant code that
Estimated hours taken: 6 Branches: main Optimize higher order calls by providing variants of the relevant code that are specialized to a given number of explicitly given arguments. runtime/mercury_ho_call.[ch]: Define variants of do_call_closure and do_call_class_method specialized to 0, 1, 2 or 3 explicit input arguments. Apart from not needing to be passed the number of explicit input arguments in a register, these avoid some runtime tests and unroll loops. Harmonize the variable names used in the do_call_closure and do_call_class_method variants. Since they are near-copies of each other, factor out their documentation. (Factoring out the code itself would be possible, but would not make maintenance easier and would make the code harder to read.) Provide a mechanism to gather statistics about the numbers of hidden and explicit arguments if the macro MR_DO_CALL_STATS is set. compiler/options.m: Add options that specify how many of these variants exist. These provide the necessary synchronization between the runtime and the compiler. They are not meant to be set from the command line, even by implementors. runtime/mercury_conf_params.h: Document MR_DO_CALL_STATS. runtime/mercury_wrapper.c: If MR_DO_CALL_STATS is set, print the gathered statistics when execution ends. runtime/mecury_mm_own_stack.c: Fix a typo that prevented the stage2 library from linking in jump.gc grade. compiler/llds.m: Provide a way to represent the labels of the new specialized variants. compiler/llds__out.m: Output the labels of the new specialized variants if required. Convert to four-space indentation. compiler/call_gen.m: Call the specialized variants of do_call_closure or do_call_class_method if they are applicable. code_info/follow_vars.m: code_info/interval.m: code_info/tupling.m: Conform to the change in call_gen.m. code_info/dupproc.m: code_info/exprn_aux.m: code_info/livemap.m: code_info/opt_util.m: Conform to the change in llds.m. compiler/code_info.m: Minor style cleanups. tools/bootcheck: Enable the collection of statistics from the compilation of stage 3 and the test cases, for use when the stage 2 is built with MR_DO_CALL_STATS enabled. tools/ho_call_stats: A new script to analyze the statistics collected. tools/makebatch: Add a new option --save-stage2-on-no-compiler, which is a variant of the existing option --save-stage2-on-error. |
||
|
|
38d9ef3479 |
Package the type_info_varmap and typeclass_info_varmap types into an ADT
Estimated hours taken: 25 Branches: main Package the type_info_varmap and typeclass_info_varmap types into an ADT called rtti_varmaps. There are two main purposes for this: - We wish to extend this set of maps with new maps. Doing this will be a lot easier and less error prone if all of the maps are packaged in a single data structure. - Any new maps that we add may contain redundant information that just makes searching the maps more efficient. Therefore they must be kept consistent with the existing maps. Having all the maps inside an ADT makes it easier to ensure this. This change also includes two extensions to the maps. First, the typeclass_info_map is made reversible so that it is possible to efficiently look up the constraint for a given typeclass_info variable. Second, a new map from prog_vars to types makes it possible to efficiently look up the type that a given type_info variable is for. These two changes mean that it is no longer necessary to consult the argument of type_info/1 or typeclass_info/1 to find this information. (We still do put that information there, though; changing the RTTI is left for a separate change.) compiler/hlds_pred.m: Move items relating to type_infos and typeclass_infos into a section of their own. Add a type `rtti_var_info' to hold information about the contents of a type_info or typeclass_info variable. Define the rtti_varmaps abstract data type. This data structure consists of the type_info_varmap and the typeclass_info_varmap. Add a new map, type_info_type_map, which is like the inverse to the type_info_varmap. The difference is that the latter can point to locations that are inside a typeclass_info variable, whereas the former only refers to type_info variables. Note that the combined maps do not form a bijection, or even an injection, since it is possible for two different type variables to point to the same location (that is, if they are aliased). Make the typeclass_info_varmap reversible, by using the new module injection.m. Unlike the type_info_varmap, this map is always injective since the same typeclass_info cannot be used for two different constraints. The predicates rtti_det_insert_type_info_locn and set_type_info_locn, which update the type_info_varmap, contain sanity checks to ensure that only type variables that have already been registered with the type_info_type_map are used, and that the information in both maps is consistent. Use the rtti_varmaps structure in proc_info and clauses_info, in place of type_info_varmap and typeclass_info_varmap. compiler/polymorphism.m: Remove polymorphism__type_info_or_ctor_type/2 and polymorphism__typeclass_info_class_constraint/2, to ensure that nobody tries to use the information in the type argument. Replace them with two similar predicates that test if a type is type_info or typeclass_info, but that don't return the argument. Ensure that the new type_info_type_map in the rtti_varmaps is kept up to date by threading the rtti_varmaps through a few more places. Some of these places are exported, so this part of the change affects other modules as well. Fix a comment that referred to a non-existent predicate. compiler/type_util.m: Remove the predicates apply_substitutions_to_var_map/5 and apply_substitutions_to_typeclass_var_map/5. The functionality is now provided by the new ADT. compiler/cse_detection.m: Rewrite update_existential_data_structures/4 to use the interface provided by rtti_varmaps. The algorithm for doing this has changed in the following ways: - The first pass, which builds a map from changed locations in the first branch to the tvars concerned, is modified slightly to traverse over the keys instead of over key-value pairs. - The second pass, which previously calculated the induced type substitution and reconstructed the type_info_varmap now only does the former. - Applying the prog_var transformation and the induced type substitution is done at the end, using the interface to rtti_varmaps. compiler/goal_util.m: Rewrite goal_util__extra_nonlocal_typeinfos/6 to avoid the need for using map__member/3 on the typeclass_info_varmap (about which the existing comments say "this is probably not very efficient..."), and to be more efficient in general. Previously, we nondeterministically generated non-local type vars and then tested each constraint to see if it had the type var in it. Now, we go through each constraint one at a time and check if any of the type variables in it are non-local. This is more efficient because we only need to find one non-local type in order to include the typeclass_info in the non-locals -- the remaining (duplicate) solutions are pruned away. compiler/higher_order.m: Use the new maps instead of looking at the arguments of type_info/1 and typeclass_info/1 types. We plan to remove this information from type_info and typeclass_info types in future. Previously, this module used the type argument in order to update the varmaps when the curried arguments of a higher order call are added as arguments to the procedure in which the call occurs. We now look up this information at the point where the curried arg variables are known, and store this information in higher_order_arg alongside the types where it used to be stored. This structure is threaded through to the place where the information is needed. Fix a cut and paste bug in higher_order_arg_depth/1. It was previously calling higher_order_args_size/1 in the recursive call, instead of calling higher_order_args_depth/1. compiler/inlining.m: In inlining__do_inline_call, apply the substitutions to the entire rtti_varmaps structure, not just to the type_info_varmap. (XXX Is there a good reason why the substitution should _not_ be applied to the typeclass_info varmap?) compiler/magic_util.m: Avoid using polymorphism__type_info_or_ctor_type/2 and polymorphism__typeclass_info_class_constraint/2, as these are no longer supported. compiler/*.m: Straightforward changes to use the new ADT. library/injection.m: New library module. This provides an `injection' type which is similar to the existing `bimap' type in that it implements back-to-back maps, but doesn't have such stringent invariants imposed. In particular, the reverse map is not required to be injective. This type is used to model the relationship between prog_constraints and program variables that hold typeclass_infos for them. Namely, the typeclass_info for a constraint can be held in two different variables, but one variable can never hold the typeclass_info for two distinct constraints. library/library.m: Add the new library module. library/list.m: Add list__foldl_corresponding and list__foldl2_corresponding, which traverse two lists in parallel, which one or two accumulators, and abort if there is a length mismatch. NEWS: Mention the changes to the standard library. |
||
|
|
9b2f51460b |
A bunch of improvements for minimal model tabling.
Estimated hours taken: 4 Branches: main A bunch of improvements for minimal model tabling. compiler/code_info.m: Improve the code we generate for model_non disjunctions with --no-allow-hijacks, which is implied by the usual (stack copy) version of minimal model tabling. When the top stack frame is the current procedure's ordinary frame, and its redoip is still do_fail, then use that redoip. Its use is not hijacking, because we are not hiding any choice from the code in runtime/mercury_minimal_model.c that looks for right branches in the SLD tree to prune; do_fail represents the ABSENCE of such a right branch. compiler/table_gen.m: Instead of lying about the type of the one fixed argument of table_mm_answer_is_not_duplicate when hanging a foreign_proc that does several other things as well on that predicate, use a variant of that predicate with the right argument type specialized for this task. library/table_builtin.m: Provide table_mm_answer_is_not_duplicate_shortcut. library/table_builtin.m: runtime/mercury_tabling.h: Make the implementation of table_mm_answer_is_not_duplicate be a foreign_proc, not hand-written code, for simpler maintenance. We gain no speedup from keeping it handwritten; the implementation isn't even used with --tabling-via-extra-args, which is now the default. runtime/mercury_minimal_model.[ch]: Add some missing arguments on code inside a #ifdef, to make the code compile in dmm (debugging minimal model) grades. runtime/mercury_tabling.[ch]: Fix the name of a C function in its definition, and delete Julien's attempt at a fix of its declaration. |
||
|
|
4975ff1bcb |
Convert these files to four-space indendation to reduce the number
Estimated hours taken: 1 Branches: main compiler/code_info.m: compiler/disj_gen.m: Convert these files to four-space indendation to reduce the number of bad line breaks. |
||
|
|
b4d5df4162 |
Provide mechanisms for measuring individually the main sources of overheads
Estimated hours taken: 1 Branches: Provide mechanisms for measuring individually the main sources of overheads of minimal model tabling. This was required for the paper I have just finished with Kostis. runtime/mercury_stacks.h: Allow the inclusion of the extra nondet stack slot needed in minimal-model grades to be added even in non-minimal-model grades. compiler/options.m: Add two new options, --disable-mm-pneg and --disable-mm-cut, that ask the code generator not to generate code for manipulating the pneg stack and the cut stack respectively. Add two new options for internal use by the compiler only, that say whether the compiler should emit code for handling the pneg stack and cut stack respectively. None of the options is documented, since they are not for users. compiler/handle_options.m: Set the options to ask for the code for the pneg and cut stacks in minimal-model grades, unless the relevant disable option is given. compiler/code_info.m: compiler/ite_gen.m: Instead of testing the minimal model grade option to see whether to emit code for the cut stack and pneg stack respectively, test the relevant new option. |
||
|
|
c08ca7fbc8 |
Import only one module per line in the modules of the compiler
Estimated hours taken: 3 Branches: main compiler/*.m: Import only one module per line in the modules of the compiler where my previous diff did not already do so. Misc other cleanups. Where relevant, use the new mechanism in tree.m. compiler/tree.m: Fix a performance problem I noticed while update :- import_module items. Instead of supplying a function to convert lists of trees to a tree, make the tree data structure able to hold a list of subtrees directly. This reduces the number of times where we have to convert list of trees to trees that are sticks just to stay within the old definition of what a tree is. |
||
|
|
a3352a6e5d |
Do not include :- import_module' and :- use_module' declarations
Estimated hours taken: 22 Branches: main Do not include `:- import_module' and `:- use_module' declarations in the implementation section of .int and .int2 files unless the types that they export are required by the definition of an equivalence type. This should help prevent unnecessary recompilations when new imports are made in the implementation of modules. Break up check_hlds.type_util so that predicates that do not require access to the HLDS are placed in a new module, parse_tree.prog_type. The above change requires some of these predicates. This also removes one of the dependencies between the parse_tree package on modules of the check_hlds package. Remove the remaining such dependency by moving inst_constrains_unconstrained_var/1 from check_hlds.inst_util to parse_tree.prog_mode. None of the modules in parse_tree now depend upon modules in check_hlds. Modify the parser so that import_module declarations that specify more than one module are replaced by multiple import_module declarations, with one module per declaration. This makes the above change easier to implement and is in any case required by the upcoming diff for canonicalizing module interfaces. We also do the same for use_module and include_module declarations. compiler/modules.m: Don't import modules in the implementation section of interface files unless they are required by the definition of equivalence types. compiler/prog_type.m: New module. Move procedures from type_util that do not depend on the HLDS to here so that we can use them when generating interface files. XXX There are probably others that could be moved as well - I only moved those that were immediately useful. compiler/type_util.m: Delete the procedures that have been moved to the new prog_type module. compiler/prog_io.m: Remove the dependency on check_hlds.inst_util. compiler/prog_io_typeclass.m: compiler/equiv_type.m: Remove dependencies on check_hlds.type_util. compiler/prog_util.m: Add a predicate sym_name_get_module_name/2 that is similar to sym_name_get_module_name/3 except that it fails if the input is an unqualified sym_name. compiler/inst_util.m: Delete inst_contains_unconstrained_var/1 from this module and copy it to prog_mode.m. compiler/parse_tree.m: Include the new module. Do not import the check_hlds package as all dependencies on this package have been removed. compiler/*.m: Minor changes to conform to the above. compiler/notes/compiler_design.html: Mention the new module. |
||
|
|
59d2d4a573 |
This adds a module mdbcomp__trace_counts that reads in the
Estimated hours taken: 17 Branches: main This adds a module mdbcomp__trace_counts that reads in the .mercury_trace_counts files produced by the compiler's trace mechanism. The format of said files was slightly changed. As the new module is to be used by the compiler and the debugger, it is placed in the mdbcomp module. This required bringing some types from the compiler into a new module within mdbcomp. browser/trace_counts.m: New module for reading execution trace summaries. browser/prim_data.m: New module holding types and predicates moved in from the compiler. Types: pred_or_func, sym_name, module_name, proc_label, special_pred_id, trace_port Predicates: string_to_sym_name, insert_module_qualifier The mode field of proc_label is now an int instead of a proc_id to avoid pulling proc_id into mdbcomp. browser/mdbcomp.m: Add trace_counts and prim_data to the mdbcomp module. browser/declarative_execution.m: Renamed mdb's definition of module_name to flat_module_name to avoid conflicts with the definition in mdbcomp__prim_data. runtime/mercury_trace_base.c: In the format of .mercury_trace_counts, write module and predicate names now use quoted atom syntax so that names with spaces and non-printable characters can be machine-parsed. browser/: compiler/: Many changes to account for movement of types, and the change to proc_label. |
||
|
|
d03ce7dbc0 |
Fix some bugs in my previous diff that optimized away stack slots storing
Estimated hours taken: 8 Branches: main Fix some bugs in my previous diff that optimized away stack slots storing dummy values that manifested themselves as warnings from the C compiler about integers too big to fit into 8 or 16 bits being implicitly truncated. They did not lead to the failure of any test case, since it doesn't matter whether the debugger gets the values it ignores (I/O states or stores) from valid stack slots or not. When generating RTTI for gc and the debugger, the compiler had three places that generated references to stack slots: the return sites of calls, resume points, and trace events. The previous diff updated only the first of these. This diff updates the other two, and ensures there are no more. Since the debugger needs to know whether a procedure has a pair of I/O state arguments (e.g. when performing a retry), we add a field to proc layouts to hold this information. runtime/mercury_grade.h: Increment the debug grade runtime compatibility version number to reflect the change in layout structures. runtime/mercury_stack_layout.h: Add an extra field to proc layouts to specify flags. At the moment, the only flag says whether the procedure has a pair of I/O state arguments. Add an extra field to proc layouts to specify the trace level of a procedure. This used to be the same as the module's trace level, but one of my bug fixes a couple of months ago broke that link. We don't yet use this field, but it makes sense to do it at the same time as the increment of the compatibility version number. compiler/continuation_info.m: Attach to every description of a live value a description of where in the compiler that description was created. Rename the type involved to avoid an ambiguity. Ignore dummy types when generating resume layouts. Add some sanity checks. Add new fields to the continuation_info data structure to allow stack_layout.m to fill in the new fields in proc layout structures. compiler/trace.m: Do not generate references to dummy values at trace events, except at call ports. At those ports, all live variables should be in registers. compiler/stack_layout.m: Make the check for whether a value fits into an unsigned 8 bit value a direct rather than an indirect one. The indirect one assumed that stack slot numbers are all positive, which is now a bad assumption. Check for negative stack slot numbers in all RTTI stack slot descriptions. Fill in the two new slots in proc layout structures. compiler/layout.m: Reserve space for the two new slots in proc layout structures. compiler/layout_out.m: Output the two new slots in proc layout structures. compiler/code_gen.m: Preserve the information needed by stack_layout.m for the two new fields. compiler/llds_out.m: Add some code that ensures that we never output an integer constant that doesn't fit into the range of its type. Since this code is executed many millions of times, it is designed to be enabled only when the checking is manually enabled. It is normally off, but I got a clean bootcheck in the debug grade (which is the best stress test) with it enabled. compiler/trace_params.m: Update a comment. compiler/code_info.m: Export a function for use by trace.m. compiler/hlds_pred.m: Export a predicate for use by stack_layout.m. compiler/Mercury.options: Enable inlining for llds_out.m, to get rid of the sanity checking overhead if it is not enabled. tests/debugger/completion.exp*: tests/debugger/interpreter.exp*: tests/debugger/multi_parameter.exp*: tests/debugger/queens.exp*: tests/debugger/print_goal.exp*: tests/debugger/tabled_read.exp*: tests/debugger/tabled_read_decl.exp*: tests/debugger/declarative/io_stream_test.exp*: tests/debugger/declarative/tabled_read_decl.exp*: Update these expected output files to not expect dummy values that aren't kept anymore. |
||
|
|
b816836f02 |
Optimize away stack slots storing dummy values; values of the io__state and
Estimated hours taken: 8
Branches: main
Optimize away stack slots storing dummy values; values of the io__state and
store__store types.
compiler/stack_alloc.m:
Allocate distinct negative stack slot numbers to values of dummy types.
We need
compiler/hlds_pred.m:
Add a predicate for testing whether a value is of a dummy type.
compiler/code_into.m:
When constructing the list of live locations after a call, do not
include the negative stack slots containing dummy values. The list
of live locations is used by the (future) native collector, which
should ignore dummy types, and by the debugger. The debugger can't
do anything with these dummy values on the stack except tell the
user about their existence, which doesn't do the debugger user any
good.
We still keep liveness information about dummy values in registers
at calls and returns, since both the procedural and declarative
debuggers need to know procedures' full argument lists.
With respect to the list of live locations before the call, which
was used only by the (now extinct) value numbering optimization,
filter out all dummy types, since their values need not be preserved.
compiler/trace.m:
Do not ask the code generator to preserve values of dummy types,
since doing so would require referring to negative stack slots.
compiler/unify_gen.m:
compiler/var_locn.m:
Fix a couple of situations in which we could refer to the negative
stack slots we now allocate to dummy values.
compiler/call_gen.m:
Reorder some code to make the source match what happens at runtime.
compiler/llds_out.m:
Fix the formatting of the sanity check for negative stack slots.
compiler/handle_options.m:
Since the --debug-opt-pred-id option is useless without --debug-opt,
make --debug-opt-pred-id option imply --debug-opt. This was useful
in debugging this diff.
trace/mercury_trace.c:
Adapt the test for whether a retry is across I/O. We used to base the
test on whether the retried predicate has any I/O state arguments,
and if so, whether the original I/O state variable is still around
on the stack. After this change, the answer to the second half of
that question would always be "no", so we now use only the first half:
whether the retried predicate has any I/O state arguments. This
requires us to consider more retries to be retries across I/O, but
from the point of view of a user who may not remember whether the I/O
predicate has done any I/O so far or not, is arguably more consistent
than our previous policy.
Allow retries even if a value of type store.store is missing, since
store.store is a dummy type just as io.state is.
trace/mercury_trace.c:
compiler/type_util.m:
Document the fact that you need to update both these files if you
want to modify the set of dummy types.
tests/debugger/retry.{inp,exp,exp2}:
Due to the change in mercury_trace.c, one retry in this test case
changes to being retry over I/O. Update the test input to force this
retry over I/O, and expect the expanded input to be echoed in the
output.
tests/debugger/nondet_stack.{exp,exp2}:
Update these expected outputs to account for the fact that we now need
fewer stack slots to hold old I/O states when debugging is enabled.
|
||
|
|
90cdc14ef9 |
Optimize away instructions that move around dummy values; values of the
Estimated hours taken: 3 Branches: main Optimize away instructions that move around dummy values; values of the io__state and store__store types. (We still reserve stack slots for them; getting rid of that is future work.) compiler/var_locn.m: When moving values around, do not emit assignments that move around dummy values. Delete an unused predicate. compiler/code_info.m: Pass to var_locn.m the extra information it now needs. compiler/llds_out.m: Do not emit assignments for dummy arguments of foreign_procs. compiler/type_util.m: Make the code for checking whether a type is a dummy type use the existing predicate for finding the type constructor of a type. |
||
|
|
e854a5f9d9 |
Major improvements to tabling, of two types.
Estimated hours taken: 32
Branches: main
Major improvements to tabling, of two types. The first is the implementation
of the loopcheck and memo forms of tabling for model_non procedures, and the
second is a start on the implementation of a new method of implementing
minimal model tabling, one that has the potential for a proper fix of the
problem that we currently merely detect with the pneg stack (the detection
is followed by a runtime abort). Since this new method relies on giving each
own generator its own stack, the grade component denoting it is "mmos"
(minimal model own stack). The true name of the existing method is changed
from "mm" to "mmsc" (minimal model stack copy). The grade component "mm"
is now a shorthand for "mmsc"; when the new method works, "mm" will be changed
to be a shorthand for "mmos".
configure.in:
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/final_grade_options.sh-subr:
compiler/options.m:
Handle the new way of handling minimal model grades.
scripts/mgnuc.in:
compiler/compile_target_code.m:
Conform to the changes in minimal model grade options.
compiler/table_gen.m:
Implement the transformations required by the loopcheck and memo
tabling of model_non procedures, and the minimal model own stack
transformation.
The new implementation transformations use foreign_procs with extra
args, since there is no point in implementing them both that way and
with separate calls to library predicates. This required making the
choice of which method to use at the top level of each transformation.
Fix an oversight that hasn't caused problems yet but may in the future:
mark goals wrapping the original goals as not impure for determinism
computations.
compiler/handle_options.m:
Handle the new arrangement of the options for minimal model tabling.
Detect simultaneous calls for both forms of minimal model tabling,
and generate an error message. Allow for more than one error message
generated at once; report them all once rather than separately.
compiler/globals.m:
Add a mechanism to allow a fix a problem detected by the changes
to handle_options: the fact that we currently may generate a usage
message more than once for invocations with more than one error.
compiler/mercury_compile.m:
compiler/make.program_target.m:
compiler/make.util.m:
Use the new mechanism in handle_options to avoid generating duplicate
usage messages.
compiler/error_util.m:
Add a utility predicate for use by handle_options.
compiler/hlds_pred.m:
Allow memo tabling for model_non predicates, and handle own stack
tabling.
compiler/hlds_out.m:
Print information about the modes of the arguments of foreign_procs,
since this is useful in debugging transformations such as tabling
that generate them.
compiler/prog_data.m:
compiler/layout_out.m:
compiler/prog_out.m:
runtime/mercury_stack_layout.h:
Mention the new evaluation method.
compiler/goal_util.m:
Change the predicates for creating calls and foreign_procs to allow
more than one goal feature to be attached to the new goal. table_gen.m
now uses this capability.
compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/polymorphism.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/typecheck.m:
compiler/unify_proc.m:
Conform to the changes in goal_util.
compiler/code_info.m:
compiler/make_hlds.m:
compiler/modules.m:
compiler/prog_io_pragma.m:
Conform to the new the options controlling minimal model
tabling.
compiler/prog_util.m:
Add a utility predicate for use by table_gen.m.
library/std_util.m:
Conform to the changes in the macros for minimal model tabling grades.
library/table_builtin.m:
Add the types and predicates required by the new transformations.
Delete an obsolete comment.
runtime/mercury_grade.h:
Handle the new minimal model grade component.
runtime/mercury_conf_param.h:
List macros controlling minimal model grades.
runtime/mercury_tabling.[ch]:
Define the types needed by the new transformations,
Implement the performance-critical predicates that need to be
hand-written for memo tabling of model_non predicates.
Add utility predicates for debugging.
runtime/mercury_tabling_preds.h:
Add the implementations of the predicates required by the new
transformations.
runtime/mercury_mm_own_stacks.[ch]:
This new module contains the first draft of the implementation
of the own stack implementation of minimal model tabling.
runtime/mercury_imp.h:
Include the new file if the grade needs it.
runtime/Mmakefile:
Mention the new files, and sort the lists of filenames.
runtime/mercury_tabling_macros.h:
Add a macro for allocating answer blocks without requiring them to be
pointed to directly by trie nodes.
runtime/mercury_minimal_model.[ch]:
The structure type holding answer lists is now in mercury_tabling.h,
since it is now also needed by memo tabling of model_non predicates.
It no longer has a field for an answer num, because while it is ok
to require a separate grade for debugging minimal model tabling,
it is not ok to require a separate grade for debugging memo tabling
of model_non predicates. Instead of printing the answer numbers,
print the answers themselves when we need to identify solutions
for debugging.
Change function names, macro names, error messages etc where this is
useful to distinguish the two kinds of minimal model tabling.
Fix some oversights wrt transient registers.
runtime/mercury_context.[ch]:
runtime/mercury_engine.[ch]:
runtime/mercury_memory.[ch]:
runtime/mercury_wrapper.[ch]:
With own stack tabling, each subgoal has its own context, so record
the identity of the subgoal owning a context in the context itself.
The main computation's context is the exception: it has no owner.
Record not just the main context, but also the contexts of subgoals
in the engine.
Add variables for holding the sizes of the det and nondet stacks
of the contexts of subgoals (which should in general be smaller
than the sizes of the corresponding stacks of the main context),
and initialize them as needed.
Initialize the variables holding the sizes of the gen, cut and pneg
stacks, even in grades where the stacks are not used, for safety.
Fix some out-of-date documentation, and conform to our coding
guidelines.
runtime/mercury_memory_zones.[ch]:
Add a function to test whether a pointer is in a zone, to help
debugging.
runtime/mercury_debug.[ch]:
Add some functions to help debugging in the presence of multiple
contexts, and factor out some common code to help with this.
Delete the obsolete, unused function MR_printdetslot_as_label.
runtime/mercury_context.h:
runtime/mercury_bootstrap.h:
Move a bootstrapping #define from mercury_context.h to
mercury_bootstrap.h.
runtime/mercury_context.h:
runtime/mercury_bootstrap.h:
Move a bootstrapping #define from mercury_context.h to
mercury_bootstrap.h.
runtime/mercury_types.h:
Add some more forward declarations of type names.
runtime/mercury_dlist.[ch]:
Rename a field to avoid assignments that dereference NULL.
runtime/mercury_debug.c:
runtime/mercury_memory.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_stack_trace.c:
runtime/mercury_stacks.[ch]:
trace/mercury_trace_util.c
Update uses of the macros that control minimal model tabling.
runtime/mercury_stack_trace.c:
Provide a mechanism to allow stack traces to be suppressed entirely.
The intention is that by using this mechanism, by the testing system
won't have to provide separate .exp files for hlc grades, nondebug
LLDS grades and debug LLDS grades, as we do currently. The mechanism
is the environment variable MERCURY_SUPPRESS_STACK_TRACE.
tools/bootcheck:
tools/test_mercury:
Specify MERCURY_SUPPRESS_STACK_TRACE.
trace/mercury_trace.c:
When performing retries across tabled calls, handle memo tabled
model_non predicates, for which the call table tip variable holds
a record with a back pointer to a trie node, instead of the trie node
itself.
trace/mercury_trace_internal.c:
When printing tables, handle memo tabled model_non predicates. Delete
the code now moved to runtime/mercury_tabling.c.
Add functions for printing the data structures for own stack minimal
model tabling.
tests/debugger/print_table.{m,inp,exp}:
Update this test case to also test the printing of tables for
memo tabled model_non predicates.
tests/debugger/retry.{m,inp,exp}:
Update this test case to also test retries across memo tabled
model_non predicates.
tests/tabling/loopcheck_nondet.{m,exp}:
tests/tabling/loopcheck_nondet_non_loop.{m,exp}:
New test cases to test loopcheck tabled model_non predicates.
One test case has a loop to detect, one doesn't.
tests/tabling/memo_non.{m,exp}:
tests/tabling/tc_memo.{m,exp}:
tests/tabling/tc_memo2.{m,exp}:
New test cases to test memo tabled model_non predicates.
One test case has a loop to detect, one has a need for minimal model
tabling to detect, and the third doesn't have either.
tests/tabling/Mmakefile:
Add the new test cases, and reenable the existing tc_loop test case.
Rename some make variables and targets to make them better reflect
their meaning.
tests/tabling/test_mercury:
Conform to the change in the name of the make target.
|
||
|
|
7bf0cd03af |
Reduce the overhead of all forms of tabling by eliminating in many cases
Estimated hours taken: 32
Branches: main
Reduce the overhead of all forms of tabling by eliminating in many cases
the overhead of transferring data across the C/Mercury boundary. These
involve lots of control transfers as well as assignments to and from
Mercury abstract machine registers, which are not real machine registers
on x86 machines. Benchmarking in Uppsala revealed this overhead to be
a real problem.
The way we do that is by changing the tabling transformation so that instead
of generating sequences of calls to predicates from library/table_builtin.m,
we generate sequences of calls to C macros from runtime/mercury_tabling_pred.h,
and emit the resulting code string as the body of a foreign_proc goal.
(The old transformation is still available via a new option,
--no-tabling-via-extra-args.)
Since the number of inputs and outputs of the resulting C code sequences
are not always fixed (they can depend on the number of input or output
arguments of predicate being transformed), implementing this required
adding to foreign_procs a new field that allows the specification of extra
arguments to be passed to and from the given foreign code fragment. For now,
this mechanism is implemented only by the C backends, since it is needed
only by the C backends. (We don't support yet tabling on other backends.)
To simplify the new implementation of the field on foreign_procs, consolidate
three existing fields into one. Each of these fields was a list with one
element per argument, so turning them into a single list with a combined record
per argument should also improve reliability, since it reduces the likelyhood
of updates leaving the data structure inconsistent.
The goal paths of components of a tabled predicate depend on whether
-no-tabling-via-extra-args was specified. To enable the expected outputs
of the debugger test cases testing tabling, we add a new mdb command,
goal_paths, that controls whether goal paths are printed by the debugger
at events, and turn off the printing of events in the relevant test cases.
Also, prepare for a future change to optimize the trie structure for
user-defined types by handling type_infos (and once we support them,
typeclass_infos) specially.
compiler/table_gen.m:
Change the tabling transformation along the lines described above.
To allow us to factor out as much of the new code as possible,
we change the meaning of the call_table_tip variable for minimal
model subgoals: instead of the trie node at the end of the answer
table, it is not now the subgoal reachable from it. This change
has no effect as yet, because we use call_table_tip variables
only to perform resets across retries in the debugger, and we
don't do retries across calls to minimal model tabled predicates.
Put predicates into logical groups.
library/table_builtin.m:
runtime/mercury_tabling_preds.h:
When the new transformations in table_gen.m generate foreign_procs
with variable numbers of arguments, the interfaces of those
foreign_procs often do not match the interfaces of the existing
library predicates at their core: they frequently have one more
or one fewer argument. To prevent any possible confusion, in such
cases we add a new variant of the predicate. These predicates
have the suffix _shortcut in their name. Their implementations
are dummy macros that do nothing; they serve merely as placeholders
before or after which the macros that actually do the work are
inserted.
Move the definitions of the lookup, save and restore predicates
into mercury_tabling_preds.h. Make the naming scheme of their
arguments more regular.
runtime/mercury_minimal_model.c:
runtime/mercury_tabling_preds.h:
Move the definition of a predicate from mercury_minimal_model.c
to mercury_tabling_preds.h, since the compiler now needs to be
able to generate an inlined version of it.
compiler/hlds_goal.m:
Replace the three existing fields describing the arguments of
foreign_procs with one, and add a new field describing the extra
arguments that may be inserted by table_gen.m.
Add utility predicates for processing the arguments of foreign_procs.
Change the order of some existing groups of declarations make it
more logical.
compiler/hlds_pred.m:
runtime/mercury_stack_layout.h:
Extend the data structures recording the structure of tabling tries
to allow the representation of trie steps for type_infos and
typeclass_infos.
runtime/mercury_tabling_macros.c:
Fix a bug regarding the tabling of typeclass_infos, which is now
required for a clean compile.
compiler/pragma_c_gen.m:
compiler/ml_code_gen.m:
Modify the generation of code for foreign_procs to handle extra
arguments, and to conform to the new data structures for foreign_proc
arguments.
compiler/llds.m:
The tabling transformations can now generate significantly sized
foreign_procs bodies, which the LLDS code generator translates to
pragma_c instructions. Duplicating these by jump optimization
may lose more by worsening locality than it gains in avoiding jumps,
so we add an extra field to pragma_c instructions that tells jumpopt
not to duplicate code sequences containing such pragma_cs.
compiler/jumpopt.m:
Respect the new flag on pragma_cs.
compiler/goal_util.m:
Add a predicate to create foreign_procs with specified contents,
modelled on the existing predicate to create calls.
Change the order of the arguments of that existing predicate
to make it more logical.
compiler/polymorphism.m:
Conform to the new definition of foreign_procs. Try to simplify
the mechanism for generating the type_info and typeclass_info
arguments of foreign_proc goals, but it is not clear that this
code is even ever executed.
compiler/aditi_builtin_ops.m:
compiler/assertion.m:
compiler/bytecode_gen.m:
compiler/clause_to_proc.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/code_util.m:
compiler/constraint.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/dnf.m:
compiler/dupelim.m:
compiler/equiv_type_hlds.m:
compiler/exprn_aux.m:
compiler/follow_code.m:
compiler/follow_vars.m:
compiler/frameopt.m:
compiler/goal_form.m:
compiler/goal_path.m:
compiler/higher_order.m:
compiler/higher_order.m:
compiler/hlds_module.m:
compiler/hlds_out.m:
compiler/inlining.m:
compiler/ite_gen.m:
compiler/layout_out.m:
compiler/livemap.m:
compiler/liveness.m:
compiler/llds_out.m:
compiler/loop_inv.m:
compiler/magic.m:
compiler/make_hlds.m:
compiler/mark_static_terms.m:
compiler/middle_rec.m:
compiler/modes.m:
compiler/modules.m:
compiler/opt_debug.m:
compiler/pd_cost.m:
compiler/prog_rep.m:
compiler/purity.m:
compiler/quantification.m:
compiler/reassign.m:
compiler/rl_exprn.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/store_alloc.m:
compiler/stratify.m:
compiler/switch_detection.m:
compiler/term_pass1.m:
compiler/term_traversal.m:
compiler/termination.m:
compiler/trace.m:
compiler/typecheck.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unneeed_code.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
Conform to the new definition of foreign_procs, pragma_cs and/or
table trie steps, or to changed argument orders.
compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/cse_detection.m:
compiler/dead_proc_elim.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/lco.m:
compiler/module_util.m:
compiler/opt_util.m:
compiler/stack_opt.m:
compiler/trans_opt.m:
Conform to the new definition of foreign_procs.
Bring these modules up to date with our current code style guidelines,
using predmode declarations, state variable syntax and unification
expressions as appropriate.
compiler/mercury_compile.m:
Conform to the changed argument order of a predicate in trans_opt.m.
compiler/options.m:
Add the --no-tabling-via-extra-args option, but leave the
documentation commented out since the option is for developers only.
doc/user_guide.texi:
Document --no-tabling-via-extra-args option, though leave the
documentation commented out since the option is for developers only.
doc/user_guide.texi:
doc/mdb_categories:
Document the new goal_paths mdb command.
trace/mercury_trace_internals.c:
Implement the new goal_paths mdb command.
tests/debugger/completion.exp:
Conform to the presence of the goal_paths mdb command.
tests/debugger/mdb_command_test.inp:
Test the existence of documentation for the goal_paths mdb command.
tests/debugger/print_table.{inp,exp*}:
tests/debugger/retry.{inp,exp*}:
Use the goal_paths command to avoid having the expected output
depend on the presence or absence of --tabling-via-extra-args.
tests/tabling/table_foreign_output.{m,exp}:
Add a new test case to test the save/restore of arguments of foreign
types.
tests/tabling/Mmakefile:
Enable the new test case.
tests/tabling/test_tabling:
Make this script more robust.
Add an option for testing only the standard model forms of tabling.
|
||
|
|
cc508c83de |
Perform frame optimization on nondet predicates.
Estimated hours taken: 6 Branches: main Perform frame optimization on nondet predicates. The need for this was revealed by benchmarking in Uppsala, which initially showed Mercury to take three to five times as long as XSB on some tabling benchmarks. One major contributor was the fact that the predicate returning answers out of answer table was creating and destroying a nondet stack frame for every answer it returned. To make this change easier, make the representation of labels more reader friendly, classifying them primarily on whether they represent entry or internal labels, and only secondarily on the scope in which they represent valid references to the label. compiler/frameopt.m: Add a predicate to perform frame optimization on model_non predicates. This optimization involves separating the steps of creating the frame (done once) and setting the redoip (potentially done on every iteration). compiler/optimize.m: Invoke this new predicate. Reorder the arguments of predicates in this file, and the top level predicates of the optimizations it invokes, to allow the use of state variable notation. runtime/mercury_stacks.h: Provide macros for creating nondet stack frames that do not fill in the redoip slot. compiler/llds.m: Make the setting of redoip optional in mkframe operations. Make the representation of labels more reader friendly. compiler/layout_out.m: Change the representation of label layouts to enforce the invariant that these can refer only to internal labels. (The layout structures of entry labels are proc layout structures, whose design enforces the relevant invariant already.) compiler/jumpopt.m: Add an optimization that improves code that matches a new pattern: % Attempt to transform code such as % % if (Cond) L1 % goto L2 % % into % % if (! Cond) L2 % <code at L1> % % when we know the code at L1 and don't know the code at L2. The new frame optimization creates instances of this pattern, usually with L2 being do_fail. compiler/*.m: Minor diffs to conform to the changes above. |
||
|
|
bd1ea24cc3 |
Remove the dependence of this module on ll_backend.llds by defining
Estimated hours taken: 6 Branches: main compiler/hlds_llds.m: Remove the dependence of this module on ll_backend.llds by defining types using abstract descriptions of LLDS storage locations. These have the added advantage that they express the intent of the affected data structures more directly. For example, the stack slot type used to be able to map a variable to a register or to a field of a cell on the heap, which doesn't make sense. This is no longer the case. The cost of the conversion operations now required is partly paid for by our new ability to avoid some old sanity checks. compiler/llds.m: compiler/code_util.m: Add some utility predicates to operate on the new data structures. compiler/code_aux.m: compiler/code_gen.m: compiler/code_info.m: compiler/continuation_info.m: compiler/follow_vars.m: compiler/lookup_switch.m: compiler/par_conj_gen.m: compiler/stack_alloc.m: compiler/store_alloc.m: compiler/var_locn.m: Conform to the changes in hlds_llds.m. In some cases, improve the style of the affected predicates, e.g. by introducing state variable syntax. compiler/hlds_out.m: Conform to the changes in hlds_llds.m, and avoid importing ll_backend. |
||
|
|
c02e7a6c09 |
Fix bad indentation.
Estimated hours taken: 0.1 Branches: main compiler/code_info.m: Fix bad indentation. |
||
|
|
5d6fd3bd6f |
Reduce the dependence of earlier parts of the compiler on the later ones.
Estimated hours taken: 4 Branches: main Reduce the dependence of earlier parts of the compiler on the later ones. Unnecessary import_module declarations in top level modules such as hlds.m cause unnecessary recompilations when adding new types in later modules, such as submodules of ll_backend.m. This change reduces the number of such unnecessary imports. There are no changes in algorithms, only functionality being moved around. compiler/code_model.m: Change this module from being a submodule of backend_libs.m to being a submodule of hlds.m, since nothing in it is dependent on any backend. compiler/arg_info.m: compiler/code_util.m: Change arg_info.m from being a submodule of ll_backend.m to being a submodule of hlds.m, since most of it is applicable to all current and foreseeable backends. Move the one exported predicate that is ll_backend dependent, and its support predicates, to code_util.m. compiler/backend_libs.m: compiler/ll_backend.m: compiler/hlds.m: Update include_module declarations in accordance with the above. compiler/prog_data.m: compiler/term_util.m: Instead of defining two separate types for holding argument size and termination information, one including HLDS-specific information (in term_util.m) and one not (in prog_data.m), use a polymorphic type defined in prog_data.m and two monomorphic instances. compiler/termination.m: compiler/mercury_to_mercury.m: Change the predicates for writing out argument size and termination information to handle the polymorphic type (we don't need special handling of the monomorphic versions), and move them from termination.m to mercury_to_mercury.m, since this allows us to avoid some undesirable dependencies. compiler/base_typeclass_info.m: compiler/hlds_code_util.m: Move the predicate make_instance_string from base_typeclass_info.m to hlds_code_util.m, again because it allows us to remove some undesirable dependencies. compiler/top_level.m: compiler/backend_libs.m: compiler/check_hlds.m: compiler/hlds.m: compiler/ll_backend.m: compiler/parse_tree.m: compiler/transform_hlds.m: Delete some import_module declarations of other top level modules in these top level modules. Some imports were totally unnecessary. Some imports were useful in only a small minority of submodules; those submodules now import the necessary top level modules directly. Move remaining import_module declarations to the implementation section where this is feasible. Where we still need to import modules we ideally shouldn't, note why. compiler/*.m: Update imports of code_util and arg_info. In some cases, import top level modules no longer imported by the parent module. In some cases, delete unnecessary imports. |
||
|
|
f3e08a26d5 |
Another step towards supporting accurate GC for the LLDs back-end:
Estimated hours taken: 3 Branches: main Another step towards supporting accurate GC for the LLDs back-end: modify the LLDS code generator to allocate the proper forwarding pointer slots for type_infos and typeclass_infos. compiler/unify_gen.m: compiler/code_info.m: compiler/var_locn.m: When allocating type_infos or typeclass_infos on the heap, if accurate garbage collection is enabled then ensure that we reserve a word before the start of the object. This word is used by the collector to store a forwarding pointer. For ordinary objects, we store the forwarding pointer in the old copy of the object, but we can't clobber the old copies of type_infos and typeclass_infos, since they might be used _during_ garbage collection. |
||
|
|
82c6cdb55e |
Make definitions of abstract types available when generating
Estimated hours taken: 100
Branches: main
Make definitions of abstract types available when generating
code for importing modules. This is necessary for the .NET
back-end, and for `:- pragma export' on the C back-end.
compiler/prog_data.m:
compiler/modules.m:
compiler/make.dependencies.m:
compiler/recompilation.version.m:
Handle implementation sections in interface files.
There is a new pseudo-declaration `abstract_imported'
which is applied to items from the implementation
section of an interface file. `abstract_imported'
items may not be used in the error checking passes
for the curent module.
compiler/equiv_type_hlds.m:
compiler/notes/compiler_design.html:
New file.
Go over the HLDS expanding all types fully after
semantic checking has been run.
compiler/mercury_compile.m:
Add the new pass.
Don't write the `.opt' file if there are any errors.
compiler/instmap.m:
Add a predicate instmap_delta_map_foldl to apply
a procedure to all insts in an instmap.
compiler/equiv_type.m:
Export predicates for use by equiv_type_hlds.m
Reorder arguments so state variables and higher-order
programming can be used.
compiler/prog_data.m:
compiler/prog_io_pragma.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
Handle `:- pragma foreign_type' as a form of type
declaration rather than a pragma.
compiler/hlds_data.m:
compiler/*.m:
Add a field to the type_info_cell_constructor cons_id
to identify the type_ctor, which is needed by
equiv_type_hlds.m.
compiler/module_qual.m:
Donn't allow items from the implementation section of
interface files to match items in the current module.
compiler/*.m:
tests/*/*.m:
Add missing imports which only became apparent with
the bug fixes above.
Remove unnecessary imports which only became apparent with
the bug fixes above.
tests/hard_coded/Mmakefile:
tests/hard_coded/export_test2.{m,exp}:
Test case.
tests/invalid/Mmakefile:
tests/invalid/missing_interface_import2.{m,err_exp}:
Test case.
|
||
|
|
4c8ca5dd41 |
Add some comments, to address Zoltan's review comments on my
Estimated hours taken: 1 Branches: main compiler/code_info.m: compiler/var_locn.m: Add some comments, to address Zoltan's review comments on my previous change. |
||
|
|
3e89507352 |
Another step towards supporting accurate GC for the LLDs back-end:
Estimated hours taken: 3 Branches: main Another step towards supporting accurate GC for the LLDs back-end: modify the LLDS code generator to allocate the proper forwarding pointer slots for type_infos and typeclass_infos. compiler/unify_gen.m: compiler/code_info.m: compiler/var_locn.m: When allocating type_infos or typeclass_infos on the heap, if accurate garbage collection is enabled then ensure that we reserve a word before the start of the object. This word is used by the collector to store a forwarding pointer. For ordinary objects, we store the forwarding pointer in the old copy of the object, but we can't clobber the old copies of type_infos and typeclass_infos, since they might be used _during_ garbage collection. |
||
|
|
a2bf36e49a |
This diff contains no changes in algorithms whatsoever.
Estimated hours taken: 4 Branches: main This diff contains no changes in algorithms whatsoever. browser/*.m: compiler/*.m: library/*.m: Replace old-style lambdas with new-style lambdas or with named procedures. |
||
|
|
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. |
||
|
|
f007b45df8 |
Implement the infrastructure for term size profiling.
Estimated hours taken: 400
Branches: main
Implement the infrastructure for term size profiling. This means adding two
new grade components, tsw and tsc, and implementing them in the LLDS code
generator. In grades including tsw (term size words), each term is augmented
with an extra word giving the number of heap words it contains; in grades
including tsc (term size cells), each term is augmented with an extra word
giving the number of heap cells it contains. The extra word is at the start,
at offset -1, to leave almost all of the machinery for accessing the heap
unchanged.
For now, the only way to access term sizes is with a new mdb command,
"term_size <varspec>". Later, we will use term sizes in conjunction with
deep profiling to do experimental complexity analysis, but that requires
a lot more research. This diff is a necessary first step.
The implementation of term size profiling consists of three main parts:
- a source-to-source transform that computes the size of each heap cell
when it is constructed (and increments it in the rare cases when a free
argument of an existing heap cell is bound),
- a relatively small change to the code generator that reserves the extra
slot in new heap cells, and
- extensions to the facilities for creating cells from C code to record
the extra information we now need.
The diff overhauls polymorphism.m to make the source-to-source transform
possible. This overhaul includes separating type_ctor_infos and type_infos
as strictly as possible from each other, converting type_ctor_infos into
type_infos only as necessary. It also includes separating type_ctor_infos,
type_infos, base_typeclass_infos and typeclass_infos (as well as voids,
for clarity) from plain user-defined type constructors in type categorizations.
This change needs this separation because values of those four types do not
have size slots, but they ought to be treated specially in other situations
as well (e.g. by tabling).
The diff adds a new mdb command, term_size. It also replaces the proc_body
mdb command with new ways of using the existing print and browse commands
("print proc_body" and "browse proc_body") in order to make looking at
procedure bodies more controllable. This was useful in debugging the effect
of term size profiling on some test case outputs. It is not strictly tied
to term size profiling, but turns out to be difficult to disentangle.
compiler/size_prof.m:
A new module implementing the source-to-source transform.
compiler/notes/compiler_design.html:
Mention the new module.
compiler/transform_hlds.m:
Include size_prof as a submodule of transform_hlds.
compiler/mercury_compile.m:
If term size profiling is enabled, invoke its source-to-source
transform.
compiler/hlds_goal.m:
Extend construction unifications with an optional slot for recording
the size of the term if the size is a constant, or the identity of the
variable holding the size, if the size is not constant. This is
needed by the source-to-source transform.
compiler/quantification.m:
Treat the variable reference that may be in this slot as a nonlocal
variable of construction unifications, since the code generator needs
this.
compiler/compile_target_code.m:
Handle the new grade components.
compiler/options.m:
Implement the options that control term size profiling.
doc/user_guide.texi:
Document the options and grade components that control term size
profiling, and the term_size mdb command. The documentation is
commented out for now.
Modify the wording of the 'u' HLDS dump flag to include other details
of unifications (e.g. term size info) rather than just unification
categories.
Document the new alternatives of the print and browse commands. Since
they are for developers only, the documentation is commented out.
compiler/handle_options.m:
Handle the implications of term size profiling grades.
Add a -D flag value to print HLDS components relevant to HLDS
transformations.
compiler/modules.m:
Import the new builtin library module that implements the operations
needed by term size profiling automatically in term size profiling
grades.
Switch the predicate involved to use state var syntax.
compiler/prog_util.m:
Add predicates and functions that return the sym_names of the modules
needed by term size profiling.
compiler/code_info.m:
compiler/unify_gen.m:
compiler/var_locn.m:
Reserve an extra slot in heap cells and fill them in in unifications
marked by size_prof.
compiler/builtin_ops.m:
Add term_size_prof_builtin.term_size_plus as a builtin, with the same
implementation as int.+.
compiler/make_hlds.m:
Disable warnings about clauses for builtins while the change to
builtin_ops is bootstrapped.
compiler/polymorphism.m:
Export predicates that generate goals to create type_infos and
type_ctor_infos to add_to_construct.m. Rewrite their documentation
to make it more detailed.
Make orders of arguments amenable to the use of state variable syntax.
Consolidate knowledge of which type categories have builtin unify and
compare predicates in one place.
Add code to leave the types of type_ctor_infos alone: instead of
changing their types to type_info when used as arguments of other
type_infos, create a new variable of type type_info instead, and
use an unsafe_cast. This would make the HLDS closer to being type
correct, but this new code is currently commented out, for two
reasons. First, common.m is currently not smart enough to figure out
that if X and Y are equal, then similar unsafe_casts of X and Y
are also equal, and this causes the compiler do not detect some
duplicate calls it used to detect. Second, the code generators
are also not smart enough to know that if Z is an unsafe_cast of X,
then X and Z do not need separate stack slots, but can use the same
slot.
compiler/type_util.m:
Add utility predicates for returning the types of type_infos and
type_ctor_infos, for use by new code in polymorphism.m.
Move some utility predicates here from other modules, since they
are now used by more than one module.
Rename the type `builtin_type' as `type_category', to better reflect
what it does. Extend it to put the type_info, type_ctor_info,
typeclass_info, base_typeclass_info and void types into categories
of their own: treating these types as if they were a user-defined
type (which is how they used to be classified) is not always correct.
Rename the functor polymorphic_type to variable_type, since types
such as list(T) are polymorphic, but they fall into the user-defined
category. Rename user_type as user_ctor_type, since list(int) is not
wholly user-defined but falls into this category. Rename pred_type
as higher_order_type, since it also encompasses functions.
Replace code that used to check for a few of the alternatives
of this type with code that does a full switch on the type,
to ensure that they are updated if the type definition ever
changes again.
compiler/pseudo_type_info.m:
Delete a predicate whose updated implementation is now in type_util.m.
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
Still treat type_infos, type_ctor_infos, typeclass_infos and
base_typeclass_infos as user-defined types, but prepare for when
they won't be.
compiler/hlds_pred.m:
Require interface typeinfo liveness when term size profiling is
enabled.
Add term_size_profiling_builtin.increase_size as a
no_type_info_builtin.
compiler/hlds_out.m:
Print the size annotations on unifications if HLDS dump flags call
for unification details. (The flag test is in the caller of the
modified predicate.)
compiler/llds.m:
Extend incr_hp instructions and data_addr_consts with optional fields
that allow the code generator to refer to N words past the start of
a static or dynamic cell. Term size profiling uses this with N=1.
compiler/llds_out.m:
When allocating memory on the heap, use the macro variants that
specify an optional offset, and specify the offset when required.
compiler/bytecode_gen.m:
compiler/dense_switch.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/goal_form.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_match.m:
compiler/intermod.m:
compiler/jumpopt.m:
compiler/lambda.m:
compiler/livemap.m:
compiler/ll_pseudo_type_info.m:
compiler/lookup_switch.m:
compiler/magic_util.m:
compiler/middle_rec.m:
compiler/ml_code_util.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modecheck_unify.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/post_typecheck.m:
compiler/reassign.m:
compiler/rl.m:
compiler/rl_key.m:
compiler/special_pred.m:
compiler/stack_layout.m:
compiler/static_term.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
Minor updates to conform to the changes above.
library/term_size_prof_builtin.m:
New module containing helper predicates for term size profiling.
size_prof.m generates call to these predicates.
library/library.m:
Include the new module in the library.
doc/Mmakefile:
Do not include the term_size_prof_builtin module in the library
documentation.
library/array.m:
library/benchmarking.m:
library/construct.m:
library/deconstruct.m:
library/io.m:
library/sparse_bitset.m:
library/store.m:
library/string.m:
Replace all uses of MR_incr_hp with MR_offset_incr_hp, to ensure
that we haven't overlooked any places where offsets may need to be
specified.
Fix formatting of foreign_procs.
Use new macros defined by the runtime system when constructing
terms (which all happen to be lists) in C code. These new macros
specify the types of the cell arguments, allowing the implementation
to figure out the size of the new cell based on the sizes of its
fields.
library/private_builtin.m:
Define some constant type_info structures for use by these macros.
They cannot be defined in the runtime, since they refer to types
defined in the library (list.list and std_util.univ).
util/mkinit.c:
Make the addresses of these type_info structures available to the
runtime.
runtime/mercury_init.h:
Declare these type_info structures, for use in mkinit-generated
*_init.c files.
runtime/mercury_wrapper.[ch]:
Declare and define the variables that hold these addresses, for use
in the new macros for constructing typed lists.
Since term size profiling can refer to a memory cell by a pointer
that is offset by one word, register the extra offsets with the Boehm
collector if is being used.
Document the incompatibility of MR_HIGHTAGS and the Boehm collector.
runtime/mercury_tags.h:
Define new macros for constructing typed lists.
Provide macros for preserving the old interface presented by this file
to the extent possible. Uses of the old MR_list_cons macro will
continue to work in grades without term size profiling. In term
size profiling grades, their use will get a C compiler error.
Fix a bug caused by a missing backslash.
runtime/mercury_heap.h:
Change the basic macros for allocating new heap cells to take
an optional offset argument. If this is nonzero, the macros
increment the returned address by the given number of words.
Term size profiling specifies offset=1, reserving the extra
word at the start (which is ignored by all components of the
system except term size profiling) for holding the size of the term.
Provide macros for preserving the old interface presented by this file
to the extent possible. Since the old MR_create[123] and MR_list_cons
macros did not specify type information, they had to be changed
to take additional arguments. This affects only hand-written C code.
Call new diagnostic macros that can help debug heap allocations.
Document why the macros in this files must expand to expressions
instead of statements, evn though the latter would be preferable
(e.g. by allowing them to declare and use local variables without
depending on gcc extensions).
runtime/mercury_debug.[ch]:
Add diagnostic macros to debug heap allocations, and the functions
behind them if MR_DEBUG_HEAP_ALLOC is defined.
Update the debugging routines for hand-allocated cells to print the
values of the term size slot as well as the other slots in the relevant
grades.
runtime/mercury_string.h:
Provide some needed variants of the macro for copying strings.
runtime/mercury_deconstruct_macros.h:
runtime/mercury_type_info.c:
Supply type information when constructing terms.
runtime/mercury_deep_copy_body.h:
Preserve the term size slot when copying terms.
runtime/mercury_deep_copy_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_ml_expand_body.h:
Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
that allocate cells also allocate space for the term size slot if
necessary.
Reduce code duplication by using a now standard macro for copying
strings.
runtime/mercury_grade.h:
Handle the two new grade components.
runtime/mercury_conf_param.h:
Document the C macros used to control the two new grade components,
as well as MR_DEBUG_HEAP_ALLOC.
Detect incompatibilities between high level code and profiling.
runtime/mercury_term_size.[ch]:
A new module to house a function to find and return term sizes
stored in heap cells.
runtime/mercury_proc_id.h:
runtime/mercury_univ.h:
New header files. mercury_proc_id.h contains the (unchanged)
definition of MR_Proc_Id, while mercury_univ.h contains the
definitions of the macros for manipulating univs that used to be
in mercury_type_info.h, updated to use the new macros for allocating
memory.
In the absence of these header files, the following circularity
would ensue:
mercury_deep_profiling.h includes mercury_stack_layout.h
- needs definition of MR_Proc_Id
mercury_stack_layout.h needs mercury_type_info.h
- needs definition of MR_PseudoTypeInfo
mercury_type_info.h needs mercury_heap.h
- needs heap allocation macros for MR_new_univ_on_hp
mercury_heap.h includes mercury_deep_profiling.h
- needs MR_current_call_site_dynamic for recording allocations
Breaking the circular dependency in two places, not just one, is to
minimize similar problems in the future.
runtime/mercury_stack_layout.h:
Delete the definition of MR_Proc_Id, which is now in mercury_proc_id.h.
runtime/mercury_type_info.h:
Delete the macros for manipulating univs, which are now in
mercury_univ.h.
runtime/Mmakefile:
Mention the new files.
runtime/mercury_imp.h:
runtime/mercury.h:
runtime/mercury_construct.c:
runtime/mercury_deep_profiling.h:
Include the new files at appropriate points.
runtime/mercury.c:
Change the names of the functions that create heap cells for
hand-written code, since the interface to hand-written code has
changed to include type information.
runtime/mercury_tabling.h:
Delete some unused macros.
runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
Use the new macros supplying type information when constructing lists.
scripts/canonical_grade_options.sh-subr:
Fix an undefined sh variable bug that could cause error messages
to come out without identifying the program they were from.
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade_options.sh-subr:
scripts/mgnuc.in:
Handle the new grade components and the options controlling them.
trace/mercury_trace_internal.c:
Implement the mdb command "term_size <varspec>", which is like
"print <varspec>", but prints the size of a term instead of its value.
In non-term-size-profiling grades, it prints an error message.
Replace the "proc_body" command with optional arguments to the "print"
and "browse" commands.
doc/user_guide.tex:
Add documentation of the term_size mdb command. Since the command is
for implementors only, and works only in grades that are not yet ready
for public consumption, the documentation is commented out.
Add documentation of the new arguments of the print and browse mdb
commands. Since they are for implementors only, the documentation
is commented out.
trace/mercury_trace_vars.[ch]:
Add the functions needed to implement the term_size command, and
factor out the code common to the "size" and "print"/"browse" commands.
Decide whether to print the name of a variable before invoking the
supplied print or browse predicate on it based on a flag design for
this purpose, instead of overloading the meaning of the output FILE *
variable. This arrangement is much clearer.
trace/mercury_trace_browse.c:
trace/mercury_trace_external.c:
trace/mercury_trace_help.c:
Supply type information when constructing terms.
browser/program_representation.m:
Since the new library module term_size_prof_builtin never generates
any events, mark it as such, so that the declarative debugger doesn't
expect it to generate any.
Do the same for the deep profiling builtin module.
tests/debugger/term_size_words.{m,inp,exp}:
tests/debugger/term_size_cells.{m,inp,exp}:
Two new test cases, each testing one of the new grades.
tests/debugger/Mmakefile:
Enable the two new test cases in their grades.
Disable the tests sensitive to stack frame sizes in term size profiling
grades.
tests/debugger/completion.exp:
Add the new "term_size" mdb command to the list of command completions,
and delete "proc_body".
tests/debugger/declarative/dependency.{inp,exp}:
Use "print proc_body" instead of "proc_body".
tests/hard_coded/nondet_c.m:
tests/hard_coded/pragma_inline.m:
Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
that allocate cells also allocate space for the term size slot if
necessary.
tests/valid/Mmakefile:
Disable the IL tests in term size profiling grades, since the term size
profiling primitives haven't been (and probably won't be) implemented
for the MLDS backends, and handle_options causes a compiler abort
for grades that combine term size profiling and any one of IL, Java
and high level C.
|
||
|
|
6554ef7daa |
Replace "is" with "=".
Estimated hours taken: 2 Branches: main Replace "is" with "=". Add field names where relevant. Replace integers with counters where relevant. |
||
|
|
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. |
||
|
|
cbd6a7c56a |
Delete the old, lazy LLDS code generator, since we won't be maintaining it
Estimated hours taken: 3 Branches: main Delete the old, lazy LLDS code generator, since we won't be maintaining it anymore. Its deletion speeds up the compiler by 0.2% when using the LLDS back end. compiler/code_exprn.m: Delete the module. compiler/ll_backend.m: Delete code_exprn from the list of submodules of this module. compiler/notes/compiler_design.html: Delete the documentation of code_exprn.m, and update the documentation of var_locn.m. compiler/options.m: Delete the --lazy-code option that used to select code_exprn over var_locn. Delete the follow_vars option, since the LLDS backend now always executes the follow_vars pass. compiler/handle_options.m: Delete the code setting the follow_vars option. Make the setting of static_ground_terms conditional on the use of the LLDS backend (which now implies the eager code generator). compiler/code_info.m: Delete lots of code that switches between code_exprn.m and var_locn.m. Simplify the data structures accordingly. compiler/store_alloc.m: Delete the code and data structures required to cater for the case where the follow_vars pass isn't run. compiler/pragma_c_gen.m: compiler/var_locn.m: compiler/hlds_goal.m: compiler/lookup_switch.m: Update a comment. doc/user_guide.texi: Delete the documentation of --follow-vars. --lazy-code was already undocumented. tests/valid/Mercury.options: Delete a setting of --no-follow-vars. |
||
|
|
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. |
||
|
|
1cb657b998 |
Reduce inappropriate dependencies on ll_backend modules.
Estimated hours taken: 3 Branches: main Reduce inappropriate dependencies on ll_backend modules. Except for simplification of unnecessarily complicated logic in dependency_graph.m, this change only moves functionality around. compiler/llds_out.m: compiler/c_util.m: compiler/name_mangle.m: Move predicates that are used by multiple backends from ll_backend__llds_out to backend_libs__c_util and to a new module backend_libs__name_mangle. Make the relevant ones functions, and give some of them more meaningful names. compiler/trace.m: compiler/hlds_goal.m: Move a backend-independent predicate from ll_backend__trace to hlds__hlds_goal. compiler/llds.m: compiler/trace_params.m: Move the definition of the trace_port type from ll_backend__llds to libs__trace_params to avoid having libs__trace_params depend on ll_backend. compiler/exprn_aux.m: compiler/globals.m: Move the definition of the imported_is_constant from ll_backend__exprn_aux to libs__globals to avoid having libs__globals depend on ll_backend. compiler/*.m: Conform to the above changes. This removes many inappropriate dependencies on the LLDS backend. |
||
|
|
d3e315ffd2 |
Move functionality that is not part of the LLDS backend from
Estimated hours taken: 1 Branches: main compiler/code_util.m: compiler/goal_form.m: compiler/hlds_code_util.m: Move functionality that is not part of the LLDS backend from ll_backend__code_util to hlds__goal_form and to hlds__hlds_code_util. Turn some predicates into functions. compiler/*.m: Conform to the changes above. |
||
|
|
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. |
||
|
|
37e1c49f78 |
Implement a flag that can be used by the compiler to signal to the debugger
Estimated hours taken: 1 Branches: main Implement a flag that can be used by the compiler to signal to the debugger that some events should be hidden from the user. The flag is not used yet. compiler/continuation_info.m: compiler/layout.m: Make room for the flag in the data structures storing information about events. compiler/layout_out.m: Output the flag in label layouts. runtime/mercury_stack_layout.h: Define a field for the flag in label layouts. compiler/trace.m: Specify "no" as the value of the hidden flag, for now. Later, when we add hidden events, we will specify "yes" for them. compiler/code_info.m: compiler/stack_layout.m: Pass on the value of the hidden flag. |
||
|
|
f4d3f98066 |
Make newlines line terminators, not line separators, in C code constructed by
Estimated hours taken: 0.2 Branches: main Make newlines line terminators, not line separators, in C code constructed by the compiler. This makes it easier to put such C code fragments together and get nice looking code. compiler/llds_out.m: Do not add a newline at the end of such C code fragments. compiler/code_info.m: compiler/trace.m: Adjust the formatting of compiler-generated C code fragments accordingly. |
||
|
|
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).
|
||
|
|
0b2c0c6b6c |
Remove the code that reserves two stack slots for declarative debugging.
Estimated hours taken: 0.5 Branches: main Remove the code that reserves two stack slots for declarative debugging. Now that code for MR_USE_DECL_STACK_SLOT no longer exists, there is no chance that the stack slots will be required. compiler/layout.m: Remove the maybe_decl_debug_slot field from proc_layout_exec_trace. compiler/layout_out.m: Don't print the field that was just removed. Update a couple of comments. compiler/trace.m: Remove the slot_decl field from trace_slot_info. Don't reserve the two slots. compiler/llds_common.m: compiler/code_info.m: compiler/stack_layout.m: Propagate the effects of the above changes. compiler/trace_params.m: Remove trace_level_needs_decl_debug_slots. runtime/mercury_stack_layout.h: Remove the MR_exec_maybe_decl_debug field from MR_Exec_Trace. runtime/mercury_conf_param.h: Don't document MR_USE_DECL_STACK_SLOT. trace/mercury_trace_declarative.c: Remove the prototypes of two unused functions whose definitions were removed earlier. |
||
|
|
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. |
||
|
|
41a27af862 |
Change type_id to the more descriptive type_ctor everywhere.
Estimated hours taken: 6 Branches: main compiler/*.m: Change type_id to the more descriptive type_ctor everywhere. |