For review: code generator improvements

Zoltan Somogyi zs at cs.mu.oz.au
Mon May 12 12:02:35 AEST 1997


Tom, pleae review this.

Slight rearrangement of the data structures of the code generator, to allow
more flexibility in code generation. The rearrangement moves the stack_slots
information (mapping vars to their stack slots if any) and follow_vars
information (mapping vars to the location preferred for them by future code)
from code_info to code_exprn. This allows the predicates in code_exprn to
make use of this information.

As a result of these changes, the code generator now emits 110 fewer lines
of C code for the compiler (478 lines are replaced by 368). There is no
discernible impact on the memory requirements or running time of the compiler
itself.

code_exprn:
	Add the two fields to the exprn_info data structure.

	Several predicates in code_exprn now evaluate variables directly
	into their preferred location, instead of a random register.

code_info:
	Remove the two fields from the code_info data structure.

Zoltan.

cvs diff: Diffing .
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/code_exprn.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_exprn.m,v
retrieving revision 1.47
diff -u -r1.47 code_exprn.m
--- code_exprn.m	1997/04/07 05:39:07	1.47
+++ code_exprn.m	1997/04/08 06:13:29
@@ -35,19 +35,35 @@
 
 :- type exprn_info.
 
-%	code_exprn__init_state(Arguments, Varset, Opts, ExprnInfo)
+%	code_exprn__init_state(Arguments, Varset, StackSlots, FollowVars,
+%			Opts, ExprnInfo)
 %		Produces an initial state of the ExprnInfo given
 %		an association list of variables and lvalues. The initial
 %		state places the given variables at their corresponding
 %		locations. The Varset parameter contains a mapping from
 %		variables to names, which is used when code is generated
-%		to provide meaningful comments. Opts gives the table of
-%		options; this is used to decide what expressions are
-%		considered constants.
-
-:- pred code_exprn__init_state(assoc_list(var, rval), varset, option_table,
-	exprn_info).
-:- mode code_exprn__init_state(in, in, in, out) is det.
+%		to provide meaningful comments. StackSlots maps each variable
+%		to its stack slot (if it has one). FollowVars is the initial
+%		follow_vars set; such sets give guidance as to what lvals
+%		(if any) each variable will be needed in next. Opts gives
+%		the table of options; this is used to decide what expressions
+%		are considered constants.
+
+:- pred code_exprn__init_state(assoc_list(var, rval), varset, stack_slots,
+	follow_vars, option_table, exprn_info).
+:- mode code_exprn__init_state(in, in, in, in, in, out) is det.
+
+%	code_exprn__reinit_state(VarLocs, ExprnInfo0, ExprnInfo)
+%		Produces a new state of the ExprnInfo in which the static
+%		and mostly static information (stack slot map, follow vars map,
+%		varset, option settings) comes from ExprnInfo0 but the dynamic
+%		state regarding variable locations is thrown away and then
+%		rebuilt from the information in VarLocs, an association list
+%		of variables and lvalues. The new state places the given
+%		variables at their corresponding locations.
+
+:- pred code_exprn__reinit_state(assoc_list(var, rval), exprn_info, exprn_info).
+:- mode code_exprn__reinit_state(in, in, out) is det.
 
 %	code_exprn__clobber_regs(CriticalVars, ExprnInfo0, ExprnInfo)
 %		Modifies the state ExprnInfo0 to produce ExprnInfo
@@ -117,17 +133,17 @@
 %		provide it as an Rval of the form lval(reg(_)).
 
 :- pred code_exprn__produce_var_in_reg(var, rval, code_tree,
-						exprn_info, exprn_info).
+	exprn_info, exprn_info).
 :- mode code_exprn__produce_var_in_reg(in, out, out, in, out) is det.
 
