Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
49 changes: 45 additions & 4 deletions llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2113,8 +2113,32 @@ 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));
auto MIB = MIRBuilder.buildInstr(SPIRV::OpCompositeConstruct)
.addDef(Call->ReturnRegister)
.addUse(GR->getSPIRVTypeID(Call->ReturnType));

constexpr unsigned MaxWordCount = UINT16_MAX;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible and make sense to try to factor out common logic of long composites support as a separate utility function to avoid repetitions in this and previous PR? I think we would end up with a more concise version eventually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks tricky to unify it together with the type instruction, but for those introduced in PR - will do.
(For continued type instructions we should do the logic when we're calling createOpType, which I can't see how to unify for now).

const size_t NumElements = Call->Arguments.size();
size_t MaxNumElements = MaxWordCount - 3;
size_t SPIRVStructNumElements = NumElements;

if (NumElements > MaxNumElements) {
// Do adjustments for continued instructions.
SPIRVStructNumElements = MaxNumElements;
MaxNumElements = MaxWordCount - 1;
}

for (size_t I = 0; I < SPIRVStructNumElements; ++I)
MIB.addUse(Call->Arguments[I]);

for (size_t I = SPIRVStructNumElements; I < NumElements;
I += MaxNumElements) {
auto MIB = MIRBuilder.buildInstr(SPIRV::OpCompositeConstructContinuedINTEL);
for (size_t J = I; J < std::min(I + MaxNumElements, NumElements); ++J)
MIB.addUse(Call->Arguments[J]);
}

return true;
}

static bool generateCoopMatrInst(const SPIRV::IncomingCall *Call,
Expand Down Expand Up @@ -2230,8 +2254,25 @@ static bool generateSpecConstantInst(const SPIRV::IncomingCall *Call,
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]);

constexpr unsigned MaxWordCount = UINT16_MAX;
const size_t NumElements = Call->Arguments.size();
size_t MaxNumElements = MaxWordCount - 3;
size_t SPIRVStructNumElements = NumElements;
if (NumElements > MaxNumElements) {
SPIRVStructNumElements = MaxNumElements;
MaxNumElements = MaxWordCount - 1;
}
for (size_t I = 0; I < SPIRVStructNumElements; ++I)
MIB.addUse(Call->Arguments[I]);

for (size_t I = SPIRVStructNumElements; I < NumElements;
I += MaxNumElements) {
auto MIB =
MIRBuilder.buildInstr(SPIRV::OpSpecConstantCompositeContinuedINTEL);
for (size_t J = I; J < std::min(I + MaxNumElements, NumElements); ++J)
MIB.addUse(Call->Arguments[J]);
}
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.