diff: make LCO work again

David Matthew Overton dmo at cs.mu.OZ.AU
Wed Aug 5 18:12:54 AEST 1998


Andrew,

I've already committed the following changes to the alias branch, but
I've posted them here in case you want to look at them.

David
-- 
David Overton
MEngSc Student                       Email: dmo at cs.mu.oz.au     
Department of Computer Science       Web: http://www.cs.mu.oz.au/~dmo
The University of Melbourne          Phone: +61 3 9344 9159

Estimated hours taken: 10
 
Fix some bugs that were stopping the alias branch bootstrapping with
`--optimize-constructor-last-call' turned on.  Most of these bugs were
either caused by or uncovered by Andrew Bromage's recent changes to
instmaps.
  
compiler/inst.m:
	In `inst_expand_fully' add an instmap argument and use
	`instmap__inst_key_table_lookup' instead of
	`inst_key_table_lookup' to ensure that all inst_key
	substitutions are applied to the inst as it is expanded.

compiler/instmap.m:
	Pass the current instmap when calling `inst_expand_fully'.

compiler/lco.m:
	Disallow lco if it would result in a construction with more
	than one reference to the same free(alias) variable.  This is
	just a temporary restriction until free(alias_many) is
	implemented.

compiler/liveness.m:
	Include ref_in args in the liveness set output by
	`initial_liveness'.  This undoes a change made by Andrew
	Bromage.

