[flang-commits] [flang] [ACC] Add support for force clause for loop collapse (PR #162534)

via flang-commits flang-commits at lists.llvm.org
Wed Oct 8 12:07:50 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- flang/lib/Lower/Bridge.cpp flang/lib/Lower/OpenACC.cpp
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 3d331cdad..2f624c81a 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -3195,7 +3195,7 @@ private:
     uint64_t collapseDepth = 1;
     uint64_t loopCount = 1;
     auto parseCollapse = [&](const Fortran::parser::AccClauseList &cl)
-                             -> std::pair<bool, uint64_t> {
+        -> std::pair<bool, uint64_t> {
       bool force = false;
       uint64_t depth = 1;
       for (const Fortran::parser::AccClause &clause : cl.v) {
@@ -3242,16 +3242,17 @@ private:
 
     const bool isStructured = curEval && curEval->lowerAsStructured();
     if (isStructured && collapseForce && collapseDepth > 1) {
-      // force: collect prologue/epilogue for the first collapseDepth nested loops
-      // and sink them into the innermost loop body at that depth
+      // force: collect prologue/epilogue for the first collapseDepth nested
+      // loops and sink them into the innermost loop body at that depth
       llvm::SmallVector<Fortran::lower::pft::Evaluation *> prologue, epilogue;
       Fortran::lower::pft::Evaluation *parent = &getEval();
       Fortran::lower::pft::Evaluation *innermostLoopEval = nullptr;
       for (uint64_t lvl = 0; lvl + 1 < collapseDepth; ++lvl) {
         epilogue.clear();
         auto &kids = parent->getNestedEvaluations();
-        // Collect all non-loop statements before the next inner loop as prologue,
-        // then mark remaining siblings as epilogue and descend into the inner loop.
+        // Collect all non-loop statements before the next inner loop as
+        // prologue, then mark remaining siblings as epilogue and descend into
+        // the inner loop.
         Fortran::lower::pft::Evaluation *childLoop = nullptr;
         for (auto it = kids.begin(); it != kids.end(); ++it) {
           if (it->getIf<Fortran::parser::DoConstruct>()) {
@@ -3271,8 +3272,10 @@ private:
 
       // Track sunk evaluations (avoid double-lowering)
       llvm::SmallPtrSet<const Fortran::lower::pft::Evaluation *, 16> sunk;
-      for (auto *e : prologue)  sunk.insert(e);
-      for (auto *e : epilogue)  sunk.insert(e);
+      for (auto *e : prologue)
+        sunk.insert(e);
+      for (auto *e : epilogue)
+        sunk.insert(e);
 
       auto sink =
           [&](llvm::SmallVector<Fortran::lower::pft::Evaluation *> &lst) {
@@ -3283,8 +3286,10 @@ private:
       sink(prologue);
 
       // Lower innermost loop body, skipping sunk
-      for (Fortran::lower::pft::Evaluation &e : innermostLoopEval->getNestedEvaluations())
-        if (!sunk.contains(&e)) genFIR(e);
+      for (Fortran::lower::pft::Evaluation &e :
+           innermostLoopEval->getNestedEvaluations())
+        if (!sunk.contains(&e))
+          genFIR(e);
 
       sink(epilogue);
     } else {

``````````

</details>


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


More information about the flang-commits mailing list