[llvm] [TableGen] More generically handle tied source operands in CompressInstEmitter. (PR #146183)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 1 10:52:31 PDT 2025
================
@@ -331,60 +348,29 @@ static bool verifyDagOpCount(const CodeGenInstruction &Inst, const DagInit *Dag,
return true;
}
-static bool validateArgsTypes(const Init *Arg1, const Init *Arg2) {
- return cast<DefInit>(Arg1)->getDef() == cast<DefInit>(Arg2)->getDef();
-}
-
-// Creates a mapping between the operand name in the Dag (e.g. $rs1) and
-// its index in the list of Dag operands and checks that operands with the same
-// name have the same types. For example in 'C_ADD $rs1, $rs2' we generate the
-// mapping $rs1 --> 0, $rs2 ---> 1. If the operand appears twice in the (tied)
-// same Dag we use the last occurrence for indexing.
-void CompressInstEmitter::createDagOperandMapping(
- const Record *Rec, StringMap<unsigned> &SourceOperands,
- StringMap<unsigned> &DestOperands, const DagInit *SourceDag,
- const DagInit *DestDag, IndexedMap<OpData> &SourceOperandMap,
- bool HasSourceTiedOp) {
- for (unsigned I = 0; I < DestDag->getNumArgs(); ++I) {
- // Skip fixed immediates and registers, they were handled in
- // addDagOperandMapping.
- if ("" == DestDag->getArgNameStr(I))
- continue;
- DestOperands[DestDag->getArgNameStr(I)] = I;
- }
+// Check that all names in the source DAG appear in the destionation DAG.
+void CompressInstEmitter::checkDagOperandMapping(
+ const Record *Rec,
+ const StringMap<std::pair<unsigned, unsigned>> &DestOperands,
+ const DagInit *SourceDag, const DagInit *DestDag) {
for (unsigned I = 0; I < SourceDag->getNumArgs(); ++I) {
// Skip fixed immediates and registers, they were handled in
// addDagOperandMapping.
- if ("" == SourceDag->getArgNameStr(I))
+ if (SourceDag->getArgNameStr(I).empty())
continue;
- StringMap<unsigned>::iterator It =
- SourceOperands.find(SourceDag->getArgNameStr(I));
- if (It != SourceOperands.end()) {
- // Operand sharing the same name in the Dag should be mapped as tied.
- if (HasSourceTiedOp)
- SourceOperandMap[I + 1].TiedOpIdx = It->getValue() + 1;
- else
- SourceOperandMap[I].TiedOpIdx = It->getValue();
- if (!validateArgsTypes(SourceDag->getArg(It->getValue()),
- SourceDag->getArg(I)))
- PrintFatalError(Rec->getLoc(),
- "Input Operand '" + SourceDag->getArgNameStr(I) +
- "' has a mismatched tied operand!\n");
- }
- It = DestOperands.find(SourceDag->getArgNameStr(I));
+ auto It = DestOperands.find(SourceDag->getArgNameStr(I));
----------------
jurahul wrote:
extract SourceDag->getArgNameStr(I) into a local variable?
https://github.com/llvm/llvm-project/pull/146183
More information about the llvm-commits
mailing list