118 Commits

Author SHA1 Message Date
Kiran Chandramohan
96b112fb61
Revert "[flang][openmp] Adds Parser and Semantic Support for Interop Construct, and Init and Use Clauses." (#132005)
Reverts llvm/llvm-project#120584

Reverting due to CI failure
https://lab.llvm.org/buildbot/#/builders/157/builds/22946
2025-03-19 11:13:52 +00:00
swatheesh-mcw
ee8a759bfb
[flang][openmp] Adds Parser and Semantic Support for Interop Construct, and Init and Use Clauses. (#120584)
Adds Parser and Semantic Support for the below construct and clauses:
- Interop Construct
- Init Clause
- Use Clause

Note:
The other clauses supported by Interop Construct such as Destroy, Use,
Depend and Device are added already.
2025-03-19 10:49:17 +00:00
Mats Petersson
d0188ebcc2
[flang][OpenMP]Add symbls omp_in, omp_out and omp_priv in DECLARE RED… (#129908)
…UCTION

This patch allows better parsing of the reduction and initializer
components, including supporting derived types in both those places.

There is more work needed here, but this is a definite improvement in
what can be handled through parser and semantics.

Note that declare reduction is still not supported in lowering, so any
attempt to compile DECLARE REDUCTION code will end with a TODO aka "Not
yet implemented" abort in the compiler.

Note that this version of the code does not cover declaring multiple
reductions using the same name with different types. This is will be
fixed in a future patch. [This was also the case before this change].

One existing test modified to actually compile (as it didn't in the
original form).
2025-03-13 09:39:45 +00:00
Krzysztof Parzyszek
5ba7a3bd4c
[flang][OpenMP] Parse cancel-directive-name as clause (#130146)
The cancellable construct names on CANCEL or CANCELLATION POINT
directives are actually clauses (with the same names as the
corresponding constructs).

Instead of parsing them into a custom structure, parse them as a clause,
which will make CANCEL/CANCELLATION POINT follow the same uniform scheme
as other constructs (<directive> [(<arguments>)] [clauses]).
2025-03-10 11:58:02 -05:00
Krzysztof Parzyszek
4e453d5292
[flang][OpenMP] Accept old FLUSH syntax in METADIRECTIVE (#130122)
Accommodate it in OmpDirectiveSpecification, which may become the
primary component of the actual FLUSH construct in the future.
2025-03-10 08:12:46 -05:00
Krzysztof Parzyszek
90f45a15ab
[flang][OpenMP] Implement OmpDirectiveName, use in OmpDirectiveSpecif… (#130121)
…ication

The `OmpDirectiveName` class has a source in addition to wrapping the
llvm::omp::Directive.
2025-03-07 07:56:40 -06: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
Krzysztof Parzyszek
9573c62114
[flang][OpenMP] Accept modern syntax of FLUSH construct (#128975)
The syntax with the object list following the memory-order clause has
been removed in OpenMP 5.2. Still, accept that syntax with versions >=
5.2, but treat it as deprecated (and emit a warning).
2025-03-03 07:59:19 -06:00
Mats Petersson
50301052e9
[flang][OpenMP]Support for subroutine call for DECLARE REDUCTION init (#127889)
The DECLARE REDUCTION allows the initialization part to be either an
expression or a call to a subroutine.

This modifies the parsing and semantic analysis to allow the use of the
subroutine, in addition to the simple expression that was already
supported.

New tests in parser and semantics sections check that the generated
structure is as expected.

DECLARE REDUCTION lowering is not yet implemented, so will end in a
TODO. A new test with an init subroutine is added, that checks that this
variant also ends with a "Not yet implemented" message.
2025-03-03 13:49:51 +00:00
Mats Petersson
24b7759a9d
[FLANG][OpenMP]Add frontend support for ASSUME and ASSUMES (#120770)
Enough suport to parse correctly formed directives of !$OMP ASSUME and
!$OMP ASSUMES with teh related clauses that go with them: ABSENT,
CONTAINS, NO_OPENPP, NO_OPENMP_ROUTINES, NO_PARALLELISM and HOLDS.

Tests added for unparsing and dump parse-tree.

Semantics support is very minimal and no specific tests added.

The lowering will hit a TODO, and there are tests in Lower/OpenMP/Todo
to make it clear that this is currently expected behaviour.

---------

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
Co-authored-by: Krzysztof Parzyszek <Krzysztof.Parzyszek@amd.com>
2025-02-25 17:36:25 +00:00
Mats Petersson
0de2ccab7b
[flang][OpenMP]Improve support for DECLARE REDUCTION (#127088)
Part of the DECLARE REDUCTION was already supported by the parser, but
the semantics to add the reduction identifier wasn't implemented.

The semantics would not accept the name given by the reduction, so a few
lines added to support that.

Some tests were in place but not quite working, so fixed those up too.
Adding new tests for unparsing and parse-tree, as well as checking the
symbolic name being generated.

Lowering of DECLARE REDUCTION is not supported in this patch, and a test
that it hits the relevant TODO is in this patch (most of this was
already existing, but not actually testing the TODO message).
2025-02-19 10:39:43 +00:00
Krzysztof Parzyszek
e8100c399b
[flang][OpenMP] Handle directive arguments in OmpDirectiveSpecifier (#124278)
Implement parsing and symbol resolution for directives that take
arguments. There are a few, and most of them take objects. Special
handling is needed for two that take more specialized arguments: DECLARE
MAPPER and DECLARE REDUCTION.

This only affects directives in METADIRECTIVE's WHEN and OTHERWISE
clauses. Parsing and semantic checks of other cases is unaffected.
2025-02-03 12:58:42 -06:00
Krzysztof Parzyszek
6dfe20dbbd
[flang][OpenMP] Parse METADIRECTIVE in specification part (#123397)
Add METADIRECTIVE to the OpenMP declarative constructs as well. Emit a
TODO error for both declarative and executable cases.
2025-02-03 11:13:44 -06: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
c8593239a3
[flang][OpenMP] Make parsing of trait properties more context-sensitive (#122900)
A trait poperty can be one of serveral alternatives (name, expression,
etc.), and each property in a list was parsed as if it could be any of
these alternatives independently from other properties. This made the
parsing vulnerable to certain ambiguities in the trait grammar (provided
in the OpenMP spec).
At the same time the OpenMP spec gives the expected types of properties
for almost every trait: all properties listed for a given trait are
usually of the same type, e.g. names, clauses, etc.

Incorporate these restrictions into the parser, and additionally use
property extensions as the fallback if the parsing of the expected
property type failed. This is intended to allow the parser to succeed,
and instead let the semantic-checking code emit a more user-friendly
message.
2025-01-29 11:54:52 -06:00
Mats Petersson
8035d38daa
[Flang][OpenMP]Add parsing support for DISPATCH construct (#121982)
This allows the Flang parser to accept the !$OMP DISPATCH and related
clauses.

Lowering is currently not implemented. Tests for unparse and parse-tree
dump is provided, and one for checking that the lowering ends in a "not
yet implemented"

---------

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
2025-01-26 09:44:04 +00:00
Krzysztof Parzyszek
70e96dc3fb
[flang][OpenMP] Parsing context selectors for METADIRECTIVE (#121815)
This is just adding parsers for context selectors. There are no tests
because there is no way to execute these parsers yet.
2025-01-10 11:05:23 -06:00
Mats Petersson
4df366cd80
[FLANG][OpenMP]Add support for ALIGN clause on OMP ALLOCATE (#120791)
This is trivially additional support for the existing ALLOCATE
directive, which allows an ALIGN clause.

The ALLOCATE directive is currently not implemented, so this is just
addding the necessary parser parts to allow the compiler to not say
"Huh? I don't get this" [or "Expected OpenMP construct"] when it
encounters the ALIGN clause.

Some parser testing is updated and a new todo test, just in case the
feature of align clause is not supported by the initial support for
ALLOCATE.
2025-01-06 11:02:31 +00:00
Krzysztof Parzyszek
adeff9f63a
[flang][OpenMP] Allow utility constructs in specification part (#121509)
Allow utility constructs (error and nothing) to appear in the
specification part as well as the execution part. The exception is
"ERROR AT(EXECUTION)" which should only be in the execution part.
In case of ambiguity (the boundary between the specification and the
execution part), utility constructs will be parsed as belonging to the
specification part. In such cases move them to the execution part in the
OpenMP canonicalization code.
2025-01-03 09:21:36 -06:00
Krzysztof Parzyszek
df859f90aa
[flang][OpenMP] Frontend support for NOTHING directive (#120606)
Create OpenMPUtilityConstruct and put the two utility directives in it
(error and nothing). Rename OpenMPErrorConstruct to OmpErrorDirective.
2025-01-03 08:36:34 -06:00
Mats Petersson
75e6d0eb4d
[flang][OpenMP]Add support for OpenMP ERROR directive (#119582)
Lowering leads to a TODO, with a test to confirm.

Also testing unparse.

---------

Co-authored-by: Krzysztof Parzyszek <Krzysztof.Parzyszek@amd.com>
2024-12-13 14:05:48 +00:00
Ivan R. Ivanov
7c9404c279
[flang][OpenMP] Add frontend support for ompx_bare clause (#111106) 2024-12-13 21:44:43 +09: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
Mats Petersson
00e1cc4c9d
[flang][OpenMP]Add support for fail clause (#118683)
Support the atomic compare option of a fail(memory-order) clauses.

Additional tests introduced to check that parsing and semantics checks
for the new clause is handled.

Lowering for atomic compare is still unsupported and wil end in a TOOD
(aka "Not yet implemented"). A test for this case with the fail clause
is also present.
2024-12-11 16:29:02 +00: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
Mats Petersson
03b5f8f0f0
[flang][OpenMP]Add parsing and semantics support for ATOMIC COMPARE (#117032)
This adds a minimalistic implementation of parsing and semantics for the
ATOMIC COMPARE feature from OpenMP 5.1.

There is no lowering, just a TODO for that part. Some of the Semantics
is also just a comment explaining that more is needed.
2024-12-02 15:05:21 +00: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
Anchu Rajendran S
e67e09a77e
[Flang][OpenMP][Sema] Adding parsing and semantic support for scan directive. (#102792) 2024-11-15 09:10:36 -08:00
Mats Petersson
ec1e0c5ecd
[Flang][OMP]Add support for DECLARE MAPPER parsing and semantics (#115160)
Will hit a TODO in the lowering, which there are tests added to check
for this happening.
2024-11-14 09:35:34 +00:00
Krzysztof Parzyszek
71ae021359 [flang] Few minor formatting changes, NFC
This makes these files be invariant with respect to clang-format.
2024-11-13 13:02:07 -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
Kareem Ergawy
50e73aeea2
[flang][OpenMP] Parse bind clause for loop direcitve. (#113662)
Adds parsing for the `bind` clause. The clause was already part of the
`loop` direcitve's definition but parsing was still missing.
2024-11-08 05:17:31 +01: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
Kiran Chandramohan
092a819e94
[Flang][OpenMP] Add frontend support for directives involving master (#113893)
Issue deprecation warning for these directives.
Lowering currently supports parallel master, for all other combined or
composite directives involving master, issue TODO errors.

Note: The first commit changes the formatting and generalizes the
deprecation message emission for reuse in the second commit. I can pull
it out into a separate commit if required.
2024-10-30 10:58:26 +00: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