diff: correct insts in continuation_info

Tyson Richard DOWD trd at hydra.cs.mu.oz.au
Thu Jun 5 12:17:29 AEST 1997


Hi,

Can someone review this one?

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

Estimated hours taken: 1.5

Fix the insts of live variables in continuation_info. They were calculated
using the insts before the call instead of after the call.

compiler/call_gen.m:
compiler/code_info.m:
	Apply the instmap_delta of the current goal to the instmap when
	looking up the insts of live variables.
	Make the hlds_goal_info of the current goal available when
	generating calls.

compiler/code_gen.m:
	Make the hlds_goal_info of the current goal available when
	generating calls.

Index: compiler/call_gen.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/call_gen.m,v
retrieving revision 1.110
diff -u -r1.110 call_gen.m
--- call_gen.m	1997/05/27 03:06:16	1.110
+++ call_gen.m	1997/06/05 01:58:15
@@ -21,33 +21,33 @@
 :- import_module hlds_pred, llds, code_info.
 
 :- pred call_gen__generate_higher_order_call(code_model, var, list(var),
-				list(type), list(mode), determinism,
-				code_tree, code_info, code_info).
-:- mode call_gen__generate_higher_order_call(in, in, in, in, in, in, out,
+			list(type), list(mode), determinism, hlds_goal_info,
+			code_tree, code_info, code_info).
+:- mode call_gen__generate_higher_order_call(in, in, in, in, in, in, in, out,
 				in, out) is det.
 
-:- pred call_gen__generate_det_call(pred_id, proc_id, list(var),
-					code_tree, code_info, code_info).
-:- mode call_gen__generate_det_call(in, in, in, out, in, out) is det.
+:- pred call_gen__generate_det_call(pred_id, proc_id, list(var), 
+			hlds_goal_info, code_tree, code_info, code_info).
+:- mode call_gen__generate_det_call(in, in, in, in, out, in, out) is det.
 
 :- pred call_gen__generate_semidet_call(pred_id, proc_id, list(var),
-					code_tree, code_info, code_info).
-:- mode call_gen__generate_semidet_call(in, in, in, out, in, out) is det.
+			hlds_goal_info, code_tree, code_info, code_info).
+:- mode call_gen__generate_semidet_call(in, in, in, in, out, in, out) is det.
 
 :- pred call_gen__generate_nondet_call(pred_id, proc_id, list(var),
-					code_tree, code_info, code_info).
-:- mode call_gen__generate_nondet_call(in, in, in, out, in, out) is det.
+			hlds_goal_info, code_tree, code_info, code_info).
+:- mode call_gen__generate_nondet_call(in, in, in, in, out, in, out) is det.
 
 :- pred call_gen__generate_det_builtin(pred_id, proc_id, list(var),
-					code_tree, code_info, code_info).
+			code_tree, code_info, code_info).
 :- mode call_gen__generate_det_builtin(in, in, in, out, in, out) is det.
 
 :- pred call_gen__generate_semidet_builtin(pred_id, proc_id, list(var),
-					code_tree, code_info, code_info).
+			code_tree, code_info, code_info).
 :- mode call_gen__generate_semidet_builtin(in, in, in, out, in, out) is det.
 
 :- pred call_gen__generate_nondet_builtin(pred_id, proc_id, list(var),
-					code_tree, code_info, code_info).
+			code_tree, code_info, code_info).
 :- mode call_gen__generate_nondet_builtin(in, in, in, out, in, out) is
 					erroneous.
 
@@ -80,6 +80,7 @@
 
 :- import_module hlds_module, hlds_data, prog_data, code_util, globals.
 :- import_module arg_info, type_util, mode_util, unify_proc, instmap.
+:- import_module hlds_goal.
 :- import_module bool, int, list, assoc_list, tree, set, map.
 :- import_module std_util, require.
 
@@ -91,7 +92,7 @@
 	% for the procedure call. We then branch to the procedure
 	% and rebuild the register information to reflect the state
 	% when the callee returns.
-call_gen__generate_det_call(PredId, ModeId, Arguments, Code) -->
+call_gen__generate_det_call(PredId, ModeId, Arguments, GoalInfo, Code) -->
 	code_info__get_pred_proc_arginfo(PredId, ModeId, ArgInfo),
 	{ assoc_list__from_corresponding_lists(Arguments, ArgInfo, Args) },
 	{ call_gen__select_out_args(Args, OutArgs) },
@@ -102,7 +103,7 @@
 	{ call_gen__input_args(ArgInfo, InputArguments) },
 	call_gen__generate_call_livevals(OutArgs, InputArguments, CodeC0),
 	{ call_gen__output_arg_locs(Args, OutputArguments) },
