forked from OSchip/llvm-project
cache computation of #preds for a BB. This speeds up
mem2reg from 2.0742->2.0522s on PR1432. llvm-svn: 40821
This commit is contained in:
parent
050bac4bed
commit
840259c8d3
|
@ -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,
|
||||
|
@ -166,6 +168,14 @@ namespace {
|
|||
--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);
|
||||
|
||||
void MarkDominatingPHILive(BasicBlock *BB, unsigned AllocaNum,
|
||||
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue