[m-rev.] for review: trail usage optimization for LLDS grades

Julien Fischer juliensf at cs.mu.OZ.AU
Thu Nov 17 14:17:17 AEDT 2005


For review by anyone.

Estimated hours taken: 5
Branches: main

Implement trail usage optimization for the lowlevel backend.

compiler/code_gen.m:
	As we generate code for each HLDS goal check if it is safe to omit
	trailing operations.  Do so, if trail usage optimization is enabled.

	Reformat some code for the purposes of readability.

compiler/commit_gen.m:
compiler/disj_gen.m:
compiler/ite_gen.m:
compiler/code_info.m:
	Thread the above information down to the relevant parts of the code
	generator.

	Misc. cleanups: reduce unnecessary module qualification and minor
	layout fixes.

compiler/code_util.m:
	Add a utility predicate the tests if we are allowed to omit trailing
	primitives for a given HLDS goal.

compiler/llds.m:
	Add the equivalence type: add_trail_ops == bool.

compiler/hlds_goal.m:
compiler/prog_data.m:
	Unrelated changes: fix typos in comments.

	Add an end_module declaration to the former.

Julien.

Index: compiler/code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_gen.m,v
retrieving revision 1.145
diff -u -r1.145 code_gen.m
--- compiler/code_gen.m	28 Oct 2005 02:09:59 -0000	1.145
+++ compiler/code_gen.m	17 Nov 2005 02:51:35 -0000
@@ -43,6 +43,8 @@
 :- import_module io.
 :- import_module list.

+%---------------------------------------------------------------------------%
+
     % Translate a HLDS module to LLDS.
     %
 :- pred generate_code(module_info::in, global_data::in, global_data::out,
@@ -1080,7 +1082,16 @@
                 error("nondet model in det/semidet context")
             )
         ),
-        code_gen__generate_goal_2(Goal, GoalInfo, CodeModel, GoalCode, !CI),
+        %
+        % 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),
+        code_info__get_module_info(!.CI, ModuleInfo),
+        AddTrailOps = should_add_trail_ops(Globals, ModuleInfo,
+            Goal - GoalInfo),
+        code_gen__generate_goal_2(Goal, GoalInfo, CodeModel, AddTrailOps,
+            GoalCode, !CI),
         goal_info_get_features(GoalInfo, Features),
         code_info__get_proc_info(!.CI, ProcInfo),

@@ -1174,34 +1185,40 @@
 %---------------------------------------------------------------------------%

 :- pred code_gen__generate_goal_2(hlds_goal_expr::in, hlds_goal_info::in,
-    code_model::in, code_tree::out, code_info::in, code_info::out) is det.
+    code_model::in, add_trail_ops::in, code_tree::out,
+    code_info::in, code_info::out) is det.

-code_gen__generate_goal_2(unify(_, _, _, Uni, _), GoalInfo, CodeModel, Code,
-        !CI) :-
+code_gen__generate_goal_2(Goal, GoalInfo, CodeModel, _, Code, !CI) :-
+    Goal = unify(_, _, _, Uni, _),
     unify_gen__generate_unification(CodeModel, Uni, GoalInfo, Code, !CI).
-code_gen__generate_goal_2(conj(Goals), _GoalInfo, CodeModel, Code, !CI) :-
+code_gen__generate_goal_2(conj(Goals), _GoalInfo, CodeModel, _, Code, !CI) :-
     code_gen__generate_goals(Goals, CodeModel, Code, !CI).
-code_gen__generate_goal_2(par_conj(Goals), GoalInfo, CodeModel, Code, !CI) :-
+code_gen__generate_goal_2(par_conj(Goals), GoalInfo, CodeModel, _, Code, !CI) :-
     par_conj_gen__generate_par_conj(Goals, GoalInfo, CodeModel, Code, !CI).
