[m-rev.] diff: Coverage Profiling: Reduce the number of coverage points required for disjunctions.

Paul Bone pbone at csse.unimelb.edu.au
Sun Sep 28 17:48:08 AEST 2008


Estimated hours taken: 0.5
Branches: main

Reduce the number of coverage points required for disjunctions.  The coverage
after a disjunction is equal to the sum of the coverage after each disjunct,
this can be used to avoid placing a coverage point after each disjunction.

deep_profiler/program_representation_utils.m:
compiler/deep_profiling.m:
	As above.

Index: compiler/deep_profiling.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/deep_profiling.m,v
retrieving revision 1.89
diff -u -p -b -r1.89 deep_profiling.m
--- compiler/deep_profiling.m	27 Sep 2008 11:56:19 -0000	1.89
+++ compiler/deep_profiling.m	28 Sep 2008 07:12:44 -0000
@@ -2314,16 +2314,18 @@ coverage_prof_second_pass_disj(DPInfo, C
         Disjuncts = [FirstDisjunct, SecondDisjunct]
     ;
         coverage_prof_second_pass_disj_2(DPInfo, CoverageBeforeKnown,
-            Disjuncts0, Disjuncts, !Info, AddedImpurity),
-        NextCoverageBeforeKnown = coverage_before_unknown
+            coverage_before_known, NextCoverageBeforeKnown,
+            Disjuncts0, Disjuncts, !Info, AddedImpurity)
     ).
 
 :- pred coverage_prof_second_pass_disj_2(dp_goal_info::in,
-    coverage_before_known::in, list(hlds_goal)::in, list(hlds_goal)::out,
+    coverage_before_known::in,
+    coverage_before_known::in, coverage_before_known::out,
+    list(hlds_goal)::in, list(hlds_goal)::out,
     proc_coverage_info::in, proc_coverage_info::out, bool::out) is det.
 
