[llvm] [TableGen] Store flat source operand number in OperandMap in PseudoLoweringEmitter. NFC (PR #135886)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 15 17:03:48 PDT 2025
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/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 MIOperandNo and adding the sub index into loop that updates OperandMap and the emitting loop just prints the index.
While there, I've added a check that MIOperandNo is the same for source and destination.
>From 04dc7e24cd3cb2f76b50c5334bc296587a628f72 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 15 Apr 2025 16:56:40 -0700
Subject: [PATCH] [TableGen] Store flat source operand number in OperandMap in
PseudoLoweringEmitter. NFC
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 MIOperandNo and adding the sub index into
loop that updates OperandMap and the emitting loop just prints the index.
While there, I've added a check that MIOperandNo is the same for
source and destination.
---
llvm/utils/TableGen/PseudoLoweringEmitter.cpp | 29 +++++++++++--------
1 file changed, 17 insertions(+), 12 deletions(-)
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 different 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