[llvm-branch-commits] [flang] [flang][OpenACC] Privatize nested DO variables of unstructured seq loops (PR #240800)

Kareem Ergawy via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Nov 10 03:59:53 PST 2026


https://github.com/ergawy created https://github.com/llvm/llvm-project/pull/240800

A DO nested in the body of an unstructured `acc loop seq` that the directive does not own has no acc.loop of its own when it is unstructured, so nothing privatized its induction variable and it hit the "unstructured do loop in acc kernels" TODO. It runs on the thread executing the seq loop, and its induction variable is predetermined private to that thread, so privatize it on the seq loop's acc.loop.

Factor the check for the default device_type in a list of device_type attributes into a helper, used here and by the two existing copies.

Stacked on https://github.com/llvm/llvm-project/pull/240777.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


>From 064aae012f74ca7e3e9b6a78e894b7f47f790733 Mon Sep 17 00:00:00 2001
From: ergawy <kareem.ergawy at gmail.com>
Date: Tue, 10 Nov 2026 03:16:11 -0800
Subject: [PATCH] [flang][OpenACC] Privatize nested DO variables of
 unstructured seq loops

A DO nested in the body of an unstructured `acc loop seq` that the
directive does not own has no acc.loop of its own when it is
unstructured, so nothing privatized its induction variable and it hit
the "unstructured do loop in acc kernels" TODO. It runs on the thread
executing the seq loop, and its induction variable is predetermined
private to that thread, so privatize it on the seq loop's acc.loop.

Factor the check for the default device_type in a list of device_type
attributes into a helper, used here and by the two existing copies.
---
 flang/lib/Lower/OpenACC.cpp                   | 100 ++++++++---
 .../Todo/do-loops-to-acc-loops-todo.f90       | 105 ------------
 .../acc-kernels-unstructured-seq-loop.f90     | 161 +++++++++++++++++-
 3 files changed, 240 insertions(+), 126 deletions(-)

diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index e7128289f4832..1edf31cec2502 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -1436,6 +1436,14 @@ static void gatherDeviceTypeAttrs(
         builder.getContext(), getDeviceType(deviceTypeExpr.v)));
 }
 
+// Returns true if `deviceTypes` holds the default device_type (none).
+static bool hasDefaultDeviceType(llvm::ArrayRef<mlir::Attribute> deviceTypes) {
+  return llvm::any_of(deviceTypes, [](mlir::Attribute attr) {
+    return mlir::cast<mlir::acc::DeviceTypeAttr>(attr).getValue() ==
+           mlir::acc::DeviceType::None;
+  });
+}
+
 // Tries to handle a clause that affects the loop's parallelism-mode tracking:
 //   - `seq` / `auto` / `independent`: append the current device_type set to
 //     the corresponding list.
@@ -1644,14 +1652,9 @@ static void determineDefaultLoopParMode(
     llvm::SmallVector<mlir::Attribute> &independentDeviceTypes,
     llvm::SmallVector<mlir::Attribute> &autoDeviceTypes,
     bool kernelsDoConcurrentIsIndependent) {
-  auto hasDeviceNone = [](mlir::Attribute attr) -> bool {
-    return mlir::dyn_cast<mlir::acc::DeviceTypeAttr>(attr).getValue() ==
-           mlir::acc::DeviceType::None;
-  };
-  bool hasDefaultSeq = llvm::any_of(seqDeviceTypes, hasDeviceNone);
-  bool hasDefaultIndependent =
-      llvm::any_of(independentDeviceTypes, hasDeviceNone);
-  bool hasDefaultAuto = llvm::any_of(autoDeviceTypes, hasDeviceNone);
+  bool hasDefaultSeq = hasDefaultDeviceType(seqDeviceTypes);
+  bool hasDefaultIndependent = hasDefaultDeviceType(independentDeviceTypes);
+  bool hasDefaultAuto = hasDefaultDeviceType(autoDeviceTypes);
   if (hasDefaultSeq || hasDefaultIndependent || hasDefaultAuto)
     return; // Default loop par mode is already specified.
 
@@ -1736,15 +1739,10 @@ loopWillBeIndependent(Fortran::lower::AbstractConverter &converter,
     tryHandleLoopParModeClause(builder, clause, crtDeviceTypes, seqDeviceTypes,
                                independentDeviceTypes, autoDeviceTypes);
 
-  auto hasDeviceNone = [](mlir::Attribute attr) -> bool {
-    return mlir::dyn_cast<mlir::acc::DeviceTypeAttr>(attr).getValue() ==
-           mlir::acc::DeviceType::None;
-  };
-
-  if (llvm::any_of(independentDeviceTypes, hasDeviceNone))
+  if (hasDefaultDeviceType(independentDeviceTypes))
     return true;
-  if (llvm::any_of(seqDeviceTypes, hasDeviceNone) ||
-      llvm::any_of(autoDeviceTypes, hasDeviceNone))
+  if (hasDefaultDeviceType(seqDeviceTypes) ||
+      hasDefaultDeviceType(autoDeviceTypes))
     return false;
 
   // No explicit parallelism clause for the default device_type. Defer to the
@@ -2293,6 +2291,64 @@ void AccDataMap::remapDataOperandSymbols(
   }
 }
 
+/// For an unstructured `acc loop seq` construct \p eval, privatize the
+/// induction variables of the unstructured DOs nested in its body that it does
+/// not own. Such a DO has no acc.loop of its own to privatize its induction
+/// variable, as a structured DO does. It runs entirely on the thread executing
+/// the seq loop, so the seq loop's acc.loop privatizes it. OpenACC 3.4,
+/// section 2.6.1 "Variables with Predetermined Data Attributes":
+///
+///   Loop variables in Fortran do statements within a compute construct are
+///   predetermined to be private to the thread that executes the loop.
+///
+/// For example:
+///
+///   !$acc loop seq                 ! acc.loop private(k, l), seq unstructured
+///   kloop: do k = 1, m             ! owned: privatized by
+///                                  !   privatizeInductionVariables
+///     do l = 1, p                  ! nested: privatized here
+///       if (b(l, k) > 0.0) exit kloop
+///     end do
+///   end do kloop
+///
+/// Structured DOs are left alone: they get an acc.loop of their own. DOs in a
+/// nested OpenACC construct belong to that construct.
+static void privatizeNestedUnstructuredDoIvs(
+    Fortran::lower::AbstractConverter &converter,
+    Fortran::lower::pft::Evaluation &eval,
+    llvm::SmallVector<mlir::Value> &privateOperands,
+    llvm::SmallVectorImpl<std::pair<mlir::Value, Fortran::semantics::SymbolRef>>
+        &ivPrivate) {
+  // No acc.loop control arguments are created for these induction variables.
+  llvm::SmallVector<mlir::Type> ivTypes;
+  llvm::SmallVector<mlir::Location> ivLocs;
+  std::function<void(Fortran::lower::pft::Evaluation &)> visit =
+      [&](Fortran::lower::pft::Evaluation &parent) {
+        for (Fortran::lower::pft::Evaluation &nested :
+             parent.getNestedEvaluations()) {
+          if (nested.isA<Fortran::parser::OpenACCConstruct>())
+            continue;
+          if (const auto *doConstruct =
+                  nested.getIf<Fortran::parser::DoConstruct>())
+            if (nested.lowerAsUnstructured() && doConstruct->IsDoNormal()) {
+              const auto &bounds =
+                  std::get<Fortran::parser::LoopControl::Bounds>(
+                      doConstruct->GetLoopControl()->u);
+              // privatizeIv reuses the private copy of an induction variable
+              // that is already privatized, such as the owned DO's.
+              privatizeIv(
+                  converter, bounds.Name().thing.symbol->GetUltimate(),
+                  converter.genLocation(
+                      Fortran::parser::FindSourceLocation(*doConstruct)),
+                  ivTypes, ivLocs, privateOperands, ivPrivate);
+            }
+          if (nested.hasNestedEvaluations())
+            visit(nested);
+        }
+      };
+  visit(eval);
+}
+
 static void privatizeInductionVariables(
     Fortran::lower::AbstractConverter &converter,
     mlir::Location currentLocation,
@@ -2345,7 +2401,7 @@ buildACCLoopOp(Fortran::lower::AbstractConverter &converter,
                llvm::SmallVector<mlir::Value> &cacheOperands,
                llvm::SmallVector<mlir::Value> &reductionOperands,
                llvm::SmallVector<mlir::Type> &retTy, mlir::Value yieldValue,
-               uint64_t loopsToProcess, bool hasDirective) {
+               uint64_t loopsToProcess, bool hasDirective, bool isSeq = false) {
   fir::FirOpBuilder &builder = converter.getFirOpBuilder();
 
   llvm::SmallVector<std::pair<mlir::Value, Fortran::semantics::SymbolRef>>
@@ -2376,6 +2432,9 @@ buildACCLoopOp(Fortran::lower::AbstractConverter &converter,
     privatizeInductionVariables(converter, currentLocation, outerDoConstruct,
                                 eval, privateOperands, ivPrivate, locs,
                                 loopsToProcess);
+    if (isSeq)
+      privatizeNestedUnstructuredDoIvs(converter, eval, privateOperands,
+                                       ivPrivate);
   }
   llvm::SmallVector<mlir::Value> operands;
   llvm::SmallVector<int32_t> operandSegments;
@@ -2719,7 +2778,8 @@ static mlir::acc::LoopOp createLoopOp(
       eval, privateOperands, firstprivateOperands, dataMap, gangOperands,
       workerNumOperands, vectorOperands, tileOperands, cacheOperands,
       reductionOperands, retTy, yieldValue, loopsToProcess,
-      /*hasDirective=*/true);
+      /*hasDirective=*/true,
+      /*isSeq=*/hasDefaultDeviceType(seqDeviceTypes));
 
   if (!gangDeviceTypes.empty())
     loopOp.setGangAttr(builder.getArrayAttr(gangDeviceTypes));
@@ -5747,8 +5807,8 @@ static bool isDoOfContainedUnstructuredSeqLoop(
   //
   // In the example, k and l are bound to `hlfir.declare %k_private` and
   // `hlfir.declare %l_private`, both private operands of currentLoop. Without
-  // collapse(2), currentLoop would privatize only k, and the DO over l -- then
-  // a plain DO in the seq loop's body -- would not qualify.
+  // collapse(2), the DO over l is a plain DO in the seq loop's body, and
+  // currentLoop privatizes l as well (see privatizeNestedUnstructuredDoIvs).
   const auto *bounds = std::get_if<Fortran::parser::LoopControl::Bounds>(
       &doConstruct.GetLoopControl()->u);
   if (!bounds)
diff --git a/flang/test/Lower/OpenACC/Todo/do-loops-to-acc-loops-todo.f90 b/flang/test/Lower/OpenACC/Todo/do-loops-to-acc-loops-todo.f90
index e3687d1e2e23a..e9d1177b02177 100644
--- a/flang/test/Lower/OpenACC/Todo/do-loops-to-acc-loops-todo.f90
+++ b/flang/test/Lower/OpenACC/Todo/do-loops-to-acc-loops-todo.f90
@@ -6,10 +6,6 @@
 ! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/collapse_nested.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK6
 ! RUN: bbc -fopenacc -pft-test -o /dev/null %t/seq_exit_in_kernels.f90 | FileCheck %s --check-prefix=PFT9
 ! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/seq_exit_in_kernels.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK9
-! RUN: bbc -fopenacc -pft-test -o /dev/null %t/plain_do_in_seq_loop.f90 | FileCheck %s --check-prefix=PFT10
-! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/plain_do_in_seq_loop.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK10
-! RUN: bbc -fopenacc -pft-test -o /dev/null %t/collapse_force_sibling_do.f90 | FileCheck %s --check-prefix=PFT11
-! RUN: %not_todo_cmd bbc -fopenacc -emit-hlfir %t/collapse_force_sibling_do.f90 -o - 2>&1 | FileCheck %s --check-prefix=CHECK11
 
 //--- do_loop_with_cycle_goto.f90
 
@@ -138,104 +134,3 @@ subroutine seq_exit_in_kernels(m, b, kfirst)
 ! CHECK9: {{.*}}seq_exit_in_kernels.f90":13:3){{.*}}not yet implemented: unstructured do loop in acc kernels
 
 end subroutine
-
-//--- plain_do_in_seq_loop.f90
-
-! A plain DO in the body of a contained seq loop, leaving the seq loop with a
-! named EXIT. The seq acc.loop does not own the plain DO, so it does not
-! privatize its induction variable.
-subroutine plain_do_in_seq_loop(n, m, p, b, kref)
-  integer :: n, m, p
-  real :: b(p, m, n)
-  integer :: kref(n)
-  integer :: i, k, l
-  !$acc kernels
-  do i = 1, n
-    kref(i) = 0
-    !$acc loop seq
-    kloop: do k = 1, m
-      do l = 1, p
-        if (b(l, k, i) > 0.0) then
-          kref(i) = k
-          exit kloop
-        end if
-      end do
-    end do kloop
-  end do
-  !$acc end kernels
-
-! PFT10-LABEL: Subroutine plain_do_in_seq_loop
-! PFT10:         <<OpenACCConstruct~>>
-! PFT10-NEXT:      <<DoConstruct~>>
-! PFT10-NEXT:        NonLabelDoStmt {{.*}}: do i = 1, n
-! PFT10:             <<OpenACCConstruct!>>
-! PFT10-NEXT:          <<DoConstruct!>>
-! PFT10-NEXT:            NonLabelDoStmt {{.*}}: kloop: do k = 1, m
-! PFT10-NEXT:            <<DoConstruct!>>
-! PFT10-NEXT:              NonLabelDoStmt {{.*}}: do l = 1, p
-! PFT10:                   ExitStmt! {{.*}}: exit kloop
-! PFT10:                 <<End DoConstruct!>>
-! PFT10:               <<End DoConstruct!>>
-! PFT10:             <<End OpenACCConstruct!>>
-! PFT10:           <<End DoConstruct~>>
-! PFT10:         <<End OpenACCConstruct~>>
-
-! The `!` DO over k lowers into the seq acc.loop, which privatizes k. Lowering
-! stops at the `!` DO over l (line 15): the acc.loop does not privatize l.
-! CHECK10: {{.*}}plain_do_in_seq_loop.f90":15:7){{.*}}not yet implemented: unstructured do loop in acc kernels
-
-end subroutine
-
-//--- collapse_force_sibling_do.f90
-
-! A contained seq loop with collapse(force:2). The collapse absorbs only the
-! first DO nested in the outer one, so the seq acc.loop privatizes k and l but
-! not q, although the DO over q is as deeply nested as the one over l.
-subroutine collapse_force_sibling_do(n, m, p, b, kref)
-  integer :: n, m, p
-  real :: b(p, m, n)
-  integer :: kref(n)
-  integer :: i, k, l, q
-  !$acc kernels
-  do i = 1, n
-    kref(i) = 0
-    !$acc loop seq collapse(force:2)
-    kloop: do k = 1, m
-      do l = 1, p
-        kref(i) = kref(i) + 1
-      end do
-      do q = 1, p
-        if (b(q, k, i) > 0.0) then
-          kref(i) = k
-          exit kloop
-        end if
-      end do
-    end do kloop
-  end do
-  !$acc end kernels
-
-! PFT11-LABEL: Subroutine collapse_force_sibling_do
-! PFT11:         <<OpenACCConstruct~>>
-! PFT11-NEXT:      <<DoConstruct~>>
-! PFT11-NEXT:        NonLabelDoStmt {{.*}}: do i = 1, n
-! PFT11:             <<OpenACCConstruct!>>
-! PFT11-NEXT:          <<DoConstruct!>>
-! PFT11-NEXT:            NonLabelDoStmt {{.*}}: kloop: do k = 1, m
-! PFT11-NEXT:            <<DoConstruct>>
-! PFT11-NEXT:              NonLabelDoStmt {{.*}}: do l = 1, p
-! PFT11:                 <<End DoConstruct>>
-! PFT11-NEXT:            <<DoConstruct!>>
-! PFT11-NEXT:              NonLabelDoStmt {{.*}}: do q = 1, p
-! PFT11:                   ExitStmt! {{.*}}: exit kloop
-! PFT11:                 <<End DoConstruct!>>
-! PFT11:               <<End DoConstruct!>>
-! PFT11:             <<End OpenACCConstruct!>>
-! PFT11:           <<End DoConstruct~>>
-! PFT11:         <<End OpenACCConstruct~>>
-
-! The `!` DO over k lowers into the seq acc.loop, which privatizes k and l. The
-! structured DO over l lowers as a structured loop. Lowering stops at the `!`
-! DO over q (line 18): the acc.loop does not privatize q.
-! CHECK11: {{.*}}collapse_force_sibling_do.f90":18:7){{.*}}not yet implemented: unstructured do loop in acc kernels
-
-end subroutine
diff --git a/flang/test/Lower/OpenACC/acc-kernels-unstructured-seq-loop.f90 b/flang/test/Lower/OpenACC/acc-kernels-unstructured-seq-loop.f90
index e7f3d7a50cb9e..a9b6f2346e62a 100644
--- a/flang/test/Lower/OpenACC/acc-kernels-unstructured-seq-loop.f90
+++ b/flang/test/Lower/OpenACC/acc-kernels-unstructured-seq-loop.f90
@@ -2,7 +2,8 @@
 ! makes the seq loop unstructured, but its enclosing loop keeps its branching
 ! inside its body, so the seq loop's control flow is contained there: the
 ! enclosing loop stays a structured acc.loop with bounds, and the seq acc.loop
-! privatizes the induction variables of the DOs it owns.
+! privatizes the induction variables of the DOs it owns and of the
+! unstructured DOs nested in its body.
 !
 ! In the pre-FIR tree, the seq loop and its `acc loop` construct are
 ! unstructured (!), while the enclosing loop and the kernels construct are
@@ -138,3 +139,161 @@ subroutine seq_collapse_exit_in_loop(n, m, p, b, kref)
 ! CHECK:           } inclusiveUpperbound(array<i1: true>) auto_
 ! CHECK:           acc.terminator
 ! CHECK:         }
+
+! A plain DO in the body of the seq loop, leaving the seq loop with a named
+! EXIT. The seq loop does not own the plain DO, but the DO runs on the thread
+! executing the seq loop, so the seq acc.loop privatizes its induction variable
+! too.
+subroutine plain_do_in_seq_loop(n, m, p, b, kref)
+  integer :: n, m, p
+  real :: b(p, m, n)
+  integer :: kref(n)
+  integer :: i, k, l
+  !$acc kernels
+  do i = 1, n
+    kref(i) = 0
+    !$acc loop seq
+    kloop: do k = 1, m
+      do l = 1, p
+        if (b(l, k, i) > 0.0) then
+          kref(i) = k
+          exit kloop
+        end if
+      end do
+    end do kloop
+  end do
+  !$acc end kernels
+end subroutine
+
+! PFT-LABEL: Subroutine plain_do_in_seq_loop
+! PFT:         <<OpenACCConstruct~>>
+! PFT-NEXT:      <<DoConstruct~>>
+! PFT-NEXT:        NonLabelDoStmt {{.*}}: do i = 1, n
+! PFT:             <<OpenACCConstruct!>>
+! PFT-NEXT:          <<DoConstruct!>>
+! PFT-NEXT:            NonLabelDoStmt {{.*}}: kloop: do k = 1, m
+! PFT-NEXT:            <<DoConstruct!>>
+! PFT-NEXT:              NonLabelDoStmt {{.*}}: do l = 1, p
+! PFT:                   ExitStmt! {{.*}}: exit kloop
+! PFT:                 <<End DoConstruct!>>
+! PFT:               <<End DoConstruct!>>
+! PFT:             <<End OpenACCConstruct!>>
+! PFT:           <<End DoConstruct~>>
+! PFT:         <<End OpenACCConstruct~>>
+
+! The PFT nodes above lower to:
+!   <<OpenACCConstruct~>> kernels  -> acc.kernels
+!   <<DoConstruct~>> do i          -> acc.loop with bounds (auto_), its body in
+!                                     an scf.execute_region
+!   <<OpenACCConstruct!>> loop seq -> acc.loop private(k, l) without bounds
+!                                     (seq unstructured)
+!   <<DoConstruct!>> do k, do l    -> CFG blocks inside that acc.loop
+! CHECK-LABEL: func.func @_QPplain_do_in_seq_loop
+! CHECK:         %[[I_DECL:.*]]:2 = hlfir.declare %{{.*}} uniq_name("_QFplain_do_in_seq_loopEi")
+! CHECK:         %[[K_DECL:.*]]:2 = hlfir.declare %{{.*}} uniq_name("_QFplain_do_in_seq_loopEk")
+! CHECK:         %[[L_DECL:.*]]:2 = hlfir.declare %{{.*}} uniq_name("_QFplain_do_in_seq_loopEl")
+! CHECK:         acc.kernels {
+! CHECK:           %[[I_PRIV:.*]] = acc.private varPtr(%[[I_DECL]]#0 : !fir.ref<i32>) recipe(@privatization_ref_i32) implicit(true) name("i")
+! CHECK:           acc.loop private(%[[I_PRIV]] : !fir.ref<i32>) control(%{{.*}} : i32) = (%{{.*}} : i32) to (%{{.*}} : i32)  step (%{{.*}} : i32) {
+! CHECK:             hlfir.declare %[[I_PRIV]] uniq_name("_QFplain_do_in_seq_loopEi")
+! CHECK:             scf.execute_region no_inline {
+! CHECK:               %[[K_PRIV:.*]] = acc.private varPtr(%[[K_DECL]]#0 : !fir.ref<i32>) recipe(@privatization_ref_i32) implicit(true) name("k")
+! CHECK:               %[[L_PRIV:.*]] = acc.private varPtr(%[[L_DECL]]#0 : !fir.ref<i32>) recipe(@privatization_ref_i32) implicit(true) name("l")
+! CHECK:               acc.loop private(%[[K_PRIV]], %[[L_PRIV]] : !fir.ref<i32>, !fir.ref<i32>) {
+! CHECK:                 hlfir.declare %[[K_PRIV]] uniq_name("_QFplain_do_in_seq_loopEk")
+! CHECK:                 hlfir.declare %[[L_PRIV]] uniq_name("_QFplain_do_in_seq_loopEl")
+! CHECK:                 acc.yield
+! CHECK:               } seq  unstructured
+! CHECK:               scf.yield
+! CHECK:             }
+! CHECK:             acc.yield
+! CHECK:           } inclusiveUpperbound(array<i1: true>) auto_
+! CHECK:           acc.terminator
+! CHECK:         }
+
+! collapse(force:2) absorbs only the first DO nested in the DO over k, the one
+! over l. The DO over q next to it is a plain DO of the seq loop's body, so the
+! seq acc.loop privatizes k, l and q. The DO over l is structured and also gets
+! an acc.loop of its own.
+subroutine collapse_force_sibling_do(n, m, p, b, kref)
+  integer :: n, m, p
+  real :: b(p, m, n)
+  integer :: kref(n)
+  integer :: i, k, l, q
+  !$acc kernels
+  do i = 1, n
+    kref(i) = 0
+    !$acc loop seq collapse(force:2)
+    kloop: do k = 1, m
+      do l = 1, p
+        kref(i) = kref(i) + 1
+      end do
+      do q = 1, p
+        if (b(q, k, i) > 0.0) then
+          kref(i) = k
+          exit kloop
+        end if
+      end do
+    end do kloop
+  end do
+  !$acc end kernels
+end subroutine
+
+! PFT-LABEL: Subroutine collapse_force_sibling_do
+! PFT:         <<OpenACCConstruct~>>
+! PFT-NEXT:      <<DoConstruct~>>
+! PFT-NEXT:        NonLabelDoStmt {{.*}}: do i = 1, n
+! PFT:             <<OpenACCConstruct!>>
+! PFT-NEXT:          <<DoConstruct!>>
+! PFT-NEXT:            NonLabelDoStmt {{.*}}: kloop: do k = 1, m
+! PFT-NEXT:            <<DoConstruct>>
+! PFT-NEXT:              NonLabelDoStmt {{.*}}: do l = 1, p
+! PFT:                 <<End DoConstruct>>
+! PFT-NEXT:            <<DoConstruct!>>
+! PFT-NEXT:              NonLabelDoStmt {{.*}}: do q = 1, p
+! PFT:                   ExitStmt! {{.*}}: exit kloop
+! PFT:                 <<End DoConstruct!>>
+! PFT:               <<End DoConstruct!>>
+! PFT:             <<End OpenACCConstruct!>>
+! PFT:           <<End DoConstruct~>>
+! PFT:         <<End OpenACCConstruct~>>
+
+! The PFT nodes above lower to:
+!   <<OpenACCConstruct~>> kernels  -> acc.kernels
+!   <<DoConstruct~>> do i          -> acc.loop with bounds (auto_), its body in
+!                                     an scf.execute_region
+!   <<OpenACCConstruct!>> loop seq -> acc.loop private(k, l, q) without bounds
+!                                     (collapse 2, seq unstructured)
+!   <<DoConstruct!>> do k, do q    -> CFG blocks inside that acc.loop
+!   <<DoConstruct>> do l           -> acc.loop with bounds (auto_) inside that
+!                                     acc.loop
+! CHECK-LABEL: func.func @_QPcollapse_force_sibling_do
+! CHECK:         %[[I_DECL:.*]]:2 = hlfir.declare %{{.*}} uniq_name("_QFcollapse_force_sibling_doEi")
+! CHECK:         %[[K_DECL:.*]]:2 = hlfir.declare %{{.*}} uniq_name("_QFcollapse_force_sibling_doEk")
+! CHECK:         %[[L_DECL:.*]]:2 = hlfir.declare %{{.*}} uniq_name("_QFcollapse_force_sibling_doEl")
+! CHECK:         %[[Q_DECL:.*]]:2 = hlfir.declare %{{.*}} uniq_name("_QFcollapse_force_sibling_doEq")
+! CHECK:         acc.kernels {
+! CHECK:           %[[I_PRIV:.*]] = acc.private varPtr(%[[I_DECL]]#0 : !fir.ref<i32>) recipe(@privatization_ref_i32) implicit(true) name("i")
+! CHECK:           acc.loop private(%[[I_PRIV]] : !fir.ref<i32>) control(%{{.*}} : i32) = (%{{.*}} : i32) to (%{{.*}} : i32)  step (%{{.*}} : i32) {
+! CHECK:             hlfir.declare %[[I_PRIV]] uniq_name("_QFcollapse_force_sibling_doEi")
+! CHECK:             scf.execute_region no_inline {
+! CHECK:               %[[K_PRIV:.*]] = acc.private varPtr(%[[K_DECL]]#0 : !fir.ref<i32>) recipe(@privatization_ref_i32) implicit(true) name("k")
+! CHECK:               %[[L_PRIV:.*]] = acc.private varPtr(%[[L_DECL]]#0 : !fir.ref<i32>) recipe(@privatization_ref_i32) implicit(true) name("l")
+! CHECK:               %[[Q_PRIV:.*]] = acc.private varPtr(%[[Q_DECL]]#0 : !fir.ref<i32>) recipe(@privatization_ref_i32) implicit(true) name("q")
+! CHECK:               acc.loop private(%[[K_PRIV]], %[[L_PRIV]], %[[Q_PRIV]] : !fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>) {
+! CHECK:                 hlfir.declare %[[K_PRIV]] uniq_name("_QFcollapse_force_sibling_doEk")
+! CHECK:                 %[[L_SEQ:.*]]:2 = hlfir.declare %[[L_PRIV]] uniq_name("_QFcollapse_force_sibling_doEl")
+! CHECK:                 hlfir.declare %[[Q_PRIV]] uniq_name("_QFcollapse_force_sibling_doEq")
+! CHECK:                 %[[L_INNER:.*]] = acc.private varPtr(%[[L_SEQ]]#0 : !fir.ref<i32>) recipe(@privatization_ref_i32) implicit(true) name("l")
+! CHECK:                 acc.loop private(%[[L_INNER]] : !fir.ref<i32>) control(%{{.*}} : i32) = (%{{.*}} : i32) to (%{{.*}} : i32)  step (%{{.*}} : i32) {
+! CHECK:                   hlfir.declare %[[L_INNER]] uniq_name("_QFcollapse_force_sibling_doEl")
+! CHECK:                   acc.yield
+! CHECK:                 } inclusiveUpperbound(array<i1: true>) auto_
+! CHECK:                 acc.yield
+! CHECK:               } collapse([2]) collapseDeviceType([#acc.device_type<none>]) seq  unstructured
+! CHECK:               scf.yield
+! CHECK:             }
+! CHECK:             acc.yield
+! CHECK:           } inclusiveUpperbound(array<i1: true>) auto_
+! CHECK:           acc.terminator
+! CHECK:         }



More information about the llvm-branch-commits mailing list