[m-dev.] [reuse] diff: endless-loop-bugfix in inderect-pass
Nancy Mazur
Nancy.Mazur at cs.kuleuven.ac.be
Sun Oct 15 22:21:51 AEDT 2000
Hi,
===================================================================
Estimated hours taken: 4
Fix a endless-loop bug in the indirect-reuse pass and add
a couple of more explicit veryverbose messages to monitor what is
happening.
hlds_pred.m:
Make sure to put simplified conditions as reuse information
for each procedure.
sr_data.m:
Here is the core fix of the endless loop bug: when updating
conditions to the local environment, make sure to normalize
the aliases.
sr_indirect.m:
Give some process output when the very_verbose option is set.
First few (one step in fact) steps in making the code
more fergus-acceptable.
sr_direct.m:
sr_lbu.m:
sr_lfu.m:
Give some process output when the very_verbose option is set.
Index: hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.81.2.5
diff -u -r1.81.2.5 hlds_pred.m
--- hlds_pred.m 2000/10/12 15:03:32 1.81.2.5
+++ hlds_pred.m 2000/10/15 11:13:47
@@ -1809,8 +1809,9 @@
ProcInfo^maybe_alias_as := yes(Aliases)).
proc_info_set_global_use(ProcInfo, GLOBAL_USE,
ProcInfo^maybe_global_use := yes(GLOBAL_USE)).
-proc_info_set_reuse_information(ProcInfo, REUSE,
- ProcInfo^structure_reuse:= REUSE).
+proc_info_set_reuse_information(ProcInfo, Reuse0,
+ ProcInfo^structure_reuse:= Reuse):-
+ memo_reuse_simplify(Reuse0, Reuse).
proc_info_get_typeinfo_vars(Vars, VarTypes, TVarMap, TypeInfoVars) :-
set__to_sorted_list(Vars, VarList),
Index: sr_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_data.m,v
retrieving revision 1.1.2.7
diff -u -r1.1.2.7 sr_data.m
--- sr_data.m 2000/10/12 15:03:47 1.1.2.7
+++ sr_data.m 2000/10/15 11:13:48
@@ -101,6 +101,8 @@
reuse_condition, reuse_condition ).
:- mode reuse_condition_update( in, in, in, in, in, in, in, out) is det.
+:- pred reuse_conditions_simplify( list(reuse_condition)::in,
+ list(reuse_condition)::out) is det.
%-----------------------------------------------------------------------------%
% memo_reuse predicates
%-----------------------------------------------------------------------------%
@@ -276,6 +278,8 @@
NodesList,
[] ).
+:- import_module instmap.
+
reuse_condition_update( _ProcInfo, _HLDS,
_LFUi, _LBUi, _ALIASi, _HVs, always, always ).
reuse_condition_update( ProcInfo, HLDS, LFUi, LBUi, ALIASi, HVs,
@@ -312,7 +316,13 @@
% operation.
pa_alias_as__extend( ProcInfo, HLDS,
OLD_LAiH, ALIASi, NewALIASi),
- pa_alias_as__project( HVs, NewALIASi, NEW_LAiH),
+ pa_alias_as__project( HVs, NewALIASi, NEW_LAiH0),
+ % XXX instmap here simply initialized, as currently
+ % it's not used in the normalization anyway..
+ instmap__init_reachable(InstMap0),
+ pa_alias_as__normalize( ProcInfo, HLDS, InstMap0,
+ NEW_LAiH0, NEW_LAiH),
+
set__union(LFUi, LBUi, LUi),
set__union(LUi, OLD_LUiH, NEW_LUi),
set__list_to_set(HVs, HVsSet),
@@ -321,8 +331,6 @@
CONDITION = condition( NORM_NODES_set, NEW_LUiH, NEW_LAiH )
).
-:- pred reuse_conditions_simplify( list(reuse_condition)::in,
- list(reuse_condition)::out) is det.
reuse_conditions_simplify( OLD, NEW ):-
list__foldl(
Index: sr_direct.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_direct.m,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 sr_direct.m
--- sr_direct.m 2000/10/12 15:03:47 1.1.2.8
+++ sr_direct.m 2000/10/15 11:13:48
@@ -26,16 +26,18 @@
:- implementation.
-:- import_module map, list, set, std_util, int.
+:- import_module map, list, set, std_util, int, bool.
:- import_module assoc_list.
:- import_module require.
:- import_module sr_lfu, sr_lbu, sr_dead, sr_choice, sr_data, sr_live.
:- import_module hlds_goal, hlds_data, prog_data.
-:- import_module hlds_pred.
+:- import_module hlds_pred, passes_aux.
+:- import_module globals, options.
-process_proc(PredId, _ProcId, ProcInfo0, ProcInfo, ModuleInfo0, ModuleInfo) -->
+process_proc(PredId, ProcId, ProcInfo0, ProcInfo, ModuleInfo0, ModuleInfo) -->
% Determine the LFU (local forward use)
+ globals__io_lookup_bool_option(very_verbose, VeryVerbose),
{ sr_lfu__process_proc(ProcInfo0, ProcInfo1) },
% Determine the LBU (local backward use)
@@ -44,12 +46,26 @@
% Determine which cells die and can be reused and what
% the conditions on that reuse are
{ proc_info_goal(ProcInfo2, Goal0) },
+
+ (
+ { VeryVerbose = yes }
+ ->
+ passes_aux__write_proc_progress_message(
+ "% Analysing ", PredId, ProcId, ModuleInfo0),
+ io__write_string("%\tdeadness analysis...")
+ ;
+ []
+ ),
{ sr_dead__process_goal(PredId,ProcInfo0,ModuleInfo0,Goal0,Goal1) },
+ maybe_write_string(VeryVerbose, "done.\n"),
+
% Select which cells will be reused and which can be
% compile time garbage collected.
+ maybe_write_string(VeryVerbose, "%\tchoice analysis..."),
{ sr_choice__process_goal(strategy(same_cons_id, random),
Goal1, Goal, MaybeReuseConditions) },
+ maybe_write_string(VeryVerbose, "done.\n"),
{ proc_info_set_reuse_information( ProcInfo2, MaybeReuseConditions,
ProcInfo3 ) },
{ proc_info_set_goal( ProcInfo3, Goal, ProcInfo ) },
Index: sr_indirect.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_indirect.m,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 sr_indirect.m
--- sr_indirect.m 2000/10/12 15:03:47 1.1.2.2
+++ sr_indirect.m 2000/10/15 11:13:48
@@ -24,12 +24,13 @@
:- implementation.
-:- import_module map, list, std_util, require, set.
-:- import_module hlds_pred.
+:- import_module map, list, std_util, require, set, string, bool.
+:- import_module hlds_pred, passes_aux.
:- import_module dependency_graph, hlds_goal, prog_data, prog_util.
:- import_module pa_alias_as, pa_run.
:- import_module sr_data, sr_util, sr_live.
:- import_module sr_fixpoint_table.
+:- import_module globals, options.
compute_fixpoint(HLDS0, HLDSout) -->
% compute the strongly connected components
@@ -98,8 +99,8 @@
:- pred pred_id_in( list(pred_id), pred_proc_id ).
:- mode pred_id_in( in, in) is semidet.
-pred_id_in( IDS, PRED_PROC_ID):-
- PRED_PROC_ID = proc( PRED_ID, _),
+pred_id_in( IDS, PredProcId):-
+ PredProcId = proc( PRED_ID, _),
list__member( PRED_ID, IDS ).
:- pred not_defined_in_this_module(module_info, pred_proc_id).
@@ -108,7 +109,7 @@
not_defined_in_this_module( HLDS, proc(PREDID, _) ):-
hlds_module__pred_not_defined_in_this_module(HLDS,
PREDID).
- % module_info_pred_proc_info(HLDS, PRED_PROC_ID, PRED_INFO, _),
+ % module_info_pred_proc_info(HLDS, PredProcId, PRED_INFO, _),
% pred_info_import_status(PRED_INFO, STATUS),
% status_defined_in_this_module(STATUS, no).
@@ -155,10 +156,37 @@
io__state, io__state).
:- mode analyse_pred_proc( in, in, in, out, di, uo) is det.
-analyse_pred_proc( HLDS, PRED_PROC_ID, FPin, FPout) -->
- { module_info_pred_proc_info( HLDS, PRED_PROC_ID,_PredInfo,ProcInfo) },
- { PRED_PROC_ID = proc(PredId, _ProcId) },
+analyse_pred_proc( HLDS, PredProcId, FPin, FPout) -->
+ { module_info_pred_proc_info( HLDS, PredProcId,_PredInfo,ProcInfo) },
+ { PredProcId = proc(PredId, ProcId) },
+ globals__io_lookup_bool_option(very_verbose, VeryVerbose),
+ (
+ { VeryVerbose = no }
+ ->
+ []
+ ;
+ { sr_fixpoint_table_which_run(FPin, Run) },
+ { string__int_to_string( Run, SRun ) },
+ { string__append_list([
+ "% Indirect reuse analysing (run ", SRun, ") "],
+ Msg) },
+ passes_aux__write_proc_progress_message( Msg,
+ PredId, ProcId, HLDS),
+ { sr_fixpoint_table_get_final_reuse( PredProcId, M, _, FPin) },
+
+ (
+ { M = yes( Conditions ) }
+ ->
+ { list__length(Conditions, Length) },
+ { string__int_to_string(Length, LengthS ) },
+ { string__append_list(["%\tNumber of conditions:\t",
+ LengthS, "\n"], Msg2) } ,
+ maybe_write_string(VeryVerbose, Msg2)
+ ;
+ maybe_write_string(VeryVerbose, "%\t No reuse.\n")
+ )
+ ),
{
% initialize all the necessary information to get the
% analysis started.
@@ -175,7 +203,7 @@
compute_real_headvars( HLDS, PredId, ProcInfo, HVs),
% do not change the state of the fixpoint table by
% simply consulting it now for initialization.
- sr_fixpoint_table_get_final_reuse( PRED_PROC_ID,
+ sr_fixpoint_table_get_final_reuse( PredProcId,
MemoStarting, _, FPin ),
indirect_reuse_pool_init( HVs, MemoStarting, Pool0 ),
% 5. analyse_goal
@@ -187,7 +215,7 @@
% OK
% 6. update all kind of information
indirect_reuse_pool_get_memo_reuse( Pool, Memo ),
- sr_fixpoint_table_new_reuse( PRED_PROC_ID,
+ sr_fixpoint_table_new_reuse( PredProcId,
Memo, Goal, FP1, FPout )
}.
@@ -470,10 +498,10 @@
% no special treatment necessary for primitive predicates and
% alike, as the default of predicates is no reuse anyway.
lookup_memo_reuse( PredId, ProcId, HLDS, FP0, FP, Memo ):-
- PRED_PROC_ID = proc(PredId, ProcId),
+ PredProcId = proc(PredId, ProcId),
(
% 1 - check in table
- sr_fixpoint_table_get_reuse( PRED_PROC_ID,
+ sr_fixpoint_table_get_reuse( PredProcId,
Memo1, FP0, FP1 )
->
Memo = Memo1,
@@ -481,7 +509,7 @@
;
FP = FP0,
% 2 - lookup in module_info
- module_info_pred_proc_info( HLDS, PRED_PROC_ID, _PredInfo,
+ module_info_pred_proc_info( HLDS, PredProcId, _PredInfo,
ProcInfo ),
proc_info_reuse_information( ProcInfo, Memo)
).
@@ -546,7 +574,8 @@
reuse_condition_update(ProcInfo, HLDS,
LFUi, LBUi, Alias, HVS ),
OldConditions,
- NewConditions),
+ NewConditions0),
+ reuse_conditions_simplify(NewConditions0, NewConditions),
memo_reuse_merge(ExistingMemo, yes(NewConditions),
NewMemo),
Pool = pool( HVS, NewMemo )
Index: sr_lbu.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_lbu.m,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 sr_lbu.m
--- sr_lbu.m 2000/10/04 13:34:23 1.1.2.2
+++ sr_lbu.m 2000/10/15 11:13:48
@@ -62,9 +62,6 @@
:- import_module sr_live.
-% temporary inclusion
-:- import_module sr_reuse.
-
sr_lbu__lbu_pass( HLDSin , HLDSout) -->
% get all the predicate id's
{ hlds_module__module_info_predids( HLDSin, ALL_PRED_IDS ) },
@@ -93,10 +90,17 @@
annotate_lbu_in_pred( PRED_ID, HLDSin, HLDSout ) -->
{ hlds_module__module_info_pred_info( HLDSin, PRED_ID, PredInfo) },
- passes_aux__write_pred_progress_message(
+ globals__io_lookup_bool_option(very_verbose, VeryVerbose),
+ (
+ { VeryVerbose = yes }
+ ->
+ passes_aux__write_pred_progress_message(
"% LBU-annotating ",
PRED_ID,
- HLDSin),
+ HLDSin)
+ ;
+ []
+ ),
% fetching the procids
{ pred_info_procids(PredInfo, PROC_IDS) },
Index: sr_lfu.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_lfu.m,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 sr_lfu.m
--- sr_lfu.m 2000/10/04 13:34:24 1.1.2.2
+++ sr_lfu.m 2000/10/15 11:13:48
@@ -68,10 +68,17 @@
annotate_lfu_in_pred( PRED_ID, HLDSin, HLDSout ) -->
{ hlds_module__module_info_pred_info( HLDSin, PRED_ID, PredInfo) },
- passes_aux__write_pred_progress_message(
+ globals__io_lookup_bool_option(very_verbose, VeryVerbose),
+ (
+ { VeryVerbose = yes }
+ ->
+ passes_aux__write_pred_progress_message(
"% LFU-annotating ",
PRED_ID,
- HLDSin),
+ HLDSin)
+ ;
+ []
+ ),
% fetching the procids
{ pred_info_procids(PredInfo, PROC_IDS) },
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list