diff options
author | Gabor Greif <ggreif@gmail.com> | 2009-01-23 19:40:15 +0000 |
---|---|---|
committer | Gabor Greif <ggreif@gmail.com> | 2009-01-23 19:40:15 +0000 |
commit | a36791da41cf4f635e50077b290676b873836bda (patch) | |
tree | 93f751d2adbba6056d4f2e16b04288a5864f238d | |
parent | 60789e419e04c260e36af9a1add5ad316313e490 (diff) | |
download | external_llvm-a36791da41cf4f635e50077b290676b873836bda.zip external_llvm-a36791da41cf4f635e50077b290676b873836bda.tar.gz external_llvm-a36791da41cf4f635e50077b290676b873836bda.tar.bz2 |
Simplify the logic of getting hold of a PHI predecessor block.
There is now a direct way from value-use-iterator to incoming block in PHINode's API.
This way we avoid the iterator->index->iterator trip, and especially the costly
getOperandNo() invocation. Additionally there is now an assertion that the iterator
really refers to one of the PHI's Uses.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62869 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Analysis/LoopInfo.h | 3 | ||||
-rw-r--r-- | include/llvm/Instructions.h | 8 | ||||
-rw-r--r-- | lib/Transforms/IPO/GlobalOpt.cpp | 3 | ||||
-rw-r--r-- | lib/Transforms/Scalar/CodeGenPrepare.cpp | 3 | ||||
-rw-r--r-- | lib/Transforms/Utils/LCSSA.cpp | 6 | ||||
-rw-r--r-- | lib/VMCore/Instruction.cpp | 3 |
6 files changed, 14 insertions, 12 deletions
diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index 7aa325a..a1bac66 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -482,8 +482,7 @@ public: ++UI) { BlockT *UserBB = cast<Instruction>(*UI)->getParent(); if (PHINode *P = dyn_cast<PHINode>(*UI)) { - unsigned OperandNo = UI.getOperandNo(); - UserBB = P->getIncomingBlock(OperandNo/2); + UserBB = P->getIncomingBlock(UI); } // Check the current block, as a fast-path. Most values are used in diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 841cf9c..fbf376a 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -1943,6 +1943,14 @@ public: return i*2; } + /// getIncomingBlock - Return incoming basic block corresponding + /// to value use iterator + /// + template <typename U> + BasicBlock *getIncomingBlock(value_use_iterator<U> I) const { + assert(this == *I && "Iterator doesn't point to PHI's Uses?"); + return static_cast<BasicBlock*>((&I.getUse() + 1)->get()); + } /// getIncomingBlock - Return incoming basic block number x /// BasicBlock *getIncomingBlock(unsigned i) const { diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 99fc731..7f636c9 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -988,8 +988,7 @@ static void ReplaceUsesOfMallocWithGlobal(Instruction *Alloc, } else if (PHINode *PN = dyn_cast<PHINode>(U)) { // Insert the load in the corresponding predecessor, not right before the // PHI. - unsigned PredNo = Alloc->use_begin().getOperandNo()/2; - InsertPt = PN->getIncomingBlock(PredNo)->getTerminator(); + InsertPt = PN->getIncomingBlock(Alloc->use_begin())->getTerminator(); } else if (isa<BitCastInst>(U)) { // Must be bitcast between the malloc and store to initialize the global. ReplaceUsesOfMallocWithGlobal(U, GV); diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp index 59c6586..0a1c641 100644 --- a/lib/Transforms/Scalar/CodeGenPrepare.cpp +++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp @@ -459,8 +459,7 @@ static bool OptimizeNoopCopyExpression(CastInst *CI, const TargetLowering &TLI){ // appropriate predecessor block. BasicBlock *UserBB = User->getParent(); if (PHINode *PN = dyn_cast<PHINode>(User)) { - unsigned OpVal = UI.getOperandNo()/2; - UserBB = PN->getIncomingBlock(OpVal); + UserBB = PN->getIncomingBlock(UI); } // Preincrement use iterator so we don't invalidate it. diff --git a/lib/Transforms/Utils/LCSSA.cpp b/lib/Transforms/Utils/LCSSA.cpp index 3855888..9cd7e69 100644 --- a/lib/Transforms/Utils/LCSSA.cpp +++ b/lib/Transforms/Utils/LCSSA.cpp @@ -175,8 +175,7 @@ void LCSSA::ProcessInstruction(Instruction *Instr, UI != E;) { BasicBlock *UserBB = cast<Instruction>(*UI)->getParent(); if (PHINode *P = dyn_cast<PHINode>(*UI)) { - unsigned OperandNo = UI.getOperandNo(); - UserBB = P->getIncomingBlock(OperandNo/2); + UserBB = P->getIncomingBlock(UI); } // If the user is in the loop, don't rewrite it! @@ -212,8 +211,7 @@ void LCSSA::getLoopValuesUsedOutsideLoop(Loop *L, ++UI) { BasicBlock *UserBB = cast<Instruction>(*UI)->getParent(); if (PHINode* p = dyn_cast<PHINode>(*UI)) { - unsigned OperandNo = UI.getOperandNo(); - UserBB = p->getIncomingBlock(OperandNo/2); + UserBB = p->getIncomingBlock(UI); } if (*BB != UserBB && !inLoop(UserBB)) { diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index b09ab93..f33c1a2 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -278,8 +278,7 @@ bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const { continue; } - unsigned UseOperand = UI.getOperandNo(); - if (PN->getIncomingBlock(UseOperand/2) != BB) + if (PN->getIncomingBlock(UI) != BB) return true; } return false; |