[Mlir-commits] [llvm] [mlir] [IR] Split Br into UncondBr and CondBr (PR #184027)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Mar 1 11:13:51 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-powerpc

Author: Alexis Engelke (aengelke)

<details>
<summary>Changes</summary>

BranchInst currently represents both unconditional and conditional branches. However, these are quite different operations that are often handled separately. Therefore, split them into separate opcodes and classes to allow distinguishing these operations in the type system. Additionally, this also slightly improves compile-time performance.

---

Patch is 113.84 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/184027.diff


69 Files Affected:

- (modified) llvm/include/llvm-c/Core.h (+3-1) 
- (modified) llvm/include/llvm/Analysis/TargetTransformInfoImpl.h (+2-1) 
- (modified) llvm/include/llvm/CodeGen/BasicTTIImpl.h (+1-1) 
- (modified) llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h (+2-1) 
- (modified) llvm/include/llvm/IR/InstVisitor.h (+6) 
- (modified) llvm/include/llvm/IR/Instruction.def (+81-80) 
- (modified) llvm/include/llvm/IR/Instructions.h (+203-48) 
- (modified) llvm/include/llvm/Transforms/InstCombine/InstCombiner.h (+1-1) 
- (modified) llvm/lib/Analysis/ObjCARCInstKind.cpp (+2-1) 
- (modified) llvm/lib/Analysis/ValueTracking.cpp (+4-5) 
- (modified) llvm/lib/AsmParser/LLLexer.cpp (+1-1) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+11-10) 
- (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+4-4) 
- (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+17-12) 
- (modified) llvm/lib/CodeGen/SelectionDAG/FastISel.cpp (+6-13) 
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+20-15) 
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h (+2-1) 
- (modified) llvm/lib/CodeGen/TargetLoweringBase.cpp (+2-1) 
- (modified) llvm/lib/CodeGen/TypePromotion.cpp (+2-1) 
- (modified) llvm/lib/FuzzMutate/RandomIRBuilder.cpp (+1-1) 
- (modified) llvm/lib/IR/Instruction.cpp (+2-1) 
- (modified) llvm/lib/IR/Instructions.cpp (+39-27) 
- (modified) llvm/lib/IR/Metadata.cpp (+8-7) 
- (modified) llvm/lib/IR/ProfDataUtils.cpp (+1-2) 
- (modified) llvm/lib/SandboxIR/Context.cpp (+2-1) 
- (modified) llvm/lib/Target/AArch64/AArch64FastISel.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp (+4-5) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp (+3-5) 
- (modified) llvm/lib/Target/AMDGPU/R600TargetTransformInfo.cpp (+2-1) 
- (modified) llvm/lib/Target/ARM/ARMFastISel.cpp (+1-1) 
- (modified) llvm/lib/Target/Mips/MipsFastISel.cpp (+1-1) 
- (modified) llvm/lib/Target/PowerPC/PPCFastISel.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp (+2-2) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp (+1-1) 
- (modified) llvm/lib/Target/X86/X86FastISel.cpp (+1-1) 
- (modified) llvm/lib/Target/X86/X86TargetTransformInfo.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/Attributor.cpp (+2-1) 
- (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+5-13) 
- (modified) llvm/lib/Transforms/IPO/IROutliner.cpp (+4-4) 
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp (+2-1) 
- (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/SimplifyCFG.cpp (+5-8) 
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp (+2-1) 
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+9-8) 
- (modified) llvm/lib/Transforms/Vectorize/VPlan.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Vectorize/VPlan.h (+2-1) 
- (modified) llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp (+3-2) 
- (modified) llvm/test/Analysis/IR2Vec/Inputs/dummy_2D_vocab.json (+2-1) 
- (modified) llvm/test/Analysis/IR2Vec/Inputs/dummy_3D_nonzero_arg_vocab.json (+2-1) 
- (modified) llvm/test/Analysis/IR2Vec/Inputs/dummy_3D_nonzero_opc_vocab.json (+2-1) 
- (modified) llvm/test/Analysis/IR2Vec/Inputs/dummy_3D_nonzero_type_vocab.json (+2-1) 
- (modified) llvm/test/Analysis/IR2Vec/Inputs/reference_default_vocab_print.txt (+2-1) 
- (modified) llvm/test/Analysis/IR2Vec/Inputs/reference_wtd1_vocab_print.txt (+2-1) 
- (modified) llvm/test/Analysis/IR2Vec/Inputs/reference_wtd2_vocab_print.txt (+2-1) 
- (modified) llvm/test/Analysis/InstCount/instcount.ll (+2-1) 
- (modified) llvm/test/Transforms/IRNormalizer/naming-args-instr-blocks.ll (+3-3) 
- (modified) llvm/test/Transforms/IRNormalizer/naming-arguments.ll (+2-2) 
- (modified) llvm/test/Transforms/IRNormalizer/naming.ll (+6-6) 
- (modified) llvm/test/Transforms/IRNormalizer/pass-parameters.ll (+2-2) 
- (modified) llvm/test/Transforms/IRNormalizer/regression-convergence-tokens.ll (+3-3) 
- (modified) llvm/test/Transforms/IRNormalizer/regression-infinite-loop.ll (+89-89) 
- (modified) llvm/test/Transforms/IRNormalizer/reordering-basic.ll (+7-7) 
- (modified) llvm/test/Transforms/IRNormalizer/reordering.ll (+18-18) 
- (modified) llvm/test/tools/llvm-ir2vec/entities.ll (+112-111) 
- (modified) llvm/test/tools/llvm-ir2vec/triplets.ll (+38-38) 
- (modified) llvm/tools/llvm-c-test/echo.cpp (+7-8) 
- (modified) llvm/unittests/Analysis/IR2VecTest.cpp (+17-16) 
- (modified) mlir/lib/Target/LLVMIR/ModuleImport.cpp (+14-8) 


