summaryrefslogtreecommitdiff
path: root/flang/lib/Optimizer/OpenMP/GenericLoopConversion.cpp
AgeCommit message (Collapse)Author
2025-09-06[flang] Fix build after #155244 (#157248)Matthias Springer
Fix build after #155244.
2025-07-24[mlir][NFC] update `flang/lib` create APIs (12/n) (#149914)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-04-04[flang][OpenMP] Move reductions from `loop` to `teams` when `loop` is mapped ↵Kareem Ergawy
to `distribute` (#132920) Follow-up to #132003, in particular, see https://github.com/llvm/llvm-project/pull/132003#issuecomment-2739701936. This PR extends reduction support for `loop` directives. Consider the following scenario: ```fortran subroutine bar implicit none integer :: x, i !$omp teams loop reduction(+: x) DO i = 1, 5 call foo() END DO end subroutine ``` Note the following: * According to the spec, the `reduction` clause will be attached to `loop` during earlier stages in the compiler. * Additionally, `loop` cannot be mapped to `distribute parallel for` due to the call to a foreign function inside the loop's body. * Therefore, `loop` must be mapped to `distribute`. * However, `distribute` does not have `reduction` clauses. * As a result, we have to move the `reduction`s from the `loop` to its parent `teams` directive, which is what is done by this PR.
2025-03-24[flang][OpenMP] Skip multi-block `teams` regions when processing `loop` ↵Kareem Ergawy
directives (#132687) Fixes a regression when the generic `loop` directive conversion pass encounters a multi-block `teams` region. At the moment, we skip such regions.
2025-03-21[flang][OpenMP] Hoist reduction info from nested `loop` ops to parent ↵Kareem Ergawy
`teams` ops (#132003) Fixes a bug in reductions when converting `teams loop` constructs with `reduction` clauses. According to the spec (v5.2, p340, 36): ``` The effect of the reduction clause is as if it is applied to all leaf constructs that permit the clause, except for the following constructs: * .... * The teams construct, when combined with the loop construct. ``` Therefore, for a combined directive similar to: `!$omp teams loop reduction(...)`, the earlier stages of the compiler assign the `reduction` clauses only to the `loop` leaf and not to the `teams` leaf. On the other hand, if we have a combined construct similar to: `!$omp teams distribute parallel do`, the `reduction` clauses are assigned both to the `teams` and the `do` leaves. We need to match this behavior when we convert `teams` op with a nested `loop` op since the target set of constructs/ops will be incorrect without moving the reductions up to the `teams` op as well. This PR introduces a pattern that does exactly this. Given the following input: ``` omp.teams { omp.loop reduction(@red_sym %red_op -> %red_arg : !fir.ref<i32>) { omp.loop_nest ... { ... } } } ``` this pattern updates the `omp.teams` op in-place to: ``` omp.teams reduction(@red_sym %red_op -> %teams_red_arg : !fir.ref<i32>) { omp.loop reduction(@red_sym %teams_red_arg -> %red_arg : !fir.ref<i32>) { omp.loop_nest ... { ... } } } ``` Note the following: * The nested `omp.loop` is not rewritten by this pattern, this happens through `GenericLoopConversionPattern`. * The reduction info are cloned from the nested `omp.loop` op to the parent `omp.teams` op. * The reduction operand of the `omp.loop` op is updated to be the **new** reduction block argument of the `omp.teams` op.
2025-02-28[flang][OpenMP] Add `reduction` clause support to `loop` directive (#128849)Kareem Ergawy
Extends `loop` directive transformation by adding support for the `reduction` clause.
2025-02-21[flang][OpenMP] Support `parallel loop` construct. (#127588)Kareem Ergawy
Extends support for the `loop` directive by adding support for `parallel loop` combined directive. Parent PR: #127489. Only the latest commit is relevant.
2025-02-21[flang][OpenMP] Map `teams loop` to `teams distribute` when required. (#127489)Kareem Ergawy
This extends support for generic `loop` rewriting by: 1. Preventing nesting multiple worksharing loops inside each other. This is checked by walking the `teams loop` region searching for any `loop` directive whose `bind` modifier is `parallel`. 2. Preventing convert to worksharing loop if calls to unknow functions are found in the `loop` directive's body. We walk the `teams loop` body to identify either of the above 2 conditions, if either of them is found to be true, we map the `loop` directive to `distribute`.
2025-02-17[flang][OpenMP] Support `bind` clause for `teams loop` (#127021)Kareem Ergawy
Extends generic `loop` directive support by supporting the `bind` clause. Since semantic checking does the heavy lifting of verifying the proper usage of the clause modifier, we can simply enable code-gen for `teams loop bind(...)` without the need to differentiate between the values the the clause can accept.
2025-02-06[Flang] Move non-common headers to FortranSupport (#124416)Michael Kruse
Move non-common files from FortranCommon to FortranSupport (analogous to LLVMSupport) such that * declarations and definitions that are only used by the Flang compiler, but not by the runtime, are moved to FortranSupport * declarations and definitions that are used by both ("common"), the compiler and the runtime, remain in FortranCommon * generic STL-like/ADT/utility classes and algorithms remain in FortranCommon This allows a for cleaner separation between compiler and runtime components, which are compiled differently. For instance, runtime sources must not use STL's `<optional>` which causes problems with CUDA support. Instead, the surrogate header `flang/Common/optional.h` must be used. This PR fixes this for `fast-int-sel.h`. Declarations in include/Runtime are also used by both, but are header-only. `ISO_Fortran_binding_wrapper.h`, a header used by compiler and runtime, is also moved into FortranCommon.
2025-01-27[NFC][mlir][OpenMP] Remove mentions of `target` from generic `loop` rewrite ↵Kareem Ergawy
(#124528) This removes mentions of `target` from the generic `loop` rewrite pass since there is not need for it anyway. It is enough to detect `loop`'s nesting within `teams` or `parallel` directives.
2025-01-27[flang][OpenMP] Support `bind` clause code-gen for standalone `loop`s (#122674)Kareem Ergawy
Extends rewriting of `loop` directives by supporting `bind` clause for standalone directives. This follows both the spec and the current state of clang as follows: * No `bind` or `bind(thread)`: the `loop` is rewritten to `simd`. * `bind(parallel)`: the `loop` is rewritten to `do`. * `bind(teams)`: the `loop` is rewritten to `distribute`. This is a follow-up PR for https://github.com/llvm/llvm-project/pull/122632, only the latest commit in this PR is relevant to the PR.
2025-01-21[flang][OpenMP] Rewrite standalone `loop` (without `bind`) directives to ↵Kareem Ergawy
`simd` (#122632) Extends conversion support for `loop` directives. This PR handles standalone `loop` constructs that do not have a `bind` clause attached by rewriting them to equivalent `simd` constructs. The reasoning behind that decision is documented in the rewrite function itself.
2024-11-28[flang][OpenMP] Rewrite `omp.loop` to semantically equivalent ops (#115443)Kareem Ergawy
Introduces a new conversion pass that rewrites `omp.loop` ops to their semantically equivalent op nests bases on the surrounding/binding context of the `loop` op. Not all forms of `omp.loop` are supported yet. See `isLoopConversionSupported` for more info on which forms are supported.