[m-rev.] [diff] reuse: use public reuse-condition type
Nancy Mazur
Nancy.Mazur at cs.kuleuven.ac.be
Thu Jul 29 11:57:32 AEST 2004
Hi,
===================================================================
Estimated hours taken: 3
Branches: reuse
Change the proc-info and the reuse-pragma such that it uses the public
representation for reuse-conditions instead of the private representation.
Move and adapt printing/parsing routines for reuse conditions to prog_io_pasr.
hlds_module.m:
hlds_out.m:
hlds_pred.m:
make_hlds.m:
prog_data.m:
prog_io_pasr.m:
prog_io_pragma.m:
sr_data.m:
sr_top.m:
Index: hlds_module.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_module.m,v
retrieving revision 1.59.2.14
diff -u -r1.59.2.14 hlds_module.m
--- hlds_module.m 25 Jun 2004 02:33:39 -0000 1.59.2.14
+++ hlds_module.m 29 Jul 2004 01:47:30 -0000
@@ -27,8 +27,6 @@
:- import_module hlds__special_pred.
:- import_module libs__globals, backend_libs__foreign.
:- import_module relation, map, std_util, list, set, multi_map, counter.
-:- import_module structure_reuse.
-:- import_module structure_reuse__sr_data.
:- implementation.
@@ -139,7 +137,7 @@
:- type unproc_reuse_pragma
---> unproc_reuse_pragma(pred_or_func, sym_name, list(mode),
list(prog_var), list((type)),
- sr_data__memo_reuse, maybe(sym_name)).
+ maybe_reuse_tuples, maybe(sym_name)).
%-----------------------------------------------------------------------------%
Index: hlds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_out.m,v
retrieving revision 1.243.2.29
diff -u -r1.243.2.29 hlds_out.m
--- hlds_out.m 27 Jun 2004 10:06:25 -0000 1.243.2.29
+++ hlds_out.m 29 Jul 2004 01:47:49 -0000
@@ -267,6 +267,10 @@
:- import_module check_hlds__type_util.
:- import_module transform_hlds__termination, transform_hlds__term_errors.
+% Reuse modules
+:- import_module structure_reuse.
+:- import_module structure_reuse__sr_data.
+
% RL back-end modules (XXX should avoid using those here).
:- import_module aditi_backend__rl.
@@ -283,9 +287,6 @@
:- import_module int, string, set, assoc_list, map, multi_map.
:- import_module require, getopt, std_util, term_io, varset.
-:- import_module structure_reuse.
-:- import_module structure_reuse__sr_data.
-
hlds_out__write_type_ctor(Name - Arity) -->
prog_out__write_sym_name_and_arity(Name / Arity).
@@ -3427,18 +3428,12 @@
(
{ string__contains_char(Verbose, 'p') }
->
- { proc_info_reuse_information(Proc, Memo) },
- (
- { Memo = yes(_MemoReuse) }
- ->
- hlds_out__write_indent(Indent),
- io__write_string("% Reuse version = "),
- sr_data__memo_reuse_print_dump(Memo, Proc,
- PredInfo),
- io__write_string("\n")
- ;
- []
- )
+ { proc_info_reuse_information(Proc, MaybeReuseTuples) },
+ hlds_out__write_indent(Indent),
+ io__write_string("% Reuse version = "),
+ prog_io_pasr__print_maybe_reuse_tuples(
+ VarSet, TVarSet, MaybeReuseTuples, no),
+ io__write_string("\n")
;
[]
),
Index: hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.81.2.24
diff -u -r1.81.2.24 hlds_pred.m
--- hlds_pred.m 25 Jun 2004 02:33:41 -0000 1.81.2.24
+++ hlds_pred.m 29 Jul 2004 01:48:03 -0000
@@ -21,8 +21,6 @@
:- import_module libs__globals.
:- import_module bool, list, set, map, std_util, term, varset.
-:- import_module structure_reuse.
-:- import_module structure_reuse__sr_data.
:- implementation.
@@ -1800,12 +1798,11 @@
:- pred proc_info_set_global_use(proc_info, set(prog_var), proc_info).
:- mode proc_info_set_global_use(in, in, out) is det.
-:- pred proc_info_reuse_information(proc_info,
- maybe(list(sr_data__reuse_condition))).
+:- pred proc_info_reuse_information(proc_info, maybe_reuse_tuples).
:- mode proc_info_reuse_information(in, out) is det.
-:- pred proc_info_set_reuse_information(proc_info,
- maybe(list(sr_data__reuse_condition)), proc_info).
+:- pred proc_info_set_reuse_information(proc_info, maybe_reuse_tuples,
+ proc_info).
:- mode proc_info_set_reuse_information(in, in, out) is det.
:- pred proc_info_static_terms(proc_info, maybe(set(datastruct))).
@@ -2109,7 +2106,7 @@
% (set during structure_reuse phase)
% Possible set of reuse conditions.
- structure_reuse:: maybe(list(sr_data__reuse_condition)),
+ structure_reuse:: maybe_reuse_tuples,
% Possible set of datastructures that
% might be static after calling
@@ -2282,8 +2279,10 @@
proc_info_maybe_declared_argmodes(ProcInfo, ProcInfo^maybe_declared_head_modes).
proc_info_is_address_taken(ProcInfo, ProcInfo^is_address_taken).
proc_info_get_rl_exprn_id(ProcInfo, ProcInfo^maybe_aditi_rl_id).
+
:- pred proc_info_alias_reuse_info(proc_info::in, pa_sr_info::out) is det.
proc_info_alias_reuse_info(ProcInfo, ProcInfo^alias_reuse_info).
+
proc_info_possible_aliases(ProcInfo, AliasReuseInfo^maybe_alias):-
proc_info_alias_reuse_info(ProcInfo, AliasReuseInfo).
proc_info_global_use(ProcInfo, AliasReuseInfo^maybe_global_use):-
Index: make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.347.2.27
diff -u -r1.347.2.27 make_hlds.m
--- make_hlds.m 30 Jun 2004 04:46:41 -0000 1.347.2.27
+++ make_hlds.m 29 Jul 2004 01:48:37 -0000
@@ -117,13 +117,6 @@
:- import_module recompilation.
:- import_module libs__options, libs__globals.
-:- import_module possible_alias.
-:- import_module possible_alias__pa_run.
-:- import_module possible_alias__pa_alias_as.
-:- import_module structure_reuse.
-:- import_module structure_reuse__sr_data.
-:- import_module structure_reuse__sr_split.
-
:- import_module string, char, int, set, bintree, map, multi_map, require.
:- import_module bag, term, varset, getopt, assoc_list, term_io.
@@ -558,10 +551,10 @@
;
{ Pragma = structure_reuse(PredOrFunc, SymName, ModeList,
- HeadVars, Types, Memo, MaybeReuseSymName) },
+ HeadVars, Types, MaybeReuseTuples, MaybeReuseSymName) },
add_pragma_reuse_info( PredOrFunc, SymName, ModeList,
HeadVars, Types,
- Memo, MaybeReuseSymName,
+ MaybeReuseTuples, MaybeReuseSymName,
Module0, Module)
;
{ Pragma = terminates(Name, Arity) },
@@ -1594,7 +1587,7 @@
list(mode)::in,
list(var(T))::in,
list( (type) )::in,
- sr_data__memo_reuse::in,
+ maybe_reuse_tuples::in,
maybe(sym_name)::in,
module_info::in, module_info::out,
io__state::di, io__state::uo) is det.
Index: prog_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.58.2.20
diff -u -r1.58.2.20 prog_data.m
--- prog_data.m 28 Jun 2004 06:56:46 -0000 1.58.2.20
+++ prog_data.m 29 Jul 2004 01:48:52 -0000
@@ -29,12 +29,8 @@
:- import_module (parse_tree__inst), libs__options, libs__globals.
:- import_module recompilation.
:- import_module bool, list, assoc_list, map, set, varset, term, std_util.
- % XXX Dependencies moeten weg!!
-:- import_module structure_reuse.
-:- import_module structure_reuse__sr_data.
%-----------------------------------------------------------------------------%
-
% This is how programs (and parse errors) are represented.
:- type message_list == list(pair(string, term)).
@@ -308,7 +304,8 @@
; structure_reuse(pred_or_func, sym_name, list(mode),
list(prog_var),
- list( (type) ), memo_reuse, maybe(sym_name))
+ list( (type) ),
+ maybe_reuse_tuples, maybe(sym_name))
; terminates(sym_name, arity)
% Predname, Arity
@@ -490,6 +487,7 @@
% headvariables of the concerned procedure.
).
+:- type maybe_reuse_tuples == maybe(list(reuse_tuple)).
%
% Stuff for the `unused_args' pragma.
Index: prog_io_pasr.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/prog_io_pasr.m,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 prog_io_pasr.m
--- prog_io_pasr.m 28 Jun 2004 06:56:46 -0000 1.1.2.5
+++ prog_io_pasr.m 29 Jul 2004 01:48:56 -0000
@@ -16,6 +16,7 @@
:- import_module io, term, std_util, list, varset, map.
+
% XXX prog_io_pasr shows to be a bad name, if it also contains procedures to
% transform the aliases types, like the renaming below.
%-----------------------------------------------------------------------------%
@@ -77,6 +78,17 @@
maybe(aliases_domain)::in,
io__state::di, io__state::uo) is det.
+% 7. reuse_tuple.
+:- pred print_reuse_tuple(prog_varset::in, tvarset::in, reuse_tuple::in,
+ io__state::di, io__state::uo) is det.
+
+ % The sym_name is the name of the reuse-predicate for which the
+ % reuse-conditions are valid.
+:- pred print_maybe_reuse_tuples(prog_varset::in, tvarset::in,
+ maybe_reuse_tuples::in, maybe(sym_name)::in,
+ io__state::di, io__state::uo) is det.
+
+
% Print the aliases in a form suitable for the transitive-optimisation
% files. The msg's in top-aliases are discarded: a top alias set is
% simply printed as "top".
@@ -103,6 +115,11 @@
% Parse the used declared aliases (pragma aliasing).
:- pred parse_user_declared_aliasing(term::in, varset::in,
aliasing::out) is semidet.
+% 6. reuse_tuple
+:- pred parse_reuse_tuple(term(T)::in, reuse_tuple::out) is det.
+% 7. maybe_reuse_tuple
+:- pred parse_maybe_reuse_tuples(term(T)::in, maybe_reuse_tuples::out,
+ maybe(sym_name)::out) is semidet.
:- pred format_context(term__context::in, string::out) is det.
%-----------------------------------------------------------------------------%
@@ -113,6 +130,8 @@
:- import_module hlds__hlds_data.
:- import_module parse_tree__mercury_to_mercury.
:- import_module parse_tree__prog_io.
+:- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_io_util.
:- import_module string, require, bool, varset, std_util, int, set.
@@ -276,6 +295,48 @@
print_aliases(ProgVarSet, TVarSet, MaybeThreshold, "[", ", ",
"]", AliasList, !IO)
).
+
+print_reuse_tuple(_ProgVarSet, _TVarSet, unconditional, !IO) :-
+ io__write_string("always", !IO).
+print_reuse_tuple(ProgVarSet, TVarSet, conditional(Nodes, LUiH, LAiH), !IO) :-
+ set__to_sorted_list(Nodes, NodesList),
+ set__to_sorted_list(LUiH, ListLUiH),
+ ListLUiHVars = list__map(
+ (func(D) = V :- V = D ^ sc_var), ListLUiH),
+
+ io__write_string("condition(", !IO),
+ % write out the list of headvar-nodes involved
+ io__write_string("[", !IO),
+ io__write_list(NodesList, ",",
+ print_datastruct(ProgVarSet, TVarSet), !IO),
+ io__write_string("], ", !IO),
+
+ % write out LUiH, list of prog_vars
+ io__write_string("[", !IO),
+ mercury_output_vars(ListLUiHVars, ProgVarSet, bool__no, !IO),
+ io__write_string("], ", !IO),
+
+ % write out LAiH, the aliases at the reuse-point
+ print_aliases_domain(ProgVarSet, TVarSet, no, LAiH, !IO),
+ io__write_string(")", !IO).
+
+print_maybe_reuse_tuples(_, _, no, _, !IO) :-
+ io__write_string("no", !IO).
+print_maybe_reuse_tuples(ProgVarSet, TVarSet, yes(Tuples), MaybeName, !IO) :-
+ io__write_string("yes([", !IO),
+ io__write_list(Tuples, ",",
+ print_reuse_tuple(ProgVarSet, TVarSet), !IO),
+ io__write_string("]", !IO),
+ (
+ MaybeName = yes(Name)
+ ->
+ io__write_string(",", !IO),
+ prog_out__write_quoted_sym_name(Name, !IO)
+ ;
+ true
+ ),
+ io__write_string(")", !IO).
+
%-----------------------------------------------------------------------------%
% Parsing routines.
@@ -630,7 +691,180 @@
parse_user_declared_aliases(AliasTerm, AliasAs),
Aliasing = aliasing(MaybeTypes, TypeVarSet, AliasAs).
-
+ % Note that in the interfaces, unconditional reuse tuples are simply
+ % not printed, therefore, there is no need to parse such tuples.
+parse_reuse_tuple(Term, ReuseTuple) :-
+ (
+ Term = term__functor(term__atom(Cons), Args, _)
+ ->
+ (
+ Cons = "condition"
+ ->
+ (
+ Args = [NodesTerm, LUiHTerm, LAiHTerm]
+ ->
+ nodes_parse(NodesTerm, NodesList),
+ set__list_to_set(NodesList, Nodes),
+ vars_parse(LUiHTerm, LUiH),
+ LUiHData = set__map(
+ (func(V) = selected_cel(V,[])),
+ LUiH),
+ parse_aliases_domain(LAiHTerm,
+ LAiH),
+ ReuseTuple = conditional(Nodes, LUiHData, LAiH)
+ ;
+ list__length(Args, L),
+ string__int_to_string(L, LS),
+ string__append_list(
+ [ "(prog_io_pasr) condition_parse: ",
+ "wrong number of arguments. ",
+ "condition/",LS, " should be ",
+ "condition/3"], Msg),
+ error(Msg)
+ )
+ ;
+ term__det_term_to_type(Term, Type),
+ varset__init(V),
+ StringTerm = mercury_type_to_string(V, Type),
+ string__append_list(
+ ["(prog_io_pasr) condition_parse: ",
+ "wrong constructur. `",
+ StringTerm,
+ "' should be `condition'"], Msg),
+ error(Msg)
+ )
+ ;
+ error("(prog_io_pasr) condition_parse: term is not a functor")
+ ).
+
+:- pred vars_parse(term(T)::in, set(prog_var)::out) is det.
+
+vars_parse(Term, Vars) :-
+ vars_parse_list(Term, VarList) ,
+ set__list_to_set(VarList, Vars).
+
+:- pred vars_parse_list(term(T)::in, list(prog_var)::out) is det.
+
+vars_parse_list(Term, Vars) :-
+ (
+ Term = term__functor(term__atom(Cons), Args, _)
+ ->
+ (
+ Cons = "[|]",
+ Args = [First, Rest]
+ ->
+ (
+ First = term__variable(V)
+ ->
+ V1 = V
+ ;
+ error("(prog_io_pasr) vars_parse_list: list should contain variables.")
+ ),
+ term__coerce_var(V1, ProgVar),
+ vars_parse_list(Rest, V2),
+ Vars = [ProgVar | V2]
+ ;
+ Cons = "[]"
+ ->
+ Vars = []
+ ;
+ string__append("(prog_io_pasr) vars_parse_list: could not parse nodes, top cons: ", Cons, Msg),
+ error(Msg)
+ )
+ ;
+ error("(prog_io_pasr) vars_parse_list: term not a functor")
+ ).
+
+:- pred nodes_parse(term(T)::in, list(datastruct)::out) is det.
+
+nodes_parse(Term, Datastructs) :-
+ (
+ Term = term__functor(term__atom(Cons), Args, _)
+ ->
+ (
+ Cons = "[|]",
+ Args = [First, Rest]
+ ->
+ parse_datastruct(First, D1),
+ nodes_parse(Rest, D2),
+ Datastructs = [D1 | D2]
+ ;
+ Cons = "[]"
+ ->
+ Datastructs = []
+ ;
+ string__append("(prog_io_pasr) nodes_parse: could not parse nodes, top cons: ", Cons, Msg),
+ error(Msg)
+ )
+ ;
+ error("(prog_io_pasr) nodes_parse: term not a functor")
+ ).
+
+:- pred parse_reuse_tuples(term(T)::in, list(reuse_tuple)::out) is det.
+parse_reuse_tuples(Term, Tuples) :-
+ (
+ Term = term__functor(term__atom(Cons), Args, _)
+ ->
+ (
+ Cons = "[|]",
+ Args = [First, Rest]
+ ->
+ parse_reuse_tuple(First, Cond1),
+ parse_reuse_tuples(Rest, Cond2),
+ Tuples = [Cond1 | Cond2]
+ ;
+ Cons = "[]"
+ ->
+ Tuples = []
+ ;
+ string__append_list([
+ "(prog_io_pasr) parse_reuse_tuples: ",
+ "could not parse conditions, top cons: ",
+ Cons], Msg),
+ error(Msg)
+ )
+ ;
+ error("(prog_io_pasr) parse_reuse_tuples: term not a functor")
+ ).
+
+
+parse_maybe_reuse_tuples(Term, MaybeReuseTuples, MaybeReuseName) :-
+ (
+ Term = term__functor(term__atom("no"), _, _),
+ MaybeReuseName = no,
+ MaybeReuseTuples = no
+ ;
+ Term = term__functor(term__atom("yes"),
+ ReadTuplesAndName, _),
+ (
+ ReadTuplesAndName = [ReadTuples, NameTerm]
+ ->
+ parse_reuse_tuples(ReadTuples, Tuples),
+ MaybeReuseTuples = yes(Tuples),
+ parse_qualified_term(NameTerm,
+ NameTerm, "pragma reuse",
+ Result),
+ (
+ Result = ok(ReuseName, [])
+ ->
+ MaybeReuseName = yes(ReuseName)
+ ;
+ string__append_list([
+ "(prog_io_pasr) ",
+ "parse_maybe_reuse_tuples"], Msg),
+ error(Msg)
+ )
+ ;
+ list__length(ReadTuplesAndName, L),
+ string__int_to_string(L, LS),
+ string__append_list([
+ "(sr_data) conditions_list_parse: ",
+ "wrong number of arguments. yes/", LS,
+ " should be yes/2"], Msg),
+ error(Msg)
+ )
+ ).
+
:- func typeselector_init(list(type)) = selector.
typeselector_init(Types) = Selector :-
list__map(
@@ -638,3 +872,4 @@
US = ts(T),
Types,
Selector).
+
Index: prog_io_pragma.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io_pragma.m,v
retrieving revision 1.23.2.18
diff -u -r1.23.2.18 prog_io_pragma.m
--- prog_io_pragma.m 28 Jun 2004 06:56:47 -0000 1.23.2.18
+++ prog_io_pragma.m 29 Jul 2004 01:49:02 -0000
@@ -27,10 +27,6 @@
:- import_module parse_tree__prog_util.
:- import_module transform_hlds__term_util, transform_hlds__term_errors.
:- import_module int, map, string, std_util, bool, require, set.
-:- import_module possible_alias.
-:- import_module possible_alias__pa_alias_as.
-:- import_module structure_reuse.
-:- import_module structure_reuse__sr_data.
parse_pragma(ModuleName, VarSet, PragmaTerms, Result) :-
(
@@ -1116,7 +1112,7 @@
HVsTypes = term__functor(term__atom("types"), ListHVTypesTerm, _),
list__map(term__coerce, ListHVTypesTerm, HVTypes ),
- sr_data__memo_reuse_parse(ReuseInformation, ParsedReuse,
+ parse_maybe_reuse_tuples(ReuseInformation, ParsedReuse,
MaybeReuseName),
Result0 = ok(pragma(structure_reuse(PredOrFunc, PredName, ModeList,
Index: sr_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_data.m,v
retrieving revision 1.1.2.32
diff -u -r1.1.2.32 sr_data.m
--- sr_data.m 28 Jul 2004 02:31:58 -0000 1.1.2.32
+++ sr_data.m 29 Jul 2004 01:49:19 -0000
@@ -26,6 +26,8 @@
%-----------------------------------------------------------------------------%
+:- type memo_reuse == maybe(list(reuse_condition)).
+
:- type reuse_condition_table ==
map(pred_proc_id, maybe(list(reuse_condition))).
:- func reuse_condition_table_init = reuse_condition_table.
@@ -36,6 +38,16 @@
reuse_condition_table::in, reuse_condition_table::out) is det.
%-----------------------------------------------------------------------------%
+ % Conversion between public/private reuse condition types.
+:- pred from_reuse_condition_to_reuse_tuple(reuse_condition::in,
+ reuse_tuple::out) is det.
+:- pred from_reuse_tuple_to_reuse_condition(reuse_tuple::in,
+ reuse_condition::out) is det.
+:- pred from_memo_reuse_to_maybe_reuse_typles(memo_reuse::in,
+ maybe_reuse_tuples::out) is det.
+:- pred from_maybe_reuse_tuples_to_memo_reuse(maybe_reuse_tuples::in,
+ memo_reuse::out) is det.
+%-----------------------------------------------------------------------------%
% The information placed in the goal info which is used by
% structure reuse.
% This field should be initilaised to empty.
@@ -105,12 +117,11 @@
:- type reuse_condition
---> always
; condition(
- nodes :: set(prog_data__datastruct),
+ nodes :: set(datastruct),
local_use_headvars :: set(prog_var),
local_alias_headvars :: alias_as
).
-:- type memo_reuse == maybe(list(reuse_condition)).
%-----------------------------------------------------------------------------%
@@ -208,7 +219,38 @@
reuse_condition_table_search(PredProcId, Table) = Table ^ elem(PredProcId).
reuse_condition_table_set(PredProcId, Conds, Table0, Table) :-
map__set(Table0, PredProcId, Conds, Table).
+%-----------------------------------------------------------------------------%
+from_reuse_condition_to_reuse_tuple(Condition, Tuple) :-
+ (
+ Condition = always,
+ Tuple = unconditional
+ ;
+ Condition = condition(Nodes, LocalUse, AliasAs),
+ from_alias_as_to_aliases_domain(AliasAs, AliasesDomain),
+ LocalUseData = set__map(pa_datastruct__init, LocalUse),
+ Tuple = conditional(Nodes, LocalUseData, AliasesDomain)
+ ).
+from_reuse_tuple_to_reuse_condition(Tuple, Condition) :-
+ (
+ Tuple = unconditional,
+ Condition = always
+ ;
+ Tuple = conditional(Nodes, LocalUseData, AliasesDomain),
+ from_aliases_domain_to_alias_as(AliasesDomain, AliasAs),
+ LocalUse = set__map(
+ (func(D) = V :-
+ V = D ^ sc_var), LocalUseData),
+ Condition = condition(Nodes, LocalUse, AliasAs)
+ ).
+from_memo_reuse_to_maybe_reuse_typles(no, no).
+from_memo_reuse_to_maybe_reuse_typles(yes(Conditions), yes(Tuples)):-
+ list__map(from_reuse_condition_to_reuse_tuple,
+ Conditions, Tuples).
+from_maybe_reuse_tuples_to_memo_reuse(no, no).
+from_maybe_reuse_tuples_to_memo_reuse(yes(Tuples), yes(Conditions)):-
+ list__map(from_reuse_tuple_to_reuse_condition,
+ Tuples, Conditions).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
/**
@@ -340,30 +382,11 @@
Cout = Cin
).
-reuse_condition_print(_, _, always) -->
- io__write_string("always").
-reuse_condition_print(ProcInfo, PredInfo, condition(Nodes, LUiH, LAiH)) -->
- { proc_info_varset(ProcInfo, ProgVarSet) },
- { pred_info_typevarset(PredInfo, TypeVarSet) },
- { set__to_sorted_list(Nodes, NodesList) },
- io__write_string("condition("),
- % write out the list of headvar-nodes involved
- io__write_string("["),
- io__write_list(NodesList, ",",
- print_datastruct(ProgVarSet, TypeVarSet)),
- io__write_string("], "),
-
- % write out LUiH, list of prog_vars
- io__write_string("["),
- { set__to_sorted_list(LUiH, ListLUiH) },
- mercury_output_vars(ListLUiH, ProgVarSet, bool__no),
- io__write_string("], "),
-
- % write out LAiH, the aliases at the reuse-point
- { from_alias_as_to_aliases_domain(LAiH, PublicLAiH) },
- print_aliases_domain(ProgVarSet, TypeVarSet, no, PublicLAiH),
-
- io__write_string(")").
+reuse_condition_print(ProcInfo, PredInfo, Condition, !IO) :-
+ proc_info_varset(ProcInfo, ProgVarSet),
+ pred_info_typevarset(PredInfo, TypeVarSet),
+ from_reuse_condition_to_reuse_tuple(Condition, Tuple),
+ print_reuse_tuple(ProgVarSet, TypeVarSet, Tuple, !IO).
reuse_condition_verify(_ProcInfo, _HLDS, _Live0, _Alias0, _Static, always).
reuse_condition_verify(ProcInfo, HLDS, Live0, Alias0, Static,
@@ -518,200 +541,20 @@
:- pred memo_reuse_print2(memo_reuse::in, maybe(sym_name)::in,
proc_info::in, pred_info::in,
io__state::di, io__state::uo) is det.
-memo_reuse_print2(MemoReuse, MaybeName, ProcInfo, PredInfo) -->
- (
- { MemoReuse = yes(Cond) }
- ->
- io__write_string("yes(["),
- io__write_list(Cond, ",",
- reuse_condition_print(ProcInfo, PredInfo)),
- io__write_string("]"),
- (
- { MaybeName = yes(Name) }
- ->
- io__write_string(","),
- prog_out__write_quoted_sym_name(Name)
- ;
- []
- ),
- io__write_string(")")
- ;
- io__write_string("no")
- ).
+memo_reuse_print2(MemoReuse, MaybeName, ProcInfo, PredInfo, !IO) :-
+ proc_info_varset(ProcInfo, ProgVarSet),
+ pred_info_typevarset(PredInfo, TypeVarSet),
+ from_memo_reuse_to_maybe_reuse_typles(MemoReuse, MaybeReuseTuples),
+ print_maybe_reuse_tuples(ProgVarSet, TypeVarSet, MaybeReuseTuples,
+ MaybeName, !IO).
memo_reuse_print_dump(MemoReuse, ProcInfo, PredInfo) -->
memo_reuse_print2(MemoReuse, no, ProcInfo, PredInfo).
memo_reuse_parse(ReuseInformation, ParsedReuse, MaybeReuseName) :-
- (
- ReuseInformation = term__functor(term__atom("no"), _, _),
- MaybeReuseName = no,
- memo_reuse_init(ParsedReuse)
- ;
- ReuseInformation = term__functor(term__atom("yes"),
- ReadConditions, _),
- conditions_list_parse(ReadConditions, Conditions, ReuseName),
- MaybeReuseName = yes(ReuseName),
- ParsedReuse = yes(Conditions)
- ).
-
-:- pred conditions_list_parse(list(term(T))::in,
- list(reuse_condition)::out, sym_name::out) is det.
-
-conditions_list_parse(ListTerm, Conds, ReuseName) :-
- (
- ListTerm = [OneItem, NameTerm]
- ->
- condition_rest_parse(OneItem, Conds),
- parse_qualified_term(NameTerm, NameTerm, "pragma reuse",
- Result),
- (Result = ok(ReuseName0, []) ->
- ReuseName = ReuseName0
- ;
- error("(sr_data) conditions_list_parse: conditions_list_parse")
- )
- ;
- list__length(ListTerm, L),
- string__int_to_string(L, LS),
- string__append_list(["(sr_data) conditions_list_parse: ",
- "wrong number of arguments. yes/", LS,
- " should be yes/2"], Msg),
- error(Msg)
- ).
-
-:- pred condition_parse(term(T)::in, reuse_condition::out) is det.
-
-condition_parse(Term, Cond) :-
- (
- Term = term__functor(term__atom(Cons), Args, _)
- ->
- (
- Cons = "condition"
- ->
- (
- Args = [NodesTerm, LUiHTerm, LAiHTerm]
- ->
- nodes_parse(NodesTerm, NodesList),
- set__list_to_set(NodesList, Nodes),
- vars_parse(LUiHTerm, LUiH),
- parse_aliases_domain(LAiHTerm,
- LAiH_Domain),
- from_aliases_domain_to_alias_as(LAiH_Domain,
- LAiH),
- Cond = condition(Nodes, LUiH, LAiH)
- ;
- list__length(Args, L),
- string__int_to_string(L, LS),
- string__append_list(
- [ "(sr_data) condition_parse: ",
- "wrong number of arguments. ",
- "condition/",LS, " should be ",
- "condition/3"], Msg),
- error(Msg)
- )
- ;
- term__det_term_to_type(Term, Type),
- varset__init(V),
- StringTerm = mercury_type_to_string(V, Type),
- string__append_list(
- ["(sr_data) condition_parse: ",
- "wrong constructur. `",
- StringTerm,
- "' should be `condition'"], Msg),
- error(Msg)
- )
- ;
- error("(sr_data) condition_parse: term is not a functor")
- ).
-
-:- pred nodes_parse(term(T)::in, list(prog_data__datastruct)::out) is det.
-
-nodes_parse(Term, Datastructs) :-
- (
- Term = term__functor(term__atom(Cons), Args, _)
- ->
- (
- Cons = "[|]",
- Args = [First, Rest]
- ->
- parse_datastruct(First, D1),
- nodes_parse(Rest, D2),
- Datastructs = [D1 | D2]
- ;
- Cons = "[]"
- ->
- Datastructs = []
- ;
- string__append("(sr_data) nodes_parse: could not parse nodes, top cons: ", Cons, Msg),
- error(Msg)
- )
- ;
- error("(sr_data) nodes_parse: term not a functor")
- ).
-
-:- pred vars_parse(term(T)::in, set(prog_var)::out) is det.
-
-vars_parse(Term, Vars) :-
- vars_parse_list(Term, VarList) ,
- set__list_to_set(VarList, Vars).
-
-:- pred vars_parse_list(term(T)::in, list(prog_var)::out) is det.
-
-vars_parse_list(Term, Vars) :-
- (
- Term = term__functor(term__atom(Cons), Args, _)
- ->
- (
- Cons = "[|]",
- Args = [First, Rest]
- ->
- (
- First = term__variable(V)
- ->
- V1 = V
- ;
- error("(sr_data) vars_parse_list: list should contain variables.")
- ),
- term__coerce_var(V1, ProgVar),
- vars_parse_list(Rest, V2),
- Vars = [ProgVar | V2]
- ;
- Cons = "[]"
- ->
- Vars = []
- ;
- string__append("(sr_data) vars_parse_list: could not parse nodes, top cons: ", Cons, Msg),
- error(Msg)
- )
- ;
- error("(sr_data) vars_parse_list: term not a functor")
- ).
-
-
-:- pred condition_rest_parse(term(T)::in, list(reuse_condition)::out) is det.
-
-condition_rest_parse(Term, Conds) :-
- (
- Term = term__functor(term__atom(Cons), Args, _)
- ->
- (
- Cons = "[|]",
- Args = [First, Rest]
- ->
- condition_parse(First, Cond1),
- condition_rest_parse(Rest, Cond2),
- Conds = [Cond1 | Cond2]
- ;
- Cons = "[]"
- ->
- Conds = []
- ;
- string__append("(sr_data) condition_rest_parse: could not parse conditions, top cons: ", Cons, Msg),
- error(Msg)
- )
- ;
- error("(sr_data) condition_rest_parse: term not a functor")
- ).
+ parse_maybe_reuse_tuples(ReuseInformation, MaybeReuseTuples,
+ MaybeReuseName),
+ from_maybe_reuse_tuples_to_memo_reuse(MaybeReuseTuples, ParsedReuse).
memo_reuse_verify_reuse(ProcInfo, HLDS, Memo, Live0, Alias0, Static) :-
Memo = yes(Conditions),
Index: sr_top.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_top.m,v
retrieving revision 1.1.2.7
diff -u -r1.1.2.7 sr_top.m
--- sr_top.m 28 Jul 2004 02:32:00 -0000 1.1.2.7
+++ sr_top.m 29 Jul 2004 01:49:19 -0000
@@ -70,6 +70,7 @@
:- import_module libs__options.
:- import_module parse_tree__mercury_to_mercury.
:- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_io_pasr.
:- import_module possible_alias__pa_sr_util.
:- import_module structure_reuse__sr_choice_util.
:- import_module structure_reuse__sr_data.
@@ -158,7 +159,8 @@
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),
+ from_memo_reuse_to_maybe_reuse_typles(Memo, MaybeReuseTuples),
+ proc_info_set_reuse_information(ProcInfo0, MaybeReuseTuples, ProcInfo),
module_info_set_pred_proc_info(!.ModuleInfo, PredProcId,
PredInfo0, ProcInfo, !:ModuleInfo).
%-----------------------------------------------------------------------------%
@@ -203,8 +205,7 @@
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),
+ Proc0, Proc, MaybeReuseConditions, !.ModuleInfo, _, !IO),
reuse_condition_table_set(proc(PredId, ProcId),
MaybeReuseConditions, !RT),
@@ -222,8 +223,8 @@
process_unproc_reuse_pragma(UnprocReusePragma, !ReuseTable,
!ModuleInfo, !IO) :-
UnprocReusePragma = unproc_reuse_pragma(PredOrFunc, SymName,
- Modes, HeadVars, Types, Reuse, _MaybeReuseName),
-
+ Modes, HeadVars, Types, MaybeReuseTuples, _MaybeReuseName),
+ from_maybe_reuse_tuples_to_memo_reuse(MaybeReuseTuples, Reuse),
globals__io_lookup_bool_option(very_verbose, VeryVerbose, !IO),
module_info_get_predicate_table(!.ModuleInfo, Preds),
@@ -376,9 +377,9 @@
},
{ module_info_pred_proc_info(HLDS, ReusePredId, ReuseProcId,
_ReusePredInfo, ReuseProcInfo) },
- { proc_info_reuse_information(ReuseProcInfo, TREUSE) },
- sr_data__memo_reuse_print(TREUSE, ReuseName, ReuseProcInfo, PredInfo) ,
-
+ { proc_info_reuse_information(ReuseProcInfo, MaybeReuseTuples) },
+ print_maybe_reuse_tuples(ProgVarset, TypeVarSet,
+ MaybeReuseTuples, yes(ReuseName)),
io__write_string(").\n").
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
--
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