[m-rev.] diff: frameopt cleanup

Zoltan Somogyi zs at cs.mu.OZ.AU
Thu Aug 4 15:50:02 AEST 2005


compiler/frameopt.m:
	Conform to the standard format for comments.

	Change to four-space indentation to reduce the number of bad line
	breaks.

	There are no algorithmic changes.

Zoltan.

cvs diff: Diffing .
Index: frameopt.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/frameopt.m,v
retrieving revision 1.89
diff -u -b -r1.89 frameopt.m
--- frameopt.m	24 Mar 2005 02:00:25 -0000	1.89
+++ frameopt.m	3 Aug 2005 10:44:26 -0000
@@ -1,4 +1,6 @@
 %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
 % Copyright (C) 1994-2001,2003-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.
@@ -99,8 +101,7 @@
 :- import_module list.
 :- import_module set.
 
-	% frameopt_main(ProcLabel, !LabelCounter, !Instrs,
-	%	AnyChange, NewJumps):
+    % frameopt_main(ProcLabel, !LabelCounter, !Instrs, AnyChange, NewJumps):
 	%
 	% Attempt to update !Instrs using the one of the transformations
 	% described above for procedures that live on the det stack.
@@ -114,7 +115,7 @@
 	% If yes, then we also introduced some extra labels that should be
 	% deleted. NewJumps says whether we introduced any jumps that could
 	% be profitably be short-circuited.
-
+    %
 :- pred frameopt_main(proc_label::in, counter::in, counter::out,
 	list(instruction)::in, list(instruction)::out,
 	bool::out, bool::out) is det.
@@ -138,7 +139,7 @@
 	% If yes, then we also introduced some extra labels that should be
 	% deleted, and we introduced some jumps that may be profitably
 	% short-circuited.
-
+    %
 :- pred frameopt_nondet(proc_label::in, set(label)::in, may_alter_rtti::in,
 	counter::in, counter::out,
 	list(instruction)::in, list(instruction)::out, bool::out) is det.
@@ -161,40 +162,40 @@
 :- import_module set.
 :- import_module std_util.
 :- import_module string.
+:- import_module svmap.
+:- import_module svqueue.
+:- import_module svset.
 
 frameopt_main(ProcLabel, !C, Instrs0, Instrs, Mod, Jumps) :-
 	opt_util__get_prologue(Instrs0, LabelInstr, Comments0, Instrs1),
 	( frameopt__detstack_setup(Instrs1, FrameSize, Msg, _, _, _) ->
-		map__init(BlockMap0),
+    	some [!BlockMap] (
+            map__init(!:BlockMap),
 		divide_into_basic_blocks([LabelInstr | Instrs1], ProcLabel,
 			BasicInstrs, !C),
 		build_block_map(BasicInstrs, FrameSize, LabelSeq0,
-			BlockMap0, BlockMap1, ProcLabel, !C),
-		analyze_block_map(LabelSeq0, BlockMap1, BlockMap2, KeepFrame),
+                !BlockMap, ProcLabel, !C),
+            analyze_block_map(LabelSeq0, !BlockMap, KeepFrame),
 		(
 			KeepFrame = yes(FirstLabel - SecondLabel),
-			CanClobberSuccip =
-				can_clobber_succip(LabelSeq0, BlockMap2),
+                CanClobberSuccip = can_clobber_succip(LabelSeq0, !.BlockMap),
 			keep_frame(LabelSeq0, FirstLabel, SecondLabel,
-				CanClobberSuccip, BlockMap2, BlockMap),
+                    CanClobberSuccip, !BlockMap),
 			LabelSeq = LabelSeq0,
 			NewComment = comment("keeping stack frame") - "",
 			list__append(Comments0, [NewComment], Comments),
-			flatten_block_seq(LabelSeq, BlockMap, BodyInstrs),
+                flatten_block_seq(LabelSeq, !.BlockMap, BodyInstrs),
 			list__append(Comments, BodyInstrs, Instrs),
 			Mod = yes,
 			Jumps = yes
 		;
 			KeepFrame = no,
-			( can_delay_frame(LabelSeq0, BlockMap2, yes) ->
-				delay_frame(LabelSeq0, LabelSeq, FrameSize,
-					Msg, ProcLabel, !C,
-					BlockMap2, BlockMap),
-				NewComment = comment("delaying stack frame")
-					- "",
+                ( can_delay_frame(LabelSeq0, !.BlockMap, yes) ->
+                    delay_frame(LabelSeq0, LabelSeq, FrameSize, Msg, ProcLabel,
+                        !C, !BlockMap),
+                    NewComment = comment("delaying stack frame") - "",
 				list__append(Comments0, [NewComment], Comments),
-				flatten_block_seq(LabelSeq, BlockMap,
-					BodyInstrs),
+                    flatten_block_seq(LabelSeq, !.BlockMap, BodyInstrs),
 				list__append(Comments, BodyInstrs, Instrs),
 				Mod = yes,
 				Jumps = no
@@ -204,6 +205,7 @@
 				Jumps = no
 			)
 		)
+        )
 	;
 		Instrs = Instrs0,
 		Mod = no,
