diff options
author | Michael Zolotukhin <mzolotukhin@apple.com> | 2018-04-20 08:01:08 +0000 |
---|---|---|
committer | Michael Zolotukhin <mzolotukhin@apple.com> | 2018-04-20 08:01:08 +0000 |
commit | 79e4f7fadb5f6588f5933b80fccfdb1fb8db5532 (patch) | |
tree | 3c4befff54e03d34f8745cab8334518299edeff3 /llvm/lib/Transforms | |
parent | 26339b445ab3edc063a0985c7f536452e5f7363d (diff) | |
download | bcm5719-llvm-79e4f7fadb5f6588f5933b80fccfdb1fb8db5532.tar.gz bcm5719-llvm-79e4f7fadb5f6588f5933b80fccfdb1fb8db5532.zip |
Reapply "[PR16756] Use SSAUpdaterBulk in JumpThreading." one more time.
Hopefully, changing set to vector removes nondeterminism detected by
some bots, or the new assert will catch something.
This reverts commit r330180.
llvm-svn: 330403
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 29c707799bd..59e653b338d 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -66,6 +66,7 @@ #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/SSAUpdater.h" +#include "llvm/Transforms/Utils/SSAUpdaterBulk.h" #include "llvm/Transforms/Utils/ValueMapper.h" #include <algorithm> #include <cassert> @@ -1989,15 +1990,20 @@ bool JumpThreadingPass::ThreadEdge(BasicBlock *BB, // now have to update all uses of the value to use either the original value, // the cloned value, or some PHI derived value. This can require arbitrary // PHI insertion, of which we are prepared to do, clean these up now. - SSAUpdater SSAUpdate; - SmallVector<Use*, 16> UsesToRename; + SSAUpdaterBulk SSAUpdate; + + unsigned VarNum = 0; for (Instruction &I : *BB) { + SmallVector<Use*, 16> UsesToRename; + // Scan all uses of this instruction to see if it is used outside of its - // block, and if so, record them in UsesToRename. + // block, and if so, record them in UsesToRename. Also, skip phi operands + // from PredBB - we'll remove them anyway. for (Use &U : I.uses()) { Instruction *User = cast<Instruction>(U.getUser()); if (PHINode *UserPN = dyn_cast<PHINode>(User)) { - if (UserPN->getIncomingBlock(U) == BB) + if (UserPN->getIncomingBlock(U) == BB || + UserPN->getIncomingBlock(U) == PredBB) continue; } else if (User->getParent() == BB) continue; @@ -2008,19 +2014,15 @@ bool JumpThreadingPass::ThreadEdge(BasicBlock *BB, // If there are no uses outside the block, we're done with this instruction. if (UsesToRename.empty()) continue; + SSAUpdate.AddVariable(VarNum, I.getName(), I.getType()); - DEBUG(dbgs() << "JT: Renaming non-local uses of: " << I << "\n"); - - // We found a use of I outside of BB. Rename all uses of I that are outside - // its block to be uses of the appropriate PHI node etc. See ValuesInBlocks - // with the two values we know. - SSAUpdate.Initialize(I.getType(), I.getName()); - SSAUpdate.AddAvailableValue(BB, &I); - SSAUpdate.AddAvailableValue(NewBB, ValueMapping[&I]); - - while (!UsesToRename.empty()) - SSAUpdate.RewriteUse(*UsesToRename.pop_back_val()); - DEBUG(dbgs() << "\n"); + // We found a use of I outside of BB - we need to rename all uses of I that + // are outside its block to be uses of the appropriate PHI node etc. + SSAUpdate.AddAvailableValue(VarNum, BB, &I); + SSAUpdate.AddAvailableValue(VarNum, NewBB, ValueMapping[&I]); + for (auto *U : UsesToRename) + SSAUpdate.AddUse(VarNum, U); + VarNum++; } // Ok, NewBB is good to go. Update the terminator of PredBB to jump to @@ -2037,6 +2039,10 @@ bool JumpThreadingPass::ThreadEdge(BasicBlock *BB, {DominatorTree::Insert, PredBB, NewBB}, {DominatorTree::Delete, PredBB, BB}}); + // Apply all updates we queued with DDT and get the updated Dominator Tree. + DominatorTree *DT = &DDT->flush(); + SSAUpdate.RewriteAllUses(DT); + // At this point, the IR is fully up to date and consistent. Do a quick scan // over the new instructions and zap any that are constants or dead. This // frequently happens because of phi translation. |