Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/SPIRV/OCLToSPIRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,11 @@ bool OCLToSPIRVBase::runOCLToSPIRV(Module &Module) {
auto Src = getSPIRVSource(&Module);
// This is a pre-processing pass, which transform LLVM IR module to a more
// suitable form for the SPIR-V translation: it is specifically designed to
// handle OpenCL C built-in functions and shouldn't be launched for other
// source languages
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C)
// handle OpenCL C/C++ and C++ for OpenCL modules and shouldn't be launched
// for other source languages.
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C &&
std::get<0>(Src) != spv::SourceLanguageOpenCL_CPP &&
std::get<0>(Src) != spv::SourceLanguageCPP_for_OpenCL)
return false;

CLVer = std::get<1>(Src);
Expand Down
8 changes: 7 additions & 1 deletion lib/SPIRV/OCLTypeToSPIRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ bool OCLTypeToSPIRVBase::runOCLTypeToSPIRV(Module &Module) {
AdaptedTy.clear();
WorkSet.clear();
auto Src = getSPIRVSource(&Module);
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C)
// This is a pre-processing pass, which transform LLVM IR module to a more
// suitable form for the SPIR-V translation: it is specifically designed to
// handle OpenCL C/C++ and C++ for OpenCL types and shouldn't be launched for
// other source languages.
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C &&
std::get<0>(Src) != spv::SourceLanguageOpenCL_CPP &&
std::get<0>(Src) != spv::SourceLanguageCPP_for_OpenCL)
return false;

for (auto &F : Module.functions())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ attributes #5 = { nounwind }

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 1, i32 2}
!2 = !{i32 4, i32 100000}
!2 = !{i32 7, i32 100000}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case was actually derived from SYCL source.

!3 = !{!"clang version 11.0.0"}
!4 = !{}
!5 = !{!6, !6, i64 0}
Expand Down
27 changes: 27 additions & 0 deletions test/ocl_to_spirv_for_cpp_for_opencl.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
;; This test checks if builtins in LLVM IR generated from CPP_for_OpenCL sources
;; are correctly translated to SPIR-V builtin variables.

; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc -o %t.spv
; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt
; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
; RUN: spirv-val %t.spv

target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir-unknown-unknown"

%opencl.event_t = type opaque

; CHECK-SPIRV: {{[0-9]+}} Name {{[0-9]+}} "__spirv_BuiltInWorkgroupId"
; Function Attrs: nounwind
define spir_kernel void @test_fn(i32 %a) {
entry:
%call15 = call spir_func i32 @_Z12get_group_idj(i32 0)
ret void
}

declare spir_func i32 @_Z12get_group_idj(i32)

!spirv.Source = !{!0}

!0 = !{i32 6, i32 100000}
27 changes: 27 additions & 0 deletions test/ocl_to_spirv_for_opencl_cpp.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
;; This test checks if builtins in LLVM IR generated from OpenCL_CPP sources
;; are correctly translated to SPIR-V builtin variables.

; RUN: llvm-as %s -o %t.bc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment describing purpose of this test. I think that looking at the filename or file history is not as clear or convenient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks

; RUN: llvm-spirv %t.bc -o %t.spv
; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt
; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
; RUN: spirv-val %t.spv

target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir-unknown-unknown"

%opencl.event_t = type opaque

; CHECK-SPIRV: {{[0-9]+}} Name {{[0-9]+}} "__spirv_BuiltInWorkgroupId"
; Function Attrs: nounwind
define spir_kernel void @test_fn(i32 %a) {
entry:
%call15 = call spir_func i32 @_Z12get_group_idj(i32 0)
ret void
}

declare spir_func i32 @_Z12get_group_idj(i32)

!spirv.Source = !{!0}

!0 = !{i32 4, i32 100000}