[flang-commits] [flang] [flang][OpenACC] Generalize cross-region GOTO exit handling for all ACC region ops (PR #187613)
via flang-commits
flang-commits at lists.llvm.org
Mon Mar 23 02:50:41 PDT 2026
================
@@ -3677,6 +3693,40 @@ class FirConverter : public Fortran::lower::AbstractConverter {
localSymbols.popScope();
builder->restoreInsertionPoint(insertPt);
+ // Generate jump table for GOTO exits from the ACC region.
+ if (needsExitSelector) {
+ auto exitInfo = accRegionExitStack.pop_back_val();
+ if (!exitInfo.exits.empty()) {
+ mlir::Location loc = toLocation();
+ mlir::Value sel = fir::LoadOp::create(*builder, loc, exitInfo.selector);
+ mlir::Block *continueBlock =
+ builder->getBlock()->splitBlock(builder->getBlock()->end());
+ if (exitInfo.exits.size() == 1) {
+ mlir::Value id = builder->createIntegerConstant(
+ loc, builder->getI32Type(), exitInfo.exits[0].first);
+ mlir::Value cmp = mlir::arith::CmpIOp::create(
+ *builder, loc, mlir::arith::CmpIPredicate::eq, sel, id);
+ mlir::cf::CondBranchOp::create(
+ *builder, loc, cmp, exitInfo.exits[0].second, continueBlock);
+ } else {
+ // Multiple exit targets: chain of comparisons.
+ for (auto &[id, target] : exitInfo.exits) {
+ mlir::Value idVal =
+ builder->createIntegerConstant(loc, builder->getI32Type(), id);
+ mlir::Value cmp = mlir::arith::CmpIOp::create(
+ *builder, loc, mlir::arith::CmpIPredicate::eq, sel, idVal);
+ mlir::Block *nextCheck =
+ builder->getBlock()->splitBlock(builder->getBlock()->end());
+ mlir::cf::CondBranchOp::create(*builder, loc, cmp, target,
+ nextCheck);
+ builder->setInsertionPointToEnd(nextCheck);
+ }
----------------
jeanPerier wrote:
I think just having this loop instead of also having the special case for the 1 exit case is equivalent and less code (nextCheck will just construct the continueBlock in that case).
https://github.com/llvm/llvm-project/pull/187613
More information about the flang-commits
mailing list