@@ -239,9 +241,7 @@
 		list__condense([[LabelInstr], Comments0,
 			[mkframe(FrameInfo, no) - MkframeComment,
 			label(KeepFrameLabel) - "tail recursion target",
-			assign(redoip(lval(curfr)),
-				const(code_addr_const(Redoip)))
-				- ""],
+            assign(redoip(lval(curfr)), const(code_addr_const(Redoip))) - ""],
 			Instrs2], Instrs),
 		Mod = yes
 	;
@@ -253,8 +253,8 @@
 	nondet_frame_info::out, code_addr::out,
 	instruction::out, list(instruction)::out) is semidet.
 
-frameopt__nondetstack_setup(Instrs0, FrameInfo, Redoip,
-		MkframeInstr, Remain) :-
+frameopt__nondetstack_setup(Instrs0, FrameInfo, Redoip, MkframeInstr,
+        Remain) :-
 	Instrs0 = [MkframeInstr | Remain],
 	MkframeInstr = mkframe(FrameInfo, yes(Redoip)) - _,
 	FrameInfo = ordinary_frame(_, _, _).
@@ -270,7 +270,7 @@
 		opt_util__skip_comments(Instrs, TailInstrs),
 		opt_util__is_succeed_next(TailInstrs, Between)
 	->
-		map__det_insert(!.SuccMap, Label, Between, !:SuccMap)
+        svmap__det_insert(Label, Between, !SuccMap)
 	;
 		true
 	),
@@ -351,7 +351,7 @@
 
 	% Add labels to the given instruction sequence so that
 	% every basic block has labels around it.
-
+    %
 :- pred divide_into_basic_blocks(list(instruction)::in, proc_label::in,
 	list(instruction)::out, counter::in, counter::out) is det.
 
