[m-rev.] [reuse] reorganize code
Nancy Mazur
Nancy.Mazur at cs.kuleuven.ac.be
Sat Mar 17 04:16:55 AEDT 2001
Hi,
===================================================================
Estimated hours taken: 1
Branches: reuse
Reorganize code.
hlds_pred.m:
Gather all the alias and reuse fields (alias, global use and reuse)
of the proc_info into one single field alias_reuse_info.
Add a fourth field to this which will collect the static terms
that the procedure might produce.
pa_run.m:
sr_indirect.m:
pa_sr_util.m:
Move `some_are_special_preds' into pa_sr_util, a module
common to the alias and reuse analysis.
(+ cleaning up here and there).
Index: hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.81.2.14
diff -u -r1.81.2.14 hlds_pred.m
--- hlds_pred.m 2001/02/28 13:34:16 1.81.2.14
+++ hlds_pred.m 2001/03/16 17:02:10
@@ -19,7 +19,7 @@
:- import_module globals.
:- import_module bool, list, set, map, std_util, term, varset.
-:- import_module pa_alias_as.
+:- import_module pa_alias_as, pa_datastruct.
:- import_module sr_data.
:- implementation.
@@ -1579,6 +1579,14 @@
maybe(list(sr_data__reuse_condition)), proc_info).
:- mode proc_info_set_reuse_information(in, in, out) is det.
+:- pred proc_info_static_terms(proc_info,
+ maybe(set(pa_datastruct__datastruct))).
+:- mode proc_info_static_terms(in, out) is det.
+
+:- pred proc_info_set_static_terms(proc_info,
+ maybe(set(pa_datastruct__datastruct)), proc_info).
+:- mode proc_info_set_static_terms(in, in, out) is det.
+
:- pred proc_info_get_need_maxfr_slot(proc_info, bool).
:- mode proc_info_get_need_maxfr_slot(in, out) is det.
@@ -1775,24 +1783,11 @@
% of the connection, we generate an RL
% expression, for which this is an
% identifier. See rl_update.m.
- maybe_alias_as :: maybe(alias_as),
- % `Possible' aliases annotations per
- % procedure. This field is set by the
- % possible alias analysis.
- maybe_global_use :: maybe(set(prog_var)),
- % Set of headvars which are not
- % fully consumed (in the sense of
- % deathness as in liveness.m) in
- % the procedure. This corresponds
- % to the vars which are output
- % w.r.t. the modes of the procedure.
- % (corresponds to the final set
- % of Local Forward Use in the goal)
- % (set during structure_reuse phase)
-
- % Possible set of reuse conditions.
- structure_reuse:: maybe(list(sr_data__reuse_condition)),
-
+ alias_reuse_info :: pa_sr_info,
+ % All information gathered during
+ % passes that are related to either
+ % the possible-alias analysis or
+ % structure reuse pass.
need_maxfr_slot :: bool,
% True iff tracing is enabled, this
% is a procedure that lives on the det
@@ -1836,6 +1831,36 @@
% debugger.
).
+:- type pa_sr_info
+ ---> pa_sr_information(
+ maybe_alias_as :: maybe(alias_as),
+ % `Possible' aliases annotations per
+ % procedure. This field is set by the
+ % possible alias analysis.
+ maybe_global_use :: maybe(set(prog_var)),
+ % Set of headvars which are not
+ % fully consumed (in the sense of
+ % deathness as in liveness.m) in
+ % the procedure. This corresponds
+ % to the vars which are output
+ % w.r.t. the modes of the procedure.
+ % (corresponds to the final set
+ % of Local Forward Use in the goal)
+ % (set during structure_reuse phase)
+
+ % Possible set of reuse conditions.
+ structure_reuse:: maybe(list(sr_data__reuse_condition)),
+
+ % Possible set of datastructures that
+ % might be static after calling
+ % the procedure.
+ static_terms:: maybe(set(pa_datastruct__datastruct))
+ ).
+
+:- func pa_sr_info_init = pa_sr_info.
+pa_sr_info_init = pa_sr_information(no, no, no, no).
+
+
% Some parts of the procedure aren't known yet. We initialize
% them to any old garbage which we will later throw away.
@@ -1861,17 +1886,13 @@
map__init(TVarsMap),
map__init(TCVarsMap),
RLExprn = no,
- Alias = no,
- GlobalUse = no,
- Reuse = no,
NewProc = procedure(
BodyVarSet, BodyTypes, HeadVars, HeadVars,
Modes, ModeErrors, InstVarSet,
MaybeArgLives, ClauseBody, MContext, StackSlots, MaybeDet,
InferredDet, CanProcess, ArgInfo, InitialLiveness, TVarsMap,
TCVarsMap, eval_normal, no, no, DeclaredModes, IsAddressTaken,
- RLExprn, Alias, GlobalUse, Reuse, no, no
- ).
+ RLExprn, pa_sr_info_init, no, no).
proc_info_set(DeclaredDetism, BodyVarSet, BodyTypes, HeadVars, HeadModes,
InstVarSet, HeadLives, Goal, Context, StackSlots,
@@ -1879,9 +1900,6 @@
TCVarsMap, ArgSizes, Termination, IsAddressTaken,
ProcInfo) :-
RLExprn = no,
- Alias = no,
- GlobalUse = no,
- Reuse = no,
ModeErrors = [],
ProcInfo = procedure(
BodyVarSet, BodyTypes, HeadVars, HeadVars, HeadModes,
@@ -1889,7 +1907,7 @@
StackSlots, DeclaredDetism, InferredDetism, CanProcess, ArgInfo,
Liveness, TVarMap, TCVarsMap, eval_normal, ArgSizes,
Termination, no, IsAddressTaken, RLExprn,
- Alias, GlobalUse, Reuse, no, no).
+ pa_sr_info_init, no, no).
proc_info_create(VarSet, VarTypes, HeadVars, HeadModes, InstVarSet, Detism,
Goal, Context, TVarMap, TCVarsMap, IsAddressTaken, ProcInfo) :-
@@ -1897,16 +1915,13 @@
set__init(Liveness),
MaybeHeadLives = no,
RLExprn = no,
- Alias = no,
- GlobalUse = no,
- Reuse = no,
ModeErrors = [],
ProcInfo = procedure(VarSet, VarTypes, HeadVars, HeadVars, HeadModes,
ModeErrors, InstVarSet,
MaybeHeadLives, Goal, Context, StackSlots,
yes(Detism), Detism, yes, [], Liveness, TVarMap, TCVarsMap,
eval_normal, no, no, no, IsAddressTaken, RLExprn,
- Alias, GlobalUse, Reuse, no, no).
+ pa_sr_info_init, no, no).
proc_info_set_body(ProcInfo0, VarSet, VarTypes, HeadVars, Goal,
TI_VarMap, TCI_VarMap, ProcInfo) :-
@@ -1993,9 +2008,16 @@
proc_info_maybe_declared_argmodes(ProcInfo, ProcInfo^maybe_declared_head_modes).
proc_info_is_address_taken(ProcInfo, ProcInfo^is_address_taken).
proc_info_get_rl_exprn_id(ProcInfo, ProcInfo^maybe_aditi_rl_id).
-proc_info_possible_aliases(ProcInfo, ProcInfo^maybe_alias_as).
-proc_info_global_use(ProcInfo, ProcInfo^maybe_global_use).
-proc_info_reuse_information(ProcInfo, ProcInfo^structure_reuse).
+:- pred proc_info_alias_reuse_info(proc_info::in, pa_sr_info::out) is det.
+proc_info_alias_reuse_info(ProcInfo, ProcInfo^alias_reuse_info).
+proc_info_possible_aliases(ProcInfo, AliasReuseInfo^maybe_alias_as):-
+ proc_info_alias_reuse_info(ProcInfo, AliasReuseInfo).
+proc_info_global_use(ProcInfo, AliasReuseInfo^maybe_global_use):-
+ proc_info_alias_reuse_info(ProcInfo, AliasReuseInfo).
+proc_info_reuse_information(ProcInfo, AliasReuseInfo^structure_reuse):-
+ proc_info_alias_reuse_info(ProcInfo, AliasReuseInfo).
+proc_info_static_terms(ProcInfo, AliasReuseInfo^static_terms):-
+ proc_info_alias_reuse_info(ProcInfo, AliasReuseInfo).
proc_info_get_need_maxfr_slot(ProcInfo, ProcInfo^need_maxfr_slot).
proc_info_get_call_table_tip(ProcInfo, ProcInfo^call_table_tip).
@@ -2024,13 +2046,32 @@
ProcInfo^maybe_termination := MT).
proc_info_set_address_taken(ProcInfo, AT, ProcInfo^is_address_taken := AT).
proc_info_set_rl_exprn_id(ProcInfo, ID, ProcInfo^maybe_aditi_rl_id := yes(ID)).
-proc_info_set_possible_aliases(ProcInfo, Aliases,
- ProcInfo^maybe_alias_as := yes(Aliases)).
-proc_info_set_global_use(ProcInfo, GlobalUse,
- ProcInfo^maybe_global_use := yes(GlobalUse)).
-proc_info_set_reuse_information(ProcInfo, Reuse0,
- ProcInfo^structure_reuse:= Reuse):-
- memo_reuse_simplify(Reuse0, Reuse).
+
+:- pred proc_info_set_alias_reuse_info(proc_info::in, pa_sr_info::in,
+ proc_info::out) is det.
+proc_info_set_alias_reuse_info(ProcInfo, AliasReuseInfo,
+ ProcInfo^alias_reuse_info := AliasReuseInfo).
+proc_info_set_possible_aliases(ProcInfo0, Aliases, ProcInfo):-
+ proc_info_alias_reuse_info(ProcInfo0, AliasReuseInfo),
+ proc_info_set_alias_reuse_info(ProcInfo0,
+ AliasReuseInfo^maybe_alias_as := yes(Aliases),
+ ProcInfo).
+proc_info_set_global_use(ProcInfo0, GlobalUse, ProcInfo):-
+ proc_info_alias_reuse_info(ProcInfo0, AliasReuseInfo),
+ proc_info_set_alias_reuse_info(ProcInfo0,
+ AliasReuseInfo^maybe_global_use := yes(GlobalUse),
+ ProcInfo).
+proc_info_set_reuse_information(ProcInfo0, Reuse0, ProcInfo):-
+ memo_reuse_simplify(Reuse0, Reuse),
+ proc_info_alias_reuse_info(ProcInfo0, AliasReuseInfo),
+ proc_info_set_alias_reuse_info(ProcInfo0,
+ AliasReuseInfo^structure_reuse := Reuse,
+ ProcInfo).
+proc_info_set_static_terms(ProcInfo0, StaticTerms, ProcInfo):-
+ proc_info_alias_reuse_info(ProcInfo0, AliasReuseInfo),
+ proc_info_set_alias_reuse_info(ProcInfo0,
+ AliasReuseInfo^static_terms := StaticTerms,
+ ProcInfo).
proc_info_set_need_maxfr_slot(ProcInfo, NMS, ProcInfo^need_maxfr_slot := NMS).
proc_info_set_call_table_tip(ProcInfo, CTT, ProcInfo^call_table_tip := CTT).
Index: pa_run.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_run.m,v
retrieving revision 1.1.2.16
diff -u -r1.1.2.16 pa_run.m
--- pa_run.m 2001/03/05 17:06:51 1.1.2.16
+++ pa_run.m 2001/03/16 17:02:10
@@ -126,7 +126,7 @@
run_with_dependency( SCC , HLDSin, HLDSout ) -->
(
% analysis ignores special predicates
- { some_are_special_preds(SCC, HLDSin) }
+ { pa_sr_util__some_are_special_preds(SCC, HLDSin) }
->
{ HLDSout = HLDSin }
;
@@ -136,46 +136,6 @@
run_with_dependency_until_fixpoint( SCC, FPtable0,
HLDSin, HLDSout )
).
-
-:- pred some_are_special_preds( list(pred_proc_id), module_info).
-:- mode some_are_special_preds( in, in ) is semidet.
-
-some_are_special_preds( SCC, HLDS ):-
- module_info_get_special_pred_map( HLDS, MAP),
- map__values( MAP, SpecPRED_IDS ),
-
- (
- % either some of the predicates are special
- % preds, such as __Unify__ and others
-
- list__filter( pred_id_in(SpecPRED_IDS), SCC, SpecialPREDS),
- SpecialPREDS = [_|_]
-
- ;
- % or some of the predicates are not defined in this
- % module.
-
- list__filter( not_defined_in_this_module(HLDS), SCC,
- FILTERED),
- FILTERED = [_|_]
- ).
-
-:- 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, _),
- list__member( PRED_ID, IDS ).
-
-:- pred not_defined_in_this_module(module_info, pred_proc_id).
-:- mode not_defined_in_this_module(in,in) is semidet.
-
-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, _),
- % pred_info_import_status(PRED_INFO, STATUS),
- % status_defined_in_this_module(STATUS, no).
:- pred run_with_dependency_until_fixpoint( list(pred_proc_id),
pa_util__pa_fixpoint_table, module_info, module_info,
Index: pa_sr_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_sr_util.m,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 pa_sr_util.m
--- pa_sr_util.m 2001/03/05 17:06:51 1.1.2.2
+++ pa_sr_util.m 2001/03/16 17:02:10
@@ -15,6 +15,7 @@
:- import_module io, list, std_util, term.
:- import_module hlds_pred, prog_data.
+:- import_module hlds_module.
:- pred trans_opt_output_vars_and_types(
prog_varset::in,
@@ -28,6 +29,8 @@
term__substitution(tvar_type)::in,
term__substitution(tvar_type)::out ) is det.
+:- pred some_are_special_preds(list(pred_proc_id)::in,
+ module_info::in) is semidet.
%-----------------------------------------------------------------------------%
:- implementation.
@@ -131,3 +134,40 @@
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
+
+some_are_special_preds(PredProcIds, ModuleInfo):-
+ module_info_get_special_pred_map(ModuleInfo, SpecialPredMap),
+ map__values(SpecialPredMap, SpecialPreds),
+
+ (
+ % either some of the predicates are special
+ % preds, such as __Unify__ and others
+
+ list__filter(pred_id_in(SpecialPreds), PredProcIds,
+ SpecialPredProcs),
+ SpecialPredProcs = [_|_]
+
+ ;
+ % or some of the predicates are not defined in this
+ % module.
+
+ list__filter(not_defined_in_this_module(ModuleInfo),
+ PredProcIds,
+ FilteredPredProcIds),
+ FilteredPredProcIds = [_|_]
+ ).
+
+:- pred pred_id_in(list(pred_id), pred_proc_id).
+:- mode pred_id_in(in, in) is semidet.
+
+pred_id_in(PredIds, PredProcId):-
+ PredProcId = proc(PredId, _),
+ list__member(PredId, PredIds).
+
+:- pred not_defined_in_this_module(module_info, pred_proc_id).
+:- mode not_defined_in_this_module(in,in) is semidet.
+
+not_defined_in_this_module(ModuleInfo, proc(Predid, _)):-
+ hlds_module__pred_not_defined_in_this_module(ModuleInfo,
+ Predid).
+
Index: sr_indirect.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_indirect.m,v
retrieving revision 1.1.2.19
diff -u -r1.1.2.19 sr_indirect.m
--- sr_indirect.m 2001/03/07 17:20:33 1.1.2.19
+++ sr_indirect.m 2001/03/16 17:02:11
@@ -28,6 +28,7 @@
:- 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 pa_sr_util.
:- import_module sr_data, sr_util, sr_live.
:- import_module sr_fixpoint_table.
:- import_module globals, options.
@@ -60,10 +61,10 @@
io__state, io__state).
:- mode run_with_dependency( in, in, out, di, uo ) is det.
-run_with_dependency( SCC , HLDSin, HLDSout ) -->
+run_with_dependency(SCC, HLDSin, HLDSout ) -->
(
% analysis ignores special predicates
- { some_are_special_preds(SCC, HLDSin) }
+ { pa_sr_util__some_are_special_preds(SCC, HLDSin) }
->
{ HLDSout = HLDSin }
;
@@ -74,47 +75,7 @@
HLDSin, HLDSout )
).
-:- pred some_are_special_preds( list(pred_proc_id), module_info).
-:- mode some_are_special_preds( in, in ) is semidet.
-
-some_are_special_preds( SCC, HLDS ):-
- module_info_get_special_pred_map( HLDS, MAP),
- map__values( MAP, SpecPRED_IDS ),
-
- (
- % either some of the predicates are special
- % preds, such as __Unify__ and others
-
- list__filter( pred_id_in(SpecPRED_IDS), SCC, SpecialPREDS),
- SpecialPREDS = [_|_]
-
- ;
- % or some of the predicates are not defined in this
- % module.
-
- list__filter( not_defined_in_this_module(HLDS), SCC,
- FILTERED),
- FILTERED = [_|_]
- ).
-
-:- pred pred_id_in( list(pred_id), pred_proc_id ).
-:- mode pred_id_in( in, in) is semidet.
-
-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).
-:- mode not_defined_in_this_module(in,in) is semidet.
-
-not_defined_in_this_module( HLDS, proc(PREDID, _) ):-
- hlds_module__pred_not_defined_in_this_module(HLDS,
- PREDID).
- % module_info_pred_proc_info(HLDS, PredProcId, PRED_INFO, _),
- % pred_info_import_status(PRED_INFO, STATUS),
- % status_defined_in_this_module(STATUS, no).
-
-%-------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
:- pred run_with_dependency_until_fixpoint( list(pred_proc_id),
sr_fixpoint_table__table, module_info, module_info,
io__state, io__state ).
@@ -134,31 +95,31 @@
HLDSout)
).
-:- pred update_goal_in_module_info( sr_fixpoint_table__table::in,
- pred_proc_id::in,
- module_info::in, module_info::out) is det.
+:- pred update_goal_in_module_info(sr_fixpoint_table__table::in,
+ pred_proc_id::in, module_info::in, module_info::out) is det.
-update_goal_in_module_info( FP, PredProcId, HLDS0, HLDS) :-
- PredProcId = proc( PredId, ProcId ),
+update_goal_in_module_info(FP, PredProcId, HLDS0, HLDS) :-
+ PredProcId = proc(PredId, ProcId),
sr_fixpoint_table_get_final_reuse(PredProcId, Memo, Goal, FP),
- module_info_pred_proc_info( HLDS0, PredProcId, PredInfo0, ProcInfo0),
- proc_info_set_goal( ProcInfo0, Goal, ProcInfo1),
- proc_info_set_reuse_information( ProcInfo1, Memo, ProcInfo),
- pred_info_procedures( PredInfo0, Procedures0),
- map__det_update( Procedures0, ProcId, ProcInfo, Procedures ),
- pred_info_set_procedures( PredInfo0, Procedures, PredInfo),
- module_info_set_pred_info( HLDS0, PredId, PredInfo, HLDS ).
+ module_info_pred_proc_info(HLDS0, PredProcId, PredInfo0, ProcInfo0),
+ proc_info_set_goal(ProcInfo0, Goal, ProcInfo1),
+ proc_info_set_reuse_information(ProcInfo1, Memo, ProcInfo),
+ pred_info_procedures(PredInfo0, Procedures0),
+ map__det_update(Procedures0, ProcId, ProcInfo, Procedures),
+ pred_info_set_procedures(PredInfo0, Procedures, PredInfo),
+ module_info_set_pred_info(HLDS0, PredId, PredInfo, HLDS).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
-:- pred analyse_pred_proc( module_info, pred_proc_id,
+:- pred analyse_pred_proc(module_info, pred_proc_id,
sr_fixpoint_table__table,
sr_fixpoint_table__table,
io__state, io__state).
-:- mode analyse_pred_proc( in, in, in, out, di, uo) is det.
+:- mode analyse_pred_proc(in, in, in, out, di, uo) is det.
-analyse_pred_proc( HLDS, PredProcId, FPin, FPout) -->
- { module_info_pred_proc_info( HLDS, PredProcId,_PredInfo,ProcInfo) },
+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),
@@ -168,16 +129,16 @@
[]
;
{ sr_fixpoint_table_which_run(FPin, Run) },
- { string__int_to_string( Run, SRun ) },
+ { string__int_to_string(Run, SRun) },
{ string__append_list([
"% Indirect reuse analysing (run ", SRun, ") "],
Msg) },
- passes_aux__write_proc_progress_message( Msg,
+ passes_aux__write_proc_progress_message(Msg,
PredId, ProcId, HLDS),
- { sr_fixpoint_table_get_final_reuse( PredProcId, M, _, FPin) },
+ { sr_fixpoint_table_get_final_reuse(PredProcId, M, _, FPin) },
(
- { M = yes( Conditions ) }
+ { M = yes(Conditions) }
->
{ list__length(Conditions, Length) },
{ string__int_to_string(Length, LengthS ) },
@@ -196,7 +157,7 @@
% 1. get ProcInfo
% OK
% 2. get Goal
- proc_info_goal( ProcInfo, Goal0 ),
+ proc_info_goal(ProcInfo, Goal0),
% OK
% 3. initialize alias-information
pa_alias_as__init(Alias0),
@@ -205,11 +166,11 @@
hlds_pred__proc_info_real_headvars(ProcInfo, HVs),
% do not change the state of the fixpoint table by
% simply consulting it now for initialization.
- sr_fixpoint_table_get_final_reuse( PredProcId,
- MemoStarting, _, FPin ),
- indirect_reuse_pool_init( HVs, MemoStarting, Pool0 ),
+ sr_fixpoint_table_get_final_reuse(PredProcId,
+ MemoStarting, _, FPin),
+ indirect_reuse_pool_init(HVs, MemoStarting, Pool0),
% 5. analyse_goal
- analyse_goal( ProcInfo, HLDS,
+ analyse_goal(ProcInfo, HLDS,
Goal0, Goal,
analysis_info(Alias0, Pool0,
set__init, FPin),
@@ -224,9 +185,9 @@
*/
% OK
% 6. update all kind of information
- indirect_reuse_pool_get_memo_reuse( Pool, Memo ),
- sr_fixpoint_table_new_reuse( PredProcId,
- Memo, Goal, FP1, FPout )
+ indirect_reuse_pool_get_memo_reuse(Pool, Memo),
+ sr_fixpoint_table_new_reuse(PredProcId,
+ Memo, Goal, FP1, FPout)
},
(
{ VeryVerbose = no }
@@ -260,7 +221,7 @@
table :: sr_fixpoint_table__table
).
-:- pred analyse_goal( proc_info::in, module_info::in,
+:- pred analyse_goal(proc_info::in, module_info::in,
hlds_goal::in, hlds_goal::out,
analysis_info::in, analysis_info::out) is det.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list