[m-rev.] [reuse] diff: keeping potential_reuse information
Nancy Mazur
Nancy.Mazur at cs.kuleuven.ac.be
Sat Jun 23 00:44:36 AEST 2001
Hi,
===================================================================
Estimated hours taken: 2
Branches: reuse
Extend the reuse_goal_info with a new functor: potential_reuse/1. This
is equivalent to reuse/1. Yet, insteaf of generating reuse information
during the choice (sr_choice) and indirect reuse passes (sr_indirect),
we now generate potential_reuse information. This allows to split
procedures into reuse versions, yet keeping all the interesting reuse-related
information (lfu, lbu, dead deconstructs which lead to no reuse) within
the basic no-reuse version. This is a first step into diagnosing what
goes on when no reuse is allowed.
(In a second step, I'll be adding a full reuse-assignment pass based
on a kindof matching-solving algorithm. Diagnoses will be different, but
at least it'll be possible to start comparing).
hlds_out.m:
Consider potential_reuse as possible reuse information.
Reorder some of the code.
sr_choice.m:
sr_indirect.m:
Instead of directly generating reuse/1, generate potential_reuse/1.
sr_data.m:
Extend the reuse_goal_info type with potential_reuse/1.
sr_split.m:
When splitting procedures into their reuse/no-reuse versions
we now proceed by running over the hlds_goal of the reuse version
and substituting all potential_reuse/1 by reuse/1.
The basic no-reuse versions are then simply those versions
with possibly potential_reuse/1 annotations, instead of the
plain clean procedures as they were before reuse analysis.
This allows to check what is going on, even for procedures
which do not have any reuse.
structure_reuse.m:
No reference to the HLDS as it was before reuse analysis is needed
when splitting the procedures.
Index: hlds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_out.m,v
retrieving revision 1.243.2.20
diff -u -r1.243.2.20 hlds_out.m
--- hlds_out.m 2001/04/20 15:22:20 1.243.2.20
+++ hlds_out.m 2001/06/22 14:22:29
@@ -1162,27 +1162,40 @@
{ set__to_sorted_list(LFU, LFU_list) },
hlds_out__write_indent(Indent),
io__write_string("% lfu: "),
- mercury_output_vars(LFU_list, VarSet,
+ mercury_output_vars(LFU_list, VarSet,
AppendVarnums),
io__write_string("\n"),
{ goal_info_get_reuse(GoalInfo, REUSE) } ,
(
- { REUSE = reuse(no_reuse) ; REUSE = empty }
+ { REUSE = potential_reuse(no_reuse);
+ REUSE = reuse(no_reuse) ;
+ REUSE = empty }
->
[]
;
- hlds_out__write_indent(Indent),
- io__write_string("% reuse: "),
+ { REUSE = potential_reuse(SR) ; REUSE = reuse(SR) }
+ ->
+ hlds_out__write_indent(Indent),
+ io__write_string("% reuse"),
+ (
+ { REUSE = potential_reuse(_) }
+ ->
+ io__write_string(" (potential)")
+ ;
+ []
+ ),
+ io__write_string(": "),
(
- { REUSE = reuse(cell_died) }
- ->
+ { SR = no_reuse },
+ io__write_string("nothing.\n")
+ ;
+ { SR = cell_died },
io__write_string("cell just died (deconstruction).\n")
;
- { REUSE = reuse(cell_reused(ProgVar,
+ { SR = cell_reused(ProgVar,
IntroducesCondition,
- ConsIds, _ReuseFields)) }
- ->
+ ConsIds, _ReuseFields) },
io__write_string("cell "),
mercury_output_var(ProgVar, VarSet,
AppendVarnums),
@@ -1198,9 +1211,7 @@
),
io__nl
;
- { REUSE = reuse(
- reuse_call(IntroducesCondition)) }
- ->
+ { SR = reuse_call(IntroducesCondition) },
( { IntroducesCondition = yes } ->
io__write_string("Conditional ")
;
@@ -1208,13 +1219,12 @@
),
io__write_string("call to procedure with reuse.\n")
;
- { REUSE = reuse(missed_reuse_call(Causes)) }
- ->
+ { SR = missed_reuse_call(Causes) } ,
io__write_string("failed reuse call:\n"),
write_missed_reuse_call_text(Indent,Causes)
- ;
- { require__error("Not a legal alternative for short_reuse_info at this stage.\n") }
)
+ ;
+ []
),
{ goal_info_get_lbu(GoalInfo, Lbu) },
Index: sr_choice.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_choice.m,v
retrieving revision 1.1.2.21
diff -u -r1.1.2.21 sr_choice.m
--- sr_choice.m 2001/04/23 12:34:45 1.1.2.21
+++ sr_choice.m 2001/06/22 14:23:22
@@ -690,7 +690,8 @@
ConditionalReuse = yes
},
{ goal_info_set_reuse(GoalInfo0,
- reuse(cell_reused(ReuseVar, ConditionalReuse,
+ potential_reuse(cell_reused(ReuseVar,
+ ConditionalReuse,
ConsIds, ReuseFields)),
GoalInfo) },
ReuseConditions =^ reuse_conds,
@@ -698,7 +699,7 @@
;
{ LocalReused = LocalReused0 },
{ goal_info_set_reuse(GoalInfo0,
- reuse(no_reuse),
+ potential_reuse(no_reuse),
GoalInfo) }
),
^ local_used := LocalReused.
@@ -812,7 +813,8 @@
{ ReuseInfo = choice(deconstruct(MaybeDies)) ->
(
MaybeDies = yes(Condition),
- goal_info_set_reuse(GoalInfo0, reuse(cell_died),
+ goal_info_set_reuse(GoalInfo0,
+ potential_reuse(cell_died),
GoalInfo),
( set__member(Var, ReusedVars) ->
CanCGC = no
@@ -832,7 +834,8 @@
;
MaybeDies = no,
CanCGC = no,
- goal_info_set_reuse(GoalInfo0, reuse(no_reuse),
+ goal_info_set_reuse(GoalInfo0,
+ potential_reuse(no_reuse),
GoalInfo)
)
;
Index: sr_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_data.m,v
retrieving revision 1.1.2.17
diff -u -r1.1.2.17 sr_data.m
--- sr_data.m 2001/03/16 09:09:56 1.1.2.17
+++ sr_data.m 2001/06/22 14:23:22
@@ -24,10 +24,14 @@
% structure reuse.
% This field should be initilaised to empty.
% The sr_dead module replaces empty with choice.
- % The sr_choice module replaces choice with reuse.
+ % The sr_choice&sr_indirect module replaces choice with
+ % potential_reuse.
+ % The sr_split module replaces potential_reuse with reuse for
+ % the reuse-version of a procedure.
:- type reuse_goal_info
---> empty
; choice(choice_info)
+ ; potential_reuse(short_reuse_info)
; reuse(short_reuse_info).
:- type short_reuse_info --->
@@ -92,6 +96,13 @@
:- type memo_reuse == maybe(list(reuse_condition)).
+
+%-----------------------------------------------------------------------------%
+% small predicates for manipulating/transforming reuse_goal_info
+%-----------------------------------------------------------------------------%
+
+% :- func reuse_to_string(reuse_goal_info) = string.
+
%-----------------------------------------------------------------------------%
% reuse_condition predicates
%-----------------------------------------------------------------------------%
@@ -173,6 +184,24 @@
:- import_module pa_datastruct, pa_alias_as.
:- import_module mercury_to_mercury, prog_out, prog_io, prog_io_util.
:- import_module sr_util, pa_sr_util.
+
+%-----------------------------------------------------------------------------%
+/**
+reuse_to_string(Reuse) = String :-
+ Reuse = empty,
+ String = "empty".
+reuse_to_string(Reuse) = String :-
+ Reuse = choice(_),
+ String = "choice".
+reuse_to_string(Reuse) = String :-
+ Reuse = potential_reuse(_),
+ String = "potential_reuse".
+reuse_to_string(Reuse) = String :-
+ Reuse = reuse,
+ String = "reuse".
+**/
+%-----------------------------------------------------------------------------%
+
reuse_condition_merge(C1, C2, C):-
(
Index: sr_indirect.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_indirect.m,v
retrieving revision 1.1.2.24
diff -u -r1.1.2.24 sr_indirect.m
--- sr_indirect.m 2001/04/20 15:23:24 1.1.2.24
+++ sr_indirect.m 2001/06/22 14:23:23
@@ -514,7 +514,8 @@
Memo, LFUi, LBUi,
Alias0, ConditionalReuse, Pool0, Pool),
goal_info_set_reuse(Info0,
- reuse(reuse_call(ConditionalReuse)),
+ potential_reuse(
+ reuse_call(ConditionalReuse)),
Info),
YesNo = yes
;
@@ -526,7 +527,7 @@
Cause),
goal_info_set_reuse(Info0,
- reuse(missed_reuse_call(Cause)), Info),
+ potential_reuse(missed_reuse_call(Cause)), Info),
YesNo = no
)
).
Index: sr_split.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/sr_split.m,v
retrieving revision 1.1.2.14
diff -u -r1.1.2.14 sr_split.m
--- sr_split.m 2001/04/20 15:23:25 1.1.2.14
+++ sr_split.m 2001/06/22 14:23:24
@@ -17,12 +17,12 @@
:- import_module hlds_module, io, string.
:- import_module hlds_pred, sr_data, std_util, hlds_goal.
- % create_multiple_versions(VirginHLDS, ReuseHLDS, FinalHLDS).
+ % create_multiple_versions(ReuseHLDS, FinalHLDS).
% Starting from the VirginHLDS, it computes a new HLDS where for
% each procedure having conditional reuse (ReuseHLDS), a new
% separate reuse-procedure is added. The calls can then also
% be corrected so that they point to the correct reuse-versions.
-:- pred sr_split__create_multiple_versions(module_info::in, module_info::in,
+:- pred sr_split__create_multiple_versions(module_info::in,
module_info::out, io__state::di, io__state::uo) is det.
:- pred create_reuse_pred(pred_proc_id::in, memo_reuse::in,
@@ -46,9 +46,9 @@
reuse_predicate_name(PredName) :-
string__prefix(PredName, "reuse__").
-sr_split__create_multiple_versions(VirginHLDS, ReuseHLDS, HLDS) -->
+sr_split__create_multiple_versions(ReuseHLDS, HLDS) -->
% compute the strongly connected components
- { create_versions(VirginHLDS, ReuseHLDS, HLDS1) },
+ { create_versions(ReuseHLDS, HLDS1) },
{ reprocess_all_goals(HLDS1, HLDS) }.
% reprocess each of the procedures to make sure that all calls
@@ -104,28 +104,27 @@
).
-:- pred create_versions(module_info, module_info, module_info).
-:- mode create_versions(in, in, out) is det.
+:- pred create_versions(module_info, module_info).
+:- mode create_versions(in, out) is det.
-create_versions(VirginHLDS, ReuseHLDS, HLDS) :-
+create_versions(ReuseHLDS, HLDS) :-
module_info_predids(ReuseHLDS, PredIds),
list__foldl(
- create_versions_2(VirginHLDS),
+ create_versions_2,
PredIds,
ReuseHLDS,
HLDS).
-:- pred create_versions_2(module_info::in, pred_id::in,
+:- pred create_versions_2(pred_id::in,
module_info::in, module_info::out) is det.
-create_versions_2(VirginHLDS, PredId , HLDS0, HLDS) :-
+create_versions_2(PredId , HLDS0, HLDS) :-
module_info_pred_info(HLDS0, PredId, PredInfo0),
pred_info_procids(PredInfo0, ProcIds),
list__foldl(
pred(Id::in, H0::in, H::out) is det :-
(
- create_versions_3(VirginHLDS,
- proc(PredId, Id),
+ create_versions_3(proc(PredId, Id),
H0, H)
),
ProcIds,
@@ -133,23 +132,24 @@
HLDS
).
-:- pred create_versions_3(module_info::in, pred_proc_id::in,
+:- pred create_versions_3(pred_proc_id::in,
module_info::in, module_info::out) is det.
-create_versions_3(VirginHLDS, PredProcId, WorkingHLDS, HLDS):-
+create_versions_3(PredProcId, WorkingHLDS, HLDS):-
module_info_pred_proc_info(WorkingHLDS, PredProcId,
PredInfo0, ProcInfo0),
proc_info_reuse_information(ProcInfo0, Memo),
- module_info_pred_proc_info(VirginHLDS, PredProcId, _,
- CleanProcInfo),
+% module_info_pred_proc_info(VirginHLDS, PredProcId, _,
+% CleanProcInfo),
proc_info_goal(ProcInfo0, ReuseGoal),
(
Memo = no
->
% restore the old status of the procedure
- module_info_set_pred_proc_info(WorkingHLDS, PredProcId,
- PredInfo0, CleanProcInfo, HLDS)
+ % module_info_set_pred_proc_info(WorkingHLDS, PredProcId,
+ % PredInfo0, CleanProcInfo, HLDS)
+ HLDS = WorkingHLDS
;
(
memo_reuse_is_conditional(Memo)
@@ -242,7 +242,8 @@
proc_info_set_reuse_information(ProcInfo,
TabledReuse, ReuseProcInfo0),
(
- MaybeReuseGoal = yes(ReuseGoal),
+ MaybeReuseGoal = yes(PotReuseGoal),
+ convert_potential_reuse_to_reuse(PotReuseGoal, ReuseGoal),
proc_info_set_goal(ReuseProcInfo0, ReuseGoal, ReuseProcInfo)
;
MaybeReuseGoal = no,
@@ -276,6 +277,83 @@
ReuseProcId, ReusePredInfo).
%-----------------------------------------------------------------------------%
+
+:- pred convert_potential_reuse_to_reuse(hlds_goal::in,
+ hlds_goal::out) is det.
+convert_potential_reuse_to_reuse(Goal0 - GoalInfo0, Goal - GoalInfo) :-
+ Goal0 = conj(Goals0),
+ list__map(convert_potential_reuse_to_reuse, Goals0, Goals),
+ Goal = conj(Goals),
+ GoalInfo = GoalInfo0.
+convert_potential_reuse_to_reuse(Goal0 - GoalInfo0, Goal - GoalInfo) :-
+ Goal0 = call(_,_,_,_,_,_),
+ Goal = Goal0,
+ goal_info_get_reuse(GoalInfo0, Reuse0),
+ convert_reuse(Reuse0, Reuse),
+ goal_info_set_reuse(GoalInfo0, Reuse, GoalInfo).
+convert_potential_reuse_to_reuse(Goal0 - GoalInfo0, Goal - GoalInfo) :-
+ Goal0 = generic_call(_,_,_,_),
+ Goal = Goal0,
+ GoalInfo = GoalInfo0.
+convert_potential_reuse_to_reuse(Goal0 - GoalInfo0, Goal - GoalInfo) :-
+ Goal0 = switch(X,Y,Cases0,Z),
+ list__map(
+ pred(C0::in, C::out) is det:-
+ ( C0 = case(Id, G0),
+ convert_potential_reuse_to_reuse(G0, G),
+ C = case(Id, G)),
+ Cases0,
+ Cases),
+ Goal = switch(X, Y, Cases, Z),
+ GoalInfo = GoalInfo0.
+convert_potential_reuse_to_reuse(Goal0 - GoalInfo0, Goal - GoalInfo) :-
+ Goal0 = unify(_,_,_,_,_),
+ Goal = Goal0,
+ goal_info_get_reuse(GoalInfo0, Reuse0),
+ convert_reuse(Reuse0,Reuse),
+ goal_info_set_reuse(GoalInfo0, Reuse, GoalInfo).
+convert_potential_reuse_to_reuse(Goal0 - GoalInfo0, Goal - GoalInfo) :-
+ Goal0 = disj(Goals0, SM),
+ list__map(convert_potential_reuse_to_reuse, Goals0, Goals),
+ Goal = disj(Goals, SM),
+ GoalInfo = GoalInfo0.
+convert_potential_reuse_to_reuse(Goal0 - GoalInfo0, Goal - GoalInfo) :-
+ Goal0 = not(NegGoal0),
+ convert_potential_reuse_to_reuse(NegGoal0, NegGoal),
+ Goal = not(NegGoal),
+ GoalInfo = GoalInfo0.
+convert_potential_reuse_to_reuse(Goal0 - GoalInfo0, Goal - GoalInfo) :-
+ Goal0 = some(A, B, SG0),
+ convert_potential_reuse_to_reuse(SG0, SG),
+ Goal = some(A, B, SG),
+ GoalInfo = GoalInfo0.
+convert_potential_reuse_to_reuse(Goal0 - GoalInfo0, Goal - GoalInfo) :-
+ Goal0 = if_then_else(A, If0, Then0, Else0, B),
+ convert_potential_reuse_to_reuse(If0, If),
+ convert_potential_reuse_to_reuse(Then0, Then),
+ convert_potential_reuse_to_reuse(Else0, Else),
+ Goal = if_then_else(A, If, Then, Else, B),
+ GoalInfo0 = GoalInfo.
+convert_potential_reuse_to_reuse(Goal0 - GoalInfo0, Goal - GoalInfo) :-
+ Goal0 = foreign_proc(_,_,_,_,_,_,_),
+ Goal = Goal0,
+ GoalInfo = GoalInfo0.
+convert_potential_reuse_to_reuse(Goal0 - GoalInfo0, Goal - GoalInfo) :-
+ Goal0 = par_conj(_,_),
+ Goal = Goal0,
+ GoalInfo = GoalInfo0.
+convert_potential_reuse_to_reuse(Goal0 - GoalInfo0, Goal - GoalInfo) :-
+ Goal0 = shorthand(_),
+ Goal = Goal0,
+ GoalInfo = GoalInfo0.
+
+:- pred convert_reuse(reuse_goal_info::in, reuse_goal_info::out) is det.
+convert_reuse(R0, R):- R0 = empty, R = R0.
+convert_reuse(R0, _R):- R0 = choice(_),
+ error("(sr_split) convert_reuse: reuse_goal_info should not be choice/1 at this stage. ").
+convert_reuse(R0, R):- R0 = potential_reuse(S), R = reuse(S).
+convert_reuse(R0, R):- R0 = reuse(_), R = R0.
+
%-----------------------------------------------------------------------------%
:- pred process_goal(bool::in, hlds_goal::in, hlds_goal::out,
module_info::in, module_info::out) is det.
Index: structure_reuse.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Attic/structure_reuse.m,v
retrieving revision 1.1.2.8
diff -u -r1.1.2.8 structure_reuse.m
--- structure_reuse.m 2001/02/07 10:19:12 1.1.2.8
+++ structure_reuse.m 2001/06/22 14:23:25
@@ -71,7 +71,7 @@
% Do the fixpoint computation to determine all the indirect
% reuse, and the implied conditions.
sr_indirect__compute_fixpoint(HLDS1, HLDS2),
- sr_split__create_multiple_versions(HLDS0, HLDS2, HLDS),
+ sr_split__create_multiple_versions(HLDS2, HLDS),
sr_profile_run__structure_reuse_profiling(HLDS).
--------------------------------------------------------------------------
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