for review: turn off stack optimizations for .agc

Tyson Dowd trd at cs.mu.OZ.AU
Mon Jun 15 17:58:55 AEST 1998


Hi,

Here's a change for code generation when doing accurate GC.
(It's more conservative than it needs to be).

===================================================================


Estimated hours taken: 2

Turn off frame optimizations for accurate GC.
We need the stack frames present so we can replace the succip on the
stack to schedule accurate GC.

compiler/handle_options.m:
	Make accurate GC imply --no-optimize-frames.

compiler/optimize.m:
compiler/peephole.m:
compiler/value_number.m:
	If doing accurate GC, don't peephole optimize incr_sp...decr_sp
	code.



Index: compiler/handle_options.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/handle_options.m,v
retrieving revision 1.54
diff -u -r1.54 handle_options.m
--- handle_options.m	1998/06/09 02:12:47	1.54
+++ handle_options.m	1998/06/13 09:22:00
@@ -325,10 +325,12 @@
 	% `trace' stack layouts need `procid' stack layouts
 	option_implies(trace_stack_layout, procid_stack_layout, bool(yes)),
 
-	% --gc accurate requires `agc' stack layouts and typeinfo liveness.
+	% --gc accurate requires `agc' stack layouts, typeinfo liveness,
+	% and needs frameopt to be switched off.
 	( { GC_Method = accurate } ->
 		globals__io_set_option(agc_stack_layout, bool(yes)),
-		globals__io_set_option(typeinfo_liveness, bool(yes)) 
+		globals__io_set_option(typeinfo_liveness, bool(yes)),
+		globals__io_set_option(optimize_frames, bool(no)) 
 	;
 		[]
 	),
Index: compiler/optimize.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/optimize.m,v
retrieving revision 1.14
diff -u -r1.14 optimize.m
--- optimize.m	1998/03/03 17:35:31	1.14
+++ optimize.m	1998/06/13 09:20:40
@@ -137,6 +137,12 @@
 		{ Mod1 = no }
 	),
 	globals__io_lookup_bool_option(optimize_peep, Peephole),
