mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-20 03:43:51 +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.
137 lines
1.1 KiB
Plaintext
137 lines
1.1 KiB
Plaintext
p1 a ->
|
|
p1_one f1 1.1
|
|
end
|
|
|
|
p1 b ->
|
|
p1_two f2 2.2
|
|
end
|
|
|
|
p1 c ->
|
|
p1_three f1 3.3
|
|
end
|
|
|
|
p1 d ->
|
|
p1_four f1 4.4
|
|
end
|
|
|
|
p1 e ->
|
|
p1_five f2 5.5
|
|
p1_five2 f3(5) 55.5
|
|
end
|
|
|
|
p1 f ->
|
|
p1_six f4("hex") 6.6
|
|
end
|
|
|
|
p1 g ->
|
|
p1_seven f5(77.7) 7.7
|
|
p1_seven2 f1 777.7
|
|
p1_seven3 f2 7777.7
|
|
end
|
|
|
|
p1 h ->
|
|
p1_eight f1 8.0
|
|
end
|
|
|
|
p2 a ->
|
|
p2_one f1 1.1
|
|
end
|
|
|
|
p2 b ->
|
|
end
|
|
|
|
p2 c ->
|
|
p2_three f1 3.3
|
|
end
|
|
|
|
p2 d ->
|
|
p2_four f1 4.4
|
|
end
|
|
|
|
p2 e ->
|
|
p2_five f2 5.5
|
|
p2_five2 f3(5) 55.5
|
|
end
|
|
|
|
p2 f ->
|
|
p2_six f4("hex") 6.6
|
|
end
|
|
|
|
p2 g ->
|
|
p2_seven f5(77.7) 7.7
|
|
p2_seven2 f1 777.7
|
|
p2_seven3 f2 7777.7
|
|
end
|
|
|
|
p2 h ->
|
|
end
|
|
|
|
p3 -1 ->
|
|
end
|
|
|
|
p3 0 ->
|
|
end
|
|
|
|
p3 1 ->
|
|
end
|
|
|
|
p3 2 ->
|
|
p3_two_a f2 6.6
|
|
p3_two_b f2 8.8
|
|
end
|
|
|
|
p3 3 ->
|
|
p3_three f3(5) 66.6
|
|
end
|
|
|
|
p3 4 ->
|
|
p3_four_a f5(78.7) 7.8
|
|
p3_four_b f1 999.7
|
|
p3_four_c f2 9999.7
|
|
end
|
|
|
|
p3 5 ->
|
|
p3_five f5(88.8) 9999.9
|
|
end
|
|
|
|
p3 6 ->
|
|
end
|
|
|
|
p3 7 ->
|
|
end
|
|
|
|
p4 -1 ->
|
|
end
|
|
|
|
p4 0 ->
|
|
end
|
|
|
|
p4 1 ->
|
|
end
|
|
|
|
p4 2 ->
|
|
p4_two_a f2 6.6
|
|
p4_two_b f2 8.8
|
|
end
|
|
|
|
p4 3 ->
|
|
end
|
|
|
|
p4 4 ->
|
|
p4_four_a f5(78.7) 7.8
|
|
p4_four_b f1 999.7
|
|
p4_four_c f2 9999.7
|
|
end
|
|
|
|
p4 5 ->
|
|
p4_five f5(88.8) 9999.9
|
|
end
|
|
|
|
p4 6 ->
|
|
p4_six f5(66.0) 666.6
|
|
end
|
|
|
|
p4 7 ->
|
|
end
|
|
|