Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPIR-V 1.2] SPIRVReader: Add MaxByteOffsetId support #2884

Merged
merged 1 commit into from
Nov 29, 2024
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: 8 additions & 0 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3177,6 +3177,14 @@ void SPIRVToLLVM::transFunctionAttrs(SPIRVFunction *BF, Function *F) {
SPIRVWord MaxOffset = 0;
if (BA->hasDecorate(DecorationMaxByteOffset, 0, &MaxOffset))
Builder.addDereferenceableAttr(MaxOffset);
else {
SPIRVId MaxOffsetId;
if (BA->hasDecorateId(DecorationMaxByteOffsetId, 0, &MaxOffsetId)) {
if (auto MaxOffsetVal = transIdAsConstant(MaxOffsetId)) {
Builder.addDereferenceableAttr(*MaxOffsetVal);
}
}
}
if (auto Alignment = getAlignment(BA)) {
Builder.addAlignmentAttr(*Alignment);
}
Expand Down
33 changes: 33 additions & 0 deletions test/MaxByteOffsetId.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
; REQUIRES: spirv-as

; RUN: spirv-as %s --target-env spv1.2 -o %t.spv
; RUN: spirv-val %t.spv
; RUN: llvm-spirv -r -o %t.rev.bc %t.spv
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s

; CHECK: define spir_kernel void @testMaxByteOffsetId(
; CHECK-SAME: ptr addrspace(1) dereferenceable(24) %p,
; CHECK-SAME: ptr addrspace(1) dereferenceable(48) %q)

OpCapability Addresses
OpCapability Kernel
OpMemoryModel Physical64 OpenCL
OpEntryPoint Kernel %fn "testMaxByteOffsetId"
OpName %p "p"
OpName %q "q"
OpDecorateId %p MaxByteOffsetId %mbo
OpDecorateId %q MaxByteOffsetId %spec
%void = OpTypeVoid
%i32 = OpTypeInt 32 0
%ptr = OpTypePointer CrossWorkgroup %i32
%fnTy = OpTypeFunction %void %ptr %ptr
%mbo = OpConstant %i32 24
%spec = OpSpecConstantOp %i32 IAdd %mbo %mbo

%fn = OpFunction %void None %fnTy
%p = OpFunctionParameter %ptr
%q = OpFunctionParameter %ptr
%entry = OpLabel

OpReturn
OpFunctionEnd
Loading