-code_gen__generate_goal_2(disj(Goals), GoalInfo, CodeModel, Code, !CI) :-
-    disj_gen__generate_disj(CodeModel, Goals, GoalInfo, Code, !CI).
-code_gen__generate_goal_2(not(Goal), GoalInfo, CodeModel, Code, !CI) :-
-    ite_gen__generate_negation(CodeModel, Goal, GoalInfo, Code, !CI).
-code_gen__generate_goal_2(if_then_else(_Vars, Cond, Then, Else),
-        GoalInfo, CodeModel, Code, !CI) :-
-    ite_gen__generate_ite(CodeModel, Cond, Then, Else, GoalInfo, Code, !CI).
-code_gen__generate_goal_2(switch(Var, CanFail, CaseList),
-        GoalInfo, CodeModel, Code, !CI) :-
+code_gen__generate_goal_2(disj(Goals), GoalInfo, CodeModel, AddTrailOps,
+        Code, !CI) :-
+    disj_gen__generate_disj(AddTrailOps, CodeModel, Goals, GoalInfo, Code, !CI).
+code_gen__generate_goal_2(not(Goal), GoalInfo, CodeModel, AddTrailOps,
+        Code, !CI) :-
+    ite_gen__generate_negation(AddTrailOps, CodeModel, Goal, GoalInfo,
+        Code, !CI).
+code_gen__generate_goal_2(Goal, GoalInfo, CodeModel, AddTrailOps, Code, !CI) :-
+    Goal = if_then_else(_Vars, Cond, Then, Else),
+    ite_gen__generate_ite(AddTrailOps, CodeModel, Cond, Then, Else, GoalInfo,
+        Code, !CI).
+code_gen__generate_goal_2(Goal, GoalInfo, CodeModel, _, Code, !CI) :-
+    Goal = switch(Var, CanFail, CaseList),
     switch_gen__generate_switch(CodeModel, Var, CanFail, CaseList,
         GoalInfo, Code, !CI).
-code_gen__generate_goal_2(scope(_, Goal), _GoalInfo, CodeModel, Code, !CI) :-
-    commit_gen__generate_commit(CodeModel, Goal, Code, !CI).
-code_gen__generate_goal_2(generic_call(GenericCall, Args, Modes, Det),
-        GoalInfo, CodeModel, Code, !CI) :-
+code_gen__generate_goal_2(scope(_, Goal), _GoalInfo, CodeModel, AddTrailOps,
+        Code, !CI) :-
+    commit_gen__generate_commit(AddTrailOps, CodeModel, Goal, Code, !CI).
+code_gen__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).
-code_gen__generate_goal_2(call(PredId, ProcId, Args, BuiltinState, _,_),
-        GoalInfo, CodeModel, Code, !CI) :-
+code_gen__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,
             GoalInfo, Code, !CI)
@@ -1209,19 +1226,19 @@
         call_gen__generate_builtin(CodeModel, PredId, ProcId, Args,
             Code, !CI)
     ).
-code_gen__generate_goal_2(foreign_proc(Attributes, PredId, ProcId,
-        Args, ExtraArgs, PragmaCode),
-        GoalInfo, CodeModel, Code, !CI) :-
+code_gen__generate_goal_2(Goal, GoalInfo, CodeModel, _, Code, !CI) :-
+    Goal = foreign_proc(Attributes, PredId, ProcId, Args, ExtraArgs,
+        PragmaCode),
     ( c = foreign_language(Attributes) ->
         pragma_c_gen__generate_pragma_c_code(CodeModel, Attributes,
             PredId, ProcId, Args, ExtraArgs, GoalInfo, PragmaCode, Code, !CI)
     ;
         unexpected(this_file,
-            "code_gen__generate_goal_2: foreign code other than C unexpected")
+            "generate_goal_2: foreign code other than C unexpected")
     ).
-code_gen__generate_goal_2(shorthand(_), _, _, _, !CI) :-
+code_gen__generate_goal_2(shorthand(_), _, _, _, _, !CI) :-
     % These should have been expanded out by now.
-    unexpected(this_file, "code_gen__generate_goal_2: unexpected shorthand").
+    unexpected(this_file, "generate_goal_2: unexpected shorthand").

 %---------------------------------------------------------------------------%

Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.310
diff -u -r1.310 code_info.m
--- compiler/code_info.m	28 Oct 2005 02:09:59 -0000	1.310
+++ compiler/code_info.m	17 Nov 2005 02:52:38 -0000
@@ -1231,7 +1231,7 @@
     %
 :- type det_commit_info.

