[m-rev.] diff: remove redundant reuse conditions
Peter Wang
novalazy at gmail.com
Mon Jun 30 17:44:22 AEST 2008
Branches: main
Revert `reuse_conditions_add_condition' to only add a new condition to a set
if the new condition is not 'subsumed' by existing conditions. This was
commented out because, with the existing definition of reuse condition
subsumption, it caused the test case bad_indirect_reuse.m to fail. However it
also made reuse conditions unnecessarily big, which is especially important
for standard library modules whose `.analysis' files are read and parsed many
times.
compiler/structure_reuse.domain.m:
Change `reuse_condition_subsumed_by' to use a subset relation between
the dead nodes of a condition, instead of datastruct subsumption.
compiler/prog_data.m:
Change the `dead_datastructs' type to a set instead of a list.
compiler/prog_ctgc.m:
Conform to `dead_datastructs' change.
Index: compiler/prog_ctgc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_ctgc.m,v
retrieving revision 1.19
diff -u -p -r1.19 prog_ctgc.m
--- compiler/prog_ctgc.m 11 Apr 2008 03:40:15 -0000 1.19
+++ compiler/prog_ctgc.m 30 Jun 2008 07:43:11 -0000
@@ -365,7 +365,8 @@ parse_structure_reuse_condition(Term) =
Cons = "condition",
Args = [DeadNodesTerm, InUseNodesTerm, SharingTerm]
->
- DeadNodes = parse_datastruct_list(DeadNodesTerm),
+ DeadNodesList = parse_datastruct_list(DeadNodesTerm),
+ DeadNodes = set.from_list(DeadNodesList),
InUseNodes = parse_datastruct_list(InUseNodesTerm),
Sharing = parse_structure_sharing_domain(SharingTerm),
ReuseCondition = structure_reuse_condition(DeadNodes,
@@ -660,8 +661,9 @@ dump_maybe_structure_reuse_domain(ProgVa
print_structure_reuse_condition(ProgVarSet, TypeVarSet, ReuseCond, !IO) :-
ReuseCond = structure_reuse_condition(DeadNodes, InUseNodes, Sharing),
+ DeadNodesList = set.to_sorted_list(DeadNodes),
io.write_string("condition(", !IO),
- print_datastructs(ProgVarSet, TypeVarSet, DeadNodes, !IO),
+ print_datastructs(ProgVarSet, TypeVarSet, DeadNodesList, !IO),
io.write_string(", ", !IO),
print_datastructs(ProgVarSet, TypeVarSet, InUseNodes, !IO),
io.write_string(", ", !IO),
@@ -787,7 +789,7 @@ rename_user_annotated_sharing(HeadVars,
rename_structure_reuse_condition(Dict, TypeSubst,
structure_reuse_condition(DeadNodes, LiveNodes, Sharing),
structure_reuse_condition(RenDeadNodes, RenLiveNodes, RenSharing)) :-
- RenDeadNodes = list.map(rename_datastruct(Dict, TypeSubst), DeadNodes),
+ RenDeadNodes = set.map(rename_datastruct(Dict, TypeSubst), DeadNodes),
RenLiveNodes = list.map(rename_datastruct(Dict, TypeSubst), LiveNodes),
rename_structure_sharing_domain(Dict, TypeSubst, Sharing, RenSharing).
Index: compiler/prog_data.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.212
diff -u -p -r1.212 prog_data.m
--- compiler/prog_data.m 28 May 2008 05:26:51 -0000 1.212
+++ compiler/prog_data.m 30 Jun 2008 07:43:11 -0000
@@ -432,7 +432,7 @@
:- type dead_var == prog_var.
:- type dead_vars == list(dead_var).
:- type dead_datastruct == datastruct.
-:- type dead_datastructs == list(dead_datastruct).
+:- type dead_datastructs == set(dead_datastruct).
:- type live_var == prog_var.
:- type live_vars == list(live_var).
:- type live_datastruct == datastruct.
Index: compiler/structure_reuse.domain.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/structure_reuse.domain.m,v
retrieving revision 1.16
diff -u -p -r1.16 structure_reuse.domain.m
--- compiler/structure_reuse.domain.m 28 May 2008 00:52:29 -0000 1.16
+++ compiler/structure_reuse.domain.m 30 Jun 2008 07:43:11 -0000
@@ -360,7 +360,8 @@ reuse_condition_init(ModuleInfo, ProcInf
structure_sharing.domain.sharing_as_project(HeadVars, Sharing,
HeadVarSharing),
- Condition = condition(Nodes, HeadVarSharedLU, HeadVarSharing)
+ Condition = condition(set.from_list(Nodes), HeadVarSharedLU,
+ HeadVarSharing)
).
reuse_condition_is_conditional(condition(_, _, _)).
@@ -373,7 +374,19 @@ reuse_condition_subsumed_by(ModuleInfo,
;
Cond1 = condition(Nodes1, LocalUse1, LocalSharing1),
Cond2 = condition(Nodes2, LocalUse2, LocalSharing2),
- datastructs_subsumed_by_list(ModuleInfo, ProcInfo, Nodes1, Nodes2),
+
+ % XXX this was Nancy's implementation, but bad_indirect_reuse.m is
+ % broken when using this definition. --pw
+ %
+ % datastructs_subsumed_by_list(ModuleInfo, ProcInfo, Nodes1, Nodes2),
+ %
+ % That seems to match the theory, but doesn't make sense to me: if you
+ % satisfy a condition that allows you to clobber the top-cell
+ % `selected_cel(V, [])', it doesn't mean you're free to clobber a cell
+ % beneath that, say `selected_cel(V, [termsel(f, 1)])'.
+ %
+ set.subset(Nodes1, Nodes2),
+
datastructs_subsumed_by_list(ModuleInfo, ProcInfo, LocalUse1,
LocalUse2),
sharing_as_is_subsumed_by(ModuleInfo,
@@ -400,7 +413,7 @@ reuse_condition_rename(MapVar, TypeSubst
RenamedCondition = always
;
Condition = condition(DeadNodes, InUseNodes, LocalSharing),
- RenamedDeadNodes = list.map(rename_datastruct(MapVar, TypeSubst),
+ RenamedDeadNodes = set.map(rename_datastruct(MapVar, TypeSubst),
DeadNodes),
RenamedInUseNodes = list.map(rename_datastruct(MapVar, TypeSubst),
InUseNodes),
@@ -523,13 +536,11 @@ reuse_as_add_unconditional(!ReuseAs) :-
:- pred reuse_conditions_add_condition(module_info::in, proc_info::in,
reuse_condition::in, reuse_conditions::in, reuse_conditions::out) is det.
-reuse_conditions_add_condition(_ModuleInfo, _ProcInfo, Condition, !Conds):-
+reuse_conditions_add_condition(ModuleInfo, ProcInfo, Condition, !Conds):-
(
- % XXX this used to check if Condition was subsumed by !.Conds, but
- % that can produce conditions which are too weak, I think.
- % The test suite has an example of this. --pw
- list.member(Condition, !.Conds)
- ->
+ reuse_condition_subsumed_by_list(ModuleInfo, ProcInfo,
+ Condition, !.Conds)
+ ->
true
;
!:Conds = [Condition | !.Conds]
@@ -619,7 +630,7 @@ reuse_condition_from_called_proc_to_loca
% Translate the dead nodes:
AllDeadNodes = extend_datastructs(ModuleInfo, ProcInfo,
- SharingAs, CalledDeadNodes),
+ SharingAs, set.to_sorted_list(CalledDeadNodes)),
AllDeadHeadVarNodes = datastructs_project(HeadVars, AllDeadNodes),
(
@@ -639,7 +650,7 @@ reuse_condition_from_called_proc_to_loca
AllHeadVarLocalSharing = sharing_as_project(HeadVars,
AllLocalSharing),
- LocalCondition = condition(AllDeadHeadVarNodes,
+ LocalCondition = condition(set.from_list(AllDeadHeadVarNodes),
AllInUseHeadVarNodes, AllHeadVarLocalSharing)
)
).
@@ -732,7 +743,8 @@ reuse_as_satisfied_2(ModuleInfo, ProcInf
aliases_between_reuse_nodes(ModuleInfo, ProcInfo, SharingAs, Conditions,
AliasedVars) :-
list.filter_map(reuse_condition_reusable_nodes, Conditions, ListNodes),
- list.condense(ListNodes, AllNodes),
+ AllNodes0 = set.union_list(ListNodes),
+ AllNodes = set.to_sorted_list(AllNodes0),
(
AllNodes = [Node | Rest],
aggregate(aliases_between_reuse_nodes_2(ModuleInfo, ProcInfo,
@@ -805,7 +817,9 @@ reuse_condition_satisfied(ModuleInfo, Pr
Condition = always,
Result = reuse_possible
;
- Condition = condition(DeadNodes, InUseNodes, SharingNodes),
+ Condition = condition(DeadNodes0, InUseNodes, SharingNodes),
+ DeadNodes = set.to_sorted_list(DeadNodes0),
+
% Reuse of static vars is not allowed:
StaticDeadNodes = datastructs_project(StaticVars, DeadNodes),
(
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list