Skip to content

[MISched] Small debug improvements #125072

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 5 commits into from
Feb 5, 2025

Conversation

c-rhodes
Copy link
Collaborator

Changes:

  1. Fix inconsistencies in register pressure set printing. "Max Pressure"
    printing is inconsistent with "Bottom Pressure" and "Top Pressure".
    For the former, register class begins on the same line vs newline for
    latter. Also for the former, the first register class is on the same
    line, but subsequent register classes are newline separated. That's
    removed so all are on the same line.

    Before:
    Max Pressure: FPR8=1
    GPR32=14
    Top Pressure:
    GPR32=2
    Bottom Pressure:
    FPR8=7
    GPR32=17

    After:
    Max Pressure: FPR8=1 GPR32=14
    Top Pressure: GPR32=2
    Bottom Pressure: FPR8=7 GPR32=17

  2. After scheduling an instruction, don't print pressure diff if there
    isn't one. Also s/UpdateRegP/UpdateRegPressure. E.g.,

    Before:
    UpdateRegP: SU(3) %0:gpr64common = ADDXrr %58:gpr64common, gpr64
    to
    UpdateRegP: SU(4) %393:gpr64sp = ADDXri %58:gpr64common, 390, 12
    to GPR32 -1

    After:
    UpdateRegPressure: SU(4) %393:gpr64sp = ADDXri %58:gpr64common, 12
    to GPR32 -1

  3. Don't print excess pressure sets if there are none.

Changes:
1. Fix inconsistencies in register pressure set printing. "Max Pressure"
   printing is inconsistent with "Bottom Pressure" and "Top Pressure".
   For the former, register class begins on the same line vs newline for
   latter. Also for the former, the first register class is on the same
   line, but subsequent register classes are newline separated. That's
   removed so all are on the same line.

   Before:
     Max Pressure: FPR8=1
     GPR32=14
     Top Pressure:
     GPR32=2
     Bottom Pressure:
     FPR8=7
     GPR32=17

   After:
     Max Pressure: FPR8=1 GPR32=14
     Top Pressure: GPR32=2
     Bottom Pressure: FPR8=7 GPR32=17

2. After scheduling an instruction, don't print pressure diff if there
   isn't one. Also s/UpdateRegP/UpdateRegPressure. E.g.,

   Before:
     UpdateRegP: SU(3) %0:gpr64common = ADDXrr %58:gpr64common, gpr64
                 to
     UpdateRegP: SU(4) %393:gpr64sp = ADDXri %58:gpr64common, 390, 12
                 to GPR32 -1

   After:
     UpdateRegPressure: SU(4) %393:gpr64sp = ADDXri %58:gpr64common, 12
                        to GPR32 -1
3. Don't print excess pressure sets if there are none.
@llvmbot
Copy link
Member

llvmbot commented Jan 30, 2025

@llvm/pr-subscribers-llvm-regalloc

Author: Cullen Rhodes (c-rhodes)

Changes

Changes:

  1. Fix inconsistencies in register pressure set printing. "Max Pressure"
    printing is inconsistent with "Bottom Pressure" and "Top Pressure".
    For the former, register class begins on the same line vs newline for
    latter. Also for the former, the first register class is on the same
    line, but subsequent register classes are newline separated. That's
    removed so all are on the same line.

    Before:
    Max Pressure: FPR8=1
    GPR32=14
    Top Pressure:
    GPR32=2
    Bottom Pressure:
    FPR8=7
    GPR32=17

    After:
    Max Pressure: FPR8=1 GPR32=14
    Top Pressure: GPR32=2
    Bottom Pressure: FPR8=7 GPR32=17

  2. After scheduling an instruction, don't print pressure diff if there
    isn't one. Also s/UpdateRegP/UpdateRegPressure. E.g.,

    Before:
    UpdateRegP: SU(3) %0:gpr64common = ADDXrr %58:gpr64common, gpr64
    to
    UpdateRegP: SU(4) %393:gpr64sp = ADDXri %58:gpr64common, 390, 12
    to GPR32 -1

    After:
    UpdateRegPressure: SU(4) %393:gpr64sp = ADDXri %58:gpr64common, 12
    to GPR32 -1

  3. Don't print excess pressure sets if there are none.


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

