[m-rev.] diff: progress indicators for ctgc analyses

Peter Wang novalazy at gmail.com
Wed Feb 20 13:34:39 AEDT 2008


Estimated hours taken: 0.5
Branches: main

In very verbose mode, write "progress dots" during structure sharing and
structure reuse analyses.  Especially in debugging grades, these analyses can
take long enough on some procedures such that it looks that the compiler has
gone into an infinite loop.

compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.indirect.m:
compiler/structure_sharing.analysis.m:
	As above.

compiler/structure_reuse.versions.m:
	Fix a spelling mistake.

Index: compiler/structure_reuse.direct.detect_garbage.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/structure_reuse.direct.detect_garbage.m,v
retrieving revision 1.12
diff -u -r1.12 structure_reuse.direct.detect_garbage.m
--- compiler/structure_reuse.direct.detect_garbage.m	30 Jan 2008 00:46:31 -0000	1.12
+++ compiler/structure_reuse.direct.detect_garbage.m	20 Feb 2008 02:20:02 -0000
@@ -37,6 +37,8 @@
 :- import_module parse_tree.prog_data.
 :- import_module transform_hlds.ctgc.datastruct.
 
+:- import_module bool.
+:- import_module io.
 :- import_module pair. 
 :- import_module set.
 :- import_module string.
@@ -48,15 +50,18 @@
                 module_info     ::  module_info, 
                 pred_info       ::  pred_info, 
                 proc_info       ::  proc_info, 
-                sharing_table   ::  sharing_as_table
+                sharing_table   ::  sharing_as_table,
+                very_verbose    ::  bool
             ).
    
 :- func detect_bg_info_init(module_info, pred_info, proc_info, 
     sharing_as_table) = detect_bg_info.
 
-detect_bg_info_init(ModuleInfo, PredInfo, ProcInfo, SharingTable) =
-    detect_bg_info(ModuleInfo, PredInfo, ProcInfo, SharingTable). 
-
+detect_bg_info_init(ModuleInfo, PredInfo, ProcInfo, SharingTable) = BG :-
+    module_info_get_globals(ModuleInfo, Globals),
+    globals.lookup_bool_option(Globals, very_verbose, VeryVerbose),
+    BG = detect_bg_info(ModuleInfo, PredInfo, ProcInfo, SharingTable,
+        VeryVerbose).
 
 determine_dead_deconstructions(ModuleInfo, PredInfo, ProcInfo, SharingTable, 
         Goal, DeadCellTable) :- 
@@ -66,7 +71,18 @@
     % which boils down to reconstructing that sharing information based on the
     % sharing recorded in the sharing table. 
     determine_dead_deconstructions_2(Background, Goal, 
-        sharing_as_init, _, dead_cell_table_init, DeadCellTable).
+        sharing_as_init, _, dead_cell_table_init, DeadCellTable),
+
+    % Add a newline after the "progress dots".
+    VeryVerbose = Background ^ very_verbose,
+    (
+        VeryVerbose = yes,
+        trace [io(!IO)] (
+            io.nl(!IO)
+        )
+    ;
+        VeryVerbose = no
+    ).
 
     % Process a procedure goal, determining the sharing at each subgoal, as
     % well as constructing the table of dead cells. 
