diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -20,6 +20,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/SetVector.h" #include "llvm/ADT/MapVector.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/STLExtras.h" @@ -219,6 +220,7 @@ // The BasicBlock work list SmallVector BBWorkList; + /// KnownFeasibleEdges - Entries in this set are edges which have already had /// PHI nodes retriggered. using Edge = std::pair; @@ -228,6 +230,7 @@ DenseMap> AdditionalUsers; public: + SetVector PossiblyUndefined; void addAnalysis(Function &F, AnalysisResultsForFn A) { AnalysisResults.insert({&F, std::move(A)}); } @@ -258,6 +261,7 @@ return false; LLVM_DEBUG(dbgs() << "Marking Block Executable: " << BB->getName() << '\n'); BBWorkList.push_back(BB); // Add the block to the work list! + PossiblyUndefined.insert(BB->getParent()); return true; } @@ -1862,13 +1866,16 @@ while (ResolvedUndefs) { LLVM_DEBUG(dbgs() << "RESOLVING UNDEFS\n"); ResolvedUndefs = false; - for (Function &F : M) + while (!Solver.PossiblyUndefined.empty()) { + Function &F = *Solver.PossiblyUndefined.back(); if (Solver.ResolvedUndefsIn(F)) { // We run Solve() after we resolved an undef in a function, because // we might deduce a fact that eliminates an undef in another function. Solver.Solve(); ResolvedUndefs = true; - } + } else + Solver.PossiblyUndefined.pop_back(); + } } bool MadeChanges = false;