[llvm] 0c316f0 - [BBUtils][NFC] Delete SplitBlockAndInsertIfThen with DT.
Joshua Cao via llvm-commits
llvm-commits at lists.llvm.org
Tue May 23 21:09:50 PDT 2023
Author: Joshua Cao
Date: 2023-05-23T21:02:37-07:00
New Revision: 0c316f00672ff5968ea9c49663b2449a37ff6715
URL: https://github.com/llvm/llvm-project/commit/0c316f00672ff5968ea9c49663b2449a37ff6715
DIFF: https://github.com/llvm/llvm-project/commit/0c316f00672ff5968ea9c49663b2449a37ff6715.diff
LOG: [BBUtils][NFC] Delete SplitBlockAndInsertIfThen with DT.
The method is marked for deprecation. Delete the method and move all of
its consumers to use the DomTreeUpdater version.
Reviewed By: foad
Differential Revision: https://reviews.llvm.org/D149428
Added:
Modified:
llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp
llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp
polly/lib/CodeGen/BlockGenerators.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
index 7c296b414eabd..d65c2fe5fe6b3 100644
--- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -416,36 +416,7 @@ ReturnInst *FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
/// 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
-/// 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.
+/// Updates DTU and LI if given.
Instruction *SplitBlockAndInsertIfThen(Value *Cond, Instruction *SplitBefore,
bool Unreachable,
MDNode *BranchWeights = nullptr,
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp
index 13eaa7be1abe3..affa214bc396b 100644
--- 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 @@ class AMDGPUAtomicOptimizerImpl
SmallVector<ReplacementInfo, 8> ToReplace;
const UniformityInfo *UA;
const DataLayout *DL;
- DominatorTree *DT;
+ DomTreeUpdater &DTU;
const GCNSubtarget *ST;
bool IsPixelShader;
@@ -76,9 +77,9 @@ class AMDGPUAtomicOptimizerImpl
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);
@@ -103,7 +104,8 @@ bool AMDGPUAtomicOptimizer::runOnFunction(Function &F) {
DominatorTreeWrapperPass *const DTW =
getAnalysisIfAvailable<DominatorTreeWrapperPass>();
- DominatorTree *DT = DTW ? &DTW->getDomTree() : nullptr;
+ DomTreeUpdater DTU(DTW ? &DTW->getDomTree() : nullptr,
+ DomTreeUpdater::UpdateStrategy::Lazy);
const TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
const TargetMachine &TM = TPC.getTM<TargetMachine>();
@@ -111,7 +113,7 @@ bool AMDGPUAtomicOptimizer::runOnFunction(Function &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 AMDGPUAtomicOptimizerPass::run(Function &F,
@@ -120,12 +122,13 @@ PreservedAnalyses AMDGPUAtomicOptimizerPass::run(Function &F,
const auto *UA = &AM.getResult<UniformityInfoAnalysis>(F);
const DataLayout *DL = &F.getParent()->getDataLayout();
- DominatorTree *DT = &AM.getResult<DominatorTreeAnalysis>(F);
+ DomTreeUpdater DTU(&AM.getResult<DominatorTreeAnalysis>(F),
+ DomTreeUpdater::UpdateStrategy::Lazy);
const GCNSubtarget *ST = &TM.getSubtarget<GCNSubtarget>(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 @@ void AMDGPUAtomicOptimizerImpl::optimizeAtomic(Instruction &I,
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 @@ void AMDGPUAtomicOptimizerImpl::optimizeAtomic(Instruction &I,
// 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
index 314a262a2b566..3a8a7801c5e2f 100644
--- 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,9 @@ void DFSanFunction::storeOrigin(Instruction *Pos, Value *Addr, uint64_t Size,
ConstantInt::get(DFS.IntptrTy, Size), Origin});
} else {
Value *Cmp = convertToBool(CollapsedShadow, IRB, "_dfscmp");
+ DomTreeUpdater DTU(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
index 9d86afa347a3e..4b93b624c2eb0 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1471,11 +1471,12 @@ ReturnInst *llvm::FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB,
return cast<ReturnInst>(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<DominatorTree::UpdateType, 8> Updates;
BasicBlock *Head = SplitBefore->getParent();
BasicBlock *Tail = Head->splitBasicBlock(SplitBefore->getIterator());
@@ -1514,21 +1515,6 @@ SplitBlockAndInsertIfThenImpl(Value *Cond, Instruction *SplitBefore,
if (DTU)
DTU->applyUpdates(Updates);
- else if (DT) {
- if (DomTreeNode *OldNode = DT->getNode(Head)) {
- std::vector<DomTreeNode *> 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 @@ SplitBlockAndInsertIfThenImpl(Value *Cond, Instruction *SplitBefore,
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
index 80f685d7edabc..a470ddc5bb703 100644
--- 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 @@ STATISTIC(NumWrappedTwoCond, "Number of Two-Condition Wrappers Inserted");
namespace {
class LibCallsShrinkWrap : public InstVisitor<LibCallsShrinkWrap> {
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 @@ class LibCallsShrinkWrap : public InstVisitor<LibCallsShrinkWrap> {
}
const TargetLibraryInfo &TLI;
- DominatorTree *DT;
+ DomTreeUpdater &DTU;
SmallVector<CallInst *, 16> WorkList;
};
} // end anonymous namespace
@@ -466,7 +467,7 @@ void LibCallsShrinkWrap::shrinkWrapCI(CallInst *CI, Value *Cond) {
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,12 +497,14 @@ static bool runImpl(Function &F, const TargetLibraryInfo &TLI,
DominatorTree *DT) {
if (F.hasFnAttribute(Attribute::OptimizeForSize))
return false;
- LibCallsShrinkWrap CCDCE(TLI, DT);
+ DomTreeUpdater DTU(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));
+ // Verify the dominator after we've updated it locally.
+ assert(!DT ||
+ DTU.getDomTree().verify(DominatorTree::VerificationLevel::Fast));
return Changed;
}
diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp
index 1c18f2dbbbdbb..4c1336456e496 100644
--- 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,9 @@ void BlockGenerator::generateConditionalExecution(
StringRef BlockName = HeadBlock->getName();
// Generate the conditional block.
+ DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
SplitBlockAndInsertIfThen(Cond, &*Builder.GetInsertPoint(), false, nullptr,
- &DT, &LI);
+ &DTU, &LI);
BranchInst *Branch = cast<BranchInst>(HeadBlock->getTerminator());
BasicBlock *ThenBlock = Branch->getSuccessor(0);
BasicBlock *TailBlock = Branch->getSuccessor(1);
More information about the llvm-commits
mailing list