Make LiveIntervals::handleMove() bundle aware.
[oota-llvm.git] / lib / CodeGen / LiveIntervalAnalysis.cpp
index 0e64ec9011887ade789d3fd6acce533362fb7cb5..0bf47322ba10d2e392317d0120d74d31279a659f 100644 (file)
@@ -107,10 +107,21 @@ bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) {
 /// print - Implement the dump method.
 void LiveIntervals::print(raw_ostream &OS, const Module* ) const {
   OS << "********** INTERVALS **********\n";
-  for (const_iterator I = begin(), E = end(); I != E; ++I) {
-    I->second->print(OS, tri_);
-    OS << "\n";
-  }
+
+  // Dump the physregs.
+  for (unsigned Reg = 1, RegE = tri_->getNumRegs(); Reg != RegE; ++Reg)
+    if (const LiveInterval *LI = r2iMap_.lookup(Reg)) {
+      LI->print(OS, tri_);
+      OS << '\n';
+    }
+
+  // Dump the virtregs.
+  for (unsigned Reg = 0, RegE = mri_->getNumVirtRegs(); Reg != RegE; ++Reg)
+    if (const LiveInterval *LI =
+        r2iMap_.lookup(TargetRegisterInfo::index2VirtReg(Reg))) {
+      LI->print(OS, tri_);
+      OS << '\n';
+    }
 
   printInstrs(OS);
 }
@@ -424,7 +435,6 @@ void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock *MBB,
 
   // FIXME: We need saner rules for reserved regs.
   if (isReserved(interval.reg)) {
-    assert(!isRegLiveOutOf(MBB, interval.reg) && "Reserved reg live-out?");
     end = start.getDeadSlot();
   } else {
     // Unreserved, unallocable registers like EFLAGS can be live across basic
@@ -496,7 +506,7 @@ void LiveIntervals::handleLiveInRegister(MachineBasicBlock *MBB,
       end = baseIndex.getRegSlot();
       SeenDefUse = true;
       break;
-    } else if (mi->definesRegister(interval.reg, tri_)) {
+    } else if (mi->modifiesRegister(interval.reg, tri_)) {
       // Another instruction redefines the register before it is ever read.
       // Then the register is essentially dead at the instruction that defines
       // it. Hence its interval is:
@@ -518,9 +528,10 @@ void LiveIntervals::handleLiveInRegister(MachineBasicBlock *MBB,
   if (!SeenDefUse) {
     if (isAllocatable(interval.reg) || isReserved(interval.reg)) {
       // This must be an entry block or landing pad - we asserted so on entry
-      // to the function. For these blocks the interval is dead on entry.
+      // to the function. For these blocks the interval is dead on entry, so
+      // we won't emit a live-range for it.
       DEBUG(dbgs() << " dead");
-      end = start.getDeadSlot();
+      return;
     } else {
       assert(isRegLiveOutOf(MBB, interval.reg) &&
              "Live in reg untouched in block should be be live through.");
@@ -952,21 +963,18 @@ static void handleMoveUses(const MachineBasicBlock *mbb,
   }
 }
 
-void LiveIntervals::moveInstr(MachineBasicBlock::iterator insertPt,
-                              MachineInstr *mi) {
-  MachineBasicBlock* mbb = mi->getParent();
-  assert((insertPt == mbb->end() || insertPt->getParent() == mbb) &&
-         "Cannot handle moves across basic block boundaries.");
-  assert(&*insertPt != mi && "No-op move requested?");
-  assert(!mi->isBundled() && "Can't handle bundled instructions yet.");
 
-  // Grab the original instruction index.
-  SlotIndex origIdx = indexes_->getInstructionIndex(mi);
 
-  // Move the machine instr and obtain its new index.
+void LiveIntervals::handleMove(MachineInstr* mi) {
+  SlotIndex origIdx = indexes_->getInstructionIndex(mi);
   indexes_->removeMachineInstrFromMaps(mi);
-  mbb->splice(insertPt, mbb, mi);
-  SlotIndex miIdx = indexes_->insertMachineInstrInMaps(mi);
+  SlotIndex miIdx = mi->isInsideBundle() ?
+                     indexes_->getInstructionIndex(mi->getBundleStart()) :
+                     indexes_->insertMachineInstrInMaps(mi);
+  MachineBasicBlock* mbb = mi->getParent();
+  assert(getMBBStartIdx(mbb) <= origIdx && origIdx < getMBBEndIdx(mbb) &&
+         "Cannot handle moves across basic block boundaries.");
+  assert(!mi->isBundled() && "Can't handle bundled instructions yet.");
 
   // Pick the direction.
   bool movingUp = miIdx < origIdx;