[m-rev.] diff: Fix a regression that affected coverage profiling at automatic parallelisation.

Paul Bone pbone at csse.unimelb.edu.au
Thu Jan 6 22:26:32 AEDT 2011


Fix a regression that affected coverage profiling and automatic parallelism
analysis.

When instrumenting a program for deep and coverage profiling the compiler adds
goal path information to the program.  The compiler also writes out a bytecode
representation of the program.  The step_switch goal path step includes a field
for the number of functors of the type of the variable that is being switched
upon.  When this is included in the deep profiling data (as it is now) and
these goals paths are used as the indexes in tables the deep profiler cannot
reconstruct matching goal paths from the program representation bytecode,
causing many important map lookups to fail or throw an exception.

We fix this not by preventing the compiler from writing out this information,
but by stripping it out of goal paths before the analysis tool uses those goal
paths.

mdbcomp/program_representation.m:
    Add a new predicate rev_goal_path_remove_type_info/2 that removes
    type-dependant information from goals.

deep_profiler/profile.m:
    Change the goal_path string in the call_site_static type to contain a
    reverse_goal_path rather than a string.  This hides the abstraction of the
    stripping of type dependant information within read_profile.m

deep_profiler/read_profile.m:
    Strip type dependant information from goal path strings as they are read in.

    Conform to changes in profile.m

deep_profiler/report.m:
    In the call site static dump information use a goal_path field rather than
    a string.

deep_profiler/analysis_utils.m:
deep_profiler/create_report.m:
deep_profiler/dump.m:
deep_profiler/mdprof_fb.automatic_parallelism.m:
deep_profiler/old_query.m:
    Conform to changes in profile.m.

deep_profiler/display_report.m:
    Conform to changes in report.m.

