284 Commits

Author SHA1 Message Date
NimishMishra
6bfa042a10
[flang][mlir] Add checks and test for linear clause on omp.wsloop and omp.simd (#174916)
This PR adds additional checks and tests for linear clause on omp.wsloop
and omp.simd (both standalone and composite). For composite simd
constructs, the translation to LLVMIR uses the same
`LinearClauseProcessor` under `convertOmpSimd`, as already present in
previous PRs like https://github.com/llvm/llvm-project/pull/150386 and
https://github.com/llvm/llvm-project/pull/139386
2026-01-09 06:51:29 -08:00
Chi-Chun, Chen
3f5d91bfbc
[Flang][OpenMP] Implement device clause lowering for target directive (#173509)
Add lowering support for the OpenMP `device` clause on the `target`
directive in Flang.

The device expression is propagated through MLIR OpenMP and passed to
the host-side `__tgt_target_kernel` call.
2026-01-06 11:10:03 -06:00
NimishMishra
11d9694b75
[flang][mlir] Add support for implicit linearization in omp.simd (#150386)
Up till OpenMP version 4.5, the loop iteration variable in the
associated do-construct of simd is linear with a linear step equal to
the increment of the loop. This PR implements this functionality. For
versions > 4.5, such an implicit linear clause is not assumed for the
loop iteration variable.

Fixes https://github.com/llvm/llvm-project/issues/171006
2026-01-03 21:37:43 -08: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
Tom Eccles
3a0c006054
Revert "[flang][OpenMP] Fix firstprivate not working with lastprivate in DO SIMD" (#171646)
Reverts llvm/llvm-project#170163

Regression in fujitsu test suite
2025-12-10 16:51:17 +00:00
Krish Gupta
748e7af8dd
[flang][OpenMP] Fix firstprivate not working with lastprivate in DO SIMD (#170163)
This fixes a bug where firstprivate was ignored when the same variable
had both firstprivate and lastprivate clauses in a do simd construct.

What was broken:
```
integer :: a
a = 10
!$omp do simd firstprivate(a) lastprivate(a)
do i = 1, 1
   print *, a  ! Should print 10, but printed garbage/0
   a = 20
end do
!$omp end do simd
print *, a  ! Correctly prints 20
```

Inside the loop, [a] wasn't being initialized from the firstprivate
clause—it just had whatever uninitialized value was there.

The fix:

In genCompositeDoSimd(), we were using simdItemDSP to handle
privatization for the whole loop nest. This only looked at SIMD clauses
and missed the firstprivate from the DO part. Changed it to use
wsloopItemDSP instead, which handles both DO clauses (firstprivate,
lastprivate) correctly.

One line change in OpenMP.cpp

Tests added:

Lowering test to check MLIR generation
Runtime test to verify the actual values are correct
<img width="740" height="440" alt="image"
src="https://github.com/user-attachments/assets/fa911ea8-2024-4edf-b710-52c10659742e"
/>


Fixes #168306

---------

Co-authored-by: Krish Gupta <krishgupta@Krishs-MacBook-Air.local>
2025-12-09 15:10:21 +00: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
d989ff93e2
[flang][OpenMP] Add lowering of subroutine calls in custom reduction combiners (#169808)
This patch adds support for lowering subroutine calls in custom
reduction combiners to MLIR.
2025-11-28 09:00:18 -05:00
Krzysztof Parzyszek
fd22706e93
[flang][OpenMP] Skip compiler directives in getCollapsedLoopEval (#169565)
Use `getNestedDoConstruct` from Utils to get the nested DoConstructs.

Fixes https://github.com/llvm/llvm-project/issues/169532
2025-11-25 17:30:28 -06: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
Ferran Toda
f4ebee0ca9
[Flang][OpenMP] Add semantic support for Loop Sequences and OpenMP loop fuse (#161213)
This patch adds semantics for the `omp fuse` directive in flang, as
specified in OpenMP 6.0. This patch also enables semantic support for
loop sequences which are needed for the fuse directive along with
semantics for the `looprange` clause. These changes are only semantic.
Relevant tests have been added , and previous behavior is retained with
no changes.

---------

Co-authored-by: Ferran Toda <ferran.todacasaban@bsc.es>
Co-authored-by: Krzysztof Parzyszek <Krzysztof.Parzyszek@amd.com>
2025-11-21 08:16:30 -06:00
Krzysztof Parzyszek
d69320e775
[OpenMP] Introduce "loop sequence" as directive association (#168934)
OpenMP 6.0 introduced a `fuse` directive, and with it a "loop sequence"
as the associated code. What used to be "loop association" has become
"loop-nest association".

Rename Association::Loop to LoopNest, add Association::LoopSeq to
represent the "loop sequence" association.

Change the association of fuse from "block" to "loop sequence".
2025-11-21 07:40:44 -06: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
Krzysztof Parzyszek
e70e9ec3b8
[flang][OpenMP] Store Block in OpenMPLoopConstruct, add access functions (#168078)
Instead of storing a variant with specific types, store parser::Block as
the body. Add two access functions to make the traversal of the nest
simpler.

This will allow storing loop-nest sequences in the future.
2025-11-17 08:02:36 -06: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
Jack Styles
7838dbee3a
[Flang][OpenMP] Add Lowering support for Collapse with Taskloop (#166791)
Support for lowering collapse already exists within
`genLoopNestClauses`, which is called when lowering taskloop. However,
the TODO message still included the Collapse clause, so it was not
activated. By removing this, it enables lowering of the Collapse clause
in taskloop.
2025-11-12 13:15:34 +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
Kaviya Rajendiran
faf9ac0f6f
[Flang][MLIR][OpenMP] Add MLIR lowering support for taskloop clauses. (#165851)
This patch add MLIR lowering support for the following taskloop clauses:

1. Default clause
2. Shared clause
3. Allocate clause
4. Final clause
5. If clause
6. Mergeable clause
7. Priority clause
8. Untied clause
2025-11-11 09:49:14 +05:30
agozillon
86fa018a1d
[Flang][OpenMP] Initial defaultmap(none) implementation (#166715)
This PR adds defaultmap(none) behaviour to Flang, where we emit a
semantic error if variables within the target construct do not have an
associated data attribute. Similar to the way default behaves, as
described by the OpenMP specification.
2025-11-11 03:15:58 +01:00
Krzysztof Parzyszek
3d3fab17f5
[flang][OpenMP] Use OmpDirectiveSpecification in ALLOCATE (#165865)
The ALLOCATE directive has two forms:
- A declarative form with a standalone directive:
  ```
  !$OMP ALLOCATE (variable-list-item...)
  ```
- An executable form that consists of several directives followed by an
ALLOCATE statement:
  ```
  !$OMP ALLOCATE (variable-list-item...)
  !$OMP ALLOCATE (variable-list-item...)
  ...
  ALLOCATE (...)
  ```

The second form was deprecated in OpenMP 5.2 in favor of the ALLOCATORS
construct.

Since in the parse tree every type corresponding to a directive only
corresponds to a single directive, the executable form is represented by
a sequence of nested OmpAllocateDirectives, e.g.
```
   !$OMP ALLOCATE(x)
   !$OMP ALLOCATE(y)
   ALLOCATE(x, y)
```
will become
```
   OmpAllocateDirective
   |- ALLOCATE(x)            // begin directive
   `- OmpAllocateDirective   // block
      |- ALLOCATE(y)            // begin directive
      `- ALLOCATE(x, y)         // block
```
With this change all AST nodes for directives use
OmpDirectiveSpecification as the directive representation.
2025-11-03 07:37:13 -06:00
Jakub Kuderski
23ead47655
[flang][mlir] Migrate to free create functions. NFC. (#164657)
See
https://discourse.llvm.org/t/psa-opty-create-now-with-100-more-tab-complete/87339.

I plan to mark these as deprecated in
https://github.com/llvm/llvm-project/pull/164649.
2025-10-22 12:47:48 -04:00
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
Peter Klausler
5cd9f0f655
[flang] Move parse tree tool to Parser/tools.h (#163998)
Move the parse tree utility function
semantics::getDesignatorNameIfDataRef to Parser/tools.h and rename it to
comply with the local style.
2025-10-20 13:20:33 -07:00
Krzysztof Parzyszek
d55879de50
[flang][OpenMP] Emit requirements in module files (#163449)
For each program unit, collect the set of requirements from REQUIRES
directives in the source, and modules used by the program unit, and add
them to the details of the program unit symbol.

The requirements in the symbol details as now stored as clauses. Since
requirements need to be emitted in the module files as OpenMP
directives, this makes the clause emission straightforward via
getOpenMPClauseName.

Each program unit, including modules, the corresponding symbol will have
the transitive closure of the requirements for everything contained or
used in that program unit.
2025-10-16 07:02:49 -05:00
Kelvin Li
7eee672023
[flang] Fix build breakage with FLANG_ENABLE_WERROR on (NFC) (#162894) 2025-10-11 09:48:02 -04:00
Alexey Bataev
6a02c0f2fa
[Flang]Fix propagation of loop collapse number for target-based directives (#162707) 2025-10-09 14:32:10 -04: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
Krzysztof Parzyszek
727aad15f0
[flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_TARGET (#160573) 2025-09-26 15:47:31 -05:00
Krzysztof Parzyszek
3ca59104cf
[flang][OpenMP] Use OmpDirectiveSpecification in DECLARE_MAPPER (#160169) 2025-09-23 08:50:15 -05:00
Krzysztof Parzyszek
8c189327e5
[flang][OpenMP] Use OmpDirectiveSpecification in SECTIONS (#159580) 2025-09-19 10:50:23 -05:00
Krzysztof Parzyszek
e75e28ad3c
[flang][OpenMP] Use OmpDirectiveSpecification in Omp[Begin|End]LoopDi… (#159087)
…rective

This makes accessing directive components, such as directive name or the
list of clauses simpler and more uniform across different directives. It
also makes the parser simpler, since it reuses existing parsing
functionality.

The changes are scattered over a number of files, but they all share the
same nature:
- getting the begin/end directive from OpenMPLoopConstruct,
- getting the llvm::omp::Directive enum, and the source location,
- getting the clause list.
2025-09-16 11:38:03 -05:00
Akash Banerjee
5365f8bc91
Revert "[NFC][Flang] Move bounds helper functions to Util header." (#158654)
Reverts llvm/llvm-project#154164
2025-09-15 16:11:55 +01:00
Akash Banerjee
32ab6ff9f9
[NFC][Flang] Move bounds helper functions to Util header. (#154164)
This PR moves the `needsBoundsOps` and `genBoundsOps` helper functions
to `flang/include/flang/Optimizer/OpenMP/Utils.h`.
2025-09-15 15:45:49 +01: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
Kareem Ergawy
c85e6ac74d
[NFC][flang][OpenMP] Extract target region utils to map or clone outside values (#155754)
Following up on #154483, this PR introduces further refactoring to
extract some shared utils between OpenMP lowering and `do concurrent`
conversion pass. In particular, this PR extracts 2 utils that handle
mapping or cloning values used inside target regions but defined
outside.

Later `do concurrent` PR(s) will also use these utils.

PR stack:
- https://github.com/llvm/llvm-project/pull/155754 ◀️
- https://github.com/llvm/llvm-project/pull/155987
- https://github.com/llvm/llvm-project/pull/155992
- https://github.com/llvm/llvm-project/pull/155993
- https://github.com/llvm/llvm-project/pull/156589
- https://github.com/llvm/llvm-project/pull/156610
- https://github.com/llvm/llvm-project/pull/156837
2025-09-08 14:33:00 +02: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
Krzysztof Parzyszek
88b71e2048
[flang][OpenMP] Replace OpenMPBlockConstruct with OmpBlockConstruct (#155872)
OpenMPBlockConstruct, somewhat confusingly, represents most but not all
block-associated constructs. It's derived from OmpBlockConstruct, as are
all the remaining block-associated constructs.

It does not correspond to any well-defined group of constructs. It's the
collection of constructs that don't have their own types (and those that
do have their own types do so for their own reasons).

Using the broader OmpBlockConstruct in type-based visitors won't cause
issues, because the specific overloads (for classes derived from it)
will always be preferred.
2025-08-29 07:37:48 -05:00
Kajetan Puchalski
9cf8752ccf
[flang][OpenMP] Handle symbols on composite simd with multiple privatizers (#155640)
In some cases, a clause on a composite simd construct applied to simd
can be using a symbol that is also used by another privatizer, not
applied to simd. Correctly handle this scenario by checking which
directive the privatizer is being generated for while determining
whether to emit the copy region.

Fixes #155195.

Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
2025-08-28 15:58:29 +01:00
Kareem Ergawy
86e4c175e3
[NFC][flang][OpenMP] Create FortranUtils lib and move createMapInfoOp to it (#154483) 2025-08-27 18:25:36 +02:00
Tom Eccles
044e1aabbd
[flang][OpenMP] move omp end sections validation to semantics (#154740)
See #90452. The old parse tree errors exploded to thousands of unhelpful
lines when there were multiple missing end directives.

Instead, allow a missing end directive in the parse tree then validate
that it is present during semantics (where the error messages are a lot
easier to control).
2025-08-26 10:45:56 +00:00
Chaitanya
21019a3c11
[flang][openmp] Add Lowering to omp mlir for workdistribute construct (#154378)
This PR adds lowering of workdistribute construct in flang to omp mlir dialect workdistribute op.

The work in this PR is c-p and updated from @ivanradanov commits from coexecute implementation:
flang_workdistribute_iwomp_2024
2025-08-26 09:30:21 +05:30
Krzysztof Parzyszek
42350f428d
[flang][OpenMP] Parse GROUPPRIVATE directive (#153807)
No semantic checks or lowering yet.
2025-08-19 08:32:43 -05:00
Kajetan Puchalski
d3d96e2057
[flang][OpenMP] Add -f[no]-openmp-simd (#150269)
Both clang and gfortran support the -fopenmp-simd flag, which enables
OpenMP support only for simd constructs, while disabling the rest of
OpenMP.

Implement the appropriate parse tree rewriting to remove non-SIMD OpenMP
constructs at the parsing stage.

Add a new SimdOnly flang OpenMP IR pass which rewrites generated OpenMP
FIR to handle untangling composite simd constructs, and clean up OpenMP
operations leftover after the parse tree rewriting stage.
With this approach, the two parts of the logic required to make the flag
work can be self-contained within the parse tree rewriter and the MLIR
pass, respectively. It does not need to be implemented within the core
lowering logic itself.

The flag is expected to have no effect if -fopenmp is passed explicitly,
and is only expected to remove OpenMP constructs, not things like OpenMP
library functions calls. This matches the behaviour of other compilers.

---------

Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
2025-08-14 14:20:15 +01:00