@@ -88,7 +104,7 @@
     SharingTable = Background ^ sharing_table, 
     (
         GoalExpr = conj(_, Goals),
-        list.foldl2(determine_dead_deconstructions_2(Background),
+        list.foldl2(determine_dead_deconstructions_2_with_progress(Background),
             Goals, !SharingAs, !DeadCellTable)
     ;
         GoalExpr = plain_call(PredId, ProcId, ActualVars, _, _, _),
@@ -145,6 +161,25 @@
         unexpected(detect_garbage.this_file, 
             "determine_dead_deconstructions_2: shorthand goal.")
     ).
+
+:- pred determine_dead_deconstructions_2_with_progress(detect_bg_info::in,
+    hlds_goal::in, sharing_as::in, sharing_as::out, dead_cell_table::in, 
+    dead_cell_table::out) is det.
+
+determine_dead_deconstructions_2_with_progress(Background, TopGoal,
+        !SharingAs, !DeadCellTable) :- 
+    VeryVerbose = Background ^ very_verbose,
+    (
+        VeryVerbose = yes,
+        trace [io(!IO)] (
+            io.write_char('.', !IO),
+            io.flush_output(!IO)
+        )
+    ;
+        VeryVerbose = no
+    ),
+    determine_dead_deconstructions_2(Background, TopGoal, !SharingAs,
+        !DeadCellTable).
        
 :- pred determine_dead_deconstructions_2_disj(detect_bg_info::in, 
     hlds_goals::in, sharing_as::in, sharing_as::out,
Index: compiler/structure_reuse.indirect.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/structure_reuse.indirect.m,v
retrieving revision 1.15
diff -u -r1.15 structure_reuse.indirect.m
--- compiler/structure_reuse.indirect.m	21 Jan 2008 05:23:32 -0000	1.15
+++ compiler/structure_reuse.indirect.m	20 Feb 2008 02:10:58 -0000
@@ -63,6 +63,7 @@
 :- import_module transform_hlds.ctgc.util.
 :- import_module transform_hlds.dependency_graph.
 
+:- import_module bool.
 :- import_module int.
 :- import_module list.
 :- import_module map.
@@ -152,7 +153,7 @@
     !:FixpointTable = AnalysisInfo ^ fptable,
 
     % Some feedback.
-    maybe_write_string(VeryVerbose, "% FPT: " ++
+    maybe_write_string(VeryVerbose, "\n% FPT: " ++
         sr_fixpoint_table_get_short_description(PPId, !.FixpointTable)
         ++ "\n", !IO),
 
@@ -178,7 +179,8 @@
                 proc_info       :: proc_info,
                 sharing_table   :: sharing_as_table,
                 reuse_table     :: reuse_as_table,
-                headvars        :: list(prog_var)
+                headvars        :: list(prog_var),
+                very_verbose    :: bool
             ).
 
     % The type analysis_info gathers the analysis information that may change
@@ -205,8 +207,11 @@
     HeadVarsOfInterest = 
         remove_typeinfo_vars(Vartypes, HeadVars), 
 
+    module_info_get_globals(ModuleInfo, Globals),
+    globals.lookup_bool_option(Globals, very_verbose, VeryVerbose),
+
     BG = ir_background_info(ModuleInfo, PredInfo, ProcInfo,
-        SharingTable, ReuseTable, HeadVarsOfInterest).
+        SharingTable, ReuseTable, HeadVarsOfInterest, VeryVerbose).
 
 :- func analysis_info_init(pred_proc_id, sr_fixpoint_table) = ir_analysis_info.
 
@@ -268,8 +273,8 @@
     !.Goal = hlds_goal(GoalExpr0, GoalInfo0),
     (
         GoalExpr0 = conj(ConjType, Goals0),
-        list.map_foldl2(indirect_reuse_analyse_goal(BaseInfo), Goals0,
-            Goals, !AnalysisInfo, !IO),
+        list.map_foldl2(indirect_reuse_analyse_goal_with_progress(BaseInfo),
+            Goals0, Goals, !AnalysisInfo, !IO),
         GoalExpr = conj(ConjType, Goals),
         !:Goal = hlds_goal(GoalExpr, GoalInfo0)
     ;
@@ -385,6 +390,22 @@
         unexpected(this_file, "indirect_reuse_analyse_goal: shorthand goal.")
     ).
 
+:- pred indirect_reuse_analyse_goal_with_progress(ir_background_info::in,
+    hlds_goal::in, hlds_goal::out, ir_analysis_info::in, ir_analysis_info::out,
+    io::di, io::uo) is det.
+
+indirect_reuse_analyse_goal_with_progress(BaseInfo, !Goal, !AnalysisInfo,
+        !IO) :-
+    VeryVerbose = BaseInfo ^ very_verbose,
+    (
+        VeryVerbose = yes,
+        io.write_char('.', !IO),
+        io.flush_output(!IO)
+    ;
+        VeryVerbose = no
+    ),
+    indirect_reuse_analyse_goal(BaseInfo, !Goal, !AnalysisInfo, !IO).
+
     % Analyse each branch of a disjunction with respect to an input
     % analysis_info, producing a resulting analysis_info, and possibly
     % updating the state of the sr_fixpoint_table.
Index: compiler/structure_reuse.versions.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/structure_reuse.versions.m,v
retrieving revision 1.10
diff -u -r1.10 structure_reuse.versions.m
--- compiler/structure_reuse.versions.m	15 Jan 2008 05:10:56 -0000	1.10
+++ compiler/structure_reuse.versions.m	19 Feb 2008 02:30:00 -0000
@@ -210,7 +210,7 @@
             CalleePredName),
         ReuseDescription0 = goal_info_get_reuse(GoalInfo0),
         (
-            % If the reuse description already sais "reuse", then this is
+            % If the reuse description already says "reuse", then this is
             % a call to a procedure which might have specified conditions, yet
             % whose conditions are always met, hence do not imply conditions on
             % the procedure in which this call appears. We must therefore
Index: compiler/structure_sharing.analysis.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/structure_sharing.analysis.m,v
retrieving revision 1.28
diff -u -r1.28 structure_sharing.analysis.m
--- compiler/structure_sharing.analysis.m	18 Feb 2008 23:57:45 -0000	1.28
+++ compiler/structure_sharing.analysis.m	20 Feb 2008 01:50:19 -0000
@@ -308,8 +308,8 @@
         ;
             % Start analysis.
             proc_info_get_goal(ProcInfo, Goal),
-            analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, Goal,
-                !FixpointTable, !Sharing, !IO),
+            analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable,
+                Verbose, Goal, !FixpointTable, !Sharing, !IO),
             FullAsDescr = sharing_as_short_description(!.Sharing),
 
             sharing_as_project(HeadVars, !Sharing),
