135 Commits

Author SHA1 Message Date
Tom Eccles
4befe65cf0
[flang][semantics][OpenMP] store DSA using ultimate sym (#107002)
Previously we tracked data sharing attributes by the symbol itself not
by the ultimate symbol. When the private clause came first, subsequent
uses of the symbol found a host-associated version instead of the
ultimate symbol and so the check didn't consider them to be the same
symbol. Always adding and checking for the ultimate symbol ensures that
we have the same behaviour no matter the order of clauses.

The modified list is only used for this multiple clause check.

Closes #78235
2024-09-03 10:19:22 +01:00
Leandro Lupori
216ba6bc6c
[flang][OpenMP] Privatize vars referenced in statement functions (#103390)
Variables referenced in the body of statement functions need to be
handled as if they are explicitly referenced. Otherwise, they are
skipped during implicit privatization, because statement functions
are represented as procedures in the parse tree.

To avoid missing symbols referenced only in statement functions
during implicit privatization, new symbols, associated with them,
are created and inserted into the context of the directive that
privatizes them. They are later collected and processed in
lowering. To avoid confusing these new symbols with regular ones,
they are tagged with the new OmpFromStmtFunction flag.

Fixes https://github.com/llvm/llvm-project/issues/74273
2024-08-26 08:39:32 -03:00
Leandro Lupori
062e69a647
[flang][OpenMP] Fix 2 more regressions after #101009 (#101538)
PR #101009 exposed a semantic check issue with OPTIONAL dummy
arguments.
Another issue occurred when using %{re,im,len,kind}, as these also
need to be skipped when handling variables with implicitly defined
DSAs.

These issues were found by Fujitsu testsuite.
2024-08-15 14:14:18 -03:00
Leandro Lupori
366eade911
[flang][OpenMP] Reland Fix copyprivate semantic checks (#95799) (#101009)
There are some cases in which variables used in OpenMP constructs
are predetermined as private. The semantic checks for copyprivate
were not handling those cases.

Besides that, shared symbols were not being properly represented
in some cases. When there was no previously declared private
(implicit) symbol, no new association symbols, representing
shared ones, were being created.

These symbols must always be inserted in constructs that may
privatize the original symbol: parallel, teams and task
generating constructs.

Fixes #87214 and #86907
2024-07-31 14:39:06 -03:00
Leandro Lupori
58fb51492d
Revert "[flang][OpenMP] Fix copyprivate semantic checks" (#100478)
Reverts llvm/llvm-project#95799

This caused errors in some internal test suites.
2024-07-24 19:14:59 -03:00
Anchu Rajendran S
a51d263282
Adding warning for Master as it is deprecated in 5.2 (#98955)
Since `master` is deprecated from OpenMP spec 5.2, warning is added.
Using `masked` is the recommended alternative as per spec
2024-07-23 09:19:54 -07:00
Leandro Lupori
eb9bf18891
[flang][OpenMP] Fix copyprivate semantic checks (#95799)
There are some cases in which variables used in OpenMP constructs
are predetermined as private. The semantic checks for copyprivate
were not handling those cases.

Besides that, shared symbols were not being properly represented
in some cases. When there was no previously declared private
(implicit) symbol, no new association symbols, representing
shared ones, were being created.

These symbols must always be inserted in constructs that may
privatize the original symbol: parallel, teams and task
generating constructs.

Fixes #87214 and #86907
2024-07-23 08:58:08 -03:00
harishch4
471ca9496f
[Flang][OpenMP]Make Do concurrent indices private (#93785)
Fixes: #85538
2024-07-02 09:21:24 +05:30
Anchu Rajendran S
826bde5d8a
Adding parsing support for omp loop, target loop directives (#93517)
Change adds parsing support for omp loop, omp target loop, omp target
parallel loop and omp target teams loop.
2024-06-21 09:40:34 +05:30
Anchu Rajendran S
6658e1a3fd
Adding parsing and semantic check support for omp masked (#91432)
omp masked directive in OpenMP 5.2 allows to specify code regions which
are expected to be executed by thread ids specified by the programmer.
Filter clause of the directive allows to specify the thread id. This
change adds the parsing support for the directive
2024-05-20 21:32:41 -07:00
Leandro Lupori
e365ac809e
[flang][OpenMP] Fix symbol handling in critical/sections constructs (#90671)
Fixes https://github.com/llvm/llvm-project/issues/78936
2024-05-06 08:18:02 -03:00
Leandro Lupori
1e9625e595
[flang][OpenMP] Support tasks' implicit firstprivate DSA (#85989)
Handle implicit firstprivate DSAs on task generating constructs.

Fixes https://github.com/llvm/llvm-project/issues/64480
2024-05-06 08:15:52 -03:00
agozillon
5850f6ba9b
[Flang][OpenMP] Parse and semantically analyze common blocks in map clauses correctly (#89847)
Currently, you cannot provide the common block syntax that you should be
able to provide for map clauses (and that you can for declare target)
e.g.:

` !$omp target map(tofrom: /var/)`

This PR seeks to change that and allow this syntax via a small tweak,
which may also allow a wider range of types to be provided without issue
as well via the utilisation of ResolveOmpObject a helper function used
by the majority of other OmpObject handling clauses.

A by product of this change, is that we now emit an error for the
following syntax, when provided to map clauses with an assumed size
array:

`!$omp target map(arr(:))`

This seems inline with the specification from what I understand of it
(do feel free to correct me if that is not your reading or I am
incorrect!) and other OpenMP compilers i.e. gfortran, ifx, ifort.
2024-05-03 14:10:28 +02:00
Leandro Lupori
5198923c70
[flang][OpenMP] Allow common blocks in nested directives (#88430)
COMMON block names must be declared in the same scoping unit in
which the OpenMP directive or clause appears, but OpenMP
constructs must not be considered as scoping units. Instead,
consider only program units and block constructs as such.
2024-04-22 10:19:42 -03:00
NimishMishra
506ff54792
[flang][Semantics] Fix updating flags of threadprivate symbols in presence of default clause (#78283)
Current semantic checks of default clause incorrectly update symbol
flags related to threadprivate symbols. This patch adds an additional
check to skip such updation should a symbol be already declared
threadprivate.

Fixes https://github.com/llvm/llvm-project/issues/78282
2024-04-11 22:12:14 -07:00
Leandro Lupori
edcf65d40c
[flang][OpenMP] Allow loop iteration variables in DSA clauses (#86194)
Iteration variables of non-associated loops may be listed in DSA
clauses.

Fixes https://github.com/llvm/llvm-project/issues/78938
2024-03-25 08:48:11 -03:00
Tom Eccles
53d8c6b1b1
[flang][Semantics][OpenMP] set intrinsic attr for reductions (#85114)
Reductions such as min are intrinsic procedures. This distinguishes them
from user defined reductions. Previously, the intrinsic attribute was
not set when visiting reduction clauses causing them to be missed.

wsloop-reduction-min.f90 (the other min reduction test) worked because
it contained "min" used as an intrinsic inside of the body of the
reduction. This allowed ResolveNamesVisitor::HandleProcedureName to set
the correct attribute on that Symbol.
2024-03-15 11:12:09 +00:00
Sergio Afonso
27498e9942
[Flang][OpenMP] Prevent ICE for certain constructs in unnamed programs (#73938)
This patch fixes #72748 by modifying the processing of program units to
search for a symbol to which OpenMP REQUIRES clauses can bind to. Rather
than picking up the first PFT node with a source reference and getting
its associated scope, it picks up the last one.

This avoids using the source from the first specification construct of
a nameless program, which can sometimes not be associated to any scope,
causing an ICE due to an invalid source location.
2024-02-22 14:35:05 +00:00
harishch4
40fae67a50
[Flang][OpenMP] Fix to construct-names inside OpenMP construct with default(none) (#82479)
When a do loop with a construct-name is used inside OpenMP construct
with default(none), an incorrect error will be raised as below.

```
program cn_and_default
    implicit none
    integer :: i

    !$omp parallel default(none)
        loop: do i = 1, 10
        end do loop
    !$omp end parallel
end program
```

> The DEFAULT(NONE) clause requires that 'loop' must be listed in a
data-sharing attribute clause

This patch fixes this by adding a condition to check and skip processing
construct-names.
2024-02-21 17:44:54 +05:30
Leandro Lupori
e6866955f6
[flang][OpenMP] Accept firstprivate vars in copyprivate (#80467)
This is patch 1 of 4, to add support for COPYPRIVATE.
Original PR: https://github.com/llvm/llvm-project/pull/73128
2024-02-06 10:02:42 -03:00
Valentin Clement
2f490f9246
[flang][openacc] Check trip count invariance with other IVs (#79906)
2.9.1 The trip count for all loops associated with the collapse clause must be
computable and invariant in all the loops.

This patch checks that loops part of a collapse nest does not depends on outer
loops induction variables.

The check is also applied to combined construct with a loop.
2024-01-30 14:48:17 -08:00
Valentin Clement
d9423398ea
Revert "[flang][openacc] Check trip count invariance with other IVs (#79906)"
This reverts commit 0fa4463e93dca275ee80fd85120e33ccc9f22c5e.

Breaks buildbot https://lab.llvm.org/buildbot/#/builders/268/builds/7155
2024-01-30 13:43:04 -08:00
Valentin Clement (バレンタイン クレメン)
0fa4463e93
[flang][openacc] Check trip count invariance with other IVs (#79906)
2.9.1 The trip count for all loops associated with the collapse clause
must be computable and invariant in all the loops.

This patch checks that iteration range of loops part of a collapse nest
does not depend on outer loops induction variables.

The check is also applied to combined construct with a loop.
2024-01-30 13:36:39 -08:00
harishch4
47bcc91e06
[Flang][OpenMP] Fix to variables not inheriting data sharing attributes (#79017)
When a default(none) clause exists and a threadprivate variable is used
inside the construct, the variable does not inherit threadprivate
behavior and throws the below error.

> error: The DEFAULT(NONE) clause requires that 'a' must be listed in a
data-sharing attribute clause

Added a condition to skip the error if it is a threadprivate variable.

Fixes: https://github.com/llvm/llvm-project/issues/49545
2024-01-23 15:16:49 +05:30
Kiran Chandramohan
aac1d9710b
[Flang][OpenMP] Consider renames when processing reduction intrinsics (#70822)
Fixes #68654

Depends on https://github.com/llvm/llvm-project/pull/70790
2024-01-19 15:17:21 +00:00
Peter Klausler
345c1ea881
[flang] Avoid new spurious error under -fopenacc (#78504)
Don't create HostAssocDetails symbols for subprograms in OpenACC
regions; it can cause warnings to became errors later in compilation
when calls do not appear to be to external procedures with implicit
interfaces.
2024-01-17 14:03:47 -08:00
Kiran Chandramohan
3ae87467a6
[Flang][OpenMP] Avoid default none errors for seq loop indices in par… (#76258)
…allel
2024-01-15 16:07:43 +00:00
Valentin Clement
c8ad802443
[flang][openacc] Carry device dependent info for routine in the module file 2024-01-11 13:57:23 -08:00
Shraiysh
8840eb3fb5
[flang][OpenMP] Add semantic check for declare target (#72770) 2023-11-22 16:13:14 -06:00
Valentin Clement (バレンタイン クレメン)
575c9bf940
[flang][openacc] Avoid crash when collapse loop nest has extra directive (#73166)
The compiler was crashing when the collapse loop nest could not be
retrieved because of extra acc loop directive inside it.
2023-11-22 13:01:12 -08: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
Valentin Clement (バレンタイン クレメン)
c3629923aa
[flang][openacc] Allow constant variable in data clause (#71580)
The check introduced in #71444 was to restrictive and this patch relax
it so data clause can accept constant.
2023-11-07 14:28:30 -08:00
Valentin Clement (バレンタイン クレメン)
6be6081610
[flang][openacc] Issue an error when TBP are used in data clause (#71444)
Putting a type-bound procedure in a data clause was crashing the
lowering. Issue a proper semantic error in this case.
2023-11-06 14:52:41 -08:00
Kiran Chandramohan
742d8eb96d
[Flang][OpenMP] Dont add PreDetermined Flag if symbol is privatized already (#70931)
If the symbol is already privatized due to a user specification then it
is not required to mark it as PreDetermined. This happens if there is a
sequential loop in a parallel region that has the private specification
for the index of the sequential loop.

Fixes #63143
2023-11-06 16:07:22 +00:00
Valentin Clement (バレンタイン クレメン)
72d8e47a2c
[flang][openacc] Allow scalar in acc cache directive (#70713) 2023-10-31 08:54:33 -07:00
Z572
558c1f123e
[Flang][OpenMP] skip CompilerDirective on ResolveOmpTopLevelParts. (#69580)
Fixes #68966
2023-10-28 08:28:55 +08:00
Valentin Clement (バレンタイン クレメン)
828674395b
[flang][openacc] Allow acc routine at the top level (#69936)
Some compilers allow the `$acc routine(<name>)` to be placed at the
program unit level. To be compatible, this patch enables the use of acc
routine at this level. These acc routine directives must have a name.
2023-10-24 09:17:48 -07:00
Valentin Clement (バレンタイン クレメン)
eb6ec17206
[flang][openacc] Do not error when bind symbol is defined later or external (#69657)
The symbol in bind clause on acc routine refers to a function or a
subroutine. This patch avoids to raise error when the function or
subroutine is declared later in the code or is external. This is in line
with normal procedure name resolution in Fortran code.
2023-10-19 17:25:05 -07:00
Razvan Lupusoru
362b115786
[flang][openacc] Avoid privatizing symbols during semantics (#69506)
During flang handling of semantics of OpenACC private/firstprivate/
reduction clauses (including the implicitly private loop IV), a new
scoped symbol was being created. This could lead to ambiguity in the
lowered FIR - aka having multiple fir.declare for the same symbol.
Because lowering of OpenACC does not materialize the meaning of the
private clauses (by actually creating a scoped local symbol), it does
not make sense to create a new symbol in semantics either.

I updated the acc-symbols01.f90 test to reflect this updated approach.
Technically, the test could be removed, but it made sense to keep in
place to highlight this intentional decision.
2023-10-18 14:55:42 -07:00
Leandro Lupori
499d41cef2
[flang][OpenMP] Fix threadprivate common blocks (#68739)
Using a threadprivate common block within a nested scope resulted
in compilation errors.

This happened because common block names were being first resolved
to those in the parent scope. Because of this, in a nested scope,
an inner threadprivate directive would be applied to the outter
common block. This caused a 'common_block appears in more than one
data-sharing clause' error.

Also, when a copyin clause in a parallel region tried to use the
common block, getting the inner version of it, their objects would
be missing the threadprivate attribute, causing a 'Non-THREADPRIVATE
object in COPYIN clause' error.

Fixes https://github.com/llvm/llvm-project/issues/61200
2023-10-16 09:12:53 -03:00
David Truby
f35e2d8022
[flang][openmp] Don't mark loop variables with explicit DSA as predetermined (#68723)
This patch fixes a bug where loop variables are always marked as
predetermined
even when they have an explicit data sharing attribute specified.
2023-10-12 13:04:10 +01:00
Raghu Maddhipatla
80b571c66c
[Flang] [OpenMP] [Semantics] Add semantic support for IS_DEVICE_PTR nd HAS_DEVICE_ADDR clauses on OMP TARGET directive and add more semantic checks for OMP TARGET. (#67290)
Summary of this patch

- Add semantic support for HAS_DEVICE_ADDR and IS_DEVICE_PTR clauses.
- A list item that appears in an IS_DEVICE_PTR clause must be a valid
device pointer for the device data environment.
- A list item may not be specified in both an IS_DEVICE_PTR clause and a
HAS_DEVICE_ADDR clauses on the directive.
- A list item that appears in an IS_DEVICE_PTR or a HAS_DEVICE_ADDR
clauses must not be specified in any data-sharing attribute clause on
the same target construct.
2023-09-28 11:50:26 -05:00
Valentin Clement (バレンタイン クレメン)
bc32346082
[flang][openacc] Support labeled DO loop after acc loop directive (#66294)
Make the `DoConstruct` in `OpenACCLoopConstruct` optional and move the
labeled do construct in in the canonicalization step.
2023-09-13 20:50:20 -07:00
Sergio Afonso
edc2fb0733
[Flang][OpenMP][Sema] Support propagation of REQUIRES information across program units
Re-land commit 3787fd942f3927345320cc97a479f13e44355805

This patch adds support for storing OpenMP REQUIRES information in the
semantics symbols for programs/subprograms and modules/submodules, and
populates them during directive resolution. A pass is added to name resolution
that makes sure this information is also propagated across top-level programs,
functions and subprograms.

Storing REQUIRES information inside of semantics symbols will also allow
supporting the propagation of this information across Fortran modules. This
will come as a separate patch.

The `bool DirectiveAttributeVisitor::Pre(const parser::SpecificationPart &x)`
method is removed since it resulted in specification parts being visited twice.

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

Differential Revision: https://reviews.llvm.org/D157983
2023-09-11 15:01:57 +01:00
Sergio Afonso
4b9259b947
Revert "[Flang][OpenMP][Sema] Support propagation of REQUIRES information across program units"
Changes in this commit make some gfortran tests crash the compiler. It is
likely trying to dereference undefined symbol pointers.

This reverts commit 3787fd942f3927345320cc97a479f13e44355805.
2023-09-11 13:01:29 +01:00
Sergio Afonso
3787fd942f
[Flang][OpenMP][Sema] Support propagation of REQUIRES information across program units
This patch adds support for storing OpenMP REQUIRES information in the
semantics symbols for programs/subprograms and modules/submodules, and
populates them during directive resolution. A pass is added to name resolution
that makes sure this information is also propagated across top-level programs,
functions and subprograms.

Storing REQUIRES information inside of semantics symbols will also allow
supporting the propagation of this information across Fortran modules. This
will come as a separate patch.

The `bool DirectiveAttributeVisitor::Pre(const parser::SpecificationPart &x)`
method is removed since it resulted in specification parts being visited twice.

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

Differential Revision: https://reviews.llvm.org/D157983
2023-09-11 11:48:07 +01:00
Ethan Luis McDonough
9ac5b1f1b2
[flang][openmp] Semantic check for OpenMPExecutableAllocate
Executable allocate directives require that list items show up in the corresponding allocate statement.  This patch is dependent on revision D150428 and applies the semantic check introduced there to allocate directives associated with allocate statements.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D150483
2023-09-08 13:03:04 -05:00
Fangrui Song
872aa457ba [Semantics] Properly fix -Wcovered-switch-default after 6d1c183c6f8be717e466f6c55f74729d178c8ee2
And revert commit 9168fcacd8b3e3e4f17b12d4ea37dd7038c53640
"[flang] Fix -Wcovered-switch-default in resolve-directives.cpp (NFC)"
2023-09-07 20:57:09 -07:00
Jie Fu
9168fcacd8 [flang] Fix -Wcovered-switch-default in resolve-directives.cpp (NFC)
/data/llvm-project/flang/lib/Semantics/resolve-directives.cpp:555:7: error: default label in switch which covers all enumeration values [-Werror,-Wcovered-switch-default]
      default:
      ^
1 error generated.
2023-09-08 07:53:53 +08:00