Skip to content

Commit 52c66e4

Browse files
committed
Revert "Revert "Turn on SPIR-V builtin generation for OpenCL CPP sources (KhronosGroup#2466)" (KhronosGroup#2508)"
This reverts commit 9e60105.
1 parent 648654d commit 52c66e4

File tree

5 files changed

+67
-5
lines changed

5 files changed

+67
-5
lines changed

lib/SPIRV/OCLToSPIRV.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,11 @@ bool OCLToSPIRVBase::runOCLToSPIRV(Module &Module) {
169169
auto Src = getSPIRVSource(&Module);
170170
// This is a pre-processing pass, which transform LLVM IR module to a more
171171
// suitable form for the SPIR-V translation: it is specifically designed to
172-
// handle OpenCL C built-in functions and shouldn't be launched for other
173-
// source languages
174-
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C)
172+
// handle OpenCL C/C++ and C++ for OpenCL modules and shouldn't be launched
173+
// for other source languages.
174+
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C &&
175+
std::get<0>(Src) != spv::SourceLanguageOpenCL_CPP &&
176+
std::get<0>(Src) != spv::SourceLanguageCPP_for_OpenCL)
175177
return false;
176178

177179
CLVer = std::get<1>(Src);

lib/SPIRV/OCLTypeToSPIRV.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ bool OCLTypeToSPIRVBase::runOCLTypeToSPIRV(Module &Module) {
8888
AdaptedTy.clear();
8989
WorkSet.clear();
9090
auto Src = getSPIRVSource(&Module);
91-
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C)
91+
// This is a pre-processing pass, which transform LLVM IR module to a more
92+
// suitable form for the SPIR-V translation: it is specifically designed to
93+
// handle OpenCL C/C++ and C++ for OpenCL types and shouldn't be launched for
94+
// other source languages.
95+
if (std::get<0>(Src) != spv::SourceLanguageOpenCL_C &&
96+
std::get<0>(Src) != spv::SourceLanguageOpenCL_CPP &&
97+
std::get<0>(Src) != spv::SourceLanguageCPP_for_OpenCL)
9298
return false;
9399

94100
for (auto &F : Module.functions())

test/extensions/INTEL/SPV_INTEL_arbitrary_precision_fixed_point/capability-arbitrary-precision-fixed-point-numbers.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ attributes #5 = { nounwind }
546546

547547
!0 = !{i32 1, !"wchar_size", i32 4}
548548
!1 = !{i32 1, i32 2}
549-
!2 = !{i32 4, i32 100000}
549+
!2 = !{i32 7, i32 100000}
550550
!3 = !{!"clang version 11.0.0"}
551551
!4 = !{}
552552
!5 = !{!6, !6, i64 0}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
;; This test checks if builtins in LLVM IR generated from CPP_for_OpenCL sources
2+
;; are correctly translated to SPIR-V builtin variables.
3+
4+
; RUN: llvm-as %s -o %t.bc
5+
; RUN: llvm-spirv %t.bc -o %t.spv
6+
; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt
7+
; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
8+
; RUN: spirv-val %t.spv
9+
10+
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"
11+
target triple = "spir-unknown-unknown"
12+
13+
%opencl.event_t = type opaque
14+
15+
; CHECK-SPIRV: {{[0-9]+}} Name {{[0-9]+}} "__spirv_BuiltInWorkgroupId"
16+
; Function Attrs: nounwind
17+
define spir_kernel void @test_fn(i32 %a) {
18+
entry:
19+
%call15 = call spir_func i32 @_Z12get_group_idj(i32 0)
20+
ret void
21+
}
22+
23+
declare spir_func i32 @_Z12get_group_idj(i32)
24+
25+
!spirv.Source = !{!0}
26+
27+
!0 = !{i32 6, i32 100000}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
;; This test checks if builtins in LLVM IR generated from OpenCL_CPP sources
2+
;; are correctly translated to SPIR-V builtin variables.
3+
4+
; RUN: llvm-as %s -o %t.bc
5+
; RUN: llvm-spirv %t.bc -o %t.spv
6+
; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt
7+
; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
8+
; RUN: spirv-val %t.spv
9+
10+
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"
11+
target triple = "spir-unknown-unknown"
12+
13+
%opencl.event_t = type opaque
14+
15+
; CHECK-SPIRV: {{[0-9]+}} Name {{[0-9]+}} "__spirv_BuiltInWorkgroupId"
16+
; Function Attrs: nounwind
17+
define spir_kernel void @test_fn(i32 %a) {
18+
entry:
19+
%call15 = call spir_func i32 @_Z12get_group_idj(i32 0)
20+
ret void
21+
}
22+
23+
declare spir_func i32 @_Z12get_group_idj(i32)
24+
25+
!spirv.Source = !{!0}
26+
27+
!0 = !{i32 4, i32 100000}

0 commit comments

Comments
 (0)