From cc045d5df8ad029363f2d0c58db87b15748ce67f Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Wed, 18 Apr 2007 22:39:00 +0000 Subject: [PATCH] Revert Owen's last check-in. This is breaking Mac OS X / PPC llvm-gcc bootstrap. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36258 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/LCSSA.cpp | 39 ++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/lib/Transforms/Utils/LCSSA.cpp b/lib/Transforms/Utils/LCSSA.cpp index b044a478d87..0c223c53024 100644 --- a/lib/Transforms/Utils/LCSSA.cpp +++ b/lib/Transforms/Utils/LCSSA.cpp @@ -49,7 +49,7 @@ namespace { struct VISIBILITY_HIDDEN LCSSA : public FunctionPass { // Cached analysis information for the current function. LoopInfo *LI; - ETForest *ET; + DominatorTree *DT; std::vector LoopBlocks; virtual bool runOnFunction(Function &F); @@ -66,14 +66,14 @@ namespace { AU.addRequiredID(LoopSimplifyID); AU.addPreservedID(LoopSimplifyID); AU.addRequired(); - AU.addRequired(); + AU.addRequired(); } private: void getLoopValuesUsedOutsideLoop(Loop *L, SetVector &AffectedValues); - Value *GetValueForBlock(BasicBlock *BB, Instruction *OrigInst, - std::map &Phis); + Value *GetValueForBlock(DominatorTree::Node *BB, Instruction *OrigInst, + std::map &Phis); /// inLoop - returns true if the given block is within the current loop const bool inLoop(BasicBlock* B) { @@ -92,7 +92,7 @@ bool LCSSA::runOnFunction(Function &F) { bool changed = false; LI = &getAnalysis(); - ET = &getAnalysis(); + DT = &getAnalysis(); for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) changed |= visitSubloop(*I); @@ -142,17 +142,18 @@ void LCSSA::ProcessInstruction(Instruction *Instr, ++NumLCSSA; // We are applying the transformation // Keep track of the blocks that have the value available already. - std::map Phis; + std::map Phis; - //ETNode *InstrNode = ET->getNodeForBlock(Instr->getParent()); + DominatorTree::Node *InstrNode = DT->getNode(Instr->getParent()); // Insert the LCSSA phi's into the exit blocks (dominated by the value), and // add them to the Phi's map. for (std::vector::const_iterator BBI = exitBlocks.begin(), BBE = exitBlocks.end(); BBI != BBE; ++BBI) { BasicBlock *BB = *BBI; - Value *&Phi = Phis[BB]; - if (!Phi && ET->dominates(Instr->getParent(), BB)) { + DominatorTree::Node *ExitBBNode = DT->getNode(BB); + Value *&Phi = Phis[ExitBBNode]; + if (!Phi && InstrNode->dominates(ExitBBNode)) { PHINode *PN = new PHINode(Instr->getType(), Instr->getName()+".lcssa", BB->begin()); PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB))); @@ -185,7 +186,7 @@ void LCSSA::ProcessInstruction(Instruction *Instr, // Otherwise, patch up uses of the value with the appropriate LCSSA Phi, // inserting PHI nodes into join points where needed. - Value *Val = GetValueForBlock(UserBB, Instr, Phis); + Value *Val = GetValueForBlock(DT->getNode(UserBB), Instr, Phis); // Preincrement the iterator to avoid invalidating it when we change the // value. @@ -224,8 +225,8 @@ void LCSSA::getLoopValuesUsedOutsideLoop(Loop *L, /// GetValueForBlock - Get the value to use within the specified basic block. /// available values are in Phis. -Value *LCSSA::GetValueForBlock(BasicBlock *BB, Instruction *OrigInst, - std::map &Phis) { +Value *LCSSA::GetValueForBlock(DominatorTree::Node *BB, Instruction *OrigInst, + std::map &Phis) { // If there is no dominator info for this BB, it is unreachable. if (BB == 0) return UndefValue::get(OrigInst->getType()); @@ -234,7 +235,7 @@ Value *LCSSA::GetValueForBlock(BasicBlock *BB, Instruction *OrigInst, Value *&V = Phis[BB]; if (V) return V; - BasicBlock* IDom = ET->getIDom(BB); + DominatorTree::Node *IDom = BB->getIDom(); // Otherwise, there are two cases: we either have to insert a PHI node or we // don't. We need to insert a PHI node if this block is not dominated by one @@ -247,22 +248,24 @@ Value *LCSSA::GetValueForBlock(BasicBlock *BB, Instruction *OrigInst, // dominate this block. Note that we *know* that the block defining the // original instruction is in the idom chain, because if it weren't, then the // original value didn't dominate this use. - if (!inLoop(IDom)) { + if (!inLoop(IDom->getBlock())) { // Idom is not in the loop, we must still be "below" the exit block and must // be fully dominated by the value live in the idom. return V = GetValueForBlock(IDom, OrigInst, Phis); } + BasicBlock *BBN = BB->getBlock(); + // Otherwise, the idom is the loop, so we need to insert a PHI node. Do so // now, then get values to fill in the incoming values for the PHI. PHINode *PN = new PHINode(OrigInst->getType(), OrigInst->getName()+".lcssa", - BB->begin()); - PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB))); + BBN->begin()); + PN->reserveOperandSpace(std::distance(pred_begin(BBN), pred_end(BBN))); V = PN; // Fill in the incoming values for the block. - for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) - PN->addIncoming(GetValueForBlock(*PI, OrigInst, Phis), *PI); + for (pred_iterator PI = pred_begin(BBN), E = pred_end(BBN); PI != E; ++PI) + PN->addIncoming(GetValueForBlock(DT->getNode(*PI), OrigInst, Phis), *PI); return PN; }