[llvm] 76b5fcb - [TableGen] Store flat source operand number in OperandMap in PseudoLoweringEmitter. NFC (#135886)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 16 09:39:56 PDT 2025
Author: Craig Topper
Date: 2025-04-16T09:39:52-07:00
New Revision: 76b5fcbf975547251faaeed8b567ea09d139a607
URL: https://github.com/llvm/llvm-project/commit/76b5fcbf975547251faaeed8b567ea09d139a607
DIFF: https://github.com/llvm/llvm-project/commit/76b5fcbf975547251faaeed8b567ea09d139a607.diff
LOG: [TableGen] Store flat source operand number in OperandMap in PseudoLoweringEmitter. NFC (#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.
Added:
Modified:
llvm/utils/TableGen/PseudoLoweringEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/PseudoLoweringEmitter.cpp b/llvm/utils/TableGen/PseudoLoweringEmitter.cpp
index 7f67c13c0bbbd..96325eac95004 100644
--- a/llvm/utils/TableGen/PseudoLoweringEmitter.cpp
+++ b/llvm/utils/TableGen/PseudoLoweringEmitter.cpp
@@ -181,24 +181,32 @@ void PseudoLoweringEmitter::evaluateExpansion(const Record *Rec) {
SourceOperands[SrcOp.Name] = Idx;
LLVM_DEBUG(dbgs() << " Operand mapping:\n");
- for (unsigned i = 0, e = Insn.Operands.size(); i != e; ++i) {
+ for (const auto &[Idx, Opnd] : enumerate(Insn.Operands)) {
// We've already handled constant values. Just map instruction operands
// here.
- if (OperandMap[Insn.Operands[i].MIOperandNo].Kind != OpData::Operand)
+ if (OperandMap[Opnd.MIOperandNo].Kind != OpData::Operand)
continue;
StringMap<unsigned>::iterator SourceOp =
- SourceOperands.find(Dag->getArgNameStr(i));
+ SourceOperands.find(Dag->getArgNameStr(Idx));
if (SourceOp == SourceOperands.end())
PrintFatalError(Rec, "In pseudo instruction '" + Rec->getName() +
- "', output operand '" + Dag->getArgNameStr(i) +
+ "', output operand '" + Dag->getArgNameStr(Idx) +
"' has no matching source operand");
+ const auto &SrcOpnd = SourceInsn.Operands[SourceOp->getValue()];
+ if (Opnd.MINumOperands != SrcOpnd.MINumOperands)
+ PrintFatalError(
+ Rec,
+ "In pseudo instruction '" + Rec->getName() + "', output operand '" +
+ Opnd.Rec->getName() +
+ "' has a
diff erent number of sub operands than source operand '" +
+ SrcOpnd.Rec->getName() + "'");
+
// Map the source operand to the destination operand index for each
// MachineInstr operand.
- for (unsigned I = 0, E = Insn.Operands[i].MINumOperands; I != E; ++I)
- OperandMap[Insn.Operands[i].MIOperandNo + I].Data.Operand =
- SourceOp->getValue();
+ for (unsigned I = 0, E = Opnd.MINumOperands; I != E; ++I)
+ OperandMap[Opnd.MIOperandNo + I].Data.Operand = SrcOpnd.MIOperandNo + I;
- LLVM_DEBUG(dbgs() << " " << SourceOp->getValue() << " ==> " << i
+ LLVM_DEBUG(dbgs() << " " << SourceOp->getValue() << " ==> " << Idx
<< "\n");
}
@@ -236,10 +244,7 @@ void PseudoLoweringEmitter::emitLoweringEmitter(raw_ostream &o) {
switch (Expansion.OperandMap[MIOpNo + i].Kind) {
case OpData::Operand:
o << " lowerOperand(MI->getOperand("
- << Source.Operands[Expansion.OperandMap[MIOpNo].Data.Operand]
- .MIOperandNo +
- i
- << "), MCOp);\n"
+ << Expansion.OperandMap[MIOpNo + i].Data.Operand << "), MCOp);\n"
<< " Inst.addOperand(MCOp);\n";
break;
case OpData::Imm:
More information about the llvm-commits
mailing list