2019-12-13 04:33:18 +08:00
|
|
|
// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefix HOST
|
2020-08-28 03:35:36 +08:00
|
|
|
// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-unknown-linux -emit-pch -o %t -fopenmp-version=45 %s
|
|
|
|
// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-unknown-linux -include-pch %t -verify %s -emit-llvm -o - -fopenmp-version=45 | FileCheck %s --check-prefix HOST
|
|
|
|
// RUN: %clang_cc1 -verify -fopenmp -x c -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc -fopenmp-version=45
|
|
|
|
// RUN: %clang_cc1 -verify -fopenmp -x c -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -fopenmp-version=45 | FileCheck %s --check-prefix GPU
|
|
|
|
// RUN: %clang_cc1 -verify -fopenmp -x c -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -emit-pch -o %t -fopenmp-version=45
|
|
|
|
// RUN: %clang_cc1 -verify -fopenmp -x c -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -include-pch %t -o - -fopenmp-version=45 | FileCheck %s --check-prefix GPU
|
|
|
|
|
|
|
|
// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s --check-prefix HOST
|
|
|
|
// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-unknown-linux -emit-pch -o %t %s
|
|
|
|
// RUN: %clang_cc1 -fopenmp -x c -triple x86_64-unknown-linux -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix HOST
|
|
|
|
// RUN: %clang_cc1 -verify -fopenmp -x c -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
|
|
|
|
// RUN: %clang_cc1 -verify -fopenmp -x c -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix GPU
|
|
|
|
// RUN: %clang_cc1 -verify -fopenmp -x c -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -emit-pch -o %t
|
|
|
|
// RUN: %clang_cc1 -verify -fopenmp -x c -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -include-pch %t -o - | FileCheck %s --check-prefix GPU
|
2019-12-13 04:33:18 +08:00
|
|
|
// expected-no-diagnostics
|
|
|
|
|
|
|
|
#ifndef HEADER
|
|
|
|
#define HEADER
|
|
|
|
|
|
|
|
int dev(double i) { return 0; }
|
|
|
|
|
|
|
|
int hst(double i) { return 1; }
|
|
|
|
|
|
|
|
#pragma omp declare variant(hst) match(device = {kind(host)})
|
|
|
|
#pragma omp declare variant(dev) match(device = {kind(gpu)})
|
|
|
|
int base();
|
|
|
|
|
2020-12-31 16:27:11 +08:00
|
|
|
// HOST-LABEL: define{{.*}} void @foo()
|
2021-11-09 01:09:49 +08:00
|
|
|
// HOST: call i32 @hst(double -1.000000e+00)
|
|
|
|
// HOST: call i32 @hst(double -2.000000e+00)
|
2020-08-28 03:35:36 +08:00
|
|
|
// HOST: call void [[OFFL:@.+_foo_l36]]()
|
2019-12-13 04:33:18 +08:00
|
|
|
void foo() {
|
|
|
|
base(-1);
|
|
|
|
hst(-2);
|
|
|
|
#pragma omp target
|
|
|
|
{
|
|
|
|
base(-3);
|
|
|
|
dev(-4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// HOST: define {{.*}}void [[OFFL]]()
|
2021-11-09 01:09:49 +08:00
|
|
|
// HOST: call i32 @hst(double -3.000000e+00)
|
|
|
|
// HOST: call i32 @dev(double -4.000000e+00)
|
2019-12-13 04:33:18 +08:00
|
|
|
|
2020-08-28 03:35:36 +08:00
|
|
|
// GPU: define {{.*}}void @__omp_offloading_{{.+}}_foo_l36()
|
2021-11-09 01:09:49 +08:00
|
|
|
// GPU: call i32 @dev(double -3.000000e+00)
|
|
|
|
// GPU: call i32 @dev(double -4.000000e+00)
|
2019-12-13 04:33:18 +08:00
|
|
|
|
[OpenMP] `omp begin/end declare variant` - part 2, sema ("+CG")
This is the second part loosely extracted from D71179 and cleaned up.
This patch provides semantic analysis support for `omp begin/end declare
variant`, mostly as defined in OpenMP technical report 8 (TR8) [0].
The sema handling makes code generation obsolete as we generate "the
right" calls that can just be handled as usual. This handling also
applies to the existing, albeit problematic, `omp declare variant
support`. As a consequence a lot of unneeded code generation and
complexity is removed.
A major purpose of this patch is to provide proper `math.h`/`cmath`
support for OpenMP target offloading. See PR42061, PR42798, PR42799. The
current code was developed with this feature in mind, see [1].
The logic is as follows:
If we have seen a `#pragma omp begin declare variant match(<SELECTOR>)`
but not the corresponding `end declare variant`, and we find a function
definition we will:
1) Create a function declaration for the definition we were about to generate.
2) Create a function definition but with a mangled name (according to
`<SELECTOR>`).
3) Annotate the declaration with the `OMPDeclareVariantAttr`, the same
one used already for `omp declare variant`, using and the mangled
function definition as specialization for the context defined by
`<SELECTOR>`.
When a call is created we inspect it. If the target has an
`OMPDeclareVariantAttr` attribute we try to specialize the call. To this
end, all variants are checked, the best applicable one is picked and a
new call to the specialization is created. The new call is used instead
of the original one to the base function. To keep the AST printing and
tooling possible we utilize the PseudoObjectExpr. The original call is
the syntactic expression, the specialized call is the semantic
expression.
[0] https://www.openmp.org/wp-content/uploads/openmp-TR8.pdf
[1] https://reviews.llvm.org/D61399#change-496lQkg0mhRN
Reviewers: kiranchandramohan, ABataev, RaviNarayanaswamy, gtbercea, grokos, sdmitriev, JonChesterfield, hfinkel, fghanim, aaron.ballman
Subscribers: bollu, guansong, openmp-commits, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75779
2020-02-26 06:04:06 +08:00
|
|
|
// GPU-NOT: @base
|
2019-12-13 04:33:18 +08:00
|
|
|
// GPU: define {{.*}}i32 @dev(double
|
|
|
|
// GPU: ret i32 0
|
|
|
|
|
|
|
|
#endif // HEADER
|