[llvm] fd1e37b - [IR] Remove Before argument from splitBlock APIs (NFC) (#179195)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 2 02:51:02 PST 2026
Author: Nikita Popov
Date: 2026-02-02T10:50:58Z
New Revision: fd1e37b6530ec5b7b12bcb7c379fb297e001f6ee
URL: https://github.com/llvm/llvm-project/commit/fd1e37b6530ec5b7b12bcb7c379fb297e001f6ee
DIFF: https://github.com/llvm/llvm-project/commit/fd1e37b6530ec5b7b12bcb7c379fb297e001f6ee.diff
LOG: [IR] Remove Before argument from splitBlock APIs (NFC) (#179195)
We never need to use this conditionally (and it doesn't really make
sense, as the behavior is substantially different). Force the use of
separate APIs instead of a boolean argument.
Added:
Modified:
llvm/include/llvm/IR/BasicBlock.h
llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/lib/IR/BasicBlock.cpp
llvm/lib/Target/AArch64/SMEABIPass.cpp
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/BasicBlock.h b/llvm/include/llvm/IR/BasicBlock.h
index 07d411fcf07ae..d8d5990a9a997 100644
--- a/llvm/include/llvm/IR/BasicBlock.h
+++ b/llvm/include/llvm/IR/BasicBlock.h
@@ -623,9 +623,6 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
/// Split the basic block into two basic blocks at the specified instruction.
///
- /// If \p Before is true, splitBasicBlockBefore handles the
- /// block splitting. Otherwise, execution proceeds as described below.
- ///
/// Note that all instructions BEFORE the specified iterator
/// stay as part of the original basic block, an unconditional branch is added
/// to the original BB, and the rest of the instructions in the BB are moved
@@ -639,11 +636,9 @@ class BasicBlock final : public Value, // Basic blocks are data objects also
///
/// Also note that this doesn't preserve any passes. To split blocks while
/// keeping loop information consistent, use the SplitBlock utility function.
- LLVM_ABI BasicBlock *splitBasicBlock(iterator I, const Twine &BBName = "",
- bool Before = false);
- BasicBlock *splitBasicBlock(Instruction *I, const Twine &BBName = "",
- bool Before = false) {
- return splitBasicBlock(I->getIterator(), BBName, Before);
+ LLVM_ABI BasicBlock *splitBasicBlock(iterator I, const Twine &BBName = "");
+ BasicBlock *splitBasicBlock(Instruction *I, const Twine &BBName = "") {
+ return splitBasicBlock(I->getIterator(), BBName);
}
/// Split the basic block into two basic blocks at the specified instruction
diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
index c951597498033..8a80e7f1d8e9b 100644
--- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -315,9 +315,6 @@ ehAwareSplitEdge(BasicBlock *BB, BasicBlock *Succ,
/// Split the specified block at the specified instruction.
///
-/// If \p Before is true, splitBlockBefore handles the block
-/// splitting. Otherwise, execution proceeds as described below.
-///
/// Everything before \p SplitPt stays in \p Old and everything starting with \p
/// SplitPt moves to a new block. The two blocks are joined by an unconditional
/// branch. The new block with name \p BBName is returned.
@@ -326,19 +323,16 @@ ehAwareSplitEdge(BasicBlock *BB, BasicBlock *Succ,
LLVM_ABI BasicBlock *SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt,
DominatorTree *DT, LoopInfo *LI = nullptr,
MemorySSAUpdater *MSSAU = nullptr,
- const Twine &BBName = "", bool Before = false);
-inline BasicBlock *SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT,
- LoopInfo *LI = nullptr,
- MemorySSAUpdater *MSSAU = nullptr,
- const Twine &BBName = "", bool Before = false) {
- return SplitBlock(Old, SplitPt->getIterator(), DT, LI, MSSAU, BBName, Before);
+ const Twine &BBName = "");
+inline BasicBlock *SplitBlock(BasicBlock *Old, Instruction *SplitPt,
+ DominatorTree *DT, LoopInfo *LI = nullptr,
+ MemorySSAUpdater *MSSAU = nullptr,
+ const Twine &BBName = "") {
+ return SplitBlock(Old, SplitPt->getIterator(), DT, LI, MSSAU, BBName);
}
/// Split the specified block at the specified instruction.
///
-/// If \p Before is true, splitBlockBefore handles the block
-/// splitting. Otherwise, execution proceeds as described below.
-///
/// Everything before \p SplitPt stays in \p Old and everything starting with \p
/// SplitPt moves to a new block. The two blocks are joined by an unconditional
/// branch. The new block with name \p BBName is returned.
@@ -346,12 +340,13 @@ LLVM_ABI BasicBlock *SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt,
DomTreeUpdater *DTU = nullptr,
LoopInfo *LI = nullptr,
MemorySSAUpdater *MSSAU = nullptr,
- const Twine &BBName = "", bool Before = false);
+ const Twine &BBName = "");
inline BasicBlock *SplitBlock(BasicBlock *Old, Instruction *SplitPt,
- DomTreeUpdater *DTU = nullptr, LoopInfo *LI = nullptr,
- MemorySSAUpdater *MSSAU = nullptr,
- const Twine &BBName = "", bool Before = false) {
- return SplitBlock(Old, SplitPt->getIterator(), DTU, LI, MSSAU, BBName, Before);
+ DomTreeUpdater *DTU = nullptr,
+ LoopInfo *LI = nullptr,
+ MemorySSAUpdater *MSSAU = nullptr,
+ const Twine &BBName = "") {
+ return SplitBlock(Old, SplitPt->getIterator(), DTU, LI, MSSAU, BBName);
}
/// Split the specified block at the specified instruction \p SplitPt.
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index b9cf73a48ee22..288ce3b52d0e9 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -6464,8 +6464,7 @@ bool CodeGenPrepare::optimizeMulWithOverflow(Instruction *I, bool IsSigned,
Type *LegalTy = Ty->getWithNewBitWidth(VTHalfBitWidth);
// New BBs:
- BasicBlock *OverflowEntryBB =
- I->getParent()->splitBasicBlock(I, "", /*Before*/ true);
+ BasicBlock *OverflowEntryBB = I->getParent()->splitBasicBlockBefore(I, "");
OverflowEntryBB->takeName(I->getParent());
// Keep the 'br' instruction that is generated as a result of the split to be
// erased/replaced later.
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 2cf18dfafcdf7..2a0a017fbb0f3 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -5830,8 +5830,8 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::applyWorkshareLoopTarget(
// Mark the body loop as region which needs to be extracted
OI.EntryBB = CLI->getBody();
- OI.ExitBB = CLI->getLatch()->splitBasicBlock(CLI->getLatch()->begin(),
- "omp.prelatch", true);
+ OI.ExitBB = CLI->getLatch()->splitBasicBlockBefore(CLI->getLatch()->begin(),
+ "omp.prelatch");
// Prepare loop body for extraction
Builder.restoreIP({CLI->getPreheader(), CLI->getPreheader()->begin()});
@@ -6649,8 +6649,8 @@ void OpenMPIRBuilder::createIfVersion(CanonicalLoopInfo *CanonicalLoop,
// The loop latch must have only one predecessor. Currently it is branched to
// from both the 'then' and 'else' branches.
- L->getLoopLatch()->splitBasicBlock(
- L->getLoopLatch()->begin(), NamePrefix + ".pre_latch", /*Before=*/true);
+ L->getLoopLatch()->splitBasicBlockBefore(L->getLoopLatch()->begin(),
+ NamePrefix + ".pre_latch");
// Ensure that the then block is added to the loop so we add the attributes in
// the next step
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 3642e935397cb..e89231cac32b7 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -552,11 +552,7 @@ bool BasicBlock::isEntryBlock() const {
return this == &F->getEntryBlock();
}
-BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName,
- bool Before) {
- if (Before)
- return splitBasicBlockBefore(I, BBName);
-
+BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) {
assert(getTerminator() && "Can't use splitBasicBlock on degenerate BB!");
assert(I != InstList.end() &&
"Trying to get me to create degenerate basic block!");
diff --git a/llvm/lib/Target/AArch64/SMEABIPass.cpp b/llvm/lib/Target/AArch64/SMEABIPass.cpp
index 6bdad036c1f71..4245afbbf6beb 100644
--- a/llvm/lib/Target/AArch64/SMEABIPass.cpp
+++ b/llvm/lib/Target/AArch64/SMEABIPass.cpp
@@ -119,7 +119,7 @@ bool SMEABI::updateNewStateFunctions(Module *M, Function *F,
// to commit the lazy save.
if (FnAttrs.hasPrivateZAInterface()) {
// Create the new blocks for reading TPIDR2_EL0 & enabling ZA state.
- auto *SaveBB = OrigBB->splitBasicBlock(OrigBB->begin(), "save.za", true);
+ auto *SaveBB = OrigBB->splitBasicBlockBefore(OrigBB->begin(), "save.za");
auto *PreludeBB = BasicBlock::Create(Context, "prelude", F, SaveBB);
// Read TPIDR2_EL0 in PreludeBB & branch to SaveBB if not 0.
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index 7e8cc03f7b002..2f51ad4eb95e0 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -669,7 +669,7 @@ static bool unswitchTrivialBranch(Loop &L, BranchInst &BI, DominatorTree &DT,
UnswitchedBB = LoopExitBB;
} else {
UnswitchedBB =
- SplitBlock(LoopExitBB, LoopExitBB->begin(), &DT, &LI, MSSAU, "", false);
+ SplitBlock(LoopExitBB, LoopExitBB->begin(), &DT, &LI, MSSAU, "");
}
if (MSSAU && VerifyMemorySSA)
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index b0c04086f5e84..68d1fd892402c 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -679,8 +679,8 @@ BasicBlock *llvm::SplitEdge(BasicBlock *BB, BasicBlock *Succ, DominatorTree *DT,
// block.
assert(SP == BB && "CFG broken");
(void)SP;
- return SplitBlock(Succ, &Succ->front(), DT, LI, MSSAU, BBName,
- /*Before=*/true);
+ DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
+ return splitBlockBefore(Succ, &Succ->front(), &DTU, LI, MSSAU, BBName);
}
// Otherwise, if BB has a single successor, split it at the bottom of the
@@ -996,13 +996,7 @@ llvm::SplitAllCriticalEdges(Function &F,
static BasicBlock *SplitBlockImpl(BasicBlock *Old, BasicBlock::iterator SplitPt,
DomTreeUpdater *DTU, DominatorTree *DT,
LoopInfo *LI, MemorySSAUpdater *MSSAU,
- const Twine &BBName, bool Before) {
- if (Before) {
- DomTreeUpdater LocalDTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
- return splitBlockBefore(Old, SplitPt,
- DTU ? DTU : (DT ? &LocalDTU : nullptr), LI, MSSAU,
- BBName);
- }
+ const Twine &BBName) {
BasicBlock::iterator SplitIt = SplitPt;
while (isa<PHINode>(SplitIt) || SplitIt->isEHPad()) {
++SplitIt;
@@ -1051,17 +1045,13 @@ static BasicBlock *SplitBlockImpl(BasicBlock *Old, BasicBlock::iterator SplitPt,
BasicBlock *llvm::SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt,
DominatorTree *DT, LoopInfo *LI,
- MemorySSAUpdater *MSSAU, const Twine &BBName,
- bool Before) {
- return SplitBlockImpl(Old, SplitPt, /*DTU=*/nullptr, DT, LI, MSSAU, BBName,
- Before);
+ MemorySSAUpdater *MSSAU, const Twine &BBName) {
+ return SplitBlockImpl(Old, SplitPt, /*DTU=*/nullptr, DT, LI, MSSAU, BBName);
}
BasicBlock *llvm::SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt,
DomTreeUpdater *DTU, LoopInfo *LI,
- MemorySSAUpdater *MSSAU, const Twine &BBName,
- bool Before) {
- return SplitBlockImpl(Old, SplitPt, DTU, /*DT=*/nullptr, LI, MSSAU, BBName,
- Before);
+ MemorySSAUpdater *MSSAU, const Twine &BBName) {
+ return SplitBlockImpl(Old, SplitPt, DTU, /*DT=*/nullptr, LI, MSSAU, BBName);
}
BasicBlock *llvm::splitBlockBefore(BasicBlock *Old, BasicBlock::iterator SplitPt,
@@ -1073,9 +1063,8 @@ BasicBlock *llvm::splitBlockBefore(BasicBlock *Old, BasicBlock::iterator SplitPt
while (isa<PHINode>(SplitIt) || SplitIt->isEHPad())
++SplitIt;
std::string Name = BBName.str();
- BasicBlock *New = Old->splitBasicBlock(
- SplitIt, Name.empty() ? Old->getName() + ".split" : Name,
- /* Before=*/true);
+ BasicBlock *New = Old->splitBasicBlockBefore(
+ SplitIt, Name.empty() ? Old->getName() + ".split" : Name);
// The new block lives in whichever loop the old one did. This preserves
// LCSSA as well, because we force the split point to be after any PHI nodes.
More information about the llvm-commits
mailing list