Skip to content

Commit c34bf5a

Browse files
svenvhdbudanov-cmplr
authored andcommitted
Restore getArgIndex in OCLTypeToSPIRV (#1567)
* Update for LLVM Optional API changes Update for LLVM commit b5f8d42 ("[ADT] Deprecate Optional::{hasValue,getValue} (NFC)", 2022-08-07). This is a mechanical replacement of `hasValue` to `has_value` and `getValue` to `value`. * Restore argument tracing in OCLTypeToSPIRV Commit 4a9c78ee ("Prepare SPIRVWriter for type conversion without opaque pointers. (#1499)", 2022-06-20) removed `getArgIndex` in favor of passing `Idx`, but this leads to incorrect adaptation of argument types if sampler arguments are not in the same position between different functions. We might be able to drop `adaptArgumentsBySamplerUse` entirely, as we don't represent samplers as i32 anymore; but for now just fix the regression. Fixes KhronosGroup/SPIRV-LLVM-Translator#1562 Original commit: KhronosGroup/SPIRV-LLVM-Translator@87f8a58
1 parent 4f341b2 commit c34bf5a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

llvm-spirv/lib/SPIRV/OCLTypeToSPIRV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void OCLTypeToSPIRVBase::adaptArgumentsBySamplerUse(Module &M) {
184184
addAdaptedType(SamplerArg, getSamplerStructType(&M), SPIRAS_Constant);
185185
auto Caller = cast<Argument>(SamplerArg)->getParent();
186186
addWork(Caller);
187-
TraceArg(Caller, Idx);
187+
TraceArg(Caller, cast<Argument>(SamplerArg)->getArgNo());
188188
}
189189
};
190190

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc
3+
; RUN: spirv-val %t.spv
4+
5+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
6+
target triple = "spirv64"
7+
8+
%opencl.image2d_ro_t = type opaque
9+
%opencl.sampler_t = type opaque
10+
11+
define internal spir_func <4 x float> @user_fn(%opencl.image2d_ro_t addrspace(1)* %I, %opencl.sampler_t addrspace(2)* %S, <2 x float> %Pos) {
12+
entry:
13+
%call = tail call spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)* %I, %opencl.sampler_t addrspace(2)* %S, <2 x float> noundef %Pos) #0
14+
ret <4 x float> %call
15+
}
16+
17+
declare spir_func <4 x float> @_Z11read_imagef14ocl_image2d_ro11ocl_samplerDv2_f(%opencl.image2d_ro_t addrspace(1)*, %opencl.sampler_t addrspace(2)*, <2 x float>) local_unnamed_addr
18+
19+
define hidden spir_kernel void @kernel_fn(float addrspace(1)* %0, %opencl.image2d_ro_t addrspace(1)* %1, %opencl.sampler_t addrspace(2)* %2, i32 %3, i32 %4) local_unnamed_addr {
20+
entry:
21+
%5 = call spir_func <4 x float> @user_fn(%opencl.image2d_ro_t addrspace(1)* %1, %opencl.sampler_t addrspace(2)* %2, <2 x float> undef)
22+
%add16 = add nsw i32 undef, undef
23+
ret void
24+
}
25+
26+
attributes #0 = { convergent nounwind readonly willreturn }
27+
28+
!opencl.ocl.version = !{!0}
29+
30+
!0 = !{i32 2, i32 0}

0 commit comments

Comments
 (0)