mi-sched: Precompute a PressureDiff for each instruction, adjust for liveness later.

Created SUPressureDiffs array to hold the per node PDiff computed during DAG building.

Added a getUpwardPressureDelta API that will soon replace the old
one. Compute PressureDelta here from the precomputed PressureDiffs.

Updating for liveness will come next.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189640 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/MachineScheduler.cpp b/lib/CodeGen/MachineScheduler.cpp
index 8afc504..ffab5f4 100644
--- a/lib/CodeGen/MachineScheduler.cpp
+++ b/lib/CodeGen/MachineScheduler.cpp
@@ -505,13 +505,13 @@
       DEBUG(dbgs() << TRI->getRegPressureSetName(i)
             << " Limit " << Limit
             << " Actual " << RegionPressure[i] << "\n");
-      RegionCriticalPSets.push_back(PressureElement(i, 0));
+      RegionCriticalPSets.push_back(PressureChange(i));
     }
   }
   DEBUG(dbgs() << "Excess PSets: ";
         for (unsigned i = 0, e = RegionCriticalPSets.size(); i != e; ++i)
           dbgs() << TRI->getRegPressureSetName(
-            RegionCriticalPSets[i].PSetID) << " ";
+            RegionCriticalPSets[i].getPSet()) << " ";
         dbgs() << "\n");
 }
 
@@ -520,10 +520,10 @@
 void ScheduleDAGMI::
 updateScheduledPressure(const std::vector<unsigned> &NewMaxPressure) {
   for (unsigned i = 0, e = RegionCriticalPSets.size(); i < e; ++i) {
-    unsigned ID = RegionCriticalPSets[i].PSetID;
-    int &MaxUnits = RegionCriticalPSets[i].UnitIncrease;
-    if ((int)NewMaxPressure[ID] > MaxUnits)
-      MaxUnits = NewMaxPressure[ID];
+    unsigned ID = RegionCriticalPSets[i].getPSet();
+    if ((int)NewMaxPressure[ID] > RegionCriticalPSets[i].getUnitInc()
+        && NewMaxPressure[ID] <= INT16_MAX)
+      RegionCriticalPSets[i].setUnitInc(NewMaxPressure[ID]);
   }
   DEBUG(
     for (unsigned i = 0, e = NewMaxPressure.size(); i < e; ++i) {
@@ -599,7 +599,7 @@
     RPTracker.recede();
 
   // Build the DAG, and compute current register pressure.
-  buildSchedGraph(AA, &RPTracker);
+  buildSchedGraph(AA, &RPTracker, &SUPressureDiffs);
 
   // Initialize top/bottom trackers after computing region pressure.
   initRegPressure();
@@ -2177,26 +2177,28 @@
   return false;
 }
 
-static bool tryPressure(const PressureElement &TryP,
-                        const PressureElement &CandP,
+static bool tryPressure(const PressureChange &TryP,
+                        const PressureChange &CandP,
                         ConvergingScheduler::SchedCandidate &TryCand,
                         ConvergingScheduler::SchedCandidate &Cand,
                         ConvergingScheduler::CandReason Reason) {
-  // If both candidates affect the same set, go with the smallest increase.
-  if (TryP.PSetID == CandP.PSetID) {
-    return tryLess(TryP.UnitIncrease, CandP.UnitIncrease, TryCand, Cand,
-                   Reason);
-  }
-  // If one candidate decreases and the other increases, go with it.
-  if (tryLess(TryP.UnitIncrease < 0, CandP.UnitIncrease < 0, TryCand, Cand,
-              Reason)) {
-    return true;
+  if (TryP.isValid() && CandP.isValid()) {
+    // If both candidates affect the same set, go with the smallest increase.
+    if (TryP.getPSet() == CandP.getPSet()) {
+      return tryLess(TryP.getUnitInc(), CandP.getUnitInc(), TryCand, Cand,
+                     Reason);
+    }
+    // If one candidate decreases and the other increases, go with it.
+    if (tryLess(TryP.getUnitInc() < 0, CandP.getUnitInc() < 0, TryCand, Cand,
+                Reason)) {
+      return true;
+    }
   }
   // If TryP has lower Rank, it has a higher priority.
-  int TryRank = TryP.PSetRank();
-  int CandRank = CandP.PSetRank();
+  int TryRank = TryP.getRank();
+  int CandRank = CandP.getRank();
   // If the candidates are decreasing pressure, reverse priority.
-  if (TryP.UnitIncrease < 0)
+  if (TryP.getUnitInc() < 0)
     std::swap(TryRank, CandRank);
   return tryGreater(TryRank, CandRank, TryCand, Cand, Reason);
 }
@@ -2277,9 +2279,31 @@
                                        RegPressureTracker &TempTracker) {
 
   // Always initialize TryCand's RPDelta.
-  TempTracker.getMaxPressureDelta(TryCand.SU->getInstr(), TryCand.RPDelta,
-                                  DAG->getRegionCriticalPSets(),
-                                  DAG->getRegPressure().MaxSetPressure);
+  if (Zone.isTop()) {
+    TempTracker.getMaxDownwardPressureDelta(
+      TryCand.SU->getInstr(),
+      TryCand.RPDelta,
+      DAG->getRegionCriticalPSets(),
+      DAG->getRegPressure().MaxSetPressure);
+  }
+  else {
+    if (VerifyScheduling) {
+      TempTracker.getMaxUpwardPressureDelta(
+        TryCand.SU->getInstr(),
+        &DAG->getPressureDiff(TryCand.SU),
+        TryCand.RPDelta,
+        DAG->getRegionCriticalPSets(),
+        DAG->getRegPressure().MaxSetPressure);
+    }
+    else {
+      RPTracker.getUpwardPressureDelta(
+        TryCand.SU->getInstr(),
+        DAG->getPressureDiff(TryCand.SU),
+        TryCand.RPDelta,
+        DAG->getRegionCriticalPSets(),
+        DAG->getRegPressure().MaxSetPressure);
+    }
+  }
 
   // Initialize the candidate if needed.
   if (!Cand.isValid()) {
@@ -2385,7 +2409,7 @@
 }
 
 void ConvergingScheduler::traceCandidate(const SchedCandidate &Cand) {
-  PressureElement P;
+  PressureChange P;
   unsigned ResIdx = 0;
   unsigned Latency = 0;
   switch (Cand.Reason) {
@@ -2421,8 +2445,8 @@
   }
   dbgs() << "  SU(" << Cand.SU->NodeNum << ") " << getReasonStr(Cand.Reason);
   if (P.isValid())
-    dbgs() << " " << TRI->getRegPressureSetName(P.PSetID)
-           << ":" << P.UnitIncrease << " ";
+    dbgs() << " " << TRI->getRegPressureSetName(P.getPSet())
+           << ":" << P.getUnitInc() << " ";
   else
     dbgs() << "      ";
   if (ResIdx)