[m-rev.] For post-commit review: Fix coverage profiling bugs.

Paul Bone pbone at csse.unimelb.edu.au
Sat Sep 20 19:20:39 AEST 2008


For post-commit review by Zoltan.

This doesn't fix all the problems, however it's a convinent place for me to
commit my work before I make large changes.

Estimated hours taken: 2
Branches: main

Fix some coverage profiling bugs.

compiler/deep_profiling.m:
	A goal introduced by the deep profiler for scopes was not marked as
	instrumentation,
  
	If a coverage point has been inserted after a goal that is not deterministic,
	we cannot infer the coverage before this goal.  Previously, the coverage
	profiling transformation assumed that we could infer the coverage before
	this goal.

	We now assume that the coverage after a negated goal cannot be calculated
	from the coverage after the entire negation.  This is also true for scopes
	that cut the number of solutions.

	Correct comments in coverage profiling of if-then-else goals.

	Remove duplicated code in the coverage profiling of if-then-else goals.

	The coverage after a condition of an if-then-else can only be inferred by
	the coverage at the beginning of the else branch.

Index: compiler/deep_profiling.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/deep_profiling.m,v
retrieving revision 1.84
diff -u -p -b -r1.84 deep_profiling.m
--- compiler/deep_profiling.m	18 Sep 2008 12:41:54 -0000	1.84
+++ compiler/deep_profiling.m	20 Sep 2008 08:55:15 -0000
@@ -1052,7 +1052,9 @@ deep_prof_transform_goal(Path, Goal0, Go
             Goal = hlds_goal(scope(Reason, SubGoal), GoalInfo)
         ;
             AddForceCommit = yes,
-            InnerGoal = hlds_goal(scope(Reason, SubGoal), GoalInfo),
+            goal_info_set_mdprof_inst(goal_is_mdprof_inst, GoalInfo, 
+                InnerGoalInfo),
+            InnerGoal = hlds_goal(scope(Reason, SubGoal), InnerGoalInfo),
             Goal = hlds_goal(scope(commit(force_pruning), InnerGoal), GoalInfo)
         )
     ;
@@ -2166,12 +2168,14 @@ coverage_prof_second_pass_goal(Goal0, Go
     % Update coverage known information.
     (
         MaybeCPType = yes(_),
-        CoverageAfterKnown = coverage_after_known
+        CoverageAfterKnown2 = coverage_after_known
     ;
         MaybeCPType = no,
+        CoverageAfterKnown2 = CoverageAfterKnown1
+    ),
+    % If the goal has a port count, then coverage is known at the point directy
+    % before this goal.
         (
-            % If the goal has a port count, then coverage is known at the
-            % point directy before this goal.
             GoalPortCountsCoverageAfter = port_counts_give_coverage_after,
             CoverageAfterKnown = coverage_after_known
         ;
@@ -2192,8 +2196,7 @@ coverage_prof_second_pass_goal(Goal0, Go
                 ( Detism = detism_det
                 ; Detism = detism_cc_multi
                 ),
-                CoverageAfterKnown = CoverageAfterKnown1
-            )
+            CoverageAfterKnown = CoverageAfterKnown2
         )
     ),
 
