[m-rev.] diff: four-space indentation for jumpopt.m
Zoltan Somogyi
zs at cs.mu.OZ.AU
Thu Jun 16 13:38:03 AEST 2005
compiler/jumpopt.m:
Convert this module to four-space indentation to reduce the number
of bad line breaks.
Zoltan.
cvs diff: Diffing .
Index: jumpopt.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/jumpopt.m,v
retrieving revision 1.74
diff -u -b -r1.74 jumpopt.m
--- jumpopt.m 22 Mar 2005 06:40:02 -0000 1.74
+++ jumpopt.m 14 Jun 2005 04:30:39 -0000
@@ -1,4 +1,6 @@
%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
% Copyright (C) 1994-2005 The University of Melbourne.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
@@ -23,8 +25,8 @@
:- import_module set.
% jumpopt_main(LayoutLabels, MayAlterRtti, ProcLabel, Fulljumpopt,
- % Recjump, PessimizeTailCalls, CheckedNondetTailCall,
- % !LabelCounter, !Instrs, Mod):
+ % Recjump, PessimizeTailCalls, CheckedNondetTailCall, !LabelCounter,
+ % !Instrs, Mod):
%
% Take an instruction list and optimize jumps. This includes the jumps
% implicit in procedure returns.
@@ -48,7 +50,7 @@
%
% Mod will say whether the instruction sequence was modified
% by the optimization.
-
+ %
:- pred jumpopt_main(set(label)::in, may_alter_rtti::in, proc_label::in,
bool::in, bool::in, bool::in, bool::in, counter::in, counter::out,
list(instruction)::in, list(instruction)::out, bool::out) is det.
@@ -92,59 +94,56 @@
% been applied.
jumpopt_main(LayoutLabels, MayAlterRtti, ProcLabel, Fulljumpopt, Recjump,
- PessimizeTailCalls, CheckedNondetTailCall, !C, Instrs0, Instrs,
- Mod) :-
- map__init(Instrmap0),
- map__init(Lvalmap0),
- map__init(Procmap0),
- map__init(Sdprocmap0),
- map__init(Succmap0),
- map__init(Blockmap0),
- jumpopt__build_maps(Instrs0, Recjump, Instrmap0, Instrmap,
- Blockmap0, Blockmap, Lvalmap0, Lvalmap,
- Procmap0, Procmap1, Sdprocmap0, Sdprocmap1,
- Succmap0, Succmap1),
- map__init(Forkmap0),
- jumpopt__build_forkmap(Instrs0, Sdprocmap1, Forkmap0, Forkmap1),
- (
- PessimizeTailCalls = no,
- Procmap = Procmap1,
- Sdprocmap = Sdprocmap1,
- Succmap = Succmap1,
- Forkmap = Forkmap1
+ PessimizeTailCalls, CheckedNondetTailCall, !C, !Instrs, Mod) :-
+ some [!Instrmap, !Blockmap, !Lvalmap, !Procmap, !Sdprocmap, !Succmap,
+ !Forkmap] (
+ Instrs0 = !.Instrs,
+ map.init(!:Instrmap),
+ map.init(!:Blockmap),
+ map.init(!:Lvalmap),
+ map.init(!:Procmap),
+ map.init(!:Sdprocmap),
+ map.init(!:Succmap),
+ jumpopt__build_maps(!.Instrs, Recjump, !Instrmap, !Blockmap, !Lvalmap,
+ !Procmap, !Sdprocmap, !Succmap),
+ jumpopt__build_forkmap(!.Instrs, !.Sdprocmap, map.init, !:Forkmap),
+ (
+ PessimizeTailCalls = no
;
PessimizeTailCalls = yes,
- Procmap = map__init,
- Sdprocmap = map__init,
- Succmap = map__init,
- Forkmap = map__init
+ !:Procmap = map.init,
+ !:Sdprocmap = map.init,
+ !:Succmap = map.init,
+ !:Forkmap = map.init
),
(
CheckedNondetTailCall = yes,
CheckedNondetTailCallInfo0 = yes(ProcLabel - !.C),
- jumpopt__instr_list(Instrs0, comment(""), Instrmap, Blockmap,
- Lvalmap, Procmap, Sdprocmap, Forkmap, Succmap,
+ jumpopt__instr_list(!.Instrs, comment(""), !.Instrmap, !.Blockmap,
+ !.Lvalmap, !.Procmap, !.Sdprocmap, !.Forkmap, !.Succmap,
LayoutLabels, Fulljumpopt, MayAlterRtti,
CheckedNondetTailCallInfo0, CheckedNondetTailCallInfo,
- Instrs1),
- ( CheckedNondetTailCallInfo = yes(_ - !:C) ->
- true
+ !:Instrs),
+ (
+ CheckedNondetTailCallInfo = yes(_ - !:C)
;
+ CheckedNondetTailCallInfo = no,
error("jumpopt_main: lost the next label number")
)
;
CheckedNondetTailCall = no,
CheckedNondetTailCallInfo0 = no,
- jumpopt__instr_list(Instrs0, comment(""), Instrmap, Blockmap,
- Lvalmap, Procmap, Sdprocmap, Forkmap, Succmap,
+ jumpopt__instr_list(!.Instrs, comment(""), !.Instrmap, !.Blockmap,
+ !.Lvalmap, !.Procmap, !.Sdprocmap, !.Forkmap, !.Succmap,
LayoutLabels, Fulljumpopt, MayAlterRtti,
- CheckedNondetTailCallInfo0, _, Instrs1)
+ CheckedNondetTailCallInfo0, _, !:Instrs)
),
- opt_util__filter_out_bad_livevals(Instrs1, Instrs),
- ( Instrs = Instrs0 ->
+ opt_util__filter_out_bad_livevals(!Instrs),
+ ( !.Instrs = Instrs0 ->
Mod = no
;
Mod = yes
+ )
).
%-----------------------------------------------------------------------------%
@@ -154,16 +153,15 @@
lvalmap::in, lvalmap::out, tailmap::in, tailmap::out,
tailmap::in, tailmap::out, tailmap::in, tailmap::out) is det.
-jumpopt__build_maps([], _, !Instrmap, !Blockmap, !Lvalmap, !Procmap,
- !Sdprocmap, !Succmap).
-jumpopt__build_maps([Instr0 | Instrs0], Recjump, !Instrmap,
- !Blockmap, !Lvalmap, !Procmap, !Sdprocmap, !Succmap) :-
+jumpopt__build_maps([], _, !Instrmap, !Blockmap,
+ !Lvalmap, !Procmap, !Sdprocmap, !Succmap).
+jumpopt__build_maps([Instr0 | Instrs0], Recjump, !Instrmap, !Blockmap,
+ !Lvalmap, !Procmap, !Sdprocmap, !Succmap) :-
Instr0 = Uinstr0 - _,
( Uinstr0 = label(Label) ->
opt_util__skip_comments(Instrs0, Instrs1),
( Instrs1 = [Instr1 | _], Instr1 = livevals(_) - _ ->
- map__det_insert(!.Lvalmap, Label, yes(Instr1),
- !:Lvalmap)
+ map__det_insert(!.Lvalmap, Label, yes(Instr1), !:Lvalmap)
;
map__det_insert(!.Lvalmap, Label, no, !:Lvalmap)
),
@@ -179,8 +177,7 @@
true
),
( opt_util__is_sdproceed_next(Instrs1, Between2) ->
- map__det_insert(!.Sdprocmap, Label, Between2,
- !:Sdprocmap)
+ map__det_insert(!.Sdprocmap, Label, Between2, !:Sdprocmap)
;
true
),
@@ -204,12 +201,12 @@
;
true
),
- jumpopt__build_maps(Instrs0, Recjump, !Instrmap,
- !Blockmap, !Lvalmap, !Procmap, !Sdprocmap, !Succmap).
+ jumpopt__build_maps(Instrs0, Recjump, !Instrmap, !Blockmap, !Lvalmap,
+ !Procmap, !Sdprocmap, !Succmap).
% Find labels followed by a test of r1 where both paths set r1 to
% its original value and proceed.
-
+ %
:- pred jumpopt__build_forkmap(list(instruction)::in, tailmap::in,
tailmap::in, tailmap::out) is det.
@@ -248,7 +245,7 @@
% We also try to eliminate a goto following an if-val, if we can
% do so by negating the condition and possibly also deleting a label
% between the if-val and the goto.
-
+ %
:- pred jumpopt__instr_list(list(instruction)::in, instr::in, instrmap::in,
tailmap::in, lvalmap::in, tailmap::in, tailmap::in, tailmap::in,
tailmap::in, set(label)::in, bool::in, may_alter_rtti::in,
@@ -260,8 +257,7 @@
_Fulljumpopt, _MayAlterRtti, !CheckedNondetTailCallInfo, []).
jumpopt__instr_list([Instr0 | Instrs0], PrevInstr, Instrmap, Blockmap,
Lvalmap, Procmap, Sdprocmap, Forkmap, Succmap, LayoutLabels,
- Fulljumpopt, MayAlterRtti, !CheckedNondetTailCallInfo,
- Instrs) :-
+ Fulljumpopt, MayAlterRtti, !CheckedNondetTailCallInfo, Instrs) :-
Instr0 = Uinstr0 - Comment0,
(
Uinstr0 = call(Proc, label(RetLabel), LiveInfos, Context,
@@ -280,8 +276,7 @@
->
opt_util__filter_out_livevals(Between0, Between1),
list__append(Between1, [livevals(Livevals) - "",
- goto(Proc) - redirect_comment(Comment0)],
- NewInstrs),
+ goto(Proc) - redirect_comment(Comment0)], NewInstrs),
RemainInstrs = Instrs0
;
% Look for semidet style tailcalls.
@@ -292,8 +287,7 @@
not set__member(RetLabel, LayoutLabels)
->
list__append(Between, [livevals(Livevals) - "",
- goto(Proc) - redirect_comment(Comment0)],
- NewInstrs),
+ goto(Proc) - redirect_comment(Comment0)], NewInstrs),
RemainInstrs = Instrs0
;
% Look for nondet style tailcalls which do not need
@@ -320,8 +314,7 @@
% Look for nondet style tailcalls which do need
% a runtime check.
CallModel = nondet(checked_tail_call),
- !.CheckedNondetTailCallInfo =
- yes(ProcLabel - Counter0),
+ !.CheckedNondetTailCallInfo = yes(ProcLabel - Counter0),
map__search(Succmap, RetLabel, BetweenIncl),
BetweenIncl = [livevals(_) - _, goto(_) - _],
PrevInstr = livevals(Livevals),
@@ -331,8 +324,7 @@
counter__allocate(LabelNum, Counter0, Counter1),
NewLabel = internal(LabelNum, ProcLabel),
NewInstrs = [
- if_val(binop(ne, lval(curfr), lval(maxfr)),
- label(NewLabel))
+ if_val(binop(ne, lval(curfr), lval(maxfr)), label(NewLabel))
- "branch around if cannot tail call",
assign(maxfr, lval(prevfr(lval(curfr))))
- "discard this frame",
@@ -359,10 +351,8 @@
NewInstrs = [Instr0],
RemainInstrs = Instrs0
;
- NewInstrs = [call(Proc, label(DestLabel),
- LiveInfos, Context, GoalPath,
- CallModel)
- - redirect_comment(Comment0)],
+ NewInstrs = [call(Proc, label(DestLabel), LiveInfos, Context,
+ GoalPath, CallModel) - redirect_comment(Comment0)],
RemainInstrs = Instrs0
)
;
@@ -395,23 +385,20 @@
map__search(Procmap, TargetLabel, Between0)
->
jumpopt__adjust_livevals(PrevInstr, Between0, Between),
- list__append(Between, [goto(succip) - "shortcircuit"],
- NewInstrs),
+ list__append(Between, [goto(succip) - "shortcircuit"], NewInstrs),
RemainInstrs = Instrs0
;
% Replace a jump to a semidet epilog with the epilog.
map__search(Sdprocmap, TargetLabel, Between0)
->
jumpopt__adjust_livevals(PrevInstr, Between0, Between),
- list__append(Between, [goto(succip) - "shortcircuit"],
- NewInstrs),
+ list__append(Between, [goto(succip) - "shortcircuit"], NewInstrs),
RemainInstrs = Instrs0
;
% Replace a jump to a nondet epilog with the epilog.
map__search(Succmap, TargetLabel, BetweenIncl0)
->
- jumpopt__adjust_livevals(PrevInstr, BetweenIncl0,
- NewInstrs),
+ jumpopt__adjust_livevals(PrevInstr, BetweenIncl0, NewInstrs),
RemainInstrs = Instrs0
;
% Replace a jump to a non-epilog block with the
@@ -436,17 +423,15 @@
block_may_be_duplicated(Block) = yes
->
opt_util__filter_out_labels(Block, FilteredBlock),
- jumpopt__adjust_livevals(PrevInstr, FilteredBlock,
- AdjustedBlock),
+ jumpopt__adjust_livevals(PrevInstr, FilteredBlock, AdjustedBlock),
% Block may end with a goto to DestLabel. We avoid
% infinite expansion in such cases by removing
% DestLabel from Blockmap, though only while
% processing AdjustedBlock.
map__delete(Blockmap, DestLabel, CrippledBlockmap),
- jumpopt__instr_list(AdjustedBlock, comment(""),
- Instrmap, CrippledBlockmap, Lvalmap, Procmap,
- Sdprocmap, Forkmap, Succmap, LayoutLabels,
- Fulljumpopt, MayAlterRtti,
+ jumpopt__instr_list(AdjustedBlock, comment(""), Instrmap,
+ CrippledBlockmap, Lvalmap, Procmap, Sdprocmap, Forkmap,
+ Succmap, LayoutLabels, Fulljumpopt, MayAlterRtti,
!CheckedNondetTailCallInfo, NewInstrs),
RemainInstrs = Instrs0
;
@@ -456,10 +441,8 @@
jumpopt__final_dest(Instrmap, TargetLabel, DestLabel,
TargetInstr, DestInstr),
DestInstr = UdestInstr - _Destcomment,
- string__append("shortcircuited jump: ",
- Comment0, Shorted),
- opt_util__can_instr_fall_through(UdestInstr,
- Canfallthrough),
+ string__append("shortcircuited jump: ", Comment0, Shorted),
+ opt_util__can_instr_fall_through(UdestInstr, Canfallthrough),
( Canfallthrough = no ->
NewInstrs0 = [UdestInstr - Shorted],
RemainInstrs = Instrs0
@@ -468,14 +451,13 @@
NewInstrs0 = [Instr0],
RemainInstrs = Instrs0
;
- NewInstrs0 = [goto(label(DestLabel))
- - Shorted],
+ NewInstrs0 = [goto(label(DestLabel)) - Shorted],
RemainInstrs = Instrs0
)
),
( map__search(Lvalmap, DestLabel, yes(Lvalinstr)) ->
- jumpopt__adjust_livevals(PrevInstr,
- [Lvalinstr | NewInstrs0], NewInstrs)
+ jumpopt__adjust_livevals(PrevInstr, [Lvalinstr | NewInstrs0],
+ NewInstrs)
;
NewInstrs = NewInstrs0
)
@@ -483,18 +465,21 @@
NewInstrs = [Instr0],
RemainInstrs = Instrs0
)
- ; Uinstr0 = computed_goto(Index, LabelList0) ->
+ ;
+ Uinstr0 = computed_goto(Index, LabelList0)
+ ->
% Short-circuit all the destination labels.
jumpopt__short_labels(Instrmap, LabelList0, LabelList),
RemainInstrs = Instrs0,
( LabelList = LabelList0 ->
NewInstrs = [Instr0]
;
- string__append(Comment0, " (some shortcircuits)",
- Shorted),
+ string__append(Comment0, " (some shortcircuits)", Shorted),
NewInstrs = [computed_goto(Index, LabelList) - Shorted]
)
- ; Uinstr0 = if_val(Cond, label(TargetLabel)) ->
+ ;
+ Uinstr0 = if_val(Cond, label(TargetLabel))
+ ->
(
% Attempt to transform code such as
%
@@ -575,8 +560,7 @@
NewIfInstr = if_val(NotCond, GotoAddr) - GotoComment,
NewInstrs = [NewIfInstr],
NewGotoComment = Comment0 ++ " (switched)",
- NewGotoInstr = goto(label(TargetLabel)) -
- NewGotoComment,
+ NewGotoInstr = goto(label(TargetLabel)) - NewGotoComment,
RemainInstrs = [NewGotoInstr | AfterGoto]
;
map__search(Instrmap, TargetLabel, TargetInstr)
@@ -602,10 +586,8 @@
opt_util__is_sdproceed_next(Instrs0, BetweenFT),
map__search(Blockmap, DestLabel, Block),
opt_util__is_sdproceed_next(Block, BetweenBR),
- opt_util__filter_out_r1(BetweenFT,
- yes(SuccessFT), Between),
- opt_util__filter_out_r1(BetweenBR,
- yes(SuccessBR), Between),
+ opt_util__filter_out_r1(BetweenFT, yes(SuccessFT), Between),
+ opt_util__filter_out_r1(BetweenBR, yes(SuccessBR), Between),
(
SuccessFT = true,
SuccessBR = false,
@@ -624,17 +606,14 @@
"shortcircuit bool computation"
),
Proceed = goto(succip) - "shortcircuit",
- list__append([NewAssign | Between], [Proceed],
- NewInstrs),
+ list__append([NewAssign | Between], [Proceed], NewInstrs),
RemainInstrs = Instrs0
;
% Try to short-circuit the destination.
TargetLabel \= DestLabel
->
- string__append("shortcircuited jump: ",
- Comment0, Shorted),
- NewInstrs = [if_val(Cond, label(DestLabel))
- - Shorted],
+ string__append("shortcircuited jump: ", Comment0, Shorted),
+ NewInstrs = [if_val(Cond, label(DestLabel)) - Shorted],
RemainInstrs = Instrs0
;
NewInstrs = [Instr0],
@@ -644,27 +623,28 @@
NewInstrs = [Instr0],
RemainInstrs = Instrs0
)
- ; Uinstr0 = assign(Lval, Rval0) ->
+ ;
+ Uinstr0 = assign(Lval, Rval0)
+ ->
% Any labels mentioned in Rval0 should be short-circuited.
jumpopt__short_labels_rval(Instrmap, Rval0, Rval),
RemainInstrs = Instrs0,
( Rval = Rval0 ->
NewInstrs = [Instr0]
;
- string__append(Comment0, " (some shortcircuits)",
- Shorted),
+ Shorted = Comment0 ++ " (some shortcircuits)",
NewInstrs = [assign(Lval, Rval) - Shorted]
)
- ; Uinstr0 = mkframe(FrameInfo, yes(label(Label0))) ->
+ ;
+ Uinstr0 = mkframe(FrameInfo, yes(label(Label0)))
+ ->
jumpopt__short_label(Instrmap, Label0, Label),
RemainInstrs = Instrs0,
( Label = Label0 ->
NewInstrs = [Instr0]
;
- string__append(Comment0, " (some shortcircuits)",
- Shorted),
- NewInstrs = [mkframe(FrameInfo, yes(label(Label)))
- - Shorted]
+ string__append(Comment0, " (some shortcircuits)", Shorted),
+ NewInstrs = [mkframe(FrameInfo, yes(label(Label))) - Shorted]
)
;
NewInstrs = [Instr0],
@@ -677,8 +657,7 @@
),
jumpopt__instr_list(RemainInstrs, NewPrevInstr, Instrmap, Blockmap,
Lvalmap, Procmap, Sdprocmap, Forkmap, Succmap, LayoutLabels,
- Fulljumpopt, MayAlterRtti, !CheckedNondetTailCallInfo,
- Instrs9),
+ Fulljumpopt, MayAlterRtti, !CheckedNondetTailCallInfo, Instrs9),
list__append(NewInstrs, Instrs9, Instrs).
:- func block_may_be_duplicated(list(instruction)) = bool.
@@ -762,8 +741,7 @@
( BetweenLivevals = PrevLivevals ->
Instrs = Instrs2
;
- error("BetweenLivevals and PrevLivevals differ " ++
- "in jumpopt")
+ error("BetweenLivevals and PrevLivevals differ in jumpopt")
)
;
Instrs = Instrs0
@@ -773,7 +751,7 @@
% Short-circuit the given label by following any gotos at the
% labelled instruction or by falling through consecutive labels.
-
+ %
:- pred jumpopt__short_label(instrmap::in, label::in, label::out) is det.
jumpopt__short_label(Instrmap, Label0, Label) :-
@@ -795,7 +773,7 @@
% Find the final destination of a given instruction at a given label.
% We follow gotos as well as consecutive labels.
-
+ %
:- pred jumpopt__final_dest(instrmap::in, label::in, label::out,
instruction::in, instruction::out) is det.
cvs diff: Diffing notes
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list