-	call_gen__generate_return_livevals(OutArgs, OutputArguments,
+	call_gen__generate_return_livevals(OutArgs, OutputArguments, GoalInfo,
 		OutLiveVals),
 	code_info__make_entry_label(ModuleInfo, PredId, ModeId, yes, Address),
 	{ CodeC1 = node([
@@ -119,7 +120,7 @@
 	% it's a nondet call for which we are pruning all solutions except the
 	% first.
 
-call_gen__generate_semidet_call(PredId, ProcId, Arguments, Code) -->
+call_gen__generate_semidet_call(PredId, ProcId, Arguments, GoalInfo, Code) -->
 	code_info__get_module_info(ModuleInfo),
 	{ module_info_preds(ModuleInfo, Preds) },
 	{ map__lookup(Preds, PredId, PredInfo) },
@@ -128,14 +129,15 @@
 	{ proc_info_interface_code_model(ProcInfo, CodeModel) },
 	( { CodeModel = model_semi } ->
 		call_gen__generate_semidet_call_2(PredId, ProcId, Arguments,
-			Code)
+			GoalInfo, Code)
 	;
-		call_gen__generate_nondet_call(PredId, ProcId, Arguments, Code)
+		call_gen__generate_nondet_call(PredId, ProcId, Arguments, 
+			GoalInfo, Code)
 	).
 
 :- pred call_gen__generate_semidet_call_2(pred_id, proc_id, list(var),
-					code_tree, code_info, code_info).
-:- mode call_gen__generate_semidet_call_2(in, in, in, out, in, out) is det.
+			hlds_goal_info, code_tree, code_info, code_info).
+:- mode call_gen__generate_semidet_call_2(in, in, in, in, out, in, out) is det.
 
 	% To generate a call to a semideterministic predicate, first
 	% we get the arginfo for the callee.
@@ -150,7 +152,7 @@
 	% we branch to the appropriate continuation as generated by
 	% code_info__generate_failure.
 
-call_gen__generate_semidet_call_2(PredId, ModeId, Arguments, Code) -->
+call_gen__generate_semidet_call_2(PredId, ModeId, Arguments, GoalInfo, Code) -->
 	code_info__get_pred_proc_arginfo(PredId, ModeId, ArgInfo),
 	{ assoc_list__from_corresponding_lists(Arguments, ArgInfo, Args) },
 	{ call_gen__select_out_args(Args, OutArgs) },
@@ -161,7 +163,7 @@
 	{ call_gen__input_args(ArgInfo, InputArguments) },
 	call_gen__generate_call_livevals(OutArgs, InputArguments, CodeC0),
 	{ call_gen__output_arg_locs(Args, OutputArguments) },
-	call_gen__generate_return_livevals(OutArgs, OutputArguments,	
+	call_gen__generate_return_livevals(OutArgs, OutputArguments, GoalInfo,
 		OutLiveVals),
 	code_info__make_entry_label(ModuleInfo, PredId, ModeId, yes, Address),
 	{ CodeC1 = node([
@@ -182,7 +184,7 @@
 
 %---------------------------------------------------------------------------%
 
-call_gen__generate_nondet_call(PredId, ModeId, Arguments, Code) -->
+call_gen__generate_nondet_call(PredId, ModeId, Arguments, GoalInfo, Code) -->
 	code_info__get_pred_proc_arginfo(PredId, ModeId, ArgInfo),
 	{ assoc_list__from_corresponding_lists(Arguments, ArgInfo, Args) },
 	{ call_gen__select_out_args(Args, OutArgs) },
@@ -195,7 +197,7 @@
 	{ call_gen__input_args(ArgInfo, InputArguments) },
 	call_gen__generate_call_livevals(OutArgs, InputArguments, LiveCode),
 	{ call_gen__output_arg_locs(Args, OutputArguments) },
-	call_gen__generate_return_livevals(OutArgs, OutputArguments,
+	call_gen__generate_return_livevals(OutArgs, OutputArguments, GoalInfo,
 		OutLiveVals),
 	code_info__make_entry_label(ModuleInfo, PredId, ModeId, yes, Address),
 	{ CallModel = nondet(TailCall) },
@@ -378,7 +380,7 @@
 			CodeC0),
 		{ call_gen__output_arg_locs(Args, OutputArguments) },
 		call_gen__generate_return_livevals(OutArgs, OutputArguments, 
-						OutLiveVals),
+				GoalInfo, OutLiveVals),
 		{ code_util__make_uni_label(ModuleInfo, VarTypeId, ModeNum,
 			UniLabel) },
 		{ Address = imported(UniLabel) },
@@ -520,15 +522,15 @@
 %---------------------------------------------------------------------------%
 
 :- pred call_gen__generate_return_livevals(set(var), list(pair(var, arg_loc)),
-					list(liveinfo), code_info, code_info).
-:- mode call_gen__generate_return_livevals(in, in, out, in, out) is det.
+		hlds_goal_info,	list(liveinfo), code_info, code_info).
+:- mode call_gen__generate_return_livevals(in, in, in, out, in, out) is det.
 
-call_gen__generate_return_livevals(OutArgs, OutputArgs, LiveVals) -->
-	code_info__generate_stack_livelvals(OutArgs, LiveVals0),
+call_gen__generate_return_livevals(OutArgs, OutputArgs, GoalInfo, LiveVals) -->
+	code_info__generate_stack_livelvals(OutArgs, GoalInfo, LiveVals0),
 	code_info__get_globals(Globals),
 	{ globals__get_gc_method(Globals, GC_Method) },
-	call_gen__insert_arg_livelvals(OutputArgs, GC_Method, LiveVals0, 
-		LiveVals).
+	call_gen__insert_arg_livelvals(OutputArgs, GC_Method, GoalInfo,
+		LiveVals0, LiveVals).
 	
 
 % Maybe a varlist to type_id list would be a better way to do this...
@@ -536,18 +538,26 @@
 %---------------------------------------------------------------------------%
 
 :- pred call_gen__insert_arg_livelvals(list(pair(var, arg_loc)), gc_method, 
-	list(liveinfo), list(liveinfo), code_info, code_info).
-:- mode call_gen__insert_arg_livelvals(in, in, in, out, in, out) is det.
+	hlds_goal_info, list(liveinfo), list(liveinfo), code_info, code_info).
+:- mode call_gen__insert_arg_livelvals(in, in, in, in, out, in, out) is det.
 
-call_gen__insert_arg_livelvals([], _, LiveVals, LiveVals) --> [].
-call_gen__insert_arg_livelvals([Var - L | As], GC_Method, LiveVals0,
+call_gen__insert_arg_livelvals([], _, _, LiveVals, LiveVals) --> [].
+call_gen__insert_arg_livelvals([Var - L | As], GC_Method, GoalInfo, LiveVals0,
 		LiveVals) -->
 	(
 		{ GC_Method = accurate }
 	->
-		code_info__variable_type(Var, Type),
+			% we want the instmap _after_ the call, because
+			% GC will do collection at the continuation
+			% points, so we need to get this goals
+			% instmap_delta.
 		code_info__get_instmap(InstMap),
-		{ instmap__lookup_var(InstMap, Var, Inst) },
+		{ goal_info_get_instmap_delta(GoalInfo, InstMapDelta) },
+		{ instmap__apply_instmap_delta(InstMap, InstMapDelta,
+			AfterCallInstMap) },
+		{ instmap__lookup_var(AfterCallInstMap, Var, Inst) },
+
+		code_info__variable_type(Var, Type),
 		{ type_util__vars(Type, TypeVars) },
 		code_info__find_type_infos(TypeVars, TypeParams),
 		{ LiveVal = live_lvalue(R, var(Type, Inst), TypeParams) }
@@ -555,8 +565,8 @@
 		{ LiveVal = live_lvalue(R, unwanted, []) }
 	),
 	{ code_util__arg_loc_to_register(L, R) },
-	call_gen__insert_arg_livelvals(As, GC_Method, [LiveVal | LiveVals0], 
-		LiveVals).
+	call_gen__insert_arg_livelvals(As, GC_Method, GoalInfo, 
+		[LiveVal | LiveVals0], LiveVals).
 
 %---------------------------------------------------------------------------%
 
@@ -575,7 +585,7 @@
 	%
 
 call_gen__generate_higher_order_call(_OuterCodeModel, PredVar, Args, Types,
-		Modes, Det, Code) -->
+		Modes, Det, GoalInfo, Code) -->
 	{ determinism_to_code_model(Det, InnerCodeModel) },
 	code_info__get_globals(Globals),
 	code_info__get_module_info(ModuleInfo),
@@ -585,13 +595,14 @@
 	{ assoc_list__from_corresponding_lists(Args, ArgInfo, ArgsAndArgInfo) },
 	{ call_gen__partition_args(ArgsAndArgInfo, InVars, OutVars) },
 	call_gen__generate_higher_call(InnerCodeModel, PredVar, InVars, OutVars,
-		Code).
+		GoalInfo, Code).
 
 :- pred call_gen__generate_higher_call(code_model, var, list(var), list(var),
-				code_tree, code_info, code_info).
-:- mode call_gen__generate_higher_call(in, in, in, in, out, in, out) is det.
+			hlds_goal_info, code_tree, code_info, code_info).
+:- mode call_gen__generate_higher_call(in, in, in, in, in, out, in, out) is det.
 
-call_gen__generate_higher_call(CodeModel, PredVar, InVars, OutVars, Code) -->
+call_gen__generate_higher_call(CodeModel, PredVar, InVars, OutVars, GoalInfo,
+		Code) -->
 	code_info__succip_is_used,
 	{ set__list_to_set(OutVars, OutArgs) },
 	call_gen__save_variables(OutArgs, SaveCode),
@@ -627,7 +638,8 @@
 	),
 	{ call_gen__outvars_to_outargs(OutVars, FirstArg, OutArguments) },
 	{ call_gen__output_arg_locs(OutArguments, OutLocs) },
