diff: bug in liveness (affects .agc grade).

Tyson Richard DOWD trd at cs.mu.oz.au
Fri May 9 17:12:28 AEST 1997


Hi,

	Tom, can you please review this.

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

Estimated hours taken: 15

Fix a bug in code generation for accurate GC grades, and rename a
predicate.

compiler/call_gen.m:
compiler/hlds_pred.m:
compiler/live_vars.m:
	Change `proc_info_get_used_typeinfos_setwise' to
	`proc_info_get_typeinfo_vars_setwise'.

compiler/liveness.m:
	When computing initial liveness, don't include the head variables 
	if they are unused in the predicate - this can lead to typeinfo
	variables being kept live for no reason, which causes problems 
	when generating code.


Index: call_gen.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/call_gen.m,v
retrieving revision 1.107
diff -u -r1.107 call_gen.m
--- call_gen.m	1997/01/21 22:09:14	1.107
+++ call_gen.m	1997/05/06 06:41:34
@@ -226,7 +226,7 @@
 		{ GC_Method = accurate }
 	->
 		code_info__get_proc_info(ProcInfo),
-		{ proc_info_get_used_typeinfos_setwise(ProcInfo, Vars1, 
+		{ proc_info_get_typeinfo_vars_setwise(ProcInfo, Vars1, 
 			TypeInfoVars) },
 		{ set__union(Vars1, TypeInfoVars, Vars) }
 	;
Index: hlds_pred.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_pred.m,v
retrieving revision 1.30
diff -u -r1.30 hlds_pred.m
--- hlds_pred.m	1997/04/23 01:02:35	1.30
+++ hlds_pred.m	1997/05/09 06:42:33
@@ -687,16 +687,19 @@
 :- pred proc_info_declared_argmodes(proc_info, list(mode)).
 :- mode proc_info_declared_argmodes(in, out) is det.
 
+
+
 	% For a set of variables V, find all the type variables in the types 
 	% of the variables in V, and return set of typeinfo variables for 
 	% those type variables. (find all typeinfos for variables in V).
+	% (If any type variable is unbound, it will not be returned).
 	%
 	% This set of typeinfos is often needed in liveness computation
 	% for accurate garbage collection - live variables need to have 
 	% their typeinfos stay live too.
 
-:- pred proc_info_get_used_typeinfos_setwise(proc_info, set(var), set(var)).
-:- mode proc_info_get_used_typeinfos_setwise(in, in, out) is det.
+:- pred proc_info_get_typeinfo_vars_setwise(proc_info, set(var), set(var)).
+:- mode proc_info_get_typeinfo_vars_setwise(in, in, out) is det.
 
 :- pred proc_info_ensure_unique_names(proc_info, proc_info).
 :- mode proc_info_ensure_unique_names(in, out) is det.
@@ -973,17 +976,17 @@
 	ProcInfo = procedure(A, B, C, D, E, F, G, H, I,
 			J, K, L, M, TVarMap, O).
 
-proc_info_get_used_typeinfos_setwise(ProcInfo, Vars, TypeInfoVars) :-
+proc_info_get_typeinfo_vars_setwise(ProcInfo, Vars, TypeInfoVars) :-
 	set__to_sorted_list(Vars, VarList),
-	proc_info_get_used_typeinfos_2(ProcInfo, VarList, TypeInfoVarList),
+	proc_info_get_typeinfo_vars_2(ProcInfo, VarList, TypeInfoVarList),
 	set__list_to_set(TypeInfoVarList, TypeInfoVars).
 
 	% auxiliary predicate - traverses variables and builds a list of
 	% variables that store typeinfos for these variables. 
-:- pred proc_info_get_used_typeinfos_2(proc_info, list(var), list(var)).
-:- mode proc_info_get_used_typeinfos_2(in, in, out) is det.
-proc_info_get_used_typeinfos_2(_, [], []).
-proc_info_get_used_typeinfos_2(ProcInfo, [Var | Vars1], TypeInfoVars) :-
+:- pred proc_info_get_typeinfo_vars_2(proc_info, list(var), list(var)).
+:- mode proc_info_get_typeinfo_vars_2(in, in, out) is det.
+proc_info_get_typeinfo_vars_2(_, [], []).
+proc_info_get_typeinfo_vars_2(ProcInfo, [Var | Vars1], TypeInfoVars) :-
 	proc_info_vartypes(ProcInfo, VarTypeMap),
 	( 
 		map__search(VarTypeMap, Var, Type)
@@ -993,20 +996,20 @@
 			% Optimize common case
 			TypeVars = []
 		->
-			proc_info_get_used_typeinfos_2(ProcInfo, Vars1, 
+			proc_info_get_typeinfo_vars_2(ProcInfo, Vars1, 
 				TypeInfoVars)
 		;
-			% It's possible there are some complications with
+			% XXX It's possible there are some complications with
 			% higher order pred types here -- if so, maybe
 			% treat them specially.
 			proc_info_typeinfo_varmap(ProcInfo, TVarMap),
 			map__apply_to_list(TypeVars, TVarMap, TypeInfoVars0),
-			proc_info_get_used_typeinfos_2(ProcInfo, Vars1,
+			proc_info_get_typeinfo_vars_2(ProcInfo, Vars1,
 				TypeInfoVars1),
 			list__append(TypeInfoVars0, TypeInfoVars1, TypeInfoVars)
 		)
 	;
-		error("proc_info_get_used_typeinfos_2: var not found in typemap")
+		error("proc_info_get_typeinfo_vars_2: var not found in typemap")
 	).
 
 proc_info_ensure_unique_names(ProcInfo0, ProcInfo) :-
Index: live_vars.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/live_vars.m,v
retrieving revision 1.63
diff -u -r1.63 live_vars.m
--- live_vars.m	1997/05/05 11:17:11	1.63
+++ live_vars.m	1997/05/08 06:49:19
@@ -467,9 +467,9 @@
 	(
 		GC_Method = accurate
 	->
-		proc_info_get_used_typeinfos_setwise(ProcInfo, LiveVars1,
+		proc_info_get_typeinfo_vars_setwise(ProcInfo, LiveVars1,
 			TypeInfoVarsLive),
-		proc_info_get_used_typeinfos_setwise(ProcInfo, OutVars,
+		proc_info_get_typeinfo_vars_setwise(ProcInfo, OutVars,
 			TypeInfoVarsOut),
 		set__union(LiveVars1, TypeInfoVarsOut, LiveVars2),
 		set__union(LiveVars2, TypeInfoVarsLive, LiveVars)
Index: liveness.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/liveness.m,v
retrieving revision 1.71
diff -u -r1.71 liveness.m
--- liveness.m	1997/05/05 11:17:13	1.71
+++ liveness.m	1997/05/09 06:07:33
@@ -318,7 +318,7 @@
 			GCmethod = accurate
 		->
 			live_info_get_proc_info(LiveInfo, ProcInfo),
-			proc_info_get_used_typeinfos_setwise(ProcInfo,
+			proc_info_get_typeinfo_vars_setwise(ProcInfo,
 				NonLocals0, TypeInfoVars),
 			set__union(NonLocals0, TypeInfoVars, NonLocals)
 		;
@@ -790,9 +790,30 @@
 		initial_liveness_2(Vars, Modes, Types, ModuleInfo,
 			Liveness0, Liveness1)
 	->
-		Liveness = Liveness1
+		Liveness2 = Liveness1
 	;
 		error("initial_liveness: list length mismatch")
+	),
+		% If a variable is unused in the goal, it shouldn't be
+		% in the initial liveness. (If we allowed it to start
+		% live, it wouldn't ever become dead, because it would
+		% have to be used to be killed).
+		% So we intersect the headvars with the non-locals.
+	proc_info_goal(ProcInfo, _Goal - GoalInfo),
+	goal_info_get_nonlocals(GoalInfo, NonLocals),
+	set__intersect(Liveness2, NonLocals, Liveness3),
+		% If doing accurate garbage collection, the corresponding
+		% typeinfos need to be added to these.
+	module_info_globals(ModuleInfo, Globals),
+	globals__get_gc_method(Globals, GCmethod),
+	(
+		GCmethod = accurate
+	->
+		proc_info_get_typeinfo_vars_setwise(ProcInfo, Liveness3,
+			TypeInfoVars),
+		set__union(Liveness3, TypeInfoVars, Liveness)
+	;
+		Liveness = Liveness3
 	).
 
 :- pred initial_liveness_2(list(var), list(mode), list(type), module_info,
@@ -837,7 +858,7 @@
 	(
 		GCmethod = accurate
 	->
-		proc_info_get_used_typeinfos_setwise(ProcInfo, Deadness2,
+		proc_info_get_typeinfo_vars_setwise(ProcInfo, Deadness2,
 			TypeInfoVars),
 		set__union(Deadness2, TypeInfoVars, Deadness)
 	;
-- 
       Tyson Dowd           #
                            #             Sign on refrigerator:
     trd at cs.mu.oz.au        #           Refrigerate after opening. 
http://www.cs.mu.oz.au/~trd #                  - C. J. Owen.



More information about the developers mailing list