forked from OSchip/llvm-project
Check for terminating conditions before adding PHIs to the worklists.
This is more efficient than adding them to the worklist and then ignoring them. llvm-svn: 100158
This commit is contained in:
parent
d3020a4b90
commit
9af4e118c6
|
@ -471,22 +471,27 @@ void SSAUpdater::RecordMatchingPHI(PHINode *PHI) {
|
||||||
SmallVector<PHINode*, 20> WorkList;
|
SmallVector<PHINode*, 20> WorkList;
|
||||||
WorkList.push_back(PHI);
|
WorkList.push_back(PHI);
|
||||||
|
|
||||||
|
// Record this PHI.
|
||||||
|
BasicBlock *BB = PHI->getParent();
|
||||||
|
AvailableVals[BB] = PHI;
|
||||||
|
(*BBMap)[BB]->AvailableVal = PHI;
|
||||||
|
|
||||||
while (!WorkList.empty()) {
|
while (!WorkList.empty()) {
|
||||||
PHI = WorkList.pop_back_val();
|
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.
|
// Iterate through the PHI's incoming values.
|
||||||
for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) {
|
for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) {
|
||||||
PHINode *IncomingVal = dyn_cast<PHINode>(PHI->getIncomingValue(i));
|
PHINode *IncomingPHIVal = dyn_cast<PHINode>(PHI->getIncomingValue(i));
|
||||||
if (!IncomingVal) continue;
|
if (!IncomingPHIVal) continue;
|
||||||
WorkList.push_back(IncomingVal);
|
BB = IncomingPHIVal->getParent();
|
||||||
|
BBInfo *Info = (*BBMap)[BB];
|
||||||
|
if (!Info || Info->AvailableVal)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Record the PHI and add it to the worklist.
|
||||||
|
AvailableVals[BB] = IncomingPHIVal;
|
||||||
|
Info->AvailableVal = IncomingPHIVal;
|
||||||
|
WorkList.push_back(IncomingPHIVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -499,21 +504,24 @@ void SSAUpdater::ClearPHITags(PHINode *PHI) {
|
||||||
SmallVector<PHINode*, 20> WorkList;
|
SmallVector<PHINode*, 20> WorkList;
|
||||||
WorkList.push_back(PHI);
|
WorkList.push_back(PHI);
|
||||||
|
|
||||||
|
// Clear the tag for this PHI.
|
||||||
|
(*BBMap)[PHI->getParent()]->PHITag = 0;
|
||||||
|
|
||||||
while (!WorkList.empty()) {
|
while (!WorkList.empty()) {
|
||||||
PHI = WorkList.pop_back_val();
|
PHI = WorkList.pop_back_val();
|
||||||
BasicBlock *BB = PHI->getParent();
|
|
||||||
BBInfo *Info = (*BBMap)[BB];
|
|
||||||
if (!Info || Info->AvailableVal || !Info->PHITag)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Clear the tag.
|
|
||||||
Info->PHITag = 0;
|
|
||||||
|
|
||||||
// Iterate through the PHI's incoming values.
|
// Iterate through the PHI's incoming values.
|
||||||
for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) {
|
for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) {
|
||||||
PHINode *IncomingVal = dyn_cast<PHINode>(PHI->getIncomingValue(i));
|
PHINode *IncomingPHIVal = dyn_cast<PHINode>(PHI->getIncomingValue(i));
|
||||||
if (!IncomingVal) continue;
|
if (!IncomingPHIVal) continue;
|
||||||
WorkList.push_back(IncomingVal);
|
BasicBlock *BB = IncomingPHIVal->getParent();
|
||||||
|
BBInfo *Info = (*BBMap)[BB];
|
||||||
|
if (!Info || Info->AvailableVal || !Info->PHITag)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Clear the tag and add the PHI to the worklist.
|
||||||
|
Info->PHITag = 0;
|
||||||
|
WorkList.push_back(IncomingPHIVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue