[m-rev.] for review: loop hoist const goals

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Feb 10 20:32:41 AEDT 2004


On 10-Feb-2004, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Enable loop invariant hoisting for goals that have no input arguments.

Further testing (in particular building the standard library in grade java
with --loop-invariants) uncovered a bug which is fixed by the following
relative diff.

--- CHANGES2	2004-02-09 19:41:47.000000000 +1100
+++ CHANGES2b	2004-02-10 20:28:14.000000000 +1100
@@ -1,5 +1,5 @@
 
-Estimated hours taken: 1
+Estimated hours taken: 2
 Branches: main
 
 Enable loop invariant hoisting for goals that have no input arguments.
@@ -8,6 +8,8 @@
 	Delete the code which was explicitly disable loop invariant
 	hoisting for "const goals", i.e. goals that have no input arguments.
 	(Why was this code there in the first place?)
+	Instead, add some code to prevent loop invariant hoisting for
+	goals that cannot succeed.
 
 tests/hard_coded/Mmakefile:
 	Enable loop_inv_test1, since we now pass it.

diff -u compiler/loop_inv.m compiler/loop_inv.m
--- compiler/loop_inv.m	9 Feb 2004 06:18:18 -0000
+++ compiler/loop_inv.m	10 Feb 2004 05:24:34 -0000
@@ -126,6 +126,7 @@
 :- import_module check_hlds__purity.
 :- import_module hlds__error_util.
 :- import_module hlds__hlds_goal.
+:- import_module hlds__hlds_data.
 :- import_module hlds__instmap.
 :- import_module hlds__quantification.
 :- import_module parse_tree__inst.
@@ -198,6 +199,15 @@
             % (it's probably cheaper to do the dereference than pass an extra
             % argument).
             %
+            % We also don't want to hoist out goals that can't succeed,
+            % e.g. calls to error/1, and in fact we MUST NOT hoist out
+            % such goals, because if we hoisted out such goals, later
+            % passes might think that the code which follows is actually
+            % reachable, which may lead to internal errors because code
+            % which follow a call to error/1 need not be determinism-correct.
+            %
+            % We also must not hoist impure goals.
+            %
             % So here we compute the subset of InvGoals (and the corresponding
             % InvVars) that should not be hoisted.
             %
@@ -602,6 +612,7 @@
         (   const_construction(Goal)
         ;   deconstruction(Goal)
         ;   impure_goal(Goal)
+        ;   cannot_succeed(Goal)
         )
       then
         DHGs = [Goal | DHGs0],
@@ -647,0 +658,10 @@
+:- pred cannot_succeed(hlds_goal).
+:- mode cannot_succeed(in) is semidet.
+
+cannot_succeed(_GoalExpr - GoalInfo) :-
+    goal_info_get_determinism(GoalInfo, Detism),
+    determinism_components(Detism, _CanFail, MaxSolns),
+    MaxSolns = at_most_zero.
+
+%------------------------------------------------------------------------------%
+


-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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