shangwuyao created this revision. shangwuyao added reviewers: jlebar, yaxunl, tra. Herald added subscribers: ldrumm, ThomasRaoux, Anastasia. Herald added a project: All. shangwuyao requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This is required for converting function calls such as get_global_id() into SPIR-V builtins. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D123049 Files: clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/test/CodeGenCUDASPIRV/kernel-cc.cu Index: clang/test/CodeGenCUDASPIRV/kernel-cc.cu =================================================================== --- clang/test/CodeGenCUDASPIRV/kernel-cc.cu +++ clang/test/CodeGenCUDASPIRV/kernel-cc.cu @@ -7,3 +7,6 @@ // CHECK: define spir_kernel void @_Z6kernelv() __attribute__((global)) void kernel() { return; } + +// CHECK: !opencl.ocl.version = !{[[OCL:![0-9]+]]} +// CHECK: [[OCL]] = !{i32 2, i32 0} Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -3312,6 +3312,10 @@ // whereas respecting contract flag in backend. Opts.setDefaultFPContractMode(LangOptions::FPM_FastHonorPragmas); } else if (Opts.CUDA) { + if (T.isSPIRV()) { + // Emit OpenCL version metadata in LLVM IR when targeting SPIR-V. + Opts.OpenCLVersion = 200; + } // Allow fuse across statements disregarding pragmas. Opts.setDefaultFPContractMode(LangOptions::FPM_Fast); } Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -784,7 +784,7 @@ LangOpts.OpenMP); // Emit OpenCL specific module metadata: OpenCL/SPIR version. - if (LangOpts.OpenCL) { + if (LangOpts.OpenCL || (LangOpts.CUDAIsDevice && getTriple().isSPIRV())) { EmitOpenCLMetadata(); // Emit SPIR version. if (getTriple().isSPIR()) {
Index: clang/test/CodeGenCUDASPIRV/kernel-cc.cu =================================================================== --- clang/test/CodeGenCUDASPIRV/kernel-cc.cu +++ clang/test/CodeGenCUDASPIRV/kernel-cc.cu @@ -7,3 +7,6 @@ // CHECK: define spir_kernel void @_Z6kernelv() __attribute__((global)) void kernel() { return; } + +// CHECK: !opencl.ocl.version = !{[[OCL:![0-9]+]]} +// CHECK: [[OCL]] = !{i32 2, i32 0} Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -3312,6 +3312,10 @@ // whereas respecting contract flag in backend. Opts.setDefaultFPContractMode(LangOptions::FPM_FastHonorPragmas); } else if (Opts.CUDA) { + if (T.isSPIRV()) { + // Emit OpenCL version metadata in LLVM IR when targeting SPIR-V. + Opts.OpenCLVersion = 200; + } // Allow fuse across statements disregarding pragmas. Opts.setDefaultFPContractMode(LangOptions::FPM_Fast); } Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -784,7 +784,7 @@ LangOpts.OpenMP); // Emit OpenCL specific module metadata: OpenCL/SPIR version. - if (LangOpts.OpenCL) { + if (LangOpts.OpenCL || (LangOpts.CUDAIsDevice && getTriple().isSPIRV())) { EmitOpenCLMetadata(); // Emit SPIR version. if (getTriple().isSPIR()) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits