[llvm] [IR][Core][NFC] Drop some BranchInst uses (PR #186352)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 13 03:00:05 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Alexis Engelke (aengelke)
<details>
<summary>Changes</summary>
Now that CondBrInst and UncondBrInst are explicit subclasses, use them instead.
HotColdSplitting was trying to inspect prof metadata also on unconditional branches, fix this.
Also introduce C API cast functions and deprecate LLVMIsConditional in favor of LLVMIsACondBrInst.
This patch covers all LLVM uses outside of Transforms, Analysis, CodeGen/Target, SandboxIR, Frontend/OpenMP, tools, examples.
---
Patch is 29.66 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/186352.diff
26 Files Affected:
- (modified) llvm/docs/BranchWeightMetadata.rst (+2-3)
- (modified) llvm/include/llvm-c/Core.h (+8-8)
- (modified) llvm/include/llvm/ADT/GenericUniformityInfo.h (+1-1)
- (modified) llvm/include/llvm/IR/IRBuilder.h (+6-6)
- (modified) llvm/include/llvm/IR/PatternMatch.h (+6-7)
- (modified) llvm/lib/AsmParser/LLParser.cpp (+2-2)
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+5-5)
- (modified) llvm/lib/ExecutionEngine/Interpreter/Execution.cpp (+7-9)
- (modified) llvm/lib/ExecutionEngine/Interpreter/Interpreter.h (+2-1)
- (modified) llvm/lib/FuzzMutate/IRMutator.cpp (+4-4)
- (modified) llvm/lib/FuzzMutate/Operations.cpp (+1-1)
- (modified) llvm/lib/IR/AsmWriter.cpp (+4-6)
- (modified) llvm/lib/IR/BasicBlock.cpp (+2-2)
- (modified) llvm/lib/IR/Core.cpp (+3-3)
- (modified) llvm/lib/IR/ProfDataUtils.cpp (+2-3)
- (modified) llvm/lib/IR/SafepointIRVerifier.cpp (+2-2)
- (modified) llvm/lib/IR/Verifier.cpp (+5-7)
- (modified) llvm/lib/Passes/StandardInstrumentations.cpp (+4-8)
- (modified) llvm/lib/Transforms/IPO/HotColdSplitting.cpp (+1-1)
- (modified) llvm/unittests/FuzzMutate/OperationsTest.cpp (+5-8)
- (modified) llvm/unittests/IR/BasicBlockTest.cpp (+3-3)
- (modified) llvm/unittests/IR/DominatorTreeTest.cpp (+2-2)
- (modified) llvm/unittests/IR/IRBuilderTest.cpp (+2-2)
- (modified) llvm/unittests/IR/InstructionsTest.cpp (+25-13)
- (modified) llvm/unittests/IR/LegacyPassManagerTest.cpp (+3-3)
- (modified) llvm/unittests/IR/VerifierTest.cpp (+5-5)
``````````diff
diff --git a/llvm/docs/BranchWeightMetadata.rst b/llvm/docs/BranchWeightMetadata.rst
index 71d7a7d3a6c05..76edfcffb6e97 100644
--- a/llvm/docs/BranchWeightMetadata.rst
+++ b/llvm/docs/BranchWeightMetadata.rst
@@ -23,11 +23,10 @@ indicates a greater chance of being taken.
Supported Instructions
======================
-``BranchInst``
+``CondBrInst``
^^^^^^^^^^^^^^
-Metadata is only assigned to conditional branches. There are two extra
-operands for the true and the false branch.
+There are two extra operands for the true and the false branch.
We optionally track if the metadata was added by ``__builtin_expect`` or
``__builtin_expect_with_probability`` with an optional field ``!"expected"``.
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index de1b5aa092ac6..869031d9e1c73 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -2053,6 +2053,8 @@ LLVM_C_ABI unsigned LLVMGetTargetExtTypeIntParam(LLVMTypeRef TargetExtTy,
macro(ShuffleVectorInst) \
macro(StoreInst) \
macro(BranchInst) \
+ macro(UncondBrInst) \
+ macro(CondBrInst) \
macro(IndirectBrInst) \
macro(InvokeInst) \
macro(ReturnInst) \
@@ -4297,29 +4299,27 @@ LLVM_C_ABI void LLVMSetSuccessor(LLVMValueRef Term, unsigned i,
LLVMBasicBlockRef block);
/**
- * Return if a branch is conditional.
+ * Return if an instruction is a conditional branch.
*
- * This only works on llvm::BranchInst instructions.
- *
- * @see llvm::BranchInst::isConditional
+ * Deprecated: Use LLVMIsACondBrInst instead.
*/
LLVM_C_ABI LLVMBool LLVMIsConditional(LLVMValueRef Branch);
/**
* Return the condition of a branch instruction.
*
- * This only works on llvm::BranchInst instructions.
+ * This only works on llvm::CondBrInst instructions.
*
- * @see llvm::BranchInst::getCondition
+ * @see llvm::CondBrInst::getCondition
*/
LLVM_C_ABI LLVMValueRef LLVMGetCondition(LLVMValueRef Branch);
/**
* Set the condition of a branch instruction.
*
- * This only works on llvm::BranchInst instructions.
+ * This only works on llvm::CondBrInst instructions.
*
- * @see llvm::BranchInst::setCondition
+ * @see llvm::CondBrInst::setCondition
*/
LLVM_C_ABI void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond);
diff --git a/llvm/include/llvm/ADT/GenericUniformityInfo.h b/llvm/include/llvm/ADT/GenericUniformityInfo.h
index 9376fa6ee0bae..be948707c3af8 100644
--- a/llvm/include/llvm/ADT/GenericUniformityInfo.h
+++ b/llvm/include/llvm/ADT/GenericUniformityInfo.h
@@ -68,7 +68,7 @@ template <typename ContextT> class GenericUniformityInfo {
// Similar queries for InstructionT. These accept a pointer argument so that
// in LLVM IR, they overload the equivalent queries for Value*. For example,
- // if querying whether a BranchInst is divergent, it should not be treated as
+ // if querying whether a CondBrInst is divergent, it should not be treated as
// a Value in LLVM IR.
bool isUniform(const InstructionT *I) const { return !isDivergent(I); };
bool isDivergent(const InstructionT *I) const;
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 5c0d0ab6a5015..b0bf40304fc5d 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -1191,24 +1191,24 @@ class IRBuilderBase {
}
/// Create an unconditional 'br label X' instruction.
- BranchInst *CreateBr(BasicBlock *Dest) {
- return Insert(BranchInst::Create(Dest));
+ UncondBrInst *CreateBr(BasicBlock *Dest) {
+ return Insert(UncondBrInst::Create(Dest));
}
/// Create a conditional 'br Cond, TrueDest, FalseDest'
/// instruction.
- BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False,
+ CondBrInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False,
MDNode *BranchWeights = nullptr,
MDNode *Unpredictable = nullptr) {
- return Insert(addBranchMetadata(BranchInst::Create(True, False, Cond),
+ return Insert(addBranchMetadata(CondBrInst::Create(Cond, True, False),
BranchWeights, Unpredictable));
}
/// Create a conditional 'br Cond, TrueDest, FalseDest'
/// instruction. Copy branch meta data if available.
- BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False,
+ CondBrInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False,
Instruction *MDSrc) {
- BranchInst *Br = BranchInst::Create(True, False, Cond);
+ CondBrInst *Br = CondBrInst::Create(Cond, True, False);
if (MDSrc) {
unsigned WL[4] = {LLVMContext::MD_prof, LLVMContext::MD_unpredictable,
LLVMContext::MD_make_implicit, LLVMContext::MD_dbg};
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index cd0f7187e134c..5a905b90d88cf 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -2468,11 +2468,10 @@ struct br_match {
br_match(BasicBlock *&Succ) : Succ(Succ) {}
template <typename OpTy> bool match(OpTy *V) const {
- if (auto *BI = dyn_cast<BranchInst>(V))
- if (BI->isUnconditional()) {
- Succ = BI->getSuccessor(0);
- return true;
- }
+ if (auto *BI = dyn_cast<UncondBrInst>(V)) {
+ Succ = BI->getSuccessor();
+ return true;
+ }
return false;
}
};
@@ -2489,8 +2488,8 @@ struct brc_match {
: Cond(C), T(t), F(f) {}
template <typename OpTy> bool match(OpTy *V) const {
- if (auto *BI = dyn_cast<BranchInst>(V))
- if (BI->isConditional() && Cond.match(BI->getCondition()))
+ if (auto *BI = dyn_cast<CondBrInst>(V))
+ if (Cond.match(BI->getCondition()))
return T.match(BI->getSuccessor(0)) && F.match(BI->getSuccessor(1));
return false;
}
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 551b88d8b435b..b7832cafc27c8 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -7780,7 +7780,7 @@ bool LLParser::parseBr(Instruction *&Inst, PerFunctionState &PFS) {
return true;
if (BasicBlock *BB = dyn_cast<BasicBlock>(Op0)) {
- Inst = BranchInst::Create(BB);
+ Inst = UncondBrInst::Create(BB);
return false;
}
@@ -7793,7 +7793,7 @@ bool LLParser::parseBr(Instruction *&Inst, PerFunctionState &PFS) {
parseTypeAndBasicBlock(Op2, Loc2, PFS))
return true;
- Inst = BranchInst::Create(Op1, Op2, Op0);
+ Inst = CondBrInst::Create(Op0, Op1, Op2);
return false;
}
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 1b9f13ecec62f..5dbab67900dc0 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -5653,7 +5653,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
return error("Invalid br record");
if (Record.size() == 1) {
- I = BranchInst::Create(TrueDest);
+ I = UncondBrInst::Create(TrueDest);
InstructionList.push_back(I);
}
else {
@@ -5663,7 +5663,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
getVirtualTypeID(CondType), CurBB);
if (!FalseDest || !Cond)
return error("Invalid br record");
- I = BranchInst::Create(TrueDest, FalseDest, Cond);
+ I = CondBrInst::Create(Cond, TrueDest, FalseDest);
InstructionList.push_back(I);
}
break;
@@ -7011,7 +7011,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
BasicBlock *From = Pair.first.first;
BasicBlock *To = Pair.first.second;
BasicBlock *EdgeBB = Pair.second;
- BranchInst::Create(To, EdgeBB);
+ UncondBrInst::Create(To, EdgeBB);
From->getTerminator()->replaceSuccessorWith(To, EdgeBB);
To->replacePhiUsesWith(From, EdgeBB);
EdgeBB->moveBefore(To);
@@ -7113,8 +7113,8 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
if (ProfName != MDProfLabels::BranchWeights)
continue;
unsigned ExpectedNumOperands = 0;
- if (BranchInst *BI = dyn_cast<BranchInst>(&I))
- ExpectedNumOperands = BI->getNumSuccessors();
+ if (isa<CondBrInst>(&I))
+ ExpectedNumOperands = 2;
else if (SwitchInst *SI = dyn_cast<SwitchInst>(&I))
ExpectedNumOperands = SI->getNumSuccessors();
else if (isa<CallInst>(&I))
diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
index 9da7bce76dbf2..08952d6459656 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -897,17 +897,15 @@ void Interpreter::visitUnreachableInst(UnreachableInst &I) {
report_fatal_error("Program executed an 'unreachable' instruction!");
}
-void Interpreter::visitBranchInst(BranchInst &I) {
+void Interpreter::visitUncondBrInst(UncondBrInst &I) {
ExecutionContext &SF = ECStack.back();
- BasicBlock *Dest;
+ SwitchToNewBasicBlock(I.getSuccessor(), SF);
+}
- Dest = I.getSuccessor(0); // Uncond branches have a fixed dest...
- if (!I.isUnconditional()) {
- Value *Cond = I.getCondition();
- if (getOperandValue(Cond, SF).IntVal == 0) // If false cond...
- Dest = I.getSuccessor(1);
- }
- SwitchToNewBasicBlock(Dest, SF);
+void Interpreter::visitCondBrInst(CondBrInst &I) {
+ ExecutionContext &SF = ECStack.back();
+ bool Cond = getOperandValue(I.getCondition(), SF).IntVal != 0;
+ SwitchToNewBasicBlock(I.getSuccessor(Cond ? 0 : 1), SF);
}
void Interpreter::visitSwitchInst(SwitchInst &I) {
diff --git a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h
index 41a0389442d38..3c358ca28391c 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h
+++ b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h
@@ -119,7 +119,8 @@ class Interpreter : public ExecutionEngine, public InstVisitor<Interpreter> {
// Opcode Implementations
void visitReturnInst(ReturnInst &I);
- void visitBranchInst(BranchInst &I);
+ void visitUncondBrInst(UncondBrInst &I);
+ void visitCondBrInst(CondBrInst &I);
void visitSwitchInst(SwitchInst &I);
void visitIndirectBrInst(IndirectBrInst &I);
diff --git a/llvm/lib/FuzzMutate/IRMutator.cpp b/llvm/lib/FuzzMutate/IRMutator.cpp
index 702afe28503b2..b56f3704d4305 100644
--- a/llvm/lib/FuzzMutate/IRMutator.cpp
+++ b/llvm/lib/FuzzMutate/IRMutator.cpp
@@ -518,7 +518,7 @@ void InsertCFGStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
uint64_t IP = uniform<uint64_t>(IB.Rand, 0, Insts.size() - 1);
auto InstsBeforeSplit = ArrayRef(Insts).slice(0, IP);
- // `Sink` inherits Blocks' terminator, `Source` will have a BranchInst
+ // `Sink` inherits Blocks' terminator, `Source` will have a UncondBrInst
// directly jumps to `Sink`. Here, we have to create a new terminator for
// `Source`.
BasicBlock *Block = Insts[IP]->getParent();
@@ -535,7 +535,7 @@ void InsertCFGStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
Value *Cond =
IB.findOrCreateSource(*Source, InstsBeforeSplit, {},
fuzzerop::onlyType(Type::getInt1Ty(C)), false);
- BranchInst *Branch = BranchInst::Create(IfTrue, IfFalse, Cond);
+ CondBrInst *Branch = CondBrInst::Create(Cond, IfTrue, IfFalse);
// Remove the old terminator.
ReplaceInstWithInst(Source->getTerminator(), Branch);
// Connect these blocks to `Sink`
@@ -607,7 +607,7 @@ void InsertCFGStrategy::connectBlocksToSink(ArrayRef<BasicBlock *> Blocks,
break;
}
case CFGToSink::DirectSink: {
- BranchInst::Create(Sink, BB);
+ UncondBrInst::Create(Sink, BB);
break;
}
case CFGToSink::SinkOrSelfLoop: {
@@ -616,7 +616,7 @@ void InsertCFGStrategy::connectBlocksToSink(ArrayRef<BasicBlock *> Blocks,
uint64_t coin = uniform<uint64_t>(IB.Rand, 0, 1);
Value *Cond = IB.findOrCreateSource(
*BB, {}, {}, fuzzerop::onlyType(Type::getInt1Ty(C)), false);
- BranchInst::Create(Branches[coin], Branches[1 - coin], Cond, BB);
+ CondBrInst::Create(Cond, Branches[coin], Branches[1 - coin], BB);
break;
}
case CFGToSink::EndOfCFGToLink:
diff --git a/llvm/lib/FuzzMutate/Operations.cpp b/llvm/lib/FuzzMutate/Operations.cpp
index c9cad7d142760..bedb2ce3635e4 100644
--- a/llvm/lib/FuzzMutate/Operations.cpp
+++ b/llvm/lib/FuzzMutate/Operations.cpp
@@ -176,7 +176,7 @@ OpDescriptor llvm::fuzzerop::splitBlockDescriptor(unsigned Weight) {
// Loop back on this block by replacing the unconditional forward branch
// with a conditional with a backedge.
if (Block != &Block->getParent()->getEntryBlock()) {
- BranchInst::Create(Block, Next, Srcs[0],
+ CondBrInst::Create(Srcs[0], Block, Next,
Block->getTerminator()->getIterator());
Block->getTerminator()->eraseFromParent();
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index dd99b14d45d6e..2147488d381f4 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -4453,15 +4453,13 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
const Value *Operand = I.getNumOperands() ? I.getOperand(0) : nullptr;
// Special case conditional branches to swizzle the condition out to the front
- if (isa<BranchInst>(I) && cast<BranchInst>(I).isConditional()) {
- const BranchInst &BI(cast<BranchInst>(I));
+ if (const auto *BI = dyn_cast<CondBrInst>(&I)) {
Out << ' ';
- writeOperand(BI.getCondition(), true);
+ writeOperand(BI->getCondition(), true);
Out << ", ";
- writeOperand(BI.getSuccessor(0), true);
+ writeOperand(BI->getSuccessor(0), true);
Out << ", ";
- writeOperand(BI.getSuccessor(1), true);
-
+ writeOperand(BI->getSuccessor(1), true);
} else if (isa<SwitchInst>(I)) {
const SwitchInst& SI(cast<SwitchInst>(I));
// Special case switch instruction to get formatting nice and correct.
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index e89231cac32b7..e2b1bbe0392fe 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -570,7 +570,7 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) {
New->splice(New->end(), this, I, end());
// Add a branch instruction to the newly formed basic block.
- BranchInst *BI = BranchInst::Create(New, this);
+ UncondBrInst *BI = UncondBrInst::Create(New, this);
BI->setDebugLoc(Loc);
// Now we must loop through all of the successors of the New block (which
@@ -615,7 +615,7 @@ BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
this->replacePhiUsesWith(Pred, New);
}
// Add a branch instruction from "New" to "this" Block.
- BranchInst *BI = BranchInst::Create(this, New);
+ UncondBrInst *BI = UncondBrInst::Create(this, New);
BI->setDebugLoc(Loc);
return New;
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index d586290d72903..65add3415b3bf 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -3252,15 +3252,15 @@ void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block) {
/*--.. Operations on branch instructions (only) ............................--*/
LLVMBool LLVMIsConditional(LLVMValueRef Branch) {
- return unwrap<BranchInst>(Branch)->isConditional();
+ return isa<CondBrInst>(unwrap<Instruction>(Branch));
}
LLVMValueRef LLVMGetCondition(LLVMValueRef Branch) {
- return wrap(unwrap<BranchInst>(Branch)->getCondition());
+ return wrap(unwrap<CondBrInst>(Branch)->getCondition());
}
void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond) {
- return unwrap<BranchInst>(Branch)->setCondition(unwrap(Cond));
+ return unwrap<CondBrInst>(Branch)->setCondition(unwrap(Cond));
}
/*--.. Operations on switch instructions (only) ............................--*/
diff --git a/llvm/lib/IR/ProfDataUtils.cpp b/llvm/lib/IR/ProfDataUtils.cpp
index 80eb7506cfab5..09794478103ea 100644
--- a/llvm/lib/IR/ProfDataUtils.cpp
+++ b/llvm/lib/IR/ProfDataUtils.cpp
@@ -217,9 +217,8 @@ bool llvm::extractBranchWeights(const Instruction &I,
bool llvm::extractBranchWeights(const Instruction &I, uint64_t &TrueVal,
uint64_t &FalseVal) {
- assert((isa<BranchInst, SelectInst>(I)) &&
- "Looking for branch weights on something besides branch, select, or "
- "switch");
+ assert((isa<CondBrInst, SelectInst>(I)) &&
+ "Looking for branch weights on something besides CondBr or Select");
SmallVector<uint32_t, 2> Weights;
auto *ProfileData = I.getMetadata(LLVMContext::MD_prof);
diff --git a/llvm/lib/IR/SafepointIRVerifier.cpp b/llvm/lib/IR/SafepointIRVerifier.cpp
index d3dba17de2b0e..b1fb621c41baf 100644
--- a/llvm/lib/IR/SafepointIRVerifier.cpp
+++ b/llvm/lib/IR/SafepointIRVerifier.cpp
@@ -138,8 +138,8 @@ class CFGDeadness {
// For conditional branches, we can perform simple conditional propagation on
// the condition value itself.
- const BranchInst *BI = dyn_cast<BranchInst>(TI);
- if (!BI || !BI->isConditional() || !isa<Constant>(BI->getCondition()))
+ const CondBrInst *BI = dyn_cast<CondBrInst>(TI);
+ if (!BI || !isa<Constant>(BI->getCondition()))
continue;
// If a branch has two identical successors, we cannot declare either dead.
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 3784ee00811f8..f0b8ccb907661 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -597,7 +597,7 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
void verifyDominatesUse(Instruction &I, unsigned i);
void visitInstruction(Instruction &I);
void visitTerminator(Instruction &I);
- void visitBranchInst(BranchInst &BI);
+ void visitCondBrInst(CondBrInst &BI);
void visitReturnInst(ReturnInst &RI);
void visitSwitchInst(SwitchInst &SI);
void visitIndirectBrInst(IndirectBrInst &BI);
@@ -3443,11 +3443,9 @@ void Verifier::visitTerminator(Instruction &I) {
visitInstruction(I);
}
-void Verifier::visitBranchInst(BranchInst &BI) {
- if (BI.isConditional()) {
- Check(BI.getCondition()->getType()->isIntegerTy(1),
- "Branch condition is not 'i1' type!", &BI, BI.getCondition());
- }
+void Verifier::visitCondBrInst(CondBrInst &BI) {
+ Check(BI.getCondition()->getType()->isIntegerTy(1),
+ "Branch condition is not 'i1' type!", &BI, BI.getCondition());
visitTerminator(BI);
}
@@ -5257,7 +5255,7 @@ void Verifier::visitNofreeMetadata(Instruction &I, MDNode *MD) {
void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) {
auto GetBranchingTerminatorNumOperands = [&]() {
unsigned ExpectedNumOperands = 0;
- if (BranchInst *BI = dyn_cast<BranchInst>(&I))
+ if (CondBrInst *BI = dyn_cast<CondBrInst>(&I))
ExpectedNumOperands = BI->getNumSuccessors();
else if (SwitchInst *SI = dyn_cast<SwitchInst>(&I))
ExpectedNumOperands = SI->getNumSuccessors();
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 6b7e980d048a4..19e72a8612c4a 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -2192,14 +2192,10 @@ namespace llvm {
DCData::DCData(const BasicBlock &B) {
// Build up transition labels.
const Instruction *Term = B.getTerminator();
- if (const BranchInst *Br = dyn_cast<const BranchInst>(Term))
- if (Br->isUnconditional())
- addSuccessorLabel(Br->getSuccessor(0)->getName().str(), "");
- else {
- addSuccessorLabel(Br->getSuccessor(0)->getName().str(), "true");
- addSuccessorLabel(Br->getSuccessor(1)->getName().str(), "false");
- }
- else if (const SwitchInst *Sw = dyn_cast<const SwitchInst>(Term)) {
+ if (const CondBrInst *Br = dyn_cast<const CondBrInst>(Term)) {
+ addSuccessorLabel(Br->getSuccessor(0)->getName().str(), "true");
+ addSuccessorLabel(Br->getSuccessor(1)->getName().str(), "false");
+ } else if (const SwitchInst *Sw = dyn_cast<const SwitchInst>(Term)) {
addSuccessorLabel(Sw->ca...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/186352
More information about the llvm-commits
mailing list