``````````diff
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 3fa2801e4b4bd..de1b5aa092ac6 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -61,7 +61,9 @@ LLVM_C_EXTERN_C_BEGIN
 typedef enum {
   /* Terminator Instructions */
   LLVMRet            = 1,
-  LLVMBr             = 2,
+  /* removed 2 due to API changes */
+  LLVMUncondBr       = 70,
+  LLVMCondBr         = 71,
   LLVMSwitch         = 3,
   LLVMIndirectBr     = 4,
   LLVMInvoke         = 5,
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
index e062b70be6b59..b0f2f718e552d 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -1452,7 +1452,8 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
       IntrinsicCostAttributes CostAttrs(Intrinsic->getIntrinsicID(), *CB);
       return TargetTTI->getIntrinsicInstrCost(CostAttrs, CostKind);
     }
-    case Instruction::Br:
+    case Instruction::UncondBr:
+    case Instruction::CondBr:
     case Instruction::Ret:
     case Instruction::PHI:
     case Instruction::Switch:
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index 6dcb6f0062a08..f393bd7f9e6f7 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -255,7 +255,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
           getScalarizationOverhead(
               FixedVectorType::get(Type::getInt1Ty(DataTy->getContext()), VF),
               /*Insert=*/false, /*Extract=*/true, CostKind) +