@@ -325,7 +325,7 @@
                 WidenAsDescr = "-"
             ),
 
-            maybe_write_string(Verbose, "\t\t: " ++
+            maybe_write_string(Verbose, "\n\t\t: " ++
                 TabledAsDescr ++ "->" ++
                 FullAsDescr ++ "/" ++
                 ProjAsDescr ++ "/" ++
@@ -343,19 +343,20 @@
 %
 
 :- pred analyse_goal(module_info::in, pred_info::in, proc_info::in,
-    sharing_as_table::in, hlds_goal::in,
+    sharing_as_table::in, bool::in, hlds_goal::in,
     ss_fixpoint_table::in, ss_fixpoint_table::out,
     sharing_as::in, sharing_as::out, io::di, io::uo) is det.
 
-analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, Goal,
+analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, Verbose, Goal,
         !FixpointTable, !SharingAs, !IO) :-
     Goal = hlds_goal(GoalExpr, GoalInfo),
     (
         GoalExpr = conj(ConjType, Goals),
         (
             ConjType = plain_conj,
-            list.foldl3(analyse_goal(ModuleInfo, PredInfo, ProcInfo,
-                SharingTable), Goals, !FixpointTable, !SharingAs, !IO)
+            list.foldl3(analyse_goal_with_progress(ModuleInfo, PredInfo,
+                ProcInfo, SharingTable, Verbose), Goals,
+                !FixpointTable, !SharingAs, !IO)
         ;
             ConjType = parallel_conj,
             Context = goal_info_get_context(GoalInfo),
@@ -395,13 +396,13 @@
         GoalExpr = disj(Goals),
         list.foldl3(
             analyse_disj(ModuleInfo, PredInfo, ProcInfo,
-                SharingTable, !.SharingAs),
+                SharingTable, !.SharingAs, Verbose),
             Goals, !FixpointTable, sharing_as_init, !:SharingAs, !IO)
     ;
         GoalExpr = switch(_, _, Cases),
         list.foldl3(
             analyse_case(ModuleInfo, PredInfo, ProcInfo,
-                SharingTable, !.SharingAs),
+                SharingTable, !.SharingAs, Verbose),
             Cases, !FixpointTable, sharing_as_init, !:SharingAs, !IO)
     ;
         GoalExpr = negation(_Goal)
@@ -410,15 +411,15 @@
     ;
         GoalExpr = scope(_, SubGoal),
         % XXX Check theory.
-        analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, SubGoal,
-            !FixpointTable, !SharingAs, !IO)
+        analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, Verbose,
+            SubGoal, !FixpointTable, !SharingAs, !IO)
     ;
         GoalExpr = if_then_else(_, IfGoal, ThenGoal, ElseGoal),
