[clang] [Clang][NFC] Drop uses of BranchInst (PR #187242)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 18 04:13:23 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Alexis Engelke (aengelke)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/187242.diff
7 Files Affected:
- (modified) clang/lib/CodeGen/CGClass.cpp (+1-1)
- (modified) clang/lib/CodeGen/CGCleanup.cpp (+20-20)
- (modified) clang/lib/CodeGen/CGException.cpp (+2-5)
- (modified) clang/lib/CodeGen/CGExpr.cpp (+1-1)
- (modified) clang/lib/CodeGen/CGStmt.cpp (+3-3)
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+3-4)
- (modified) clang/lib/CodeGen/EHScopeStack.h (+1-1)
``````````diff
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 26a7f08f5cfc6..6572009fc6003 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -2174,7 +2174,7 @@ void CodeGenFunction::EmitCXXAggrConstructorCall(
// because of GCC extensions that permit zero-length arrays. There
// are probably legitimate places where we could assume that this
// doesn't happen, but it's not clear that it's worth it.
- llvm::BranchInst *zeroCheckBranch = nullptr;
+ llvm::CondBrInst *zeroCheckBranch = nullptr;
// Optimize for a constant count.
llvm::ConstantInt *constantCount = dyn_cast<llvm::ConstantInt>(numElements);
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 28ac9bf396356..3d242bec73126 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -346,7 +346,7 @@ static void ResolveAllBranchFixups(CodeGenFunction &CGF,
createStoreInstBefore(CGF.Builder.getInt32(Fixup.DestinationIndex),
CGF.getNormalCleanupDestSlot(),
Fixup.InitialBranch->getIterator(), CGF);
- Fixup.InitialBranch->setSuccessor(0, CleanupEntry);
+ Fixup.InitialBranch->setSuccessor(CleanupEntry);
}
// Don't add this case to the switch statement twice.
@@ -369,8 +369,7 @@ static llvm::SwitchInst *TransitionToCleanupSwitch(CodeGenFunction &CGF,
llvm::Instruction *Term = Block->getTerminator();
assert(Term && "can't transition block without terminator");
- if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
- assert(Br->isUnconditional());
+ if (llvm::UncondBrInst *Br = dyn_cast<llvm::UncondBrInst>(Term)) {
auto Load = createLoadInstBefore(CGF.getNormalCleanupDestSlot(),
"cleanup.dest", Term->getIterator(), CGF);
llvm::SwitchInst *Switch =
@@ -530,9 +529,10 @@ static llvm::BasicBlock *SimplifyCleanupEntry(CodeGenFunction &CGF,
llvm::BasicBlock *Pred = Entry->getSinglePredecessor();
if (!Pred) return Entry;
- llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Pred->getTerminator());
- if (!Br || Br->isConditional()) return Entry;
- assert(Br->getSuccessor(0) == Entry);
+ llvm::UncondBrInst *Br = dyn_cast<llvm::UncondBrInst>(Pred->getTerminator());
+ if (!Br)
+ return Entry;
+ assert(Br->getSuccessor() == Entry);
// If we were previously inserting at the end of the cleanup entry
// block, we'll need to continue inserting at the end of the
@@ -591,9 +591,9 @@ static void ForwardPrebranchedFallthrough(llvm::BasicBlock *Exit,
// an unconditional branch or a switch.
llvm::Instruction *Term = Exit->getTerminator();
- if (llvm::BranchInst *Br = dyn_cast<llvm::BranchInst>(Term)) {
- assert(Br->isUnconditional() && Br->getSuccessor(0) == From);
- Br->setSuccessor(0, To);
+ if (llvm::UncondBrInst *Br = dyn_cast<llvm::UncondBrInst>(Term)) {
+ assert(Br->getSuccessor() == From);
+ Br->setSuccessor(To);
} else {
llvm::SwitchInst *Switch = cast<llvm::SwitchInst>(Term);
for (unsigned I = 0, E = Switch->getNumSuccessors(); I != E; ++I)
@@ -626,8 +626,8 @@ static void destroyOptimisticNormalEntry(CodeGenFunction &CGF,
llvm::SwitchInst *si = cast<llvm::SwitchInst>(use.getUser());
if (si->getNumCases() == 1 && si->getDefaultDest() == unreachableBB) {
// Replace the switch with a branch.
- llvm::BranchInst::Create(si->case_begin()->getCaseSuccessor(),
- si->getIterator());
+ llvm::UncondBrInst::Create(si->case_begin()->getCaseSuccessor(),
+ si->getIterator());
// The switch operand is a load from the cleanup-dest alloca.
llvm::LoadInst *condition = cast<llvm::LoadInst>(si->getCondition());
@@ -903,13 +903,13 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
}
llvm::BasicBlock *BranchAfter = Scope.getBranchAfterBlock(0);
- InstsToAppend.push_back(llvm::BranchInst::Create(BranchAfter));
+ InstsToAppend.push_back(llvm::UncondBrInst::Create(BranchAfter));
- // Build a switch-out if we need it:
- // - if there are branch-afters threaded through the scope
- // - if fall-through is a branch-after
- // - if there are fixups that have nowhere left to go and
- // so must be immediately resolved
+ // Build a switch-out if we need it:
+ // - if there are branch-afters threaded through the scope
+ // - if fall-through is a branch-after
+ // - if there are fixups that have nowhere left to go and
+ // so must be immediately resolved
} else if (Scope.getNumBranchAfters() ||
(HasFallthrough && !FallthroughIsBranchThrough) ||
(HasFixups && !HasEnclosingCleanups)) {
@@ -950,7 +950,7 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
} else {
// We should always have a branch-through destination in this case.
assert(BranchThroughDest);
- InstsToAppend.push_back(llvm::BranchInst::Create(BranchThroughDest));
+ InstsToAppend.push_back(llvm::UncondBrInst::Create(BranchThroughDest));
}
// IV. Pop the cleanup and emit it.
@@ -975,7 +975,7 @@ void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
createStoreInstBefore(Builder.getInt32(Fixup.DestinationIndex),
getNormalCleanupDestSlot(),
Fixup.InitialBranch->getIterator(), *this);
- Fixup.InitialBranch->setSuccessor(0, NormalEntry);
+ Fixup.InitialBranch->setSuccessor(NormalEntry);
}
Fixup.OptimisticBranchBlock = NormalExit;
}
@@ -1117,7 +1117,7 @@ void CodeGenFunction::EmitBranchThroughCleanup(JumpDest Dest) {
return;
// Create the branch.
- llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock());
+ llvm::UncondBrInst *BI = Builder.CreateBr(Dest.getBlock());
addInstToCurrentSourceAtom(BI, nullptr);
// Calculate the innermost active normal cleanup.
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index 1437bc2d32159..7559727721496 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1325,11 +1325,8 @@ void CodeGenFunction::ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock) {
// we follow the false destination for each of the cond branches to reach
// the rethrow block.
llvm::BasicBlock *RethrowBlock = WasmCatchStartBlock;
- while (llvm::Instruction *TI = RethrowBlock->getTerminator()) {
- auto *BI = cast<llvm::BranchInst>(TI);
- assert(BI->isConditional());
- RethrowBlock = BI->getSuccessor(1);
- }
+ while (llvm::Instruction *TI = RethrowBlock->getTerminator())
+ RethrowBlock = cast<llvm::CondBrInst>(TI)->getSuccessor(1);
assert(RethrowBlock != WasmCatchStartBlock && RethrowBlock->empty());
Builder.SetInsertPoint(RethrowBlock);
llvm::Function *RethrowInCatchFn =
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 88b2b6b3c33fb..23802cdeb4811 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4287,7 +4287,7 @@ void CodeGenFunction::EmitCfiSlowPathCheck(
llvm::BasicBlock *Cont = createBasicBlock("cfi.cont");
llvm::BasicBlock *CheckBB = createBasicBlock("cfi.slowpath");
- llvm::BranchInst *BI = Builder.CreateCondBr(Cond, Cont, CheckBB);
+ llvm::CondBrInst *BI = Builder.CreateCondBr(Cond, Cont, CheckBB);
llvm::MDBuilder MDHelper(getLLVMContext());
llvm::MDNode *Node = MDHelper.createLikelyBranchWeights();
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index ad31ecc75b01e..a923002bec9b6 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -616,7 +616,7 @@ CodeGenFunction::EmitCompoundStmtWithoutScope(const CompoundStmt &S,
}
void CodeGenFunction::SimplifyForwardingBlocks(llvm::BasicBlock *BB) {
- llvm::BranchInst *BI = dyn_cast<llvm::BranchInst>(BB->getTerminator());
+ llvm::UncondBrInst *BI = dyn_cast<llvm::UncondBrInst>(BB->getTerminator());
// If there is a cleanup stack, then we it isn't worth trying to
// simplify this block (we would need to remove it from the scope map
@@ -625,14 +625,14 @@ void CodeGenFunction::SimplifyForwardingBlocks(llvm::BasicBlock *BB) {
return;
// Can only simplify direct branches.
- if (!BI || !BI->isUnconditional())
+ if (!BI)
return;
// Can only simplify empty blocks.
if (BI->getIterator() != BB->begin())
return;
- BB->replaceAllUsesWith(BI->getSuccessor(0));
+ BB->replaceAllUsesWith(BI->getSuccessor());
BI->eraseFromParent();
BB->eraseFromParent();
}
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index 81b293fe5fe89..a64cec801a173 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -326,10 +326,9 @@ llvm::DebugLoc CodeGenFunction::EmitReturnBlock() {
// branch then we can just put the code in that block instead. This
// cleans up functions which started with a unified return block.
if (ReturnBlock.getBlock()->hasOneUse()) {
- llvm::BranchInst *BI =
- dyn_cast<llvm::BranchInst>(*ReturnBlock.getBlock()->user_begin());
- if (BI && BI->isUnconditional() &&
- BI->getSuccessor(0) == ReturnBlock.getBlock()) {
+ auto *BI =
+ dyn_cast<llvm::UncondBrInst>(*ReturnBlock.getBlock()->user_begin());
+ if (BI && BI->getSuccessor(0) == ReturnBlock.getBlock()) {
// Record/return the DebugLoc of the simple 'return' expression to be used
// later by the actual 'ret' instruction.
llvm::DebugLoc Loc = BI->getDebugLoc();
diff --git a/clang/lib/CodeGen/EHScopeStack.h b/clang/lib/CodeGen/EHScopeStack.h
index 2dcb75556c4e5..b9b8021191d62 100644
--- a/clang/lib/CodeGen/EHScopeStack.h
+++ b/clang/lib/CodeGen/EHScopeStack.h
@@ -49,7 +49,7 @@ struct BranchFixup {
unsigned DestinationIndex;
/// The initial branch of the fixup.
- llvm::BranchInst *InitialBranch;
+ llvm::UncondBrInst *InitialBranch;
};
template <class T> struct InvariantValue {
``````````
</details>
https://github.com/llvm/llvm-project/pull/187242
More information about the cfe-commits
mailing list