-%	code_exprn__produce_var_in_reg_or_stack(Var, Rval, Code,
+%	code_exprn__produce_var_in_reg_or_stack(Var, FollowVars, Rval, Code,
 %			ExprnInfo0, ExprnInfo)
 %		Produces a code fragment Code to evaluate Var and
 %		provide it as an Rval of the form lval(reg(_)),
 %		lval(stackvar(_)), or lval(framevar(_)).
 
 :- pred code_exprn__produce_var_in_reg_or_stack(var, rval, code_tree,
-						exprn_info, exprn_info).
+	exprn_info, exprn_info).
 :- mode code_exprn__produce_var_in_reg_or_stack(in, out, out, in, out) is det.
 
 %	code_exprn__materialize_vars_in_rval(Rval0, Rval, Code, ExprnInfo0,
@@ -196,6 +212,27 @@
 :- pred code_exprn__get_varlocs(exprn_info, map(var, set(rval))).
 :- mode code_exprn__get_varlocs(in, out) is det.
 
+%	code_exprn__get_stack_slots(StackSlots)
+%		Returns the table mapping each variable to its stack slot
+%		(if any).
+
+:- pred code_exprn__get_stack_slots(stack_slots, exprn_info, exprn_info).
+:- mode code_exprn__get_stack_slots(out, in, out) is det.
+
+%	code_exprn__get_follow_vars(FollowVars)
+%		Returns the table mapping each variable to the lval (if any)
+%		where it is desired next.
+
+:- pred code_exprn__get_follow_vars(follow_vars, exprn_info, exprn_info).
+:- mode code_exprn__get_follow_vars(out, in, out) is det.
+
+%	code_exprn__set_follow_vars(FollowVars)
+%		Sets the table mapping each variable to the lval (if any)
+%		where it is desired next.
+
+:- pred code_exprn__set_follow_vars(follow_vars, exprn_info, exprn_info).
+:- mode code_exprn__set_follow_vars(in, in, out) is det.
+
 %------------------------------------------------------------------------------%
 %------------------------------------------------------------------------------%
 
@@ -215,18 +252,32 @@
 			var_map,	% what each variable stands for
 			bag(lval),	% the 'in use' markers for regs
 			set(lval),	% extra markers for acquired regs
+			stack_slots,	% map vars to the stack slot (if any)
+			follow_vars,	% where vars are needed next
 			exprn_opts	% options needed for constant checks
 		).
 
 %------------------------------------------------------------------------------%
 
-code_exprn__init_state(Initializations, Varset, Options, ExprnInfo) :-
+code_exprn__init_state(VarLocs, Varset, StackSlots, FollowVars,
+		Options, ExprnInfo) :-
 	map__init(Vars0),
 	bag__init(Regs0),
-	code_exprn__init_state_2(Initializations, Vars0, Vars, Regs0, Regs),
+	code_exprn__init_state_2(VarLocs, Vars0, Vars, Regs0, Regs),
 	set__init(Acqu),
 	exprn_aux__init_exprn_opts(Options, ExprnOpts),
-	ExprnInfo = exprn_info(Varset, Vars, Regs, Acqu, ExprnOpts).
+	ExprnInfo = exprn_info(Varset, Vars, Regs, Acqu,
+		StackSlots, FollowVars, ExprnOpts).
+
+code_exprn__reinit_state(VarLocs, ExprnInfo0, ExprnInfo) :-
+	map__init(Vars0),
+	bag__init(Regs0),
+	code_exprn__init_state_2(VarLocs, Vars0, Vars, Regs0, Regs),
+	set__init(Acqu),
+	ExprnInfo0 = exprn_info(Varset, _, _, _,
+		StackSlots, FollowVars, ExprnOpts),
+	ExprnInfo = exprn_info(Varset, Vars, Regs, Acqu,
+		StackSlots, FollowVars, ExprnOpts).
 
 :- pred code_exprn__init_state_2(assoc_list(var, rval), var_map, var_map,
 	bag(lval), bag(lval)).
@@ -784,25 +835,15 @@
 :- mode code_exprn__select_rval(in, out) is det.
 
 code_exprn__select_rval(Rvals, Rval) :-
-	(
-		Rvals = []
-	->
+	( Rvals = [] ->
 		error("code_exprn__select_rval: no rvals")
-	;
-		code_exprn__select_reg(Rvals, Rval0)
-	->
+	; code_exprn__select_reg(Rvals, Rval0) ->
 		Rval = Rval0
-	;
-		code_exprn__select_simple_const(Rvals, Rval1)
-	->
+	; code_exprn__select_simple_const(Rvals, Rval1) ->
 		Rval = Rval1
-	;
-		code_exprn__select_stackvar(Rvals, Rval2)
-	->
+	; code_exprn__select_stackvar(Rvals, Rval2) ->
 		Rval = Rval2
-	;
-		Rvals = [Rval3 | _]
-	->
+	; Rvals = [Rval3 | _] ->
 		Rval = Rval3
 	;
 		error("code_exprn__select_rval: cosmic rays strike again")
@@ -1302,7 +1343,7 @@
 %------------------------------------------------------------------------------%
 
 :- pred code_exprn__produce_vars(list(var), assoc_list(var, rval), code_tree,
-						exprn_info, exprn_info).
+	exprn_info, exprn_info).
 :- mode code_exprn__produce_vars(in, out, out, in, out) is det.
 
 code_exprn__produce_vars([], [], empty) --> [].
@@ -1334,7 +1375,7 @@
 		{ code_exprn__select_rval(RvalList, Rval) },
 		{ Code = empty }
 	;
-		code_exprn__get_spare_reg(r, Lval),
+		code_exprn__select_preferred_reg(Var, Lval),
 		{ Rval = lval(Lval) },
 		code_exprn__place_var(Var, Lval, Code)
 	).