compiler/mode_util.m:
	In `mode_to_arg_mode', make free(alias) -> free(alias) modes
	have arg_mode top_unused instead of ref_out.  XXX This may
	evetually require a separate ref_unused arg_mode, but I can't
	see any reason for it at the moment.

	In `make_var_alias', fix a bug where free variables in
	constructions were made free(alias) before the construction
	instead of after it.  (This bug did not previously show up
	because it was cancelled out by the bug in `mode_to_arg_mode'.)

compiler/unify_gen.m:
	When looking for free arguments in constructions in order to
	create references, look for ref_out modes rather than ref_in
	modes.

Index: inst.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/inst.m,v
retrieving revision 1.2.4.9
diff -u -r1.2.4.9 inst.m
--- 1.2.4.9	1998/07/31 08:07:14
+++ inst.m	1998/08/05 02:52:34
@@ -12,7 +12,7 @@
 :- module (inst).
 :- interface.
 
-:- import_module prog_data, hlds_data, hlds_pred.
+:- import_module prog_data, hlds_data, hlds_pred, instmap.
 :- import_module list, std_util, term, map, io, set.
 
 %-----------------------------------------------------------------------------%
@@ -159,8 +159,8 @@
 :- pred inst_keys_in_inst(inst, list(inst_key), list(inst_key)).
 :- mode inst_keys_in_inst(in, in, out) is det.
 
-:- pred inst_expand_fully(inst_key_table, inst, inst).
-:- mode inst_expand_fully(in, in, out) is det.
+:- pred inst_expand_fully(inst_key_table, instmap, inst, inst).
+:- mode inst_expand_fully(in, in, in, out) is det.
 
 :- pred inst_apply_sub(inst_key_sub, inst, inst).
 :- mode inst_apply_sub(in, in, out) is det.
@@ -462,31 +462,34 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-inst_expand_fully(_IKT, any(Uniq), any(Uniq)).
-inst_expand_fully(IKT, alias(Key), Inst) :-
-	inst_key_table_lookup(IKT, Key, Inst0),
-	inst_expand_fully(IKT, Inst0, Inst).
-inst_expand_fully(_IKT, free(A), free(A)).
-inst_expand_fully(_IKT, free(A, Type), free(A, Type)).
-inst_expand_fully(IKT, bound(Uniq, BoundInsts0), bound(Uniq, BoundInsts)) :-
-	bound_insts_expand_fully(IKT, BoundInsts0, BoundInsts).
-inst_expand_fully(_IKT, ground(Uniq, PredInstInfo), ground(Uniq, PredInstInfo)).
-inst_expand_fully(_IKT, not_reached, not_reached).
-inst_expand_fully(_IKT, inst_var(Var), inst_var(Var)).
-inst_expand_fully(_IKT, defined_inst(InstName), defined_inst(InstName)).
-inst_expand_fully(IKT, abstract_inst(SymName, Insts0),
+inst_expand_fully(_IKT, _InstMap, any(Uniq), any(Uniq)).
+inst_expand_fully(IKT, InstMap, alias(Key), Inst) :-
+	instmap__inst_key_table_lookup(InstMap, IKT, Key, Inst0),
+	inst_expand_fully(IKT, InstMap, Inst0, Inst).
+inst_expand_fully(_IKT, _InstMap, free(A), free(A)).
+inst_expand_fully(_IKT, _InstMap, free(A, Type), free(A, Type)).
+inst_expand_fully(IKT, InstMap, bound(Uniq, BoundInsts0),
+		bound(Uniq, BoundInsts)) :-
+	bound_insts_expand_fully(IKT, InstMap, BoundInsts0, BoundInsts).
+inst_expand_fully(_IKT, _InstMap, ground(Uniq, PredInstInfo),
+		ground(Uniq, PredInstInfo)).
+inst_expand_fully(_IKT, _InstMap, not_reached, not_reached).
+inst_expand_fully(_IKT, _InstMap, inst_var(Var), inst_var(Var)).
+inst_expand_fully(_IKT, _InstMap, defined_inst(InstName),
+		defined_inst(InstName)).
+inst_expand_fully(IKT, InstMap, abstract_inst(SymName, Insts0),
 			abstract_inst(SymName, Insts)) :-
-	list__map(inst_expand_fully(IKT), Insts0, Insts).
+	list__map(inst_expand_fully(IKT, InstMap), Insts0, Insts).
 
-:- pred bound_insts_expand_fully(inst_key_table, list(bound_inst),
+:- pred bound_insts_expand_fully(inst_key_table, instmap, list(bound_inst),
 		list(bound_inst)).
-:- mode bound_insts_expand_fully(in, in, out) is det.
+:- mode bound_insts_expand_fully(in, in, in, out) is det.
 
-bound_insts_expand_fully(_IKT, [], []).
-bound_insts_expand_fully(IKT, [functor(ConsId, Insts0) | BIs0],
+bound_insts_expand_fully(_IKT, _InstMap, [], []).
+bound_insts_expand_fully(IKT, InstMap, [functor(ConsId, Insts0) | BIs0],
 		[functor(ConsId, Insts) | BIs]) :-
-	list__map(inst_expand_fully(IKT), Insts0, Insts),
-	bound_insts_expand_fully(IKT, BIs0, BIs).
+	list__map(inst_expand_fully(IKT, InstMap), Insts0, Insts),
+	bound_insts_expand_fully(IKT, InstMap, BIs0, BIs).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
Index: instmap.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/instmap.m,v
retrieving revision 1.15.2.15
diff -u -r1.15.2.15 instmap.m
--- 1.15.2.15	1998/07/27 05:30:08
+++ instmap.m	1998/08/05 02:44:32
@@ -704,7 +704,7 @@
 		InstList0, Inst0, InstTable1, ModuleInfo1, Error0),
 	instmap__lookup_var(InstMap, Var, VarInst0),
 	inst_table_get_inst_key_table(InstTable1, IKT1),
-	inst_expand_fully(IKT1, VarInst0, VarInst),
+	inst_expand_fully(IKT1, InstMap, VarInst0, VarInst),
 	InstList = [VarInst | InstList0],
 	(
 		% YYY Not sure about the returned InstMap here.
Index: lco.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/lco.m,v
retrieving revision 1.7.2.6
diff -u -r1.7.2.6 lco.m
--- 1.7.2.6	1998/07/31 06:29:01
+++ lco.m	1998/08/05 07:53:22
@@ -248,7 +248,8 @@
 
 		% XXX - Also, we currently only allow one reference per
 		% variable, so make sure there is no more than one reference
-		% to each output variable in the call.
+		% to each output variable in the call.  This restriction can
+		% be lifted once free(alias_many) is implemented.
 		pred_info_procedures(PredInfo, ProcTable),
 		map__lookup(ProcTable, ProcId, CalledProcInfo),
 		check_only_one_ref_per_var(Unifies1, Vars, Module0,
@@ -393,6 +394,13 @@
 		mode_to_arg_mode(CalledInstMap, CalledInstTable, Module,
 				Mode, Type, top_out)
 	->
+		% Ensure that no single construction uses the var more the once.
+		\+ (
+			list__member(_ - ConsVars0, UnifVars),
+			list__delete_first(ConsVars0, Var, ConsVars1),
+			list__member(Var, ConsVars1)
+		),
+
 		% Ensure that there is at most one construction
 		% that has this variable on its RHS.
 		\+ (
@@ -411,7 +419,8 @@
 			list__member(Var, Vars),
 			list__member(Var - HMode, CallingHeadVarModes),
 			mode_to_arg_mode(CallingInstMap, CallingInstTable,
-				Module, HMode, Type, ArgMode), ( ArgMode = top_out 
+				Module, HMode, Type, ArgMode), 
+			( ArgMode = top_out 
 			; ArgMode = ref_in
 			)
 		)
Index: liveness.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/liveness.m,v
retrieving revision 1.81.2.12
diff -u -r1.81.2.12 liveness.m
--- 1.81.2.12	1998/07/27 05:30:21
+++ liveness.m	1998/08/03 06:02:33
@@ -1052,7 +1052,7 @@
 		ModuleInfo, Liveness0, Liveness, Refs0, Refs) :-
 	mode_to_arg_mode(InstMap, InstTable, ModuleInfo, M, T, ArgMode),
 	(
-		ArgMode = top_in
+		arg_mode_is_input(ArgMode)
 	->
 		set__insert(Liveness0, V, Liveness1)
 	;
Index: mode_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/mode_util.m,v
retrieving revision 1.99.2.21
diff -u -r1.99.2.21 mode_util.m
--- 1.99.2.21	1998/07/29 04:20:18
+++ mode_util.m	1998/08/05 07:07:18
@@ -385,7 +385,16 @@
 			inst_is_free_alias(InstB, InstMapB, InstTable,
 					ModuleInfo)
 		->
-			ArgMode = ref_out
+			( inst_is_free_alias(InstA, InstMapA, InstTable,
+					ModuleInfo)
+			->
+				ArgMode = top_unused
+				% XXX this may eventually require a new arg_mode
+				% `ref_unused', but I can't see a reason for
+				% it at the moment.
+			;
+				ArgMode = ref_out
+			)
 		;
 			ArgMode = top_unused
 		)
