[m-rev.] for review: --no-optimize-fulljumps

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon Jan 12 15:47:37 AEDT 2004


For review by Fergus.

Zoltan.

compiler/jumpopt.m:
	Fix an old though minor error: replace code sequences of the form

		if (<cond>)
			r1 = TRUE;
		else
			r1 = FALSE

	with
		r1 = <cond>;

	even with -no-optimize-fulljumps, which is implied by --opt-space,
	since the C compiler can generate smaller code for it than for the
	original code.

Index: jumpopt.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/jumpopt.m,v
retrieving revision 1.68
diff -u -b -r1.68 jumpopt.m
--- jumpopt.m	11 Nov 2003 03:35:07 -0000	1.68
+++ jumpopt.m	10 Jan 2004 14:06:09 -0000
@@ -76,23 +76,21 @@
 %		test r1, and to execute the the success or failure epilog
 %		depending on the result) to the epilog.
 %
-% If we are not doing full jump optimization, Blockmap will be empty.
-% Even with full jump optimization, Blockmap will not contain the initial
-% block of the procedure unless Recjump is set. The intention is that
-% Recjump will not be set until optimizations such as frameopt and value
-% numbering, which can do a better job of optimizing this block, have
+% Blockmap will not contain the initial block of the procedure unless
+% Recjump is set. The intention is that Recjump will not be set until
+% frameopt, which can do a better job of optimizing this block, have
 % been applied.
 
 jumpopt_main(Instrs0, LayoutLabels, MayAlterRtti, ProcLabel, C0, C,
-		Blockopt, Recjump, PessimizeTailCalls, CheckedNondetTailCall,
-		Instrs, Mod) :-
+		Fulljumpopt, Recjump, PessimizeTailCalls,
+		CheckedNondetTailCall, Instrs, Mod) :-
 	map__init(Instrmap0),
 	map__init(Lvalmap0),
 	map__init(Procmap0),
 	map__init(Sdprocmap0),
 	map__init(Succmap0),
 	map__init(Blockmap0),
-	jumpopt__build_maps(Instrs0, Blockopt, Recjump, Instrmap0, Instrmap,
+	jumpopt__build_maps(Instrs0, Recjump, Instrmap0, Instrmap,
 		Blockmap0, Blockmap, Lvalmap0, Lvalmap,
 		Procmap0, Procmap1, Sdprocmap0, Sdprocmap1,
 		Succmap0, Succmap1),
@@ -116,8 +114,9 @@
 		CheckedNondetTailCallInfo0 = yes(ProcLabel - C0),
 		jumpopt__instr_list(Instrs0, comment(""), Instrmap, Blockmap,
 			Lvalmap, Procmap, Sdprocmap, Forkmap, Succmap,
-			LayoutLabels, MayAlterRtti, CheckedNondetTailCallInfo0,
-			CheckedNondetTailCallInfo, Instrs1),
+			LayoutLabels, Fulljumpopt, MayAlterRtti,
+			CheckedNondetTailCallInfo0, CheckedNondetTailCallInfo,
+			Instrs1),
 		( CheckedNondetTailCallInfo = yes(_ - Cprime) ->
 			C = Cprime
 		;
@@ -128,8 +127,8 @@
 		CheckedNondetTailCallInfo0 = no,
 		jumpopt__instr_list(Instrs0, comment(""), Instrmap, Blockmap,
 			Lvalmap, Procmap, Sdprocmap, Forkmap, Succmap,
-			LayoutLabels, MayAlterRtti, CheckedNondetTailCallInfo0,
-			_, Instrs1),
+			LayoutLabels, Fulljumpopt, MayAlterRtti,
+			CheckedNondetTailCallInfo0, _, Instrs1),
 		C = C0
 	),
 	opt_util__filter_out_bad_livevals(Instrs1, Instrs),
@@ -141,14 +140,14 @@
 
 %-----------------------------------------------------------------------------%
 
