[m-dev.] for review: thread instmap through ml_code_gen.m

Simon Taylor stayl at cs.mu.OZ.AU
Thu Dec 9 14:10:04 AEDT 1999


Fergus, could you please take a look at this.

Simon.


Estimated hours taken: 0.5

compiler/ml_code_gen.m:
	Thread an instmap through. The instmap will be needed
	for the alias branch - this change to the main branch
	will hopefully minimise conflicts between the branches.

Index: ml_code_gen.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.22
diff -u -u -r1.22 ml_code_gen.m
--- ml_code_gen.m	1999/12/03 20:22:45	1.22
+++ ml_code_gen.m	1999/12/09 00:58:27
@@ -614,7 +614,7 @@
 :- import_module code_util. % XXX needed for `code_util__compiler_generated'.
 			    % and `code_util__cons_id_to_tag'.
 :- import_module goal_util.
-:- import_module hlds_goal, hlds_data, prog_data, special_pred.
+:- import_module hlds_goal, hlds_data, prog_data, special_pred, instmap.
 :- import_module hlds_out, builtin_ops, passes_aux, type_util, mode_util.
 :- import_module prog_util.
 :- import_module globals, options.
@@ -2194,6 +2194,8 @@
 ml_switch_generate_cases([Case | Cases], Var, CodeModel, CanFail, Context,
 		MLDS_Decls, MLDS_Statements) -->
 	{ Case = case(_, _Tag, ConsId, Goal) },
+	=(MLDSGenInfo0),
+	{ ml_gen_info_get_instmap(MLDSGenInfo0, InstMap0) },
 	(
 		{ Cases = [], CanFail = cannot_fail }
 	->
@@ -2202,6 +2204,7 @@
 		ml_gen_tag_test(Var, ConsId, TagTestDecls, TagTestStatements,
 			TagTestExpression),
 		ml_gen_goal(CodeModel, Goal, GoalStatement),
+		ml_gen_info_set_instmap(InstMap0),
 		ml_switch_generate_cases(Cases, Var, CodeModel, CanFail,
 			Context, RestDecls, RestStatements),
 		{ Rest = ml_gen_block(RestDecls, RestStatements, Context) },
@@ -2227,6 +2230,8 @@
 		MLDS_Decls, MLDS_Statements) -->
 	{ Cond = _ - CondGoalInfo },
 	{ goal_info_get_code_model(CondGoalInfo, CondCodeModel) },