-          VF * (thisT()->getCFInstrCost(Instruction::Br, CostKind) +
+          VF * (thisT()->getCFInstrCost(Instruction::CondBr, CostKind) +
                 thisT()->getCFInstrCost(Instruction::PHI, CostKind));
     }
 
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
index 2f3f55a58a517..6d916b76cee55 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h
@@ -380,7 +380,8 @@ class IRTranslator : public MachineFunctionPass {
 
   /// Translate branch (br) instruction.
   /// \pre \p U is a branch instruction.
-  bool translateBr(const User &U, MachineIRBuilder &MIRBuilder);
+  bool translateUncondBr(const User &U, MachineIRBuilder &MIRBuilder);
+  bool translateCondBr(const User &U, MachineIRBuilder &MIRBuilder);
 
   // Begin switch lowering functions.
   bool emitJumpTableHeader(SwitchCG::JumpTable &JT,
diff --git a/llvm/include/llvm/IR/InstVisitor.h b/llvm/include/llvm/IR/InstVisitor.h
index 8e4dc647e5230..e58c7745c87f9 100644
--- a/llvm/include/llvm/IR/InstVisitor.h
+++ b/llvm/include/llvm/IR/InstVisitor.h
@@ -221,6 +221,12 @@ class InstVisitor {
   RetTy visitReturnInst(ReturnInst &I) {
     return static_cast<SubClass *>(this)->visitTerminator(I);
   }
+  RetTy visitUncondBrInst(UncondBrInst &I) {
+    return static_cast<SubClass *>(this)->visitBranchInst(I);
+  }
+  RetTy visitCondBrInst(CondBrInst &I) {
+    return static_cast<SubClass *>(this)->visitBranchInst(I);
+  }
   RetTy visitBranchInst(BranchInst &I) {
     return static_cast<SubClass *>(this)->visitTerminator(I);
   }
diff --git a/llvm/include/llvm/IR/Instruction.def b/llvm/include/llvm/IR/Instruction.def
index face6a93ec7d5..89d214868e16b 100644
--- a/llvm/include/llvm/IR/Instruction.def
+++ b/llvm/include/llvm/IR/Instruction.def
@@ -125,101 +125,102 @@
 //
  FIRST_TERM_INST  ( 1)
 HANDLE_TERM_INST  ( 1, Ret           , ReturnInst)
-HANDLE_TERM_INST  ( 2, Br            , BranchInst)
-HANDLE_TERM_INST  ( 3, Switch        , SwitchInst)
-HANDLE_TERM_INST  ( 4, IndirectBr    , IndirectBrInst)
-HANDLE_TERM_INST  ( 5, Invoke        , InvokeInst)
-HANDLE_TERM_INST  ( 6, Resume        , ResumeInst)
-HANDLE_TERM_INST  ( 7, Unreachable   , UnreachableInst)
-HANDLE_TERM_INST  ( 8, CleanupRet    , CleanupReturnInst)
-HANDLE_TERM_INST  ( 9, CatchRet      , CatchReturnInst)
-HANDLE_TERM_INST  (10, CatchSwitch   , CatchSwitchInst)
-HANDLE_TERM_INST  (11, CallBr        , CallBrInst) // A call-site terminator
-  LAST_TERM_INST  (11)
+HANDLE_TERM_INST  ( 2, UncondBr      , UncondBrInst)
+HANDLE_TERM_INST  ( 3, CondBr        , CondBrInst)
+HANDLE_TERM_INST  ( 4, Switch        , SwitchInst)
+HANDLE_TERM_INST  ( 5, IndirectBr    , IndirectBrInst)
+HANDLE_TERM_INST  ( 6, Invoke        , InvokeInst)
+HANDLE_TERM_INST  ( 7, Resume        , ResumeInst)
+HANDLE_TERM_INST  ( 8, Unreachable   , UnreachableInst)
+HANDLE_TERM_INST  ( 9, CleanupRet    , CleanupReturnInst)
+HANDLE_TERM_INST  (10, CatchRet      , CatchReturnInst)
+HANDLE_TERM_INST  (11, CatchSwitch   , CatchSwitchInst)
+HANDLE_TERM_INST  (12, CallBr        , CallBrInst) // A call-site terminator
+  LAST_TERM_INST  (12)
 
 // Standard unary operators...
- FIRST_UNARY_INST(12)
-HANDLE_UNARY_INST(12, FNeg  , UnaryOperator)
-  LAST_UNARY_INST(12)
+ FIRST_UNARY_INST(13)
+HANDLE_UNARY_INST(13, FNeg  , UnaryOperator)
+  LAST_UNARY_INST(13)
 
 // Standard binary operators...
- FIRST_BINARY_INST(13)
-HANDLE_BINARY_INST(13, Add  , BinaryOperator)
-HANDLE_BINARY_INST(14, FAdd , BinaryOperator)
-HANDLE_BINARY_INST(15, Sub  , BinaryOperator)
-HANDLE_BINARY_INST(16, FSub , BinaryOperator)
-HANDLE_BINARY_INST(17, Mul  , BinaryOperator)
-HANDLE_BINARY_INST(18, FMul , BinaryOperator)
-HANDLE_BINARY_INST(19, UDiv , BinaryOperator)
-HANDLE_BINARY_INST(20, SDiv , BinaryOperator)
-HANDLE_BINARY_INST(21, FDiv , BinaryOperator)
-HANDLE_BINARY_INST(22, URem , BinaryOperator)
-HANDLE_BINARY_INST(23, SRem , BinaryOperator)
-HANDLE_BINARY_INST(24, FRem , BinaryOperator)
+ FIRST_BINARY_INST(14)
+HANDLE_BINARY_INST(14, Add  , BinaryOperator)
+HANDLE_BINARY_INST(15, FAdd , BinaryOperator)
+HANDLE_BINARY_INST(16, Sub  , BinaryOperator)
+HANDLE_BINARY_INST(17, FSub , BinaryOperator)
+HANDLE_BINARY_INST(18, Mul  , BinaryOperator)
+HANDLE_BINARY_INST(19, FMul , BinaryOperator)
+HANDLE_BINARY_INST(20, UDiv , BinaryOperator)
+HANDLE_BINARY_INST(21, SDiv , BinaryOperator)
+HANDLE_BINARY_INST(22, FDiv , BinaryOperator)
+HANDLE_BINARY_INST(23, URem , BinaryOperator)
+HANDLE_BINARY_INST(24, SRem , BinaryOperator)
+HANDLE_BINARY_INST(25, FRem , BinaryOperator)
 
 // Logical operators (integer operands)
-HANDLE_BINARY_INST(25, Shl  , BinaryOperator) // Shift left  (logical)
-HANDLE_BINARY_INST(26, LShr , BinaryOperator) // Shift right (logical)
-HANDLE_BINARY_INST(27, AShr , BinaryOperator) // Shift right (arithmetic)
-HANDLE_BINARY_INST(28, And  , BinaryOperator)
-HANDLE_BINARY_INST(29, Or   , BinaryOperator)
-HANDLE_BINARY_INST(30, Xor  , BinaryOperator)
-  LAST_BINARY_INST(30)
+HANDLE_BINARY_INST(26, Shl  , BinaryOperator) // Shift left  (logical)
+HANDLE_BINARY_INST(27, LShr , BinaryOperator) // Shift right (logical)
+HANDLE_BINARY_INST(28, AShr , BinaryOperator) // Shift right (arithmetic)
+HANDLE_BINARY_INST(29, And  , BinaryOperator)
+HANDLE_BINARY_INST(30, Or   , BinaryOperator)
+HANDLE_BINARY_INST(31, Xor  , BinaryOperator)
+  LAST_BINARY_INST(31)
 
 // Memory operators...
- FIRST_MEMORY_INST(31)
-HANDLE_MEMORY_INST(31, Alloca, AllocaInst)  // Stack management
-HANDLE_MEMORY_INST(32, Load  , LoadInst  )  // Memory manipulation instrs
-HANDLE_MEMORY_INST(33, Store , StoreInst )
-HANDLE_MEMORY_INST(34, GetElementPtr, GetElementPtrInst)
-HANDLE_MEMORY_INST(35, Fence , FenceInst )
-HANDLE_MEMORY_INST(36, AtomicCmpXchg , AtomicCmpXchgInst )
-HANDLE_MEMORY_INST(37, AtomicRMW , AtomicRMWInst )
-  LAST_MEMORY_INST(37)
+ FIRST_MEMORY_INST(32)
+HANDLE_MEMORY_INST(32, Alloca, AllocaInst)  // Stack management
+HANDLE_MEMORY_INST(33, Load  , LoadInst  )  // Memory manipulation instrs
+HANDLE_MEMORY_INST(34, Store , StoreInst )
+HANDLE_MEMORY_INST(35, GetElementPtr, GetElementPtrInst)
+HANDLE_MEMORY_INST(36, Fence , FenceInst )
+HANDLE_MEMORY_INST(37, AtomicCmpXchg , AtomicCmpXchgInst )
+HANDLE_MEMORY_INST(38, AtomicRMW , AtomicRMWInst )
+  LAST_MEMORY_INST(38)
 
 // Cast operators ...
 // NOTE: The order matters here because CastInst::isEliminableCastPair
 // NOTE: (see Instructions.cpp) encodes a table based on this ordering.
- FIRST_CAST_INST(38)
-HANDLE_CAST_INST(38, Trunc   , TruncInst   )  // Truncate integers
-HANDLE_CAST_INST(39, ZExt    , ZExtInst    )  // Zero extend integers
-HANDLE_CAST_INST(40, SExt    , SExtInst    )  // Sign extend integers
-HANDLE_CAST_INST(41, FPToUI  , FPToUIInst  )  // floating point -> UInt
-HANDLE_CAST_INST(42, FPToSI  , FPToSIInst  )  // floating point -> SInt
-HANDLE_CAST_INST(43, UIToFP  , UIToFPInst  )  // UInt -> floating point
-HANDLE_CAST_INST(44, SIToFP  , SIToFPInst  )  // SInt -> floating point
-HANDLE_CAST_INST(45, FPTrunc , FPTruncInst )  // Truncate floating point
-HANDLE_CAST_INST(46, FPExt   , FPExtInst   )  // Extend floating point
-HANDLE_CAST_INST(47, PtrToInt, PtrToIntInst)  // Pointer -> Integer (bitcast)
-HANDLE_CAST_INST(48, PtrToAddr, PtrToAddrInst) // Pointer -> Address
-HANDLE_CAST_INST(49, IntToPtr, IntToPtrInst)  // Integer -> Pointer
-HANDLE_CAST_INST(50, BitCast , BitCastInst )  // Type cast
-HANDLE_CAST_INST(51, AddrSpaceCast, AddrSpaceCastInst)  // addrspace cast
-  LAST_CAST_INST(51)
+ FIRST_CAST_INST(39)
+HANDLE_CAST_INST(39, Trunc   , TruncInst   )  // Truncate integers
+HANDLE_CAST_INST(40, ZExt    , ZExtInst    )  // Zero extend integers
+HANDLE_CAST_INST(41, SExt    , SExtInst    )  // Sign extend integers
+HANDLE_CAST_INST(42, FPToUI  , FPToUIInst  )  // floating point -> UInt
+HANDLE_CAST_INST(43, FPToSI  , FPToSIInst  )  // floating point -> SInt
+HANDLE_CAST_INST(44, UIToFP  , UIToFPInst  )  // UInt -> floating point
+HANDLE_CAST_INST(45, SIToFP  , SIToFPInst  )  // SInt -> floating point
+HANDLE_CAST_INST(46, FPTrunc , FPTruncInst )  // Truncate floating point
+HANDLE_CAST_INST(47, FPExt   , FPExtInst   )  // Extend floating point
+HANDLE_CAST_INST(48, PtrToInt, PtrToIntInst)  // Pointer -> Integer (bitcast)
+HANDLE_CAST_INST(49, PtrToAddr, PtrToAddrInst) // Pointer -> Address
+HANDLE_CAST_INST(50, IntToPtr, IntToPtrInst)  // Integer -> Pointer
+HANDLE_CAST_INST(51, BitCast , BitCastInst )  // Type cast
+HANDLE_CAST_INST(52, AddrSpaceCast, AddrSpaceCastInst)  // addrspace cast
+  LAST_CAST_INST(52)
 
- FIRST_FUNCLETPAD_INST(52)
-HANDLE_FUNCLETPAD_INST(52, CleanupPad, CleanupPadInst)
-HANDLE_FUNCLETPAD_INST(53, CatchPad  , CatchPadInst)
-  LAST_FUNCLETPAD_INST(53)
+ FIRST_FUNCLETPAD_INST(53)
+HANDLE_FUNCLETPAD_INST(53, CleanupPad, CleanupPadInst)
+HANDLE_FUNCLETPAD_INST(54, CatchPad  , CatchPadInst)
+  LAST_FUNCLETPAD_INST(54)
 
 // Other operators...
- FIRST_OTHER_INST(54)
-HANDLE_OTHER_INST(54, ICmp   , ICmpInst   )  // Integer comparison instruction
-HANDLE_OTHER_INST(55, FCmp   , FCmpInst   )  // Floating point comparison instr.
-HANDLE_OTHER_INST(56, PHI    , PHINode    )  // PHI node instruction
-HANDLE_OTHER_INST(57, Call   , CallInst   )  // Call a function
-HANDLE_OTHER_INST(58, Select , SelectInst )  // select instruction
-HANDLE_USER_INST (59, UserOp1, Instruction)  // May be used internally in a pass
-HANDLE_USER_INST (60, UserOp2, Instruction)  // Internal to passes only
-HANDLE_OTHER_INST(61, VAArg  , VAArgInst  )  // vaarg instruction
-HANDLE_OTHER_INST(62, ExtractElement, ExtractElementInst)// extract from vector
-HANDLE_OTHER_INST(63, InsertElement, InsertElementInst)  // insert into vector
-HANDLE_OTHER_INST(64, ShuffleVector, ShuffleVectorInst)  // shuffle two vectors.
-HANDLE_OTHER_INST(65, ExtractValue, ExtractValueInst)// extract from aggregate
-HANDLE_OTHER_INST(66, InsertValue, InsertValueInst)  // insert into aggregate
-HANDLE_OTHER_INST(67, LandingPad, LandingPadInst)  // Landing pad instruction.
-HANDLE_OTHER_INST(68, Freeze, FreezeInst) // Freeze instruction.
-  LAST_OTHER_INST(68)
+ FIRST_OTHER_INST(55)
+HANDLE_OTHER_INST(55, ICmp   , ICmpInst   )  // Integer comparison instruction
+HANDLE_OTHER_INST(56, FCmp   , FCmpInst   )  // Floating point comparison instr.
+HANDLE_OTHER_INST(57, PHI    , PHINode    )  // PHI node instruction
+HANDLE_OTHER_INST(58, Call   , CallInst   )  // Call a function
+HANDLE_OTHER_INST(59, Select , SelectInst )  // select instruction
+HANDLE_USER_INST (60, UserOp1, Instruction)  // May be used internally in a pass
+HANDLE_USER_INST (61, UserOp2, Instruction)  // Internal to passes only
+HANDLE_OTHER_INST(62, VAArg  , VAArgInst  )  // vaarg instruction
+HANDLE_OTHER_INST(63, ExtractElement, ExtractElementInst)// extract from vector
+HANDLE_OTHER_INST(64, InsertElement, InsertElementInst)  // insert into vector
+HANDLE_OTHER_INST(65, ShuffleVector, ShuffleVectorInst)  // shuffle two vectors.
+HANDLE_OTHER_INST(66, ExtractValue, ExtractValueInst)// extract from aggregate
+HANDLE_OTHER_INST(67, InsertValue, InsertValueInst)  // insert into aggregate
+HANDLE_OTHER_INST(68, LandingPad, LandingPadInst)  // Landing pad instruction.
+HANDLE_OTHER_INST(69, Freeze, FreezeInst) // Freeze instruction.
+  LAST_OTHER_INST(69)
 
 #undef  FIRST_TERM_INST
 #undef HANDLE_TERM_INST
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index d4ea74c05ae62..8f1014594a7b8 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -3056,32 +3056,10 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)
 /// Conditional or Unconditional Branch instruction.
 ///
 class BranchInst : public Instruction {
-  /// Ops list - Branches are strange.  The operands are ordered:
-  ///  [Cond, FalseDest,] TrueDest.  This makes some accessors faster because
-  /// they don't have to check for cond/uncond branchness. These are mostly
-  /// accessed relative from op_end().
-  BranchInst(const BranchInst &BI, AllocInfo AllocInfo);
-  // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
-  // BranchInst(BB *B)                           - 'br B'
-  // BranchInst(BB* T, BB *F, Value *C)          - 'br C, T, F'
-  // BranchInst(BB* B, Iter It)                  - 'br B'        insert before I
-  // BranchInst(BB* T, BB *F, Value *C, Iter It) - 'br C, T, F', insert before I
-  // BranchInst(BB* B, Inst *I)                  - 'br B'        insert before I
-  // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
-  // BranchInst(BB* B, BB *I)                    - 'br B'        insert at end
-  // BranchInst(BB* T, BB *F, Value *C, BB *I)   - 'br C, T, F', insert at end
-  LLVM_ABI explicit BranchInst(BasicBlock *IfTrue, AllocInfo AllocInfo,
-                               InsertPosition InsertBefore);
-  LLVM_ABI BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
-                      AllocInfo AllocInfo, InsertPosition InsertBefore);
-
-  void AssertOK();
-
 protected:
-  // Note: Instruction needs to be a friend here to call cloneImpl.
-  friend class Instruction;
-
-  LLVM_ABI BranchInst *cloneImpl() const;
+  BranchInst(Type *Ty, unsigned Opcode, AllocInfo AllocInfo,
+             InsertPosition InsertBefore = nullptr)
+      : Instruction(Ty, Opcode, AllocInfo, InsertBefore) {}
 
 public:
   /// Iterator type that casts an operand to a basic block.
@@ -3112,34 +3090,20 @@ class BranchInst : public Instruction {
   };
 
   static BranchInst *Create(BasicBlock *IfTrue,
-                            InsertPosition InsertBefore = nullptr) {
-    IntrusiveOperandsAllocMarker AllocMarker{1};
-    return new (AllocMarker) BranchInst(IfTrue, AllocMarker, InsertBefore);
-  }
+                            InsertPosition InsertBefore = nullptr);
 
   static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
-                            Value *Cond,
-                            InsertPosition InsertBefore = nullptr) {
-    IntrusiveOperandsAllocMarker AllocMarker{3};
-    return new (AllocMarker)
-        BranchInst(IfTrue, IfFalse, Cond, AllocMarker, InsertBefore);
-  }
+                            Value *Cond, InsertPosition InsertBefore = nullptr);
 
   /// Transparently provide more efficient getOperand methods.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
 
-  bool isUnconditional() const { return getNumOperands() == 1; }
-  bool isConditional()   const { return getNumOperands() == 3; }
-
-  Value *getCondition() const {
-    assert(isConditional() && "Cannot get condition of an uncond branch!");
-    return Op<-3>();
-  }
+  // Defined out-of-line below to access CondBrInst.
+  bool isUnconditional() const;
+  bool isConditional() const;
 
-  void setCondition(Value *V) {
-    assert(isConditional() && "Cannot set condition of unconditional branch!");
-    Op<-3>() = V;
-  }
+  Value *getCondition() const;
+  void setCondition(Value *V);
 
   unsigned getNumSuccessors() const { return 1+isConditional(); }
 
@@ -3158,7 +3122,7 @@ class BranchInst : public Instruction {
   /// Swaps the successors of the branch instruction. This also swaps any
   /// branch weight metadata associated with the instruction so that it
   /// continues to map correctly to each operand.
-  LLVM_ABI void swapSuccessors();
+  void swapSuccessors();
 
   iterator_range<succ_op_iterator> successors() {
     return make_range(
@@ -3174,7 +3138,8 @@ class BranchInst : public Instruction {
 
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static bool classof(const Instruction *I) {
-    return (I->getOpcode() == Instruction::Br);
+    return (I->getOpcode() == Instruction::UncondBr ||
+            I->getOpcode() == Instruction::CondBr);
   }
   static bool classof(const Value *V) {
     return isa<Instruction>(V) && classof(cast<Instruction>(V));
@@ -3186,6 +3151,196 @@ struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst> {};
 
 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)
 
+//===----------------------------------------------------------------------===//
+//                               UncondBrInst Class
+//===----------------------------------------------------------------------===//
+
+//===---------------------------------------------------------------------------
+/// Unconditional Branch instruction.
+///
+class UncondBrInst : public BranchInst {
+  UncondBrInst(const UncondBrInst &BI, AllocInfo AllocInfo);
+  LLVM_ABI explicit UncondBrInst(BasicBlock *IfTrue, AllocInfo AllocInfo,
+                                 InsertPosition InsertBefore);
+
+protected:
+  // Note: Instruction needs to be a friend here to call cloneImpl.
+  friend class Instruction;
+
+  LLVM_ABI UncondBrInst *cloneImpl() const;
+
+public:
+  static UncondBrInst *Create(BasicBlock *IfTrue,
+                              InsertPosition InsertBefore = nullptr) {
+    IntrusiveOperandsAllocMarker AllocMarker{1};
+    return new (AllocMarker) UncondBrInst(IfTrue, AllocMarker, InsertBefore);
+  }
+
+  /// Transparently provide more efficient getOperand methods.
+  DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
+
+private:
+  // Hide methods.
+  using BranchInst::getCondition;
+  using BranchInst::isConditional;
+  using BranchInst::isUnconditional;
+  using BranchInst::setCondition;
+  using BranchInst::swapSuccessors;
+
+public:
+  unsigned getNumSuccessors() const { return 1; }
+
+  BasicBlock *getSuccessor(unsigned i = 0) const {
+    assert(i == 0 && "Successor # out of range for Branch!");
+    return cast_or_null<BasicBlock>(Op<-1>().get());
+  }
+
+  void setSuccessor(BasicBlock *NewSucc) { Op<-1>() = NewSucc; }
+  void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
+    assert(idx == 0 && "Successor # out of range for Branch!");
+    Op<-1>() = NewSucc;
+  }
+
+  iterator_range<succ_op_iterator> successors() {
+    return make_range(succ_op_iterator(value_op_begin()),
+                      succ_op_iterator(value_op_end()));
+  }
+
+  iterator_range<const_succ_op_iterator> successors() const {
+    return make_range(const_succ_op_iterator(value_op_begin()),
+                      const_succ_op_iterator(value_op_end()));
+  }
+
+  // Methods for support type inquiry through isa, cast, and dyn_cast:
+  static bool classof(const Instruction *I) {
+    return (I->getOpcode() == Instruction::UncondBr);
+  }
+  static bool classof(const Value *V) {
+    return isa<Instruction>(V) && classof(cast<Instruction>(V));
+  }
+};
+
+template <>
+struct OperandTraits<UncondBrInst>
+    : public FixedNumOperandTraits<UncondBrInst, 1> {};
+
+DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UncondBr...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/184027


More information about the Mlir-commits mailing list