@@ -1342,36 +1383,110 @@
 %------------------------------------------------------------------------------%
 
 code_exprn__produce_var_in_reg(Var, Rval, Code) -->
-	code_exprn__produce_var(Var, Rval0, Code0),
+	code_exprn__get_var_status(Var, Stat),
 	(
-		{ Rval0 = lval(reg(_, _)) }
+		{ Stat = evaled(Rvals) },
+		{ set__to_sorted_list(Rvals, RvalList) },
+		{ code_exprn__select_reg_rval(RvalList, Rval0) }
 	->
-		{ Code = Code0 },
+		{ Code = empty },
 		{ Rval = Rval0 }
 	;
-		code_exprn__get_spare_reg(r, Lval),
-		code_exprn__place_var(Var, Lval, Code1),
-		{ Rval = lval(Lval) },
-		{ Code = tree(Code0, Code1) }
+		code_exprn__select_preferred_reg(Var, Lval),
+		code_exprn__place_var(Var, Lval, Code),
+		{ Rval = lval(Lval) }
 	).
 
 code_exprn__produce_var_in_reg_or_stack(Var, Rval, Code) -->
-	code_exprn__produce_var(Var, Rval0, Code0),
+	code_exprn__get_var_status(Var, Stat),
 	(
-		{ Rval0 = lval(Loc) },
-		{ Loc = reg(_, _) ; Loc = stackvar(_) ; Loc = framevar(_) }
+		{ Stat = evaled(Rvals) },
+		{ set__to_sorted_list(Rvals, RvalList) },
+		{ code_exprn__select_reg_or_stack_rval(RvalList, Rval0) }
 	->
-		{ Code = Code0 },
+		{ Code = empty },
 		{ Rval = Rval0 }
 	;
-		code_exprn__get_spare_reg(r, Lval),
-		code_exprn__place_var(Var, Lval, Code1),
-		{ Rval = lval(Lval) },
-		{ Code = tree(Code0, Code1) }
+		code_exprn__select_preferred_lval(Var, Lval),
+		code_exprn__place_var(Var, Lval, Code),
+		{ Rval = lval(Lval) }
 	).
 
 %------------------------------------------------------------------------------%
 
+:- pred code_exprn__select_reg_rval(list(rval), rval).
+:- mode code_exprn__select_reg_rval(in, out) is semidet.
+
+code_exprn__select_reg_rval([Rval0 | Rvals0], Rval) :-
+	( Rval0 = lval(reg(_, _)) ->
+		Rval = Rval0
+	;
+		code_exprn__select_reg_rval(Rvals0, Rval)
+	).
+
+:- pred code_exprn__select_reg_or_stack_rval(list(rval), rval).
+:- mode code_exprn__select_reg_or_stack_rval(in, out) is semidet.
+
+code_exprn__select_reg_or_stack_rval([Rval0 | Rvals0], Rval) :-
+	(
+		Rval0 = lval(Lval),
+		( Lval = reg(_, _) ; Lval = stackvar(_) ; Lval = framevar(_) )
+	->
+		Rval = Rval0
+	;
+		code_exprn__select_reg_or_stack_rval(Rvals0, Rval)
+	).
+
+%------------------------------------------------------------------------------%
+
+:- pred code_exprn__select_preferred_lval(var, lval, exprn_info, exprn_info).
+:- mode code_exprn__select_preferred_lval(in, out, in, out) is det.
+
+code_exprn__select_preferred_lval(Var, Lval) -->
+	code_exprn__get_follow_vars(FollowVars),
+	(
+		{ map__search(FollowVars, Var, PrefLval) }
+	->
+		(
+			\+ { unreal_lval(PrefLval) },
+			\+ code_exprn__lval_in_use(PrefLval)
+		->
+			{ Lval = PrefLval }
+		;
+			code_exprn__get_spare_reg(r, Lval)
+		)
+	;
+		code_exprn__get_spare_reg(r, Lval)
+	).
+
+:- pred code_exprn__select_preferred_reg(var, lval, exprn_info, exprn_info).
+:- mode code_exprn__select_preferred_reg(in, out, in, out) is det.
+
+code_exprn__select_preferred_reg(Var, Lval) -->
+	code_exprn__get_follow_vars(FollowVars),
+	(
+		{ map__search(FollowVars, Var, PrefLval) },
+		{ PrefLval = reg(_, _) }
+	->
+		(
+			\+ { unreal_lval(PrefLval) },
+			\+ code_exprn__lval_in_use(PrefLval)
+		->
+			{ Lval = PrefLval }
+		;
+			code_exprn__get_spare_reg(r, Lval)
+		)
+	;
+		code_exprn__get_spare_reg(r, Lval)
+	).
+
+:- pred unreal_lval(lval).
+:- mode unreal_lval(in) is semidet.
+
+unreal_lval(reg(_, 0)).
+
+%------------------------------------------------------------------------------%
+
 :- pred code_exprn__produce_args(list(rval), assoc_list(rval, rval),
 	code_tree, exprn_info, exprn_info).
 :- mode code_exprn__produce_args(in, out, out, in, out) is det.
