2021-05-20 10:57:24 +08:00
// RUN: %clang_cc1 -verify=host -Rpass=openmp-opt -Rpass-analysis=openmp-opt -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
2022-04-12 04:14:22 +08:00
// RUN: %clang_cc1 -verify -Rpass=openmp-opt -Rpass-analysis=openmp-opt -fopenmp -O2 -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o %t.out
2020-07-15 08:11:30 +08:00
// host-no-diagnostics
2021-06-24 05:33:49 +08:00
void baz ( void ) __attribute__ ( ( assume ( " omp_no_openmp " ) ) ) ;
[OpenMP] Overhaul `declare target` handling
This patch fixes various issues with our prior `declare target` handling
and extends it to support `omp begin declare target` as well.
This started with PR49649 in mind, trying to provide a way for users to
avoid the "ref" global use introduced for globals with internal linkage.
From there it went down the rabbit hole, e.g., all variables, even
`nohost` ones, were emitted into the device code so it was impossible to
determine if "ref" was needed late in the game (based on the name only).
To make it really useful, `begin declare target` was needed as it can
carry the `device_type`. Not emitting variables eagerly had a ripple
effect. Finally, the precedence of the (explicit) declare target list
items needed to be taken into account, that meant we cannot just look
for any declare target attribute to make a decision. This caused the
handling of functions to require fixup as well.
I tried to clean up things while I was at it, e.g., we should not "parse
declarations and defintions" as part of OpenMP parsing, this will always
break at some point. Instead, we keep track what region we are in and
act on definitions and declarations instead, this is what we do for
declare variant and other begin/end directives already.
Highlights:
- new diagnosis for restrictions specificed in the standard,
- delayed emission of globals not mentioned in an explicit
list of a declare target,
- omission of `nohost` globals on the host and `host` globals on the
device,
- no explicit parsing of declarations in-between `omp [begin] declare
variant` and the corresponding end anymore, regular parsing instead,
- precedence for explicit mentions in `declare target` lists over
implicit mentions in the declaration-definition-seq, and
- `omp allocate` declarations will now replace an earlier emitted
global, if necessary.
---
Notes:
The patch is larger than I hoped but it turns out that most changes do
on their own lead to "inconsistent states", which seem less desirable
overall.
After working through this I feel the standard should remove the
explicit declare target forms as the delayed emission is horrible.
That said, while we delay things anyway, it seems to me we check too
often for the current status even though that is often not sufficient to
act upon. There seems to be a lot of duplication that can probably be
trimmed down. Eagerly emitting some things seems pretty weak as an
argument to keep so much logic around.
---
Reviewed By: ABataev
Differential Revision: https://reviews.llvm.org/D101030
2021-04-22 13:57:28 +08:00
void bar ( void ) {
2020-07-15 08:11:30 +08:00
# pragma omp parallel // #1 \
2021-07-14 03:31:44 +08:00
// expected-remark@#1 {{Parallel region is used in unknown ways. Will not attempt to rewrite the state machine. [OMP101]}}
2020-07-15 08:11:30 +08:00
{
}
}
void foo ( void ) {
2021-07-13 22:01:21 +08:00
# pragma omp target teams // #2
2021-07-14 03:31:44 +08:00
// expected-remark@#2 {{Rewriting generic-mode kernel with a customized state machine. [OMP131]}}
2020-07-15 08:11:30 +08:00
{
2021-07-14 03:31:44 +08:00
baz ( ) ; // expected-remark {{Value has potential side effects preventing SPMD-mode execution. Add `__attribute__((assume("ompx_spmd_amenable")))` to the called function to override. [OMP121]}}
2021-09-22 04:20:39 +08:00
# pragma omp parallel
2020-07-15 08:11:30 +08:00
{
}
bar ( ) ;
2021-09-22 04:20:39 +08:00
# pragma omp parallel
2020-07-15 08:11:30 +08:00
{
}
}
}
void spmd ( void ) {
// Verify we do not emit the remarks above for "SPMD" regions.
# pragma omp target teams
# pragma omp parallel
{
}
# pragma omp target teams distribute parallel for
for ( int i = 0 ; i < 100 ; + + i ) {
}
}
2021-07-14 03:31:44 +08:00
// expected-remark@* {{OpenMP runtime call __kmpc_global_thread_num deduplicated. [OMP170]}}