Chris Lattner | 4c9df7c | 2002-08-02 16:43:03 +0000 | [diff] [blame] | 1 | //===- PostDominators.cpp - Post-Dominator Calculation --------------------===// |
Misha Brukman | 2b37d7c | 2005-04-21 21:13:18 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | 2b37d7c | 2005-04-21 21:13:18 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 1715229 | 2001-07-02 05:46:38 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 4c9df7c | 2002-08-02 16:43:03 +0000 | [diff] [blame] | 10 | // This file implements the post-dominator construction algorithms. |
Chris Lattner | 1715229 | 2001-07-02 05:46:38 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | a69fd90 | 2002-08-21 23:43:50 +0000 | [diff] [blame] | 14 | #include "llvm/Analysis/PostDominators.h" |
Misha Brukman | 47b14a4 | 2004-07-29 17:30:56 +0000 | [diff] [blame] | 15 | #include "llvm/Instructions.h" |
Chris Lattner | 221d688 | 2002-02-12 21:07:25 +0000 | [diff] [blame] | 16 | #include "llvm/Support/CFG.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/DepthFirstIterator.h" |
| 18 | #include "llvm/ADT/SetOperations.h" |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 19 | #include <iostream> |
Chris Lattner | cd7c287 | 2003-12-07 00:35:42 +0000 | [diff] [blame] | 20 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 21 | |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 22 | //===----------------------------------------------------------------------===// |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 23 | // ImmediatePostDominators Implementation |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
| 26 | static RegisterAnalysis<ImmediatePostDominators> |
| 27 | D("postidom", "Immediate Post-Dominators Construction", true); |
| 28 | |
| 29 | unsigned ImmediatePostDominators::DFSPass(BasicBlock *V, InfoRec &VInfo, |
| 30 | unsigned N) { |
| 31 | VInfo.Semi = ++N; |
| 32 | VInfo.Label = V; |
| 33 | |
| 34 | Vertex.push_back(V); // Vertex[n] = V; |
| 35 | //Info[V].Ancestor = 0; // Ancestor[n] = 0 |
| 36 | //Child[V] = 0; // Child[v] = 0 |
| 37 | VInfo.Size = 1; // Size[v] = 1 |
| 38 | |
| 39 | // For PostDominators, we want to walk predecessors rather than successors |
| 40 | // as we do in forward Dominators. |
| 41 | for (pred_iterator PI = pred_begin(V), PE = pred_end(V); PI != PE; ++PI) { |
| 42 | InfoRec &SuccVInfo = Info[*PI]; |
| 43 | if (SuccVInfo.Semi == 0) { |
| 44 | SuccVInfo.Parent = V; |
| 45 | N = DFSPass(*PI, SuccVInfo, N); |
| 46 | } |
| 47 | } |
| 48 | return N; |
| 49 | } |
| 50 | |
| 51 | void ImmediatePostDominators::Compress(BasicBlock *V, InfoRec &VInfo) { |
| 52 | BasicBlock *VAncestor = VInfo.Ancestor; |
| 53 | InfoRec &VAInfo = Info[VAncestor]; |
| 54 | if (VAInfo.Ancestor == 0) |
| 55 | return; |
| 56 | |
| 57 | Compress(VAncestor, VAInfo); |
| 58 | |
| 59 | BasicBlock *VAncestorLabel = VAInfo.Label; |
| 60 | BasicBlock *VLabel = VInfo.Label; |
| 61 | if (Info[VAncestorLabel].Semi < Info[VLabel].Semi) |
| 62 | VInfo.Label = VAncestorLabel; |
| 63 | |
| 64 | VInfo.Ancestor = VAInfo.Ancestor; |
| 65 | } |
| 66 | |
| 67 | BasicBlock *ImmediatePostDominators::Eval(BasicBlock *V) { |
| 68 | InfoRec &VInfo = Info[V]; |
| 69 | |
| 70 | // Higher-complexity but faster implementation |
| 71 | if (VInfo.Ancestor == 0) |
| 72 | return V; |
| 73 | Compress(V, VInfo); |
| 74 | return VInfo.Label; |
| 75 | } |
| 76 | |
| 77 | void ImmediatePostDominators::Link(BasicBlock *V, BasicBlock *W, |
| 78 | InfoRec &WInfo) { |
| 79 | // Higher-complexity but faster implementation |
| 80 | WInfo.Ancestor = V; |
| 81 | } |
| 82 | |
| 83 | bool ImmediatePostDominators::runOnFunction(Function &F) { |
| 84 | IDoms.clear(); // Reset from the last time we were run... |
| 85 | Roots.clear(); |
| 86 | |
| 87 | // Step #0: Scan the function looking for the root nodes of the post-dominance |
| 88 | // relationships. These blocks, which have no successors, end with return and |
| 89 | // unwind instructions. |
| 90 | for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) |
| 91 | if (succ_begin(I) == succ_end(I)) |
| 92 | Roots.push_back(I); |
| 93 | |
| 94 | Vertex.push_back(0); |
| 95 | |
| 96 | // Step #1: Number blocks in depth-first order and initialize variables used |
| 97 | // in later stages of the algorithm. |
| 98 | unsigned N = 0; |
| 99 | for (unsigned i = 0, e = Roots.size(); i != e; ++i) |
| 100 | N = DFSPass(Roots[i], Info[Roots[i]], N); |
| 101 | |
| 102 | for (unsigned i = N; i >= 2; --i) { |
| 103 | BasicBlock *W = Vertex[i]; |
| 104 | InfoRec &WInfo = Info[W]; |
| 105 | |
| 106 | // Step #2: Calculate the semidominators of all vertices |
| 107 | for (succ_iterator SI = succ_begin(W), SE = succ_end(W); SI != SE; ++SI) |
| 108 | if (Info.count(*SI)) { // Only if this predecessor is reachable! |
| 109 | unsigned SemiU = Info[Eval(*SI)].Semi; |
| 110 | if (SemiU < WInfo.Semi) |
| 111 | WInfo.Semi = SemiU; |
| 112 | } |
| 113 | |
| 114 | Info[Vertex[WInfo.Semi]].Bucket.push_back(W); |
| 115 | |
| 116 | BasicBlock *WParent = WInfo.Parent; |
| 117 | Link(WParent, W, WInfo); |
| 118 | |
| 119 | // Step #3: Implicitly define the immediate dominator of vertices |
| 120 | std::vector<BasicBlock*> &WParentBucket = Info[WParent].Bucket; |
| 121 | while (!WParentBucket.empty()) { |
| 122 | BasicBlock *V = WParentBucket.back(); |
| 123 | WParentBucket.pop_back(); |
| 124 | BasicBlock *U = Eval(V); |
| 125 | IDoms[V] = Info[U].Semi < Info[V].Semi ? U : WParent; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // Step #4: Explicitly define the immediate dominator of each vertex |
| 130 | for (unsigned i = 2; i <= N; ++i) { |
| 131 | BasicBlock *W = Vertex[i]; |
| 132 | BasicBlock *&WIDom = IDoms[W]; |
| 133 | if (WIDom != Vertex[Info[W].Semi]) |
| 134 | WIDom = IDoms[WIDom]; |
| 135 | } |
| 136 | |
| 137 | // Free temporary memory used to construct idom's |
| 138 | Info.clear(); |
| 139 | std::vector<BasicBlock*>().swap(Vertex); |
| 140 | |
| 141 | return false; |
| 142 | } |
| 143 | |
| 144 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4c9df7c | 2002-08-02 16:43:03 +0000 | [diff] [blame] | 145 | // PostDominatorSet Implementation |
Chris Lattner | 1715229 | 2001-07-02 05:46:38 +0000 | [diff] [blame] | 146 | //===----------------------------------------------------------------------===// |
| 147 | |
Chris Lattner | 1e43516 | 2002-07-26 21:12:44 +0000 | [diff] [blame] | 148 | static RegisterAnalysis<PostDominatorSet> |
Chris Lattner | 17689df | 2002-07-30 16:27:52 +0000 | [diff] [blame] | 149 | B("postdomset", "Post-Dominator Set Construction", true); |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 150 | |
Chris Lattner | ce6ef11 | 2002-07-26 18:40:14 +0000 | [diff] [blame] | 151 | // Postdominator set construction. This converts the specified function to only |
| 152 | // have a single exit node (return stmt), then calculates the post dominance |
| 153 | // sets for the function. |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 154 | // |
Chris Lattner | ce6ef11 | 2002-07-26 18:40:14 +0000 | [diff] [blame] | 155 | bool PostDominatorSet::runOnFunction(Function &F) { |
Chris Lattner | 706e61e | 2003-09-10 20:37:08 +0000 | [diff] [blame] | 156 | // Scan the function looking for the root nodes of the post-dominance |
| 157 | // relationships. These blocks end with return and unwind instructions. |
| 158 | // While we are iterating over the function, we also initialize all of the |
| 159 | // domsets to empty. |
| 160 | Roots.clear(); |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 161 | for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) |
Chris Lattner | ec7c1ab | 2004-10-16 18:21:33 +0000 | [diff] [blame] | 162 | if (succ_begin(I) == succ_end(I)) |
Chris Lattner | 706e61e | 2003-09-10 20:37:08 +0000 | [diff] [blame] | 163 | Roots.push_back(I); |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 164 | |
Chris Lattner | 706e61e | 2003-09-10 20:37:08 +0000 | [diff] [blame] | 165 | // If there are no exit nodes for the function, postdomsets are all empty. |
| 166 | // This can happen if the function just contains an infinite loop, for |
| 167 | // example. |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 168 | ImmediatePostDominators &IPD = getAnalysis<ImmediatePostDominators>(); |
| 169 | Doms.clear(); // Reset from the last time we were run... |
Chris Lattner | 706e61e | 2003-09-10 20:37:08 +0000 | [diff] [blame] | 170 | if (Roots.empty()) return false; |
| 171 | |
| 172 | // If we have more than one root, we insert an artificial "null" exit, which |
| 173 | // has "virtual edges" to each of the real exit nodes. |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 174 | //if (Roots.size() > 1) |
| 175 | // Doms[0].insert(0); |
Chris Lattner | 706e61e | 2003-09-10 20:37:08 +0000 | [diff] [blame] | 176 | |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 177 | // Root nodes only dominate themselves. |
| 178 | for (unsigned i = 0, e = Roots.size(); i != e; ++i) |
| 179 | Doms[Roots[i]].insert(Roots[i]); |
| 180 | |
| 181 | // Loop over all of the blocks in the function, calculating dominator sets for |
| 182 | // each function. |
| 183 | for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) |
| 184 | if (BasicBlock *IPDom = IPD[I]) { // Get idom if block is reachable |
| 185 | DomSetType &DS = Doms[I]; |
| 186 | assert(DS.empty() && "PostDomset already filled in for this block?"); |
| 187 | DS.insert(I); // Blocks always dominate themselves |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 188 | |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 189 | // Insert all dominators into the set... |
| 190 | while (IPDom) { |
| 191 | // If we have already computed the dominator sets for our immediate post |
| 192 | // dominator, just use it instead of walking all the way up to the root. |
| 193 | DomSetType &IPDS = Doms[IPDom]; |
| 194 | if (!IPDS.empty()) { |
| 195 | DS.insert(IPDS.begin(), IPDS.end()); |
| 196 | break; |
Chris Lattner | 706e61e | 2003-09-10 20:37:08 +0000 | [diff] [blame] | 197 | } else { |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 198 | DS.insert(IPDom); |
| 199 | IPDom = IPD[IPDom]; |
Chris Lattner | 706e61e | 2003-09-10 20:37:08 +0000 | [diff] [blame] | 200 | } |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 201 | } |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 202 | } else { |
| 203 | // Ensure that every basic block has at least an empty set of nodes. This |
| 204 | // is important for the case when there is unreachable blocks. |
| 205 | Doms[I]; |
Chris Lattner | cd7c287 | 2003-12-07 00:35:42 +0000 | [diff] [blame] | 206 | } |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 207 | |
| 208 | return false; |
Chris Lattner | cd7c287 | 2003-12-07 00:35:42 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Chris Lattner | 1715229 | 2001-07-02 05:46:38 +0000 | [diff] [blame] | 211 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4c9df7c | 2002-08-02 16:43:03 +0000 | [diff] [blame] | 212 | // PostDominatorTree Implementation |
Chris Lattner | 1715229 | 2001-07-02 05:46:38 +0000 | [diff] [blame] | 213 | //===----------------------------------------------------------------------===// |
| 214 | |
Chris Lattner | 1e43516 | 2002-07-26 21:12:44 +0000 | [diff] [blame] | 215 | static RegisterAnalysis<PostDominatorTree> |
Chris Lattner | 17689df | 2002-07-30 16:27:52 +0000 | [diff] [blame] | 216 | F("postdomtree", "Post-Dominator Tree Construction", true); |
Chris Lattner | 93193f8 | 2002-01-31 00:42:27 +0000 | [diff] [blame] | 217 | |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 218 | DominatorTreeBase::Node *PostDominatorTree::getNodeForBlock(BasicBlock *BB) { |
| 219 | Node *&BBNode = Nodes[BB]; |
| 220 | if (BBNode) return BBNode; |
| 221 | |
| 222 | // Haven't calculated this node yet? Get or calculate the node for the |
| 223 | // immediate postdominator. |
| 224 | BasicBlock *IPDom = getAnalysis<ImmediatePostDominators>()[BB]; |
| 225 | Node *IPDomNode = getNodeForBlock(IPDom); |
| 226 | |
| 227 | // Add a new tree node for this BasicBlock, and link it as a child of |
| 228 | // IDomNode |
| 229 | return BBNode = IPDomNode->addChild(new Node(BB, IPDomNode)); |
| 230 | } |
| 231 | |
| 232 | void PostDominatorTree::calculate(const ImmediatePostDominators &IPD) { |
Chris Lattner | 706e61e | 2003-09-10 20:37:08 +0000 | [diff] [blame] | 233 | if (Roots.empty()) return; |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 234 | |
| 235 | // Add a node for the root. This node might be the actual root, if there is |
| 236 | // one exit block, or it may be the virtual exit (denoted by (BasicBlock *)0) |
| 237 | // which postdominates all real exits if there are multiple exit blocks. |
Chris Lattner | 706e61e | 2003-09-10 20:37:08 +0000 | [diff] [blame] | 238 | BasicBlock *Root = Roots.size() == 1 ? Roots[0] : 0; |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 239 | Nodes[Root] = RootNode = new Node(Root, 0); |
| 240 | |
| 241 | Function *F = Roots[0]->getParent(); |
| 242 | // Loop over all of the reachable blocks in the function... |
| 243 | for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) |
| 244 | if (BasicBlock *ImmPostDom = IPD.get(I)) { // Reachable block. |
| 245 | Node *&BBNode = Nodes[I]; |
| 246 | if (!BBNode) { // Haven't calculated this node yet? |
| 247 | // Get or calculate the node for the immediate dominator |
| 248 | Node *IPDomNode = getNodeForBlock(ImmPostDom); |
| 249 | |
| 250 | // Add a new tree node for this BasicBlock, and link it as a child of |
| 251 | // IDomNode |
| 252 | BBNode = IPDomNode->addChild(new Node(I, IPDomNode)); |
Chris Lattner | 1715229 | 2001-07-02 05:46:38 +0000 | [diff] [blame] | 253 | } |
| 254 | } |
Chris Lattner | 1715229 | 2001-07-02 05:46:38 +0000 | [diff] [blame] | 255 | } |
Nate Begeman | 442b32b | 2006-03-11 02:20:46 +0000 | [diff] [blame] | 256 | |
Chris Lattner | ccacd3c | 2006-01-08 08:22:18 +0000 | [diff] [blame] | 257 | //===----------------------------------------------------------------------===// |
| 258 | // PostETForest Implementation |
| 259 | //===----------------------------------------------------------------------===// |
| 260 | |
| 261 | static RegisterAnalysis<PostETForest> |
| 262 | G("postetforest", "Post-ET-Forest Construction", true); |
| 263 | |
| 264 | ETNode *PostETForest::getNodeForBlock(BasicBlock *BB) { |
| 265 | ETNode *&BBNode = Nodes[BB]; |
| 266 | if (BBNode) return BBNode; |
| 267 | |
| 268 | // Haven't calculated this node yet? Get or calculate the node for the |
| 269 | // immediate dominator. |
| 270 | BasicBlock *IDom = getAnalysis<ImmediatePostDominators>()[BB]; |
| 271 | |
| 272 | // If we are unreachable, we may not have an immediate dominator. |
| 273 | if (!IDom) |
| 274 | return BBNode = new ETNode(BB); |
| 275 | else { |
| 276 | ETNode *IDomNode = getNodeForBlock(IDom); |
| 277 | |
| 278 | // Add a new tree node for this BasicBlock, and link it as a child of |
| 279 | // IDomNode |
| 280 | BBNode = new ETNode(BB); |
| 281 | BBNode->setFather(IDomNode); |
| 282 | return BBNode; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | void PostETForest::calculate(const ImmediatePostDominators &ID) { |
| 287 | for (unsigned i = 0, e = Roots.size(); i != e; ++i) |
| 288 | Nodes[Roots[i]] = new ETNode(Roots[i]); // Add a node for the root |
| 289 | |
| 290 | // Iterate over all nodes in inverse depth first order. |
| 291 | for (unsigned i = 0, e = Roots.size(); i != e; ++i) |
| 292 | for (idf_iterator<BasicBlock*> I = idf_begin(Roots[i]), |
| 293 | E = idf_end(Roots[i]); I != E; ++I) { |
| 294 | BasicBlock *BB = *I; |
| 295 | ETNode *&BBNode = Nodes[BB]; |
| 296 | if (!BBNode) { |
| 297 | ETNode *IDomNode = NULL; |
| 298 | |
| 299 | if (ID.get(BB)) |
| 300 | IDomNode = getNodeForBlock(ID.get(BB)); |
| 301 | |
| 302 | // Add a new ETNode for this BasicBlock, and set it's parent |
| 303 | // to it's immediate dominator. |
| 304 | BBNode = new ETNode(BB); |
| 305 | if (IDomNode) |
| 306 | BBNode->setFather(IDomNode); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | int dfsnum = 0; |
| 311 | // Iterate over all nodes in depth first order... |
| 312 | for (unsigned i = 0, e = Roots.size(); i != e; ++i) |
| 313 | for (idf_iterator<BasicBlock*> I = idf_begin(Roots[i]), |
| 314 | E = idf_end(Roots[i]); I != E; ++I) { |
| 315 | if (!getNodeForBlock(*I)->hasFather()) |
| 316 | getNodeForBlock(*I)->assignDFSNumber(dfsnum); |
| 317 | } |
| 318 | DFSInfoValid = true; |
| 319 | } |
Chris Lattner | 1715229 | 2001-07-02 05:46:38 +0000 | [diff] [blame] | 320 | |
Chris Lattner | 1715229 | 2001-07-02 05:46:38 +0000 | [diff] [blame] | 321 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4c9df7c | 2002-08-02 16:43:03 +0000 | [diff] [blame] | 322 | // PostDominanceFrontier Implementation |
Chris Lattner | 1715229 | 2001-07-02 05:46:38 +0000 | [diff] [blame] | 323 | //===----------------------------------------------------------------------===// |
| 324 | |
Chris Lattner | 1e43516 | 2002-07-26 21:12:44 +0000 | [diff] [blame] | 325 | static RegisterAnalysis<PostDominanceFrontier> |
Chris Lattner | 17689df | 2002-07-30 16:27:52 +0000 | [diff] [blame] | 326 | H("postdomfrontier", "Post-Dominance Frontier Construction", true); |
Chris Lattner | 93193f8 | 2002-01-31 00:42:27 +0000 | [diff] [blame] | 327 | |
Chris Lattner | 1b7f7dc | 2002-04-28 16:21:30 +0000 | [diff] [blame] | 328 | const DominanceFrontier::DomSetType & |
Misha Brukman | 2b37d7c | 2005-04-21 21:13:18 +0000 | [diff] [blame] | 329 | PostDominanceFrontier::calculate(const PostDominatorTree &DT, |
Chris Lattner | ce6ef11 | 2002-07-26 18:40:14 +0000 | [diff] [blame] | 330 | const DominatorTree::Node *Node) { |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 331 | // Loop over CFG successors to calculate DFlocal[Node] |
Chris Lattner | c444a42 | 2003-09-11 16:26:13 +0000 | [diff] [blame] | 332 | BasicBlock *BB = Node->getBlock(); |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 333 | DomSetType &S = Frontiers[BB]; // The new set to fill in... |
Chris Lattner | 706e61e | 2003-09-10 20:37:08 +0000 | [diff] [blame] | 334 | if (getRoots().empty()) return S; |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 335 | |
Chris Lattner | 706e61e | 2003-09-10 20:37:08 +0000 | [diff] [blame] | 336 | if (BB) |
| 337 | for (pred_iterator SI = pred_begin(BB), SE = pred_end(BB); |
| 338 | SI != SE; ++SI) |
Misha Brukman | 2f2d065 | 2003-09-11 18:14:24 +0000 | [diff] [blame] | 339 | // Does Node immediately dominate this predecessor? |
Chris Lattner | 706e61e | 2003-09-10 20:37:08 +0000 | [diff] [blame] | 340 | if (DT[*SI]->getIDom() != Node) |
| 341 | S.insert(*SI); |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 342 | |
| 343 | // At this point, S is DFlocal. Now we union in DFup's of our children... |
| 344 | // Loop through and visit the nodes that Node immediately dominates (Node's |
| 345 | // children in the IDomTree) |
| 346 | // |
Chris Lattner | ce6ef11 | 2002-07-26 18:40:14 +0000 | [diff] [blame] | 347 | for (PostDominatorTree::Node::const_iterator |
| 348 | NI = Node->begin(), NE = Node->end(); NI != NE; ++NI) { |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 349 | DominatorTree::Node *IDominee = *NI; |
Chris Lattner | ce6ef11 | 2002-07-26 18:40:14 +0000 | [diff] [blame] | 350 | const DomSetType &ChildDF = calculate(DT, IDominee); |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 351 | |
| 352 | DomSetType::const_iterator CDFI = ChildDF.begin(), CDFE = ChildDF.end(); |
| 353 | for (; CDFI != CDFE; ++CDFI) { |
Chris Lattner | 4b5086c | 2005-11-18 07:28:26 +0000 | [diff] [blame] | 354 | if (!Node->properlyDominates(DT[*CDFI])) |
Misha Brukman | dedf2bd | 2005-04-22 04:01:18 +0000 | [diff] [blame] | 355 | S.insert(*CDFI); |
Chris Lattner | 94108ab | 2001-07-06 16:58:22 +0000 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
| 359 | return S; |
| 360 | } |
Chris Lattner | a69fd90 | 2002-08-21 23:43:50 +0000 | [diff] [blame] | 361 | |
| 362 | // stub - a dummy function to make linking work ok. |
Reid Spencer | 192913e | 2006-06-01 07:02:51 +0000 | [diff] [blame] | 363 | int PostDominanceFrontier::stub; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 364 | |