[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:49:45 PDT 2025


================
@@ -290,6 +285,28 @@ void CompressInstEmitter::addDagOperandMapping(const Record *Rec,
       } else {
         llvm_unreachable("Unhandled CompressPat argument type!");
       }
+
+      // Create a mapping between the operand name in the Dag (e.g. $rs1) and
+      // its index in the list of Dag operands and check that operands with the
+      // same name have the same type. 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.
+      if (Dag->getArgNameStr(DAGOpNo).empty())
+        continue;
+
+      if (IsSourceInst) {
+        auto It = Operands.find(Dag->getArgNameStr(DAGOpNo));
+        if (It != Operands.end()) {
+          OperandMap[OpNo].TiedOpIdx = It->getValue().second;
+          if (!validateArgsTypes(Dag->getArg(It->getValue().first),
+                                 Dag->getArg(DAGOpNo)))
+            PrintFatalError(Rec->getLoc(),
+                            "Input Operand '" + Dag->getArgNameStr(DAGOpNo) +
+                                "' has a mismatched tied operand!\n");
----------------
jurahul wrote:

nit: drop the \n at the end of the error message? Most PrintFatalError() don't have that AFAICT. In this file, some assert messages also have '\n' at end which is unnecessary, but that can be cleaned up in a separate PR.

https://github.com/llvm/llvm-project/pull/146183


More information about the llvm-commits mailing list