Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 1 | //===-- LCSSA.cpp - Convert loops into loop-closed SSA form ---------------===// |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Owen Anderson and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This pass transforms loops by placing phi nodes at the end of the loops for |
| 11 | // all values that are live across the loop boundary. For example, it turns |
| 12 | // the left into the right code: |
| 13 | // |
| 14 | // for (...) for (...) |
| 15 | // if (c) if(c) |
| 16 | // X1 = ... X1 = ... |
| 17 | // else else |
| 18 | // X2 = ... X2 = ... |
| 19 | // X3 = phi(X1, X2) X3 = phi(X1, X2) |
| 20 | // ... = X3 + 4 X4 = phi(X3) |
| 21 | // ... = X4 + 4 |
| 22 | // |
| 23 | // This is still valid LLVM; the extra phi nodes are purely redundant, and will |
| 24 | // be trivially eliminated by InstCombine. The major benefit of this |
| 25 | // transformation is that it makes many other loop optimizations, such as |
| 26 | // LoopUnswitching, simpler. |
| 27 | // |
| 28 | //===----------------------------------------------------------------------===// |
| 29 | |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 30 | #include "llvm/Transforms/Scalar.h" |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 31 | #include "llvm/Pass.h" |
| 32 | #include "llvm/Function.h" |
| 33 | #include "llvm/Instructions.h" |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 34 | #include "llvm/ADT/SetVector.h" |
Owen Anderson | b4e1699 | 2006-05-27 00:31:37 +0000 | [diff] [blame] | 35 | #include "llvm/ADT/Statistic.h" |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 36 | #include "llvm/Analysis/Dominators.h" |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 37 | #include "llvm/Analysis/LoopInfo.h" |
| 38 | #include "llvm/Support/CFG.h" |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 39 | #include <algorithm> |
Owen Anderson | 1310e42 | 2006-05-27 18:47:11 +0000 | [diff] [blame] | 40 | #include <map> |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 41 | |
| 42 | using namespace llvm; |
| 43 | |
| 44 | namespace { |
Owen Anderson | 152d063 | 2006-05-28 19:33:28 +0000 | [diff] [blame] | 45 | static Statistic<> NumLCSSA("lcssa", |
| 46 | "Number of live out of a loop variables"); |
Owen Anderson | b4e1699 | 2006-05-27 00:31:37 +0000 | [diff] [blame] | 47 | |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 48 | class LCSSA : public FunctionPass { |
| 49 | public: |
Owen Anderson | b4e1699 | 2006-05-27 00:31:37 +0000 | [diff] [blame] | 50 | |
| 51 | |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 52 | LoopInfo *LI; // Loop information |
Owen Anderson | 766f90b | 2006-06-04 00:55:19 +0000 | [diff] [blame] | 53 | DominatorTree *DT; // Dominator Tree for the current Function... |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 54 | DominanceFrontier *DF; // Current Dominance Frontier |
Owen Anderson | 9e81c1b | 2006-06-06 04:28:30 +0000 | [diff] [blame] | 55 | std::vector<BasicBlock*> LoopBlocks; |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 56 | |
| 57 | virtual bool runOnFunction(Function &F); |
Owen Anderson | 6e047ab | 2006-05-26 21:19:17 +0000 | [diff] [blame] | 58 | bool visitSubloop(Loop* L); |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 59 | void processInstruction(Instruction* Instr, |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 60 | const std::vector<BasicBlock*>& exitBlocks); |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 61 | |
| 62 | /// This transformation requires natural loop information & requires that |
Owen Anderson | b4e1699 | 2006-05-27 00:31:37 +0000 | [diff] [blame] | 63 | /// loop preheaders be inserted into the CFG. It maintains both of these, |
| 64 | /// as well as the CFG. It also requires dominator information. |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 65 | /// |
| 66 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 67 | AU.setPreservesCFG(); |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 68 | AU.addRequiredID(LoopSimplifyID); |
| 69 | AU.addPreservedID(LoopSimplifyID); |
| 70 | AU.addRequired<LoopInfo>(); |
Owen Anderson | 1310e42 | 2006-05-27 18:47:11 +0000 | [diff] [blame] | 71 | AU.addRequired<DominatorTree>(); |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 72 | AU.addRequired<DominanceFrontier>(); |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 73 | } |
| 74 | private: |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 75 | SetVector<Instruction*> getLoopValuesUsedOutsideLoop(Loop *L); |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 76 | Instruction *getValueDominatingBlock(BasicBlock *BB, |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 77 | std::map<BasicBlock*, Instruction*>& PotDoms); |
| 78 | |
Owen Anderson | 9e81c1b | 2006-06-06 04:28:30 +0000 | [diff] [blame] | 79 | /// inLoop - returns true if the given block is within the current loop |
| 80 | const bool inLoop(BasicBlock* B) { |
Owen Anderson | ac601b4 | 2006-06-06 04:36:36 +0000 | [diff] [blame] | 81 | return std::binary_search(LoopBlocks.begin(), LoopBlocks.end(), B); |
| 82 | } |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | RegisterOpt<LCSSA> X("lcssa", "Loop-Closed SSA Form Pass"); |
| 86 | } |
| 87 | |
| 88 | FunctionPass *llvm::createLCSSAPass() { return new LCSSA(); } |
Owen Anderson | 5d02926 | 2006-06-08 20:02:53 +0000 | [diff] [blame] | 89 | const PassInfo *llvm::LCSSAID = X.getPassInfo(); |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 90 | |
Owen Anderson | 5d02926 | 2006-06-08 20:02:53 +0000 | [diff] [blame] | 91 | /// runOnFunction - Process all loops in the function, inner-most out. |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 92 | bool LCSSA::runOnFunction(Function &F) { |
| 93 | bool changed = false; |
| 94 | LI = &getAnalysis<LoopInfo>(); |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 95 | DF = &getAnalysis<DominanceFrontier>(); |
| 96 | DT = &getAnalysis<DominatorTree>(); |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 97 | |
| 98 | for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) { |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 99 | changed |= visitSubloop(*I); |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 100 | } |
Evan Cheng | 1b6e310 | 2006-06-11 09:32:57 +0000 | [diff] [blame^] | 101 | |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 102 | return changed; |
| 103 | } |
| 104 | |
Owen Anderson | 5d02926 | 2006-06-08 20:02:53 +0000 | [diff] [blame] | 105 | /// visitSubloop - Recursively process all subloops, and then process the given |
| 106 | /// loop if it has live-out values. |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 107 | bool LCSSA::visitSubloop(Loop* L) { |
| 108 | for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I) |
| 109 | visitSubloop(*I); |
| 110 | |
| 111 | // Speed up queries by creating a sorted list of blocks |
Owen Anderson | 9e81c1b | 2006-06-06 04:28:30 +0000 | [diff] [blame] | 112 | LoopBlocks.clear(); |
| 113 | LoopBlocks.insert(LoopBlocks.end(), L->block_begin(), L->block_end()); |
| 114 | std::sort(LoopBlocks.begin(), LoopBlocks.end()); |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 115 | |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 116 | SetVector<Instruction*> AffectedValues = getLoopValuesUsedOutsideLoop(L); |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 117 | |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 118 | // If no values are affected, we can save a lot of work, since we know that |
| 119 | // nothing will be changed. |
| 120 | if (AffectedValues.empty()) |
| 121 | return false; |
| 122 | |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 123 | std::vector<BasicBlock*> exitBlocks; |
| 124 | L->getExitBlocks(exitBlocks); |
| 125 | |
Owen Anderson | 1310e42 | 2006-05-27 18:47:11 +0000 | [diff] [blame] | 126 | |
| 127 | // Iterate over all affected values for this loop and insert Phi nodes |
| 128 | // for them in the appropriate exit blocks |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 129 | |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 130 | for (SetVector<Instruction*>::iterator I = AffectedValues.begin(), |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 131 | E = AffectedValues.end(); I != E; ++I) { |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 132 | processInstruction(*I, exitBlocks); |
Owen Anderson | 1310e42 | 2006-05-27 18:47:11 +0000 | [diff] [blame] | 133 | } |
Owen Anderson | 8a8f278 | 2006-05-29 01:00:00 +0000 | [diff] [blame] | 134 | |
Owen Anderson | 9e81c1b | 2006-06-06 04:28:30 +0000 | [diff] [blame] | 135 | return true; |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Owen Anderson | 5d02926 | 2006-06-08 20:02:53 +0000 | [diff] [blame] | 138 | /// processInstruction - Given a live-out instruction, insert LCSSA Phi nodes, |
| 139 | /// eliminate all out-of-loop uses. |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 140 | void LCSSA::processInstruction(Instruction* Instr, |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 141 | const std::vector<BasicBlock*>& exitBlocks) |
| 142 | { |
| 143 | ++NumLCSSA; // We are applying the transformation |
| 144 | |
| 145 | std::map<BasicBlock*, Instruction*> Phis; |
Owen Anderson | d00eacc | 2006-06-03 23:22:50 +0000 | [diff] [blame] | 146 | |
| 147 | // Add the base instruction to the Phis list. This makes tracking down |
| 148 | // the dominating values easier when we're filling in Phi nodes. This will |
| 149 | // be removed later, before we perform use replacement. |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 150 | Phis[Instr->getParent()] = Instr; |
| 151 | |
| 152 | // Phi nodes that need to be IDF-processed |
| 153 | std::vector<PHINode*> workList; |
| 154 | |
| 155 | for (std::vector<BasicBlock*>::const_iterator BBI = exitBlocks.begin(), |
Owen Anderson | cd76fa0 | 2006-06-01 06:05:47 +0000 | [diff] [blame] | 156 | BBE = exitBlocks.end(); BBI != BBE; ++BBI) |
| 157 | if (DT->getNode(Instr->getParent())->dominates(DT->getNode(*BBI))) { |
Owen Anderson | 766f90b | 2006-06-04 00:55:19 +0000 | [diff] [blame] | 158 | PHINode *phi = new PHINode(Instr->getType(), Instr->getName()+".lcssa", |
| 159 | (*BBI)->begin()); |
Owen Anderson | cd76fa0 | 2006-06-01 06:05:47 +0000 | [diff] [blame] | 160 | workList.push_back(phi); |
| 161 | Phis[*BBI] = phi; |
| 162 | } |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 163 | |
Owen Anderson | d00eacc | 2006-06-03 23:22:50 +0000 | [diff] [blame] | 164 | // Phi nodes that need to have their incoming values filled. |
| 165 | std::vector<PHINode*> needIncomingValues; |
| 166 | |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 167 | // Calculate the IDF of these LCSSA Phi nodes, inserting new Phi's where |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 168 | // necessary. Keep track of these new Phi's in the "Phis" map. |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 169 | while (!workList.empty()) { |
| 170 | PHINode *CurPHI = workList.back(); |
| 171 | workList.pop_back(); |
| 172 | |
Owen Anderson | d00eacc | 2006-06-03 23:22:50 +0000 | [diff] [blame] | 173 | // Even though we've removed this Phi from the work list, we still need |
| 174 | // to fill in its incoming values. |
| 175 | needIncomingValues.push_back(CurPHI); |
| 176 | |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 177 | // Get the current Phi's DF, and insert Phi nodes. Add these new |
| 178 | // nodes to our worklist. |
| 179 | DominanceFrontier::const_iterator it = DF->find(CurPHI->getParent()); |
| 180 | if (it != DF->end()) { |
| 181 | const DominanceFrontier::DomSetType &S = it->second; |
| 182 | for (DominanceFrontier::DomSetType::const_iterator P = S.begin(), |
| 183 | PE = S.end(); P != PE; ++P) { |
Owen Anderson | 766f90b | 2006-06-04 00:55:19 +0000 | [diff] [blame] | 184 | if (DT->getNode(Instr->getParent())->dominates(DT->getNode(*P))) { |
| 185 | Instruction *&Phi = Phis[*P]; |
| 186 | if (Phi == 0) { |
| 187 | // Still doesn't have operands... |
| 188 | Phi = new PHINode(Instr->getType(), Instr->getName()+".lcssa", |
| 189 | (*P)->begin()); |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 190 | |
Owen Anderson | 766f90b | 2006-06-04 00:55:19 +0000 | [diff] [blame] | 191 | workList.push_back(cast<PHINode>(Phi)); |
| 192 | } |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | } |
Owen Anderson | d00eacc | 2006-06-03 23:22:50 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | // Fill in all Phis we've inserted that need their incoming values filled in. |
| 199 | for (std::vector<PHINode*>::iterator IVI = needIncomingValues.begin(), |
| 200 | IVE = needIncomingValues.end(); IVI != IVE; ++IVI) { |
| 201 | for (pred_iterator PI = pred_begin((*IVI)->getParent()), |
| 202 | E = pred_end((*IVI)->getParent()); PI != E; ++PI) |
| 203 | (*IVI)->addIncoming(getValueDominatingBlock(*PI, Phis), |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 204 | *PI); |
| 205 | } |
| 206 | |
| 207 | // Find all uses of the affected value, and replace them with the |
| 208 | // appropriate Phi. |
| 209 | std::vector<Instruction*> Uses; |
| 210 | for (Instruction::use_iterator UI = Instr->use_begin(), UE = Instr->use_end(); |
| 211 | UI != UE; ++UI) { |
| 212 | Instruction* use = cast<Instruction>(*UI); |
Owen Anderson | 766f90b | 2006-06-04 00:55:19 +0000 | [diff] [blame] | 213 | // Don't need to update uses within the loop body. |
Owen Anderson | 9e81c1b | 2006-06-06 04:28:30 +0000 | [diff] [blame] | 214 | if (!inLoop(use->getParent())) |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 215 | Uses.push_back(use); |
| 216 | } |
| 217 | |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 218 | for (std::vector<Instruction*>::iterator II = Uses.begin(), IE = Uses.end(); |
| 219 | II != IE; ++II) { |
Owen Anderson | cd76fa0 | 2006-06-01 06:05:47 +0000 | [diff] [blame] | 220 | if (PHINode* phi = dyn_cast<PHINode>(*II)) { |
| 221 | for (unsigned int i = 0; i < phi->getNumIncomingValues(); ++i) { |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 222 | if (phi->getIncomingValue(i) == Instr) { |
| 223 | Instruction* dominator = |
Owen Anderson | cd76fa0 | 2006-06-01 06:05:47 +0000 | [diff] [blame] | 224 | getValueDominatingBlock(phi->getIncomingBlock(i), Phis); |
Owen Anderson | cd76fa0 | 2006-06-01 06:05:47 +0000 | [diff] [blame] | 225 | phi->setIncomingValue(i, dominator); |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 226 | } |
Owen Anderson | cd76fa0 | 2006-06-01 06:05:47 +0000 | [diff] [blame] | 227 | } |
| 228 | } else { |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 229 | Value *NewVal = getValueDominatingBlock((*II)->getParent(), Phis); |
| 230 | (*II)->replaceUsesOfWith(Instr, NewVal); |
Owen Anderson | cd76fa0 | 2006-06-01 06:05:47 +0000 | [diff] [blame] | 231 | } |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 235 | /// getLoopValuesUsedOutsideLoop - Return any values defined in the loop that |
| 236 | /// are used by instructions outside of it. |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 237 | SetVector<Instruction*> LCSSA::getLoopValuesUsedOutsideLoop(Loop *L) { |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 238 | |
| 239 | // FIXME: For large loops, we may be able to avoid a lot of use-scanning |
| 240 | // by using dominance information. In particular, if a block does not |
| 241 | // dominate any of the loop exits, then none of the values defined in the |
| 242 | // block could be used outside the loop. |
| 243 | |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 244 | SetVector<Instruction*> AffectedValues; |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 245 | for (Loop::block_iterator BB = L->block_begin(), E = L->block_end(); |
| 246 | BB != E; ++BB) { |
| 247 | for (BasicBlock::iterator I = (*BB)->begin(), E = (*BB)->end(); I != E; ++I) |
| 248 | for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E; |
| 249 | ++UI) { |
| 250 | BasicBlock *UserBB = cast<Instruction>(*UI)->getParent(); |
Owen Anderson | ac601b4 | 2006-06-06 04:36:36 +0000 | [diff] [blame] | 251 | if (!inLoop(UserBB)) { |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 252 | AffectedValues.insert(I); |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 253 | break; |
| 254 | } |
Owen Anderson | 8eca891 | 2006-05-26 13:58:26 +0000 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | return AffectedValues; |
Owen Anderson | f3dd3e2 | 2006-05-26 21:11:53 +0000 | [diff] [blame] | 258 | } |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 259 | |
Owen Anderson | 5d02926 | 2006-06-08 20:02:53 +0000 | [diff] [blame] | 260 | /// getValueDominatingBlock - Return the value within the potential dominators |
| 261 | /// map that dominates the given block. |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 262 | Instruction *LCSSA::getValueDominatingBlock(BasicBlock *BB, |
Owen Anderson | eb33815 | 2006-06-04 00:02:23 +0000 | [diff] [blame] | 263 | std::map<BasicBlock*, Instruction*>& PotDoms) { |
Owen Anderson | cd76fa0 | 2006-06-01 06:05:47 +0000 | [diff] [blame] | 264 | DominatorTree::Node* bbNode = DT->getNode(BB); |
| 265 | while (bbNode != 0) { |
| 266 | std::map<BasicBlock*, Instruction*>::iterator I = |
| 267 | PotDoms.find(bbNode->getBlock()); |
| 268 | if (I != PotDoms.end()) { |
| 269 | return (*I).second; |
| 270 | } |
| 271 | bbNode = bbNode->getIDom(); |
| 272 | } |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 273 | |
Owen Anderson | cd76fa0 | 2006-06-01 06:05:47 +0000 | [diff] [blame] | 274 | assert(0 && "No dominating value found."); |
Owen Anderson | dad8c57 | 2006-05-31 20:55:06 +0000 | [diff] [blame] | 275 | |
| 276 | return 0; |
| 277 | } |