[m-rev.] [reuse] diff: use reuse_condition_table during reuse pass
Nancy Mazur
Nancy.Mazur at cs.kuleuven.ac.be
Wed Jul 28 12:30:15 AEST 2004
Hi,
===================================================================
Estimated hours taken: 15
Branches: reuse
Change the reuse-pass such that it uses a reuse-condition-table storing
intermediate reuse results instead of storing that information in the HLDS.
In a next step, the procedure-info will be changed such that only the public
representation for reuse conditions is used.
sr_data.m:
New reuse_condition_table type.
sr_direct.m:
sr_indirect.m:
sr_profile.m:
sr_profile_run.m:
sr_split.m:
sr_top.m:
Use reuse_condition_table, and use state-variables.
sr_fixpoint_table.m:
Use reuse_condition_table to initialise the fixpoint table.
XXX Goals shouldn't have to be stored in the fixpoint table. This
should be removed soon.
Index: sr_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_data.m,v
retrieving revision 1.1.2.31
diff -u -r1.1.2.31 sr_data.m
--- sr_data.m 30 Jun 2004 04:46:46 -0000 1.1.2.31
+++ sr_data.m 28 Jul 2004 02:22:02 -0000
@@ -24,6 +24,18 @@
:- import_module bool, map, set, std_util, list, io, term.
+%-----------------------------------------------------------------------------%
+
+:- type reuse_condition_table ==
+ map(pred_proc_id, maybe(list(reuse_condition))).
+:- func reuse_condition_table_init = reuse_condition_table.
+:- func reuse_condition_table_search(pred_proc_id, reuse_condition_table)
+ = maybe(list(reuse_condition)) is semidet.
+:- pred reuse_condition_table_set(pred_proc_id::in,
+ maybe(list(reuse_condition))::in,
+ reuse_condition_table::in, reuse_condition_table::out) is det.
+
+%-----------------------------------------------------------------------------%
% The information placed in the goal info which is used by
% structure reuse.
% This field should be initilaised to empty.
@@ -190,6 +202,14 @@
:- import_module possible_alias__pa_sr_util.
:- import_module list, string, require, varset, bool, assoc_list.
+%-----------------------------------------------------------------------------%
+
+reuse_condition_table_init = map__init.
+reuse_condition_table_search(PredProcId, Table) = Table ^ elem(PredProcId).
+reuse_condition_table_set(PredProcId, Conds, Table0, Table) :-
+ map__set(Table0, PredProcId, Conds, Table).
+
+%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
/**
reuse_to_string(Reuse) = String :-
Index: sr_direct.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_direct.m,v
retrieving revision 1.1.2.23
diff -u -r1.1.2.23 sr_direct.m
--- sr_direct.m 5 Jul 2004 03:50:10 -0000 1.1.2.23
+++ sr_direct.m 28 Jul 2004 02:22:02 -0000
@@ -20,11 +20,15 @@
:- import_module hlds__hlds_module.
:- import_module hlds__hlds_pred.
:- import_module possible_alias__pa_alias_as.
+:- import_module structure_reuse__sr_choice_util.
+:- import_module structure_reuse__sr_data.
-:- import_module io.
+:- import_module io, std_util, list.
-:- pred sr_direct__process_proc(alias_as_table::in, pred_id::in, proc_id::in,
+:- pred sr_direct__process_proc(strategy::in, alias_as_table::in,
+ pred_id::in, proc_id::in,
proc_info::in, proc_info::out,
+ maybe(list(reuse_condition))::out,
module_info::in, module_info::out,
io__state::di, io__state::uo) is det.
@@ -43,8 +47,6 @@
:- import_module parse_tree__prog_data.
:- import_module structure_reuse__sr_choice.
:- import_module structure_reuse__sr_choice_graphing.
-:- import_module structure_reuse__sr_choice_util.
-:- import_module structure_reuse__sr_data.
:- import_module structure_reuse__sr_dead.
:- import_module structure_reuse__sr_lbu.
:- import_module structure_reuse__sr_lfu.
@@ -65,16 +67,17 @@
% During the choice analysis, program points are identified by the
% goal-paths leading to thes points. This should become the main way of
% identifying placed of reuse, instead of annotating the actual goals.
-process_proc(AliasTable, PredId, ProcId, !ProcInfo, !ModuleInfo, !IO) :-
+process_proc(Strategy, AliasTable, PredId, ProcId,
+ !ProcInfo, MaybeReuseConditions1, ModuleInfo, ModuleInfo,
+ !IO) :-
globals__io_lookup_bool_option(very_verbose, VeryVerbose, !IO),
sr_lfu__process_proc(!ProcInfo),
- sr_lbu__process_proc(!.ModuleInfo, !ProcInfo),
- goal_path__fill_slots(!.ProcInfo, !.ModuleInfo, !:ProcInfo),
-
+ sr_lbu__process_proc(ModuleInfo, !ProcInfo),
+ goal_path__fill_slots(!.ProcInfo, ModuleInfo, !:ProcInfo),
passes_aux__write_proc_progress_message("% Analysing ",
- PredId, ProcId, !.ModuleInfo, !IO),
+ PredId, ProcId, ModuleInfo, !IO),
proc_info_goal(!.ProcInfo, Goal0),
@@ -82,30 +85,26 @@
% structures potentially die.
passes_aux__maybe_write_string(VeryVerbose,
"%\tdeadness analysis...", !IO),
- sr_dead__process_goal(PredId, !.ProcInfo, !.ModuleInfo,
+ sr_dead__process_goal(PredId, !.ProcInfo, ModuleInfo,
AliasTable, Goal0, Goal1) ,
passes_aux__maybe_write_string(VeryVerbose, "done.\n", !IO),
% 'Choice' analysis: determine how the detected dead data structures
% can be reused locally.
passes_aux__maybe_write_string(VeryVerbose,
- "%\tchoice analysis...", !IO),
+ "%\tchoice analysis...\n", !IO),
proc_info_vartypes(!.ProcInfo, VarTypes),
- % XXX Getting the strategy also performs the check whether the
- % arguments given to the mmc were correct. This is definitely not the
- % right moment to check these arguments. Should be done way earlier.
- sr_choice_util__get_strategy(Strategy, !ModuleInfo, !IO),
Strategy = strategy(_Constraint, Selection),
(
( Selection = graph ; Selection = lifo )
->
sr_choice_graphing__set_background_info(Strategy,
- !.ModuleInfo, VarTypes, Background),
+ ModuleInfo, VarTypes, Background),
sr_choice_graphing__process_goal(Background, Goal1, Goal,
MaybeReuseConditions, !IO)
;
- sr_choice__process_goal(Strategy, VarTypes, !.ModuleInfo,
+ sr_choice__process_goal(Strategy, VarTypes, ModuleInfo,
!.ProcInfo, Goal1, Goal, MaybeReuseConditions)
),
(
@@ -130,8 +129,6 @@
),
memo_reuse_simplify(MaybeReuseConditions, MaybeReuseConditions1),
- proc_info_set_reuse_information(!.ProcInfo,
- MaybeReuseConditions1, !:ProcInfo),
proc_info_set_goal(!.ProcInfo, Goal, !:ProcInfo).
Index: sr_fixpoint_table.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_fixpoint_table.m,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 sr_fixpoint_table.m
--- sr_fixpoint_table.m 2 Jun 2004 10:30:53 -0000 1.1.2.6
+++ sr_fixpoint_table.m 28 Jul 2004 02:22:02 -0000
@@ -23,16 +23,14 @@
:- type table.
-:- pred sr_fixpoint_table_init(module_info::in, list(pred_proc_id)::in,
- table::out) is det.
+:- pred sr_fixpoint_table_init(module_info::in, reuse_condition_table::in,
+ list(pred_proc_id)::in, table::out) is det.
% the datastructure keeps track of the number of fixpoint runs
% performed, this predicates adds one.
-:- pred sr_fixpoint_table_new_run(table::in,
- table::out) is det.
+:- pred sr_fixpoint_table_new_run(table::in, table::out) is det.
-:- pred sr_fixpoint_table_which_run(table::in,
- int::out) is det.
+:- pred sr_fixpoint_table_which_run(table::in, int::out) is det.
% check whether all entries are stable. If so, one has reached
% a fixpoint
@@ -75,6 +73,8 @@
:- import_module std_util, require.
+ % XXX The goal here should be removed at some point as it's not used
+ % anymore.
:- type fixpoint_entry --->
sr_fp(
memo_reuse,
@@ -89,12 +89,18 @@
B = sr_fp(TRB, _),
sr_data__memo_reuse_equal(TRA, TRB).
-:- pred pick_reuse_information(module_info, pred_proc_id, fixpoint_entry).
-:- mode pick_reuse_information(in, in, out) is det.
+:- pred pick_reuse_information(module_info::in, reuse_condition_table::in,
+ pred_proc_id::in, fixpoint_entry::out) is det.
-pick_reuse_information(HLDS, PredProc, Entry) :-
- module_info_pred_proc_info(HLDS, PredProc, _PredInfo, ProcInfo),
- proc_info_reuse_information(ProcInfo, Memo),
+pick_reuse_information(HLDS, ReuseTable, PredProcId, Entry) :-
+ module_info_pred_proc_info(HLDS, PredProcId, _PredInfo, ProcInfo),
+ (
+ Memo1 = reuse_condition_table_search(PredProcId, ReuseTable)
+ ->
+ Memo = Memo1
+ ;
+ Memo = no
+ ),
proc_info_goal(ProcInfo, Goal),
Entry = sr_fp(Memo, Goal).
@@ -104,11 +110,11 @@
:- type table ==
fixpoint_table(pred_proc_id, fixpoint_entry).
-sr_fixpoint_table_init(HLDS, PredProcs, Table) :-
+sr_fixpoint_table_init(HLDS, ReuseTable, PredProcs, Table) :-
fp_init(
pred(K::in, E::out) is det:-
(
- pick_reuse_information(HLDS, K, E)
+ pick_reuse_information(HLDS, ReuseTable, K, E)
),
PredProcs,
Table
Index: sr_indirect.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_indirect.m,v
retrieving revision 1.1.2.35
diff -u -r1.1.2.35 sr_indirect.m
--- sr_indirect.m 30 Jun 2004 04:46:47 -0000 1.1.2.35
+++ sr_indirect.m 28 Jul 2004 02:22:04 -0000
@@ -16,10 +16,12 @@
:- import_module hlds__hlds_module.
:- import_module possible_alias__pa_alias_as.
+:- import_module structure_reuse__sr_data.
:- import_module io.
:- pred sr_indirect__compute_fixpoint(alias_as_table::in,
+ reuse_condition_table::in, reuse_condition_table::out,
module_info::in, module_info::out,
io__state::di, io__state::uo) is det.
@@ -40,203 +42,182 @@
:- import_module possible_alias__pa_alias_as.
:- import_module possible_alias__pa_run.
:- import_module possible_alias__pa_sr_util.
-:- import_module structure_reuse__sr_data.
:- import_module structure_reuse__sr_fixpoint_table.
:- import_module structure_reuse__sr_live.
:- import_module transform_hlds__dependency_graph.
:- import_module map, list, std_util, require, set, string, bool.
-compute_fixpoint(AliasTable, HLDS0, HLDSout) -->
+compute_fixpoint(AliasTable, !ReuseTable, !ModuleInfo, !IO) :-
% compute the strongly connected components
- { module_info_ensure_dependency_info(HLDS0, HLDS1) },
- { module_info_get_maybe_dependency_info(HLDS1, MaybeDepInfo) } ,
+ module_info_ensure_dependency_info(!ModuleInfo),
+ module_info_get_maybe_dependency_info(!.ModuleInfo, MaybeDepInfo),
(
- { MaybeDepInfo = yes(DepInfo) }
+ MaybeDepInfo = yes(DepInfo)
->
- { hlds_dependency_info_get_dependency_ordering(DepInfo,
- DepOrdering) },
+ hlds_dependency_info_get_dependency_ordering(DepInfo,
+ DepOrdering),
% perform the analysis, and annotate the procedures
- run_with_dependencies(AliasTable, DepOrdering, HLDS1, HLDS2),
- { HLDSout = HLDS2 }
+ run_with_dependencies(AliasTable, DepOrdering,
+ !ReuseTable, !ModuleInfo, !IO)
;
- { error("(sr_indirect) compute_fixpoint: no dependency info") }
+ error("(sr_indirect) compute_fixpoint: no dependency info")
).
:- pred run_with_dependencies(alias_as_table::in, dependency_ordering::in,
+ reuse_condition_table::in, reuse_condition_table::out,
module_info::in, module_info::out,
io__state::di, io__state::uo) is det.
-run_with_dependencies(AliasTable, Deps, HLDSin, HLDSout) -->
- list__foldl2(run_with_dependency(AliasTable), Deps, HLDSin, HLDSout).
+run_with_dependencies(AliasTable, Deps, !ReuseTable, !ModuleInfo, !IO) :-
+ list__foldl3(run_with_dependency(AliasTable), Deps,
+ !ReuseTable, !ModuleInfo, !IO).
:- pred run_with_dependency(alias_as_table::in, list(pred_proc_id)::in,
+ reuse_condition_table::in, reuse_condition_table::out,
module_info::in, module_info::out,
io__state::di, io__state::uo) is det.
-run_with_dependency(AliasTable, SCC, HLDSin, HLDSout) -->
+run_with_dependency(AliasTable, SCC, !ReuseTable, !ModuleInfo, !IO) :-
(
% analysis ignores special predicates
- { pa_sr_util__some_are_special_preds(SCC, HLDSin) }
+ pa_sr_util__some_are_special_preds(SCC, !.ModuleInfo)
->
- { HLDSout = HLDSin }
+ true
;
% for each list of strongly connected components,
% perform a fixpoint computation.
- { sr_fixpoint_table_init(HLDSin, SCC, FPtable0) } ,
+ sr_fixpoint_table_init(!.ModuleInfo, !.ReuseTable,
+ SCC, FPtable0),
run_with_dependency_until_fixpoint(AliasTable, SCC, FPtable0,
- HLDSin, HLDSout)
+ !ReuseTable, !ModuleInfo, !IO)
).
%-----------------------------------------------------------------------------%
:- pred run_with_dependency_until_fixpoint(alias_as_table::in,
list(pred_proc_id)::in, sr_fixpoint_table__table::in,
+ reuse_condition_table::in, reuse_condition_table::out,
module_info::in, module_info::out,
io__state::di, io__state::uo) is det.
run_with_dependency_until_fixpoint(AliasTable,
- SCC, FPtable0, HLDSin, HLDSout) -->
- list__foldl2(analyse_pred_proc(HLDSin, AliasTable),
- SCC, FPtable0, FPtable),
+ SCC, FPtable0, !ReuseTable, !ModuleInfo, !IO) :-
+ list__foldl3(analyse_pred_proc(AliasTable, !.ReuseTable),
+ SCC, !ModuleInfo, FPtable0, FPtable, !IO),
(
- { sr_fixpoint_table_all_stable(FPtable) }
+ sr_fixpoint_table_all_stable(FPtable)
->
- { list__foldl(update_goal_in_module_info(FPtable), SCC,
- HLDSin, HLDSout) }
+ list__foldl(update_goal_in_reuse_table(FPtable), SCC,
+ !ReuseTable)
;
- { sr_fixpoint_table_new_run(FPtable,
- FPtable1) },
+ sr_fixpoint_table_new_run(FPtable,
+ FPtable1),
run_with_dependency_until_fixpoint(AliasTable,
- SCC, FPtable1, HLDSin,
- HLDSout)
+ SCC, FPtable1, !ReuseTable,
+ !ModuleInfo, !IO)
).
-:- 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_reuse_table(sr_fixpoint_table__table::in,
+ pred_proc_id::in, reuse_condition_table::in,
+ reuse_condition_table::out) is det.
+
+update_goal_in_reuse_table(FP, PredProcId, !ReuseTable) :-
+ sr_fixpoint_table_get_final_reuse(PredProcId, Memo, _Goal, FP),
+ reuse_condition_table_set(PredProcId, Memo, !ReuseTable).
-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),
- memo_reuse_simplify(Memo, MemoS),
- proc_info_set_reuse_information(ProcInfo1, MemoS, 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::in, alias_as_table::in,
+
+:- pred maybe_write_fixpoint_table_state(bool::in, string::in,
pred_proc_id::in,
- sr_fixpoint_table__table::in, sr_fixpoint_table__table::out,
+ sr_fixpoint_table__table::in,
io__state::di, io__state::uo) is det.
-analyse_pred_proc(HLDS, AliasTable, PredProcId, FPin, FPout) -->
- { module_info_pred_proc_info(HLDS, PredProcId,
- _PredInfo, ProcInfo) },
- { PredProcId = proc(PredId, ProcId) },
+maybe_write_fixpoint_table_state(no, _, _, _, !IO).
+maybe_write_fixpoint_table_state(yes, Description,
+ PredProcId, FP, !IO) :-
+ sr_fixpoint_table_get_final_reuse(PredProcId, M, _, FP),
+ (sr_fixpoint_table_is_recursive(FP) ->
+ Rec = "yes"; Rec = "no"),
- 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) },
- { (sr_fixpoint_table_is_recursive(FPin) ->
- Rec = "yes"; Rec = "no")},
-
- (
- { M = yes(Conditions) }
- ->
- { list__length(Conditions, Length) },
- { string__int_to_string(Length, LengthS) },
- { string__append_list(
- ["%\tNumber of conditions (before):\t",
- LengthS, "\n"], Msg2) } ,
- write_string(Msg2)
- ;
- write_string("%\tNo reuse.\n")
- ),
- write_string("%\t\trec = "),
- write_string(Rec),
- write_string("\n")
+ M = yes(Conditions)
+ ->
+ list__length(Conditions, Length),
+ string__int_to_string(Length, LengthS),
+ string__append_list(
+ ["%\tNumber of conditions (",
+ Description, "):\t",
+ LengthS, "\n"], Msg2),
+ write_string(Msg2, !IO)
+ ;
+ write_string("%\tNo reuse.\n", !IO)
),
- {
- % initialize all the necessary information to get the
- % analysis started.
-
- % 1. get ProcInfo
- % OK
- % 2. get Goal
- proc_info_goal(ProcInfo, Goal0),
- % OK
- % 3. initialize alias-information
- pa_alias_as__init(Alias0),
- % OK
- % 4. initialize reuses-information
- hlds_pred__proc_info_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)
- },
- % 5. analyse_goal
- analyse_goal(ProcInfo, HLDS, AliasTable,
- Goal0, Goal,
- analysis_info(Alias0, Pool0,
- set__init, FPin),
- analysis_info(_Alias, Pool,
- _Static, FP1)),
- /*
- analyse_goal(ProcInfo, HLDS,
- Goal0, Goal,
- Pool0, Pool,
- Alias0, _Alias,
- FPin, FP1),
- */
- % 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)
- },
- (
- { VeryVerbose = no }
- ->
- []
- ;
- { sr_fixpoint_table_get_final_reuse(PredProcId,M1,_,FPout) },
- { (sr_fixpoint_table_is_recursive(FPout) ->
- Rec2 = "yes"; Rec2 = "no")},
+ write_string("%\t\trec = ", !IO),
+ write_string(Rec, !IO),
+ write_string("\n", !IO).
+
+:- pred analyse_pred_proc(alias_as_table::in,
+ reuse_condition_table::in,
+ pred_proc_id::in,
+ module_info::in, module_info::out,
+ sr_fixpoint_table__table::in, sr_fixpoint_table__table::out,
+ io__state::di, io__state::uo) is det.
- (
- { M1 = yes(Conditions1) }
- ->
- { list__length(Conditions1, Length1) },
- { string__int_to_string(Length1, LengthS1) },
- { string__append_list(
- ["%\tNumber of conditions (after):\t",
- LengthS1, "\n"], Msg21) } ,
- write_string(Msg21)
- ;
- write_string("%\tNo reuse.\n")
- ),
- write_string("%\t\trec = "),
- write_string(Rec2),
- write_string("\n")
- ).
+analyse_pred_proc(AliasTable, ReuseTable, PredProcId, !ModuleInfo, !FP, !IO) :-
+ module_info_pred_proc_info(!.ModuleInfo, PredProcId,
+ PredInfo0, ProcInfo0),
+ PredProcId = proc(PredId, ProcId),
+
+ sr_fixpoint_table_which_run(!.FP, 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, !.ModuleInfo, !IO),
+
+ globals__io_lookup_bool_option(very_verbose, VeryVerbose, !IO),
+ maybe_write_fixpoint_table_state(VeryVerbose, "before",
+ PredProcId, !.FP, !IO),
+
+ % initialize all the necessary information to get the
+ % analysis started.
+ % 1. get ProcInfo
+ % OK
+ % 2. get Goal
+ proc_info_goal(ProcInfo0, Goal0),
+ % OK
+ % 3. initialize alias-information
+ pa_alias_as__init(Alias0),
+ % OK
+ % 4. initialize reuses-information
+ hlds_pred__proc_info_headvars(ProcInfo0, 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, _, !.FP),
+ indirect_reuse_pool_init(HVs, MemoStarting, Pool0),
+
+ % 5. analyse_goal
+ analyse_goal(ProcInfo0, !.ModuleInfo,
+ AliasTable, ReuseTable, Goal0, Goal,
+ analysis_info(Alias0, Pool0, set__init, !.FP),
+ analysis_info(_Alias, Pool, _Static, !:FP), !IO),
+
+ % OK
+ % 6. update all kind of information
+ indirect_reuse_pool_get_memo_reuse(Pool, Memo),
+ sr_fixpoint_table_new_reuse(PredProcId,
+ Memo, Goal, !FP),
+
+ maybe_write_fixpoint_table_state(VeryVerbose, "after",
+ PredProcId, !.FP, !IO),
+
+ % Update the ProcInfo, PredInfo, hence also ModuleInfo:
+ proc_info_set_goal(ProcInfo0, Goal, ProcInfo),
+ module_info_set_pred_proc_info(!.ModuleInfo, PredProcId,
+ PredInfo0, ProcInfo, !:ModuleInfo).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -267,76 +248,80 @@
).
:- pred analyse_goal(proc_info::in, module_info::in, alias_as_table::in,
+ reuse_condition_table::in,
hlds_goal::in, hlds_goal::out,
analysis_info::in, analysis_info::out,
io__state::di, io__state::uo) is det.
-analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
- Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable, Expr0 - Info0,
+ Goal, !AnalysisInfo, !IO) :-
Expr0 = conj(Goals0),
- list__map_foldl2(analyse_goal(ProcInfo, HLDS, AliasTable),
+ list__map_foldl2(analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable),
Goals0, Goals,
- AI0, AI, IO0, IO),
+ !AnalysisInfo, !IO),
Expr = conj(Goals),
Info = Info0,
Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
- Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable, Expr0 - Info0,
+ Goal, !AnalysisInfo, !IO) :-
Expr0 = call(PredId, ProcId, ActualVars, _, _, _),
+ AnalysisInfo0 = !.AnalysisInfo,
passes_aux__write_proc_progress_message(
"%\t\tcall to ",
- PredId, ProcId, HLDS, IO0, IO2),
+ PredId, ProcId, HLDS, !IO),
proc_info_vartypes(ProcInfo, VarTypes),
list__map(
map__lookup(VarTypes),
ActualVars,
ActualTypes),
- call_verify_reuse(ProcInfo, HLDS,
+ call_verify_reuse(ProcInfo, HLDS, ReuseTable,
PredId, ProcId, ActualVars,
- ActualTypes, Info0, Info, AI0, AI1, _, IO2, IO3),
+ ActualTypes, Info0, Info, !AnalysisInfo, _, !IO),
pa_run__extend_with_call_alias(HLDS, ProcInfo, AliasTable,
- PredId, ProcId, ActualVars, ActualTypes, AI0 ^ alias, Alias),
- AI = AI1 ^ alias := Alias,
+ PredId, ProcId, ActualVars, ActualTypes,
+ AnalysisInfo0 ^ alias, Alias),
+ !:AnalysisInfo = !.AnalysisInfo ^ alias := Alias,
Expr = Expr0,
- Goal = Expr - Info,
- IO = IO3.
+ Goal = Expr - Info.
-analyse_goal(_ProcInfo, _HLDS, _AliasTable, Expr0 - Info0,
- Goal, AI0, AI, IO0, IO) :-
+analyse_goal(_ProcInfo, _HLDS, _AliasTable, _ReuseTable, Expr0 - Info0,
+ Goal, !AnalysisInfo, !IO) :-
Expr0 = generic_call(_, _, _, _),
pa_alias_as__top("unhandled goal", Alias),
- AI = AI0 ^ alias := Alias,
- Goal = Expr0 - Info0,
- IO = IO0.
+ !:AnalysisInfo = !.AnalysisInfo ^ alias := Alias,
+ Goal = Expr0 - Info0.
-analyse_goal(ProcInfo, HLDS, _AliasTable, Expr0 - Info0,
- Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, _AliasTable, _ReuseTable, Expr0 - Info0,
+ Goal, !AnalysisInfo, !IO) :-
Expr0 = unify(_Var, _Rhs, _Mode, Unification, _Context),
% Record the statically constructed variables.
( Unification = construct(Var, _, _, _,
construct_statically(_), _, _) ->
- AI1 = AI0 ^ static := set__insert(AI0 ^ static, Var)
+ !:AnalysisInfo = !.AnalysisInfo ^ static
+ := set__insert(!.AnalysisInfo ^ static, Var)
;
- AI1 = AI0
+ true
),
pa_alias_as__extend_unification(HLDS, ProcInfo,
- Unification, Info, AI0 ^ alias, Alias),
- AI = AI1 ^ alias := Alias,
+ Unification, Info, !.AnalysisInfo ^ alias,
+ Alias),
+ !:AnalysisInfo = !.AnalysisInfo ^ alias := Alias,
Info = Info0,
Expr = Expr0,
- Goal = Expr - Info,
- IO = IO0.
+ Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
- Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable, Expr0 - Info0,
+ Goal, !AnalysisInfo, !IO) :-
Expr0 = switch(Var, CanFail, Cases0),
+ AI0 = !.AnalysisInfo,
list__map_foldl2(
(pred(case(ConsId, Gin)::in, Tuple::out,
FPin::in, FPout::out,
IOin::di, IOout::uo) is det :-
- analyse_goal(ProcInfo, HLDS, AliasTable, Gin, Gout,
+ analyse_goal(ProcInfo, HLDS, AliasTable,
+ ReuseTable, Gin, Gout,
analysis_info(AI0 ^ alias, AI0 ^ pool,
AI0 ^ static, FPin),
analysis_info(NewAlias,
@@ -346,7 +331,7 @@
NewStatic }
),
Cases0, Tuples,
- AI0 ^ table, FP, IO0, IO),
+ AI0 ^ table, FP, !IO),
Cases = list__map((func({C, _A, _P, _S}) = C), Tuples),
ListPools = list__map((func({_G, _A, P, _S}) = P), Tuples),
@@ -364,28 +349,28 @@
% reduce the aliases
project_on_live_vars(ProcInfo, Info0, Alias1, Alias),
- AI = analysis_info(Alias, Pool, Static, FP),
+ !:AnalysisInfo = analysis_info(Alias, Pool, Static, FP),
Info = Info0,
Expr = switch(Var, CanFail, Cases),
Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
- Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable, Expr0 - Info0,
+ Goal, !AnalysisInfo, !IO) :-
Expr0 = disj(Goals0),
(
Goals0 = []
->
- Goals = Goals0,
- AI0 = AI,
- IO = IO0
+ Goals = Goals0
;
% XXX up to here
+ AI0 = !.AnalysisInfo,
list__map_foldl2(
(pred(Gin::in, Tuple::out,
FPin::in, FPout::out,
IOin::di, IOout::uo) is det :-
analyse_goal(ProcInfo, HLDS, AliasTable,
+ ReuseTable,
Gin, Gout,
analysis_info(AI0 ^ alias, AI0 ^ pool,
AI0 ^ static, FPin),
@@ -395,7 +380,7 @@
Tuple = { Gout, NewAlias, NewPool, NewStatic }
),
Goals0, Tuples,
- AI0 ^ table, FP, IO0, IO),
+ AI0 ^ table, FP, !IO),
Goals = list__map((func({G, _A, _P, _S}) = G), Tuples),
ListPools = list__map((func({_G, _A, P, _S}) = P), Tuples),
@@ -414,42 +399,42 @@
pa_alias_as__project_on_live_vars(ProcInfo, Info, Alias1,
Alias),
- AI = analysis_info(Alias, Pool, Static, FP)
+ !:AnalysisInfo = analysis_info(Alias, Pool, Static, FP)
),
Info = Info0,
Expr = disj(Goals),
Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
- Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable, Expr0 - Info0,
+ Goal, !AnalysisInfo, !IO) :-
Expr0 = not(NegatedGoal0),
- analyse_goal(ProcInfo, HLDS, AliasTable, NegatedGoal0, NegatedGoal,
- AI0, AI, IO0, IO),
+ analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable,
+ NegatedGoal0, NegatedGoal, !AnalysisInfo, !IO),
Info = Info0,
Expr = not(NegatedGoal),
Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
- Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable, Expr0 - Info0,
+ Goal, !AnalysisInfo, !IO) :-
Expr0 = some(A, B, SomeGoal0),
- analyse_goal(ProcInfo, HLDS, AliasTable, SomeGoal0,
- SomeGoal, AI0, AI, IO0, IO),
+ analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable, SomeGoal0,
+ SomeGoal, !AnalysisInfo, !IO),
Info = Info0,
Expr = some(A, B, SomeGoal),
Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
- Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable, Expr0 - Info0,
+ Goal, AI0, AI, !IO) :-
Expr0 = if_then_else(Vars, Cond0, Then0, Else0),
- analyse_goal(ProcInfo, HLDS, AliasTable,
- Cond0, Cond, AI0, AI_Cond, IO0, IO1),
- analyse_goal(ProcInfo, HLDS, AliasTable,
- Then0, Then, AI_Cond, AI_Then, IO1, IO2),
+ analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable,
+ Cond0, Cond, AI0, AI_Cond, !IO),
+ analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable,
+ Then0, Then, AI_Cond, AI_Then, !IO),
AI1 = AI0 ^ table := AI_Then ^ table,
- analyse_goal(ProcInfo, HLDS, AliasTable,
- Else0, Else, AI1, AI_Else, IO2, IO),
+ analyse_goal(ProcInfo, HLDS, AliasTable, ReuseTable,
+ Else0, Else, AI1, AI_Else, !IO),
indirect_reuse_pool_least_upper_bound_disjunction(
[AI_Then ^ pool, AI_Else ^ pool],
@@ -470,51 +455,49 @@
Expr = if_then_else(Vars, Cond, Then, Else),
Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, _AliasTable, Expr0 - Info0,
- Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, _AliasTable, _ReuseTable, Expr0 - Info0,
+ Goal, !AnalysisInfo, !IO) :-
Expr0 = foreign_proc(Attrs, PredId, ProcId,
Vars, MaybeModes, Types, _),
pa_alias_as__extend_foreign_code(HLDS, ProcInfo, Attrs,
PredId, ProcId, Vars,
- MaybeModes, Types, Info0, AI0 ^ alias, Alias),
- AI = AI0 ^ alias := Alias,
- Goal = Expr0 - Info0,
- IO = IO0.
+ MaybeModes, Types, Info0,
+ !.AnalysisInfo ^ alias, Alias),
+ !:AnalysisInfo = !.AnalysisInfo ^ alias := Alias,
+ Goal = Expr0 - Info0.
-analyse_goal(_ProcInfo, _HLDS, _AliasTable, Expr0 - Info0,
- Goal, AI0, AI, IO0, IO) :-
+analyse_goal(_ProcInfo, _HLDS, _AliasTable, _ReuseTable, Expr0 - Info0,
+ Goal, !AnalysisInfo, !IO) :-
Expr0 = par_conj(_),
pa_alias_as__top("unhandled goal (par_conj)", Alias),
- AI = AI0 ^ alias := Alias,
- Goal = Expr0 - Info0,
- IO = IO0.
+ !:AnalysisInfo = !.AnalysisInfo ^ alias := Alias,
+ Goal = Expr0 - Info0.
-analyse_goal(_ProcInfo, _HLDS, _AliasTable, Expr0 - Info0,
- Goal, AI0, AI, IO0, IO) :-
+analyse_goal(_ProcInfo, _HLDS, _AliasTable, _ReuseTable, Expr0 - _Info0,
+ _Goal, !AnalysisInfo, !IO) :-
Expr0 = shorthand(_),
- pa_alias_as__top("unhandled goal (shorthand)", Alias),
- AI = AI0 ^ alias := Alias,
- Goal = Expr0 - Info0,
- IO = IO0.
-
+ error("sr_indirect__analyse_goal: shorthand goal").
:- pred call_verify_reuse(proc_info::in, module_info::in,
+ reuse_condition_table::in,
pred_id::in, proc_id::in, list(prog_var)::in,
list((type))::in,
hlds_goal_info::in, hlds_goal_info::out,
analysis_info::in, analysis_info::out, bool::out,
io__state::di, io__state::uo) is det.
-call_verify_reuse(ProcInfo, ModuleInfo, PredId, ProcId, ActualVars,
- ActualTypes,
+call_verify_reuse(ProcInfo, ModuleInfo, ReuseTable,
+ PredId, ProcId, ActualVars, ActualTypes,
GoalInfo0, GoalInfo, analysis_info(Alias0, Pool0, Static, FP0),
analysis_info(Alias0, Pool, Static, FP), YesNo) -->
- call_verify_reuse(ProcInfo, ModuleInfo, PredId, ProcId, ActualVars,
+ call_verify_reuse(ProcInfo, ModuleInfo, ReuseTable,
+ PredId, ProcId, ActualVars,
ActualTypes,
Alias0, Static, Pool0, Pool, GoalInfo0, GoalInfo,
FP0, FP, YesNo).
-:- pred call_verify_reuse(proc_info::in, module_info::in, pred_id::in,
+:- pred call_verify_reuse(proc_info::in, module_info::in,
+ reuse_condition_table::in, pred_id::in,
proc_id::in, list(prog_var)::in, list((type))::in,
alias_as::in,
set(prog_var)::in, indirect_reuse_pool::in,
@@ -523,7 +506,7 @@
sr_fixpoint_table__table::out, bool::out,
io__state::di, io__state::uo) is det.
-call_verify_reuse(ProcInfo, HLDS, PredId0, ProcId0,
+call_verify_reuse(ProcInfo, HLDS, ReuseTable, PredId0, ProcId0,
ActualVars, ActualTypes, Alias0,
StaticTerms, Pool0, Pool,
Info0, Info, FP0, FP, YesNo, IO0, IO) :-
@@ -545,7 +528,7 @@
module_info_pred_proc_info(HLDS, PredId, ProcId, PredInfo,
ProcInfo0),
% 1. find the tabled reuse for the called predicate
- lookup_memo_reuse(PredId, ProcId, HLDS, FP0, FP,
+ lookup_memo_reuse(PredId, ProcId, HLDS, ReuseTable, FP0, FP,
FormalMemo, IO2, IO),
% 2. once found, we can immediately handle the case where
% the tabled reuse would say that reuse is not possible anyway:
@@ -721,39 +704,43 @@
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
-:- pred lookup_memo_reuse(pred_id, proc_id, module_info,
- sr_fixpoint_table__table, sr_fixpoint_table__table,
- memo_reuse, io__state, io__state).
-:- mode lookup_memo_reuse(in, in, in, in, out, out, di, uo) is det.
+:- pred lookup_memo_reuse(pred_id::in, proc_id::in, module_info::in,
+ reuse_condition_table::in,
+ sr_fixpoint_table__table::in, sr_fixpoint_table__table::out,
+ memo_reuse::out, io__state::di, io__state::uo) is det.
% similar to the lookup_call_alias from pa_run:
% 1. check in fixpoint table
% 2. check in module_info (already fully analysed or imported pred)
% 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, IO0, IO):-
+lookup_memo_reuse(PredId, ProcId, HLDS, ReuseTable, !FP, Memo, !IO) :-
PredProcId = proc(PredId, ProcId),
(
% 1 - check in table
sr_fixpoint_table_get_reuse(PredProcId,
- Memo1, FP0, FP1)
+ Memo1, !FP)
->
- ( sr_fixpoint_table_is_recursive(FP1) -> R = "yes"; R = "no"),
+ ( sr_fixpoint_table_is_recursive(!.FP) -> R = "yes"; R = "no"),
string__append_list(
["%\t\tsucceeded fpt (R = ", R, ") for "], Msg),
passes_aux__write_proc_progress_message(Msg,
- PredId, ProcId, HLDS, IO0, IO),
- Memo = Memo1,
- FP = FP1
+ PredId, ProcId, HLDS, !IO),
+ Memo = Memo1
;
passes_aux__write_proc_progress_message(
"%\t\tfailed fpt lookup for ",
- PredId, ProcId, HLDS, IO0, IO),
- FP = FP0,
- % 2 - lookup in module_info
- module_info_pred_proc_info(HLDS, PredProcId, _PredInfo,
- ProcInfo),
- proc_info_reuse_information(ProcInfo, Memo)
+ PredId, ProcId, HLDS, !IO),
+ % 2 - lookup in reuse table
+ Memo1 = reuse_condition_table_search(PredProcId, ReuseTable)
+ ->
+ Memo = Memo1
+ ;
+ passes_aux__write_proc_progress_message(
+ "%\t\tfailed reuse_table lookup for ",
+ PredId, ProcId, HLDS, !IO),
+ Memo = no
+
).
%-----------------------------------------------------------------------------%
Index: sr_profile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_profile.m,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 sr_profile.m
--- sr_profile.m 2 Jun 2004 10:30:54 -0000 1.1.2.8
+++ sr_profile.m 28 Jul 2004 02:22:05 -0000
@@ -12,6 +12,7 @@
:- interface.
:- import_module hlds__hlds_module.
+:- import_module structure_reuse__sr_data.
:- import_module io, int, string.
@@ -69,7 +70,8 @@
:- pred write_profiling(string::in, profiling_info::in, module_info::in,
- io__state::di, io__state::uo) is det.
+ reuse_condition_table::in,
+ io__state::di, io__state::uo) is det.
%-----------------------------------------------------------------------------%
@@ -140,7 +142,7 @@
reuse_calls(P0, P0 ^ reuse_calls).
no_reuse_calls(P0, P0 ^ no_reuse_calls).
-write_profiling(String, Prof, HLDS) -->
+write_profiling(String, Prof, HLDS, ReuseTable) -->
{ string__append(String, ".profile", String2) },
io__open_output(String2, IOResult),
(
@@ -229,7 +231,7 @@
DomList) },
write_graph_nodes(DomList, DepGraph,
- write_procedure_node(HLDS, Stream),
+ write_procedure_node(HLDS, ReuseTable, Stream),
write_procedure_link(HLDS, Stream)),
io__write_string(Stream, "\n}\n"),
@@ -241,19 +243,26 @@
{ require__error(IOErrorString) }
).
-:- pred write_procedure_node(module_info::in, io__output_stream::in,
+:- pred write_procedure_node(module_info::in,
+ reuse_condition_table::in, io__output_stream::in,
pred_proc_id::in, io__state::di, io__state::uo) is det.
-write_procedure_node(HLDS, Stream, PredProcId) -->
- { module_info_structure_reuse_info(HLDS, HLDSReuseInfo) },
- { HLDSReuseInfo = structure_reuse_info(ReuseMap) },
- io__set_output_stream(Stream, OldStream),
- { PredProcId = proc(PredId, ProcId) },
- { module_info_pred_proc_info(HLDS, PredProcId, PredInfo, ProcInfo) },
- { proc_info_reuse_information(ProcInfo, ReuseInfo) },
- { pred_info_import_status(PredInfo, ImportStatus) },
+write_procedure_node(HLDS, ReuseTable, Stream, PredProcId, !IO) :-
+ module_info_structure_reuse_info(HLDS, HLDSReuseInfo),
+ HLDSReuseInfo = structure_reuse_info(ReuseMap),
+ io__set_output_stream(Stream, OldStream, !IO),
+ PredProcId = proc(PredId, ProcId),
+ module_info_pred_proc_info(HLDS, PredProcId, PredInfo, _ProcInfo),
+ (
+ ReuseInfo1 = reuse_condition_table_search(PredProcId,
+ ReuseTable)
+ ->
+ ReuseInfo = ReuseInfo1
+ ;
+ ReuseInfo = no
+ ),
+ pred_info_import_status(PredInfo, ImportStatus),
- {
(
ImportStatus = exported
->
@@ -289,17 +298,15 @@
;
Color = "color=black"
)
- ) },
- { string__append_list(["[", Color,
+ ),
+ string__append_list(["[", Color,
",shape=",Shape,
",peripheries=", Periferies, "];\n"],
- Options) },
-
- write_node_name(HLDS, PredId, ProcId),
-
- io__write_string(Options),
+ Options),
- io__set_output_stream(OldStream, _).
+ write_node_name(HLDS, PredId, ProcId, !IO),
+ io__write_string(Options, !IO),
+ io__set_output_stream(OldStream, _, !IO).
:- pred write_procedure_link(module_info::in, io__output_stream::in,
pred_proc_id::in, pred_proc_id::in,
Index: sr_profile_run.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_profile_run.m,v
retrieving revision 1.1.2.9
diff -u -r1.1.2.9 sr_profile_run.m
--- sr_profile_run.m 25 Jun 2004 02:33:52 -0000 1.1.2.9
+++ sr_profile_run.m 28 Jul 2004 02:22:07 -0000
@@ -12,11 +12,12 @@
:- interface.
:- import_module hlds__hlds_module.
+:- import_module structure_reuse__sr_data.
:- import_module io.
-:- pred structure_reuse_profiling(module_info::in, io__state::di,
- io__state::uo) is det.
+:- pred structure_reuse_profiling(module_info::in, reuse_condition_table::in,
+ io__state::di, io__state::uo) is det.
%-----------------------------------------------------------------------------%
:- implementation.
@@ -29,26 +30,27 @@
:- import_module parse_tree__prog_out.
:- import_module parse_tree__prog_data.
:- import_module possible_alias__pa_alias_as.
-:- import_module structure_reuse__sr_data.
:- import_module structure_reuse__sr_profile.
:- import_module list, map, bool, std_util.
-structure_reuse_profiling(HLDS) -->
+structure_reuse_profiling(HLDS, ReuseTable) -->
globals__io_lookup_bool_option(very_verbose, Verbose),
maybe_write_string(Verbose,
"% Collecting reuse-profiling information... "),
- { collect_profiling_information(HLDS, Profiling) },
+ { collect_profiling_information(HLDS, ReuseTable, Profiling) },
{ module_info_name(HLDS, ModuleName) },
{ prog_out__sym_name_to_string(ModuleName, ModuleNameString) },
- sr_profile__write_profiling(ModuleNameString, Profiling, HLDS),
+ sr_profile__write_profiling(ModuleNameString, Profiling, HLDS,
+ ReuseTable),
maybe_write_string(Verbose, "done.\n").
:- pred collect_profiling_information(module_info::in,
+ reuse_condition_table::in,
profiling_info::out) is det.
-collect_profiling_information(HLDS, Prof) :-
+collect_profiling_information(HLDS, ReuseTable, Prof) :-
sr_profile__init(Prof0),
module_info_predids(HLDS, PredIds0),
module_info_get_special_pred_map(HLDS, Map),
@@ -61,34 +63,45 @@
PredIds0,
PredIds),
list__foldl(
- collect_profiling_information_2(HLDS),
+ collect_profiling_information_2(HLDS, ReuseTable),
PredIds,
Prof0,
Prof).
-:- pred collect_profiling_information_2(module_info::in, pred_id::in,
- profiling_info::in, profiling_info::out) is det.
-collect_profiling_information_2(HLDS, PredId, Prof0, Prof):-
+:- pred collect_profiling_information_2(module_info::in,
+ reuse_condition_table::in, pred_id::in,
+ profiling_info::in, profiling_info::out) is det.
+collect_profiling_information_2(HLDS, ReuseTable, PredId, Prof0, Prof):-
module_info_pred_info(HLDS, PredId, PredInfo),
pred_info_import_status(PredInfo, ImportStatus),
pred_info_procedures(PredInfo, Procedures),
- map__values(Procedures, ProcInfos),
+ map__to_assoc_list(Procedures, ProcIdInfos),
list__foldl(
- collect_profiling_information_3(HLDS, ImportStatus),
- ProcInfos,
+ collect_profiling_information_3(HLDS, ReuseTable,
+ ImportStatus, PredId),
+ ProcIdInfos,
Prof0,
Prof).
:- pred collect_profiling_information_3(module_info::in,
- import_status::in, proc_info::in,
- profiling_info::in, profiling_info::out) is det.
+ reuse_condition_table::in, import_status::in,
+ pred_id::in, pair(proc_id, proc_info)::in,
+ profiling_info::in, profiling_info::out) is det.
-collect_profiling_information_3(HLDS, ImportStatus, ProcInfo) -->
+collect_profiling_information_3(HLDS, ReuseTable, ImportStatus, PredId,
+ ProcId - ProcInfo) -->
% first record some info about the procedure in general...
{
status_is_exported(ImportStatus, IsExported),
- proc_info_reuse_information(ProcInfo, ReuseInfo),
+ (
+ ReuseInfo0 = reuse_condition_table_search(
+ proc(PredId, ProcId), ReuseTable)
+ ->
+ ReuseInfo = ReuseInfo0
+ ;
+ ReuseInfo = no
+ ),
(
ReuseInfo = yes(List)
->
Index: sr_split.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_split.m,v
retrieving revision 1.1.2.20
diff -u -r1.1.2.20 sr_split.m
--- sr_split.m 2 Jun 2004 10:30:55 -0000 1.1.2.20
+++ sr_split.m 28 Jul 2004 02:22:09 -0000
@@ -26,11 +26,14 @@
% each procedure having conditional reuse (ReuseHLDS), a new
% separate reuse-procedure is added. The calls can then also
% be corrected so that they point to the correct reuse-versions.
-:- pred sr_split__create_multiple_versions(module_info::in,
+:- pred sr_split__create_multiple_versions(reuse_condition_table::in,
+ reuse_condition_table::out, module_info::in,
module_info::out, io__state::di, io__state::uo) is det.
:- pred create_reuse_pred(pred_proc_id::in, memo_reuse::in,
maybe(hlds_goal)::in,
+ pred_proc_id::out,
+ reuse_condition_table::in, reuse_condition_table::out,
module_info::in, module_info::out) is det.
:- pred reuse_predicate_name(string).
@@ -42,6 +45,9 @@
:- implementation.
:- import_module hlds__hlds_data.
+:- import_module hlds__passes_aux.
+:- import_module libs__globals.
+:- import_module libs__options.
:- import_module parse_tree__prog_data.
:- import_module parse_tree__prog_util.
:- import_module structure_reuse__sr_data.
@@ -51,31 +57,32 @@
reuse_predicate_name(PredName) :-
string__prefix(PredName, "reuse__").
-sr_split__create_multiple_versions(ReuseHLDS, HLDS) -->
+sr_split__create_multiple_versions(!ReuseTable, !ModuleInfo, !IO) :-
% compute the strongly connected components
- { create_versions(ReuseHLDS, HLDS1) },
- { reprocess_all_goals(HLDS1, HLDS) }.
+ create_versions(!ReuseTable, !ModuleInfo, !IO),
+ reprocess_all_goals(!.ReuseTable, !ModuleInfo).
% reprocess each of the procedures to make sure that all calls
% to reuse preds are correct.
-:- pred reprocess_all_goals(module_info::in, module_info::out) is det.
+:- pred reprocess_all_goals(reuse_condition_table::in,
+ module_info::in, module_info::out) is det.
-reprocess_all_goals(HLDS0, HLDS) :-
+reprocess_all_goals(ReuseTable, HLDS0, HLDS) :-
module_info_predids(HLDS0, PredIds),
list__foldl(
- reprocess_all_goals_2,
+ reprocess_all_goals_2(ReuseTable),
PredIds,
HLDS0,
HLDS).
-:- pred reprocess_all_goals_2(pred_id::in, module_info::in,
- module_info::out) is det.
-reprocess_all_goals_2(PredId, HLDS0, HLDS) :-
+:- pred reprocess_all_goals_2(reuse_condition_table::in, pred_id::in,
+ module_info::in, module_info::out) is det.
+reprocess_all_goals_2(ReuseTable, PredId, HLDS0, HLDS) :-
module_info_pred_info(HLDS0, PredId, PredInfo0),
pred_info_procids(PredInfo0, ProcIds),
pred_info_procedures(PredInfo0, Procedures0),
list__foldl(
- reprocess_all_goals_3(HLDS0),
+ reprocess_all_goals_3(ReuseTable, HLDS0, PredId),
ProcIds,
Procedures0,
Procedures
@@ -83,12 +90,15 @@
pred_info_set_procedures(PredInfo0, Procedures, PredInfo),
module_info_set_pred_info(HLDS0, PredId, PredInfo, HLDS).
-:- pred reprocess_all_goals_3(module_info::in, proc_id::in,
+:- pred reprocess_all_goals_3(reuse_condition_table::in,
+ module_info::in, pred_id::in, proc_id::in,
proc_table::in, proc_table::out) is det.
-reprocess_all_goals_3(HLDS, ProcId, ProcTable0, ProcTable) :-
+reprocess_all_goals_3(ReuseTable, HLDS, PredId, ProcId,
+ ProcTable0, ProcTable) :-
map__lookup(ProcTable0, ProcId, ProcInfo0),
- proc_info_reuse_information(ProcInfo0 , Memo),
(
+ Memo = reuse_condition_table_search(proc(PredId, ProcId),
+ ReuseTable),
Memo = yes(Conditions)
->
proc_info_goal(ProcInfo0, Goal0),
@@ -109,61 +119,57 @@
).
-:- pred create_versions(module_info, module_info).
-:- mode create_versions(in, out) is det.
-
-create_versions(ReuseHLDS, HLDS) :-
- module_info_predids(ReuseHLDS, PredIds),
- list__foldl(
- create_versions_2,
- PredIds,
- ReuseHLDS,
- HLDS).
+:- pred create_versions(reuse_condition_table::in,
+ reuse_condition_table::out,
+ module_info::in, module_info::out,
+ io__state::di, io__state::uo) is det.
+
+create_versions(!ReuseTable, !ModuleInfo, !IO) :-
+ module_info_predids(!.ModuleInfo, PredIds),
+ list__foldl3(create_versions_2, PredIds, !ReuseTable,
+ !ModuleInfo, !IO).
:- pred create_versions_2(pred_id::in,
- module_info::in, module_info::out) is det.
+ reuse_condition_table::in,
+ reuse_condition_table::out,
+ module_info::in, module_info::out,
+ io__state::di, io__state::uo) is det.
-create_versions_2(PredId , HLDS0, HLDS) :-
- module_info_pred_info(HLDS0, PredId, PredInfo0),
+create_versions_2(PredId, !ReuseTable, !ModuleInfo, !IO) :-
+ module_info_pred_info(!.ModuleInfo, PredId, PredInfo0),
pred_info_procids(PredInfo0, ProcIds),
- list__foldl(
- pred(Id::in, H0::in, H::out) is det :-
+ list__foldl3(
+ pred(Id::in, RT0::in, RT::out, H0::in, H::out,
+ IOin::di, IOout::uo) is det :-
(
- create_versions_3(proc(PredId, Id),
- H0, H)
+ create_versions_3(proc(PredId, Id), RT0, RT,
+ H0, H, IOin, IOout)
),
- ProcIds,
- HLDS0,
- HLDS
- ).
+ ProcIds, !ReuseTable, !ModuleInfo, !IO).
:- pred create_versions_3(pred_proc_id::in,
- module_info::in, module_info::out) is det.
+ reuse_condition_table::in,
+ reuse_condition_table::out,
+ module_info::in, module_info::out,
+ io__state::di, io__state::uo) is det.
-create_versions_3(PredProcId, WorkingHLDS, HLDS):-
+create_versions_3(PredProcId, !ReuseTable, WorkingHLDS, HLDS, !IO):-
module_info_pred_proc_info(WorkingHLDS, PredProcId,
PredInfo0, ProcInfo0),
- proc_info_reuse_information(ProcInfo0, Memo),
-% module_info_pred_proc_info(VirginHLDS, PredProcId, _,
-% CleanProcInfo),
proc_info_goal(ProcInfo0, ReuseGoal),
(
- Memo = no
+ Memo = reuse_condition_table_search(PredProcId, !.ReuseTable),
+ Memo = yes(_)
->
- % restore the old status of the procedure
- % module_info_set_pred_proc_info(WorkingHLDS, PredProcId,
- % PredInfo0, CleanProcInfo, HLDS)
- HLDS = WorkingHLDS
- ;
(
memo_reuse_is_conditional(Memo)
->
% fetch the reuse goal
- create_reuse_pred(Memo, PredProcId, yes(ReuseGoal),
+ create_reuse_pred_info(PredProcId, yes(ReuseGoal),
PredInfo0, ProcInfo0,
- ReusePredInfo, _ReuseProcInfo0,
+ ReusePredInfo,
ReuseProcId, ReuseName),
module_info_get_predicate_table(WorkingHLDS,
PredTable0),
@@ -172,25 +178,55 @@
StrReuseInfo0 = structure_reuse_info(ReuseMap0),
predicate_table_insert(PredTable0, ReusePredInfo,
ReusePredId, PredTable),
- map__det_insert(ReuseMap0, PredProcId,
- proc(ReusePredId, ReuseProcId) - ReuseName,
- ReuseMap),
- StrReuseInfo = structure_reuse_info(ReuseMap),
- module_info_set_structure_reuse_info(WorkingHLDS,
- StrReuseInfo, WorkingHLDS1),
- module_info_set_predicate_table(WorkingHLDS1,
+
+ memo_reuse_simplify(Memo, SimplifiedMemo),
+ reuse_condition_table_set(
+ proc(ReusePredId, ReuseProcId),
+ SimplifiedMemo, !ReuseTable),
+
+ (
+ map__search(ReuseMap0, PredProcId, _)
+ ->
+ PredProcId = proc(PredId, ProcId),
+ Msg1 = "% Adding already existing procedure: ",
+ write_proc_progress_message(Msg1,
+ PredId, ProcId, WorkingHLDS, !IO),
+ HLDS = WorkingHLDS
+
+ % pred_id_to_int(PredId, PredIdInt),
+ % proc_id_to_int(ProcId, ProcIdInt),
+ % string__append_list([
+ % "(sr_split) ",
+ % "Reuse map already ",
+ % "contains id: proc(",
+ % string__int_to_string(PredIdInt),
+ % ", ",
+ % string__int_to_string(ProcIdInt),
+ % ").\n"], Msg),
+ % error(Msg)
+ ;
+ map__det_insert(ReuseMap0, PredProcId,
+ proc(ReusePredId,
+ ReuseProcId) - ReuseName,
+ ReuseMap),
+ StrReuseInfo = structure_reuse_info(ReuseMap),
+ module_info_set_structure_reuse_info(
+ WorkingHLDS, StrReuseInfo,
+ WorkingHLDS1),
+ module_info_set_predicate_table(WorkingHLDS1,
PredTable, WorkingHLDS2),
+ module_info_set_pred_proc_info(WorkingHLDS2,
+ PredProcId, PredInfo0, ProcInfo0, HLDS)
+ ),
% Change the conditions on this version
% to be unconditional. This ensures
% that when process_goal is run on this
% procedure only the reuse which is
% unconditional is kept.
- proc_info_set_reuse_information(ProcInfo0,
- yes([]), ProcInfo),
+ reuse_condition_table_set(PredProcId,
+ yes([]), !ReuseTable)
- module_info_set_pred_proc_info(WorkingHLDS2,
- PredProcId, PredInfo0, ProcInfo, HLDS)
;
% memo_reuse is unconditional -- perfect --
% nothing to be done! (processing the goal is
@@ -206,62 +242,79 @@
PredProcId, PredInfo0, ProcInfo2, HLDS)
)
+ ;
+ % restore the old status of the procedure
+ % module_info_set_pred_proc_info(WorkingHLDS, PredProcId,
+ % PredInfo0, CleanProcInfo, HLDS)
+ HLDS = WorkingHLDS
).
-create_reuse_pred(PRED_PROC_ID, TREUSE, MaybeHLDS_GOAL, HLDSin, HLDSout) :-
- module_info_pred_proc_info(HLDSin, PRED_PROC_ID, PredInfo0,
+create_reuse_pred(PredProcId, TransOptReuse, MaybeHLDS_GOAL,
+ proc(ReusePredId, ReuseProcId),
+ !ReuseTable, !ModuleInfo) :-
+ module_info_pred_proc_info(!.ModuleInfo, PredProcId, PredInfo0,
ProcInfo0),
- (memo_reuse_is_conditional(TREUSE) ->
- create_reuse_pred(TREUSE, PRED_PROC_ID,
- MaybeHLDS_GOAL, PredInfo0, ProcInfo0,
- ReusePredInfo, _ReuseProcInfo,
- ReuseProcId, ReuseName),
+ (
+ memo_reuse_is_conditional(TransOptReuse)
+ ->
+ create_reuse_pred_info(PredProcId,
+ MaybeHLDS_GOAL, PredInfo0, ProcInfo0,
+ ReusePredInfo,
+ ReuseProcId, ReuseName),
- module_info_get_predicate_table(HLDSin, PredTable0),
+ module_info_get_predicate_table(!.ModuleInfo, PredTable0),
predicate_table_insert(PredTable0, ReusePredInfo,
- ReusePredId, PredTable),
- module_info_structure_reuse_info(HLDSin, StrReuseInfo0),
+ ReusePredId, PredTable),
+
+ memo_reuse_simplify(TransOptReuse, SimplifiedTabledReuse),
+ reuse_condition_table_set(proc(ReusePredId, ReuseProcId),
+ SimplifiedTabledReuse, !ReuseTable),
+
+ module_info_structure_reuse_info(!.ModuleInfo, StrReuseInfo0),
StrReuseInfo0 = structure_reuse_info(ReuseMap0),
- map__det_insert(ReuseMap0, PRED_PROC_ID,
- proc(ReusePredId, ReuseProcId) - ReuseName,
- ReuseMap),
+ map__det_insert(ReuseMap0, PredProcId,
+ proc(ReusePredId, ReuseProcId) - ReuseName,
+ ReuseMap),
StrReuseInfo = structure_reuse_info(ReuseMap),
- module_info_set_structure_reuse_info(HLDSin,
- StrReuseInfo, HLDSin1),
- module_info_set_predicate_table(HLDSin1, PredTable, HLDSout)
+ module_info_set_structure_reuse_info(!.ModuleInfo,
+ StrReuseInfo, !:ModuleInfo),
+ module_info_set_predicate_table(!.ModuleInfo,
+ PredTable, !:ModuleInfo)
% ; contains_unconditional_reuse(TREUSE) ->
;
- memo_reuse_simplify(TREUSE, TREUSE1),
- proc_info_set_reuse_information(ProcInfo0, TREUSE1, ProcInfo1),
+ PredProcId = proc(PredId, ProcId),
+ ReuseProcId = ProcId,
+ ReusePredId = PredId,
+ % is unconditional, or has no reuse, so no simplify required:
+ reuse_condition_table_set(PredProcId, TransOptReuse,
+ !ReuseTable),
(
MaybeHLDS_GOAL = yes(HLDS_GOAL),
- proc_info_set_goal(ProcInfo1, HLDS_GOAL, ProcInfo)
+ proc_info_set_goal(ProcInfo0, HLDS_GOAL, ProcInfo)
;
MaybeHLDS_GOAL = no,
- ProcInfo = ProcInfo1
+ ProcInfo = ProcInfo0
),
- module_info_set_pred_proc_info(HLDSin, PRED_PROC_ID,
- PredInfo0, ProcInfo, HLDSout)
+ module_info_set_pred_proc_info(!.ModuleInfo, PredProcId,
+ PredInfo0, ProcInfo, !:ModuleInfo)
).
-:- pred create_reuse_pred(memo_reuse::in, pred_proc_id::in,
+:- pred create_reuse_pred_info(pred_proc_id::in,
maybe(hlds_goal)::in, pred_info::in, proc_info::in,
- pred_info::out, proc_info::out,
+ pred_info::out,
proc_id::out, sym_name::out) is det.
-create_reuse_pred(TabledReuse, PredProcId, MaybeReuseGoal, PredInfo, ProcInfo,
- ReusePredInfo, ReuseProcInfo, ReuseProcId, SymName) :-
- memo_reuse_simplify(TabledReuse, TabledReuse1),
- proc_info_set_reuse_information(ProcInfo, TabledReuse1,
- ReuseProcInfo0),
+create_reuse_pred_info(PredProcId, MaybeReuseGoal, PredInfo, ProcInfo0,
+ ReusePredInfo,
+ ReuseProcId, SymName) :-
(
MaybeReuseGoal = yes(PotReuseGoal),
convert_potential_reuse_to_reuse(PotReuseGoal, ReuseGoal),
- proc_info_set_goal(ReuseProcInfo0, ReuseGoal, ReuseProcInfo)
+ proc_info_set_goal(ProcInfo0, ReuseGoal, ReuseProcInfo)
;
MaybeReuseGoal = no,
- ReuseProcInfo = ReuseProcInfo0
+ ReuseProcInfo = ProcInfo0
),
pred_info_module(PredInfo, ModuleName),
pred_info_name(PredInfo, Name),
Index: sr_top.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_top.m,v
retrieving revision 1.1.2.6
diff -u -r1.1.2.6 sr_top.m
--- sr_top.m 30 Jun 2004 04:46:47 -0000 1.1.2.6
+++ sr_top.m 28 Jul 2004 02:22:10 -0000
@@ -71,6 +71,7 @@
:- import_module parse_tree__mercury_to_mercury.
:- import_module parse_tree__prog_data.
:- import_module possible_alias__pa_sr_util.
+:- import_module structure_reuse__sr_choice_util.
:- import_module structure_reuse__sr_data.
:- import_module structure_reuse__sr_direct.
:- import_module structure_reuse__sr_indirect.
@@ -107,75 +108,165 @@
module_info::in, module_info::out,
io::di, io::uo) is det.
-structure_reuse(AliasTable, HLDS00, HLDS) -->
+structure_reuse(AliasTable, !ModuleInfo, !IO) :-
+ globals__io_lookup_bool_option(very_verbose, VeryVerbose, !IO),
+ % Before starting any of the analysis, check whether the strategy
+ % options for structure reuse were correctly given. Retreive the
+ % general strategy information.
+ get_strategy(Strategy, !ModuleInfo, !IO),
+
% Before starting the actual reuse-analysis, process all the reuse
% information of the imported predicates.
- { module_info_unproc_reuse_pragmas(HLDS00, UnprocReusePragmas) },
- list__foldl2(
- process_unproc_reuse_pragma, UnprocReusePragmas,
- HLDS00, HLDS01),
- { module_info_remove_unproc_reuse_pragmas(HLDS01, HLDS0) },
+ module_info_unproc_reuse_pragmas(!.ModuleInfo, UnprocReusePragmas),
+ list__foldl3(process_unproc_reuse_pragma, UnprocReusePragmas,
+ reuse_condition_table_init, ReuseTable0,
+ !ModuleInfo, !IO),
+ module_info_remove_unproc_reuse_pragmas(!ModuleInfo),
% We do not want to analyse predicates that are introduced by the
% compiler. We will therefore filter out these predicates.
- { module_info_get_special_pred_map(HLDS0, SpecialPredMap) },
- { map__values(SpecialPredMap, SpecialPredIds) },
-
- % Do the direct reuse analysis phase.
- process_matching_nonimported_procs(
- update_module_io(sr_direct__process_proc(AliasTable)),
- (pred(PredId::in, _PredInfo::in) is semidet :-
- \+ list__member(PredId, SpecialPredIds)
- ),
- HLDS0, HLDS1),
+ module_info_get_special_pred_map(!.ModuleInfo, SpecialPredMap),
+ map__values(SpecialPredMap, SpecialPredIds),
+ module_info_predids(!.ModuleInfo, AllPredIds),
+ list__filter(pred(Id::in) is semidet :-
+ \+ list__member(Id, SpecialPredIds), AllPredIds,
+ ToBeAnalysedPredIds),
+
+ direct_reuse_pass(Strategy, AliasTable, ToBeAnalysedPredIds,
+ ReuseTable0, ReuseTable1, !ModuleInfo, !IO),
% Do the fixpoint computation to determine all the indirect
% reuse, and the implied conditions.
- sr_indirect__compute_fixpoint(AliasTable, HLDS1, HLDS2),
- sr_split__create_multiple_versions(HLDS2, HLDS),
- sr_profile_run__structure_reuse_profiling(HLDS).
+ maybe_write_string(VeryVerbose,
+ "% START indirect reuse analysis.\n", !IO),
+ sr_indirect__compute_fixpoint(AliasTable, ReuseTable1, ReuseTable2,
+ !ModuleInfo, !IO),
+ maybe_write_string(VeryVerbose,
+ "% END indirect reuse analysis.\n", !IO),
+ sr_split__create_multiple_versions(ReuseTable2, ReuseTable3,
+ !ModuleInfo, !IO),
+ map__foldl(record_reuse_information_in_hlds, ReuseTable3,
+ !ModuleInfo),
+ sr_profile_run__structure_reuse_profiling(!.ModuleInfo,
+ ReuseTable3, !IO).
+
+%-----------------------------------------------------------------------------%
+:- pred record_reuse_information_in_hlds(pred_proc_id::in,
+ maybe(list(reuse_condition))::in,
+ module_info::in, module_info::out) is det.
+
+record_reuse_information_in_hlds(PredProcId, Memo, !ModuleInfo) :-
+ module_info_pred_proc_info(!.ModuleInfo, PredProcId,
+ PredInfo0, ProcInfo0),
+ proc_info_set_reuse_information(ProcInfo0, Memo, ProcInfo),
+ module_info_set_pred_proc_info(!.ModuleInfo, PredProcId,
+ PredInfo0, ProcInfo, !:ModuleInfo).
+%-----------------------------------------------------------------------------%
+
+ % Perform the direct reuse pass on the listed predicates, using the
+ % alias_table for retreiving the relevant aliasing information. This
+ % pass annotates the procedures with reuse conditions related to the
+ % direct reuses that were detected. It also annotates the procedure
+ % goals with all these detected reuses. The result is immediately taken
+ % into account in a new HLDS.
+
+:- pred direct_reuse_pass(strategy::in, alias_as_table::in, list(pred_id)::in,
+ reuse_condition_table::in, reuse_condition_table::out,
+ module_info::in, module_info::out,
+ io__state::di, io__state::uo) is det.
+direct_reuse_pass(Strategy, AliasTable, PredIds, !RT, !ModuleInfo, !IO) :-
+ list__foldl3(direct_reuse_process_pred(Strategy, AliasTable), PredIds,
+ !RT, !ModuleInfo, !IO).
+
+:- pred direct_reuse_process_pred(strategy::in, alias_as_table::in,
+ pred_id::in,
+ reuse_condition_table::in, reuse_condition_table::out,
+ module_info::in, module_info::out,
+ io__state::di, io__state::uo) is det.
+direct_reuse_process_pred(Strategy, AliasTable, PredId, !RT,
+ !ModuleInfo, !IO) :-
+ module_info_pred_info(!.ModuleInfo, PredId, PredInfo0),
+ pred_info_non_imported_procids(PredInfo0, ProcIds),
+ list__foldl3(direct_reuse_process_proc(Strategy, AliasTable,
+ PredId), ProcIds, !RT, !ModuleInfo, !IO).
+
+:- pred direct_reuse_process_proc(strategy::in, alias_as_table::in,
+ pred_id::in, proc_id::in,
+ reuse_condition_table::in, reuse_condition_table::out,
+ module_info::in, module_info::out,
+ io__state::di, io__state::uo) is det.
+direct_reuse_process_proc(Strategy, AliasTable, PredId, ProcId, !RT,
+ !ModuleInfo, !IO) :-
+ module_info_preds(!.ModuleInfo, Preds0),
+ map__lookup(Preds0, PredId, Pred0),
+ pred_info_procedures(Pred0, Procs0),
+ map__lookup(Procs0, ProcId, Proc0),
+
+ sr_direct__process_proc(Strategy, AliasTable, PredId, ProcId,
+ Proc0, Proc1, MaybeReuseConditions, !.ModuleInfo, _, !IO),
+ proc_info_set_reuse_information(Proc1, MaybeReuseConditions, Proc),
+ reuse_condition_table_set(proc(PredId, ProcId),
+ MaybeReuseConditions, !RT),
+
+ map__det_update(Procs0, ProcId, Proc, Procs),
+ pred_info_set_procedures(Pred0, Procs, Pred),
+ map__det_update(Preds0, PredId, Pred, Preds),
+ module_info_set_preds(!.ModuleInfo, Preds, !:ModuleInfo).
%-----------------------------------------------------------------------------%
-:- pred process_unproc_reuse_pragma(unproc_reuse_pragma, module_info,
- module_info, io__state, io__state).
-:- mode process_unproc_reuse_pragma(in, in, out, di, uo) is det.
-
-process_unproc_reuse_pragma(UnprocReusePragma, Module0, Module) -->
- { UnprocReusePragma = unproc_reuse_pragma(PredOrFunc, SymName,
- Modes, HeadVars, Types, Reuse, _MaybeReuseName) },
-
- globals__io_lookup_bool_option(very_verbose, VeryVerbose),
-
- { module_info_get_predicate_table(Module0, Preds) },
- { module_info_preds(Module0, PredTable0) },
- { list__length(Modes, Arity) },
+:- pred process_unproc_reuse_pragma(unproc_reuse_pragma::in,
+ reuse_condition_table::in, reuse_condition_table::out,
+ module_info::in, module_info::out,
+ io__state::di, io__state::uo) is det.
+
+process_unproc_reuse_pragma(UnprocReusePragma, !ReuseTable,
+ !ModuleInfo, !IO) :-
+ UnprocReusePragma = unproc_reuse_pragma(PredOrFunc, SymName,
+ Modes, HeadVars, Types, Reuse, _MaybeReuseName),
+
+ globals__io_lookup_bool_option(very_verbose, VeryVerbose, !IO),
+
+ module_info_get_predicate_table(!.ModuleInfo, Preds),
+ module_info_preds(!.ModuleInfo, PredTable0),
+ list__length(Modes, Arity),
(
- { predicate_table_search_pf_sym_arity_declmodes(
- Module0, Preds, PredOrFunc, SymName,
- Arity, Modes, PredId, ProcId) }
+ predicate_table_search_pf_sym_arity_declmodes(
+ !.ModuleInfo, Preds, PredOrFunc, SymName,
+ Arity, Modes, PredId, ProcId)
->
- { map__lookup(PredTable0, PredId, PredInfo0) },
- { pred_info_procedures(PredInfo0, ProcTable0) },
- { map__lookup(ProcTable0, ProcId, ProcInfo0) },
+ map__lookup(PredTable0, PredId, PredInfo0),
+ pred_info_procedures(PredInfo0, ProcTable0),
+ map__lookup(ProcTable0, ProcId, ProcInfo0),
write_proc_progress_message("(Reuse) Looking into ",
- PredId, ProcId, Module0),
+ PredId, ProcId, !.ModuleInfo, !IO),
- % rename the headvars:
- maybe_write_string(VeryVerbose, "Renaming HeadVars/Types..."),
- { proc_info_headvars(ProcInfo0, ProcHeadVars) },
- { list__map(term__coerce_var, HeadVars, CHVars) },
- { map__from_corresponding_lists(CHVars, ProcHeadVars,
- MapHeadVars) },
- { pred_info_arg_types(PredInfo0, ArgTypes) },
- { sr_data__memo_reuse_rename(MapHeadVars,
- yes(to_type_renaming(Types, ArgTypes)),
- Reuse, Reuse2) },
- maybe_write_string(VeryVerbose, "done.\n"),
-
- % create the reuse-version of the procedure
- { sr_split__create_reuse_pred(proc(PredId, ProcId),
- Reuse2, no, Module0, Module) }
+ (
+ Reuse = yes(_)
+ ->
+ % rename the headvars:
+ maybe_write_string(VeryVerbose,
+ "Renaming HeadVars/Types...", !IO),
+ proc_info_headvars(ProcInfo0, ProcHeadVars),
+ list__map(term__coerce_var, HeadVars, CHVars),
+ map__from_corresponding_lists(CHVars, ProcHeadVars,
+ MapHeadVars),
+ pred_info_arg_types(PredInfo0, ArgTypes),
+ sr_data__memo_reuse_rename(MapHeadVars,
+ yes(to_type_renaming(Types, ArgTypes)),
+ Reuse, Reuse2),
+ maybe_write_string(VeryVerbose, "done.\n", !IO),
+
+ % create the reuse-version of the procedure
+ sr_split__create_reuse_pred(proc(PredId, ProcId),
+ Reuse2, no, proc(RPredId, RProcId),
+ !ReuseTable, !ModuleInfo),
+ write_proc_progress_message("Created reuse-version ",
+ RPredId, RProcId, !.ModuleInfo, !IO)
+ ;
+ reuse_condition_table_set(proc(PredId, ProcId),
+ no, !ReuseTable)
+ )
;
% XXX Currently a lot of pragma's with no corresponding
@@ -189,7 +280,7 @@
% { varset__init(EmptyVarset) },
% io__write_list(Modes, ", ", write_mode(EmptyVarset)),
% io__write_string(" (reuse_info).\n"),
- { Module = Module0 }
+ true
).
% :- import_module mercury_to_mercury.
@@ -200,7 +291,6 @@
% io__write_string(mercury_mode_to_string(Mode, CVarset)).
%-----------------------------------------------------------------------------%
-
write_pragma_reuse_info( HLDS, SpecPredIds, PredId ) -->
{ module_info_pred_info( HLDS, PredId, PredInfo ) },
--
nancy.mazur at cs.kuleuven.ac.be ------------ Katholieke Universiteit Leuven -
tel: +32-16-327596 - fax: +32-16-327996 ------- Dept. of Computer Science -
--------------------------------------------------------------------------
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