[all-commits] [llvm/llvm-project] 3bf6ec: [flang][PFT-to-MLIR] Wrap unstructured Fortran con...
Kareem Ergawy via All-commits
all-commits at lists.llvm.org
Thu Jul 16 07:03:01 PDT 2026
Branch: refs/heads/users/ergawy/enclode_in_scf.execute_region
Home: https://github.com/llvm/llvm-project
Commit: 3bf6ec5d581affe3b25a7069b57b95774749e4e4
https://github.com/llvm/llvm-project/commit/3bf6ec5d581affe3b25a7069b57b95774749e4e4
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: 734638f0c7222917809905c4d6212e0836390cd7
https://github.com/llvm/llvm-project/commit/734638f0c7222917809905c4d6212e0836390cd7
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>
Commit: 1d99ead9459fe79e0f14240ab2837981d2efd459
https://github.com/llvm/llvm-project/commit/1d99ead9459fe79e0f14240ab2837981d2efd459
Author: ergawy <kareem.ergawy at gmail.com>
Date: 2026-07-16 (Thu, 16 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
wrapUnstructuredConstruct was previously invoked at the top of
genFIR(DoConstruct), before any of the per-branch preheader/header/body
blocks had been settled. That layout worked but was fragile: the wrap
happened before createEmptyBlocks (called inside
wrapUnstructuredConstruct) had a chance to reallocate doStmtEval.block
into the scf.execute_region entry block, and the follow-on setup
recomputed beginBlock from a stale value.
Introduce a maybeWrapAndRecalc lambda that is called in each of the DO
variants (infinite / while / increment / concurrent) after
maybeStartBlock(preheaderBlock). It:
- conditionally creates the scf.execute_region wrap,
- notices whether createEmptyBlocks allocated a fresh preheader
inside the new region, and, if so, branches the scf entry to it
and uses it as beginBlock; otherwise it falls back to the scf
entry block itself,
- refreshes bodyBlock/exitBlock so the rest of the DO lowering
lands inside the wrap.
headerBlock is now computed per-branch after the wrap so that the
"step beginBlock through preheader/header/mask" walk starts from the
correct scf-internal block. No functional change when
--wrap-unstructured-constructs-in-execute-region is off (unstructured
DOs still lower to flat CFG).
Co-Authored-By: Claude Sonnet 4.6 <noreply at anthropic.com>
Compare: https://github.com/llvm/llvm-project/compare/119fbaeffa97...1d99ead9459f
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