[m-rev.] diff: replace some if-then-elses with switches
Julien Fischer
juliensf at csse.unimelb.edu.au
Thu Oct 11 00:34:57 AEST 2007
Estimated hours taken: 0.5
Branches: main
Replace more if-then-elses with switches (particularly on the
type builtin_state/0).
compiler/cse_detection.m:
compiler/deep_profiling.m:
compiler/dependency_graph.m:
compiler/follow_vars.m:
compiler/goal_form.m:
compiler/interval.m:
compiler/live_vars.m:
compiler/lp_rational.m:
compiler/pd_cost.m:
compiler/simplify.m:
compiler/tupling.m:
As above.
Julien.
Index: cse_detection.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/cse_detection.m,v
retrieving revision 1.110
diff -u -r1.110 cse_detection.m
--- cse_detection.m 7 Aug 2007 07:09:49 -0000 1.110
+++ cse_detection.m 10 Oct 2007 14:30:44 -0000
@@ -281,10 +281,12 @@
Redo, conj(ConjType, Goals)) :-
detect_cse_in_conj(Goals0, ConjType, InstMap, !CseInfo, Redo, Goals).
detect_cse_in_goal_2(disj(Goals0), GoalInfo, InstMap, !CseInfo, Redo, Goal) :-
- ( Goals0 = [] ->
+ (
+ Goals0 = [],
Redo = no,
Goal = disj([])
;
+ Goals0 = [_ | _],
NonLocals = goal_info_get_nonlocals(GoalInfo),
set.to_sorted_list(NonLocals, NonLocalsList),
detect_cse_in_disj(NonLocalsList, Goals0, GoalInfo,
Index: deep_profiling.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/deep_profiling.m,v
retrieving revision 1.65
diff -u -r1.65 deep_profiling.m
--- deep_profiling.m 13 Aug 2007 03:01:39 -0000 1.65
+++ deep_profiling.m 10 Oct 2007 14:30:44 -0000
@@ -366,10 +366,13 @@
;
true
),
- ( BuiltinState \= inline_builtin ->
+ (
+ ( BuiltinState = out_of_line_builtin
+ ; BuiltinState = not_builtin
+ ),
!:N = !.N + 1
;
- true
+ BuiltinState = inline_builtin
)
;
GoalExpr = generic_call(_, _, _, _),
@@ -917,10 +920,14 @@
Goal0 = hlds_goal(GoalExpr0, GoalInfo0),
(
GoalExpr0 = plain_call(_, _, _, BuiltinState, _, _),
- ( BuiltinState \= inline_builtin ->
+ (
+ ( BuiltinState = out_of_line_builtin
+ ; BuiltinState = not_builtin
+ ),
deep_prof_wrap_call(Path, Goal0, Goal, !DeepInfo),
AddedImpurity = yes
;
+ BuiltinState = inline_builtin,
Goal = Goal0,
AddedImpurity = no
)
Index: dependency_graph.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/dependency_graph.m,v
retrieving revision 1.96
diff -u -r1.96 dependency_graph.m
--- dependency_graph.m 7 Sep 2007 15:08:16 -0000 1.96
+++ dependency_graph.m 10 Oct 2007 14:30:44 -0000
@@ -378,9 +378,12 @@
GoalExpr = generic_call(_, _, _, _)
;
GoalExpr = plain_call(PredId, ProcId, _, Builtin, _, _),
- ( Builtin = inline_builtin ->
- true
+ (
+ Builtin = inline_builtin
;
+ ( Builtin = out_of_line_builtin
+ ; Builtin = not_builtin
+ ),
(
% If the node isn't in the graph, then we didn't insert it
% because is was imported, and we don't consider it.
Index: follow_vars.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/follow_vars.m,v
retrieving revision 1.87
diff -u -r1.87 follow_vars.m
--- follow_vars.m 6 Jan 2007 09:23:31 -0000 1.87
+++ follow_vars.m 10 Oct 2007 14:30:44 -0000
@@ -246,9 +246,12 @@
plain_call(PredId, ProcId, Args, State, UC, Name),
plain_call(PredId, ProcId, Args, State, UC, Name), GoalInfo, GoalInfo,
_, ModuleInfo, !FollowVarsMap, !NextNonReserved) :-
- ( State = inline_builtin ->
- true
+ (
+ State = inline_builtin
;
+ ( State = out_of_line_builtin
+ ; State = not_builtin
+ ),
find_follow_vars_in_call(PredId, ProcId, Args, ModuleInfo,
!:FollowVarsMap, !:NextNonReserved)
).
Index: goal_form.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/goal_form.m,v
retrieving revision 1.39
diff -u -r1.39 goal_form.m
--- goal_form.m 7 Aug 2007 07:09:53 -0000 1.39
+++ goal_form.m 10 Oct 2007 14:30:44 -0000
@@ -599,9 +599,13 @@
goal_may_allocate_heap_2(generic_call(_, _, _, _), yes).
goal_may_allocate_heap_2(plain_call(_, _, _, Builtin, _, _), May) :-
- ( Builtin = inline_builtin ->
+ (
+ Builtin = inline_builtin,
May = no
;
+ ( Builtin = out_of_line_builtin
+ ; Builtin = not_builtin
+ ),
May = yes
).
goal_may_allocate_heap_2(unify(_, _, _, Unification, _), May) :-
Index: interval.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/interval.m,v
retrieving revision 1.33
diff -u -r1.33 interval.m
--- interval.m 28 Sep 2007 03:17:12 -0000 1.33
+++ interval.m 10 Oct 2007 14:30:44 -0000
@@ -310,10 +310,14 @@
arg_info.partition_proc_call_args(ProcInfo, VarTypes,
ModuleInfo, ArgVars, InputArgs, _, _),
set.to_sorted_list(InputArgs, Inputs),
- ( Builtin = inline_builtin ->
+ (
+ Builtin = inline_builtin,
require_in_regs(Inputs, !IntervalInfo),
require_access(Inputs, !IntervalInfo)
;
+ ( Builtin = out_of_line_builtin
+ ; Builtin = not_builtin
+ ),
goal_info_get_maybe_need_across_call(GoalInfo,
MaybeNeedAcrossCall),
build_interval_info_at_call(Inputs, MaybeNeedAcrossCall, GoalInfo,
@@ -954,18 +958,27 @@
;
GoalExpr0 = generic_call(GenericCall, _, _, _),
% Casts are generated inline.
- ( GenericCall = cast(_) ->
+ (
+ GenericCall = cast(_),
MustHaveMap = no
;
+ ( GenericCall = higher_order(_, _, _, _)
+ ; GenericCall = class_method(_, _, _, _)
+ ; GenericCall = event_call(_)
+ ),
MustHaveMap = yes
),
record_decisions_at_call_site(Goal0, Goal, !VarInfo, !VarRename,
MustHaveMap, InsertMap, MaybeFeature)
;
GoalExpr0 = plain_call(_, _, _, Builtin, _, _),
- ( Builtin = inline_builtin ->
+ (
+ Builtin = inline_builtin,
MustHaveMap = no
;
+ ( Builtin = out_of_line_builtin
+ ; Builtin = not_builtin
+ ),
MustHaveMap = yes
),
record_decisions_at_call_site(Goal0, Goal, !VarInfo, !VarRename,
Index: live_vars.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/live_vars.m,v
retrieving revision 1.131
diff -u -r1.131 live_vars.m
--- live_vars.m 7 Aug 2007 07:09:57 -0000 1.131
+++ live_vars.m 10 Oct 2007 14:30:44 -0000
@@ -339,9 +339,14 @@
build_live_sets_in_goal_2(Goal, Goal, GoalInfo0, GoalInfo, ResumeVars0,
AllocData, !StackAlloc, !Liveness, !NondetLiveness, !ParStackVars) :-
Goal = generic_call(GenericCall, ArgVars, Modes, _Det),
- ( GenericCall = cast(_) ->
+ (
+ GenericCall = cast(_),
GoalInfo = GoalInfo0
;
+ ( GenericCall = higher_order(_, _, _, _)
+ ; GenericCall = class_method(_, _, _, _)
+ ; GenericCall = event_call(_)
+ ),
ProcInfo = AllocData ^ proc_info,
proc_info_get_vartypes(ProcInfo, VarTypes),
map.apply_to_list(ArgVars, VarTypes, Types),
@@ -361,9 +366,13 @@
module_info_pred_proc_info(ModuleInfo, PredId, ProcId, _, ProcInfo),
arg_info.partition_proc_call_args(ProcInfo, VarTypes, ModuleInfo,
ArgVars, _InVars, OutVars, _UnusedVars),
- ( Builtin = inline_builtin ->
+ (
+ Builtin = inline_builtin,
GoalInfo = GoalInfo0
;
+ ( Builtin = out_of_line_builtin
+ ; Builtin = not_builtin
+ ),
build_live_sets_in_call(OutVars, GoalInfo0, GoalInfo,
ResumeVars0, AllocData, !StackAlloc, !.Liveness, !NondetLiveness,
!ParStackVars)
Index: lp_rational.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/lp_rational.m,v
retrieving revision 1.9
diff -u -r1.9 lp_rational.m
--- lp_rational.m 23 May 2007 10:09:18 -0000 1.9
+++ lp_rational.m 10 Oct 2007 14:30:44 -0000
@@ -1445,7 +1445,8 @@
% Skip the call to fourier_elimination/6 if there are no variables to
% project - this avoids the transformation to vector form.
%
- ( !.Vars \= [] ->
+ (
+ !.Vars = [_ | _],
Matrix0 = constraints_to_matrix(Constraints1),
fourier_elimination(!.Vars, Varset, MaybeThreshold, 0,
Matrix0, FourierResult),
@@ -1463,6 +1464,7 @@
% would mean traversing the matrix, so we wait until the next
% operation that needs to traverse it anyway or until the
% next entailment check.
+ !.Vars = [],
Result = ok(Constraints1)
)
).
Index: pd_cost.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/pd_cost.m,v
retrieving revision 1.34
diff -u -r1.34 pd_cost.m
--- pd_cost.m 7 Aug 2007 07:10:01 -0000 1.34
+++ pd_cost.m 10 Oct 2007 14:30:44 -0000
@@ -76,9 +76,13 @@
Cost = Cost1 + Cost2 + Cost3.
goal_expr_cost(plain_call(_, _, Args, BuiltinState, _, _), _, Cost) :-
- ( BuiltinState = inline_builtin ->
+ (
+ BuiltinState = inline_builtin,
Cost = cost_of_builtin_call
;
+ ( BuiltinState = out_of_line_builtin
+ ; BuiltinState = not_builtin
+ ),
list.length(Args, Arity),
InputArgs = Arity // 2, % rough
Cost = cost_of_stack_flush + cost_of_call
Index: simplify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.217
diff -u -r1.217 simplify.m
--- simplify.m 28 Sep 2007 03:17:13 -0000 1.217
+++ simplify.m 10 Oct 2007 14:30:44 -0000
@@ -3470,9 +3470,13 @@
WillFlush = no
).
will_flush(plain_call(_, _, _, BuiltinState, _, _), BeforeAfter) = WillFlush :-
- ( BuiltinState = inline_builtin ->
+ (
+ BuiltinState = inline_builtin,
WillFlush = no
;
+ ( BuiltinState = out_of_line_builtin
+ ; BuiltinState = not_builtin
+ ),
(
BeforeAfter = before,
WillFlush = no
Index: tupling.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/tupling.m,v
retrieving revision 1.39
diff -u -r1.39 tupling.m
--- tupling.m 7 Sep 2007 15:08:19 -0000 1.39
+++ tupling.m 10 Oct 2007 14:30:44 -0000
@@ -1222,10 +1222,14 @@
arg_info.partition_proc_call_args(CalleeProcInfo, VarTypes,
ModuleInfo, ArgVars, InputArgs, Outputs, _),
set.to_sorted_list(InputArgs, Inputs),
- ( Builtin = inline_builtin ->
+ (
+ Builtin = inline_builtin,
cls_require_in_regs(CountInfo, Inputs, !CountState),
cls_put_in_regs(set.to_sorted_list(Outputs), !CountState)
- ;
+ ;
+ ( Builtin = out_of_line_builtin
+ ; Builtin = not_builtin
+ ),
goal_info_get_maybe_need_across_call(GoalInfo,
MaybeNeedAcrossCall),
count_load_stores_for_call(CountInfo, Inputs, Outputs,
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list