diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h --- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h +++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h @@ -396,35 +396,6 @@ BasicBlock *Pred, DomTreeUpdater *DTU = nullptr); -/// Split the containing block at the specified instruction - everything before -/// SplitBefore stays in the old basic block, and the rest of the instructions -/// in the BB are moved to a new block. The two blocks are connected by a -/// conditional branch (with value of Cmp being the condition). -/// Before: -/// Head -/// SplitBefore -/// Tail -/// After: -/// Head -/// if (Cond) -/// ThenBlock -/// SplitBefore -/// Tail -/// -/// If \p ThenBlock is not specified, a new block will be created for it. -/// If \p Unreachable is true, the newly created block will end with -/// UnreachableInst, otherwise it branches to Tail. -/// Returns the NewBasicBlock's terminator. -/// -/// Updates DT and LI if given. -/// -/// FIXME: deprecated, switch to the DomTreeUpdater-based one. -Instruction *SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore, - bool Unreachable, MDNode *BranchWeights, - DominatorTree *DT, - LoopInfo *LI = nullptr, - BasicBlock *ThenBlock = nullptr); - /// Split the containing block at the specified instruction - everything before /// SplitBefore stays in the old basic block, and the rest of the instructions /// in the BB are moved to a new block. The two blocks are connected by a diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp @@ -15,6 +15,7 @@ #include "AMDGPU.h" #include "GCNSubtarget.h" +#include "llvm/Analysis/DomTreeUpdater.h" #include "llvm/Analysis/UniformityAnalysis.h" #include "llvm/CodeGen/TargetPassConfig.h" #include "llvm/IR/IRBuilder.h" @@ -59,7 +60,7 @@ SmallVector ToReplace; const UniformityInfo *UA; const DataLayout *DL; - DominatorTree *DT; + DomTreeUpdater &DTU; const GCNSubtarget *ST; bool IsPixelShader; @@ -76,9 +77,9 @@ AMDGPUAtomicOptimizerImpl() = delete; AMDGPUAtomicOptimizerImpl(const UniformityInfo *UA, const DataLayout *DL, - DominatorTree *DT, const GCNSubtarget *ST, + DomTreeUpdater &DTU, const GCNSubtarget *ST, bool IsPixelShader) - : UA(UA), DL(DL), DT(DT), ST(ST), IsPixelShader(IsPixelShader) {} + : UA(UA), DL(DL), DTU(DTU), ST(ST), IsPixelShader(IsPixelShader) {} bool run(Function &F); @@ -104,6 +105,7 @@ DominatorTreeWrapperPass *const DTW = getAnalysisIfAvailable(); DominatorTree *DT = DTW ? &DTW->getDomTree() : nullptr; + DomTreeUpdater DTU = DomTreeUpdater(DT, DomTreeUpdater::UpdateStrategy::Lazy); const TargetPassConfig &TPC = getAnalysis(); const TargetMachine &TM = TPC.getTM(); @@ -111,7 +113,7 @@ bool IsPixelShader = F.getCallingConv() == CallingConv::AMDGPU_PS; - return AMDGPUAtomicOptimizerImpl(UA, DL, DT, ST, IsPixelShader).run(F); + return AMDGPUAtomicOptimizerImpl(UA, DL, DTU, ST, IsPixelShader).run(F); } PreservedAnalyses AMDGPUAtomicOptimizerPass::run(Function &F, @@ -121,11 +123,12 @@ const DataLayout *DL = &F.getParent()->getDataLayout(); DominatorTree *DT = &AM.getResult(F); + DomTreeUpdater DTU = DomTreeUpdater(DT, DomTreeUpdater::UpdateStrategy::Lazy); const GCNSubtarget *ST = &TM.getSubtarget(F); bool IsPixelShader = F.getCallingConv() == CallingConv::AMDGPU_PS; - return AMDGPUAtomicOptimizerImpl(UA, DL, DT, ST, IsPixelShader).run(F) + return AMDGPUAtomicOptimizerImpl(UA, DL, DTU, ST, IsPixelShader).run(F) ? PreservedAnalyses::none() : PreservedAnalyses::all(); } @@ -519,7 +522,7 @@ Value *const Cond = B.CreateIntrinsic(Intrinsic::amdgcn_ps_live, {}, {}); Instruction *const NonHelperTerminator = - SplitBlockAndInsertIfThen(Cond, &I, false, nullptr, DT, nullptr); + SplitBlockAndInsertIfThen(Cond, &I, false, nullptr, &DTU, nullptr); // Record I's new position as the exit block. PixelExitBB = I.getParent(); @@ -648,7 +651,7 @@ // entry --> single_lane -\ // \------------------> exit Instruction *const SingleLaneTerminator = - SplitBlockAndInsertIfThen(Cond, &I, false, nullptr, DT, nullptr); + SplitBlockAndInsertIfThen(Cond, &I, false, nullptr, &DTU, nullptr); // Move the IR builder into single_lane next. B.SetInsertPoint(SingleLaneTerminator); diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -68,6 +68,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/iterator.h" +#include "llvm/Analysis/DomTreeUpdater.h" #include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/ValueTracking.h" @@ -2524,8 +2525,10 @@ ConstantInt::get(DFS.IntptrTy, Size), Origin}); } else { Value *Cmp = convertToBool(CollapsedShadow, IRB, "_dfscmp"); + DomTreeUpdater DTU = + DomTreeUpdater(DT, DomTreeUpdater::UpdateStrategy::Lazy); Instruction *CheckTerm = SplitBlockAndInsertIfThen( - Cmp, &*IRB.GetInsertPoint(), false, DFS.OriginStoreWeights, &DT); + Cmp, &*IRB.GetInsertPoint(), false, DFS.OriginStoreWeights, &DTU); IRBuilder<> IRBNew(CheckTerm); paintOrigin(IRBNew, updateOrigin(Origin, IRBNew), StoreOriginAddr, Size, OriginAlignment); diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -1471,11 +1471,12 @@ return cast(NewRet); } -static Instruction * -SplitBlockAndInsertIfThenImpl(Value *Cond, Instruction *SplitBefore, - bool Unreachable, MDNode *BranchWeights, - DomTreeUpdater *DTU, DominatorTree *DT, - LoopInfo *LI, BasicBlock *ThenBlock) { +Instruction *llvm::SplitBlockAndInsertIfThen(Value *Cond, + Instruction *SplitBefore, + bool Unreachable, + MDNode *BranchWeights, + DomTreeUpdater *DTU, LoopInfo *LI, + BasicBlock *ThenBlock) { SmallVector Updates; BasicBlock *Head = SplitBefore->getParent(); BasicBlock *Tail = Head->splitBasicBlock(SplitBefore->getIterator()); @@ -1514,21 +1515,6 @@ if (DTU) DTU->applyUpdates(Updates); - else if (DT) { - if (DomTreeNode *OldNode = DT->getNode(Head)) { - std::vector Children(OldNode->begin(), OldNode->end()); - - DomTreeNode *NewNode = DT->addNewBlock(Tail, Head); - for (DomTreeNode *Child : Children) - DT->changeImmediateDominator(Child, NewNode); - - // Head dominates ThenBlock. - if (CreateThenBlock) - DT->addNewBlock(ThenBlock, Head); - else - DT->changeImmediateDominator(ThenBlock, Head); - } - } if (LI) { if (Loop *L = LI->getLoopFor(Head)) { @@ -1540,27 +1526,6 @@ return CheckTerm; } -Instruction *llvm::SplitBlockAndInsertIfThen(Value *Cond, - Instruction *SplitBefore, - bool Unreachable, - MDNode *BranchWeights, - DominatorTree *DT, LoopInfo *LI, - BasicBlock *ThenBlock) { - return SplitBlockAndInsertIfThenImpl(Cond, SplitBefore, Unreachable, - BranchWeights, - /*DTU=*/nullptr, DT, LI, ThenBlock); -} -Instruction *llvm::SplitBlockAndInsertIfThen(Value *Cond, - Instruction *SplitBefore, - bool Unreachable, - MDNode *BranchWeights, - DomTreeUpdater *DTU, LoopInfo *LI, - BasicBlock *ThenBlock) { - return SplitBlockAndInsertIfThenImpl(Cond, SplitBefore, Unreachable, - BranchWeights, DTU, /*DT=*/nullptr, LI, - ThenBlock); -} - void llvm::SplitBlockAndInsertIfThenElse(Value *Cond, Instruction *SplitBefore, Instruction **ThenTerm, Instruction **ElseTerm, diff --git a/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp b/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp --- a/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp +++ b/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp @@ -28,6 +28,7 @@ #include "llvm/Transforms/Utils/LibCallsShrinkWrap.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" +#include "llvm/Analysis/DomTreeUpdater.h" #include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/IR/Constants.h" @@ -51,8 +52,8 @@ namespace { class LibCallsShrinkWrap : public InstVisitor { public: - LibCallsShrinkWrap(const TargetLibraryInfo &TLI, DominatorTree *DT) - : TLI(TLI), DT(DT){}; + LibCallsShrinkWrap(const TargetLibraryInfo &TLI, DomTreeUpdater &DTU) + : TLI(TLI), DTU(DTU){}; void visitCallInst(CallInst &CI) { checkCandidate(CI); } bool perform() { bool Changed = false; @@ -105,7 +106,7 @@ } const TargetLibraryInfo &TLI; - DominatorTree *DT; + DomTreeUpdater &DTU; SmallVector WorkList; }; } // end anonymous namespace @@ -466,7 +467,7 @@ MDBuilder(CI->getContext()).createBranchWeights(1, 2000); Instruction *NewInst = - SplitBlockAndInsertIfThen(Cond, CI, false, BranchWeights, DT); + SplitBlockAndInsertIfThen(Cond, CI, false, BranchWeights, &DTU); BasicBlock *CallBB = NewInst->getParent(); CallBB->setName("cdce.call"); BasicBlock *SuccBB = CallBB->getSingleSuccessor(); @@ -496,13 +497,10 @@ DominatorTree *DT) { if (F.hasFnAttribute(Attribute::OptimizeForSize)) return false; - LibCallsShrinkWrap CCDCE(TLI, DT); + DomTreeUpdater DTU = DomTreeUpdater(DT, DomTreeUpdater::UpdateStrategy::Lazy); + LibCallsShrinkWrap CCDCE(TLI, DTU); CCDCE.visit(F); - bool Changed = CCDCE.perform(); - -// Verify the dominator after we've updated it locally. - assert(!DT || DT->verify(DominatorTree::VerificationLevel::Fast)); - return Changed; + return CCDCE.perform(); } PreservedAnalyses LibCallsShrinkWrapPass::run(Function &F, diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp --- a/polly/lib/CodeGen/BlockGenerators.cpp +++ b/polly/lib/CodeGen/BlockGenerators.cpp @@ -20,6 +20,7 @@ #include "polly/Support/ISLTools.h" #include "polly/Support/ScopHelper.h" #include "polly/Support/VirtualInstruction.h" +#include "llvm/Analysis/DomTreeUpdater.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/RegionInfo.h" #include "llvm/Analysis/ScalarEvolution.h" @@ -626,8 +627,10 @@ StringRef BlockName = HeadBlock->getName(); // Generate the conditional block. + DomTreeUpdater DTU = + DomTreeUpdater(DT, DomTreeUpdater::UpdateStrategy::Eager); SplitBlockAndInsertIfThen(Cond, &*Builder.GetInsertPoint(), false, nullptr, - &DT, &LI); + &DTU, &LI); BranchInst *Branch = cast(HeadBlock->getTerminator()); BasicBlock *ThenBlock = Branch->getSuccessor(0); BasicBlock *TailBlock = Branch->getSuccessor(1);