-:- pred jumpopt__build_maps(list(instruction)::in, bool::in, bool::in,
+:- pred jumpopt__build_maps(list(instruction)::in, bool::in,
 	instrmap::in, instrmap::out, tailmap::in, tailmap::out,
 	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,
+jumpopt__build_maps([], _, !Instrmap, !Blockmap, !Lvalmap, !Procmap,
 		!Sdprocmap, !Succmap).
-jumpopt__build_maps([Instr0 | Instrs0], Blockopt, Recjump, !Instrmap,
+jumpopt__build_maps([Instr0 | Instrs0], Recjump, !Instrmap,
 		!Blockmap, !Lvalmap, !Procmap, !Sdprocmap, !Succmap) :-
 	Instr0 = Uinstr0 - _,
 	( Uinstr0 = label(Label) ->
@@ -183,7 +182,11 @@
 		),
 		% put the start of the procedure into Blockmap
 		% only after frameopt and value_number have had a shot at it
-		( Blockopt = yes, ( Label = local(_, _) ; Recjump = yes ) ->
+		(
+			( Label = local(_, _)
+			; Recjump = yes
+			)
+		->
 			opt_util__find_no_fallthrough(Instrs1, Block),
 			map__det_insert(!.Blockmap, Label, Block, !:Blockmap)
 		;
@@ -192,7 +195,7 @@
 	;
 		true
 	),
-	jumpopt__build_maps(Instrs0, Blockopt, Recjump, !Instrmap,
+	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
@@ -239,16 +242,17 @@
 
 :- 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, may_alter_rtti::in,
+	tailmap::in, set(label)::in, bool::in, may_alter_rtti::in,
 	maybe(pair(proc_label, counter))::in,
 	maybe(pair(proc_label, counter))::out, list(instruction)::out) is det.
 
 jumpopt__instr_list([], _PrevInstr, _Instrmap, _Blockmap, _Lvalmap,
 		_Procmap, _Sdprocmap, _Forkmap, _Succmap, _LayoutLabels,
-		_, !CheckedNondetTailCallInfo, []).
+		_Fulljumpopt, _MayAlterRtti, !CheckedNondetTailCallInfo, []).
 jumpopt__instr_list([Instr0 | Instrs0], PrevInstr, Instrmap, Blockmap,
 		Lvalmap, Procmap, Sdprocmap, Forkmap, Succmap, LayoutLabels,
-		MayAlterRtti, !CheckedNondetTailCallInfo, Instrs) :-
+		Fulljumpopt, MayAlterRtti, !CheckedNondetTailCallInfo,
+		Instrs) :-
 	Instr0 = Uinstr0 - Comment0,
 	(
 		Uinstr0 = call(Proc, label(RetLabel), LiveInfos, Context,
@@ -408,14 +412,14 @@
 			% always want to replace jumps to them, whereas
 			% other blocks may be long, so we want to replace
 			% jumps to them only if the fulljumps option
-			% was given (if it wasn't, Blockmap will be empty).
-			% Second, non-epilog blocks may contain branches to
-			% other labels in this procedure, and we want to
-			% make sure that these are short-circuited.
+			% was given. Second, non-epilog blocks may contain
+			% branches to other labels in this procedure, and
+			% we want to make sure that these are short-circuited.
 			% This short-circuiting is necessary because
 			% another optimization below eliminates labels,
 			% which is correct only if jumps to those labels
 			% are short-circuited everywhere.
+			Fulljumpopt = yes,
 			map__search(Instrmap, TargetLabel, TargetInstr),
 			jumpopt__final_dest(Instrmap, TargetLabel, DestLabel,
 				TargetInstr, _DestInstr),
@@ -432,8 +436,8 @@
 			jumpopt__instr_list(AdjustedBlock, comment(""),
 				Instrmap, CrippledBlockmap, Lvalmap, Procmap,
 				Sdprocmap, Forkmap, Succmap, LayoutLabels,
-				MayAlterRtti, !CheckedNondetTailCallInfo,
-				NewInstrs),
+				Fulljumpopt, MayAlterRtti,
+				!CheckedNondetTailCallInfo, NewInstrs),
 			RemainInstrs = Instrs0
 		;
 			% Short-circuit the goto.
@@ -626,7 +630,8 @@
 	),
 	jumpopt__instr_list(RemainInstrs, NewPrevInstr, Instrmap, Blockmap,
 		Lvalmap, Procmap, Sdprocmap, Forkmap, Succmap, LayoutLabels,
-		MayAlterRtti, !CheckedNondetTailCallInfo, Instrs9),
+		Fulljumpopt, MayAlterRtti, !CheckedNondetTailCallInfo,
+		Instrs9),
 	list__append(NewInstrs, Instrs9, Instrs).
 
 :- func redirect_comment(string) = string.
--------------------------------------------------------------------------
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