+	globals__io_get_gc_method(GC_Method),
+	{ GC_Method = accurate ->
+		InvalidPatterns = [incr_sp]
+	;
+		InvalidPatterns = []
+	},
 	( { Peephole = yes } ->
 		( { VeryVerbose = yes } ->
 			io__write_string("% Optimizing locally for "),
@@ -145,7 +151,7 @@
 		;
 			[]
 		),
-		{ peephole__optimize(Instrs2, Instrs3, Mod2) },
+		{ peephole__optimize(InvalidPatterns, Instrs2, Instrs3, Mod2) },
 		( { Mod2 = yes } ->
 			opt_debug__msg(DebugOpt, "after peepholing"),
 			opt_debug__dump_instrs(DebugOpt, Instrs3)
Index: compiler/peephole.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/peephole.m,v
retrieving revision 1.72
diff -u -r1.72 peephole.m
--- peephole.m	1998/01/13 10:13:10	1.72
+++ peephole.m	1998/06/13 09:16:35
@@ -17,8 +17,17 @@
 :- import_module bool, list.
 :- import_module llds.
 
-:- pred peephole__optimize(list(instruction), list(instruction), bool).
-:- mode peephole__optimize(in, out, out) is det.
+	% Patterns that can be switched off.
+
+:- type pattern --->		incr_sp.
+
+
+	% Peephole optimize a list of instructions.  The given list of
+	% patterns are not optimized.
+
+:- pred peephole__optimize(list(pattern), list(instruction),
+		list(instruction), bool).
+:- mode peephole__optimize(in, in, out, out) is det.
 
 :- implementation.
 
@@ -31,10 +40,12 @@
 	% when we find a sequence we can't optimize, we back up and try
 	% to optimize the sequence starting with the previous instruction.
 
-peephole__optimize([], [], no).
-peephole__optimize([Instr0 - Comment | Instrs0], Instrs, Mod) :-
-	peephole__optimize(Instrs0, Instrs1, Mod0),
-	peephole__opt_instr(Instr0, Comment, Instrs1, Instrs, Mod1),
+peephole__optimize(_, [], [], no).
+peephole__optimize(InvalidPatterns, [Instr0 - Comment | Instrs0],
+		Instrs, Mod) :-
+	peephole__optimize(InvalidPatterns, Instrs0, Instrs1, Mod0),
+	peephole__opt_instr(Instr0, Comment, InvalidPatterns, Instrs1,
+		Instrs, Mod1),
 	( Mod0 = no, Mod1 = no ->
 		Mod = no
 	;
@@ -44,18 +55,19 @@
 	% Try to optimize the beginning of the given instruction sequence.
 	% If successful, try it again.
 
-:- pred peephole__opt_instr(instr, string,
+:- pred peephole__opt_instr(instr, string, list(pattern),
 	list(instruction), list(instruction), bool).
-:- mode peephole__opt_instr(in, in, in, out, out) is det.
+:- mode peephole__opt_instr(in, in, in, in, out, out) is det.
 
-peephole__opt_instr(Instr0, Comment0, Instrs0, Instrs, Mod) :-
+peephole__opt_instr(Instr0, Comment0, InvalidPatterns, Instrs0, Instrs, Mod) :-
 	(
 		opt_util__skip_comments(Instrs0, Instrs1),
-		peephole__match(Instr0, Comment0, Instrs1, Instrs2)
+		peephole__match(Instr0, Comment0, InvalidPatterns, Instrs1,
+			Instrs2)
 	->
 		( Instrs2 = [Instr2 - Comment2 | Instrs3] ->
-			peephole__opt_instr(Instr2, Comment2, Instrs3, Instrs,
-				_)
+			peephole__opt_instr(Instr2, Comment2, InvalidPatterns,
+				Instrs3, Instrs, _)
 		;
 			Instrs = Instrs2
 		),
@@ -67,15 +79,17 @@
 
 %-----------------------------------------------------------------------------%
 
+		
 	% Look for code patterns that can be optimized, and optimize them.
 
-:- pred peephole__match(instr, string, list(instruction), list(instruction)).
-:- mode peephole__match(in, in, in, out) is semidet.
+:- pred peephole__match(instr, string, list(pattern),
+		list(instruction), list(instruction)).
+:- mode peephole__match(in, in, in, in, out) is semidet.
 
 	% A `computed_goto' with all branches pointing to the same 
 	% label can be replaced with an unconditional goto. 
 
-peephole__match(computed_goto(_, Labels), Comment, Instrs0, Instrs) :-
+peephole__match(computed_goto(_, Labels), Comment, _, Instrs0, Instrs) :-
 	list__all_same(Labels),
 	Labels = [Target|_],
 	Instrs = [goto(label(Target)) - Comment | Instrs0].
@@ -89,7 +103,7 @@
 	% A conditional branch to a label followed by that label
 	% can be eliminated.
 
-peephole__match(if_val(Rval, CodeAddr), Comment, Instrs0, Instrs) :-
+peephole__match(if_val(Rval, CodeAddr), Comment, _, Instrs0, Instrs) :-
 	(
 		opt_util__is_const_condition(Rval, Taken)
 	->
@@ -140,7 +154,7 @@
 	% These two patterns are mutually exclusive because if_val is not
 	% straigh-line code.
 
-peephole__match(mkframe(Name, Slots, Pragma, Redoip1), Comment,
+peephole__match(mkframe(Name, Slots, Pragma, Redoip1), Comment, _,
 		Instrs0, Instrs) :-
 	(
 		opt_util__next_modframe(Instrs0, [], Redoip2, Skipped, Rest),
@@ -197,7 +211,7 @@
 	%	store_ticket(Lval)	=>	store_ticket(Lval)
 	%	reset_ticket(Lval, _R)
 
-peephole__match(store_ticket(Lval), Comment, Instrs0, Instrs) :-
+peephole__match(store_ticket(Lval), Comment, _, Instrs0, Instrs) :-
 	opt_util__skip_comments(Instrs0, Instrs1),
 	Instrs1 = [reset_ticket(lval(Lval), _Reason) - _Comment2 | Instrs2],
 	Instrs = [store_ticket(Lval) - Comment | Instrs2].
@@ -216,7 +230,7 @@
 	% are not touched by the straight-line instructions, then we can
 	% discard the nondet stack frame early.
 
-peephole__match(modframe(Redoip), Comment, Instrs0, Instrs) :-
+peephole__match(modframe(Redoip), Comment, _, Instrs0, Instrs) :-
 	(
 		opt_util__next_modframe(Instrs0, [], Redoip2, Skipped, Rest),
 		opt_util__touches_nondet_ctrl(Skipped, no)
@@ -249,7 +263,8 @@
 	%	succip = detstackvar(N)
 	%	decr_sp N
 
-peephole__match(incr_sp(N, _), _, Instrs0, Instrs) :-
+peephole__match(incr_sp(N, _), _, InvalidPatterns, Instrs0, Instrs) :-
+	\+ list__member(incr_sp, InvalidPatterns),
 	(
 		opt_util__no_stackvars_til_decr_sp(Instrs0, N, Between, Remain)
 	->
Index: compiler/value_number.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/value_number.m,v
retrieving revision 1.92
diff -u -r1.92 value_number.m
--- value_number.m	1998/06/09 02:15:03	1.92
+++ value_number.m	1998/06/13 09:18:19
@@ -408,7 +408,13 @@
 		{ value_number__push_livevals_back(Instrs3, Instrs4) },
 		{ value_number__convert_back_modframe(Instrs4, Instrs5) },
 		{ vn_filter__block(Instrs5, Instrs6) },
-		{ peephole__optimize(Instrs6, Instrs7, _) },
+		globals__io_get_gc_method(GC_Method),
+		{ GC_Method = accurate ->
+			InvalidPatterns = [incr_sp]
+		;
+			InvalidPatterns = []
+		},
+		{ peephole__optimize(InvalidPatterns, Instrs6, Instrs7, _) },
 
 		vn_debug__cost_header_msg("original code sequence"),
 		vn_cost__block_cost(Instrs0, Params, yes, OrigCost),


-- 
       Tyson Dowd           # There isn't any reason why Linux can't be
                            # implemented as an enterprise computing solution.
     trd at cs.mu.oz.au        # Find out what you've been missing while you've
http://www.cs.mu.oz.au/~trd # been rebooting Windows NT. -- InfoWorld, 1998.



More information about the developers mailing list