Skip to content

[TableGen] Simplify computeUberWeights. NFC. #143716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025

Conversation

jayfoad
Copy link
Contributor

@jayfoad jayfoad commented Jun 11, 2025

Using RegUnitIterator made the code more complicated than having two
nested loops over each register and each register's regunits.

Using RegUnitIterator made the code more complicated than having two
nested loops over each register and each register's regunits.
@llvmbot
Copy link
Member

llvmbot commented Jun 11, 2025

@llvm/pr-subscribers-tablegen

Author: Jay Foad (jayfoad)

Changes

Using RegUnitIterator made the code more complicated than having two
nested loops over each register and each register's regunits.


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

1 Files Affected:

  • (modified) llvm/utils/TableGen/Common/CodeGenRegisters.cpp (+12-17)
diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
index 5ec9b35379fa4..4d24eb3de1ed9 100644
--- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
@@ -1849,26 +1849,21 @@ static void computeUberWeights(MutableArrayRef<UberRegSet> UberSets,
   // Skip the first unallocatable set.
   for (UberRegSet &S : UberSets.drop_front()) {
     // Initialize all unit weights in this set, and remember the max units/reg.
-    const CodeGenRegister *Reg = nullptr;
-    unsigned MaxWeight = 0, Weight = 0;
-    for (RegUnitIterator UnitI(S.Regs); UnitI.isValid(); ++UnitI) {
-      if (Reg != UnitI.getReg()) {
-        if (Weight > MaxWeight)
-          MaxWeight = Weight;
-        Reg = UnitI.getReg();
-        Weight = 0;
-      }
-      if (!RegBank.getRegUnit(*UnitI).Artificial) {
-        unsigned UWeight = RegBank.getRegUnit(*UnitI).Weight;
-        if (!UWeight) {
-          UWeight = 1;
-          RegBank.increaseRegUnitWeight(*UnitI, UWeight);
+    unsigned MaxWeight = 0;
+    for (const CodeGenRegister *R : S.Regs) {
+      unsigned Weight = 0;
+      for (unsigned U : R->getRegUnits()) {
+        if (!RegBank.getRegUnit(U).Artificial) {
+          unsigned UWeight = RegBank.getRegUnit(U).Weight;
+          if (!UWeight) {
+            UWeight = 1;
+            RegBank.increaseRegUnitWeight(U, UWeight);
+          }
+          Weight += UWeight;
         }
-        Weight += UWeight;
       }
+      MaxWeight = std::max(MaxWeight, Weight);
     }
-    if (Weight > MaxWeight)
-      MaxWeight = Weight;
     if (S.Weight != MaxWeight) {
       LLVM_DEBUG({
         dbgs() << "UberSet " << &S - UberSets.begin() << " Weight "

@jayfoad jayfoad requested review from jurahul and nvjle June 11, 2025 14:52
Copy link
Contributor

@nvjle nvjle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jayfoad jayfoad merged commit 78765bb into llvm:main Jun 11, 2025
9 checks passed
@jayfoad jayfoad deleted the simplify-computeuberweights branch June 11, 2025 16:23
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
Using RegUnitIterator made the code more complicated than having two
nested loops over each register and each register's regunits.
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
Using RegUnitIterator made the code more complicated than having two
nested loops over each register and each register's regunits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants