Skip to content

Commit c19a303

Browse files
authored
[SPIR-V] Support 2 more instructions from SPV_INTEL_long_composites (#128190)
This change adds support for `OpSpecConstantCompositeContinuedINTEL` and `OpCompositeConstructContinuedINTEL` instructions and continues work done in #126545. Specification: https://github.khronos.org/SPIRV-Registry/extensions/INTEL/SPV_INTEL_long_composites.html
1 parent 46a13a5 commit c19a303

File tree

6 files changed

+65670
-7
lines changed

6 files changed

+65670
-7
lines changed

llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,8 +2116,11 @@ static bool generateSelectInst(const SPIRV::IncomingCall *Call,
21162116
static bool generateConstructInst(const SPIRV::IncomingCall *Call,
21172117
MachineIRBuilder &MIRBuilder,
21182118
SPIRVGlobalRegistry *GR) {
2119-
return buildOpFromWrapper(MIRBuilder, SPIRV::OpCompositeConstruct, Call,
2120-
GR->getSPIRVTypeID(Call->ReturnType));
2119+
createContinuedInstructions(MIRBuilder, SPIRV::OpCompositeConstruct, 3,
2120+
SPIRV::OpCompositeConstructContinuedINTEL,
2121+
Call->Arguments, Call->ReturnRegister,
2122+
GR->getSPIRVTypeID(Call->ReturnType));
2123+
return true;
21212124
}
21222125

21232126
static bool generateCoopMatrInst(const SPIRV::IncomingCall *Call,
@@ -2230,11 +2233,10 @@ static bool generateSpecConstantInst(const SPIRV::IncomingCall *Call,
22302233
return true;
22312234
}
22322235
case SPIRV::OpSpecConstantComposite: {
2233-
auto MIB = MIRBuilder.buildInstr(Opcode)
2234-
.addDef(Call->ReturnRegister)
2235-
.addUse(GR->getSPIRVTypeID(Call->ReturnType));
2236-
for (unsigned i = 0; i < Call->Arguments.size(); i++)
2237-
MIB.addUse(Call->Arguments[i]);
2236+
createContinuedInstructions(MIRBuilder, Opcode, 3,
2237+
SPIRV::OpSpecConstantCompositeContinuedINTEL,
2238+
Call->Arguments, Call->ReturnRegister,
2239+
GR->getSPIRVTypeID(Call->ReturnType));
22382240
return true;
22392241
}
22402242
default:

llvm/lib/Target/SPIRV/SPIRVInstrInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ bool SPIRVInstrInfo::isSpecConstantInstr(const MachineInstr &MI) const {
5555
case SPIRV::OpSpecConstantFalse:
5656
case SPIRV::OpSpecConstant:
5757
case SPIRV::OpSpecConstantComposite:
58+
case SPIRV::OpSpecConstantCompositeContinuedINTEL:
5859
case SPIRV::OpSpecConstantOp:
5960
return true;
6061
default:

llvm/lib/Target/SPIRV/SPIRVUtils.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,4 +800,36 @@ bool isSpvIntrinsic(const Value *Arg) {
800800
return false;
801801
}
802802

803+
// Function to create continued instructions for SPV_INTEL_long_composites
804+
// extension
805+
void createContinuedInstructions(MachineIRBuilder &MIRBuilder, unsigned Opcode,
806+
unsigned MinWC, unsigned ContinuedOpcode,
807+
ArrayRef<Register> Args,
808+
Register ReturnRegister, Register TypeID) {
809+
constexpr unsigned MaxWordCount = UINT16_MAX;
810+
const size_t NumElements = Args.size();
811+
size_t MaxNumElements = MaxWordCount - MinWC;
812+
size_t SPIRVStructNumElements = NumElements;
813+
814+
if (NumElements > MaxNumElements) {
815+
// Do adjustments for continued instructions which always had only one
816+
// minumum word count.
817+
SPIRVStructNumElements = MaxNumElements;
818+
MaxNumElements = MaxWordCount - 1;
819+
}
820+
821+
auto MIB =
822+
MIRBuilder.buildInstr(Opcode).addDef(ReturnRegister).addUse(TypeID);
823+
824+
for (size_t I = 0; I < SPIRVStructNumElements; ++I)
825+
MIB.addUse(Args[I]);
826+
827+
for (size_t I = SPIRVStructNumElements; I < NumElements;
828+
I += MaxNumElements) {
829+
auto MIB = MIRBuilder.buildInstr(ContinuedOpcode);
830+
for (size_t J = I; J < std::min(I + MaxNumElements, NumElements); ++J)
831+
MIB.addUse(Args[J]);
832+
}
833+
}
834+
803835
} // namespace llvm

llvm/lib/Target/SPIRV/SPIRVUtils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,5 +444,10 @@ inline FPDecorationId demangledPostfixToDecorationId(const std::string &S) {
444444
return It == Mapping.end() ? FPDecorationId::NONE : It->second;
445445
}
446446

447+
void createContinuedInstructions(MachineIRBuilder &MIRBuilder, unsigned Opcode,
448+
unsigned MinWC, unsigned ContinuedOpcode,
449+
ArrayRef<Register> Args,
450+
Register ReturnRegister, Register TypeID);
451+
447452
} // namespace llvm
448453
#endif // LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H

llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_long_composites/long-composite-construct.ll

Lines changed: 28 additions & 0 deletions
Large diffs are not rendered by default.

llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_long_composites/long-spec-const-composite.ll

Lines changed: 65595 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)