[m-rev.] for review: stack slot optimization, part 6

Zoltan Somogyi zs at cs.mu.OZ.AU
Sat Mar 9 20:24:45 AEDT 2002


Index: compiler/store_alloc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/store_alloc.m,v
retrieving revision 1.77
diff -u -b -r1.77 store_alloc.m
--- compiler/store_alloc.m	7 Apr 2001 14:04:58 -0000	1.77
+++ compiler/store_alloc.m	19 Feb 2002 13:41:03 -0000
@@ -28,34 +28,33 @@
 
 :- import_module hlds_module, hlds_pred.
 
-:- pred store_alloc_in_proc(proc_info, pred_id, module_info, proc_info).
-:- mode store_alloc_in_proc(in, in, in, out) is det.
+:- type store_map_run_type
+	--->	final_allocation
+	;	for_stack_opt.
+
+:- pred allocate_store_maps(store_map_run_type::in, proc_info::in, pred_id::in,
+	module_info::in, proc_info::out) is det.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
 :- implementation.
 
-:- import_module follow_vars, liveness, hlds_goal, llds, prog_data.
-:- import_module options, globals, trace_params, trace.
+:- import_module follow_vars, liveness, hlds_goal, hlds_llds, llds, prog_data.
+:- import_module options, globals, arg_info, trace_params, trace.
 :- import_module goal_util, mode_util, instmap.
 :- import_module list, map, set, std_util, assoc_list.
 :- import_module bool, int, require.
 
-:- type stack_slot_info
-	--->	stack_slot_info(
-			bool,		% was follow_vars run?
-			int,		% the number of real r regs
-			stack_slots	% maps each var to its stack slot
-					% (if it has one)
-		).
-
 %-----------------------------------------------------------------------------%
 
-store_alloc_in_proc(ProcInfo0, PredId, ModuleInfo, ProcInfo) :-
+allocate_store_maps(RunType, ProcInfo0, PredId, ModuleInfo, ProcInfo) :-
 	module_info_globals(ModuleInfo, Globals),
 	globals__lookup_bool_option(Globals, follow_vars, ApplyFollowVars),
-	( ApplyFollowVars = yes ->
+	(
+		RunType = final_allocation,
+		ApplyFollowVars = yes
+	->
 		proc_info_goal(ProcInfo0, Goal0),
 
 		find_final_follow_vars(ProcInfo0,
@@ -79,22 +78,47 @@
 	;
 		set__init(ResumeVars0)
 	),
+	arg_info__build_input_arg_list(ProcInfo0, InputArgLvals),
+	LastLocns0 = initial_last_locns(InputArgLvals),
 	globals__lookup_int_option(Globals, num_real_r_regs, NumRealRRegs),
 	proc_info_stack_slots(ProcInfo0, StackSlots),
-	StackSlotsInfo = stack_slot_info(ApplyFollowVars, NumRealRRegs,
-		StackSlots),
-	store_alloc_in_goal(Goal2, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotsInfo, Goal, _),
+	StoreAllocInfo = store_alloc_info(ModuleInfo, ApplyFollowVars,
+		NumRealRRegs, StackSlots),
+	store_alloc_in_goal(Goal2, Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, Goal, _, _),
 	proc_info_set_goal(ProcInfo0, Goal, ProcInfo).
 
+:- func initial_last_locns(assoc_list(prog_var, lval)) = last_locns.
+
+initial_last_locns([]) = map__init.
+initial_last_locns([Var - Lval | VarLvals]) =
+	map__det_insert(initial_last_locns(VarLvals), Var,
+		set__make_singleton_set(Lval)).
+
 %-----------------------------------------------------------------------------%
 
-:- pred store_alloc_in_goal(hlds_goal, liveness_info, set(prog_var),
-		module_info, stack_slot_info, hlds_goal, liveness_info).
-:- mode store_alloc_in_goal(in, in, in, in, in, out, out) is det.
+:- type store_alloc_info
+	--->	store_alloc_info(
+			module_info		:: module_info,
+			done_follow_vars	:: bool,
+						% was follow_vars run?
+			num_real_r_regs		:: int,
+						% the number of real r regs
+			stack_slots		:: stack_slots
+						% maps each var to its stack
+						% slot (if it has one)
+		).
+
+:- type where_stored	== set(lval).	% These lvals may contain var() rvals.
+
+:- type last_locns	== map(prog_var, where_stored).
+
+:- pred store_alloc_in_goal(hlds_goal::in, liveness_info::in, set(prog_var)::in,
+	last_locns::in, store_alloc_info::in, hlds_goal::out,
+	liveness_info::out, last_locns::out) is det.
 
-store_alloc_in_goal(Goal0 - GoalInfo0, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Goal - GoalInfo0, Liveness) :-
+store_alloc_in_goal(Goal0 - GoalInfo0, Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, Goal - GoalInfo, Liveness, LastLocns) :-
 	% note: we must be careful to apply deaths before births
 	goal_info_get_pre_deaths(GoalInfo0, PreDeaths),
 	goal_info_get_pre_births(GoalInfo0, PreBirths),
@@ -103,8 +127,8 @@
 
 	set__difference(Liveness0,  PreDeaths, Liveness1),
 	set__union(Liveness1, PreBirths, Liveness2),
-	store_alloc_in_goal_2(Goal0, Liveness2, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Goal1, Liveness3),
+	store_alloc_in_goal_2(Goal0, Liveness2, ResumeVars0, LastLocns0,
+		PostDeaths, StoreAllocInfo, Goal, Liveness3, LastLocns),
 	set__difference(Liveness3, PostDeaths, Liveness4),
 	% If any variables magically become live in the PostBirths,
 	% then they have to mundanely become live in a parallel goal,
@@ -114,154 +138,154 @@
 	% should not be included in the store map.
 	set__union(Liveness4, PostBirths, Liveness),
 	(
-		Goal1 = switch(Var, CanFail, Cases, AdvisoryStoreMap)
-	->
-		set__union(Liveness4, ResumeVars0, MappedSet),
-		set__to_sorted_list(MappedSet, MappedVars),
-		store_alloc_allocate_storage(MappedVars, AdvisoryStoreMap,
-			StackSlotInfo, StoreMap),
-		Goal = switch(Var, CanFail, Cases, StoreMap)
-	;
-		Goal1 = if_then_else(Vars, Cond, Then, Else, AdvisoryStoreMap)
+		( Goal = switch(_Var, _CanFail, _Cases)
+		; Goal = if_then_else(_Vars, _Cond, _Then, _Else)
+		; Goal = disj(_Disjuncts)
+		)
 	->
 		set__union(Liveness4, ResumeVars0, MappedSet),
 		set__to_sorted_list(MappedSet, MappedVars),
-		store_alloc_allocate_storage(MappedVars, AdvisoryStoreMap,
-			StackSlotInfo, StoreMap),
-		Goal = if_then_else(Vars, Cond, Then, Else, StoreMap)
+		( goal_info_maybe_get_store_map(GoalInfo0, StoreMapPrime) ->
+			AdvisoryStoreMap = StoreMapPrime
 	;
-		Goal1 = disj(Disjuncts, AdvisoryStoreMap)
-	->
-		set__union(Liveness4, ResumeVars0, MappedSet),
-		set__to_sorted_list(MappedSet, MappedVars),
+			AdvisoryStoreMap = map__init
+		),
 		store_alloc_allocate_storage(MappedVars, AdvisoryStoreMap,
-			StackSlotInfo, StoreMap),
-		Goal = disj(Disjuncts, StoreMap)
+			StoreAllocInfo, StoreMap),
+		goal_info_set_store_map(GoalInfo0, StoreMap, GoalInfo)
 	;
-		Goal = Goal1
+		GoalInfo = GoalInfo0
 	).
 
 %-----------------------------------------------------------------------------%
 
 	% Here we process each of the different sorts of goals.
 
-:- pred store_alloc_in_goal_2(hlds_goal_expr, liveness_info,
-		set(prog_var), module_info, stack_slot_info, hlds_goal_expr,
-		liveness_info).
-:- mode store_alloc_in_goal_2(in, in, in, in, in, out, out) is det.
-
-store_alloc_in_goal_2(conj(Goals0), Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, conj(Goals), Liveness) :-
-	store_alloc_in_conj(Goals0, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Goals, Liveness).
-
-store_alloc_in_goal_2(par_conj(Goals0, SM), Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, par_conj(Goals, SM), Liveness) :-
-	store_alloc_in_par_conj(Goals0, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Goals, Liveness).
-
-store_alloc_in_goal_2(disj(Goals0, FV), Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, disj(Goals, FV), Liveness) :-
-	store_alloc_in_disj(Goals0, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Goals, Liveness).
+:- pred store_alloc_in_goal_2(hlds_goal_expr::in, liveness_info::in,
+	set(prog_var)::in, last_locns::in, set(prog_var)::in,
+	store_alloc_info::in, hlds_goal_expr::out, liveness_info::out,
+	last_locns::out) is det.
+
+store_alloc_in_goal_2(conj(Goals0), Liveness0, ResumeVars0, LastLocns0,
+		_, StoreAllocInfo, conj(Goals), Liveness, LastLocns) :-
+	store_alloc_in_conj(Goals0, Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, Goals, Liveness, LastLocns).
+
+store_alloc_in_goal_2(par_conj(Goals0), Liveness0, ResumeVars0, LastLocns0,
+		_, StoreAllocInfo, par_conj(Goals), Liveness, LastLocns) :-
+	store_alloc_in_par_conj(Goals0, Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, Goals, Liveness, LastLocns).
+
+store_alloc_in_goal_2(disj(Goals0), Liveness0, ResumeVars0, LastLocns0,
+		_, StoreAllocInfo, disj(Goals), Liveness, LastLocns) :-
+	store_alloc_in_disj(Goals0, Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, Goals, Liveness, LastLocnsList),
+	merge_last_locations(LastLocnsList, LastLocns).
 
-store_alloc_in_goal_2(not(Goal0), Liveness0, _ResumeVars0, ModuleInfo,
-		StackSlotInfo, not(Goal), Liveness) :-
+store_alloc_in_goal_2(not(Goal0), Liveness0, _ResumeVars0, LastLocns0,
+		_, StoreAllocInfo, not(Goal), Liveness, LastLocns0) :-
 	Goal0 = _ - GoalInfo0,
 	goal_info_get_resume_point(GoalInfo0, ResumeNot),
 	goal_info_resume_vars_and_loc(ResumeNot, ResumeNotVars, _),
-	store_alloc_in_goal(Goal0, Liveness0, ResumeNotVars, ModuleInfo,
-		StackSlotInfo, Goal, Liveness).
+	store_alloc_in_goal(Goal0, Liveness0, ResumeNotVars, LastLocns0,
+		StoreAllocInfo, Goal, Liveness, _).
 
-store_alloc_in_goal_2(switch(Var, Det, Cases0, FV), Liveness0, ResumeVars0,
-		ModuleInfo, StackSlotInfo,
-		switch(Var, Det, Cases, FV), Liveness) :-
-	store_alloc_in_cases(Cases0, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Cases, Liveness).
-
-store_alloc_in_goal_2(if_then_else(Vars, Cond0, Then0, Else0, FV),
-		Liveness0, ResumeVars0, ModuleInfo, StackSlotInfo,
-		if_then_else(Vars, Cond, Then, Else, FV), Liveness) :-
+store_alloc_in_goal_2(switch(Var, Det, Cases0), Liveness0, ResumeVars0,
+		LastLocns0, _, StoreAllocInfo,
+		switch(Var, Det, Cases), Liveness, LastLocns) :-
+	store_alloc_in_cases(Cases0, Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, Cases, Liveness, LastLocnsList),
+	merge_last_locations(LastLocnsList, LastLocns).
+
+store_alloc_in_goal_2(if_then_else(Vars, Cond0, Then0, Else0),
+		Liveness0, ResumeVars0, LastLocns0, _, StoreAllocInfo,
+		if_then_else(Vars, Cond, Then, Else), Liveness, LastLocns) :-
 	Cond0 = _ - CondGoalInfo0,
 	goal_info_get_resume_point(CondGoalInfo0, ResumeCond),
 	goal_info_resume_vars_and_loc(ResumeCond, ResumeCondVars, _),
-	store_alloc_in_goal(Cond0, Liveness0, ResumeCondVars, ModuleInfo,
-		StackSlotInfo, Cond, Liveness1),
-	store_alloc_in_goal(Then0, Liveness1, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Then, Liveness),
-	store_alloc_in_goal(Else0, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Else, _Liveness2).
+	store_alloc_in_goal(Cond0, Liveness0, ResumeCondVars, LastLocns0,
+		StoreAllocInfo, Cond, Liveness1, LastLocnsCond),
+	store_alloc_in_goal(Then0, Liveness1, ResumeVars0, LastLocnsCond,
+		StoreAllocInfo, Then, Liveness, LastLocnsThen),
+	store_alloc_in_goal(Else0, Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, Else, _Liveness2, LastLocnsElse),
+	merge_last_locations([LastLocnsThen, LastLocnsElse], LastLocns).
 
 store_alloc_in_goal_2(some(Vars, CanRemove, Goal0), Liveness0, ResumeVars0,
-		ModuleInfo,
-		StackSlotInfo, some(Vars, CanRemove, Goal), Liveness) :-
-	store_alloc_in_goal(Goal0, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Goal, Liveness).
+		LastLocns0, _, StoreAllocInfo,
+		some(Vars, CanRemove, Goal), Liveness, LastLocns) :-
+	store_alloc_in_goal(Goal0, Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, Goal, Liveness, LastLocns).
 
-store_alloc_in_goal_2(generic_call(A, B, C, D), Liveness, _, _,
-		_, generic_call(A, B, C, D), Liveness).
+store_alloc_in_goal_2(generic_call(A, B, C, D), Liveness, _, LastLocns,
+		_, _, generic_call(A, B, C, D), Liveness, LastLocns).
 
-store_alloc_in_goal_2(call(A, B, C, D, E, F), Liveness, _, _,
-		_, call(A, B, C, D, E, F), Liveness).
+store_alloc_in_goal_2(call(A, B, C, D, E, F), Liveness, _, LastLocns,
+		_, _, call(A, B, C, D, E, F), Liveness, LastLocns).
 
-store_alloc_in_goal_2(unify(A,B,C,D,E), Liveness, _, _,
-		_, unify(A,B,C,D,E), Liveness).
+store_alloc_in_goal_2(unify(A,B,C,D,E), Liveness, _, LastLocns,
+		_, _, unify(A,B,C,D,E), Liveness, LastLocns).
 
-store_alloc_in_goal_2(foreign_proc(A, B, C, D, E, F, G), Liveness,
-		_, _, _, foreign_proc(A, B, C, D, E, F, G), Liveness).
+store_alloc_in_goal_2(foreign_proc(A, B, C, D, E, F, G), Liveness, _,
+		LastLocns, _, _, foreign_proc(A, B, C, D, E, F, G),
+		Liveness, LastLocns).
 
