[m-dev.] for review: turn off stack optimizations for .agc

Tyson Dowd trd at cs.mu.OZ.AU
Tue Jun 16 15:57:16 AEST 1998


On 15-Jun-1998, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> 
> It's fine, except for the fact that the code fragment
> 
> > +	globals__io_get_gc_method(GC_Method),
> > +	{ GC_Method = accurate ->
> > +		InvalidPatterns = [incr_sp]
> > +	;
> > +		InvalidPatterns = []
> > +	},
> 
> is present twice. The pattern list ought to be computed once, either
> in peephole.m or in handle_options.m.

I've fixed this by putting it in peephole, and making GC_Method one
of the arguments to peephole__optimize.

Here's the new diff (for completeness).  I'll commit this soon.

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/16 05:10:36
@@ -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/16 05:28:24
@@ -145,7 +145,8 @@
 		;
 			[]
 		),
-		{ peephole__optimize(Instrs2, Instrs3, Mod2) },
+		globals__io_get_gc_method(GC_Method),
+		{ peephole__optimize(GC_Method, 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/16 05:42:14
@@ -15,26 +15,43 @@
 :- interface.
 
 :- import_module bool, list.
-:- import_module llds.
+:- import_module llds, globals.
 
-:- pred peephole__optimize(list(instruction), list(instruction), bool).
-:- mode peephole__optimize(in, out, out) is det.
+	% Peephole optimize a list of instructions.  The given list of
+	% patterns are not optimized.
+
+:- pred peephole__optimize(gc_method, list(instruction), list(instruction),
+		bool).
+:- mode peephole__optimize(in, in, out, out) is det.
 
 :- implementation.
 
 :- import_module map, string, std_util.
 :- import_module code_util, opt_util, opt_debug.
 
+	% Patterns that can be switched off.
+
+:- type pattern --->		incr_sp.
+
 	% We zip down to the end of the instruction list, and start attempting
 	% to optimize instruction sequences. As long as we can continue
 	% optimizing the instruction sequence, we keep doing so;
 	% 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(GC_Method, Instrs0, Instrs, Mod) :-
+	peephole__invalid_opts(GC_Method, InvalidPatterns),
+	peephole__optimize_2(InvalidPatterns, Instrs0, Instrs, Mod).
+
+:- pred peephole__optimize_2(list(pattern), list(instruction),
+		list(instruction), bool).
+:- mode peephole__optimize_2(in, in, out, out) is det.
+peephole__optimize_2(_, [], [], no).
+peephole__optimize_2(InvalidPatterns, [Instr0 - Comment | Instrs0],
+		Instrs, Mod) :-
+	peephole__optimize_2(InvalidPatterns, Instrs0, Instrs1, Mod0),
+	peephole__opt_instr(Instr0, Comment, InvalidPatterns, Instrs1,
+		Instrs, Mod1),
 	( Mod0 = no, Mod1 = no ->
 		Mod = no
 	;
@@ -44,18 +61,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 +85,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 +109,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 +160,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 +217,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 +236,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,13 +269,30 @@
 	%	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)
 	->
 		list__append(Between, Remain, Instrs)
 	;
 		fail
+	).
+
+%-----------------------------------------------------------------------------%
+
+	% Given a GC method, return the list of invalid peephole
+	% optimizations.
+:- pred peephole__invalid_opts(gc_method, list(pattern)). 
+:- mode peephole__invalid_opts(in, out) is det.
+
+peephole__invalid_opts(GC_Method, InvalidPatterns) :-
+	( 
+		GC_Method = accurate
+	->
+		InvalidPatterns = [incr_sp]
+	;
+		InvalidPatterns = []
 	).
 
 %-----------------------------------------------------------------------------%
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/16 05:44:42
@@ -408,7 +408,8 @@
 		{ 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),
+		{ peephole__optimize(GC_Method, 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