Commit Graph

251 Commits

Author SHA1 Message Date
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
Krzysztof Parzyszek
c57a8f5b3f [flang][OpenMP] Remove redundant Fortran:: from namespaces, NFC
Apply clang-format after the changes.
2024-12-13 11:00:05 -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
Thirumalai Shaktivel
e73ec1a74a [Flang][OpenMP] Add some semantic checks for Linear clause (#111354)
This PR adds all the missing semantics for the Linear clause based on
the OpenMP 5.2 restrictions. The restriction details are mentioned
below.

OpenMP 5.2:
5.4.6 linear Clause restrictions
- A linear-modifier may be specified as ref or uval only on a declare
simd directive.
- If linear-modifier is not ref, all list items must be of type integer.
- If linear-modifier is ref or uval, all list items must be dummy
arguments without the VALUE attribute.
- List items must not be Cray pointers or variables that have the
POINTER attribute. Cray pointer support has been deprecated.
- If linear-modifier is ref, list items must be polymorphic variables,
assumed-shape arrays, or variables with the ALLOCATABLE attribute.
- A common block name must not appear in a linear clause.
- The list-item cannot appear more than once

4.4.4 ordered Clause restriction
- If n is explicitly specified, a linear clause must not be specified on
the same directive.

5.11 aligned Clause restriction
- Each list item must have C_PTR or Cray pointer type or have the
POINTER or ALLOCATABLE attribute. Cray pointer support has been
deprecated.
2024-12-06 12:11:46 -06:00
Krzysztof Parzyszek
02db35a1d6 [flang][OpenMP] Implement CheckReductionObjects for all reduction c… (#118689)
…lauses

Currently we only do semantic checks for REDUCTION. There are two other
clauses, IN_REDUCTION, and TASK_REDUCTION which will also need those
checks. Implement a function that checks the common list-item
requirements for all those clauses.
2024-12-06 12:00:48 -06:00
Krzysztof Parzyszek
c282d79024 [flang][OpenMP] Use range-for to iterate over SymbolSourceMap, NFC
Avoid iterators, use structured bindings to unpack the [key, value]
pairs.
2024-12-04 12:52:34 -06:00
Krzysztof Parzyszek
3dcc52d464 [flang][OpenMP] Add comments to IsContiguous, improve formatting, NFC 2024-12-04 12:29:20 -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
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
b0e7383e59 Reapply [flang][OpenMP] Avoid early returns, NFC #117231 (#117325)
Two PRs were merged at the same time: one that modified `maybeApplyToV`
function, and shortly afterwards, this (the reverted) one that had the
old definition.

During the merge both definitions were retained leading to compilation
errors.

Reapply the reverted PR (1a08b15589) with the duplicate removed.
2024-11-23 10:29:52 -06:00
Raghu Maddhipatla
556ea5265a [Flang] [Semantics] [OpenMP] Added missing semantic check with nested target region. (#115344)
Issue semantic warning for any combination of nested OMP TARGET
directives inside another OMP TARGET region.

This change would not affect OMP TARGET inside an OMP TARGET DATA.
However, it issues warning for OMP TARGET DATA inside an OMP TARGET
region.
2024-11-22 08:24:08 -06:00
Kazu Hirata
764cfd7d09 Revert "[flang][OpenMP] Avoid early returns, NFC (#117231)"
This reverts commit 1a08b15589.

Buildbot failure:
https://lab.llvm.org/buildbot/#/builders/157/builds/13427
2024-11-21 19:16:36 -08:00
Krzysztof Parzyszek
1a08b15589 [flang][OpenMP] Avoid early returns, NFC (#117231)
Frontend code is generally nested.
Follow-up to https://github.com/llvm/llvm-project/pull/116658.
2024-11-21 17:51:01 -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
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
Krzysztof Parzyszek
0398cb4592 [flang][OpenMP][OpenACC] Use iterator_range in check-directive-struct… (#115872)
…ure, NFC

The OpenMP code is already using iterator_range, lift it to the shared
header file.
2024-11-15 11:54:58 -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
9652c1cc09 [flang][OpenMP] Use iterator_range/range-for for FindClauses, NFC (#115749)
Implement a thin wrapper `GetClauses` that returns llvm::iterator_range
made from the pair of iterators returned by FindClauses. This enables
the use of range-for, which in turn makes the code a little more
readable.
2024-11-12 07:40:46 -06:00
Kazu Hirata
2778af9a70 [flang] Fix warnings
This patch fixes:

  flang/lib/Semantics/check-omp-structure.cpp:979:24: error: unused
  variable 'top' [-Werror,-Wunused-variable]

  flang/lib/Semantics/check-omp-structure.cpp:4441:24: error: unused
  variable 'top' [-Werror,-Wunused-variable]
2024-11-11 10:09:24 -08: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
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
5f8b83e40c [flang][OpenMP] Deprecation message for DESTROY with no argument (#114988)
[5.2:625:17] The syntax of the DESTROY clause on the DEPOBJ construct
with no argument was deprecated.
2024-11-05 12:21:53 -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
c6cce261f5 [flang][OpenMP] Delete ununsed data member, NFC
The `SemanticsContext &sctx_` ended up being unused in the committed
version, but the declaration remained.

Credit to Kazu Hirata for noticing it.
2024-11-04 12:11:02 -06:00
Kazu Hirata
76c16651c9 [flang] Fix warnings
This patch fixes:

  flang/lib/Semantics/check-omp-structure.cpp:286:27: error: lambda
  capture 'this' is not used [-Werror,-Wunused-lambda-capture]

  flang/lib/Semantics/check-omp-structure.cpp:299:21: error: private
  field 'sctx_' is not used [-Werror,-Wunused-private-field]
2024-11-04 09:31:29 -08: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
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
46944d1f95 [flang][OpenMP] Extract OMP version hint into helper functions, NFC (#113621) 2024-10-29 06:43:40 -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
Kiran Chandramohan
843c2fbe7f Add parser+semantics support for scope construct (#113700)
Test parsing, semantics and a couple of basic semantic checks for
block/worksharing constructs.
Add TODO message in lowering.
2024-10-25 18:57:01 +01: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
NimishMishra
1cbc015551 [flang][OpenMP] Error out when CHARACTER type is used in atomic constructs (#113045)
According to OpenMPv5.2 1.2.6, "For Fortran, a scalar variable with
intrinsic type, as defined by the base language, excluding character
type.". Likewise, section 4.3.1.3 states that atomic operations are on
"scalar variables of intrinsic type". This PR hence introduces a check
to error out when CHARACTER type is used in atomic operations.

Fixes https://github.com/llvm/llvm-project/issues/112918
2024-10-22 19:29:21 -07:00