-:- pred prepare_for_det_commit(det_commit_info::out,
+:- pred prepare_for_det_commit(add_trail_ops::in, det_commit_info::out,
     code_tree::out, code_info::in, code_info::out) is det.

 :- pred generate_det_commit(det_commit_info::in,
@@ -1244,7 +1244,7 @@
     %
 :- type semi_commit_info.

-:- pred prepare_for_semi_commit(semi_commit_info::out,
+:- pred prepare_for_semi_commit(bool::in, semi_commit_info::out,
     code_tree::out, code_info::in, code_info::out) is det.

 :- pred generate_semi_commit(semi_commit_info::in,
@@ -1746,7 +1746,7 @@
                                     % counter and trail pointer.
             ).

-prepare_for_det_commit(DetCommitInfo, Code, !CI) :-
+prepare_for_det_commit(AddTrailOps, DetCommitInfo, Code, !CI) :-
     get_fail_info(!.CI, FailInfo0),
     FailInfo0 = fail_info(_, _, CurfrMaxfr, _, _),
     (
@@ -1761,7 +1761,7 @@
         SaveMaxfrCode = empty,
         MaybeMaxfrSlot = no
     ),
-    maybe_save_trail_info(MaybeTrailSlots, SaveTrailCode, !CI),
+    maybe_save_trail_info(AddTrailOps, MaybeTrailSlots, SaveTrailCode, !CI),
     DetCommitInfo = det_commit_info(MaybeMaxfrSlot, MaybeTrailSlots),
     Code = tree(SaveMaxfrCode, SaveTrailCode).

@@ -1816,7 +1816,7 @@
                             % the value of maxfr.
             ).

-prepare_for_semi_commit(SemiCommitInfo, Code, !CI) :-
+prepare_for_semi_commit(AddTrailOps, SemiCommitInfo, Code, !CI) :-
     get_fail_info(!.CI, FailInfo0),
     FailInfo0 = fail_info(ResumePoints0, ResumeKnown, CurfrMaxfr, CondEnv,
         Allow),
@@ -1917,7 +1917,7 @@
                 - "hijack the redoip slot"
         ])
     ),
-    maybe_save_trail_info(MaybeTrailSlots, SaveTrailCode, !CI),
+    maybe_save_trail_info(AddTrailOps, MaybeTrailSlots, SaveTrailCode, !CI),
     SemiCommitInfo = semi_commit_info(FailInfo0, NewResumePoint,
         HijackInfo, MaybeTrailSlots),
     Code = tree(HijackCode, SaveTrailCode).
@@ -2584,14 +2584,12 @@

 %---------------------------------------------------------------------------%

-:- pred maybe_save_trail_info(maybe(pair(lval))::out,
+:- pred maybe_save_trail_info(bool::in, maybe(pair(lval))::out,
     code_tree::out, code_info::in, code_info::out) is det.

-maybe_save_trail_info(MaybeTrailSlots, SaveTrailCode, !CI) :-
-    get_globals(!.CI, Globals),
-    globals__lookup_bool_option(Globals, use_trail, UseTrail),
+maybe_save_trail_info(AddTrailOps, MaybeTrailSlots, SaveTrailCode, !CI) :-
     (
-        UseTrail = yes,
+        AddTrailOps = yes,
         acquire_temp_slot(ticket_counter, CounterSlot, !CI),
         acquire_temp_slot(ticket, TrailPtrSlot, !CI),
         MaybeTrailSlots = yes(CounterSlot - TrailPtrSlot),
@@ -2600,7 +2598,7 @@
             store_ticket(TrailPtrSlot) - "save the trail pointer"
         ])
     ;
-        UseTrail = no,
+        AddTrailOps = no,
         MaybeTrailSlots = no,
         SaveTrailCode = empty
     ).
Index: compiler/code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_util.m,v
retrieving revision 1.159
diff -u -r1.159 code_util.m
--- compiler/code_util.m	28 Oct 2005 02:10:00 -0000	1.159
+++ compiler/code_util.m	17 Nov 2005 03:05:19 -0000
@@ -23,6 +23,7 @@
 :- import_module hlds.hlds_llds.
 :- import_module hlds.hlds_module.
 :- import_module hlds.hlds_pred.
+:- import_module libs.globals.
 :- import_module ll_backend.llds.
 :- import_module mdbcomp.prim_data.
 :- import_module parse_tree.prog_data.
@@ -92,6 +93,19 @@
     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, module_info, hlds_goal) = add_trail_ops.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%

 :- implementation.

