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
  • Loading branch information
vmaksimo authored Apr 12, 2024
1 parent 5577a5a commit 8518a6f
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 @@ -2104,6 +2104,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 @@ -2047,6 +2047,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 @@ -329,6 +329,7 @@ _SPIRV_OP(GroupNonUniformBitwiseXor, 361)
_SPIRV_OP(GroupNonUniformLogicalAnd, 362)
_SPIRV_OP(GroupNonUniformLogicalOr, 363)
_SPIRV_OP(GroupNonUniformLogicalXor, 364)
_SPIRV_OP(CopyLogical, 400)
_SPIRV_OP(GroupNonUniformRotateKHR, 4431)
_SPIRV_OP(SDotKHR, 4450)
_SPIRV_OP(UDotKHR, 4451)
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 8518a6f

Please sign in to comment.