[llvm] [TableGen] Combine the two separate OperandMapping loops in PseudoLoweringEmitter. (PR #136007)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 16 13:34:28 PDT 2025
================
@@ -180,37 +176,43 @@ void PseudoLoweringEmitter::evaluateExpansion(const Record *Rec) {
for (const auto &[Idx, SrcOp] : enumerate(SourceInsn.Operands))
SourceOperands[SrcOp.Name] = Idx;
- LLVM_DEBUG(dbgs() << " Operand mapping:\n");
- for (const auto &[Idx, Opnd] : enumerate(Insn.Operands)) {
- // We've already handled constant values. Just map instruction operands
- // here.
- if (OperandMap[Opnd.MIOperandNo].Kind != OpData::Operand)
- continue;
- StringMap<unsigned>::iterator SourceOp =
- SourceOperands.find(Dag->getArgNameStr(Idx));
- if (SourceOp == SourceOperands.end())
- PrintFatalError(Rec, "In pseudo instruction '" + Rec->getName() +
- "', 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() + "'");
+ unsigned NumMIOperands = 0;
+ for (const auto &Op : Insn.Operands)
+ NumMIOperands += Op.MINumOperands;
+ IndexedMap<OpData> OperandMap;
+ OperandMap.grow(NumMIOperands);
- // Map the source operand to the destination operand index for each
- // MachineInstr operand.
- for (unsigned I = 0, E = Opnd.MINumOperands; I != E; ++I)
- OperandMap[Opnd.MIOperandNo + I].Data.Operand = SrcOpnd.MIOperandNo + I;
+ // FIXME: This pass currently can only expand a pseudo to a single
+ // instruction. The pseudo expansion really should take a list of dags, not
+ // just a single dag, so we can do fancier things.
+ LLVM_DEBUG(dbgs() << " Operand mapping:\n");
+ for (const auto &[Idx, DstOp] : enumerate(Insn.Operands)) {
+ unsigned MIOpNo = DstOp.MIOperandNo;
- LLVM_DEBUG(dbgs() << " " << SourceOp->getValue() << " ==> " << Idx
- << "\n");
+ if (const auto *SubDag = dyn_cast<DagInit>(Dag->getArg(Idx))) {
+ if (DstOp.MIOperandInfo->getNumArgs() == 0)
----------------
s-barannikov wrote:
It is awkward, but not all operands derive from Operand, e.g., RegisterOperand.
> I think we need both.
Kind of redundant with the next check, but SG.
https://github.com/llvm/llvm-project/pull/136007
More information about the llvm-commits
mailing list