@@ -1678,35 +1793,45 @@
 :- mode code_exprn__get_options(out, in, out) is det.
 
 code_exprn__get_varset(Varset, ExprnInfo, ExprnInfo) :-
-	ExprnInfo = exprn_info(Varset, _Vars, _Regs, _Acqu, _Opt).
+	ExprnInfo = exprn_info(Varset, _Vars, _Regs, _Acqu, _SS, _FV, _Opt).
 
 code_exprn__set_varset(Varset, ExprnInfo0, ExprnInfo) :-
-	ExprnInfo0 = exprn_info(_Varset, Vars, Regs, Acqu, Opt),
-	ExprnInfo = exprn_info(Varset, Vars, Regs, Acqu, Opt).
+	ExprnInfo0 = exprn_info(_Varset, Vars, Regs, Acqu, SS, FV, Opt),
+	ExprnInfo = exprn_info(Varset, Vars, Regs, Acqu, SS, FV, Opt).
 
 code_exprn__get_vars(Vars, ExprnInfo, ExprnInfo) :-
-	ExprnInfo = exprn_info(_Varset, Vars, _Regs, _Acqu, _Opt).
+	ExprnInfo = exprn_info(_Varset, Vars, _Regs, _Acqu, _SS, _FV, _Opt).
 
 code_exprn__set_vars(Vars, ExprnInfo0, ExprnInfo) :-
-	ExprnInfo0 = exprn_info(Varset, _Vars, Regs, Acqu, Opt),
-	ExprnInfo = exprn_info(Varset, Vars, Regs, Acqu, Opt).
+	ExprnInfo0 = exprn_info(Varset, _Vars, Regs, Acqu, SS, FV, Opt),
+	ExprnInfo = exprn_info(Varset, Vars, Regs, Acqu, SS, FV, Opt).
 
 code_exprn__get_regs(Regs, ExprnInfo, ExprnInfo) :-
-	ExprnInfo = exprn_info(_Varset, _Vars, Regs, _Acqu, _Opt).
+	ExprnInfo = exprn_info(_Varset, _Vars, Regs, _Acqu, _SS, _FV, _Opt).
 
 code_exprn__set_regs(Regs, ExprnInfo0, ExprnInfo) :-
-	ExprnInfo0 = exprn_info(Varset, Vars, _Regs, Acqu, Opt),
-	ExprnInfo = exprn_info(Varset, Vars, Regs, Acqu, Opt).
+	ExprnInfo0 = exprn_info(Varset, Vars, _Regs, Acqu, SS, FV, Opt),
+	ExprnInfo = exprn_info(Varset, Vars, Regs, Acqu, SS, FV, Opt).
 
 code_exprn__get_acquired(Acqu, ExprnInfo, ExprnInfo) :-
-	ExprnInfo = exprn_info(_Varset, _Vars, _Regs, Acqu, _Opt).
+	ExprnInfo = exprn_info(_Varset, _Vars, _Regs, Acqu, _SS, _FV, _Opt).
 
 code_exprn__set_acquired(Acqu, ExprnInfo0, ExprnInfo) :-
-	ExprnInfo0 = exprn_info(Varset, Vars, Regs, _Acqu, Opt),
-	ExprnInfo = exprn_info(Varset, Vars, Regs, Acqu, Opt).
+	ExprnInfo0 = exprn_info(Varset, Vars, Regs, _Acqu, SS, FV, Opt),
+	ExprnInfo = exprn_info(Varset, Vars, Regs, Acqu, SS, FV, Opt).
+
+code_exprn__get_stack_slots(SS, ExprnInfo, ExprnInfo) :-
+	ExprnInfo = exprn_info(_Varset, _Vars, _Regs, _Acqu, SS, _FV, _Opt).
+
+code_exprn__get_follow_vars(FV, ExprnInfo, ExprnInfo) :-
+	ExprnInfo = exprn_info(_Varset, _Vars, _Regs, _Acqu, _SS, FV, _Opt).
+
+code_exprn__set_follow_vars(FV, ExprnInfo0, ExprnInfo) :-
+	ExprnInfo0 = exprn_info(Varset, Vars, Regs, Acqu, SS, _FV, Opt),
+	ExprnInfo = exprn_info(Varset, Vars, Regs, Acqu, SS, FV, Opt).
 
 code_exprn__get_options(Opt, ExprnInfo, ExprnInfo) :-
