Skip to content

Commit cb3498c

Browse files
authored
[OpenMP][OpenMPIRBuilder] Support SPIR-V device variant matches (#126801)
We should be able to use `spirv64` as a device variant match and it should be considered a GPU. Also add the triple to an RTTI check. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent c77d202 commit cb3498c

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

clang/lib/CodeGen/CodeGenModule.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,8 @@ class CodeGenModule : public CodeGenTypeCache {
10671067
bool shouldEmitRTTI(bool ForEH = false) {
10681068
return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
10691069
!(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
1070-
(getTriple().isNVPTX() || getTriple().isAMDGPU()));
1070+
(getTriple().isNVPTX() || getTriple().isAMDGPU() ||
1071+
getTriple().isSPIRV()));
10711072
}
10721073

10731074
/// Get the address of the RTTI descriptor for the given type.
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -fopenmp-targets=spirv64-intel -emit-llvm-bc %s -o %t-host.bc -DDEVICE
2+
// RUN: %clang_cc1 -verify -triple spirv64-intel -aux-triple x86_64-unknown-unknown -fopenmp -fopenmp-is-target-device \
3+
// RUN:-fopenmp-host-ir-file-path %t-host.bc -nogpulib %s -emit-llvm -DDEVICE -o - | FileCheck %s
4+
5+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -fopenmp-targets=spirv64-intel -emit-llvm-bc %s -o %t-host.bc -DTARGET
6+
// RUN: %clang_cc1 -verify -triple spirv64-intel -aux-triple x86_64-unknown-unknown -fopenmp -fopenmp-is-target-device \
7+
// RUN: -fopenmp-host-ir-file-path %t-host.bc -nogpulib %s -emit-llvm -DTARGET -o - | FileCheck %s
8+
9+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -fopenmp-targets=spirv64-intel -emit-llvm-bc %s -o %t-host.bc -DTARGET_KIND
10+
// RUN: %clang_cc1 -verify -triple spirv64-intel -aux-triple x86_64-unknown-unknown -fopenmp -fopenmp-is-target-device \
11+
// RUN: -fopenmp-host-ir-file-path %t-host.bc -nogpulib %s -emit-llvm -DTARGET_KIND -o - | FileCheck %s
12+
13+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -fopenmp-targets=spirv64-intel -emit-llvm-bc %s -o %t-host.bc
14+
// RUN: %clang_cc1 -verify -triple spirv64-intel -aux-triple x86_64-unknown-unknown -fopenmp -fopenmp-is-target-device \
15+
// RUN: -fopenmp-host-ir-file-path %t-host.bc -nogpulib %s -emit-llvm -o - | FileCheck %s
16+
17+
// expected-no-diagnostics
18+
19+
#pragma omp declare target
20+
int foo() { return 0; }
21+
22+
#ifdef DEVICE
23+
#pragma omp begin declare variant match(device = {arch(spirv64)})
24+
#elif defined(TARGET)
25+
#pragma omp begin declare variant match(target_device = {arch(spirv64)})
26+
#elif defined(TARGET_KIND)
27+
#pragma omp begin declare variant match(target_device = {kind(gpu)})
28+
#else
29+
#pragma omp begin declare variant match(device = {kind(gpu)})
30+
#endif
31+
32+
int foo() { return 1; }
33+
#pragma omp end declare variant
34+
#pragma omp end declare target
35+
36+
// CHECK-DAG: define{{.*}} @{{"_Z[0-9]+foo\$ompvariant\$.*"}}()
37+
38+
// CHECK-DAG: call spir_func noundef i32 @{{"_Z[0-9]+foo\$ompvariant\$.*"}}()
39+
40+
int main() {
41+
int res;
42+
#pragma omp target map(from \
43+
: res)
44+
res = foo();
45+
return res;
46+
}

llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

+2
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,7 @@ __OMP_TRAIT_PROPERTY(device, arch, x86_64)
12691269
__OMP_TRAIT_PROPERTY(device, arch, amdgcn)
12701270
__OMP_TRAIT_PROPERTY(device, arch, nvptx)
12711271
__OMP_TRAIT_PROPERTY(device, arch, nvptx64)
1272+
__OMP_TRAIT_PROPERTY(device, arch, spirv64)
12721273

12731274
__OMP_TRAIT_SET(target_device)
12741275

@@ -1301,6 +1302,7 @@ __OMP_TRAIT_PROPERTY(target_device, arch, x86_64)
13011302
__OMP_TRAIT_PROPERTY(target_device, arch, amdgcn)
13021303
__OMP_TRAIT_PROPERTY(target_device, arch, nvptx)
13031304
__OMP_TRAIT_PROPERTY(target_device, arch, nvptx64)
1305+
__OMP_TRAIT_PROPERTY(target_device, arch, spirv64)
13041306

13051307
__OMP_TRAIT_SET(implementation)
13061308

llvm/lib/Frontend/OpenMP/OMPContext.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ OMPContext::OMPContext(bool IsDeviceCompilation, Triple TargetTriple,
5252
case Triple::amdgcn:
5353
case Triple::nvptx:
5454
case Triple::nvptx64:
55+
case Triple::spirv64:
5556
ActiveTraits.set(unsigned(TraitProperty::target_device_kind_gpu));
5657
break;
5758
default:
@@ -98,6 +99,7 @@ OMPContext::OMPContext(bool IsDeviceCompilation, Triple TargetTriple,
9899
case Triple::amdgcn:
99100
case Triple::nvptx:
100101
case Triple::nvptx64:
102+
case Triple::spirv64:
101103
ActiveTraits.set(unsigned(TraitProperty::device_kind_gpu));
102104
ActiveTraits.set(unsigned(TraitProperty::target_device_kind_gpu));
103105
break;

0 commit comments

Comments
 (0)