Move RABasic::addMBBLiveIns to the base class, it is generally useful.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Wed, 8 Dec 2010 01:06:06 +0000 (01:06 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Wed, 8 Dec 2010 01:06:06 +0000 (01:06 +0000)
Minor optimization to the use of IntervalMap iterators. They are fairly
heavyweight, so prefer SI.valid() over SI != end().

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

lib/CodeGen/LiveIntervalUnion.h
lib/CodeGen/RegAllocBase.h
lib/CodeGen/RegAllocBasic.cpp

index 2068149ca0ca6881a06a0f265e56367a5af8602b..0c9a13a606c7f1c7d7304ee47f5a6c9a87369bce 100644 (file)
@@ -75,6 +75,7 @@ public:
   // by their starting position.
   SegmentIter begin() { return Segments.begin(); }
   SegmentIter end() { return Segments.end(); }
+  bool empty() { return Segments.empty(); }
 
   // Add a live virtual register to this union and merge its segments.
   void unify(LiveInterval &VirtReg);
index 32f5e0870ed90632eac0cfa96733402a5884b9d8..7f38c9b95a974ff6b744941aa2b18d3458ae8889 100644 (file)
@@ -149,6 +149,9 @@ protected:
   bool spillInterferences(LiveInterval &VirtReg, unsigned PhysReg,
                           SmallVectorImpl<LiveInterval*> &SplitVRegs);
 
+  /// addMBBLiveIns - Add physreg liveins to basic blocks.
+  void addMBBLiveIns(MachineFunction *);
+
 #ifndef NDEBUG
   // Verify each LiveIntervalUnion.
   void verify();
index f8eafe4200950878fd94fdf847225958d61a51e4..d0e635512902cfc8a9c738ed03653bbd847b1e04 100644 (file)
@@ -110,9 +110,6 @@ public:
   virtual bool runOnMachineFunction(MachineFunction &mf);
 
   static char ID;
-
-private:
-  void addMBBLiveIns();
 };
 
 char RABasic::ID = 0;
@@ -395,6 +392,36 @@ RegAllocBase::spillInterferences(LiveInterval &VirtReg, unsigned PhysReg,
   return true;
 }
 
+// Add newly allocated physical registers to the MBB live in sets.
+void RegAllocBase::addMBBLiveIns(MachineFunction *MF) {
+  typedef SmallVector<MachineBasicBlock*, 8> MBBVec;
+  MBBVec liveInMBBs;
+  MachineBasicBlock &entryMBB = *MF->begin();
+
+  for (unsigned PhysReg = 0; PhysReg < PhysReg2LiveUnion.numRegs(); ++PhysReg) {
+    LiveIntervalUnion &LiveUnion = PhysReg2LiveUnion[PhysReg];
+    if (LiveUnion.empty())
+      continue;
+    for (LiveIntervalUnion::SegmentIter SI = LiveUnion.begin(); SI.valid();
+         ++SI) {
+
+      // Find the set of basic blocks which this range is live into...
+      liveInMBBs.clear();
+      if (!LIS->findLiveInMBBs(SI.start(), SI.stop(), liveInMBBs)) continue;
+
+      // And add the physreg for this interval to their live-in sets.
+      for (MBBVec::iterator I = liveInMBBs.begin(), E = liveInMBBs.end();
+           I != E; ++I) {
+        MachineBasicBlock *MBB = *I;
+        if (MBB == &entryMBB) continue;
+        if (MBB->isLiveIn(PhysReg)) continue;
+        MBB->addLiveIn(PhysReg);
+      }
+    }
+  }
+}
+
+
 //===----------------------------------------------------------------------===//
 //                         RABasic Implementation
 //===----------------------------------------------------------------------===//
@@ -467,35 +494,6 @@ unsigned RABasic::selectOrSplit(LiveInterval &VirtReg,
   return 0;
 }
 
-// Add newly allocated physical registers to the MBB live in sets.
-void RABasic::addMBBLiveIns() {
-  typedef SmallVector<MachineBasicBlock*, 8> MBBVec;
-  MBBVec liveInMBBs;
-  MachineBasicBlock &entryMBB = *MF->begin();
-
-  for (unsigned PhysReg = 0; PhysReg < PhysReg2LiveUnion.numRegs(); ++PhysReg) {
-    LiveIntervalUnion &LiveUnion = PhysReg2LiveUnion[PhysReg];
-
-    for (LiveIntervalUnion::SegmentIter SI = LiveUnion.begin(),
-           SegEnd = LiveUnion.end();
-         SI != SegEnd; ++SI) {
-
-      // Find the set of basic blocks which this range is live into...
-      liveInMBBs.clear();
-      if (!LIS->findLiveInMBBs(SI.start(), SI.stop(), liveInMBBs)) continue;
-
-      // And add the physreg for this interval to their live-in sets.
-      for (MBBVec::iterator I = liveInMBBs.begin(), E = liveInMBBs.end();
-           I != E; ++I) {
-        MachineBasicBlock *MBB = *I;
-        if (MBB == &entryMBB) continue;
-        if (MBB->isLiveIn(PhysReg)) continue;
-        MBB->addLiveIn(PhysReg);
-      }
-    }
-  }
-}
-
 bool RABasic::runOnMachineFunction(MachineFunction &mf) {
   DEBUG(dbgs() << "********** BASIC REGISTER ALLOCATION **********\n"
                << "********** Function: "
@@ -517,7 +515,7 @@ bool RABasic::runOnMachineFunction(MachineFunction &mf) {
 
   allocatePhysRegs();
 
-  addMBBLiveIns();
+  addMBBLiveIns(MF);
 
   // Diagnostic output before rewriting
   DEBUG(dbgs() << "Post alloc VirtRegMap:\n" << *VRM << "\n");