-	ExprnInfo = exprn_info(_Varset, _Vars, _Regs, _Acqu, Opt).
+	ExprnInfo = exprn_info(_Varset, _Vars, _Regs, _Acqu, _SS, _FV, Opt).
 
 %------------------------------------------------------------------------------%
 %------------------------------------------------------------------------------%
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.199
diff -u -r1.199 code_info.m
--- code_info.m	1997/04/25 09:14:27	1.199
+++ code_info.m	1997/05/12 01:19:16
@@ -74,10 +74,6 @@
 :- pred code_info__get_varset(varset, code_info, code_info).
 :- mode code_info__get_varset(out, in, out) is det.
 
-		% Get the hlds mapping from variables to stack slots
-:- pred code_info__get_stack_slots(stack_slots, code_info, code_info).
-:- mode code_info__get_stack_slots(out, in, out) is det.
-
 		% Get the id of the predicate we are generating code for.
 :- pred code_info__get_pred_id(pred_id, code_info, code_info).
 :- mode code_info__get_pred_id(out, in, out) is det.
@@ -126,16 +122,6 @@
 :- pred code_info__set_shapes(shape_table, code_info, code_info).
 :- mode code_info__set_shapes(in, in, out) is det.
 
-		% Get the table that contains advice about where
-		% variables should be put.
-:- pred code_info__get_follow_vars(follow_vars, code_info, code_info).
-:- mode code_info__get_follow_vars(out, in, out) is det.
-
-		% Set the table that contains advice about where
-		% variables should be put.
-:- pred code_info__set_follow_vars(follow_vars, code_info, code_info).
-:- mode code_info__set_follow_vars(in, in, out) is det.
-
 %---------------------------------------------------------------------------%
 
 :- implementation.
@@ -218,10 +204,6 @@
 			int,		% Counter for the local labels used
 					% by this procedure.
 			varset,		% The variables in this procedure.
-			stack_slots,	% The map giving the stack slot
-					% to be used for each variable
-					% that will ever need to be stored
-					% on the stack.
 			pred_id,	% The label of the current predicate.
 			proc_id,	% The label of the current procedure.
 			int,		% Counter for cells in this proc.
@@ -247,8 +229,6 @@
 					% The temp locations in use on the stack
 					% and what they contain (for gc).
 			shape_table,	% Table of shapes.
-			follow_vars,	% Advisory information about where
-					% each variable will be needed next.
 			set(var),	% Zombie variables; variables that have
 					% been killed but are protected by a
 					% resume point.
@@ -288,7 +268,8 @@
 	assoc_list__from_corresponding_lists(HeadVars, ArgInfos, Args),
 	code_info__build_input_arg_list(Args, ArgList),
 	globals__get_options(Globals, Options),
-	code_exprn__init_state(ArgList, Varset, Options, ExprnInfo),
+	code_exprn__init_state(ArgList, Varset, StackSlots, FollowVars,
+		Options, ExprnInfo),
 	stack__init(Continue),
 	stack__init(ResumeSetStack0),
 	set__init(AvailSlots0),
@@ -307,7 +288,6 @@
 		VarSlotCount,
 		0,
 		Varset,
-		StackSlots,
 		PredId,
 		ProcId,
 		CellCount,
@@ -323,7 +303,6 @@
 		Globals,
 		TempsInUse0,
 		Shapes,
-		FollowVars,
 		Zombies0,
 		ResumeSetStack0,
 		0
