[llvm] [TableGen] Share identical super-register class masks (PR #224633)

Nick Desaulniers via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 18 10:47:10 PDT 2026


================
@@ -1291,18 +1327,31 @@ void RegisterInfoEmitter::runMCDesc(raw_ostream &OS, raw_ostream &MainOS,
     OS << "    // " << StartIndices[Idx].SubClassMaskIdx << " " << RC.getName()
        << "\n    ";
     printBitVectorAsHex(OS, RC.getSubClasses(), 32);
+    OS << "\n";
+  }
 
-    // Emit super-reg class masks for any relevant SubRegIndices that can
-    // project into RC.
-    for (auto &Idx : SubRegIndices) {
-      MaskBV.reset();
-      RC.getSuperRegClasses(&Idx, MaskBV);
-      if (MaskBV.none())
-        continue;
-      OS << "\n    ";
-      printBitVectorAsHex(OS, MaskBV, 32);
-      OS << "// " << Idx.getName();
-    }
+  // Emit the pool of super-reg class masks, shared by all the classes that
+  // project into the same set of classes under some sub-register index.
+  for (const auto &[Idx, Mask] : enumerate(MaskPool)) {
+    OS << "    /* " << MaskPoolStarts[Idx] << " */ ";
+    for (uint32_t Word : Mask)
+      OS << format("0x%08x, ", Word);
+    OS << "\n";
+  }
+  OS << "  },\n  {\n";
+
+  // Emit, for each class, the offset of each of its super-reg class masks.
+  // Offsets are relative to the class itself, as MCRegisterClass reads them.
+  for (const auto &[Idx, RC] : enumerate(RegisterClasses)) {
+    ArrayRef<unsigned> MaskIndices = SuperRegMaskIndices[RC.EnumValue];
+    if (MaskIndices.empty())
+      continue;
+    OS << "    /* " << StartIndices[Idx].SuperRegMaskOffsetIdx << " "
+       << RC.getName() << " */ ";
+    for (unsigned MaskIdx : MaskIndices)
+      OS << "offsetof(" << TargetName << "RegisterClassStorage, SubClassMasks["
+         << MaskPoolStarts[MaskIdx] << "]) - " << Idx
+         << " * sizeof(MCRegisterClass), ";
----------------
nickdesaulniers wrote:

This looks like the `GetOff` lambda from line 1224 (before your change). Hoist+reuse that here?

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


More information about the llvm-commits mailing list