Estimated hours taken: 0.25
Address juliensf's review comments on my recent change to add an MLDS
optimization to convert assignments into initializers.
compiler/ml_optimize.m:
doc/user_guide.texi:
Fix some typos.
compiler/options.m:
Wrap some long lines.
Estimated hours taken: 1.5
Add an MLDS optimization to convert assignments into
initializers.
compiler/options.m:
doc/user_guide.texi:
Add new option `--optimize-initializations'.
compiler/ml_optimize.m:
Implement the new optimization.
compiler/ml_elim_nested.m:
compiler/ml_util.m:
Move initializer_contains_var, rval_contains_var and related
predicates from ml_elim_nested.m to ml_util.m, for use by
ml_optimize.m.
Estimated hours taken: 16
Add an MLDS to MLDS transformation that converts MLDS switches
into computed gotos or if-then-else chains. (Eventually we
should make this code also handle binary searches.)
This transformation should allow tag switch optimization to work for
the IL back-end. It also replaces ml_dense_switch.m and lets us
simplify ml_string_switch.m.
compiler/mlds.m:
Add a new `switch_range' field to the `switch' stmt.
compiler/ml_simplify_switch.m:
The new transformation. This converts MLDS switches into
computed gotos or if-then-else chains.
It uses the new `switch_range' field to determine how big
it would need to make the jump table to cover all cases.
compiler/ml_switch_gen.m:
compiler/ml_string_switch.m:
compiler/ml_tag_switch.m:
compiler/ml_dense_switch.m:
Generate the new field.
Change the places that generate switches so that after
generating the switch they invoke the new transformation.
Delete ml_dense_switch.m, since it is now redundant,
and significantly simplify ml_string_switch.m.
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_il.m:
Trivial changes to handle the new field.
compiler/switch_util.m:
compiler/dense_switch.m:
Move most of the code from the `type_range' procedure from
dense_switch.m to switch_util.m, so we can use it in
ml_switch_gen.m for computing the switch range.
Estimated hours taken: 8
Get the MLDS back-end to generate better code for switches.
It now compiles Mercury switches on int/char/enums into C switches.
compiler/mlds.m:
Add `switch' as a new alternative in the `mlds__stmt' type.
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_util.m:
Minor changes to handle the new `switch' statement.
compiler/ml_code_gen.m:
Move the code for handling switches to ml_switch_gen.m.
Export `ml_gen_goal', for use in ml_switch_gen.m.
compiler/ml_switch_gen.m:
compiler/ml_dense_switch.m:
New files, adapted from switch_gen.m and dense_switch.m, but
with significant changes. These now handle three forms of switch:
- dense switches, implemented as computed gotos;
- "direct mapped" switches, which get implemented using the
MLDS switch statement, which in turn gets mapped to the
target language's switch statement;
- if-then-else chains
compiler/ml_code_util.m:
Add a label counter to the ml_gen_info, and define predicates
for allocating new labels.
compiler/mlds_to_c.m:
Output switch statements. Also fix a layout bug in the output:
make sure we output newlines at the end of comments.
compiler/mlds_to_il.m:
Call error/1 for MLDS switch statements. The code generator
will generate MLDS computed_gotos (which map to IL `switch'
instructions) rather than MLDS switch statements, so we should
never get MLDS switch statements here.
compiler/options.m:
Add a new option `--prefer-switch', defaulting to enabled,
which says to generate switches rather than computed gotos
where possible.
Estimated hours taken: 0.5
Various fixes for problems fjh pointed out in a review.
compiler/ml_code_util.m:
Fix a typo.
compiler/ml_optimize.m:
compiler/mlds_to_c.m:
Move some comments from mlds_output_assign_args to
generate_assign_args.
Remove mlds_output_assign_args as it is now dead code.
compiler/options.m:
Fix a typo, llds-optimize should be mlds-optimize.
doc/user_guide.texi:
Document --no-mlds-optimize.
Estimated hours taken: 5
Do the transformation of self-tailcalls into loops as an MLDS->MLDS
transformation (instead of during mlds_to_c.m). Both the IL and C
backends for MLDS use this transformation.
Also, we transform into label/goto instead of for/continue. This is
because IL doesn't have a for/continue construct. It may be worth
revisiting this decision in future and performing benchmarks.
compiler/mercury_compile.m:
Add an optimization phase to the MLDS end of the compiler.
compiler/ml_optimize.m:
New file that performs MLDS->MLDS optimizations such as turning
self-tail calls into loops.
compiler/ml_tailcall.m:
Use ml_util.
compiler/ml_util.m:
New file containing generic MLDS utilities.
Contents are can_optimize_tailcall and statements_contain_statements.
This code was in mlds_to_c but will be used by more than just
this backend.
compiler/mlds_to_c.m:
Delete old tailcall transformation code (it is either moved into
ml_optimize, ml_util or it is no longer needed).
Only handle general tailcalls.