diff options
author | Michael Zolotukhin <mzolotukhin@apple.com> | 2018-04-20 13:34:32 +0000 |
---|---|---|
committer | Michael Zolotukhin <mzolotukhin@apple.com> | 2018-04-20 13:34:32 +0000 |
commit | a2c9af02097b085baab54291a18d23f2201e050e (patch) | |
tree | 04a0bb83deef1841b749dce06ec747dc89591795 /llvm/lib/Transforms/Utils | |
parent | 06039e8fc1cb641d2dbed00b30d00751310c5272 (diff) | |
download | bcm5719-llvm-a2c9af02097b085baab54291a18d23f2201e050e.tar.gz bcm5719-llvm-a2c9af02097b085baab54291a18d23f2201e050e.zip |
Revert "Revert r330403 and r330413."
Reapply the patches with a fix. Thanks Ilya and Hans for the reproducer!
This reverts commit r330416.
The issue was that removing predecessors invalidated uses that we stored
for rewrite. The fix is to finish manipulating with CFG before we select
uses for rewrite.
llvm-svn: 330431
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r-- | llvm/lib/Transforms/Utils/SSAUpdaterBulk.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Utils/SSAUpdaterBulk.cpp b/llvm/lib/Transforms/Utils/SSAUpdaterBulk.cpp index dbc671cc16f..61ceb9c9277 100644 --- a/llvm/lib/Transforms/Utils/SSAUpdaterBulk.cpp +++ b/llvm/lib/Transforms/Utils/SSAUpdaterBulk.cpp @@ -38,18 +38,19 @@ static BasicBlock *getUserBB(Use *U) { /// Add a new variable to the SSA rewriter. This needs to be called before /// AddAvailableValue or AddUse calls. -void SSAUpdaterBulk::AddVariable(unsigned Var, StringRef Name, Type *Ty) { - assert(Rewrites.find(Var) == Rewrites.end() && "Variable added twice!"); +unsigned SSAUpdaterBulk::AddVariable(StringRef Name, Type *Ty) { + unsigned Var = Rewrites.size(); DEBUG(dbgs() << "SSAUpdater: Var=" << Var << ": initialized with Ty = " << *Ty << ", Name = " << Name << "\n"); RewriteInfo RI(Name, Ty); - Rewrites[Var] = RI; + Rewrites.push_back(RI); + return Var; } /// 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(Rewrites.find(Var) != Rewrites.end() && "Should add variable first!"); + assert(Var < Rewrites.size() && "Variable not found!"); DEBUG(dbgs() << "SSAUpdater: Var=" << Var << ": added new available value" << *V << " in " << BB->getName() << "\n"); Rewrites[Var].Defines[BB] = V; @@ -58,7 +59,7 @@ void SSAUpdaterBulk::AddAvailableValue(unsigned Var, BasicBlock *BB, Value *V) { /// 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(Rewrites.find(Var) != Rewrites.end() && "Should add variable first!"); + assert(Var < Rewrites.size() && "Variable not found!"); DEBUG(dbgs() << "SSAUpdater: Var=" << Var << ": added a use" << *U->get() << " in " << getUserBB(U)->getName() << "\n"); Rewrites[Var].Uses.push_back(U); @@ -67,7 +68,7 @@ void SSAUpdaterBulk::AddUse(unsigned Var, Use *U) { /// 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 Rewrites.count(Var) ? Rewrites[Var].Defines.count(BB) : false; + return (Var < Rewrites.size()) ? Rewrites[Var].Defines.count(BB) : false; } // Compute value at the given block BB. We either should already know it, or we @@ -126,16 +127,14 @@ ComputeLiveInBlocks(const SmallPtrSetImpl<BasicBlock *> &UsingBlocks, /// requested uses update. void SSAUpdaterBulk::RewriteAllUses(DominatorTree *DT, SmallVectorImpl<PHINode *> *InsertedPHIs) { - for (auto &P : Rewrites) { + for (auto &R : 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); - RewriteInfo &R = P.second; - DEBUG(dbgs() << "SSAUpdater: Var=" << P.first << ": rewriting " - << R.Uses.size() << " use(s)\n"); + DEBUG(dbgs() << "SSAUpdater: rewriting " << R.Uses.size() << " use(s)\n"); SmallPtrSet<BasicBlock *, 2> DefBlocks; for (auto &Def : R.Defines) @@ -165,7 +164,7 @@ void SSAUpdaterBulk::RewriteAllUses(DominatorTree *DT, } // 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); @@ -182,8 +181,8 @@ void SSAUpdaterBulk::RewriteAllUses(DominatorTree *DT, // Notify that users of the existing value that it is being replaced. if (OldVal != V && OldVal->hasValueHandle()) ValueHandleBase::ValueIsRAUWd(OldVal, V); - DEBUG(dbgs() << "SSAUpdater: Var=" << P.first << ": replacing" << *OldVal - << " with " << *V << "\n"); + DEBUG(dbgs() << "SSAUpdater: replacing " << *OldVal << " with " << *V + << "\n"); U->set(V); } } |