[m-rev.] For review by Zoltan: Fix some auto-parallelism problems.

Paul Bone pbone at csse.unimelb.edu.au
Sun Jan 23 14:56:36 AEDT 2011


Zoltan, Could you please review the changes to mercury_compile_middle_passes.m

---

These problems wern't noticed until I tried to parallelise larger examples.

Fix an error in calculating the probability of recursion of ITE goals.

var_use_analysis.m:
    As above.

The wrong goal path step is used for disjunctions when labeling goals.  I think
Zoltan reported this earlier but I thought that he fixed it.

deep_profiler/program_represetnation_utils.m:
    As above.

In some cases the HLDS does not match the feedback data, from this example in
benchmarks/progs/pic:

    chargeDensity(particle_heap(Xypos,_)) =
        accum_mesh((+), 0.0, N, N, accumCharge(Xypos)) :-
            N = nCell - 1.

nCall and 1 are constants and are known at compile time (nCall via inter-module
analysis) In the feedback data this expression has been elimiated and replaced
with a constant however at this stage in the HLDS this hasn't happened.  The
change below inserts a simplification pass before the implicit parallelism
transformation.

compiler/options.m:
    Add a new option pre_implicit_parallelism_simplify

compiler/handle_options.m:
    implicit-parallelism implies pre_implicit_parallelism_simplify.

compiler/mercury_compile_front_end.m:
    Add the new constructor symbol for the new simplification pass.

    Perform a 'do once' simplification pass for the new simplification pass.

compiler/mercury_compile_middle_passes.m:
    Run the new simplfication pass immediatly before implicit parallelism.

    Re-order the middle-end passes so that implicit parallelism is applied
    after many optimisations such as inlining.

Index: compiler/handle_options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/handle_options.m,v
retrieving revision 1.358
diff -u -p -b -r1.358 handle_options.m
--- compiler/handle_options.m	3 Jan 2011 14:45:33 -0000	1.358
+++ compiler/handle_options.m	23 Jan 2011 01:32:14 -0000
@@ -625,6 +625,10 @@ convert_options_to_globals(OptionTable0,
     ;
         ImplicitParallelism = no
     ),