@@ -2030,18 +2039,13 @@
 		inst_key_table, inst_key_table).
 :- mode make_var_alias(in, in, in, out, in, out) is det.
 
-make_var_alias(Var, Live, InstMap0, InstMap, IKT0, IKT) :-
+make_var_alias(Var, _Live, InstMap0, InstMap, IKT0, IKT) :-
 	instmap__lookup_var(InstMap0, Var, Inst),
 	( Inst = alias(_) ->
 		InstMap0 = InstMap,
 		IKT0 = IKT
 	;
-		( Inst = free(_), Live = live ->
-			NewInst = free(alias)
-		;
-			NewInst = Inst
-		),
-		inst_key_table_add(IKT0, NewInst, InstKey, IKT),
+		inst_key_table_add(IKT0, Inst, InstKey, IKT),
 		instmap__set(InstMap0, Var, alias(InstKey), InstMap)
 	).
 
Index: unify_gen.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/unify_gen.m,v
retrieving revision 1.83.2.9
diff -u -r1.83.2.9 unify_gen.m
--- 1.83.2.9	1998/07/31 08:07:16
+++ unify_gen.m	1998/08/03 03:17:57
@@ -654,7 +654,7 @@
 	{ Mode = ((_LI - RI) -> (_LF - RF)) },
 	( 
 		{ insts_to_arg_mode(InstTable, ModuleInfo, RI, InstMap0,
-			RF, InstMap, Type, ref_in) }
+			RF, InstMap, Type, ref_out) }
 	->
 		code_info__acquire_reg_for_var(Var, Reg),
 		code_info__set_var_reference_location(Var, Reg),



More information about the developers mailing list