Commit Graph

120 Commits

Author SHA1 Message Date
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 0fa4463e93.

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 3787fd942f

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 3787fd942f.
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 6d1c183c6f
And revert commit 9168fcacd8
"[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
Raghu Maddhipatla
6d1c183c6f [Flang] [OpenMP] [Semantics] Add missing semantic check for MAP clause.
Added support for following semantic check for MAP clause.
  - A list item cannot appear in both a map clause and a data-sharing attribute clause on the same target construct.

Reviewed By: NimishMishra

Differential Revision: https://reviews.llvm.org/D158807
2023-09-07 15:42:25 -05:00
Peter Klausler
031b4e5e79 [flang] Support SELECT RANK on allocatables & pointers
Unlike other executable constructs with associating selectors, the
selector of a SELECT RANK construct can have the ALLOCATABLE or POINTER
attribute, and will work as an allocatable or object pointer within
each rank case, so long as there is no RANK(*) case.

Getting this right exposed a correctness risk with the popular
predicate IsAllocatableOrPointer() -- it will be true for procedure
pointers as well as object pointers, and in many contexts, a procedure
pointer should not be acceptable.  So this patch adds the new predicate
IsAllocatableOrObjectPointer(), and updates some call sites of the original
function to use the new one.

Differential Revision: https://reviews.llvm.org/D159043
2023-08-29 14:56:15 -07:00
Valentin Clement
760eca1d10 [flang][openacc] Accept !$acc end loop
Some compilers accept `!$acc end loop` associated with an `!$acc loop`
directive. This patch updates the acc loop parser to accept it as well.
The parser is also updated to be stricter on the following statement
to match the OpenACC combined construct parser.
The rewrite canonicalization is not a rewrite anymore and the naming
will be updated in a follow up patch for the Loop and Combined constructs.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D159015
2023-08-29 09:17:24 -07:00
Valentin Clement
c3afa7901d [flang][openacc] Fix function name resolution in acc routine
When acc routine is in a function, the first symbol resolved
was the function result and not the function name itself. It was
then failing the deferred attachment because the mangled name
had the entity attach to it. This patch fix the name resolution
for the function name in acc routine directive.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158868
2023-08-25 14:27:40 -07:00
Kazu Hirata
fae11ab208 [flang] Fix a warning
This patch fixes:

  flang/lib/Semantics/resolve-directives.cpp:899:29: error: moving a
  temporary object prevents copy elision [-Werror,-Wpessimizing-move]
2023-08-23 09:20:12 -07:00
Valentin Clement
22209a673e [flang][openacc] Keep routine information in the module file
This patch propagates the acc routine information
to the module file so they can be used by the caller.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158541
2023-08-23 08:56:55 -07:00
Valentin Clement
e2f6891551 [flang][openacc] Fix name resolution on routine bind clause
Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158120
2023-08-16 15:12:36 -07:00
Sergio Afonso
e5a524b8b5 Revert "Revert "[Flang][Sema] Move directive sets to a shared location""
This reverts commit f48969f907.

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
Valentin Clement
a749b32a11 [flang][openacc] Support readonly modifier for declare copyin in module file
Distinguish between copyin and copyin with the readonly modifier.

Depends on D157121

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D157125
2023-08-07 09:53:09 -07:00
Kiran Chandramohan
f48969f907 Revert "[Flang][Sema] Move directive sets to a shared location"
This reverts commit ec70627dd1.

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
Valentin Clement
ebf5f37130 [flang][openacc] Make sure the correct flags are set for symbol in acc declare
Flags were not correctly set for symbols appearing in the OpenACC declare
directive in module declaration part.

Also some missing flags for OpenACC are added. This makes the Flags enum
> 64 and then the implementation switch to std::bitset as defined in
`flang/include/flang/Common/enum-set.h`. Therefore, `constexpr` cannot be
used for set of flags in `flang/lib/Semantics/resolve-directives.cpp`.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D157042
2023-08-04 13:08:47 -07: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