mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-19 19:33:46 +00:00
Estimated hours taken: 24
Branches: main
Implement lookup disjunctions and model_non lookup switches.
compiler/ml_disj_gen.m:
New module that looks after code generation for disjunctions.
Note the link to disj_gen.m.
Part of the code in it comes from ml_code_gen.m, but the part that
implements lookup disjunctions is new, and its bulk is what justifies
a separate module.
Even the old code has been restructured to make the decision
about whether this is a model_non disj or not just once, instead
of once for every single disjunct.
compiler/ml_backend.m:
compiler/notes/compiler_design.html:
Mention the new module.
compiler/mlds.m:
Use a purpose-specific type instead of a bool to represent
whether a loop can loop zero times.
compiler/ml_code_gen.m:
Remove the code moved to ml_disj_gen.m.
Improve the style of the ml_gen_maybe_convert_goal_code_model
predicate.
compiler/ml_lookup_switch.m:
Implement model_non lookup switches.
Note the link to lookup_switch.m.
Give better names to some predicates and variables.
Remove the predicates moved to ml_code_util.m, goal_form.m and
ml_util.m.
compiler/switch_util.m:
When a switch arm has several solutions, store the first solution
separately. This assures statically that there IS a first solution
(which a simple list of solutions does not), and prepares the first
solution for its special treatment (it is stored in a different vector
than the later solutions, and in the LLDS backend, we take the liveness
after the arms from it).
compiler/ml_code_util.m:
Move here the predicates previously in ml_lookup_switch.m that are now
needed by ml_disj_gen.m as well. Make it possible to generate
constants for individual arms, as well as individual field assigns,
since ml_disj_gen.m now needs this capability.
compiler/goal_form.m:
Move here a suitably generalized version of the two previously
backend-specific versions of the predicates that test goals to see
if they can be part of a lookup switch or disjunction.
compiler/ml_util.m:
Move here from ml_lookup_switch.m a predicate now needed by
ml_disj_gen.m as well.
compiler/lookup_util.m:
Remove the predicate moved to goal_form.m.
Make it possible to generate constants for a single disjunct.
Avoid uselessly wrapping up a return argument in a yes().
compiler/disj_gen.m:
compiler/lookup_switch.m:
Move a cheap test significantly earlier, to avoid wasting time
on disjunctions on which it would fail.
Conform to the changes in the backend libraries.
In lookup_switch.m, note the paper that describes the code generation
scheme followed by the module.
compiler/mlds_to_c.m:
Conform to the changes above.
When generating scalar and vector static cells, indicate the row
numbers in comments, since without this, it is too difficult to check
visually whether the generated code is correct.
compiler/mlds_to_java.m:
Conform to the changes above.
Improve the style of a big predicate.
compiler/ml_accurate_gc.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tailcall.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
Conform to the changes above.
tests/hard_coded/dense_lookup_switch_non.{m,exp}:
Make this test case significantly more comprehensive, by making it
test all combinations of the presence and absence of both range checks
and bit vector checks.
tests/hard_coded/lookup_switch_simple_bitvec.{m,exp}:
This test was not doing its job, because the switch had too few arms
for ml_switch_gen.m to decide that a lookup switch was worthwhile.
It succeeded, but did not exercise the lookup switch code that existed
in the MLDS backend before this diff. Fix this by adding more arms.
8 lines
193 B
Plaintext
8 lines
193 B
Plaintext
N = 1: no solution
|
|
N = 2: 22 2.2 "two" 222 - 222
|
|
N = 3: 33 3.3 "three" 222 - 223
|
|
N = 4: no solution
|
|
N = 5: 55 5.5 "five" 222 - 225
|
|
N = 6: 66 6.6 "six" 222 - 226
|
|
N = 7: 77 7.7 "seven" 222 - 227
|