From 4c745df8bc90d3271a6612bee2fa39afe9ab1dad Mon Sep 17 00:00:00 2001 From: Alexis Engelke Date: Wed, 18 Mar 2026 16:55:10 +0100 Subject: [PATCH] [MLIR][LLVMIR][NFC] Drop uses of BranchInst (#187304) --- .../LLVMIR/LLVMToLLVMIRTranslation.cpp | 4 ++-- .../OpenACC/OpenACCToLLVMIRTranslation.cpp | 2 +- .../OpenMP/OpenMPToLLVMIRTranslation.cpp | 24 ++++++++----------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp index e60a682b42ea..8c3680033b2b 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp @@ -685,14 +685,14 @@ convertOperationImpl(Operation &opInst, llvm::IRBuilderBase &builder, // Emit branches. We need to look up the remapped blocks and ignore the // block arguments that were transformed into PHI nodes. if (auto brOp = dyn_cast(opInst)) { - llvm::BranchInst *branch = + llvm::UncondBrInst *branch = builder.CreateBr(moduleTranslation.lookupBlock(brOp.getSuccessor())); moduleTranslation.mapBranch(&opInst, branch); moduleTranslation.setLoopMetadata(&opInst, branch); return success(); } if (auto condbrOp = dyn_cast(opInst)) { - llvm::BranchInst *branch = builder.CreateCondBr( + llvm::CondBrInst *branch = builder.CreateCondBr( moduleTranslation.lookupValue(condbrOp.getOperand(0)), moduleTranslation.lookupBlock(condbrOp.getSuccessor(0)), moduleTranslation.lookupBlock(condbrOp.getSuccessor(1))); diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp index 97c6b4e25542..9bb693904362 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenACC/OpenACCToLLVMIRTranslation.cpp @@ -383,7 +383,7 @@ static LogicalResult convertDataOp(acc::DataOp &op, auto afterDataRegion = builder.saveIP(); - llvm::BranchInst *sourceTerminator = builder.CreateBr(entryBlock); + llvm::UncondBrInst *sourceTerminator = builder.CreateBr(entryBlock); builder.restoreIP(afterDataRegion); llvm::BasicBlock *endDataBlock = llvm::BasicBlock::Create( diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp index 37b1a37c2e1a..42fdadaba0da 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -2129,11 +2129,10 @@ buildDependData(std::optional dependKinds, OperandRange dependVars, /// if there is cancellation inside of the taskgroup body. /// The terminator will need to be fixed to branch to the correct block to /// cleanup the construct. -static void -pushCancelFinalizationCB(SmallVectorImpl &cancelTerminators, - llvm::IRBuilderBase &llvmBuilder, - llvm::OpenMPIRBuilder &ompBuilder, mlir::Operation *op, - llvm::omp::Directive cancelDirective) { +static void pushCancelFinalizationCB( + SmallVectorImpl &cancelTerminators, + llvm::IRBuilderBase &llvmBuilder, llvm::OpenMPIRBuilder &ompBuilder, + mlir::Operation *op, llvm::omp::Directive cancelDirective) { auto finiCB = [&](llvm::OpenMPIRBuilder::InsertPointTy ip) -> llvm::Error { llvm::IRBuilderBase::InsertPointGuard guard(llvmBuilder); @@ -2160,16 +2159,13 @@ pushCancelFinalizationCB(SmallVectorImpl &cancelTerminators, /// is immediately before the continuation block. Now this finalization has /// been created we can fix the branch. static void -popCancelFinalizationCB(const ArrayRef cancelTerminators, +popCancelFinalizationCB(const ArrayRef cancelTerminators, llvm::OpenMPIRBuilder &ompBuilder, const llvm::OpenMPIRBuilder::InsertPointTy &afterIP) { ompBuilder.popFinalizationCB(); llvm::BasicBlock *constructFini = afterIP.getBlock()->getSinglePredecessor(); - for (llvm::BranchInst *cancelBranch : cancelTerminators) { - assert(cancelBranch->getNumSuccessors() == 1 && - "cancel branch should have one target"); - cancelBranch->setSuccessor(0, constructFini); - } + for (llvm::UncondBrInst *cancelBranch : cancelTerminators) + cancelBranch->setSuccessor(constructFini); } namespace { @@ -2811,7 +2807,7 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase &builder, }; llvm::OpenMPIRBuilder &ompBuilder = *moduleTranslation.getOpenMPBuilder(); - SmallVector cancelTerminators; + SmallVector cancelTerminators; // The directive to match here is OMPD_taskgroup because it is the taskgroup // which is canceled. This is handled here because it is the task's cleanup // block which should be branched to. @@ -3197,7 +3193,7 @@ convertOmpTaskloopOp(Operation &opInst, llvm::IRBuilderBase &builder, taskDupOrNull = taskDupCB; llvm::OpenMPIRBuilder &ompBuilder = *moduleTranslation.getOpenMPBuilder(); - SmallVector cancelTerminators; + SmallVector cancelTerminators; // The directive to match here is OMPD_taskgroup because it is the // taskgroup which is canceled. This is handled here because it is the // task's cleanup block which should be branched to. It doesn't depend upon @@ -3365,7 +3361,7 @@ convertOmpWsloop(Operation &opInst, llvm::IRBuilderBase &builder, ? llvm::omp::WorksharingLoopType::DistributeForStaticLoop : llvm::omp::WorksharingLoopType::ForStaticLoop; - SmallVector cancelTerminators; + SmallVector cancelTerminators; pushCancelFinalizationCB(cancelTerminators, builder, *ompBuilder, wsloopOp, llvm::omp::Directive::OMPD_for);