[m-rev.] for post-commit review: optimize compilation of trail ops

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Mar 31 14:31:45 AEDT 2006


I know the change to assertion.m is logically separate, but I had to test
it in the same workspace due to limited CPU resources.

Zoltan.

compiler/code_gen.m:
	Don't test whether we are emitting trail operations when generating
	*every* goal; test it only when generating goals that may want to
	emit trailing operations. Make the test itself more efficient
	by doing option lookups and boolean operations on option values
	once per procedure rather than once per affected goal.

compiler/code_info.m:
	Extend the code_info structure to provide storage space for the
	result of this per-procedure computation.

compiler/code_util.m:
	Delete a function whose functionality is now in code_info.m.

compiler/goal_form.m:
	Turn the predicates that test whether a goal can modify the trail
	into functions, since that is how they were being used. Make them
	take only the goal_info as the argument, since the goal expression
	isn't needed, and creating the expression/goal_info pair would be
	an unnecessary cost on the code generator.

compiler/add_trail_ops.m:
compiler/disj_gen.m:
	Conform to the change in goal_form.m.

compiler/mercury_compile.m:
	Fix formatting.

compiler/assertion.m:
	Address some old review comments: fix some bad predicate names,
	and put some predicate's arguments into a more conventional order.

	Remove some redundant and slightly inconsistent documentation.

compiler/accumulator.m:
compiler/typecheck.m:
	Conform to the change in assertion.m.

