Skip to content
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
32 changes: 19 additions & 13 deletions llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2940,24 +2940,30 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
case Intrinsic::spv_const_composite: {
// If no values are attached, the composite is null constant.
bool IsNull = I.getNumExplicitDefs() + 1 == I.getNumExplicitOperands();
// Select a proper instruction.
unsigned Opcode = SPIRV::OpConstantNull;
SmallVector<Register> CompositeArgs;
if (!IsNull) {
Opcode = SPIRV::OpConstantComposite;
if (!wrapIntoSpecConstantOp(I, CompositeArgs))
return false;
}
MRI->setRegClass(ResVReg, GR.getRegClass(ResType));
auto MIB = BuildMI(BB, I, I.getDebugLoc(), TII.get(Opcode))
.addDef(ResVReg)
.addUse(GR.getSPIRVTypeID(ResType));

// skip type MD node we already used when generated assign.type for this
if (!IsNull) {
for (Register OpReg : CompositeArgs)
MIB.addUse(OpReg);
if (!wrapIntoSpecConstantOp(I, CompositeArgs))
return false;
MachineIRBuilder MIR(I);
SmallVector<MachineInstr *, 4> Instructions = createContinuedInstructions(
MIR, SPIRV::OpConstantComposite, 3,
SPIRV::OpConstantCompositeContinuedINTEL, CompositeArgs, ResVReg,
GR.getSPIRVTypeID(ResType));
for (auto *Instr : Instructions) {
Instr->setDebugLoc(I.getDebugLoc());
if (!constrainSelectedInstRegOperands(*Instr, TII, TRI, RBI))
return false;
}
return true;
} else {
auto MIB = BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpConstantNull))
.addDef(ResVReg)
.addUse(GR.getSPIRVTypeID(ResType));
return MIB.constrainAllUses(TII, TRI, RBI);
}
return MIB.constrainAllUses(TII, TRI, RBI);
}
case Intrinsic::spv_assign_name: {
auto MIB = BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpName));
Expand Down
9 changes: 7 additions & 2 deletions llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,16 @@ void SPIRVModuleAnalysis::visitDecl(
} else if (Opcode == SPIRV::OpFunction ||
Opcode == SPIRV::OpFunctionParameter) {
GReg = handleFunctionOrParameter(MF, MI, GlobalToGReg, IsFunDef);
} else if (Opcode == SPIRV::OpTypeStruct) {
} else if (Opcode == SPIRV::OpTypeStruct ||
Opcode == SPIRV::OpConstantComposite) {
GReg = handleTypeDeclOrConstant(MI, SignatureToGReg);
const MachineInstr *NextInstr = MI.getNextNode();
while (NextInstr &&
NextInstr->getOpcode() == SPIRV::OpTypeStructContinuedINTEL) {
((Opcode == SPIRV::OpTypeStruct &&
NextInstr->getOpcode() == SPIRV::OpTypeStructContinuedINTEL) ||
(Opcode == SPIRV::OpConstantComposite &&
NextInstr->getOpcode() ==
SPIRV::OpConstantCompositeContinuedINTEL))) {
MCRegister Tmp = handleTypeDeclOrConstant(*NextInstr, SignatureToGReg);
MAI.setRegisterAlias(MF, NextInstr->getOperand(0).getReg(), Tmp);
MAI.setSkipEmission(NextInstr);
Expand Down
15 changes: 11 additions & 4 deletions llvm/lib/Target/SPIRV/SPIRVUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,10 +813,13 @@ bool isSpvIntrinsic(const Value *Arg) {

// 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) {
SmallVector<MachineInstr *, 4>
createContinuedInstructions(MachineIRBuilder &MIRBuilder, unsigned Opcode,
unsigned MinWC, unsigned ContinuedOpcode,
ArrayRef<Register> Args, Register ReturnRegister,
Register TypeID) {

SmallVector<MachineInstr *, 4> Instructions;
constexpr unsigned MaxWordCount = UINT16_MAX;
const size_t NumElements = Args.size();
size_t MaxNumElements = MaxWordCount - MinWC;
Expand All @@ -835,12 +838,16 @@ void createContinuedInstructions(MachineIRBuilder &MIRBuilder, unsigned Opcode,
for (size_t I = 0; I < SPIRVStructNumElements; ++I)
MIB.addUse(Args[I]);

Instructions.push_back(MIB.getInstr());

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]);
Instructions.push_back(MIB.getInstr());
}
return Instructions;
}

} // namespace llvm
9 changes: 5 additions & 4 deletions llvm/lib/Target/SPIRV/SPIRVUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,11 @@ 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);
SmallVector<MachineInstr *, 4>
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.