summaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Utils/LCSSA.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2007-04-18 22:39:00 +0000
committerEvan Cheng <evan.cheng@apple.com>2007-04-18 22:39:00 +0000
commitcc045d5df8ad029363f2d0c58db87b15748ce67f (patch)
treec79dd7c4b4dc67a5b78d148d019331fc8ab86d2a /lib/Transforms/Utils/LCSSA.cpp
parent65fc36b64afd0335a93b82e12e93f4894ebb9683 (diff)
downloadexternal_llvm-cc045d5df8ad029363f2d0c58db87b15748ce67f.zip
external_llvm-cc045d5df8ad029363f2d0c58db87b15748ce67f.tar.gz
external_llvm-cc045d5df8ad029363f2d0c58db87b15748ce67f.tar.bz2
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
Diffstat (limited to 'lib/Transforms/Utils/LCSSA.cpp')
-rw-r--r--lib/Transforms/Utils/LCSSA.cpp39
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/Transforms/Utils/LCSSA.cpp b/lib/Transforms/Utils/LCSSA.cpp
index b044a47..0c223c5 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<BasicBlock*> LoopBlocks;
virtual bool runOnFunction(Function &F);
@@ -66,14 +66,14 @@ namespace {
AU.addRequiredID(LoopSimplifyID);
AU.addPreservedID(LoopSimplifyID);
AU.addRequired<LoopInfo>();
- AU.addRequired<ETForest>();
+ AU.addRequired<DominatorTree>();
}
private:
void getLoopValuesUsedOutsideLoop(Loop *L,
SetVector<Instruction*> &AffectedValues);
- Value *GetValueForBlock(BasicBlock *BB, Instruction *OrigInst,
- std::map<BasicBlock*, Value*> &Phis);
+ Value *GetValueForBlock(DominatorTree::Node *BB, Instruction *OrigInst,
+ std::map<DominatorTree::Node*, Value*> &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<LoopInfo>();
- ET = &getAnalysis<ETForest>();
+ DT = &getAnalysis<DominatorTree>();
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<BasicBlock*, Value*> Phis;
+ std::map<DominatorTree::Node*, Value*> 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<BasicBlock*>::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<BasicBlock*, Value*> &Phis) {
+Value *LCSSA::GetValueForBlock(DominatorTree::Node *BB, Instruction *OrigInst,
+ std::map<DominatorTree::Node*, Value*> &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;
}