Skip to content

Commit

Permalink
[SYCL] Emit SPIR-V specific OpenCL C++ metadata.
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lazarev <[email protected]>
  • Loading branch information
vladimirlaz committed Jan 22, 2019
1 parent f29e1cd commit 2f8d080
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
16 changes: 9 additions & 7 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions clang/test/CodeGenSYCL/spir-opencl-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit 2f8d080

Please sign in to comment.