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

Kareem Ergawy via All-commits all-commits at lists.llvm.org
Thu Jul 16 02:13:09 PDT 2026


  Branch: refs/heads/users/ergawy/enclode_in_scf.execute_region
  Home:   https://github.com/llvm/llvm-project
  Commit: d32614f716107241d48f2f5d3eb6e15315a73108
      https://github.com/llvm/llvm-project/commit/d32614f716107241d48f2f5d3eb6e15315a73108
  Author: ergawy <kareem.ergawy at gmail.com>
  Date:   2026-07-16 (Thu, 16 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: 119fbaeffa97c4763a77ea8165388b7541056aea
      https://github.com/llvm/llvm-project/commit/119fbaeffa97c4763a77ea8165388b7541056aea
  Author: ergawy <kareem.ergawy at gmail.com>
  Date:   2026-07-16 (Thu, 16 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>


Compare: https://github.com/llvm/llvm-project/compare/4d49bad9b3df...119fbaeffa97

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