for review: bug-avoidance in value numbering

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Mar 13 20:43:56 AEDT 1998


value_number.m:
	Do not attempt to optimize code sequences that manipulate tickets.
	That code is buggy, and it is not worth fixing in this incarnation
	of the value numbering optimization.

Zoltan.

Index: value_number.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/value_number.m,v
retrieving revision 1.90
diff -u -u -r1.90 value_number.m
--- 1.90	1998/01/13 10:14:00
+++ value_number.m	1998/03/12 03:49:21
@@ -382,12 +382,30 @@
 
 value_number__optimize_fragment_2(Instrs0, LiveMap, Params, ParEntries,
 		LabelNo0, Tuple, Instrs) -->
-	( { Instrs0 = [Uinstr0Prime - _ | _] } ->
-		{ Uinstr0 = Uinstr0Prime },
-		vn_debug__fragment_msg(Uinstr0)
+	( { Instrs0 = [Uinstr0 - _ | _] } ->
+		( { value_number__can_handle_all_instrs(Instrs0, yes) } ->
+			vn_debug__fragment_msg(Uinstr0),
+			value_number__optimize_fragment_3(Uinstr0, Instrs0,
+				LiveMap, Params, ParEntries, LabelNo0,
+				Tuple, Instrs)
+		;
+			{ vn_block__build_block_info(Instrs0, LiveMap, Params,
+				ParEntries, LabelNo0, _VnTables0, _Liveset0,
+				_SeenIncr0, Tuple) },
+			{ Instrs = Instrs0 }
+		)
 	;
 		{ error("empty instruction sequence in value_number__optimize_fragment") }
-	),
+	).
+
+:- pred value_number__optimize_fragment_3(instr, list(instruction), livemap,
+	vn_params, list(parentry), int, vn_ctrl_tuple, list(instruction),
+	io__state, io__state).
+:- mode value_number__optimize_fragment_3(in, in, in, in, in, in, out, out,
+	di, uo) is det.
+
+value_number__optimize_fragment_3(Uinstr0, Instrs0, LiveMap, Params,
+		ParEntries, LabelNo0, Tuple, Instrs) -->
 	{ vn_block__build_block_info(Instrs0, LiveMap, Params, ParEntries,
 		LabelNo0, VnTables0, Liveset0, SeenIncr0, Tuple0) },
 	{ Tuple0 = tuple(Ctrl, Ctrlmap, Flushmap, LabelNo, _Parmap) },
@@ -1176,3 +1194,80 @@
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
+
+:- pred value_number__can_handle_all_instrs(list(instruction), bool).
+:- mode value_number__can_handle_all_instrs(in, out) is det.
+
+value_number__can_handle_all_instrs([], yes).
+value_number__can_handle_all_instrs([Instr | Instrs], CanHandle) :-
+	Instr = Uinstr - _,
+	(
+		Uinstr = comment(_),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = livevals(_),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = block(_, _, _),
+		CanHandle = no
+	;
+		Uinstr = assign(_, _),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = call(_, _, _, _),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = mkframe(_, _, _, _),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = modframe(_),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = label(_),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = goto(_),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = computed_goto(_, _),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = c_code(_),
+		CanHandle = no
+	;
+		Uinstr = if_val(_, _),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = incr_hp(_, _, _, _),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = mark_hp(_),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = restore_hp(_),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = store_ticket(_),
+		CanHandle = no
+	;
+		Uinstr = reset_ticket(_, _),
+		CanHandle = no
+	;
+		Uinstr = discard_ticket,
+		CanHandle = no
+	;
+		Uinstr = mark_ticket_stack(_),
+		CanHandle = no
+	;
+		Uinstr = discard_tickets_to(_),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = incr_sp(_, _),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = decr_sp(_),
+		value_number__can_handle_all_instrs(Instrs, CanHandle)
+	;
+		Uinstr = pragma_c(_, _, _, _),
+		CanHandle = no
+	).



More information about the developers mailing list