Commit Graph

107 Commits

Author SHA1 Message Date
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
Valentin Clement
c217ff8794 [flang][openacc] Add basic lowering for OpenACC declare construct in module
This patch adds the skeleton and the basic lowering for OpenACC declare
construct when located in the module declaration. This patch just lower the
create clause with or without modifier. Other clause and global descrutor
lowering will come in follow up patches to keep this one small enough for
review.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156266
2023-07-26 09:56:19 -07:00
Valentin Clement
a25edba7b5 [flang][NFC] Remove duplicate of getDesignatorNameIfDataRef function
Remove duplicate of the getDesignatorNameIfDataRef() function.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D155105
2023-07-13 08:53:19 -07:00
Valentin Clement
5a0b91fc28 [flang][openacc] Fix false positive error in common block resolution
The following error was triggered in the added test case.
This is a false positive.

COMMON block must be declared in the same scoping unit in which the OpenACC directive or clause appears

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D154742
2023-07-10 08:39:35 -07:00
Valentin Clement
85128d8b6a [flang][openacc] Fix false error when common block is in copy clause
Wrong error was reported mentioning that the common block was in
more than one data sharing clause.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D154393
2023-07-05 08:34:22 -07:00
Raghu Maddhipatla
f36a25479b [Flang] [OpenMP] [Semantics] Change SIMD ALIGNED clause support from parsing a std::list<Name> to OmpObjectlist
This is an assisting patch which is implemented to address review comment to switch std::list<Name> to OmpObjectlist from https://reviews.llvm.org/D142722.

Also addressed a semantic check https://github.com/llvm/llvm-project/issues/61161 OpenMP 5.2 standard states that only pointer variables (C_PTR, Cray pointers, POINTER or ALLOCATABLE items) can appear in SIMD aligned clause (section 5.11). And not to allow common block names on an ALIGNED clause.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D152637
2023-06-29 17:24:54 -05:00
Valentin Clement
45c97af55e [flang][openacc] Fix name resolution for fct name in acc routine
Name resolution was failing when the routine name is
a function/subroutine in the parent scope.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D154002
2023-06-29 09:05:50 -07:00
Valentin Clement
eeba037e0b [flang][openacc] Resolve symbol in device, host and self clause
Some symbols were not resolved in the device, host and self clause
resulting in an `Internal: no symbol found` error.

This patch adds symbol resolution for these clauses.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D153919
2023-06-28 09:08:42 -07:00
Valentin Clement
ae86fe8591 [flang][openacc] Add parser support for the force modifier in the collapse clause
This patch adds parser support for the force modifier on the collapse clause
introduced in OpenACC 3.3.
Lowering will currently hit a TODO as the MLIR representation of the acc.loop
might need some update.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D151974
2023-06-12 11:01:59 -07:00
Andrew Gozillon
70fc081f74 [Flang][OpenMP][Parser] Resolve Declare Target Directive Symbols
Currently symbols are not resolved for declare target
after they've been modified by prior passes. This can
lead to missing or incorrect symbols in subsequent
compiler phases when declare target is used with
more complex types e.g. common block.

This patch should allow these symbols to be
resolved appropriately.

Reviewers: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D151993
2023-06-02 14:28:48 -05:00
Kiran Chandramohan
218841af7c [Flang][OpenMP] Add Todo for doconcurrent with worksharing loop
This is a valid usage. We do not handle it as of now. Gfortran/Ifx produces an error, possibly because `do concurrent` was not allowed in previous versions of the OpenMP standard.

Fixes #62649

Reviewed By: Leporacanthicus

Differential Revision: https://reviews.llvm.org/D150869
2023-05-19 12:03:03 +00:00
Raghu Maddhipatla
f85a8456f1 [OpenMP][Flang][Semantics] Add semantics support for USE_DEVICE_ADDR clause on OMP TARGET DATA directive.
Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D149815
2023-05-10 19:17:47 -05:00
Ethan Luis McDonough
42df495114 [flang] OpenMP allocate directive parse tree fix
Addresses the same issue as the following abandoned revision: D104391.

Rewrite leading declarative allocations so they are nested within their respective executable allocate directive

Original:
ExecutionPartConstruct -> OpenMPDeclarativeAllocate
ExecutionPartConstruct -> OpenMPDeclarativeAllocate
ExecutionPartConstruct -> OpenMPExecutableAllocate

After rewriting:
ExecutionPartConstruct -> OpenMPExecutableAllocate
| ExecutionPartConstruct -> OpenMPDeclarativeAllocate
| ExecutionPartConstruct -> OpenMPDeclarativeAllocate

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D148409

Co-authored-by: Isaac Perry <isaac.perry@arm.com>
2023-05-05 15:50:49 -05:00
Ethan Luis McDonough
a6e616cdb1 Revert "[flang] OpenMP allocate directive parse tree fix"
This reverts commit 597d8563cd.
2023-05-05 15:47:00 -05:00