-	call_gen__generate_return_livevals(OutArgs, OutLocs, OutLiveVals),
+	call_gen__generate_return_livevals(OutArgs, OutLocs, GoalInfo, 
+		OutLiveVals),
 	code_info__produce_variable(PredVar, PredVarCode, PredRVal),
 	(
 		{ PredRVal = lval(reg(r, 1)) }
Index: compiler/code_gen.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/code_gen.m,v
retrieving revision 1.27
diff -u -r1.27 code_gen.m
--- code_gen.m	1997/05/27 03:06:18	1.27
+++ code_gen.m	1997/06/05 01:30:46
@@ -712,16 +712,17 @@
 	code_gen__generate_negation(model_det, Goal, Instr).
 code_gen__generate_det_goal_2(higher_order_call(PredVar, Args, Types,
 		Modes, Det),
-		_CodeInfo, Instr) -->
+		GoalInfo, Instr) -->
 	call_gen__generate_higher_order_call(model_det, PredVar, Args,
-		Types, Modes, Det, Instr).
+		Types, Modes, Det, GoalInfo, Instr).
 code_gen__generate_det_goal_2(call(PredId, ProcId, Args, BuiltinState, _, _),
-		_GoalInfo, Instr) -->
+		GoalInfo, Instr) -->
 	(
 		{ BuiltinState = not_builtin }
 	->
 		code_info__succip_is_used,
-		call_gen__generate_det_call(PredId, ProcId, Args, Instr)
+		call_gen__generate_det_call(PredId, ProcId, Args, GoalInfo,
+			Instr)
 	;
 		call_gen__generate_det_builtin(PredId, ProcId, Args, Instr)
 	).