@@ -365,15 +365,13 @@
 		(
 			Instrs0 = [Instr1 | _],
 			( Instr1 = label(_) - _ ->
-				divide_into_basic_blocks(Instrs0, ProcLabel,
-					Instrs1, !C),
+                divide_into_basic_blocks(Instrs0, ProcLabel, Instrs1, !C),
 				Instrs = [Instr0 | Instrs1]
 			;
 				counter__allocate(N, !C),
 				NewLabel = internal(N, ProcLabel),
 				NewInstr = label(NewLabel) - "",
-				divide_into_basic_blocks(Instrs0, ProcLabel,
-					Instrs1, !C),
+                divide_into_basic_blocks(Instrs0, ProcLabel, Instrs1, !C),
 				Instrs = [Instr0, NewInstr | Instrs1]
 			)
 		;
@@ -406,7 +404,7 @@
 	% Put these block_info structures into a table indexed by the label,
 	% and return the sequence of labels of the blocks in their original
 	% order.
-
+    %
 :- pred build_block_map(list(instruction)::in, int::in, list(label)::out,
 	block_map::in, block_map::out, proc_label::in,
 	counter::in, counter::out) is det.
@@ -416,14 +414,12 @@
 		ProcLabel, !C) :-
 	( Instr0 = label(Label) - _ ->
 		(
-			frameopt__detstack_setup(Instrs0, _, _, Setup,
-				Others, Remain)
+            frameopt__detstack_setup(Instrs0, _, _, Setup, Others, Remain)
 		->
 			% Create a block with just the Setup instructions
 			% in it.
 
-			BlockInfo = block_info(Label, [Instr0 | Setup],
-				[], no, setup),
+            BlockInfo = block_info(Label, [Instr0 | Setup], [], no, setup),
 			list__append(Others, Remain, Instrs1),
 			(
 				Instrs1 = [Instr1 | _],
@@ -436,64 +432,58 @@
 				NewInstr = label(NewLabel) - "",
 				Instrs2 = [NewInstr | Instrs1]
 			),
-			build_block_map(Instrs2, FrameSize, LabelSeq0,
-				!BlockMap, ProcLabel, !C),
-			map__det_insert(!.BlockMap, Label, BlockInfo,
-				!:BlockMap),
+            build_block_map(Instrs2, FrameSize, LabelSeq0, !BlockMap,
+                ProcLabel, !C),
+            svmap__det_insert(Label, BlockInfo, !BlockMap),
 			LabelSeq = [Label | LabelSeq0]
 		;
-			frameopt__detstack_teardown(Instrs0, FrameSize,
-				Tail, Succip, Decrsp, Livevals, Goto, Remain)
+            frameopt__detstack_teardown(Instrs0, FrameSize, Tail, Succip,
+                Decrsp, Livevals, Goto, Remain)
 		->
 			list__append(Livevals, [Goto], Teardown0),
 			list__append(Decrsp, Teardown0, Teardown1),
 			list__append(Succip, Teardown1, Teardown),
-			( Tail = [] ->
+            (
+                Tail = [],
 				MaybeTailInfo = no,
 				LabelledBlock = [Instr0 | Teardown],
 				TeardownLabel = Label,
-				TeardownInfo = block_info(TeardownLabel,
-					LabelledBlock, [], no,
+                TeardownInfo = block_info(TeardownLabel, LabelledBlock, [], no,
 					teardown(Succip, Livevals, Goto))
 			;
+                Tail = [_ | _],
 				block_needs_frame(Tail, Needs),
-				TailInfo = block_info(Label, [Instr0 | Tail],
-					[], no, ordinary(Needs)),
+                TailInfo = block_info(Label, [Instr0 | Tail], [], no,
+                    ordinary(Needs)),
 				MaybeTailInfo = yes(TailInfo - Label),
 				counter__allocate(N, !C),
 				NewLabel = internal(N, ProcLabel),
 				NewInstr = label(NewLabel) - "",
 				LabelledBlock = [NewInstr | Teardown],
 				TeardownLabel = NewLabel,
-				TeardownInfo = block_info(TeardownLabel,
-					LabelledBlock, [], no,
+                TeardownInfo = block_info(TeardownLabel, LabelledBlock, [], no,
 					teardown(Succip, Livevals, Goto))
 			),
-			build_block_map(Remain, FrameSize, LabelSeq0,
-				!BlockMap, ProcLabel, !C),
+            build_block_map(Remain, FrameSize, LabelSeq0, !BlockMap,
+                ProcLabel, !C),
 			(
 				MaybeTailInfo = no,
-				map__det_insert(!.BlockMap, TeardownLabel,
-					TeardownInfo, !:BlockMap),
+                svmap__det_insert(TeardownLabel, TeardownInfo, !BlockMap),
 				LabelSeq = [TeardownLabel | LabelSeq0]
 			;
 				MaybeTailInfo = yes(TailInfo2 - TailLabel2),
-				map__det_insert(!.BlockMap, TeardownLabel,
-					TeardownInfo, !:BlockMap),
-				map__det_insert(!.BlockMap, TailLabel2,
-					TailInfo2, !:BlockMap),
-				LabelSeq = [TailLabel2, TeardownLabel
-					| LabelSeq0]
+                svmap__det_insert(TeardownLabel, TeardownInfo, !BlockMap),
+                svmap__det_insert(TailLabel2, TailInfo2, !BlockMap),
+                LabelSeq = [TailLabel2, TeardownLabel | LabelSeq0]
 			)
 		;
 			opt_util__skip_to_next_label(Instrs0, Block, Instrs1),
 			block_needs_frame(Block, Needs),
-			BlockInfo = block_info(Label, [Instr0 | Block],
-				[], no, ordinary(Needs)),
-			build_block_map(Instrs1, FrameSize, LabelSeq0,
-				!BlockMap, ProcLabel, !C),
-			map__det_insert(!.BlockMap, Label, BlockInfo,
-				!:BlockMap),
+            BlockInfo = block_info(Label, [Instr0 | Block], [], no,
+                ordinary(Needs)),
+            build_block_map(Instrs1, FrameSize, LabelSeq0, !BlockMap,
+                ProcLabel, !C),
+            svmap__det_insert(Label, BlockInfo, !BlockMap),
 			LabelSeq = [Label | LabelSeq0]
 		)
 	;
@@ -509,7 +499,7 @@
 	% non-interfering instructions that were interspersed with Setup
 	% but can be moved after Setup, and Remain is all remaining
 	% instructions.
-
+    %
 :- pred frameopt__detstack_setup(list(instruction)::in, int::out, string::out,
 	list(instruction)::out, list(instruction)::out, list(instruction)::out)
 	is semidet.
@@ -569,7 +559,7 @@
 	% to be interleaved with instructions that do not access the stack;
 	% any such instructions are returned as Extra. Remain is all the
 	% instructions after the teardown.
-
+    %
 :- pred frameopt__detstack_teardown(list(instruction)::in, int::in,
 	list(instruction)::out, list(instruction)::out,
 	list(instruction)::out, list(instruction)::out,
@@ -593,8 +583,8 @@
 		Goto = GotoPrime,
 		Remain = RemainPrime
 	;
-		frameopt__detstack_teardown(Instrs0, FrameSize,
-			Extra1, Succip, Decrsp, Livevals, Goto, Remain),
+        frameopt__detstack_teardown(Instrs0, FrameSize, Extra1, Succip,
+            Decrsp, Livevals, Goto, Remain),
 		Extra = [Instr0 | Extra1]
 	).
 
@@ -619,29 +609,27 @@
 			!.Succip = [],
 			!.Decrsp = [],
 			!:Succip = [Instr1],
-			frameopt__detstack_teardown_2(Instrs2, FrameSize,
-				!Extra, !Succip, !Decrsp, !Livevals,
-				Goto, Remain)
+            frameopt__detstack_teardown_2(Instrs2, FrameSize, !Extra, !Succip,
+                !Decrsp, !Livevals, Goto, Remain)
 		;
 			opt_util__lval_refers_stackvars(Lval, no),
 			opt_util__rval_refers_stackvars(Rval, no),
 			list__append(!.Extra, [Instr1], !:Extra),
-			frameopt__detstack_teardown_2(Instrs2, FrameSize,
-				!Extra, !Succip, !Decrsp, !Livevals,
-				Goto, Remain)
+            frameopt__detstack_teardown_2(Instrs2, FrameSize, !Extra, !Succip,
+                !Decrsp, !Livevals, Goto, Remain)
 		)
 	;
 		Uinstr1 = decr_sp(FrameSize),
 		!.Decrsp = [],
 		!:Decrsp = [Instr1],
-		frameopt__detstack_teardown_2(Instrs2, FrameSize,
-			!Extra, !Succip, !Decrsp, !Livevals, Goto, Remain)
+        frameopt__detstack_teardown_2(Instrs2, FrameSize, !Extra, !Succip,
+            !Decrsp, !Livevals, Goto, Remain)
 	;
 		Uinstr1 = livevals(_),
 		!.Livevals = [],
 		!:Livevals = [Instr1],
-		frameopt__detstack_teardown_2(Instrs2, FrameSize,
-			!Extra, !Succip, !Decrsp, !Livevals, Goto, Remain)
+        frameopt__detstack_teardown_2(Instrs2, FrameSize, !Extra, !Succip,
+            !Decrsp, !Livevals, Goto, Remain)
 	;
 		Uinstr1 = goto(_),
 		!.Decrsp = [_],
@@ -652,14 +640,16 @@
 %-----------------------------------------------------------------------------%
 
 	% Does an ordinary block with the given content need a stack frame?
-
+    %
 :- pred block_needs_frame(list(instruction)::in, bool::out) is det.
 
 block_needs_frame(Instrs, NeedsFrame) :-
 	opt_util__block_refers_stackvars(Instrs, ReferStackVars),
-	( ReferStackVars = yes ->
+    (
+        ReferStackVars = yes,
 		NeedsFrame = yes
 	;
+        ReferStackVars = no,
 		(
 			list__member(Instr, Instrs),
 			Instr = Uinstr - _,
@@ -670,9 +660,8 @@
 			;
 				Uinstr = c_code(_, _)
 			;
-				Uinstr = pragma_c(_, _, MayCallMercury,
-					_, MaybeLayout, MaybeOnlyLayout, _,
-					NeedStack, _),
+                Uinstr = pragma_c(_, _, MayCallMercury, _, MaybeLayout,
+                    MaybeOnlyLayout, _, NeedStack, _),
 				(
 					MayCallMercury = may_call_mercury
 				;
@@ -696,8 +685,8 @@
 	% For each block in the given sequence, whose block_info structures
 	% in the given block map have been partially filled in, fill in the
 	% remaining two fields. These two fields give the labels the block
-	% can branch to on the side (this includes return addresses for
-	% calls), and the label if any to which it falls through.
+    % can branch to on the side (this includes return addresses for calls),
+    % and the label if any to which it falls through.
 	%
 	% Also decide whether the optimization we want to apply is keeping
 	% the stack frame for recursive tail calls once it has been set up
@@ -708,7 +697,7 @@
 	% the label starting the procedure and the label that should replace
 	% it in tailcalls that avoid the stack teardown, which is the label
 	% immediately after the initial stack setup block.
-
+    %
 :- pred analyze_block_map(list(label)::in, block_map::in, block_map::out,
 	maybe(pair(label))::out) is det.
 
@@ -718,11 +707,12 @@
 		map__search(!.BlockMap, FirstLabel, FirstBlockInfo),
 		FirstBlockInfo = block_info(FirstLabel, _, _, _, setup)
 	->
-		analyze_block_map_2(LabelSeq, FirstLabel,
-			!BlockMap, no, KeepFrame),
-		( KeepFrame = yes ->
+        analyze_block_map_2(LabelSeq, FirstLabel, !BlockMap, no, KeepFrame),
+        (
+            KeepFrame = yes,
 			KeepFrameData = yes(FirstLabel - SecondLabel)
 		;
+            KeepFrame = no,
 			KeepFrameData = no
 		)
 	;
@@ -775,7 +765,7 @@
 	% This predicate tests whether the second label (from the tailcall)
 	% is a proper reference to the first label (from the initial label
 	% instruction).
-
+    %
 :- pred matching_label_ref(label::in, label::in) is semidet.
 
 matching_label_ref(entry(FirstLabelType, ProcLabel),
@@ -825,7 +815,7 @@
 	% The two label arguments are the label starting the procedure
 	% (a form of which appears in existing tailcalls) and the label that
 	% should replace it in tailcalls that avoid the stack teardown.
-
+    %
 :- pred keep_frame(list(label)::in, label::in, label::in, bool::in,
 	block_map::in, block_map::out) is det.
 
@@ -850,9 +840,11 @@
 		string__append(Comment, " (keeping frame)", NewComment),
 		NewGoto = goto(label(SecondLabel)) - NewComment,
 		list__append(Livevals, [NewGoto], LivevalsGoto),
-		( CanClobberSuccip = yes ->
+        (
+            CanClobberSuccip = yes,
 			list__append(Succip, LivevalsGoto, BackInstrs)
 		;
+            CanClobberSuccip = no,
 			BackInstrs = LivevalsGoto
 		),
 		Instrs = [OrigLabelInstr | BackInstrs],
@@ -862,18 +854,19 @@
 	;
 		true
 	),
-	keep_frame(Labels, FirstLabel, SecondLabel, CanClobberSuccip,
-		!BlockMap).
+    keep_frame(Labels, FirstLabel, SecondLabel, CanClobberSuccip, !BlockMap).
 
 :- pred pick_last(list(T)::in, list(T)::out, T::out) is det.
 
 pick_last([], _, _) :-
 	error("empty list in pick_last").
 pick_last([First | Rest], NonLast, Last) :-
-	( Rest = [] ->
+    (
+        Rest = [],
 		NonLast = [],
 		Last = First
 	;
+        Rest = [_ | _],
 		pick_last(Rest, NonLast0, Last),
 		NonLast = [First | NonLast0]
 	).
@@ -887,7 +880,7 @@
 	% is a null operation if the second block needs a stack frame,
 	% we lie a bit and say that the transformation is not applicable
 	% in such cases.
-
+    %
 :- pred can_delay_frame(list(label)::in, block_map::in, bool::in) is semidet.
 
 can_delay_frame([], _, _).
@@ -907,19 +900,19 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-	% The data structures used in the delaying optimizations:
+    % The data structures used in the delaying optimizations.
 
 	% map__search(RevMap, Label, SideLabels) should be true
 	% if the block started by Label can be reached via jump
 	% (i.e. not fallthrough) from the labels in SideLabels.
-
+    %
 :- type rev_map	==	map(label, list(label)).
 
 	% map__search(ParMap, Label, ParallelLabel) should be true if
 	% Label starts a teardown block and ParallelLabel starts its parallel
 	% (i.e. a copy without the stack teardown code and therefore an
 	% ordinary block).
-
+    %
 :- type par_map	==	map(label, label).
 
 	% set__member(Label, FallIntoParallel) should be true if
@@ -972,7 +965,7 @@
 	% -	The third phase creates non-teardown parallels to the teardown
 	%	blocks that need them, and puts them in their correct place,
 	%	either just before or just after the original block.
-
+    %
 :- pred delay_frame(list(label)::in, list(label)::out, int::in, string::in,
 	proc_label::in, counter::in, counter::out,
 	block_map::in, block_map::out) is det.
@@ -982,11 +975,9 @@
 		queue__init, Queue1),
 	propagate_framed_labels(Queue1, !.BlockMap, RevMap,
 		set__init, FramedLabels),
-	process_frame_delay(LabelSeq0, FramedLabels, FrameSize, Msg, ProcLabel,
-		!C, LabelSeq1, !BlockMap, map__init, ParMap,
-		set__init, FallIntoParallel),
-	create_parallels(LabelSeq1, LabelSeq, ParMap, FallIntoParallel,
-		!BlockMap).
+    process_frame_delay(LabelSeq0, FramedLabels, FrameSize, Msg, ProcLabel, !C,
+        LabelSeq1, !BlockMap, map__init, ParMap, set__init, FallIntoParallel),
+    create_parallels(LabelSeq1, LabelSeq, ParMap, FallIntoParallel, !BlockMap).
 
 %-----------------------------------------------------------------------------%
 
@@ -994,50 +985,47 @@
 	% The first is a map showing the predecessors of each block,
 	% i.e. the set of blocks that can jump to each other block.
 	% The second is a queue of ordinary blocks that need a stack frame.
-
+    %
 :- pred delay_frame_init(list(label)::in, block_map::in,
 	rev_map::in, rev_map::out, queue(label)::in, queue(label)::out) is det.
 
-delay_frame_init([], _, RevMap, RevMap, Queue, Queue).
-delay_frame_init([Label | Labels], BlockMap, RevMap0, RevMap, Queue0, Queue) :-
+delay_frame_init([], _, !RevMap, !Queue).
+delay_frame_init([Label | Labels], BlockMap, !RevMap, !Queue) :-
 	map__lookup(BlockMap, Label, BlockInfo),
 	BlockInfo = block_info(_, _, SideLabels, _, BlockType),
 	(
-		BlockType = setup,
-		Queue1 = Queue0
+        BlockType = setup
 	;
 		BlockType = ordinary(NeedsFrame),
 		(
-			NeedsFrame = no,
-			Queue1 = Queue0
+            NeedsFrame = no
 		;
 			NeedsFrame = yes,
-			queue__put(Queue0, Label, Queue1)
+            svqueue__put(Label, !Queue)
 		)
 	;
-		BlockType = teardown(_, _, _),
-		Queue1 = Queue0
+        BlockType = teardown(_, _, _)
 	),
-	rev_map_side_labels(SideLabels, Label, RevMap0, RevMap1),
-	delay_frame_init(Labels, BlockMap, RevMap1, RevMap, Queue1, Queue).
+    rev_map_side_labels(SideLabels, Label, !RevMap),
+    delay_frame_init(Labels, BlockMap, !RevMap, !Queue).
 
 :- pred rev_map_side_labels(list(label)::in, label::in,
 	rev_map::in, rev_map::out) is det.
 
-rev_map_side_labels([], _Label, RevMap, RevMap).
-rev_map_side_labels([Label | Labels], SourceLabel, RevMap0, RevMap) :-
-	( map__search(RevMap0, Label, OtherSources0) ->
+rev_map_side_labels([], _Label, !RevMap).
+rev_map_side_labels([Label | Labels], SourceLabel, !RevMap) :-
+    ( map__search(!.RevMap, Label, OtherSources0) ->
 		OtherSources = [SourceLabel | OtherSources0],
-		map__det_update(RevMap0, Label, OtherSources, RevMap1)
+        svmap__det_update(Label, OtherSources, !RevMap)
 	;
 		OtherSources = [SourceLabel],
-		map__det_insert(RevMap0, Label, OtherSources, RevMap1)
+        svmap__det_insert(Label, OtherSources, !RevMap)
 	),
-	rev_map_side_labels(Labels, SourceLabel, RevMap1, RevMap).
+    rev_map_side_labels(Labels, SourceLabel, !RevMap).
 
 %-----------------------------------------------------------------------------%
 
-	% Given FramedLabels0, a set of labels representing ordinary blocks
+    % Given !.FramedLabels, a set of labels representing ordinary blocks
 	% that must have a stack frame, propagate the requirement for a stack
 	% frame to labels representing other ordinary blocks that
 	%
@@ -1047,23 +1035,22 @@
 	% - can perform a jump to a block in FramedLabels0.
 	%
 	% The requirement is not propagated to blocks that can fall through
-	% to a block in FramedLabels0, since on such paths stack frame setup
+    % to a block in !.FramedLabels, since on such paths stack frame setup
 	% code can be inserted between the two blocks.
-
+    %
 :- pred propagate_framed_labels(queue(label)::in, block_map::in, rev_map::in,
 	set(label)::in, set(label)::out) is det.
 
-propagate_framed_labels(Queue0, BlockMap, RevMap,
-		FramedLabels0, FramedLabels) :-
-	( queue__get(Queue0, Label, Queue1) ->
+propagate_framed_labels(!.Queue, BlockMap, RevMap, !FramedLabels) :-
+    ( svqueue__get(Label, !Queue) ->
 		(
 			map__lookup(BlockMap, Label, BlockInfo),
-			BlockInfo = block_info(_, _, SideLabels,
-				MaybeFallThrough, BlockType),
+            BlockInfo = block_info(_, _, SideLabels, MaybeFallThrough,
+                BlockType),
 			BlockType = ordinary(_),
-			\+ set__member(Label, FramedLabels0)
+            \+ set__member(Label, !.FramedLabels)
 		->
-			set__insert(FramedLabels0, Label, FramedLabels1),
+            svset__insert(Label, !FramedLabels),
 			(
 				MaybeFallThrough = no,
 				ReachableLabels = SideLabels
@@ -1071,20 +1058,18 @@
 				MaybeFallThrough = yes(FallThrough),
 				ReachableLabels = [FallThrough | SideLabels]
 			),
-			queue__put_list(Queue1, ReachableLabels, Queue2),
+            svqueue__put_list(ReachableLabels, !Queue),
 			( map__search(RevMap, Label, Sources) ->
-				queue__put_list(Queue2, Sources, Queue3)
+                svqueue__put_list(Sources, !Queue)
 			;
-				Queue3 = Queue2
+                true
 			),
-			propagate_framed_labels(Queue3, BlockMap, RevMap,
-				FramedLabels1, FramedLabels)
+            propagate_framed_labels(!.Queue, BlockMap, RevMap, !FramedLabels)
 		;
-			propagate_framed_labels(Queue1, BlockMap, RevMap,
-				FramedLabels0, FramedLabels)
+            propagate_framed_labels(!.Queue, BlockMap, RevMap, !FramedLabels)
 		)
 	;
-		FramedLabels = FramedLabels0
+        true
 	).
 
 %-----------------------------------------------------------------------------%
@@ -1092,17 +1077,16 @@
 	% The predicates process_frame_delay and transform_ordinary_block
 	% implement the second phase of delay_frame. For documentation,
 	% see the comment at the top of delay_frame.
-
+    %
 :- pred process_frame_delay(list(label)::in, set(label)::in, int::in,
 	string::in, proc_label::in, counter::in, counter::out,
 	list(label)::out, block_map::in, block_map::out,
 	par_map::in, par_map::out, set(label)::in, set(label)::out) is det.
 
-process_frame_delay([], _, _, _, _, !C, [],
-		!BlockMap, !ParMap, !FallIntoParallel).
+process_frame_delay([], _, _, _, _, !C, [], !BlockMap, !ParMap,
+        !FallIntoParallel).
 process_frame_delay([Label0 | Labels0], FramedLabels, FrameSize, Msg,
-		ProcLabel, !C, Labels, !BlockMap, !ParMap,
-		!FallIntoParallel) :-
+        ProcLabel, !C, Labels, !BlockMap, !ParMap, !FallIntoParallel) :-
 	map__lookup(!.BlockMap, Label0, BlockInfo0),
 	BlockInfo0 = block_info(Label0Copy, Instrs0, SideLabels0,
 		MaybeFallThrough0, Type),
@@ -1119,9 +1103,10 @@
 			MaybeFallThrough0 = no,
 			error("no fallthrough for setup block")
 		),
-		( SideLabels0 = [] ->
-			true
+        (
+            SideLabels0 = []
 		;
+            SideLabels0 = [_ | _],
 			error("nonempty side labels for setup block")
 		),
 		(
@@ -1139,11 +1124,9 @@
 		;
 			BlockInfo = block_info(Label0, [LabelInstr],
 				SideLabels0, MaybeFallThrough0, ordinary(no)),
-			map__det_update(!.BlockMap, Label0, BlockInfo,
-				!:BlockMap),
-			process_frame_delay(Labels0, FramedLabels, FrameSize,
-				Msg, ProcLabel, !C, Labels1,
-				!BlockMap, !ParMap, !FallIntoParallel),
+            svmap__det_update(Label0, BlockInfo, !BlockMap),
+            process_frame_delay(Labels0, FramedLabels, FrameSize, Msg,
+                ProcLabel, !C, Labels1, !BlockMap, !ParMap, !FallIntoParallel),
 			Labels = [Label0 | Labels1]
 		)
 	;
@@ -1154,9 +1137,8 @@
 			% in FramedLabels, or will be a teardown block.
 			% We already have a stack frame, and all our
 			% successors expect one, so we need not do anything.
-			process_frame_delay(Labels0, FramedLabels, FrameSize,
-				Msg, ProcLabel, !C, Labels1,
-				!BlockMap, !ParMap, !FallIntoParallel),
+            process_frame_delay(Labels0, FramedLabels, FrameSize, Msg,
+                ProcLabel, !C, Labels1, !BlockMap, !ParMap, !FallIntoParallel),
 			Labels = [Label0 | Labels1]
 		;
 			% Every block reachable from this block, whether via
@@ -1167,15 +1149,14 @@
 			% the teardown blocks are a different matter; we must
 			% make sure that we reach their non-teardown parallels
 			% instead.
-			transform_ordinary_block(Label0, Labels0, BlockInfo0,
-				FramedLabels, FrameSize, Msg, ProcLabel, !C,
-				Labels, !BlockMap, !ParMap, !FallIntoParallel)
+            transform_ordinary_block(Label0, Labels0, BlockInfo0, FramedLabels,
+                FrameSize, Msg, ProcLabel, !C, Labels, !BlockMap, !ParMap,
+                !FallIntoParallel)
 		)
 	;
 		Type = teardown(_, _, _),
-		process_frame_delay(Labels0, FramedLabels, FrameSize,
-			Msg, ProcLabel, !C, Labels1,
-			!BlockMap, !ParMap, !FallIntoParallel),
+        process_frame_delay(Labels0, FramedLabels, FrameSize, Msg, ProcLabel,
+            !C, Labels1, !BlockMap, !ParMap, !FallIntoParallel),
 		Labels = [Label0 | Labels1]
 	).
 
@@ -1186,16 +1167,13 @@
 	set(label)::in, set(label)::out) is det.
 
 transform_ordinary_block(Label0, Labels0, BlockInfo0, FramedLabels, FrameSize,
-		Msg, ProcLabel, !C, Labels,
-		!BlockMap, !ParMap, !FallIntoParallel) :-
-	BlockInfo0 = block_info(_, Instrs0, SideLabels0,
-		MaybeFallThrough0, Type),
-	mark_parallels_for_teardown(SideLabels0, SideLabels,
-		AssocLabelMap, !.BlockMap, ProcLabel, !C, !ParMap),
+        Msg, ProcLabel, !C, Labels, !BlockMap, !ParMap, !FallIntoParallel) :-
+    BlockInfo0 = block_info(_, Instrs0, SideLabels0, MaybeFallThrough0, Type),
+    mark_parallels_for_teardown(SideLabels0, SideLabels, AssocLabelMap,
+        !.BlockMap, ProcLabel, !C, !ParMap),
 	pick_last(Instrs0, PrevInstrs, LastInstr0),
 	map__from_assoc_list(AssocLabelMap, LabelMap),
-	opt_util__replace_labels_instruction(LastInstr0, LabelMap, no,
-		LastInstr),
+    opt_util__replace_labels_instruction(LastInstr0, LabelMap, no, LastInstr),
 	list__append(PrevInstrs, [LastInstr], Instrs),
 	(
 		MaybeFallThrough0 = yes(FallThrough),
@@ -1216,18 +1194,13 @@
 				MaybeFallThrough = yes(NewLabel),
 				MaybeNewLabel = yes(NewLabel),
 				SetupCode = [
-					label(NewLabel)
-						- "late setup label",
-					incr_sp(FrameSize, Msg)
-						- "late setup",
-					assign(stackvar(FrameSize),
-						lval(succip))
-						- "late save"
+                    label(NewLabel) - "late setup label",
+                    incr_sp(FrameSize, Msg) - "late setup",
+                    assign(stackvar(FrameSize), lval(succip)) - "late save"
 				],
-				SetupBlock = block_info(NewLabel, SetupCode,
-					[], MaybeFallThrough0, setup),
-				map__det_insert(!.BlockMap, NewLabel,
-					SetupBlock, !:BlockMap)
+                SetupBlock = block_info(NewLabel, SetupCode, [],
+                    MaybeFallThrough0, setup),
+                svmap__det_insert(NewLabel, SetupBlock, !BlockMap)
 			;
 				MaybeFallThrough = yes(FallThrough),
 				MaybeNewLabel = no
@@ -1235,8 +1208,7 @@
 		;
 			FallThroughType = teardown(_, _, _),
 			MaybeFallThrough = yes(FallThrough),
-			set__insert(!.FallIntoParallel, FallThrough,
-				!:FallIntoParallel),
+            svset__insert(FallThrough, !FallIntoParallel),
 			MaybeNewLabel = no,
 			mark_parallel(FallThrough, _, ProcLabel, !C, !ParMap)
 		)
@@ -1245,14 +1217,15 @@
 		MaybeFallThrough = no,
 		MaybeNewLabel = no
 	),
-	BlockInfo = block_info(Label0, Instrs, SideLabels, MaybeFallThrough,
-		Type),
+    BlockInfo = block_info(Label0, Instrs, SideLabels, MaybeFallThrough, Type),
 	map__set(!.BlockMap, Label0, BlockInfo, !:BlockMap),
-	process_frame_delay(Labels0, FramedLabels, FrameSize, Msg, ProcLabel,
-		!C, Labels1, !BlockMap, !ParMap, !FallIntoParallel),
-	( MaybeNewLabel = yes(NewLabel2) ->
+    process_frame_delay(Labels0, FramedLabels, FrameSize, Msg, ProcLabel, !C,
+        Labels1, !BlockMap, !ParMap, !FallIntoParallel),
+    (
+        MaybeNewLabel = yes(NewLabel2),
 		Labels = [Label0, NewLabel2 | Labels1]
 	;
+        MaybeNewLabel = no,
 		Labels = [Label0 | Labels1]
 	).
 
@@ -1265,7 +1238,7 @@
 	% already. We return both the updated list of labels and the
 	% substitution (represented as an association list) that will have
 	% to applied to the jumping instruction.
-
+    %
 :- pred mark_parallels_for_teardown(list(label)::in, list(label)::out,
 	assoc_list(label)::out, block_map::in,
 	proc_label::in, counter::in, counter::out,
@@ -1273,8 +1246,7 @@
 
 mark_parallels_for_teardown([], [], [], _, _, !C, !ParMap).
 mark_parallels_for_teardown([Label0 | Labels0], [Label | Labels],
-		[Label0 - Label | LabelMap], BlockMap,
-		ProcLabel, !C, !ParMap) :-
+        [Label0 - Label | LabelMap], BlockMap, ProcLabel, !C, !ParMap) :-
 	map__lookup(BlockMap, Label0, BlockInfo),
 	BlockInfo = block_info(_, _, _, _, Type),
 	(
@@ -1287,12 +1259,12 @@
 		Type = teardown(_, _, _),
 		mark_parallel(Label0, Label, ProcLabel, !C, !ParMap)
 	),
-	mark_parallels_for_teardown(Labels0, Labels, LabelMap,
-		BlockMap, ProcLabel, !C, !ParMap).
+    mark_parallels_for_teardown(Labels0, Labels, LabelMap, BlockMap, ProcLabel,
+        !C, !ParMap).
 
 	% Given the label of a teardown block, allocate a label for its
 	% non-teardown parallel if it doesn't already have one.
-
+    %
 :- pred mark_parallel(label::in, label::out, proc_label::in,
 	counter::in, counter::out, par_map::in, par_map::out) is det.
 
@@ -1303,45 +1275,43 @@
 		counter__allocate(N, !C),
 		NewParallel = internal(N, ProcLabel),
 		Label = NewParallel,
-		map__det_insert(!.ParMap, Label0, NewParallel, !:ParMap)
+        svmap__det_insert(Label0, NewParallel, !ParMap)
 	).
 
 %-----------------------------------------------------------------------------%
 
 	% The third phase of the delay_frame optimization, creating
 	% the non-teardown parallel blocks.
-
+    %
 :- pred create_parallels(list(label)::in, list(label)::out,
 	par_map::in, set(label)::in, block_map::in, block_map::out) is det.
 
 create_parallels([], [], _, _, !BlockMap).
 create_parallels([Label0 | Labels0], Labels, ParMap, FallIntoParallel,
 		!BlockMap) :-
-	create_parallels(Labels0, Labels1, ParMap, FallIntoParallel,
-		!BlockMap),
+    create_parallels(Labels0, Labels1, ParMap, FallIntoParallel, !BlockMap),
 	( map__search(ParMap, Label0, ParallelLabel) ->
 		map__lookup(!.BlockMap, Label0, BlockInfo0),
-		BlockInfo0 = block_info(Label0Copy, _,
-			SideLabels, MaybeFallThrough, Type),
+        BlockInfo0 = block_info(Label0Copy, _, SideLabels, MaybeFallThrough,
+            Type),
 		( Label0 = Label0Copy ->
 			true
 		;
 			error("label in block_info is not copy")
 		),
-		( MaybeFallThrough = no ->
-			true
+        (
+            MaybeFallThrough = no
 		;
+            MaybeFallThrough = yes(_),
 			error("block with parallel has fall through")
 		),
 		( Type = teardown(_, Livevals, Goto) ->
-			LabelInstr = label(ParallelLabel)
-				- "non-teardown parallel",
+            LabelInstr = label(ParallelLabel) - "non-teardown parallel",
 			list__append(Livevals, [Goto], Replacement0),
 			Replacement = [LabelInstr | Replacement0],
-			NewBlockInfo = block_info(ParallelLabel, Replacement,
-				SideLabels, no, ordinary(no)),
-			map__det_insert(!.BlockMap, ParallelLabel,
-				NewBlockInfo, !:BlockMap),
+            NewBlockInfo = block_info(ParallelLabel, Replacement, SideLabels,
+                no, ordinary(no)),
+            svmap__det_insert(ParallelLabel, NewBlockInfo, !BlockMap),
 			( set__member(Label0, FallIntoParallel) ->
 				Labels = [ParallelLabel, Label0 | Labels1]
 			;
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