Skip to content

Commit d4e33e7

Browse files
vmaksimosvenvh
authored andcommitted
[Backport to 14] [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 1cfcf1b commit d4e33e7

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
@@ -2181,6 +2181,10 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
21812181
LoadInst *LI = new LoadInst(Ty, AI, "", BB);
21822182
return mapValue(BV, LI);
21832183
}
2184+
case OpCopyLogical: {
2185+
SPIRVCopyLogical *CL = static_cast<SPIRVCopyLogical *>(BV);
2186+
return mapValue(BV, transSPIRVBuiltinFromInst(CL, BB));
2187+
}
21842188

21852189
case OpAccessChain:
21862190
case OpInBoundsAccessChain:

lib/SPIRV/libSPIRV/SPIRVInstruction.h

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

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