-store_alloc_in_goal_2(shorthand(_), _, _, _, _, _, _) :-
+store_alloc_in_goal_2(shorthand(_), _, _, _, _, _, _, _, _) :-
 	% these should have been expanded out by now
 	error("store_alloc_in_goal_2: unexpected shorthand").
 
 %-----------------------------------------------------------------------------%
 
-:- pred store_alloc_in_conj(list(hlds_goal), liveness_info, set(prog_var),
-	module_info, stack_slot_info, list(hlds_goal), liveness_info).
-:- mode store_alloc_in_conj(in, in, in, in, in, out, out) is det.
-
-store_alloc_in_conj([], Liveness, _, _, _, [], Liveness).
-store_alloc_in_conj([Goal0 | Goals0], Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, [Goal | Goals], Liveness) :-
+:- pred store_alloc_in_conj(list(hlds_goal)::in, liveness_info::in,
+	set(prog_var)::in, last_locns::in, store_alloc_info::in,
+	list(hlds_goal)::out, liveness_info::out, last_locns::out) is det.
+
+store_alloc_in_conj([], Liveness, _, LastLocns, _, [], Liveness, LastLocns).
+store_alloc_in_conj([Goal0 | Goals0], Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, [Goal | Goals], Liveness, LastLocns) :-
 	(
 			% XXX should be threading the instmap
 		Goal0 = _ - GoalInfo,
 		goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
 		instmap_delta_is_unreachable(InstMapDelta)
 	->
-		store_alloc_in_goal(Goal0, Liveness0, ResumeVars0, ModuleInfo,
-			StackSlotInfo, Goal, Liveness),
+		store_alloc_in_goal(Goal0, Liveness0, ResumeVars0, LastLocns0,
+			StoreAllocInfo, Goal, Liveness, LastLocns),
 		Goals = Goals0
 	;
-		store_alloc_in_goal(Goal0, Liveness0, ResumeVars0, ModuleInfo,
-			StackSlotInfo, Goal, Liveness1),
-		store_alloc_in_conj(Goals0, Liveness1, ResumeVars0, ModuleInfo,
-			StackSlotInfo, Goals, Liveness)
+		store_alloc_in_goal(Goal0, Liveness0, ResumeVars0, LastLocns0,
+			StoreAllocInfo, Goal, Liveness1, LastLocns1),
+		store_alloc_in_conj(Goals0, Liveness1, ResumeVars0, LastLocns1,
+			StoreAllocInfo, Goals, Liveness, LastLocns)
 	).
 
 %-----------------------------------------------------------------------------%
 
-:- pred store_alloc_in_par_conj(list(hlds_goal), liveness_info, set(prog_var),
-	module_info, stack_slot_info, list(hlds_goal), liveness_info).
-:- mode store_alloc_in_par_conj(in, in, in, in, in, out, out) is det.
-
-store_alloc_in_par_conj([], Liveness, _, _, _, [], Liveness).
-store_alloc_in_par_conj([Goal0 | Goals0], Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, [Goal | Goals], Liveness) :-
-	store_alloc_in_goal(Goal0, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Goal, Liveness),
-	store_alloc_in_par_conj(Goals0, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Goals, _Liveness1).
+:- pred store_alloc_in_par_conj(list(hlds_goal)::in, liveness_info::in,
+	set(prog_var)::in, last_locns::in, store_alloc_info::in,
+	list(hlds_goal)::out, liveness_info::out, last_locns::out) is det.
+
+store_alloc_in_par_conj([], Liveness, _, LastLocns, _,
+		[], Liveness, LastLocns).
+store_alloc_in_par_conj([Goal0 | Goals0], Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, [Goal | Goals], Liveness, LastLocns) :-
+	% XXX ignoring _Liveness1 looks fishy
+	store_alloc_in_goal(Goal0, Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, Goal, Liveness, LastLocns1),
+	store_alloc_in_par_conj(Goals0, Liveness0, ResumeVars0, LastLocns1,
+		StoreAllocInfo, Goals, _Liveness1, LastLocns).
 
 %-----------------------------------------------------------------------------%
 
-:- pred store_alloc_in_disj(list(hlds_goal), liveness_info, set(prog_var),
-	module_info, stack_slot_info, list(hlds_goal), liveness_info).
-:- mode store_alloc_in_disj(in, in, in, in, in, out, out) is det.
-
-store_alloc_in_disj([], Liveness, _, _, _, [], Liveness).
-store_alloc_in_disj([Goal0 | Goals0], Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, [Goal | Goals], Liveness) :-
+:- pred store_alloc_in_disj(list(hlds_goal)::in, liveness_info::in,
+	set(prog_var)::in, last_locns::in, store_alloc_info::in,
+	list(hlds_goal)::out, liveness_info::out, list(last_locns)::out)
+	is det.
+
+store_alloc_in_disj([], Liveness, _, _, _, [], Liveness, []).
+store_alloc_in_disj([Goal0 | Goals0], Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, [Goal | Goals], Liveness,
+		[LastLocnsGoal | LastLocnsDisj]) :-
 	Goal0 = _ - GoalInfo0,
 	goal_info_get_resume_point(GoalInfo0, ResumeGoal),
 	(
@@ -270,25 +294,37 @@
 	;
 		ResumeGoal = resume_point(ResumeGoalVars, _)
 	),
-	store_alloc_in_goal(Goal0, Liveness0, ResumeGoalVars, ModuleInfo,
-		StackSlotInfo, Goal, Liveness),
-	store_alloc_in_disj(Goals0, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Goals, _Liveness1).
+	store_alloc_in_goal(Goal0, Liveness0, ResumeGoalVars, LastLocns0,
+		StoreAllocInfo, Goal, Liveness, LastLocnsGoal),
+	store_alloc_in_disj(Goals0, Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, Goals, _Liveness1, LastLocnsDisj).
 
 %-----------------------------------------------------------------------------%
 
-:- pred store_alloc_in_cases(list(case), liveness_info, set(prog_var),
-	module_info, stack_slot_info, list(case), liveness_info).
-:- mode store_alloc_in_cases(in, in, in, in, in, out, out) is det.
+:- pred store_alloc_in_cases(list(case)::in, liveness_info::in,
+	set(prog_var)::in, last_locns::in, store_alloc_info::in,
+	list(case)::out, liveness_info::out, list(last_locns)::out) is det.
 
-store_alloc_in_cases([], Liveness, _, _, _, [], Liveness).
+store_alloc_in_cases([], Liveness, _, _, _, [], Liveness, []).
 store_alloc_in_cases([case(Cons, Goal0) | Goals0], Liveness0, ResumeVars0,
-		ModuleInfo, StackSlotInfo,
-		[case(Cons, Goal) | Goals], Liveness) :-
-	store_alloc_in_goal(Goal0, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Goal, Liveness),
-	store_alloc_in_cases(Goals0, Liveness0, ResumeVars0, ModuleInfo,
-		StackSlotInfo, Goals, _Liveness1).
+		LastLocns0, StoreAllocInfo, [case(Cons, Goal) | Goals],
+		Liveness, [LastLocnsGoal | LastLocnsCases]) :-
+	store_alloc_in_goal(Goal0, Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, Goal, Liveness, LastLocnsGoal),
+	store_alloc_in_cases(Goals0, Liveness0, ResumeVars0, LastLocns0,
+		StoreAllocInfo, Goals, _Liveness1, LastLocnsCases).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- pred merge_last_locations(list(last_locns)::in, last_locns::out) is det.
+
+merge_last_locations(LastLocnsList, LastLocns) :-
+	( LastLocnsList = [LastLocnsPrime | _] ->
+		LastLocns = LastLocnsPrime
+	;
+		LastLocns = map__init
+	).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -306,11 +342,10 @@
 	% generate a store map that maps every live variable to its own
 	% real location.
 
-:- pred store_alloc_allocate_storage(list(prog_var), store_map,
-		stack_slot_info, store_map).
-:- mode store_alloc_allocate_storage(in, in, in, out) is det.
+:- pred store_alloc_allocate_storage(list(prog_var)::in, store_map::in,
+	store_alloc_info::in, store_map::out) is det.
 
-store_alloc_allocate_storage(LiveVars, FollowVars, StackSlotInfo, StoreMap) :-
+store_alloc_allocate_storage(LiveVars, FollowVars, StoreAllocInfo, StoreMap) :-
 
 	% This addresses point 1
 	map__keys(FollowVars, FollowKeys),
@@ -323,7 +358,7 @@
 		SeenLvals0, SeenLvals, StoreMap0, StoreMap1),
 
 	% This addresses point 2
-	store_alloc_allocate_extras(LiveVars, N, SeenLvals, StackSlotInfo,
+	store_alloc_allocate_extras(LiveVars, N, SeenLvals, StoreAllocInfo,
 		StoreMap1, StoreMap).
 
 :- pred store_alloc_remove_nonlive(list(prog_var), list(prog_var),
@@ -367,11 +402,11 @@
 		SeenLvals1, SeenLvals, StoreMap1, StoreMap).
 
 :- pred store_alloc_allocate_extras(list(prog_var), int, set(lval),
-		stack_slot_info, store_map, store_map).
+		store_alloc_info, store_map, store_map).
 :- mode store_alloc_allocate_extras(in, in, in, in, in, out) is det.
 
 store_alloc_allocate_extras([], _, _, _, StoreMap, StoreMap).
