1
%%%----------------------------------------------------------------------
5
%%% Created : 18 Mar 2002 by
6
%%%----------------------------------------------------------------------
12
-define(hash,hipe_hash).
14
%%>----------------------------------------------------------------------<
16
% Purpose : This function creates an empty instance of DF. It is
17
% represented by a hash table.
18
% Arguments : N - The number of Dominance Frontiers
20
%%>----------------------------------------------------------------------<
24
%%>----------------------------------------------------------------------<
26
% Purpose : This function adds Node to N in DF.
27
% Arguments : N - The value being inserted
28
% Node - The node getting the value
29
% DF - The Dominance Frontiers
31
% Notes : If Node already exists at position N, it is not added again.
32
%%>----------------------------------------------------------------------<
34
case ?hash:lookup(N, DF) of
36
?hash:update(N, [Node], DF);
38
case lists:member(Node, DFList) of
42
?hash:update(N, [Node|DFList], DF)
47
%%>----------------------------------------------------------------------<
49
% Purpose : This function gets the Dominance Frontier for Node
50
% Arguments : Node - The node which Dominance Frontier we request
51
% DF - The Dominance Frontiers
54
%%>----------------------------------------------------------------------<
56
case ?hash:lookup(Node, DF) of
62
%%>----------------------------------------------------------------------<
64
% Purpose : This function calculates the Dominance Frontiers from
65
% a CFG and a Dominantor Tree.
66
% Arguments : SuccMap - The successor map of the CFG we are working with
67
% DomTree - The dominance tree of the CFG.
68
% Notes : DomTree must actually be the dominance tree of the CFG.
69
%%>----------------------------------------------------------------------<
70
make(SuccMap, DomTree) ->
71
make(hipe_domtree:getRoot(DomTree), SuccMap, DomTree, create()).
73
make(Node, SuccMap, DomTree, DF) ->
75
Children = hipe_domtree:getChildren(Node, DomTree),
76
Succ = hipe_gen_cfg:succ(SuccMap, Node),
77
DF1 = checkIDomList(Succ, Node, DomTree, DF),
78
makeDFChildren(Children, Node, SuccMap, DomTree, DF1).
81
%%>----------------------------------------------------------------------<
82
% Procedure : makeDFChildren
83
% Purpose : This function calculates the dominance frontiers of the
84
% children of the parent and adds the nodes in these
85
% dominance frontiers who are not immediate dominantors of
86
% the parent to parents dominance frontier.
87
% Arguments : ChildList - The list of children that the function traverses
88
% Parent - The parent of the children
89
% SuccMap - The successor map of the CFG
90
% DomTree - The dominantor tree of the CFG
91
% DF - The dominance frontiers so far
93
%%>----------------------------------------------------------------------<
94
makeDFChildren([Child|T], Parent, SuccMap, DomTree, DF) ->
95
DF1 = make(Child, SuccMap, DomTree, DF),
96
DF2 = checkIDomList(get(Child, DF1), Parent, DomTree, DF1),
97
makeDFChildren(T, Parent, SuccMap, DomTree, DF2);
98
makeDFChildren([], _, _, _, DF) -> DF.
101
%%>----------------------------------------------------------------------<
102
% Procedure : checIDomList
103
% Purpose : Adds all the nodes in the list to the parents dominance
104
% frontier who do not have parent as immediate dominator.
105
% Arguments : NodeList - The list of nodes that the function traverses
106
% Parent - The parent of the nodes
107
% DomTree - Our dominator tree
108
% DF - The dominance frontiers so far
110
%%>----------------------------------------------------------------------<
111
checkIDomList([Node|T], Parent, DomTree, DF) ->
112
DF1 = checkIDom(Node, Parent, DomTree, DF),
113
checkIDomList(T, Parent, DomTree, DF1);
114
checkIDomList([], _, _, DF) -> DF.
117
%%>----------------------------------------------------------------------<
118
% Procedure : checkIdom
119
% Purpose : adds Node1 to Node2s dominance frontier if Node2 is not
120
% Node1s immediate dominator.
121
% Arguments : Node1 - a node
122
% Node2 - another node
123
% DomTree - the dominator tree
124
% DF - the dominance frontier so far
126
%%>----------------------------------------------------------------------<
127
checkIDom(Node1, Node2, DomTree, DF) ->
128
case hipe_domtree:getIDom(Node1, DomTree) of
134
add(Node2, Node1, DF)