29
29
30
30
namespace llvm {
31
31
32
- template <class GraphT >
33
- unsigned DFSPass (DominatorTreeBase< typename GraphT::NodeType>& DT,
34
- typename GraphT::NodeType* V, unsigned N) {
32
+ template <class GraphT >
33
+ unsigned DFSPass (DominatorTreeBaseByGraphTraits< GraphT> & DT,
34
+ typename GraphT::NodeRef V, unsigned N) {
35
35
// This is more understandable as a recursive algorithm, but we can't use the
36
36
// recursive algorithm due to stack depth issues. Keep it here for
37
37
// documentation purposes.
@@ -52,15 +52,16 @@ unsigned DFSPass(DominatorTreeBase<typename GraphT::NodeType>& DT,
52
52
#else
53
53
bool IsChildOfArtificialExit = (N != 0 );
54
54
55
- SmallVector<std::pair<typename GraphT::NodeType*,
56
- typename GraphT::ChildIteratorType>, 32 > Worklist;
55
+ SmallVector<
56
+ std::pair<typename GraphT::NodeRef, typename GraphT::ChildIteratorType>,
57
+ 32 >
58
+ Worklist;
57
59
Worklist.push_back (std::make_pair (V, GraphT::child_begin (V)));
58
60
while (!Worklist.empty ()) {
59
- typename GraphT::NodeType* BB = Worklist.back ().first ;
61
+ typename GraphT::NodeRef BB = Worklist.back ().first ;
60
62
typename GraphT::ChildIteratorType NextSucc = Worklist.back ().second ;
61
63
62
- typename DominatorTreeBase<typename GraphT::NodeType>::InfoRec &BBInfo =
63
- DT.Info [BB];
64
+ auto &BBInfo = DT.Info [BB];
64
65
65
66
// First time we visited this BB?
66
67
if (NextSucc == GraphT::child_begin (BB)) {
@@ -89,10 +90,9 @@ unsigned DFSPass(DominatorTreeBase<typename GraphT::NodeType>& DT,
89
90
++Worklist.back ().second ;
90
91
91
92
// Visit the successor next, if it isn't already visited.
92
- typename GraphT::NodeType* Succ = *NextSucc;
93
+ typename GraphT::NodeRef Succ = *NextSucc;
93
94
94
- typename DominatorTreeBase<typename GraphT::NodeType>::InfoRec &SuccVInfo =
95
- DT.Info [Succ];
95
+ auto &SuccVInfo = DT.Info [Succ];
96
96
if (SuccVInfo.Semi == 0 ) {
97
97
SuccVInfo.Parent = BBDFSNum;
98
98
Worklist.push_back (std::make_pair (Succ, GraphT::child_begin (Succ)));
@@ -103,25 +103,23 @@ unsigned DFSPass(DominatorTreeBase<typename GraphT::NodeType>& DT,
103
103
}
104
104
105
105
template <class GraphT >
106
- typename GraphT::NodeType *
107
- Eval (DominatorTreeBase<typename GraphT::NodeType> &DT,
108
- typename GraphT::NodeType *VIn, unsigned LastLinked) {
109
- typename DominatorTreeBase<typename GraphT::NodeType>::InfoRec &VInInfo =
110
- DT.Info [VIn];
106
+ typename GraphT::NodeRef Eval (DominatorTreeBaseByGraphTraits<GraphT> &DT,
107
+ typename GraphT::NodeRef VIn,
108
+ unsigned LastLinked) {
109
+ auto &VInInfo = DT.Info [VIn];
111
110
if (VInInfo.DFSNum < LastLinked)
112
111
return VIn;
113
112
114
- SmallVector<typename GraphT::NodeType* , 32 > Work;
115
- SmallPtrSet<typename GraphT::NodeType* , 32 > Visited;
113
+ SmallVector<typename GraphT::NodeRef , 32 > Work;
114
+ SmallPtrSet<typename GraphT::NodeRef , 32 > Visited;
116
115
117
116
if (VInInfo.Parent >= LastLinked)
118
117
Work.push_back (VIn);
119
118
120
119
while (!Work.empty ()) {
121
- typename GraphT::NodeType* V = Work.back ();
122
- typename DominatorTreeBase<typename GraphT::NodeType>::InfoRec &VInfo =
123
- DT.Info [V];
124
- typename GraphT::NodeType* VAncestor = DT.Vertex [VInfo.Parent ];
120
+ typename GraphT::NodeRef V = Work.back ();
121
+ auto &VInfo = DT.Info [V];
122
+ typename GraphT::NodeRef VAncestor = DT.Vertex [VInfo.Parent ];
125
123
126
124
// Process Ancestor first
127
125
if (Visited.insert (VAncestor).second && VInfo.Parent >= LastLinked) {
@@ -134,10 +132,9 @@ Eval(DominatorTreeBase<typename GraphT::NodeType> &DT,
134
132
if (VInfo.Parent < LastLinked)
135
133
continue ;
136
134
137
- typename DominatorTreeBase<typename GraphT::NodeType>::InfoRec &VAInfo =
138
- DT.Info [VAncestor];
139
- typename GraphT::NodeType* VAncestorLabel = VAInfo.Label ;
140
- typename GraphT::NodeType* VLabel = VInfo.Label ;
135
+ auto &VAInfo = DT.Info [VAncestor];
136
+ typename GraphT::NodeRef VAncestorLabel = VAInfo.Label ;
137
+ typename GraphT::NodeRef VLabel = VInfo.Label ;
141
138
if (DT.Info [VAncestorLabel].Semi < DT.Info [VLabel].Semi )
142
139
VInfo.Label = VAncestorLabel;
143
140
VInfo.Parent = VAInfo.Parent ;
@@ -146,16 +143,18 @@ Eval(DominatorTreeBase<typename GraphT::NodeType> &DT,
146
143
return VInInfo.Label ;
147
144
}
148
145
149
- template <class FuncT , class NodeT >
150
- void Calculate (DominatorTreeBase< typename GraphTraits<NodeT>::NodeType>& DT,
151
- FuncT& F) {
146
+ template <class FuncT , class NodeT >
147
+ void Calculate (DominatorTreeBaseByGraphTraits< GraphTraits<NodeT>> & DT,
148
+ FuncT & F) {
152
149
typedef GraphTraits<NodeT> GraphT;
150
+ static_assert (std::is_pointer<typename GraphT::NodeRef>::value,
151
+ " NodeRef should be pointer type" );
152
+ typedef typename std::remove_pointer<typename GraphT::NodeRef>::type NodeType;
153
153
154
154
unsigned N = 0 ;
155
155
bool MultipleRoots = (DT.Roots .size () > 1 );
156
156
if (MultipleRoots) {
157
- typename DominatorTreeBase<typename GraphT::NodeType>::InfoRec &BBInfo =
158
- DT.Info [nullptr ];
157
+ auto &BBInfo = DT.Info [nullptr ];
159
158
BBInfo.DFSNum = BBInfo.Semi = ++N;
160
159
BBInfo.Label = nullptr ;
161
160
@@ -188,14 +187,13 @@ void Calculate(DominatorTreeBase<typename GraphTraits<NodeT>::NodeType>& DT,
188
187
Buckets[i] = i;
189
188
190
189
for (unsigned i = N; i >= 2 ; --i) {
191
- typename GraphT::NodeType* W = DT.Vertex [i];
192
- typename DominatorTreeBase<typename GraphT::NodeType>::InfoRec &WInfo =
193
- DT.Info [W];
190
+ typename GraphT::NodeRef W = DT.Vertex [i];
191
+ auto &WInfo = DT.Info [W];
194
192
195
193
// Step #2: Implicitly define the immediate dominator of vertices
196
194
for (unsigned j = i; Buckets[j] != i; j = Buckets[j]) {
197
- typename GraphT::NodeType* V = DT.Vertex [Buckets[j]];
198
- typename GraphT::NodeType* U = Eval<GraphT>(DT, V, i + 1 );
195
+ typename GraphT::NodeRef V = DT.Vertex [Buckets[j]];
196
+ typename GraphT::NodeRef U = Eval<GraphT>(DT, V, i + 1 );
199
197
DT.IDoms [V] = DT.Info [U].Semi < i ? U : W;
200
198
}
201
199
@@ -207,7 +205,7 @@ void Calculate(DominatorTreeBase<typename GraphTraits<NodeT>::NodeType>& DT,
207
205
for (typename InvTraits::ChildIteratorType CI =
208
206
InvTraits::child_begin (W),
209
207
E = InvTraits::child_end (W); CI != E; ++CI) {
210
- typename InvTraits::NodeType * N = *CI;
208
+ typename InvTraits::NodeRef N = *CI;
211
209
if (DT.Info .count (N)) { // Only if this predecessor is reachable!
212
210
unsigned SemiU = DT.Info [Eval<GraphT>(DT, N, i + 1 )].Semi ;
213
211
if (SemiU < WInfo.Semi )
@@ -227,17 +225,17 @@ void Calculate(DominatorTreeBase<typename GraphTraits<NodeT>::NodeType>& DT,
227
225
}
228
226
229
227
if (N >= 1 ) {
230
- typename GraphT::NodeType* Root = DT.Vertex [1 ];
228
+ typename GraphT::NodeRef Root = DT.Vertex [1 ];
231
229
for (unsigned j = 1 ; Buckets[j] != 1 ; j = Buckets[j]) {
232
- typename GraphT::NodeType* V = DT.Vertex [Buckets[j]];
230
+ typename GraphT::NodeRef V = DT.Vertex [Buckets[j]];
233
231
DT.IDoms [V] = Root;
234
232
}
235
233
}
236
234
237
235
// Step #4: Explicitly define the immediate dominator of each vertex
238
236
for (unsigned i = 2 ; i <= N; ++i) {
239
- typename GraphT::NodeType* W = DT.Vertex [i];
240
- typename GraphT::NodeType*& WIDom = DT.IDoms [W];
237
+ typename GraphT::NodeRef W = DT.Vertex [i];
238
+ typename GraphT::NodeRef & WIDom = DT.IDoms [W];
241
239
if (WIDom != DT.Vertex [DT.Info [W].Semi ])
242
240
WIDom = DT.IDoms [WIDom];
243
241
}
@@ -248,34 +246,32 @@ void Calculate(DominatorTreeBase<typename GraphTraits<NodeT>::NodeType>& DT,
248
246
// one exit block, or it may be the virtual exit (denoted by (BasicBlock *)0)
249
247
// which postdominates all real exits if there are multiple exit blocks, or
250
248
// an infinite loop.
251
- typename GraphT::NodeType* Root = !MultipleRoots ? DT.Roots [0 ] : nullptr ;
249
+ typename GraphT::NodeRef Root = !MultipleRoots ? DT.Roots [0 ] : nullptr ;
252
250
253
251
DT.RootNode =
254
252
(DT.DomTreeNodes [Root] =
255
- llvm::make_unique<DomTreeNodeBase<typename GraphT:: NodeType>>(
256
- Root, nullptr )) .get ();
253
+ llvm::make_unique<DomTreeNodeBase<NodeType>>(Root, nullptr ))
254
+ .get ();
257
255
258
256
// Loop over all of the reachable blocks in the function...
259
257
for (unsigned i = 2 ; i <= N; ++i) {
260
- typename GraphT::NodeType* W = DT.Vertex [i];
258
+ typename GraphT::NodeRef W = DT.Vertex [i];
261
259
262
260
// Don't replace this with 'count', the insertion side effect is important
263
261
if (DT.DomTreeNodes [W])
264
262
continue ; // Haven't calculated this node yet?
265
263
266
- typename GraphT::NodeType* ImmDom = DT.getIDom (W);
264
+ typename GraphT::NodeRef ImmDom = DT.getIDom (W);
267
265
268
266
assert (ImmDom || DT.DomTreeNodes [nullptr ]);
269
267
270
268
// Get or calculate the node for the immediate dominator
271
- DomTreeNodeBase<typename GraphT::NodeType> *IDomNode =
272
- DT.getNodeForBlock (ImmDom);
269
+ DomTreeNodeBase<NodeType> *IDomNode = DT.getNodeForBlock (ImmDom);
273
270
274
271
// Add a new tree node for this BasicBlock, and link it as a child of
275
272
// IDomNode
276
273
DT.DomTreeNodes [W] = IDomNode->addChild (
277
- llvm::make_unique<DomTreeNodeBase<typename GraphT::NodeType>>(
278
- W, IDomNode));
274
+ llvm::make_unique<DomTreeNodeBase<NodeType>>(W, IDomNode));
279
275
}
280
276
281
277
// Free temporary memory used to construct idom's
0 commit comments