[llvm] [TableGen] Complete the support for artificial registers (PR #183371)

Mikael Holmen via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 9 08:02:36 PDT 2026


================
@@ -844,7 +844,30 @@ unsigned CodeGenRegisterClass::getWeight(const CodeGenRegBank &RegBank) const {
 bool CodeGenRegisterClass::Key::operator<(
     const CodeGenRegisterClass::Key &B) const {
   assert(Members && B.Members);
-  return std::tie(*Members, RSI) < std::tie(*B.Members, B.RSI);
+  if (!IgnoreArtificialMembers)
+    return std::tie(*Members, RSI) < std::tie(*B.Members, B.RSI);
+
+  // Do the same lexicographical comparison, but ignoring
+  // artificial registers.
+  auto IA = Members->begin(), EA = Members->end();
+  auto IB = B.Members->begin(), EB = B.Members->end();
+  while (IA != EA && IB != EB) {
+    if ((*IA)->Artificial) {
+      ++IA;
+      continue;
+    }
+    if ((*IB)->Artificial) {
+      ++IB;
+      continue;
+    }
+    if (*IA != *IB)
+      return *IA < *IB;
+    ++IA;
+    ++IB;
+  }
+  if (IA == EA && IB == EB)
----------------
mikaelholmen wrote:

In the loop above we ignore Artificial registers. But what if we end up down here and there are trailing Artificial registers in either "A" or "B", then they could affect the comparison.

So I suppose we should skip over any trailing Artificial here too before doing the final comparisons?

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


More information about the llvm-commits mailing list