blob: caff1f1db3048f5b7b04d678a3b6fe0210585e94 [file] [log] [blame]
Chris Lattner17152292001-07-02 05:46:38 +00001//===- DominatorSet.cpp - Dominator Set Calculation --------------*- C++ -*--=//
2//
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00003// This file provides a simple class to calculate the dominator set of a
4// function.
Chris Lattner17152292001-07-02 05:46:38 +00005//
6//===----------------------------------------------------------------------===//
7
8#include "llvm/Analysis/Dominators.h"
Chris Lattnerfc514f42002-05-07 19:18:48 +00009#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
Chris Lattner221d6882002-02-12 21:07:25 +000010#include "llvm/Support/CFG.h"
Chris Lattnercee8f9a2001-11-27 00:03:19 +000011#include "Support/DepthFirstIterator.h"
12#include "Support/STLExtras.h"
Chris Lattnereb5230c2002-02-05 03:35:31 +000013#include "Support/SetOperations.h"
Chris Lattner17152292001-07-02 05:46:38 +000014#include <algorithm>
Chris Lattner697954c2002-01-20 22:54:45 +000015using std::set;
16
Chris Lattner94108ab2001-07-06 16:58:22 +000017//===----------------------------------------------------------------------===//
Chris Lattner17152292001-07-02 05:46:38 +000018// DominatorSet Implementation
19//===----------------------------------------------------------------------===//
20
Chris Lattner07a228d2002-05-06 19:32:07 +000021AnalysisID DominatorSet::ID(AnalysisID::create<DominatorSet>(), true);
22AnalysisID DominatorSet::PostDomID(AnalysisID::create<DominatorSet>(), true);
Chris Lattner93193f82002-01-31 00:42:27 +000023
Chris Lattner7e708292002-06-25 16:13:24 +000024bool DominatorSet::runOnFunction(Function &F) {
Chris Lattner93193f82002-01-31 00:42:27 +000025 Doms.clear(); // Reset from the last time we were run...
26
27 if (isPostDominator())
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000028 calcPostDominatorSet(F);
Chris Lattner93193f82002-01-31 00:42:27 +000029 else
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000030 calcForwardDominatorSet(F);
Chris Lattner93193f82002-01-31 00:42:27 +000031 return false;
Chris Lattner94108ab2001-07-06 16:58:22 +000032}
33
Chris Lattneref704a22002-05-13 22:03:16 +000034// dominates - Return true if A dominates B. This performs the special checks
35// neccesary if A and B are in the same basic block.
36//
37bool DominatorSet::dominates(Instruction *A, Instruction *B) const {
38 BasicBlock *BBA = A->getParent(), *BBB = B->getParent();
39 if (BBA != BBB) return dominates(BBA, BBB);
40
41 // Loop through the basic block until we find A or B.
42 BasicBlock::iterator I = BBA->begin();
Chris Lattner7e708292002-06-25 16:13:24 +000043 for (; &*I != A && &*I != B; ++I) /*empty*/;
Chris Lattneref704a22002-05-13 22:03:16 +000044
45 // A dominates B if it is found first in the basic block...
Chris Lattner7e708292002-06-25 16:13:24 +000046 return &*I == A;
Chris Lattneref704a22002-05-13 22:03:16 +000047}
Chris Lattner93193f82002-01-31 00:42:27 +000048
Chris Lattner94108ab2001-07-06 16:58:22 +000049// calcForwardDominatorSet - This method calculates the forward dominator sets
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000050// for the specified function.
Chris Lattner94108ab2001-07-06 16:58:22 +000051//
Chris Lattner7e708292002-06-25 16:13:24 +000052void DominatorSet::calcForwardDominatorSet(Function &F) {
53 Root = &F.getEntryNode();
Chris Lattner455889a2002-02-12 22:39:50 +000054 assert(pred_begin(Root) == pred_end(Root) &&
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000055 "Root node has predecessors in function!");
Chris Lattnerff5a8c42001-11-26 18:52:02 +000056
Chris Lattner17152292001-07-02 05:46:38 +000057 bool Changed;
58 do {
59 Changed = false;
60
61 DomSetType WorkingSet;
Chris Lattner7e708292002-06-25 16:13:24 +000062 df_iterator<Function*> It = df_begin(&F), End = df_end(&F);
Chris Lattner17152292001-07-02 05:46:38 +000063 for ( ; It != End; ++It) {
Chris Lattnera298d272002-04-28 00:15:57 +000064 BasicBlock *BB = *It;
65 pred_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
Chris Lattner17152292001-07-02 05:46:38 +000066 if (PI != PEnd) { // Is there SOME predecessor?
67 // Loop until we get to a predecessor that has had it's dom set filled
68 // in at least once. We are guaranteed to have this because we are
69 // traversing the graph in DFO and have handled start nodes specially.
70 //
71 while (Doms[*PI].size() == 0) ++PI;
72 WorkingSet = Doms[*PI];
73
74 for (++PI; PI != PEnd; ++PI) { // Intersect all of the predecessor sets
75 DomSetType &PredSet = Doms[*PI];
76 if (PredSet.size())
77 set_intersect(WorkingSet, PredSet);
78 }
79 }
80
81 WorkingSet.insert(BB); // A block always dominates itself
82 DomSetType &BBSet = Doms[BB];
83 if (BBSet != WorkingSet) {
84 BBSet.swap(WorkingSet); // Constant time operation!
85 Changed = true; // The sets changed.
86 }
87 WorkingSet.clear(); // Clear out the set for next iteration
88 }
89 } while (Changed);
Chris Lattner94108ab2001-07-06 16:58:22 +000090}
Chris Lattner17152292001-07-02 05:46:38 +000091
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000092// Postdominator set constructor. This ctor converts the specified function to
Chris Lattner94108ab2001-07-06 16:58:22 +000093// only have a single exit node (return stmt), then calculates the post
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000094// dominance sets for the function.
Chris Lattner94108ab2001-07-06 16:58:22 +000095//
Chris Lattner7e708292002-06-25 16:13:24 +000096void DominatorSet::calcPostDominatorSet(Function &F) {
Chris Lattner93193f82002-01-31 00:42:27 +000097 // Since we require that the unify all exit nodes pass has been run, we know
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000098 // that there can be at most one return instruction in the function left.
Chris Lattner93193f82002-01-31 00:42:27 +000099 // Get it.
100 //
Chris Lattner483e14e2002-04-27 07:27:19 +0000101 Root = getAnalysis<UnifyFunctionExitNodes>().getExitNode();
Chris Lattner94108ab2001-07-06 16:58:22 +0000102
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000103 if (Root == 0) { // No exit node for the function? Postdomsets are all empty
Chris Lattner7e708292002-06-25 16:13:24 +0000104 for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
105 Doms[FI] = DomSetType();
Chris Lattner384e5b12001-08-23 17:07:19 +0000106 return;
107 }
Chris Lattner94108ab2001-07-06 16:58:22 +0000108
109 bool Changed;
110 do {
111 Changed = false;
112
113 set<const BasicBlock*> Visited;
114 DomSetType WorkingSet;
Chris Lattner93193f82002-01-31 00:42:27 +0000115 idf_iterator<BasicBlock*> It = idf_begin(Root), End = idf_end(Root);
Chris Lattner94108ab2001-07-06 16:58:22 +0000116 for ( ; It != End; ++It) {
Chris Lattnera298d272002-04-28 00:15:57 +0000117 BasicBlock *BB = *It;
118 succ_iterator PI = succ_begin(BB), PEnd = succ_end(BB);
Chris Lattner94108ab2001-07-06 16:58:22 +0000119 if (PI != PEnd) { // Is there SOME predecessor?
120 // Loop until we get to a successor that has had it's dom set filled
121 // in at least once. We are guaranteed to have this because we are
122 // traversing the graph in DFO and have handled start nodes specially.
123 //
124 while (Doms[*PI].size() == 0) ++PI;
125 WorkingSet = Doms[*PI];
126
127 for (++PI; PI != PEnd; ++PI) { // Intersect all of the successor sets
128 DomSetType &PredSet = Doms[*PI];
129 if (PredSet.size())
130 set_intersect(WorkingSet, PredSet);
131 }
132 }
133
134 WorkingSet.insert(BB); // A block always dominates itself
135 DomSetType &BBSet = Doms[BB];
136 if (BBSet != WorkingSet) {
137 BBSet.swap(WorkingSet); // Constant time operation!
138 Changed = true; // The sets changed.
139 }
140 WorkingSet.clear(); // Clear out the set for next iteration
141 }
142 } while (Changed);
Chris Lattner17152292001-07-02 05:46:38 +0000143}
144
Chris Lattnerf57b8452002-04-27 06:56:12 +0000145// getAnalysisUsage - This obviously provides a dominator set, but it also
146// uses the UnifyFunctionExitNodes pass if building post-dominators
Chris Lattner93193f82002-01-31 00:42:27 +0000147//
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000148void DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
Chris Lattnerf57b8452002-04-27 06:56:12 +0000149 AU.setPreservesAll();
Chris Lattner65b97092002-01-31 18:29:24 +0000150 if (isPostDominator()) {
Chris Lattnerf57b8452002-04-27 06:56:12 +0000151 AU.addProvided(PostDomID);
Chris Lattner483e14e2002-04-27 07:27:19 +0000152 AU.addRequired(UnifyFunctionExitNodes::ID);
Chris Lattner65b97092002-01-31 18:29:24 +0000153 } else {
Chris Lattnerf57b8452002-04-27 06:56:12 +0000154 AU.addProvided(ID);
Chris Lattner65b97092002-01-31 18:29:24 +0000155 }
Chris Lattner93193f82002-01-31 00:42:27 +0000156}
157
Chris Lattner17152292001-07-02 05:46:38 +0000158
159//===----------------------------------------------------------------------===//
160// ImmediateDominators Implementation
161//===----------------------------------------------------------------------===//
162
Chris Lattner07a228d2002-05-06 19:32:07 +0000163AnalysisID ImmediateDominators::ID(AnalysisID::create<ImmediateDominators>(), true);
164AnalysisID ImmediateDominators::PostDomID(AnalysisID::create<ImmediateDominators>(), true);
Chris Lattner93193f82002-01-31 00:42:27 +0000165
Chris Lattner17152292001-07-02 05:46:38 +0000166// calcIDoms - Calculate the immediate dominator mapping, given a set of
167// dominators for every basic block.
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000168void ImmediateDominators::calcIDoms(const DominatorSet &DS) {
Chris Lattner17152292001-07-02 05:46:38 +0000169 // Loop over all of the nodes that have dominators... figuring out the IDOM
170 // for each node...
171 //
172 for (DominatorSet::const_iterator DI = DS.begin(), DEnd = DS.end();
173 DI != DEnd; ++DI) {
Chris Lattnera298d272002-04-28 00:15:57 +0000174 BasicBlock *BB = DI->first;
Chris Lattner17152292001-07-02 05:46:38 +0000175 const DominatorSet::DomSetType &Dominators = DI->second;
176 unsigned DomSetSize = Dominators.size();
177 if (DomSetSize == 1) continue; // Root node... IDom = null
178
179 // Loop over all dominators of this node. This corresponds to looping over
180 // nodes in the dominator chain, looking for a node whose dominator set is
181 // equal to the current nodes, except that the current node does not exist
182 // in it. This means that it is one level higher in the dom chain than the
183 // current node, and it is our idom!
184 //
185 DominatorSet::DomSetType::const_iterator I = Dominators.begin();
186 DominatorSet::DomSetType::const_iterator End = Dominators.end();
187 for (; I != End; ++I) { // Iterate over dominators...
188 // All of our dominators should form a chain, where the number of elements
189 // in the dominator set indicates what level the node is at in the chain.
190 // We want the node immediately above us, so it will have an identical
191 // dominator set, except that BB will not dominate it... therefore it's
192 // dominator set size will be one less than BB's...
193 //
194 if (DS.getDominators(*I).size() == DomSetSize - 1) {
195 IDoms[BB] = *I;
196 break;
197 }
198 }
199 }
200}
201
202
203//===----------------------------------------------------------------------===//
204// DominatorTree Implementation
205//===----------------------------------------------------------------------===//
206
Chris Lattner07a228d2002-05-06 19:32:07 +0000207AnalysisID DominatorTree::ID(AnalysisID::create<DominatorTree>(), true);
208AnalysisID DominatorTree::PostDomID(AnalysisID::create<DominatorTree>(), true);
Chris Lattner93193f82002-01-31 00:42:27 +0000209
210// DominatorTree::reset - Free all of the tree node memory.
Chris Lattner17152292001-07-02 05:46:38 +0000211//
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000212void DominatorTree::reset() {
Chris Lattner17152292001-07-02 05:46:38 +0000213 for (NodeMapType::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I)
214 delete I->second;
Chris Lattner93193f82002-01-31 00:42:27 +0000215 Nodes.clear();
Chris Lattner17152292001-07-02 05:46:38 +0000216}
217
218
Chris Lattner93193f82002-01-31 00:42:27 +0000219#if 0
220// Given immediate dominators, we can also calculate the dominator tree
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000221DominatorTree::DominatorTree(const ImmediateDominators &IDoms)
Chris Lattner94108ab2001-07-06 16:58:22 +0000222 : DominatorBase(IDoms.getRoot()) {
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000223 const Function *M = Root->getParent();
Chris Lattner17152292001-07-02 05:46:38 +0000224
225 Nodes[Root] = new Node(Root, 0); // Add a node for the root...
226
227 // Iterate over all nodes in depth first order...
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000228 for (df_iterator<const Function*> I = df_begin(M), E = df_end(M); I!=E; ++I) {
Chris Lattner17152292001-07-02 05:46:38 +0000229 const BasicBlock *BB = *I, *IDom = IDoms[*I];
230
231 if (IDom != 0) { // Ignore the root node and other nasty nodes
232 // We know that the immediate dominator should already have a node,
233 // because we are traversing the CFG in depth first order!
234 //
235 assert(Nodes[IDom] && "No node for IDOM?");
236 Node *IDomNode = Nodes[IDom];
237
238 // Add a new tree node for this BasicBlock, and link it as a child of
239 // IDomNode
240 Nodes[BB] = IDomNode->addChild(new Node(BB, IDomNode));
241 }
242 }
243}
Chris Lattner93193f82002-01-31 00:42:27 +0000244#endif
Chris Lattner17152292001-07-02 05:46:38 +0000245
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000246void DominatorTree::calculate(const DominatorSet &DS) {
Chris Lattner17152292001-07-02 05:46:38 +0000247 Nodes[Root] = new Node(Root, 0); // Add a node for the root...
248
Chris Lattner94108ab2001-07-06 16:58:22 +0000249 if (!isPostDominator()) {
250 // Iterate over all nodes in depth first order...
Chris Lattner93193f82002-01-31 00:42:27 +0000251 for (df_iterator<BasicBlock*> I = df_begin(Root), E = df_end(Root);
Chris Lattner3ff43872001-09-28 22:56:31 +0000252 I != E; ++I) {
Chris Lattnera298d272002-04-28 00:15:57 +0000253 BasicBlock *BB = *I;
Chris Lattner94108ab2001-07-06 16:58:22 +0000254 const DominatorSet::DomSetType &Dominators = DS.getDominators(BB);
255 unsigned DomSetSize = Dominators.size();
256 if (DomSetSize == 1) continue; // Root node... IDom = null
257
Chris Lattner3ff43872001-09-28 22:56:31 +0000258 // Loop over all dominators of this node. This corresponds to looping over
Chris Lattner94108ab2001-07-06 16:58:22 +0000259 // nodes in the dominator chain, looking for a node whose dominator set is
260 // equal to the current nodes, except that the current node does not exist
Chris Lattner3ff43872001-09-28 22:56:31 +0000261 // in it. This means that it is one level higher in the dom chain than the
Chris Lattner94108ab2001-07-06 16:58:22 +0000262 // current node, and it is our idom! We know that we have already added
263 // a DominatorTree node for our idom, because the idom must be a
264 // predecessor in the depth first order that we are iterating through the
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000265 // function.
Chris Lattner17152292001-07-02 05:46:38 +0000266 //
Chris Lattner94108ab2001-07-06 16:58:22 +0000267 DominatorSet::DomSetType::const_iterator I = Dominators.begin();
268 DominatorSet::DomSetType::const_iterator End = Dominators.end();
269 for (; I != End; ++I) { // Iterate over dominators...
Chris Lattner3ff43872001-09-28 22:56:31 +0000270 // All of our dominators should form a chain, where the number of
271 // elements in the dominator set indicates what level the node is at in
272 // the chain. We want the node immediately above us, so it will have
273 // an identical dominator set, except that BB will not dominate it...
274 // therefore it's dominator set size will be one less than BB's...
Chris Lattner17152292001-07-02 05:46:38 +0000275 //
Chris Lattner94108ab2001-07-06 16:58:22 +0000276 if (DS.getDominators(*I).size() == DomSetSize - 1) {
277 // We know that the immediate dominator should already have a node,
278 // because we are traversing the CFG in depth first order!
279 //
280 Node *IDomNode = Nodes[*I];
281 assert(IDomNode && "No node for IDOM?");
282
283 // Add a new tree node for this BasicBlock, and link it as a child of
284 // IDomNode
285 Nodes[BB] = IDomNode->addChild(new Node(BB, IDomNode));
286 break;
287 }
288 }
289 }
Chris Lattner384e5b12001-08-23 17:07:19 +0000290 } else if (Root) {
Chris Lattner94108ab2001-07-06 16:58:22 +0000291 // Iterate over all nodes in depth first order...
Chris Lattner93193f82002-01-31 00:42:27 +0000292 for (idf_iterator<BasicBlock*> I = idf_begin(Root), E = idf_end(Root);
Chris Lattner3ff43872001-09-28 22:56:31 +0000293 I != E; ++I) {
Chris Lattnera298d272002-04-28 00:15:57 +0000294 BasicBlock *BB = *I;
Chris Lattner94108ab2001-07-06 16:58:22 +0000295 const DominatorSet::DomSetType &Dominators = DS.getDominators(BB);
296 unsigned DomSetSize = Dominators.size();
297 if (DomSetSize == 1) continue; // Root node... IDom = null
298
Chris Lattner3ff43872001-09-28 22:56:31 +0000299 // Loop over all dominators of this node. This corresponds to looping
300 // over nodes in the dominator chain, looking for a node whose dominator
301 // set is equal to the current nodes, except that the current node does
302 // not exist in it. This means that it is one level higher in the dom
303 // chain than the current node, and it is our idom! We know that we have
304 // already added a DominatorTree node for our idom, because the idom must
305 // be a predecessor in the depth first order that we are iterating through
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000306 // the function.
Chris Lattner94108ab2001-07-06 16:58:22 +0000307 //
308 DominatorSet::DomSetType::const_iterator I = Dominators.begin();
309 DominatorSet::DomSetType::const_iterator End = Dominators.end();
310 for (; I != End; ++I) { // Iterate over dominators...
Chris Lattner93193f82002-01-31 00:42:27 +0000311 // All of our dominators should form a chain, where the number
312 // of elements in the dominator set indicates what level the
313 // node is at in the chain. We want the node immediately
314 // above us, so it will have an identical dominator set,
315 // except that BB will not dominate it... therefore it's
Chris Lattner94108ab2001-07-06 16:58:22 +0000316 // dominator set size will be one less than BB's...
317 //
318 if (DS.getDominators(*I).size() == DomSetSize - 1) {
319 // We know that the immediate dominator should already have a node,
320 // because we are traversing the CFG in depth first order!
321 //
322 Node *IDomNode = Nodes[*I];
323 assert(IDomNode && "No node for IDOM?");
324
325 // Add a new tree node for this BasicBlock, and link it as a child of
326 // IDomNode
327 Nodes[BB] = IDomNode->addChild(new Node(BB, IDomNode));
328 break;
329 }
Chris Lattner17152292001-07-02 05:46:38 +0000330 }
331 }
332 }
333}
334
335
336
337//===----------------------------------------------------------------------===//
338// DominanceFrontier Implementation
339//===----------------------------------------------------------------------===//
340
Chris Lattner07a228d2002-05-06 19:32:07 +0000341AnalysisID DominanceFrontier::ID(AnalysisID::create<DominanceFrontier>(), true);
342AnalysisID DominanceFrontier::PostDomID(AnalysisID::create<DominanceFrontier>(), true);
Chris Lattner93193f82002-01-31 00:42:27 +0000343
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000344const DominanceFrontier::DomSetType &
345DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
346 const DominatorTree::Node *Node) {
Chris Lattner17152292001-07-02 05:46:38 +0000347 // Loop over CFG successors to calculate DFlocal[Node]
Chris Lattnera298d272002-04-28 00:15:57 +0000348 BasicBlock *BB = Node->getNode();
Chris Lattner17152292001-07-02 05:46:38 +0000349 DomSetType &S = Frontiers[BB]; // The new set to fill in...
350
Chris Lattnera298d272002-04-28 00:15:57 +0000351 for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB);
Chris Lattner455889a2002-02-12 22:39:50 +0000352 SI != SE; ++SI) {
Chris Lattner17152292001-07-02 05:46:38 +0000353 // Does Node immediately dominate this successor?
354 if (DT[*SI]->getIDom() != Node)
355 S.insert(*SI);
356 }
357
358 // At this point, S is DFlocal. Now we union in DFup's of our children...
359 // Loop through and visit the nodes that Node immediately dominates (Node's
360 // children in the IDomTree)
361 //
362 for (DominatorTree::Node::const_iterator NI = Node->begin(), NE = Node->end();
363 NI != NE; ++NI) {
364 DominatorTree::Node *IDominee = *NI;
365 const DomSetType &ChildDF = calcDomFrontier(DT, IDominee);
366
367 DomSetType::const_iterator CDFI = ChildDF.begin(), CDFE = ChildDF.end();
368 for (; CDFI != CDFE; ++CDFI) {
369 if (!Node->dominates(DT[*CDFI]))
370 S.insert(*CDFI);
371 }
372 }
373
374 return S;
375}
Chris Lattner94108ab2001-07-06 16:58:22 +0000376
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000377const DominanceFrontier::DomSetType &
378DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT,
379 const DominatorTree::Node *Node) {
Chris Lattner94108ab2001-07-06 16:58:22 +0000380 // Loop over CFG successors to calculate DFlocal[Node]
Chris Lattnera298d272002-04-28 00:15:57 +0000381 BasicBlock *BB = Node->getNode();
Chris Lattner94108ab2001-07-06 16:58:22 +0000382 DomSetType &S = Frontiers[BB]; // The new set to fill in...
Chris Lattner384e5b12001-08-23 17:07:19 +0000383 if (!Root) return S;
Chris Lattner94108ab2001-07-06 16:58:22 +0000384
Chris Lattnera298d272002-04-28 00:15:57 +0000385 for (pred_iterator SI = pred_begin(BB), SE = pred_end(BB);
Chris Lattner455889a2002-02-12 22:39:50 +0000386 SI != SE; ++SI) {
Chris Lattner94108ab2001-07-06 16:58:22 +0000387 // Does Node immediately dominate this predeccessor?
388 if (DT[*SI]->getIDom() != Node)
389 S.insert(*SI);
390 }
391
392 // At this point, S is DFlocal. Now we union in DFup's of our children...
393 // Loop through and visit the nodes that Node immediately dominates (Node's
394 // children in the IDomTree)
395 //
396 for (DominatorTree::Node::const_iterator NI = Node->begin(), NE = Node->end();
397 NI != NE; ++NI) {
398 DominatorTree::Node *IDominee = *NI;
Chris Lattner35908302001-07-08 05:54:09 +0000399 const DomSetType &ChildDF = calcPostDomFrontier(DT, IDominee);
Chris Lattner94108ab2001-07-06 16:58:22 +0000400
401 DomSetType::const_iterator CDFI = ChildDF.begin(), CDFE = ChildDF.end();
402 for (; CDFI != CDFE; ++CDFI) {
403 if (!Node->dominates(DT[*CDFI]))
404 S.insert(*CDFI);
405 }
406 }
407
408 return S;
409}