[llvm] [TableGen] Print MVT name in the isel table when it doesn't require a VBR. (PR #175128)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 8 23:40:52 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-selectiondag

Author: Craig Topper (topperc)

<details>
<summary>Changes</summary>

If the MVT is small enough, we can emit the enum name instead of
printing its encoding.

Stacked on #<!-- -->175127

---
Full diff: https://github.com/llvm/llvm-project/pull/175128.diff


1 Files Affected:

- (modified) llvm/utils/TableGen/DAGISelMatcherEmitter.cpp (+22-33) 


``````````diff
diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
index 7877a1f36424f..6eaac318d3e41 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -424,6 +424,18 @@ void MatcherTableEmitter::EmitPatternMatchTable(raw_ostream &OS) {
   EndEmitFunction(OS);
 }
 
+static unsigned emitMVT(MVT VT, raw_ostream &OS) {
+  // Print the MVT directly if it doesn't require a VBR.
+  if (VT.SimpleTy <= 127) {
+    OS << getEnumName(VT) << ',';
+    return 1;
+  }
+
+  if (!OmitComments)
+    OS << "/*" << getEnumName(VT) << "*/";
+  return EmitVBRValue(VT.SimpleTy, OS);
+}
+
 /// EmitMatcher - Emit bytes for the specified matcher and return
 /// the number of bytes emitted.
 unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
@@ -631,12 +643,8 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
       OS << ' ';
       if (const SwitchOpcodeMatcher *SOM = dyn_cast<SwitchOpcodeMatcher>(N))
         OS << "TARGET_VAL(" << SOM->getCaseOpcode(i).getEnumName() << "),";
-      else {
-        if (!OmitComments)
-          OS << "/*" << getEnumName(cast<SwitchTypeMatcher>(N)->getCaseType(i))
-             << "*/";
-        EmitVBRValue(cast<SwitchTypeMatcher>(N)->getCaseType(i).SimpleTy, OS);
-      }
+      else
+        emitMVT(cast<SwitchTypeMatcher>(N)->getCaseType(i), OS);
       if (!OmitComments)
         OS << " // ->" << CurrentIdx + ChildSize;
       OS << '\n';
@@ -669,18 +677,13 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
         return 1;
       default:
         OS << "OPC_CheckType, ";
-        if (!OmitComments)
-          OS << "/*" << getEnumName(VT) << "*/";
-        unsigned NumBytes = EmitVBRValue(VT.SimpleTy, OS);
+        unsigned NumBytes = emitMVT(VT, OS);
         OS << "\n";
         return NumBytes + 1;
       }
     }
     OS << "OPC_CheckTypeRes, " << cast<CheckTypeMatcher>(N)->getResNo() << ", ";
-    if (!OmitComments)
-      OS << "/*" << getEnumName(cast<CheckTypeMatcher>(N)->getType()) << "*/";
-    unsigned NumBytes =
-        EmitVBRValue(cast<CheckTypeMatcher>(N)->getType().SimpleTy, OS);
+    unsigned NumBytes = emitMVT(cast<CheckTypeMatcher>(N)->getType(), OS);
     OS << "\n";
     return NumBytes + 2;
   }
@@ -696,9 +699,7 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
     default:
       OS << "OPC_CheckChild" << cast<CheckChildTypeMatcher>(N)->getChildNo()
          << "Type, ";
-      if (!OmitComments)
-        OS << "/*" << getEnumName(VT) << "*/";
-      unsigned NumBytes = EmitVBRValue(VT.SimpleTy, OS);
+      unsigned NumBytes = emitMVT(VT, OS);
       OS << "\n";
       return NumBytes + 1;
     }
@@ -731,11 +732,7 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
 
   case Matcher::CheckValueType: {
     OS << "OPC_CheckValueType, ";
-    if (!OmitComments)
-      OS << "/*" << getEnumName(cast<CheckValueTypeMatcher>(N)->getVT())
-         << "*/";
-    unsigned NumBytes =
-        EmitVBRValue(cast<CheckValueTypeMatcher>(N)->getVT().SimpleTy, OS);
+    unsigned NumBytes = emitMVT(cast<CheckValueTypeMatcher>(N)->getVT(), OS);
     OS << "\n";
     return NumBytes + 1;
   }
@@ -807,9 +804,7 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
       break;
     default:
       OS << "OPC_EmitInteger, ";
-      if (!OmitComments)
-        OS << "/*" << getEnumName(VT) << "*/";
-      TypeBytes = EmitVBRValue(VT.SimpleTy, OS);
+      TypeBytes = emitMVT(VT, OS);
       OS << ' ';
       break;
     }
@@ -840,9 +835,7 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
     // use EmitRegister2.
     if (Reg && Reg->EnumValue > 255) {
       OS << "OPC_EmitRegister2, ";
-      if (!OmitComments)
-        OS << "/*" << getEnumName(VT) << "*/";
-      OpBytes = EmitVBRValue(VT.SimpleTy, OS);
+      OpBytes = emitMVT(VT, OS);
       OS << "TARGET_VAL(" << getQualifiedName(Reg->TheDef) << "),\n";
       return OpBytes + 3;
     }
@@ -854,9 +847,7 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
       break;
     default:
       OS << "OPC_EmitRegister, ";
-      if (!OmitComments)
-        OS << "/*" << getEnumName(VT) << "*/";
-      OpBytes = EmitVBRValue(VT.SimpleTy, OS) + 1;
+      OpBytes = emitMVT(VT, OS) + 1;
       break;
     }
     if (Reg) {
@@ -1020,9 +1011,7 @@ unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
     unsigned NumTypeBytes = 0;
     for (unsigned i = 0, e = EN->getNumVTs(); i != e; ++i) {
       OS << ' ';
-      if (!OmitComments)
-        OS << "/*" << getEnumName(EN->getVT(i)) << "*/";
-      NumTypeBytes += EmitVBRValue(EN->getVT(i).SimpleTy, OS);
+      NumTypeBytes += emitMVT(EN->getVT(i), OS);
     }
 
     OS << ' ' << EN->getNumOperands();

``````````

</details>


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


More information about the llvm-commits mailing list