@@ -2254,13 +2257,24 @@ coverage_prof_second_pass_goal(Goal0, Go
         GoalExpr1 = switch(Var, SwitchCanFail, Cases)
     ;
         GoalExpr0 = negation(NegGoal0),
-        coverage_prof_second_pass_goal(NegGoal0, NegGoal, CoverageAfterKnown,
-            NextCoverageAfterKnown, !Info, AddedImpurityInner),
+        % The coverage after a negated goal is always unknown.
+        coverage_prof_second_pass_goal(NegGoal0, NegGoal, 
+            coverage_after_unknown, NextCoverageAfterKnown, !Info,
+            AddedImpurityInner),
         GoalExpr1 = negation(NegGoal)
     ;
         GoalExpr0 = scope(Reason, ScopeGoal0),
+        % A scope may cut away solutions, if it does we don't know the number
+        % of solutions of the scoped goal.
+        ScopedGoalDetism =
+            ScopeGoal0 ^ hlds_goal_info ^ goal_info_get_determinism,
+        ( ScopedGoalDetism = Detism ->
+            CoverageAfterScopedGoalKnown = CoverageAfterKnown
+        ;
+            CoverageAfterScopedGoalKnown = coverage_after_unknown
+        ),
         coverage_prof_second_pass_goal(ScopeGoal0, ScopeGoal,
-            CoverageAfterKnown, NextCoverageAfterKnown, !Info,
+            CoverageAfterScopedGoalKnown, NextCoverageAfterKnown, !Info,
             AddedImpurityInner),
         GoalExpr1 = scope(Reason, ScopeGoal)
     ;
@@ -2494,26 +2508,10 @@ coverage_prof_second_pass_ite(DPInfo, IT
                 CoverageAfterElseKnown = coverage_after_known
             )
         ;
-            % The arms of the switch are nondeterministic.  Set the coverage to
-            % unknown for each arm unless port counts are available from within
-            % that goal.
-            (
-                ThenPortCountsCoverageAfter = port_counts_give_coverage_after,
-                CoverageAfterThenKnown = coverage_after_known
-            ;   
-                ThenPortCountsCoverageAfter =
-                    no_port_counts_give_coverage_after,
-                CoverageAfterThenKnown = coverage_after_unknown
-            ),
-            (
-                ElsePortCountsCoverageAfter = port_counts_give_coverage_after,
-                CoverageAfterElseKnown = coverage_after_known
-            ;   
-                ElsePortCountsCoverageAfter =
-                    no_port_counts_give_coverage_after,
+            % The branches of the ITE are not deterministic.
+            CoverageAfterThenKnown = coverage_after_unknown,
                 CoverageAfterElseKnown = coverage_after_unknown
             )
-        )        
     ;
         CoverageAfterITEKnown = coverage_after_unknown,
         CoverageAfterElseKnown = coverage_after_unknown,
@@ -2555,6 +2553,10 @@ coverage_prof_second_pass_ite(DPInfo, IT
         ;
             CoverageBeforeThenKnown1 = coverage_after_known,
             InsertCPThen = no
+        )
+    ;
+        % Don't insert any coverage points,
+        InsertCPThen = no
         ),
         (
             CoverageBeforeElseKnown1 = coverage_after_unknown,
@@ -2564,16 +2566,11 @@ coverage_prof_second_pass_ite(DPInfo, IT
         ;
             CoverageBeforeElseKnown1 = coverage_after_known,
             InsertCPElse = no
-        )
-    ;
-        % Don't insert any coverage points,
-        InsertCPThen = no,
-        InsertCPElse = no
     ),
 
     % Insert any coverage points.
     maybe_insert_coverage_point_before(InsertCPElse, Else1, Else,
-        CoverageBeforeElseKnown1, CoverageBeforeElseKnown, !Info,
+        CoverageBeforeElseKnown1, _CoverageBeforeElseKnown, !Info,
         AddedImpurityElseCP),
     bool.or(AddedImpurityElseGoal, AddedImpurityElseCP, AddedImpurityElse),
 
@@ -2583,8 +2580,7 @@ coverage_prof_second_pass_ite(DPInfo, IT
     bool.or(AddedImpurityThenGoal, AddedImpurityThenCP, AddedImpurityThen),
 
     % Transform Cond branch.
-    coverage_after_known_branch(CoverageBeforeThenKnown,
-        CoverageBeforeElseKnown, CoverageKnownAfterCond),
+    CoverageKnownAfterCond = CoverageBeforeThenKnown,
     coverage_prof_second_pass_goal(Cond0, Cond,
         CoverageKnownAfterCond, NextCoverageAfterKnown, !Info,
         AddedImpurityCond),

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20080920/3fbf86af/attachment.sig>


More information about the reviews mailing list