[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
This commit is contained in:
Viktoria Maximova 2025-02-27 15:46:23 +01:00 committed by GitHub
parent 46a13a5b17
commit c19a303867
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 65670 additions and 7 deletions

View File

@ -2116,8 +2116,11 @@ static bool generateSelectInst(const SPIRV::IncomingCall *Call,
static bool generateConstructInst(const SPIRV::IncomingCall *Call,
MachineIRBuilder &MIRBuilder,
SPIRVGlobalRegistry *GR) {
return buildOpFromWrapper(MIRBuilder, SPIRV::OpCompositeConstruct, Call,
GR->getSPIRVTypeID(Call->ReturnType));
createContinuedInstructions(MIRBuilder, SPIRV::OpCompositeConstruct, 3,
SPIRV::OpCompositeConstructContinuedINTEL,
Call->Arguments, Call->ReturnRegister,
GR->getSPIRVTypeID(Call->ReturnType));
return true;
}
static bool generateCoopMatrInst(const SPIRV::IncomingCall *Call,
@ -2230,11 +2233,10 @@ static bool generateSpecConstantInst(const SPIRV::IncomingCall *Call,
return true;
}
case SPIRV::OpSpecConstantComposite: {
auto MIB = MIRBuilder.buildInstr(Opcode)
.addDef(Call->ReturnRegister)
.addUse(GR->getSPIRVTypeID(Call->ReturnType));
for (unsigned i = 0; i < Call->Arguments.size(); i++)
MIB.addUse(Call->Arguments[i]);
createContinuedInstructions(MIRBuilder, Opcode, 3,
SPIRV::OpSpecConstantCompositeContinuedINTEL,
Call->Arguments, Call->ReturnRegister,
GR->getSPIRVTypeID(Call->ReturnType));
return true;
}
default:

View File

@ -55,6 +55,7 @@ bool SPIRVInstrInfo::isSpecConstantInstr(const MachineInstr &MI) const {
case SPIRV::OpSpecConstantFalse:
case SPIRV::OpSpecConstant:
case SPIRV::OpSpecConstantComposite:
case SPIRV::OpSpecConstantCompositeContinuedINTEL:
case SPIRV::OpSpecConstantOp:
return true;
default:

View File

@ -800,4 +800,36 @@ bool isSpvIntrinsic(const Value *Arg) {
return false;
}
// Function to create continued instructions for SPV_INTEL_long_composites
// extension
void createContinuedInstructions(MachineIRBuilder &MIRBuilder, unsigned Opcode,
unsigned MinWC, unsigned ContinuedOpcode,
ArrayRef<Register> Args,
Register ReturnRegister, Register TypeID) {
constexpr unsigned MaxWordCount = UINT16_MAX;
const size_t NumElements = Args.size();
size_t MaxNumElements = MaxWordCount - MinWC;
size_t SPIRVStructNumElements = NumElements;
if (NumElements > MaxNumElements) {
// Do adjustments for continued instructions which always had only one
// minumum word count.
SPIRVStructNumElements = MaxNumElements;
MaxNumElements = MaxWordCount - 1;
}
auto MIB =
MIRBuilder.buildInstr(Opcode).addDef(ReturnRegister).addUse(TypeID);
for (size_t I = 0; I < SPIRVStructNumElements; ++I)
MIB.addUse(Args[I]);
for (size_t I = SPIRVStructNumElements; I < NumElements;
I += MaxNumElements) {
auto MIB = MIRBuilder.buildInstr(ContinuedOpcode);
for (size_t J = I; J < std::min(I + MaxNumElements, NumElements); ++J)
MIB.addUse(Args[J]);
}
}
} // namespace llvm

View File

@ -444,5 +444,10 @@ inline FPDecorationId demangledPostfixToDecorationId(const std::string &S) {
return It == Mapping.end() ? FPDecorationId::NONE : It->second;
}
void createContinuedInstructions(MachineIRBuilder &MIRBuilder, unsigned Opcode,
unsigned MinWC, unsigned ContinuedOpcode,
ArrayRef<Register> Args,
Register ReturnRegister, Register TypeID);
} // namespace llvm
#endif // LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long