2 Files Affected:

  • (modified) llvm/lib/CodeGen/MachineScheduler.cpp (+19-16)
  • (modified) llvm/lib/CodeGen/RegisterPressure.cpp (+2-5)
diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp
index 393530f56cc27e..e499dfa9822b96 100644
--- a/llvm/lib/CodeGen/MachineScheduler.cpp
+++ b/llvm/lib/CodeGen/MachineScheduler.cpp
@@ -1293,9 +1293,9 @@ void ScheduleDAGMILive::initRegPressure() {
     updatePressureDiffs(LiveUses);
   }
 
-  LLVM_DEBUG(dbgs() << "Top Pressure:\n";
+  LLVM_DEBUG(dbgs() << "Top Pressure: ";
              dumpRegSetPressure(TopRPTracker.getRegSetPressureAtPos(), TRI);
-             dbgs() << "Bottom Pressure:\n";
+             dbgs() << "Bottom Pressure: ";
              dumpRegSetPressure(BotRPTracker.getRegSetPressureAtPos(), TRI););
 
   assert((BotRPTracker.getPos() == RegionEnd ||
@@ -1316,11 +1316,12 @@ void ScheduleDAGMILive::initRegPressure() {
       RegionCriticalPSets.push_back(PressureChange(i));
     }
   }
-  LLVM_DEBUG(dbgs() << "Excess PSets: ";
-             for (const PressureChange &RCPS
-                  : RegionCriticalPSets) dbgs()
-             << TRI->getRegPressureSetName(RCPS.getPSet()) << " ";
-             dbgs() << "\n");
+  if (RegionCriticalPSets.size() > 0)
+    LLVM_DEBUG(dbgs() << "Excess PSets: ";
+               for (const PressureChange &RCPS
+                    : RegionCriticalPSets) dbgs()
+               << TRI->getRegPressureSetName(RCPS.getPSet()) << " ";
+               dbgs() << "\n");
 }
 
 void ScheduleDAGMILive::
@@ -1374,10 +1375,11 @@ void ScheduleDAGMILive::updatePressureDiffs(ArrayRef<VRegMaskOrUnit> LiveUses) {
 
         PressureDiff &PDiff = getPressureDiff(&SU);
         PDiff.addPressureChange(Reg, Decrement, &MRI);
-        LLVM_DEBUG(dbgs() << "  UpdateRegP: SU(" << SU.NodeNum << ") "
-                          << printReg(Reg, TRI) << ':'
-                          << PrintLaneMask(P.LaneMask) << ' ' << *SU.getInstr();
-                   dbgs() << "              to "; PDiff.dump(*TRI););
+        if (llvm::any_of(PDiff, [](const PressureChange &Change) { return Change.isValid(); }))
+          LLVM_DEBUG(dbgs() << "  UpdateRegPressure: SU(" << SU.NodeNum << ") "
+                            << printReg(Reg, TRI) << ':'
+                            << PrintLaneMask(P.LaneMask) << ' ' << *SU.getInstr();
+                     dbgs() << "                     to "; PDiff.dump(*TRI););
       }
     } else {
       assert(P.LaneMask.any());
@@ -1409,9 +1411,10 @@ void ScheduleDAGMILive::updatePressureDiffs(ArrayRef<VRegMaskOrUnit> LiveUses) {
           if (LRQ.valueIn() == VNI) {
             PressureDiff &PDiff = getPressureDiff(SU);
             PDiff.addPressureChange(Reg, true, &MRI);
-            LLVM_DEBUG(dbgs() << "  UpdateRegP: SU(" << SU->NodeNum << ") "
-                              << *SU->getInstr();
-                       dbgs() << "              to "; PDiff.dump(*TRI););
+            if (llvm::any_of(PDiff, [](const PressureChange &Change) { return Change.isValid(); }))
+              LLVM_DEBUG(dbgs() << "  UpdateRegPressure: SU(" << SU->NodeNum << ") "
+                                << *SU->getInstr();
+                         dbgs() << "                     to "; PDiff.dump(*TRI););
           }
         }
       }
