138 Commits

Author SHA1 Message Date
Kareem Ergawy
acd52a2419
[flang][OpenMP][DoConcurrent] Emit declare mapper for records (#179936)
Extends `do concurrent` device support by emitting compiler-generated
declare mapper ops for live-ins whose types are record types and have
allocatable members.
2026-03-11 13:43:55 +01:00
Chi-Chun, Chen
e4160cb52d
[Flang][mlir][OpenMP] Support affinity clause codegen in Flang (#182222)
This patch translates the Flang AST to the OpenMP dialect for the
affinity clause, including support for the iterator modifier.

2/3 in stack for implementing affinity clause with iterator modifier
1/3 #182218
2/3 #182222
3/3 #182223
2026-03-08 18:32:17 -05:00
agozillon
18f228810e
[Flang][OpenMP] Skip intermediate map generation for motion modifier map directives (#177737)
Currently if we create the following map:

!$omp target update from/to(derived_type%allocatable)

We'll generate an extra map for the derived type (and any other
allocatable maps that may be in-between the final mapped allocatable
member). However, for cases like this, and other motion modifier related
map directives we don't need to do so. All the user cares about is the
specified member. Removing the intermediate member will minimize extra
performance overhead. It also maintains correctness, as currently, the
MLIR diagnostics for the motion modifiers restricts possible map types
for updates to to and from, and applying this map type to an
intermediate map will result in unintended side affects, e.g. mapping
back data the user didn't want to or over-writing data they didn't
intend to on device. This minor modification addresses that.
2026-03-05 16:41:36 +01:00
Akash Banerjee
f55080da98
[flang][OpenMP] Avoid implicit default mapper on pointer captures (#184382)
This change fixes incorrect implicit declare mapper behavior in Flang
OpenMP lowering.

Issue:
Implicit default mappers were being attached/generated for pointer-based
implicit captures, and also on data-motion directives. That could
trigger recursive component mapping that overlaps/conflicts with
explicit user mappings, causing runtime mapping failures.

Fix:

- Skip implicit default mapper generation for implicit pointer captures
(keep support for allocatables).
- Do not auto-attach implicit mappers on target enter data, target exit
data, or target update.
- Apply the same pointer guard in the implicit target-capture lowering
path.
2026-03-04 15:27:06 +00:00
Krish Gupta
148b10be8a
[flang][OpenMP] Support custom mappers in target update to/from clauses (#169673)
Implement support for the OpenMP `mapper` modifier on `target update` `to` and
`from` clauses in Flang.

Semantic name resolution is extended to bind the mapper symbol for
`OmpClause::To` and `OmpClause::From` via a shared `ResolveMapperModifier`
helper. Lowering is extended in `ClauseProcessor` with a `getMapperIdentifier`
template helper to extract the mapper name for both `map` and `target update`
clauses and forward it to `omp.map_info`.

Fixes #168701.

Reviewed By: TIFitis, kparzysz
Assited By: Copilot( For review and articulations of messages)
2026-03-02 21:59:56 +05:30
Sunil Shrestha
af2b6ed6aa
[flang][openmp] Add support for ordered regions in SIMD directives (#… (#183379)
Add support for ordered regions within SIMD directives (!$omp simd
ordered and !$omp do simd ordered). This initial implementation matches
Clang's behavior.

In SIMD directives, loop induction variables have an implicit linear
clause with deferred store semantics (storing to .linear_result). To
properly support ordered regions, the LinearClauseProcessor rewrites
variable references to use .linear_result in:
- omp.ordered.region: Code inside ordered blocks
- omp_region.finalize: Code after ordered blocks

Note: The vectorizer cannot currently vectorize loops with ordered
regions. Future enhancement would require generating lane loops or
unrolling ordered regions across SIMD lanes while maintaining ordering
semantics.

This PR is a reland for https://github.com/llvm/llvm-project/pull/181012
and fixes the regression caused by syntax change in IR for linear clause
2026-02-25 15:23:18 -06:00
Aiden Grossman
efe0b2f993 Revert "[flang][openmp] Add support for ordered regions in SIMD directives (#181012)"
This reverts commit 31dacdc1f5d486da6ef6d8b2f7e3b6126d92c9ff.

See the PR for test failure details.
2026-02-25 19:31:47 +00:00
Sunil Shrestha
31dacdc1f5
[flang][openmp] Add support for ordered regions in SIMD directives (#181012)
Add support for ordered regions within SIMD directives (!$omp simd
ordered and !$omp do simd ordered). This initial implementation matches
Clang's behavior.

In SIMD directives, loop induction variables have an implicit linear
clause with deferred store semantics (storing to .linear_result). To
properly support ordered regions, the LinearClauseProcessor rewrites
variable references to use .linear_result in:
- omp.ordered.region: Code inside ordered blocks
- omp_region.finalize: Code after ordered blocks

Note: The vectorizer cannot currently vectorize loops with ordered
regions. Future enhancement would require generating lane loops or
unrolling ordered regions across SIMD lanes while maintaining ordering
semantics.
2026-02-25 11:49:07 -06:00
NimishMishra
8c3e8e526b
[flang][mlir][OpenMP] Allow for flexible typing of linear step variables (#182816)
This PR allows for flexible typing of linear step variables. The format
of the linear clause is also changed to: `linear(linear_var : type =
linear_step : type)`; this format closely follows the formatting of the
allocate/allocators clauses.

Fixes https://github.com/llvm/llvm-project/issues/178793

Co-authored-by: urvi-rav <urvi.rav@hpe.com>
2026-02-24 18:01:23 -05:00
Ferran Toda
f560e4cfb1
[MLIR][OpenMP] Add omp.fuse operation (#168898)
This patch is a follow-up from #161213 and adds the omp.fuse loop
transformation for the OpenMP dialect. Used for lowering a `!$omp fuse`
in Flang.

Added Lowering and end2end tests.
2026-02-17 15:34:27 +01:00
Krish Gupta
aef8a2c483
[Flang][OpenMP] Fix crash with character types in declare_reduction (#178038)
Fixes #177501

This PR fixes a compilation crash when using character types in OpenMP
REDUCTION clauses with declare_reduction directives.

The problem was that character types weren't being handled properly
during OpenMP lowering. Specifically:
- Missing character length parameters in hlfir.declare operations
- Incorrect type wrapping for by-ref reductions
- Missing special case handling for boxed/unboxed character types

The fix ensures character types are treated similarly to derived types
throughout the reduction pipeline, since fir::isa_trivial() excludes
them.

Added a regression test to verify the fix works for both allocatable and
non-allocatable character reductions.
<img width="654" height="47" alt="image"
src="https://github.com/user-attachments/assets/cc962f01-3432-44ce-befb-324644767c8b"
/>
2026-02-10 11:31:24 +00:00
Chi-Chun, Chen
36dadddd74
[Flang][mlir][OpenMP] Add affinity clause to omp.task and Flang lowering (#179003)
- Add MLIR OpenMP affinity clause
- Lower flang task affinity to mlir
- Emit TODO for iterator modifier and update negative test
2026-02-04 10:30:35 -06:00
Chaitanya
55f0ed91ef
[OpenMP][MLIR] Add thread_limit with dims modifier support (#171825)
PR adds support of openmp 6.1 feature thread_limit with dims modifier.
llvmIR translation for thread_limit with dims modifier is marked as NYI.
2026-01-27 18:16:48 +05:30
Chaitanya
08654adc62
[OpenMP][MLIR] Add num_threads clause with dims modifier support (#171767)
PR adds support of openmp 6.1 feature num_threads with dims modifier.
llvmIR translation for num_threads with dims modifier is marked as NYI.
2026-01-27 15:30:55 +05:30
Chaitanya
3aaeace4e2
[OpenMP][MLIR] Add num_teams clause with dims modifier support (#169883)
PR adds support of openmp 6.1 feature `num_teams` with dims modifier.
llvmIR translation for num_teams with dims modifier is marked as NYI.
2026-01-27 10:55:40 +05:30
Chi-Chun, Chen
2f1b1f3a54
[flang][mlir][OpenMP] Support inbranch and notinbranch clause (#177310)
Support inbranch and notinbranch clause for OpenMP declare simd
directive.
2026-01-24 13:19:13 -06:00
Chi-Chun, Chen
d13119f269
[flang][mlir][OpenMP] Add support for uniform clause in declare simd (#176046)
Define OpenMP uniform clause in mlir and emit it from flang.
2026-01-20 11:08:01 -06:00
Krzysztof Parzyszek
a05f603c71
[flang][Lower] Lower OmpDependClause to Depend or Doacross (#175772)
The clause::Depend class was a variant that either held a TaskDep class
or a Doacross clause. This mirrors the OmpDependClause in the AST, which
due to changes in the OpenMP spec can contain two different forms.

This is not actually necessary, and we can save some complexity by
having clause::Depend only represent task dependence, and lowering
OmpDependClause to either clause:Depend or clause::Doacross.
2026-01-13 11:34:13 -06:00
Krzysztof Parzyszek
755f298ddc
[flang][OpenMP] Implement COMBINER clause (#172036)
This adds parsing and lowering of the COMBINER clause. It utilizes the
existing lowering code for combiner-expression to lower the COMBINER
clause as well.
2025-12-18 08:04:28 -06:00
Krzysztof Parzyszek
1451f3d9b0
[flang][OpenMP] Use StylizedInstance in converted clauses (#171907)
Invent `StylizedInstance` class to store special variables together with
the instantiated expression in omp::clause::Initializer. This will
eliminate the need for visiting the original AST nodes in lowering to
MLIR.
2025-12-12 08:09:25 -06:00
Krzysztof Parzyszek
bfce02548d
[flang][OpenMP] Store list of expressions in InitializerT (#170923)
The INITIALIZER clause holds a stylized expression that can be
intiantiated with different types. Currently, the InitializerT class
only holds one expression, which happens to correspond to the first type
in the DECLARE_REDUCTION type list.

Change InitializerT to hold a list of expressions instead, one for each
type. Keep the lowering code unchanged by picking the first expression
from the list.
2025-12-10 07:35:15 -06:00
Akash Banerjee
b360a782ca
Reland "[Flang][OpenMP] Add lowering support for is_device_ptr clause (#169331)" (#170851)
Add support for OpenMP is_device_ptr clause for target directives.

[MLIR][OpenMP] Add OpenMPToLLVMIRTranslation support for is_device_ptr
#169367 This PR adds support for the OpenMP is_device_ptr clause in the
MLIR to LLVM IR translation for target regions. The is_device_ptr clause
allows device pointers (allocated via OpenMP runtime APIs) to be used
directly in target regions without implicit mapping.
2025-12-05 17:38:41 +00:00
NimishMishra
290b32a699
[llvm][mlir][OpenMP] Support translation for linear clause in omp.wsloop and omp.simd (#139386)
This patch adds support for LLVM translation of linear clause on
omp.wsloop (except for linear modifiers).
2025-12-04 20:39:17 -08:00
theRonShark
be79a0d90f
Revert "[Flang][OpenMP] Add lowering support for is_device_ptr clause" (#170778)
Reverts llvm/llvm-project#169331
2025-12-04 19:38:16 -05:00
Akash Banerjee
a77c4948a5
[Flang][OpenMP] Add lowering support for is_device_ptr clause (#169331)
Add support for OpenMP is_device_ptr clause for target directives.

[MLIR][OpenMP] Add OpenMPToLLVMIRTranslation support for is_device_ptr #169367
This PR adds support for the OpenMP is_device_ptr clause in the MLIR to LLVM IR translation for target regions. The is_device_ptr clause allows device pointers (allocated via OpenMP runtime APIs) to be used directly in target regions without implicit mapping.
2025-12-04 15:57:24 +00:00
Jan Leyonberg
3e86f05621
[OpenMP][flang] Lowering of OpenMP custom reductions to MLIR (#168417)
This patch add support for lowering of custom reductions to MLIR. It
also enhances the capability of the pass to automatically mark functions
as "declare target" by traversing custom reduction initializers and
combiners.
2025-11-24 16:00:46 -05:00
Akash Banerjee
8c674f04aa
[OpenMP][Flang] Change the OmpDefaultMapperName suffix (#168399)
This PR fixes a Fortran syntax violation in the OpenMP default mapper
naming convention. The suffix .omp.default.mapper contains dots which
are invalid in Fortran identifiers, causing failures when mappers are
written to and read from module files. The fix changes the suffix to
_omp_default_mapper which uses underscores instead of dots, complying
with Fortran syntax rules.

Key changes:

- Changed OmpDefaultMapperName constant from .omp.default.mapper to
_omp_default_mapper
- Added GetUltimate() calls in mapper symbol resolution to properly
handle symbols across module boundaries
- Added new test case verifying default mappers work correctly when
defined in a module and used in consuming programs

This fixes #168336.
2025-11-17 17:18:12 +00:00
Akash Banerjee
8aa7d823b0
[OpenMP][Flang] Emit default declare mappers implicitly for derived types (#140562)
This patch adds support to emit default declare mappers for implicit
mapping of derived types when not supplied by user. This especially
helps tackle mapping of allocatables of derived types.
2025-11-14 15:59:48 +00:00
Akash Banerjee
833ffa54f2
[Flang][OpenMP] Update declare mapper lookup via use-module (#167903) 2025-11-13 19:21:34 +00:00
Akash Banerjee
e1324a9377
Revert "[Flang][OpenMP] Update declare mapper lookup via use-module" (#167896)
Reverts llvm/llvm-project#163860
2025-11-13 16:05:33 +00:00
Akash Banerjee
bb5f3a08b6
[Flang][OpenMP] Update declare mapper lookup via use-module (#163860)
- Implemented semantic TODO to catch undeclared mappers.
- Fix mapper lookup to include modules imported through USE.
- Update and add tests.

Fixes #163385.
2025-11-13 15:07:46 +00:00
Kaviya Rajendiran
eb614cda37
[Flang][OpenMP][MLIR] Lowering of reduction,inreduction, nogroup and lastprivate clause to MLIR (#166751)
This patch add MLIR lowering support for nogroup, reduction, inreduction
and lastprivate clauses of taskloop directive.
2025-11-11 21:02:58 +05:30
agozillon
f2b20d3410
[Flang][OpenMP][Dialect] Swap to using MLIR dialect enum to encode map flags (#164043)
This PR shifts from using the LLVM OpenMP enumerator bit flags to an
OpenMP dialect specific enumerator. This allows us to better represent
map types that wouldn't be of interest to the LLVM backend and runtime
in the dialect.

Primarily things like
ref_ptr/ref_ptee/ref_ptr_ptee/atach_none/attach_always/attach_auto which
are of interest to the compiler for certrain transformations (primarily
in the FIR transformation passes dealing with mapping), but the runtime
has no need to know about them. It also means if another OpenMP
implementation comes along they won't need to stick to the same bit flag
system LLVM chose/do leg work to address it.
2025-10-21 21:54:25 +02:00
Krzysztof Parzyszek
9d0c211b14
[flang][OpenMP] Frontend support for ATTACH modifier (#163608)
Add parsing, semantic checks, but no lowering.
2025-10-16 06:51:34 -05:00
Michael Kruse
375f48942b
[Flang] Add standalone tile support (#160298)
Add support for the standalone OpenMP tile construct:
```f90
!$omp tile sizes(...)
DO i = 1, 100
  ...
```

This is complementary to #143715 which added support for the tile
construct as part of another loop-associated construct such as
worksharing-loop, distribute, etc.
2025-10-03 15:52:48 +02:00
Jan Leyonberg
d452e67ee7
[flang][OpenMP] Enable tiling (#143715)
This patch enables tiling in flang. In MLIR tiling is handled by
changing the the omp.loop_nest op to be able to represent both collapse
and tiling, so the flang front-end will combine the nested constructs into
a single MLIR op. The MLIR->LLVM-IR lowering of the LoopNestOp is
enhanced to first do the tiling if present, then collapse.
2025-09-10 09:25:40 -04:00
Slava Zakharin
83da8d08ff
[flang] Attach proper storage to [hl]fir.declare in lowering. (#155742)
As described in
https://discourse.llvm.org/t/rfc-flang-representation-for-objects-inside-physical-storage/88026,
`[hl]fir.declare` should carry information about the layout
of COMMON/EQUIVALENCE variables within the physical storage.

This patch modifes Flang lowering to attach this information.
2025-09-04 15:49:11 -07:00
Kaviya Rajendiran
c0fc5be60f
[Flang][OpenMP] Fix to resolve the crash with SIMD aligned clause. (#150612)
**Issue:**
When SIMD aligned clause has a alignment value which is not a power of
2, compiler crashes with error Assertion (alignment & (alignment - 1))
== 0 && "alignment is not power of 2"

**Fix:**
According to LLVM Language Reference manual
[[link]](https://llvm.org/docs/LangRef.html#assume-opbundles), the
alignment value may be non-power-of-two. In that case, the pointer value
must be a null pointer otherwise the behavior is undefined.

So instead of emitting `llvm.assume` intrinsic function with a null
pointer having the specified alignment, modified the implementation
which ignores the aligned clause which has an alignment value which is
not a power of 2. This patch also emits a warning indicating that the aligned clause is ignored if the alignment value is not a power of two.

It fixes the issue https://github.com/llvm/llvm-project/issues/149458
2025-08-29 11:48:24 +05:30
Kareem Ergawy
86e4c175e3
[NFC][flang][OpenMP] Create FortranUtils lib and move createMapInfoOp to it (#154483) 2025-08-27 18:25:36 +02:00
Akash Banerjee
a9f9c7db4f Fix build error from #151513. 2025-08-11 13:16:39 +01:00
Akash Banerjee
3b10b9a2b0
[MLIR][OpenMP] Add lowering support for AUTOMAP modifier (#151513)
Add Automap modifier to the MLIR op definition for the DeclareTarget
directive's Enter clause. Also add lowering support in Flang.

Automap Ref: OpenMP 6.0 section 7.9.7.
2025-08-11 12:45:22 +01:00
Tom Eccles
8cc4c6d78f
[flang][Lower] Make reduction processing failure a hard error (#150233)
See #150178

This may regress some test cases which only ever passed by accident.

I've tested SPEC2017 and a sample of applications to check that this
doesn't break anything too obvious. Presumably this was not a widely
used feature or we would have noticed the bug sooner.

I'm unsure whether this should be backported to LLVM 21 or not: I think
it is much better to refuse to compile than to silently produce the
wrong result, but there is a chance this could regress something which
previously worked by accident. Opinions welcome.
2025-08-04 12:01:27 +01:00
Akash Banerjee
9fdd1d3d46
[Flang] Add parser support for AUTOMAP modifier (#151511)
Add parser support for the new AUTOMAP modifier for OpenMP Declare
Target Enter clause introduced in OpenMP 6.0 section 7.9.7.
2025-07-31 15:56:16 +01:00
Kareem Ergawy
36c37b019b
[flang][OpenMP] Restore reduction processor behavior broken by #145837 (#150178)
Fixes #149089 and #149700.

Before #145837, when processing a reduction symbol not yet supported by
OpenMP lowering, the reduction processor would simply skip filling in
the reduction symbols and variables. With #145837, this behvaior was
slightly changed because the reduction symbols are populated before
invoking the reduction processor (this is more convenient to shared the
code with `do concurrent`).

This PR restores the previous behavior.
2025-07-23 11:23:00 +02:00
Krzysztof Parzyszek
2914a488c7
[flang][OpenMP] Sema checks, lowering with new format of MAP modifiers (#149137)
OpenMP 6.0 has changed the modifiers on the MAP clause. Previous patch
has introduced parsing support for them. This patch introduces
processing of the new forms in semantic checks and in lowering. This
only applies to existing modifiers, which were updated in the 6.0 spec.
Any of the newly introduced modifiers (SELF and REF) are ignored.
2025-07-22 07:37:47 -05:00
Maksim Levental
a3a007ad5f
[mlir][NFC] update flang/Lower create APIs (8/n) (#149912)
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-21 19:54:29 -04:00
Kareem Ergawy
7c8a197918
[NFC][flang] Move ReductionProcessor to Lower/Support. (#146025)
With #145837, the `ReductionProcessor` component is now used by both
OpenMP and `do concurrent`. Therefore, this PR moves it to a shared
location: `flang/Lower/Support`.

PR stack:
- https://github.com/llvm/llvm-project/pull/145837
- https://github.com/llvm/llvm-project/pull/146025 (this one)
- https://github.com/llvm/llvm-project/pull/146028
- https://github.com/llvm/llvm-project/pull/146033
2025-07-11 07:42:51 +02:00
Kareem Ergawy
eba35cc1c0
[flang][do concurrent] Re-model reduce to match reductions are modelled in OpenMP and OpenACC (#145837)
This PR proposes re-modelling `reduce` specifiers to match OpenMP and
OpenACC. In particular, this PR includes the following:

* A new `fir` op: `fir.delcare_reduction` which is identical to OpenMP's
`omp.declare_reduction` op.
* Updating the `reduce` clause on `fir.do_concurrent.loop` to use the
new op.
* Re-uses the `ReductionProcessor` component to emit reductions for `do
concurrent` just like we do for OpenMP. To do this, the
`ReductionProcessor` had to be refactored to be more generalized.
* Upates mapping `do concurrent` to `fir.loop ... unordered` nests using
the new reduction model.

Unfortunately, this is a big PR that would be difficult to divide up in
smaller parts because the bottom of the changes are the `fir` table-gen
changes to `do concurrent`. However, doing these MLIR changes cascades
to the other parts that have to be modified to not break things.

This PR goes in the same direction we went for `private/local`
speicifiers. Now the `do concurrent` and OpenMP (and OpenACC) dialects
are modelled in essentially the same way which makes mapping between
them more trivial, hopefully.

PR stack:
- https://github.com/llvm/llvm-project/pull/145837 (this one)
- https://github.com/llvm/llvm-project/pull/146025
- https://github.com/llvm/llvm-project/pull/146028
- https://github.com/llvm/llvm-project/pull/146033
2025-07-11 06:39:30 +02:00
Jack Styles
89efae916a
[Flang][OpenMP] Update default MapType for Map Clauses and OpenMP 5.2 (#144715)
In OpenMP 5.2, the `target enter data` and `target exit data` constructs
now have default map types if the user does not define them in the Map
clause. For `target enter data`, this is `to` and `target exit data`
this is `from`. This behaviour is now enabled when OpenMP 5.2 or greater
is used when compiling. To enable this, the default value is now set in
the `processMap` clause, with any previous behaviour being maintained
for either older versions of OpenMP or other directives.

See also #110008
2025-06-19 15:32:27 +01:00
Kajetan Puchalski
4cfe0d7f4c
[flang][OpenMP] Support using copyprivate with fir.boxchar arguments (#144092)
Implement the lowering for passing a fir.boxchar argument to the
copyprivate clause.

Resolves https://github.com/llvm/llvm-project/issues/142123.

---------

Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
2025-06-17 15:32:23 +01:00