Keep track of the number of positively biased nodes when adding constraints.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Wed, 6 Apr 2011 19:14:00 +0000 (19:14 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Wed, 6 Apr 2011 19:14:00 +0000 (19:14 +0000)
If there are no positive nodes, the algorithm can be aborted early.

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

lib/CodeGen/RegAllocGreedy.cpp
lib/CodeGen/SpillPlacement.cpp
lib/CodeGen/SpillPlacement.h

index 4e8891f66f300a1646f9b28a3809b8e3bb21d358..31729ec441e060384682779b8d6278bbd3f64294 100644 (file)
@@ -772,6 +772,7 @@ unsigned RAGreedy::tryRegionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
 
     SpillPlacer->prepare(LiveBundles);
     SpillPlacer->addConstraints(SplitConstraints);
+    DEBUG(dbgs() << ", " << SpillPlacer->getPositiveNodes() << " biased nodes");
     SpillPlacer->finish();
 
     // No live bundles, defer to splitSingleBlocks().
index d648d5a9e15393d45627e8fea68eb5142c0f63ad..0ccb93f871dcdd3d9b195886fd672c2bb5bd4087 100644 (file)
@@ -134,10 +134,14 @@ struct SpillPlacement::Node {
   }
 
   /// addBias - Bias this node from an ingoing[0] or outgoing[1] link.
-  void addBias(float w, bool out) {
+  /// Return the change to the total number of positive biases.
+  int addBias(float w, bool out) {
     // Normalize w relative to all connected blocks from that direction.
     w /= Frequency[out];
+    int Before = Bias > 0;
     Bias += w;
+    int After = Bias > 0;
+    return After - Before;
   }
 
   /// update - Recompute Value from Bias and Links. Return true when node
@@ -237,14 +241,14 @@ void SpillPlacement::addConstraints(ArrayRef<BlockConstraint> LiveBlocks) {
     if (I->Entry != DontCare) {
       unsigned ib = bundles->getBundle(I->Number, 0);
       activate(ib);
-      nodes[ib].addBias(Freq * Bias[I->Entry], 1);
+      PositiveNodes += nodes[ib].addBias(Freq * Bias[I->Entry], 1);
     }
 
     // Live-out from block?
     if (I->Exit != DontCare) {
       unsigned ob = bundles->getBundle(I->Number, 1);
       activate(ob);
-      nodes[ob].addBias(Freq * Bias[I->Exit], 0);
+      PositiveNodes += nodes[ob].addBias(Freq * Bias[I->Exit], 0);
     }
   }
 }
@@ -292,6 +296,7 @@ void SpillPlacement::prepare(BitVector &RegBundles) {
   ActiveNodes = &RegBundles;
   ActiveNodes->clear();
   ActiveNodes->resize(bundles->getNumBundles());
+  PositiveNodes = 0;
 }
 
 bool
index d1c6ceb78575ec39c6ac3c5134c957165a00ccfc..a67785ddf9b0e20c5044af0179d7117956cfcab4 100644 (file)
@@ -49,6 +49,9 @@ class SpillPlacement  : public MachineFunctionPass {
   // caller.
   BitVector *ActiveNodes;
 
+  // The number of active nodes with a positive bias.
+  unsigned PositiveNodes;
+
   // Block frequencies are computed once. Indexed by block number.
   SmallVector<float, 4> BlockFrequency;
 
@@ -91,6 +94,10 @@ public:
   ///                   out, but not live in.
   void addConstraints(ArrayRef<BlockConstraint> LiveBlocks);
 
+  /// getPositiveNodes - Return the total number of graph nodes with a positive
+  /// bias after adding constraints.
+  unsigned getPositiveNodes() const { return PositiveNodes; }
+
   /// finish - Compute the optimal spill code placement given the
   /// constraints. No MustSpill constraints will be violated, and the smallest
   /// possible number of PrefX constraints will be violated, weighted by