+    % Perform a simplification pass before the implicit parallelism pass to
+    % ensure that the HLDS more-closely matches the feedback data.
+    option_implies(implicit_parallelism, pre_implicit_parallelism_simplify,
+        bool(yes), !Globals),
 
     % Generating IL implies:
     %   - gc_method `automatic' and no heap reclamation on failure
Index: compiler/mercury_compile_front_end.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile_front_end.m,v
retrieving revision 1.8
diff -u -p -b -r1.8 mercury_compile_front_end.m
--- compiler/mercury_compile_front_end.m	20 Dec 2010 07:47:34 -0000	1.8
+++ compiler/mercury_compile_front_end.m	23 Jan 2011 01:32:14 -0000
@@ -50,6 +50,11 @@
             % before the source-to-source transformations that
             % implement them.
 
+    ;       simplify_pass_pre_implicit_parallelism
+            % If implicit parallelism is anbled then perform simplification
+            % before it is applied.  This helps ensure that the HLDS matches
+            % the feedback data.
+
     ;       simplify_pass_ml_backend
             % The first stage of MLDS code generation.
 
@@ -864,6 +869,21 @@ maybe_simplify(Warn, SimplifyPass, Verbo
                 !:SimpList = []
             )
         ;
+            SimplifyPass =simplify_pass_pre_implicit_parallelism,
+
+            % We run the simplify pass before the implicit parallelism pass if
+            % implicit parallelism is enabled.
+
+            globals.lookup_bool_option(Globals,
+                pre_implicit_parallelism_simplify, SimplifyPrePar),
+            (
+                SimplifyPrePar = yes,
+                list.cons(simp_do_once, !SimpList)
+            ;
+                SimplifyPrePar = no,
+                !:SimpList = []
+            )
+        ;
             SimplifyPass = simplify_pass_ml_backend,
             list.cons(simp_do_once, !SimpList)
         ;
@@ -914,6 +934,7 @@ maybe_simplify(Warn, SimplifyPass, Verbo
             ; SimplifyPass = simplify_pass_ml_backend
             ; SimplifyPass = simplify_pass_post_untuple
             ; SimplifyPass = simplify_pass_pre_prof_transforms
+            ; SimplifyPass = simplify_pass_pre_implicit_parallelism
             )
         ),
         maybe_write_string(Verbose, "% done.\n", !IO),
Index: compiler/mercury_compile_middle_passes.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile_middle_passes.m,v
retrieving revision 1.13
diff -u -p -b -r1.13 mercury_compile_middle_passes.m
--- compiler/mercury_compile_middle_passes.m	4 Jan 2011 05:01:33 -0000	1.13
+++ compiler/mercury_compile_middle_passes.m	23 Jan 2011 02:34:31 -0000
@@ -181,9 +181,6 @@ middle_pass(ModuleName, !HLDS, !DumpInfo
     maybe_ssdb(Verbose, Stats, !HLDS, !IO),
     maybe_dump_hlds(!.HLDS, 137, "ssdb", !DumpInfo, !IO),
 
-    maybe_implicit_parallelism(Verbose, Stats, !HLDS, !IO),
-    maybe_dump_hlds(!.HLDS, 139, "implicit_parallelism", !DumpInfo, !IO),
-
     maybe_introduce_accumulators(Verbose, Stats, !HLDS, !IO),
     maybe_dump_hlds(!.HLDS, 140, "accum", !DumpInfo, !IO),
 
@@ -216,6 +213,16 @@ middle_pass(ModuleName, !HLDS, !DumpInfo
     maybe_unneeded_code(Verbose, Stats, !HLDS, !IO),
     maybe_dump_hlds(!.HLDS, 170, "unneeded_code", !DumpInfo, !IO),
 
+    maybe_simplify(no, simplify_pass_pre_implicit_parallelism, Verbose, Stats,
+        !HLDS, [], SimplifySpecsPreImpPar, !IO),
+    expect(unify(contains_errors(Globals, SimplifySpecsPreImpPar), no),
+        this_file, "middle_pass: simplify has errors"),
+    maybe_dump_hlds(!.HLDS, 172, "pre_implicit_parallelism_simplify", !DumpInfo,
+        !IO),
+
+    maybe_implicit_parallelism(Verbose, Stats, !HLDS, !IO),
+    maybe_dump_hlds(!.HLDS, 173, "implicit_parallelism", !DumpInfo, !IO),
+
     maybe_lco(Verbose, Stats, !HLDS, !IO),
     maybe_dump_hlds(!.HLDS, 175, "lco", !DumpInfo, !IO),
 
@@ -237,8 +244,8 @@ middle_pass(ModuleName, !HLDS, !DumpInfo
     % propagation and we cannot do that once the term-size profiling or deep
     % profiling transformations have been applied.
     maybe_simplify(no, simplify_pass_pre_prof_transforms, Verbose, Stats,
-        !HLDS, [], SimplifySpecs, !IO),
-    expect(unify(contains_errors(Globals, SimplifySpecs), no), this_file,
+        !HLDS, [], SimplifySpecsPreProf, !IO),
+    expect(unify(contains_errors(Globals, SimplifySpecsPreProf), no), this_file,
         "middle_pass: simplify has errors"),
     maybe_dump_hlds(!.HLDS, 215, "pre_prof_transforms_simplify", !DumpInfo,
         !IO),
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.686
diff -u -p -b -r1.686 options.m
--- compiler/options.m	10 Jan 2011 06:40:24 -0000	1.686
+++ compiler/options.m	23 Jan 2011 03:04:33 -0000
@@ -331,6 +331,10 @@
             % option causes this simplification pass to run even when profiling
             % is not enabled.
 
+    ;       pre_implicit_parallelism_simplify
+            % Run the simplification pass before the implicit parallelism pass
+            % to ensure that the HLDS more closely matches the feedback data.
+
             % Perform coverage profiling, this affects only deep profiling
             % grades.
     ;       coverage_profiling
@@ -1242,6 +1246,7 @@ option_defaults_2(compilation_model_opti
     profile_deep                        -   bool(no),
     use_activation_counts               -   bool(no),
     pre_prof_transforms_simplify        -   bool(no),
+    pre_implicit_parallelism_simplify   -   bool(no),
     coverage_profiling                  -   bool(no),
     coverage_profiling_via_calls        -   bool(no),
     coverage_profiling_static           -   bool(no),
@@ -2111,6 +2116,8 @@ long_option("profile-memory",       prof
 long_option("profile-deep",         profile_deep).
 long_option("use-activation-counts",    use_activation_counts).
 long_option("pre-prof-transforms-simplify", pre_prof_transforms_simplify).
+long_option("pre-implicit-parallelism-simplify",
+    pre_implicit_parallelism_simplify).
 long_option("coverage-profiling", 
                     coverage_profiling).
 long_option("coverage-profiling-via-calls", 
Index: deep_profiler/program_representation_utils.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/program_representation_utils.m,v
retrieving revision 1.31
diff -u -p -b -r1.31 program_representation_utils.m
--- deep_profiler/program_representation_utils.m	17 Jan 2011 01:47:18 -0000	1.31
+++ deep_profiler/program_representation_utils.m	22 Jan 2011 13:35:24 -0000
@@ -738,7 +738,7 @@ label_goal(ContainingGoal, !Goal, !Count
         GoalExpr = conj_rep(Conjs)
     ;
         GoalExpr0 = disj_rep(Disjs0),
-        map_foldl3(label_goal_wrapper((func(N) = step_conj(N)), GoalId),
+        map_foldl3(label_goal_wrapper((func(N) = step_disj(N)), GoalId),
             Disjs0, Disjs, 1, _, !Counter, !Map),
         GoalExpr = disj_rep(Disjs)
     ;
Index: deep_profiler/var_use_analysis.m
===================================================================
RCS file: /home/mercury1/repository/mercury/deep_profiler/var_use_analysis.m,v
retrieving revision 1.13
diff -u -p -b -r1.13 var_use_analysis.m
--- deep_profiler/var_use_analysis.m	20 Jan 2011 13:44:10 -0000	1.13
+++ deep_profiler/var_use_analysis.m	22 Jan 2011 10:58:09 -0000
@@ -1725,7 +1725,7 @@ ite_rec_prob(Cond, Then, Else, RecCalls,
     goal_rec_prob(Cond, CondRecCalls, Info, CondProb, !ProbArray),
     goal_rec_prob(Then, ThenRecCalls, Info, ThenProb0, !ProbArray),
     goal_rec_prob(Else, ElseRecCalls, Info, ElseProb0, !ProbArray),
-    CondId = Then ^ goal_annotation,
+    CondId = Cond ^ goal_annotation,
     Coverage = get_goal_attribute_det(Info ^ fui_coverage_array, CondId),
     get_coverage_before_and_after_det(Coverage, Before, After),
     ThenCallProb = probable(float(After) / float(Before)),
-------------- 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/20110123/21974c7e/attachment.sig>


More information about the reviews mailing list