-store_alloc_allocate_extras([Var | Vars], N0, SeenLvals0, StackSlotInfo,
+store_alloc_allocate_extras([Var | Vars], N0, SeenLvals0, StoreAllocInfo,
 		StoreMap0, StoreMap) :-
 	(
 		map__contains(StoreMap0, Var)
@@ -383,7 +418,7 @@
 	;
 		% We have not yet allocated a slot for this variable,
 		% which means it is not in the follow vars (if any).
-		StackSlotInfo = stack_slot_info(FollowVars, NumRealRRegs,
+		StoreAllocInfo = store_alloc_info(_, FollowVars, NumRealRRegs,
 			StackSlots),
 		(
 			map__search(StackSlots, Var, StackSlot),
@@ -412,7 +447,7 @@
 		map__det_insert(StoreMap0, Var, Locn, StoreMap1),
 		set__insert(SeenLvals0, Locn, SeenLvals1)
 	),
-	store_alloc_allocate_extras(Vars, N1, SeenLvals1, StackSlotInfo,
+	store_alloc_allocate_extras(Vars, N1, SeenLvals1, StoreAllocInfo,
 		StoreMap1, StoreMap).
 
 %-----------------------------------------------------------------------------%
Index: compiler/stratify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stratify.m,v
retrieving revision 1.25
diff -u -b -r1.25 stratify.m
--- compiler/stratify.m	7 Apr 2001 14:04:59 -0000	1.25
+++ compiler/stratify.m	16 Jul 2001 17:35:46 -0000
@@ -149,20 +149,20 @@
 		ThisPredProcId, Error, Module0, Module) -->
 	first_order_check_goal_list(Goals, Negated, WholeScc, ThisPredProcId,
 		Error, Module0, Module).
-first_order_check_goal(par_conj(Goals, _SM), _GoalInfo, Negated, WholeScc, 
+first_order_check_goal(par_conj(Goals), _GoalInfo, Negated, WholeScc, 
 		ThisPredProcId, Error, Module0, Module) -->
 	first_order_check_goal_list(Goals, Negated, WholeScc, ThisPredProcId,
 		Error, Module0, Module).
-first_order_check_goal(disj(Goals, _Follow), _GoalInfo, Negated, 
+first_order_check_goal(disj(Goals), _GoalInfo, Negated, 
 		WholeScc, ThisPredProcId, Error, Module0, Module) -->
 	first_order_check_goal_list(Goals, Negated, WholeScc, ThisPredProcId,
 		Error, Module0, Module).
-first_order_check_goal(switch(_Var, _Fail, Cases, _Follow), _GoalInfo,
+first_order_check_goal(switch(_Var, _Fail, Cases), _GoalInfo,
 		Negated, WholeScc, ThisPredProcId, Error, Module0, Module) -->
 	first_order_check_case_list(Cases, Negated, WholeScc, ThisPredProcId,
 		Error, Module0, Module).
 first_order_check_goal(if_then_else(_Vars, Cond - CInfo, Then - TInfo, 
-	Else - EInfo, _Follow), _GoalInfo, Negated, WholeScc, ThisPredProcId,
+		Else - EInfo), _GoalInfo, Negated, WholeScc, ThisPredProcId,
 		Error, Module0, Module) -->
 	first_order_check_goal(Cond, CInfo, yes, WholeScc, ThisPredProcId,
 		Error, Module0, Module1),
@@ -304,21 +304,21 @@
 		ThisPredProcId, HighOrderLoops, Error, Module0, Module) -->
 	higher_order_check_goal_list(Goals, Negated, WholeScc, ThisPredProcId,
 		HighOrderLoops, Error, Module0, Module).
-higher_order_check_goal(par_conj(Goals, _), _GoalInfo, Negated, WholeScc, 
+higher_order_check_goal(par_conj(Goals), _GoalInfo, Negated, WholeScc, 
 		ThisPredProcId, HighOrderLoops, Error, Module0, Module) -->
 	higher_order_check_goal_list(Goals, Negated, WholeScc, ThisPredProcId,
 		HighOrderLoops, Error, Module0, Module).
-higher_order_check_goal(disj(Goals, _Follow), _GoalInfo, Negated, WholeScc, 
+higher_order_check_goal(disj(Goals), _GoalInfo, Negated, WholeScc, 
 		ThisPredProcId, HighOrderLoops, Error, Module0, Module) -->
 	higher_order_check_goal_list(Goals, Negated, WholeScc, ThisPredProcId,
 		HighOrderLoops, Error, Module0, Module).
-higher_order_check_goal(switch(_Var, _Fail, Cases, _Follow), _GoalInfo,
+higher_order_check_goal(switch(_Var, _Fail, Cases), _GoalInfo,
 		Negated, WholeScc, ThisPredProcId, HighOrderLoops, 
 		Error, Module0, Module) -->
 	higher_order_check_case_list(Cases, Negated, WholeScc, ThisPredProcId,
 		HighOrderLoops, Error, Module0, Module).
 higher_order_check_goal(if_then_else(_Vars, Cond - CInfo, Then - TInfo, 
-		Else - EInfo, _Follow), _GoalInfo, Negated, WholeScc, 
+		Else - EInfo), _GoalInfo, Negated, WholeScc, 
 		ThisPredProcId, HighOrderLoops, Error, Module0, Module) -->
 	higher_order_check_goal(Cond, CInfo, yes, WholeScc, ThisPredProcId,
 		HighOrderLoops, Error, Module0, Module1),
@@ -799,17 +799,16 @@
 
 check_goal1(conj(Goals), Calls0, Calls, HasAT0, HasAT, CallsHO0, CallsHO) :-
 	check_goal_list(Goals, Calls0, Calls, HasAT0, HasAT, CallsHO0, CallsHO).
-check_goal1(par_conj(Goals, _), Calls0, Calls, HasAT0, HasAT,
+check_goal1(par_conj(Goals), Calls0, Calls, HasAT0, HasAT,
 		CallsHO0, CallsHO) :-
 	check_goal_list(Goals, Calls0, Calls, HasAT0, HasAT, CallsHO0, CallsHO).
-check_goal1(disj(Goals, _Follow), Calls0, Calls, HasAT0, HasAT, CallsHO0, 
-		CallsHO) :-
+check_goal1(disj(Goals), Calls0, Calls, HasAT0, HasAT, CallsHO0, CallsHO) :-
 	check_goal_list(Goals, Calls0, Calls, HasAT0, HasAT, CallsHO0, CallsHO).
-check_goal1(switch(_Var, _Fail, Cases, _Follow), Calls0, Calls, HasAT0, 
+check_goal1(switch(_Var, _Fail, Cases), Calls0, Calls, HasAT0, 
 		HasAT, CallsHO0, CallsH0) :- 
 	check_case_list(Cases, Calls0, Calls, HasAT0, HasAT, CallsHO0, CallsH0).
-check_goal1(if_then_else(_Vars, Cond - _CInfo, Then - _TInfo, Else - _EInfo,
-		_Follow), Calls0, Calls, HasAT0, HasAT, CallsHO0, CallsHO) :-
+check_goal1(if_then_else(_Vars, Cond - _CInfo, Then - _TInfo, Else - _EInfo),
+		Calls0, Calls, HasAT0, HasAT, CallsHO0, CallsHO) :-
 	check_goal1(Cond, Calls0, Calls1, HasAT0, HasAT1, CallsHO0, CallsHO1),
 	check_goal1(Then, Calls1, Calls2, HasAT1, HasAT2, CallsHO1, CallsHO2),
 	check_goal1(Else, Calls2, Calls, HasAT2, HasAT, CallsHO2, CallsHO).
@@ -898,14 +897,14 @@
 
 get_called_procs(conj(Goals), Calls0, Calls) :-
 	check_goal_list(Goals, Calls0, Calls).
-get_called_procs(par_conj(Goals, _), Calls0, Calls) :-
+get_called_procs(par_conj(Goals), Calls0, Calls) :-
 	check_goal_list(Goals, Calls0, Calls).
-get_called_procs(disj(Goals, _Follow), Calls0, Calls) :-
+get_called_procs(disj(Goals), Calls0, Calls) :-
 	check_goal_list(Goals, Calls0, Calls).
-get_called_procs(switch(_Var, _Fail, Cases, _Follow), Calls0, Calls) :-
+get_called_procs(switch(_Var, _Fail, Cases), Calls0, Calls) :-
 	check_case_list(Cases, Calls0, Calls).
 get_called_procs(if_then_else(_Vars, Cond - _CInfo, Then - _TInfo, 
-		Else - _EInfo, _Follow), Calls0, Calls) :-
+		Else - _EInfo), Calls0, Calls) :-
 	get_called_procs(Cond, Calls0, Calls1),
 	get_called_procs(Then, Calls1, Calls2),
 	get_called_procs(Else, Calls2, Calls). 
Index: compiler/string_switch.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/string_switch.m,v
retrieving revision 1.37
diff -u -b -r1.37 string_switch.m
--- compiler/string_switch.m	8 Jul 2001 16:40:11 -0000	1.37
+++ compiler/string_switch.m	18 Jul 2001 12:16:39 -0000
@@ -17,7 +17,7 @@
 
 :- interface.
 
-:- import_module prog_data, hlds_data, hlds_goal.
+:- import_module prog_data, hlds_data, hlds_llds.
 :- import_module switch_util, code_model.
 :- import_module llds, code_info.
 
Index: compiler/switch_detection.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/switch_detection.m,v
retrieving revision 1.96
diff -u -b -r1.96 switch_detection.m
--- compiler/switch_detection.m	7 Apr 2001 14:04:59 -0000	1.96
+++ compiler/switch_detection.m	16 Jul 2001 17:44:27 -0000
@@ -149,15 +149,15 @@
 		map(prog_var, type), module_info, hlds_goal_expr).
 :- mode detect_switches_in_goal_2(in, in, in, in, in, out) is det.
 
-detect_switches_in_goal_2(disj(Goals0, SM), GoalInfo, InstMap0,
+detect_switches_in_goal_2(disj(Goals0), GoalInfo, InstMap0,
 		VarTypes, ModuleInfo, Goal) :-
 	( Goals0 = [] ->
-		Goal = disj([], SM)
+		Goal = disj([])
 	;
 		goal_info_get_nonlocals(GoalInfo, NonLocals),
 		set__to_sorted_list(NonLocals, NonLocalsList),
 		detect_switches_in_disj(NonLocalsList, Goals0, GoalInfo,
-			SM, InstMap0, VarTypes, NonLocalsList, ModuleInfo,
+			InstMap0, VarTypes, NonLocalsList, ModuleInfo,
 			[], Goal)
 	).
 
@@ -165,8 +165,8 @@
 		VarTypes, ModuleInfo, conj(Goals)) :-
 	detect_switches_in_conj(Goals0, InstMap0, VarTypes, ModuleInfo, Goals).
 
-detect_switches_in_goal_2(par_conj(Goals0, SM), _GoalInfo, InstMap0,
-		VarTypes, ModuleInfo, par_conj(Goals, SM)) :-
+detect_switches_in_goal_2(par_conj(Goals0), _GoalInfo, InstMap0,
+		VarTypes, ModuleInfo, par_conj(Goals)) :-
 	detect_switches_in_par_conj(Goals0, InstMap0, VarTypes,
 		ModuleInfo, Goals).
 
@@ -174,9 +174,9 @@
 		VarTypes, ModuleInfo, not(Goal)) :-
 	detect_switches_in_goal(Goal0, InstMap0, VarTypes, ModuleInfo, Goal).
 
-detect_switches_in_goal_2(if_then_else(Vars, Cond0, Then0, Else0, SM),
+detect_switches_in_goal_2(if_then_else(Vars, Cond0, Then0, Else0),
 		_GoalInfo, InstMap0, VarTypes, ModuleInfo,
-		if_then_else(Vars, Cond, Then, Else, SM)) :-
+		if_then_else(Vars, Cond, Then, Else)) :-
 	detect_switches_in_goal_1(Cond0, InstMap0, VarTypes, ModuleInfo, Cond,
 		InstMap1),
 	detect_switches_in_goal(Then0, InstMap1, VarTypes, ModuleInfo, Then),
@@ -210,8 +210,8 @@
 		RHS = RHS0
 	).
 
-detect_switches_in_goal_2(switch(Var, CanFail, Cases0, SM), _, InstMap,
-		VarTypes, ModuleInfo, switch(Var, CanFail, Cases, SM)) :-
+detect_switches_in_goal_2(switch(Var, CanFail, Cases0), _, InstMap,
+		VarTypes, ModuleInfo, switch(Var, CanFail, Cases)) :-
 	detect_switches_in_cases(Cases0, InstMap, VarTypes, ModuleInfo, Cases).
 
 detect_switches_in_goal_2(foreign_proc(A,B,C,D,E,F,G), _, _, _, _,
@@ -238,11 +238,11 @@
 :- type again ---> again(prog_var, list(hlds_goal), sorted_case_list).
 
 :- pred detect_switches_in_disj(list(prog_var), list(hlds_goal), hlds_goal_info,
-	store_map, instmap, map(prog_var, type), list(prog_var), module_info,
+	instmap, map(prog_var, type), list(prog_var), module_info,
 	list(again), hlds_goal_expr).
-:- mode detect_switches_in_disj(in, in, in, in, in, in, in, in, in, out) is det.
+:- mode detect_switches_in_disj(in, in, in, in, in, in, in, in, out) is det.
 
-detect_switches_in_disj([Var | Vars], Goals0, GoalInfo, SM, InstMap,
+detect_switches_in_disj([Var | Vars], Goals0, GoalInfo, InstMap,
 		VarTypes, AllVars, ModuleInfo, Again0, Goal) :-
 	% can we do at least a partial switch on this variable?
 	(
@@ -268,12 +268,12 @@
 		->
 			( CasesList = [_, _ | _] ->
 				cases_to_switch(CasesList, Var, VarTypes,
-					GoalInfo, SM, InstMap, ModuleInfo,
+					GoalInfo, InstMap, ModuleInfo,
 					Goal)
 			;
 				detect_sub_switches_in_disj(Goals0, InstMap,
 					VarTypes, ModuleInfo, Goals),
-				Goal = disj(Goals, SM)
+				Goal = disj(Goals)
 			)
 		;
 			% insert this switch into the list of incomplete
@@ -286,15 +286,15 @@
 			),
 			% try to find a switch
 			detect_switches_in_disj(Vars, Goals0, GoalInfo,
-				SM, InstMap, VarTypes, AllVars, ModuleInfo,
+				InstMap, VarTypes, AllVars, ModuleInfo,
 				Again1, Goal)
 		)
 	;
-		detect_switches_in_disj(Vars, Goals0, GoalInfo, SM, InstMap,
+		detect_switches_in_disj(Vars, Goals0, GoalInfo, InstMap,
 			VarTypes, AllVars, ModuleInfo, Again0, Goal)
 	).
-detect_switches_in_disj([], Goals0, GoalInfo, SM, InstMap,
-		VarTypes, AllVars, ModuleInfo, AgainList0, disj(Goals, SM)) :-
+detect_switches_in_disj([], Goals0, GoalInfo, InstMap,
+		VarTypes, AllVars, ModuleInfo, AgainList0, disj(Goals)) :-
 	(
 		AgainList0 = [],
 		detect_sub_switches_in_disj(Goals0, InstMap, VarTypes,
@@ -303,9 +303,9 @@
 		AgainList0 = [Again | AgainList1],
 		select_best_switch(AgainList1, Again, BestAgain),
 		BestAgain = again(Var, Left0, CasesList),
-		cases_to_switch(CasesList, Var, VarTypes, GoalInfo, SM, InstMap,
+		cases_to_switch(CasesList, Var, VarTypes, GoalInfo, InstMap,
 			ModuleInfo, SwitchGoal),
-		detect_switches_in_disj(AllVars, Left0, GoalInfo, SM, InstMap,
+		detect_switches_in_disj(AllVars, Left0, GoalInfo, InstMap,
 			VarTypes, AllVars, ModuleInfo, [], Left),
 		goal_to_disj_list(Left - GoalInfo, LeftList),
 		Goals = [SwitchGoal - GoalInfo | LeftList]
@@ -557,11 +557,10 @@
 %-----------------------------------------------------------------------------%
 
 :- pred cases_to_switch(sorted_case_list, prog_var, map(prog_var, type),
-		hlds_goal_info, store_map, instmap, module_info,
-		hlds_goal_expr).
-:- mode cases_to_switch(in, in, in, in, in, in, in, out) is det.
+		hlds_goal_info, instmap, module_info, hlds_goal_expr).
+:- mode cases_to_switch(in, in, in, in, in, in, out) is det.
 
-cases_to_switch(CasesList, Var, VarTypes, _GoalInfo, SM, InstMap, ModuleInfo,
+cases_to_switch(CasesList, Var, VarTypes, _GoalInfo, InstMap, ModuleInfo,
 		Goal) :-
 	instmap__lookup_var(InstMap, Var, VarInst),
 	( inst_is_bound_to_functors(ModuleInfo, VarInst, Functors) ->
@@ -593,11 +592,10 @@
 	% nonexistent anyway.
 	(
 		Cases = [],
-		map__init(Empty),
-		Goal = disj([], Empty)
+		Goal = disj([])
 	;
 		Cases = [_ | _],
-		Goal = switch(Var, CanFail, Cases, SM)
+		Goal = switch(Var, CanFail, Cases)
 	).
 
 	% check whether a switch handles all the possible
Index: compiler/switch_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/switch_gen.m,v
retrieving revision 1.76
diff -u -b -r1.76 switch_gen.m
--- compiler/switch_gen.m	24 Oct 2001 07:09:56 -0000	1.76
+++ compiler/switch_gen.m	12 Jan 2002 05:26:01 -0000
@@ -49,14 +49,15 @@
 :- import_module list.
 
 :- pred switch_gen__generate_switch(code_model, prog_var, can_fail, list(case),
-	store_map, hlds_goal_info, code_tree, code_info, code_info).
-:- mode switch_gen__generate_switch(in, in, in, in, in, in, out, in, out)
+	hlds_goal_info, code_tree, code_info, code_info).
+:- mode switch_gen__generate_switch(in, in, in, in, in, out, in, out)
 	is det.
 
 %---------------------------------------------------------------------------%
 
 :- implementation.
 
+:- import_module hlds_llds.
 :- import_module dense_switch, string_switch, tag_switch, lookup_switch.
 :- import_module code_gen, unify_gen, code_aux, code_util.
 :- import_module switch_util, type_util.
@@ -69,8 +70,9 @@
 	% Choose which method to use to generate the switch.
 	% CanFail says whether the switch covers all cases.
 
-switch_gen__generate_switch(CodeModel, CaseVar, CanFail, Cases, StoreMap,
-		GoalInfo, Code) -->
+switch_gen__generate_switch(CodeModel, CaseVar, CanFail, Cases, GoalInfo,
+		Code) -->
+	{ goal_info_get_store_map(GoalInfo, StoreMap) },
 	switch_gen__determine_category(CaseVar, SwitchCategory),
 	code_info__get_next_label(EndLabel),
 	switch_gen__lookup_tags(Cases, CaseVar, TaggedCases0),
Index: compiler/table_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/table_gen.m,v
retrieving revision 1.32
diff -u -b -r1.32 table_gen.m
--- compiler/table_gen.m	7 Mar 2002 08:30:21 -0000	1.32
+++ compiler/table_gen.m	8 Mar 2002 04:04:58 -0000
@@ -568,9 +568,8 @@
 		Context, CallSaveAnsGoalInfo),
 	CallSaveAnsGoal = CallSaveAnsGoalEx - CallSaveAnsGoalInfo,
 
-	map__init(StoreMap),
 	GenIfNecGoalEx = if_then_else([], OccurredGoal,
-		RestoreAnsGoal, CallSaveAnsGoal, StoreMap),
+		RestoreAnsGoal, CallSaveAnsGoal),
 	create_instmap_delta([OccurredGoal, RestoreAnsGoal,
 		CallSaveAnsGoal], GenIfNecInstMapDelta0),
 	set__insert(OrigNonLocals, TableVar, GenIfNecNonLocals),
@@ -592,7 +591,7 @@
 	CheckAndGenAnsGoal = CheckAndGenAnsGoalEx - CheckAndGenAnsGoalInfo,
 
 	BodyGoalEx = if_then_else([], InRangeGoal, CheckAndGenAnsGoal,
-		OrigGoal, StoreMap),
+		OrigGoal),
 	create_instmap_delta([InRangeGoal, CheckAndGenAnsGoal, OrigGoal],
 		BodyInstMapDelta0),
 	instmap_delta_restrict(BodyInstMapDelta0, OrigNonLocals,
@@ -680,9 +679,8 @@
 		NoLoopGenGoalInfo),
 	NoLoopGenAnsGoal = NoLoopGenAnsGoalEx - NoLoopGenGoalInfo,
 
-	map__init(StoreMap),
 	GenAnsGoalEx = if_then_else([], ActiveCheckGoal,
-		LoopErrorGoal, NoLoopGenAnsGoal, StoreMap),
+		LoopErrorGoal, NoLoopGenAnsGoal),
 	create_instmap_delta([ActiveCheckGoal, LoopErrorGoal,
 		NoLoopGenAnsGoal], GenAnsInstMapDelta0),
 	instmap_delta_restrict(GenAnsInstMapDelta0, GenAnsNonLocals,
@@ -693,7 +691,7 @@
 	GenAnsGoal = GenAnsGoalEx - GenAnsGoalInfo,
 
 	ITEGoalEx = if_then_else([], CompleteCheckGoal, RestoreAnsGoal,
-		GenAnsGoal, StoreMap),
+		GenAnsGoal),
 	create_instmap_delta([CompleteCheckGoal, RestoreAnsGoal, GenAnsGoal],
 		ITEInstMapDelta0),
 	instmap_delta_restrict(ITEInstMapDelta0, GenAnsNonLocals,
@@ -760,7 +758,6 @@
 
 	set__insert(OrigNonLocals, TableVar, GenAnsNonLocals),
 
-	map__init(StoreMap),
 	(
 		(
 			EvalMethod = eval_loop_check
@@ -792,7 +789,7 @@
 		NoLoopGenAnsGoal = NoLoopGenAnsGoalEx - NoLoopGenGoalInfo,
 
 		GenTrueAnsGoalEx = if_then_else([], ActiveCheckGoal,
-			LoopErrorGoal, NoLoopGenAnsGoal, StoreMap),
+			LoopErrorGoal, NoLoopGenAnsGoal),
 		create_instmap_delta([ActiveCheckGoal, LoopErrorGoal,
 			NoLoopGenAnsGoal], GenTrueAnsInstMapDelta0),
 		instmap_delta_restrict(GenTrueAnsInstMapDelta0,
@@ -858,7 +855,7 @@
 	),
 
 	GenAnsGoalEx = if_then_else([], GenTrueAnsGoal, SaveAnsGoal,
-		MarkAsFailedGoal, StoreMap),
+		MarkAsFailedGoal),
 	create_instmap_delta([GenTrueAnsGoal, SaveAnsGoal, MarkAsFailedGoal],
 		GenAnsGoalInstMapDelta0),
 	instmap_delta_restrict(GenAnsGoalInstMapDelta0, GenAnsNonLocals,
@@ -868,7 +865,7 @@
 	GenAnsGoal = GenAnsGoalEx - GenAnsGoalInfo,
 
 	ITEGoalEx = if_then_else([], CompleteCheckGoal, RestoreAnsGoal,
-		GenAnsGoal, StoreMap),
+		GenAnsGoal),
 	create_instmap_delta([CompleteCheckGoal, RestoreAnsGoal, GenAnsGoal],
 		ITEInstMapDelta0),
 	instmap_delta_restrict(ITEInstMapDelta0, GenAnsNonLocals,
@@ -939,7 +936,6 @@
 	true_goal(TrueGoal),
 	fail_goal(FailGoal),
 
-	map__init(StoreMap),
 	(
 		EvalMethod = eval_memo
 	->
@@ -977,11 +973,11 @@
 	;
 		ResumeGoal = FailGoal
 	),
-	GenAnsGoalEx = disj([GenAnsGoalPart1, ResumeGoal], StoreMap),
+	GenAnsGoalEx = disj([GenAnsGoalPart1, ResumeGoal]),
 	GenAnsGoal = GenAnsGoalEx - GenAnsGoalPart1GoalInfo,
 
 	ITE1GoalEx = if_then_else([], IsActiveCheckGoal, ActiveGoal,
-		GenAnsGoal, StoreMap),
+		GenAnsGoal),
 	ITE1Goal = ITE1GoalEx - GenAnsGoalPart1GoalInfo,
 
 	(
@@ -990,7 +986,7 @@
 		ITE2Goal = ITE1Goal
 	;
 		ITE2GoalEx = if_then_else([], CompleteCheckGoal,
-			RestoreAllAnsGoal, ITE1Goal, StoreMap),
+			RestoreAllAnsGoal, ITE1Goal),
 		ITE2Goal = ITE2GoalEx - GenAnsGoalPart1GoalInfo
 	),
 
Index: compiler/tag_switch.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/tag_switch.m,v
retrieving revision 1.51
diff -u -b -r1.51 tag_switch.m
--- compiler/tag_switch.m	23 Nov 2000 04:32:48 -0000	1.51
+++ compiler/tag_switch.m	18 Jul 2001 12:17:00 -0000
@@ -14,7 +14,7 @@
 
 :- interface.
 
-:- import_module prog_data, hlds_goal, hlds_data.
+:- import_module prog_data, hlds_llds, hlds_data.
 :- import_module switch_util, code_model.
 :- import_module llds, code_info.
 
Index: compiler/term_traversal.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_traversal.m,v
retrieving revision 1.18
diff -u -b -r1.18 term_traversal.m
--- compiler/term_traversal.m	7 Mar 2002 08:30:22 -0000	1.18
+++ compiler/term_traversal.m	8 Mar 2002 04:04:59 -0000
@@ -159,14 +159,14 @@
 	list__reverse(Goals, RevGoals),
 	traverse_conj(RevGoals, Params, Info0, Info).
 
-traverse_goal_2(par_conj(Goals, _SM), _, Params, Info0, Info) :-
+traverse_goal_2(par_conj(Goals), _, Params, Info0, Info) :-
 	list__reverse(Goals, RevGoals),
 	traverse_conj(RevGoals, Params, Info0, Info).
 
-traverse_goal_2(switch(_, _, Cases, _), _, Params, Info0, Info) :-
+traverse_goal_2(switch(_, _, Cases), _, Params, Info0, Info) :-
 	traverse_switch(Cases, Params, Info0, Info).
 
-traverse_goal_2(disj(Goals, _StoreMap), _, Params, Info0, Info) :-
+traverse_goal_2(disj(Goals), _, Params, Info0, Info) :-
 	traverse_disj(Goals, Params, Info0, Info).
 
 traverse_goal_2(not(Goal), _, Params, Info0, Info) :-
@@ -178,7 +178,7 @@
 traverse_goal_2(some(_Vars, _, Goal), _GoalInfo, Params, Info0, Info) :-
 	traverse_goal(Goal, Params, Info0, Info).
 
-traverse_goal_2(if_then_else(_, Cond, Then, Else, _), _, Params, Info0, Info) :-
+traverse_goal_2(if_then_else(_, Cond, Then, Else), _, Params, Info0, Info) :-
 	traverse_conj([Then, Cond], Params, Info0, Info1),
 	traverse_goal(Else, Params, Info0, Info2),
 	combine_paths(Info1, Info2, Params, Info).
Index: compiler/trace.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trace.m,v
retrieving revision 1.49
diff -u -b -r1.49 trace.m
--- compiler/trace.m	18 Feb 2002 07:00:58 -0000	1.49
+++ compiler/trace.m	19 Feb 2002 04:54:07 -0000
@@ -220,7 +220,7 @@
 
 :- import_module continuation_info, trace_params, llds_out, layout_out, tree.
 :- import_module type_util, (inst), instmap, inst_match, mode_util.
-:- import_module code_model, code_util, options.
+:- import_module hlds_llds, code_model, code_util, options.
 
 :- import_module list, bool, int, string, map, std_util, require, term, varset.
 
Index: compiler/trace_params.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/trace_params.m,v
retrieving revision 1.5
diff -u -b -r1.5 trace_params.m
--- compiler/trace_params.m	18 Jan 2001 01:18:58 -0000	1.5
+++ compiler/trace_params.m	16 Jul 2001 13:44:39 -0000
@@ -31,6 +31,7 @@
 
 	% These functions check for various properties of the trace level.
 :- func trace_level_is_none(trace_level) = bool.
+:- func trace_level_needs_input_vars(trace_level) = bool.
 :- func trace_level_needs_fixed_slots(trace_level) = bool.
 :- func trace_level_needs_from_full_slot(trace_level) = bool.
 :- func trace_level_needs_decl_debug_slots(trace_level) = bool.
@@ -80,6 +81,12 @@
 trace_level_is_none(deep) = no.
 trace_level_is_none(decl) = no.
 trace_level_is_none(decl_rep) = no.
+
+trace_level_needs_input_vars(none) = no.
+trace_level_needs_input_vars(shallow) = yes.
+trace_level_needs_input_vars(deep) = yes.
+trace_level_needs_input_vars(decl) = yes.
+trace_level_needs_input_vars(decl_rep) = yes.
 
 trace_level_needs_fixed_slots(none) = no.
 trace_level_needs_fixed_slots(shallow) = yes.
Index: compiler/typecheck.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/typecheck.m,v
retrieving revision 1.312
diff -u -b -r1.312 typecheck.m
--- compiler/typecheck.m	7 Mar 2002 08:30:23 -0000	1.312
+++ compiler/typecheck.m	8 Mar 2002 04:05:04 -0000
@@ -1010,14 +1010,14 @@
 typecheck_goal_2(conj(List0), conj(List)) -->
 	checkpoint("conj"),
 	typecheck_goal_list(List0, List).
-typecheck_goal_2(par_conj(List0, SM), par_conj(List, SM)) -->
+typecheck_goal_2(par_conj(List0), par_conj(List)) -->
 	checkpoint("par_conj"),
 	typecheck_goal_list(List0, List).
-typecheck_goal_2(disj(List0, SM), disj(List, SM)) -->
+typecheck_goal_2(disj(List0), disj(List)) -->
 	checkpoint("disj"),
 	typecheck_goal_list(List0, List).
-typecheck_goal_2(if_then_else(Vs, A0, B0, C0, SM),
-		if_then_else(Vs, A, B, C, SM)) -->
+typecheck_goal_2(if_then_else(Vs, A0, B0, C0),
+		if_then_else(Vs, A, B, C)) -->
 	checkpoint("if"),
 	typecheck_goal(A0, A),
 	checkpoint("then"),
@@ -1063,7 +1063,7 @@
 	typecheck_info_set_arg_num(0),
 	typecheck_info_set_unify_context(UnifyContext),
 	typecheck_unification(A, B0, B).
-typecheck_goal_2(switch(_, _, _, _), _) -->
+typecheck_goal_2(switch(_, _, _), _) -->
 	{ error("unexpected switch") }.
 typecheck_goal_2(foreign_proc(A, PredId, C, Args, E, F, G), 
 		foreign_proc(A, PredId, C, Args, E, F, G)) -->
Index: compiler/unify_proc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_proc.m,v
retrieving revision 1.105
diff -u -b -r1.105 unify_proc.m
--- compiler/unify_proc.m	7 Mar 2002 08:30:27 -0000	1.105
+++ compiler/unify_proc.m	8 Mar 2002 04:05:06 -0000
@@ -1234,8 +1234,7 @@
 		Return_R) },
 
 	unify_proc__generate_compare_cases(Ctors, R, X, Y, Context, Cases),
-	{ map__init(Empty) },
-	{ CasesGoal = disj(Cases, Empty) - GoalInfo },
+	{ CasesGoal = disj(Cases) - GoalInfo },
 
 	unify_proc__build_call("compare_error", [], Context, Abort),
 
@@ -1244,10 +1243,10 @@
 		Call_Y_Index, 
 		if_then_else([], Call_Less_Than, Return_Less_Than,
 		    if_then_else([], Call_Greater_Than, Return_Greater_Than,
-		        if_then_else([], CasesGoal, Return_R, Abort, Empty
-		        ) - GoalInfo, Empty
-		    ) - GoalInfo, Empty
-		) - GoalInfo
+		        if_then_else([], CasesGoal, Return_R, Abort)
+		        - GoalInfo)
+		    - GoalInfo)
+		- GoalInfo
 	]) - GoalInfo }.
 
 %	unify_proc__generate_compare_cases: for a type such as 
@@ -1432,8 +1431,7 @@
 			R, var(R1), Context, explicit, [], Return_R1) },
 		{ Condition = conj([Do_Comparison, Check_Not_Equal])
 					- GoalInfo },
-		{ map__init(Empty) },
-		{ Goal = if_then_else([], Condition, Return_R1, ElseCase, Empty)
+		{ Goal = if_then_else([], Condition, Return_R1, ElseCase)
 					- GoalInfo},
 		unify_proc__compare_args_2(ArgTypes, ExistQTVars, Xs, Ys, R,
 			Context, ElseCase)
Index: compiler/unique_modes.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unique_modes.m,v
retrieving revision 1.72
diff -u -b -r1.72 unique_modes.m
--- compiler/unique_modes.m	7 Apr 2001 14:05:02 -0000	1.72
+++ compiler/unique_modes.m	16 Jul 2001 17:40:56 -0000
@@ -260,8 +260,8 @@
 	),
 	mode_checkpoint(exit, "conj").
 
-unique_modes__check_goal_2(par_conj(List0, SM), GoalInfo0,
-		par_conj(List, SM)) -->
+unique_modes__check_goal_2(par_conj(List0), GoalInfo0,
+		par_conj(List)) -->
 	mode_checkpoint(enter, "par_conj"),
 	{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
 	mode_info_add_live_vars(NonLocals),
@@ -274,7 +274,7 @@
 	mode_info_remove_live_vars(NonLocals),
 	mode_checkpoint(exit, "par_conj").
 
-unique_modes__check_goal_2(disj(List0, SM), GoalInfo0, disj(List, SM)) -->
+unique_modes__check_goal_2(disj(List0), GoalInfo0, disj(List)) -->
 	mode_checkpoint(enter, "disj"),
 	( { List0 = [] } ->
 		{ List = [] },
@@ -315,7 +315,7 @@
 	),
 	mode_checkpoint(exit, "disj").
 
-unique_modes__check_goal_2(if_then_else(Vs, Cond0, Then0, Else0, SM),
+unique_modes__check_goal_2(if_then_else(Vs, Cond0, Then0, Else0),
 		GoalInfo0, Goal) -->
 	mode_checkpoint(enter, "if-then-else"),
 	{ goal_info_get_nonlocals(GoalInfo0, NonLocals) },
@@ -383,7 +383,7 @@
 	mode_info_dcg_get_instmap(InstMapElse),
 	mode_info_set_instmap(InstMap0),
 	instmap__merge(NonLocals, [InstMapThen, InstMapElse], if_then_else),
-	{ Goal = if_then_else(Vs, Cond, Then, Else, SM) },
+	{ Goal = if_then_else(Vs, Cond, Then, Else) },
 	mode_checkpoint(exit, "if-then-else").
 
 unique_modes__check_goal_2(not(A0), GoalInfo0, not(A)) -->
@@ -492,8 +492,8 @@
 	mode_info_unset_call_context,
 	mode_checkpoint(exit, "unify").
 
-unique_modes__check_goal_2(switch(Var, CanFail, Cases0, SM), GoalInfo0,
-		switch(Var, CanFail, Cases, SM)) -->
+unique_modes__check_goal_2(switch(Var, CanFail, Cases0), GoalInfo0,
+		switch(Var, CanFail, Cases)) -->
 	mode_checkpoint(enter, "switch"),
 	( { Cases0 = [] } ->
 		{ Cases = [] },
Index: compiler/unneeded_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unneeded_code.m,v
retrieving revision 1.9
diff -u -b -r1.9 unneeded_code.m
--- compiler/unneeded_code.m	7 Apr 2001 14:05:03 -0000	1.9
+++ compiler/unneeded_code.m	16 Jul 2001 17:41:45 -0000
@@ -623,7 +623,7 @@
 		RefinedGoals = RefinedGoals0,
 		Changed = Changed0
 	;
-		GoalExpr0 = par_conj(_, _),
+		GoalExpr0 = par_conj(_),
 		Goal = Goal0,
 		unneeded_code__demand_inputs(Goal, ModuleInfo, InstMap0,
 			everywhere, WhereNeededMap0, WhereNeededMap),
@@ -638,7 +638,7 @@
 		GoalExpr = conj(Conjuncts),
 		Goal = GoalExpr - GoalInfo0
 	;
-		GoalExpr0 = switch(SwitchVar, CanFail, Cases0, StoreMap),
+		GoalExpr0 = switch(SwitchVar, CanFail, Cases0),
 		(
 			Cases0 = [case(_, _ - FirstCaseGoalInfo) | _],
 			goal_info_get_goal_path(FirstCaseGoalInfo,
@@ -664,10 +664,10 @@
 			WhereNeededMap1, BranchNeededMap, WhereNeededMap2),
 		unneeded_code__demand_var(GoalPath, everywhere, SwitchVar,
 			WhereNeededMap2, WhereNeededMap),
-		GoalExpr = switch(SwitchVar, CanFail, Cases, StoreMap),
+		GoalExpr = switch(SwitchVar, CanFail, Cases),
 		Goal = GoalExpr - GoalInfo0
 	;
-		GoalExpr0 = disj(Disjuncts0, StoreMap),
+		GoalExpr0 = disj(Disjuncts0),
 		goal_info_get_goal_path(GoalInfo0, GoalPath),
 		map__map_values(unneeded_code__demand_var_everywhere,
 			WhereNeededMap0, WhereNeededMap1),
@@ -675,10 +675,10 @@
 			VarTypes, ModuleInfo, Options, GoalPath, Disjuncts,
 			WhereNeededMap1, WhereNeededMap1, WhereNeededMap,
 			RefinedGoals0, RefinedGoals, Changed0, Changed),
-		GoalExpr = disj(Disjuncts, StoreMap),
+		GoalExpr = disj(Disjuncts),
 		Goal = GoalExpr - GoalInfo0
 	;
-		GoalExpr0 = if_then_else(Quant, Cond0, Then0, Else0, StoreMap),
+		GoalExpr0 = if_then_else(Quant, Cond0, Then0, Else0),
 		goal_info_get_goal_path(GoalInfo0, GoalPath),
 		BranchPoint = branch_point(GoalPath, ite), 
 		map__map_values(unneeded_code__demand_var_everywhere,
@@ -688,7 +688,7 @@
 			GoalPath, Cond, Then, Else, WhereNeededMap1,
 			WhereNeededMap, RefinedGoals0, RefinedGoals, Changed0,
 			Changed),
-		GoalExpr = if_then_else(Quant, Cond, Then, Else, StoreMap),
+		GoalExpr = if_then_else(Quant, Cond, Then, Else),
 		Goal = GoalExpr - GoalInfo0
 	;
 		GoalExpr0 = not(NegGoal0),
@@ -967,7 +967,7 @@
 		Goal = Goal0,
 		RefinedGoals = RefinedGoals0
 	;
-		GoalExpr0 = par_conj(_, _),
+		GoalExpr0 = par_conj(_),
 		Goal = Goal0,
 		RefinedGoals = RefinedGoals0
 	;
@@ -977,25 +977,25 @@
 		GoalExpr = conj(Conjuncts),
 		Goal = GoalExpr - GoalInfo0
 	;
-		GoalExpr0 = switch(SwitchVar, CanFail, Cases0, StoreMap),
+		GoalExpr0 = switch(SwitchVar, CanFail, Cases0),
 		goal_info_get_goal_path(GoalInfo0, GoalPath),
 		unneeded_code__refine_cases(Cases0, RefinedGoals0,
 			GoalPath, 1, Cases, RefinedGoals),
-		GoalExpr = switch(SwitchVar, CanFail, Cases, StoreMap),
+		GoalExpr = switch(SwitchVar, CanFail, Cases),
 		Goal = GoalExpr - GoalInfo0
 	;
-		GoalExpr0 = disj(Disjuncts0, StoreMap),
+		GoalExpr0 = disj(Disjuncts0),
 		goal_info_get_goal_path(GoalInfo0, GoalPath),
 		unneeded_code__refine_disj(Disjuncts0, RefinedGoals0,
 			GoalPath, 1, Disjuncts, RefinedGoals),
-		GoalExpr = disj(Disjuncts, StoreMap),
+		GoalExpr = disj(Disjuncts),
 		Goal = GoalExpr - GoalInfo0
 	;
-		GoalExpr0 = if_then_else(Quant, Cond0, Then0, Else0, StoreMap),
+		GoalExpr0 = if_then_else(Quant, Cond0, Then0, Else0),
 		goal_info_get_goal_path(GoalInfo0, GoalPath),
 		unneeded_code__refine_ite(Cond0, Then0, Else0, RefinedGoals0,
 			GoalPath, Cond, Then, Else, RefinedGoals),
-		GoalExpr = if_then_else(Quant, Cond, Then, Else, StoreMap),
+		GoalExpr = if_then_else(Quant, Cond, Then, Else),
 		Goal = GoalExpr - GoalInfo0
 	;
 		GoalExpr0 = not(NegGoal0),
Index: compiler/unused_args.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unused_args.m,v
retrieving revision 1.75
diff -u -b -r1.75 unused_args.m
--- compiler/unused_args.m	7 Mar 2002 08:30:28 -0000	1.75
+++ compiler/unused_args.m	8 Mar 2002 04:05:07 -0000
@@ -56,6 +56,7 @@
 :- import_module code_util, globals, make_hlds, mercury_to_mercury, mode_util.
 :- import_module options, prog_data, prog_out, quantification, special_pred.
 :- import_module passes_aux, inst_match, modules, polymorphism, goal_util.
+:- import_module util.
 
 :- import_module assoc_list, bool, char, int, list, map, require.
 :- import_module set, std_util, string.
@@ -393,15 +394,15 @@
 	traverse_list_of_goals(Info, Goals, UseInf0, UseInf).
 
 % handle parallel conjunction
-traverse_goal(Info, par_conj(Goals, _SM), UseInf0, UseInf) :-
+traverse_goal(Info, par_conj(Goals), UseInf0, UseInf) :-
 	traverse_list_of_goals(Info, Goals, UseInf0, UseInf).
 
 % handle disjunction
-traverse_goal(Info, disj(Goals, _), UseInf0, UseInf) :-
+traverse_goal(Info, disj(Goals), UseInf0, UseInf) :-
 	traverse_list_of_goals(Info, Goals, UseInf0, UseInf).
 
 % handle switch
-traverse_goal(Info, switch(Var, _, Cases, _), UseInf0, UseInf) :-
+traverse_goal(Info, switch(Var, _, Cases), UseInf0, UseInf) :-
 	set_var_used(Var, UseInf0, UseInf1),
 	list_case_to_list_goal(Cases, Goals),
 	traverse_list_of_goals(Info, Goals, UseInf1, UseInf).
@@ -416,7 +417,7 @@
 		UseInf0, UseInf).
 
 % handle if then else
-traverse_goal(Info, if_then_else(_, Cond - _, Then - _, Else - _, _),
+traverse_goal(Info, if_then_else(_, Cond - _, Then - _, Else - _),
 			UseInf0, UseInf) :-
 	traverse_goal(Info, Cond, UseInf0, UseInf1),
 	traverse_goal(Info, Then, UseInf1, UseInf2),
@@ -1211,13 +1212,13 @@
 						Changed, Goals0, Goals).
 
 fixup_goal_expr(ModuleInfo, UnusedVars, ProcCallInfo, Changed,
-		par_conj(Goals0, SM) - GoalInfo,
-		par_conj(Goals, SM) - GoalInfo) :-
+		par_conj(Goals0) - GoalInfo,
+		par_conj(Goals) - GoalInfo) :-
 	fixup_conjuncts(ModuleInfo, UnusedVars, ProcCallInfo, no,
 						Changed, Goals0, Goals).
 
 fixup_goal_expr(ModuleInfo, UnusedVars, ProcCallInfo, Changed,
-		disj(Goals0, SM) - GoalInfo, disj(Goals, SM) - GoalInfo) :-
+		disj(Goals0) - GoalInfo, disj(Goals) - GoalInfo) :-
 	fixup_disjuncts(ModuleInfo, UnusedVars, ProcCallInfo,
 				no, Changed, Goals0, Goals).
 
