Add an MLDS to MLDS transformation that converts MLDS switches

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.
This commit is contained in:
Fergus Henderson
2000-11-21 13:37:45 +00:00
parent 5f06ab143e
commit 258107eeac
14 changed files with 650 additions and 503 deletions

View File

@@ -134,8 +134,8 @@ optimize_in_stmt(OptInfo, Stmt0) = Stmt :-
optimize_in_statement(OptInfo, Then),
maybe_apply(optimize_in_statement(OptInfo), MaybeElse))
;
Stmt0 = switch(Type, Rval, Cases0, Default0),
Stmt = switch(Type, Rval,
Stmt0 = switch(Type, Rval, Range, Cases0, Default0),
Stmt = switch(Type, Rval, Range,
list__map(optimize_in_case(OptInfo), Cases0),
optimize_in_default(OptInfo, Default0))
;
@@ -168,7 +168,8 @@ optimize_in_stmt(OptInfo, Stmt0) = Stmt :-
optimize_in_case(OptInfo, Conds - Statement0) = Conds - Statement :-
Statement = optimize_in_statement(OptInfo, Statement0).
:- func optimize_in_default(opt_info, mlds__switch_default) = mlds__switch_default.
:- func optimize_in_default(opt_info, mlds__switch_default) =
mlds__switch_default.
optimize_in_default(_OptInfo, default_is_unreachable) = default_is_unreachable.
optimize_in_default(_OptInfo, default_do_nothing) = default_do_nothing.
@@ -176,6 +177,8 @@ optimize_in_default(OptInfo, default_case(Statement0)) =
default_case(Statement) :-
Statement = optimize_in_statement(OptInfo, Statement0).
%-----------------------------------------------------------------------------%
:- func optimize_in_call_stmt(opt_info, mlds__stmt) = mlds__stmt.
optimize_in_call_stmt(OptInfo, Stmt0) = Stmt :-
@@ -310,7 +313,7 @@ optimize_func_stmt(OptInfo, mlds__statement(Stmt0, Context)) =
Stmt = Stmt0
).
%-----------------------------------------------------------------------------%
% Maps T into V, inside a maybe .
:- func maybe_apply(func(T) = V, maybe(T)) = maybe(V).
@@ -318,5 +321,4 @@ optimize_func_stmt(OptInfo, mlds__statement(Stmt0, Context)) =
maybe_apply(_, no) = no.
maybe_apply(F, yes(T)) = yes(F(T)).
%-----------------------------------------------------------------------------%