[m-rev.] for review: [CTGC] add pragma structure_reuse and related public types
Nancy Mazur
Nancy.Mazur at cs.kuleuven.ac.be
Mon May 1 18:54:24 AEST 2006
Hi,
here is a small diff which adds the structure_reuse pragma to the known set of
pragma's.
I hope to have my new PC very soon, as my laptop can't handle the mercury
compiler anymore without overheating, the poor lad. A full compilation takes
two meltdowns ;-)
Nancy
===================================================================
Estimated hours taken: 1
Branches: reuse
Add structure_reuse pragma (prog_item.m) and related types (prog_data.m).
compiler/prog_data.m:
Add reuse_tuple and reuse_tuples as public representations for
reuse conditions needed in the CTGC system.
compiler/prog_ctgc.m:
Add parsing and printing routines for reuse_tuple(s).
compiler/prog_item.m:
compiler/add_pragma.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.version.m:
Add pragma structure_reuse/7.
Index: compiler/add_pragma.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/add_pragma.m,v
retrieving revision 1.31
diff -u -d -r1.31 add_pragma.m
--- compiler/add_pragma.m 26 Apr 2006 03:05:30 -0000 1.31
+++ compiler/add_pragma.m 1 May 2006 08:43:55 -0000
@@ -303,6 +303,8 @@
;
Pragma = structure_sharing(_, _, _, _, _, _)
;
+ Pragma = structure_reuse(_, _, _, _, _, _, _)
+ ;
Pragma = mode_check_clauses(Name, Arity),
add_pred_marker("mode_check_clauses", Name, Arity, ImportStatus,
Context, mode_check_clauses, [], !ModuleInfo, !IO),
Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.289
diff -u -d -r1.289 mercury_to_mercury.m
--- compiler/mercury_to_mercury.m 29 Mar 2006 08:07:01 -0000 1.289
+++ compiler/mercury_to_mercury.m 1 May 2006 08:44:06 -0000
@@ -661,6 +661,8 @@
write_pragma_structure_sharing_info(PredOrFunc, PredName, ModesList,
Context, HeadVars, no, Types, no, MaybeStructureSharing, !IO)
;
+ Pragma = structure_reuse(_, _, _, _, _, _, _)
+ ;
Pragma = mode_check_clauses(Pred, Arity),
mercury_output_pragma_decl(Pred, Arity, predicate,
"mode_check_clauses", no, !IO)
Index: compiler/module_qual.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/module_qual.m,v
retrieving revision 1.132
diff -u -d -r1.132 module_qual.m
--- compiler/module_qual.m 20 Apr 2006 05:36:57 -0000 1.132
+++ compiler/module_qual.m 1 May 2006 08:44:11 -0000
@@ -1112,6 +1112,12 @@
structure_sharing(PredOrFunc, SymName, ModeList, Vars, Types, Sharing),
!Info, !IO) :-
qualify_mode_list(ModeList0, ModeList, !Info, !IO).
+qualify_pragma(structure_reuse(PredOrFunc, SymName, ModeList0, Vars, Types,
+ ReuseTuples, ReuseName),
+ structure_reuse(PredOrFunc, SymName, ModeList, Vars, Types,
+ ReuseTuples, ReuseName),
+ !Info, !IO) :-
+ qualify_mode_list(ModeList0, ModeList, !Info, !IO).
qualify_pragma(termination2_info(PredOrFunc, SymName, ModeList0,
SuccessArgs, FailureArgs, Term),
termination2_info(PredOrFunc, SymName, ModeList,
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.389
diff -u -d -r1.389 modules.m
--- compiler/modules.m 27 Apr 2006 07:34:30 -0000 1.389
+++ compiler/modules.m 1 May 2006 08:44:33 -0000
@@ -2132,6 +2132,7 @@
pragma_allowed_in_interface(does_not_terminate(_, _), yes).
pragma_allowed_in_interface(check_termination(_, _), yes).
pragma_allowed_in_interface(structure_sharing(_, _, _, _, _, _), yes).
+pragma_allowed_in_interface(structure_reuse(_, _, _, _, _, _, _), yes).
pragma_allowed_in_interface(mode_check_clauses(_, _), yes).
check_for_no_exports(Items, ModuleName, !IO) :-
@@ -7666,6 +7667,7 @@
; Pragma = termination2_info(_, _, _, _, _, _), Reorderable = no
; Pragma = termination_info(_, _, _, _, _), Reorderable = yes
; Pragma = structure_sharing(_, _, _, _, _, _), Reorderable = yes
+ ; Pragma = structure_reuse(_, _, _, _, _, _, _), Reorderable = yes
; Pragma = type_spec(_, _, _, _, _, _, _, _), Reorderable = yes
; Pragma = unused_args(_, _, _, _, _), Reorderable = yes
).
@@ -7746,6 +7748,7 @@
; Pragma = termination2_info( _, _, _, _, _, _), Reorderable = no
; Pragma = termination_info(_, _, _, _, _), Reorderable = yes
; Pragma = structure_sharing(_, _, _, _, _, _), Reorderable = yes
+ ; Pragma = structure_reuse(_, _, _, _, _, _, _), Reorderable = yes
; Pragma = trailing_info(_, _, _, _, _), Reorderable = yes
; Pragma = type_spec(_, _, _, _, _, _, _, _), Reorderable = yes
; Pragma = unused_args(_, _, _, _, _), Reorderable = yes
Index: compiler/prog_ctgc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_ctgc.m,v
retrieving revision 1.6
diff -u -d -r1.6 prog_ctgc.m
--- compiler/prog_ctgc.m 29 Mar 2006 08:07:16 -0000 1.6
+++ compiler/prog_ctgc.m 1 May 2006 08:44:34 -0000
@@ -22,6 +22,7 @@
:- import_module bool.
:- import_module int.
:- import_module io.
+:- import_module list.
:- import_module map.
:- import_module maybe.
:- import_module term.
@@ -38,6 +39,9 @@
:- func parse_structure_sharing(term(T)) = structure_sharing.
:- func parse_structure_sharing_domain(term(T)) = structure_sharing_domain.
+:- func parse_reuse_tuple(term(T)) = reuse_tuple.
+:- func parse_reuse_tuples(term(T)) = reuse_tuples.
+
%-----------------------------------------------------------------------------%
%
% Printing routines
@@ -48,6 +52,9 @@
:- pred print_datastruct(prog_varset::in, tvarset::in, datastruct::in,
io::di, io::uo) is det.
+:- pred print_datastructs(prog_varset::in, tvarset::in, list(datastruct)::in,
+ io::di, io::uo) is det.
+
:- pred print_structure_sharing_pair(prog_varset::in, tvarset::in,
structure_sharing_pair::in, io::di, io::uo) is det.
@@ -98,6 +105,15 @@
:- pred print_interface_structure_sharing_domain(prog_varset::in,
tvarset::in, maybe(structure_sharing_domain)::in, io::di, io::uo) is det.
+:- pred print_reuse_tuple(prog_varset::in, tvarset::in, reuse_tuple::in,
+ io::di, io::uo) is det.
+
+:- pred print_reuse_tuples(prog_varset::in, tvarset::in, reuse_tuples::in,
+ io::di, io::uo) is det.
+
+:- pred print_interface_maybe_reuse_tuples(prog_varset::in, tvarset::in,
+ maybe(reuse_tuples)::in, io::di, io::uo) is det.
+
%-----------------------------------------------------------------------------%
%
% Renaming operations
@@ -132,7 +148,6 @@
:- import_module parse_tree.prog_type_subst.
:- import_module parse_tree.prog_util.
-:- import_module list.
:- import_module string.
:- import_module pair.
:- import_module varset.
@@ -227,6 +242,30 @@
"parse_datastruct: error while parsing datastruct.")
).
+:- func parse_datastruct_list(term(T)) = list(datastruct).
+
+parse_datastruct_list(Term) = Datastructs :-
+ (
+ Term = term.functor(term.atom(Cons), Args, _)
+ ->
+ (
+ Cons = "[|]",
+ Args = [FirstDataTerm, RestDataTerm]
+ ->
+ Datastructs = [parse_datastruct(FirstDataTerm)|
+ parse_datastruct_list(RestDataTerm)]
+ ;
+ Cons = "[]"
+ ->
+ Datastructs = []
+ ;
+ unexpected(this_file, "Error while parsing list of datastructs.")
+ )
+ ;
+ unexpected(this_file, "Error while parsing list of datastructs " ++
+ "(term not a functor).")
+ ).
+
parse_structure_sharing_pair(Term) = SharingPair :-
(
Term = term.functor(term.atom(Cons), Args, _),
@@ -277,6 +316,54 @@
unexpected(this_file, "Error while parsing structure sharing domain.")
).
+
+parse_reuse_tuple(Term) = ReuseTuple :-
+ (
+ Term = term.functor(term.atom(Cons), Args, _)
+ ->
+ (
+ Cons = "condition",
+ Args = [DeadNodesTerm, InUseNodesTerm, SharingTerm]
+ ->
+ DeadNodes = parse_datastruct_list(DeadNodesTerm),
+ InUseNodes = parse_datastruct_list(InUseNodesTerm),
+ Sharing = parse_structure_sharing_domain(SharingTerm),
+ ReuseTuple = conditional(DeadNodes, InUseNodes, Sharing)
+ ;
+ Cons = "unconditional"
+ ->
+ ReuseTuple = unconditional
+ ;
+ unexpected(this_file, "Error while parsing reuse tuple.")
+ )
+ ;
+ unexpected(this_file, "Error while parsing reuse tuple " ++
+ "(term not a functor).")
+ ).
+
+parse_reuse_tuples(Term) = ReuseTuples :-
+ (
+ Term = term.functor(term.atom(Cons), Args, _)
+ ->
+ (
+ Cons = "[|]",
+ Args = [FirstTupleTerm, RestTuplesTerm]
+ ->
+ ReuseTuples = [parse_reuse_tuple(FirstTupleTerm)|
+ parse_reuse_tuples(RestTuplesTerm)]
+ ;
+ Cons = "[]"
+ ->
+ ReuseTuples = []
+ ;
+ unexpected(this_file, "Error while parsing list of reuse tuples.")
+ )
+ ;
+ unexpected(this_file, "Error while parsing list of reuse tuples " ++
+ "(term not a functor).")
+ ).
+
+
%-----------------------------------------------------------------------------%
%
% Printing routines
@@ -321,6 +408,12 @@
print_selector(TypeVarSet, DataStruct^sc_selector, !IO),
io.write_string(")", !IO).
+print_datastructs(ProgVarSet, TypeVarSet, Datastructs, !IO) :-
+ io.write_string("[", !IO),
+ io.write_list(Datastructs, ",", print_datastruct(ProgVarSet, TypeVarSet),
+ !IO),
+ io.write_string("]", !IO).
+
print_structure_sharing_pair(ProgVarSet, TypeVarSet, SharingPair, !IO) :-
SharingPair = D1 - D2,
io.write_string("pair(", !IO),
@@ -407,6 +500,37 @@
io.write_string("yes(", !IO),
print_structure_sharing_domain(ProgVarSet, TypeVarSet, no, no, SharingAs,
!IO),
+ io.write_string(")", !IO).
+
+print_reuse_tuple(ProgVarSet, TypeVarSet, ReuseTuple, !IO) :-
+ (
+ ReuseTuple = unconditional,
+ io.write_string("unconditional", !IO)
+ ;
+ ReuseTuple = conditional(DeadNodes, InUseNodes, Sharing),
+ io.write_string("conditional(", !IO),
+ print_datastructs(ProgVarSet, TypeVarSet, DeadNodes, !IO),
+ io.write_string(",", !IO),
+ print_datastructs(ProgVarSet, TypeVarSet, InUseNodes, !IO),
+ io.write_string(",", !IO),
+ print_structure_sharing_domain(ProgVarSet, TypeVarSet, no, no,
+ Sharing, !IO),
+ io.write_string(")", !IO)
+ ).
+
+print_reuse_tuples(ProgVarSet, TypeVarSet, ReuseTuples, !IO) :-
+ io.write_string("[", !IO),
+ io.write_list(ReuseTuples, ",", print_reuse_tuple(ProgVarSet, TypeVarSet),
+ !IO),
+ io.write_string("]", !IO).
+
+print_interface_maybe_reuse_tuples(_, _, no, !IO) :-
+ io.write_string("not_available", !IO).
+
+print_interface_maybe_reuse_tuples(ProgVarSet, TypeVarSet,
+ yes(ReuseTuples), !IO) :-
+ io.write_string("yes(", !IO),
+ print_reuse_tuples(ProgVarSet, TypeVarSet, ReuseTuples, !IO),
io.write_string(")", !IO).
%-----------------------------------------------------------------------------%
Index: compiler/prog_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.160
diff -u -d -r1.160 prog_data.m
--- compiler/prog_data.m 26 Apr 2006 03:05:39 -0000 1.160
+++ compiler/prog_data.m 1 May 2006 08:44:39 -0000
@@ -354,6 +354,35 @@
%-----------------------------------------------------------------------------%
%
+% Stuff for the `structure_reuse_info' pragma.
+%
+
+ % A reuse-tuple is used to describe the condition for which reuse
+ % within a particular procedure is allowed.
+:- type reuse_tuple
+ ---> unconditional
+ ; conditional(
+ reuse_nodes :: list(datastruct),
+ % The set of datastructures pointing to the memory that
+ % becomes 'dead' and thus will be reused. This set is
+ % restricted to the head variables of the involved
+ % procedure.
+ live_headvars :: list(datastruct),
+ % The set of datastructures inherently live at the moment
+ % where the reuse_nodes become dead. This set is
+ % restricted to the head variables of the procedure the
+ % reuse condition refers to.
+ sharing_headvars :: structure_sharing_domain
+ % Description of the structure sharing existing at the
+ % moment where the reuse_nodes become dead. The sharing is
+ % also restricted to the headvariables of the concerned
+ % procedure.
+ ).
+
+:- type reuse_tuples == list(reuse_tuple).
+
+%-----------------------------------------------------------------------------%
+%
% Stuff for the `unused_args' pragma
%
Index: compiler/prog_item.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_item.m,v
retrieving revision 1.12
diff -u -d -r1.12 prog_item.m
--- compiler/prog_item.m 27 Apr 2006 07:34:31 -0000 1.12
+++ compiler/prog_item.m 1 May 2006 08:44:41 -0000
@@ -608,7 +608,24 @@
%
% The list of modes consists of the declared argmodes (or inferred
% argmodes if there are no declared ones).
-
+ ;
+ structure_reuse(
+ reuse_p_or_f :: pred_or_func,
+ reuse_name :: sym_name,
+ reuse_mode :: list(mer_mode),
+ reuse_headvars :: prog_vars,
+ reuse_headvartypes :: list(mer_type),
+ reuse_description :: maybe(reuse_tuples),
+ reuse_optimised_name :: maybe(sym_name)
+ )
+ % After reuse analysis, the compiler generates structure reuse
+ % pragmas to be stored in and read from optimization interface
+ % files.
+ %
+ % The list of modes consists of the declared argmodes (or inferred
+ % argmodes if there are no declared ones).
+ % The last sym_name (reuse_optimised_name) stores the name of the
+ % optimised version of the exported predicate.
.
%-----------------------------------------------------------------------------%
Index: compiler/recompilation.version.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/recompilation.version.m,v
retrieving revision 1.44
diff -u -d -r1.44 recompilation.version.m
--- compiler/recompilation.version.m 20 Apr 2006 05:37:01 -0000 1.44
+++ compiler/recompilation.version.m 1 May 2006 08:44:44 -0000
@@ -594,6 +594,9 @@
is_pred_pragma(structure_sharing(PredOrFunc, Name, Modes, _, _, _),
yes(yes(PredOrFunc) - Name / Arity)) :-
adjust_func_arity(PredOrFunc, Arity, list.length(Modes)).
+is_pred_pragma(structure_reuse(PredOrFunc, Name, Modes, _, _, _, _),
+ yes(yes(PredOrFunc) - Name / Arity)) :-
+ adjust_func_arity(PredOrFunc, Arity, list.length(Modes)).
is_pred_pragma(termination2_info(PredOrFunc, Name, Modes, _, _, _),
yes(yes(PredOrFunc) - Name / Arity)) :-
adjust_func_arity(PredOrFunc, Arity, list.length(Modes)).
--
nancy.mazur at cs.kuleuven.ac.be ------------ Katholieke Universiteit Leuven -
tel: +32-16-327596 - fax: +32-16-327996 ------- Dept. of Computer Science -
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
--------------------------------------------------------------------------
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