@@ -798,16 +799,17 @@
 code_gen__generate_semi_goal_2(not(Goal), _GoalInfo, Code) -->
 	code_gen__generate_negation(model_semi, Goal, Code).
 code_gen__generate_semi_goal_2(higher_order_call(PredVar, Args, Types, Modes,
-		Det), _CodeInfo, Code) -->
+		Det), GoalInfo, Code) -->
 	call_gen__generate_higher_order_call(model_semi, PredVar, Args,
-		Types, Modes, Det, Code).
+		Types, Modes, Det, GoalInfo, Code).
 code_gen__generate_semi_goal_2(call(PredId, ProcId, Args, BuiltinState, _, _),
-							_GoalInfo, Code) -->
+							GoalInfo, Code) -->
 	(
 		{ BuiltinState = not_builtin }
 	->
 		code_info__succip_is_used,
-		call_gen__generate_semidet_call(PredId, ProcId, Args, Code)
+		call_gen__generate_semidet_call(PredId, ProcId, Args, GoalInfo,
+			Code)
 	;
 		call_gen__generate_semidet_builtin(PredId, ProcId, Args, Code)
 	).
@@ -992,16 +994,17 @@
 	{ error("Cannot have a nondet negation.") }.
 code_gen__generate_non_goal_2(higher_order_call(PredVar, Args, Types, Modes,
 		Det),
-		_CodeInfo, Code) -->
+		GoalInfo, Code) -->
 	call_gen__generate_higher_order_call(model_non, PredVar, Args, Types,
-		Modes, Det, Code).
+		Modes, Det, GoalInfo, Code).
 code_gen__generate_non_goal_2(call(PredId, ProcId, Args, BuiltinState, _, _),
-							_GoalInfo, Code) -->
+							GoalInfo, Code) -->
 	(
 		{ BuiltinState = not_builtin }
 	->
 		code_info__succip_is_used,
-		call_gen__generate_nondet_call(PredId, ProcId, Args, Code)
+		call_gen__generate_nondet_call(PredId, ProcId, Args, GoalInfo,
+			Code)
 	;
 		call_gen__generate_nondet_builtin(PredId, ProcId, Args, Code)
 	).