@@ -351,95 +330,87 @@
 
 code_info__get_var_slot_count(A, CI, CI) :-
 	CI = code_info(A, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
 code_info__get_label_count(B, CI, CI) :-
 	CI = code_info(_, B, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
 code_info__get_varset(C, CI, CI) :-
 	CI = code_info(_, _, C, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_stack_slots(D, CI, CI) :-
+code_info__get_pred_id(D, CI, CI) :-
 	CI = code_info(_, _, _, D, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_pred_id(E, CI, CI) :-
+code_info__get_proc_id(E, CI, CI) :-
 	CI = code_info(_, _, _, _, E, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_proc_id(F, CI, CI) :-
+code_info__get_cell_count(F, CI, CI) :-
 	CI = code_info(_, _, _, _, _, F, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_cell_count(G, CI, CI) :-
+code_info__get_exprn_info(G, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, G, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_exprn_info(H, CI, CI) :-
+code_info__get_proc_info(H, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, H, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_proc_info(I, CI, CI) :-
+code_info__get_succip_used(I, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, I, _, _, _, _, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_succip_used(J, CI, CI) :-
+code_info__get_fail_stack(J, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, _, J, _, _, _, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_fail_stack(K, CI, CI) :-
+code_info__get_module_info(K, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, _, _, K, _, _, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_module_info(L, CI, CI) :-
+code_info__get_forward_live_vars(L, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, _, _, _, L, _, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_forward_live_vars(M, CI, CI) :-
+code_info__get_instmap(M, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, _, _, _, _, M, _, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_instmap(N, CI, CI) :-
+code_info__get_avail_temp_slots(N, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, _, _, _, _, _, N, _, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_avail_temp_slots(O, CI, CI) :-
+code_info__get_max_temp_slot_count(O, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, _, _, _, _, _, _, O, _, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_max_temp_slot_count(P, CI, CI) :-
+code_info__get_globals(P, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, P, _, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_globals(Q, CI, CI) :-
+code_info__get_temps_in_use(Q, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, Q, _, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_temps_in_use(R, CI, CI) :-
+code_info__get_shapes(R, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, R, _,
-		_, _, _, _).
+		_, _).
 
-code_info__get_shapes(S, CI, CI) :-
+code_info__get_zombies(S, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, S,
-		_, _, _, _).
-
-code_info__get_follow_vars(T, CI, CI) :-
-	CI = code_info(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		T, _, _, _).
+		_, _).
 
-code_info__get_zombies(U, CI, CI) :-
+code_info__get_resume_point_stack(T, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, U, _, _).
+		T, _).
 
-code_info__get_resume_point_stack(V, CI, CI) :-
+code_info__get_commit_triple_count(U, CI, CI) :-
 	CI = code_info(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, V, _).
-
-code_info__get_commit_triple_count(W, CI, CI) :-
-	CI = code_info(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, _, W).
+		_, U).
 
 % :- type code_info	--->
 %		code_info(
@@ -450,41 +421,35 @@
 %	B		int,		% Counter for the local labels used
 %					% by this procedure.
 %	C		varset,		% The variables in this procedure.
-%	D		stack_slots,	% The map giving the stack slot
-%					% to be used for each variable
-%					% that will ever need to be stored
-%					% on the stack.
-%	E		pred_id,	% The label of the current predicate.
-%	F		proc_id,	% The label of the current procedure.
-%	G		int,		% Counter for cells in this proc.
-%	H		exprn_info,	% A map storing the information about
+%	D		pred_id,	% The label of the current predicate.
+%	E		proc_id,	% The label of the current procedure.
+%	F		int,		% Counter for cells in this proc.
+%	G		exprn_info,	% A map storing the information about
 %					% the status of each variable.
-%	I		proc_info,	% The proc_info for the this procedure.
-%	J		bool,		% do we need to store succip?
-%	K		fail_stack,	% The failure continuation stack
-%	L		module_info,	% The module_info structure - you just
+%	H		proc_info,	% The proc_info for the this procedure.
+%	I		bool,		% do we need to store succip?
+%	J		fail_stack,	% The failure continuation stack
+%	K		module_info,	% The module_info structure - you just
 %					% never know when you might need it.
 %					% It should be read-only.
-%	M		set(var),	% Variables that are forward live
+%	L		set(var),	% Variables that are forward live
 %					% after this goal
-%	N		instmap,	% insts of variables
-%	O		set(lval),	% Stack variables that have been used
+%	M		instmap,	% insts of variables
+%	N		set(lval),	% Stack variables that have been used
 %					% for temporaries and are now again
 %					% available for reuse.
-%	P		int,		% The maximum number of extra
+%	O		int,		% The maximum number of extra
 %					% temporary stackslots that have been
 %					% used during the procedure
-%	Q		globals,	% code generation options
-%	R		map(lval, lval_or_ticket),
+%	P		globals,	% code generation options
+%	Q		map(lval, lval_or_ticket),
 %					% The temp locations in use on the stack
 %					% and what they contain (for gc).
-%	S		shape_table,	% Table of shapes.
-%	T		follow_vars,	% Advisory information about where
-%					% each variable will be needed next.
-%	U		set(var),	% Zombie variables; variables that have
+%	R		shape_table,	% Table of shapes.
+%	S		set(var),	% Zombie variables; variables that have
 %					% been killed but are protected by a
 %					% resume point.
-%	V		stack(set(var)),
+%	T		stack(set(var)),
 %					% Each resumption point has an
 %					% associated set of variables
 %					% whose values may be needed on
@@ -496,7 +461,7 @@
 %					% When a variable included in the top
 %					% set becomes no longer forward live,
 %					% we must save its value to the stack.
-%	W		int,
+%	U		int,
 %					% A count of how many triples of
 %					% curfr, maxfr and redoip are live on
 %					% the det stack. These triples are
@@ -513,99 +478,92 @@
 % code_info__set_varset
 % code_info__set_pred_id
 % code_info__set_proc_id
-% code_info__set_stack_slots
 % code_info__set_module_info
 % code_info__set_globals
 
 code_info__set_label_count(B, CI0, CI) :-
 	CI0 = code_info(A, _, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W),
+		R, S, T, U),
+	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
+		R, S, T, U).
+
+code_info__set_cell_count(F, CI0, CI) :-
+	CI0 = code_info(A, B, C, D, E, _, G, H, I, J, K, L, M, N, O, P, Q,
+		R, S, T, U),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
-code_info__set_cell_count(G, CI0, CI) :-
+code_info__set_exprn_info(G, CI0, CI) :-
 	CI0 = code_info(A, B, C, D, E, F, _, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W),
+		R, S, T, U),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
-code_info__set_exprn_info(H, CI0, CI) :-
-	CI0 = code_info(A, B, C, D, E, F, G, _, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W),
+code_info__set_succip_used(I, CI0, CI) :-
+	CI0 = code_info(A, B, C, D, E, F, G, H, _, J, K, L, M, N, O, P, Q,
+		R, S, T, U),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
-code_info__set_succip_used(J, CI0, CI) :-
+code_info__set_fail_stack(J, CI0, CI) :-
 	CI0 = code_info(A, B, C, D, E, F, G, H, I, _, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W),
+		R, S, T, U),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
-code_info__set_fail_stack(K, CI0, CI) :-
-	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, _, L, M, N, O, P, Q,
-		R, S, T, U, V, W),
+code_info__set_forward_live_vars(L, CI0, CI) :-
+	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, K, _, M, N, O, P, Q,
+		R, S, T, U),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
-code_info__set_forward_live_vars(M, CI0, CI) :-
+code_info__set_instmap(M, CI0, CI) :-
 	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, K, L, _, N, O, P, Q,
-		R, S, T, U, V, W),
+		R, S, T, U),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
-code_info__set_instmap(N, CI0, CI) :-
+code_info__set_avail_temp_slots(N, CI0, CI) :-
 	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, _, O, P, Q,
-		R, S, T, U, V, W),
+		R, S, T, U),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
-code_info__set_avail_temp_slots(O, CI0, CI) :-
+code_info__set_max_temp_slot_count(O, CI0, CI) :-
 	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, _, P, Q,
-		R, S, T, U, V, W),
+		R, S, T, U),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
-code_info__set_max_temp_slot_count(P, CI0, CI) :-
-	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, _, Q,
-		R, S, T, U, V, W),
-	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
-
-code_info__set_temps_in_use(R, CI0, CI) :-
-	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		_, S, T, U, V, W),
-	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
-
-code_info__set_shapes(S, CI0, CI) :-
-	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, _, T, U, V, W),
+code_info__set_temps_in_use(Q, CI0, CI) :-
+	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, _,
+		R, S, T, U),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
-code_info__set_follow_vars(T, CI0, CI) :-
+code_info__set_shapes(R, CI0, CI) :-
 	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, _, U, V, W),
