mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 19:12:56 +02:00
Record PRE predecessors with a SmallVector instead of a DenseMap, and
avoid a second pred_iterator traversal. llvm-svn: 175001
This commit is contained in:
parent
3eb029b4c7
commit
a04e614c0f
@ -2389,7 +2389,7 @@ bool GVN::processBlock(BasicBlock *BB) {
|
|||||||
/// control flow patterns and attempts to perform simple PRE at the join point.
|
/// control flow patterns and attempts to perform simple PRE at the join point.
|
||||||
bool GVN::performPRE(Function &F) {
|
bool GVN::performPRE(Function &F) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
DenseMap<BasicBlock*, Value*> predMap;
|
SmallVector<std::pair<Value*, BasicBlock*>, 8> predMap;
|
||||||
for (df_iterator<BasicBlock*> DI = df_begin(&F.getEntryBlock()),
|
for (df_iterator<BasicBlock*> DI = df_begin(&F.getEntryBlock()),
|
||||||
DE = df_end(&F.getEntryBlock()); DI != DE; ++DI) {
|
DE = df_end(&F.getEntryBlock()); DI != DE; ++DI) {
|
||||||
BasicBlock *CurrentBlock = *DI;
|
BasicBlock *CurrentBlock = *DI;
|
||||||
@ -2452,6 +2452,7 @@ bool GVN::performPRE(Function &F) {
|
|||||||
|
|
||||||
Value* predV = findLeader(P, ValNo);
|
Value* predV = findLeader(P, ValNo);
|
||||||
if (predV == 0) {
|
if (predV == 0) {
|
||||||
|
predMap.push_back(std::make_pair(static_cast<Value *>(0), P));
|
||||||
PREPred = P;
|
PREPred = P;
|
||||||
++NumWithout;
|
++NumWithout;
|
||||||
} else if (predV == CurInst) {
|
} else if (predV == CurInst) {
|
||||||
@ -2459,7 +2460,7 @@ bool GVN::performPRE(Function &F) {
|
|||||||
NumWithout = 2;
|
NumWithout = 2;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
predMap[P] = predV;
|
predMap.push_back(std::make_pair(predV, P));
|
||||||
++NumWith;
|
++NumWith;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2514,7 +2515,6 @@ bool GVN::performPRE(Function &F) {
|
|||||||
PREInstr->insertBefore(PREPred->getTerminator());
|
PREInstr->insertBefore(PREPred->getTerminator());
|
||||||
PREInstr->setName(CurInst->getName() + ".pre");
|
PREInstr->setName(CurInst->getName() + ".pre");
|
||||||
PREInstr->setDebugLoc(CurInst->getDebugLoc());
|
PREInstr->setDebugLoc(CurInst->getDebugLoc());
|
||||||
predMap[PREPred] = PREInstr;
|
|
||||||
VN.add(PREInstr, ValNo);
|
VN.add(PREInstr, ValNo);
|
||||||
++NumGVNPRE;
|
++NumGVNPRE;
|
||||||
|
|
||||||
@ -2522,13 +2522,14 @@ bool GVN::performPRE(Function &F) {
|
|||||||
addToLeaderTable(ValNo, PREInstr, PREPred);
|
addToLeaderTable(ValNo, PREInstr, PREPred);
|
||||||
|
|
||||||
// Create a PHI to make the value available in this block.
|
// Create a PHI to make the value available in this block.
|
||||||
pred_iterator PB = pred_begin(CurrentBlock), PE = pred_end(CurrentBlock);
|
PHINode* Phi = PHINode::Create(CurInst->getType(), predMap.size(),
|
||||||
PHINode* Phi = PHINode::Create(CurInst->getType(), std::distance(PB, PE),
|
|
||||||
CurInst->getName() + ".pre-phi",
|
CurInst->getName() + ".pre-phi",
|
||||||
CurrentBlock->begin());
|
CurrentBlock->begin());
|
||||||
for (pred_iterator PI = PB; PI != PE; ++PI) {
|
for (unsigned i = 0, e = predMap.size(); i != e; ++i) {
|
||||||
BasicBlock *P = *PI;
|
if (Value *V = predMap[i].first)
|
||||||
Phi->addIncoming(predMap[P], P);
|
Phi->addIncoming(V, predMap[i].second);
|
||||||
|
else
|
||||||
|
Phi->addIncoming(PREInstr, PREPred);
|
||||||
}
|
}
|
||||||
|
|
||||||
VN.add(Phi, ValNo);
|
VN.add(Phi, ValNo);
|
||||||
|
Loading…
Reference in New Issue
Block a user