[MLIR][LLVMIR][NFC] Drop uses of BranchInst (#187304)

This commit is contained in:
Alexis Engelke 2026-03-18 16:55:10 +01:00 committed by GitHub
parent bfedc2aa76
commit 4c745df8bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 17 deletions

View File

@ -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<LLVM::BrOp>(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<LLVM::CondBrOp>(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)));

View File

@ -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(

View File

@ -2129,11 +2129,10 @@ buildDependData(std::optional<ArrayAttr> 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<llvm::BranchInst *> &cancelTerminators,
llvm::IRBuilderBase &llvmBuilder,
llvm::OpenMPIRBuilder &ompBuilder, mlir::Operation *op,
llvm::omp::Directive cancelDirective) {
static void pushCancelFinalizationCB(
SmallVectorImpl<llvm::UncondBrInst *> &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<llvm::BranchInst *> &cancelTerminators,
/// is immediately before the continuation block. Now this finalization has
/// been created we can fix the branch.
static void
popCancelFinalizationCB(const ArrayRef<llvm::BranchInst *> cancelTerminators,
popCancelFinalizationCB(const ArrayRef<llvm::UncondBrInst *> 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<llvm::BranchInst *> cancelTerminators;
SmallVector<llvm::UncondBrInst *> 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<llvm::BranchInst *> cancelTerminators;
SmallVector<llvm::UncondBrInst *> 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<llvm::BranchInst *> cancelTerminators;
SmallVector<llvm::UncondBrInst *> cancelTerminators;
pushCancelFinalizationCB(cancelTerminators, builder, *ompBuilder, wsloopOp,
llvm::omp::Directive::OMPD_for);