Skip to content

Commit 76b5fcb

Browse files
authored
[TableGen] Store flat source operand number in OperandMap in PseudoLoweringEmitter. NFC (llvm#135886)
Previously we stored the index into the source CodeGenInstruction's operand list. Any operand with sub operands stored the same index into all of the OperandMap entries for that operand. The emitting loop would look up the MIOperandNo for the source and add the sub index. This patch moves the logic into the loop that updates the OperandMap. Now the emitting loop only needs to print the value. While there, I've added a check that MIOperandNo is the same for source and destination.
1 parent 24171f4 commit 76b5fcb

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

llvm/utils/TableGen/PseudoLoweringEmitter.cpp

+17-12
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,32 @@ void PseudoLoweringEmitter::evaluateExpansion(const Record *Rec) {
181181
SourceOperands[SrcOp.Name] = Idx;
182182

183183
LLVM_DEBUG(dbgs() << " Operand mapping:\n");
184-
for (unsigned i = 0, e = Insn.Operands.size(); i != e; ++i) {
184+
for (const auto &[Idx, Opnd] : enumerate(Insn.Operands)) {
185185
// We've already handled constant values. Just map instruction operands
186186
// here.
187-
if (OperandMap[Insn.Operands[i].MIOperandNo].Kind != OpData::Operand)
187+
if (OperandMap[Opnd.MIOperandNo].Kind != OpData::Operand)
188188
continue;
189189
StringMap<unsigned>::iterator SourceOp =
190-
SourceOperands.find(Dag->getArgNameStr(i));
190+
SourceOperands.find(Dag->getArgNameStr(Idx));
191191
if (SourceOp == SourceOperands.end())
192192
PrintFatalError(Rec, "In pseudo instruction '" + Rec->getName() +
193-
"', output operand '" + Dag->getArgNameStr(i) +
193+
"', output operand '" + Dag->getArgNameStr(Idx) +
194194
"' has no matching source operand");
195+
const auto &SrcOpnd = SourceInsn.Operands[SourceOp->getValue()];
196+
if (Opnd.MINumOperands != SrcOpnd.MINumOperands)
197+
PrintFatalError(
198+
Rec,
199+
"In pseudo instruction '" + Rec->getName() + "', output operand '" +
200+
Opnd.Rec->getName() +
201+
"' has a different number of sub operands than source operand '" +
202+
SrcOpnd.Rec->getName() + "'");
203+
195204
// Map the source operand to the destination operand index for each
196205
// MachineInstr operand.
197-
for (unsigned I = 0, E = Insn.Operands[i].MINumOperands; I != E; ++I)
198-
OperandMap[Insn.Operands[i].MIOperandNo + I].Data.Operand =
199-
SourceOp->getValue();
206+
for (unsigned I = 0, E = Opnd.MINumOperands; I != E; ++I)
207+
OperandMap[Opnd.MIOperandNo + I].Data.Operand = SrcOpnd.MIOperandNo + I;
200208

201-
LLVM_DEBUG(dbgs() << " " << SourceOp->getValue() << " ==> " << i
209+
LLVM_DEBUG(dbgs() << " " << SourceOp->getValue() << " ==> " << Idx
202210
<< "\n");
203211
}
204212

@@ -236,10 +244,7 @@ void PseudoLoweringEmitter::emitLoweringEmitter(raw_ostream &o) {
236244
switch (Expansion.OperandMap[MIOpNo + i].Kind) {
237245
case OpData::Operand:
238246
o << " lowerOperand(MI->getOperand("
239-
<< Source.Operands[Expansion.OperandMap[MIOpNo].Data.Operand]
240-
.MIOperandNo +
241-
i
242-
<< "), MCOp);\n"
247+
<< Expansion.OperandMap[MIOpNo + i].Data.Operand << "), MCOp);\n"
243248
<< " Inst.addOperand(MCOp);\n";
244249
break;
245250
case OpData::Imm:

0 commit comments

Comments
 (0)