Skip to content

Commit d6cd563

Browse files
vmaksimosvenvh
authored andcommitted
[SPIR-V 1.4] Add CopyLogical instruction (KhronosGroup#2484)
There is no mapping to LLVM instructions, so it can be used only via SPIR-V friendly translation. This addresses p1. of KhronosGroup#2460 (cherry picked from commit 8518a6f)
1 parent 8825136 commit d6cd563

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

lib/SPIRV/SPIRVReader.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2156,6 +2156,10 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
21562156
LoadInst *LI = new LoadInst(Ty, AI, "", BB);
21572157
return mapValue(BV, LI);
21582158
}
2159+
case OpCopyLogical: {
2160+
SPIRVCopyLogical *CL = static_cast<SPIRVCopyLogical *>(BV);
2161+
return mapValue(BV, transSPIRVBuiltinFromInst(CL, BB));
2162+
}
21592163

21602164
case OpAccessChain:
21612165
case OpInBoundsAccessChain:

lib/SPIRV/libSPIRV/SPIRVInstruction.h

+25
Original file line numberDiff line numberDiff line change
@@ -2049,6 +2049,31 @@ class SPIRVCopyObject : public SPIRVInstruction {
20492049
SPIRVId Operand;
20502050
};
20512051

2052+
class SPIRVCopyLogical : public SPIRVInstruction {
2053+
public:
2054+
const static Op OC = OpCopyLogical;
2055+
2056+
// Complete constructor
2057+
SPIRVCopyLogical(SPIRVType *TheType, SPIRVId TheId, SPIRVValue *TheOperand,
2058+
SPIRVBasicBlock *TheBB)
2059+
: SPIRVInstruction(4, OC, TheType, TheId, TheBB),
2060+
Operand(TheOperand->getId()) {
2061+
validate();
2062+
assert(TheBB && "Invalid BB");
2063+
}
2064+
// Incomplete constructor
2065+
SPIRVCopyLogical() : SPIRVInstruction(OC), Operand(SPIRVID_INVALID) {}
2066+
2067+
SPIRVValue *getOperand() { return getValue(Operand); }
2068+
std::vector<SPIRVValue *> getOperands() override { return {getOperand()}; }
2069+
2070+
protected:
2071+
_SPIRV_DEF_ENCDEC3(Type, Id, Operand)
2072+
2073+
void validate() const override { SPIRVInstruction::validate(); }
2074+
SPIRVId Operand;
2075+
};
2076+
20522077
class SPIRVCopyMemory : public SPIRVInstruction, public SPIRVMemoryAccess {
20532078
public:
20542079
const static Op OC = OpCopyMemory;

lib/SPIRV/libSPIRV/SPIRVOpCodeEnum.h

+1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ _SPIRV_OP(GroupNonUniformBitwiseXor, 361)
330330
_SPIRV_OP(GroupNonUniformLogicalAnd, 362)
331331
_SPIRV_OP(GroupNonUniformLogicalOr, 363)
332332
_SPIRV_OP(GroupNonUniformLogicalXor, 364)
333+
_SPIRV_OP(CopyLogical, 400)
333334
_SPIRV_OP(PtrEqual, 401)
334335
_SPIRV_OP(PtrNotEqual, 402)
335336
_SPIRV_OP(PtrDiff, 403)

test/OpCopyLogical.spvasm

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; Check support of OpCopyLogical instruction that was added in SPIR-V 1.4
2+
3+
; REQUIRES: spirv-as
4+
; RUN: spirv-as --target-env spv1.4 -o %t.spv %s
5+
; RUN: spirv-val %t.spv
6+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
7+
; RUN: llvm-dis %t.rev.bc
8+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
9+
OpCapability Addresses
10+
OpCapability Kernel
11+
OpMemoryModel Physical32 OpenCL
12+
OpEntryPoint Kernel %1 "test"
13+
OpName %entry "entry"
14+
%void = OpTypeVoid
15+
%_struct_4 = OpTypeStruct
16+
%_struct_5 = OpTypeStruct
17+
%6 = OpConstantComposite %_struct_4
18+
%7 = OpTypeFunction %void
19+
%1 = OpFunction %void None %7
20+
%entry = OpLabel
21+
%8 = OpCopyLogical %_struct_5 %6
22+
OpReturn
23+
OpFunctionEnd
24+
25+
; CHECK-LLVM: @_Z19__spirv_CopyLogical12structtype.0(ptr sret(%structtype) %[[#]], %structtype.0 zeroinitializer)

0 commit comments

Comments
 (0)