Skip to content

Commit 15a1769

Browse files
committed
Emit OpenCL metadata when targeting SPIR-V
This is required for converting function calls such as get_global_id() into SPIR-V builtins. Differential Revision: https://reviews.llvm.org/D123049
1 parent 1acba8a commit 15a1769

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ void CodeGenModule::Release() {
784784
LangOpts.OpenMP);
785785

786786
// Emit OpenCL specific module metadata: OpenCL/SPIR version.
787-
if (LangOpts.OpenCL) {
787+
if (LangOpts.OpenCL || (LangOpts.CUDAIsDevice && getTriple().isSPIRV())) {
788788
EmitOpenCLMetadata();
789789
// Emit SPIR version.
790790
if (getTriple().isSPIR()) {

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,6 +3328,10 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
33283328
// whereas respecting contract flag in backend.
33293329
Opts.setDefaultFPContractMode(LangOptions::FPM_FastHonorPragmas);
33303330
} else if (Opts.CUDA) {
3331+
if (T.isSPIRV()) {
3332+
// Emit OpenCL version metadata in LLVM IR when targeting SPIR-V.
3333+
Opts.OpenCLVersion = 200;
3334+
}
33313335
// Allow fuse across statements disregarding pragmas.
33323336
Opts.setDefaultFPContractMode(LangOptions::FPM_Fast);
33333337
}

clang/test/CodeGenCUDASPIRV/kernel-cc.cu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
// CHECK: define spir_kernel void @_Z6kernelv()
88

99
__attribute__((global)) void kernel() { return; }
10+
11+
// CHECK: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
12+
// CHECK: [[OCL]] = !{i32 2, i32 0}

0 commit comments

Comments
 (0)