From 2f8d0801878db2a3db4e891b03a72036de85b449 Mon Sep 17 00:00:00 2001 From: Vladimir Lazarev Date: Fri, 28 Dec 2018 16:34:47 +0300 Subject: [PATCH] [SYCL] Emit SPIR-V specific OpenCL C++ metadata. Signed-off-by: Vladimir Lazarev --- clang/lib/CodeGen/CodeGenModule.cpp | 16 +++++++++------- clang/test/CodeGenSYCL/spir-opencl-version.cpp | 7 ++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 63455638a92e2..313e98f68d5fd 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -552,21 +552,23 @@ void CodeGenModule::Release() { } } - // Emit SYCL specific module metadata: OpenCL/SPIR version. + // Emit SYCL specific module metadata: OpenCL/SPIR version, OpenCL language. if (LangOpts.SYCL) { - llvm::Metadata *OCLVerElts[] = { - llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 1)), - llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 2))}; - llvm::NamedMDNode *OCLVerMD = - TheModule.getOrInsertNamedMetadata("opencl.ocl.version"); llvm::LLVMContext &Ctx = TheModule.getContext(); - OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts)); llvm::Metadata *SPIRVerElts[] = { llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 1)), llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 2))}; llvm::NamedMDNode *SPIRVerMD = TheModule.getOrInsertNamedMetadata("opencl.spir.version"); SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts)); + // We are trying to look like OpenCL C++ for SPIR-V translator. + // 4 - OpenCL_CPP, 100000 - OpenCL C++ version 1.0 + llvm::Metadata *SPIRVSourceElts[] = { + llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 4)), + llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 100000))}; + llvm::NamedMDNode *SPIRVSourceMD = + TheModule.getOrInsertNamedMetadata("spirv.Source"); + SPIRVSourceMD->addOperand(llvm::MDNode::get(Ctx, SPIRVSourceElts)); } if (uint32_t PLevel = Context.getLangOpts().PICLevel) { diff --git a/clang/test/CodeGenSYCL/spir-opencl-version.cpp b/clang/test/CodeGenSYCL/spir-opencl-version.cpp index fe405b4891a2f..db4bae14fd7e5 100644 --- a/clang/test/CodeGenSYCL/spir-opencl-version.cpp +++ b/clang/test/CodeGenSYCL/spir-opencl-version.cpp @@ -20,6 +20,7 @@ int main() { } -// CHECK: !opencl.ocl.version = !{[[VER:![0-9]+]]} -// CHECK: !opencl.spir.version = !{[[VER]]} -// CHECK: [[VER]] = !{i32 1, i32 2} +// CHECK: !opencl.spir.version = !{[[SPIR:![0-9]+]]} +// CHECK: !spirv.Source = !{[[LANG:![0-9]+]]} +// CHECK: [[SPIR]] = !{i32 1, i32 2} +// CHECK: [[LANG]] = !{i32 4, i32 100000}