[clang] abbdc13 - [CUDA][SPIRV] Use OpenCLKernel CC for CUDA -> SPIRV
Artem Belevich via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 6 15:12:15 PST 2021
Author: Daniele Castagna
Date: 2021-12-06T15:06:57-08:00
New Revision: abbdc13e6803562bce4e42866a9ebf7f2a04a89b
URL: https://github.com/llvm/llvm-project/commit/abbdc13e6803562bce4e42866a9ebf7f2a04a89b
DIFF: https://github.com/llvm/llvm-project/commit/abbdc13e6803562bce4e42866a9ebf7f2a04a89b.diff
LOG: [CUDA][SPIRV] Use OpenCLKernel CC for CUDA -> SPIRV
Select the OpenCLKernel calling convention for kernels when compiling
CUDA targeting SPIR-V.
In this way the generated LLVM IR will have a spir_kernel calling
convention that will be translated to an OpEntryPoint when converting
to SPIRV.
Reviewed By: jlebar, tra
Differential Revision: https://reviews.llvm.org/D114407
Added:
clang/test/CodeGenCUDASPIRV/kernel-cc.cu
Modified:
clang/lib/Sema/SemaType.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index b786c9f050ec9..0607d3a774aad 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -3940,6 +3940,20 @@ static CallingConv getCCForDeclaratorChunk(
break;
}
}
+ } else if (S.getLangOpts().CUDA) {
+ // If we're compiling CUDA/HIP code and targeting SPIR-V we need to make
+ // sure the kernels will be marked with the right calling convention so that
+ // they will be visible by the APIs that ingest SPIR-V.
+ llvm::Triple Triple = S.Context.getTargetInfo().getTriple();
+ if (Triple.getArch() == llvm::Triple::spirv32 ||
+ Triple.getArch() == llvm::Triple::spirv64) {
+ for (const ParsedAttr &AL : D.getDeclSpec().getAttributes()) {
+ if (AL.getKind() == ParsedAttr::AT_CUDAGlobal) {
+ CC = CC_OpenCLKernel;
+ break;
+ }
+ }
+ }
}
return CC;
diff --git a/clang/test/CodeGenCUDASPIRV/kernel-cc.cu b/clang/test/CodeGenCUDASPIRV/kernel-cc.cu
new file mode 100644
index 0000000000000..1ba906ebc90d7
--- /dev/null
+++ b/clang/test/CodeGenCUDASPIRV/kernel-cc.cu
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fcuda-is-device -triple spirv32 -o - -emit-llvm -x cuda %s | FileCheck %s
+// RUN: %clang_cc1 -fcuda-is-device -triple spirv64 -o - -emit-llvm -x cuda %s | FileCheck %s
+
+// Verifies that building CUDA targeting SPIR-V {32,64} generates LLVM IR with
+// spir_kernel attributes for kernel functions.
+
+// CHECK: define spir_kernel void @_Z6kernelv()
+
+__attribute__((global)) void kernel() { return; }
More information about the cfe-commits
mailing list