Skip to content

Commit 65c532d

Browse files
svenvhjsji
authored andcommitted
SPIRVReader: Add MaxByteOffsetId support (#2884)
If there is no `OpDecorate .. MaxByteOffset` in the input, see if there is an `OpDecorateId .. MaxByteOffsetId` and take the value for the LLVM `dereferenceable` attribute from the referenced constant instead. Once `MaxByteOffsetId` has been translated to LLVM IR, it is indistinguishable from a (non-ID) `MaxByteOffset` decoration. Original commit: KhronosGroup/SPIRV-LLVM-Translator@0332a1e50c3b878
1 parent c08b3e4 commit 65c532d

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,6 +3211,14 @@ void SPIRVToLLVM::transFunctionAttrs(SPIRVFunction *BF, Function *F) {
32113211
SPIRVWord MaxOffset = 0;
32123212
if (BA->hasDecorate(DecorationMaxByteOffset, 0, &MaxOffset))
32133213
Builder.addDereferenceableAttr(MaxOffset);
3214+
else {
3215+
SPIRVId MaxOffsetId;
3216+
if (BA->hasDecorateId(DecorationMaxByteOffsetId, 0, &MaxOffsetId)) {
3217+
if (auto MaxOffsetVal = transIdAsConstant(MaxOffsetId)) {
3218+
Builder.addDereferenceableAttr(*MaxOffsetVal);
3219+
}
3220+
}
3221+
}
32143222
if (auto Alignment = getAlignment(BA)) {
32153223
Builder.addAlignmentAttr(*Alignment);
32163224
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; REQUIRES: spirv-as
2+
3+
; RUN: spirv-as %s --target-env spv1.2 -o %t.spv
4+
; RUN: spirv-val %t.spv
5+
; RUN: llvm-spirv -r -o %t.rev.bc %t.spv
6+
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s
7+
8+
; CHECK: define spir_kernel void @testMaxByteOffsetId(
9+
; CHECK-SAME: ptr addrspace(1) dereferenceable(24) %p,
10+
; CHECK-SAME: ptr addrspace(1) dereferenceable(48) %q)
11+
12+
OpCapability Addresses
13+
OpCapability Kernel
14+
OpMemoryModel Physical64 OpenCL
15+
OpEntryPoint Kernel %fn "testMaxByteOffsetId"
16+
OpName %p "p"
17+
OpName %q "q"
18+
OpDecorateId %p MaxByteOffsetId %mbo
19+
OpDecorateId %q MaxByteOffsetId %spec
20+
%void = OpTypeVoid
21+
%i32 = OpTypeInt 32 0
22+
%ptr = OpTypePointer CrossWorkgroup %i32
23+
%fnTy = OpTypeFunction %void %ptr %ptr
24+
%mbo = OpConstant %i32 24
25+
%spec = OpSpecConstantOp %i32 IAdd %mbo %mbo
26+
27+
%fn = OpFunction %void None %fnTy
28+
%p = OpFunctionParameter %ptr
29+
%q = OpFunctionParameter %ptr
30+
%entry = OpLabel
31+
32+
OpReturn
33+
OpFunctionEnd

0 commit comments

Comments
 (0)