[all-commits] [llvm/llvm-project] e90ba2: [flang][PFT-to-MLIR] Wrap unstructured Fortran con...

Kareem Ergawy via All-commits all-commits at lists.llvm.org
Fri Jul 17 01:09:47 PDT 2026


  Branch: refs/heads/users/ergawy/enclode_in_scf.execute_region
  Home:   https://github.com/llvm/llvm-project
  Commit: e90ba2617e7cfb04c935ba3b16265e94baa18e21
      https://github.com/llvm/llvm-project/commit/e90ba2617e7cfb04c935ba3b16265e94baa18e21
  Author: ergawy <kareem.ergawy at gmail.com>
  Date:   2026-07-17 (Fri, 17 Jul 2026)

  Changed paths:
    M flang/include/flang/Lower/PFTBuilder.h
    M flang/lib/Lower/Bridge.cpp
    M flang/lib/Lower/PFTBuilder.cpp
    M flang/lib/Lower/Runtime.cpp
    M flang/test/HLFIR/assumed_shape_with_value_keyword.f90
    M flang/test/HLFIR/optional_dummy.f90
    M flang/test/Integration/OpenMP/parallel-private-reduction-worstcase.f90
    M flang/test/Lower/HLFIR/intrinsic-subroutines.f90
    M flang/test/Lower/MIF/change_team2.f90
    M flang/test/Lower/OpenACC/Todo/acc-unstructured-combined-construct.f90
    M flang/test/Lower/OpenACC/Todo/do-loops-to-acc-loops-todo.f90
    M flang/test/Lower/OpenACC/acc-terminator.f90
    M flang/test/Lower/OpenACC/acc-unstructured.f90
    M flang/test/Lower/OpenMP/loop-compound.f90
    M flang/test/Lower/OpenMP/parallel-reduction3.f90
    M flang/test/Lower/OpenMP/stop-stmt-in-region.f90
    M flang/test/Lower/OpenMP/unstructured.f90
    M flang/test/Lower/OpenMP/wsloop-unstructured.f90
    M flang/test/Lower/branching-directive.f90
    A flang/test/Lower/do_loop_execute_region_wrap.f90
    M flang/test/Lower/do_loop_unstructured.f90
    M flang/test/Lower/fail_image.f90
    M flang/test/Lower/ifconvert.f90
    M flang/test/Lower/mixed_loops.f90
    M flang/test/Lower/nsw.f90
    M flang/test/Lower/pre-fir-tree02.f90
    M flang/test/Lower/while_loop.f90

  Log Message:
  -----------
  [flang][PFT-to-MLIR] Wrap unstructured Fortran constructs in scf.execute_region

Extend the PFT-to-MLIR (HLFIR/FIR) lowering so unstructured DO and IF
constructs are emitted inside scf.execute_region, hiding their multi-block
CFG behind a single op. OpenACC and OpenMP lowerings that reject
multi-block content (e.g. the "unstructured do loop in combined acc
construct" TODO in OpenACC.cpp) now see a structured op instead.

Flag: -mmlir --wrap-unstructured-constructs-in-execute-region (default on).

An evaluation is wrappable iff all of the following hold:

  * wrap flag on
  * eval is parser::DoConstruct or parser::IfConstruct
  * eval.isUnstructured
  * branchesAreInternal(eval) -- every controlSuccessor in the subtree
    targets a nested eval or the constructExit
  * !hasIncomingBranch(eval) -- no outside eval branches into the body
    (PFT's synthetic IfConstruct around `if(c) goto X` absorbs label
    targets between the IF and X; the incoming-branch check excludes
    such wrappers when an outer GOTO names one of those labels)
  * does not contain a ReturnStmt -- its lowering creates the function's
    final block in the current region, which would mis-parent func.return
  * not an infinite DO and does not contain one (no LoopControl in any
    nested DO): the wrap's yield is unreachable and the body has no
    write-shaped side effects, so RegionDCE treats the wrap as trivially
    dead and drops it. Excluding the whole enclosing construct keeps
    such infinite loops visible in the parent CFG.
  * not the body DO of an enclosing OpenACCLoopConstruct or
    OpenACCCombinedConstruct -- nor one of the N collapsed iterator DOs
    reached by walking down through `collapse(N)`. Such DOs are driven
    directly into acc.loop by the OpenACC lowering, so wrapping them
    would hide the iteration from the acc.loop op.

Diagnostics
-----------
Emit per-wrap and per-function diagnostics on stderr so the wrapping is
observable from a single compile invocation:

  [wrap-unstructured] wrapped DO at <loc>
  [wrap-unstructured] wrapped IF at <loc>
  [wrap-unstructured] summary: N execute_region(s) wrapping unstructured
                      constructs at <loc>

The counter is reset per function and the summary is suppressed when no
wraps fire.

Co-authored-by: Claude Opus 4.7 <noreply at anthropic.com>


  Commit: 5732104cf80e260c0d4da9ffaeac53e4b40b2c00
      https://github.com/llvm/llvm-project/commit/5732104cf80e260c0d4da9ffaeac53e4b40b2c00
  Author: ergawy <kareem.ergawy at gmail.com>
  Date:   2026-07-17 (Fri, 17 Jul 2026)

  Changed paths:
    M flang/lib/Lower/PFTBuilder.cpp
    M flang/test/Lower/do_loop_execute_region_wrap.f90

  Log Message:
  -----------
  [flang][PFT] check every branch target in wrappability analyses

Co-Authored-By: Claude Sonnet 4.6 <noreply at anthropic.com>


  Commit: 17776245f20a12408825b8b1c9a111ba5b42f1da
      https://github.com/llvm/llvm-project/commit/17776245f20a12408825b8b1c9a111ba5b42f1da
  Author: ergawy <kareem.ergawy at gmail.com>
  Date:   2026-07-17 (Fri, 17 Jul 2026)

  Changed paths:
    M flang/lib/Lower/Bridge.cpp

  Log Message:
  -----------
  [flang][PFT-to-MLIR] pull the scf.execute_region wrap inside the DO lowering

Co-authored-by: Claude Opus 4.7 <noreply at anthropic.com>


  Commit: dc7076904b4b5d3a46d67b50fda844dd0ae0a5cc
      https://github.com/llvm/llvm-project/commit/dc7076904b4b5d3a46d67b50fda844dd0ae0a5cc
  Author: ergawy <kareem.ergawy at gmail.com>
  Date:   2026-07-17 (Fri, 17 Jul 2026)

  Changed paths:
    M flang/lib/Lower/Bridge.cpp
    A flang/test/Lower/if_construct_execute_region_wrap.f90

  Log Message:
  -----------
  [flang][PFT-to-MLIR] start entry block for wrappable nested IfConstruct

Co-authored-by: Claude Opus 4.7 <noreply at anthropic.com>


  Commit: a2729d5358a2496b4df8caa99988e404606f6ef9
      https://github.com/llvm/llvm-project/commit/a2729d5358a2496b4df8caa99988e404606f6ef9
  Author: ergawy <kareem.ergawy at gmail.com>
  Date:   2026-07-17 (Fri, 17 Jul 2026)

  Changed paths:
    M flang/lib/Lower/Bridge.cpp

  Log Message:
  -----------
  Self review


Compare: https://github.com/llvm/llvm-project/compare/e986d156f0b9...a2729d5358a2

To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list