RegisterPressure: Remove 0 entries from PressureChange
authorMatthias Braun <matze@braunis.de>
Sat, 17 Oct 2015 00:35:59 +0000 (00:35 +0000)
committerMatthias Braun <matze@braunis.de>
Sat, 17 Oct 2015 00:35:59 +0000 (00:35 +0000)
This should not change behaviour because as far as I can see all code
reading the pressure changes has no effect if the PressureInc is 0.
Removing these entries however does avoid unnecessary computation, and
results in a more stable debug output. I want the stable debug output to
check that some upcoming changes are indeed NFC and identical even at
the debug output level.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250595 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/RegisterPressure.cpp

index 88566d88732abfa7d97eb08cbb79a35fae4cffff..2ebca20e59949c2fc98425d5dbd045b5b879af2f 100644 (file)
@@ -79,8 +79,8 @@ void RegPressureTracker::dump() const {
 
 void PressureDiff::dump(const TargetRegisterInfo &TRI) const {
   for (const PressureChange &Change : *this) {
-    if (!Change.isValid() || Change.getUnitInc() == 0)
-      continue;
+    if (!Change.isValid())
+      break;
     dbgs() << "    " << TRI.getRegPressureSetName(Change.getPSet())
            << " " << Change.getUnitInc();
   }
@@ -401,10 +401,20 @@ void PressureDiff::addPressureChange(unsigned RegUnit, bool IsDec,
     if (!I->isValid() || I->getPSet() != *PSetI) {
       PressureChange PTmp = PressureChange(*PSetI);
       for (PressureDiff::iterator J = I; J != E && PTmp.isValid(); ++J)
-        std::swap(*J,PTmp);
+        std::swap(*J, PTmp);
     }
     // Update the units for this pressure set.
-    I->setUnitInc(I->getUnitInc() + Weight);
+    unsigned NewUnitInc = I->getUnitInc() + Weight;
+    if (NewUnitInc != 0) {
+      I->setUnitInc(NewUnitInc);
+    } else {
+      // Remove entry
+      PressureDiff::iterator J;
+      for (J = std::next(I); J != E && J->isValid(); ++J, ++I)
+        *I = *J;
+      if (J != E)
+        *I = *J;
+    }
   }
 }