Change another SSAUpdater function to avoid recursion.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100131 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bob Wilson 2010-04-01 20:04:30 +00:00
parent 9bdb8f0717
commit 33f22e8c66
2 changed files with 26 additions and 20 deletions

View File

@ -110,7 +110,7 @@ private:
void FindAvailableVal(BasicBlock *BB, BBInfo *Info, unsigned Counter); void FindAvailableVal(BasicBlock *BB, BBInfo *Info, unsigned Counter);
void FindExistingPHI(BasicBlock *BB, BBInfo *Info); void FindExistingPHI(BasicBlock *BB, BBInfo *Info);
bool CheckIfPHIMatches(BasicBlock *BB, BBInfo *Info, Value *Val); bool CheckIfPHIMatches(BasicBlock *BB, BBInfo *Info, Value *Val);
void RecordMatchingPHI(BasicBlock *BB, BBInfo *Info, PHINode *PHI); void RecordMatchingPHI(PHINode *PHI);
void ClearPHITags(PHINode *PHI); void ClearPHITags(PHINode *PHI);
void operator=(const SSAUpdater&); // DO NOT IMPLEMENT void operator=(const SSAUpdater&); // DO NOT IMPLEMENT

View File

@ -406,7 +406,7 @@ void SSAUpdater::FindExistingPHI(BasicBlock *BB, BBInfo *Info) {
for (BasicBlock::iterator It = BB->begin(); for (BasicBlock::iterator It = BB->begin();
(SomePHI = dyn_cast<PHINode>(It)); ++It) { (SomePHI = dyn_cast<PHINode>(It)); ++It) {
if (CheckIfPHIMatches(BB, Info, SomePHI)) { if (CheckIfPHIMatches(BB, Info, SomePHI)) {
RecordMatchingPHI(BB, Info, SomePHI); RecordMatchingPHI(SomePHI);
break; break;
} }
ClearPHITags(SomePHI); ClearPHITags(SomePHI);
@ -449,25 +449,31 @@ bool SSAUpdater::CheckIfPHIMatches(BasicBlock *BB, BBInfo *Info, Value *Val) {
return IsMatch; return IsMatch;
} }
/// RecordMatchingPHI - For a PHI node that matches, record it in both the /// RecordMatchingPHI - For a PHI node that matches, record it and its input
/// BBMap and the AvailableVals mapping. Recursively record its input PHIs /// PHIs in both the BBMap and the AvailableVals mapping.
/// as well. void SSAUpdater::RecordMatchingPHI(PHINode *PHI) {
void SSAUpdater::RecordMatchingPHI(BasicBlock *BB, BBInfo *Info, PHINode *PHI) {
if (!Info || Info->AvailableVal)
return;
// Record the PHI.
AvailableValsTy &AvailableVals = getAvailableVals(AV);
AvailableVals[BB] = PHI;
Info->AvailableVal = PHI;
// Iterate through the predecessors.
BBMapTy *BBMap = getBBMap(BM); BBMapTy *BBMap = getBBMap(BM);
for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) { AvailableValsTy &AvailableVals = getAvailableVals(AV);
PHINode *PHIVal = dyn_cast<PHINode>(PHI->getIncomingValue(i)); SmallVector<PHINode*, 20> WorkList;
if (!PHIVal) continue; WorkList.push_back(PHI);
BasicBlock *Pred = PHIVal->getParent();
RecordMatchingPHI(Pred, (*BBMap)[Pred], PHIVal); while (!WorkList.empty()) {
PHI = WorkList.pop_back_val();
BasicBlock *BB = PHI->getParent();
BBInfo *Info = (*BBMap)[BB];
if (!Info || Info->AvailableVal)
return;
// Record the PHI.
AvailableVals[BB] = PHI;
Info->AvailableVal = PHI;
// Iterate through the PHI's incoming values.
for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) {
PHINode *IncomingVal = dyn_cast<PHINode>(PHI->getIncomingValue(i));
if (!IncomingVal) continue;
WorkList.push_back(IncomingVal);
}
} }
} }