mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 21:35:49 +00:00
e62c7da10c7643d6ccb39accb530e1254974b32c
53 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
5df1cedc11 |
s/goal_cannot_loop/goal_cannot_loop_or_throw/ throughout
Estimated hours taken: 0.5 Branches: main compiler/constraint.m: compiler/deforest.m: compiler/goal_util.m: compiler/simplify.m: compiler/rl.m: s/goal_cannot_loop/goal_cannot_loop_or_throw/ throughout the optimization passes. This is needed to avoid optimizing away calls to error/1 now that it is marked as terminating. compiler/pd_util.m: Remove a duplicate of goal_util__reordering_maintains_termination. |
||
|
|
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. |
||
|
|
9551640f55 |
Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2 Branches: main compiler/*.m: Import only one compiler module per line. Sort the blocks of imports. This makes it easier to merge in changes. In a couple of places, remove unnecessary imports. |
||
|
|
129f605d25 |
Fix bugs in the handling of purity in the optimization passes
Estimated hours taken: 8
Branches: main, release
Fix bugs in the handling of purity in the optimization passes
(in particular constraint propagation), which caused purity
annotations on goals to be lost. This caused
tests/tabling/unused_args to fail on earth.
compiler/hlds_goal.m:
Make the version of goal_info_init called from
the optimization passes take the purity as an
argument. Previously, callers were constructing
a goal_info then adding the purity, which was
error prone.
compiler/hlds_goal.m:
compiler/purity.m:
Move the predicates to deal with purity representation
in hlds_goal_infos into hlds_goal.m. Rationale -
goal_info_get_determinism is not in det_analysis.m,
goal_info_get_nonlocals is not in quantification.m, etc.
This makes it easier to make the purity setting code
efficient.
Don't allocate memory in add_goal_info_purity_feature
if the call doesn't change the purity.
compiler/*.m:
Pass the extra argument to goal_info_init.
compiler/polymorphism.m:
Remove a duplicate definition of
hlds_goal__make_int_const_construction.
compiler/magic.m:
Remove some unused code.
tests/hard_coded/purity/Mmakefile:
tests/hard_coded/purity/Mercury.options:
tests/hard_coded/purity/purity_opt.{m,exp}:
Test case.
|
||
|
|
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.
|
||
|
|
c980ee58d8 |
Split code_aux.m into two. The part that remains in code_aux.m needs stuff
Estimated hours taken: 1 Branches: main Split code_aux.m into two. The part that remains in code_aux.m needs stuff from the LLDS back end. The part that moves out (to the new file goal_form) doesn't. This removes several unnecessary dependencies on the LLDS back end. compiler/goal_form.m: The predicates from code_aux that test goals for having particular forms. It is part of the hlds module. compiler/code_aux.m: Delete the predicates that moved to goal_form.m. compiler/*.m: Fix module qualifications and module imports to account for the above change. In the process, sort module imports into groups. |
||
|
|
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. |
||
|
|
a456c011d3 |
Don't attempt to move complex goals into other goals,
Estimated hours taken: 1 Branches: main compiler/constraint.m: Don't attempt to move complex goals into other goals, to avoid increases in code size. (A complex goal is anything other than an atomic goal, or a quantification or a negation of an atomic goal). |
||
|
|
311d0af1e5 |
Constraint propagation.
Estimated hours taken: 90
Constraint propagation.
compiler/constraint.m:
Push constraints left and inwards as much as possible
within a goal. This module has been completely rewritten.
compiler/deforest.m:
Push constraints within a goal before processing it.
Make specialized versions for calls with constrained outputs.
Rerun determinism inference on specialized versions
when constraint propagation has been run, because the
determinism can change from nondet to semidet.
compiler/pd_util.m:
Add pd_util__propagate_constraints, which uses constraint.m
to push constraints within a goal.
Add some documentation for the exported predicates.
compiler/pd_term.m:
Add support for checking termination of the optimization process
for constraint propagation, which differs from deforestation
in that the conjunctions selected for optimization don't
necessarily have a call at both ends.
compiler/pd_debug.m:
Print some extra information when `--debug-pd' is enabled.
compiler/mercury_compile.m:
Check whether constraint propagation should be performed when
working out whether to run the deforestation pass.
compiler/make_hlds.m:
Add `no_inline' markers to the "recursive" procedures
introduced for builtins to stop constraint propagation
attempting to specialize such procedures.
compiler/hlds_pred.m:
Don't fill in the declared determinism field of the predicates
introduced by `hlds_pred__define_new_pred', so that rerunning
determinism inference will compute a more accurate determinism.
compiler/inlining.m:
Requantify before recomputing instmap_deltas, not after.
compiler/det_report.m:
Add predicates to disable warnings when rerunning
determinism analysis after constraint propagation.
compiler/options.m:
Add documentation for `--constraint-propagation'.
Add option `--local-constraint-propagation', which makes
deforestation call constraint.m to move constraints within
a goal, but does not create specialized versions of procedures
for which there are calls with constrained outputs.
compiler/handle_options.m:
`--constraint-propagation' implies `--local-constraint-propagation'.
compiler/notes/compiler_design.html:
Change the documentation to show that constraint.m is now part
of the deforestation pass.
NEWS:
Announce the new transformation.
doc/user_guide.texi:
Document the new options.
tests/hard_coded/Mmakefile:
tests/hard_coded/constraint.{m,exp}:
tests/hard_coded/constraint_order.{m,exp}:
Test cases.
|
||
|
|
2725b1a331 |
Aditi update syntax, type and mode checking.
Estimated hours taken: 220
Aditi update syntax, type and mode checking.
Change the hlds_goal for constructions in preparation for
structure reuse to avoid making multiple conflicting changes.
compiler/hlds_goal.m:
Merge `higher_order_call' and `class_method_call' into a single
`generic_call' goal type. This also has alternatives for the
various Aditi builtins for which type declarations can't
be written.
Remove the argument types field from higher-order/class method calls.
It wasn't used often, and wasn't updated by optimizations
such as inlining. The types can be obtained from the vartypes
field of the proc_info.
Add a `lambda_eval_method' field to lambda_goals.
Add a field to constructions to identify which RL code fragment should
be used for an top-down Aditi closure.
Add fields to constructions to hold structure reuse information.
This is currently ignored -- the changes to implement structure
reuse will be committed to the alias branch.
This is included here to avoid lots of CVS conflicts caused by
changing the definition of `hlds_goal' twice.
Add a field to `some' goals to specify whether the quantification
can be removed. This is used to make it easier to ensure that
indexes are used for updates.
Add a field to lambda_goals to describe whether the modes were
guessed by the compiler and may need fixing up after typechecking
works out the argument types.
Add predicate `hlds_goal__generic_call_id' to work out a call_id
for a generic call for use in error messages.
compiler/purity.m:
compiler/post_typecheck.m:
Fill in the modes of Aditi builtin calls and closure constructions.
This needs to know which are the `aditi__state' arguments, so
it must be done after typechecking.
compiler/prog_data.m:
Added `:- type sym_name_and_arity ---> sym_name/arity'.
Add a type `lambda_eval_method', which describes how a closure
is to be executed. The alternatives are normal Mercury execution,
bottom-up execution by Aditi and top-down execution by Aditi.
compiler/prog_out.m:
Add predicate `prog_out__write_sym_name_and_arity', which
replaces duplicated inline code in a few places.
compiler/hlds_data.m:
Add a `lambda_eval_method' field to `pred_const' cons_ids and
`pred_closure_tag' cons_tags.
compiler/hlds_pred.m:
Remove type `pred_call_id', replace it with type `simple_call_id',
which combines a `pred_or_func' and a `sym_name_and_arity'.
Add a type `call_id' which describes all the different types of call,
including normal calls, higher-order and class-method calls
and Aditi builtins.
Add `aditi_top_down' to the type `marker'.
Remove `aditi_interface' from type `marker'. Interfacing to
Aditi predicates is now handled by `generic_call' hlds_goals.
Add a type `rl_exprn_id' which identifies a predicate to
be executed top-down by Aditi.
Add a `maybe(rl_exprn_id)' field to type `proc_info'.
Add predicate `adjust_func_arity' to convert between the arity
of a function to its arity as a predicate.
Add predicates `get_state_args' and `get_state_args_det' to
extract the DCG state arguments from an argument list.
Add predicate `pred_info_get_call_id' to get a `simple_call_id'
for a predicate for use in error messages.
compiler/hlds_out.m:
Write the new representation for call_ids.
Add a predicate `hlds_out__write_call_arg_id' which
replaces similar code in mode_errors.m and typecheck.m.
compiler/prog_io_goal.m:
Add support for `aditi_bottom_up' and `aditi_top_down' annotations
on pred expressions.
compiler/prog_io_util.m:
compiler/prog_io_pragma.m:
Add predicates
- `prog_io_util:parse_name_and_arity' to parse `SymName/Arity'
(moved from prog_io_pragma.m).
- `prog_io_util:parse_pred_or_func_name_and_arity to parse
`pred SymName/Arity' or `func SymName/Arity'.
- `prog_io_util:parse_pred_or_func_and_args' to parse terms resembling
a clause head (moved from prog_io_pragma.m).
compiler/type_util.m:
Add support for `aditi_bottom_up' and `aditi_top_down' annotations
on higher-order types.
Add predicates `construct_higher_order_type',
`construct_higher_order_pred_type' and
`construct_higher_order_func_type' to avoid some code duplication.
compiler/mode_util.m:
Add predicate `unused_mode/1', which returns `builtin:unused'.
Add functions `aditi_di_mode/0', `aditi_ui_mode/0' and
`aditi_uo_mode/0' which return `in', `in', and `out', but will
be changed to return `di', `ui' and `uo' when alias tracking
is implemented.
compiler/goal_util.m:
Add predicate `goal_util__generic_call_vars' which returns
any arguments to a generic_call which are not in the argument list,
for example the closure passed to a higher-order call or
the typeclass_info for a class method call.
compiler/llds.m:
compiler/exprn_aux.m:
compiler/dupelim.m:
compiler/llds_out.m:
compiler/opt_debug.m:
Add builtin labels for the Aditi update operations.
compiler/hlds_module.m:
Add predicate predicate_table_search_pf_sym, used for finding
possible matches for a call with the wrong number of arguments.
compiler/intermod.m:
Don't write predicates which build `aditi_top_down' goals,
because there is currently no way to tell importing modules
which RL code fragment to use.
compiler/simplify.m:
Obey the `cannot_remove' field of explicit quantification goals.
compiler/make_hlds.m:
Parse Aditi updates.
Don't typecheck clauses for which syntax errors in Aditi updates
are found - this avoids spurious "undefined predicate `aditi_insert/3'"
errors.
Factor out some common code to handle terms of the form `Head :- Body'.
Factor out common code in the handling of pred and func expressions.
compiler/typecheck.m:
Typecheck Aditi builtins.
Allow the argument types of matching predicates to be adjusted
when typechecking the higher-order arguments of Aditi builtins.
Change `typecheck__resolve_pred_overloading' to take a list of
argument types rather than a `map(var, type)' and a list of
arguments to allow a transformation to be performed on the
argument types before passing them.
compiler/error_util.m:
Move the part of `report_error_num_args' which writes
"wrong number of arguments (<x>; expected <y>)" from
typecheck.m for use by make_hlds.m when reporting errors
for Aditi builtins.
compiler/modes.m:
compiler/unique_modes.m:
compiler/modecheck_call.m:
Modecheck Aditi builtins.
compiler/lambda.m:
Handle the markers for predicates introduced for
`aditi_top_down' and `aditi_bottom_up' lambda expressions.
compiler/polymorphism.m:
Add extra type_infos to `aditi_insert' calls
describing the tuple to insert.
compiler/call_gen.m:
Generate code for Aditi builtins.
compiler/unify_gen.m:
compiler/bytecode_gen.m:
Abort on `aditi_top_down' and `aditi_bottom_up' lambda
expressions - code generation for them is not yet implemented.
compiler/magic.m:
Use the `aditi_call' generic_call rather than create
a new procedure for each Aditi predicate called from C.
compiler/rl_out.pp:
compiler/rl_gen.m:
compiler/rl.m:
Move some utility code used by magic.m and call_gen.m into rl.m.
Remove an XXX comment about reference counting being not yet
implemented - Evan has fixed that.
library/ops.m:
compiler/mercury_to_mercury.m:
doc/transition_guide.texi:
Add unary prefix operators `aditi_bottom_up' and `aditi_top_down',
used as qualifiers on lambda expressions.
Add infix operator `==>' to separate the tuples in an
`aditi_modify' call.
compiler/follow_vars.m:
Thread a `map(prog_var, type)' through, needed because
type information is no longer held in higher-order call goals.
compiler/table_gen.m:
Use the `make_*_construction' predicates in hlds_goal.m
to construct constants.
compiler/*.m:
Trivial changes to add extra fields to hlds_goal structures.
doc/reference_manual.texi:
Document Aditi updates.
Use @samp{pragma base_relation} instead of
@samp{:- pragma base_relation} throughout the Aditi documentation
to be consistent with other parts of the reference manual.
tests/valid/Mmakefile:
tests/valid/aditi_update.m:
tests/valid/aditi.m:
Test case.
tests/valid/Mmakefile:
Remove some hard-coded --intermodule-optimization rules which are
no longer needed because `mmake depend' is now run in this directory.
tests/invalid/*.err_exp:
Fix expected output for changes in reporting of call_ids
in typecheck.m.
tests/invalid/Mmakefile
tests/invalid/aditi_update_errors.{m,err_exp}:
tests/invalid/aditi_update_mode_errors.{m,err_exp}:
Test error messages for Aditi updates.
tests/valid/aditi.m:
tests/invalid/aditi.m:
Cut down version of extras/aditi/aditi.m to provide basic declarations
for Aditi compilation such as `aditi__state' and the modes
`aditi_di', `aditi_uo' and `aditi_ui'. Installing extras/aditi/aditi.m
somewhere would remove the need for these.
|
||
|
|
8d41d4200a |
Fix some old problems with HLDS dumps, including blank lines between goals
Estimated hours taken: 4
Fix some old problems with HLDS dumps, including blank lines between goals
(using vi's paragraph commands to move between predicates now works),
unescaped characters in strings and chars in unifications, and extra dots
in type definitions.
compiler/hlds_out.m:
Make the above fixes. To fix the problem of blank lines between goals,
we reinterpret the meaning of the Follow arguments of several
predicates that print goals, which say what to print after the
goal, to include the newline to print after the goal. This avoids
lots of separate calls to io__write_string("\n").
Document the meanings of the arguments of many predicates.
compiler/prog_out.m:
Modify prog_out__write_sym_name to escape any special characters
(e.g. newlines) in the symbols written. (Strings, as cons_ids,
are printed as symbols.)
Add a new predicate for printing a symbol with single forward quotes
around it.
compiler/mercury_to_mercury:
When printing cons_id, quote strings.
compiler/constraint.m:
compiler/mode_errors.m:
compiler/pd_debug.m:
compiler/rl_dump.m:
compiler/saved_vars.m:
Conform to the new meaning of the Follow arguments in hlds_out.m.
|
||
|
|
5c955626f2 |
These changes make var' and term' polymorphic.
Estimated hours taken: 20 These changes make `var' and `term' polymorphic. This allows us to make variables and terms representing types of a different type to those representing program terms and those representing insts. These changes do not *fix* any existing problems (for instance there was a messy conflation of program variables and inst variables, and where necessary I've just called varset__init(InstVarSet) with an XXX comment). NEWS: Mention the changes to the standard library. library/term.m: Make term, var and var_supply polymorphic. Add new predicates: term__generic_term/1 term__coerce/2 term__coerce_var/2 term__coerce_var_supply/2 library/varset.m: Make varset polymorphic. Add the new predicate: varset__coerce/2 compiler/prog_data.m: Introduce type equivalences for the different kinds of vars, terms, and varsets that we use (tvar and tvarset were already there but have been changed to use the polymorphic var and term). Also change the various kinds of items to use the appropriate kinds of var/varset. compiler/*.m: Thousands of boring changes to make the compiler type correct with the different types for type, program and inst vars and varsets. |
||
|
|
a70b59e83c |
Add a test to find the number of words needed to represent a
configure.in:
Add a test to find the number of words needed to represent a
synchronization term.
boehm_gc/gc.h:
fix a declaration by replacing the args () with (void).
boehm_gc/solaris_pthreads.c:
add a missing include
check the return values of pthread calls.
compiler/*.m:
Add handling for the new HLDS goal type par_conj.
Add handling for the four new LLDS instructions:
init_sync_term
fork
join_and_terminate
join_and_continue
compiler/code_info.m:
add a new alternative for slot_contents - sync_term.
compiler/handle_options.m:
add .par as part of the grade
compiler/hlds_goal.m:
add the new goal type par_conj.
compiler/instmap.m:
add instmap__unify which takes a list of instmaps
and abstractly unifies them.
add unify_instmap_delta which tajes two instmap deltas
and abstractly unifies them.
compiler/llds.m:
add the new llds instructions.
compiler/mode_info.m:
add par_conj as a lock reason.
library/Makefile:
work around a bug in the solaris version pthread.h
library/benchmarking.m:
reference the stack zones from the engine structure
rather than from global variables.
library/{nc,sp}_builtin.nl:
add an op declaration for &.
library/std_util.m:
change references to global variables to references inside
the engine structure.
runtime/Mmakefile:
add mercury_thread.{c,h}
add THREADLIBS to the libraries
runtime/*.{c,h}
Remove some old junk from the previous processes/shrd-mem
changes that found their way into the repository.
Add MR_ prefixes to lots of names.
runtime/mercury_context.c:
Add init_thread_stuff for creating and initializing a
context structure for the current thread.
runtime/mercury_context.h:
add a field to the mercury context which stores the thread id
of the thread where this context originated.
add various macros for implementing the new llds instructions.
runtime/mercury_engine.c:
initialize the engine structure, rather than a bunch of globals.
runtime/mercury_engine.h:
declare the mercury_engine structure.
runtime/mercury_regorder.h:
if MR_THREAD_SAFE, and there is at least one global register
then use mr0 as a pointer to the mercury engine structure.
scripts/init_grade_options.sh-subr
add thread_safe
scripts/mgnuc.in
add THREAD_OPTS
scripts/ml.in:
add THREAD_LIBS
|
||
|
|
75354e38bb |
Deforestation.
Estimated hours taken: 400
Deforestation.
This increases the code size of the compiler by ~80k when compiling
with --intermodule-optimization --deforestation.
The improvement from deforestation is not measurable for mmc -C make_hlds.m.
Compile time for make_hlds.m increased from 50.7 seconds to 52.2 seconds
when running deforestation.
compiler/simplify.m
compiler/common.m
Provide a nicer interface for simplifying a goal,
not an entire procedure.
Rework the interface to avoid manipulating lots of booleans.
Return an estimate of the improvement in cost from simplification.
Remove failing cases and disjuncts.
Add an option to optimize common structures even across calls.
Remove code to merge branched goals, since that is now
done by deforestation.
Fix a bug: the code to collect instmap_deltas for cases was not
including the switched-on variable in the instmap_delta,
which caused an abort in merge_instmap_delta if the switched
on variable was further instantiated in the switch.
This came up while compiling the compiler with --deforestation.
compiler/det_report.
Output duplicate call warnings even if --warn-simple-code is not set.
XXX fix the same problem with `:- pragma obsolete'.
compiler/code_aux.m
Update code_aux__cannot_loop to use termination information.
compiler/hlds_pred.m
compiler/dnf.m
Pass the type_info_varmap and typeclass_info_varmap
into hlds_pred__define_new_pred.
Restrict the variables of the new procedure onto the variables
of the goal.
Make sure all relevant type_infos are passed into the new
procedure if --typeinfo-liveness is set.
compiler/modes.m
compiler/unique_modes.m
compiler/mode_info.m
compiler/modecheck_unify.m
Put `how_to_check_goal' into the mode_info, rather
than passing it around.
Add a field to the `check_unique_modes' case which
controls whether unique modes is allowed to choose
a different procedure. For deforestation, this is
not allowed, since it could result in choosing a less
efficient procedure after generalisation.
compiler/options.m
New options:
--deforestation
--deforestation-depth-limit
Safety net for termination of the algorithm.
--deforestation-cost-factor
Fudge factor for working out whether deforestation
was worthwhile.
--deforestation-vars-threshold
Like --inline-vars-threshold.
Enable deforestation at -O3.
Removed an unnecessary mode for option_defaults_2, since it
resulted in a warning about disjuncts which cannot succeed.
compiler/handle_options.m
--no-reorder-conj implies --no-deforestation.
compiler/inlining.m
Separate code to rename goals into inlining__do_inline_call.
compiler/hlds_goal.m
Added predicates goal_list_nonlocals, goal_list_instmap_delta
and goal_list_determinism to approximate information about
conjunctions.
compiler/hlds_module.m
Added module_info_set_pred_proc_info to put an updated
pred_info and proc_info back into the module_info.
compiler/hlds_out.m
Exported hlds_out__write_instmap for debugging of deforestation.
Bracket module names on constructors where necessary.
compiler/mercury_compile.m
Call deforestation.
Use the new interface to simplify.m.
compiler/intermod.m
Put recursive predicates with a top-level branched goal
into `.opt' files.
goal_util.m
Added goal_calls_pred_id to work out if a predicate is
recursive before mode analysis.
Export goal_util__goals_goal_vars for use by deforestation.
Give a better message for a missing variable in a substitution.
compiler/instmap.m
Give a better message for inst_merge failing.
compiler/notes/compiler_design.m
Document the new modules.
library/varset.m
Add varset__select to project a varset's names and values
onto a set of variables.
doc/user_guide.texi
Document deforestation.
Remove a reference to a non-existent option, --no-specialize.
util/mdemangle.c
profiler/demangle.m
tests/misc_tests/mdemangle_test.{exp,inp}
Handle the `DeforestationIn__' predicate names introduced by
deforestation, similar to the `IntroducedFrom__' for lambda goals.
New files:
deforest.m Deforestation.
pd_cost.m Cost estimation.
pd_debug.m Debugging output.
pd_info.m State type and version control.
pd_term.m Termination checking.
pd_util.m Utility predicates
|
||
|
|
5013dd9c76 |
Implement nondet pragma C codes.
Estimated hours taken: 40
Implement nondet pragma C codes.
runtime/mercury_stacks.h:
Define a new macro, mkpragmaframe, for use in the implementation
of nondet pragma C codes. This new macro includes space for a
struct with a given sruct tag in the nondet stack frame being created.
compiler/{prog_data.m,hlds_goal.m}:
Revise the representation of pragma C codes, both as the item and
in the HLDS.
compiler/prog_io_pragma.m:
Parse nondet pragma C declarations.
Fix the indentation in some places.
compiler/llds.m:
Include an extra argument in mkframe instructions. This extra argument
gives the details of the C structure (if any) to be included in the
nondet stack frame to be created.
Generalize the LLDS representation of pragma C codes. Instead of a
fixed sequence of <assign from inputs, user c code, assign to outputs>,
let the sequence contain these elements, as well as arbitrary
compiler-generated C code, in any order and possibly with repetitions.
This flexibility is needed for nondet pragma C codes.
Add a field to pragma C codes to say whether they can call Mercury.
Some optimizations can do a better job if they know that a pragma C
code cannot call Mercury.
Add another field to pragma C codes to give the name of the label
they refer to (if any). This is needed to prevent labelopt from
incorrectly optimizing away the label definition.
Add a new alternative to the type pragma_c_decl, to describe the
declaration of the local variable that points to the save struct.
compiler/llds_out.m:
Output mkframe instructions that specify a struct as invoking the new
mkpragmaframe macro, and make sure that the struct is declared just
before the procedure that uses it.
Other minor changes to keep up with the changes to the representation
of pragma C code in the LLDS, and to make the output look a bit nicer.
compiler/pragma_c_gen.m:
Add code to generate code for nondet pragma C codes. Revise the utility
predicates and their data structures a bit to make this possible.
compiler/code_gen.m:
Add code for the necessary special handling of prologs and epilogs
of procedures defined by nondet pragma C codes. The prologs need
to be modified to include a programmer-defined C structure in the
nondet stack frame and to communicate the location of this structure
to the pragma C code, whereas the functionality of the epilog is
taken care of by the pragma C code itself.
compiler/make_hlds.m:
When creating a proc_info for a procedure defined by a pragma C code,
we used to insert unifications between the headvars and the vars of
the pragma C code into the body goal. We now perform substitutions
instead. This removes a factor that would complicate the generation
of code for nondet pragma C codes.
Pass a moduleinfo down the procedures that warn about singletons
(and other basic scope errors). When checking whether to warn about
an argument of a pragma C code not being mentioned in the C code
fragment, we need to know whether the argument is input or output,
since input variables should appear in some code fragments in a
nondet pragma C code and must not appear in others. The
mode_is_{in,out}put checks need the moduleinfo.
(We do not need to check for any variables being mentioned where
they shouldn't be. The C compiler will fail in the presence of any
errors of that type, and since those variables could be referred
to via macros whose definitions we do not see, we couldn't implement
a reliable test anyway.)
compiler/opt_util.m:
Recognize that some sorts of pragma_c codes cannot affect the data
structures that control backtracking. This allows peepholing to
do a better job on code sequences produced for nondet pragma C codes.
Recognize that the C code strings inside some pragma_c codes refer to
other labels in the procedure. This prevents labelopt from incorrectly
optimizing away these labels.
compiler/dupelim.m:
If a label is referred to from within a C code string, then do not
attempt to optimize it away.
compiler/det_analysis.m:
Remove a now incorrect part of an error message.
compiler/*.m:
Minor changes to conform to changes to the HLDS and LLDS data
structures.
|
||
|
|
0b337ee174 |
Handle inference of mostly-unique (not just unique) modes.
Estimated hours taken: 25 Handle inference of mostly-unique (not just unique) modes. compiler/unique_modes.m: Change the handling of calls so that if the mode originally selected by ordinary mode analysis (modes.m) won't work, then it now calls modecheck_call_pred to introduce a new mode for the predicate. compiler/unify_proc.m: Generalize the existing "unify request queue" so that it can handle requests for any kind of predicate, not just for unification predicates, and hence rename the `unify_request' table which contains it as the `proc_request' table. compiler/hlds_module.m: Rename the `unify_request' table as the `proc_request' table. compiler/modecheck_call.m: When introducing new modes for predicates, do this by adding them to the request queue. This ensures that when we do get around to processing predicates added in unique mode analysis, we will run mode analysis, switch detection, and determinism analysis before doing unique mode analysis. To make this work, we need to pass down a `maybe(determinism)' argument indicating the determinism of the newly added procedure. unique_modes.m sets this to the determinism inferred for the mode originally inferred by modes.m. That should be OK, because uniqueness should not affect determinism. Also change modecheck_call_proc to return a `Changed' flag indicating whether we need to rerun fixpoint analysis. And change `get_var_insts_and_lives' to return `dead' for mostly_unique modes, not just for unique modes, so that we can infer `mdi' modes. compiler/modes.m: Instead of analyzing everything to a fixpoint, and then analyzing the queued unification procedures, change it so that analysis of queued procedures is part of each fixpoint iteration. When doing ordinary mode analysis for calls, pass `no' as the new `maybe(determinism)' argument to modecheck_call_pred. compiler/constraint.m: compiler/cse_detection.m: Ignore the new output argument for modecheck_call_proc. compiler/mode_util.m: Add code to insts_to_mode to recognize `muo', `mui', and `mdi' modes and use the corresponding abbreviations (previously this was done only for `uo', `ui', `di', `in' and `out'). tests/valid/mostly_uniq_mode_inf.m: A test case for the above change. |
||
|
|
b4813457c9 |
A rewrite of termination analysis to make it significantly easier to modify,
Estimated hours taken: 60
A rewrite of termination analysis to make it significantly easier to modify,
and to extend its capabilities.
compiler/error_util.m:
A new file containing code that makes it easier to generate
nicely formatted error messages.
compiler/termination.m:
Updates to reflect the changes to the representation of termination
information.
Instead of doing pass 1 on all SCCs and then pass 2 on all SCCs,
we now do both pass 1 and 2 on an SCC before moving on to the next.
Do not insist that either all procedures in an SCC are
compiler-generated or all are user-written, since this need not be
true in the presence of user-defined equality predicates.
Clarify the structure of the code that handles builtins and compiler
generated predicates.
Concentrate all the code for updating module_infos in this module.
Previously it was scattered in several places in several files.
Put all the code for writing out termination information at the
end of the module in a logical order.
compiler/term_traversal.m:
A new file containing code used by both pass 1 and pass 2 to
traverse procedure bodies.
compiler/term_pass1.m:
Use the new traversal module.
Clarify the fixpoint computation on the set of output supplier
arguments.
Remove duplicates from the list of equations given to the solver.
This avoids a det stack overflow in lp.m when doing termination
analysis on options.m.
If an output argument of a predicate makes sense only in the absence
of errors, then return it only in the absence of errors.
compiler/term_pass2.m:
Use the new traversal module. Unlike the previous code, this allows us
to ignore recursive calls with input arguments bigger than the head
if those calls occur after goals that cannot succeed (since those
calls will never be reached).
Implement a better way of doing single argument analysis, which
(unlike the previous version) works in the presence of mutual recursion
and other calls between the recursive call and the start of the clause.
Implement a more precise way of checking for recursions that don't
cause termination problems. We now allow calls from p to q in which
the recursive input supplier arguments can grow, provided that on
any path on which q can call p, directly or indirectly, the recursive
input supplier arguments shrink by a greater amount.
If an output argument of a predicate makes sense only in the absence
of errors, then return it only in the absence of errors.
compiler/term_util.m:
Updates to reflect the changes to the representation of termination
information.
Reorder to put related code together.
Change the interface of several predicates to better reflect the
way they are used.
Add some more utility predicates.
compiler/term_errors.m:
Small changes to the set of possible errors, and major changes in
the way the messages are printed out (we now use error_util).
compiler/options.m:
Change --term-single-arg from being a bool to an int option,
whose value indicates the maximum size of an SCC in which we try
single argument analysis. (Large SCCs can cause single-arg analysis
to require a lot of iterations.)
Add an (int) option that controls the max number of paths
that we are willing to analyze (analyzing too many paths can cause
det stack overflow).
Add an (int) option that controls the max number of causes of
nontermination that we print out.
compiler/hlds_pred.m:
Use two separate slots in the proc_info to hold argument size data
and termination info, instead of the single slot used until now.
The two kinds of information are produced and used separately.
Make the layout of the get and set procedures for proc_infos more
regular, to facilitate later updates.
The procedures proc_info_{,set_}variables did the same work as
proc_info_{,set_}varset. To eliminate potential confusion, I
removed the first set.
compiler/*.m:
Change proc_info_{,set_}variables to proc_info_{,set_}varset.
compiler/hlds_out.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
Change the code to handle the arg size data and the termination
info separately.
compiler/prog_data.m:
Change the internal representation of termination_info pragmas to
hold the arg size data and the termination info separately.
compiler/prog_io_pragma.m:
Change the external representation of termination_info pragmas to
group the arg size data together with the output supplier data,
to which it is logically connected.
compiler/module_qual.m:
compiler/modules.m:
Change the code to accommodate the change to the internal
representation of termination_info pragmas.
compiler/notes/compiler_design.html:
Fix some documentation rot, and clarify some points.
Document termination analysis.
doc/user_guide.texi:
Document --term-single-arg and the new options.
Remove spaces from the ends of lines.
library/bag.m:
Add a new predicate, bag__least_upper_bound.
Fix code that would do the wrong thing if executed by Prolog.
Remove spaces from the ends of lines.
library/list.m:
Add a new predicate, list__take_upto.
library/set{,_ordlist}.m:
Add a new predicate, set{,_ordlist}__count.
tests/term/*:
A bunch of new test cases to test the behaviour of termination
analysis. They are the small benchmark suite from our paper.
tests/Mmakefile:
Enable the new test case directory.
|
||
|
|
7406335105 |
This change implements typeclasses. Included are the necessary changes to
Estimated hours taken: 500 or so This change implements typeclasses. Included are the necessary changes to the compiler, runtime and library. compiler/typecheck.m: Typecheck the constraints on a pred by adding constraints for each call to a pred/func with constraints, and eliminating constraints by applying context reduction. While reducing the constraints, keep track of the proofs so that polymorphism can produce the tyepclass_infos for eliminated constraints. compiler/polymorphism.m: Perform the source-to-source transformation which turns code with typeclass constraints into code without constraints, but with extra "typeclass_info", or "dictionary" parameters. Also, rather than always having a type_info directly for each type variable, sometimes the type_info is hidden inside a typeclass_info. compiler/bytecode*.m: Insert some code to abort if bytecode generation is used when typeclasses are used. compiler/call_gen.m: Generate code for a class_method_call, which forms the body of a class method (by selecting the appropriate proc from the typeclass_info). compiler/dead_proc_elim.m: Don't eliminate class methods if they are potentially used outside the module compiler/hlds_data.m: Define data types to store: - the typeclass definitions - the instances of a class - "constraint_proof". ie. the proofs of redundancy of a constraint. This info is used by polymorphism to construct the typeclass_infos for a constraint. - the "base_tyepclass_info_constant", which is analagous the the base_type_info_constant compiler/hlds_data.m: Define the class_method_call goal. This goal is inserted into the body of class method procs, and is responsible for selecting the appropriate part of the typeclass_info to call. compiler/hlds_data.m: Add the class table and instance table to the module_info. compiler/hlds_out.m: Output info about base_typeclass_infos and class_method_calls compiler/hlds_pred.m: Change the representation of the locations of type_infos from "var" to type_info_locn, which is either a var, or part of a typeclass_info, since now the typeclass_infos contain the type_infos for the type that they constrain. Add constraints to the pred_info. Add constraint_proofs to the pred_info (so that typeclass.m can annotate the pred_info with the reasons that constraints were eliminated, so that polymorphism.m can in turn generate the typeclass_infos for the constraints). Add the "class_method" marker. compiler/lambda.m: A feable attempt at adding class ontexts to lambda expressions, untested and almost certainly not working. compiler/llds_out.m: Output the code addresses for do_*det_class_method, and output appropriately mangled symbol names for base_typeclass_infos. compiler/make_hlds.m: Add constraints to the types on pred and func decls, and add class and instance declarations to the class_table and instance_table respectively. compiler/mercury_compile.m: Add the check_typeclass pass. compiler/mercury_to_mercury.m: Output constraints of pred and funcs, and output typeclass and instance declarations. compiler/module_qual.m: Module qualify typeclass names in pred class contexts, and qualify the typeclass and instance decls themselves. compiler/modules.m: Output typeclass declarations in the short interface too. compiler/prog_data.m: Add the "typeclass" and "instance" items. Define the types to store information about the declarations, including class contexts on pred and func decls. compiler/prog_io.m: Parse constraints on pred and func declarations. compiler/prod_out.m: Output class contexts on pred and func decls. compiler/type_util.m: Add preds to apply a substitution to a class_constraint, and to a list of class constraints. Add type_list_matches_exactly/2. Also add typeclass_info and base_typeclass_info as types which should not be optimised as no_tag types (seeing that we cheat a bit about their representation). compiler/notes/compiler_design.html: Add notes on module qualification of class contexts. Needs expansion to include more stuff on typeclasses. compiler/*.m: Various minor changes. New Files: compiler/base_typeclass_info.m: Produce one base_typeclass_info for each instance declaration. compiler/prog_io_typeclass.m: Parse typeclass and instance declarations. compiler/check_typeclass.m: Check the conformance of an instance declaration to the typeclass declaration, including building up a proof of how superclass constraints are satisfied so that polymorphism.m is able to construct the typeclass_info, including the superclass typeclass_infos. library/mercury_builtin.m: Implement that base_typeclass_info and typeclass_info types, as well as the predicates type_info_from_typeclass_info/3 to extract a type_info from a typeclass_info, and superclass_from_typeclass_info/3 for extracting superclasses. library/ops.m: Add "typeclass" and "instance" as operators. library/string.m: Add a (in, uo) mode for string__length/3. runtime/mercury_ho_call.c: Implement do_call_*det_class_method, which are the pieces of code responsible for extracting the correct code address from the typeclass_info, setting up the arguments correctly, then executing the code. runtime/mercury_type_info.h: Macros for accessing the typeclass_info structure. |
||
|
|
5976f769f7 |
Fix a bug for the case of a higher-order function call in code
Estimated hours taken: 1 Fix a bug for the case of a higher-order function call in code with common sub-expression; mercury 0.7 failed this test, reporting "Software Error: modecheck fails when repeated", due to confusion between h.o. _function_ call and h.o. _predicate_ call. compiler/hlds_goal.m: Add `pred_or_func' field to HLDS higher_order_calls. compiler/modes.m: compiler/modecheck_call.m: compiler/hlds_out.m: compiler/*.m: Add code to handle new field for higher_order_call goals. tests/valid/Mmake: tests/valid/ho_func_call.m: Regression test for the above-mentioned bug. |
||
|
|
04b720630b |
Update the copyright messages so that (a) they contain the correct years
and (b) they say "Copyright (C) ... _The_ University of Melbourne". |
||
|
|
cbcb23d17b |
Enable --warn-interface-imports by default.
Estimated hours taken: 3
Enable --warn-interface-imports by default. This was turned off while
list and term were defined in mercury_builtin.m, since it caused many
warnings.
Fix all the unused interface imports that have been added since then.
compiler/options.m:
Enable --warn-interface-imports by default.
compiler/module_qual.m:
Fix formatting inconsistencies with module names in warning
messages. (".m" was not appended to module names if there was
only one module).
compiler/*.m:
library/*.m:
tests/invalid/type_loop.m:
tests/warnings/*.m:
Remove usused interface imports, or move them into
implementation (mostly bool, list and std_util).
|
||
|
|
e3471f333f |
Fix a bug in inlining of polymorphic pragma c_code procedures.
Estimated hours taken: 3 Fix a bug in inlining of polymorphic pragma c_code procedures. The bug was that if the actual argument type has a specific type of say `float', then the C variable for the corresponding formal parameter will be declared to have type `Float', whereas without inlining the argument type would have been polymorphic and so the C variable would have been declared to have type `Word'. Hence we need to keep track of the original argument types, before any inlining or specialization has occurred, and use these original argument types to determine how to declare the C variables, rather than using the actual argument types for this particular specialization. compiler/hlds_goal.m: Add a new field to pragma_c_code goals, holding the original argument types (before any inlining or specialization) of the pragma_c_code procedure. compiler/make_hlds.m: Initialize this field with the declared argument types for the pragma c_code procedure. compiler/polymorphism.m: Update this field to account for the inserted type_info variables. compiler/code_gen.m: Pass this field to pragma_c_gen.m. compiler/pragma_c_gen.m: Use the original argument types field for the pragma variable declarations, rather than looking up the actual types of the arguments. compiler/*.m: Trivial changes to handle new field. compiler/live_vars.m: Comment out some code to avoid a warning about `fail' in the condition of an if-then-else. |
||
|
|
3ec8a17ffc |
Enable the code to treat `__' as an alternative syntax for module
Estimated hours taken: 8 Enable the code to treat `__' as an alternative syntax for module qualification, after fixing various places in the compiler where we use `__' in ways that are incompatible with this. compiler/prog_io.m: compiler/prog_io_goal.m: Uncomment the code to handle `__' as module qualification. compiler/intermod.m: compiler/hlds_module.m: compiler/modecheck_unify.m: Fix bugs in the handling of module qualified higher-order terms. compiler/*.m: s/hlds__/hlds_/g compiler/passes_aux.m: s/process__/process_/g compiler/pragma_c_gen.m: compiler/code_gen.m: s/code_gen__/pragma_c_gen__/ for the predicates defined in pragma_c_gen.m (this ought to have been done when the code was first moved from code_gen.m to pragma_c_gen.m). compiler/llds.m: s/llds__proc_id/llds_proc_id/g The reason for this was to avoid ambiguity between proc_id in hlds_pred.m and llds__proc_id in llds.m. compiler/quantification.m: compiler/make_hlds.m: compiler/mercury_to_c.m: s/goal_vars/quantification__goal_vars/g The reason for this was to avoid ambiguity between goal_vars in quantification.m and goal_util__goal_vars in goal_util.m. compiler/dupelim.m: compiler/optimize.m: s/dupelim__main/dupelim_main/g The reason for this change is that a program can only have one main/2 predicate. compiler/prog_io_dcg.m: Remove the old "temporary hack" to strip off and ignore io__gc_call/1, since the new handling of `__' broke it. It was only useful for optimizing NU-Prolog performance, which we don't care about anymore. compiler/mercury_compile.m: compiler/modules.m: compiler/intermod.m: compiler/prog_io.m: Remove occurrences of io__gc_call. compiler/llds_out.m: compiler/base_type_info.m: Ensure that we properly handle the special hacks in mercury_builtin where predicates from other modules (e.g. term__context_init) are defined in mercury_builtin because they are needed for type_to_term and term_to_type. llds_out.m: don't put `mercury_builtin' in the mangled names for those symbols. base_type_info.m: handle types whose status is "imported" in their own module. |
||
|
|
91c4330db7 |
The first half of a change to introduce nondet pragma C goals.
Estimated hours taken: 12 The first half of a change to introduce nondet pragma C goals. This half makes the necessary modifications to the HLDS; the next half will modify the LLDS and emit it. prog_data: Add a new pragma type for nondet pragma c_codes; these specify the names of a a bunch of variables to save across backtracking, and a list of label names to which backtracking may take place. Rename is_recursive to may_call_mercury, since this is a more direct expression of the meaning. prog_io: Move much of the functionality to new files. prog_io_dcg, prog_io_goal, prog_io_pragma, prog_io_util: New files, made up of pieces of prog_io. hlds_goal: Add an extra argument to the pragma_c_goals to store the extra information present in the new type of pragma c_codes. det_analysis: Take into account that the new type of pragma_c goal may have more than one solution. goal_util: Rename variables in the new field of pragma_cs. live_vars: Allocate stack slots to the saved variables in the new type of pragma_c goals. make_hlds: Handle the new type of pragma_c goals. mercury_output, hlds_out: Output the new type of pragma_c goals. garbage_out: Rename type "det" to "frame_type". others: Ignore one more arg of pragma_c goals or import prog_io_util. |
||
|
|
f23324f5fa |
This change fixes two bugs, in quantification and liveness.
Estimated hours taken: 10 This change fixes two bugs, in quantification and liveness. I made the changes to the other files while trying to find them; they ought to be useful in trying to find similar bugs in the future. The compiler now bootstraps with agressive inlining enabled. quantification: Fix a bug that switched two different accumulators of the same type when processing pragma_c_codes. liveness: Fix a bug that could cause a variable to end up in both the post-death and post-birth set of the same goal. options: Reenable inlining. hlds_out, mercury_to_mercury: If -D v is given, include the number of each variable at the end of its name (e.g. Varname_20). The predicates involved (a few from mercury_to_mercury and many from hlds_out) now have an extra argument that says whether this should be done or not. (It is not done when printing clauses e.g. for .opt files.) The bug in quantification was causing the improper substitution of one variable for another, but both had the same name; such bugs would be very difficult to find without this change. constraint, det_report, intermod, make_hlds, mercury_to_c, mode_debug, mode_errors, module_qual, typecheck: Call predicates in hlds_out or mercury_to_mercury with the extra argument. saved_vars: Thread the io__state through this module to allow debugging. mercury_compile: Call saved_vars via its new interface. Fix an inadvertent use of an out-of-date ModuleInfo. goal_util, hlds_goal: Minor formatting cleanup. code_gen: Clean up the import sequence. |
||
|
|
ee24e66a71 |
Switch from using a stack of store_maps in the code_info to govern what
Estimated hours taken: 2.5 Switch from using a stack of store_maps in the code_info to govern what goes where at the end of each branched structure to using the store map fields of the goal expressions of those structures. Fix variable names where they resembled the wrong kind of map(var, lval). code_info: Remove the operations on stacks of store maps. Modify the generate_forced_saves and remake_with_store_map operations to take a store_map parameter. When making variables magically live, pick random unused variables to hold them, since we can no longer use the guidance of the top store map stack entry. This may lead to the generation of some excess move instructions at non-reachable points in the code; this will be fixed later. code_gen: Remove the store map push and pop invocations. Modify the generate_forced_goal operation to take a store_map parameter. code_exprn: Export a predicate for use by code_info. middle_rec, disj_gen, ite_gen, switch_gen, dense_switch, lookup_switch, string_switch, tag_switch: Pass the store map around to get it to invocations of the primitives in code_gen and code_info that now need it. goal_util: Name apart the new follow_vars field in hlds__goal_infos. (This should have been in the change that introduced that field.) common, constraint, cse_detection, det_analysis, dnf, excess, follow_code, intermod, lambda, lco, liveness, make_hlds, mode_util, modes, polymorphism, quantification, simplify, switch_detection, typecheck, unique_modes, unused_args: Fix variable names. follow_vars, store_alloc: Add comments. |
||
|
|
e9cbb5c329 |
Add a new option, --assume-gmake. Rename the existing option
Estimated hours taken: 5 options: Add a new option, --assume-gmake. Rename the existing option --optimize-constructor-recursion to --optimize-constructor-last-call, since it also affects last calls that are not recursive calls. modules.m If --assume-gmake is set, exploit the capabilities of gmake to produce significantly smaller .dep files (about 10% the size of the ones we produced before for mercury_compile). mercury_compile: Change --optimize-constructor-recursion to --optimize-constructor-last-call. hlds_out: Clean up the way we produce HLDS dumps. The new algorithm eliminates lines containing nothing but white space or a single comma or dot in procedure definitions. It should also be easier to modify. constraint, mode_errors: Use the new interface of a predicate in hlds_out. livemap: Make a predicate more self-contained. |
||
|
|
06e05928e1 |
Makes instmap and instmap_delta into ADTs.
Estimated hours taken: 38 Makes instmap and instmap_delta into ADTs. compiler/code_gen.m: compiler/code_info.m: compiler/cse_detection.m: compiler/det_analysis.m: compiler/dnf.m: compiler/goal_util.m: compiler/higher_order.m: compiler/hlds_goal.m: compiler/hlds_out.m: compiler/hlds_pred.m: compiler/live_vars.m: compiler/liveness.m: compiler/lookup_switch.m: compiler/mode_debug.m: compiler/mode_info.m: compiler/modecheck_call.m: compiler/modecheck_unify.m: compiler/modes.m: compiler/polymorphism.m: compiler/simplify.m: compiler/store_alloc.m: compiler/switch_detection.m: compiler/transform.m: compiler/uniq_modes.m: compiler/unused_args.m: Miscellaneous minor changes to use the new instmap.m compiler/constraint.m: Removed unnecessary duplication of code in constraint__checkpoint/4 and constraint__no_output_vars/2. compiler/det_util.m: Changed no_output_vars/4 to det_no_output_vars/4, moved body of code to instmap.m. compiler/instmap.m: Added abstract types instmap/0, instmap_delta/0. Added predicates: instmap__init_reachable/1, instmap__init_unreachable/1, instmap_delta_init_reachable/1, instmap_delta_init_unreachable/1, instmap__is_reachable/1, instmap__is_unreachable/1, instmap_delta_is_reachable/1, instmap_delta_is_unreachable/1, instmap__from_assoc_list/2, instmap_delta_from_assoc_list/2, instmap__vars/2, instmap__vars_list/2, instmap_delta_changed_vars/2, instmap_delta_lookup_var/3, instmap__set/3, instmap_delta_insert/4, instmap_delta_apply_instmap_delta/3, instmap_delta_restrict/3, instmap_delta_delete_vars/3, instmap__no_output_vars/4, instmap_delta_apply_sub/4, instmap__to_assoc_list/2, instmap_delta_to_assoc_list/2. Renamed predicates: instmap__lookup_var/3 (was instmap_lookup_var/3) instmap__lookup_vars/3 (was instmap_lookup_vars/3) instmap__apply_instmap_delta/3 (was apply_instmap_delta/3) instmap__merge/5 (was instmap_merge/5) instmap__restrict/3 (was instmap_restrict/3) Moved predicates: merge_instmap_delta/5 (from mode_util.m) Removed predicates: instmapping_lookup_var/3 compiler/mode_util.m: Moved merge_instmap_delta/5 to instmap.m |
||
|
|
5d64b759db |
The main changes are
Estimated hours taken: 12
The main changes are
1 associating a name with the arguments of constructors
2 removing the follow_vars field from calls, higher-order calls
and complicated unifications, since they are not used
3 merging the follow_vars and store_alloc passes, since they logically
belong together
4 add a new module, lco, for detecting opportunities for last
call optimization modulo constructor application; it won't
actually apply the optimization until the mode system becomes
expressive enough to handle it (this module detects 529 opportunities
in the compiler and library)
5 make "-O3 --optimize-value-number" do the right thing; previously,
it used not to apply value numbering because the vnrepeat option
defaulted to zero
6 don't refer to .err2 files anymore; use .err instead.
prog_data:
The list associated with each value of type "constructor" now
contains not only the types of the arguments but their names as well.
equiv_type, hlds_data, hlds_out, make_hlds, mercury_to_{goedel,mercury},
mode_util, module_qual, shapes, type_util, unify_proc:
Modify the traversal of type definitions to account for the names
in the lists inside values of type "constructor".
prog_io:
Parse argument names. An unrelated change is that we now
check whether :- pred declarations give modes to some of their
arguments but not to all, in which case we return an error.
hlds_goal:
Remove the follow_vars field from calls, higher-order calls
and complicated unifications.
*.m:
Handle the new arities of calls, higher order calls and complicated
unifications.
mercury_compile:
Don't call follow_vars directly anymore, but do call lco if its option
is set. Also flush the main output before a call to maybe_report_stats
to prevent ugly output.
store_alloc:
Call follow_vars directly.
follow_vars:
Expose the initialization and traversal predicates for store_alloc.
lco:
Find opportunities for last call optimization modulo constructor
application.
passes_aux:
Add a HLDS traversal type for lco.
optimize:
Consider the vnrepeat count to be zero unless value numbering is on.
options:
Set the default value of vnrepeat to 1.
modules:
Don't refer to .err2 files.
|
||
|
|
5c149e55b2 |
Mode analyser reorganisation.
Estimated hours taken: 20
Mode analyser reorganisation.
compiler/mode_util.m:
Removed: instmap_init/1, apply_instmap_delta/3, instmap_lookup_var/3,
instmapping_lookup_var/3, instmap_restrict/3, map_restrict/3 (all
moved to instmap.m).
compiler/hlds_goal.m:
Removed the declarations of instmap_delta, instmap and instmapping.
compiler/mode_errors.m:
Added report_mode_errors/2 (was modecheck_report_errors, from
modes.m).
compiler/modes.m:
Predicates now exported:
modecheck_goal/4
modecheck_goal_expr/5 (previously named modecheck_goal_2/5)
handle_extra_goals/8
mode_context_to_unify_context/3
Moved to mode_errors.m:
modecheck_report_errors/2
Moved to instmap.m:
compute_instmap_delta/4
instmap_merge/3
instmap_lookup_vars (was instmap_lookup_arg_list/3)
compute_instmap_delta/4
Moved to mode_debug.m:
Type port/0
mode_checkpoint/4
Moved to modecheck_call.m:
modecheck_call_pred/7
modecheck_higher_order_call/10
modecheck_higher_order_pred_call/4
modecheck_higher_order_func_call/7
Moved to modecheck_unify.m:
modecheck_unification/9
categorize_unify_var_var/12
categorize_unify_var_functor/11
categorize_unify_var_lambda/9
Moved to mode_info.m:
mode_info_error/4
mode_info_add_error/3
compiler/code_gen.pp, compiler/code_info.m, compiler/constraint.m,
compiler/cse_detection.m, compiler/det_analysis.m, compiler/det_util.m,
compiler/dnf.m, compiler/goal_util.m, compiler/higher_order.m,
compiler/hlds_out.m, compiler/hlds_pred.m, compiler/live_vars.m,
compiler/liveness.m, compiler/lookup_switch.m, compiler/polymorphism.m,
compiler/simplify.m, compiler/store_alloc.m, compiler/switch_detection.m,
compiler/transform.m, compiler/unused_args.m:
Imported instmap.m
New files:
compiler/instmap.m:
Handle operations associated with instmaps.
compiler/modecheck_unify.m:
Handle mode checking of unifications.
compiler/modecheck_call.m:
Handle mode checking of calls
compiler/mode_debug.m:
Code to trace the actions of the mode checker.
|
||
|
|
5d3fc10571 |
- Inter-module optimization.
Estimated hours taken: 50 - Inter-module optimization. Allows inlining and higher-order specialization across module boundaries. Gives ~10% speed-up on the compiler compiling to C. - The code to handle explicit type qualification. The test to recognise a type qualification is semidet_fail'ed until we work out which operator to use. - Improved data structures in module_qual.m. Also, module qualification of the modes of lambda expressions is now done in make_hlds.m, since it is more convenient now that type qualifications are module qualified there also. * Type qualification and module qualifiers on higher-order predicate constants and function calls still need to be implemented before this will work on all programs. * To create a version of a program using this optimization method, add --intermodule-optimization to MCFLAGS, mmake change_clean, mmake depend, then make as normal. * mmake change_clean removes the executable, the .dep file and all .cs and .os. compiler/intermod.m Handle input and output of .opt files. compiler/modules.m Added some new dependencies in the .d files for the .c and .opt files if inter-module optimization is being used. Also added .opt and .optdate to the list of things for mmake realclean to remove. Added a target, change_clean, which removes only those files necessary to force a rebuild using --intermodule-optimization. These are <module>, <module>.dep and all the .c, .o and .s files. compiler/options.m Added options: --make-optimization-interface - make the .opt file. --intermodule-optimization - puts extra dependencies into .d files and turns on input of .opt files. compiler/make_hlds.m Changes to give items from .opt files the correct import_status. Also, when matching pragma_c_code clauses to the declared modes of the predicates, expand and match on the initial and final insts of the argument modes, not the modes themselves, since items in .opt files have the modes expanded. Module qualify the modes of lambda expressions in unravel_unification rather than during mode analysis. Parse explicit type qualifications, and add these to the vartypes. At the moment this is disabled. compiler/typecheck.m Get the head type params from the tvarset, not from the arg types, so that tvars in type qualifications are included. Added checks to prevent matching of predicates, functions and constructors which should not be visible to a clause. compiler/module_qual.m Module qualify explicit type qualifications. More efficient data structures. compiler/mercury_to_mercury.m Export some predicates. Make sure C code strings are properly quoted in the .opt files. compiler/hlds_out.m Output function calls correctly. Alter hlds_out__write_goal to write out type qualifications on all functors if writing a .opt file. compiler/hlds_pred.m Added a new import_status opt_imported for clauses and declarations read from a .opt file. Pred and func declarations read from a .opt file get an `opt_decl' import_status so that the compiler doesn't expect clauses for them and local preds can't use them. Also added import_status abstract_imported and abstract_exported to describe types which have only an abstract definition imported or exported. Added a field to clauses_info to store the map(var, type) from explicit type qualifications. Renamed pred_info_set_status/3 to pred_info_set_import_status/3 to be consistent with pred_info_import_status/2. compiler/hlds_data.m Added an import_status field to the hlds__mode_defn and hlds__inst_defn so that intermod.m knows what has already been exported. compiler/equiv_type.m Pass out the equiv_map and export a predicate used to expand type qualifications. compiler/dead_proc_elim.m Remove non-optimized versions of opt_imported preds. All optimizations must give the optimized version an import_status of local. compiler/code_util.m Changed code_util__make_local_entry_label so that `localcall's are used for recursive calls in exported predicates. compiler/code_aux.m Changed code_aux__contains_only_builtins_2 so that it doesn't check for complicated unifies, since any time this is called, complicated unifies have either not been created (when called when writing the .opt files) or have been converted to calls (when called during inlining). compiler/higher_order.m Make sure that the specialized versions get unique names. compiler/mercury_compile.pp Add calls to intermod.m predicates. compiler/bytecode_gen.m Bracketed some '->'/2 insts so that they can be parsed by SICStus. compiler/peephole.m Replace computed_gotos where all the targets are the same with an unconditional goto. compiler/notes/COMPILER_DESIGN Documented intermod.m. library/list.m Added list__all_same/1, which is true if all elements of a list are identical. Also added list__last/2, which returns the final element of a list, failing on the empty list. library/io.m Change the format specifier for io__write_float so that the decimal point is always output. Without this, the result may not be a valid Mercury floating point constant. library/varset.m Add predicate varset__create_name_var_map/2 to create a mapping from variable name to variable id given a varset. This is used in processing type qualifications. scripts/Mmake.rules scripts/Mmake.vars.in Add suffixes, rules and options for .opt and .optdate. scripts/mercury_update_interface.in Work-around for a problem with parallel gmake. mc --make-interface was being run twice in a row on the same module. The first call mercury_update_interface moves module.int.tmp to module.int, then the second can't find module.int.tmp. The work-around is to ignore the exit status of the mv. Some cleaning up: compiler/*.m Fixed some out of date comments about the handling of complicated_unify. Also commented some dead code to do with generation of code for complicated_unify. compiler/modes.m compiler/mode_info.m Moved code to module qualify modes of lambda expressions into make_hlds. Moved predicates resolve_pred_overloading and find_matching_pred_id into typecheck, renaming with a typecheck__ prefix, so that these can be called from intermod.m. compiler/undef_modes.m compiler/undef_types.m Removed - their functionality is now in module_qual.m, except for checking for looping equivalence types. compiler/no_builtin.m compiler/nit_builtin.m Removed - they were made useless (if they weren't already) by the removal of the --builtin-module option. compiler/notes/AUTHORS Updated student email addresses. |
||
|
|
85e770bb56 |
Documentation fix and minor code cleanup.
Estimated hours taken: 0.5 compiler/constraint.m Documentation fix and minor code cleanup. |
||
|
|
4aca4a1035 |
Another fix to make `any' insts work better.
Estimated hours taken: 1 Another fix to make `any' insts work better. det_util.m, constraint.m: Change the way we check for no_output_vars so that it takes into account non-local variables that are not in the instmap delta, because a non-local variable whose initial and final insts are both `any' will not be recorded in the instmap delta, yet it may get further instantiated by the goal. |
||
|
|
5d9e4158f7 |
Module qualification of types, insts and modes.
Estimated hours taken: 45
Module qualification of types, insts and modes.
Added a new interface file - <module>.int3. This contains the
short interface qualified as much as possible given the information
in the current module.
When producing the .int and .int2 files for a module, the compiler uses
the information in the .int3 files of modules imported in the interface
to fully module qualify all items. The .int2 file is just a fully
qualified version of the .int3 file. The .int3 file cannot be overwritten
by the fully qualified version in the .int2 file because then mmake would
not be able to tell when the interface files that depend on that .int3
file really need updating.
The --warn-interface-imports option can be used to check whether
a module imported in the interface really needs to be imported in
the interface.
compiler/module_qual.m
Module qualify all types, insts and modes. Also checks for modules
imported in the interface of a module that do not need to be.
compiler/modules.m
The .int file for a module now depends on the .int3 files of imported
modules. Added code to generate the make rule for the .int file in the
.d file. There is now a file .date2 which records the last time the
.int2 file was updated.
The .int3 files are made using the --make-short-interface option
introduced a few weeks ago.
compiler/options.m
Added option --warn-interface-imports to enable warning about interface
imports which need not be in the interface. This is off by default
because a lot of modules in the library import list.m when they only
need the type list, which is defined in mercury_builtin.m.
Removed option --builtin-module, since the mercury_builtin name is wired
into the compiler in a large number of places.
compiler/prog_util.m
Added a predicates construct_qualified_term/3 and construct_qualfied_term/4
which take a sym_name, a list of argument term and a context for the /4
version and give a :/2 term.
compiler/type_util.m
Modified type_to_type_id to handle qualified types. Also added predicates
construct_type/3 and construct_type/4 which take a sym_name and a list of
types and return a type by calling prog_util:construct_qualified_term.
compiler/modes.m
On the first iteration of mode analysis, module qualify the modes of
lambda expressions.
compiler/mode_info.m
Added field to mode_info used to decide whether or not to module qualify
lambda expressions.
compiler/mode_errors.m
Added dummy mode error for when module qualification fails so that mode
analysis will stop.
Added code to strip mercury_builtin qualifiers from error messages to
improve readability.
compiler/typecheck.m
Strip builtin qualifiers from error messages.
compiler/llds.m
compiler/llds_out.m
compiler/opt_util.m
compiler/opt_debug.m
Change the format of labels produced for the predicates to use the
qualified version of the type name.
compiler/mercury_compile.pp
Call module_qual__module_qualify_items and make_short_interface.
Remove references to undef_modes.m and undef_types.m
compiler/undef_modes.m
compiler/undef_types.m
Removed, since their functionality is now in module_qual.m.
compiler/prog_io.m
Changed to qualify the subjects of type, mode and inst declarations.
compiler/*.m
Changes to stop various parts of the compiler from throwing away
module qualifiers.
Qualified various mercury_builtin builtins, e.g. in, out, term etc.
where they are wired in to the compiler.
compiler/hlds_data.m
The mode_table and user_inst_table are now abstract types each
storing the {mode | inst}_id to hlds__{mode | inst}_defn maps
and a list of mode_ids or inst_ids. This was done to improve the
efficiency of module qualifying the modes of lambda expressions
during mode analysis.
module_info_optimize/2 now sorts the lists of ids.
The hlds_module interface to the mode and inst tables has not changed.
compiler/hlds_module.m
Added yet another predicate to search the predicate table.
predicate_table_search_pf_sym_arity searches for predicates or
functions matching the given sym_name, arity and pred_or_func.
compiler/higher_order.m
Changed calls to solutions/2 to list__filter/3. Eliminated unnecessary
requantification of goals.
compiler/unused_args.m
Improved abstraction slightly.
|
||
|
|
0e1e0b0b91 |
Implement recursive' and non_recursive' pragma c_code declarations.
Estimated hours taken: 4 Implement `recursive' and `non_recursive' pragma c_code declarations. This allows the compiler to optimize cases when the C code is known to not call Mercury code. It's also necessary to allow C code which modifies the hp register to work (such code must be declared `non_recursive', otherwise the registers will be saved and restored over it). To make things bootstrap OK, the old pragma c_code declarations default to `non_recursive'. prog_data.m, hlds_goal.m: Add new field c_is_recursive to pragma c_code goals. prog_io.m: Parse the new `recursive' and `non_recursive' pragma c_code declarations. make_hlds.m: Pass the c_is_recursive field from the parse tree to the HLDS. live_vars.m: For non-recursive C code, don't save variables on the stack. code_gen.pp: For non-recursive C code, don't save variables on the stack, don't mark the succip as needing to be saved, and don't call save_registers() and restore_registers(). *.m: Change c_code/5 to c_code/6. |
||
|
|
9a7da88ce0 |
Treat higher-order predicate calls as a new sort of goal,
Estimated hours taken: 24 Treat higher-order predicate calls as a new sort of goal, rather than as calls to the special predicate call/N, in order to remove the fixed limit on the number of arguments and on the modes for call/N. Also, remove the restriction on output arguments preceding input arguments in lambda expressions. hlds_goal.m: Add new functor higher_order_call/6 to the hlds__goal type. *.m: Handle new functor higher_order_call/6. arg_info.m: Abstract things a bit more: the argument passing convention for a procedure may be affected by that procedure's types, modes, and code_model, as well as the arg_method. follow_vars.m: Pass down the args_method, since it is now needed for figuring out the arg_info for unifications and higher-order calls. follow_code.m: Treat complicated unifications in the same way as calls. lambda.m: When creating lambda predicates, permute the arguments so that all input arguments come before all output arguments. call_gen.m: When generating higher-order predicate calls, don't abort if outputs precede inputs; instead, generate code assuming that the called predicate's args have been permuted so that the inputs to come before all the outputs. |
||
|
|
649b6908c3 |
Rename branch_delay_slot to have_delay_slot.
Estimated hours taken: 8 options.m: Rename branch_delay_slot to have_delay_slot. Set optimize_delay_slot in -O2 only if have_delay_slot was set earlier. This is possible now because the default optimization level is now set in mc. mercury_compile: Change verbose output a bit to be more consistent. dead_proc_elim: Export the predicates that will eventually be needed by inlining.m. inlining.m: Use the information about the number of times each procedure is called to inline local nonrecursive procedures that are called exactly once. EXCEPT that this is turned off at the moment, since the inlining of parse_dcg_goal_2 in prog_io, which this change enables, causes the compiler to emit incorrect code. prog_io: Moved the data type definitions to prog_data. (Even though prog_io.m is ten times the size of prog_data.m, the sizes of the .c files are not too dissimilar.) |
||
|
|
d344165793 |
Add a new option, --branch-delay-slot, intended for use by mc on
Estimated hours taken: 3 options: Add a new option, --branch-delay-slot, intended for use by mc on the basis of the configuattion script. It says whether the machine architecture has delays slots on branches. The setting of option should affect whether we set --optimize-delay-slots at -O2, but this doesn't work yet. hlds_goal: Add an extra field to hold follow_vars infromation to disjunctions, switches and if-then-elses. I intend to use this information to generate better code. *.m: Changes to accommodate the extra field. |
||
|
|
2833bfffb7 |
Divided the old hlds.m into four files:
Estimated hours taken: 10
hlds, hlds_module, hlds_pred, hlds_goal, hlds_data:
Divided the old hlds.m into four files:
hlds_module.m defines the data structures that deal with issues
that are wider than a single predicate. These data structures are
the module_info structure, dependency_info, the predicate table
and the shape table.
hlds_pred.m defined pred_info and proc_info, pred_id and proc_id.
hlds_goal.m defines hlds__goal, hlds__goal_{expr,info}, and the
other parts of goal structures.
hlsd_data.m defines the HLDS types that deal with issues related
to data and its representation: function symbols, types, insts, modes.
It also defines the types related to determinism.
hlds.m is now an empty module. I have not removed it from CVS
because we may need the name hlds.m again, and CVS does not like
the reuse of a name once removed.
other modules:
Import the necessary part of hlds.
det_analysis:
Define a type that was up to now improperly defined in hlds.m.
prog_io:
Move the definition of type determinism to hlds_data. This decision
may need to be revisited when prog_io is broken up.
dnf, lambda:
Simplify the task of defining predicates.
llds:
Fix some comments.
mercury_compile:
If the option -d all is given, dump all HLDS stages.
shape, unused_args:
Fix formatting.
|
||
|
|
3b36da6e77 |
Implement functional syntax. You can now use `:- func' in a similar manner
Estimated hours taken: 12 Implement functional syntax. You can now use `:- func' in a similar manner to `:- pred'. For example, `:- func foo(int, int) = int.' declares a function, and `:- mode foo(in, in) = out.' defines a mode for it. You can write clauses for functions, such as `foo(X, Y) = Z :- Z is 2*X + Y.' Any term in the head or body of a clause can be a function call, e.g. `bar(X, Y, foo(X, Y))'. Until we have implemented a proper Mercury debugger, this syntax should not be used (except that I might reimplement the functions provided by Prolog's is/2 predicate using this syntax, rather than the current special-case hack in the parser). prog_io.m: Add syntax for declaring and defining functions. Disallow the use of `=' to define modes, as in `:- mode foo = bar.' (Instead, you should use `::'. `==' is also allowed.) Also, use higher-order predicates to simplify some of the rather repetitious parsing code. mercury_to_mercury.m, mercury_to_goedel.m, make_hlds.m, modules.m: Handle new functional syntax. typecheck.m: Add support for functions, function types such as `func(int) = int', and currying. (But there's currently no equivalent to call/N for functions, so function types and currying aren't very useful yet.) undef_types.m: Add support for function types. modes.m: Convert function calls into predicate calls. (This must be done after typechecking is complete, so I put it in mode analysis.) hlds.m: Add new field `pred_or_func' to the pred_info. hlds_out.m: Print out the `pred_or_func' field. higher_order.m, unused_args.m, lambda.m, dnf.m: Pass extra pred_or_func argument to pred_info_init to specify that the thing being created is a predicate, not a function. constraint.m, dependency_graph.m, hlds_out.m: `mercury_output_mode_subdecl' has been renamed `mercury_output_pred_mode_subdecl'. prog_util.m: Add new predicate split_type_and_mode/3. llds.m: Print out /* code for predicate '*'/3 in mode 0 */ rather than /* code for predicate */3 in mode 0 */ to avoid a syntax error in the generated C code. |
||
|
|
3e4a019dcc |
Fix the pass structure, and start using a loose sequence of stage
Estimated hours taken: 8 mercury_compile: Fix the pass structure, and start using a loose sequence of stage numbers, to make it easier to add new stages without having to fiddle stage numbers. THIS DOES MEAN THAT ALL STAGE NUMBERS HAVE CHANGED NOW. The stage number assignment scheme assigns 1 to 25 to the front end, 26 to 50 to the middle passes, and 51 to 99 to the back end. hlds: We had two types that combined a pred_id and a proc_id. One, pred_proc_id, used a simple pair; the other, procedure_id, had a better definition using a specific function symbol but was not used anywhere else. I standardized on the name pred_proc_id, but using the definition with a dedicated function symbol (proc). I also defined a type pred_proc_list as a list of pred_proc_id. To prepare for memoing, I added a new field to pred_info, which is a list of markers, each requesting a specific transformation on the predicate or indicating that the transformation has been done. The inline request is now represented using such a marker. However, the interface is backwards compatible. constraint, dead_proc_elim, dependency_graph, det_analysis, det_report, higher_order, unused_args: Changes to conform to the new definition of pred_proc_id. In two places removed definitions of predproclist, whose equivalent pred_proc_list is now defined in hlds.m. hlds_out, make_hlds, mercury_to_mercury, prog_io: Add code to handle memo pragma declarations, using whenever possible a version of the existing code for handling inline requests, but generalized for handling any pragma that sets a marker. switch_detection: Rename the type cases_list to sorted_cases_list. This avoids a name clash that creates a duplicate label and therefore screws up the profiler, and is a better name anyway. options: Add a new option, --opt-space, that turns on optimizations that save space and turns off optimizations that squander space. handle_options: Pass the special option handler to getopt. frameopt: For each labelled code sequence that tears down the stack frame but does not use it, we used to create a parallel code sequence that omits the teardown code, for use by gotos from locations that did not have a stack frame. However, peepholing may discover that it is better not to tear down the stack frame at the site of the goto after all, so we need the original code sequence as well. The current change fixes a bug that occurs if the original code sequence is modified by another part of frameopt to omit teardown code. In such cases, which are produced by --pred-value-number, peepholing redirects a goto to a code sequence that it thinks tears down the stack frame, but actually doesn't. With this change, --pred-value-number now works. llds: Fix typos in a comment. |
||
|
|
bc2b8632b1 |
Add support for the compact argument passing convention.
Estimated hours taken: 6 arg_info: Add support for the compact argument passing convention. The proper handling of higher order calls etc is still missing. globals: Added a third global type, args_method, current either "old" or "compact". passes_aux: Moved some auxiliary predicates from mercury_compile and options to passes_aux. constraint, det_analysis, make_hlds, modules, optimize, undef_types: Import and refer to passes_aux. mercury_compile, handle_options: Remove the predicates moved to passes_aux. Also move the option postprocessing code to a new module, handle_options. Another change is that we stop after syntax errors if the new option --halt-at-syntax-errors is set. handle_option: New module for option postprocessing. options: Remove the option lookup predicates, which were obsolete. Add new options --args, --halt-at-syntax-errors and --opt-level. Add a special handler for --opt-level. lookup_switch: Call getopt to look up options, not options. value_number, vn_block: Extended basic blocks with more than one incr_hp pose a problem for value numbering when using boehm_gc, because value numbering coalesces all the allocations into one. Previously we did not optimize such sequences. I modified value numbering to divide up such blocks into smaller blocks, each with at most one incr_hp, and optimize these. At the moment, some of these blocks contain deeply nested field refs, which value numbering is very slow to handle; code_exprn should be modified to fix these. value_number: Rename usemap to useset, since this is more accurate. Fixed a bug in --pred-value-number, which manifested itself as the generation of duplicate labels. labelopt: Rename usemap to useset, since this is more accurate. |
||
|
|
6d7f4b9b30 |
Undo dylan's changes in the names of some library entities,
Estimated hours taken: 1.5 Undo dylan's changes in the names of some library entities, by applying the following sed script s/term_atom/term__atom/g s/term_string/term__string/g s/term_integer/term__integer/g s/term_float/term__float/g s/term_context/term__context/g s/term_functor/term__functor/g s/term_variable/term__variable/g s/_term__/_term_/g s/std_util__bool_/bool__/g to all the `.m' and `.pp' files in the compiler and library directories. The reason for undoing these changes was to minimize incompatibilities with 0.4 (and besides, the changes were not a really good idea in the first place). I also moved `bool' to a separate module. The main reason for that change is to ensure that the `__' prefix is only used when it genuinely represents a module qualifier. (That's what dylan's changes were trying to acheive, but `term__' does genuinely represent a module qualifier.) compiler/*.m: Apply sed script above; where appropriate, add `bool' to the list of imported modules. |
||
|
|
022f847e33 |
Fix new warnings detected by the latest version of the compiler.
Estimated hours taken: 0.25 Fix new warnings detected by the latest version of the compiler. constraint.m, mercury_to_mercury.m, mercury_to_goedel.m: Eliminate `condition in if-then-else cannot fail' warnings. |
||
|
|
3ab8d92226 |
Change names with badly placed double underscores (ie where the part of
Estimated hours taken: _2___ Change names with badly placed double underscores (ie where the part of a name before a double underscore is not the same as the module name.) Reflect changes in the library interface. compiler/*: Use the newer, more correct form of the term and bool names. Predicates "bool__" are now "std_util__bool" and labels of the term ADT are now "term_" instead of "term__". compiler/vn*.m: change all names "vn__*" to a correct module prefix. All the names remain qualified. compiler/hlds.m: s/\<is_builtin__/hlds__is_builtin_/g s/\<dependency_info__/hlds__dependency_info_/g compiler/unify_proc.m: s/\<unify_proc_info__/unify_proc__info_/g compiler/transform.m: s/\<reschedule__conj/transform__reschedule_conj/g |
||
|
|
3224e94532 |
A new pass to remove unnecessary assignment unifications.
excess: A new pass to remove unnecessary assignment unifications. mercury_compile: Call the new excess assignment module. options: Add a new option, excess_assign, to control the new optimization. Add another, num-real-regs, to specify how many of r1, r2 etc are actually real registers. The default is now set to 5 for kryten; later it should be supplied by the mc script, with a value determined at configuration time. tag_switch: Use num-real-regs to figure out whether it is likely to be worthwhile to eliminate the common subexpression of taking the primary tag of a variable. Also fix an old performance bug: the test for when a jump table is worthwhile was reversed. value_number, vn_block: Do value numbering on extended basic blocks, not basic blocks. vn_debug: Modify an information message. labelopt: Clean up an export an internal predicate for value numbering. Replace bintree_set with set. middle_rec: Prepare for the generalization of middle recursion optimization to include predicates with an if-then-else structure. cse_detection: Fix a bug: when hoisting a common desconstruction X = f(Yi), create new variables for the Yi. This avoids problems with any of the Yis appearing in other branches of the code. goal_util: Add a new predicate for use by cse_detection. common: Fix a bug: recompute instmap deltas, since they may be affected by the optimization of common structures. code_info: Make an error message more explicit. det_analysis: Restrict import list to the needed modules. *.m: Import assoc_list. |
||
|
|
4b91fb61cf |
Add new predicate `inst_matches_binding'.
inst_match.m: Add new predicate `inst_matches_binding'. This is like `inst_matches_final', except that it ignores differences in uniqueness. modes.m, det_report.m, constraint.m: Use `inst_matches_binding' rather than `inst_matches_final' when testing whether a goal has no output variables. This avoids some problems with unique modes. |
||
|
|
f75693e80a |
The C interface.
The changes made allow declarations of the form: :- pragma(c_code, predname(Varname1::mode1, Varname2::mode2, ...), "Some C code to execute instead of a mercury clause;"). There are still a couple of minor problems to be fixed in the near future: If there is a regular clause given as well as a pragma(c_code, ...) dec, it is not handled well, and variables names '_' are not handled well. prog_io.m: parse the pragma(c_code, ...) dec. hlds.m: define a new hlds__goal_expr 'pragma_c_code'. make_hlds.m: insert the pragma(c_code, ...) dec. as a pragma_c_code into the hlds. det_analysis.m: infer that pragma_c_code goals are det. modes.m: convince the mode checker that the correct pragma variables are bound etc. quantification.m: quantify the variables in the pragma(c_code, ...) dec. code_gen.pp: convert pragma_c_code into pragma_c (in the llds). llds.m: define a new instr, pragma_c. Output the pragma_c hlds_out.m: mercury_to_mercury.m: mercury_to_goedel.m: spit out pragma(c_code, ...) decs properly *.m: handle the new pragma_c_code in the hlds or the new pragma_c in the llds |
||
|
|
0bbf5def61 |
Fix obscure "map_lookup failed" bug triggered by a partially
modes.m, unify_proc.m: Fix obscure "map_lookup failed" bug triggered by a partially instantiated mode of a complicated unification predicate, whose procedure body contained a call the the same complicated unification predicate in a different partially instantiated mode. constraint.m, cse_detection.m: Change calls to modecheck to match new simplified interface. |
||
|
|
b905b2f4d8 |
Added an extra argument to call, which contains a maybe of the unification
context of the unification from which call was made. We we use this to generate significantly better error messages. (There should be no more messages of the form "call to __Unify__(blah blah blah) can fail".) Most of the files are changed just to reflect this. An unrelated change in det_analysis is that we now ensure the absence of cycles by modifying the new inferred determinism in the light of the old one, ensuring that any changes are monotonic. In hlds_out, inhibit the printing of pseudo-imported predicates (unifications) since nobody cares about them except sometimes Fergus. |