@@ -1671,7 +1674,7 @@ void ScheduleDAGMILive::scheduleMI(SUnit *SU, bool IsTopNode) {
 
       TopRPTracker.advance(RegOpers);
       assert(TopRPTracker.getPos() == CurrentTop && "out of sync");
-      LLVM_DEBUG(dbgs() << "Top Pressure:\n"; dumpRegSetPressure(
+      LLVM_DEBUG(dbgs() << "Top Pressure: "; dumpRegSetPressure(
                      TopRPTracker.getRegSetPressureAtPos(), TRI););
 
       updateScheduledPressure(SU, TopRPTracker.getPressure().MaxSetPressure);
@@ -1709,7 +1712,7 @@ void ScheduleDAGMILive::scheduleMI(SUnit *SU, bool IsTopNode) {
       SmallVector<VRegMaskOrUnit, 8> LiveUses;
       BotRPTracker.recede(RegOpers, &LiveUses);
       assert(BotRPTracker.getPos() == CurrentBottom && "out of sync");
-      LLVM_DEBUG(dbgs() << "Bottom Pressure:\n"; dumpRegSetPressure(
+      LLVM_DEBUG(dbgs() << "Bottom Pressure: "; dumpRegSetPressure(
                      BotRPTracker.getRegSetPressureAtPos(), TRI););
 
       updateScheduledPressure(SU, BotRPTracker.getPressure().MaxSetPressure);
diff --git a/llvm/lib/CodeGen/RegisterPressure.cpp b/llvm/lib/CodeGen/RegisterPressure.cpp
index e8e6db1e3b3bd1..ca51b670b46cce 100644
--- a/llvm/lib/CodeGen/RegisterPressure.cpp
+++ b/llvm/lib/CodeGen/RegisterPressure.cpp
@@ -79,15 +79,12 @@ static void decreaseSetPressure(std::vector<unsigned> &CurrSetPressure,
 LLVM_DUMP_METHOD
 void llvm::dumpRegSetPressure(ArrayRef<unsigned> SetPressure,
                               const TargetRegisterInfo *TRI) {
-  bool Empty = true;
   for (unsigned i = 0, e = SetPressure.size(); i < e; ++i) {
     if (SetPressure[i] != 0) {
-      dbgs() << TRI->getRegPressureSetName(i) << "=" << SetPressure[i] << '\n';
-      Empty = false;
+      dbgs() << TRI->getRegPressureSetName(i) << "=" << SetPressure[i] << ' ';
     }
   }
-  if (Empty)
-    dbgs() << "\n";
+  dbgs() << "\n";
 }
 
 LLVM_DUMP_METHOD

Copy link

github-actions bot commented Jan 30, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

upstream clang-format prefers this format whereas downstream prefers to
existing.
@arsenm arsenm requested review from kerbowa and jrbyrnes January 31, 2025 13:14
Copy link
Collaborator

@davemgreen davemgreen left a comment

Choose a reason for hiding this comment

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

Looks useful, from looking at the diffs. LGTM.

@c-rhodes c-rhodes merged commit 1cf9092 into llvm:main Feb 5, 2025
8 checks passed
@c-rhodes c-rhodes deleted the msched-debug-improvements branch February 5, 2025 09:14
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
Changes:
1. Fix inconsistencies in register pressure set printing. "Max Pressure"
   printing is inconsistent with "Bottom Pressure" and "Top Pressure".
   For the former, register class begins on the same line vs newline for
   latter. Also for the former, the first register class is on the same
   line, but subsequent register classes are newline separated. That's
   removed so all are on the same line.

   Before:
     Max Pressure: FPR8=1
     GPR32=14
     Top Pressure:
     GPR32=2
     Bottom Pressure:
     FPR8=7
     GPR32=17

   After:
     Max Pressure: FPR8=1 GPR32=14
     Top Pressure: GPR32=2
     Bottom Pressure: FPR8=7 GPR32=17

2. After scheduling an instruction, don't print pressure diff if there
   isn't one. Also s/UpdateRegP/UpdateRegPressure. E.g.,

   Before:
     UpdateRegP: SU(3) %0:gpr64common = ADDXrr %58:gpr64common, gpr64
                 to
     UpdateRegP: SU(4) %393:gpr64sp = ADDXri %58:gpr64common, 390, 12
                 to GPR32 -1

   After:
     UpdateRegPressure: SU(4) %393:gpr64sp = ADDXri %58:gpr64common, 12
                        to GPR32 -1
3. Don't print excess pressure sets if there are none.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants