Skip to content

Commit 4df2fcc

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 23d28db commit 4df2fcc

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
@@ -2236,6 +2236,10 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
22362236
LoadInst *LI = new LoadInst(Ty, AI, "", BB);
22372237
return mapValue(BV, LI);
22382238
}
2239+
case OpCopyLogical: {
2240+
SPIRVCopyLogical *CL = static_cast<SPIRVCopyLogical *>(BV);
2241+
return mapValue(BV, transSPIRVBuiltinFromInst(CL, BB));
2242+
}
22392243

22402244
case OpAccessChain:
22412245
case OpInBoundsAccessChain:

lib/SPIRV/libSPIRV/SPIRVInstruction.h

+25
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,31 @@ class SPIRVCopyObject : public SPIRVInstruction {
20752075
SPIRVId Operand;
20762076
};
20772077

2078+
class SPIRVCopyLogical : public SPIRVInstruction {
2079+
public:
2080+
const static Op OC = OpCopyLogical;
2081+
2082+
// Complete constructor
2083+
SPIRVCopyLogical(SPIRVType *TheType, SPIRVId TheId, SPIRVValue *TheOperand,
2084+
SPIRVBasicBlock *TheBB)
2085+
: SPIRVInstruction(4, OC, TheType, TheId, TheBB),
2086+
Operand(TheOperand->getId()) {
2087+
validate();
2088+
assert(TheBB && "Invalid BB");
2089+
}
2090+
// Incomplete constructor
2091+
SPIRVCopyLogical() : SPIRVInstruction(OC), Operand(SPIRVID_INVALID) {}
2092+
2093+
SPIRVValue *getOperand() { return getValue(Operand); }
2094+
std::vector<SPIRVValue *> getOperands() override { return {getOperand()}; }
2095+
2096+
protected:
2097+
_SPIRV_DEF_ENCDEC3(Type, Id, Operand)
2098+
2099+
void validate() const override { SPIRVInstruction::validate(); }
2100+
SPIRVId Operand;
2101+
};
2102+
20782103
class SPIRVCopyMemory : public SPIRVInstruction, public SPIRVMemoryAccess {
20792104
public:
20802105
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)