+		_, S, T, U),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
-code_info__set_zombies(U, CI0, CI) :-
+code_info__set_zombies(S, CI0, CI) :-
 	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, _, V, W),
+		R, _, T, U),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
-code_info__set_resume_point_stack(V, CI0, CI) :-
+code_info__set_resume_point_stack(T, CI0, CI) :-
 	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, _, W),
+		R, S, _, U),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
-code_info__set_commit_triple_count(W, CI0, CI) :-
+code_info__set_commit_triple_count(U, CI0, CI) :-
 	CI0 = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, _),
+		R, S, T, _),
 	CI = code_info(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
-		R, S, T, U, V, W).
+		R, S, T, U).
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
@@ -614,6 +572,20 @@
 
 :- interface.
 
+		% Get the hlds mapping from variables to stack slots
+:- pred code_info__get_stack_slots(stack_slots, code_info, code_info).
+:- mode code_info__get_stack_slots(out, in, out) is det.
+
+		% Get the table that contains advice about where
+		% variables should be put.
+:- pred code_info__get_follow_vars(follow_vars, code_info, code_info).
+:- mode code_info__get_follow_vars(out, in, out) is det.
+
+		% Set the table that contains advice about where
+		% variables should be put.
+:- pred code_info__set_follow_vars(follow_vars, code_info, code_info).
+:- mode code_info__set_follow_vars(in, in, out) is det.
+
 	% code_info__pre_goal_update(GoalInfo, Atomic, OldCodeInfo, NewCodeInfo)
 	% updates OldCodeInfo to produce NewCodeInfo with the changes
 	% specified by GoalInfo.