Index: deep_profiler/analysis_utils.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/analysis_utils.m,v
retrieving revision 1.4
diff -u -p -b -r1.4 analysis_utils.m
--- deep_profiler/analysis_utils.m	20 Dec 2010 07:47:45 -0000	1.4
+++ deep_profiler/analysis_utils.m	6 Jan 2011 11:06:33 -0000
@@ -176,7 +176,7 @@ build_call_site_cost_and_callee_map(Deep
     CostAndCallees = cost_and_callees(CostCsq, set(Callees), HigherOrder),
     lookup_call_site_statics(Deep ^ call_site_statics, CSSPtr, CSS),
     call_site_kind_to_higher_order(CSS ^ css_kind, HigherOrder),
-    rev_goal_path_from_string_det(CSS ^ css_goal_path, RevGoalPath),
+    RevGoalPath = CSS ^ css_goal_path,
     svmap.det_insert(RevGoalPath, CostAndCallees, !CallSitesMap).
 
 :- pred call_site_dynamic_get_callee_and_costs(deep::in,
@@ -309,7 +309,7 @@ build_recursive_call_site_counts_map(Dee
     (
         Recursive = yes,
         deep_lookup_call_site_statics(Deep, CSSPtr, CSS),
-        rev_goal_path_from_string_det(CSS ^ css_goal_path, RevGoalPath),
+        RevGoalPath = CSS ^ css_goal_path,
         svmap.det_insert(RevGoalPath, Count, !Map)
     ;
         Recursive = no
Index: deep_profiler/create_report.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/create_report.m,v
retrieving revision 1.30
diff -u -p -b -r1.30 create_report.m
--- deep_profiler/create_report.m	20 Dec 2010 07:47:45 -0000	1.30
+++ deep_profiler/create_report.m	6 Jan 2011 11:06:33 -0000
@@ -1191,7 +1191,7 @@ maybe_create_procrep_coverage_report(Dee
 
 add_ps_calls_and_exits_to_map(Deep, CSSPtr, !.Map) = !:Map :-
     lookup_call_site_statics(Deep ^ call_site_statics, CSSPtr, CSS),
-    rev_goal_path_from_string_det(CSS ^ css_goal_path, RevGoalPath),
+    RevGoalPath = CSS ^ css_goal_path,
     lookup_css_own(Deep ^ css_own, CSSPtr, Own),
     svmap.det_insert(RevGoalPath, calls_and_exits(calls(Own), exits(Own)),
         !Map).
@@ -1211,7 +1211,7 @@ add_pd_calls_and_exits_to_map(Deep, CSSP
             0, Calls, 0, Exits)
     ),
     deep_lookup_call_site_statics(Deep, CSSPtr, CSS),
-    rev_goal_path_from_string_det(CSS ^ css_goal_path, RevGoalPath),
+    RevGoalPath = CSS ^ css_goal_path,
     svmap.det_insert(RevGoalPath, calls_and_exits(Calls, Exits), !Map).
 
 :- pred csd_get_calls_and_exits(deep::in, call_site_dynamic_ptr::in,
@@ -1647,13 +1647,12 @@ describe_call_site(Deep, CSSPtr) = CallS
     ( valid_call_site_static_ptr(Deep, CSSPtr) ->
         deep_lookup_call_site_statics(Deep, CSSPtr, CSS),
         CSS = call_site_static(ContainingPSPtr, SlotNumber, Kind, LineNumber,
-            GoalPathString),
+            RevGoalPath),
         deep_lookup_proc_statics(Deep, ContainingPSPtr, ContainingPS),
         FileName = ContainingPS ^ ps_file_name,
         ModuleName = ContainingPS ^ ps_decl_module,
         UnQualRefinedName = ContainingPS ^ ps_uq_refined_id,
         QualRefinedName = ContainingPS ^ ps_q_refined_id,
-        rev_goal_path_from_string_det(GoalPathString, RevGoalPath),
         (
             Kind = normal_call_and_callee(CalleePSPtr, _TypeSubst),
             CalleeDesc = describe_proc(Deep, CalleePSPtr),
Index: deep_profiler/display_report.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/display_report.m,v
retrieving revision 1.33
diff -u -p -b -r1.33 display_report.m
--- deep_profiler/display_report.m	20 Dec 2010 07:47:45 -0000	1.33
+++ deep_profiler/display_report.m	6 Jan 2011 11:06:33 -0000
@@ -2266,7 +2266,7 @@ display_report_call_site_static_dump(Pre
         [("Containing proc_static:" - td_l(ContainingProcStaticLink)),
         ("Slot number:"             - td_i(SlotNumber)),
         ("Line number:"             - td_i(LineNumber)),
-        ("Goal path:"               - td_s(GoalPath)),
+        ("Goal path:"               - td_s(rev_goal_path_to_string(GoalPath))),
         ("Call site kind:"          - CallSiteKindData)],
 
     Rows = list.map(make_labelled_table_row, Values),
Index: deep_profiler/dump.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/dump.m,v
retrieving revision 1.21
diff -u -p -b -r1.21 dump.m
--- deep_profiler/dump.m	20 Dec 2010 07:47:46 -0000	1.21
+++ deep_profiler/dump.m	6 Jan 2011 11:06:33 -0000
@@ -503,11 +503,12 @@ dump_call_site_static(Restriction, Index
         CallSiteStatic = call_site_static(ContainerPSPtr, SlotNum,
             Kind, LineNum, GoalPath),
         ContainerPSPtr = proc_static_ptr(ContainerPSI),
+        GoalPathString = rev_goal_path_to_string(GoalPath),
         io.format("css%d:\n", [i(Index)], !IO),
         io.format("\tcss_container\t= ps%d\n", [i(ContainerPSI)], !IO),
         io.format("\tcss_slot_num\t= <%d>\n", [i(SlotNum)], !IO),
         io.format("\tcss_line_num\t= <%d>\n", [i(LineNum)], !IO),
-        io.format("\tcss_goal_path\t= <%s>\n", [s(GoalPath)], !IO),
+        io.format("\tcss_goal_path\t= <%s>\n", [s(GoalPathString)], !IO),
         io.write_string("\tcss_kind\t= ", !IO),
         dump_call_site_kind_and_callee(Kind, !IO),
         io.nl(!IO),
Index: deep_profiler/mdprof_fb.automatic_parallelism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/mdprof_fb.automatic_parallelism.m,v
retrieving revision 1.25
diff -u -p -b -r1.25 mdprof_fb.automatic_parallelism.m
--- deep_profiler/mdprof_fb.automatic_parallelism.m	3 Jan 2011 12:39:19 -0000	1.25
+++ deep_profiler/mdprof_fb.automatic_parallelism.m	6 Jan 2011 11:06:33 -0000
@@ -355,7 +355,7 @@ proc_dynamic_callees(Deep, Parallelism, 
 
 pd_slot_callees(Deep, Parallelism, ProcLabel, CSSPtr - Slot, ChildCliques) :-
     deep_lookup_call_site_statics(Deep, CSSPtr, CSS),
-    rev_goal_path_from_string_det(CSS ^ css_goal_path, RevGoalPath),
+    RevGoalPath = CSS ^ css_goal_path,
     (
         Slot = slot_normal(CSDPtr),
         call_site_dynamic_callees(Deep, Parallelism, ProcLabel, RevGoalPath,
Index: deep_profiler/old_query.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/old_query.m,v
retrieving revision 1.10
diff -u -p -b -r1.10 old_query.m
--- deep_profiler/old_query.m	15 Dec 2010 06:30:34 -0000	1.10
+++ deep_profiler/old_query.m	6 Jan 2011 11:06:33 -0000
@@ -40,6 +40,8 @@
 :- import_module apply_exclusion.
 :- import_module exclude.
 :- import_module html_format.       % for escape_break_html_string
+:- import_module mdbcomp.
+:- import_module mdbcomp.program_representation.
 :- import_module measurements.
 :- import_module old_html_format.
 :- import_module top_procs.
@@ -205,7 +207,7 @@ generate_call_site_static_debug_page(CSS
             string.int_to_string(CSS ^ css_slot_num) ++ " " ++
             string.int_to_string(CSS ^ css_line_num) ++ " " ++
             kind_and_callee_to_string(CSS ^ css_kind) ++ " " ++
-            CSS ^ css_goal_path ++
+            rev_goal_path_to_string(CSS ^ css_goal_path) ++
             "</HTML>\n"
     ;
         HTML =
Index: deep_profiler/profile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/profile.m,v
retrieving revision 1.33
diff -u -p -b -r1.33 profile.m
--- deep_profiler/profile.m	15 Dec 2010 06:30:34 -0000	1.33
+++ deep_profiler/profile.m	6 Jan 2011 11:06:33 -0000
@@ -248,7 +248,7 @@
                                % Slot number in the containing procedure.
                 css_kind      :: call_site_kind_and_callee,
                 css_line_num  :: int,
-                css_goal_path :: string
+                css_goal_path :: reverse_goal_path
             ).
 
 %-----------------------------------------------------------------------------%
Index: deep_profiler/read_profile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/read_profile.m,v
retrieving revision 1.32
diff -u -p -b -r1.32 read_profile.m
--- deep_profiler/read_profile.m	20 Dec 2010 07:47:46 -0000	1.32
+++ deep_profiler/read_profile.m	6 Jan 2011 11:06:33 -0000
@@ -210,7 +210,7 @@ maybe_init_deep(ProgName, FlagsInt, MaxC
             array.init(MaxCSS + 1,
                 call_site_static(
                     make_dummy_psptr, -1,
-                    normal_call_and_callee(make_dummy_psptr, ""), -1, ""
+                    normal_call_and_callee(make_dummy_psptr, ""), -1, rgp([])
                 )),
             array.init(MaxPS + 1,
                 proc_static(dummy_proc_id, "", "", "", "", "", -1, no,
@@ -437,12 +437,14 @@ read_call_site_static(MaybeCSS, !IO) :-
         read_call_site_kind_and_callee,
         read_num,
         read_string,
-        (pred(CSSI0::in, Kind::in, LineNumber::in, Str::in, CSS::out)
+        (pred(CSSI0::in, Kind::in, LineNumber::in, GoalPathStr::in, CSS::out)
                 is det :-
             DummyPSPtr = make_dummy_psptr,
             DummySlotNum = -1,
+            rev_goal_path_from_string_det(GoalPathStr, RevGoalPath0),
+            rev_goal_path_remove_type_info(RevGoalPath0, RevGoalPath),
             CallSiteStatic0 = call_site_static(DummyPSPtr,
-                DummySlotNum, Kind, LineNumber, Str),
+                DummySlotNum, Kind, LineNumber, RevGoalPath),
             CSS = ok({CallSiteStatic0, CSSI0})
         ),
         MaybeCSS, !IO),
@@ -703,7 +705,8 @@ read_coverage_point_static(MaybeCP, !IO)
         read_string,
         read_cp_type,
         (pred(GoalPathString::in, CPType::in, MaybeCPI::out) is det :-
-            rev_goal_path_from_string_det(GoalPathString, RevGoalPath),
+            rev_goal_path_from_string_det(GoalPathString, RevGoalPath0),
+            rev_goal_path_remove_type_info(RevGoalPath0, RevGoalPath),
             MaybeCPI = ok(coverage_point_info(RevGoalPath, CPType))
         ), MaybeCP, !IO).
 
Index: deep_profiler/report.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/report.m,v
retrieving revision 1.28
diff -u -p -b -r1.28 report.m
--- deep_profiler/report.m	20 Dec 2010 07:47:46 -0000	1.28
+++ deep_profiler/report.m	6 Jan 2011 11:06:33 -0000
@@ -493,7 +493,7 @@
                 cssdi_containing_psptr      :: proc_static_ptr,
                 cssdi_slot_number           :: int,
                 cssdi_line_number           :: int,
-                cssdi_goal_path             :: string,
+                cssdi_goal_path             :: reverse_goal_path,
                 cssdi_callee                :: call_site_kind_and_callee
             ).
 
Index: mdbcomp/program_representation.m
===================================================================
RCS file: /home/mercury1/repository/mercury/mdbcomp/program_representation.m,v
retrieving revision 1.56
diff -u -p -b -r1.56 program_representation.m
--- mdbcomp/program_representation.m	3 Jan 2011 01:55:31 -0000	1.56
+++ mdbcomp/program_representation.m	6 Jan 2011 11:06:33 -0000
@@ -618,6 +618,15 @@
 :- pred rev_goal_path_inside(reverse_goal_path::in, reverse_goal_path::in,
     reverse_goal_path::out) is semidet.
 
+    % Remove information from the goal path that depends on type information.
+    %
+    % This is necessary when using goal paths to lookup a map within the deep
+    % profiler.  The goal paths used to perform the query cannot construct the
+    % parts of the goal paths that depend on type information.
+    %
+:- pred rev_goal_path_remove_type_info(reverse_goal_path::in,
+    reverse_goal_path::out) is det.
+
 %----------------------------------------------------------------------------%
 
     % User-visible head variables are represented by a number from 1..N,
@@ -1077,6 +1086,31 @@ goal_path_step_to_string(step_atomic_mai
 goal_path_step_to_string(step_atomic_orelse(N)) =
     "o" ++ int_to_string(N) ++ ";".
 
+rev_goal_path_remove_type_info(rgp(Steps0), rgp(Steps)) :-
+    map(goal_path_step_remove_type_info, Steps0, Steps).
+
+:- pred goal_path_step_remove_type_info(goal_path_step::in,
+    goal_path_step::out) is det.
+
+goal_path_step_remove_type_info(!Step) :-
+    (
+        ( !.Step = step_conj(_)
+        ; !.Step = step_disj(_)
+        ; !.Step = step_ite_cond
+        ; !.Step = step_ite_then
+        ; !.Step = step_ite_else
+        ; !.Step = step_neg
+        ; !.Step = step_scope(_)
+        ; !.Step = step_lambda
+        ; !.Step = step_try
+        ; !.Step = step_atomic_main
+        ; !.Step = step_atomic_orelse(_)
+        )
+    ;
+        !.Step = step_switch(N, _),
+        !:Step = step_switch(N, no)
+    ).
+
 %-----------------------------------------------------------------------------%
 
 detism_rep(Detism) = Rep :-
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: Digital signature
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20110106/8d9fd7fc/attachment.sig>


More information about the reviews mailing list