Skip to content

Commit

Permalink
[SPIR-V 1.4] Add CopyLogical instruction (#2484)
Browse files Browse the repository at this point in the history
There is no mapping to LLVM instructions, so it can be used only via SPIR-V friendly translation.

This addresses p1. of #2460

(cherry picked from commit 8518a6f)
  • Loading branch information
vmaksimo authored and svenvh committed Nov 25, 2024
1 parent 0b6e7b5 commit 1532155
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2282,6 +2282,10 @@ 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);
return mapValue(BV, transSPIRVBuiltinFromInst(CL, BB));
}

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 @@ -2067,6 +2067,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
25 changes: 25 additions & 0 deletions test/OpCopyLogical.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; 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 %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: @_Z19__spirv_CopyLogical12structtype.0(ptr sret(%structtype) %[[#]], %structtype.0 zeroinitializer)

0 comments on commit 1532155

Please sign in to comment.