From ec54d6ab84ea314f2a8ac0fd996d8d28cbbc76db Mon Sep 17 00:00:00 2001 From: Bob Wilson Date: Fri, 2 Apr 2010 00:10:41 +0000 Subject: [PATCH] Check for terminating conditions before adding PHIs to the worklists. This is more efficient than adding them to the worklist and then ignoring them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100158 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SSAUpdater.cpp | 50 +++++++++++++++++------------ 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/lib/Transforms/Utils/SSAUpdater.cpp b/lib/Transforms/Utils/SSAUpdater.cpp index 769e798faec..292332e4f8a 100644 --- a/lib/Transforms/Utils/SSAUpdater.cpp +++ b/lib/Transforms/Utils/SSAUpdater.cpp @@ -471,22 +471,27 @@ void SSAUpdater::RecordMatchingPHI(PHINode *PHI) { SmallVector WorkList; WorkList.push_back(PHI); + // Record this PHI. + BasicBlock *BB = PHI->getParent(); + AvailableVals[BB] = PHI; + (*BBMap)[BB]->AvailableVal = PHI; + 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(PHI->getIncomingValue(i)); - if (!IncomingVal) continue; - WorkList.push_back(IncomingVal); + PHINode *IncomingPHIVal = dyn_cast(PHI->getIncomingValue(i)); + if (!IncomingPHIVal) continue; + 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 WorkList; WorkList.push_back(PHI); + // Clear the tag for this PHI. + (*BBMap)[PHI->getParent()]->PHITag = 0; + while (!WorkList.empty()) { 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. for (unsigned i = 0, e = PHI->getNumIncomingValues(); i != e; ++i) { - PHINode *IncomingVal = dyn_cast(PHI->getIncomingValue(i)); - if (!IncomingVal) continue; - WorkList.push_back(IncomingVal); + PHINode *IncomingPHIVal = dyn_cast(PHI->getIncomingValue(i)); + if (!IncomingPHIVal) continue; + 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); } } }