@@ -1227,14 +1228,14 @@
 				Changed, NegGoal0, NegGoal).
 
 fixup_goal_expr(ModuleInfo, UnusedVars, ProcCallInfo, Changed,
-		switch(Var, CanFail, Cases0, SM) - GoalInfo,
-		switch(Var, CanFail, Cases, SM) - GoalInfo) :-
+		switch(Var, CanFail, Cases0) - GoalInfo,
+		switch(Var, CanFail, Cases) - GoalInfo) :-
 	fixup_cases(ModuleInfo, UnusedVars, ProcCallInfo,
 				no, Changed, Cases0, Cases).
 
 fixup_goal_expr(ModuleInfo, UnusedVars, ProcCallInfo, Changed,
-		if_then_else(Vars, Cond0, Then0, Else0, SM) - GoalInfo, 
-		if_then_else(Vars, Cond, Then, Else, SM) - GoalInfo) :- 
+		if_then_else(Vars, Cond0, Then0, Else0) - GoalInfo, 
+		if_then_else(Vars, Cond, Then, Else) - GoalInfo) :- 
 	fixup_goal(ModuleInfo, UnusedVars, ProcCallInfo, Changed1, Cond0, Cond),
 	fixup_goal(ModuleInfo, UnusedVars, ProcCallInfo, Changed2, Then0, Then),
 	fixup_goal(ModuleInfo, UnusedVars, ProcCallInfo, Changed3, Else0, Else),
@@ -1593,21 +1594,6 @@
 		output_arg_list(UnusedArgs),
 		io__write_string(" are unused.\n")
 	).
-
-:- pred write_int_list(list(int)::in, io__state::di, io__state::uo) is det.
-
-write_int_list([]) --> [].
-write_int_list([First | Rest]) -->
-	io__write_int(First),
-	write_int_list_2(Rest).
-
-:- pred write_int_list_2(list(int)::in, io__state::di, io__state::uo) is det.
-
-write_int_list_2([]) --> [].
-write_int_list_2([First | Rest]) -->
-	io__write_string(", "),
-	io__write_int(First),
-	write_int_list_2(Rest).
 
 	% adjust warning message for the presence of type_infos.
 :- pred adjust_unused_args(int::in, list(int)::in, list(int)::out) is det.
Index: compiler/use_local_vars.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/use_local_vars.m,v
retrieving revision 1.1
diff -u -b -r1.1 use_local_vars.m
--- compiler/use_local_vars.m	24 Apr 2001 03:59:03 -0000	1.1
+++ compiler/use_local_vars.m	8 Mar 2002 13:17:26 -0000
@@ -19,7 +19,7 @@
 % in each block by looking for the temp(_, _) lvals that represent those local
 % variables.
 %
-% This module looks for two patterns. The first is
+% This module looks for three patterns. The first is
 %
 %	<instruction that defines a fake register>
 %	<instructions that use and possibly define the fake register>
@@ -45,6 +45,15 @@
 % lval as well. This is a win because the cost of the assignment is less than
 % the savings from replacing the fake register or stack slot references with
 % local variable references.
+%
+% The third pattern we look for consists of a sequence of instructions in which
+% a false register or stack slot is used several times, including at least once
+% in the first instruction as a part of a path to a memory location, before
+% being redefined or maybe aliased. This typically occurs when the code
+% generator fills in the fields of a structure or extracts the fields of a
+% structure. Again, we replace the false register or stack slot with a
+% temporary after assigning the value in the false register or stack slot to
+% the temporary.
 
 %-----------------------------------------------------------------------------%
 
@@ -56,17 +65,18 @@
 :- import_module list, counter.
 
 :- pred use_local_vars__main(list(instruction)::in, list(instruction)::out,
-	proc_label::in, int::in, counter::in, counter::out) is det.
+	proc_label::in, int::in, int::in, counter::in, counter::out) is det.
 
 :- implementation.
 
-:- import_module basic_block, livemap, exprn_aux, opt_util.
+:- import_module basic_block, livemap, exprn_aux, code_util, opt_util.
 :- import_module int, set, map, counter, std_util, require.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-use_local_vars__main(Instrs0, Instrs, ProcLabel, NumRealRRegs, C0, C) :-
+use_local_vars__main(Instrs0, Instrs, ProcLabel, NumRealRRegs, AccessThreshold,
+		C0, C) :-
 	create_basic_blocks(Instrs0, Comments, ProcLabel, C0, C1,
 		LabelSeq, BlockMap0),
 	flatten_basic_blocks(LabelSeq, BlockMap0, TentativeInstrs),
@@ -78,17 +88,18 @@
 		C = C0
 	;
 		MaybeLiveMap = yes(LiveMap),
-		list__foldl(use_local_vars_block(LiveMap, NumRealRRegs),
-			LabelSeq, BlockMap0, BlockMap),
+		list__foldl(use_local_vars_block(LiveMap, NumRealRRegs,
+			AccessThreshold), LabelSeq, BlockMap0, BlockMap),
 		flatten_basic_blocks(LabelSeq, BlockMap, Instrs1),
 		list__append(Comments, Instrs1, Instrs),
 		C = C1
 	).
 
-:- pred use_local_vars_block(livemap::in, int::in, label::in, block_map::in,
-	block_map::out) is det.
+:- pred use_local_vars_block(livemap::in, int::in, int::in, label::in,
+	block_map::in, block_map::out) is det.
 
-use_local_vars_block(LiveMap, NumRealRRegs, Label, BlockMap0, BlockMap) :-
+use_local_vars_block(LiveMap, NumRealRRegs, AccessThreshold, Label,
+		BlockMap0, BlockMap) :-
 	map__lookup(BlockMap0, Label, BlockInfo0),
 	BlockInfo0 = block_info(BlockLabel, LabelInstr, RestInstrs0,
 		JumpLabels, MaybeFallThrough),