Index: compiler/code_info.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/code_info.m,v
retrieving revision 1.203
diff -u -r1.203 code_info.m
--- code_info.m	1997/05/27 03:06:20	1.203
+++ code_info.m	1997/06/05 01:56:50
@@ -2600,9 +2600,9 @@
 	code_info, code_info).
 :- mode code_info__generate_stack_livevals(in, out, in, out) is det.
 
-:- pred code_info__generate_stack_livelvals(set(var), list(liveinfo),
-	code_info, code_info).
-:- mode code_info__generate_stack_livelvals(in, out, in, out) is det.
+:- pred code_info__generate_stack_livelvals(set(var), hlds_goal_info, 
+	list(liveinfo), code_info, code_info).
+:- mode code_info__generate_stack_livelvals(in, in, out, in, out) is det.
 
 %---------------------------------------------------------------------------%
 
@@ -2662,7 +2662,7 @@
 
 %---------------------------------------------------------------------------%
 
-code_info__generate_stack_livelvals(Args, LiveVals) -->
+code_info__generate_stack_livelvals(Args, GoalInfo, LiveVals) -->
 	code_info__get_known_variables(LiveVars),
 	{ set__list_to_set(LiveVars, Vars0) },
 	{ set__difference(Vars0, Args, Vars) },
@@ -2672,7 +2672,8 @@
 	{ set__to_sorted_list(LiveVals1, LiveVals2) },
 	code_info__get_globals(Globals),
 	{ globals__get_gc_method(Globals, GC_Method) },
-	code_info__livevals_to_livelvals(LiveVals2, GC_Method, LiveVals3),
+	code_info__livevals_to_livelvals(LiveVals2, GC_Method, GoalInfo,
+		LiveVals3),
 	code_info__get_temps_in_use(TempsSet),
 	{ map__to_assoc_list(TempsSet, Temps) },
 	{ code_info__generate_temp_livelvals(Temps, LiveVals3, LiveVals4) },
@@ -2729,25 +2730,33 @@
 	).
 
 :- pred code_info__livevals_to_livelvals(assoc_list(lval, var), gc_method,
-	list(liveinfo), code_info, code_info).
-:- mode code_info__livevals_to_livelvals(in, in, out, in, out) is det.
+	hlds_goal_info, list(liveinfo), code_info, code_info).
+:- mode code_info__livevals_to_livelvals(in, in, in, out, in, out) is det.
 
-code_info__livevals_to_livelvals([], _GC_Method, []) --> [].
-code_info__livevals_to_livelvals([Lval - Var | Ls], GC_Method,
+code_info__livevals_to_livelvals([], _GC_Method, _, []) --> [].
+code_info__livevals_to_livelvals([Lval - Var | Ls], GC_Method, GoalInfo,
 		[LiveLval | Lives]) -->
 	(
 		{ GC_Method = accurate }
 	->
-		code_info__variable_type(Var, Type),
+		      % we want the instmap _after_ the call, because 
+		      % GC will do collection at the continuation 
+		      % points, so we need to get this goals 
+		      % instmap_delta.
 		code_info__get_instmap(InstMap),
-		{ instmap__lookup_var(InstMap, Var, Inst) },
+		{ goal_info_get_instmap_delta(GoalInfo, InstMapDelta) },
+		{ instmap__apply_instmap_delta(InstMap, InstMapDelta,
+			AfterCallInstMap) },
+		{ instmap__lookup_var(AfterCallInstMap, Var, Inst) },
+
+		code_info__variable_type(Var, Type),
 		{ type_util__vars(Type, TypeVars) },
 		code_info__find_type_infos(TypeVars, TypeParams),
 		{ LiveLval = live_lvalue(Lval, var(Type, Inst), TypeParams) }
 	;
 		{ LiveLval = live_lvalue(Lval, unwanted, []) }
 	),
-	code_info__livevals_to_livelvals(Ls, GC_Method, Lives).
+	code_info__livevals_to_livelvals(Ls, GC_Method, GoalInfo, Lives).
 
 :- pred code_info__get_live_value_type(lval_or_ticket, live_value_type).
 :- mode code_info__get_live_value_type(in, out) is det.


-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't eveyone's cup of
     trd at cs.mu.oz.au        #  fur.
http://www.cs.mu.oz.au/~trd #



More information about the developers mailing list