[m-rev.] for review: preserve contexts during specialization

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon Dec 31 17:12:41 AEDT 2001


For review by anyone.

When optimizing type-specific unifications and comparisons, preserve the
contexts of the transformed goals, since deep profiling may need them.

compiler/higher_order.m:
	Preserve contexts as necessary.

compiler/hlds_goal.m:
	Provide a variant of the predicate that initializes a goal_info
	that also takes a context as input.

cvs diff: Diffing .
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/higher_order.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/higher_order.m,v
retrieving revision 1.91
diff -u -b -r1.91 higher_order.m
--- compiler/higher_order.m	2001/07/31 14:29:29	1.91
+++ compiler/higher_order.m	2001/08/14 02:40:00
@@ -1012,8 +1012,8 @@
 	(
 		% Look for calls to unify/2 and compare/3 which can
 		% be specialized.
-		specialize_special_pred(CalledPred, CalledProc,
-			Args0, MaybeContext, HaveSpecialPreds, Goal1,
+		specialize_special_pred(CalledPred, CalledProc, Args0,
+			MaybeContext, GoalInfo, HaveSpecialPreds, Goal1,
 			Info0, Info1)
 	->
 		Goal = Goal1,
@@ -1854,11 +1854,12 @@
 	% Succeed if the called pred is "unify" or "compare" and
 	% is specializable, returning a specialized goal.
 :- pred specialize_special_pred(pred_id::in, proc_id::in, list(prog_var)::in,
-	maybe(call_unify_context)::in, bool::in, hlds_goal_expr::out,
-	higher_order_info::in, higher_order_info::out) is semidet.
+	maybe(call_unify_context)::in, hlds_goal_info::in, bool::in,
+	hlds_goal_expr::out, higher_order_info::in, higher_order_info::out)
+	is semidet.
 
-specialize_special_pred(CalledPred, CalledProc, Args,
-		MaybeContext, HaveSpecialPreds, Goal, Info0, Info) :-
+specialize_special_pred(CalledPred, CalledProc, Args, MaybeContext,
+		OrigGoalInfo, HaveSpecialPreds, Goal, Info0, Info) :-
 	ModuleInfo = Info0 ^ global_info ^ module_info,
 	ProcInfo0 = Info0 ^ proc_info,
 	PredVars = Info0 ^ pred_vars,
@@ -1939,10 +1940,11 @@
 				Info = Info0
 			;
 				NeedIntCast = yes,
-				generate_unsafe_type_cast(ModuleInfo,
+				goal_info_get_context(OrigGoalInfo, Context),
+				generate_unsafe_type_cast(ModuleInfo, Context,
 					CompareType, Arg1, CastArg1, CastGoal1,
 					ProcInfo0, ProcInfo1),
-				generate_unsafe_type_cast(ModuleInfo,
+				generate_unsafe_type_cast(ModuleInfo, Context,
 					CompareType, Arg2, CastArg2, CastGoal2,
 					ProcInfo1, ProcInfo),
 				NewCallArgs = [ComparisonResult,
@@ -1958,7 +1960,7 @@
 					InstMapDelta),
 				Detism = det,
 				goal_info_init(NonLocals, InstMapDelta,
-					Detism, GoalInfo),
+					Detism, Context, GoalInfo),
 				Goal = conj([CastGoal1, CastGoal2,
 						Call - GoalInfo]),
 				Info = Info0 ^ proc_info := ProcInfo
@@ -1996,9 +1998,10 @@
 			SpecialId = compare,
 			SpecialPredArgs = [_, Arg1, Arg2]
 		),
-		unwrap_no_tag_arg(WrappedType, Constructor, Arg1,
+		goal_info_get_context(OrigGoalInfo, Context),
+		unwrap_no_tag_arg(WrappedType, Context, Constructor, Arg1,
 			UnwrappedArg1, ExtractGoal1, ProcInfo0, ProcInfo1),
-		unwrap_no_tag_arg(WrappedType, Constructor, Arg2,
+		unwrap_no_tag_arg(WrappedType, Context, Constructor, Arg2,
 			UnwrappedArg2, ExtractGoal2, ProcInfo1, ProcInfo2),
 		set__list_to_set([UnwrappedArg1, UnwrappedArg2], NonLocals0),
 		(
@@ -2012,7 +2015,7 @@
 				simple_test(UnwrappedArg1, UnwrappedArg2),
 				unify_context(explicit, [])),
 			goal_info_init(NonLocals, InstMapDelta, Detism,
-				GoalInfo),
+				Context, GoalInfo),
 			Goal = conj([ExtractGoal1, ExtractGoal2,
 					SpecialGoal - GoalInfo]),
 			Info = Info0 ^ proc_info := ProcInfo2
@@ -2039,16 +2042,16 @@
 					SpecialProcId, NewCallArgs,
 					not_builtin, MaybeContext, SymName),
 				goal_info_init(NonLocals, InstMapDelta, Detism,
-					GoalInfo),
+					Context, GoalInfo),
 				Goal = conj([ExtractGoal1, ExtractGoal2,
 						SpecialGoal - GoalInfo]),
 				Info = Info0 ^ proc_info := ProcInfo2
 			;
 				NeedIntCast = yes,
