145 Commits

Author SHA1 Message Date
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
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
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
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
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
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
Krzysztof Parzyszek
697d65ded6
[flang][OpenMP] Parsing support for map type modifiers (#111860)
This commit adds parsing of type modifiers for the MAP clause: CLOSE,
OMPX_HOLD, and PRESENT. The support for ALWAYS has already existed.

The new modifiers are not yet handled in lowering: when present, a TODO
message is emitted and compilation stops.
2024-10-11 11:38:32 -05:00
Krzysztof Parzyszek
d602f935da
[flang][OpenMP] Treat POINTER variables as valid variable list items (#111722)
Follow-up to 418920b3fbdefec5b56ee2b9db96884d0ada7329, which started
diagnosing the legality of objects in OpenMP clauses (and caused some
test failures).
2024-10-09 14:22:34 -05:00
Krzysztof Parzyszek
418920b3fb
[flang][OpenMP] Diagnose non-variable symbols in OpenMP clauses (#111394)
The original motivation came from this scenario:
```
!$omp parallel do shared(xyz)
  xyz: do i = 1, 100
  enddo xyz
!$omp end parallel do
```
Implement a general check for validity of items listed in OpenMP
clauses. In most cases they need to be variables, some clauses allow
"extended list items", i.e. variables or procedures.
2024-10-08 13:58:13 -05:00
Krzysztof Parzyszek
00ab44ee66
[flang][OpenMP] Add version checks for clauses (#110015)
If there is a clause that is allowed on a given directive in a later
version of the OpenMP spec, report an error and provide the minimal spec
version that allows the clause.

The case where a clause is not allowed on a directive at all is already
handled elsewhere.
2024-09-26 08:56:41 -05:00
harishch4
81dac7d613
[Flang][OpenMP] Add Semantic Checks for Atomic Capture Construct (#108516)
This PR adds semantic checks to ensure the atomic capture construct
conforms to one of the valid forms:
[capture-stmt, update-stmt], [capture-stmt, write-stmt] or [update-stmt,
capture-stmt].

Functions checkForSymbolMatch and checkForSingleVariableOnRHS are moved
from flang/lib/Lower/DirectivesCommon.h to flang/Semantics/tools.h for
reuse.

---------

Co-authored-by: Kiran Chandramohan <kiranchandramohan@gmail.com>
2024-09-25 09:29:44 +05:30
Kiran Chandramohan
977cb5d1cb
[Flang][OpenMP] Restrict certain loops not allowed in associated loops (#91818)
Extends the OmpCycleAndExitChecker to check that associated loops of a
loop construct are not DO WHILE or DO without control.

OpenMP 5.0 standard clearly mentions this restriction. Later standards
enforce this through the definition of associated loops and canonical
loop forms.
https://www.openmp.org/spec-html/5.0/openmpsu41.html

Fixes #81949
2024-07-16 11:41:19 +01:00
Krzysztof Parzyszek
2aa218c247
[flang][OpenMP] Diagnose invalid reduction modifiers (#92406)
Emit diagnostic messages for invalid modifiers in "reduction" clause.

Fixes https://github.com/llvm/llvm-project/issues/92397
2024-05-22 07:23:14 -05:00
Kiran Chandramohan
0661af893f
[Flang][OpenMP] Add restriction about subobjects to firstprivate and … (#89608)
…lastprivate

OpenMP 5.2 standard (Section 5.3) defines privatization for list items.
Section 3.2.1 in the standard defines list items to exclude variables
that are part of other variables.

This patch adds the restriction to firstprivate and lastprivates, it was
previously added for privates.

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

Note: The specific checks that are added here are explicitly called out
in OpenMP 4.0
(https://www.openmp.org/wp-content/uploads/OpenMP4.0.0.pdf) Sections
2.14.3.4 and 2.14.3.5 but in later standards have become implicit
through other definitions.
2024-04-23 12:56:52 +01:00
Krzysztof Parzyszek
4078afc6d2
[LLVM][OpenMP] Add "nowait" clause as valid for "workshare" (#88426)
Add the "nowait" clause to the list of allowed clauses for the "workshare"
directive. This will make it consistent with other directives (which are
shared between C/C++ and Fortran).

The parser will still reject "nowait" on "!$omp workshare", so this has no
effect on accepting/rejecting Fortran source code.
2024-04-12 14:52:24 -05:00
Kiran Kumar T P
666a61972f
[Flang] Add semantic check for usage of COPYPRIVATE and NOWAIT clauses (#73486)
1. COPYPRIVATE clause should be specified on END SINGLE construct.
2. NOWAIT clause should be specified on END DO/DO SIMD/SINGLE/SECTIONS
construct.

Special handling for semantic checks for nowait/copyprivate clause is
needed in Fortran due to the fact that Openmp pragmas for C/C++ doesn't
have end directive (clause). nowait/copyprivate clauses are allowed in
begin directive clause lists for C/C++ and it is not allowed for
Fortran.
2023-12-04 17:27:24 +05:30
Shraiysh
8840eb3fb5
[flang][OpenMP] Add semantic check for declare target (#72770) 2023-11-22 16:13:14 -06:00
Shraiysh
c06700bd75
Revert "[flang][OpenMP] Add semantic check for declare target" (#72592)
Reverts llvm/llvm-project#71861
2023-11-16 19:17:56 -06:00
Shraiysh
7ff8094a39
[flang][OpenMP] Add semantic check for declare target (#71861)
This patch adds the following check from OpenMP 5.2.

```
If the directive has a clause, it must contain at least one enter clause
or at least one link clause.
```

Also added a warning for the deprication of `TO` clause on `DECLARE
TARGET` construct.

```
The clause-name to may be used as a synonym for the clause-name enter.
This use has been deprecated.
```

Based on the tests for to clause, the tests for enter clause are added.

This patch does not add tests where both to and enter clause are used together.
2023-11-16 18:03:32 -06:00
Shraiysh
6846258aa6
[flang][OpenMP] Add semantic check for declare target (#71425)
This patch adds a semantic check for the following:

```
If a list item is a procedure name, it must not be a generic name,
procedure pointer, entry name, or statement function name.
```
2023-11-06 20:42:05 -06:00
Shraiysh
97c9c9429c
[flang][OpenMP] Added semantic checks for target update (#71270)
This patch adds the following semantic check for target update

```
At least one motion-clause must be specified.
```

A motion clause is either a `to` or a `from` clause.

This patch also adds a test for the following semantic check which was
already supported.

```
At most one nowait clause can appear on the directive.
```
2023-11-04 15:20:43 -05:00
Sergio Afonso
b49f846fe5
[Flang][OpenMP][Sema] Add directive rewrite pass to support atomic_default_mem_order REQUIRES clause
This patch creates the `OmpRewriteMutator` pass that runs at the end of
`RewriteParseTree()`. This pass is intended to make OpenMP-specific mutations
to the PFT after name resolution.

In the case of the `atomic_default_mem_order` clause of the REQUIRES directive,
name resolution results in populating global symbols with information about the
REQUIRES clauses that apply to that scope. The new rewrite pass is then able to
use this information in order to explicitly set the memory order of ATOMIC
constructs for which that is not already specified.

Given that this rewrite happens before semantics checks, the check of the order
in which ATOMIC constructs without explicit memory order and REQUIRES
directives with `atomic_default_mem_order` appear is moved earlier into the
rewrite pass. Otherwise, these problems would not be caught by semantics
checks, since the PFT would be modified by that stage.

This is patch 4/5 of a series splitting D149337 to simplify review.

Depends on D157983.

Differential Revision: https://reviews.llvm.org/D158096
2023-10-19 10:43:37 +01:00
Nimish Mishra
1c4c9e8e70 [flang][OpenMP] Added semantic checks for atomic capture, write, and update statements
This patch adds general checks for atomic read, write, and capture statements.

-check "capture statement is of the form v = x if atomic construct is read"
-check "write statement is of the form x = expr if atomic construct is write"
-check "x must not have the ALLOCATABLE attribute."
-check for non-scalar variables
-check if x (LHS variable) is accessed on the RHS of assignment statement
-improve error reporting in atomic update statemen

Reviewed By: TIFitis, raghavendhra

Differential Revision: https://reviews.llvm.org/D127620
2023-08-27 03:44:40 +00:00
Sergio Afonso
2221b758d2
[Flang][OpenMP][Sema] Add semantics checks for REQUIRES directive
This patch adds semantics checks for REQUIRES directives appearing after other
directives that are affected by them. In particular, it adds checks for device
constructs appearing after device-related REQUIRES directives and for the
`atomic_default_mem_order` clause appearing after atomic operations where the
memory order is not explicitly specified.

This is patch 2/5 of a series splitting D149337 to simplify review.

Depends on D157710.

Differential Revision: https://reviews.llvm.org/D157722
2023-08-15 12:38:14 +01:00
Sergio Afonso
e5a524b8b5
Revert "Revert "[Flang][Sema] Move directive sets to a shared location""
This reverts commit f48969f90769f37e042025dba6c544eeddd6d3e6.

Differential Revision: https://reviews.llvm.org/D157493
2023-08-10 11:54:45 +01:00
Raghu Maddhipatla
9c2d54e96d [OpenMP] [Flang] [Semantics] Add a missing semantic check for OMP DISTRIBUTE directive.
Added semantic support for following restriction which applies to OMP DISTRIBUTE directives

  - A list item may appear in a firstprivate or lastprivate clause but not both.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D157465
2023-08-09 13:03:28 -05:00
Kiran Chandramohan
f48969f907 Revert "[Flang][Sema] Move directive sets to a shared location"
This reverts commit ec70627dd17703a2a12ce0f28bd3794aa77d2058.

Reverting due to CI failure
2023-08-07 16:43:42 +00:00
Sergio Afonso
ec70627dd1
[Flang][Sema] Move directive sets to a shared location
This patch moves directive sets defined internally in Semantics to a header
accessible by other stages of the compiler to enable reuse. Some sets are
renamed/rearranged and others are lifted from local definitions to provide
a single source of truth.

Differential Revision: https://reviews.llvm.org/D157090
2023-08-07 11:18:43 +01:00
Sergio Afonso
65e80d6dfd
[Flang][OpenMP] Improve support for if clause on combined constructs
This patch adds support for matching multiple OpenMP `if` clauses to their
specified directive in a combined construct. It also enables this clause to be
attached by name to `simd` and `teams` directives, in addition to the others
that were already supported.

This patch on its own cannot yet be tested because there is currently no
lowering to MLIR support for any combined construct containing two or more
OpenMP directives that can have an `if` clause attached.

Depends on D155981.

Differential Revision: https://reviews.llvm.org/D156313
2023-08-04 10:43:12 +01:00
Raghu Maddhipatla
71d763b88d [OpenMP] [Semantics] [Flang] Adding more semantic checks for USE_DEVICE_PTR and USE_DEVICE_ADDR clauses.
The following restrictions for USE_DEVICE_PTR and USE_DEVICE_ADDR clauses on OMP TARGET DATA directive are implemented in this patch.

  - A list item may not be specified more than once in use_device_ptr clauses that appear on the directive.
  - A list item may not be specified more than once in use_device_addr clauses that appear on the directive.
  - A list item may not be specified in both a use_device_addr clause and a use_device_ptr clause on the directive.
  - A list item that appears in a use_device_ptr or use_device_addr clause must not be a structure element.
  - A list item that appears in a use_device_ptr must be of type C_PTR.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D155133
2023-08-04 00:19:36 -05:00
Ethan Luis McDonough
7f0d54b429
[flang][openmp] Allocators construct semantic checks
This patch applies the semantic checks for executable allocation directives to the new allocators construct.  It also introduces a new check that ensures all items in the list appear in the corresponding Fortran allocate statement.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D150428
2023-08-02 12:59:06 -05:00
Andrew Gozillon
39b747d0b5 [Flang][OpenMP][Sema] More gracefully handle undefined symbol in a no implicit module for declare target
Prior to this change, if you define a module as such with a declare target in it:

module test_0
    implicit none
!$omp declare target(no_implicit_materialization_1)
end module test_0

The compiler will crash rather than give some form of reasonable
diagnostic. This patch attempts to fix that.

Reviewers: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D149913
2023-05-05 06:29:51 -05:00
Kiran Chandramohan
460c2eaa4a [Flang][OpenMP] Restrict check to worksharing construct reductions
The outer context private check for reduction variables was firing
for all constructs. This check is not applicable to non-worksharing
constructs.

OpenMP 5.2: Section 5.5.8
A list item that appears in a reduction clause on a worksharing construct
must be shared in the parallel region to which a correspodning worksharing
region binds.

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D144824
2023-03-09 14:13:04 +00:00
Sergio Afonso
d5fb5960d0 [flang][OpenMP] Add parser support for Requires directive
OpenMP 5.0 adds support for the "requires" directive. This patch adds parser support for it in flang.

Differential revision: https://reviews.llvm.org/D136867
2022-11-10 05:38:31 -06:00
Nimish Mishra
7dc18a62e4 [flang][OpenMP] Added semantic checks for hint clause
This patch improves semantic checks for hint clause.
It checks "hint-expression is a constant expression
that evaluates to a scalar value with kind
`omp_sync_hint_kind` and a value that is a valid
synchronization hint."

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D127615
2022-07-14 18:24:57 +05:30
Nimish Mishra
c05b99971f [flang][OpenMP][NFC] Refactor code related to OpenMP atomic memory order clause semantics
Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D127822
2022-06-19 22:36:40 +05:30
Peixin-Qiao
9441003b52 [flang][OpenMP] Add one semantic check for data-sharing clauses
As OpenMP 5.0, for firstprivate, lastprivate, copyin, and copyprivate
clauses, if the list item is a polymorphic variable with the allocatable
attribute, the behavior is unspecified.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D127601
2022-06-15 16:02:27 +08:00
Arnamoy Bhattacharyya
314abe3922 [flang][OpenMP] Check for occurrence of multiple list items in nontemporal clause for simd directive
This patch implements the following semantic check:

A list-item cannot appear in more than one nontemporal clause.

Reviewed By: kiranchandramohan, shraiysh

Differential Revision: https://reviews.llvm.org/D110270
2022-05-30 10:59:23 -04:00
PeixinQiao
154135c11c [flang][OpenMP] Add semantic checks of nesting of region about ordered construct
This patch supports the following checks for ORDERED construct:

```
[5.1] 2.19.9 ORDERED Construct
The worksharing-loop or worksharing-loop SIMD region to which an ordered
region corresponding to an ordered construct without a depend clause
binds must have an ordered clause without the parameter specified on the
corresponding worksharing-loop or worksharing-loop SIMD directive.
The worksharing-loop region to which an ordered region that corresponds
to an ordered construct with any depend clauses binds must have an
ordered clause with the parameter specified on the corresponding
worksharing-loop directive.
An ordered construct with the depend clause specified must be closely
nested inside a worksharing-loop (or parallel worksharing-loop)
construct.
An ordered region that corresponds to an ordered construct with the simd
clause specified must be closely nested inside a simd or
worksharing-loop SIMD region.
```

Reviewed By: kiranchandramohan, shraiysh, NimishMishra

Differential Revision: https://reviews.llvm.org/D113399
2022-04-13 22:27:58 +08:00
Nimish Mishra
3519dcfec2 Added OpenMP 5.0 specification based semantic checks for atomic update construct 2022-01-24 13:24:00 +05:30
PeixinQiao
dd8c8d4b7c This patch supports the following checks for THREADPRIVATE Directive:
```
[5.1] 2.21.2 THREADPRIVATE Directive
A variable that appears in a threadprivate directive must be declared in
the scope of a module or have the SAVE attribute, either explicitly or
implicitly.
A variable that appears in a threadprivate directive must not be an
element of a common block or appear in an EQUIVALENCE statement.
```

This patch supports the following checks for DECLARE TARGET Directive:
```
[5.1] 2.14.7 Declare Target Directive
A variable that is part of another variable (as an array, structure
element or type parameter inquiry) cannot appear in a declare
target directive.
A variable that appears in a declare target directive must be declared
in the scope of a module or have the SAVE attribute, either explicitly
or implicitly.
A variable that appears in a declare target directive must not be an
element of a common block or appear in an EQUIVALENCE statement.
```

As Fortran 2018 standard [8.5.16] states, a variable, common block, or
procedure pointer declared in the scoping unit of a main program,
module, or submodule implicitly has the SAVE attribute, which may be
confirmed by explicit specification.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D109864
2021-10-17 22:08:02 +08:00
PeixinQiao
6fb01a9470 [flang][OpenMP] Add semantic checks for ordered construct
This patch implements the following semantic checks according to
OpenMP Version 5.1 Ordered construct restriction:

```
At most one threads clause can appear on an ordered construct; At most
one simd clause can appear on an ordered construct; At most one
depend(source) clause can appear on an ordered construct; Either
depend(sink:vec) clauses or depend(source) clauses may appear on an
ordered construct, but not both.
```

This patch also implements the following semantic checks according to
the syntax and descriptions in OpenMP Version 5.1 Ordered construct:

```
The dependence types of sink or source are only allowed on an ordered
construct. The depend(*) clauses are not allowed when ordered construct
is a block construct with an ordered region. The threads or simd clauses
are not allowed when the ordered construct is a standalone construct
with no ordered region.
```

Co-authored-by: Sameeran Joshi <sameeranjayant.joshi@amd.com>

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D108512
2021-09-17 21:53:07 +08:00
PeixinQiao
2685212184 [flang][OpenMP] Add semantic check for threadprivate directive
This patch implements the following check for THREADPRIVATE construct:
```
A variable that is part of another variable (as an array, structure
element or type parameter inquiry) cannot appear in a threadprivate
directive.
```

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D109685
2021-09-15 00:22:03 +08:00
PeixinQiao
3883e266f4 [flang][OpenMP] Add semantic check for target nesting
This patch implements the following check for TARGET construct:
```
OpenMP Version 5.0 Target construct restriction: If a target update,
target data, target enter data, or target exit data construct is
encountered during execution of a target region, the behavior is
unspecified.
```

Also add one test case for the check.

Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D106165
2021-08-18 09:40:52 +08:00
Peixin Qiao
42f5110701 [flang][OpenMP] Add semantic check for teams nesting
This patch implements the following check for TEAMS construct:
```
OpenMP Version 5.0 Teams construct restriction: A teams region can
only be strictly nested within the implicit parallel region or a target
region. If a teams construct is nested within a target construct, that
target construct must contain no statements, declarations or directives
outside of the teams construct.
```

Also add one test case for the check.

Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D106335
2021-08-13 10:42:47 -04:00
Peixin Qiao
70894c8dd1 [flang][OpenMP] Add semantic checks for cancellation nesting
This patch implements the following semantic checks for cancellation constructs:
```
OpenMP Version 5.0 Section 2.18.1: CANCEL construct restriction:
If construct-type-clause is taskgroup, the cancel construct must be
closely nested inside a task or a taskloop construct and the cancel
region must be closely nested inside a taskgroup region. If
construct-type-clause is sections, the cancel construct must be closely
nested inside a sections or section construct. Otherwise, the cancel
construct must be closely nested inside an OpenMP construct that matches
the type specified in construct-type-clause of the cancel construct.

OpenMP Version 5.0 Section 2.18.2: CANCELLATION POINT restriction:
A cancellation point construct for which construct-type-clause is
taskgroup must be closely nested inside a task or taskloop construct,
and the cancellation point region must be closely nested inside a
taskgroup region. A cancellation point construct for which
construct-type-clause is sections must be closely nested inside a
sections or section construct. A cancellation point construct for which
construct-type-clause is neither sections nor taskgroup must be closely
nested inside an OpenMP construct that matches the type specified in
construct-type-clause.
```

Also add test cases for the check.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D106538
2021-08-13 10:11:39 -04:00
Arnamoy Bhattacharyya
8fdd475c85 [flang][OpenMP] Add semantic checks for occurrence of nested Barrier regions
This patch adds the following nesting check for `barrier` constructs:

```
A barrier region may not be closely nested inside a worksharing, loop, task, taskloop, critical, ordered, atomic, or master region.
```

Also adds a test case for the check,

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D99888
2021-06-18 16:24:36 -04:00