+	=(MLDSGenInfo0),
+	{ ml_gen_info_get_instmap(MLDSGenInfo0, InstMap0) },
 	(
 		{ CondCodeModel = model_det },
 		% simplify.m should remove these
@@ -2248,7 +2253,9 @@
 		{ CondCodeModel = model_semi },
 		ml_gen_goal(model_semi, Cond, CondDecls, CondStatements),
 		ml_gen_test_success(Succeeded),
+		ml_gen_info_update_instmap(Cond),
 		ml_gen_goal(CodeModel, Then, ThenStatement),
+		ml_gen_info_set_instmap(InstMap0),
 		ml_gen_goal(CodeModel, Else, ElseStatement),
 		{ IfStmt = if_then_else(Succeeded, ThenStatement,
 			yes(ElseStatement)) },
@@ -2290,6 +2297,7 @@
 		{ CondCodeModel = model_non },
 
 		% generate the `then_func'
+		ml_gen_info_update_instmap(Cond),
 		ml_gen_new_func_label(ThenFuncLabel, ThenFuncLabelRval),
 		/* push nesting level */
 		{ Then = _ - ThenGoalInfo },
@@ -2307,9 +2315,11 @@
 		ml_get_env_ptr(EnvPtrRval),
 		{ SuccessCont = success_cont(ThenFuncLabelRval, EnvPtrRval) },
 		ml_gen_info_push_success_cont(SuccessCont),
+		ml_gen_info_set_instmap(InstMap0),
 		ml_gen_goal(model_non, Cond, CondDecls, CondStatements),
 		ml_gen_info_pop_success_cont,
 		ml_gen_test_success(Succeeded),
+		ml_gen_info_set_instmap(InstMap0),
 		ml_gen_goal(CodeModel, Else, ElseStatement),
 		{ IfStmt = if_then_else(unop(std_unop(not), Succeeded),
 			ElseStatement, no) },
@@ -2404,10 +2414,24 @@
 ml_gen_conj([First | Rest], CodeModel, Context,
 		MLDS_Decls, MLDS_Statements) -->
 	{ Rest = [_ | _] },
+	=(MLDSGenInfo0),
+	{ ml_gen_info_get_instmap(MLDSGenInfo0, InstMap0) },
 	{ First = _ - FirstGoalInfo },
 	{ goal_info_get_code_model(FirstGoalInfo, FirstCodeModel) },
-	{ DoGenFirst = ml_gen_goal(FirstCodeModel, First) },
-	{ DoGenRest = ml_gen_conj(Rest, CodeModel, Context) },
+	{ goal_info_get_instmap_delta(FirstGoalInfo, FirstInstMapDelta) },
+	{ instmap__apply_instmap_delta(InstMap0, FirstInstMapDelta,
+		InstMapAfterFirst) },
+	{ DoGenFirst =
+	    (pred(FirstDecls::out, FirstStatements::out, in, out) is det -->
+		ml_gen_info_set_instmap(InstMap0),
+		ml_gen_goal(FirstCodeModel, First, FirstDecls, FirstStatements)
+	    ) },
+	{ DoGenRest =
+	    (pred(RestDecls::out, RestStatements::out, in, out) is det -->
+	     	ml_gen_info_set_instmap(InstMapAfterFirst),	
+		ml_gen_conj(Rest, CodeModel, Context,
+			RestDecls, RestStatements)
+	    ) },
 	ml_combine_conj(FirstCodeModel, Context, DoGenFirst, DoGenRest,
 		MLDS_Decls, MLDS_Statements).
 
@@ -2617,6 +2641,10 @@
 ml_gen_disj([First | Rest], CodeModel, Context,
 		MLDS_Decls, MLDS_Statements) -->
 	{ Rest = [_ | _] },
+
+	=(MLDSGenInfo0),
+	{ ml_gen_info_get_instmap(MLDSGenInfo0, InstMap0) },
+
 	( { CodeModel = model_non } ->
 		%
 		% model_non disj:
@@ -2627,6 +2655,7 @@
 		%		<Goals && SUCCEED()>
 		%
 		ml_gen_goal(model_non, First, FirstDecls, FirstStatements),
+		ml_gen_info_set_instmap(InstMap0),
 		ml_gen_disj(Rest, model_non, Context,
 			RestDecls, RestStatements),
 		{ ml_join_decls(FirstDecls, FirstStatements,
@@ -2665,6 +2694,7 @@
 			ml_gen_goal(model_semi, First,
 				FirstDecls, FirstStatements),
 			ml_gen_test_success(Succeeded),
+			ml_gen_info_set_instmap(InstMap0),
 			ml_gen_disj(Rest, CodeModel, Context,
 				RestDecls, RestStatements),
 			{ RestStatement = ml_gen_block(RestDecls,
@@ -4343,7 +4373,10 @@
 				% constants which should be inserted
 				% before the definition of the function
 				% for the current procedure
-			mlds__defns
+			mlds__defns,
+			instmap,
+			unit	% this field is used for the inst_table
+				% on the alias branch.
 		).
 
 :- type commit_sequence_num == int.
@@ -4357,6 +4390,7 @@
 	proc_info_varset(ProcInfo, VarSet),
 	proc_info_vartypes(ProcInfo, VarTypes),
 	proc_info_argmodes(ProcInfo, HeadModes),
+	proc_info_get_initial_instmap(ProcInfo, ModuleInfo, InstMap),
 	OutputVars = select_output_vars(ModuleInfo, HeadVars, HeadModes,
 		VarTypes),
 	FuncLabelCounter = 0,
@@ -4373,13 +4407,16 @@
 			FuncLabelCounter,
 			CommitLabelCounter,
 			SuccContStack,
-			ExtraDefns
+			ExtraDefns,
+			InstMap,
+			unit
 		).
 
 :- pred ml_gen_info_get_module_info(ml_gen_info, module_info).
 :- mode ml_gen_info_get_module_info(in, out) is det.
 
-ml_gen_info_get_module_info(ml_gen_info(ModuleInfo, _, _, _, _, _, _, _, _, _),
+ml_gen_info_get_module_info(
+	ml_gen_info(ModuleInfo, _, _, _, _, _, _, _, _, _, _, _),
 	ModuleInfo).
 
 :- pred ml_gen_info_get_module_name(ml_gen_info, mercury_module_name).
@@ -4392,36 +4429,41 @@
 :- pred ml_gen_info_get_pred_id(ml_gen_info, pred_id).
 :- mode ml_gen_info_get_pred_id(in, out) is det.
 
-ml_gen_info_get_pred_id(ml_gen_info(_, PredId, _, _, _, _, _, _, _, _), PredId).
+ml_gen_info_get_pred_id(ml_gen_info(_, PredId, _, _, _, _, _, _, _, _, _, _),
+		PredId).
 
 :- pred ml_gen_info_get_proc_id(ml_gen_info, proc_id).
 :- mode ml_gen_info_get_proc_id(in, out) is det.
 
-ml_gen_info_get_proc_id(ml_gen_info(_, _, ProcId, _, _, _, _, _, _, _), ProcId).
+ml_gen_info_get_proc_id(ml_gen_info(_, _, ProcId, _, _, _, _, _, _, _, _, _),
+		ProcId).
 
 :- pred ml_gen_info_get_varset(ml_gen_info, prog_varset).
 :- mode ml_gen_info_get_varset(in, out) is det.
 
-ml_gen_info_get_varset(ml_gen_info(_, _, _, VarSet, _, _, _, _, _, _), VarSet).
+ml_gen_info_get_varset(ml_gen_info(_, _, _, VarSet, _, _, _, _, _, _, _, _),
+		VarSet).
 
 :- pred ml_gen_info_get_var_types(ml_gen_info, map(prog_var, prog_type)).
 :- mode ml_gen_info_get_var_types(in, out) is det.
 
-ml_gen_info_get_var_types(ml_gen_info(_, _, _, _, VarTypes, _, _, _, _, _),
+ml_gen_info_get_var_types(
+	ml_gen_info(_, _, _, _, VarTypes, _, _, _, _, _, _, _),
 	VarTypes).
 
 :- pred ml_gen_info_get_output_vars(ml_gen_info, list(prog_var)).
 :- mode ml_gen_info_get_output_vars(in, out) is det.
 
-ml_gen_info_get_output_vars(ml_gen_info(_, _, _, _, _, OutputVars, _, _, _, _),
+ml_gen_info_get_output_vars(
+	ml_gen_info(_, _, _, _, _, OutputVars, _, _, _, _, _, _),
 	OutputVars).
 
 :- pred ml_gen_info_new_func_label(ml_label_func, ml_gen_info, ml_gen_info).
 :- mode ml_gen_info_new_func_label(out, in, out) is det.
 
 ml_gen_info_new_func_label(Label,
-		ml_gen_info(A, B, C, D, E, F, Label0, H, I, J),
-		ml_gen_info(A, B, C, D, E, F, Label, H, I, J)) :-
+		ml_gen_info(A, B, C, D, E, F, Label0, H, I, J, K, L),
+		ml_gen_info(A, B, C, D, E, F, Label, H, I, J, K, L)) :-
 	Label is Label0 + 1.
 
 :- pred ml_gen_info_new_commit_label(commit_sequence_num,
@@ -4429,8 +4471,8 @@
 :- mode ml_gen_info_new_commit_label(out, in, out) is det.
 
 ml_gen_info_new_commit_label(CommitLabel,
-		ml_gen_info(A, B, C, D, E, F, G, CommitLabel0, I, J),
-		ml_gen_info(A, B, C, D, E, F, G, CommitLabel, I, J)) :-
+		ml_gen_info(A, B, C, D, E, F, G, CommitLabel0, I, J, K, L),
+		ml_gen_info(A, B, C, D, E, F, G, CommitLabel, I, J, K, L)) :-
 	CommitLabel is CommitLabel0 + 1.
 
 :- type success_cont 
@@ -4448,15 +4490,16 @@
 :- mode ml_gen_info_get_success_cont_stack(in, out) is det.
 
 ml_gen_info_get_success_cont_stack(
-	ml_gen_info(_, _, _, _, _, _, _, _, SuccContStack, _), SuccContStack).
+	ml_gen_info(_, _, _, _, _, _, _, _, SuccContStack, _, _, _),
+	SuccContStack).
 
 :- pred ml_gen_info_set_success_cont_stack(stack(success_cont),
 			ml_gen_info, ml_gen_info).
 :- mode ml_gen_info_set_success_cont_stack(in, in, out) is det.
 
 ml_gen_info_set_success_cont_stack(SuccContStack,
-		ml_gen_info(A, B, C, D, E, F, G, H, _, J),
-		ml_gen_info(A, B, C, D, E, F, G, H, SuccContStack, J)).
+		ml_gen_info(A, B, C, D, E, F, G, H, _, J, K, L),
+		ml_gen_info(A, B, C, D, E, F, G, H, SuccContStack, J, K, L)).
 ********/
 
 :- pred ml_gen_info_push_success_cont(success_cont,
@@ -4464,16 +4507,16 @@
 :- mode ml_gen_info_push_success_cont(in, in, out) is det.
 
 ml_gen_info_push_success_cont(SuccCont,
-		ml_gen_info(A, B, C, D, E, F, G, H, Stack0, J),
-		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J)) :-
+		ml_gen_info(A, B, C, D, E, F, G, H, Stack0, J, K, L),
+		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J, K, L)) :-
 	stack__push(Stack0, SuccCont, Stack).
 
 :- pred ml_gen_info_pop_success_cont(ml_gen_info, ml_gen_info).
 :- mode ml_gen_info_pop_success_cont(in, out) is det.
 
 ml_gen_info_pop_success_cont(
-		ml_gen_info(A, B, C, D, E, F, G, H, Stack0, J),
-		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J)) :-
+		ml_gen_info(A, B, C, D, E, F, G, H, Stack0, J, K, L),
+		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J, K, L)) :-
 	stack__pop_det(Stack0, _SuccCont, Stack).
 
 :- pred ml_gen_info_current_success_cont(success_cont,
@@ -4481,8 +4524,8 @@
 :- mode ml_gen_info_current_success_cont(out, in, out) is det.
 
 ml_gen_info_current_success_cont(SuccCont,
-		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J),
-		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J)) :-
+		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J, K, L),
+		ml_gen_info(A, B, C, D, E, F, G, H, Stack, J, K, L)) :-
 	stack__top_det(Stack, SuccCont).
 
 :- pred ml_gen_info_add_extra_defn(mlds__defn,
@@ -4490,15 +4533,40 @@
 :- mode ml_gen_info_add_extra_defn(in, in, out) is det.
 
 ml_gen_info_add_extra_defn(ExtraDefn,
-		ml_gen_info(A, B, C, D, E, F, G, H, I, ExtraDefns0),
-		ml_gen_info(A, B, C, D, E, F, G, H, I, ExtraDefns)) :-
+		ml_gen_info(A, B, C, D, E, F, G, H, I, ExtraDefns0, K, L),
+		ml_gen_info(A, B, C, D, E, F, G, H, I, ExtraDefns, K, L)) :-
 	ExtraDefns = [ExtraDefn | ExtraDefns0].
 
 :- pred ml_gen_info_get_extra_defns(ml_gen_info, mlds__defns).
 :- mode ml_gen_info_get_extra_defns(in, out) is det.
 
-ml_gen_info_get_extra_defns(ml_gen_info(_, _, _, _, _, _, _, _, _, ExtraDefns),
+ml_gen_info_get_extra_defns(
+	ml_gen_info(_, _, _, _, _, _, _, _, _, ExtraDefns, _, _),
 	ExtraDefns).
+
+:- pred ml_gen_info_get_instmap(ml_gen_info, instmap).
+:- mode ml_gen_info_get_instmap(in, out) is det.
+
+ml_gen_info_get_instmap(
+	ml_gen_info(_, _, _, _, _, _, _, _, _, _, InstMap, _),
+	InstMap).
+
+:- pred ml_gen_info_set_instmap(instmap, ml_gen_info, ml_gen_info).
+:- mode ml_gen_info_set_instmap(in, in, out) is det.
+
+ml_gen_info_set_instmap(InstMap,
+		ml_gen_info(A, B, C, D, E, F, G, H, I, J, _, L),
+		ml_gen_info(A, B, C, D, E, F, G, H, I, J, InstMap, L)).
+
+:- pred ml_gen_info_update_instmap(hlds_goal,
+		ml_gen_info, ml_gen_info).
+:- mode ml_gen_info_update_instmap(in, in, out) is det.
+
+ml_gen_info_update_instmap(_ - GoalInfo, Info0, Info) :-
+	goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
+	ml_gen_info_get_instmap(Info0, InstMap0),
+	instmap__apply_instmap_delta(InstMap0, InstMapDelta, InstMap),
+	ml_gen_info_set_instmap(InstMap, Info0, Info).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list