74 Commits

Author SHA1 Message Date
Valentin Clement (バレンタイン クレメン)
2837fd7e5a
[flang][openacc] Allow if_present multiple times on host_data and update (#135422)
Similar to #135415.

The spec has not strict restriction to allow a single `if_present`
clause on the host_data and update directives. Allowing this clause
multiple times does not change the semantic of it. This patch relax the
rules in ACC.td since there is no restriction in the standard.

The OpenACC dialect represents the `if_present` clause with a `UnitAttr`
so the attribute will be set if the is one or more `if_present` clause.
2025-04-11 14:01:03 -07:00
Valentin Clement (バレンタイン クレメン)
609361ab39
[flang][openacc] Allow finalize clause on exit data more than once (#135415)
The spec has not strict restriction to allow a single `finalize` clause
on the `exit data` directive. Allowing this clause multiple times does
not change the semantic of it. This patch relax the rules in `ACC.td`
since there is no restriction in the standard.

The OpenACC dialect represent the finalize clause with a UnitAttr so the
attribute will be set if the is one or more `finalize` clause.
2025-04-11 13:54:48 -07:00
Valentin Clement (バレンタイン クレメン)
8fb6bb3e23
[flang][openacc] Allow multiple device_type clauses on init and shutdown (#135314)
Relax the restriction for init and shutdown directives for device_type
clause. The clause can be allowed multiple times.
2025-04-11 10:15:17 -07:00
Valentin Clement (バレンタイン クレメン)
7f64e8f691
[flang][openacc] Avoid crash when variable is not declared in reduction (#114603) 2024-11-03 17:27:41 -08:00
jeanPerier
8ca6401fdd
[flang][openacc] parse and ignore non-standard shortloop clause (#106564)
shortloop is a non standard OpenACC extension
(https://docs.nvidia.com/hpc-sdk/pgi-compilers/2015/pgirn157.pdf) that
can be found on loop directives.

f18 parser was choking when seeing it. Since it can be found in existing
apps and is mainly an optimization hint, parse it on loop directives and
ignore it with a warning.

For the records, here is shortloop meaning according to the manual linked above:

"If the shortloop clause appears on a loop directive with the vector clause, it tells the compiler that the
loop trip count is less than or equal to the number of vector lanes created for that loop. This means the
value of the vector() clause on the loop directive in a kernels region, or the value of the
vector_length() clause on the parallel directive in a parallel region will be greater than or
equal to the loop trip count. This allows the compiler to generate more efficient code for the loop"
2024-08-30 09:26:22 +02: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
Valentin Clement
c8ad802443
[flang][openacc] Carry device dependent info for routine in the module file 2024-01-11 13:57:23 -08:00
Valentin Clement (バレンタイン クレメン)
238b5790ba
[flang][openacc] Do not accept static and num for gang clause on routine dir (#77673)
Only the dim argument is allowed on the gang clause for the routine
directive. Reject static and num arguments in the semantic check.
2024-01-11 13:42:52 -08:00
Valentin Clement (バレンタイン クレメン)
bdfe5d69de
[flang][openacc] Apply mutually exclusive clauses restriction to routine (#77802)
this patch enforce or fix the enforcement of two restrictions from
section 2.15.1:

> Only the gang, worker, vector, seq and bind clauses may follow a
device_type clause.

`seq` was not allowed after `device_type` with the current
implementation.

> Exactly one of the gang, worker, vector, or seq clauses must appear.

This was not properly checked. This patch check correctly for mutually
exclusion as described in section 2.4. Mutually exclusive clauses may
appear on the same directive if they apply for different device_type.
2024-01-11 13:10:53 -08:00
Valentin Clement (バレンタイン クレメン)
ed640420b5
[flang][openacc] Fix clauses check with device_type (#77389)
A couple of clauses are allowed multiple times when they are separated
by a device_type clause. This patch updates the ACC.td file to move
these clauses to the `allowedClause` list and the
`CheckAllowedOncePerGroup` function is used to make sure they appear
only once on the directive or for each device_type.
2024-01-09 09:51:41 -08:00
Valentin Clement (バレンタイン クレメン)
a1db874d35
[flang][openacc] Allow multiple clauses when in preceded by device_type (#73976)
Some clauses can be repeated on the compute construct when they are
placed after `device_type`. The semantic check was reporting an error
for these cases. This patch fixes this.
2023-11-30 13:16:53 -08:00
Valentin Clement (バレンタイン クレメン)
a6c02edd6e
[flang][openacc] Keep CYCLE check for compute and data construct (#73897)
Unlike mentioned in #73839, some OpenACC construct still need the cycle
branching check to be performed. This patch adds a list of construct
where the check is not needed (loop and combined construct) and add
tests to check where it is still needed.
2023-11-29 21:34:12 -08:00
Valentin Clement (バレンタイン クレメン)
a87ca1bbd9
[flang][openacc] Do not check for unlabelled CYCLE branching (#73839)
There is no such restriction for any OpenACC construct. This patch adds
a constexpr condition on the type of Directive.
2023-11-29 15:37:53 -08:00
Valentin Clement (バレンタイン クレメン)
f4c5c470cd
[flang][openacc] Enforce no branching out of compute region for combined construct (#73581)
`A program may not branch into or out of a compute construct.` This
restriction is also true for combined constructs. This patch enforce
this rule.
2023-11-28 08:50:30 -08: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
Peter Klausler
1c91d9bdea
[flang] Ensure that portability warnings are conditional (#71857)
Before emitting a warning message, code should check that the usage in
question should be diagnosed by calling ShouldWarn(). A fair number of
sites in the code do not, and can emit portability warnings
unconditionally, which can confuse a user that hasn't asked for them
(-pedantic) and isn't terribly concerned about portability *to* other
compilers.

Add calls to ShouldWarn() or IsEnabled() around messages that need them,
and add -pedantic to tests that now require it to test their portability
messages, and add more expected message lines to those tests when
-pedantic causes other diagnostics to fire.
2023-11-13 16:13:50 -08: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
Valentin Clement (バレンタイン クレメン)
72d8e47a2c
[flang][openacc] Allow scalar in acc cache directive (#70713) 2023-10-31 08:54:33 -07:00
Valentin Clement (バレンタイン クレメン)
b096b8b1ff
[flang][openacc] Warn only when the same variable is in the same declare (#70698)
A var may appear at most once in all the clauses of declare directives
for a function, subroutine, program, or module.
We raise an error when a var appears in two different clauses. If it is
in the same clauses, we just issue a warning.
2023-10-31 08:51:54 -07:00
Valentin Clement (バレンタイン クレメン)
f706837e2b
[flang][mlir][openacc] Switch device_type representation to an enum (#70250)
Switch the representation from scalar integer to a enumeration. The
parser transform the string in the input to the correct enumeration.
2023-10-30 09:51:42 -07: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
Valentin Clement (バレンタイン クレメン)
621a271aac
[flang][openacc] Warn for num_gangs, num_workers and vector_length on acc serial (#69622)
For portability with other compilers, just issue a portability warning
instead of a hard error when `num_gangs`, `num_workers` or
`vector_length` are present on an `!$acc serial` directive
2023-10-19 14:03:16 -07:00
Valentin Clement (バレンタイン クレメン)
d2e7a15dfb
[flang][openacc] Warn about misplaced end loop directive and ignore it (#69512)
Instead of raising an error for a misplaced `end loop directive`, just
warn about it and ignore it. This directive is an extension and is
optional.
2023-10-19 08:49:01 -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
Valentin Clement (バレンタイン クレメン)
cf670d5e56
[flang][openacc] Accept scalar integer expression in the if clause (#69381)
Relax the parser to accept scalar integer expression in addition to
scalar logical expression. The parser now accepts scalar expression and
the semantic checks its type.
2023-10-17 14:41:03 -07:00
Valentin Clement (バレンタイン クレメン)
6ade518323
[flang][openacc][NFC] Issue better error message when directive is wrong (#69034) 2023-10-16 08:52:02 -07:00
Valentin Clement (バレンタイン クレメン)
16cf9c9af0
[flang][openacc] Support labeled DO loop after acc combined directive (#66296)
This patch adds support for labeled do loop after combined directive. It
relaxes the initial parser and canonicalize labeled do loop into the
OpenACCCombinedConstruct.
2023-09-13 20:50:42 -07: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
Valentin Clement (バレンタイン クレメン)
c46d732fd7
[flang][openacc] Check atomic update lhs/rhs are scalar (#66113)
Add semantic check for `!$acc atomic update`. RHS and LHS of the update
assignment must be scalar.

Without this check the code was going all the way to MLIR and trigger a
verifier error. This gives better user error message.
2023-09-12 11:00:01 -07:00
Valentin Clement (バレンタイン クレメン)
db20592ffe
[flang][openacc] Add check for acc cache directive (#65807)
OpenACC 3.3 - 2.10 The cache directive may appear at the top of (inside
of) a loop.

This patch adds a semantic check to ensure the cache directive is inside
a loop.
2023-09-08 14:50:47 -07:00
Valentin Clement
e8824e05e3
[flang][openacc] Relax required clauses on acc data as portability warning
Some compilers accept `!$acc data` without any clauses. For portability
reason, this patch relaxes the strict error to a simple portability warning.

Reviewed By: razvanlupusoru, vzakhari

Differential Revision: https://reviews.llvm.org/D159019
2023-08-29 14:57:50 -07:00
Valentin Clement
d77ae428e0
Revert "[compiler-rt] Use just built libatomic if available"
This reverts commit 02fa9fc018db5b757a4ce129d85d64efefc8645c.

Commit message and content does not match. Revert to commit with
a proper commit message.
2023-08-29 14:54:33 -07:00
Alex Brachet
02fa9fc018
[compiler-rt] Use just built libatomic if available
Use libclang_rt.atomic.so instead of the libatomic installed
on the system if it is available.

Differential Revision: https://reviews.llvm.org/D151680
2023-08-29 14:53:01 -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
60090a50ff
[flang][openacc] Restrict number of device_type values on the set directive
The standard suggests that the value for the `device_type` clause on the
`set` directive is a list but this does not makes sense. Restrict the number
of value to one so it matches the runtime function.

Depends on D158644

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D158645
2023-08-23 11:59:49 -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
d94c042b6b
[flang][openacc] Restrict branching out of data construct
This restriction is not clearly stated in the OpenACC standard
but all other compilers enforce it and there no explanation to
what should happen if there is a branching out of the construct.
Add the restriction for now.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D158319
2023-08-21 08:37:52 -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
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
Valentin Clement
22f63b5c73
[flang][openacc] Retain the declare information in module file declaration
F18 produce a module file with a declaration part. This patch
propagates the OpenACC declare information in the module file along the variable
declaration.

Depends on D157042

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D157121
2023-08-04 14:03:16 -07: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
Valentin Clement
c988e78f8e
[flang][openacc] Enforce restriction on declare directive
Enforce the following restriction specified in 2.13
A var may appear at most once in all the clauses of declare directives for a
function, subroutine, program, or module.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156945
2023-08-02 21:27:00 -07:00
Valentin Clement
b1f3667a60
[flang][openacc] Disallow the zero modifier on the copyout clause with the declare directive
The OpenACC 3.3 specification does not allow the `zero` modifier
on the `copyout` clause used with the declare directive.

This is similar to D156703 for the create clause.

This might be missing piece in the spec but we disallow it until proven otherwise.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156825
2023-08-02 15:52:14 -07:00
Valentin Clement
887b69c1f1
[flang][openacc] Disallow the zero modifier on the create clause with the declare directive
The OpenACC 3.3 specification does not allow the `zero` modifier
on the `create` clause used with the declare directive.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D156703
2023-07-31 14:29:56 -07:00
Valentin Clement
d3a0df78bf
[flang][openacc] Add semantic check for reduction operator and types
Check the combination of reduction operator and types. This is
currently not checking common block and composite types.

Depends on D155105

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D155106
2023-07-13 08:55:01 -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