Skip to content

Commit c5f8977

Browse files
vmaksimosys-ce-bb
authored andcommitted
Add CopyLogical instruction (#2484)
There is no mapping to LLVM instructions, so it can be used only via SPIR-V friendly translation. This addresses p1. of #2460 Original commit: KhronosGroup/SPIRV-LLVM-Translator@8518a6f72fd586c
1 parent 847f91e commit c5f8977

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,6 +2105,10 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
21052105
LoadInst *LI = new LoadInst(Ty, AI, "", BB);
21062106
return mapValue(BV, LI);
21072107
}
2108+
case OpCopyLogical: {
2109+
SPIRVCopyLogical *CL = static_cast<SPIRVCopyLogical *>(BV);
2110+
return mapValue(BV, transSPIRVBuiltinFromInst(CL, BB));
2111+
}
21082112

21092113
case OpAccessChain:
21102114
case OpInBoundsAccessChain:

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVInstruction.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,31 @@ class SPIRVCopyObject : public SPIRVInstruction {
20352035
SPIRVId Operand;
20362036
};
20372037

2038+
class SPIRVCopyLogical : public SPIRVInstruction {
2039+
public:
2040+
const static Op OC = OpCopyLogical;
2041+
2042+
// Complete constructor
2043+
SPIRVCopyLogical(SPIRVType *TheType, SPIRVId TheId, SPIRVValue *TheOperand,
2044+
SPIRVBasicBlock *TheBB)
2045+
: SPIRVInstruction(4, OC, TheType, TheId, TheBB),
2046+
Operand(TheOperand->getId()) {
2047+
validate();
2048+
assert(TheBB && "Invalid BB");
2049+
}
2050+
// Incomplete constructor
2051+
SPIRVCopyLogical() : SPIRVInstruction(OC), Operand(SPIRVID_INVALID) {}
2052+
2053+
SPIRVValue *getOperand() { return getValue(Operand); }
2054+
std::vector<SPIRVValue *> getOperands() override { return {getOperand()}; }
2055+
2056+
protected:
2057+
_SPIRV_DEF_ENCDEC3(Type, Id, Operand)
2058+
2059+
void validate() const override { SPIRVInstruction::validate(); }
2060+
SPIRVId Operand;
2061+
};
2062+
20382063
class SPIRVCopyMemory : public SPIRVInstruction, public SPIRVMemoryAccess {
20392064
public:
20402065
const static Op OC = OpCopyMemory;

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVOpCodeEnum.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ _SPIRV_OP(GroupNonUniformBitwiseXor, 361)
329329
_SPIRV_OP(GroupNonUniformLogicalAnd, 362)
330330
_SPIRV_OP(GroupNonUniformLogicalOr, 363)
331331
_SPIRV_OP(GroupNonUniformLogicalXor, 364)
332+
_SPIRV_OP(CopyLogical, 400)
332333
_SPIRV_OP(GroupNonUniformRotateKHR, 4431)
333334
_SPIRV_OP(SDotKHR, 4450)
334335
_SPIRV_OP(UDotKHR, 4451)

llvm-spirv/test/OpCopyLogical.spvasm

Lines changed: 25 additions & 0 deletions
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)