70 Commits

Author SHA1 Message Date
Krzysztof Parzyszek
8429f7faaa
[flang][OpenMP] Parsing support for DYN_GROUPPRIVATE (#153615)
This does not perform semantic checks or lowering.
2025-08-18 13:35:02 -05: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
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
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
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
Jack Styles
cb355def95
[Flang][OpenMP] Add Parsing support for Indirect Clause (#143505)
As part of OpenMP Version 5.1, support for the `indirect` clause was
added for the `declare target` directive. This clause should follow an
`enter` clause, and allows procedure calls to be done indirectly through
OpenMP.

This adds Parsing support for the clause, along with semantics checks.
Currently, lowering for the clause is not supported so a TODO message
will be outputted to the user. It also performs version checking as
`indirect` is only support in OpenMP 5.1 or greater.

See also: #110008
2025-06-17 09:05:36 +01:00
Tom Eccles
4a47634a00
[flang][OpenMP] Support substrings and complex part refs for DEPEND (#143907)
Fixes #142404

The parser can't tell the difference between array indexing and a
substring: that has to be done in semantics once we have types.
Substrings can only be in the form string([lower]:[higher]) not
string(index) or string(lower:higher:step). I added semantic checks to
catch this for the DEPEND clause.

This patch also adds lowering for correct substrings and for complex
part references.
2025-06-13 14:16:58 +01:00
agozillon
f687ed9ff7
[Flang][OpenMP] Initial defaultmap implementation (#135226)
This aims to implement most of the initial arguments for defaultmap
aside from firstprivate and none, and some of the more recent OpenMP 6
additions which will come in subsequent updates (with the OpenMP 6
variants needing parsing/semantic support first).
2025-05-12 16:30:43 +02:00
Krzysztof Parzyszek
760bba4666
[flang][OpenMP] Allow UPDATE clause to not have any arguments (#137521)
The UPDATE clause can be specified on both ATOMIC and DEPOBJ directives.
Currently, the ATOMIC directive has its own handling of it, and the
definition of the UPDATE clause only supports its use in the DEPOBJ
directive, where it takes a dependence-type as an argument.

The UPDATE clause on the ATOMIC directive may not have any arguments.
Since the implementation of the ATOMIC construct will be modified to use
the standard handling of clauses, the definition of UPDATE should
reflect that.
2025-05-01 13:30:45 -05:00
Krzysztof Parzyszek
386ff113f9
[flang][OpenMP] Use OmpMemoryOrderType enumeration in FAIL clause (#136313)
Make the FAIL clause contain OmpMemoryOrderType enumeration instead of
OmpClause. This simplifies the semantic checks of the FAIL clause.
2025-04-23 07:40:30 -05:00
Krzysztof Parzyszek
05b7e97c78
[flang][OpenMP] Extend common::AtomicDefaultMemOrderType enumeration (#136312)
Add "Acquire" and "Release", and rename it to OmpMemoryOrderType, since
memory order type is a concept extending beyond the
ATOMIC_DEFAULT_MEM_ORDER clause.

When processing a REQUIRES directive (in rewrite-directives.cpp), do not
add Acquire or Release to ATOMIC constructs, because handling of those
types depends on the OpenMP version, which is not available in that
file. This issue will be addressed later.
2025-04-23 05:57:52 -05:00
Krzysztof Parzyszek
b5eae19f64
[flang][OpenMP] Introduce OmpHintClause, simplify OmpAtomicClause (#136311)
The OmpAtomicClause is a variant of a few specific clauses that are used
on the ATOMIC construct. The HINT clause, however, was represented as a
generic OmpClause, which somewhat complicated the analysis of an
OmpAtomicClause.

Introduce OmpHintClause to represent the contents of the HINT clause,
and use it on OmpAtomicClause similarly to how OmpFailClause is used.
2025-04-22 14:05:32 -05:00
Tom Eccles
4c09ae0b2e
[flang][OpenMP] Lowering for CANCEL and CANCELLATIONPOINT (#134248)
These will still hit TODOs in OpenMPToLLVMIRConversion.cpp
2025-04-08 10:29:18 +01:00
Krzysztof Parzyszek
68180d8d16
[flang][OpenMP] Use OmpDirectiveSpecification in standalone directives (#131163)
This uses OmpDirectiveSpecification in the rest of the standalone
directives.
2025-03-20 06:50:43 -05:00
Kelvin Li
6c7c660afe
[flang] Use C-style casts to silence message (NFC) (#131796) 2025-03-18 13:02:18 -04:00
Kelvin Li
c2b66ce655
[flang][OpenMP] Silence unused-but-set-variable message (NFC) (#130979) 2025-03-13 14:09:47 -04:00
Ritanya-B-Bharadwaj
63635c1746
[clang] [OpenMP] New OpenMP 6.0 self_maps clause (#129888)
Initial parsing/sema support for self maps in map and requirement clause
[Sections 7.9.6 and 10.5.1.6 in OpenMP 6.0 spec]
2025-03-11 16:31:42 +05:30
Krzysztof Parzyszek
d67947162f
[flang][OpenMP] Implement HAS_DEVICE_ADDR clause (#128568)
The HAS_DEVICE_ADDR indicates that the object(s) listed exists at an
address that is a valid device address. Specifically,
`has_device_addr(x)` means that (in C/C++ terms) `&x` is a device
address.

When entering a target region, `x` does not need to be allocated on the
device, or have its contents copied over (in the absence of additional
mapping clauses). Passing its address verbatim to the region for use is
sufficient, and is the intended goal of the clause.

Some Fortran objects use descriptors in their in-memory representation.
If `x` had a descriptor, both the descriptor and the contents of `x`
would be located in the device memory. However, the descriptors are
managed by the compiler, and can be regenerated at various points as
needed. The address of the effective descriptor may change, hence it's
not safe to pass the address of the descriptor to the target region.
Instead, the descriptor itself is always copied, but for objects like
`x`, no further mapping takes place (as this keeps the storage pointer
in the descriptor unchanged).

---------

Co-authored-by: Sergio Afonso <safonsof@amd.com>
2025-03-10 08:11:01 -05:00
Mats Petersson
9925359fee
[flang][llvm][openmp]Add Initializer clause to OMP.td (#129540)
Then use this in the Flang compiler for parsing the OpenMP declare
reduction.

This has no real functional change to the existing code, it's only
moving the declaration itself around.

A few tests has been updated, to reflect the new type names.
2025-03-05 15:41:24 +00:00
David Pagan
8fb1b3f4b2
[flang][OpenMP] 'no_openmp_constructs' added to clang broke flang build (#126145)
Adding 'no_openmp_constructs' assumption clause to clang broke the flang
build. Adding to flang so it builds.

Testing
- Build
- Testing: check-all
2025-02-06 15:00:47 -08:00
Anchu Rajendran S
ccd92ec4c6
[flang][openmp] Changes for invoking scan Op (#123254) 2025-02-05 06:55:32 -08:00
Krzysztof Parzyszek
15ab7be2e0
[flang][OpenMP] Parse WHEN, OTHERWISE, MATCH clauses plus METADIRECTIVE (#121817)
Parse METADIRECTIVE as a standalone executable directive at the moment.
This will allow testing the parser code.

There is no lowering, not even clause conversion yet. There is also no
verification of the allowed values for trait sets, trait properties.
2025-01-29 15:07:20 -06:00
Krzysztof Parzyszek
03cbe42627
[flang][OpenMP] Rework LINEAR clause (#119278)
The OmpLinearClause class was a variant of two classes, one for when the
linear modifier was present, and one for when it was absent. These two
classes did not follow the conventions for parse tree nodes, (i.e.
tuple/wrapper/union formats), which necessitated specialization of the
parse tree visitor.

The new form of OmpLinearClause is the standard tuple with a list of
modifiers and an object list. The specialization of parse tree visitor
for it has been removed.
Parsing and unparsing of the new form bears additional complexity due to
syntactical differences between OpenMP 5.2 and prior versions: in OpenMP
5.2 the argument list is post-modified, while in the prior versions, the
step modifier was a post-modifier while the linear modifier had an
unusual syntax of `modifier(list)`.

With this change the LINEAR clause is no different from any other
clauses in terms of its structure and use of modifiers. Modifier
validation and all other checks work the same as with other clauses.
2024-12-12 12:19:35 -06:00
Krzysztof Parzyszek
58f9c4fc00
[flang][OpenMP] Semantic checks for IN_REDUCTION and TASK_REDUCTION (#118841)
Update parsing of these two clauses and add semantic checks for them.
Simplify some code in IsReductionAllowedForType and
CheckReductionOperator.
2024-12-12 12:19:12 -06:00
Krzysztof Parzyszek
33faa8285f
[flang][OpenMP] Use new modifiers in IF/LASTPRIVATE (#118128)
The usual changes, added more references to OpenMP specs.
2024-12-02 16:36:31 -06:00
Krzysztof Parzyszek
bde79c0e27
[flang][OpenMP] Use new modifiers in DEPEND/GRAINSIZE/NUM_TASKS (#117917)
The usual changes, added more references to OpenMP specs.
2024-12-02 15:22:05 -06:00
Krzysztof Parzyszek
05096590e0
[flang][OpenMP] Use new modifiers with AFFINITY/ALIGNED/DEVICE (#117786)
This is a mostly mechanical change from specific modifiers embedded
directly in a clause to the Modifier variant.

Additional comments and references to the OpenMP specs were added.
2024-12-02 10:46:06 -06:00
Krzysztof Parzyszek
608f4ae113
[flang][OpenMP] Rename some Type members in OpenMP clauses (#117784)
The intent is to keep names in sync with the terminology from the OpenMP
spec:
```
  OmpBindClause::Type       -> Binding
  OmpDefaultClause::Type    -> DataSharingAttribute
  OmpDeviceTypeClause::Type -> DeviceTypeDescription
  OmpProcBindClause::Type   -> AffinityPolicy
```
Add more comments with references to the OpenMP specs.
2024-12-02 09:22:30 -06:00
Krzysztof Parzyszek
cdbd22876b
[flang][OpenMP] Use new modifiers in ALLOCATE clause (#117627)
Again, this simplifies the semantic checks and lowering quite a bit.
Update the check for positive alignment to use a more informative
message, and to highlight the modifier itsef, not the whole clause.
Remove the checks for the allocator expression itself being positive:
there is nothing in the spec that says that it should be positive.

Remove the "simple" modifier from the AllocateT template, since both
simple and complex modifiers are the same thing, only differing in
syntax.
2024-12-02 08:11:49 -06:00
Krzysztof Parzyszek
52755ac253
[flang][OpenMP] Use new modifier infrastructure for MAP/FROM/TO clauses (#117447)
This removes the specialized parsers and helper classes for these
clauses, namely ConcatSeparated, MapModifiers, and MotionModifiers. Map
and the motion clauses are now handled in the same way as all other
clauses with modifiers, with one exception: the commas separating their
modifiers are optional. This syntax is deprecated in OpenMP 5.2.

Implement version checks for modifiers: for a given modifier on a given
clause, check if that modifier is allowed on this clause in the
specified OpenMP version. This replaced several individual checks.

Add a testcase for handling map modifiers in a different order, and for
diagnosing an ultimate modifier out of position.
2024-11-25 07:38:12 -06:00
Krzysztof Parzyszek
e79cd24676
[flang][OpenMP] Use new modifier code in ORDER and SCHEDULE clauses (#117081)
This actually simplifies the AST node for the schedule clause: the two
allowed modifiers can be easily classified as the ordering-modifier and
the chunk-modifier during parsing without the need to create additional
classes.
2024-11-21 17:50:37 -06:00
Krzysztof Parzyszek
4fc1141e76
[flang][OpenMP] Apply modifier representation to semantic checks (#116658)
Also, define helper macros in parse-tree.h.

Apply the new modifier representation to the DEFAULTMAP and REDUCTION
clauses, with testcases utilizing the new modifier validation.

OpenMP modifier overhaul: #3/3
2024-11-21 13:18:01 -06:00
Krzysztof Parzyszek
cfd67c2149
[flang][OpenMP] Normalize clause modifiers that exist on their own (#116655)
This is the first part of the effort to make parsing of clause modifiers
more uniform and robust. Currently, when multiple modifiers are allowed,
the parser will expect them to appear in a hard-coded order.
Additionally, modifier properties (such as "ultimate") are checked
separately for each case.

The overall plan is
1. Extract all modifiers into their own top-level classes, and then
equip them with sets of common properties that will allow performing the
property checks generically, without refering to the specific kind of
the modifier.
2. Define a parser (as a separate class) for each modifier.
3. For each clause define a union (std::variant) of all allowable
modifiers, and parse the modifiers as a list of these unions.

The intent is also to isolate parts of the code that could eventually be
auto-generated.

OpenMP modifier overhaul: #1/3
2024-11-20 08:33:17 -06:00
Mats Petersson
92604d7c80
[flang][OpenMP]Add parsing support for MAP(MAPPER(name) ...) (#116274)
This prepares for using the DECLARE MAPPER construct.

A check in lowering will say "Not implemented" when trying to use a
mapper as some code is required to tie the mapper to the declared one.

Senantics check for the symbol generated.
2024-11-20 09:23:41 +00:00
Krzysztof Parzyszek
4c4a4134d5
[flang][OpenMP] Update frontend support for DEFAULTMAP clause (#116506)
Add ALL variable category, implement semantic checks to verify the
validity of the clause, improve error messages, add testcases.

The variable category modifier is optional since 5.0, make sure we allow
it to be missing. If it is missing, assume "all" in clause conversion.
2024-11-18 07:04:10 -06:00
Kareem Ergawy
b4c0ef1822
[flang][OpenMP] Add MLIR lowering for loop ... bind (#114219)
Extends MLIR lowering support for the `loop` directive by adding
lowering support for the `bind` clause.

Parent PR: https://github.com/llvm/llvm-project/pull/114199, only the
latest commit is relevant to this PR.
2024-11-18 08:18:47 +01:00
Krzysztof Parzyszek
b08b252a02
[flang][OpenMP] Semantic checks for DOACROSS clause (#115397)
Keep track of loop constructs and OpenMP loop constructs that have been
entered. Use the information to validate the variables in the SINK loop
iteration vector.

---------

Co-authored-by: Tom Eccles <tom.eccles@arm.com>
2024-11-11 10:10:16 -06:00
Krzysztof Parzyszek
f87737f3fd
[flang][OpenMP] Parse DOACROSS clause (#115396)
Extract the SINK/SOURCE parse tree elements into a separate class
`OmpDoacross`, share them between DEPEND and DOACROSS clauses. Most of
the changes in Semantics are to accommodate the new contents of
OmpDependClause, and a mere introduction of OmpDoacrossClause.

There are no semantic checks specifically for DOACROSS.
2024-11-11 08:48:51 -06:00
Krzysztof Parzyszek
6fb36f0bd0 [flang][OpenMP] Remove std::variant with single alternative, NFC 2024-11-08 14:40:59 -06:00
Krzysztof Parzyszek
29d4d7f620
[flang][OpenMP] Add frontend support for INOUTSET and MUTEXINOUTSET (#114895)
These are additional modifiers of the "task dependence type" kind, which
is already handled by the frontend.
2024-11-05 10:40:43 -06:00
Krzysztof Parzyszek
1c6ec29b6b
[flang][OpenMP] Parsing support for iterator modifiers in FROM and TO (#114593)
Parse PRESENT modifier as well while we're at it (no MAPPER though). Add
semantic checks for these clauses in the TARGET UPDATE construct, TODO
messages in lowering.
2024-11-04 10:44:56 -06:00
NimishMishra
0653698d86
[flang][OpenMP] Add parsing support for Task detach (#112312)
Add parsing support for task detach, along with parse/unparse tests.
2024-11-04 06:43:47 -08:00
Krzysztof Parzyszek
c478aab684
[flang][OpenMP] Parser support for DEPOBJ plus DEPEND, DESTROY, UPDATE (#114074)
Parse the DEPOBJ construct and the associated clauses, perform basic
semantic checks.
2024-10-30 08:36:08 -05:00
Krzysztof Parzyszek
d48c849ea9
[flang][OpenMP] Parsing support for iterator in DEPEND clause (#113622)
Warn about use of iterators OpenMP versions that didn't have them
(support added in 5.0). Emit a TODO error in lowering.
2024-10-29 08:00:44 -05:00
Krzysztof Parzyszek
09a4bcf1a5
[flang][OpenMP] Update handling of DEPEND clause (#113620)
Parse the locator list in OmpDependClause as an OmpObjectList (instead
of a list of Designators). When a common block appears in the locator
list, show an informative message.
Implement resolving symbols in DependSinkVec in a dedicated visitor
instead of having a visitor for OmpDependClause.
Resolve unresolved names common blocks in OmpObjectList.

Minor changes to the code organization:
- rename OmpDependenceType to OmpTaskDependenceType (to follow 5.2
terminology),
- rename Depend::WithLocators to Depend::DepType,
- add comments with more detailed spec references to parse-tree.h.

---------

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
2024-10-28 16:06:22 -05:00
Kiran Chandramohan
5621929f7f
[Flang][OpenMP] Add parser support for grainsize and num_tasks clause (#113136)
These clauses are applicable only for the taskloop directive. Since the
directive has a TODO error, skipping the addition of TODOs for these
clauses.
2024-10-27 20:16:24 +00:00
Krzysztof Parzyszek
ea3534b385
[flang][OpenMP] Parse AFFINITY clause, lowering not supported yet (#113485)
Implement parsing of the AFFINITY clause on TASK construct, conversion
from the parser class to omp::Clause.
Lowering to HLFIR is unsupported, a TODO message is displayed.
2024-10-24 05:54:35 -05:00
Krzysztof Parzyszek
973fa983af
[flang][OpenMP] Parse iterators, add to MAP clause, TODO for lowering (#113167)
Define `OmpIteratorSpecifier` and `OmpIteratorModifier` parser classes,
and add parsing for them. Those are reusable between any clauses that
use iterator modifiers.

Add support for iterator modifiers to the MAP clause up to lowering,
where a TODO message is emitted.
2024-10-23 08:31:53 -05:00
Krzysztof Parzyszek
a8d506b320
[flang][OpenMP] Rename enum OmpxHold to Ompx_Hold in parser (#113366)
The convention is to use enum names that match the source spelling (up
to upper/lower case), including names with underscores.

Remove the special case from unparser, update tests.
2024-10-22 16:24:17 -05:00
Krzysztof Parzyszek
852e4779ba
[flang][OpenMP] Add Id function to OmpClause to return clause id,… (#112712)
… NFC

This replaces the two instances of `GetClauseKindForParserClass` with a
localized member function.
2024-10-18 07:17:01 -05:00