diff options
author | Chris Lattner <sabre@nondot.org> | 2007-08-04 20:24:50 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-08-04 20:24:50 +0000 |
commit | e7b653dabe83546c2c13e4595c3ed068eccb88bd (patch) | |
tree | 0b1d5f6fd58d7b969aeba067913b2ed6308858c4 /lib/Transforms/Utils/PromoteMemoryToRegister.cpp | |
parent | 384c7e04366b3eaa1d38d285d586bf5cf13e5fd3 (diff) |
cache computation of #preds for a BB. This speeds up
mem2reg from 2.0742->2.0522s on PR1432.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40821 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/PromoteMemoryToRegister.cpp')
-rw-r--r-- | lib/Transforms/Utils/PromoteMemoryToRegister.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index ecc317f24c..9baa197851 100644 --- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -137,6 +137,8 @@ namespace { /// non-determinstic behavior. DenseMap<BasicBlock*, unsigned> BBNumbers; + /// BBNumPreds - Lazily compute the number of predecessors a block has. + DenseMap<const BasicBlock*, unsigned> BBNumPreds; public: PromoteMem2Reg(const std::vector<AllocaInst*> &A, SmallVector<AllocaInst*, 16> &Retry, DominatorTree &dt, @@ -165,6 +167,14 @@ namespace { Allocas.pop_back(); --AllocaIdx; } + + unsigned getNumPreds(const BasicBlock *BB) { + unsigned &NP = BBNumPreds[BB]; + if (NP == 0) + NP = std::distance(pred_begin(BB), pred_end(BB))+1; + return NP-1; + } + void RewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info); @@ -209,7 +219,7 @@ namespace { // and decide whether all of the loads and stores to the alloca are within // the same basic block. for (Value::use_iterator U = AI->use_begin(), E = AI->use_end(); - U != E; ++U){ + U != E; ++U) { Instruction *User = cast<Instruction>(*U); if (StoreInst *SI = dyn_cast<StoreInst>(User)) { // Remember the basic blocks which define new values for the alloca @@ -218,7 +228,8 @@ namespace { OnlyStore = SI; } else { LoadInst *LI = cast<LoadInst>(User); - // Otherwise it must be a load instruction, keep track of variable reads + // Otherwise it must be a load instruction, keep track of variable + // reads. UsingBlocks.push_back(LI->getParent()); AllocaPointerVal = LI; } @@ -772,7 +783,7 @@ bool PromoteMem2Reg::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo, Allocas[AllocaNo]->getName() + "." + utostr(Version++), BB->begin()); PhiToAllocaMap[PN] = AllocaNo; - PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB))); + PN->reserveOperandSpace(getNumPreds(BB)); InsertedPHINodes.insert(PN); |