@@ -99,9 +113,9 @@
 :- import_module backend_libs.proc_label.
 :- import_module backend_libs.rtti.
 :- import_module hlds.code_model.
+:- import_module hlds.goal_form.
 :- import_module hlds.special_pred.
 :- import_module libs.compiler_util.
-:- import_module libs.globals.
 :- import_module libs.options.
 :- import_module parse_tree.prog_util.

@@ -441,6 +455,33 @@
     ),
     build_input_arg_list_2(Rest0, VarArgs0).

+%---------------------------------------------------------------------------%
+%
+% Utility predicates used to implement trailing
+%
+
+should_add_trail_ops(Globals, ModuleInfo, Goal) = AddTrailOps :-
+    globals.lookup_bool_option(Globals, use_trail, UseTrail),
+    (
+        UseTrail = no,
+        AddTrailOps = no
+    ;
+        UseTrail = yes,
+        globals.lookup_bool_option(Globals, optimize_trail_usage,
+            OptTrailUsage),
+        (
+            OptTrailUsage = no,
+            AddTrailOps = yes
+        ;
+            OptTrailUsage = yes,
+            ( goal_cannot_modify_trail(ModuleInfo, Goal) ->
+                AddTrailOps = no
+            ;
+                AddTrailOps = yes
+            )
+        )
+    ).
+
 %-----------------------------------------------------------------------------%

 :- func this_file = string.
@@ -448,3 +489,5 @@
 this_file = "code_util.m".

 %-----------------------------------------------------------------------------%
+:- end_module code_util.
+%-----------------------------------------------------------------------------%
Index: compiler/commit_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/commit_gen.m,v
retrieving revision 1.8
diff -u -r1.8 commit_gen.m
--- compiler/commit_gen.m	28 Oct 2005 02:10:01 -0000	1.8
+++ compiler/commit_gen.m	17 Nov 2005 02:55:52 -0000
@@ -23,8 +23,13 @@
 :- import_module ll_backend.code_info.
 :- import_module ll_backend.llds.

-:- pred commit_gen__generate_commit(code_model::in, hlds_goal::in,
-    code_tree::out, code_info::in, code_info::out) is det.
+%---------------------------------------------------------------------------%
+
+:- pred commit_gen__generate_commit(add_trail_ops::in, code_model::in,
+    hlds_goal::in, code_tree::out, code_info::in, code_info::out) is det.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%

 :- implementation.

@@ -35,7 +40,9 @@
 :- import_module require.
 :- import_module std_util.