cvs diff: Diffing .
cvs diff: Diffing analysis
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/accumulator.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/accumulator.m,v
retrieving revision 1.56
diff -u -b -r1.56 accumulator.m
--- compiler/accumulator.m	29 Mar 2006 08:06:34 -0000	1.56
+++ compiler/accumulator.m	30 Mar 2006 07:00:26 -0000
@@ -958,7 +958,7 @@
 associativity_assertion([AssertId | AssertIds], ModuleInfo, Args0, VarAB,
         OutputVar) :-
     (
-        assertion.is_associativity_assertion(AssertId, ModuleInfo,
+        assertion.is_associativity_assertion(ModuleInfo, AssertId,
             Args0, VarA - VarB, OutputVar0)
     ->
         \+ associativity_assertion(AssertIds, ModuleInfo, Args0, _, _),
@@ -981,7 +981,7 @@
 commutativity_assertion([AssertId | AssertIds], ModuleInfo, Args0,
         PossibleStaticVars) :-
     (
-        assertion.is_commutativity_assertion(AssertId, ModuleInfo,
+        assertion.is_commutativity_assertion(ModuleInfo, AssertId,
             Args0, StaticVarA - StaticVarB)
     ->
         \+ commutativity_assertion(AssertIds, ModuleInfo, Args0, _),
@@ -1005,7 +1005,7 @@
 
     list.filter_map(
         (pred(AssertId::in, StateVars::out) is semidet :-
-            assertion.is_update_assertion(AssertId, ModuleInfo,
+            assertion.is_update_assertion(ModuleInfo, AssertId,
                 PredId, Args, StateVars)
         ),
         set.to_sorted_list(Assertions), Result),
@@ -1027,8 +1027,8 @@
     pred_info_get_assertions(PredInfo, Assertions),
     list.filter(
         (pred(AssertId::in) is semidet :-
-            assertion.is_construction_equivalence_assertion(AssertId,
-                ModuleInfo, ConsId, PredId)
+            assertion.is_construction_equivalence_assertion(ModuleInfo,
+                AssertId, ConsId, PredId)
         ),
         set.to_sorted_list(Assertions), Result),
     Result = [_ | _].
Index: compiler/add_trail_ops.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_trail_ops.m,v
retrieving revision 1.35
diff -u -b -r1.35 add_trail_ops.m
--- compiler/add_trail_ops.m	29 Mar 2006 08:06:35 -0000	1.35
+++ compiler/add_trail_ops.m	30 Mar 2006 13:19:29 -0000
@@ -138,15 +138,15 @@
 
 goal_add_trail_ops(!Goal, !Info) :-
     OptTrailUsage = !.Info ^ opt_trail_usage,
+    !.Goal = GoalExpr0 - GoalInfo,
     (
         OptTrailUsage = yes,
-        goal_cannot_modify_trail(!.Goal)
+        goal_cannot_modify_trail(GoalInfo) = yes
     ->
         % Don't add trail ops if the goal cannot modify the trail
         % and we are optimizing trail usage.
         true
     ;
-        !.Goal = GoalExpr0 - GoalInfo,
         goal_expr_add_trail_ops(GoalExpr0, GoalInfo, !:Goal, !Info)
     ). 
 
@@ -378,7 +378,7 @@
     % if the disjunct doesn't modify the trail and `--optimize-trail-usage' is
     % set.
     %
-    ThisDisjunctModifiesTrail = pred_to_bool(goal_may_modify_trail(Goal0)),
+    ThisDisjunctModifiesTrail = goal_may_modify_trail(GoalInfo0),
     CanOmitTrailOps =
         not(ThisDisjunctModifiesTrail) `and` !.Info ^ opt_trail_usage,
     (
Index: compiler/assertion.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/assertion.m,v
retrieving revision 1.49
diff -u -b -r1.49 assertion.m
--- compiler/assertion.m	29 Mar 2006 08:06:35 -0000	1.49
+++ compiler/assertion.m	30 Mar 2006 06:57:47 -0000
@@ -31,7 +31,7 @@
 
     % Get the hlds_goal which represents the assertion.
     %
-:- pred goal(assert_id::in, module_info::in, hlds_goal::out) is det.
+:- pred assert_id_goal(module_info::in, assert_id::in, hlds_goal::out) is det.
 
     % Record into the pred_info of each pred used in the assertion
     % the assert_id.
@@ -39,7 +39,7 @@
 :- pred record_preds_used_in(hlds_goal::in, assert_id::in,
     module_info::in, module_info::out) is det.
 
-    % is_commutativity_assertion(Id, MI, Vs, CVs):
+    % is_commutativity_assertion(MI, Id, Vs, CVs):
     %
     % Does the assertion represented by the assertion id, Id,
     % state the commutativity of a pred/func?
@@ -55,10 +55,10 @@
     % arguments, Is, can be any where providing they are in
     % identical locations on both sides of the equivalence).
     %
-:- pred is_commutativity_assertion(assert_id::in, module_info::in,
+:- pred is_commutativity_assertion(module_info::in, assert_id::in,
     prog_vars::in, pair(prog_var)::out) is semidet.
 
-    % is_associativity_assertion(Id, MI, Vs, CVs, OV):
+    % is_associativity_assertion(MI, Id, Vs, CVs, OV):
     %
     % Does the assertion represented by the assertion id, Id,
     % state the associativity of a pred/func?
@@ -72,46 +72,56 @@
     % AB, BC or ABC).
     %
     % The assertion must be in a form similar to this
+    %
     %   all [Is,A,B,C,ABC]
     %   (
     %     some [AB] p(Is,A,B,AB), p(Is,AB,C,ABC)
     %   <=>
     %     some [BC] p(Is,B,C,BC), p(Is,A,BC,ABC)
     %   )
+    %
     % for the predicate to return true (note that the invariant
     % arguments, Is, can be any where providing they are in
     % identical locations on both sides of the equivalence).
     %
-:- pred is_associativity_assertion(assert_id::in, module_info::in,
+:- pred is_associativity_assertion(module_info::in, assert_id::in,
     prog_vars::in, pair(prog_var)::out, prog_var::out) is semidet.
 
-    % is_associativity_assertion(Id, MI, PId, Vs, SPair):
+    % is_update_assertion(MI, Id, PId, Ss):
+    %
+    % is true iff the assertion, Id, is about a predicate, PId,
+    % which takes some state as input and produces some state as output
+    % and we are guaranteed to get the same final state regardless of
+    % the order that the state is updated.
+    %
+    % i.e. the promise should look something like this, note that A
+    % and B could be vectors of variables.
     %
-    % Recognise assertions in the form
-    %   all [A,B,S0,S]
+    % :- promise all [A,B,SO,S]
     %   (
-    %     some [SA] p(A,S0,SA), p(B,SA,S)
+    %       (some [SA] (update(S0,A,SA), update(SA,B,S)))
     %   <=>
-    %     some [SB] p(B,S0,SB), p(A,SB,S)
-    %   )
-    % and given the actual variables, Vs, to the call to p, return
+    %       (some [SB] (update(S0,B,SB), update(SB,A,S)))
+    %   ).
+    %
+    % Given the actual variables, Vs, to the call to update, return
     % the pair of variables which are state variables, SPair.
     %
-:- pred is_update_assertion(assert_id::in, module_info::in,
+:- pred is_update_assertion(module_info::in, assert_id::in,
     pred_id::in, prog_vars::in, pair(prog_var)::out) is semidet.
 
-    % is_construction_equivalence_assertion(Id, MI, C, P):
+    % is_construction_equivalence_assertion(MI, Id, C, P):
     %
-    % Can a single construction unification whose functor is
-    % determined by the cons_id, C, be expressed as a call
-    % to the predid, P (with possibly some construction unifications
-    % to initialise the arguments).
+    % Can a single construction unification whose functor is determined
+    % by the cons_id, C, be expressed as a call to the predid, P (with possibly
+    % some construction unifications to initialise the arguments).
     %
     % The assertion will be in a form similar to
-    %   all [L,H,T] ( L = [H|T] <=> append([H], T, L) )
     %
-:- pred is_construction_equivalence_assertion(assert_id::in,
-    module_info::in, cons_id::in, pred_id::in) is semidet.
+    %   all [L,H,T] ( L = [H | T] <=> append([H], T, L) )
+    %
+:- pred is_construction_equivalence_assertion(module_info::in, assert_id::in,
+    cons_id::in, pred_id::in) is semidet.
 
     % Ensure that an assertion which is defined in an interface
     % doesn't refer to any constructors, functions and predicates
@@ -156,10 +166,9 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-is_commutativity_assertion(AssertId, Module, CallVars,
-        CommutativeVars) :-
-    goal(AssertId, Module, Goal),
-    equivalent(Goal, P, Q),
+is_commutativity_assertion(Module, AssertId, CallVars, CommutativeVars) :-
+    assert_id_goal(Module, AssertId, Goal),
+    goal_is_equivalence(Goal, P, Q),
     P = call(PredId, _, VarsP, _, _, _) - _,
     Q = call(PredId, _, VarsQ, _, _, _) - _,
     commutative_var_ordering(VarsP, VarsQ, CallVars, CommutativeVars).
@@ -200,10 +209,10 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-is_associativity_assertion(AssertId, Module, CallVars,
+is_associativity_assertion(Module, AssertId, CallVars,
         AssociativeVars, OutputVar) :-
-    goal(AssertId, Module, Goal - GoalInfo),
-    equivalent(Goal - GoalInfo, P, Q),
+    assert_id_goal(Module, AssertId, Goal - GoalInfo),
+    goal_is_equivalence(Goal - GoalInfo, P, Q),
 
     goal_info_get_nonlocals(GoalInfo, UniversiallyQuantifiedVars),
 
@@ -308,26 +317,9 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-    % is_update_assertion(Id, MI, PId, Ss):
-    %
-    % is true iff the assertion, Id, is about a predicate, PId,
-    % which takes some state as input and produces some state as
-    % output and the same state is produced as input regardless of
-    % the order that the state is updated.
-    %
-    % i.e. the promise should look something like this, note that A
-    % and B could be vectors of variables.
-    % :- promise all [A,B,SO,S]
-    %   (
-    %       (some [SA] (update(S0,A,SA), update(SA,B,S)))
-    %   <=>
-    %       (some [SB] (update(S0,B,SB), update(SB,A,S)))
-    %   ).
-    %
-is_update_assertion(AssertId, Module, _PredId, CallVars,
-        StateA - StateB) :-
-    goal(AssertId, Module, Goal - GoalInfo),
-    equivalent(Goal - GoalInfo, P, Q),
+is_update_assertion(Module, AssertId, _PredId, CallVars, StateA - StateB) :-
+    assert_id_goal(Module, AssertId, Goal - GoalInfo),
+    goal_is_equivalence(Goal - GoalInfo, P, Q),
     goal_info_get_nonlocals(GoalInfo, UniversiallyQuantifiedVars),
 
         % There may or may not be an explicit some [Vars] there,
@@ -410,9 +402,9 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-is_construction_equivalence_assertion(AssertId, Module, ConsId, PredId) :-
-    goal(AssertId, Module, Goal),
-    equivalent(Goal, P, Q),
+is_construction_equivalence_assertion(Module, AssertId, ConsId, PredId) :-
+    assert_id_goal(Module, AssertId, Goal),
+    goal_is_equivalence(Goal, P, Q),
     ( single_construction(P, ConsId) ->
         predicate_call(Q, PredId)
     ;
@@ -455,7 +447,7 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-goal(AssertId, Module, Goal) :-
+assert_id_goal(Module, AssertId, Goal) :-
     module_info_get_assertion_table(Module, AssertTable),
     assertion_table_lookup(AssertTable, AssertId, PredId),
     module_info_pred_info(Module, PredId, PredInfo),
@@ -470,9 +462,10 @@
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 
-:- pred implies(hlds_goal::in, hlds_goal::out, hlds_goal::out) is semidet.
+:- pred goal_is_implication(hlds_goal::in, hlds_goal::out, hlds_goal::out)
+    is semidet.
 
-implies(Goal, P, Q) :-
+goal_is_implication(Goal, P, Q) :-
         % Goal = (P => Q)
     Goal = not(conj(plain_conj, GoalList) - GI) - _,
     list.reverse(GoalList) = [NotQ | Ps],
@@ -483,14 +476,15 @@
     ),
     NotQ = not(Q) - _.
 
-:- pred equivalent(hlds_goal::in, hlds_goal::out, hlds_goal::out) is semidet.
+:- pred goal_is_equivalence(hlds_goal::in, hlds_goal::out, hlds_goal::out)
+    is semidet.
 
-equivalent(Goal, P, Q) :-
+goal_is_equivalence(Goal, P, Q) :-
         % Goal = P <=> Q
     Goal = conj(plain_conj, [A, B]) - _GoalInfo,
     map.init(Subst),
-    implies(A, PA, QA),
-    implies(B, QB, PB),
+    goal_is_implication(A, PA, QA),
+    goal_is_implication(B, QB, PB),
     equal_goals(PA, PB, Subst, _),
     equal_goals(QA, QB, Subst, _),
     P = PA,
@@ -535,8 +529,7 @@
     equal_goals(ThenA, ThenB, !Subst),
     equal_goals(ElseA, ElseB, !Subst).
 equal_goals(foreign_proc(Attribs, PredId, _, ArgsA, ExtraA, _) - _,
-        foreign_proc(Attribs, PredId, _, ArgsB, ExtraB, _) - _,
-        !Subst) :-
+        foreign_proc(Attribs, PredId, _, ArgsB, ExtraB, _) - _, !Subst) :-
     % Foreign_procs with extra args are compiler generated,
     % and as such will not participate in assertions.
     ExtraA = [],
@@ -625,8 +618,8 @@
 %-----------------------------------------------------------------------------%
 
 record_preds_used_in(Goal, AssertId, !Module) :-
-        % Explicit lambda expression needed since
-        % goal_calls_pred_id has multiple modes.
+    % Explicit lambda expression needed since goal_calls_pred_id
+    % has multiple modes.
     P = (pred(PredId::out) is nondet :- goal_calls_pred_id(Goal, PredId)),
     solutions.solutions(P, PredIds),
     list.foldl(update_pred_info(AssertId), PredIds, !Module).
@@ -655,8 +648,7 @@
 normalise_goal(Goal @ generic_call(_, _, _, _) - GI, Goal - GI).
 normalise_goal(Goal @ unify(_, _, _, _, _) - GI, Goal - GI).
 normalise_goal(Goal @ foreign_proc(_, _, _, _, _, _) - GI, Goal - GI).
-normalise_goal(conj(ConjType, Goals0) - GI,
-        conj(ConjType, Goals) - GI) :-
+normalise_goal(conj(ConjType, Goals0) - GI, conj(ConjType, Goals) - GI) :-
     (
         ConjType = plain_conj,
         normalise_conj(Goals0, Goals)
Index: compiler/code_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_gen.m,v
retrieving revision 1.156
diff -u -b -r1.156 code_gen.m
--- compiler/code_gen.m	29 Mar 2006 08:06:37 -0000	1.156
+++ compiler/code_gen.m	30 Mar 2006 13:19:29 -0000
@@ -1090,14 +1090,8 @@
                 unexpected(this_file, "nondet model in det/semidet context")
             )
         ),
-        %
-        % Check if we need to add trail ops, and if so, whether it is safe to
-        % omit them.  We only do the latter if we are optimizing trail usage.
-        %
-        code_info.get_globals(!.CI, Globals),
-        AddTrailOps = should_add_trail_ops(Globals, Goal - GoalInfo),
-        generate_goal_2(Goal, GoalInfo, CodeModel, AddTrailOps, 
-            GoalCode, !CI),
+
+        generate_goal_2(Goal, GoalInfo, CodeModel, GoalCode, !CI),
         goal_info_get_features(GoalInfo, Features),
         code_info.get_proc_info(!.CI, ProcInfo),
 
@@ -1190,13 +1184,12 @@
 %---------------------------------------------------------------------------%
 
 :- pred generate_goal_2(hlds_goal_expr::in, hlds_goal_info::in,
-    code_model::in, add_trail_ops::in, code_tree::out,
-    code_info::in, code_info::out) is det.
+    code_model::in, code_tree::out, code_info::in, code_info::out) is det.
 
-generate_goal_2(Goal, GoalInfo, CodeModel, _, Code, !CI) :-
+generate_goal_2(Goal, GoalInfo, CodeModel, Code, !CI) :-
     Goal = unify(_, _, _, Uni, _),
     unify_gen.generate_unification(CodeModel, Uni, GoalInfo, Code, !CI).
-generate_goal_2(conj(ConjType, Goals), GoalInfo, CodeModel, _, Code, !CI) :-
+generate_goal_2(conj(ConjType, Goals), GoalInfo, CodeModel, Code, !CI) :-
     (
         ConjType = plain_conj,
         generate_goals(Goals, CodeModel, Code, !CI)
@@ -1204,27 +1197,30 @@
         ConjType = parallel_conj,
         par_conj_gen.generate_par_conj(Goals, GoalInfo, CodeModel, Code, !CI)
     ).
-generate_goal_2(disj(Goals), GoalInfo, CodeModel, AddTrailOps, Code, !CI) :-
+generate_goal_2(disj(Goals), GoalInfo, CodeModel, Code, !CI) :-
+    AddTrailOps = should_add_trail_ops(!.CI, GoalInfo),
     disj_gen.generate_disj(AddTrailOps, CodeModel, Goals, GoalInfo, Code, !CI).
-generate_goal_2(not(Goal), GoalInfo, CodeModel, AddTrailOps, Code, !CI) :-
+generate_goal_2(not(Goal), GoalInfo, CodeModel, Code, !CI) :-
+    AddTrailOps = should_add_trail_ops(!.CI, GoalInfo),
     ite_gen.generate_negation(AddTrailOps, CodeModel, Goal, GoalInfo,
         Code, !CI).
-generate_goal_2(Goal, GoalInfo, CodeModel, AddTrailOps, Code, !CI) :-
+generate_goal_2(Goal, GoalInfo, CodeModel, Code, !CI) :-
     Goal = if_then_else(_Vars, Cond, Then, Else),
+    AddTrailOps = should_add_trail_ops(!.CI, GoalInfo),
     ite_gen.generate_ite(AddTrailOps, CodeModel, Cond, Then, Else, GoalInfo,
         Code, !CI).
-generate_goal_2(Goal, GoalInfo, CodeModel, _, Code, !CI) :-
+generate_goal_2(Goal, GoalInfo, CodeModel, Code, !CI) :-
     Goal = switch(Var, CanFail, CaseList),
-    switch_gen.generate_switch(CodeModel, Var, CanFail, CaseList,
-        GoalInfo, Code, !CI).
-generate_goal_2(scope(_, Goal), _GoalInfo, CodeModel, AddTrailOps, Code,
-        !CI) :-
+    switch_gen.generate_switch(CodeModel, Var, CanFail, CaseList, GoalInfo,
+        Code, !CI).
+generate_goal_2(scope(_, Goal), GoalInfo, CodeModel, Code, !CI) :-
+    AddTrailOps = should_add_trail_ops(!.CI, GoalInfo),
     commit_gen.generate_commit(AddTrailOps, CodeModel, Goal, Code, !CI).
-generate_goal_2(Goal, GoalInfo, CodeModel, _, Code, !CI) :-
+generate_goal_2(Goal, GoalInfo, CodeModel, Code, !CI) :-
     Goal = generic_call(GenericCall, Args, Modes, Det),
     call_gen.generate_generic_call(CodeModel, GenericCall, Args,
         Modes, Det, GoalInfo, Code, !CI).
-generate_goal_2(Goal, GoalInfo, CodeModel, _, Code, !CI) :-
+generate_goal_2(Goal, GoalInfo, CodeModel, Code, !CI) :-
     Goal = call(PredId, ProcId, Args, BuiltinState, _, _),
     ( BuiltinState = not_builtin ->
         call_gen.generate_call(CodeModel, PredId, ProcId, Args,
@@ -1233,7 +1229,7 @@
         call_gen.generate_builtin(CodeModel, PredId, ProcId, Args,
             Code, !CI)
     ).
-generate_goal_2(Goal, GoalInfo, CodeModel, _, Code, !CI) :-
+generate_goal_2(Goal, GoalInfo, CodeModel, Code, !CI) :-
     Goal = foreign_proc(Attributes, PredId, ProcId, Args, ExtraArgs,
         PragmaCode),
     ( c = foreign_language(Attributes) ->
@@ -1243,7 +1239,7 @@
         unexpected(this_file,
             "generate_goal_2: foreign code other than C unexpected")
     ).
-generate_goal_2(shorthand(_), _, _, _, _, !CI) :-
+generate_goal_2(shorthand(_), _, _, _, !CI) :-
     % These should have been expanded out by now.
     unexpected(this_file, "generate_goal_2: unexpected shorthand").
 
Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.318
diff -u -b -r1.318 code_info.m
--- compiler/code_info.m	30 Mar 2006 02:45:54 -0000	1.318
+++ compiler/code_info.m	30 Mar 2006 22:34:21 -0000
@@ -62,6 +62,7 @@
 :- import_module check_hlds.mode_util.
 :- import_module check_hlds.type_util.
 :- import_module hlds.arg_info.
+:- import_module hlds.goal_form.
 :- import_module hlds.hlds_code_util.
 :- import_module hlds.hlds_rtti.
 :- import_module libs.compiler_util.
@@ -144,6 +145,8 @@
 
 :- pred get_maybe_trace_info(code_info::in, maybe(trace_info)::out) is det.
 
+:- pred get_emit_trail_ops(code_info::in, add_trail_ops::out) is det.
+
     % Get the set of currently forward-live variables.
     %
 :- pred get_forward_live_vars(code_info::in, set(prog_var)::out) is det.
@@ -207,6 +210,8 @@
 
 :- pred get_opt_no_return_calls(code_info::in, bool::out) is det.
 
+:- pred get_opt_trail_ops(code_info::in, bool::out) is det.
+
 :- pred get_zombies(code_info::in, set(prog_var)::out) is det.
 
 :- pred set_zombies(set(prog_var)::in,
@@ -319,7 +324,16 @@
                                     % are stored in, provided tracing is
                                     % switched on.
                 
-                opt_no_resume_calls :: bool
+                opt_no_resume_calls :: bool,
+                                    % Should we optimize calls that cannot
+                                    % return?
+
+                emit_trail_ops      :: bool,
+                                    % Should we emit trail operations?
+
+                opt_trail_ops       :: bool
+                                    % Should we try to avoid emiting trail
+                                    % operations?
             ).
 
 :- type code_info_loc_dep
@@ -455,6 +469,17 @@
     int.max(VarSlotMax, FixedSlots, SlotMax),
     globals.lookup_bool_option(Globals, opt_no_return_calls,
         OptNoReturnCalls),
+    globals.lookup_bool_option(Globals, use_trail, UseTrail),
+    globals.lookup_bool_option(Globals, disable_trail_ops, DisableTrailOps),
+    (
+        UseTrail = yes,
+        DisableTrailOps = no
+    ->
+        EmitTrailOps = yes
+    ;
+        EmitTrailOps = no
+    ),
+    globals.lookup_bool_option(Globals, optimize_trail_usage, OptTrailOps),
     CodeInfo0 = code_info(
         code_info_static(
             Globals,
@@ -466,7 +491,9 @@
             VarSet,
             SlotMax,
             no,
-            OptNoReturnCalls
+            OptNoReturnCalls,
+            EmitTrailOps,
+            OptTrailOps
         ),
         code_info_loc_dep(
             Liveness,
@@ -530,6 +557,10 @@
     CI ^ code_info_static ^ maybe_trace_info).
 get_opt_no_return_calls(CI,
     CI ^ code_info_static ^ opt_no_resume_calls).
+get_emit_trail_ops(CI,
+    CI ^ code_info_static ^ emit_trail_ops).
+get_opt_trail_ops(CI,
+    CI ^ code_info_static ^ opt_trail_ops).
 get_forward_live_vars(CI,
     CI ^ code_info_loc_dep ^ forward_live_vars).
 get_instmap(CI,
@@ -2875,6 +2906,14 @@
 :- pred maybe_discard_and_release_ticket(maybe(lval)::in, code_tree::out,
     code_info::in, code_info::out) is det.
 
+    % Tests if we should add trail ops to the code we generate for the goal
+    % with the given goalinfo. This will be 'no' unless we are compiling
+    % in trailing grade. It may also be 'no' in trailing grades if we are
+    % optimizing trail usage and trail usage analysis tells us that it is safe
+    % to omit the trail ops.
+    %
+:- func should_add_trail_ops(code_info, hlds_goal_info) = add_trail_ops.
+
 %---------------------------------------------------------------------------%
 
 :- implementation.
@@ -3061,6 +3100,23 @@
     ;
         MaybeTicketSlot = no,
         Code = empty
+    ).
+
+should_add_trail_ops(CodeInfo, GoalInfo) = AddTrailOps :-
+    get_emit_trail_ops(CodeInfo, EmitTrailOps),
+    (
+        EmitTrailOps = no,
+        AddTrailOps = no
+    ;
+        EmitTrailOps = yes,
+        get_opt_trail_ops(CodeInfo, OptTrailOps),
+        (
+            OptTrailOps = no,
+            AddTrailOps = yes
+        ;
+            OptTrailOps = yes,
+            AddTrailOps = goal_may_modify_trail(GoalInfo)
+        )
     ).
 
 %---------------------------------------------------------------------------%
Index: compiler/code_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/code_util.m,v
retrieving revision 1.169
diff -u -b -r1.169 code_util.m
--- compiler/code_util.m	30 Mar 2006 02:45:55 -0000	1.169
+++ compiler/code_util.m	30 Mar 2006 13:19:29 -0000
@@ -21,7 +21,6 @@
 :- import_module hlds.hlds_module.
 :- import_module hlds.hlds_pred.
 :- import_module hlds.hlds_rtti.
-:- import_module libs.globals.
 :- import_module ll_backend.llds.
 :- import_module mdbcomp.prim_data.
 :- import_module parse_tree.prog_data.
@@ -94,18 +93,6 @@
     is det.
 
 %---------------------------------------------------------------------------%
-%
-% Utility predicates used to implement trailing
-%
-    % Tests if we should add trail ops to the code we generate for
-    % the given goal.  This will be 'no' unless we are compiling
-    % in trailing grade.  It may also be 'no' in trailing grades if
-    % we are optimizing trail usage and trail usage analysis tells
-    % us that it is safe to omit the trail ops.
-    %  
-:- func should_add_trail_ops(globals, hlds_goal) = add_trail_ops.
-
-%---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
 
 :- implementation.
@@ -454,41 +441,6 @@
     build_input_arg_list_2(Rest0, VarArgs0).
 
 %---------------------------------------------------------------------------%
-%
-% Utility predicates used to implement trailing
-%
-
-should_add_trail_ops(Globals, Goal) = AddTrailOps :-
-    globals.lookup_bool_option(Globals, use_trail, UseTrail),
-    (
-        UseTrail = no,
-        AddTrailOps = no
-    ;
-        UseTrail = yes,
-        globals.lookup_bool_option(Globals, disable_trail_ops,
-            DisableTrailOps),
-        (
-            DisableTrailOps = yes,
-            AddTrailOps = no
-        ;
-            DisableTrailOps = no,
-            globals.lookup_bool_option(Globals, optimize_trail_usage,
-                OptTrailUsage),
-            (
-                OptTrailUsage = no,
-                AddTrailOps = yes
-            ;
-                OptTrailUsage = yes,
-                ( goal_cannot_modify_trail(Goal) ->
-                    AddTrailOps = no
-                ;
-                    AddTrailOps = yes
-                )
-            )
-        )
-    ).
-
-%-----------------------------------------------------------------------------%
 
 :- func this_file = string.
 
Index: compiler/disj_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/disj_gen.m,v
retrieving revision 1.91
diff -u -b -r1.91 disj_gen.m
--- compiler/disj_gen.m	29 Mar 2006 08:06:42 -0000	1.91
+++ compiler/disj_gen.m	31 Mar 2006 03:30:20 -0000
@@ -300,7 +300,7 @@
         % Check if this branch modifies the trail. If it doesn't then the next
         % branch can avoid resetting it.
         %
-        ThisBranchModifiesTrail = pred_to_bool(goal_may_modify_trail(Goal)),
+        ThisBranchModifiesTrail = goal_may_modify_trail(GoalInfo),
 
         disj_gen.generate_disjuncts(Goals, CodeModel, FullResumeMap,
             yes(NextResumePoint), HijackInfo, DisjGoalInfo,
Index: compiler/goal_form.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/goal_form.m,v
retrieving revision 1.29
diff -u -b -r1.29 goal_form.m
--- compiler/goal_form.m	29 Mar 2006 08:06:45 -0000	1.29
+++ compiler/goal_form.m	30 Mar 2006 13:19:29 -0000
@@ -158,13 +158,13 @@
 % Trail usage
 %
 
-    % Succeeds if the goal does not modify the trail.
+    % Returns `yes' if the goal does not modify the trail.
     %
-:- pred goal_cannot_modify_trail(hlds_goal::in) is semidet.
+:- func goal_cannot_modify_trail(hlds_goal_info) = bool.
 
-    % Succeeds if the goal may modify the trail.
+    % Returns `yes' if the goal may modify the trail.
     %
-:- pred goal_may_modify_trail(hlds_goal::in) is semidet.
+:- func goal_may_modify_trail(hlds_goal_info) = bool.
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
@@ -752,15 +752,20 @@
         int.min(Min0, Min1, Min),
         int.max(Max0, Max1, Max)
     ).
+
 %-----------------------------------------------------------------------------%
 %
 % Trail usage
 %
 
-goal_cannot_modify_trail(Goal) :-
-    goal_has_feature(Goal, will_not_modify_trail).
-goal_may_modify_trail(Goal) :-
-    not goal_cannot_modify_trail(Goal).
+goal_cannot_modify_trail(GoalInfo) =
+    ( goal_info_has_feature(GoalInfo, will_not_modify_trail) ->
+        yes
+    ;
+        no
+    ).
+
+goal_may_modify_trail(GoalInfo) = bool.not(goal_cannot_modify_trail(GoalInfo)).
 
 %-----------------------------------------------------------------------------%
 
Index: compiler/mercury_compile.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.383
diff -u -b -r1.383 mercury_compile.m
--- compiler/mercury_compile.m	29 Mar 2006 08:07:00 -0000	1.383
+++ compiler/mercury_compile.m	30 Mar 2006 13:19:29 -0000
@@ -3119,8 +3119,7 @@
         EmitTrailOps = no
     ;
         UseTrail = yes,
-        globals.io_lookup_bool_option(disable_trail_ops, DisableTrailOps,
-            !IO),
+        globals.io_lookup_bool_option(disable_trail_ops, DisableTrailOps, !IO),
         (
             DisableTrailOps = yes,
             EmitTrailOps = no
@@ -3143,7 +3142,8 @@
             %
             ( Target = il
             ; Target = java
-            ; Target = asm ),
+            ; Target = asm
+            ),
             GenerateInline = no
         ),
         maybe_write_string(Verbose, "% Adding trailing operations...\n", !IO),
Index: compiler/post_typecheck.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/post_typecheck.m,v
retrieving revision 1.99
diff -u -b -r1.99 post_typecheck.m
--- compiler/post_typecheck.m	29 Mar 2006 08:07:15 -0000	1.99
+++ compiler/post_typecheck.m	30 Mar 2006 07:00:32 -0000
@@ -514,7 +514,7 @@
         assertion_table_add_assertion(PromiseId, AssertionId,
             AssertTable0, AssertTable),
         module_info_set_assertion_table(AssertTable, !Module),
-        assertion.goal(AssertionId, !.Module, Goal),
+        assertion.assert_id_goal(!.Module, AssertionId, Goal),
         assertion.record_preds_used_in(Goal, AssertionId, !Module)
     ;
         % Case for exclusivity.
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing debian/patches
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
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/error
cvs diff: Diffing extras/gator
cvs diff: Diffing extras/gator/generations
cvs diff: Diffing extras/gator/generations/1
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_glut
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/gears
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/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
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/solver_types
cvs diff: Diffing extras/solver_types/library
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/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
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 slice
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/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
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/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/trailing
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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