@@ -627,7 +599,6 @@
 :- mode code_info__post_goal_update(in, in, out) is det.
 
 	% Find out the type of the given variable.
-
 :- pred code_info__variable_type(var, type, code_info, code_info).
 :- mode code_info__variable_type(in, out, in, out) is det.
 
@@ -637,14 +608,12 @@
 
 	% Given a list of type variables, find the lvals where the
 	% corresponding type_infos are being stored.
-
 :- pred code_info__find_type_infos(list(var), list(lval), code_info, code_info).
 :- mode code_info__find_type_infos(in, out, in, out) is det.
 
 	% Given a constructor id, and a variable (so that we can work out the
 	% type of the constructor), determine correct tag (representation)
 	% of that constructor.
-
 :- pred code_info__cons_id_to_tag(var, cons_id, cons_tag, code_info, code_info).
 :- mode code_info__cons_id_to_tag(in, in, out, in, out) is det.
 
@@ -661,7 +630,6 @@
 :- mode code_info__get_pred_proc_arginfo(in, in, out, in, out) is det.
 
 	% Pop the failure continuation stack.
-
 :- pred code_info__pop_failure_cont(code_info, code_info).
 :- mode code_info__pop_failure_cont(in, out) is det.
 
@@ -738,6 +706,21 @@
 
 %-----------------------------------------------------------------------------%
 
+code_info__get_stack_slots(StackSlots, CI, CI) :-
+	code_info__get_exprn_info(ExprnInfo, CI, _),
+	code_exprn__get_stack_slots(StackSlots, ExprnInfo, _).
+
+code_info__get_follow_vars(FollowVars, CI, CI) :-
+	code_info__get_exprn_info(ExprnInfo, CI, _),
+	code_exprn__get_follow_vars(FollowVars, ExprnInfo, _).
+
+code_info__set_follow_vars(FollowVars, CI0, CI) :-
+	code_info__get_exprn_info(ExprnInfo0, CI0, _),
+	code_exprn__set_follow_vars(FollowVars, ExprnInfo0, ExprnInfo),
+	code_info__set_exprn_info(ExprnInfo, CI0, CI).
+
+%-----------------------------------------------------------------------------%
+
 	% Update the code info structure to be consistent
 	% immediately prior to generating a goal
 code_info__pre_goal_update(GoalInfo, Atomic) -->
@@ -1256,7 +1239,6 @@
 	{ map__init(Map) }.
 code_info__produce_resume_vars([V | Vs], Map, Code) -->
 	code_info__produce_resume_vars(Vs, Map0, Code0),
-		% XXX should use follow_vars to decide whether to put into reg
 	code_info__produce_variable_in_reg_or_stack(V, Code1, Rval),
 	{ set__singleton_set(Rvals, Rval) },
 	{ map__set(Map0, V, Rvals, Map) },
@@ -1533,10 +1515,8 @@
 code_info__set_var_locations(Map) -->
 	{ map__to_assoc_list(Map, List0) },
 	{ code_info__flatten_varlval_list(List0, List) },
-	code_info__get_varset(Varset),
-	code_info__get_globals(Globals),
-	{ globals__get_options(Globals, Options) },
-	{ code_exprn__init_state(List, Varset, Options, Exprn) },
+	code_info__get_exprn_info(Exprn0),
+	{ code_exprn__reinit_state(List, Exprn0, Exprn) },
 	code_info__set_exprn_info(Exprn).
 
 :- pred code_info__flatten_varlval_list(assoc_list(var, set(rval)),
@@ -2507,10 +2487,8 @@
 code_info__remake_with_store_map(StoreMap) -->
 	{ map__to_assoc_list(StoreMap, VarLvals) },
 	{ code_info__fixup_lvallist(VarLvals, VarRvals) },
-	code_info__get_varset(Varset),
-	code_info__get_globals(Globals),
-	{ globals__get_options(Globals, Options) },
-	{ code_exprn__init_state(VarRvals, Varset, Options, Exprn) },
+	code_info__get_exprn_info(Exprn0),
+	{ code_exprn__reinit_state(VarRvals, Exprn0, Exprn) },
 	code_info__set_exprn_info(Exprn).
 
 :- pred code_info__fixup_lvallist(assoc_list(var, lval), assoc_list(var, rval)).
cvs diff: Diffing compiler/notes
cvs diff: Diffing doc
cvs diff: Diffing library
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing profiler
cvs diff: Diffing runtime
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/diff
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/general
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trial
cvs diff: Diffing util



More information about the developers mailing list