-				generate_unsafe_type_cast(ModuleInfo,
+				generate_unsafe_type_cast(ModuleInfo, Context,
 					CompareType, UnwrappedArg1, CastArg1,
 					CastGoal1, ProcInfo2, ProcInfo3),
-				generate_unsafe_type_cast(ModuleInfo,
+				generate_unsafe_type_cast(ModuleInfo, Context,
 					CompareType, UnwrappedArg2, CastArg2,
 					CastGoal2, ProcInfo3, ProcInfo4),
 				NewCallArgs = [ComparisonResult,
@@ -2057,7 +2060,7 @@
 					SpecialProcId, NewCallArgs,
 					not_builtin, MaybeContext, SymName),
 				goal_info_init(NonLocals, InstMapDelta, Detism,
-					GoalInfo),
+					Context, GoalInfo),
 				Goal = conj([ExtractGoal1, CastGoal1,
 						ExtractGoal2, CastGoal2,
 						SpecialGoal - GoalInfo]),
@@ -2186,11 +2189,11 @@
 		SpecialId = compare
 	).
 
-:- pred generate_unsafe_type_cast(module_info::in, (type)::in,
-	prog_var::in, prog_var::out, hlds_goal::out,
+:- pred generate_unsafe_type_cast(module_info::in, prog_context::in,
+	(type)::in, prog_var::in, prog_var::out, hlds_goal::out,
 	proc_info::in, proc_info::out) is det.
 
-generate_unsafe_type_cast(ModuleInfo, ToType, Arg, CastArg, Goal,
+generate_unsafe_type_cast(ModuleInfo, Context, ToType, Arg, CastArg, Goal,
 		ProcInfo0, ProcInfo) :-
 	module_info_get_predicate_table(ModuleInfo, PredicateTable),
 	mercury_private_builtin_module(MercuryBuiltin),
@@ -2207,14 +2210,15 @@
 	set__list_to_set([Arg, CastArg], NonLocals),
 	instmap_delta_from_assoc_list([CastArg - ground(shared, none)],
 		InstMapDelta),
-	goal_info_init(NonLocals, InstMapDelta, det, GoalInfo),
+	goal_info_init(NonLocals, InstMapDelta, det, Context, GoalInfo),
 	Goal = call(PredId, ProcId, [Arg, CastArg], inline_builtin,
 		no, qualified(MercuryBuiltin, "unsafe_type_cast")) - GoalInfo.
 
-:- pred unwrap_no_tag_arg((type)::in, sym_name::in, prog_var::in,
-	prog_var::out, hlds_goal::out, proc_info::in, proc_info::out) is det.
+:- pred unwrap_no_tag_arg((type)::in, prog_context::in, sym_name::in,
+	prog_var::in, prog_var::out, hlds_goal::out,
+	proc_info::in, proc_info::out) is det.
 
-unwrap_no_tag_arg(WrappedType, Constructor, Arg, UnwrappedArg,
+unwrap_no_tag_arg(WrappedType, Context, Constructor, Arg, UnwrappedArg,
 		Goal, ProcInfo0, ProcInfo) :-
 	proc_info_create_var_from_type(ProcInfo0, WrappedType, UnwrappedArg,
 		ProcInfo),
@@ -2227,7 +2231,7 @@
 	% This will be recomputed later.
 	instmap_delta_from_assoc_list([UnwrappedArg - ground(shared, none)],
 		InstMapDelta),
-	goal_info_init(NonLocals, InstMapDelta, det, GoalInfo),
+	goal_info_init(NonLocals, InstMapDelta, det, Context, GoalInfo),
 	Goal = unify(Arg, functor(ConsId, [UnwrappedArg]), In - Out,
 		deconstruct(Arg, ConsId, [UnwrappedArg], UniModes,
 			cannot_fail, no),
Index: compiler/hlds_goal.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_goal.m,v
retrieving revision 1.90
diff -u -b -r1.90 hlds_goal.m
--- compiler/hlds_goal.m	2001/07/24 01:35:30	1.90
+++ compiler/hlds_goal.m	2001/08/14 02:36:50
@@ -615,6 +615,9 @@
 		hlds_goal_info).
 :- mode goal_info_init(in, in, in, out) is det.
 
+:- pred goal_info_init(set(prog_var)::in, instmap_delta::in, determinism::in,
+	prog_context::in, hlds_goal_info::out) is det.
+
 % Instead of recording the liveness of every variable at every
 % part of the goal, we just keep track of the initial liveness
 % and the changes in liveness.  Note that when traversing forwards
@@ -1293,6 +1296,13 @@
 	goal_info_set_nonlocals(GoalInfo0, NonLocals, GoalInfo1),
 	goal_info_set_instmap_delta(GoalInfo1, InstMapDelta, GoalInfo2),
 	goal_info_set_determinism(GoalInfo2, Detism, GoalInfo).
+
+goal_info_init(NonLocals, InstMapDelta, Detism, Context, GoalInfo) :-
+	goal_info_init(GoalInfo0),
+	goal_info_set_nonlocals(GoalInfo0, NonLocals, GoalInfo1),
+	goal_info_set_instmap_delta(GoalInfo1, InstMapDelta, GoalInfo2),
+	goal_info_set_determinism(GoalInfo2, Detism, GoalInfo3),
+	goal_info_set_context(GoalInfo3, Context, GoalInfo).
 
 goal_info_get_pre_births(GoalInfo, GoalInfo ^ pre_births).
 
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
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 library
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
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