Skip to content

[SPIR-V] Support 2 more instructions from SPV_INTEL_long_composites #128190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2113,8 +2113,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,
Expand Down Expand Up @@ -2227,11 +2230,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:
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/SPIRV/SPIRVInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 32 additions & 0 deletions llvm/lib/Target/SPIRV/SPIRVUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,4 +795,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
5 changes: 5 additions & 0 deletions llvm/lib/Target/SPIRV/SPIRVUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,5 +441,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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading