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

[Backport to 16] OpCopyLogical support #2872

Merged
merged 2 commits into from
Nov 25, 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
19 changes: 19 additions & 0 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,25 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
LoadInst *LI = new LoadInst(Ty, AI, "", BB);
return mapValue(BV, LI);
}
case OpCopyLogical: {
SPIRVCopyLogical *CL = static_cast<SPIRVCopyLogical *>(BV);

auto *SrcTy = transType(CL->getOperand()->getType());
auto *DstTy = transType(CL->getType());

assert(M->getDataLayout().getTypeStoreSize(SrcTy).getFixedValue() ==
M->getDataLayout().getTypeStoreSize(DstTy).getFixedValue() &&
"Size mismatch in OpCopyLogical");

IRBuilder<> Builder(BB);

auto *SrcAI = Builder.CreateAlloca(SrcTy);
Builder.CreateAlignedStore(transValue(CL->getOperand(), F, BB), SrcAI,
SrcAI->getAlign());

auto *LI = Builder.CreateAlignedLoad(DstTy, SrcAI, SrcAI->getAlign());
return mapValue(BV, LI);
}

case OpAccessChain:
case OpInBoundsAccessChain:
Expand Down
25 changes: 25 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,31 @@ class SPIRVCopyObject : public SPIRVInstruction {
SPIRVId Operand;
};

class SPIRVCopyLogical : public SPIRVInstruction {
public:
const static Op OC = OpCopyLogical;

// Complete constructor
SPIRVCopyLogical(SPIRVType *TheType, SPIRVId TheId, SPIRVValue *TheOperand,
SPIRVBasicBlock *TheBB)
: SPIRVInstruction(4, OC, TheType, TheId, TheBB),
Operand(TheOperand->getId()) {
validate();
assert(TheBB && "Invalid BB");
}
// Incomplete constructor
SPIRVCopyLogical() : SPIRVInstruction(OC), Operand(SPIRVID_INVALID) {}

SPIRVValue *getOperand() { return getValue(Operand); }
std::vector<SPIRVValue *> getOperands() override { return {getOperand()}; }

protected:
_SPIRV_DEF_ENCDEC3(Type, Id, Operand)

void validate() const override { SPIRVInstruction::validate(); }
SPIRVId Operand;
};

class SPIRVCopyMemory : public SPIRVInstruction, public SPIRVMemoryAccess {
public:
const static Op OC = OpCopyMemory;
Expand Down
1 change: 1 addition & 0 deletions lib/SPIRV/libSPIRV/SPIRVOpCodeEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ _SPIRV_OP(GroupNonUniformBitwiseXor, 361)
_SPIRV_OP(GroupNonUniformLogicalAnd, 362)
_SPIRV_OP(GroupNonUniformLogicalOr, 363)
_SPIRV_OP(GroupNonUniformLogicalXor, 364)
_SPIRV_OP(CopyLogical, 400)
_SPIRV_OP(PtrEqual, 401)
_SPIRV_OP(PtrNotEqual, 402)
_SPIRV_OP(PtrDiff, 403)
Expand Down
27 changes: 27 additions & 0 deletions test/OpCopyLogical.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; Check support of OpCopyLogical instruction that was added in SPIR-V 1.4

; REQUIRES: spirv-as
; RUN: spirv-as --target-env spv1.4 -o %t.spv %s
; RUN: spirv-val %t.spv
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc
; RUN: llvm-dis %t.rev.bc
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
OpCapability Addresses
OpCapability Kernel
OpMemoryModel Physical32 OpenCL
OpEntryPoint Kernel %1 "test"
OpName %entry "entry"
%void = OpTypeVoid
%_struct_4 = OpTypeStruct
%_struct_5 = OpTypeStruct
%6 = OpConstantComposite %_struct_4
%7 = OpTypeFunction %void
%1 = OpFunction %void None %7
%entry = OpLabel
%8 = OpCopyLogical %_struct_5 %6
OpReturn
OpFunctionEnd

; CHECK-LLVM: [[ALLOCA:%[a-z0-9.]+]] = alloca [[SRC_TYPE:%[a-z0-9.]+]], align 8
; CHECK-LLVM: store [[SRC_TYPE]] zeroinitializer, ptr [[ALLOCA]], align 8
; CHECK-LLVM: [[DST:%[a-z0-9.]+]] = load [[DST_TYPE:%[a-z0-9.]+]], ptr [[ALLOCA]], align 8
Loading