-commit_gen__generate_commit(OuterCodeModel, Goal, Code, !Info) :-
+%---------------------------------------------------------------------------%
+
+generate_commit(AddTrailOps, OuterCodeModel, Goal, Code, !Info) :-
     Goal = _ - InnerGoalInfo,
     goal_info_get_code_model(InnerGoalInfo, InnerCodeModel),
     (
@@ -48,7 +55,8 @@
             unexpected(this_file, "semidet model in det context")
         ;
             InnerCodeModel = model_non,
-            code_info__prepare_for_det_commit(CommitInfo, PreCommit, !Info),
+            code_info__prepare_for_det_commit(AddTrailOps, CommitInfo,
+                PreCommit, !Info),
             code_gen__generate_goal(InnerCodeModel, Goal, GoalCode, !Info),
             code_info__generate_det_commit(CommitInfo, Commit, !Info),
             Code = tree(PreCommit, tree(GoalCode, Commit))
@@ -63,7 +71,8 @@
             code_gen__generate_goal(InnerCodeModel, Goal, Code, !Info)
         ;
             InnerCodeModel = model_non,
-            code_info__prepare_for_semi_commit(CommitInfo, PreCommit, !Info),
+            code_info__prepare_for_semi_commit(AddTrailOps, CommitInfo,
+                PreCommit, !Info),
             code_gen__generate_goal(InnerCodeModel, Goal, GoalCode, !Info),
             code_info__generate_semi_commit(CommitInfo, Commit, !Info),
             Code = tree(PreCommit, tree(GoalCode, Commit))
@@ -80,3 +89,5 @@
 this_file = "commit_gen.m".

 %---------------------------------------------------------------------------%
+:- end_module commit_gen.
+%---------------------------------------------------------------------------%
Index: compiler/disj_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/disj_gen.m,v
retrieving revision 1.85
diff -u -r1.85 disj_gen.m
--- compiler/disj_gen.m	28 Oct 2005 02:10:03 -0000	1.85
+++ compiler/disj_gen.m	17 Nov 2005 02:57:01 -0000
@@ -12,8 +12,8 @@
 %
 % The predicates of this module generate code for disjunctions.
 %
-%---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- module ll_backend__disj_gen.

@@ -26,10 +26,13 @@

 :- import_module list.

-:- pred disj_gen__generate_disj(code_model::in, list(hlds_goal)::in,
+%-----------------------------------------------------------------------------%
+
+:- pred generate_disj(add_trail_ops::in, code_model::in, list(hlds_goal)::in,
     hlds_goal_info::in, code_tree::out, code_info::in, code_info::out) is det.

-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- implementation.

@@ -51,7 +54,9 @@
 :- import_module std_util.
 :- import_module term.

-disj_gen__generate_disj(CodeModel, Goals, DisjGoalInfo, Code, !CI) :-
+%-----------------------------------------------------------------------------%
+
+generate_disj(AddTrailOps, CodeModel, Goals, DisjGoalInfo, Code, !CI) :-
     (
         Goals = [],
         ( CodeModel = model_semi ->
@@ -68,18 +73,18 @@
         ;
             set__init(ResumeVars)
         ),
-        disj_gen__generate_real_disj(CodeModel, ResumeVars, Goals,
+        generate_real_disj(AddTrailOps, CodeModel, ResumeVars, Goals,
             DisjGoalInfo, Code, !CI)
     ).

 %---------------------------------------------------------------------------%

-:- pred disj_gen__generate_real_disj(code_model::in, set(prog_var)::in,
-    list(hlds_goal)::in, hlds_goal_info::in, code_tree::out,
-    code_info::in, code_info::out) is det.
+:- pred disj_gen__generate_real_disj(bool::in, code_model::in,
+    set(prog_var)::in, list(hlds_goal)::in, hlds_goal_info::in,
+    code_tree::out, code_info::in, code_info::out) is det.

-disj_gen__generate_real_disj(CodeModel, ResumeVars, Goals, DisjGoalInfo, Code,
-        !CI)  :-
+generate_real_disj(AddTrailOps, CodeModel, ResumeVars, Goals, DisjGoalInfo,
+        Code, !CI)  :-

         % Make sure that the variables whose values will be needed
         % on backtracking to any disjunct are materialized into
@@ -93,8 +98,7 @@
         % recovery for semi and det disjunctions, and delay saving
         % the ticket until necessary.
     code_info__get_globals(!.CI, Globals),
-    globals__lookup_bool_option(Globals, use_trail, UseTrail),
-    code_info__maybe_save_ticket(UseTrail, SaveTicketCode, MaybeTicketSlot,
+    code_info__maybe_save_ticket(AddTrailOps, SaveTicketCode, MaybeTicketSlot,
         !CI),

         % If we are using a grade in which we can recover memory
@@ -131,7 +135,7 @@
     code_info__get_next_label(EndLabel, !CI),

     code_info__remember_position(!.CI, BranchStart),
-    disj_gen__generate_disjuncts(Goals, CodeModel, ResumeMap, no, HijackInfo,
+    generate_disjuncts(Goals, CodeModel, ResumeMap, no, HijackInfo,
         DisjGoalInfo, EndLabel, ReclaimHeap, MaybeHpSlot, MaybeTicketSlot,
         BranchStart, no, MaybeEnd, GoalsCode, !CI),

@@ -147,15 +151,15 @@

 %---------------------------------------------------------------------------%

-:- pred disj_gen__generate_disjuncts(list(hlds_goal)::in, code_model::in,
+:- pred generate_disjuncts(list(hlds_goal)::in, code_model::in,
     resume_map::in, maybe(resume_point_info)::in, disj_hijack_info::in,
     hlds_goal_info::in, label::in, bool::in, maybe(lval)::in, maybe(lval)::in,
     position_info::in, maybe(branch_end_info)::in, maybe(branch_end_info)::out,
     code_tree::out, code_info::in, code_info::out) is det.

-disj_gen__generate_disjuncts([], _, _, _, _, _, _, _, _, _, _, _, _, _, !CI) :-
+generate_disjuncts([], _, _, _, _, _, _, _, _, _, _, _, _, _, !CI) :-
     error("empty disjunction!").
-disj_gen__generate_disjuncts([Goal0 | Goals], CodeModel, FullResumeMap,
+generate_disjuncts([Goal0 | Goals], CodeModel, FullResumeMap,
         MaybeEntryResumePoint, HijackInfo, DisjGoalInfo, EndLabel, ReclaimHeap,
         MaybeHpSlot0, MaybeTicketSlot, BranchStart0, MaybeEnd0, MaybeEnd,
         Code, !CI) :-
@@ -316,4 +320,12 @@
             RestoreTicketCode, UndoCode, GoalCode, SaveCode, EndCode])
     ).

-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- func this_file = string.
+
+this_file = "disj_gen.m".
+
+%-----------------------------------------------------------------------------%
+:- end_module disj_gen.
+%-----------------------------------------------------------------------------%
Index: compiler/hlds_goal.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_goal.m,v
retrieving revision 1.144
diff -u -r1.144 hlds_goal.m
--- compiler/hlds_goal.m	15 Nov 2005 03:37:55 -0000	1.144
+++ compiler/hlds_goal.m	17 Nov 2005 01:13:42 -0000
@@ -1056,7 +1056,7 @@

 %-----------------------------------------------------------------------------%
 %
-% Get/set predicates for the extra_goal_info strucutre..
+% Get/set predicates for the extra_goal_info structure
 %

 :- func goal_info_get_ho_values(hlds_goal_info) = ho_values.
@@ -2354,3 +2354,5 @@
 this_file = "hlds_goal".

 %-----------------------------------------------------------------------------%
+:- end_module hlds_goal.
+%-----------------------------------------------------------------------------%
Index: compiler/ite_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ite_gen.m,v
retrieving revision 1.82
diff -u -r1.82 ite_gen.m
--- compiler/ite_gen.m	28 Oct 2005 02:10:11 -0000	1.82
+++ compiler/ite_gen.m	17 Nov 2005 03:01:05 -0000
@@ -25,13 +25,17 @@
 :- import_module ll_backend.code_info.
 :- import_module ll_backend.llds.

-:- pred ite_gen__generate_ite(code_model::in, hlds_goal::in, hlds_goal::in,
+%---------------------------------------------------------------------------%
+
+:- pred ite_gen__generate_ite(add_trail_ops::in, code_model::in,
+    hlds_goal::in, hlds_goal::in, hlds_goal::in, hlds_goal_info::in,
+    code_tree::out, code_info::in, code_info::out) is det.
+
+:- pred ite_gen__generate_negation(add_trail_ops::in, code_model::in,
     hlds_goal::in, hlds_goal_info::in, code_tree::out,
     code_info::in, code_info::out) is det.

-:- pred ite_gen__generate_negation(code_model::in, hlds_goal::in,
-    hlds_goal_info::in, code_tree::out, code_info::in, code_info::out) is det.
-
+%---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%

 :- implementation.
@@ -57,8 +61,10 @@
 :- import_module string.
 :- import_module term.

-ite_gen__generate_ite(CodeModel, CondGoal0, ThenGoal, ElseGoal, IteGoalInfo,
-        Code, !CI) :-
+%---------------------------------------------------------------------------%
+
+generate_ite(AddTrailOps, CodeModel, CondGoal0, ThenGoal,
+        ElseGoal, IteGoalInfo, Code, !CI) :-
     CondGoal0 = CondExpr - CondInfo0,
     goal_info_get_code_model(CondInfo0, CondCodeModel),
     (
@@ -107,8 +113,7 @@
     code_info__maybe_save_hp(ReclaimHeap, SaveHpCode, MaybeHpSlot, !CI),

     % Maybe save the current trail state before the condition.
-    globals__lookup_bool_option(Globals, use_trail, UseTrail),
-    code_info__maybe_save_ticket(UseTrail, SaveTicketCode, MaybeTicketSlot,
+    code_info__maybe_save_ticket(AddTrailOps, SaveTicketCode, MaybeTicketSlot,
         !CI),

     code_info__remember_position(!.CI, BranchStart),
@@ -217,9 +222,10 @@
         EndLabelCode]),
     code_info__after_all_branches(StoreMap, MaybeEnd, !CI).

-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

-ite_gen__generate_negation(CodeModel, Goal0, NotGoalInfo, Code, !CI) :-
+generate_negation(AddTrailOps, CodeModel, Goal0, NotGoalInfo, Code,
+        !CI) :-
     ( CodeModel = model_non ->
         error("nondet negation")
     ;
@@ -268,19 +274,19 @@
         code_info__leave_simple_neg(GoalInfo, SimpleNeg, !CI),
         Code = tree(tree(CodeL, CodeR), TestCode)
     ;
-        generate_negation_general(CodeModel, Goal, NotGoalInfo,
+        generate_negation_general(AddTrailOps, CodeModel, Goal, NotGoalInfo,
             ResumeVars, ResumeLocs, Code, !CI)
     ).

     % The code of generate_negation_general is a cut-down version
     % of the code for if-then-elses.
     %
-:- pred generate_negation_general(code_model::in, hlds_goal::in,
-    hlds_goal_info::in, set(prog_var)::in, resume_locs::in, code_tree::out,
-    code_info::in, code_info::out) is det.
+:- pred generate_negation_general(add_trail_ops::in, code_model::in,
+    hlds_goal::in, hlds_goal_info::in, set(prog_var)::in, resume_locs::in,
+    code_tree::out, code_info::in, code_info::out) is det.

-generate_negation_general(CodeModel, Goal, NotGoalInfo, ResumeVars, ResumeLocs,
-        Code, !CI) :-
+generate_negation_general(AddTrailOps, CodeModel, Goal, NotGoalInfo,
+        ResumeVars, ResumeLocs, Code, !CI) :-

     code_info__produce_vars(ResumeVars, ResumeMap, FlushCode, !CI),

@@ -299,8 +305,7 @@
     ),
     code_info__maybe_save_hp(ReclaimHeap, SaveHpCode, MaybeHpSlot, !CI),

-    globals__lookup_bool_option(Globals, use_trail, UseTrail),
-    code_info__maybe_save_ticket(UseTrail, SaveTicketCode,
+    code_info__maybe_save_ticket(AddTrailOps, SaveTicketCode,
         MaybeTicketSlot, !CI),

     code_info__prepare_for_ite_hijack(CodeModel, HijackInfo,
@@ -353,7 +358,7 @@

     % Restore the heap pointer and solver state if necessary.
     code_info__maybe_restore_and_release_hp(MaybeHpSlot, RestoreHpCode, !CI),
-    code_info__maybe_reset_discard_and_release_ticket( MaybeTicketSlot, undo,
+    code_info__maybe_reset_discard_and_release_ticket(MaybeTicketSlot, undo,
         RestoreTicketCode, !CI),
     trace__maybe_generate_negated_event_code(Goal, NotGoalInfo,
         neg_success, SuccessTraceCode, !CI),
@@ -447,10 +452,12 @@
         Code,
         "\t\tMR_restore_transient_registers();\n"]).

-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

 :- func this_file = string.

 this_file = "ite_gen".

-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+:- end_module ite_gen.
+%-----------------------------------------------------------------------------%
Index: compiler/llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.322
diff -u -r1.322 llds.m
--- compiler/llds.m	28 Oct 2005 02:10:14 -0000	1.322
+++ compiler/llds.m	17 Nov 2005 02:44:44 -0000
@@ -623,6 +623,8 @@
     ;       retry
     ;       gc.

+:- type add_trail_ops == bool.
+
     % Each call instruction has a list of liveinfo, which stores information
     % about which variables are live after the call (that is, on return).
     % The information is intended for use by the native garbage collector.
Index: compiler/prog_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.147
diff -u -r1.147 prog_data.m
--- compiler/prog_data.m	8 Nov 2005 08:14:54 -0000	1.147
+++ compiler/prog_data.m	16 Nov 2005 07:03:38 -0000
@@ -352,7 +352,7 @@
 % Mutable variables
 %

-    % Indicates if  updates to the mutable are trailed or untrailed.
+    % Indicates if updates to the mutable are trailed or untrailed.
     %
 :- type trailed
     --->    trailed
--------------------------------------------------------------------------
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