-coverage_prof_second_pass_disj_2(_, _, [], [], !Info, no).
-coverage_prof_second_pass_disj_2(DPInfo, CoverageBeforeKnown0,
+coverage_prof_second_pass_disj_2(_, _, !CoverageKnownAfter, [], [], !Info, no).
+coverage_prof_second_pass_disj_2(DPInfo, CoverageBeforeKnown0, !CoverageAfterKnown,
         [HeadDisjunct0 | TailDisjuncts0], [HeadDisjunct | TailDisjuncts],
         !Info, AddedImpurity) :-
     % Decide whether we want to insert a branch coverage point at the beginning
@@ -2344,10 +2346,13 @@ coverage_prof_second_pass_disj_2(DPInfo,
     ),
 
     coverage_prof_second_pass_goal(HeadDisjunct0, HeadDisjunct1,
-        CoverageBeforeKnown, _CoverageAfterHeadKnown, !Info,
+        CoverageBeforeKnown, CoverageAfterDisjKnown, !Info,
         AddedImpurityHead),
+    !:CoverageAfterKnown = 
+        coverage_before_known_and(!.CoverageAfterKnown, CoverageAfterDisjKnown),
     coverage_prof_second_pass_disj_2(DPInfo, coverage_before_unknown,
-        TailDisjuncts0, TailDisjuncts, !Info, AddedImpurityTail),
+        !CoverageAfterKnown, TailDisjuncts0, TailDisjuncts, !Info,
+        AddedImpurityTail),
 
     % Insert the coverage point if we decided to above.
     (
Index: deep_profiler/program_representation_utils.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/program_representation_utils.m,v
retrieving revision 1.8
diff -u -p -b -r1.8 program_representation_utils.m
--- deep_profiler/program_representation_utils.m	27 Sep 2008 14:17:18 -0000	1.8
+++ deep_profiler/program_representation_utils.m	28 Sep 2008 07:23:07 -0000
@@ -737,7 +737,7 @@ conj_annotate_coverage_2(Info, GoalPath,
     %   - The coverage before a disjunction is equal to the coverage before the
     %     first disjunct.
     %   - The coverage after a disjunction is equal to the sum of coverages
-    %     after each disjunct.  This rule is not yet implemented.
+    %     after each disjunct.
     %
 :- pred disj_annotate_coverage(coverage_reference_info::in, detism_rep::in,
     goal_path::in, coverage_info::in, coverage_info::out,
@@ -745,19 +745,21 @@ conj_annotate_coverage_2(Info, GoalPath,
 
 disj_annotate_coverage(Info, Detism, GoalPath, !Coverage,
         Disjs0, Disjs) :-
-    CoverageBefore0 = get_coverage_before(!.Coverage),
+    CoverageBefore = get_coverage_before(!.Coverage),
     Solutions = detism_get_solutions(Detism),
     disj_annotate_coverage_2(Info, GoalPath, 1, Solutions,
-        CoverageBefore0, Disjs0, Disjs).
+        CoverageBefore, coverage_known_after(0), CoverageAfter, Disjs0, Disjs),
+    !:Coverage = merge_coverage(CoverageBefore, CoverageAfter).
 
 :- pred disj_annotate_coverage_2(coverage_reference_info::in,
     goal_path::in, int::in, solution_count::in,
     coverage_info::in(coverage_before),
+    coverage_info::in(coverage_after), coverage_info::out(coverage_after),
     list(goal_rep)::in, list(goal_rep(coverage_info))::out) is det.
 
-disj_annotate_coverage_2(_, _, _, _, _, [], []).
+disj_annotate_coverage_2(_, _, _, _, _, !CoverageAfter, [], []).
 disj_annotate_coverage_2(Info, GoalPath, DisjNum, Solutions, CoverageBefore0,
-        [Disj0 | Disjs0], [Disj | Disjs]) :-
+        !CoverageAfter, [Disj0 | Disjs0], [Disj | Disjs]) :-
     DisjGoalPath = goal_path_add_at_end(GoalPath, step_disj(DisjNum)),
     (
         CoverageBefore0 = coverage_unknown,
@@ -766,11 +768,20 @@ disj_annotate_coverage_2(Info, GoalPath,
         CoverageBefore0 = coverage_known_before(_),
         CoverageBefore1 = CoverageBefore0
     ),
-    goal_annotate_coverage(Info, DisjGoalPath, CoverageBefore1, _CoverageDisj,
+    goal_annotate_coverage(Info, DisjGoalPath, CoverageBefore1, CoverageDisj,
         Disj0, Disj),
+    (
+        coverage_count_after(!.CoverageAfter, CoverageAfter0),
+        coverage_count_after(CoverageDisj, CoverageAfterDisj)
+    ->
+        !:CoverageAfter = 
+            coverage_known_after(CoverageAfter0 + CoverageAfterDisj)
+    ;
+        !:CoverageAfter = coverage_unknown
+    ),
 
     disj_annotate_coverage_2(Info, GoalPath, DisjNum + 1, Solutions,
-        coverage_unknown, Disjs0, Disjs).
+        coverage_unknown, !CoverageAfter, Disjs0, Disjs).
 
 :- pred switch_annotate_coverage(coverage_reference_info::in,
     switch_can_fail_rep::in, goal_path::in,
@@ -879,7 +890,7 @@ switch_annotate_coverage_2(Info, CanFail
         get_branch_coverage(Info, CaseGoalPath, Coverage0)
     ),
 
-    % Look for a coverage point for this switch case.
+    % Calculate and annotate the coverage for the case itself.
     Case0 = case_rep(ConsID, OtherConsIDs, Goal0),
     goal_annotate_coverage(Info, CaseGoalPath, Coverage0, Coverage,
         Goal0, Goal),

-------------- 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/20080928/cbd0e3f0/attachment.sig>


More information about the reviews mailing list