File tree Expand file tree Collapse file tree 4 files changed +25
-7
lines changed Expand file tree Collapse file tree 4 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -815,7 +815,10 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
815
815
assert (!getLangOpts ().CUDA || !getLangOpts ().CUDAIsDevice ||
816
816
getLangOpts ().GPUAllowDeviceInit );
817
817
if (getLangOpts ().HIP && getLangOpts ().CUDAIsDevice ) {
818
- Fn->setCallingConv (llvm::CallingConv::AMDGPU_KERNEL);
818
+ if (getTriple ().isSPIRV ())
819
+ Fn->setCallingConv (llvm::CallingConv::SPIR_KERNEL);
820
+ else
821
+ Fn->setCallingConv (llvm::CallingConv::AMDGPU_KERNEL);
819
822
Fn->addFnAttr (" device-init" );
820
823
}
821
824
@@ -973,7 +976,10 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
973
976
assert (!getLangOpts ().CUDA || !getLangOpts ().CUDAIsDevice ||
974
977
getLangOpts ().GPUAllowDeviceInit );
975
978
if (getLangOpts ().HIP && getLangOpts ().CUDAIsDevice ) {
976
- Fn->setCallingConv (llvm::CallingConv::AMDGPU_KERNEL);
979
+ if (getTriple ().isSPIRV ())
980
+ Fn->setCallingConv (llvm::CallingConv::SPIR_KERNEL);
981
+ else
982
+ Fn->setCallingConv (llvm::CallingConv::AMDGPU_KERNEL);
977
983
Fn->addFnAttr (" device-init" );
978
984
}
979
985
Original file line number Diff line number Diff line change @@ -3738,12 +3738,12 @@ static CallingConv getCCForDeclaratorChunk(
3738
3738
}
3739
3739
}
3740
3740
} else if (S.getLangOpts ().CUDA ) {
3741
- // If we're compiling CUDA/HIP code and targeting SPIR-V we need to make
3741
+ // If we're compiling CUDA/HIP code and targeting HIPSPV we need to make
3742
3742
// sure the kernels will be marked with the right calling convention so that
3743
- // they will be visible by the APIs that ingest SPIR-V.
3743
+ // they will be visible by the APIs that ingest SPIR-V. We do not do this
3744
+ // when targeting AMDGCNSPIRV, as it does not rely on OpenCL.
3744
3745
llvm::Triple Triple = S.Context .getTargetInfo ().getTriple ();
3745
- if (Triple.getArch () == llvm::Triple::spirv32 ||
3746
- Triple.getArch () == llvm::Triple::spirv64) {
3746
+ if (Triple.isSPIRV () && Triple.getVendor () != llvm::Triple::AMD) {
3747
3747
for (const ParsedAttr &AL : D.getDeclSpec ().getAttributes ()) {
3748
3748
if (AL.getKind () == ParsedAttr::AT_CUDAGlobal) {
3749
3749
CC = CC_OpenCLKernel;
Original file line number Diff line number Diff line change 4
4
// RUN: -fgpu-allow-device-init -x hip \
5
5
// RUN: -fno-threadsafe-statics -emit-llvm -o - %s \
6
6
// RUN: | FileCheck %s
7
+ // RUN: %clang_cc1 -triple spirv64-amd-amdhsa -fcuda-is-device -std=c++11 \
8
+ // RUN: -fgpu-allow-device-init -x hip \
9
+ // RUN: -fno-threadsafe-statics -emit-llvm -o - %s \
10
+ // RUN: | FileCheck %s --check-prefix=CHECK-SPIRV
7
11
8
12
#include " Inputs/cuda.h"
9
13
10
14
// CHECK: define internal amdgpu_kernel void @_GLOBAL__sub_I_device_init_fun.cu() #[[ATTR:[0-9]*]]
11
15
// CHECK: attributes #[[ATTR]] = {{.*}}"device-init"
16
+ // CHECK-SPIRV: define internal spir_kernel void @_GLOBAL__sub_I_device_init_fun.cu(){{.*}} #[[ATTR:[0-9]*]]
17
+ // CHECK-SPIRV: attributes #[[ATTR]] = {{.*}}"device-init"
12
18
13
19
__device__ void f ();
14
20
Original file line number Diff line number Diff line change 1
1
// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -emit-llvm -x hip %s -o - | FileCheck %s
2
+ // RUN: %clang_cc1 -triple spirv64-amd-amdhsa -fcuda-is-device -emit-llvm -x hip %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2
3
#include " Inputs/cuda.h"
3
4
4
5
// CHECK: define{{.*}} amdgpu_kernel void @_ZN1A6kernelEv
6
+ // CHECK-SPIRV: define{{.*}} spir_kernel void @_ZN1A6kernelEv
5
7
class A {
6
8
public:
7
9
static __global__ void kernel (){}
8
10
};
9
11
10
12
// CHECK: define{{.*}} void @_Z10non_kernelv
13
+ // CHECK-SPIRV: define{{.*}} void @_Z10non_kernelv
11
14
__device__ void non_kernel (){}
12
15
13
16
// CHECK: define{{.*}} amdgpu_kernel void @_Z6kerneli
17
+ // CHECK-SPIRV: define{{.*}} spir_kernel void @_Z6kerneli
14
18
__global__ void kernel (int x) {
15
19
non_kernel ();
16
20
}
17
21
18
22
// CHECK: define{{.*}} amdgpu_kernel void @_Z11EmptyKernelIvEvv
23
+ // CHECK-SPIRV: define{{.*}} spir_kernel void @_Z11EmptyKernelIvEvv
19
24
template <typename T>
20
25
__global__ void EmptyKernel (void ) {}
21
26
22
27
struct Dummy {
23
28
// / Type definition of the EmptyKernel kernel entry point
24
29
typedef void (*EmptyKernelPtr)();
25
- EmptyKernelPtr Empty () { return EmptyKernel<void >; }
30
+ EmptyKernelPtr Empty () { return EmptyKernel<void >; }
26
31
};
27
32
28
33
// CHECK: define{{.*}} amdgpu_kernel void @_Z15template_kernelI1AEvT_{{.*}} #[[ATTR:[0-9][0-9]*]]
34
+ // CHECK-SPIRV: define{{.*}} spir_kernel void @_Z15template_kernelI1AEvT_{{.*}} #[[ATTR:[0-9][0-9]*]]
29
35
template <class T >
30
36
__global__ void template_kernel (T x) {}
31
37
You can’t perform that action at this time.
0 commit comments