[m-rev.] for post-commit review: cleanup of rbmm modules
Zoltan Somogyi
zs at csse.unimelb.edu.au
Mon Jul 23 15:05:33 AEST 2007
For post-commit review by Quan.
Zoltan.
compiler/rbmm.*.m:
Fix deviations from our style guides, including tabs, line lengths and
inconsistent indentation.
cvs diff: Diffing .
Index: rbmm.actual_region_arguments.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.actual_region_arguments.m,v
retrieving revision 1.2
diff -u -b -r1.2 rbmm.actual_region_arguments.m
Index: rbmm.condition_renaming.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.condition_renaming.m,v
retrieving revision 1.4
diff -u -b -r1.4 rbmm.condition_renaming.m
--- rbmm.condition_renaming.m 20 Jul 2007 08:09:53 -0000 1.4
+++ rbmm.condition_renaming.m 23 Jul 2007 04:16:07 -0000
@@ -52,19 +52,19 @@
:- type goal_path_regions_table == map(goal_path, set(string)).
% This predicate collects two pieces of information.
+ %
% 1. The non-local regions of if-then-elses.
- % A region is non-local to an if-then-else if the region
- % is created in the if-then-else and outlives the scope
- % of the if-then-else.
+ % A region is non-local to an if-then-else if the region is created
+ % in the if-then-else and outlives the scope of the if-then-else.
% 2. The regions which are created (get bound) in the condition
% goals of if-then-else.
+ %
% We will only store information about a procedure if the information
% exists. That means, for example, there is no entry which maps a PPId
% to empty.
%
- % This information is used to compute the regions which need to be
- % renamed, i.e., both non-local and created in the condition of an
- % if-then-else.
+ % This information is used to compute the regions which need to be renamed,
+ % i.e., both non-local and created in the condition of an if-then-else.
%
:- pred collect_non_local_and_in_cond_regions(module_info::in,
rpta_info_table::in, proc_pp_region_set_table::in,
@@ -203,13 +203,11 @@
map.init, InCondRegionsProc),
( if map.count(NonLocalRegionsProc) = 0
then true
- else svmap.set(PPId, NonLocalRegionsProc,
- !NonLocalRegionsTable)
+ else svmap.set(PPId, NonLocalRegionsProc, !NonLocalRegionsTable)
),
( if map.count(InCondRegionsProc) = 0
then true
- else svmap.set(PPId, InCondRegionsProc,
- !InCondRegionsTable)
+ else svmap.set(PPId, InCondRegionsProc, !InCondRegionsTable)
)
).
@@ -236,10 +234,10 @@
collect_non_local_and_in_cond_regions_expr(Graph, LRBeforeProc, LRAfterProc,
ResurRenamingProc, ResurRenamingAnnoProc, conj(_, Conjs),
!NonLocalRegionsProc, !InCondRegionsProc) :-
- list.foldl2(collect_non_local_and_in_cond_regions_goal(Graph,
+ list.foldl2(
+ collect_non_local_and_in_cond_regions_goal(Graph,
LRBeforeProc, LRAfterProc,
- ResurRenamingProc,
- ResurRenamingAnnoProc),
+ ResurRenamingProc, ResurRenamingAnnoProc),
Conjs, !NonLocalRegionsProc, !InCondRegionsProc).
collect_non_local_and_in_cond_regions_expr(_, _, _, _, _,
@@ -255,18 +253,18 @@
collect_non_local_and_in_cond_regions_expr(Graph, LRBeforeProc, LRAfterProc,
ResurRenamingProc, ResurRenamingAnnoProc, switch(_, _, Cases),
!NonLocalRegionsProc, !InCondRegionsProc) :-
- list.foldl2(collect_non_local_and_in_cond_regions_case(Graph,
+ list.foldl2(
+ collect_non_local_and_in_cond_regions_case(Graph,
LRBeforeProc, LRAfterProc,
- ResurRenamingProc,
- ResurRenamingAnnoProc),
+ ResurRenamingProc, ResurRenamingAnnoProc),
Cases, !NonLocalRegionsProc, !InCondRegionsProc).
collect_non_local_and_in_cond_regions_expr(Graph, LRBeforeProc, LRAfterProc,
ResurRenamingProc, ResurRenamingAnnoProc, disj(Disjs),
!NonLocalRegionsProc, !InCondRegionsProc) :-
- list.foldl2(collect_non_local_and_in_cond_regions_goal(Graph,
+ list.foldl2(
+ collect_non_local_and_in_cond_regions_goal(Graph,
LRBeforeProc, LRAfterProc,
- ResurRenamingProc,
- ResurRenamingAnnoProc),
+ ResurRenamingProc, ResurRenamingAnnoProc),
Disjs, !NonLocalRegionsProc, !InCondRegionsProc).
collect_non_local_and_in_cond_regions_expr(Graph, LRBeforeProc, LRAfterProc,
ResurRenamingProc, ResurRenamingAnnoProc, negation(Goal),
@@ -291,22 +289,21 @@
% We only care about regions created inside condition goals.
collect_regions_created_in_condition(Graph, LRBeforeProc, LRAfterProc,
- ResurRenamingProc, ResurRenamingAnnoProc, Cond,
- !InCondRegionsProc),
+ ResurRenamingProc, ResurRenamingAnnoProc, Cond, !InCondRegionsProc),
% The sets of non_local regions in the (Cond, Then) and in the (Else)
% branch are the same, therefore we will only calculate in one of them.
% As it is here, we calculate for (Else) with the hope that it is
% usually more efficient (only Else compared to both Cond and Then).
- collect_non_local_and_in_cond_regions_goal(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
+ collect_non_local_and_in_cond_regions_goal(Graph,
+ LRBeforeProc, LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
Cond, !NonLocalRegionProc, !InCondRegionsProc),
- collect_non_local_and_in_cond_regions_goal(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
+ collect_non_local_and_in_cond_regions_goal(Graph,
+ LRBeforeProc, LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
Then, !NonLocalRegionProc, !InCondRegionsProc),
- collect_non_local_regions_in_ite(Graph, LRBeforeProc, LRAfterProc,
- ResurRenamingProc, ResurRenamingAnnoProc, Else,
- !NonLocalRegionProc).
+ collect_non_local_regions_in_ite(Graph,
+ LRBeforeProc, LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
+ Else, !NonLocalRegionProc).
collect_non_local_and_in_cond_regions_expr(_, _, _, _, _, shorthand(_),
!NonLocalRegionProc, !InCondRegionsProc) :-
@@ -323,9 +320,9 @@
ResurRenamingProc, ResurRenamingAnnoProc, Case,
!NonLocalRegionProc, !InCondRegionsProc) :-
Case = case(_, Goal),
- collect_non_local_and_in_cond_regions_goal(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc, Goal,
- !NonLocalRegionProc, !InCondRegionsProc).
+ collect_non_local_and_in_cond_regions_goal(Graph,
+ LRBeforeProc, LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
+ Goal, !NonLocalRegionProc, !InCondRegionsProc).
:- pred collect_non_local_regions_in_ite(rpt_graph::in,
pp_region_set_table::in, pp_region_set_table::in, renaming_proc::in,
@@ -336,8 +333,7 @@
ResurRenamingProc, ResurRenamingAnnoProc, GoalInIte,
!NonLocalRegionProc) :-
GoalInIte = hlds_goal(Expr, Info),
- ( if goal_is_atomic(Expr)
- then
+ ( goal_is_atomic(Expr) ->
ProgPoint = program_point_init(Info),
ProgPoint = pp(_, GoalPath),
map.lookup(LRBeforeProc, ProgPoint, LRBefore),
@@ -353,37 +349,32 @@
% For each renaming annotation, the left one is put
% into CreatedBefore, and the right one is put into
% RemovedAfter.
- ( if map.search(ResurRenamingProc, ProgPoint,
- ResurRenaming0)
- then ResurRenaming = ResurRenaming0
- else ResurRenaming = map.init
+ ( map.search(ResurRenamingProc, ProgPoint, ResurRenaming0) ->
+ ResurRenaming = ResurRenaming0
+ ;
+ ResurRenaming = map.init
),
set.fold(apply_region_renaming(Graph, ResurRenaming),
- RemovedAfterNodes, set.init,
- RemovedAfterRegions0),
+ RemovedAfterNodes, set.init, RemovedAfterRegions0),
set.fold(apply_region_renaming(Graph, ResurRenaming),
- CreatedBeforeNodes, set.init,
- CreatedBeforeRegions0),
+ CreatedBeforeNodes, set.init, CreatedBeforeRegions0),
- ( if map.search(ResurRenamingAnnoProc, ProgPoint,
- ResurRenamingAnnos0)
- then ResurRenamingAnnos = ResurRenamingAnnos0
- else ResurRenamingAnnos = []
+ ( map.search(ResurRenamingAnnoProc, ProgPoint, ResurRenamingAnnos0) ->
+ ResurRenamingAnnos = ResurRenamingAnnos0
+ ;
+ ResurRenamingAnnos = []
),
list.foldl2(renaming_annotation_to_regions,
- ResurRenamingAnnos, set.init, LeftRegions,
- set.init, RightRegions),
- set.union(RemovedAfterRegions0, RightRegions,
- RemovedAfterRegions),
- set.union(CreatedBeforeRegions0, LeftRegions,
- CreatedBeforeRegions),
+ ResurRenamingAnnos, set.init, LeftRegions, set.init, RightRegions),
+ set.union(RemovedAfterRegions0, RightRegions, RemovedAfterRegions),
+ set.union(CreatedBeforeRegions0, LeftRegions, CreatedBeforeRegions),
record_non_local_regions(GoalPath, CreatedBeforeRegions,
RemovedAfterRegions, !NonLocalRegionProc)
- else
+ ;
collect_non_local_regions_in_ite_compound_goal(Graph,
- LRBeforeProc, LRAfterProc, ResurRenamingProc,
- ResurRenamingAnnoProc, GoalInIte,
- !NonLocalRegionProc)
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc,
+ GoalInIte, !NonLocalRegionProc)
).
:- pred apply_region_renaming(rpt_graph::in, renaming::in, rptg_node::in,
@@ -391,9 +382,10 @@
apply_region_renaming(Graph, Renaming, Node, !Regions) :-
RegionName = rptg_lookup_region_name(Graph, Node),
- ( if map.search(Renaming, RegionName, RenamedRegionName)
- then svset.insert(RenamedRegionName, !Regions)
- else svset.insert(RegionName, !Regions)
+ ( map.search(Renaming, RegionName, RenamedRegionName) ->
+ svset.insert(RenamedRegionName, !Regions)
+ ;
+ svset.insert(RegionName, !Regions)
).
:- pred renaming_annotation_to_regions(region_instruction::in,
@@ -441,33 +433,28 @@
record_non_local_regions([], _, _, !NonLocalRegionProc).
record_non_local_regions(Path, Created, Removed, !NonLocalRegionProc) :-
Path = [Step | Steps],
- (
- Step = step_ite_else
- ->
+ ( Step = step_ite_else ->
% The current NonLocalRegions are attached to the goal path to
% the corresponding condition.
PathToCond = [step_ite_cond | Steps],
- ( if map.search(!.NonLocalRegionProc, PathToCond,
- NonLocalRegions0)
- then
- set.union(NonLocalRegions0, Created,
- NonLocalRegions1),
- set.difference(NonLocalRegions1, Removed,
- NonLocalRegions)
- else set.difference(Created, Removed, NonLocalRegions)
+ ( map.search(!.NonLocalRegionProc, PathToCond, NonLocalRegions0) ->
+ set.union(NonLocalRegions0, Created, NonLocalRegions1),
+ set.difference(NonLocalRegions1, Removed, NonLocalRegions)
+ ;
+ set.difference(Created, Removed, NonLocalRegions)
),
% Only record if some non-local region(s) exist.
- ( if set.empty(NonLocalRegions)
- then true
- else svmap.set(PathToCond, NonLocalRegions,
- !NonLocalRegionProc)
+ ( set.empty(NonLocalRegions) ->
+ true
+ ;
+ svmap.set(PathToCond, NonLocalRegions, !NonLocalRegionProc)
)
;
true
),
- % Need to update the non-local sets of outer if-then-elses of this
- % one, if any.
+ % Need to update the non-local sets of outer if-then-elses of this one,
+ % if any.
record_non_local_regions(Steps, Created, Removed, !NonLocalRegionProc).
:- pred collect_non_local_regions_in_ite_compound_goal(rpt_graph::in,
@@ -481,43 +468,50 @@
GoalInIte = hlds_goal(Expr, _),
(
Expr = conj(_, [Conj | Conjs]),
- list.foldl(collect_non_local_regions_in_ite(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc,
- ResurRenamingAnnoProc),
+ list.foldl(
+ collect_non_local_regions_in_ite(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc),
[Conj | Conjs], !NonLocalRegionProc)
;
Expr = disj([Disj | Disjs]),
- list.foldl(collect_non_local_regions_in_ite(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc,
- ResurRenamingAnnoProc),
+ list.foldl(
+ collect_non_local_regions_in_ite(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc),
[Disj | Disjs], !NonLocalRegionProc)
;
Expr = switch(_, _, Cases),
- list.foldl(collect_non_local_regions_in_ite_case(Graph,
+ list.foldl(
+ collect_non_local_regions_in_ite_case(Graph,
LRBeforeProc, LRAfterProc,
- ResurRenamingProc,
- ResurRenamingAnnoProc),
+ ResurRenamingProc, ResurRenamingAnnoProc),
Cases, !NonLocalRegionProc)
;
Expr = negation(Goal),
- collect_non_local_regions_in_ite(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
+ collect_non_local_regions_in_ite(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc,
Goal, !NonLocalRegionProc)
;
Expr = scope(_, Goal),
- collect_non_local_regions_in_ite(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
+ collect_non_local_regions_in_ite(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc,
Goal, !NonLocalRegionProc)
;
Expr = if_then_else(_, Cond, Then, Else),
- collect_non_local_regions_in_ite(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
+ collect_non_local_regions_in_ite(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc,
Cond, !NonLocalRegionProc),
- collect_non_local_regions_in_ite(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
+ collect_non_local_regions_in_ite(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc,
Then, !NonLocalRegionProc),
- collect_non_local_regions_in_ite(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
+ collect_non_local_regions_in_ite(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc,
Else, !NonLocalRegionProc)
;
( Expr = unify(_, _, _, _, _)
@@ -542,8 +536,7 @@
ResurRenamingProc, ResurRenamingAnnoProc, Case, !NonLocalRegionProc) :-
Case = case(_, Goal),
collect_non_local_regions_in_ite(Graph, LRBeforeProc, LRAfterProc,
- ResurRenamingProc, ResurRenamingAnnoProc, Goal,
- !NonLocalRegionProc).
+ ResurRenamingProc, ResurRenamingAnnoProc, Goal, !NonLocalRegionProc).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -566,43 +559,41 @@
collect_regions_created_in_condition(Graph, LRBeforeProc, LRAfterProc,
ResurRenamingProc, ResurRenamingAnnoProc, Cond, !InCondRegionsProc) :-
Cond = hlds_goal(Expr, Info),
- ( if goal_is_atomic(Expr)
- then
+ ( goal_is_atomic(Expr) ->
ProgPoint = program_point_init(Info),
ProgPoint = pp(_, GoalPath),
map.lookup(LRBeforeProc, ProgPoint, LRBefore),
map.lookup(LRAfterProc, ProgPoint, LRAfter),
set.difference(LRAfter, LRBefore, CreatedNodes),
- % We need to apply renaming to this CreatedNodes set
- % and look up the renaming annotations after this
- % program point. For each renaming annotation the left
- % one is created and the right is removed.
- ( if map.search(ResurRenamingProc, ProgPoint,
- ResurRenaming0)
- then ResurRenaming = ResurRenaming0
- else ResurRenaming = map.init
+ % We need to apply renaming to this CreatedNodes set and look up
+ % the renaming annotations after this program point. For each renaming
+ % annotation the left one is created and the right is removed.
+ ( map.search(ResurRenamingProc, ProgPoint, ResurRenaming0) ->
+ ResurRenaming = ResurRenaming0
+ ;
+ ResurRenaming = map.init
),
set.fold(apply_region_renaming(Graph, ResurRenaming),
CreatedNodes, set.init, CreatedRegions0),
- ( if map.search(ResurRenamingAnnoProc, ProgPoint,
- ResurRenamingAnnos0)
- then ResurRenamingAnnos = ResurRenamingAnnos0
- else ResurRenamingAnnos = []
+ ( map.search(ResurRenamingAnnoProc, ProgPoint, ResurRenamingAnnos0) ->
+ ResurRenamingAnnos = ResurRenamingAnnos0
+ ;
+ ResurRenamingAnnos = []
),
- list.foldl2(renaming_annotation_to_regions,
- ResurRenamingAnnos, set.init, LeftRegions,
+ list.foldl2(renaming_annotation_to_regions, ResurRenamingAnnos,
+ set.init, LeftRegions,
set.init, _RightRegions),
set.union(CreatedRegions0, LeftRegions, CreatedRegions),
record_regions_created_in_condition(GoalPath,
CreatedRegions, !InCondRegionsProc)
- else
- collect_regions_created_in_condition_compound_goal(
- Graph, LRBeforeProc, LRAfterProc,
- ResurRenamingProc, ResurRenamingAnnoProc, Cond,
- !InCondRegionsProc)
+ ;
+ collect_regions_created_in_condition_compound_goal(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc,
+ Cond, !InCondRegionsProc)
).
% The regions created inside the condition of an if-then-else will
@@ -618,16 +609,17 @@
record_regions_created_in_condition(Path, Created, !InCondRegionsProc) :-
Path = [Step | Steps],
( Step = step_ite_cond ->
- ( if map.search(!.InCondRegionsProc, Path, InCondRegions0)
- then set.union(InCondRegions0, Created,
- InCondRegions)
- else InCondRegions = Created
+ ( map.search(!.InCondRegionsProc, Path, InCondRegions0) ->
+ set.union(InCondRegions0, Created, InCondRegions)
+ ;
+ InCondRegions = Created
),
% Only record if the some region(s) is actually created inside
% the condition.
- ( if set.empty(InCondRegions)
- then true
- else svmap.set(Path, InCondRegions, !InCondRegionsProc)
+ ( set.empty(InCondRegions) ->
+ true
+ ;
+ svmap.set(Path, InCondRegions, !InCondRegionsProc)
)
;
true
@@ -639,50 +631,57 @@
renaming_proc::in, renaming_annotation_proc::in, hlds_goal::in,
goal_path_regions_table::in, goal_path_regions_table::out) is det.
-collect_regions_created_in_condition_compound_goal(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc, GoalInIte,
- !InCondRegionsProc) :-
+collect_regions_created_in_condition_compound_goal(Graph,
+ LRBeforeProc, LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
+ GoalInIte, !InCondRegionsProc) :-
GoalInIte = hlds_goal(Expr, _),
(
Expr = conj(_, [Conj | Conjs]),
- list.foldl(collect_regions_created_in_condition(Graph,
- LRBeforeProc, LRAfterProc, ResurRenamingProc,
- ResurRenamingAnnoProc), [Conj | Conjs],
- !InCondRegionsProc)
+ list.foldl(
+ collect_regions_created_in_condition(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc),
+ [Conj | Conjs], !InCondRegionsProc)
;
Expr = disj([Disj | Disjs]),
- list.foldl(collect_regions_created_in_condition(Graph,
- LRBeforeProc, LRAfterProc, ResurRenamingProc,
- ResurRenamingAnnoProc), [Disj | Disjs],
- !InCondRegionsProc)
+ list.foldl(
+ collect_regions_created_in_condition(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc),
+ [Disj | Disjs], !InCondRegionsProc)
;
Expr = switch(_, _, Cases),
list.foldl(
collect_regions_created_in_condition_case(Graph,
- LRBeforeProc, LRAfterProc, ResurRenamingProc,
- ResurRenamingAnnoProc),
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc),
Cases, !InCondRegionsProc)
;
Expr = negation(Goal),
- collect_regions_created_in_condition(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc,
- ResurRenamingAnnoProc, Goal, !InCondRegionsProc)
+ collect_regions_created_in_condition(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc,
+ Goal, !InCondRegionsProc)
;
Expr = scope(_, Goal),
- collect_regions_created_in_condition(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc,
- ResurRenamingAnnoProc, Goal, !InCondRegionsProc)
+ collect_regions_created_in_condition(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc,
+ Goal, !InCondRegionsProc)
;
Expr = if_then_else(_, Cond, Then, Else),
- collect_regions_created_in_condition(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc,
- ResurRenamingAnnoProc, Cond, !InCondRegionsProc),
- collect_regions_created_in_condition(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc,
- ResurRenamingAnnoProc, Then, !InCondRegionsProc),
- collect_regions_created_in_condition(Graph, LRBeforeProc,
- LRAfterProc, ResurRenamingProc,
- ResurRenamingAnnoProc, Else, !InCondRegionsProc)
+ collect_regions_created_in_condition(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc,
+ Cond, !InCondRegionsProc),
+ collect_regions_created_in_condition(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc,
+ Then, !InCondRegionsProc),
+ collect_regions_created_in_condition(Graph,
+ LRBeforeProc, LRAfterProc,
+ ResurRenamingProc, ResurRenamingAnnoProc,
+ Else, !InCondRegionsProc)
;
( Expr = unify(_, _, _, _, _)
; Expr = plain_call(_, _, _, _, _, _)
@@ -702,13 +701,12 @@
renaming_proc::in, renaming_annotation_proc::in, case::in,
goal_path_regions_table::in, goal_path_regions_table::out) is det.
-collect_regions_created_in_condition_case(Graph, LRBeforeProc, LRAfterProc,
- ResurRenamingProc, ResurRenamingAnnoProc,
+collect_regions_created_in_condition_case(Graph,
+ LRBeforeProc, LRAfterProc, ResurRenamingProc, ResurRenamingAnnoProc,
Case, !InCondRegionsProc) :-
Case = case(_, Goal),
collect_regions_created_in_condition(Graph, LRBeforeProc, LRAfterProc,
- ResurRenamingProc, ResurRenamingAnnoProc,
- Goal, !InCondRegionsProc).
+ ResurRenamingProc, ResurRenamingAnnoProc, Goal, !InCondRegionsProc).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -731,18 +729,16 @@
collect_ite_renamed_regions_proc(NonLocalRegionsTable, PPId,
InCondRegionsProc, !IteRenamedRegionTable) :-
- ( if map.search(NonLocalRegionsTable, PPId, NonLocalRegionsProc)
- then
- map.foldl(collect_ite_renamed_regions_ite(
- NonLocalRegionsProc),
- InCondRegionsProc,
- map.init, IteRenamedRegionProc),
- ( if map.count(IteRenamedRegionProc) = 0
- then true
- else svmap.set(PPId, IteRenamedRegionProc,
- !IteRenamedRegionTable)
+ ( map.search(NonLocalRegionsTable, PPId, NonLocalRegionsProc) ->
+ map.foldl(collect_ite_renamed_regions_ite(NonLocalRegionsProc),
+ InCondRegionsProc, map.init, IteRenamedRegionProc),
+ ( map.count(IteRenamedRegionProc) = 0 ->
+ true
+ ;
+ svmap.set(PPId, IteRenamedRegionProc, !IteRenamedRegionTable)
)
- else true
+ ;
+ true
).
:- pred collect_ite_renamed_regions_ite(goal_path_regions_table::in,
@@ -751,16 +747,15 @@
collect_ite_renamed_regions_ite(NonLocalRegionsProc, PathToCond,
InCondRegions, !IteRenamedRegionProc) :-
- ( if map.search(NonLocalRegionsProc, PathToCond, NonLocalRegions)
- then
- set.intersect(NonLocalRegions, InCondRegions,
- RenamedRegions),
- ( if set.empty(RenamedRegions)
- then true
- else svmap.set(PathToCond, RenamedRegions,
- !IteRenamedRegionProc)
+ ( map.search(NonLocalRegionsProc, PathToCond, NonLocalRegions) ->
+ set.intersect(NonLocalRegions, InCondRegions, RenamedRegions),
+ ( set.empty(RenamedRegions) ->
+ true
+ ;
+ svmap.set(PathToCond, RenamedRegions, !IteRenamedRegionProc)
)
- else true
+ ;
+ true
).
%-----------------------------------------------------------------------------%
@@ -870,34 +865,28 @@
collect_ite_renaming_in_condition(IteRenamedRegionProc, Graph, Cond,
!IteRenamingProc) :-
Cond = hlds_goal(Expr, Info),
- ( if goal_is_atomic(Expr)
- then
+ ( goal_is_atomic(Expr) ->
ProgPoint = program_point_init(Info),
- % It is enough to look for the regions to be renamed
- % at the closest condition because if a region is
- % to be renamed for a compounding if-then-else of the
- % closest if-then-else then it also needs to be renamed
- % for the closest if-then-else.
+ % It is enough to look for the regions to be renamed at the closest
+ % condition because if a region is to be renamed for a compounding
+ % if-then-else of the closest if-then-else then it also needs to be
+ % renamed for the closest if-then-else.
ProgPoint = pp(_, GoalPath),
- get_closest_condition_in_goal_path(GoalPath,
- PathToClosestCond, 0, HowMany),
- ( if map.search(IteRenamedRegionProc,
- PathToClosestCond,
- RenamedRegions)
- then
- set.fold(record_ite_renaming(ProgPoint,
- HowMany, Graph),
- RenamedRegions,
- !IteRenamingProc)
- else
- % No region needs to be renamed due to
- % if-then-else covering this program
- % point.
+ get_closest_condition_in_goal_path(GoalPath, PathToClosestCond,
+ 0, HowMany),
+ (
+ map.search(IteRenamedRegionProc, PathToClosestCond, RenamedRegions)
+ ->
+ set.fold(record_ite_renaming(ProgPoint, HowMany, Graph),
+ RenamedRegions, !IteRenamingProc)
+ ;
+ % No region needs to be renamed due to if-then-else covering
+ % this program point.
true
)
- else collect_ite_renaming_in_condition_compound_goal(
- IteRenamedRegionProc, Graph, Cond,
- !IteRenamingProc)
+ ;
+ collect_ite_renaming_in_condition_compound_goal(IteRenamedRegionProc,
+ Graph, Cond, !IteRenamingProc)
).
% A renaming is of the form: R --> R_ite_HowMany.
@@ -907,9 +896,10 @@
record_ite_renaming(ProgPoint, HowMany, _Graph, RegName, !IteRenamingProc) :-
NewName = RegName ++ "_ite_" ++ string.int_to_string(HowMany),
- ( if map.search(!.IteRenamingProc, ProgPoint, IteRenaming0)
- then svmap.set(RegName, NewName, IteRenaming0, IteRenaming)
- else svmap.set(RegName, NewName, map.init, IteRenaming)
+ ( map.search(!.IteRenamingProc, ProgPoint, IteRenaming0) ->
+ svmap.set(RegName, NewName, IteRenaming0, IteRenaming)
+ ;
+ svmap.set(RegName, NewName, map.init, IteRenaming)
),
svmap.set(ProgPoint, IteRenaming, !IteRenamingProc).
@@ -922,20 +912,20 @@
GoalInCond = hlds_goal(Expr, _),
(
Expr = conj(_, [Conj | Conjs]),
- list.foldl(collect_ite_renaming_in_condition(
- IteRenamedRegionProc, Graph), [Conj | Conjs],
- !IteRenamingProc)
+ list.foldl(
+ collect_ite_renaming_in_condition(IteRenamedRegionProc, Graph),
+ [Conj | Conjs], !IteRenamingProc)
;
Expr = disj([Disj | Disjs]),
- list.foldl(collect_ite_renaming_in_condition(
- IteRenamedRegionProc, Graph), [Disj | Disjs],
- !IteRenamingProc)
+ list.foldl(
+ collect_ite_renaming_in_condition(IteRenamedRegionProc, Graph),
+ [Disj | Disjs], !IteRenamingProc)
;
Expr = switch(_, _, Cases),
list.foldl(
- collect_ite_renaming_in_condition_case(
- IteRenamedRegionProc, Graph), Cases,
- !IteRenamingProc)
+ collect_ite_renaming_in_condition_case(IteRenamedRegionProc,
+ Graph),
+ Cases, !IteRenamingProc)
;
Expr = negation(Goal),
collect_ite_renaming_in_condition(IteRenamedRegionProc,
@@ -990,12 +980,12 @@
goal_path::out, int::in, int::out) is det.
get_closest_condition_in_goal_path([], [], !HowMany).
get_closest_condition_in_goal_path([Step | Steps], PathToCond, !HowMany) :-
- ( if Step = step_ite_cond
- then
+ ( Step = step_ite_cond ->
PathToCond = [Step | Steps],
get_closest_condition_in_goal_path(Steps, _, !.HowMany, HowMany),
!:HowMany = HowMany + 1
- else get_closest_condition_in_goal_path(Steps, PathToCond, !HowMany)
+ ;
+ get_closest_condition_in_goal_path(Steps, PathToCond, !HowMany)
).
%-----------------------------------------------------------------------------%
@@ -1005,7 +995,8 @@
collect_ite_annotation(IteRenamedRegionTable, ExecPathTable,
RptaInfoTable, IteRenamingTable, IteAnnotationTable) :-
- map.foldl(collect_ite_annotation_proc(ExecPathTable, RptaInfoTable,
+ map.foldl(
+ collect_ite_annotation_proc(ExecPathTable, RptaInfoTable,
IteRenamingTable),
IteRenamedRegionTable, map.init, IteAnnotationTable).
@@ -1020,8 +1011,8 @@
map.lookup(RptaInfoTable, PPId, RptaInfo),
map.lookup(IteRenamingTable, PPId, IteRenamingProc),
RptaInfo = rpta_info(Graph, _),
- map.foldl(collect_ite_annotation_region_names(ExecPaths, Graph,
- IteRenamingProc),
+ map.foldl(
+ collect_ite_annotation_region_names(ExecPaths, Graph, IteRenamingProc),
IteRenamedRegionProc, map.init, IteAnnotationProc),
svmap.set(PPId, IteAnnotationProc, !IteAnnotationTable).
@@ -1034,16 +1025,15 @@
(
PathToCond = [],
unexpected(this_file,
- "collect_ite_annotation_region_set: " ++
- "empty path to condition.")
+ "collect_ite_annotation_region_set: empty path to condition.")
;
PathToCond = [_ | Steps],
PathToThen = [step_ite_then | Steps],
get_closest_condition_in_goal_path(PathToCond, _, 0, HowMany),
- list.foldl(collect_ite_annotation_exec_path(Graph,
- IteRenamingProc, PathToThen,
- RenamedRegions, HowMany), ExecPaths,
- !IteAnnotationProc)
+ list.foldl(
+ collect_ite_annotation_exec_path(Graph, IteRenamingProc,
+ PathToThen, RenamedRegions, HowMany),
+ ExecPaths, !IteAnnotationProc)
).
:- pred collect_ite_annotation_exec_path(rpt_graph::in,
@@ -1056,17 +1046,16 @@
RenamedRegions, HowMany,
[ProgPoint - _ | ProgPoint_Goals], !IteAnnotationProc) :-
ProgPoint = pp(_, GoalPath),
- ( if list.append(_, PathToThen, GoalPath)
- then
- % This is the first goal in the corresponding then
- % branch, we need to introduce reverse renaming at
- % this point.
- set.fold(introduce_reverse_renaming(ProgPoint,
- IteRenamingProc, HowMany),
+ ( list.append(_, PathToThen, GoalPath) ->
+ % This is the first goal in the corresponding then branch, we need
+ % to introduce reverse renaming at this point.
+ set.fold(
+ introduce_reverse_renaming(ProgPoint, IteRenamingProc, HowMany),
RenamedRegions, !IteAnnotationProc)
- else collect_ite_annotation_exec_path(Graph, IteRenamingProc,
- PathToThen, RenamedRegions, HowMany,
- ProgPoint_Goals, !IteAnnotationProc)
+ ;
+ collect_ite_annotation_exec_path(Graph, IteRenamingProc,
+ PathToThen, RenamedRegions, HowMany, ProgPoint_Goals,
+ !IteAnnotationProc)
).
% The reverse renaming annotation is in the form: R = R_ite_HowMany.
@@ -1082,18 +1071,15 @@
introduce_reverse_renaming(ProgPoint, IteRenamingProc, HowMany, RegName,
!IteAnnotationProc) :-
CurrentName = RegName ++ "_ite_" ++ string.int_to_string(HowMany),
- ( if map.search(IteRenamingProc, ProgPoint, Renaming)
- then
- ( if map.search(Renaming, RegName, RenameTo)
- then make_renaming_instruction(CurrentName, RenameTo,
- Annotation)
- else make_renaming_instruction(CurrentName, RegName,
- Annotation)
+ ( map.search(IteRenamingProc, ProgPoint, Renaming) ->
+ ( map.search(Renaming, RegName, RenameTo) ->
+ make_renaming_instruction(CurrentName, RenameTo, Annotation)
+ ;
+ make_renaming_instruction(CurrentName, RegName, Annotation)
)
- else
+ ;
% No renaming exists at this program point.
- make_renaming_instruction(CurrentName, RegName,
- Annotation)
+ make_renaming_instruction(CurrentName, RegName, Annotation)
),
record_annotation(ProgPoint, Annotation, !IteAnnotationProc).
Index: rbmm.execution_path.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.execution_path.m,v
retrieving revision 1.4
diff -u -b -r1.4 rbmm.execution_path.m
--- rbmm.execution_path.m 6 Jul 2007 02:35:22 -0000 1.4
+++ rbmm.execution_path.m 23 Jul 2007 04:17:37 -0000
@@ -72,11 +72,9 @@
execution_path_analysis_proc(ModuleInfo, PredId, ProcId, !ExecPathTable) :-
PPId = proc(PredId, ProcId),
- ( if
- some_are_special_preds([PPId], ModuleInfo)
- then
+ ( some_are_special_preds([PPId], ModuleInfo) ->
true
- else
+ ;
module_info_proc_info(ModuleInfo, PPId, ProcInfo),
compute_execution_paths(ProcInfo, ModuleInfo, ExecPaths),
svmap.set(PPId, ExecPaths, !ExecPathTable)
@@ -101,9 +99,7 @@
execution_paths_covered_goal(ProcInfo, Goal, !ExecPaths) :-
Goal = hlds_goal(Expr, Info),
- (
- goal_is_atomic(Expr)
- ->
+ ( goal_is_atomic(Expr) ->
(
( Expr = unify(_, _, _, _, _)
; Expr = plain_call(_, _, _, _, _, _)
@@ -122,8 +118,7 @@
append_to_each_execution_path(!.ExecPaths, [[]], !:ExecPaths)
)
;
- execution_paths_covered_compound_goal(ProcInfo, Goal,
- !ExecPaths)
+ execution_paths_covered_compound_goal(ProcInfo, Goal, !ExecPaths)
).
% Extend current execution paths to cover this compound goal.
@@ -215,8 +210,7 @@
is det.
execution_paths_covered_cases(_, _, [], _, []).
-execution_paths_covered_cases(ProcInfo, Switch, [Case | Cases],
- !ExecPaths) :-
+execution_paths_covered_cases(ProcInfo, Switch, [Case | Cases], !ExecPaths) :-
Case = case(ConsId, CaseGoal),
Switch = hlds_goal(_SwitchExpr, Info),
ProgPoint = program_point_init(Info),
@@ -225,11 +219,10 @@
% We add a dummy program point for this unification.
(
ConsId = cons(_SymName, Arity),
- ( if Arity = 0
- then
+ ( Arity = 0 ->
append_to_each_execution_path(!.ExecPaths,
[[pair(ProgPoint, Switch)]], ExecPathsBeforeCase)
- else
+ ;
ExecPathsBeforeCase = !.ExecPaths
)
;
Index: rbmm.interproc_region_lifetime.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.interproc_region_lifetime.m,v
retrieving revision 1.2
diff -u -b -r1.2 rbmm.interproc_region_lifetime.m
--- rbmm.interproc_region_lifetime.m 9 Jul 2007 13:28:36 -0000 1.2
+++ rbmm.interproc_region_lifetime.m 23 Jul 2007 04:20:38 -0000
@@ -157,14 +157,14 @@
module_info_ensure_dependency_info(ModuleInfo, ModuleInfo1),
module_info_get_maybe_dependency_info(ModuleInfo1, MaybeDepInfo),
(
- MaybeDepInfo = yes(DepInfo)
- ->
+ MaybeDepInfo = yes(DepInfo),
hlds.hlds_module.hlds_dependency_info_get_dependency_ordering(
DepInfo, DepOrdering),
run_with_dependencies(Rule, DepOrdering, ModuleInfo1,
RptaInfoTable, ExecPathTable, LRBeforeTable, LRAfterTable,
!ProcRegionSetTable)
;
+ MaybeDepInfo = no,
unexpected(this_file,
"apply_live_region_rule: no dependency info")
).
@@ -180,9 +180,10 @@
% We want to proceed the SCC graph top-down so reverse the list
% (the process is foldr2, but it is not yet in list module)
list.reverse(Deps, Deps1),
- list.foldl(run_with_dependency(Rule, ModuleInfo, RptaInfoTable,
- ExecPathTable, LRBeforeTable, LRAfterTable), Deps1,
- !ProcRegionSetTable).
+ list.foldl(
+ run_with_dependency(Rule, ModuleInfo, RptaInfoTable,
+ ExecPathTable, LRBeforeTable, LRAfterTable),
+ Deps1, !ProcRegionSetTable).
:- pred run_with_dependency(rule_pred::in(rule_pred),
module_info::in, rpta_info_table::in, execution_path_table::in,
@@ -192,10 +193,8 @@
run_with_dependency(Rule, ModuleInfo, RptaInfoTable, ExecPathTable,
LRBeforeTable, LRAfterTable, SCC, !ProcRegionSetTable) :-
- (
% Ignores special predicates.
- some_are_special_preds(SCC, ModuleInfo)
- ->
+ ( some_are_special_preds(SCC, ModuleInfo) ->
true
;
% Perform a fixpoint computation for each strongly connected
@@ -218,8 +217,7 @@
ExecPathTable, LRBeforeTable, LRAfterTable),
SCC, !.ProcRegionSetTable, ProcRegionSetTable1),
(
- proc_region_set_table_equal(ProcRegionSetTable1,
- !.ProcRegionSetTable)
+ proc_region_set_table_equal(ProcRegionSetTable1, !.ProcRegionSetTable)
->
% If all region_set's in the FPTable are intact update the main
% ProcRegionSetTable.
@@ -306,8 +304,7 @@
call(Rule, CalleePPId, LRBefore, LRAfter,
!.ProcRegionSetTable, AlphaAtProgPoint, RegionSet),
- map.lookup(!.ProcRegionSetTable, CalleePPId,
- RegionSet0),
+ map.lookup(!.ProcRegionSetTable, CalleePPId, RegionSet0),
( if
set.equal(RegionSet, RegionSet0)
then
@@ -316,18 +313,15 @@
true
else
% some regions are removed, record the new set for q and ...
- svmap.set(CalleePPId, RegionSet,
- !ProcRegionSetTable),
+ svmap.set(CalleePPId, RegionSet, !ProcRegionSetTable),
% ... those removals need to be propagated to the ones
% called by q
- set.difference(RegionSet0, RegionSet,
- ToBeRemoved),
+ set.difference(RegionSet0, RegionSet, ToBeRemoved),
list.foldl(
- remove_this_region_from_callees_of_proc(
- CalleePPId, ExecPathTable, ModuleInfo, RptaInfoTable),
- set.to_sorted_list(ToBeRemoved),
- !ProcRegionSetTable)
+ remove_this_region_from_callees_of_proc(CalleePPId,
+ ExecPathTable, ModuleInfo, RptaInfoTable),
+ set.to_sorted_list(ToBeRemoved), !ProcRegionSetTable)
)
)
else
@@ -362,8 +356,8 @@
% Apply dead removal rule L1 for r that is live before and after the
% call to q.
set.intersect(LRBefore, LRAfter, Rule1_Candidate),
- set.fold(dead_removal_rule_1(AlphaAtPP), Rule1_Candidate, DeadR_q0,
- DeadR_q1),
+ set.fold(dead_removal_rule_1(AlphaAtPP), Rule1_Candidate,
+ DeadR_q0, DeadR_q1),
% Remove deadR rule L2.
targets_with_more_than_one_source(AlphaAtPP, Targets),
@@ -468,8 +462,8 @@
remove_this_from_eps(ExecPaths, PPId, Region, ExecPathTable,
ModuleInfo, RptaInfoTable, !ProcRegionSetTable).
- % Follow each execution path of a procedure and update deadR and
- % bornR sets
+ % Follow each execution path of a procedure and update deadR and bornR
+ % sets.
%
:- pred remove_this_from_eps(list(execution_path)::in, pred_proc_id::in,
rptg_node::in, execution_path_table::in, module_info::in,
@@ -524,10 +518,8 @@
else
% Some is removed from deadR or bornR of this callee,
% so we update the entry of this called and analyse it.
- svmap.set(CalleePPId, RegionSet1,
- !ProcRegionSetTable),
- set.difference(RegionSet0, RegionSet1,
- RemovedFromQ),
+ svmap.set(CalleePPId, RegionSet1, !ProcRegionSetTable),
+ set.difference(RegionSet0, RegionSet1, RemovedFromQ),
% Call this one mutually recursively.
list.foldl(
@@ -598,15 +590,17 @@
retain_non_primitive_regions(ModuleInfo, Graph, Region, !RegionSet) :-
NodeType = rptg_lookup_node_type(Graph, Region),
- ( ( type_is_atomic(ModuleInfo, NodeType)
+ (
+ ( type_is_atomic(ModuleInfo, NodeType)
; is_dummy_argument_type(ModuleInfo, NodeType)
)
- -> true
- ; svset.insert(Region, !RegionSet)
+ ->
+ true
+ ;
+ svset.insert(Region, !RegionSet)
).
- % Eliminate regions of primitive types from the
- % proc_pp_region_set_table.
+ % Eliminate regions of primitive types from the proc_pp_region_set_table.
%
:- pred eliminate_primitive_regions_2(module_info::in, rpta_info_table::in,
pred_proc_id::in, pp_region_set_table::in, proc_pp_region_set_table::in,
Index: rbmm.live_region_analysis.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.live_region_analysis.m,v
retrieving revision 1.1
diff -u -b -r1.1 rbmm.live_region_analysis.m
--- rbmm.live_region_analysis.m 23 May 2007 00:17:19 -0000 1.1
+++ rbmm.live_region_analysis.m 23 Jul 2007 04:51:49 -0000
@@ -115,6 +115,7 @@
proc_region_set_table::in, proc_region_set_table::out,
proc_region_set_table::in, proc_region_set_table::out,
proc_region_set_table::in, proc_region_set_table::out) is det.
+
live_region_analysis_pred(ModuleInfo, RptaInfoTable, LVBeforeTable,
LVAfterTable, VoidVarTable, PredId, !LRBeforeTable, !LRAfterTable,
!VoidVarRegionTable, !InputRTable, !OutputRTable, !BornRTable,
@@ -122,11 +123,12 @@
module_info_pred_info(ModuleInfo, PredId, PredInfo),
pred_info_non_imported_procids(PredInfo) = ProcIds,
- foldl8(live_region_analysis_proc(ModuleInfo, RptaInfoTable,
- LVBeforeTable, LVAfterTable, VoidVarTable, PredId), ProcIds,
+ foldl8(
+ live_region_analysis_proc(ModuleInfo, RptaInfoTable,
+ LVBeforeTable, LVAfterTable, VoidVarTable, PredId),
+ ProcIds,
!LRBeforeTable, !LRAfterTable, !VoidVarRegionTable,
- !InputRTable, !OutputRTable, !BornRTable, !DeadRTable,
- !LocalRTable).
+ !InputRTable, !OutputRTable, !BornRTable, !DeadRTable, !LocalRTable).
:- pred live_region_analysis_proc(module_info::in, rpta_info_table::in,
proc_pp_varset_table::in, proc_pp_varset_table::in,
@@ -145,9 +147,7 @@
!LRAfterTable, !VoidVarRegionTable, !InputRTable, !OutputRTable,
!BornRTable, !DeadRTable, !LocalRTable) :-
PPId = proc(PredId, ProcId),
- ( if
- some_are_special_preds([PPId], ModuleInfo)
- then
+ ( some_are_special_preds([PPId], ModuleInfo) ->
% XXX: This action seems to be overkilled, it never goes in this
% branch.
% XXX: For the time being just ignore special predicates
@@ -155,23 +155,20 @@
% The latter ones should have been analysed when their
% modules analysed and their tables will be integrated.
% But it is not the case at the moment.
- %
true
- else
+ ;
(
- % This check is just a cautious check
- RptaInfo = rpta_info_table_search_rpta_info(PPId,
- RptaInfoTable)
+ % This check is just a cautious check.
+ RptaInfo = rpta_info_table_search_rpta_info(PPId, RptaInfoTable)
->
% Compute region sets.
RptaInfo = rpta_info(Graph, _ALpha),
module_info_proc_info(ModuleInfo, PPId, ProcInfo),
- find_input_output_args(ModuleInfo, ProcInfo, Inputs,
- Outputs),
- lv_to_lr(set.from_list(Inputs), Graph, ModuleInfo,
- ProcInfo, InputR),
- lv_to_lr(set.from_list(Outputs), Graph, ModuleInfo,
- ProcInfo, OutputR),
+ find_input_output_args(ModuleInfo, ProcInfo, Inputs, Outputs),
+ lv_to_lr(set.from_list(Inputs), Graph, ModuleInfo, ProcInfo,
+ InputR),
+ lv_to_lr(set.from_list(Outputs), Graph, ModuleInfo, ProcInfo,
+ OutputR),
svmap.set(PPId, InputR, !InputRTable),
svmap.set(PPId, OutputR, !OutputRTable),
% initial bornR
@@ -240,9 +237,7 @@
proc_info::in, region_set::out) is det.
lv_to_lr(LVSet, Graph, ModuleInfo, ProcInfo, LRSet) :-
- (
- set.empty(LVSet)
- ->
+ ( set.empty(LVSet) ->
set.init(LRSet)
;
% Collect reachable regions at this program point.
Index: rbmm.live_variable_analysis.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.live_variable_analysis.m,v
retrieving revision 1.2
diff -u -b -r1.2 rbmm.live_variable_analysis.m
--- rbmm.live_variable_analysis.m 23 May 2007 09:41:44 -0000 1.2
+++ rbmm.live_variable_analysis.m 23 Jul 2007 04:52:15 -0000
@@ -100,9 +100,9 @@
live_variable_analysis_proc(ModuleInfo, ExecPathTable, PredId, ProcId,
!LVBeforeTable, !LVAfterTable, !VoidVarTable) :-
PPId = proc(PredId, ProcId),
- ( if some_are_special_preds([PPId], ModuleInfo)
- then true
- else
+ ( some_are_special_preds([PPId], ModuleInfo) ->
+ true
+ ;
module_info_proc_info(ModuleInfo, PPId, ProcInfo),
find_input_output_args(ModuleInfo, ProcInfo, Inputs, Outputs),
map.lookup(ExecPathTable, PPId, ExecPaths),
@@ -130,11 +130,10 @@
live_variable_analysis_exec_paths([ExecPath0 | ExecPaths], Inputs, Outputs,
ModuleInfo, ProcInfo, !ProcLVBefore, !ProcLVAfter, !ProcVoidVar) :-
list.reverse(ExecPath0, ExecPath),
- ( if list.length(ExecPath) = 1
- then
+ ( list.length(ExecPath) = 1 ->
live_variable_analysis_singleton_exec_path(ExecPath, Inputs, Outputs,
ModuleInfo, ProcInfo, !ProcLVBefore, !ProcLVAfter, !ProcVoidVar)
- else
+ ;
% Start with the last program point.
live_variable_analysis_exec_path(ExecPath, Inputs, Outputs,
ModuleInfo, ProcInfo, yes, set.init, !ProcLVBefore, !ProcLVAfter,
@@ -151,6 +150,7 @@
live_variable_analysis_exec_path([], _, _, _, _,_, _, !ProcLVBefore,
!ProcLVAfter, !ProcVoidVar).
+ % XXX Exactly what piece of code does this comment apply to?
% Process the last program point in an execution path. The live variable
% set of the last program point is always the set of output variables
% of the procedure.
@@ -158,9 +158,9 @@
live_variable_analysis_exec_path([(LastProgPoint - Goal) | ProgPointGoals],
Inputs, Outputs, ModuleInfo, ProcInfo, yes, _LVBeforeNext,
!ProcLVBefore, !ProcLVAfter, !ProcVoidVar) :-
- ( if map.search(!.ProcLVAfter, LastProgPoint, LVAfterLast0)
- then LVAfterLast = LVAfterLast0
- else
+ ( map.search(!.ProcLVAfter, LastProgPoint, LVAfterLast0) ->
+ LVAfterLast = LVAfterLast0
+ ;
LVAfterLast = set.list_to_set(Outputs),
svmap.set(LastProgPoint, LVAfterLast, !ProcLVAfter)
),
@@ -169,8 +169,8 @@
compute_useds_produceds(ModuleInfo, Goal, UsedSet, ProducedSet),
set.union(set.difference(LVAfterLast, ProducedSet), UsedSet,
LVBeforeLastInThisExecPath),
- record_live_vars_at_prog_point(LastProgPoint,
- LVBeforeLastInThisExecPath, !ProcLVBefore),
+ record_live_vars_at_prog_point(LastProgPoint, LVBeforeLastInThisExecPath,
+ !ProcLVBefore),
% Collect void variables after this program point.
collect_void_vars(LastProgPoint, ProducedSet, ProcInfo, !ProcVoidVar),
@@ -209,18 +209,15 @@
live_variable_analysis_exec_path([FirstProgPoint - Goal], Inputs, _Outputs,
ModuleInfo, ProcInfo, no, LVBeforeNext, !ProcLVBefore,
!ProcLVAfter, !ProcVoidVar) :-
- ( if
- map.search(!.ProcLVBefore, FirstProgPoint, _LVBeforeFirst)
- then
+ ( map.search(!.ProcLVBefore, FirstProgPoint, _LVBeforeFirst) ->
true
- else
+ ;
LVBeforeFirst = set.list_to_set(Inputs),
svmap.set(FirstProgPoint, LVBeforeFirst, !ProcLVBefore)
),
% Live variable set after the first program point.
- record_live_vars_at_prog_point(FirstProgPoint, LVBeforeNext,
- !ProcLVAfter),
+ record_live_vars_at_prog_point(FirstProgPoint, LVBeforeNext, !ProcLVAfter),
% Collect void vars after this program point.
compute_useds_produceds(ModuleInfo, Goal, _UsedSet, ProducedSet),
@@ -260,9 +257,10 @@
pp_varset_table::in, pp_varset_table::out) is det.
record_live_vars_at_prog_point(ProgPoint, LV, !ProcLV) :-
- ( if map.search(!.ProcLV, ProgPoint, ExistingLV)
- then svmap.set(ProgPoint, set.union(ExistingLV, LV), !ProcLV)
- else svmap.set(ProgPoint, LV, !ProcLV)
+ ( map.search(!.ProcLV, ProgPoint, ExistingLV) ->
+ svmap.set(ProgPoint, set.union(ExistingLV, LV), !ProcLV)
+ ;
+ svmap.set(ProgPoint, LV, !ProcLV)
).
% Compute used and produced variables in an atomic goal, which
@@ -357,22 +355,18 @@
get_inputs_outputs_proc_call_2([FormalArg | FormalArgs],
[ActualArg | ActualArgs], Inputs, Outputs, !ActualInputs,
!ActualOutputs) :-
- (
- list.member(FormalArg, Inputs)
- ->
+ ( list.member(FormalArg, Inputs) ->
% This formal argument is an input, so the correspondig argument
% is an actual input argument.
ActualInputs1 = [ActualArg | !.ActualInputs],
ActualOutputs1 = !.ActualOutputs
- ;
- list.member(FormalArg, Outputs)
- ->
+ ; list.member(FormalArg, Outputs) ->
% This formal argument is an output, so the corresponding argument
% is an actual output argument.
ActualOutputs1 = [ActualArg | !.ActualOutputs],
ActualInputs1 = !.ActualInputs
;
- % this formal param is neither an output nor an input, so ignore
+ % This formal param is neither an output nor an input, so ignore
% the corresponding arg.
ActualInputs1 = !.ActualInputs,
ActualOutputs1 = !.ActualOutputs
@@ -388,11 +382,9 @@
pp_varset_table::in, pp_varset_table::out) is det.
collect_void_vars(ProgPoint, ProducedSet, ProcInfo, !ProcVoidVar) :-
- ( if
- map.search(!.ProcVoidVar, ProgPoint, _DeadVars)
- then
+ ( map.search(!.ProcVoidVar, ProgPoint, _DeadVars) ->
true
- else
+ ;
proc_info_get_varset(ProcInfo, Varset),
set.fold(void_var(Varset), ProducedSet, set.init, VoidVars),
svmap.set(ProgPoint, VoidVars, !ProcVoidVar)
@@ -407,9 +399,10 @@
void_var(Varset, Var, !VoidVars) :-
mercury_var_to_string(Varset, no, Var) = VarName,
string.substring(VarName, 0, 1, FirstChar),
- ( if FirstChar = "_"
- then set.insert(!.VoidVars, Var, !:VoidVars)
- else true
+ ( FirstChar = "_" ->
+ set.insert(!.VoidVars, Var, !:VoidVars)
+ ;
+ true
).
%----------------------------------------------------------------------------%
Index: rbmm.points_to_analysis.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.points_to_analysis.m,v
retrieving revision 1.5
diff -u -b -r1.5 rbmm.points_to_analysis.m
--- rbmm.points_to_analysis.m 25 May 2007 11:51:49 -0000 1.5
+++ rbmm.points_to_analysis.m 23 Jul 2007 04:28:20 -0000
@@ -19,12 +19,12 @@
% region points-to graph (rptg) and alpha mapping.
%
% The analysis is composed of 2 phases:
+%
% 1. intraprocedural analysis: only analyses unifications and compute only
% rptgs.
% 2. interprocedural analysis: only analyses (plain) procedure calls,
% compute both rptgs and alpha mappings.
%
-%
% Currently the analysis ONLY collects the information, do NOT record it into
% the HLDS.
%
@@ -103,9 +103,9 @@
intra_proc_rpta_proc(ModuleInfo, PredId, ProcId, !InfoTable) :-
PPId = proc(PredId, ProcId),
- ( if some_are_special_preds([PPId], ModuleInfo)
- then true
- else
+ ( some_are_special_preds([PPId], ModuleInfo) ->
+ true
+ ;
module_info_proc_info(ModuleInfo, PPId, ProcInfo),
RptaInfo0 = rpta_info_init(ProcInfo),
proc_info_get_goal(ProcInfo, Goal),
@@ -113,8 +113,8 @@
rpta_info_table_set_rpta_info(PPId, RptaInfo, !InfoTable)
).
-:- pred intra_analyse_goal(hlds_goal::in,
- rpta_info::in, rpta_info::out) is det.
+:- pred intra_analyse_goal(hlds_goal::in, rpta_info::in, rpta_info::out)
+ is det.
intra_analyse_goal(Goal, !RptaInfo) :-
Goal = hlds_goal(GoalExpr, _),
@@ -195,15 +195,14 @@
( Unification = construct(LVar, ConsId, RVars, _, _, _, _)
; Unification = deconstruct(LVar, ConsId, RVars, _, _, _)
),
- list.foldl2(process_cons_and_decons(LVar, ConsId), RVars, 1, _,
- !RptaInfo).
+ list.foldl2(process_cons_and_decons(LVar, ConsId), RVars, 1, _, !RptaInfo).
intra_analyse_unification(assign(ToVar, FromVar), !RptaInfo) :-
!.RptaInfo = rpta_info(Graph0, AlphaMapping),
get_node_by_variable(Graph0, ToVar, ToNode),
get_node_by_variable(Graph0, FromVar, FromNode),
- ( if ToNode = FromNode
- then true
- else
+ ( ToNode = FromNode ->
+ true
+ ;
unify_operator(ToNode, FromNode, Graph0, Graph),
!:RptaInfo = rpta_info(Graph, AlphaMapping),
% After merging the two nodes, apply rule P1 to restore the
@@ -231,9 +230,9 @@
% is actually added or not so it is convenient to check the edge's
% existence outside edge_operator. Otherwise we can extend edge_operator
% with one more argument to indicate that.
- ( if edge_in_graph(L_Node, EdgeLabel, R_Node, Graph0)
- then true
- else
+ ( edge_in_graph(L_Node, EdgeLabel, R_Node, Graph0) ->
+ true
+ ;
edge_operator(L_Node, R_Node, EdgeLabel, Graph0, Graph1),
!:RptaInfo = rpta_info(Graph1, AlphaMapping),
@@ -280,10 +279,8 @@
rpta_info_table::in, rpta_info_table::out) is det.
run_with_dependency(ModuleInfo, SCC, !InfoTable) :-
- (
+ ( some_are_special_preds(SCC, ModuleInfo) ->
% Analysis ignores special predicates.
- some_are_special_preds(SCC, ModuleInfo)
- ->
true
;
% Run the fixpoint computation on the SCC.
@@ -299,9 +296,7 @@
run_with_dependency_until_fixpoint(SCC, FPTable0, ModuleInfo, !InfoTable) :-
list.foldl(inter_analyse_proc(ModuleInfo, !.InfoTable), SCC,
FPTable0, FPTable1),
- (
- fixpoint_reached(FPTable1)
- ->
+ ( fixpoint_reached(FPTable1) ->
% If we have reached a fixpoint for this SCC then update the
% RPTA info table.
list.foldl(update_rpta_info_in_rpta_info_table(FPTable1), SCC,
@@ -820,7 +815,6 @@
rule_3(Node, Graph0, Graph),
!:RptaInfo = rpta_info(Graph, AlphaMapping).
-
%-----------------------------------------------------------------------------%
%
% Rule P4 and alpha mapping
@@ -846,13 +840,10 @@
!CallerGraph, !AlphaMap) :-
get_node_by_variable(CalleeGraph, Xi, N_Xi),
get_node_by_variable(!.CallerGraph, Yi, N_Yi),
- ( if map.search(!.AlphaMap, N_Xi, N_Y)
- then
-
+ ( map.search(!.AlphaMap, N_Xi, N_Y) ->
% alpha(N_Xi) = N_Y, alpha(N_Xi) = N_Yi, N_Y != N_Yi.
%
- ( if N_Y \= N_Yi
- then
+ ( N_Y \= N_Yi ->
% Apply rule P4.
unify_operator(N_Y, N_Yi, !CallerGraph),
@@ -860,10 +851,10 @@
rptg_node_contents(!.CallerGraph, N_Y, Content),
N_Y_Vars = Content ^ varset,
rule_1(N_Y_Vars, !CallerGraph)
- else
+ ;
true
)
- else
+ ;
svmap.set(N_Xi, N_Yi, !AlphaMap)
),
alpha_mapping_at_call_site(Xs, Ys, CalleeGraph, !CallerGraph, !AlphaMap).
@@ -1112,9 +1103,9 @@
:- func wrapped_init(rpta_info_table, pred_proc_id) = rpta_info.
wrapped_init(InfoTable, PPId) = Entry :-
- ( if Entry0 = rpta_info_table_search_rpta_info(PPId, InfoTable)
- then Entry = Entry0
- else
+ ( Entry0 = rpta_info_table_search_rpta_info(PPId, InfoTable) ->
+ Entry = Entry0
+ ;
% The information we are looking for should be there after the
% intraprocedural analysis.
unexpected(this_file, "wrapper_init: rpta_info should exist.")
Index: rbmm.points_to_graph.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.points_to_graph.m,v
retrieving revision 1.1
diff -u -b -r1.1 rbmm.points_to_graph.m
--- rbmm.points_to_graph.m 23 May 2007 00:17:21 -0000 1.1
+++ rbmm.points_to_graph.m 23 Jul 2007 04:33:03 -0000
@@ -93,23 +93,21 @@
rptg_arc_content % the label
).
- % rpt_graph_init(Graph) binds Graph to an empty graph
- % containing no nodes and no arcs. (The graph contains
- % a counter of the number of nodes allocated in it, so
- % it is possible for a graph to contain no nodes or arcs
- % and still fail to unify with the binding of Graph from
+ % rpt_graph_init(Graph) binds Graph to an empty graph containing
+ % no nodes and no arcs. (The graph contains a counter of the number
+ % of nodes allocated in it, so it is possible for a graph to contain
+ % no nodes or arcs and still fail to unify with the binding of Graph from
% rpt_graph_init.)
%
:- pred rpt_graph_init(rpt_graph::out) is det.
:- func rpt_graph_init = rpt_graph.
- % rptg_set_node(NodeInfo, Node, OldGraph, NewGraph) takes
- % OldGraph and NodeInfo which is the information to be stored
- % in a new node, and returns a key "Node" which refers to that
- % node, and the new graph NewGraph containing all of the nodes
- % and arcs in OldGraph as well as the new node.
- % It is possible to have two nodes in the graph with the
+ % rptg_set_node(NodeInfo, Node, OldGraph, NewGraph) takes OldGraph and
+ % NodeInfo which is the information to be stored in a new node, and
+ % returns a key "Node" which refers to that node, and the new graph
+ % NewGraph containing all of the nodes and arcs in OldGraph as well as
+ % the new node. It is possible to have two nodes in the graph with the
% same information stored in them.
%
% This operation is O(lgN) for a graph containing N nodes.
@@ -117,8 +115,8 @@
:- pred rptg_set_node(rptg_node_content::in, rptg_node::out,
rpt_graph::in, rpt_graph::out) is det.
- % rptg_node_contents(Graph, Node, NodeContent) takes Graph and
- % Node and returns the information NodeContent stored in Node.
+ % rptg_node_contents(Graph, Node, NodeContent) takes Graph and Node
+ % and returns the information NodeContent stored in Node.
%
% This operation is O(lgN) for a graph containing N nodes.
%
@@ -126,9 +124,9 @@
rptg_node::in, rptg_node_content::out) is det.
:- func rptg_node_contents(rpt_graph, rptg_node) = rptg_node_content.
- % rptg_successors(Graph, Node, Nodes) takes a graph Graph and
- % a node Node and returns the set of nodes Nodes that are reachable
- % (directly - not transitively) from Node.
+ % rptg_successors(Graph, Node, Nodes) takes a graph Graph and a node Node
+ % and returns the set of nodes Nodes that are reachable (directly -
+ % not transitively) from Node.
%
% This operation is O(NlgN) for a graph containing N nodes.
%
@@ -143,19 +141,18 @@
% rptg_set_edge(Start, End, ArcInfo, Arc, OldGraph, NewGraph)
% takes a graph OldGraph and adds an arc from Start to End with
- % the information ArcInfo stored in it, and returns a key for
- % that arc Arc, and the new graph NewGraph.
- % If an identical arc already exists then this operation has
- % no effect.
+ % the information ArcInfo stored in it, and returns a key for that arc Arc,
+ % and the new graph NewGraph.
+ % If an identical arc already exists then this operation has no effect.
%
% This operation is O(lgN+lgM) for a graph with N nodes and M arcs.
%
:- pred rptg_set_edge(rptg_node::in, rptg_node::in, rptg_arc_content::in,
rptg_arc::out, rpt_graph::in, rpt_graph::out) is det.
- % rptg_arc_contents(Graph, Arc, Start, End, ArcInfo) takes a
- % graph Graph and an arc Arc and returns the start and end nodes
- % and the content stored in that arc.
+ % rptg_arc_contents(Graph, Arc, Start, End, ArcInfo) takes a graph Graph
+ % and an arc Arc and returns the start and end nodes and the content
+ % stored in that arc.
%
:- pred rptg_arc_contents(rpt_graph::in, rptg_arc::in, rptg_node::out,
rptg_node::out, rptg_arc_content::out) is det.
@@ -217,12 +214,12 @@
%
:- pred get_node_by_node(rpt_graph::in, rptg_node::in, rptg_node::out) is det.
- % compare two graphs
+ % Compare two graphs.
%
:- pred rptg_equal(rpt_graph::in, rpt_graph::in) is semidet.
% This predicate returns a set of nodes (regions) reachable from a
- % variable X
+ % variable X.
%
:- pred reach_from_a_variable(rpt_graph::in, module_info::in, proc_info::in,
prog_var::in, set(rptg_node)::in, set(rptg_node)::out) is det.
@@ -230,12 +227,12 @@
:- func rptg_lookup_region_name(rpt_graph, rptg_node) = string.
:- func rptg_lookup_node_type(rpt_graph, rptg_node) = mer_type.
- % Implement the unify operator
+ % The unify operator.
%
:- pred unify_operator(rptg_node::in, rptg_node::in,
rpt_graph::in, rpt_graph::out) is det.
- % Implement the edge operator
+ % The edge operator.
%
:- pred edge_operator(rptg_node::in, rptg_node::in, rptg_arc_content::in,
rpt_graph::in, rpt_graph::out) is det.
@@ -251,7 +248,7 @@
:- pred find_arc_from_node_with_same_label(rptg_node::in,
rptg_arc_content::in, rpt_graph::in, rptg_node::out) is semidet.
- % Check if an edge (Start, Label, End) is in the Graph or not
+ % Check if an edge (Start, Label, End) is in the Graph or not.
%
:- pred edge_in_graph(rptg_node::in, rptg_arc_content::in, rptg_node::in,
rpt_graph::in) is semidet.
@@ -411,8 +408,7 @@
list.remove_dups([StartNode | VisitedNodes0], VisitedNodes),
list.delete_elems(StartNodes1, VisitedNodes, StartNodes),
- reachable_and_having_type_2(Graph, StartNodes, VisitedNodes,
- EType, E)
+ reachable_and_having_type_2(Graph, StartNodes, VisitedNodes, EType, E)
).
% Find a node with the given type in the list of nodes.
@@ -458,23 +454,23 @@
!.G= rpt_graph(NS, AS, N, A, _),
!:G = rpt_graph(NS, AS, N, A, E).
-rptg_node_content_get_varset(NC, NC^varset).
-rptg_node_content_get_region_name(NC, NC^reg_var_name).
-rptg_node_content_get_merged_from(NC, NC^merged_from).
-rptg_node_content_get_node_type(NC, NC^node_type).
+rptg_node_content_get_varset(NC, NC ^ varset).
+rptg_node_content_get_region_name(NC, NC ^ reg_var_name).
+rptg_node_content_get_merged_from(NC, NC ^ merged_from).
+rptg_node_content_get_node_type(NC, NC ^ node_type).
rptg_node_content_set_varset(VarSet, !NC) :-
- !.NC^varset := VarSet = !:NC.
+ !.NC ^ varset := VarSet = !:NC.
rptg_node_content_set_region_name(Name, !NC) :-
- !.NC^reg_var_name := Name = !:NC.
+ !.NC ^ reg_var_name := Name = !:NC.
rptg_node_content_set_merged_from(Nodes, !NC) :-
- !.NC^merged_from := Nodes = !:NC.
+ !.NC ^ merged_from := Nodes = !:NC.
rptg_node_content_set_node_type(NodeType, !NC) :-
- !.NC^node_type := NodeType = !:NC.
+ !.NC ^ node_type := NodeType = !:NC.
-rptg_arc_content_get_label(AC, AC^label).
+rptg_arc_content_get_label(AC, AC ^ label).
rptg_arc_content_set_label(Label, !AC) :-
- !.AC^label := Label = !:AC.
+ !.AC ^ label := Label = !:AC.
% find a node in the graph using its region name
%
@@ -487,8 +483,7 @@
then
Node = Node0
else
- unexpected(this_file,
- "get_node_by_region_name: No such a node exists")
+ unexpected(this_file, "get_node_by_region_name: No such a node exists")
).
:- pred get_node_by_region_name_from_list(rpt_graph::in, list(rptg_node)::in,
@@ -498,7 +493,7 @@
List = [ANode | Rest],
rptg_node_contents(Graph, ANode, NodeInfo),
( if
- NodeInfo^reg_var_name = RegName
+ NodeInfo ^ reg_var_name = RegName
then
Node = ANode
else
@@ -524,11 +519,9 @@
get_node_by_varset_from_list(Graph, List, Varset, Node) :-
List = [ANode | Rest],
rptg_node_contents(Graph, ANode, NodeInfo),
- ( if
- set.subset(Varset, NodeInfo^varset)
- then
+ ( set.subset(Varset, NodeInfo ^ varset) ->
Node = ANode
- else
+ ;
get_node_by_varset_from_list(Graph, Rest, Varset, Node)
).
@@ -545,41 +538,36 @@
get_node_by_node(Graph, Node, MergedNode) :-
% first the node in the NodeMap
rptg_get_nodemap(Graph, NodeMap),
- ( if
- map.search(NodeMap, Node, _NodeContent)
- then
+ ( map.search(NodeMap, Node, _NodeContent) ->
MergedNode = Node
- else
+ ;
% not directly in the NodeMap, checked if it has been merged
rptg_get_nodes(Graph, AllNodes),
- ( if
- get_node_by_node_from_list(Graph, AllNodes, Node, MergedNode0)
- then
+ ( get_node_by_node_from_list(Graph, AllNodes, Node, MergedNode0) ->
MergedNode = MergedNode0
- else
+ ;
unexpected(this_file, "get_node_by_node: No such a node exists")
)
).
:- pred get_node_by_node_from_list(rpt_graph::in, list(rptg_node)::in,
rptg_node::in, rptg_node::out) is semidet.
+
get_node_by_node_from_list(Graph, [N | Ns], Node, MergedNode) :-
rptg_node_contents(Graph, N, NContent),
- ( if
- set.member(Node, NContent^merged_from)
- then
+ ( set.member(Node, NContent ^ merged_from) ->
MergedNode = N
- else
+ ;
get_node_by_node_from_list(Graph, Ns, Node, MergedNode)
).
rptg_lookup_region_name(Graph, Node) = RegionName :-
rptg_node_contents(Graph, Node, Content),
- Content^reg_var_name = RegionName.
+ Content ^ reg_var_name = RegionName.
rptg_lookup_node_type(Graph, Node) = NodeType :-
rptg_node_contents(Graph, Node, Content),
- Content^node_type = NodeType.
+ Content ^ node_type = NodeType.
%-----------------------------------------------------------------------------%
%
@@ -593,10 +581,10 @@
rptg_node_contents(!.Graph, Node2, NodeContent2),
rptg_node_content_set_varset(
- set.union(NodeContent1^varset, NodeContent2^varset),
+ set.union(NodeContent1 ^ varset, NodeContent2 ^ varset),
NodeContent1, NewContent0),
rptg_node_content_set_merged_from(
- set.union(NodeContent1^merged_from, NodeContent2^merged_from),
+ set.union(NodeContent1 ^ merged_from, NodeContent2 ^ merged_from),
NewContent0, NewContent1),
map.det_update(NodeMap0, Node1, NewContent1, NodeMap1),
@@ -643,11 +631,9 @@
transfer_out_edges_2([], _, !Graph).
transfer_out_edges_2([Arc | Arcs], Node1, !Graph) :-
rptg_arc_contents(!.Graph, Arc, _Node2, Node, ArcContent),
- ( if
- edge_in_graph(Node1, ArcContent, Node, !.Graph)
- then
+ ( edge_in_graph(Node1, ArcContent, Node, !.Graph) ->
true
- else
+ ;
% not existed, copy the Arc as an out-edge of Node1
rptg_set_edge(Node1, Node, ArcContent, _Arc, !Graph)
),
@@ -682,11 +668,9 @@
arc_points_to_node(End, Arc, ArcInfo, !L) :-
ArcInfo = rptg_arc_info(_S, E, _C),
- ( if
- E = End
- then
+ ( E = End ->
!:L = [Arc | !.L]
- else
+ ;
true
).
@@ -699,11 +683,9 @@
transfer_in_edges_2([], _, !Graph).
transfer_in_edges_2([Arc | Arcs], Node1, !Graph) :-
rptg_arc_contents(!.Graph, Arc, Node, _Node2, ArcContent),
- ( if
- edge_in_graph(Node, ArcContent, Node1, !.Graph)
- then
+ ( edge_in_graph(Node, ArcContent, Node1, !.Graph) ->
true
- else
+ ;
% No, copy the Arc as an in-edge of Node1
rptg_set_edge(Node, Node1, ArcContent, _Arc, !Graph)
),
@@ -798,11 +780,9 @@
find_arc_with_same_label(ArcContent, [Arc | Arcs], G, M) :-
rptg_arc_contents(G, Arc, _N, M0, ArcContent0),
- ( if
- ArcContent0 = ArcContent
- then
+ ( ArcContent0 = ArcContent ->
M = M0
- else
+ ;
find_arc_with_same_label(ArcContent, Arcs, G, M)
).
@@ -954,27 +934,27 @@
update_remembered_list(Selector0, HLDS, TypeX, Graph, Processed, OutArc,
!List) :-
rptg_arc_contents(Graph, OutArc, _Start, End, ArcContent),
- ArcSelector = ArcContent^label,
+ ArcSelector = ArcContent ^ label,
Selector = Selector0 ++ ArcSelector,
- ( if
- check_type_of_node(HLDS, TypeX, Selector)
- then
+ ( check_type_of_node(HLDS, TypeX, Selector) ->
% The arc's selector is a valid one.
- ( if
- list.member(End, Processed)
- then
+ ( list.member(End, Processed) ->
% Already processed, ignore.
true
- else
+ ;
% A non-processed node and can be reached from X by a
% valid selector, so it is remembered.
- %
!:List = !.List ++ [pair(End, Selector)]
)
- else
+ ;
% Selector is not valid, ignore.
true
).
+%-----------------------------------------------------------------------------%
+
:- func this_file = string.
+
this_file = "rbmm.points_to_graph.m".
+
+%-----------------------------------------------------------------------------%
Index: rbmm.points_to_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.points_to_info.m,v
retrieving revision 1.2
diff -u -b -r1.2 rbmm.points_to_info.m
--- rbmm.points_to_info.m 23 May 2007 09:41:46 -0000 1.2
+++ rbmm.points_to_info.m 23 Jul 2007 04:37:07 -0000
@@ -77,9 +77,9 @@
rpta_info_table_init = map.init.
rpta_info_table_search_rpta_info(PredProcId, Table) = RptaInfo :-
- Table^elem(PredProcId) = RptaInfo.
+ Table ^ elem(PredProcId) = RptaInfo.
rpta_info_table_set_rpta_info(PredProcId, RptaInfo, Table0, Table) :-
- Table = Table0^elem(PredProcId) := RptaInfo.
+ Table = Table0 ^ elem(PredProcId) := RptaInfo.
% The rpta_info will be for a specific procedure, so at the beginning
% the alpha mapping is empty and the rpt graph contains all the nodes
@@ -105,11 +105,11 @@
NodeInfo = rptg_node_content(Varset, RegName, set.init, NodeType),
rptg_set_node(NodeInfo, _Node, !Graph).
-rpta_info_equal(RptaInfo1, RptaInfo2):-
- RptaInfo1 = rpta_info(Graph1, Alpha1),
- RptaInfo2 = rpta_info(Graph2, Alpha2),
- rptg_equal(Graph1, Graph2),
- rpt_alpha_mapping_equal(Alpha1, Alpha2).
+rpta_info_equal(RptaInfoA, RptaInfoB):-
+ RptaInfoA = rpta_info(GraphA, AlphaA),
+ RptaInfoB = rpta_info(GraphB, AlphaB),
+ rptg_equal(GraphA, GraphB),
+ rpt_alpha_mapping_equal(AlphaA, AlphaB).
%-----------------------------------------------------------------------------%
%
@@ -119,46 +119,46 @@
:- pred rpt_alpha_mapping_equal(rpt_alpha_mapping::in,
rpt_alpha_mapping::in) is semidet.
-rpt_alpha_mapping_equal(AlphaMapping1, AlphaMapping2) :-
- map.count(AlphaMapping1, C1),
- map.count(AlphaMapping2, C2),
- C1 = C2,
- map.keys(AlphaMapping1, CallSites1),
- rpt_alpha_mapping_equal_2(CallSites1, AlphaMapping1, AlphaMapping2).
+rpt_alpha_mapping_equal(AlphaMappingA, AlphaMappingB) :-
+ map.count(AlphaMappingA, CA),
+ map.count(AlphaMappingB, CB),
+ CA = CB,
+ map.keys(AlphaMappingA, CallSitesA),
+ rpt_alpha_mapping_equal_2(CallSitesA, AlphaMappingA, AlphaMappingB).
:- pred rpt_alpha_mapping_equal_2(list(program_point)::in,
rpt_alpha_mapping::in, rpt_alpha_mapping::in) is semidet.
rpt_alpha_mapping_equal_2([], _, _).
-rpt_alpha_mapping_equal_2([CallSite1 | CallSite1s],
- AlphaMapping1, AlphaMapping2) :-
- map.search(AlphaMapping2, CallSite1, AlphaMappingAtCallSite2),
- map.lookup(AlphaMapping1, CallSite1, AlphaMappingAtCallSite1),
+rpt_alpha_mapping_equal_2([CallSiteA | CallSiteAs],
+ AlphaMappingA, AlphaMappingB) :-
+ map.search(AlphaMappingB, CallSiteA, AlphaMappingAtCallSiteB),
+ map.lookup(AlphaMappingA, CallSiteA, AlphaMappingAtCallSiteA),
rpt_alpha_mapping_at_call_site_equal(
- AlphaMappingAtCallSite1,AlphaMappingAtCallSite2),
- rpt_alpha_mapping_equal_2(CallSite1s, AlphaMapping1, AlphaMapping2).
+ AlphaMappingAtCallSiteA,AlphaMappingAtCallSiteB),
+ rpt_alpha_mapping_equal_2(CallSiteAs, AlphaMappingA, AlphaMappingB).
:- pred rpt_alpha_mapping_at_call_site_equal(map(rptg_node, rptg_node)::in,
map(rptg_node, rptg_node)::in) is semidet.
-rpt_alpha_mapping_at_call_site_equal(AMAtCallSite1, AMAtCallSite2) :-
- map.count(AMAtCallSite1, C1),
- map.count(AMAtCallSite2, C2),
- C1 = C2,
- map.keys(AMAtCallSite1, Nodes1),
- rpt_alpha_mapping_at_call_site_equal_2(Nodes1, AMAtCallSite1,
- AMAtCallSite2).
+rpt_alpha_mapping_at_call_site_equal(AMAtCallSiteA, AMAtCallSiteB) :-
+ map.count(AMAtCallSiteA, CA),
+ map.count(AMAtCallSiteB, CB),
+ CA = CB,
+ map.keys(AMAtCallSiteA, NodesA),
+ rpt_alpha_mapping_at_call_site_equal_2(NodesA, AMAtCallSiteA,
+ AMAtCallSiteB).
:- pred rpt_alpha_mapping_at_call_site_equal_2(list(rptg_node)::in,
map(rptg_node, rptg_node)::in, map(rptg_node, rptg_node)::in) is semidet.
rpt_alpha_mapping_at_call_site_equal_2([], _, _).
-rpt_alpha_mapping_at_call_site_equal_2([N | Ns], AMAtCallSite1,
- AMAtCallSite2) :-
- map.search(AMAtCallSite2, N, NPrime2),
- map.lookup(AMAtCallSite1, N, NPrime1),
- NPrime1 = NPrime2,
- rpt_alpha_mapping_at_call_site_equal_2(Ns, AMAtCallSite1, AMAtCallSite2).
+rpt_alpha_mapping_at_call_site_equal_2([N | Ns], AMAtCallSiteA,
+ AMAtCallSiteB) :-
+ map.search(AMAtCallSiteB, N, NPrimeB),
+ map.lookup(AMAtCallSiteA, N, NPrimeA),
+ NPrimeA = NPrimeB,
+ rpt_alpha_mapping_at_call_site_equal_2(Ns, AMAtCallSiteA, AMAtCallSiteB).
%-----------------------------------------------------------------------------%
:- end_module rbmm.points_to_info.
Index: rbmm.region_instruction.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.region_instruction.m,v
retrieving revision 1.3
diff -u -b -r1.3 rbmm.region_instruction.m
--- rbmm.region_instruction.m 20 Jul 2007 08:09:53 -0000 1.3
+++ rbmm.region_instruction.m 23 Jul 2007 04:43:24 -0000
@@ -137,9 +137,9 @@
BornRTable, DeadRTable, LocalRTable, ProcId,
!RegionInstructionTable) :-
PPId = proc(PredId, ProcId),
- ( if some_are_special_preds([PPId], ModuleInfo)
- then true
- else
+ ( some_are_special_preds([PPId], ModuleInfo) ->
+ true
+ ;
module_info_proc_info(ModuleInfo, PPId, ProcInfo),
map.lookup(RptaInfoTable, PPId, RptaInfo),
map.lookup(BornRTable, PPId, BornR),
@@ -150,9 +150,8 @@
map.lookup(VoidVarRegionTable, PPId, ProcVoidVarRegion),
map.lookup(ExecPathTable, PPId, ExecPaths),
introduce_region_instructions_exec_paths(ExecPaths, RptaInfo,
- BornR, DeadR, LocalR,
- ProcLRBefore, ProcLRAfter, ProcVoidVarRegion,
- BornRTable, DeadRTable, ModuleInfo, ProcInfo,
+ BornR, DeadR, LocalR, ProcLRBefore, ProcLRAfter,
+ ProcVoidVarRegion, BornRTable, DeadRTable, ModuleInfo, ProcInfo,
map.init, RegionInstructionProc),
svmap.set(PPId, RegionInstructionProc, !RegionInstructionTable)
).
@@ -186,6 +185,7 @@
pp_region_set_table::in, proc_region_set_table::in,
proc_region_set_table::in, module_info::in, proc_info::in,
region_instruction_proc::in, region_instruction_proc::out) is det.
+
introduce_region_instructions_exec_path([], _, _, _, _, _, _, _, _, _, _, _,
!RegionInstructionProc).
introduce_region_instructions_exec_path([ProgPoint - Goal | ProgPoint_Goals],
@@ -206,17 +206,18 @@
set.union(Local_Born, DeadR, Local_Born_Dead),
set.intersect(Local_Born_Dead, DeadVoidVarRegions0, DeadVoidVarRegions),
RptaInfo = rpta_info(CallerGraph, _),
- set.fold(record_instruction_after_prog_point(remove_region_instruction, ProgPoint,
- CallerGraph), DeadVoidVarRegions, !RegionInstructionProc),
+ set.fold(
+ record_instruction_after_prog_point(remove_region_instruction,
+ ProgPoint, CallerGraph),
+ DeadVoidVarRegions, !RegionInstructionProc),
set.difference(LRBefore, LRAfter, ToBeRemoved),
set.intersect(ToBeRemoved, Local_Born_Dead, ToBeRemovedAndAllowed),
- ( if Goal = hlds_goal(switch(_, _, _), _)
- then
+ ( Goal = hlds_goal(switch(_, _, _), _) ->
% This is a switch, i.e. unification, only rule 4 applied.
transformation_rule_4_2(ProgPoint, ToBeRemovedAndAllowed,
RptaInfo, !RegionInstructionProc)
- else
+ ;
Goal = hlds_goal(Expr, _),
set.difference(LRAfter, LRBefore, ToBeCreated),
set.intersect(ToBeCreated, Local_Born, ToBeCreatedAndAllowed),
@@ -273,34 +274,40 @@
transformation_rule_1(Expr, ProgPoint, ToBeCreatedAndAllowed, CallerRptaInfo,
BornRTable, !RegionInstructionProc) :-
- ( Expr = plain_call(CalleePredId, CalleeProcId, _, _, _, _) ->
+ (
+ Expr = plain_call(CalleePredId, CalleeProcId, _, _, _, _)
+ ->
CalleePPId = proc(CalleePredId, CalleeProcId),
CallerRptaInfo = rpta_info(CallerGraph, AlphaMapping),
- ( if
+ (
% Currently we do not collect BornR for non-defined-in-module
% procedure, so if we cannot find one here then q is an
% imported.
map.search(BornRTable, CalleePPId, _)
- then
+ ->
map.lookup(AlphaMapping, ProgPoint, AlphaAtProgPoint),
map.lookup(BornRTable, CalleePPId, CalleeBornR),
- map.foldl(process_mapping_rule_1(ProgPoint,
- ToBeCreatedAndAllowed, CalleeBornR, CallerGraph),
+ map.foldl(
+ process_mapping_rule_1(ProgPoint, ToBeCreatedAndAllowed,
+ CalleeBornR, CallerGraph),
AlphaAtProgPoint, !RegionInstructionProc)
- else
+ ;
% q is from an imported module, therefore we consider BornR of
% q empty, so just create whatever regions becoming live
% provided that they are in BornR or LocalR, i.e., p is allowed
% to create them.
- set.fold(record_instruction_before_prog_point(
- create_region_instruction, ProgPoint, CallerGraph),
+ set.fold(
+ record_instruction_before_prog_point(create_region_instruction,
+ ProgPoint, CallerGraph),
ToBeCreatedAndAllowed, !RegionInstructionProc)
)
;
( Expr = conj(_, [])
; Expr = disj([])
; Expr = unify(_, _, _, _, _)
- ) -> true
+ )
+ ->
+ true
;
unexpected(this_file, "transformation_rule_1: found non-atomic goal")
).
@@ -311,12 +318,14 @@
process_mapping_rule_1(ProgPoint, ToBeCreatedAndAllowed, CalleeBornR,
CallerGraph, SourceRegion, TargetRegion, !RegionInstructionProc) :-
- ( if ( set.contains(ToBeCreatedAndAllowed, TargetRegion),
+ (
+ set.contains(ToBeCreatedAndAllowed, TargetRegion),
not set.contains(CalleeBornR, SourceRegion)
- )
- then record_instruction_before_prog_point(create_region_instruction, ProgPoint,
- CallerGraph, TargetRegion, !RegionInstructionProc)
- else true
+ ->
+ record_instruction_before_prog_point(create_region_instruction,
+ ProgPoint, CallerGraph, TargetRegion, !RegionInstructionProc)
+ ;
+ true
).
% Transformation rule 2: if a region reachable from the left variable
@@ -330,7 +339,9 @@
transformation_rule_2(Expr, ProgPoint, ToBeCreatedAndAllowed, RptaInfo,
ModuleInfo, ProcInfo, !RegionInstructionProc) :-
- ( Expr = unify(X, _, _, construct(_, _, _, _, _, _, _), _) ->
+ (
+ Expr = unify(X, _, _, construct(_, _, _, _, _, _, _), _)
+ ->
RptaInfo = rpta_info(Graph, _AlphaMapping),
% Need to be regions reachable from X.
reach_from_a_variable(Graph, ModuleInfo, ProcInfo, X,
@@ -349,7 +360,9 @@
; Expr = plain_call(_, _, _, _, _, _)
; Expr = conj(_, [])
; Expr = disj([])
- ) -> true
+ )
+ ->
+ true
;
unexpected(this_file, "transformation_rule_2: non-atomic goal found")
).
@@ -374,30 +387,35 @@
transformation_rule_3(Expr, ProgPoint, ToBeRemovedAndAllowed, CallerRptaInfo,
DeadRTable, !RegionInstructionProc) :-
- ( Expr = plain_call(CalleePredId, CalleeProcId, _, _, _, _) ->
+ (
+ Expr = plain_call(CalleePredId, CalleeProcId, _, _, _, _)
+ ->
CalleePPId = proc(CalleePredId, CalleeProcId),
CallerRptaInfo = rpta_info(CallerGraph, AlphaMapping),
- ( if map.search(DeadRTable, CalleePPId, _)
- then
+ ( map.search(DeadRTable, CalleePPId, _) ->
map.lookup(AlphaMapping, ProgPoint, AlphaAtProgPoint),
map.lookup(DeadRTable, CalleePPId, CalleeDeadR),
- map.foldl(process_mapping_rule_3(ProgPoint,
- ToBeRemovedAndAllowed, CalleeDeadR, CallerGraph),
+ map.foldl(
+ process_mapping_rule_3(ProgPoint, ToBeRemovedAndAllowed,
+ CalleeDeadR, CallerGraph),
AlphaAtProgPoint, !RegionInstructionProc)
- else
+ ;
% q is from an imported module. So just remove whatever regions
% become dead provided that p is allowed to remove those
% regions.
- set.fold(record_instruction_after_prog_point(
- remove_region_instruction, ProgPoint, CallerGraph),
+ set.fold(
+ record_instruction_after_prog_point(remove_region_instruction,
+ ProgPoint, CallerGraph),
ToBeRemovedAndAllowed, !RegionInstructionProc)
)
;
( Expr = unify(_, _, _, _, _)
; Expr = conj(_, [])
; Expr = disj([])
- ) -> true
+ )
+ ->
+ true
;
unexpected(this_file, "transformation_rule_3: non-atomic goal found")
).
@@ -408,12 +426,14 @@
process_mapping_rule_3(ProgPoint, ToBeRemovedAndAllowed, CalleeDeadR,
CallerGraph, SourceRegion, TargetRegion, !RegionInstructionProc) :-
- ( if ( set.contains(ToBeRemovedAndAllowed, TargetRegion),
+ (
+ set.contains(ToBeRemovedAndAllowed, TargetRegion),
not set.contains(CalleeDeadR, SourceRegion)
- )
- then record_instruction_after_prog_point(remove_region_instruction,
+ ->
+ record_instruction_after_prog_point(remove_region_instruction,
ProgPoint, CallerGraph, TargetRegion, !RegionInstructionProc)
- else true
+ ;
+ true
).
% Transformation rule 4: if a region is live before a unification but
@@ -427,7 +447,9 @@
transformation_rule_4(Expr, ProgPoint, ToBeRemovedAndAllowed, RptaInfo,
!RegionInstructionProc) :-
- ( Expr = unify(_, _, _, _, _) ->
+ (
+ Expr = unify(_, _, _, _, _)
+ ->
RptaInfo = rpta_info(Graph, _),
set.fold(record_instruction_after_prog_point(remove_region_instruction,
ProgPoint, Graph), ToBeRemovedAndAllowed, !RegionInstructionProc)
@@ -435,7 +457,9 @@
( Expr = plain_call(_, _, _, _, _, _)
; Expr = conj(_, [])
; Expr = disj([])
- ) -> true
+ )
+ ->
+ true
;
unexpected(this_file, "transformation_rule_4: non-atomic goal found")
).
@@ -451,8 +475,10 @@
transformation_rule_4_2(ProgPoint, ToBeRemovedAndAllowed, RptaInfo,
!RegionInstructionProc) :-
RptaInfo = rpta_info(Graph, _),
- set.fold(record_instruction_after_prog_point(remove_region_instruction, ProgPoint,
- Graph), ToBeRemovedAndAllowed, !RegionInstructionProc).
+ set.fold(
+ record_instruction_after_prog_point(remove_region_instruction,
+ ProgPoint, Graph),
+ ToBeRemovedAndAllowed, !RegionInstructionProc).
:- pred record_instruction_after_prog_point(region_instruction_type::in,
program_point::in, rpt_graph::in, rptg_node::in,
@@ -464,17 +490,20 @@
make_create_or_remove_instruction(RegionInstType, RegionName,
RegionInstruction),
% Attach the instruction to after the program point.
- ( if map.search(!.RegionInstructionProc, ProgPoint,
+ (
+ map.search(!.RegionInstructionProc, ProgPoint,
instructions_before_after(InstsBefore, InstsAfter))
- then
- ( if list.member(RegionInstruction, InstsAfter)
- then true
- else svmap.set(ProgPoint,
+ ->
+ ( list.member(RegionInstruction, InstsAfter) ->
+ true
+ ;
+ svmap.set(ProgPoint,
instructions_before_after(InstsBefore,
[RegionInstruction | InstsAfter]),
!RegionInstructionProc)
)
- else svmap.set(ProgPoint,
+ ;
+ svmap.set(ProgPoint,
instructions_before_after([], [RegionInstruction]),
!RegionInstructionProc)
).
@@ -489,19 +518,20 @@
make_create_or_remove_instruction(RegionInstType, RegionName,
RegionInstruction),
% Attach the instruction to before the program point.
- ( if map.search(!.RegionInstructionProc, ProgPoint,
+ (
+ map.search(!.RegionInstructionProc, ProgPoint,
instructions_before_after(InstsBefore, InstsAfter))
- then
- ( if list.member(RegionInstruction, InstsBefore)
- then true
- else svmap.set(ProgPoint,
- instructions_before_after(
- [RegionInstruction | InstsBefore],
- InstsAfter
- ),
+ ->
+ ( list.member(RegionInstruction, InstsBefore) ->
+ true
+ ;
+ svmap.set(ProgPoint,
+ instructions_before_after([RegionInstruction | InstsBefore],
+ InstsAfter),
!RegionInstructionProc)
)
- else svmap.set(ProgPoint,
+ ;
+ svmap.set(ProgPoint,
instructions_before_after([RegionInstruction], []),
!RegionInstructionProc)
).
@@ -526,6 +556,7 @@
%-----------------------------------------------------------------------------%
:- func this_file = string.
+
this_file = "rbmm.region_instruction.m".
%-----------------------------------------------------------------------------%
Index: rbmm.region_liveness_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.region_liveness_info.m,v
retrieving revision 1.1
diff -u -b -r1.1 rbmm.region_liveness_info.m
--- rbmm.region_liveness_info.m 23 May 2007 00:17:22 -0000 1.1
+++ rbmm.region_liveness_info.m 23 Jul 2007 04:43:58 -0000
@@ -7,7 +7,7 @@
%-----------------------------------------------------------------------------%
% File rbmm.region_liveness_info.m.
-% Main author: Quan Phan
+% Main author: Quan Phan.
%
% Defines the data structures used in several phases of the live region
% analysis.
@@ -107,7 +107,7 @@
proc_region_set_table::in) is semidet.
prst_equal_2([], _, _).
-prst_equal_2([PPId|PPIds], PRST1, PRST2) :-
+prst_equal_2([PPId | PPIds], PRST1, PRST2) :-
map.search(PRST2, PPId, RS2),
map.lookup(PRST1, PPId, RS1),
@@ -121,5 +121,3 @@
proc_info_get_argmodes(CalleeProcInfo, ArgModes),
arg_info.compute_in_and_out_vars(ModuleInfo, ArgVars, ArgModes, ArgTypes,
Inputs, Outputs).
-
-
Index: rbmm.region_resurrection_renaming.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.region_resurrection_renaming.m,v
retrieving revision 1.4
diff -u -b -r1.4 rbmm.region_resurrection_renaming.m
--- rbmm.region_resurrection_renaming.m 20 Jul 2007 08:09:53 -0000 1.4
+++ rbmm.region_resurrection_renaming.m 23 Jul 2007 04:50:35 -0000
@@ -186,9 +186,9 @@
svmap.set(PPId, CreatedBeforeProc, !CreatedBeforeTable),
% We only want to include procedures in which resurrection happens
% in this map.
- ( if map.count(PathContainsResurrectionProc) = 0
- then true
- else
+ ( map.count(PathContainsResurrectionProc) = 0 ->
+ true
+ ;
svmap.set(PPId, PathContainsResurrectionProc,
!PathContainsResurrectionTable)
).
@@ -206,9 +206,9 @@
set.init, ResurrectedRegionsInExecPath),
% We want to record only execution paths in which resurrections
% happen.
- ( if set.empty(ResurrectedRegionsInExecPath)
- then true
- else
+ ( set.empty(ResurrectedRegionsInExecPath) ->
+ true
+ ;
svmap.set(ExecPath, ResurrectedRegionsInExecPath,
!ResurrectedRegionProc)
).
@@ -264,10 +264,11 @@
collect_join_points_proc(ExecPathTable, PPId, _, !JoinPointTable) :-
map.lookup(ExecPathTable, PPId, ExecPaths),
- list.foldr(pred(ExecPath::in, Ps0::in, Ps::out) is det :- (
+ list.foldr(
+ pred(ExecPath::in, Ps0::in, Ps::out) is det :- (
assoc_list.keys(ExecPath, P),
- Ps = [P | Ps0]
- ), ExecPaths, [], Paths),
+ Ps = [P | Ps0]),
+ ExecPaths, [], Paths),
list.foldl3(collect_join_points_path(Paths), Paths,
counter.init(0), _, set.init, _JoinPoints, map.init, JoinPointProc),
svmap.set(PPId, JoinPointProc, !JoinPointTable).
@@ -282,21 +283,19 @@
list.delete_all(Paths, Path, TheOtherPaths),
% We ignore the first program point in each path because
% it cannot be a join point.
- ( if Path = [PrevPoint, ProgPoint | ProgPoints]
- then
- ( if is_join_point(ProgPoint, PrevPoint, TheOtherPaths)
- then
+ ( Path = [PrevPoint, ProgPoint | ProgPoints] ->
+ ( is_join_point(ProgPoint, PrevPoint, TheOtherPaths) ->
counter.allocate(N, !Counter),
- svmap.set(ProgPoint,
- "_jp_" ++ string.int_to_string(N),
+ svmap.set(ProgPoint, "_jp_" ++ string.int_to_string(N),
!JoinPointProc),
svset.insert(ProgPoint, !JoinPoints)
- else true
+ ;
+ true
),
- collect_join_points_path(Paths,
- [ProgPoint | ProgPoints], !Counter, !JoinPoints,
- !JoinPointProc)
- else true
+ collect_join_points_path(Paths, [ProgPoint | ProgPoints],
+ !Counter, !JoinPoints, !JoinPointProc)
+ ;
+ true
).
% This predicate succeeds if the first program point is a join point.
@@ -307,18 +306,20 @@
list(list(program_point))::in) is semidet.
is_join_point(ProgPoint, PrevProgPoint, [Path | Paths]) :-
- ( if is_join_point_2(ProgPoint, PrevProgPoint, Path)
- then true
- else is_join_point(ProgPoint, PrevProgPoint, Paths)
+ ( is_join_point_2(ProgPoint, PrevProgPoint, Path) ->
+ true
+ ;
+ is_join_point(ProgPoint, PrevProgPoint, Paths)
).
:- pred is_join_point_2(program_point::in, program_point::in,
list(program_point)::in) is semidet.
is_join_point_2(ProgPoint, PrevProgPoint, [P1, P2 | Ps]) :-
- ( if P2 = ProgPoint
- then P1 \= PrevProgPoint
- else is_join_point_2(ProgPoint, PrevProgPoint, [P2 | Ps])
+ ( P2 = ProgPoint ->
+ P1 \= PrevProgPoint
+ ;
+ is_join_point_2(ProgPoint, PrevProgPoint, [P2 | Ps])
).
%-----------------------------------------------------------------------------%
@@ -326,9 +327,10 @@
collect_paths_containing_join_points(ExecPathTable, JoinPointTable,
!PathContainsResurrectionTable) :-
- map.foldl(collect_paths_containing_join_points_proc(ExecPathTable,
- JoinPointTable), !.PathContainsResurrectionTable,
- !PathContainsResurrectionTable).
+ map.foldl(
+ collect_paths_containing_join_points_proc(ExecPathTable,
+ JoinPointTable),
+ !.PathContainsResurrectionTable, !PathContainsResurrectionTable).
:- pred collect_paths_containing_join_points_proc(execution_path_table::in,
join_point_region_name_table::in, pred_proc_id::in,
@@ -339,18 +341,19 @@
PathContainsResurrectionProc, !PathContainsResurrectionTable) :-
map.lookup(ExecPathTable, PPId, ExecPaths),
map.values(PathContainsResurrectionProc, ResurrectedRegionsInPaths),
- list.foldl(pred(ResurRegions::in, R0::in, R::out) is det :- (
+ list.foldl(
+ pred(ResurRegions::in, R0::in, R::out) is det :- (
set.union(R0, ResurRegions, R)
- ), ResurrectedRegionsInPaths,
- set.init, ResurrectedRegionsProc),
+ ),
+ ResurrectedRegionsInPaths, set.init, ResurrectedRegionsProc),
map.keys(PathContainsResurrectionProc, PathsContainResurrection),
list.delete_elems(ExecPaths, PathsContainResurrection, NonResurPaths),
- ( if map.search(JoinPointTable, PPId, JoinPointProc)
- then
+ ( map.search(JoinPointTable, PPId, JoinPointProc) ->
list.foldl(path_containing_join_point(JoinPointProc, PPId,
ResurrectedRegionsProc),
NonResurPaths, !PathContainsResurrectionTable)
- else true
+ ;
+ true
).
:- pred path_containing_join_point(map(program_point, string)::in,
@@ -363,9 +366,9 @@
assoc_list.keys(NonResurPath, ProgPointsInPath),
map.foldl(find_join_points_in_path(ProgPointsInPath), JoinPointProc,
set.init, JoinPointsInThisPath),
- ( if set.empty(JoinPointsInThisPath)
- then true
- else
+ ( set.empty(JoinPointsInThisPath) ->
+ true
+ ;
map.lookup(!.PathContainsResurrectionTable, PPId,
PathContainsResurrectionProc0),
svmap.det_insert(NonResurPath, ResurrectedRegionsProc,
@@ -379,9 +382,10 @@
set(program_point)::out) is det.
find_join_points_in_path(ProgPointsInPath, JoinPoint, _, !JoinPoints) :-
- ( if list.member(JoinPoint, ProgPointsInPath)
- then svset.insert(JoinPoint, !JoinPoints)
- else true
+ ( list.member(JoinPoint, ProgPointsInPath) ->
+ svset.insert(JoinPoint, !JoinPoints)
+ ;
+ true
).
%-----------------------------------------------------------------------------%
@@ -406,7 +410,8 @@
map.lookup(CreatedBeforeTable, PPId, CreatedBeforeProc),
map.lookup(RptaInfoTable, PPId, RptaInfo),
RptaInfo = rpta_info(Graph, _),
- map.foldl(collect_region_resurrection_renaming_exec_path(Graph,
+ map.foldl(
+ collect_region_resurrection_renaming_exec_path(Graph,
CreatedBeforeProc),
PathsContainResurrection, map.init, ResurrectionRenameProc),
svmap.set(PPId, ResurrectionRenameProc, !ResurrectionRenameTable).
@@ -418,9 +423,10 @@
collect_region_resurrection_renaming_exec_path(Graph, CreatedBeforeProc,
ExecPath, ResurrectedRegions, !ResurrectionRenameProc) :-
- list.foldl2(collect_region_resurrection_renaming_prog_point(Graph,
- CreatedBeforeProc, ResurrectedRegions), ExecPath, 1, _,
- !ResurrectionRenameProc).
+ list.foldl2(
+ collect_region_resurrection_renaming_prog_point(Graph,
+ CreatedBeforeProc, ResurrectedRegions),
+ ExecPath, 1, _, !ResurrectionRenameProc).
:- pred collect_region_resurrection_renaming_prog_point(rpt_graph::in,
pp_region_set_table::in, region_set::in,
@@ -434,12 +440,12 @@
set.intersect(ResurrectedRegions, CreatedBeforeProgPoint,
ToBeRenamedRegions),
% We only record the program points where resurrection renaming exists.
- ( if set.empty(ToBeRenamedRegions)
- then true
- else
- set.fold(record_renaming_prog_point(Graph, ProgPoint,
- !.RenamingCounter), ToBeRenamedRegions,
- !ResurrectionRenameProc)
+ ( set.empty(ToBeRenamedRegions) ->
+ true
+ ;
+ set.fold(
+ record_renaming_prog_point(Graph, ProgPoint, !.RenamingCounter),
+ ToBeRenamedRegions, !ResurrectionRenameProc)
),
!:RenamingCounter = !.RenamingCounter + 1.
@@ -452,16 +458,13 @@
Renamed = RegionName ++ "_Resur_"
++ string.int_to_string(RenamingCounter),
- ( if map.search(!.ResurrectionRenameProc, ProgPoint,
- RenamingProgPoint0)
- then
- svmap.set(RegionName, Renamed,
- RenamingProgPoint0, RenamingProgPoint)
- else svmap.det_insert(RegionName, Renamed, map.init, RenamingProgPoint)
+ ( map.search(!.ResurrectionRenameProc, ProgPoint, RenamingProgPoint0) ->
+ svmap.set(RegionName, Renamed, RenamingProgPoint0, RenamingProgPoint)
+ ;
+ svmap.det_insert(RegionName, Renamed, map.init, RenamingProgPoint)
),
svmap.set(ProgPoint, RenamingProgPoint, !ResurrectionRenameProc).
-
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -504,10 +507,11 @@
% for all resurrecting regions that become live at the join point.
map.lookup(ResurrectionPathTable, PPId, PathsContainResurrection),
map.values(PathsContainResurrection, ResurrectedRegionsInPaths),
- list.foldl(pred(ResurRegions::in, R0::in, R::out) is det :- (
+ list.foldl(
+ pred(ResurRegions::in, R0::in, R::out) is det :- (
set.union(R0, ResurRegions, R)
- ), ResurrectedRegionsInPaths,
- set.init, ResurrectedRegionsProc),
+ ),
+ ResurrectedRegionsInPaths, set.init, ResurrectedRegionsProc),
map.lookup(ExecPathTable, PPId, ExecPaths),
list.foldl2(collect_renaming_and_annotation_exec_path(
ResurrectionRenameProc, JoinPointProc, LRBeforeProc, BornR,
@@ -541,9 +545,10 @@
collect_renaming_and_annotation_exec_path(ResurrectionRenameProc,
JoinPointProc, LRBeforeProc, BornR, Graph, ResurrectedRegions,
[ProgPoint - _ | ProgPoint_Goals], !AnnotationProc, !RenamingProc) :-
- ( if map.search(ResurrectionRenameProc, ProgPoint, ResurRename)
- then svmap.set(ProgPoint, ResurRename, !RenamingProc)
- else svmap.set(ProgPoint, map.init, !RenamingProc)
+ ( map.search(ResurrectionRenameProc, ProgPoint, ResurRename) ->
+ svmap.set(ProgPoint, ResurRename, !RenamingProc)
+ ;
+ svmap.set(ProgPoint, map.init, !RenamingProc)
),
collect_renaming_and_annotation_exec_path_2(ResurrectionRenameProc,
JoinPointProc, LRBeforeProc, BornR, Graph, ResurrectedRegions,
@@ -586,36 +591,33 @@
PrevProgPoint, [ProgPoint - _ | ProgPoint_Goals],
!AnnotationProc, !RenamingProc) :-
map.lookup(!.RenamingProc, PrevProgPoint, PrevRenaming),
- ( if map.search(ResurrectionRenameProc, ProgPoint, ResurRenaming)
- then
- % This is a resurrection point of some region(s). We need to
- % merge the existing renaming at the previous point with the
- % resurrection renaming here. When two renamings have the same
- % key, i.e., the region resurrects, the resurrection renaming
- % takes priority.
+ ( map.search(ResurrectionRenameProc, ProgPoint, ResurRenaming) ->
+ % This is a resurrection point of some region(s). We need to merge
+ % the existing renaming at the previous point with the resurrection
+ % renaming here. When two renamings have the same key, i.e., the region
+ % resurrects, the resurrection renaming takes priority.
map.overlay(PrevRenaming, ResurRenaming, Renaming0),
svmap.set(ProgPoint, Renaming0, !RenamingProc)
- else
+ ;
% This is not a resurrection point (of any regions).
- % Renaming at this point is the same as at its
- % previous point
+ % Renaming at this point is the same as at its previous point.
svmap.set(ProgPoint, PrevRenaming, !RenamingProc)
),
- ( if map.search(JoinPointProc, ProgPoint, JoinPointName)
- then
+ ( map.search(JoinPointProc, ProgPoint, JoinPointName) ->
% This is a join point.
% Add annotations to the previous point.
map.lookup(LRBeforeProc, ProgPoint, LRBeforeProgPoint),
set.intersect(ResurrectedRegions, LRBeforeProgPoint,
ResurrectedAndLiveRegions),
- set.fold2(add_annotation_and_renaming(PrevProgPoint,
- Graph, JoinPointName, PrevRenaming),
- ResurrectedAndLiveRegions, !AnnotationProc,
- map.init, Renaming),
- % We will just overwrite any existing renaming
- % information at this point.
+ set.fold2(
+ add_annotation_and_renaming(PrevProgPoint, Graph,
+ JoinPointName, PrevRenaming),
+ ResurrectedAndLiveRegions, !AnnotationProc, map.init, Renaming),
+ % We will just overwrite any existing renaming information
+ % at this point.
svmap.set(ProgPoint, Renaming, !RenamingProc)
- else true
+ ;
+ true
),
(
% This is the last program point in this execution path.
@@ -654,13 +656,11 @@
% PrevProgPoint and ProgPoint).
% It seems that we have to add annotations (reverse renaming) for ones that
% have not been renamed as implemented below too. The only difference is
- % that
- % the reverse renaming is between the new name and the original name.
- ( if map.search(PrevRenaming, RegionName, CurrentName)
- then
+ % that the reverse renaming is between the new name and the original name.
+ ( map.search(PrevRenaming, RegionName, CurrentName) ->
make_renaming_instruction(CurrentName, NewName, Annotation),
record_annotation(PrevProgPoint, Annotation, !AnnotationProc)
- else
+ ;
make_renaming_instruction(RegionName, NewName, Annotation),
record_annotation(PrevProgPoint, Annotation, !AnnotationProc)
).
@@ -675,21 +675,21 @@
% Add annotation to (after) the program point.
% Annotations are only added for resurrected regions that have been
% renamed in this execution path.
- ( if map.search(Renaming, RegionName, CurrentName)
- then
+ ( map.search(Renaming, RegionName, CurrentName) ->
make_renaming_instruction(CurrentName, RegionName, Annotation),
record_annotation(ProgPoint, Annotation, !AnnotationProc)
- else true
+ ;
+ true
).
record_annotation(ProgPoint, Annotation, !AnnotationProc) :-
- ( if map.search(!.AnnotationProc, ProgPoint, Annotations0)
- then
- ( if list.member(Annotation, Annotations0)
- then Annotations = Annotations0
- else Annotations = [Annotation | Annotations0]
+ ( map.search(!.AnnotationProc, ProgPoint, Annotations0) ->
+ ( list.member(Annotation, Annotations0) ->
+ Annotations = Annotations0
+ ;
+ Annotations = [Annotation | Annotations0]
)
- else
+ ;
% No annotation exists at this program point yet.
Annotations = [Annotation]
),
@@ -697,6 +697,7 @@
make_renaming_instruction(OldRegionName, NewRegionName, RenameInstruction) :-
RenameInstruction = rename_region(OldRegionName, NewRegionName).
+
%-----------------------------------------------------------------------------%
:- func this_file = string.
Index: rbmm.region_transformation.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/rbmm.region_transformation.m,v
retrieving revision 1.2
diff -u -b -r1.2 rbmm.region_transformation.m
--- rbmm.region_transformation.m 20 Jul 2007 08:09:53 -0000 1.2
+++ rbmm.region_transformation.m 23 Jul 2007 04:03:33 -0000
@@ -35,6 +35,7 @@
:- import_module map.
:- import_module string.
+
%-----------------------------------------------------------------------------%
% Represent mapping from region name to a program variable that
@@ -43,6 +44,12 @@
:- type name_to_prog_var_table == map(pred_proc_id, name_to_prog_var).
:- type name_to_prog_var == map(string, prog_var).
+ % The names of the predicates for creating and removing regions.
+ % The predicates are in mercury_region_builtin_module.
+ %
+:- func create_region_pred_name = string.
+:- func remove_region_pred_name = string.
+
% XXX Besides changing the HLDS, this predicate also returns a mapping
% from a region name to a program variable which represents the
% region. We will only create a new program variable for a region
@@ -90,8 +97,12 @@
:- import_module svvarset.
:- import_module term.
:- import_module varset.
+
%-----------------------------------------------------------------------------%
+create_region_pred_name = "create_region".
+remove_region_pred_name = "remove_region".
+
region_transform(RptaInfoTable, ConstantRTable, DeadRTable, BornRTable,
ActualRegionArgTable, ResurRenamingTable, IteRenamingTable,
RegionInstructionTable, ResurRenamingAnnoTable, IteRenamingAnnoTable,
@@ -103,16 +114,18 @@
ResurRenamingTable, IteRenamingTable,
RegionInstructionTable, ResurRenamingAnnoTable, IteRenamingAnnoTable),
PredIds, !NameToVarTable, !ModuleInfo),
+
% We can only do the followings when all the procedures have been
% annotated with region information and recorded. This is necessary
% because recompute_instmap_delta_proc and repuritycheck_proc need to
% look up information about the (annotated) called procedures.
- %
+
list.foldl(update_instmap_delta_pred, PredIds, !ModuleInfo),
list.foldl(recheck_purity_pred, PredIds, !ModuleInfo).
% This predicate updates pred_info structure. The following information
% is updated:
+ %
% 1. Original arity: orig_arity, which is updated with the old value +
% the number of region arguments.
% 2. Argument types: arg_types, updated with region type for region
@@ -125,41 +138,34 @@
annotate_pred(DeadRTable, BornRTable, PPId, ConstantR, !Processed,
!ModuleInfo) :-
PPId = proc(PredId, _),
- ( if list.member(PredId, !.Processed)
- then true
- else
+ ( list.member(PredId, !.Processed) ->
+ true
+ ;
some [!PredInfo] (
- module_info_pred_info(!.ModuleInfo, PredId,
- !:PredInfo),
+ module_info_pred_info(!.ModuleInfo, PredId, !:PredInfo),
map.lookup(DeadRTable, PPId, DeadR),
map.lookup(BornRTable, PPId, BornR),
- NumberOfRegArgs = set.count(DeadR) +
- set.count(BornR) + set.count(ConstantR),
+ NumberOfRegArgs = set.count(DeadR) + set.count(BornR) +
+ set.count(ConstantR),
Arity = pred_info_orig_arity(!.PredInfo),
- pred_info_set_orig_arity(
- Arity + NumberOfRegArgs, !PredInfo),
+ pred_info_set_orig_arity(Arity + NumberOfRegArgs, !PredInfo),
list.duplicate(NumberOfRegArgs, region_type, RegionTypes),
- pred_info_get_arg_types(!.PredInfo, TypeVarSet,
- ExistQuantTVars, ArgTypes0),
- PredOrFunc =
- pred_info_is_pred_or_func(!.PredInfo),
+ pred_info_get_arg_types(!.PredInfo, TypeVarSet, ExistQuantTVars,
+ ArgTypes0),
+ PredOrFunc = pred_info_is_pred_or_func(!.PredInfo),
(
PredOrFunc = pf_predicate,
ArgTypes = ArgTypes0 ++ RegionTypes
;
PredOrFunc = pf_function,
- % The output of function is always at
- % the last.
- list.split_last_det(ArgTypes0,
- BeforeLast, Last),
- ArgTypes = BeforeLast ++ RegionTypes
- ++ [Last]
- ),
- pred_info_set_arg_types(TypeVarSet,
- ExistQuantTVars, ArgTypes, !PredInfo),
- module_info_set_pred_info(PredId, !.PredInfo,
- !ModuleInfo)
+ % The output of function is always at the last.
+ list.split_last_det(ArgTypes0, BeforeLast, Last),
+ ArgTypes = BeforeLast ++ RegionTypes ++ [Last]
+ ),
+ pred_info_set_arg_types(TypeVarSet, ExistQuantTVars, ArgTypes,
+ !PredInfo),
+ module_info_set_pred_info(PredId, !.PredInfo, !ModuleInfo)
),
!:Processed = [PredId | !.Processed]
).
@@ -188,6 +194,7 @@
% This predicate updates the proc_info data structure, representing
% a procedure.
+ %
% - Introduce new variables for regions (and their region types).
% - Update headvars with region arguments (types and modes).
% - Update the body
@@ -195,9 +202,9 @@
% + actual region arguments at call sites,
% + how_to_construct at construction unifications.
% - *Requantify* the annotated proc.
+ %
% As said above, we will recompute instmap delta, recheck purity for
- % this annotated procedure after all the procedures have been
- % transformed.
+ % this annotated procedure after all the procedures have been transformed.
%
:- pred region_transform_proc(rpta_info_table::in, proc_region_set_table::in,
proc_region_set_table::in, proc_region_set_table::in,
@@ -224,21 +231,17 @@
map.lookup(DeadRTable, PPId, DeadR),
map.lookup(BornRTable, PPId, BornR),
map.lookup(ActualRegionArgTable, PPId, ActualRegionArgProc),
- ( if map.search(ResurRenamingTable, PPId, ResurRenamingProc0)
- then
+ ( map.search(ResurRenamingTable, PPId, ResurRenamingProc0) ->
ResurRenamingProc = ResurRenamingProc0,
- map.lookup(ResurRenamingAnnoTable, PPId,
- ResurRenamingAnnoProc)
- else
+ map.lookup(ResurRenamingAnnoTable, PPId, ResurRenamingAnnoProc)
+ ;
ResurRenamingProc = map.init,
ResurRenamingAnnoProc = map.init
),
- ( if map.search(IteRenamingTable, PPId, IteRenamingProc0)
- then
+ ( map.search(IteRenamingTable, PPId, IteRenamingProc0) ->
IteRenamingProc = IteRenamingProc0,
- map.lookup(IteRenamingAnnoTable, PPId,
- IteRenamingAnnoProc)
- else
+ map.lookup(IteRenamingAnnoTable, PPId, IteRenamingAnnoProc)
+ ;
IteRenamingProc = map.init,
IteRenamingAnnoProc = map.init
),
@@ -254,6 +257,7 @@
svmap.det_insert(PPId, NameToVar, !NameToVarTable).
% Currently for a procedure we annotate the following information:
+ %
% 1. VarSet with region variables
% 2. VarTypes with region variables and their types
% 3. HeadVars with formal region arguments
@@ -285,6 +289,7 @@
% Add extra variables to the head of the procedure that correspond
% to the introduced region arguments.
% They are added as follows.
+ %
% For predicates:
% <OrigArgs> ==> <OrigArgs> <InputRegionArgs> <OutputRegionArgs>
%
@@ -317,8 +322,7 @@
;
PredOrFunc = pf_function,
list.split_last_det(!.HeadVars, BeforeLastHeadVar, LastHeadVar),
- !:HeadVars = BeforeLastHeadVar ++ FormalRegionArgs
- ++ [LastHeadVar],
+ !:HeadVars = BeforeLastHeadVar ++ FormalRegionArgs ++ [LastHeadVar],
list.split_last_det(!.ActualArgModes, BeforeLastHeadMode,
LastHeadMode),
!:ActualArgModes = BeforeLastHeadMode ++ InModes
@@ -331,10 +335,9 @@
proc_info_set_headvars(!.HeadVars, !ProcInfo),
proc_info_set_argmodes(!.ActualArgModes, !ProcInfo).
- % Basically, we will turn this atomic goal and all the region
- % annotations attached to (before and after) it into a
- % conjunction. When there is no annotation, the goal is just
- % transformed and returned.
+ % Basically, we will turn this atomic goal and all the region annotations
+ % attached to (before and after) it into a conjunction. When there is
+ % no annotation, the goal is just transformed and returned.
% If the newly created conjunction is a conjunct of a compounding
% conjunction then it will be flattened.
%
@@ -355,8 +358,7 @@
ActualRegionArgProc, RegionInstructionProc, ResurRenamingAnnoProc,
IteRenamingAnnoProc, !Goal, !NameToVar, !VarSet, !VarTypes) :-
!.Goal = hlds_goal(GoalExpr0, Info0),
- ( goal_is_atomic(GoalExpr0)
- ->
+ ( goal_is_atomic(GoalExpr0) ->
ProgPoint = program_point_init(Info0),
ProgPoint = pp(Context, _),
find_renamings_at_prog_point(ResurRenamingProc, IteRenamingProc,
@@ -366,37 +368,33 @@
% - a call with actual region arguments,
% - a construction unification with a region to construct in.
region_transform_goal_expr(ModuleInfo, Graph, ResurRenaming,
- IteRenaming, ActualRegionArgProc, ProgPoint,
- GoalExpr0, GoalExpr, Info0, Info, !NameToVar, !VarSet,
- !VarTypes),
+ IteRenaming, ActualRegionArgProc, ProgPoint, GoalExpr0, GoalExpr,
+ Info0, Info, !NameToVar, !VarSet, !VarTypes),
% Assignment unifications due to ite renaming.
- assignments_from_ite_renaming_anno(IteRenamingAnnoProc,
- ProgPoint, !NameToVar, !VarSet, !VarTypes,
- [], IteRenamingAssignments),
+ assignments_from_ite_renaming_anno(IteRenamingAnnoProc, ProgPoint,
+ !NameToVar, !VarSet, !VarTypes, [], IteRenamingAssignments),
% Region instructions before and after this program point.
- ( map.search(RegionInstructionProc, ProgPoint,
+ (
+ map.search(RegionInstructionProc, ProgPoint,
instructions_before_after(Before, After))
->
% Region instructions before this program point.
- list.foldl4(region_instruction_to_conj(ModuleInfo,
- Context, ResurRenaming, IteRenaming), Before,
- !NameToVar, !VarSet, !VarTypes,
- IteRenamingAssignments, Conjs1),
+ list.foldl4(region_instruction_to_conj(ModuleInfo, Context,
+ ResurRenaming, IteRenaming), Before, !NameToVar,
+ !VarSet, !VarTypes, IteRenamingAssignments, Conjs1),
% The goal at this program point itself.
Conjs2 = Conjs1 ++ [hlds_goal(GoalExpr, Info)],
% Region instructions after this program point.
- list.foldl4(region_instruction_to_conj(ModuleInfo,
- Context, ResurRenaming, IteRenaming), After,
- !NameToVar, !VarSet, !VarTypes,
- Conjs2, Conjs3)
+ list.foldl4(region_instruction_to_conj(ModuleInfo, Context,
+ ResurRenaming, IteRenaming), After, !NameToVar,
+ !VarSet, !VarTypes, Conjs2, Conjs3)
;
% The goal at this program point itself.
- Conjs3 = IteRenamingAssignments ++
- [hlds_goal(GoalExpr, Info)]
+ Conjs3 = IteRenamingAssignments ++ [hlds_goal(GoalExpr, Info)]
),
% Assignment unifications due to region resurrection renaming.
@@ -404,18 +402,16 @@
ProgPoint, IteRenaming, !NameToVar, !VarSet, !VarTypes,
Conjs3, Conjs),
- ( if Conjs = [_, _ | _]
- then
- !:Goal = hlds_goal(conj(plain_conj, Conjs),
- Info)
- else !:Goal = hlds_goal(GoalExpr, Info)
+ ( Conjs = [_, _ | _] ->
+ !:Goal = hlds_goal(conj(plain_conj, Conjs), Info)
+ ;
+ !:Goal = hlds_goal(GoalExpr, Info)
)
;
region_transform_compound_goal(ModuleInfo, Graph,
ResurRenamingProc, IteRenamingProc, ActualRegionArgProc,
RegionInstructionProc, ResurRenamingAnnoProc,
- IteRenamingAnnoProc, !Goal, !NameToVar, !VarSet,
- !VarTypes)
+ IteRenamingAnnoProc, !Goal, !NameToVar, !VarSet, !VarTypes)
).
:- pred region_transform_goal_expr(module_info::in, rpt_graph::in,
@@ -434,14 +430,15 @@
Context, Name),
% XXX Callee may be a builtin or an imported procedure that we have
% not analysed, we just ignore such a call for now.
- ( if map.search(ActualRegionArgProc, ProgPoint, ActualNodes0)
- then ActualNodes = ActualNodes0
- else ActualNodes = pair([],[])
+ ( map.search(ActualRegionArgProc, ProgPoint, ActualNodes0) ->
+ ActualNodes = ActualNodes0
+ ;
+ ActualNodes = pair([],[])
),
ActualNodes = Ins - Outs,
AllNodes = Ins ++ Outs,
- list.map_foldl3(node_to_var_with_both_renamings(Graph,
- ResurRenaming, IteRenaming),
+ list.map_foldl3(
+ node_to_var_with_both_renamings(Graph, ResurRenaming, IteRenaming),
AllNodes, ActualRegionArgs, !NameToVar, !VarSet, !VarTypes),
Args = Args0 ++ ActualRegionArgs,
!:GoalExpr = plain_call(CalleePredId, CalleeProcId, Args, Builtin,
@@ -452,9 +449,9 @@
region_transform_goal_expr(ModuleInfo, Graph, ResurRenaming, IteRenaming,
_, _, !GoalExpr, !GoalInfo, !NameToVar, !VarSet, !VarTypes) :-
!.GoalExpr = unify(LHS, RHS, Mode, Unification0, Context),
- annotate_constructions_unification(ModuleInfo, Graph, ResurRenaming,
- IteRenaming, Unification0, Unification, !NameToVar, !VarSet,
- !VarTypes),
+ annotate_constructions_unification(ModuleInfo, Graph,
+ ResurRenaming, IteRenaming, Unification0, Unification,
+ !NameToVar, !VarSet, !VarTypes),
!:GoalExpr = unify(LHS, RHS, Mode, Unification, Context).
region_transform_goal_expr(_, _, _, _, _, _, !GoalExpr, !GoalInfo, !NameToVar,
@@ -508,8 +505,7 @@
ResurRenamingProc, IteRenamingProc,
ActualRegionArgProc, RegionInstructionProc,
ResurRenamingAnnoProc, IteRenamingAnnoProc),
- [Conj0 | Conjs0], Conjs1, !NameToVar, !VarSet,
- !VarTypes),
+ [Conj0 | Conjs0], Conjs1, !NameToVar, !VarSet, !VarTypes),
flatten_conj(Conjs1, Conjs),
!:GoalExpr = conj(ConjType, Conjs)
;
@@ -518,8 +514,7 @@
ResurRenamingProc, IteRenamingProc,
ActualRegionArgProc, RegionInstructionProc,
ResurRenamingAnnoProc, IteRenamingAnnoProc),
- [Disj0 | Disjs0], Disjs, !NameToVar, !VarSet,
- !VarTypes),
+ [Disj0 | Disjs0], Disjs, !NameToVar, !VarSet, !VarTypes),
!:GoalExpr = disj(Disjs)
;
!.GoalExpr = switch(Var, CanFail, Cases0),
@@ -589,11 +584,13 @@
IsUnique, SubInfo),
get_node_by_variable(Graph, Var, Node),
NodeType = rptg_lookup_node_type(Graph, Node),
- ( if ( type_is_atomic(ModuleInfo, NodeType)
+ (
+ ( type_is_atomic(ModuleInfo, NodeType)
; is_dummy_argument_type(ModuleInfo, NodeType)
)
- then true
- else
+ ->
+ true
+ ;
Name = rptg_lookup_region_name(Graph, Node),
region_name_to_var_with_both_renamings(Name, ResurRenaming,
IteRenaming, RegVar, !NameToVar, !VarSet, !VarTypes),
@@ -637,7 +634,8 @@
ResurRenamingAnnoProc, IteRenamingAnnoProc, Switch,
case(ConsId, !.Goal), case(ConsId, !:Goal),
!NameToVar, !VarSet, !VarTypes) :-
- ( ( ConsId = cons(_, 0)
+ (
+ ( ConsId = cons(_, 0)
; ConsId = int_const(_)
; ConsId = string_const(_)
; ConsId = float_const(_)
@@ -650,36 +648,34 @@
ProgPoint, ResurRenaming, IteRenaming),
% Assignment unifications due to ite renaming.
- assignments_from_ite_renaming_anno(IteRenamingAnnoProc,
- ProgPoint, !NameToVar, !VarSet, !VarTypes,
- [], IteRenamingAssignments),
-
- % Region instructions before and after this program
- % point.
- ( map.search(RegionInstructionProc, ProgPoint,
+ assignments_from_ite_renaming_anno(IteRenamingAnnoProc, ProgPoint,
+ !NameToVar, !VarSet, !VarTypes, [], IteRenamingAssignments),
+
+ % Region instructions before and after this program point.
+ (
+ map.search(RegionInstructionProc, ProgPoint,
instructions_before_after(Before, After))
->
% Region instructions before this program point.
- list.foldl4(region_instruction_to_conj(
- ModuleInfo, Context, ResurRenaming,
- IteRenaming), Before, !NameToVar,
- !VarSet, !VarTypes,
+ list.foldl4(
+ region_instruction_to_conj(ModuleInfo, Context, ResurRenaming,
+ IteRenaming),
+ Before, !NameToVar, !VarSet, !VarTypes,
IteRenamingAssignments, Conjs1),
% Region instructions after this program point.
- list.foldl4(region_instruction_to_conj(
- ModuleInfo, Context, ResurRenaming,
- IteRenaming), After, !NameToVar,
- !VarSet, !VarTypes, Conjs1, Conjs2)
+ list.foldl4(
+ region_instruction_to_conj(ModuleInfo, Context, ResurRenaming,
+ IteRenaming),
+ After, !NameToVar, !VarSet, !VarTypes, Conjs1, Conjs2)
;
Conjs2 = IteRenamingAssignments
),
% Assignment unifications due to region resurrection
% renaming.
- assignments_from_resur_renaming_anno(ResurRenamingAnnoProc,
- ProgPoint, IteRenaming, !NameToVar, !VarSet, !VarTypes,
- Conjs2, Conjs),
+ assignments_from_resur_renaming_anno(ResurRenamingAnnoProc, ProgPoint,
+ IteRenaming, !NameToVar, !VarSet, !VarTypes, Conjs2, Conjs),
RemovedGoal = hlds_goal(conj(plain_conj, Conjs), Info)
;
@@ -699,13 +695,15 @@
find_renamings_at_prog_point(ResurRenamingProc, IteRenamingProc, ProgPoint,
ResurRenaming, IteRenaming) :-
- ( if map.search(ResurRenamingProc, ProgPoint, ResurRenaming0)
- then ResurRenaming = ResurRenaming0
- else ResurRenaming = map.init
- ),
- ( if map.search(IteRenamingProc, ProgPoint, IteRenaming0)
- then IteRenaming = IteRenaming0
- else IteRenaming = map.init
+ ( map.search(ResurRenamingProc, ProgPoint, ResurRenaming0) ->
+ ResurRenaming = ResurRenaming0
+ ;
+ ResurRenaming = map.init
+ ),
+ ( map.search(IteRenamingProc, ProgPoint, IteRenaming0) ->
+ IteRenaming = IteRenaming0
+ ;
+ IteRenaming = map.init
).
:- pred assignments_from_ite_renaming_anno(renaming_annotation_proc::in,
@@ -716,12 +714,11 @@
assignments_from_ite_renaming_anno(IteRenamingAnnoProc, ProgPoint,
!NameToVar, !VarSet, !VarTypes, !IteRenamingAssignments) :-
% Assignment unifications due to ite renaming.
- ( map.search(IteRenamingAnnoProc, ProgPoint, IteRenamingAnnos)
- ->
- list.foldl4(ite_renaming_annotation_to_assignment,
- IteRenamingAnnos, !NameToVar, !VarSet, !VarTypes,
- !IteRenamingAssignments)
- ; true
+ ( map.search(IteRenamingAnnoProc, ProgPoint, IteRenamingAnnos) ->
+ list.foldl4(ite_renaming_annotation_to_assignment, IteRenamingAnnos,
+ !NameToVar, !VarSet, !VarTypes, !IteRenamingAssignments)
+ ;
+ true
).
:- pred assignments_from_resur_renaming_anno(renaming_annotation_proc::in,
@@ -731,13 +728,11 @@
assignments_from_resur_renaming_anno(ResurRenamingAnnoProc, ProgPoint,
IteRenaming, !NameToVar, !VarSet, !VarTypes, !Conjs) :-
- ( map.search(ResurRenamingAnnoProc, ProgPoint,
- ResurRenamingAnnos)
- ->
- list.foldl4(resur_renaming_annotation_to_assignment(
- IteRenaming), ResurRenamingAnnos, !NameToVar, !VarSet,
- !VarTypes, !Conjs)
- ; true
+ ( map.search(ResurRenamingAnnoProc, ProgPoint, ResurRenamingAnnos) ->
+ list.foldl4(resur_renaming_annotation_to_assignment(IteRenaming),
+ ResurRenamingAnnos, !NameToVar, !VarSet, !VarTypes, !Conjs)
+ ;
+ true
).
% Return the program variable representing the region which is
@@ -750,8 +745,7 @@
prog_var::out, name_to_prog_var::in, name_to_prog_var::out,
prog_varset::in, prog_varset::out, vartypes::in, vartypes::out) is det.
-node_to_var(Graph, Node, RegVar, !NameToVar, !VarSet,
- !VarTypes) :-
+node_to_var(Graph, Node, RegVar, !NameToVar, !VarSet, !VarTypes) :-
RegName = rptg_lookup_region_name(Graph, Node),
region_name_to_var(RegName, RegVar, !NameToVar, !VarSet, !VarTypes).
@@ -763,9 +757,9 @@
prog_varset::in, prog_varset::out, vartypes::in, vartypes::out) is det.
region_name_to_var(Name, RegVar, !NameToVar, !VarSet, !VarTypes) :-
- ( if map.search(!.NameToVar, Name, RegVar0)
- then RegVar = RegVar0
- else
+ ( map.search(!.NameToVar, Name, RegVar0) ->
+ RegVar = RegVar0
+ ;
svvarset.new_named_var(Name, RegVar, !VarSet),
svmap.det_insert(RegVar, region_type, !VarTypes),
svmap.det_insert(Name, RegVar, !NameToVar)
@@ -782,8 +776,8 @@
node_to_var_with_both_renamings(Graph, ResurRenaming, IteRenaming,
Node, RegVar, !NameToVar, !VarSet, !VarTypes) :-
RegName = rptg_lookup_region_name(Graph, Node),
- region_name_to_var_with_both_renamings(RegName, ResurRenaming,
- IteRenaming, RegVar, !NameToVar, !VarSet, !VarTypes).
+ region_name_to_var_with_both_renamings(RegName, ResurRenaming, IteRenaming,
+ RegVar, !NameToVar, !VarSet, !VarTypes).
% Resurrection renaming will be applied first. If a renaming exists
% for the name (i.e., the name will be changed to another name) then
@@ -791,19 +785,17 @@
% applicable anymore.
%
:- pred region_name_to_var_with_both_renamings(string::in, renaming::in,
- renaming::in, prog_var::out,
- name_to_prog_var::in, name_to_prog_var::out,
+ renaming::in, prog_var::out, name_to_prog_var::in, name_to_prog_var::out,
prog_varset::in, prog_varset::out, vartypes::in, vartypes::out) is det.
region_name_to_var_with_both_renamings(Name0, ResurRenaming, IteRenaming,
RegVar, !NameToVar, !VarSet, !VarTypes) :-
- ( if map.search(ResurRenaming, Name0, Name1)
- then Name = Name1
- else
- ( if map.search(IteRenaming, Name0, Name2)
- then Name = Name2
- else Name = Name0
- )
+ ( map.search(ResurRenaming, Name0, ResurName) ->
+ Name = ResurName
+ ; map.search(IteRenaming, Name0, IteName) ->
+ Name = IteName
+ ;
+ Name = Name0
),
region_name_to_var(Name, RegVar, !NameToVar, !VarSet, !VarTypes).
@@ -816,16 +808,17 @@
region_name_to_var_with_renaming(Name0, ResurRenaming, RegVar,
!NameToVar, !VarSet, !VarTypes) :-
- ( if map.search(ResurRenaming, Name0, Name1)
- then Name = Name1
- else Name = Name0
+ ( map.search(ResurRenaming, Name0, ResurName) ->
+ Name = ResurName
+ ;
+ Name = Name0
),
region_name_to_var(Name, RegVar, !NameToVar, !VarSet, !VarTypes).
% The region name in a region instruction is subjected to renaming due
% to if-then-else and region resurrection. This predicate turns such an
% instruction into a call to a suitable region builtin.
- % XXX Call to generate_simple_call here seems overkilled because we
+ % XXX Call to generate_simple_call here seems to overkill because we
% will recompute nonlocals, instmap delta anyway.
%
:- pred region_instruction_to_conj(module_info::in, term.context::in,
@@ -841,17 +834,15 @@
region_name_to_var_with_both_renamings(RegionName, ResurRenaming,
IteRenaming, RegionVar, !NameToVar, !VarSet, !VarTypes),
generate_simple_call(mercury_region_builtin_module,
- "create_region", pf_predicate, only_mode, detism_det,
- purity_impure, [RegionVar], [], [],
- ModuleInfo, Context, CallGoal)
+ create_region_pred_name, pf_predicate, only_mode, detism_det,
+ purity_impure, [RegionVar], [], [], ModuleInfo, Context, CallGoal)
;
RegionInstruction = remove_region(RegionName),
region_name_to_var_with_both_renamings(RegionName, ResurRenaming,
IteRenaming, RegionVar, !NameToVar, !VarSet, !VarTypes),
generate_simple_call(mercury_region_builtin_module,
- "remove_region", pf_predicate, only_mode, detism_det,
- purity_impure, [RegionVar], [], [],
- ModuleInfo, Context, CallGoal)
+ remove_region_pred_name, pf_predicate, only_mode, detism_det,
+ purity_impure, [RegionVar], [], [], ModuleInfo, Context, CallGoal)
;
RegionInstruction = rename_region(_, _),
unexpected(this_file, "region_instruction_to_conj: " ++
@@ -885,8 +876,7 @@
% involve the region on the right side.
region_name_to_var_with_renaming(Left, IteRenaming, LeftRegVar,
!NameToVar, !VarSet, !VarTypes),
- region_name_to_var(Right, RightRegVar, !NameToVar, !VarSet,
- !VarTypes),
+ region_name_to_var(Right, RightRegVar, !NameToVar, !VarSet, !VarTypes),
make_assignment_goal(LeftRegVar, RightRegVar,
"resurrection renaming annotation", AssignmentGoal),
Conjs = Conjs0 ++ [AssignmentGoal]
@@ -947,8 +937,8 @@
% Recompute instmap delta.
%
-:- pred update_instmap_delta_pred(pred_id::in, module_info::in,
- module_info::out) is det.
+:- pred update_instmap_delta_pred(pred_id::in,
+ module_info::in, module_info::out) is det.
update_instmap_delta_pred(PredId, !ModuleInfo) :-
module_info_pred_info(!.ModuleInfo, PredId, PredInfo),
@@ -971,8 +961,8 @@
% Recheck purity.
%
-:- pred recheck_purity_pred(pred_id::in, module_info::in,
- module_info::out) is det.
+:- pred recheck_purity_pred(pred_id::in, module_info::in, module_info::out)
+ is det.
recheck_purity_pred(PredId, !ModuleInfo) :-
module_info_pred_info(!.ModuleInfo, PredId, PredInfo),
@@ -982,8 +972,7 @@
% Recheck purity of the procedure.
% This predicate is only called when all the procedures have been
% annotated with region information and recorded. This is necessary
- % because repuritycheck_proc looks up information
- % about procedures.
+ % because repuritycheck_proc looks up information about procedures.
%
:- pred recheck_purity_proc(pred_id::in, proc_id::in, module_info::in,
module_info::out) is det.
cvs diff: Diffing notes
--------------------------------------------------------------------------
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