Revert r330403 and r330413.
Revert r330413: "[SSAUpdaterBulk] Use SmallVector instead of DenseMap for storing rewrites."
Revert r330403 "Reapply "[PR16756] Use SSAUpdaterBulk in JumpThreading." one more time."
r330403 commit seems to crash clang during our integrate while doing PGO build with the following stacktrace:
#2 llvm::SSAUpdaterBulk::RewriteAllUses(llvm::DominatorTree*, llvm::SmallVectorImpl<llvm::PHINode*>*)
#3 llvm::JumpThreadingPass::ThreadEdge(llvm::BasicBlock*, llvm::SmallVectorImpl<llvm::BasicBlock*> const&, llvm::BasicBlock*)
#4 llvm::JumpThreadingPass::ProcessThreadableEdges(llvm::Value*, llvm::BasicBlock*, llvm::jumpthreading::ConstantPreference, llvm::Instruction*)
#5 llvm::JumpThreadingPass::ProcessBlock(llvm::BasicBlock*)
The crash happens while compiling 'lib/Analysis/CallGraph.cpp'.
r3340413 is reverted due to conflicting changes.
llvm-svn: 330416
diff --git a/llvm/lib/Transforms/Utils/SSAUpdaterBulk.cpp b/llvm/lib/Transforms/Utils/SSAUpdaterBulk.cpp
index 61ceb9c..dbc671c 100644
--- a/llvm/lib/Transforms/Utils/SSAUpdaterBulk.cpp
+++ b/llvm/lib/Transforms/Utils/SSAUpdaterBulk.cpp
@@ -38,19 +38,18 @@
/// Add a new variable to the SSA rewriter. This needs to be called before
/// AddAvailableValue or AddUse calls.
-unsigned SSAUpdaterBulk::AddVariable(StringRef Name, Type *Ty) {
- unsigned Var = Rewrites.size();
+void SSAUpdaterBulk::AddVariable(unsigned Var, StringRef Name, Type *Ty) {
+ assert(Rewrites.find(Var) == Rewrites.end() && "Variable added twice!");
DEBUG(dbgs() << "SSAUpdater: Var=" << Var << ": initialized with Ty = " << *Ty
<< ", Name = " << Name << "\n");
RewriteInfo RI(Name, Ty);
- Rewrites.push_back(RI);
- return Var;
+ Rewrites[Var] = RI;
}
/// Indicate that a rewritten value is available in the specified block with the
/// specified value.
void SSAUpdaterBulk::AddAvailableValue(unsigned Var, BasicBlock *BB, Value *V) {
- assert(Var < Rewrites.size() && "Variable not found!");
+ assert(Rewrites.find(Var) != Rewrites.end() && "Should add variable first!");
DEBUG(dbgs() << "SSAUpdater: Var=" << Var << ": added new available value"
<< *V << " in " << BB->getName() << "\n");
Rewrites[Var].Defines[BB] = V;
@@ -59,7 +58,7 @@
/// Record a use of the symbolic value. This use will be updated with a
/// rewritten value when RewriteAllUses is called.
void SSAUpdaterBulk::AddUse(unsigned Var, Use *U) {
- assert(Var < Rewrites.size() && "Variable not found!");
+ assert(Rewrites.find(Var) != Rewrites.end() && "Should add variable first!");
DEBUG(dbgs() << "SSAUpdater: Var=" << Var << ": added a use" << *U->get()
<< " in " << getUserBB(U)->getName() << "\n");
Rewrites[Var].Uses.push_back(U);
@@ -68,7 +67,7 @@
/// Return true if the SSAUpdater already has a value for the specified variable
/// in the specified block.
bool SSAUpdaterBulk::HasValueForBlock(unsigned Var, BasicBlock *BB) {
- return (Var < Rewrites.size()) ? Rewrites[Var].Defines.count(BB) : false;
+ return Rewrites.count(Var) ? Rewrites[Var].Defines.count(BB) : false;
}
// Compute value at the given block BB. We either should already know it, or we
@@ -127,14 +126,16 @@
/// requested uses update.
void SSAUpdaterBulk::RewriteAllUses(DominatorTree *DT,
SmallVectorImpl<PHINode *> *InsertedPHIs) {
- for (auto &R : Rewrites) {
+ for (auto &P : Rewrites) {
// Compute locations for new phi-nodes.
// For that we need to initialize DefBlocks from definitions in R.Defines,
// UsingBlocks from uses in R.Uses, then compute LiveInBlocks, and then use
// this set for computing iterated dominance frontier (IDF).
// The IDF blocks are the blocks where we need to insert new phi-nodes.
ForwardIDFCalculator IDF(*DT);
- DEBUG(dbgs() << "SSAUpdater: rewriting " << R.Uses.size() << " use(s)\n");
+ RewriteInfo &R = P.second;
+ DEBUG(dbgs() << "SSAUpdater: Var=" << P.first << ": rewriting "
+ << R.Uses.size() << " use(s)\n");
SmallPtrSet<BasicBlock *, 2> DefBlocks;
for (auto &Def : R.Defines)
@@ -164,7 +165,7 @@
}
// Fill in arguments of the inserted PHIs.
- for (auto *PN : InsertedPHIsForVar) {
+ for (auto PN : InsertedPHIsForVar) {
BasicBlock *PBB = PN->getParent();
for (BasicBlock *Pred : PredCache.get(PBB))
PN->addIncoming(computeValueAt(Pred, R, DT), Pred);
@@ -181,8 +182,8 @@
// Notify that users of the existing value that it is being replaced.
if (OldVal != V && OldVal->hasValueHandle())
ValueHandleBase::ValueIsRAUWd(OldVal, V);
- DEBUG(dbgs() << "SSAUpdater: replacing " << *OldVal << " with " << *V
- << "\n");
+ DEBUG(dbgs() << "SSAUpdater: Var=" << P.first << ": replacing" << *OldVal
+ << " with " << *V << "\n");
U->set(V);
}
}