llvm.org GIT mirror llvm / d20c824
Factor the dominator tree calculation details out into DominatorCalculation.h. This change is not useful in and of itself, but it lays the groundwork for combining the dominator and postdominator implementations. Also, factor a few methods that are common to DominatorTree and PostDominatorTree into DominatorTreeBase. Again, this will make merging the two calculation methods simpler in the future. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42248 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 13 years ago
4 changed file(s) with 308 addition(s) and 283 deletion(s). Raw diff Collapse all Expand all
128128
129129 // Info - Collection of information used during the computation of idoms.
130130 DenseMap Info;
131 unsigned DFSPass(BasicBlock *V, unsigned N);
131132
132133 public:
133134 DominatorTreeBase(intptr_t ID, bool isPostDom)
277278 /// updateDFSNumbers - Assign In and Out numbers to the nodes while walking
278279 /// dominator tree in dfs order.
279280 void updateDFSNumbers();
281
282 DomTreeNode *getNodeForBlock(BasicBlock *BB);
283
284 inline BasicBlock *getIDom(BasicBlock *BB) const {
285 DenseMap::const_iterator I = IDoms.find(BB);
286 return I != IDoms.end() ? I->second : 0;
287 }
280288 };
281289
282290 //===-------------------------------------
303311 /// BB is split and now it has one successor. Update dominator tree to
304312 /// reflect this change.
305313 void splitBlock(BasicBlock *BB);
314
306315 private:
307 void calculate(Function& F);
308 DomTreeNode *getNodeForBlock(BasicBlock *BB);
309 unsigned DFSPass(BasicBlock *V, unsigned N);
310 void Compress(BasicBlock *V);
311 BasicBlock *Eval(BasicBlock *v);
312 void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);
313 inline BasicBlock *getIDom(BasicBlock *BB) const {
314 DenseMap::const_iterator I = IDoms.find(BB);
315 return I != IDoms.end() ? I->second : 0;
316 }
316 friend void DTcalculate(DominatorTree& DT, Function& F);
317 friend void DTCompress(DominatorTree& DT, BasicBlock *VIn);
318 friend BasicBlock *DTEval(DominatorTree& DT, BasicBlock *v);
319 friend void DTLink(DominatorTree& DT, BasicBlock *V,
320 BasicBlock *W, InfoRec &WInfo);
317321 };
318322
319323 //===-------------------------------------
3737 }
3838 private:
3939 void calculate(Function &F);
40 DomTreeNode *getNodeForBlock(BasicBlock *BB);
4140 unsigned DFSPass(BasicBlock *V, unsigned N);
4241 void Compress(BasicBlock *V, InfoRec &VInfo);
4342 BasicBlock *Eval(BasicBlock *V);
4443 void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);
45
46 inline BasicBlock *getIDom(BasicBlock *BB) const {
47 DenseMap::const_iterator I = IDoms.find(BB);
48 return I != IDoms.end() ? I->second : 0;
49 }
5044 };
5145
5246
0 //==- llvm/VMCore/DominatorCalculation.h - Dominator Calculation -*- C++ -*-==//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by Owen Anderson and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_VMCORE_DOMINATOR_CALCULATION_H
10 #define LLVM_VMCORE_DOMINATOR_CALCULATION_H
11
12 #include "llvm/Analysis/Dominators.h"
13
14 //===----------------------------------------------------------------------===//
15 //
16 // DominatorTree construction - This pass constructs immediate dominator
17 // information for a flow-graph based on the algorithm described in this
18 // document:
19 //
20 // A Fast Algorithm for Finding Dominators in a Flowgraph
21 // T. Lengauer & R. Tarjan, ACM TOPLAS July 1979, pgs 121-141.
22 //
23 // This implements both the O(n*ack(n)) and the O(n*log(n)) versions of EVAL and
24 // LINK, but it turns out that the theoretically slower O(n*log(n))
25 // implementation is actually faster than the "efficient" algorithm (even for
26 // large CFGs) because the constant overheads are substantially smaller. The
27 // lower-complexity version can be enabled with the following #define:
28 //
29 #define BALANCE_IDOM_TREE 0
30 //
31 //===----------------------------------------------------------------------===//
32
33 namespace llvm {
34
35 void DTCompress(DominatorTree& DT, BasicBlock *VIn) {
36
37 std::vector Work;
38 SmallPtrSet Visited;
39 BasicBlock *VInAncestor = DT.Info[VIn].Ancestor;
40 DominatorTree::InfoRec &VInVAInfo = DT.Info[VInAncestor];
41
42 if (VInVAInfo.Ancestor != 0)
43 Work.push_back(VIn);
44
45 while (!Work.empty()) {
46 BasicBlock *V = Work.back();
47 DominatorTree::InfoRec &VInfo = DT.Info[V];
48 BasicBlock *VAncestor = VInfo.Ancestor;
49 DominatorTree::InfoRec &VAInfo = DT.Info[VAncestor];
50
51 // Process Ancestor first
52 if (Visited.insert(VAncestor) &&
53 VAInfo.Ancestor != 0) {
54 Work.push_back(VAncestor);
55 continue;
56 }
57 Work.pop_back();
58
59 // Update VInfo based on Ancestor info
60 if (VAInfo.Ancestor == 0)
61 continue;
62 BasicBlock *VAncestorLabel = VAInfo.Label;
63 BasicBlock *VLabel = VInfo.Label;
64 if (DT.Info[VAncestorLabel].Semi < DT.Info[VLabel].Semi)
65 VInfo.Label = VAncestorLabel;
66 VInfo.Ancestor = VAInfo.Ancestor;
67 }
68 }
69
70 BasicBlock *DTEval(DominatorTree& DT, BasicBlock *V) {
71 DominatorTree::InfoRec &VInfo = DT.Info[V];
72 #if !BALANCE_IDOM_TREE
73 // Higher-complexity but faster implementation
74 if (VInfo.Ancestor == 0)
75 return V;
76 DTCompress(DT, V);
77 return VInfo.Label;
78 #else
79 // Lower-complexity but slower implementation
80 if (VInfo.Ancestor == 0)
81 return VInfo.Label;
82 DTCompress(DT, V);
83 BasicBlock *VLabel = VInfo.Label;
84
85 BasicBlock *VAncestorLabel = DT.Info[VInfo.Ancestor].Label;
86 if (DT.Info[VAncestorLabel].Semi >= DT.Info[VLabel].Semi)
87 return VLabel;
88 else
89 return VAncestorLabel;
90 #endif
91 }
92
93 void DTLink(DominatorTree& DT, BasicBlock *V, BasicBlock *W,
94 DominatorTree::InfoRec &WInfo) {
95 #if !BALANCE_IDOM_TREE
96 // Higher-complexity but faster implementation
97 WInfo.Ancestor = V;
98 #else
99 // Lower-complexity but slower implementation
100 BasicBlock *WLabel = WInfo.Label;
101 unsigned WLabelSemi = Info[WLabel].Semi;
102 BasicBlock *S = W;
103 InfoRec *SInfo = &Info[S];
104
105 BasicBlock *SChild = SInfo->Child;
106 InfoRec *SChildInfo = &Info[SChild];
107
108 while (WLabelSemi < Info[SChildInfo->Label].Semi) {
109 BasicBlock *SChildChild = SChildInfo->Child;
110 if (SInfo->Size+Info[SChildChild].Size >= 2*SChildInfo->Size) {
111 SChildInfo->Ancestor = S;
112 SInfo->Child = SChild = SChildChild;
113 SChildInfo = &Info[SChild];
114 } else {
115 SChildInfo->Size = SInfo->Size;
116 S = SInfo->Ancestor = SChild;
117 SInfo = SChildInfo;
118 SChild = SChildChild;
119 SChildInfo = &Info[SChild];
120 }
121 }
122
123 InfoRec &VInfo = Info[V];
124 SInfo->Label = WLabel;
125
126 assert(V != W && "The optimization here will not work in this case!");
127 unsigned WSize = WInfo.Size;
128 unsigned VSize = (VInfo.Size += WSize);
129
130 if (VSize < 2*WSize)
131 std::swap(S, VInfo.Child);
132
133 while (S) {
134 SInfo = &Info[S];
135 SInfo->Ancestor = V;
136 S = SInfo->Child;
137 }
138 #endif
139 }
140
141 void DTcalculate(DominatorTree& DT, Function &F) {
142 BasicBlock* Root = DT.Roots[0];
143
144 // Add a node for the root...
145 DT.DomTreeNodes[Root] = DT.RootNode = new DomTreeNode(Root, 0);
146
147 DT.Vertex.push_back(0);
148
149 // Step #1: Number blocks in depth-first order and initialize variables used
150 // in later stages of the algorithm.
151 unsigned N = DT.DFSPass(Root, 0);
152
153 for (unsigned i = N; i >= 2; --i) {
154 BasicBlock *W = DT.Vertex[i];
155 DominatorTree::InfoRec &WInfo = DT.Info[W];
156
157 // Step #2: Calculate the semidominators of all vertices
158 for (pred_iterator PI = pred_begin(W), E = pred_end(W); PI != E; ++PI)
159 if (DT.Info.count(*PI)) { // Only if this predecessor is reachable!
160 unsigned SemiU = DT.Info[DTEval(DT, *PI)].Semi;
161 if (SemiU < WInfo.Semi)
162 WInfo.Semi = SemiU;
163 }
164
165 DT.Info[DT.Vertex[WInfo.Semi]].Bucket.push_back(W);
166
167 BasicBlock *WParent = WInfo.Parent;
168 DTLink(DT, WParent, W, WInfo);
169
170 // Step #3: Implicitly define the immediate dominator of vertices
171 std::vector &WParentBucket = DT.Info[WParent].Bucket;
172 while (!WParentBucket.empty()) {
173 BasicBlock *V = WParentBucket.back();
174 WParentBucket.pop_back();
175 BasicBlock *U = DTEval(DT, V);
176 DT.IDoms[V] = DT.Info[U].Semi < DT.Info[V].Semi ? U : WParent;
177 }
178 }
179
180 // Step #4: Explicitly define the immediate dominator of each vertex
181 for (unsigned i = 2; i <= N; ++i) {
182 BasicBlock *W = DT.Vertex[i];
183 BasicBlock *&WIDom = DT.IDoms[W];
184 if (WIDom != DT.Vertex[DT.Info[W].Semi])
185 WIDom = DT.IDoms[WIDom];
186 }
187
188 // Loop over all of the reachable blocks in the function...
189 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
190 if (BasicBlock *ImmDom = DT.getIDom(I)) { // Reachable block.
191 DomTreeNode *BBNode = DT.DomTreeNodes[I];
192 if (BBNode) continue; // Haven't calculated this node yet?
193
194 // Get or calculate the node for the immediate dominator
195 DomTreeNode *IDomNode = DT.getNodeForBlock(ImmDom);
196
197 // Add a new tree node for this BasicBlock, and link it as a child of
198 // IDomNode
199 DomTreeNode *C = new DomTreeNode(I, IDomNode);
200 DT.DomTreeNodes[I] = IDomNode->addChild(C);
201 }
202
203 // Free temporary memory used to construct idom's
204 DT.Info.clear();
205 DT.IDoms.clear();
206 std::vector().swap(DT.Vertex);
207
208 DT.updateDFSNumbers();
209 }
210
211 }
212 #endif
2222 #include "llvm/ADT/SmallVector.h"
2323 #include "llvm/Instructions.h"
2424 #include "llvm/Support/Streams.h"
25 #include "DominatorCalculation.h"
2526 #include
2627 using namespace llvm;
2728
4243 // DominatorTree Implementation
4344 //===----------------------------------------------------------------------===//
4445 //
45 // DominatorTree construction - This pass constructs immediate dominator
46 // information for a flow-graph based on the algorithm described in this
47 // document:
48 //
49 // A Fast Algorithm for Finding Dominators in a Flowgraph
50 // T. Lengauer & R. Tarjan, ACM TOPLAS July 1979, pgs 121-141.
51 //
52 // This implements both the O(n*ack(n)) and the O(n*log(n)) versions of EVAL and
53 // LINK, but it turns out that the theoretically slower O(n*log(n))
54 // implementation is actually faster than the "efficient" algorithm (even for
55 // large CFGs) because the constant overheads are substantially smaller. The
56 // lower-complexity version can be enabled with the following #define:
57 //
58 #define BALANCE_IDOM_TREE 0
46 // Provide public access to DominatorTree information. Implementation details
47 // can be found in DominatorCalculation.h.
5948 //
6049 //===----------------------------------------------------------------------===//
6150
6251 char DominatorTree::ID = 0;
6352 static RegisterPass
6453 E("domtree", "Dominator Tree Construction", true);
54
55 unsigned DominatorTreeBase::DFSPass(BasicBlock *V, unsigned N) {
56 // This is more understandable as a recursive algorithm, but we can't use the
57 // recursive algorithm due to stack depth issues. Keep it here for
58 // documentation purposes.
59 #if 0
60 InfoRec &VInfo = Info[Roots[i]];
61 VInfo.Semi = ++N;
62 VInfo.Label = V;
63
64 Vertex.push_back(V); // Vertex[n] = V;
65 //Info[V].Ancestor = 0; // Ancestor[n] = 0
66 //Info[V].Child = 0; // Child[v] = 0
67 VInfo.Size = 1; // Size[v] = 1
68
69 for (succ_iterator SI = succ_begin(V), E = succ_end(V); SI != E; ++SI) {
70 InfoRec &SuccVInfo = Info[*SI];
71 if (SuccVInfo.Semi == 0) {
72 SuccVInfo.Parent = V;
73 N = DFSPass(*SI, N);
74 }
75 }
76 #else
77 std::vector > Worklist;
78 Worklist.push_back(std::make_pair(V, 0U));
79 while (!Worklist.empty()) {
80 BasicBlock *BB = Worklist.back().first;
81 unsigned NextSucc = Worklist.back().second;
82
83 // First time we visited this BB?
84 if (NextSucc == 0) {
85 InfoRec &BBInfo = Info[BB];
86 BBInfo.Semi = ++N;
87 BBInfo.Label = BB;
88
89 Vertex.push_back(BB); // Vertex[n] = V;
90 //BBInfo[V].Ancestor = 0; // Ancestor[n] = 0
91 //BBInfo[V].Child = 0; // Child[v] = 0
92 BBInfo.Size = 1; // Size[v] = 1
93 }
94
95 // If we are done with this block, remove it from the worklist.
96 if (NextSucc == BB->getTerminator()->getNumSuccessors()) {
97 Worklist.pop_back();
98 continue;
99 }
100
101 // Otherwise, increment the successor number for the next time we get to it.
102 ++Worklist.back().second;
103
104 // Visit the successor next, if it isn't already visited.
105 BasicBlock *Succ = BB->getTerminator()->getSuccessor(NextSucc);
106
107 InfoRec &SuccVInfo = Info[Succ];
108 if (SuccVInfo.Semi == 0) {
109 SuccVInfo.Parent = BB;
110 Worklist.push_back(std::make_pair(Succ, 0U));
111 }
112 }
113 #endif
114 return N;
115 }
65116
66117 // NewBB is split and now it has one successor. Update dominator tree to
67118 // reflect this change.
143194 DomTreeNode *NewBBSuccNode = getNode(NewBBSucc);
144195 changeImmediateDominator(NewBBSuccNode, NewBBNode);
145196 }
146 }
147
148 unsigned DominatorTree::DFSPass(BasicBlock *V, unsigned N) {
149 // This is more understandable as a recursive algorithm, but we can't use the
150 // recursive algorithm due to stack depth issues. Keep it here for
151 // documentation purposes.
152 #if 0
153 InfoRec &VInfo = Info[Roots[i]];
154 VInfo.Semi = ++N;
155 VInfo.Label = V;
156
157 Vertex.push_back(V); // Vertex[n] = V;
158 //Info[V].Ancestor = 0; // Ancestor[n] = 0
159 //Info[V].Child = 0; // Child[v] = 0
160 VInfo.Size = 1; // Size[v] = 1
161
162 for (succ_iterator SI = succ_begin(V), E = succ_end(V); SI != E; ++SI) {
163 InfoRec &SuccVInfo = Info[*SI];
164 if (SuccVInfo.Semi == 0) {
165 SuccVInfo.Parent = V;
166 N = DFSPass(*SI, N);
167 }
168 }
169 #else
170 std::vector > Worklist;
171 Worklist.push_back(std::make_pair(V, 0U));
172 while (!Worklist.empty()) {
173 BasicBlock *BB = Worklist.back().first;
174 unsigned NextSucc = Worklist.back().second;
175
176 // First time we visited this BB?
177 if (NextSucc == 0) {
178 InfoRec &BBInfo = Info[BB];
179 BBInfo.Semi = ++N;
180 BBInfo.Label = BB;
181
182 Vertex.push_back(BB); // Vertex[n] = V;
183 //BBInfo[V].Ancestor = 0; // Ancestor[n] = 0
184 //BBInfo[V].Child = 0; // Child[v] = 0
185 BBInfo.Size = 1; // Size[v] = 1
186 }
187
188 // If we are done with this block, remove it from the worklist.
189 if (NextSucc == BB->getTerminator()->getNumSuccessors()) {
190 Worklist.pop_back();
191 continue;
192 }
193
194 // Otherwise, increment the successor number for the next time we get to it.
195 ++Worklist.back().second;
196
197 // Visit the successor next, if it isn't already visited.
198 BasicBlock *Succ = BB->getTerminator()->getSuccessor(NextSucc);
199
200 InfoRec &SuccVInfo = Info[Succ];
201 if (SuccVInfo.Semi == 0) {
202 SuccVInfo.Parent = BB;
203 Worklist.push_back(std::make_pair(Succ, 0U));
204 }
205 }
206 #endif
207 return N;
208 }
209
210 void DominatorTree::Compress(BasicBlock *VIn) {
211
212 std::vector Work;
213 SmallPtrSet Visited;
214 BasicBlock *VInAncestor = Info[VIn].Ancestor;
215 InfoRec &VInVAInfo = Info[VInAncestor];
216
217 if (VInVAInfo.Ancestor != 0)
218 Work.push_back(VIn);
219
220 while (!Work.empty()) {
221 BasicBlock *V = Work.back();
222 InfoRec &VInfo = Info[V];
223 BasicBlock *VAncestor = VInfo.Ancestor;
224 InfoRec &VAInfo = Info[VAncestor];
225
226 // Process Ancestor first
227 if (Visited.insert(VAncestor) &&
228 VAInfo.Ancestor != 0) {
229 Work.push_back(VAncestor);
230 continue;
231 }
232 Work.pop_back();
233
234 // Update VInfo based on Ancestor info
235 if (VAInfo.Ancestor == 0)
236 continue;
237 BasicBlock *VAncestorLabel = VAInfo.Label;
238 BasicBlock *VLabel = VInfo.Label;
239 if (Info[VAncestorLabel].Semi < Info[VLabel].Semi)
240 VInfo.Label = VAncestorLabel;
241 VInfo.Ancestor = VAInfo.Ancestor;
242 }
243 }
244
245 BasicBlock *DominatorTree::Eval(BasicBlock *V) {
246 InfoRec &VInfo = Info[V];
247 #if !BALANCE_IDOM_TREE
248 // Higher-complexity but faster implementation
249 if (VInfo.Ancestor == 0)
250 return V;
251 Compress(V);
252 return VInfo.Label;
253 #else
254 // Lower-complexity but slower implementation
255 if (VInfo.Ancestor == 0)
256 return VInfo.Label;
257 Compress(V);
258 BasicBlock *VLabel = VInfo.Label;
259
260 BasicBlock *VAncestorLabel = Info[VInfo.Ancestor].Label;
261 if (Info[VAncestorLabel].Semi >= Info[VLabel].Semi)
262 return VLabel;
263 else
264 return VAncestorLabel;
265 #endif
266 }
267
268 void DominatorTree::Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo){
269 #if !BALANCE_IDOM_TREE
270 // Higher-complexity but faster implementation
271 WInfo.Ancestor = V;
272 #else
273 // Lower-complexity but slower implementation
274 BasicBlock *WLabel = WInfo.Label;
275 unsigned WLabelSemi = Info[WLabel].Semi;
276 BasicBlock *S = W;
277 InfoRec *SInfo = &Info[S];
278
279 BasicBlock *SChild = SInfo->Child;
280 InfoRec *SChildInfo = &Info[SChild];
281
282 while (WLabelSemi < Info[SChildInfo->Label].Semi) {
283 BasicBlock *SChildChild = SChildInfo->Child;
284 if (SInfo->Size+Info[SChildChild].Size >= 2*SChildInfo->Size) {
285 SChildInfo->Ancestor = S;
286 SInfo->Child = SChild = SChildChild;
287 SChildInfo = &Info[SChild];
288 } else {
289 SChildInfo->Size = SInfo->Size;
290 S = SInfo->Ancestor = SChild;
291 SInfo = SChildInfo;
292 SChild = SChildChild;
293 SChildInfo = &Info[SChild];
294 }
295 }
296
297 InfoRec &VInfo = Info[V];
298 SInfo->Label = WLabel;
299
300 assert(V != W && "The optimization here will not work in this case!");
301 unsigned WSize = WInfo.Size;
302 unsigned VSize = (VInfo.Size += WSize);
303
304 if (VSize < 2*WSize)
305 std::swap(S, VInfo.Child);
306
307 while (S) {
308 SInfo = &Info[S];
309 SInfo->Ancestor = V;
310 S = SInfo->Child;
311 }
312 #endif
313 }
314
315 void DominatorTree::calculate(Function &F) {
316 BasicBlock* Root = Roots[0];
317
318 // Add a node for the root...
319 DomTreeNodes[Root] = RootNode = new DomTreeNode(Root, 0);
320
321 Vertex.push_back(0);
322
323 // Step #1: Number blocks in depth-first order and initialize variables used
324 // in later stages of the algorithm.
325 unsigned N = DFSPass(Root, 0);
326
327 for (unsigned i = N; i >= 2; --i) {
328 BasicBlock *W = Vertex[i];
329 InfoRec &WInfo = Info[W];
330
331 // Step #2: Calculate the semidominators of all vertices
332 for (pred_iterator PI = pred_begin(W), E = pred_end(W); PI != E; ++PI)
333 if (Info.count(*PI)) { // Only if this predecessor is reachable!
334 unsigned SemiU = Info[Eval(*PI)].Semi;
335 if (SemiU < WInfo.Semi)
336 WInfo.Semi = SemiU;
337 }
338
339 Info[Vertex[WInfo.Semi]].Bucket.push_back(W);
340
341 BasicBlock *WParent = WInfo.Parent;
342 Link(WParent, W, WInfo);
343
344 // Step #3: Implicitly define the immediate dominator of vertices
345 std::vector &WParentBucket = Info[WParent].Bucket;
346 while (!WParentBucket.empty()) {
347 BasicBlock *V = WParentBucket.back();
348 WParentBucket.pop_back();
349 BasicBlock *U = Eval(V);
350 IDoms[V] = Info[U].Semi < Info[V].Semi ? U : WParent;
351 }
352 }
353
354 // Step #4: Explicitly define the immediate dominator of each vertex
355 for (unsigned i = 2; i <= N; ++i) {
356 BasicBlock *W = Vertex[i];
357 BasicBlock *&WIDom = IDoms[W];
358 if (WIDom != Vertex[Info[W].Semi])
359 WIDom = IDoms[WIDom];
360 }
361
362 // Loop over all of the reachable blocks in the function...
363 for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
364 if (BasicBlock *ImmDom = getIDom(I)) { // Reachable block.
365 DomTreeNode *BBNode = DomTreeNodes[I];
366 if (BBNode) continue; // Haven't calculated this node yet?
367
368 // Get or calculate the node for the immediate dominator
369 DomTreeNode *IDomNode = getNodeForBlock(ImmDom);
370
371 // Add a new tree node for this BasicBlock, and link it as a child of
372 // IDomNode
373 DomTreeNode *C = new DomTreeNode(I, IDomNode);
374 DomTreeNodes[I] = IDomNode->addChild(C);
375 }
376
377 // Free temporary memory used to construct idom's
378 Info.clear();
379 IDoms.clear();
380 std::vector().swap(Vertex);
381
382 updateDFSNumbers();
383197 }
384198
385199 void DominatorTreeBase::updateDFSNumbers() {
461275 RootNode = 0;
462276 }
463277
278 DomTreeNode *DominatorTreeBase::getNodeForBlock(BasicBlock *BB) {
279 if (DomTreeNode *BBNode = DomTreeNodes[BB])
280 return BBNode;
281
282 // Haven't calculated this node yet? Get or calculate the node for the
283 // immediate dominator.
284 BasicBlock *IDom = getIDom(BB);
285 DomTreeNode *IDomNode = getNodeForBlock(IDom);
286
287 // Add a new tree node for this BasicBlock, and link it as a child of
288 // IDomNode
289 DomTreeNode *C = new DomTreeNode(BB, IDomNode);
290 return DomTreeNodes[BB] = IDomNode->addChild(C);
291 }
292
464293 /// findNearestCommonDominator - Find nearest common dominator basic block
465294 /// for basic block A and B. If there is no such block then return NULL.
466295 BasicBlock *DominatorTreeBase::findNearestCommonDominator(BasicBlock *A,
524353 }
525354 }
526355
527 DomTreeNode *DominatorTree::getNodeForBlock(BasicBlock *BB) {
528 if (DomTreeNode *BBNode = DomTreeNodes[BB])
529 return BBNode;
530
531 // Haven't calculated this node yet? Get or calculate the node for the
532 // immediate dominator.
533 BasicBlock *IDom = getIDom(BB);
534 DomTreeNode *IDomNode = getNodeForBlock(IDom);
535
536 // Add a new tree node for this BasicBlock, and link it as a child of
537 // IDomNode
538 DomTreeNode *C = new DomTreeNode(BB, IDomNode);
539 return DomTreeNodes[BB] = IDomNode->addChild(C);
540 }
541
542356 static std::ostream &operator<<(std::ostream &o, const DomTreeNode *Node) {
543357 if (Node->getBlock())
544358 WriteAsOperand(o, Node->getBlock(), false);
598412 bool DominatorTree::runOnFunction(Function &F) {
599413 reset(); // Reset from the last time we were run...
600414 Roots.push_back(&F.getEntryBlock());
601 calculate(F);
415 DTcalculate(*this, F);
602416 return false;
603417 }
604418