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.
Estimated hours taken: 3
compiler/{cse,switch}_detection.m:
Fix bugs which lead to the wrong unification being hoisted
(cse_detection.m) or the wrong unification being marked
as never-failing (switch_detection.m). Make sure the difficult
cases are rejected as determinism errors rather than causing
incorrect code to be generated.
Estimated hours taken: 8
Fix a bug which caused the compiler to miscompile
value_number__substitute_access_vns.
compiler/cse_detection.m:
In find_bind_var_for_cse, ensure that if the variable which
we are trying to hoist is bound to a different functor than
the one we're searching for, then we stop searching for
a match. This is necessary, because the code that checks
for a match assumes that the variable we're trying to hoist
has not yet been bound.
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.
Estimated hours taken: 4
More changes to finally fix the compiler so that it handles
Simon Taylor's nasty test case correctly.
Change unique_modes.m to invoke modecheck_unify_procs in unify_procs.m,
in case unique_modes.m adds new unify_requests for unification predicates
with `mostly_unique' modes.
switch_detection.m, cse_detection.m, det_analysis, unique_modes:
Export new predicates to process a single procedure at a time.
cse_detection.m:
Rearrange things so that it only redoes mode checking and switch
detection for the single procedure, not for a every mode of a predicate,
by calling `modecheck_proc' and `detect_switches_in_proc'.
hlds.m:
Add new field `can_process' to the proc_info.
modes.m, unique_modes.m:
Don't modecheck a procedure if its can_process field = no.
unify_proc.m:
Set the can_process field to `no' when adding unify procs after
a call to unify_proc__request_unify, and then back to yes again
when we are ready to process them in modecheck_unify_procs.
Add a new parameter to modecheck_unify_procs which specifies
whether we need to do ordinary mode checking or unique mode
checking. If we need to do unique mode checking, then after
doing ordinary mode checking, invoke `detect_switches_in_proc',
`cse_detect_in_proc', `determinism_check_proc', and
`unique_modes__check_proc' on the procedure.
unique_modes.m:
After checking ordinary predicates, invoke modecheck_unify_procs.
Add very_verbose progress messages.
Estimated hours taken: 6
Rearrange the ordering of the different phases in the compiler.
Moved lambda elimination (lambda.m) after unique_modes.m,
because mode analysis must have been fully completed before lambda
elimination, so that we get the right mode on the introduced
predicates. Also moved inlining.m and common.m after unique modes,
since they are optimization passes, not semantic checking passes.
The cse_detection.m, switch_detection.m, and determinism.m passes now
need to recursively traverse lambda goals. (Previously they assumed
that lambda goals had already been eliminated.)
mercury_compile.pp:
Move the inlining.m and common.m passes from semantic_phases
to middle_phases.
polymorphism.m:
Remove the code which called lambda.m.
switch_detection.m:
Recursively traverse lambda goals.
cse_detection.m:
Recursively traverse lambda goals.
Also, when redoing mode analysis and switch detection,
we shouldn't reinvoke lambda.m.
det_analysis.m, det_report.m:
Recursively traverse lambda goals, check for determinism
errors in them, and report them.
Also, print the calling predicate name & mode in the error
message for calls to predicates with cc_* determinism in
all-solutions contexts.
modes.m:
Add an extra argument to modecheck_unification that specifies
how we should recursively process lambda goals, so that we
can do the right thing when called from unique_modes.m.
The right thing in this case is to call unique_modes__check_goal
instead of modecheck_goal, and to then invoke lambda__transform_lambda
on the result.
unique_modes.m:
Make sure we don't clobber the predicate table, since we now
indirectly call lambda__transform_lambda, which inserts new
predicates into the table.
Also, simplify the code a little and add a sanity check.
lambda.m:
Make some changes that were needed because lambda.m now comes
directly after (unique_)modes.m not after polymorphism.m.
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
Estimated hours taken: 15
(Debugging 3 people * 3 hours, design 2 hours, coding 4 hours.)
Fix design error which led to the bug reported by Philip Dart:
cse_detection was reinvoking mode analysis, which converted
higher-order pred terms into lambda expressions, but was
not reinvoking polymorphism.m, and so they remained as
lambda expressions, which caused the code generator to generate
incorrect code.
compiler/polymorphism.m:
Move the stuff for handling lambda expressions into
a new file lambda.m.
compiler/lambda.m:
New file. Contains the lambda expression handling
stuff from polymorphism.m, plus new code to traverse
the HLDS for a predicate applying this transformation
to each lambda expression in the procedure bodies
for that predicate.
compiler/cse_detection.m:
After re-running mode analysis, invoke lambda__process_pred
to transform away lambda expressions.
Estimated hours taken: 0.1
compiler/cse_detection.m:
Rename a function symbol.
compiler/middle_rec.m:
Fix earlier overhast commit.
compiler/options.m:
Change help message for --num-real-regs.
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.
1. A bug fix and a new warning for quantification
quantification.m:
Fix bug in renaming apart of lambda goals: it used to
sort the lambda variables. Improve efficiency slightly.
Add some comments for quantification__rename_apart.
Use more informative variable names in a couple of places.
quantification.m, make_hlds.m, mercury_to_mercury.pp, options.m:
Add code to quantification.m to detect variables with
overlapping scopes, and pass back a list of warnings.
Add code to make_hlds.m to print out the warnings, if
the new option warn_overlapping_scopes was enabled (as
it is by default). Add code to options.m and
mercury_to_mercury.pp to handle the new warning
option.
common.m, cse_detection.m, follow_code.m, unify_proc.m,
Add an extra argument `_Warnings' to calls to
`implicitly_quantify_clause_body', as required by the
above change.
goal_util.m:
Export the predicate goal_util__rename_var_list for use by
quantification.m.
2. A (very incomplete) start to a new backend which will generate
high-level, debuggable C code.
options.m:
Add new option --high-level-C.
mercury_to_mercury.pp:
Handle new option.
mercury_to_c.m:
New file.
llds.m, hlds_out.m:
Export predicates for use by mercury_to_c.m.
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
quantification.m:
Make implicit quantification rename apart vars that
are local to distinct scopes. This will help in the
singleton variable warning pass once the latter has
been changed to work on the HLDS.
These changes also allow goals of the form:
.... X ....,
some [X] Goal
which were previously not allowed.
cse_detection.m:
A 1 line bugfix from Zoltan.
det_analysis.m:
Rather than redoing quantification, construct
a correct goal_info directly in det__disj_to_ite/3.
optimize.pp:
Fix a singleton variable. Zoltan, there is an
XXX for you to read and remove if the fix is
correct.
common.m, cse_detection.m, det_analysis.m,
follow_code.m, make_hlds.m, polymorphism.m,
unify_proc.m:
Fix the calls to implicitly_quantify_clause_body and
implicity_quantify_goal.
TODO:
Update a couple of things.
parser.m:
Add a map(string, var) to the state so that varset
can be simplified.
varset.m:
Simplfy the varset structure so that the binding
of names to variables is cheaper.
-------------------------------------------------------
Implement unique modes. We do not handle local aliasing yet, so this
is still not very useful, except for io__state. Destructive update is
not yet implemented. Also note that this really only implements
"mostly unique" variables that may be non-unique on backtracking - we
don't check that you don't backtrack over I/O, for example.
prog_io.m, mode_util.m, modes.m, inst_match.m:
Major changes to Handle unique modes.
mercury_to_mercury.m, polymorphism.m, prog_out.m, undef_modes.m:
Use `ground(Uniqueness)' rather than just `ground'.
compiler/*.m:
Fix compile errors now that unique modes are enforced: add a
few calls to copy/2, and comment out lots of unique mode
declarations that caused problems.
typecheck.m, mode_info.m:
Hack around the use of unique modes, which doesn't work
because we don't allow local aliasing yet: make the insts
`uniq_type_info' and `uniq_mode_info' not unique at all,
and add a call to copy/2 when extracting the io_state from
type_info or mode_info.
-------------------------------------------------------
Plus a couple of unrelated changes:
hlds.m:
Change the modes for the special predicates from `ground -> ground'
to `in', so that any error messages that show those modes
come out looking nicer.
Add a new shared_inst_table for shared versions of user-defined
insts.
mercury_to_goedel.m:
Use string__is_alnum_or_underscore.
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.
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.
hlds:
Removed the notion of "internal determinism"; commits are now indicated
through "some" goals. Renamed the predicate module_info_shapes to
module_info_get_shapes. Will later change other predicates also to
get consistent naming.
hlds_out:
Removed printing of internal determinisms.
det_analysis:
Changes to accommodate the new way of signalling commits. The comments
on optimizations have been modified to reflect the need for information
about whether goals can raise exceptions. Exported two predicates for
use by follow_code.
live_vars:
Changes to accommodate the new way of signalling commits.
code_gen:
Shift the handling of commits to "some" goals. Some predicates
had three versions, one for each code model; these have been
simplified significantly. The sequence of predicates has also
been rationalised a bit. There is still room for improvement
on both fronts.
disj_gen, ite_gen, middle_rec:
Changed calls to modified predicates in code_gen.
common:
When this pass changes A == f(B, C), D := f(B, C) into A == f(B, C),
D := A, it can change the scopes of A, B and C. The pass did not
take this into account; now it does. The pass is still disabled
until it has been more adequately tested.
mercury_compile:
Moved followcode into the back end. We now thread ModuleInfo through
the backend instead of Shapes, since follow_code modifies other parts
of ModuleInfo as well. Rationalised the stage numbers, WHICH MEANS
-d NUMBERS HAVE CHANGED.
follow_code:
Follow_code is now after determinism analysis, so that we can check
that it does not change the determinism of the branched structure
we are pushing code into. We now push not just builtins but also the
first call after the branched structure into the branched structure,
since this will reduce register shuffling. Made a start on pushing code
into the fronts of branched structures, when some code before the branch
point is useful only in one branch.
options:
Added an option prev_code for the (incomplete) functionality in
follow_code.
vn_flush:
Moved a comment about future functionality to where it now belongs.
cse_detection:
Removed obsolete debugging predicate.
unifications. See the comments at the top of unify_proc.m for
details of how it's done.
hlds.m:
Add new export statuses `pseudo_imported' and `pseudo_exported'
to handle unification predicates, which can now have complicated
modes.
code_gen.pp, code_info.m, common.m, constraint.m, cse_detection.m,
follow_code.m, follow_vars.m, hlds_out.m, inlining.m, live_vars,
make_hlds.m, mercury_compile.pp, modes.m, store_alloc.m,
switch_detection.m:
Handle pseudo_imported predicates.
modes.m, constraint.m:
Change modecheck to return an updated module_info, since
modechecking may insert new entries into the unify_requests
queue in the module_info. Make sure that modechecking
never inserts requests into the unify_requests queue
for code that has mode errors (or needs rescheduling).
call_gen.m, polymorphism.m:
Move duplicated code into unify_proc.m.
clause_to_proc.m:
Add new predicate clauses_to_proc for use by unify_proc.m.
unify_proc.m:
Implement complicated unifications with complicated modes.
options:
Cleanup of the option set. Main change is making linking the default,
and the replacement of -g, --compile and --link by -e, -C and -c.
WARNING: this makes the compiler inconsistent with the standard mmake
configuration, so don't do a cvs update yet unless you know what you
are doing.
conf:
Find out at configuration time how many bits the --tags low option
uses.
mercury_compile:
With the help of conf, we now make sure --tags and --num-tag-bits
are consistent. We use the new set of options. We also generate
program-specific .clean rules in .dep files.
make_tags:
Mercury_compile now makes sure that --tags and --num-tag-bits are
consistent, so make_tags need not do it.
mode_errors:
Use the new set of options.
llds:
Changes to introduce the new option use_macro_for_redo_fail and
change --mod-comments into --auto-comments.
cse_detection:
We now print the messages about redoing mode analysis, switch detection
and cse detection only if very verbose is on.
typecheck:
The error message for wrong number of arguments now gives the actual
number and the right number(s).
value_number:
Tighten the sanity check; theold version wasn't tight enough for
the code generated for prof.m.
hlds.m and lots of other files:
Change the type of the first two arguments of unify/5 in
hlds__goal_expr from `term, term' to `var, unify_rhs'
where unify_rhs is given by
:- type unify_rhs
---> var(var)
; functor(const, list(var))
; lambda_goal(list(var), hlds__goal).
This change was for two reasons: firstly, it simplifies the
code in a lot of places, and secondly, it is a step towards
implementing lambda closures and higher-order predicates
properly.
code_gen.pp:
Put the comment about the contents of stack slots before the initial
label, since this way it will be preserved by optimizations.
cse_detection.m:
Extended the search to look for cses in if-then-elses and switches
as well as disjunctions. Removed InstmapDelta from preds in which it
was not being used.
det_analysis.m:
Make the diagnosis routines more robust. The changes here avoid the
Philip's problems with lexical.m.
jumpopt.m:
Minor formatting changes.
livemap.m:
Avoid duplicating livevals instructions when optimizations are
repeated, since this can confuse some optimizations.
llds.m:
Minor documentation change.
make_hlds.m:
Minor formatting change.
mercury_compile.pp:
Do not map arguments to registers if any semantic errors have been
found.
middle_rec.m and code_aux.m:
Apply middle recursion only if tail recursion is not possible,
since tail recursion yields more efficient code.
opt_util.m:
Added a predicate to recognize constant conditions in if_vals.
Modified a predicate to make it better suited for frameopt.
optimize.pp:
Changed the way optimizations were repeated to allow better control.
Repeat peephole once more after frameopt, since the new frameopt
can benefit from this.
options.m:
Removed the --compile-to-c option, which was obsolete. Added an
option for predicate-wide value numbering, which is off by default.
Changed some of the default values of optimization flags to reduce
compilation time while holding the loss of speed of generated code
to a minimum.
peephole.m:
Look for if_vals whose conditions are constants, and eliminate the
if_val or turn it into a goto depending on the value of the constant.
Generalized the condition for optimizing incr_sp/decr_sp pairs.
value_number.m:
Added a prepass to separate primary tag tests in if-then-elses from
the test of the secondary tag, which requires dereferencing the
pointer.
Added sanity check routines to test two aspects of the generated code.
First, whether it produces the same values for the live variables as
the original code, and second, whether it has moved any dereferences
of a pointer before a test of the tag of that pointer. If either test
fails, we use the old instruction sequence.
vn_debug.m:
New messages to announce the failure of the sanity checks. They are
enabled by default, but of course can only appear if value numbering
is turned on (it is still off by default).
vn_flush.m:
Threaded a list of forbidden lvals (lvals that may not be assigned to)
through the flushing routines. When saving the old value of an lval
that is being assigned to, we use this list to avoid modifying any of
the values used on the right hand side of the assignment, even if the
saving of an old value results in assignment that requires another
save, and so on recursively.
When the flushing of a node_lval referred to a shared vn, the uses of
the access vns of the node_lvals were not being adjusted properly.
Now they are.
vn_order.m:
The ctrl_vn phase of the ordering was designed to ensure that all
nodes that need not come before a control node come after it. However,
nodes were created after this phase operated, causing leakage of some
value nodes in front of control nodes. Some of these led to pointer
dereferences before tag tests, causing bus errors. The ctrl_vn phase
is now last to avoid this problem.
vn_table.m:
Added an extra interface predicate to support the sanity checks in
value_number.
vn_util.m:
The transformation of c1-e2 into (0-e2)+c1 during vnrval simplification
could lead to an infinite loop in the compiler if c1 was zero. A test
for this case now prevents the loop.
switch_detection:
Detect partial switches, i.e. disjunctions in which not all
disjuncts form part of the switch. We give preference to full
switches, and failing that, to partial switches with the most arms.
peephole, opt_util:
Fixed the code for the introduction of succeed_discard.
code_gen:
Fixed spelling error in error message.
code_info:
Made error message somewhat more informative.
cse_detection:
Removed debugging code; we now always repeat cse detection after
finding some cses.
det_analysis:
Added some comments.
value_number, vn_debug, vn_flush:
Changes to make debugging easier.