@@ -110,7 +121,8 @@
 	),
 	counter__init(1, TempCounter0),
 	use_local_vars_instrs(RestInstrs0, RestInstrs,
-		TempCounter0, TempCounter, NumRealRRegs, MaybeEndLiveLvals),
+		TempCounter0, TempCounter, NumRealRRegs, AccessThreshold,
+		MaybeEndLiveLvals),
 	( TempCounter = TempCounter0 ->
 		BlockMap = BlockMap0
 	;
@@ -164,25 +176,39 @@
 		LiveLvals = LiveLvals0
 	).
 
+%-----------------------------------------------------------------------------%
+
 :- pred use_local_vars_instrs(list(instruction)::in, list(instruction)::out,
+	counter::in, counter::out, int::in, int::in, maybe(lvalset)::in)
+	is det.
+
+use_local_vars_instrs(RestInstrs0, RestInstrs, TempCounter0, TempCounter,
+		NumRealRRegs, AccessThreshold, MaybeEndLiveLvals) :-
+	opt_assign(RestInstrs0, RestInstrs1,
+		TempCounter0, TempCounter1, NumRealRRegs, MaybeEndLiveLvals),
+	( AccessThreshold >= 1 ->
+		opt_access(RestInstrs1, RestInstrs,
+			TempCounter1, TempCounter, NumRealRRegs, set__init,
+			AccessThreshold)
+	;
+		RestInstrs = RestInstrs1,
+		TempCounter = TempCounter1
+	).
+
+%-----------------------------------------------------------------------------%
+
+:- pred opt_assign(list(instruction)::in, list(instruction)::out,
 	counter::in, counter::out, int::in, maybe(lvalset)::in) is det.
 
