[m-rev.] [reuse] diff: use a separate alias-table during analysis
Nancy Mazur
Nancy.Mazur at cs.kuleuven.ac.be
Thu Jun 24 16:10:59 AEST 2004
Hi,
next step: use the "public" aliases type in the HLDS.
===================================================================
Estimated hours taken: 8
Branches: reuse
Instead of recording all the aliases in the HLDS, use a separate alias-table
instead. This table is then also used for structure reuse analysis.
pa_alias_as.m:
pa_prelim_run.m:
pa_run.m:
Change the alias-analysis such that a local alias-table is constructed
and used, instead of recording each and every alias-result in the HLDS.
mercury_compile.m:
Pass the alias-table constructed during the alias analysis on to the
structure reuse analysis. As this would have normally required the
exposure of the "alias_as_table" (module pa_alias_as) type, I moved the
relevant procedures to "pa_run" and "sr_top" resp.
sr_dead.m:
sr_direct.m:
sr_indirect.m:
sr_top.m:
Use the available separate alias-table during reuse analysis, instead
of relying on the annotated HLDS.
Index: mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.175.2.29
diff -u -r1.175.2.29 mercury_compile.m
--- mercury_compile.m 2 Jun 2004 10:30:45 -0000 1.175.2.29
+++ mercury_compile.m 24 Jun 2004 05:58:38 -0000
@@ -1947,13 +1947,13 @@
mercury_compile__maybe_dump_hlds(HLDS47a, "47a", "mark_static"),
% possible aliases
- mercury_compile__possible_aliases(HLDS47a, Verbose,
- Stats, HLDS48),
+ pa_run__possible_aliases(HLDS47a, Verbose,
+ Stats, HLDS48, MaybeAliasTable),
mercury_compile__maybe_dump_hlds(HLDS48,"48",
"possible_aliases"),
% structure reuse analysis
- mercury_compile__structure_reuse(HLDS48, Verbose,
+ sr_top__structure_reuse(HLDS48, MaybeAliasTable, Verbose,
Stats, HLDS48a),
mercury_compile__maybe_dump_hlds(HLDS48a,"48a",
"structure_reuse") ,
@@ -2527,45 +2527,8 @@
%-----------------------------------------------------------------------------%
-:- pred mercury_compile__possible_aliases(module_info, bool, bool,
- module_info, io__state,
- io__state).
-:- mode mercury_compile__possible_aliases(in, in, in, out, di, uo) is det.
-
-mercury_compile__possible_aliases(HLDS0, Verbose, Stats, HLDS) -->
- globals__io_lookup_bool_option(infer_possible_aliases, InferAliases),
- (
- { InferAliases = yes }
- ->
- maybe_write_string(Verbose, "% Possible alias analysis...\n"),
- maybe_flush_output(Verbose),
- pa_run__aliases_pass(HLDS0, HLDS),
- maybe_write_string(Verbose, "% done.\n"),
- maybe_report_stats(Stats)
- ;
- { HLDS = HLDS0 }
- ).
-
%-----------------------------------------------------------------------------%
-:- pred mercury_compile__structure_reuse(module_info, bool, bool,
- module_info, io__state,
- io__state).
-:- mode mercury_compile__structure_reuse(in, in, in, out, di, uo) is det.
-
-mercury_compile__structure_reuse(HLDS0, Verbose, Stats, HLDS) -->
- globals__io_lookup_bool_option(infer_structure_reuse, StrucReuse),
- (
- { StrucReuse = yes }
- ->
- maybe_write_string(Verbose, "% Structure-reuse analysis...\n"),
- maybe_flush_output(Verbose),
- structure_reuse(HLDS0, HLDS),
- maybe_write_string(Verbose, "% done.\n"),
- maybe_report_stats(Stats)
- ;
- { HLDS = HLDS0 }
- ).
%-----------------------------------------------------------------------------%
Index: pa_alias_as.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_alias_as.m,v
retrieving revision 1.1.2.35
diff -u -r1.1.2.35 pa_alias_as.m
--- pa_alias_as.m 24 Jun 2004 03:02:29 -0000 1.1.2.35
+++ pa_alias_as.m 24 Jun 2004 05:58:40 -0000
@@ -28,9 +28,20 @@
%-----------------------------------------------------------------------------%
+:- type alias_as_table == map(pred_proc_id, alias_as).
+:- func alias_as_table_init = alias_as_table.
+:- func alias_as_table_init(list(pred_proc_id)) = alias_as_table.
+:- func alias_as_table_search_alias(pred_proc_id, alias_as_table)
+ = alias_as is semidet.
+:- pred alias_as_table_set_alias(pred_proc_id::in, alias_as::in,
+ alias_as_table::in, alias_as_table::out) is det.
+
+%-----------------------------------------------------------------------------%
+
:- type alias_as.
:- pred init(alias_as::out) is det.
+:- func init = alias_as.
:- pred is_bottom(alias_as::in) is semidet.
:- pred top(string::in, alias_as::out) is det.
@@ -203,6 +214,8 @@
% alias_sets... hmmm, needs some more thinking.
:- pred normalize(module_info::in, proc_info::in, instmap::in,
alias_as::in, alias_as::out) is det.
+:- pred normalize(module_info::in, proc_info::in,
+ alias_as::in, alias_as::out) is det.
%-----------------------------------------------------------------------------%
% Printing routines.
@@ -318,9 +331,24 @@
:- import_module require, term, assoc_list.
:- import_module std_util.
+
%-----------------------------------------------------------------------------%
-%-- type definitions
+alias_as_table_init = map__init.
+alias_as_table_init(Ids) = list__foldl(
+ func(Id, T0) = T :-
+ (
+ alias_as_table_set_alias(Id, pa_alias_as__init,
+ T0, T)
+ ),
+ Ids,
+ alias_as_table_init).
+alias_as_table_search_alias(PredProcId, Table) = Alias :-
+ Table^elem(PredProcId) = Alias.
+alias_as_table_set_alias(PredProcId, Alias, Table0, Table) :-
+ Table = Table0^elem(PredProcId) := Alias.
+
+%-----------------------------------------------------------------------------%
:- type alias_as --->
real_as(alias_set)
; bottom
@@ -340,6 +368,7 @@
% init
init(bottom).
+init = B :- init(B).
% is_bottom
is_bottom(bottom).
@@ -883,6 +912,10 @@
instmap__apply_instmap_delta(InitIM, InstMapDelta, InstMap),
normalize(HLDS, ProcInfo, InstMap, Alias0, Alias).
+
+normalize(HLDS, ProcInfo, Alias0, Alias):-
+ % normalize only using type-info's
+ normalize_wti(HLDS, ProcInfo, Alias0, Alias).
normalize(HLDS, ProcInfo, _InstMap, Alias0, Alias):-
% normalize only using type-info's
Index: pa_prelim_run.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_prelim_run.m,v
retrieving revision 1.1.2.10
diff -u -r1.1.2.10 pa_prelim_run.m
--- pa_prelim_run.m 8 Jun 2004 05:13:53 -0000 1.1.2.10
+++ pa_prelim_run.m 24 Jun 2004 05:58:41 -0000
@@ -23,6 +23,7 @@
:- interface.
:- import_module hlds__hlds_module.
+:- import_module possible_alias__pa_alias_as.
:- import_module io.
@@ -35,7 +36,8 @@
% these procedures.
% XXX the type unproc_alias_pragma should not be in terms of alias_as
% but in terms of the to be defined public form of alias information.
-:- pred process_imported_predicates(module_info::in, module_info::out,
+:- pred process_imported_predicates(module_info::in,
+ module_info::out, alias_as_table::out,
io__state::di, io__state::uo) is det.
% The pre-births and post-deaths as derived by the liveness pass
@@ -85,30 +87,31 @@
:- import_module list, map, set, std_util.
:- import_module term, varset.
-process_imported_predicates(HLDS0, HLDS) -->
- { module_info_unproc_alias_pragmas(HLDS0, UnprocAliasPragmas) },
+process_imported_predicates(ModuleInfo0, ModuleInfo, AliasTable) -->
+ { module_info_unproc_alias_pragmas(ModuleInfo0, UnprocAliasPragmas) },
+ { module_info_remove_unproc_alias_pragmas(ModuleInfo0, ModuleInfo) },
list__foldl2(
- process_unproc_alias_pragma,
- UnprocAliasPragmas, HLDS0, HLDS1),
- { module_info_remove_unproc_alias_pragmas(HLDS1, HLDS) }.
+ process_unproc_alias_pragma(ModuleInfo),
+ UnprocAliasPragmas, alias_as_table_init , AliasTable).
-:- pred process_unproc_alias_pragma(unproc_alias_pragma, module_info,
- module_info, io__state, io__state).
-:- mode process_unproc_alias_pragma(in, in, out, di, uo) is det.
+:- pred process_unproc_alias_pragma(module_info::in, unproc_alias_pragma::in,
+ alias_as_table::in, alias_as_table::out,
+ io__state::di, io__state::uo) is det.
-process_unproc_alias_pragma(UnprocAliasPragma, Module0, Module) -->
+process_unproc_alias_pragma(ModuleInfo, UnprocAliasPragma, AliasTable0,
+ AliasTable) -->
{ UnprocAliasPragma = unproc_alias_pragma(PredOrFunc, SymName,
Modes, HeadVars, Types, Alias0) },
globals__io_lookup_bool_option(very_verbose, VeryVerbose),
- { module_info_get_predicate_table(Module0, Preds) },
- { module_info_preds(Module0, PredTable0) },
+ { 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,
+ ModuleInfo, Preds, PredOrFunc, SymName,
Arity, Modes, PredId, ProcId) }
->
{ map__lookup(PredTable0, PredId, PredInfo0) },
@@ -116,7 +119,7 @@
{ map__lookup(ProcTable0, ProcId, ProcInfo0) },
write_proc_progress_message("(Alias) Looking into ",
- PredId, ProcId, Module0),
+ PredId, ProcId, ModuleInfo),
% rename the headvars:
maybe_write_string(VeryVerbose, "Renaming HeadVars..."),
@@ -134,16 +137,9 @@
Alias1, Alias) },
maybe_write_string(VeryVerbose, "done.\n"),
- % set the proc_info right
- { proc_info_set_possible_aliases(ProcInfo0,
- Alias, ProcInfo) },
- { map__det_update(ProcTable0, ProcId, ProcInfo,
- ProcTable) },
- { pred_info_set_procedures(PredInfo0, ProcTable,
- PredInfo) },
- { map__det_update(PredTable0, PredId, PredInfo,
- PredTable) },
- { module_info_set_preds(Module0, PredTable, Module) }
+ % Record the alias in the aliastable.
+ { alias_as_table_set_alias(proc(PredId, ProcId), Alias,
+ AliasTable0, AliasTable) }
;
% XXX Currently a lot of pragma's with no corresponding
% procedure in the predicate table are read. Yet a priori
@@ -156,7 +152,7 @@
% { varset__init(EmptyVarset) },
% io__write_list(Modes, ", ", write_mode(EmptyVarset)),
% io__write_string(" (alias_info).\n"),
- { Module = Module0 }
+ { AliasTable = AliasTable0 }
).
% :- import_module mercury_to_mercury.
Index: pa_run.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/pa_run.m,v
retrieving revision 1.1.2.31
diff -u -r1.1.2.31 pa_run.m
--- pa_run.m 24 Jun 2004 03:02:30 -0000 1.1.2.31
+++ pa_run.m 24 Jun 2004 05:58:42 -0000
@@ -21,12 +21,14 @@
:- import_module parse_tree__prog_data.
:- import_module possible_alias__pa_alias_as.
-:- import_module io, list.
+:- import_module io, list, bool, std_util.
- % the main pass
-:- pred pa_run__aliases_pass(module_info::in, module_info::out,
+:- pred possible_aliases(module_info::in, bool::in, bool::in, module_info::out,
+ maybe(alias_as_table)::out,
io__state::di, io__state::uo) is det.
+ % the main pass
+
% Write the pa_info pragma for the given pred_id (if that
% pred_id does not belong to the list(pred_id).
%
@@ -63,7 +65,8 @@
% preferrable to keep the optimised representation as well for its
% use during the structure reuse pass. This is a bit of a dilemma.
:- pred pa_run__extend_with_call_alias(module_info::in, proc_info::in,
- pred_id::in, proc_id::in, list(prog_var)::in,
+ alias_as_table::in, pred_id::in, proc_id::in,
+ list(prog_var)::in,
list((type))::in, alias_as::in, alias_as::out) is det.
%-----------------------------------------------------------------------------%
@@ -100,209 +103,216 @@
%-----------------------------------------------------------------------------%
-pa_run__aliases_pass(HLDSin, HLDSout) -->
+possible_aliases(ModuleInfo0, Verbose, Stats, ModuleInfo, MaybeAliasTable) -->
+ globals__io_lookup_bool_option(infer_possible_aliases, InferAliases),
+ (
+ { InferAliases = yes }
+ ->
+ maybe_write_string(Verbose, "% Possible alias analysis...\n"),
+ maybe_flush_output(Verbose),
+ pa_run__aliases_pass(ModuleInfo0, ModuleInfo, AliasTable),
+ maybe_write_string(Verbose, "% done.\n"),
+ maybe_report_stats(Stats),
+ { MaybeAliasTable = yes(AliasTable) }
+ ;
+ { ModuleInfo = ModuleInfo0 },
+ { MaybeAliasTable = no }
+ ).
+
+:- pred pa_run__aliases_pass(module_info::in, module_info::out,
+ alias_as_table::out,
+ io__state::di, io__state::uo) is det.
+pa_run__aliases_pass(ModuleInfo0, ModuleInfo, AliasTable) -->
% preliminary steps:
% 0. process all the alias-information for all the imported
% predicates.
- pa_prelim_run__process_imported_predicates(HLDSin, HLDS0),
+ pa_prelim_run__process_imported_predicates(ModuleInfo0, ModuleInfo1,
+ AliasTable0),
% 1. annotate all the liveness
- pa_prelim_run__annotate_all_liveness_in_module(HLDS0, HLDS1),
+ pa_prelim_run__annotate_all_liveness_in_module(ModuleInfo1,
+ ModuleInfo2),
% 2. annotate all the outscope vars
- { pa_prelim_run__annotate_all_outscope_vars_in_module(HLDS1,HLDS2) },
+ { pa_prelim_run__annotate_all_outscope_vars_in_module(ModuleInfo2,
+ ModuleInfo3) },
+
+ % 3. do the actual aliases pass
+ aliases_pass_2(ModuleInfo3, AliasTable0, AliasTable),
- % 3. and finally do the actual aliases pass
- aliases_pass_2(HLDS2, HLDSout).
+ % 4. record the alias results in the HLDS.
+ { map__foldl(record_alias_in_hlds, AliasTable,
+ ModuleInfo3, ModuleInfo) }.
+
+:- pred record_alias_in_hlds(pred_proc_id::in, alias_as::in,
+ module_info::in, module_info::out) is det.
+record_alias_in_hlds(PredProcId, AliasAs, ModuleInfo0, ModuleInfo) :-
+ module_info_pred_proc_info(ModuleInfo0, PredProcId,
+ PredInfo0, ProcInfo0),
+ proc_info_set_possible_aliases(ProcInfo0, AliasAs, ProcInfo),
+ module_info_set_pred_proc_info(ModuleInfo0, PredProcId,
+ PredInfo0, ProcInfo, ModuleInfo).
-:- pred aliases_pass_2(module_info, module_info, io__state, io__state).
-:- mode aliases_pass_2(in, out, di, uo) is det.
-pa_run__aliases_pass_2(HLDSin, HLDSout) -->
+:- pred aliases_pass_2(module_info::in, alias_as_table::in,
+ alias_as_table::out, io__state::di, io__state::uo) is det.
+
+pa_run__aliases_pass_2(HLDS, !AliasTable, !IO) :-
% strongly connected components needed
- { module_info_ensure_dependency_info(HLDSin, HLDS1) },
- { module_info_get_maybe_dependency_info(HLDS1, MaybeDepInfo) } ,
+ module_info_ensure_dependency_info(HLDS, HLDS1),
+ module_info_get_maybe_dependency_info(HLDS1, 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(DepOrdering, HLDS1, HLDSout) %,
- % write out the results of the exported procedures into
- % a separate interface-file.
- % pa_run__make_pa_interface(HLDSout)
+ run_with_dependencies(DepOrdering, HLDS1, !AliasTable, !IO)
;
- { error("(pa) pa_run module: no dependency info") }
+ error("(pa) pa_run module: no dependency info")
).
-:- pred run_with_dependencies(dependency_ordering, module_info,
- module_info, io__state, io__state).
-:- mode run_with_dependencies(in, in, out, di, uo) is det.
-
-run_with_dependencies(Deps, HLDSin, HLDSout) -->
- list__foldl2(run_with_dependency, Deps, HLDSin, HLDSout).
-
-:- pred run_with_dependency(list(pred_proc_id), module_info, module_info,
- io__state, io__state).
-:- mode run_with_dependency(in, in, out, di, uo) is det.
+:- pred run_with_dependencies(dependency_ordering::in, module_info::in,
+ alias_as_table::in, alias_as_table::out,
+ io__state::di, io__state::uo) is det.
+
+run_with_dependencies(Deps, HLDS, !AliasTable, !IO) :-
+ list__foldl2(run_with_dependency(HLDS), Deps, !AliasTable, !IO).
+
+:- pred run_with_dependency(module_info::in, list(pred_proc_id)::in,
+ alias_as_table::in, alias_as_table::out,
+ io__state::di, io__state::uo) is det.
-run_with_dependency(SCC , HLDSin, HLDSout) -->
+run_with_dependency(HLDS, SCC, !AliasTable, !IO) :-
(
% analysis ignores special predicates
- { pa_sr_util__some_are_special_preds(SCC, HLDSin) }
+ pa_sr_util__some_are_special_preds(SCC, HLDS)
->
- { HLDSout = HLDSin }
+ true
;
% for each list of strongly connected components,
% perform a fixpoint computation.
- { pa_util__pa_fixpoint_table_init(SCC, FPtable0) } ,
+ pa_util__pa_fixpoint_table_init(SCC, FPtable0),
run_with_dependency_until_fixpoint(SCC, FPtable0,
- HLDSin, HLDSout)
+ HLDS, !AliasTable, !IO)
).
-:- pred run_with_dependency_until_fixpoint(list(pred_proc_id),
- pa_util__pa_fixpoint_table, module_info, module_info,
- io__state, io__state).
-:- mode run_with_dependency_until_fixpoint(in, in, in, out, di, uo) is det.
+:- pred run_with_dependency_until_fixpoint(list(pred_proc_id)::in,
+ pa_fixpoint_table::in, module_info::in,
+ alias_as_table::in, alias_as_table::out,
+ io__state::di, io__state::uo) is det.
-run_with_dependency_until_fixpoint(SCC, FPtable0, HLDSin, HLDSout) -->
- list__foldl2(analyse_pred_proc(HLDSin), SCC, FPtable0, FPtable),
+run_with_dependency_until_fixpoint(SCC, FPtable0, HLDS, !AliasTable, !IO) :-
+ list__foldl2(analyse_pred_proc(HLDS, !.AliasTable),
+ SCC, FPtable0, FPtable, !IO),
(
- { pa_fixpoint_table_all_stable(FPtable) }
+ pa_fixpoint_table_all_stable(FPtable)
->
- { list__foldl(update_alias_in_module_info(FPtable), SCC, HLDSin, HLDSout) }
+ list__foldl(update_alias_in_alias_table(FPtable), SCC,
+ !AliasTable)
;
- { pa_util__pa_fixpoint_table_new_run(FPtable,FPtable1) },
+ pa_util__pa_fixpoint_table_new_run(FPtable,FPtable1),
run_with_dependency_until_fixpoint(SCC, FPtable1,
- HLDSin, HLDSout)
+ HLDS, !AliasTable, !IO)
).
%-----------------------------------------------------------------------------%
% THE KERNEL
%-----------------------------------------------------------------------------%
-:- pred analyse_pred_proc(module_info, pred_proc_id, pa_fixpoint_table,
- pa_fixpoint_table, io__state, io__state).
-:- mode analyse_pred_proc(in, in, in, out, di, uo) is det.
-
-analyse_pred_proc(HLDS, PRED_PROC_ID , FPtable0, FPtable) -->
- globals__io_lookup_bool_option(very_verbose,Verbose),
- globals__io_lookup_int_option(possible_alias_widening, WideningLimit),
-
- { module_info_pred_proc_info(HLDS, PRED_PROC_ID, PredInfo,
- ProcInfo_tmp) },
-
- % XXX annotate all lbu/lfu stuff
- % may 20, 2004: should not be necessary
- % { sr_lfu__process_proc(ProcInfo_tmp, ProcInfo_tmp2) },
- % { sr_lbu__process_proc(HLDS, ProcInfo_tmp2, ProcInfo) },
+:- pred analyse_pred_proc(module_info::in, alias_as_table::in,
+ pred_proc_id::in,
+ pa_fixpoint_table::in, pa_fixpoint_table::out,
+ io__state::di, io__state::uo) is det.
- { ProcInfo = ProcInfo_tmp },
+analyse_pred_proc(HLDS, AliasTable, PredProcId, !FPTable, !IO) :-
+ % Collect the relevant compiler options.
+ globals__io_lookup_bool_option(very_verbose, Verbose, !IO),
+ globals__io_lookup_int_option(possible_alias_widening,
+ WideningLimit, !IO),
- { PRED_PROC_ID = proc(PredId, ProcId) },
+ % Select all the relevant procedure information.
+ module_info_pred_proc_info(HLDS, PredProcId, PredInfo, ProcInfo) ,
+ PredProcId = proc(PredId, ProcId),
+ proc_info_headvars(ProcInfo, HeadVars),
- { pa_util__pa_fixpoint_table_which_run(FPtable0, Run) },
- {
+ pa_util__pa_fixpoint_table_which_run(!.FPTable, Run),
(
- pa_util__pa_fixpoint_table_get_final_as_semidet(PRED_PROC_ID,
- TabledAliasAs, FPtable0)
+ pa_util__pa_fixpoint_table_get_final_as_semidet(PredProcId,
+ TabledAliasAs, !.FPTable)
->
TabledSize = size(TabledAliasAs)
;
TabledSize = 0
- )
- },
- { string__int_to_string(Run, SRun)},
- { string__append_list(["% Alias analysing (run ",SRun,") "],
- Msg) },
- passes_aux__write_proc_progress_message(Msg,
- PredId, ProcId, HLDS),
-
- {
- % begin non-io
- proc_info_goal(ProcInfo, Goal),
- proc_info_headvars(ProcInfo, HeadVars),
-
- pa_alias_as__init(Alias0)
+ ),
+ string__int_to_string(Run, SRun),
+ string__append_list(["% Alias analysing (run ",SRun,") "], Msg),
+ passes_aux__write_proc_progress_message(Msg, PredId, ProcId,
+ HLDS, !IO),
- },
+ pa_alias_as__init(Alias0),
+ % If the aliases can safely be predicted to be "bottom", then
+ % an analysis is not needed.
(
- { predict_bottom_aliases(HLDS, ProcInfo) }
+ predict_bottom_aliases(HLDS, ProcInfo)
->
- maybe_write_string(Verbose, "% bottom predicted"),
- { Alias1 = Alias0 }, % = bottom
- { FPtable1 = FPtable0 }
+ maybe_write_string(Verbose, "\t\t: bottom predicted", !IO),
+ Alias = Alias0 % = bottom
;
- analyse_goal(ProcInfo, PredInfo, HLDS, Goal,
- FPtable0, FPtable1, Alias0, Alias1)
- ),
-
- {
- FullSize = pa_alias_as__size(Alias1),
-
- pa_alias_as__project(HeadVars, Alias1, Alias2),
- ProjectSize = pa_alias_as__size(Alias2),
-
- Goal = _ - GoalInfo,
- goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
- instmap__init_reachable(InitIM),
- instmap__apply_instmap_delta(InitIM, InstMapDelta, InstMap),
- pa_alias_as__normalize(HLDS, ProcInfo, InstMap, Alias2, Alias3),
- NormSize = pa_alias_as__size(Alias3),
-
- pa_alias_as__apply_widening(HLDS, ProcInfo, WideningLimit,
+ % The alias could not be predicted to be bottom, hence, start
+ % the analysis of the procedure goal.
+ proc_info_goal(ProcInfo, Goal),
+ analyse_goal(ProcInfo, PredInfo, HLDS, AliasTable, Goal,
+ !FPTable, Alias0, Alias1, !IO),
+ FullSize = pa_alias_as__size(Alias1),
+ pa_alias_as__project(HeadVars, Alias1, Alias2),
+ ProjectSize = pa_alias_as__size(Alias2),
+
+ pa_alias_as__normalize(HLDS, ProcInfo, Alias2, Alias3),
+ NormSize = pa_alias_as__size(Alias3) ,
+ pa_alias_as__apply_widening(HLDS, ProcInfo, WideningLimit,
Alias3, Alias, Widening),
-
- pa_fixpoint_table_new_as(HLDS, ProcInfo,
- PRED_PROC_ID, Alias, FPtable1, FPtable)
- % end non-io
- },
- (
- { Verbose = yes }
- ->
- % print_maybe_possible_aliases(yes(Alias),ProcInfo),
- % io__write_string("\n")
- % []
- {
- ( pa_fixpoint_table_all_stable(FPtable) ->
- Stable = "s" ; Stable = "u"
- ),
- string__int_to_string(TabledSize, TabledS),
- string__int_to_string(FullSize, FullS),
- string__int_to_string(ProjectSize, ProjectS),
- string__int_to_string(NormSize, NormS)
- },
- io__write_strings(["\t\t: ", TabledS, "->",
- FullS, "/", ProjectS, "/",
- NormS,
- "(", Stable, ")"]),
- (
- { Widening = bool__yes }
- ->
- { string__int_to_string(
- pa_alias_as__size(Alias), WidenS) },
- { string__int_to_string(WideningLimit, WidLimitS) },
- io__write_strings(["/-->widening(", WidLimitS,"): ", WidenS, "\n"])
- ;
- io__write_string("\n")
- )
-/**
- ,
(
- { dummy_test(PRED_PROC_ID) }
+ Verbose = yes
->
- { dummy_test_here(Alias) },
- io__write_string("Alias = "),
- pa_alias_as__print_aliases(Alias, ProcInfo,PredInfo),
- io__write_string("\n\n")
+ string__append_list(["\t\t: ",
+ string__int_to_string(TabledSize), "->",
+ string__int_to_string(FullSize), "/",
+ string__int_to_string(ProjectSize), "/",
+ string__int_to_string(NormSize)], Sizes),
+
+ (
+ Widening = bool__yes
+ ->
+
+ string__append_list(["/-->widening(",
+ string__int_to_string(WideningLimit),
+ "): ",
+ string__int_to_string(size(Alias))],
+ WidMsg)
+ ;
+ WidMsg = ""
+ ),
+ io__write_string(string__append(Sizes, WidMsg), !IO)
;
- []
+ true
)
-**/
+ ),
+ pa_fixpoint_table_new_as(HLDS, ProcInfo,
+ PredProcId, Alias, !FPTable),
+ (
+ Verbose = yes
+ ->
+ ( pa_fixpoint_table_all_stable(!.FPTable) ->
+ Stable = "stable" ; Stable = "unstable"
+ ),
+ string__append_list(["\t\t (ft = ",
+ Stable, ")\n"], FPMsg),
+ io__write_string(FPMsg, !IO)
;
- []
+ true
).
:- pred predict_bottom_aliases(module_info::in, proc_info::in) is semidet.
@@ -314,11 +324,6 @@
list__map( map__lookup(VarTypes), HeadVars, Types),
pa_alias_as__predict_bottom_alias(ModuleInfo, HeadVars, Modes, Types).
-:- pred dummy_test(pred_proc_id::in) is semidet.
-dummy_test(proc(PredId, _)):- pred_id_to_int(PredId, 16).
-:- pred dummy_test_here(alias_as::in) is det.
-dummy_test_here(_).
-
% analyse a given goal, with module_info and fixpoint table
% to lookup extra information, starting from an initial abstract
% substitution, and creating a new one. During this process,
@@ -327,14 +332,17 @@
% analyse_goal(ProcInfo, HLDS, Goal, TableIn, TableOut,
% AliasIn, AliasOut).
:- pred analyse_goal(proc_info::in, pred_info::in, module_info::in,
- hlds_goal::in, pa_fixpoint_table::in, pa_fixpoint_table::out,
+ alias_as_table::in,
+ hlds_goal::in,
+ pa_fixpoint_table::in, pa_fixpoint_table::out,
alias_as::in, alias_as::out,
io__state::di, io__state::uo) is det.
-analyse_goal(ProcInfo, PredInfo, HLDS, Goal, FPtable0, FPtable,
+analyse_goal(ProcInfo, PredInfo, HLDS, AliasTable, Goal, FPtable0, FPtable,
Alias0, Alias, !IO) :-
Goal = GoalExpr - GoalInfo,
analyse_goal_expr(GoalExpr, GoalInfo, ProcInfo, PredInfo, HLDS,
+ AliasTable,
FPtable0, FPtable, Alias0, Alias, !IO).
/***
% extra: after the analysis of the current goal,
@@ -355,21 +363,23 @@
:- pred analyse_goal_expr(hlds_goal_expr::in, hlds_goal_info::in,
proc_info::in, pred_info::in, module_info::in,
+ alias_as_table::in,
pa_fixpoint_table::in, pa_fixpoint_table::out,
alias_as::in, alias_as::out,
io__state::di, io__state::uo) is det.
analyse_goal_expr(conj(Goals), _Info, ProcInfo, PredInfo,
- HLDS , !Table, !Alias, !IO) :-
- list__foldl3(analyse_goal(ProcInfo, PredInfo, HLDS), Goals,
+ HLDS , AliasTable, !Table, !Alias, !IO) :-
+ list__foldl3(analyse_goal(ProcInfo, PredInfo, HLDS, AliasTable),
+ Goals,
!Table, !Alias, !IO).
analyse_goal_expr(call(PredId, ProcId, ARGS, _,_, _PName), _Info,
- ProcInfo, _PredInfo, HLDS, !Table, !Alias, !IO) :-
+ ProcInfo, _PredInfo, HLDS, AliasTable, !Table, !Alias, !IO) :-
% write_proc_progress_message("\n--> Call to ",
% PredId, ProcId, HLDS, !IO),
PredProcId = proc(PredId, ProcId),
- lookup_call_alias(PredProcId, HLDS, !Table, CallAlias),
+ lookup_call_alias(PredProcId, HLDS, AliasTable, !Table, CallAlias),
% module_info_pred_info(HLDS, PredId, PredInfoLookedUp),
% io__write_string("--> Looked up aliases: ", !IO),
% io__write_strings(["(size = ", int_to_string(size(CallAlias)),
@@ -391,7 +401,7 @@
% print_brief_aliases(5, !.Alias, ProcInfo, PredInfo, !IO).
analyse_goal_expr(generic_call(GenCall,_,_,_), Info,
- _ProcInfo, _P, _HLDS , !Table, !Alias, !IO) :-
+ _ProcInfo, _P, _HLDS , _AliasTable, !Table, !Alias, !IO) :-
(
GenCall = higher_order(_, _, _),
Text = "higher_order"
@@ -411,25 +421,28 @@
pa_alias_as__top(Msg, !Alias).
% error("(pa) generic_call not handled") .
-analyse_goal_expr(switch(_Var,_CF,Cases), Info,
- ProcInfo, PredInfo, HLDS, !Table, !Alias, !IO) :-
- list__map_foldl2(analyse_case(ProcInfo, PredInfo, HLDS, !.Alias),
+analyse_goal_expr(switch(_Var,_CF,Cases), Info, ProcInfo, PredInfo, HLDS,
+ AliasTable, !Table, !Alias, !IO) :-
+ list__map_foldl2(analyse_case(ProcInfo, PredInfo, HLDS,
+ AliasTable, !.Alias),
Cases, SwitchAliases, !Table, !IO),
pa_alias_as__least_upper_bound_list(HLDS, ProcInfo, Info,
SwitchAliases, !:Alias).
:- pred analyse_case(proc_info::in, pred_info::in, module_info::in,
+ alias_as_table::in,
alias_as::in, case::in, alias_as::out,
pa_fixpoint_table::in, pa_fixpoint_table::out,
io__state::di, io__state::uo) is det.
-analyse_case(ProcInfo, PredInfo, HLDS, Alias0, Case, Alias, !Table, !IO) :-
+analyse_case(ProcInfo, PredInfo, HLDS, AliasTable,
+ Alias0, Case, Alias, !Table, !IO) :-
Case = case(_, Goal),
- analyse_goal(ProcInfo, PredInfo, HLDS, Goal,
+ analyse_goal(ProcInfo, PredInfo, HLDS, AliasTable, Goal,
!Table, Alias0, Alias, !IO).
analyse_goal_expr(unify(_,_,_,Unification,_), Info, ProcInfo, _PredInfo,
- HLDS, !Table, !Alias, !IO) :-
+ HLDS, _AliasTable, !Table, !Alias, !IO) :-
% io__write_string("\n--> Unification.", !IO),
% io__write_string("\n--> Existing aliases: ", !IO),
% io__write_strings(["(size = ", int_to_string(size(A0)),
@@ -443,13 +456,14 @@
% ") "], !IO),
% print_aliases(A, ProcInfo, PredInfo, !IO).
-analyse_goal_expr(disj(Goals), Info, ProcInfo, PredInfo, HLDS,
+analyse_goal_expr(disj(Goals), Info, ProcInfo, PredInfo, HLDS, AliasTable,
!Table, !Alias, !IO) :-
% io__write_string("\n--> Disjunction", !IO),
list__map_foldl2(
pred(Goal::in, Alias::out, FPT0::in, FPT::out,
IO0::di, IO::uo) is det :-
- (analyse_goal(ProcInfo, PredInfo, HLDS, Goal,
+ (analyse_goal(ProcInfo, PredInfo, HLDS, AliasTable,
+ Goal,
FPT0, FPT, !.Alias, Alias, IO0, IO)),
Goals,
DisjAliases,
@@ -473,38 +487,41 @@
% print_aliases(A, ProcInfo, PredInfo).
analyse_goal_expr(not(Goal), _Info, ProcInfo, PredInfo,
- HLDS, !Table, !Alias, !IO) :-
- analyse_goal(ProcInfo, PredInfo, HLDS, Goal, !Table, !Alias, !IO).
+ HLDS, AliasTable, !Table, !Alias, !IO) :-
+ analyse_goal(ProcInfo, PredInfo, HLDS, AliasTable,
+ Goal, !Table, !Alias, !IO).
analyse_goal_expr(some(Vars,_,Goal), _Info, ProcInfo, PredInfo,
- HLDS, !Table, !Alias, !IO) :-
+ HLDS, AliasTable, !Table, !Alias, !IO) :-
(
Vars = []
->
- % XXX
- analyse_goal(ProcInfo, PredInfo, HLDS, Goal,
+ % XXX
+ analyse_goal(ProcInfo, PredInfo, HLDS, AliasTable, Goal,
!Table, !Alias, !IO)
;
Msg = "(pa_run) analyse_goal_expr: empty vars expected.",
require__error(Msg)
).
- % pa_alias_as__top("some not handled", A).
- % error("(pa) some goal not handled") .
analyse_goal_expr(if_then_else(_VARS, IF, THEN, ELSE), _Info,
- ProcInfo, PredInfo, HLDS, !Table, A0, A, !IO) :-
- analyse_goal(ProcInfo, PredInfo, HLDS, IF, !Table, A0, A1, !IO),
- analyse_goal(ProcInfo, PredInfo, HLDS, THEN, !Table, A1, A2, !IO),
- analyse_goal(ProcInfo, PredInfo, HLDS, ELSE, !Table, A0, A3, !IO),
+ ProcInfo, PredInfo, HLDS, AliasTable, !Table, A0, A, !IO) :-
+ analyse_goal(ProcInfo, PredInfo, HLDS, AliasTable,
+ IF, !Table, A0, A1, !IO),
+ analyse_goal(ProcInfo, PredInfo, HLDS, AliasTable,
+ THEN, !Table, A1, A2, !IO),
+ analyse_goal(ProcInfo, PredInfo, HLDS, AliasTable,
+ ELSE, !Table, A0, A3, !IO),
pa_alias_as__least_upper_bound(HLDS, ProcInfo, A2, A3, A).
analyse_goal_expr(foreign_proc(Attrs, PredId, ProcId,
Vars, MaybeModes, Types, _),
- Info, ProcInfo, _PredInfo, HLDS, !Table, !Alias, !IO) :-
+ Info, ProcInfo, _PredInfo, HLDS, _AT, !Table, !Alias, !IO) :-
extend_foreign_code(HLDS, ProcInfo, Attrs, PredId, ProcId,
Vars, MaybeModes, Types, Info, !Alias).
-analyse_goal_expr(par_conj(_Goals), Info, _, _ , _, !Table, !Alias, !IO) :-
+analyse_goal_expr(par_conj(_Goals), Info, _, _ , _, _AT,
+ !Table, !Alias, !IO) :-
goal_info_get_context(Info, Context),
term__context_line(Context, ContextLine),
term__context_file(Context, ContextFile),
@@ -514,7 +531,7 @@
ContextLineS, ")"], Msg),
pa_alias_as__top(Msg, !Alias).
-analyse_goal_expr(shorthand(_), _, _, _, _, !T, !A, !IO) :-
+analyse_goal_expr(shorthand(_), _, _, _, _, _AT, !T, !A, !IO) :-
error("pa_run__analyse_goal_expr: shorthand goal").
%-----------------------------------------------------------------------------%
@@ -522,7 +539,7 @@
% lookup the alias of the procedure with given pred_proc_id and
% find it's output abstract substitution.
% 1 - look first in table, if this fails (then not in same SCC)
- % 2 - look in module_info (as we might already have analysed the
+ % 2 - look in alias_as_table (as we might already have analysed the
% predicate, if defined in same module, or analysed in other
% imported module)
% 3 - check whether the args have primitive types -- then no aliases
@@ -530,65 +547,68 @@
% 4 - react appropriately if the calls happen to be to
% * either compiler generated predicates
% * or predicates from builtin.m and private_builtin.m
-:- pred lookup_call_alias(pred_proc_id, module_info, pa_fixpoint_table,
- pa_fixpoint_table, alias_as).
-:- mode lookup_call_alias(in, in, in, out, out) is det.
+:- pred lookup_call_alias(pred_proc_id::in, module_info::in,
+ alias_as_table::in, pa_fixpoint_table::in,
+ pa_fixpoint_table::out, alias_as::out) is det.
-lookup_call_alias(PRED_PROC_ID, HLDS, FPtable0, FPtable, Alias) :-
+lookup_call_alias(PredProcId, HLDS, AliasTable, FPtable0, FPtable, Alias) :-
(
% 1 - check in table
- pa_fixpoint_table_get_as(PRED_PROC_ID, Alias1,
+ pa_fixpoint_table_get_as(PredProcId, Alias1,
FPtable0, FPtable1)
->
FPtable = FPtable1,
Alias = Alias1
;
- % 2 - look up in module_info
- lookup_call_alias_in_module_info(HLDS, PRED_PROC_ID,
- Alias),
+ % 2 - look up amongst the already recorded aliases.
+ lookup_already_recorded_alias(PredProcId, HLDS, AliasTable,
+ Alias),
FPtable = FPtable0
).
+:- pred lookup_already_recorded_alias(pred_proc_id::in, module_info::in,
+ alias_as_table::in, alias_as::out) is det.
+lookup_already_recorded_alias(PredProcId, ModuleInfo, AliasTable, Alias) :-
+ (
+ % 1 - look up in AliasTable
+ Alias1 = alias_as_table_search_alias(PredProcId, AliasTable)
+ ->
+ Alias = Alias1
+ ;
+ % 2 - perhaps predict the alias
+ predict_bottom_alias(ModuleInfo, PredProcId)
+ ->
+ Alias = pa_alias_as__init
+ ;
+ % 3. else return "top" with an error message.
+ error_not_found_alias(ModuleInfo, PredProcId, Alias)
+ ).
+
% exported predicate
-extend_with_call_alias(HLDS, ProcInfo,
+extend_with_call_alias(HLDS, ProcInfo, AliasTable,
PRED_ID, PROC_ID, ARGS, ActualTypes, ALIASin, ALIASout):-
- PRED_PROC_ID = proc(PRED_ID, PROC_ID),
- lookup_call_alias_in_module_info(HLDS, PRED_PROC_ID, ALIAS_tmp),
- rename_call_alias(PRED_PROC_ID, HLDS, ARGS, ActualTypes,
+ PredProcId = proc(PRED_ID, PROC_ID),
+ lookup_already_recorded_alias(PredProcId, HLDS, AliasTable, ALIAS_tmp),
+ rename_call_alias(PredProcId, HLDS, ARGS, ActualTypes,
ALIAS_tmp, ALIAS_call),
pa_alias_as__extend(HLDS, ProcInfo, ALIAS_call, ALIASin, ALIASout).
-:- pred lookup_call_alias_in_module_info(module_info, pred_proc_id,
- alias_as).
-:- mode lookup_call_alias_in_module_info(in, in, out) is det.
+:- pred predict_bottom_alias(module_info::in, pred_proc_id::in) is semidet.
-lookup_call_alias_in_module_info(HLDS, PRED_PROC_ID, Alias) :-
- module_info_pred_proc_info(HLDS, PRED_PROC_ID, PredInfo,
+predict_bottom_alias(HLDS, PredProcId) :-
+ module_info_pred_proc_info(HLDS, PredProcId, PredInfo,
ProcInfo),
(
- % If the determinism of the called procedure is
- % erroneous or failure, then you don't even need to
- % check anything else anymore: it simply cannot
- % introduce any aliases.
proc_info_inferred_determinism(ProcInfo, Determinism),
(
Determinism = erroneous
;
Determinism = failure
)
- ->
- init(Alias)
- ;
- proc_info_possible_aliases(ProcInfo, MaybeAliases),
- MaybeAliases = yes(SomeAL)
- ->
- Alias = SomeAL
;
% Special tricks:
% 1. check whether the args are primitive types
arg_types_are_all_primitive(HLDS, PredInfo)
- ->
- init(Alias)
;
% 2. call to builtin.m or private_builtin.m
% predicate -- unify/index/compare
@@ -605,9 +625,6 @@
;
special_pred_name_arity(_, _, Name, Arity)
)
- ->
- % no aliases created
- init(Alias)
;
% 3. XXX Any call to private_builtin.m module and
% builtin module are considered alias-free.
@@ -620,50 +637,40 @@
;
mercury_public_builtin_module(ModuleName)
)
- ->
- % no aliases created
- init(Alias)
- ;
- % if all else fails --> ERROR !!
-
- PRED_PROC_ID = proc(PRED_ID, PROC_ID),
- pred_info_name(PredInfo, PNAME),
- pred_info_module(PredInfo, PMODULE),
- prog_out__sym_name_to_string(PMODULE, SPMODULE),
- pred_info_import_status(PredInfo, Status),
- import_status_to_minimal_string(Status, SStatus),
- pred_id_to_int(PRED_ID, IPRED_ID),
- proc_id_to_int(PROC_ID, IPROC_ID),
- string__int_to_string(IPRED_ID, SPRED_ID),
- string__int_to_string(IPROC_ID, SPROC_ID),
- string__append_list(["lookup alias failed for ",
- SPMODULE, "::",
- PNAME,"(",SPRED_ID, ",", SPROC_ID, ",",
- SStatus, ")"],
- ErrMsg),
- top(ErrMsg, Alias)
).
+:- pred error_not_found_alias(module_info::in,
+ pred_proc_id::in, alias_as::out) is det.
+error_not_found_alias(ModuleInfo, PredProcId, Alias) :-
+ module_info_pred_proc_info(ModuleInfo, PredProcId, PredInfo, _),
+ PredProcId = proc(PRED_ID, PROC_ID),
+ pred_info_name(PredInfo, PNAME),
+ pred_info_module(PredInfo, PMODULE),
+ prog_out__sym_name_to_string(PMODULE, SPMODULE),
+ pred_info_import_status(PredInfo, Status),
+ import_status_to_minimal_string(Status, SStatus),
+ pred_id_to_int(PRED_ID, IPRED_ID),
+ proc_id_to_int(PROC_ID, IPROC_ID),
+ string__int_to_string(IPRED_ID, SPRED_ID),
+ string__int_to_string(IPROC_ID, SPROC_ID),
+ string__append_list(["lookup alias failed for ",
+ SPMODULE, "::",
+ PNAME,"(",SPRED_ID, ",", SPROC_ID, ",",
+ SStatus, ")"],
+ ErrMsg),
+ top(ErrMsg, Alias).
+
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
% easy stuff
- % once the abstract alias substitution is computed for
- % a procedure, one must simply update the proc-information
- % of that procedure.
-:- pred update_alias_in_module_info(pa_util__pa_fixpoint_table,
- pred_proc_id, module_info,
- module_info).
-:- mode update_alias_in_module_info(in, in, in, out) is det.
-
-update_alias_in_module_info(FPtable, PRED_PROC_ID, HLDSin, HLDSout) :-
- module_info_pred_proc_info(HLDSin, PRED_PROC_ID, PredInfo, ProcInfo),
- pa_fixpoint_table_get_final_as(PRED_PROC_ID, ALIAS_AS, FPtable),
- proc_info_set_possible_aliases(ProcInfo, ALIAS_AS, NewProcInfo),
- module_info_set_pred_proc_info(HLDSin, PRED_PROC_ID, PredInfo,
- NewProcInfo, HLDSout).
-
+:- pred update_alias_in_alias_table(pa_fixpoint_table::in, pred_proc_id::in,
+ alias_as_table::in, alias_as_table::out) is det.
+update_alias_in_alias_table(FPTable, PredProcId, AliasTable0, AliasTable) :-
+ pa_fixpoint_table_get_final_as(PredProcId, AliasAs, FPTable),
+ alias_as_table_set_alias(PredProcId, AliasAs, AliasTable0,
+ AliasTable).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
Index: sr_dead.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_dead.m,v
retrieving revision 1.1.2.23
diff -u -r1.1.2.23 sr_dead.m
--- sr_dead.m 10 Jun 2004 05:21:44 -0000 1.1.2.23
+++ sr_dead.m 24 Jun 2004 05:58:48 -0000
@@ -23,9 +23,10 @@
:- import_module hlds__hlds_goal.
:- import_module hlds__hlds_module.
:- import_module hlds__hlds_pred.
+:- import_module possible_alias__pa_alias_as.
:- pred sr_dead__process_goal(pred_id::in, proc_info::in, module_info::in,
- hlds_goal::in, hlds_goal::out) is det.
+ alias_as_table::in, hlds_goal::in, hlds_goal::out) is det.
%-----------------------------------------------------------------------------%
@@ -44,26 +45,26 @@
:- import_module assoc_list, int, require.
:- import_module set, list, map, std_util.
-process_goal(_PredId, ProcInfo, ModuleInfo, Goal0, Goal) :-
+process_goal(_PredId, ProcInfo, ModuleInfo, AliasTable, Goal0, Goal) :-
pa_alias_as__init(Alias0),
hlds_pred__proc_info_headvars(ProcInfo, HeadVars),
dead_cell_pool_init(HeadVars, Pool0),
- annotate_goal(ProcInfo, ModuleInfo, Goal0, Goal,
+ annotate_goal(ProcInfo, ModuleInfo, AliasTable, Goal0, Goal,
Pool0, _Pool, Alias0, _Alias).
%-----------------------------------------------------------------------------%
-:- pred annotate_goal(proc_info::in, module_info::in,
+:- pred annotate_goal(proc_info::in, module_info::in, alias_as_table::in,
hlds_goal::in, hlds_goal::out,
dead_cell_pool::in, dead_cell_pool::out,
alias_as::in, alias_as::out) is det.
-annotate_goal(ProcInfo, HLDS, Expr0 - Info0, Goal,
+annotate_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0, Goal,
Pool0, Pool, Alias0, Alias) :-
Expr0 = conj(Goals0),
sr_util__list_map_foldl2(
- annotate_goal(ProcInfo, HLDS),
+ annotate_goal(ProcInfo, HLDS, AliasTable),
Goals0, Goals,
Pool0, Pool,
Alias0, Alias),
@@ -71,30 +72,31 @@
Expr = conj(Goals),
Goal = Expr - Info.
-annotate_goal(ProcInfo, HLDS, Expr0 - Info0, Goal,
+annotate_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0, Goal,
Pool0, Pool, Alias0, Alias) :-
Expr0 = call(PredId, ProcId, ActualVars, _, _, _),
proc_info_vartypes(ProcInfo, VarTypes),
list__map(map__lookup(VarTypes), ActualVars, ActualTypes),
- pa_run__extend_with_call_alias(HLDS, ProcInfo,
+ pa_run__extend_with_call_alias(HLDS, ProcInfo, AliasTable,
PredId, ProcId, ActualVars, ActualTypes, Alias0, Alias),
Expr = Expr0,
Info = Info0,
Pool = Pool0,
Goal = Expr - Info.
-annotate_goal(_ProcInfo, _HLDS, Expr0 - Info0, Goal,
+annotate_goal(_ProcInfo, _HLDS, _AliasTable, Expr0 - Info0, Goal,
Pool0, Pool, _Alias0, Alias) :-
Expr0 = generic_call(_, _, _, _),
Pool = Pool0,
pa_alias_as__top("unhandled goal", Alias),
Goal = Expr0 - Info0.
-annotate_goal(ProcInfo, HLDS, Expr0 - Info0, Goal,
+annotate_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0, Goal,
Pool0, Pool, Alias0, Alias) :-
Expr0 = switch(A, B, Cases0),
goal_info_get_outscope(Info0, Outscope),
- sr_util__list_map3(annotate_case(ProcInfo, HLDS, Pool0, Alias0),
+ sr_util__list_map3(annotate_case(ProcInfo, HLDS, AliasTable,
+ Pool0, Alias0),
Cases0, Cases, ListPools, ListAliases),
dead_cell_pool_least_upper_bound_disj(Outscope, ListPools, Pool),
pa_alias_as__least_upper_bound_list(HLDS, ProcInfo, Info0,
@@ -103,7 +105,7 @@
Expr = switch(A, B, Cases),
Goal = Expr - Info.
-annotate_goal(ProcInfo, HLDS, Expr0 - Info0, Goal,
+annotate_goal(ProcInfo, HLDS, _AliasTable, Expr0 - Info0, Goal,
Pool0, Pool, Alias0, Alias) :-
Expr0 = unify(_Var, _Rhs, _Mode, Unification0, _Context),
unification_verify_reuse(HLDS, ProcInfo, Unification0, Alias0,
@@ -118,7 +120,7 @@
Expr = Expr0,
Goal = Expr - Info.
-annotate_goal(ProcInfo, HLDS, Expr0 - Info0, Goal,
+annotate_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0, Goal,
Pool0, Pool, Alias0, Alias) :-
Expr0 = disj(Goals0),
(
@@ -132,7 +134,7 @@
pred(Gin::in, Gout::out, P::out, A::out)
is det :-
(
- annotate_goal(ProcInfo, HLDS,
+ annotate_goal(ProcInfo, HLDS, AliasTable,
Gin, Gout, Pool0, P,
Alias0, A)
),
@@ -148,34 +150,35 @@
Expr = disj(Goals),
Goal = Expr - Info.
-annotate_goal(ProcInfo, HLDS, Expr0 - Info0, Goal,
+annotate_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0, Goal,
Pool0, Pool, Alias0, Alias) :-
Expr0 = not(NegatedGoal0),
- annotate_goal(ProcInfo, HLDS, NegatedGoal0, NegatedGoal,
+ annotate_goal(ProcInfo, HLDS, AliasTable, NegatedGoal0, NegatedGoal,
Pool0, Pool, Alias0, Alias),
Info = Info0,
Expr = not(NegatedGoal),
Goal = Expr - Info.
-annotate_goal(ProcInfo, HLDS, Expr0 - Info0, Goal,
+annotate_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0, Goal,
Pool0, Pool, Alias0, Alias) :-
Expr0 = some(A, B, SomeGoal0),
% XXX
- annotate_goal(ProcInfo, HLDS, SomeGoal0, SomeGoal, Pool0, Pool,
+ annotate_goal(ProcInfo, HLDS, AliasTable,
+ SomeGoal0, SomeGoal, Pool0, Pool,
Alias0, Alias),
Info = Info0,
Expr = some(A, B, SomeGoal),
Goal = Expr - Info.
-annotate_goal(ProcInfo, HLDS, Expr0 - Info0, Goal,
+annotate_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0, Goal,
Pool0, Pool, Alias0, Alias) :-
Expr0 = if_then_else(Vars, Cond0, Then0, Else0),
goal_info_get_outscope(Info0, Outscope),
- annotate_goal(ProcInfo, HLDS, Cond0, Cond, Pool0,
+ annotate_goal(ProcInfo, HLDS, AliasTable, Cond0, Cond, Pool0,
PoolCond, Alias0, AliasCond),
- annotate_goal(ProcInfo, HLDS, Then0, Then, PoolCond,
+ annotate_goal(ProcInfo, HLDS, AliasTable, Then0, Then, PoolCond,
PoolThen, AliasCond, AliasThen),
- annotate_goal(ProcInfo, HLDS, Else0, Else, Pool0,
+ annotate_goal(ProcInfo, HLDS, AliasTable, Else0, Else, Pool0,
PoolElse, Alias0, AliasElse),
dead_cell_pool_least_upper_bound_disj(Outscope,
[ PoolThen, PoolElse ], Pool),
@@ -185,7 +188,7 @@
Expr = if_then_else(Vars, Cond, Then, Else),
Goal = Expr - Info.
-annotate_goal(ProcInfo, HLDS, Expr0 - Info0, Goal,
+annotate_goal(ProcInfo, HLDS, _AliasTable, Expr0 - Info0, Goal,
Pool0, Pool, Alias0, Alias) :-
Expr0 = foreign_proc(Attrs, PredId, ProcId,
Vars, MaybeModes, Types, _),
@@ -194,14 +197,14 @@
Pool = Pool0,
Goal = Expr0 - Info0.
-annotate_goal(_ProcInfo, _HLDS, Expr0 - Info0, Goal,
+annotate_goal(_ProcInfo, _HLDS, _AliasTable, Expr0 - Info0, Goal,
Pool0, Pool, _Alias0, Alias) :-
Expr0 = par_conj(_),
Pool = Pool0,
pa_alias_as__top("unhandled goal", Alias),
Goal = Expr0 - Info0.
-annotate_goal(_ProcInfo, _HLDS, Expr0 - Info0, Goal,
+annotate_goal(_ProcInfo, _HLDS, _AliasTable, Expr0 - Info0, Goal,
Pool0, Pool, _Alias0, Alias) :-
Expr0 = shorthand(_),
Pool = Pool0,
@@ -209,13 +212,15 @@
Goal = Expr0 - Info0.
-:- pred annotate_case(proc_info::in, module_info::in,
+:- pred annotate_case(proc_info::in, module_info::in, alias_as_table::in,
dead_cell_pool::in, alias_as::in, case::in,
case::out, dead_cell_pool::out, alias_as::out) is det.
-annotate_case(ProcInfo, HLDS, Pool0, Alias0, Case0, Case, Pool, Alias) :-
+annotate_case(ProcInfo, HLDS, AliasTable, Pool0, Alias0, Case0,
+ Case, Pool, Alias) :-
Case0 = case(ConsId, Goal0),
- annotate_goal(ProcInfo, HLDS, Goal0, Goal, Pool0, Pool, Alias0, Alias),
+ annotate_goal(ProcInfo, HLDS, AliasTable, Goal0, Goal,
+ Pool0, Pool, Alias0, Alias),
Case = case(ConsId, Goal).
:- pred unification_verify_reuse(module_info::in, proc_info::in,
Index: sr_direct.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_direct.m,v
retrieving revision 1.1.2.20
diff -u -r1.1.2.20 sr_direct.m
--- sr_direct.m 19 Jun 2004 07:35:48 -0000 1.1.2.20
+++ sr_direct.m 24 Jun 2004 05:58:48 -0000
@@ -19,11 +19,13 @@
:- import_module hlds__hlds_module.
:- import_module hlds__hlds_pred.
+:- import_module possible_alias__pa_alias_as.
:- import_module io.
-:- pred sr_direct__process_proc(pred_id::in, proc_id::in, proc_info::in,
- proc_info::out, module_info::in, module_info::out,
+:- pred sr_direct__process_proc(alias_as_table::in, pred_id::in, proc_id::in,
+ proc_info::in, proc_info::out,
+ module_info::in, module_info::out,
io__state::di, io__state::uo) is det.
%-----------------------------------------------------------------------------%
@@ -58,7 +60,8 @@
% potentially die.
% 3. 'choice' analysis, i.e. identify where dead datastructure can be
% reused.
-process_proc(PredId, ProcId, ProcInfo0, ProcInfo, ModuleInfo0, ModuleInfo) -->
+process_proc(AliasTable, PredId, ProcId,
+ ProcInfo0, ProcInfo, ModuleInfo0, ModuleInfo) -->
% Some pre-processing:
% - Initialise the reuse information.
% - Annotate goals with local forward use (lfu).
@@ -83,7 +86,8 @@
% 'Deadness' analysis: determine the deconstructions in which data
% structures potentially die.
passes_aux__maybe_write_string(VeryVerbose, "%\tdeadness analysis..."),
- { sr_dead__process_goal(PredId,ProcInfo0,ModuleInfo0,Goal0,Goal1) },
+ { sr_dead__process_goal(PredId, ProcInfo0, ModuleInfo0,
+ AliasTable, Goal0,Goal1) },
passes_aux__maybe_write_string(VeryVerbose, "done.\n"),
% 'Choice' analysis: determine how the detected dead data structures
Index: sr_indirect.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_indirect.m,v
retrieving revision 1.1.2.32
diff -u -r1.1.2.32 sr_indirect.m
--- sr_indirect.m 11 Jun 2004 02:56:54 -0000 1.1.2.32
+++ sr_indirect.m 24 Jun 2004 05:58:51 -0000
@@ -15,10 +15,12 @@
:- interface.
:- import_module hlds__hlds_module.
+:- import_module possible_alias__pa_alias_as.
:- import_module io.
-:- pred sr_indirect__compute_fixpoint(module_info::in, module_info::out,
+:- pred sr_indirect__compute_fixpoint(alias_as_table::in,
+ module_info::in, module_info::out,
io__state::di, io__state::uo) is det.
%-----------------------------------------------------------------------------%
@@ -46,7 +48,7 @@
:- import_module map, list, std_util, require, set, string, bool.
-compute_fixpoint(HLDS0, HLDSout) -->
+compute_fixpoint(AliasTable, HLDS0, HLDSout) -->
% compute the strongly connected components
{ module_info_ensure_dependency_info(HLDS0, HLDS1) },
{ module_info_get_maybe_dependency_info(HLDS1, MaybeDepInfo) } ,
@@ -56,24 +58,24 @@
{ hlds_dependency_info_get_dependency_ordering(DepInfo,
DepOrdering) },
% perform the analysis, and annotate the procedures
- run_with_dependencies(DepOrdering, HLDS1, HLDS2),
+ run_with_dependencies(AliasTable, DepOrdering, HLDS1, HLDS2),
{ HLDSout = HLDS2 }
;
{ error("(sr_indirect) compute_fixpoint: no dependency info") }
).
-:- pred run_with_dependencies(dependency_ordering, module_info,
- module_info, io__state, io__state).
-:- mode run_with_dependencies(in, in, out, di, uo) is det.
-
-run_with_dependencies(Deps, HLDSin, HLDSout) -->
- list__foldl2(run_with_dependency, Deps, HLDSin, HLDSout).
-
-:- pred run_with_dependency(list(pred_proc_id), module_info, module_info,
- io__state, io__state).
-:- mode run_with_dependency(in, in, out, di, uo) is det.
+:- pred run_with_dependencies(alias_as_table::in, dependency_ordering::in,
+ 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).
+
+:- pred run_with_dependency(alias_as_table::in, list(pred_proc_id)::in,
+ module_info::in, module_info::out,
+ io__state::di, io__state::uo) is det.
-run_with_dependency(SCC, HLDSin, HLDSout) -->
+run_with_dependency(AliasTable, SCC, HLDSin, HLDSout) -->
(
% analysis ignores special predicates
{ pa_sr_util__some_are_special_preds(SCC, HLDSin) }
@@ -83,18 +85,20 @@
% for each list of strongly connected components,
% perform a fixpoint computation.
{ sr_fixpoint_table_init(HLDSin, SCC, FPtable0) } ,
- run_with_dependency_until_fixpoint(SCC, FPtable0,
+ run_with_dependency_until_fixpoint(AliasTable, SCC, FPtable0,
HLDSin, HLDSout)
).
%-----------------------------------------------------------------------------%
-:- pred run_with_dependency_until_fixpoint(list(pred_proc_id),
- sr_fixpoint_table__table, module_info, module_info,
- io__state, io__state).
-:- mode run_with_dependency_until_fixpoint(in, in, in, out, di, uo) is det.
+:- pred run_with_dependency_until_fixpoint(alias_as_table::in,
+ list(pred_proc_id)::in, sr_fixpoint_table__table::in,
+ module_info::in, module_info::out,
+ io__state::di, io__state::uo) is det.
-run_with_dependency_until_fixpoint(SCC, FPtable0, HLDSin, HLDSout) -->
- list__foldl2(analyse_pred_proc(HLDSin), SCC, FPtable0, FPtable),
+run_with_dependency_until_fixpoint(AliasTable,
+ SCC, FPtable0, HLDSin, HLDSout) -->
+ list__foldl2(analyse_pred_proc(HLDSin, AliasTable),
+ SCC, FPtable0, FPtable),
(
{ sr_fixpoint_table_all_stable(FPtable) }
->
@@ -103,7 +107,8 @@
;
{ sr_fixpoint_table_new_run(FPtable,
FPtable1) },
- run_with_dependency_until_fixpoint(SCC, FPtable1, HLDSin,
+ run_with_dependency_until_fixpoint(AliasTable,
+ SCC, FPtable1, HLDSin,
HLDSout)
).
@@ -124,13 +129,12 @@
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
-:- 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.
+:- pred analyse_pred_proc(module_info::in, alias_as_table::in,
+ pred_proc_id::in,
+ sr_fixpoint_table__table::in, sr_fixpoint_table__table::out,
+ io__state::di, io__state::uo) is det.
-analyse_pred_proc(HLDS, PredProcId, FPin, FPout) -->
+analyse_pred_proc(HLDS, AliasTable, PredProcId, FPin, FPout) -->
{ module_info_pred_proc_info(HLDS, PredProcId,
_PredInfo, ProcInfo) },
{ PredProcId = proc(PredId, ProcId) },
@@ -189,7 +193,7 @@
indirect_reuse_pool_init(HVs, MemoStarting, Pool0)
},
% 5. analyse_goal
- analyse_goal(ProcInfo, HLDS,
+ analyse_goal(ProcInfo, HLDS, AliasTable,
Goal0, Goal,
analysis_info(Alias0, Pool0,
set__init, FPin),
@@ -263,20 +267,23 @@
io__write_string(Msg2)
).
-:- pred analyse_goal(proc_info::in, module_info::in,
- hlds_goal::in, hlds_goal::out,
- analysis_info::in, analysis_info::out,
- io__state::di, io__state::uo) is det.
+:- pred analyse_goal(proc_info::in, module_info::in, alias_as_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, Expr0 - Info0, Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
+ Goal, AI0, AI, IO0, IO) :-
Expr0 = conj(Goals0),
- list__map_foldl2(analyse_goal(ProcInfo, HLDS), Goals0, Goals,
+ list__map_foldl2(analyse_goal(ProcInfo, HLDS, AliasTable),
+ Goals0, Goals,
AI0, AI, IO0, IO),
Expr = conj(Goals),
Info = Info0,
Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, Expr0 - Info0, Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
+ Goal, AI0, AI, IO0, IO) :-
Expr0 = call(PredId, ProcId, ActualVars, _, _, _),
passes_aux__write_proc_progress_message(
"%\t\tcall to ",
@@ -289,21 +296,23 @@
call_verify_reuse(ProcInfo, HLDS,
PredId, ProcId, ActualVars,
ActualTypes, Info0, Info, AI0, AI1, _, IO2, IO3),
- pa_run__extend_with_call_alias(HLDS, ProcInfo,
+ pa_run__extend_with_call_alias(HLDS, ProcInfo, AliasTable,
PredId, ProcId, ActualVars, ActualTypes, AI0 ^ alias, Alias),
AI = AI1 ^ alias := Alias,
Expr = Expr0,
Goal = Expr - Info,
IO = IO3.
-analyse_goal(_ProcInfo, _HLDS, Expr0 - Info0, Goal, AI0, AI, IO0, IO) :-
+analyse_goal(_ProcInfo, _HLDS, _AliasTable, Expr0 - Info0,
+ Goal, AI0, AI, IO0, IO) :-
Expr0 = generic_call(_, _, _, _),
pa_alias_as__top("unhandled goal", Alias),
AI = AI0 ^ alias := Alias,
Goal = Expr0 - Info0,
IO = IO0.
-analyse_goal(ProcInfo, HLDS, Expr0 - Info0, Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, _AliasTable, Expr0 - Info0,
+ Goal, AI0, AI, IO0, IO) :-
Expr0 = unify(_Var, _Rhs, _Mode, Unification, _Context),
% Record the statically constructed variables.
@@ -321,13 +330,14 @@
Goal = Expr - Info,
IO = IO0.
-analyse_goal(ProcInfo, HLDS, Expr0 - Info0, Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
+ Goal, AI0, AI, IO0, IO) :-
Expr0 = switch(Var, CanFail, Cases0),
list__map_foldl2(
(pred(case(ConsId, Gin)::in, Tuple::out,
FPin::in, FPout::out,
IOin::di, IOout::uo) is det :-
- analyse_goal(ProcInfo, HLDS, Gin, Gout,
+ analyse_goal(ProcInfo, HLDS, AliasTable, Gin, Gout,
analysis_info(AI0 ^ alias, AI0 ^ pool,
AI0 ^ static, FPin),
analysis_info(NewAlias,
@@ -361,7 +371,8 @@
Expr = switch(Var, CanFail, Cases),
Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, Expr0 - Info0, Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
+ Goal, AI0, AI, IO0, IO) :-
Expr0 = disj(Goals0),
(
Goals0 = []
@@ -375,7 +386,8 @@
(pred(Gin::in, Tuple::out,
FPin::in, FPout::out,
IOin::di, IOout::uo) is det :-
- analyse_goal(ProcInfo, HLDS, Gin, Gout,
+ analyse_goal(ProcInfo, HLDS, AliasTable,
+ Gin, Gout,
analysis_info(AI0 ^ alias, AI0 ^ pool,
AI0 ^ static, FPin),
analysis_info(NewAlias, NewPool,
@@ -410,28 +422,35 @@
Expr = disj(Goals),
Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, Expr0 - Info0, Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
+ Goal, AI0, AI, IO0, IO) :-
Expr0 = not(NegatedGoal0),
- analyse_goal(ProcInfo, HLDS, NegatedGoal0, NegatedGoal,
+ analyse_goal(ProcInfo, HLDS, AliasTable, NegatedGoal0, NegatedGoal,
AI0, AI, IO0, IO),
Info = Info0,
Expr = not(NegatedGoal),
Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, Expr0 - Info0, Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
+ Goal, AI0, AI, IO0, IO) :-
Expr0 = some(A, B, SomeGoal0),
- analyse_goal(ProcInfo, HLDS, SomeGoal0, SomeGoal, AI0, AI, IO0, IO),
+ analyse_goal(ProcInfo, HLDS, AliasTable, SomeGoal0,
+ SomeGoal, AI0, AI, IO0, IO),
Info = Info0,
Expr = some(A, B, SomeGoal),
Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, Expr0 - Info0, Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, AliasTable, Expr0 - Info0,
+ Goal, AI0, AI, IO0, IO) :-
Expr0 = if_then_else(Vars, Cond0, Then0, Else0),
- analyse_goal(ProcInfo, HLDS, Cond0, Cond, AI0, AI_Cond, IO0, IO1),
- analyse_goal(ProcInfo, HLDS, Then0, Then, AI_Cond, AI_Then, IO1, IO2),
+ 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),
AI1 = AI0 ^ table := AI_Then ^ table,
- analyse_goal(ProcInfo, HLDS, Else0, Else, AI1, AI_Else, IO2, IO),
+ analyse_goal(ProcInfo, HLDS, AliasTable,
+ Else0, Else, AI1, AI_Else, IO2, IO),
indirect_reuse_pool_least_upper_bound_disjunction(
[AI_Then ^ pool, AI_Else ^ pool],
@@ -452,7 +471,8 @@
Expr = if_then_else(Vars, Cond, Then, Else),
Goal = Expr - Info.
-analyse_goal(ProcInfo, HLDS, Expr0 - Info0, Goal, AI0, AI, IO0, IO) :-
+analyse_goal(ProcInfo, HLDS, _AliasTable, Expr0 - Info0,
+ Goal, AI0, AI, IO0, IO) :-
Expr0 = foreign_proc(Attrs, PredId, ProcId,
Vars, MaybeModes, Types, _),
pa_alias_as__extend_foreign_code(HLDS, ProcInfo, Attrs,
@@ -462,14 +482,16 @@
Goal = Expr0 - Info0,
IO = IO0.
-analyse_goal(_ProcInfo, _HLDS, Expr0 - Info0, Goal, AI0, AI, IO0, IO) :-
+analyse_goal(_ProcInfo, _HLDS, _AliasTable, Expr0 - Info0,
+ Goal, AI0, AI, IO0, IO) :-
Expr0 = par_conj(_),
pa_alias_as__top("unhandled goal (par_conj)", Alias),
AI = AI0 ^ alias := Alias,
Goal = Expr0 - Info0,
IO = IO0.
-analyse_goal(_ProcInfo, _HLDS, Expr0 - Info0, Goal, AI0, AI, IO0, IO) :-
+analyse_goal(_ProcInfo, _HLDS, _AliasTable, Expr0 - Info0,
+ Goal, AI0, AI, IO0, IO) :-
Expr0 = shorthand(_),
pa_alias_as__top("unhandled goal (shorthand)", Alias),
AI = AI0 ^ alias := Alias,
Index: sr_top.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_top.m,v
retrieving revision 1.1.2.3
diff -u -r1.1.2.3 sr_top.m
--- sr_top.m 11 Jun 2004 06:01:19 -0000 1.1.2.3
+++ sr_top.m 24 Jun 2004 05:58:51 -0000
@@ -43,12 +43,14 @@
:- import_module hlds__hlds_module.
:- import_module hlds__hlds_pred.
+:- import_module possible_alias__pa_alias_as.
-:- import_module list, io.
+:- import_module list, io, bool, std_util.
% Perform the structure reuse analysis.
-:- pred structure_reuse(module_info::in, module_info::out,
- io::di, io::uo) is det.
+:- pred structure_reuse(module_info::in, maybe(alias_as_table)::in,
+ bool::in, bool::in, module_info::out,
+ io__state::di, io__state::uo) is det.
% Write the reuse information of a module as pragma's in the trans_opt
% of that module.
@@ -78,9 +80,35 @@
:- import_module structure_reuse__sr_util.
:- import_module list, map, varset, std_util, int, bool.
-:- import_module term.
+:- import_module term, require.
-structure_reuse(HLDS00, HLDS) -->
+structure_reuse(HLDS0, MaybeAliasTable, Verbose, Stats, HLDS) -->
+ globals__io_lookup_bool_option(infer_structure_reuse, Reuse),
+ (
+ { Reuse = yes }
+ ->
+ (
+ { MaybeAliasTable = yes(AliasTable) }
+ ->
+ maybe_write_string(Verbose,
+ "% Structure-reuse analysis...\n"),
+ maybe_flush_output(Verbose),
+ structure_reuse(AliasTable, HLDS0, HLDS),
+ maybe_write_string(Verbose, "% done.\n"),
+ maybe_report_stats(Stats)
+ ;
+ { Msg = "(sr_top) No aliastable." },
+ { error(Msg) }
+ )
+ ;
+ { HLDS = HLDS0 }
+ ).
+
+:- pred structure_reuse(alias_as_table::in,
+ module_info::in, module_info::out,
+ io::di, io::uo) is det.
+
+structure_reuse(AliasTable, HLDS00, HLDS) -->
% Before starting the actual reuse-analysis, process all the reuse
% information of the imported predicates.
{ module_info_unproc_reuse_pragmas(HLDS00, UnprocReusePragmas) },
@@ -96,7 +124,7 @@
% Do the direct reuse analysis phase.
process_matching_nonimported_procs(
- update_module_io(sr_direct__process_proc),
+ update_module_io(sr_direct__process_proc(AliasTable)),
(pred(PredId::in, _PredInfo::in) is semidet :-
\+ list__member(PredId, SpecialPredIds)
),
@@ -104,7 +132,7 @@
% Do the fixpoint computation to determine all the indirect
% reuse, and the implied conditions.
- sr_indirect__compute_fixpoint(HLDS1, HLDS2),
+ sr_indirect__compute_fixpoint(AliasTable, HLDS1, HLDS2),
sr_split__create_multiple_versions(HLDS2, HLDS),
sr_profile_run__structure_reuse_profiling(HLDS).
--
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