Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions lib/SPIRV/OCLToSPIRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ 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
// handle OpenCL C/CPP built-in functions and shouldn't be launched for other
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, what is the reason for only running this transform for these types of sources?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the only OpenCL related sources and this particular module deals with OpenCL sources.

// source languages
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C)
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C &&
std::get<0>(Src) != spv::SourceLanguageOpenCL_CPP)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is also a SourceLanguageCPP_for_OpenCL. Should this be allowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Good catch. Thanks. Added.

return false;

CLVer = std::get<1>(Src);
Expand Down
3 changes: 2 additions & 1 deletion lib/SPIRV/OCLTypeToSPIRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ bool OCLTypeToSPIRVBase::runOCLTypeToSPIRV(Module &Module) {
AdaptedTy.clear();
WorkSet.clear();
auto Src = getSPIRVSource(&Module);
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C)
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C &&
std::get<0>(Src) != spv::SourceLanguageOpenCL_CPP)
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
24 changes: 24 additions & 0 deletions test/ocl_to_spirv_for_opencl_cpp.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; 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}