-use_local_vars_instrs([], [], TempCounter, TempCounter, _, _).
-use_local_vars_instrs([Instr0 | TailInstrs0], Instrs,
+opt_assign([], [], TempCounter, TempCounter, _, _).
+opt_assign([Instr0 | TailInstrs0], Instrs,
 		TempCounter0, TempCounter, NumRealRRegs, MaybeEndLiveLvals) :-
 	Instr0 = Uinstr0 - _Comment0,
 	(
 		( Uinstr0 = assign(ToLval, _FromRval)
 		; Uinstr0 = incr_hp(ToLval, _MaybeTag, _SizeRval, _Type)
 		),
-		(
-			ToLval = reg(r, RegNum),
-			RegNum > NumRealRRegs
-		;
-			ToLval = stackvar(_)
-		;
-			ToLval = framevar(_)
-		)
+		base_lval_worth_replacing(NumRealRRegs, ToLval)
 	->
 		counter__allocate(TempNum, TempCounter0, TempCounter1),
 		NewLval = temp(r, TempNum),
@@ -196,7 +222,7 @@
 			list__map_foldl(exprn_aux__substitute_lval_in_instr(
 				ToLval, NewLval),
 				TailInstrs0, TailInstrs1, 0, _),
-			use_local_vars_instrs(TailInstrs1, TailInstrs,
+			opt_assign(TailInstrs1, TailInstrs,
 				TempCounter1, TempCounter,
 				NumRealRRegs, MaybeEndLiveLvals),
 			Instrs = [Instr | TailInstrs]
@@ -208,22 +234,97 @@
 			substitute_lval_in_defn(ToLval, NewLval,
 				Instr0, Instr),
 			CopyInstr = assign(ToLval, lval(NewLval)) - "",
-			use_local_vars_instrs(TailInstrs1, TailInstrs,
+			opt_assign(TailInstrs1, TailInstrs,
 				TempCounter1, TempCounter,
 				NumRealRRegs, MaybeEndLiveLvals),
 			Instrs = [Instr, CopyInstr | TailInstrs]
 		;
-			use_local_vars_instrs(TailInstrs0, TailInstrs,
+			opt_assign(TailInstrs0, TailInstrs,
 				TempCounter0, TempCounter,
 				NumRealRRegs, MaybeEndLiveLvals),
 			Instrs = [Instr0 | TailInstrs]
 		)
 	;
-		use_local_vars_instrs(TailInstrs0, TailInstrs,
+		opt_assign(TailInstrs0, TailInstrs,
 			TempCounter0, TempCounter,
 			NumRealRRegs, MaybeEndLiveLvals),
 		Instrs = [Instr0 | TailInstrs]
 	).
+
+%-----------------------------------------------------------------------------%
+
+:- pred opt_access(list(instruction)::in, list(instruction)::out,
+	counter::in, counter::out, int::in, lvalset::in, int::in) is det.
+
+opt_access([], [], TempCounter, TempCounter, _, _, _).
+opt_access([Instr0 | TailInstrs0], Instrs,
+		TempCounter0, TempCounter, NumRealRRegs, AlreadyTried0,
+		AccessThreshold) :-
+	Instr0 = Uinstr0 - _Comment0,
+	(
+		Uinstr0 = assign(ToLval, FromRval),
+		lvals_in_lval(ToLval, ToSubLvals),
+		lvals_in_rval(FromRval, FromSubLvals),
+		list__append(ToSubLvals, FromSubLvals, SubLvals),
+		list__filter(
+			base_lval_worth_replacing_not_tried(
+				AlreadyTried0, NumRealRRegs),
+			SubLvals, ReplaceableSubLvals),
+		ReplaceableSubLvals = [ChosenLval | ChooseableRvals]
+	->
+		counter__allocate(TempNum, TempCounter0, TempCounter1),
+		TempLval = temp(r, TempNum),
+		lvals_in_lval(ChosenLval, SubChosenLvals),
+		require(unify(SubChosenLvals, []),
+			"opt_access: nonempty SubChosenLvals"),
+		substitute_lval_in_instr_until_defn(ChosenLval, TempLval,
+			[Instr0 | TailInstrs0], Instrs1, 0, NumReplacements),
+		set__insert(AlreadyTried0, ChosenLval, AlreadyTried1),
+		( NumReplacements >= AccessThreshold ->
+			TempAssign = assign(TempLval, lval(ChosenLval))
+				- "factor out common sub lval",
+			Instrs2 = [TempAssign | Instrs1],
+			opt_access(Instrs2, Instrs, TempCounter1, TempCounter,
+				NumRealRRegs, AlreadyTried1, AccessThreshold)
+		; ChooseableRvals = [_ | _] ->
+			opt_access([Instr0 | TailInstrs0], Instrs,
+				TempCounter0, TempCounter,
+				NumRealRRegs, AlreadyTried1, AccessThreshold)
+		;
+			opt_access(TailInstrs0, TailInstrs,
+				TempCounter0, TempCounter,
+				NumRealRRegs, set__init, AccessThreshold),
+			Instrs = [Instr0 | TailInstrs]
+		)
+	;
+		opt_access(TailInstrs0, TailInstrs,
+			TempCounter0, TempCounter,
+			NumRealRRegs, set__init, AccessThreshold),
+		Instrs = [Instr0 | TailInstrs]
+	).
+
+%-----------------------------------------------------------------------------%
+
+:- pred base_lval_worth_replacing(int::in, lval::in) is semidet.
+
+base_lval_worth_replacing(NumRealRRegs, Lval) :-
+	(
+		Lval = reg(r, RegNum),
+		RegNum > NumRealRRegs
+	;
+		Lval = stackvar(_)
+	;
+		Lval = framevar(_)
+	).
+
+:- pred base_lval_worth_replacing_not_tried(lvalset::in, int::in, lval::in)
+	is semidet.
+
+base_lval_worth_replacing_not_tried(AlreadyTried, NumRealRRegs, Lval) :-
+	\+ set__member(Lval, AlreadyTried),
+	base_lval_worth_replacing(NumRealRRegs, Lval).
+
+%-----------------------------------------------------------------------------%
 
 	% When processing substituting e.g. tempr1 for e.g. r2
 	% in the instruction that defines r2, we must be careful
Index: compiler/var_locn.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/var_locn.m,v
retrieving revision 1.4
diff -u -b -r1.4 var_locn.m
--- compiler/var_locn.m	6 Mar 2001 05:51:25 -0000	1.4
+++ compiler/var_locn.m	8 Mar 2002 04:00:47 -0000
@@ -19,7 +19,7 @@
 
 :- interface.
 
-:- import_module prog_data, hlds_goal, llds, options.
+:- import_module prog_data, hlds_llds, llds, options.
 :- import_module bool, map, set, list, assoc_list, std_util.
 
 :- type var_locn_info.
@@ -56,12 +56,14 @@
 :- pred var_locn__reinit_state(assoc_list(prog_var, lval)::in,
 	var_locn_info::in, var_locn_info::out) is det.
 
-%	var_locn__clobber_all_regs(VarLocnInfo0, VarLocnInfo)
+%	var_locn__clobber_all_regs(OkToDeleteAny, VarLocnInfo0, VarLocnInfo)
 %		Modifies the state VarLocnInfo0 to produce VarLocnInfo
 %		in which all variables stored in registers are clobbered.
+%		Aborts if this deletes the last record of the state of a
+%		variable unless OkToDeleteAny is `yes'.
 
-:- pred var_locn__clobber_all_regs(var_locn_info::in, var_locn_info::out)
-	is det.
+:- pred var_locn__clobber_all_regs(bool::in,
+	var_locn_info::in, var_locn_info::out) is det.
 
 %	var_locn__clobber_regs(Regs, VarLocnInfo0, VarLocnInfo)
 %		Modifies the state VarLocnInfo0 to produce VarLocnInfo
@@ -481,13 +483,8 @@
 			State = state(NewLocs, no, no, Using, alive),
 			map__det_insert(VarStateMap0, Var, State, VarStateMap1)
 		),
-		( map__search(LocVarMap0, Lval, OldVars) ->
-			set__insert(OldVars, Var, NewVars),
-			map__det_update(LocVarMap0, Lval, NewVars, LocVarMap1)
-		;
-			set__singleton_set(NewVars, Var),
-			map__det_insert(LocVarMap0, Lval, NewVars, LocVarMap1)
-		)
+		var_locn__make_var_depend_on_lval_roots(Var, Lval,
+			LocVarMap0, LocVarMap1)
 	),
 	var_locn__init_state_2(Rest, MaybeLiveness, VarStateMap1, VarStateMap,
 		LocVarMap1, LocVarMap).
@@ -509,7 +506,7 @@
 
 %----------------------------------------------------------------------------%
 
-var_locn__clobber_all_regs -->
+var_locn__clobber_all_regs(OkToDeleteAny) -->
 	{ set__init(Acquired) },
 	var_locn__set_acquired(Acquired),
 	var_locn__set_locked(0),
@@ -517,8 +514,8 @@
 	var_locn__get_loc_var_map(LocVarMap0),
 	var_locn__get_var_state_map(VarStateMap0),
 	{ map__keys(LocVarMap0, Locs) },
-	{ var_locn__clobber_regs_in_maps(Locs, LocVarMap0, LocVarMap,
-		VarStateMap0, VarStateMap) },
+	{ var_locn__clobber_regs_in_maps(Locs, OkToDeleteAny,
+		LocVarMap0, LocVarMap, VarStateMap0, VarStateMap) },
 	var_locn__set_loc_var_map(LocVarMap),
 	var_locn__set_var_state_map(VarStateMap).
 
@@ -528,42 +525,44 @@
 	var_locn__set_acquired(Acquired),
 	var_locn__get_loc_var_map(LocVarMap0),
 	var_locn__get_var_state_map(VarStateMap0),
-	{ var_locn__clobber_regs_in_maps(Regs, LocVarMap0, LocVarMap,
-		VarStateMap0, VarStateMap) },
+	{ var_locn__clobber_regs_in_maps(Regs, no,
+		LocVarMap0, LocVarMap, VarStateMap0, VarStateMap) },
 	var_locn__set_loc_var_map(LocVarMap),
 	var_locn__set_var_state_map(VarStateMap).
 
-:- pred var_locn__clobber_regs_in_maps(list(lval)::in,
+:- pred var_locn__clobber_regs_in_maps(list(lval)::in, bool::in,
 	loc_var_map::in, loc_var_map::out,
 	var_state_map::in, var_state_map::out) is det.
 
-var_locn__clobber_regs_in_maps([], LocVarMap, LocVarMap,
+var_locn__clobber_regs_in_maps([], _, LocVarMap, LocVarMap,
 		VarStateMap, VarStateMap).
-var_locn__clobber_regs_in_maps([Lval | Lvals], LocVarMap0, LocVarMap,
-		VarStateMap0, VarStateMap) :-
+var_locn__clobber_regs_in_maps([Lval | Lvals], OkToDeleteAny,
+		LocVarMap0, LocVarMap, VarStateMap0, VarStateMap) :-
 	(
 		Lval = reg(_, _),
 		map__search(LocVarMap0, Lval, DependentVarsSet)
 	->
 		map__delete(LocVarMap0, Lval, LocVarMap1),
 		set__to_sorted_list(DependentVarsSet, DependentVars),
-		list__foldl(var_locn__clobber_lval_in_var_state_map(Lval, []),
+		list__foldl(var_locn__clobber_lval_in_var_state_map(Lval, [],
+			OkToDeleteAny),
 			DependentVars, VarStateMap0, VarStateMap1)
 	;
 		LocVarMap1 = LocVarMap0,
 		VarStateMap1 = VarStateMap0
 	),
-	var_locn__clobber_regs_in_maps(Lvals, LocVarMap1, LocVarMap,
-		VarStateMap1, VarStateMap).
+	var_locn__clobber_regs_in_maps(Lvals, OkToDeleteAny,
+		LocVarMap1, LocVarMap, VarStateMap1, VarStateMap).
 
 :- pred var_locn__clobber_lval_in_var_state_map(lval::in, list(prog_var)::in,
-	prog_var::in, var_state_map::in, var_state_map::out) is det.
+	bool::in, prog_var::in, var_state_map::in, var_state_map::out) is det.
 
-var_locn__clobber_lval_in_var_state_map(Lval, OkToDeleteVars, Var,
-		VarStateMap0, VarStateMap) :-
+var_locn__clobber_lval_in_var_state_map(Lval, OkToDeleteVars, OkToDeleteAny,
+		Var, VarStateMap0, VarStateMap) :-
 	(
 		var_locn__try_clobber_lval_in_var_state_map(Lval,
-			OkToDeleteVars, Var, VarStateMap0, VarStateMap1)
+			OkToDeleteVars, OkToDeleteAny, Var,
+			VarStateMap0, VarStateMap1)
 	->
 		VarStateMap = VarStateMap1
 	;
@@ -575,11 +574,11 @@
 % Var can be found, and Var is not in OkToDeleteVars, then fail.
 
 :- pred var_locn__try_clobber_lval_in_var_state_map(lval::in,
-	list(prog_var)::in, prog_var::in,
+	list(prog_var)::in, bool::in, prog_var::in,
 	var_state_map::in, var_state_map::out) is semidet.
 
-var_locn__try_clobber_lval_in_var_state_map(Lval, OkToDeleteVars, Var,
-		VarStateMap0, VarStateMap) :-
+var_locn__try_clobber_lval_in_var_state_map(Lval, OkToDeleteVars,
+		OkToDeleteAny, Var, VarStateMap0, VarStateMap) :-
 	map__lookup(VarStateMap0, Var, State0),
 	State0 = state(LvalSet0, MaybeConstRval, MaybeExprRval, Using,
 		DeadOrAlive),
@@ -592,6 +591,8 @@
 	;
 		list__member(Var, OkToDeleteVars)
 	;
+		OkToDeleteAny = yes
+	;
 		DeadOrAlive = dead,
 		set__to_sorted_list(Using, UsingVars),
 		var_locn__recursive_using_vars_dead_and_ok_to_delete(UsingVars,
@@ -1016,8 +1017,8 @@
 
 	var_locn__get_loc_var_map(LocVarMap0),
 	var_locn__get_var_state_map(VarStateMap0),
-	{ var_locn__clobber_regs_in_maps([reg(r, 1)], LocVarMap0, LocVarMap,
-		VarStateMap0, VarStateMap) },
+	{ var_locn__clobber_regs_in_maps([reg(r, 1)], no,
+		LocVarMap0, LocVarMap, VarStateMap0, VarStateMap) },
 	var_locn__set_loc_var_map(LocVarMap),
 	var_locn__set_var_state_map(VarStateMap).
 
@@ -1128,7 +1129,7 @@
 		var_locn__get_var_state_map(VarStateMap2),
 		{ list__foldl(
 			var_locn__clobber_lval_in_var_state_map(Target,
-				Assigns),
+				Assigns, no),
 			DependentVars, VarStateMap2, VarStateMap) },
 		var_locn__set_var_state_map(VarStateMap)
 	;
@@ -1163,7 +1164,7 @@
 		var_locn__get_var_state_map(VarStateMap0),
 		\+ { list__foldl(
 			var_locn__try_clobber_lval_in_var_state_map(
-				Lval, ToBeAssignedVars),
+				Lval, ToBeAssignedVars, no),
 			AffectedVars, VarStateMap0, _) }
 	->
 		var_locn__free_up_lval_with_copy(Lval, ToBeAssignedVars,
cvs diff: Diffing compiler/notes
Index: compiler/notes/allocation.html
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/notes/allocation.html,v
retrieving revision 1.3
diff -u -b -r1.3 allocation.html
--- compiler/notes/allocation.html	30 Oct 1997 08:33:01 -0000	1.3
+++ compiler/notes/allocation.html	13 Sep 2001 00:31:30 -0000
@@ -154,16 +154,24 @@
 
 <p>
 
-We handle these by including a store_map field to if_then_else, switch and disj
-goal expressions (this field used to be called the follow_vars field). This
-field is ignored through most of the compilation process; it is meaningful
-only from the follow_vars pass onwards.
+We handle these by including a store_map field in the goal_infos of
+if_then_else, switch and disj goals.
+This field, like most other goal_info fields
+we will talk about in the rest of this document,
+is a subfield of the code_gen_info field of the goal_info.
+Through most of the compilation process,
+the code_gen_info field contains no information;
+its individual subfields are filled in
+during the various pre-passes of the LLDS code generator.
+The store map subfield
+it is meaningful only from the follow_vars pass onwards.
 
 <p>
 
-The follow_vars pass fills these fields with advisory information, saying
-where things that will be used in code following the branched structure
-should be. This advisory information may include duplicates (two variables
+The follow_vars pass fills this field of goals representing branched control
+structures with advisory information, saying where things that will be used
+in code following the branched structure should be.
+This advisory information may include duplicates (two variables
 mapped to the same location), it may miss some variables that are live at
 the end of the branched structure, and it may include variables that are
 not live at that point.
@@ -209,9 +217,10 @@
 
 <p>
 
-We handle these through the resume_point field in goal infos. During the
-liveness pass, we fill in this field for every goal that establishes
-a point at which execution may resume after backtracking. This means
+We handle these through the resume_point subfield of the code_gen_info field
+in goal infos. During the liveness pass, we fill in this field for every goal
+that establishes a point at which execution may resume after backtracking.
+This means
 the conditions of if-then-elses (the resumption point is the start of
 the else part), every disjunct in a disjunction except the last (the
 resumption point is the start of the next disjunct), and goals inside
Index: compiler/notes/compiler_design.html
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/notes/compiler_design.html,v
retrieving revision 1.71
diff -u -b -r1.71 compiler_design.html
--- compiler/notes/compiler_design.html	4 Mar 2002 07:31:38 -0000	1.71
+++ compiler/notes/compiler_design.html	8 Mar 2002 04:05:08 -0000
@@ -653,12 +653,25 @@
 			in the HLDS goal_info.
 		<dt> allocation of stack slots
 			<dd>
-			This is done by live_vars.m, which works
-			out which variables need to be saved on the
-			stack when (trace.m determines what variables
-			are needed for debugging purposes).
-			It then uses graph_colour.m to determine
-			a good allocation of variables to stack slots.
+			This is done by stack_alloc.m, with the assistance of
+			the following modules:
+
+			<ul>
+			<li> live_vars.m works out which variables need
+			to be saved on the stack when.
+			<li> trace_params.m determines what fixed slots
+			are needed for debugging purposes.
+			<li> trace.m determines what variables
+			are needed for debugging purposes.
+			<li> stack_opt.m figures out when variable A can be
+			reached from a cell pointed to by variable B,
+			so that storing variable B on the stack obviates
+			the need to store variable A on the stack as well.
+			<li> graph_colour.m contains the algorithm that
+			stack_alloc.m calls to convert sets of variables
+			that must be saved on the stack at the same time
+			to an assignment of a stack slot to each such variable.
+			</ul>
 		<dt> migration of builtins following branched structures
 			<dd>
 			This transformation, which is performed by
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.299
diff -u -b -r1.299 user_guide.texi
--- doc/user_guide.texi	8 Mar 2002 04:03:41 -0000	1.299
+++ doc/user_guide.texi	8 Mar 2002 04:05:13 -0000
@@ -5146,8 +5146,7 @@
 @sp 1
 @item --optimize-saved-vars
 @findex --optimize-saved-vars
-Reorder goals to minimize the number of variables
-that have to be saved across calls.
+Minimize the number of variables that have to be saved across calls.
 
 @sp 1
 @item --deforestation
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing java
cvs diff: Diffing java/library
cvs diff: Diffing java/runtime
cvs diff: Diffing library
Index: library/exception.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/exception.m,v
retrieving revision 1.58
diff -u -b -r1.58 exception.m
--- library/exception.m	18 Feb 2002 07:01:03 -0000	1.58
+++ library/exception.m	19 Feb 2002 04:54:13 -0000
@@ -1966,7 +1966,7 @@
 		MR_tailcall(MR_ENTRY(mercury__do_call_closure), 
 			MR_ENTRY(mercury__exception__builtin_throw_1_0));
 	}
-	MR_incr_sp_push_msg(1, ""builtin_throw/1"");
+	MR_incr_sp_push_msg(1, ""pred builtin_throw/1"");
 	MR_stackvar(1) = (MR_Word) MR_succip;
 	MR_call(MR_ENTRY(mercury__do_call_closure), 
 		MR_LABEL(mercury__exception__builtin_throw_1_0_i1),
Index: library/tree234.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/tree234.m,v
retrieving revision 1.34
diff -u -b -r1.34 tree234.m
--- library/tree234.m	12 Nov 2000 08:51:38 -0000	1.34
+++ library/tree234.m	13 Dec 2001 00:35:41 -0000
@@ -270,89 +270,71 @@
 		T = empty,
 		fail
 	;
-		T = two(K0, _, _, _),
+		T = two(K0, V0, T0, T1),
 		compare(Result, K, K0),
 		(
 			Result = (<),
-			T = two(_, _, T0, _),
 			tree234__search(T0, K, V)
 		;
 			Result = (=),
-			T = two(_, V0, _, _),
 			V = V0
 		;
 			Result = (>),
-			T = two(_, _, _, T1),
 			tree234__search(T1, K, V)
 		)
 	;
-		T = three(K0, _, _, _, _, _, _),
+		T = three(K0, V0, K1, V1, T0, T1, T2),
 		compare(Result0, K, K0),
 		(
 			Result0 = (<),
-			T = three(_, _, _, _, T0, _, _),
 			tree234__search(T0, K, V)
 		;
 			Result0 = (=),
-			T = three(_, V0, _, _, _, _, _),
 			V = V0
 		;
 			Result0 = (>),
-			T = three(_, _, K1, _, _, _, _),
 			compare(Result1, K, K1),
 			(
 				Result1 = (<),
-				T = three(_, _, _, _, _, T1, _),
 				tree234__search(T1, K, V)
 			;
 				Result1 = (=),
-				T = three(_, _, _, V1, _, _, _),
 				V = V1
 			;
 				Result1 = (>),
-				T = three(_, _, _, _, _, _, T2),
 				tree234__search(T2, K, V)
 			)
 		)
 	;
-		T = four(_, _, K1, _, _, _, _, _, _, _),
+		T = four(K0, V0, K1, V1, K2, V2, T0, T1, T2, T3),
 		compare(Result1, K, K1),
 		(
 			Result1 = (<),
-			T = four(K0, _, _, _, _, _, _, _, _, _),
 			compare(Result0, K, K0),
 			(
 				Result0 = (<),
-				T = four(_, _, _, _, _, _, T0, _, _, _),
 				tree234__search(T0, K, V)
 			;
 				Result0 = (=),
-				T = four(_, V0, _, _, _, _, _, _, _, _),
 				V = V0
 			;
 				Result0 = (>),
-				T = four(_, _, _, _, _, _, _, T1, _, _),
 				tree234__search(T1, K, V)
 			)
 		;
 			Result1 = (=),
-			T = four(_, _, _, V1, _, _, _, _, _, _),
 			V = V1
 		;
 			Result1 = (>),
-			T = four(_, _, _, _, K2, _, _, _, _, _),
 			compare(Result2, K, K2),
 			(
 				Result2 = (<),
-				T = four(_, _, _, _, _, _, _, _, T2, _),
 				tree234__search(T2, K, V)
 			;
 				Result2 = (=),
-				T = four(_, _, _, _, _, V2, _, _, _, _),
 				V = V2
 			;
 				Result2 = (>),
-				T = four(_, _, _, _, _, _, _, _, _, T3),
 				tree234__search(T3, K, V)
 			)
 		)
@@ -372,20 +354,17 @@
 		T = empty,
 		fail
 	;
-		T = two(K0, _, _, _),
+		T = two(K0, V0, T0, T1),
 		compare(Result, SearchK, K0),
 		(
 			Result = (<),
-			T = two(_, _, T0, _),
 			tree234__lower_bound_search(T0, SearchK, K, V)
 		;
 			Result = (=),
-			T = two(_, V0, _, _),
 			K = SearchK,
 			V = V0
 		;
 			Result = (>),
-			T = two(_, _, _, T1),
 			( tree234__lower_bound_search(T1, SearchK, Kp, Vp) ->
 				K = Kp,
 				V = Vp
@@ -396,24 +375,20 @@
 			)
 		)
 	;
-		T = three(K0, _, _, _, _, _, _),
+		T = three(K0, V0, K1, V1, T0, T1, T2),
 		compare(Result0, SearchK, K0),
 		(
 			Result0 = (<),
-			T = three(_, _, _, _, T0, _, _),
 			tree234__lower_bound_search(T0, SearchK, K, V)
 		;
 			Result0 = (=),
-			T = three(_, V0, _, _, _, _, _),
 			K = SearchK,
 			V = V0
 		;
 			Result0 = (>),
-			T = three(_, _, K1, _, _, _, _),
 			compare(Result1, SearchK, K1),
 			(
 				Result1 = (<),
-				T = three(_, _, _, _, _, T1, _),
 				( tree234__lower_bound_search(T1, SearchK,
 					Kp, Vp)
 				-> 
@@ -426,91 +401,76 @@
 				)
 			;
 				Result1 = (=),
-				T = three(_, _, _, V1, _, _, _),
 				K = SearchK,
 				V = V1
 			;
 				Result1 = (>),
-				T = three(_, _, _, _, _, _, T2),
 				( tree234__lower_bound_search(T2, SearchK,
 					Kp, Vp)
 				-> 
 					K = Kp,
 					V = Vp
 				;
-					T = three(_, _, _, V1, _, _, _),
 					K = K1,
 					V = V1
 				)
 			)
 		)
 	;
-		T = four(_, _, K1, _, _, _, _, _, _, _),
+		T = four(K0, V0, K1, V1, K2, V2, T0, T1, T2, T3),
 		compare(Result1, SearchK, K1),
 		(
 			Result1 = (<),
-			T = four(K0, _, _, _, _, _, _, _, _, _),
 			compare(Result0, SearchK, K0),
 			(
 				Result0 = (<),
-				T = four(_, _, _, _, _, _, T0, _, _, _),
 				tree234__lower_bound_search(T0, SearchK, K, V)
 			;
 				Result0 = (=),
-				T = four(_, V0, _, _, _, _, _, _, _, _),
 				K = SearchK,
 				V = V0
 			;
 				Result0 = (>),
-				T = four(_, _, _, _, _, _, _, T1, _, _),
 				( tree234__lower_bound_search(T1, SearchK,
 					Kp, Vp)
 				-> 
 					K = Kp,
 					V = Vp
 				;
-					T = four(_, V0, _, _, _, _, _, _, _, _),
 					K = K0,
 					V = V0
 				)
 			)
 		;
 			Result1 = (=),
-			T = four(_, _, _, V1, _, _, _, _, _, _),
 			K = SearchK,
 			V = V1
 		;
 			Result1 = (>),
-			T = four(_, _, _, _, K2, _, _, _, _, _),
 			compare(Result2, SearchK, K2),
 			(
 				Result2 = (<),
-				T = four(_, _, _, _, _, _, _, _, T2, _),
 				( tree234__lower_bound_search(T2, SearchK,
 					Kp, Vp)
 				-> 
 					K = Kp,
 					V = Vp
 				;
-					T = four(_, _, _, V1, _, _, _, _, _, _),
 					K = K1,
 					V = V1
 				)
 			;
 				Result2 = (=),
-				T = four(_, _, _, _, _, V2, _, _, _, _),
 				K = SearchK,
 				V = V2
 			;
 				Result2 = (>),
-				T = four(_, _, _, _, _, _, _, _, _, T3),
 				( tree234__lower_bound_search(T3, SearchK,
 					Kp, Vp)
 				-> 
 					K = Kp,
 					V = Vp
 				;
-					T = four(_, _, _, _, _, V2, _, _, _, _),
 					K = K2,
 					V = V2
 				)
@@ -534,11 +494,10 @@
 		T = empty,
 		fail
 	;
-		T = two(K0, _, _, _),
+		T = two(K0, V0, T0, T1),
 		compare(Result, SearchK, K0),
 		(
 			Result = (<),
-			T = two(_, _, T0, _),
 			( tree234__upper_bound_search(T0, SearchK, Kp, Vp) -> 
 				K = Kp,
 				V = Vp
@@ -549,130 +508,108 @@
 			)
 		;
 			Result = (=),
-			T = two(_, V0, _, _),
 			K = SearchK,
 			V = V0
 		;
 			Result = (>),
-			T = two(_, _, _, T1),
 			tree234__upper_bound_search(T1, SearchK, K, V)
 		)
 	;
-		T = three(K0, _, _, _, _, _, _),
+		T = three(K0, V0, K1, V1, T0, T1, T2),
 		compare(Result0, SearchK, K0),
 		(
 			Result0 = (<),
-			T = three(_, _, _, _, T0, _, _),
 			( tree234__upper_bound_search(T0, SearchK, Kp, Vp) ->
 				K = Kp,
 				V = Vp
 			;
-				T = three(_, V0, _, _, _, _, _),
 				K = K0,
 				V = V0
 			)
 		;
 			Result0 = (=),
-			T = three(_, V0, _, _, _, _, _),
 			K = SearchK,
 			V = V0
 		;
 			Result0 = (>),
-			T = three(_, _, K1, _, _, _, _),
 			compare(Result1, SearchK, K1),
 			(
 				Result1 = (<),
-				T = three(_, _, _, _, _, T1, _),
 				( tree234__upper_bound_search(T1, SearchK,
 					Kp, Vp)
 				->
 					K = Kp,
 					V = Vp
 				;
-					T = three(_, _, _, V1, _, _, _),
 					K = K1,
 					V = V1
 				)
 			;
 				Result1 = (=),
-				T = three(_, _, _, V1, _, _, _),
 				K = SearchK,
 				V = V1
 			;
 				Result1 = (>),
-				T = three(_, _, _, _, _, _, T2),
 				tree234__upper_bound_search(T2, SearchK, K, V)
 			)
 		)
 	;
-		T = four(_, _, K1, _, _, _, _, _, _, _),
+		T = four(K0, V0, K1, V1, K2, V2, T0, T1, T2, T3),
 		compare(Result1, SearchK, K1),
 		(
 			Result1 = (<),
-			T = four(K0, _, _, _, _, _, _, _, _, _),
 			compare(Result0, SearchK, K0),
 			(
 				Result0 = (<),
-				T = four(_, _, _, _, _, _, T0, _, _, _),
 				( tree234__upper_bound_search(T0, SearchK,
 					Kp, Vp)
 				->
 					K = Kp,
 					V = Vp
 				;
-					T = four(_, V0, _, _, _, _, _, _, _, _),
 					K = K0,
 					V = V0
 				)
 			;
 				Result0 = (=),
-				T = four(_, V0, _, _, _, _, _, _, _, _),
 				K = SearchK,
 				V = V0
 			;
 				Result0 = (>),
-				T = four(_, _, _, _, _, _, _, T1, _, _),
 				( tree234__upper_bound_search(T1, SearchK,
 					Kp, Vp)
 				->
 					K = Kp,
 					V = Vp
 				;
-					T = four(_, _, _, V1, _, _, _, _, _, _),
 					K = K1,
 					V = V1
 				)
 			)
 		;
 			Result1 = (=),
-			T = four(_, _, _, V1, _, _, _, _, _, _),
 			K = SearchK,
 			V = V1
 		;
 			Result1 = (>),
-			T = four(_, _, _, _, K2, _, _, _, _, _),
 			compare(Result2, SearchK, K2),
 			(
 				Result2 = (<),
-				T = four(_, _, _, _, _, _, _, _, T2, _),
 				( tree234__upper_bound_search(T2, SearchK,
 					Kp, Vp)
 				->
 					K = Kp,
 					V = Vp
 				;
-					T = four(_, _, _, _, _, V2, _, _, _, _),
 					K = K2,
 					V = V2
 				)
 			;
 				Result2 = (=),
-				T = four(_, _, _, _, _, V2, _, _, _, _),
 				K = SearchK,
 				V = V2
 			;
 				Result2 = (>),
-				T = four(_, _, _, _, _, _, _, _, _, T3),
 				tree234__upper_bound_search(T3, SearchK, K, V)
 			)
 		)
@@ -694,112 +631,85 @@
 		Tin = empty,
 		fail
 	;
-		Tin = two(K0, _, _, _),
+		Tin = two(K0, V0, T0, T1),
 		compare(Result, K, K0),
 		(
 			Result = (<),
-			Tin = two(_, _, T0, _),
 			tree234__update(T0, K, V, NewT0),
-			Tin = two(_, V0, _, T1),
 			Tout = two(K0, V0, NewT0, T1)
 		;
 			Result = (=),
-			Tin = two(_, _, T0, T1),
 			Tout = two(K0, V, T0, T1)
 		;
 			Result = (>),
-			Tin = two(_, _, _, T1),
 			tree234__update(T1, K, V, NewT1),
-			Tin = two(_, V0, T0, _),
 			Tout = two(K0, V0, T0, NewT1)
 		)
 	;
-		Tin = three(K0, _, _, _, _, _, _),
+		Tin = three(K0, V0, K1, V1, T0, T1, T2),
 		compare(Result0, K, K0),
 		(
 			Result0 = (<),
-			Tin = three(_, _, _, _, T0, _, _),
 			tree234__update(T0, K, V, NewT0),
-			Tin = three(_, V0, K1, V1, _, T1, T2),
 			Tout = three(K0, V0, K1, V1, NewT0, T1, T2)
 		;
 			Result0 = (=),
-			Tin = three(_, _, K1, V1, T0, T1, T2),
 			Tout = three(K0, V, K1, V1, T0, T1, T2)
 		;
 			Result0 = (>),
-			Tin = three(_, _, K1, _, _, _, _),
 			compare(Result1, K, K1),
 			(
 				Result1 = (<),
-				Tin = three(_, _, _, _, _, T1, _),
 				tree234__update(T1, K, V, NewT1),
-				Tin = three(_, V0, _, V1, T0, _, T2),
 				Tout = three(K0, V0, K1, V1, T0, NewT1, T2)
 			;
 				Result1 = (=),
-				Tin = three(_, V0, _, _, T0, T1, T2),
 				Tout = three(K0, V0, K1, V, T0, T1, T2)
 			;
 				Result1 = (>),
-				Tin = three(_, _, _, _, _, _, T2),
 				tree234__update(T2, K, V, NewT2),
-				Tin = three(_, V0, _, V1, T0, T1, _),
 				Tout = three(K0, V0, K1, V1, T0, T1, NewT2)
 			)
 		)
 	;
-		Tin = four(_, _, K1, _, _, _, _, _, _, _),
+		Tin = four(K0, V0, K1, V1, K2, V2, T0, T1, T2, T3),
 		compare(Result1, K, K1),
 		(
 			Result1 = (<),
-			Tin = four(K0, _, _, _, _, _, _, _, _, _),
 			compare(Result0, K, K0),
 			(
 				Result0 = (<),
-				Tin = four(_, _, _, _, _, _, T0, _, _, _),
 				tree234__update(T0, K, V, NewT0),
-				Tin = four(_, V0, _, V1, K2, V2, _, T1, T2, T3),
 				Tout = four(K0, V0, K1, V1, K2, V2,
 					NewT0, T1, T2, T3)
 			;
 				Result0 = (=),
-				Tin = four(_, _, _, V1, K2, V2, T0, T1, T2, T3),
 				Tout = four(K0, V, K1, V1, K2, V2,
 					T0, T1, T2, T3)
 			;
 				Result0 = (>),
-				Tin = four(_, _, _, _, _, _, _, T1, _, _),
 				tree234__update(T1, K, V, NewT1),
-				Tin = four(_, V0, _, V1, K2, V2, T0, _, T2, T3),
 				Tout = four(K0, V0, K1, V1, K2, V2,
 					T0, NewT1, T2, T3)
 			)
 		;
 			Result1 = (=),
-			Tin = four(K0, V0, _, _, K2, V2, T0, T1, T2, T3),
 			Tout = four(K0, V0, K1, V, K2, V2, T0, T1, T2, T3)
 		;
 			Result1 = (>),
-			Tin = four(_, _, _, _, K2, _, _, _, _, _),
 			compare(Result2, K, K2),
 			(
 				Result2 = (<),
-				Tin = four(_, _, _, _, _, _, _, _, T2, _),
 				tree234__update(T2, K, V, NewT2),
-				Tin = four(K0, V0, _, V1, _, V2, T0, T1, _, T3),
 				Tout = four(K0, V0, K1, V1, K2, V2,
 					T0, T1, NewT2, T3)
 			;
 				Result2 = (=),
-				Tin = four(K0, V0, _, V1, _, _, T0, T1, T2, T3),
 				Tout = four(K0, V0, K1, V1, K2, V,
 					T0, T1, T2, T3)
 			;
 				Result2 = (>),
-				Tin = four(_, _, _, _, _, _, _, _, _, T3),
 				tree234__update(T3, K, V, NewT3),
-				Tin = four(K0, V0, _, V1, _, V2, T0, T1, T2, _),
 				Tout = four(K0, V0, K1, V1, K2, V2,
 					T0, T1, T2, NewT3)
 			)
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
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/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
Index: tools/compare_sp
===================================================================
RCS file: tools/compare_sp
diff -N tools/compare_sp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tools/compare_sp	19 Feb 2002 08:33:00 -0000
@@ -0,0 +1,77 @@
+#!/usr/bin/awk -f
+#
+# This file is the heart of the compare_stacks. It is not intended
+# for use from the command line.
+$1 == "XYZZY" {
+		base = $2 "";
+		new = $3 "";
+		next;
+	}
+	{
+		if (NF != 5) {
+			printf "error: NF != 5\n"
+			printf "%s\n", $0;
+			next;
+		}
+
+		batch = $1 "";
+		proc = $3 " " $4 " " $5;
+		framesize = $2;
+
+		if (batch != base && batch != new) {
+			printf "error: unknown batch %s (%s %s)\n", batch, base, new;
+			next;
+		}
+
+
+		repcount = count[batch "@" proc];
+		count[batch "@" proc] = repcount + 1;
+
+		if (repcount > 0) {
+			repcount++;
+			proc = proc "#" repcount;
+		}
+
+		procs[proc] = 1;
+
+		sizes[batch "@" proc] = framesize;
+		exist[batch "@" proc] = 1;
+	}
+
+END	{
+		basetotal  = 0;
+		newtotal   = 0;
+		proccount  = 0;
+		basebetter = 0;
+		newbetter  = 0;
+
+		for (proc in procs) {
+			if (exist[base "@" proc] == 1 && exist[new "@" proc] == 1) {
+				basesize = sizes[base "@" proc];
+				newsize  = sizes[new  "@" proc];
+				basetotal += basesize;
+				newtotal  += newsize;
+				proccount += 1;
+
+				if (basesize < newsize) {
+					basebetter += 1;
+					worsened = worsened proc "	" basesize "->" newsize "\n"
+				} else if (basesize > newsize) {
+					newbetter  += 1;
+					improved = improved proc "	" basesize "->" newsize "\n"
+				}
+			} else {
+				printf "error: mismatch for %s\n", proc;
+			}
+		}
+
+		printf "base slots: %5d, %5.2f, %6.2f\n", basetotal, basetotal / proccount, 100;
+		printf "new  slots: %5d, %5.2f, %6.2f\n", newtotal, newtotal / proccount, 100 * newtotal / basetotal;
+		printf "number of procedures: %d\n", proccount;
+		printf "base better: %d, %5.2f\n", basebetter, 100 * basebetter  / proccount;
+		printf "new  better: %d, %5.2f\n", newbetter, 100 * newbetter  / proccount;
+		printf "\n";
+		printf "improved:\n%s", improved;
+		printf "\n";
+		printf "worsened:\n%s", worsened;
+	}
Index: tools/compare_stacks
===================================================================
RCS file: tools/compare_stacks
diff -N tools/compare_stacks
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tools/compare_stacks	19 Feb 2002 08:33:21 -0000
@@ -0,0 +1,11 @@
+#!/bin/sh
+#
+# XXX
+
+if test $# -ne 3
+then
+	echo "Usage: compare_stacks batchname base_version compare_version"
+	exit 1
+fi
+
+( echo XYZZY $2 $3; cat SP.$1.$2 SP.$1.$3 ) | compare_sp
Index: tools/extract_incr_sp
===================================================================
RCS file: tools/extract_incr_sp
diff -N tools/extract_incr_sp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tools/extract_incr_sp	31 Dec 2001 05:32:06 -0000
@@ -0,0 +1,55 @@
+#!/usr/bin/awk -f
+
+$1 == "EXTRACT_INCR_SP"		{
+					version = $2;
+					next;
+				}
+$1 == "MR_BEGIN_CODE"		{
+					in_valid_range = 1;
+					next;
+				}
+$1 == "MR_END_CODE"		{
+					in_valid_range = 0;
+					next;
+				}
+$1 ~ "MR_incr_sp_push_msg\(.*"	{
+					gsub(" = ", "=", $0);
+					if (in_valid_range) {
+						size = $1;
+						pf = $2;
+						name = $3;
+						gsub("MR_incr_sp_push_msg\(",
+							"", size);
+						gsub("[\"\(\),; ]", "", size);
+						gsub("[\"\(\),; ]", "", pf);
+						gsub("[\"\(\),; ]", "", name);
+
+						printf "%s %2d det %s %s\n",
+							version,
+							size, pf, name;
+
+						# frameopt can duplicate
+						# the procedure prologue
+						in_valid_range = 0;
+					}
+				}
+$1 ~ "MR_mkframe\(.*"		{
+					gsub(" = ", "=", $0);
+					if (in_valid_range) {
+						pf = $1;
+						name = $2;
+						size = $3;
+						gsub("MR_mkframe\(", "", pf);
+						gsub("[\"\(\),; ]", "", pf);
+						gsub("[\"\(\),; ]", "", name);
+						gsub("[\"\(\),; ]", "", size);
+
+						printf "%s %2d non %s %s\n",
+							version,
+							size + 5, pf, name;
+
+						# frameopt can duplicate
+						# the procedure prologue
+						in_valid_range = 0;
+					}
+				}
Index: tools/sum_incr_sp
===================================================================
RCS file: tools/sum_incr_sp
diff -N tools/sum_incr_sp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tools/sum_incr_sp	31 Dec 2001 05:32:06 -0000
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+if test $# -lt 1
+then
+	echo "Usage: sum_incr_sp batchname ..."
+	exit 1
+fi
+
+for prefix in $@
+do
+	n=1
+	n2=`two_digit $n`
+	while test -d $prefix.library.$n2
+	do
+		echo "creating SP.$prefix.$n2"
+		gunzip $prefix.library.$n2/*.c.gz $prefix.compiler.$n2/*.c.gz > /dev/null 2>&1
+		( echo EXTRACT_INCR_SP $n2 ; cat $prefix.library.$n2/*.c $prefix.compiler.$n2/*.c ) | extract_incr_sp > SP.$prefix.$n2
+		gzip $prefix.library.$n2/*.c $prefix.compiler.$n2/*.c > /dev/null 2>&1
+		n=`expr $n + 1`
+		n2=`two_digit $n`
+	done
+done
cvs diff: Diffing trace
cvs diff: Diffing util
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list