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

Kareem Ergawy via All-commits all-commits at lists.llvm.org
Fri Jul 17 00:59:02 PDT 2026


  Branch: refs/heads/users/ergawy/enclode_in_scf.execute_region
  Home:   https://github.com/llvm/llvm-project
  Commit: 2abfb0ba265c8fff10d5d20e515367e8d7222e3c
      https://github.com/llvm/llvm-project/commit/2abfb0ba265c8fff10d5d20e515367e8d7222e3c
  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: 1fb2b8444ee48f123c35cdef77f37c459da21e6b
      https://github.com/llvm/llvm-project/commit/1fb2b8444ee48f123c35cdef77f37c459da21e6b
  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: ccc371992b4053ce53eb102e38bdc5d9be2b1ccb
      https://github.com/llvm/llvm-project/commit/ccc371992b4053ce53eb102e38bdc5d9be2b1ccb
  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: 99824cd3db935dec1def4d245f58cb29a9a360a3
      https://github.com/llvm/llvm-project/commit/99824cd3db935dec1def4d245f58cb29a9a360a3
  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: e986d156f0b99379fe789a945fbf8f665e4c648b
      https://github.com/llvm/llvm-project/commit/e986d156f0b99379fe789a945fbf8f665e4c648b
  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/1d99ead9459f...e986d156f0b9

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