-        analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable,
+        analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, Verbose,
             IfGoal, !FixpointTable, !.SharingAs, IfSharingAs, !IO),
-        analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable,
+        analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, Verbose,
             ThenGoal, !FixpointTable, IfSharingAs, ThenSharingAs, !IO),
-        analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable,
+        analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, Verbose,
             ElseGoal, !FixpointTable, !.SharingAs, ElseSharingAs, !IO),
         !:SharingAs = sharing_as_least_upper_bound(ModuleInfo, ProcInfo,
             ThenSharingAs, ElseSharingAs)
@@ -434,19 +435,36 @@
         unexpected(this_file, "analyse_goal: shorthand goal.")
     ).
 
+:- pred analyse_goal_with_progress(module_info::in, pred_info::in,
+    proc_info::in, sharing_as_table::in, bool::in, hlds_goal::in,
+    ss_fixpoint_table::in, ss_fixpoint_table::out,
+    sharing_as::in, sharing_as::out, io::di, io::uo) is det.
+
+analyse_goal_with_progress(ModuleInfo, PredInfo, ProcInfo, SharingTable,
+        Verbose, Goal, !FixpointTable, !SharingAs, !IO) :-
+    (
+        Verbose = yes,
+        io.write_char('.', !IO),
+        io.flush_output(!IO)
+    ;
+        Verbose = no
+    ),
+    analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, Verbose, Goal,
+        !FixpointTable, !SharingAs, !IO).
+
 %-----------------------------------------------------------------------------%
 %
 % Additional code for analysing disjuctions
 %
 
 :- pred analyse_disj(module_info::in, pred_info::in, proc_info::in,
-    sharing_as_table::in, sharing_as::in, hlds_goal::in,
+    sharing_as_table::in, sharing_as::in, bool::in, hlds_goal::in,
     ss_fixpoint_table::in, ss_fixpoint_table::out,
     sharing_as::in, sharing_as::out, io::di, io::uo) is det.
 
 analyse_disj(ModuleInfo, PredInfo, ProcInfo, SharingTable, SharingBeforeDisj,
-        Goal, !FixpointTable, !Sharing, !IO) :-
-    analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, Goal,
+        Verbose, Goal, !FixpointTable, !Sharing, !IO) :-
+    analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, Verbose, Goal,
         !FixpointTable, SharingBeforeDisj, GoalSharing, !IO),
     !:Sharing = sharing_as_least_upper_bound(ModuleInfo, ProcInfo, !.Sharing,
         GoalSharing).
@@ -457,14 +475,14 @@
 %
 
 :- pred analyse_case(module_info::in, pred_info::in, proc_info::in,
-    sharing_as_table::in, sharing_as::in, case::in,
+    sharing_as_table::in, sharing_as::in, bool::in, case::in,
     ss_fixpoint_table::in, ss_fixpoint_table::out,
     sharing_as::in, sharing_as::out, io::di, io::uo) is det.
 
 analyse_case(ModuleInfo, PredInfo, ProcInfo, SharingTable, Sharing0,
-        Case, !FixpointTable, !Sharing, !IO) :-
+        Verbose, Case, !FixpointTable, !Sharing, !IO) :-
     Case = case(_, _, Goal),
-    analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, Goal,
+    analyse_goal(ModuleInfo, PredInfo, ProcInfo, SharingTable, Verbose, Goal,
         !FixpointTable, Sharing0, CaseSharing, !IO),
     !:Sharing = sharing_as_least_upper_bound(ModuleInfo, ProcInfo, !.Sharing,
         CaseSharing).


--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list