Split saveCallerSavedRegisters into two methods for clarity, and add comments.
[oota-llvm.git] / lib / CodeGen / LiveVariables.cpp
index cc924c3cc4474cf79e4966c4fdb11de62b65f49a..0bdf86406f104cab9b127fed994f2017a148bb2e 100644 (file)
@@ -59,12 +59,12 @@ void LiveVariables::MarkVirtRegAliveInBlock(VarInfo &VRInfo,
   // Check to see if this basic block is one of the killing blocks.  If so,
   // remove it...
   for (unsigned i = 0, e = VRInfo.Kills.size(); i != e; ++i)
-    if (VRInfo.Kills[i].first == MBB) {
+    if (VRInfo.Kills[i]->getParent() == MBB) {
       VRInfo.Kills.erase(VRInfo.Kills.begin()+i);  // Erase entry
       break;
     }
 
-  if (MBB == VRInfo.DefBlock) return;  // Terminate recursion
+  if (MBB == VRInfo.DefInst->getParent()) return;  // Terminate recursion
 
   if (VRInfo.AliveBlocks.size() <= BBNum)
     VRInfo.AliveBlocks.resize(BBNum+1);  // Make space...
@@ -83,22 +83,23 @@ void LiveVariables::MarkVirtRegAliveInBlock(VarInfo &VRInfo,
 void LiveVariables::HandleVirtRegUse(VarInfo &VRInfo, MachineBasicBlock *MBB,
                                      MachineInstr *MI) {
   // Check to see if this basic block is already a kill block...
-  if (!VRInfo.Kills.empty() && VRInfo.Kills.back().first == MBB) {
+  if (!VRInfo.Kills.empty() && VRInfo.Kills.back()->getParent() == MBB) {
     // Yes, this register is killed in this basic block already.  Increase the
     // live range by updating the kill instruction.
-    VRInfo.Kills.back().second = MI;
+    VRInfo.Kills.back() = MI;
     return;
   }
 
 #ifndef NDEBUG
   for (unsigned i = 0, e = VRInfo.Kills.size(); i != e; ++i)
-    assert(VRInfo.Kills[i].first != MBB && "entry should be at end!");
+    assert(VRInfo.Kills[i]->getParent() != MBB && "entry should be at end!");
 #endif
 
-  assert(MBB != VRInfo.DefBlock && "Should have kill for defblock!");
+  assert(MBB != VRInfo.DefInst->getParent() && 
+         "Should have kill for defblock!");
 
   // Add a new kill entry for this basic block.
-  VRInfo.Kills.push_back(std::make_pair(MBB, MI));
+  VRInfo.Kills.push_back(MI);
 
   // Update all dominating blocks to mark them known live.
   const BasicBlock *BB = MBB->getBasicBlock();
@@ -230,10 +231,10 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &MF) {
           if (MRegisterInfo::isVirtualRegister(MO.getReg())) {
             VarInfo &VRInfo = getVarInfo(MO.getReg());
 
-            assert(VRInfo.DefBlock == 0 && "Variable multiply defined!");
-            VRInfo.DefBlock = MBB;                           // Created here...
+            assert(VRInfo.DefInst == 0 && "Variable multiply defined!");
             VRInfo.DefInst = MI;
-            VRInfo.Kills.push_back(std::make_pair(MBB, MI)); // Defaults to dead
+            // Defaults to dead
+            VRInfo.Kills.push_back(MI);
           } else if (MRegisterInfo::isPhysicalRegister(MO.getReg()) &&
                      AllocatablePhysicalRegisters[MO.getReg()]) {
             HandlePhysRegDef(MO.getReg(), MI);
@@ -282,15 +283,23 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &MF) {
   //
   for (unsigned i = 0, e = VirtRegInfo.size(); i != e; ++i)
     for (unsigned j = 0, e = VirtRegInfo[i].Kills.size(); j != e; ++j) {
-      if (VirtRegInfo[i].Kills[j].second == VirtRegInfo[i].DefInst)
-        RegistersDead.insert(std::make_pair(VirtRegInfo[i].Kills[j].second,
+      if (VirtRegInfo[i].Kills[j] == VirtRegInfo[i].DefInst)
+        RegistersDead.insert(std::make_pair(VirtRegInfo[i].Kills[j],
                              i + MRegisterInfo::FirstVirtualRegister));
 
       else
-        RegistersKilled.insert(std::make_pair(VirtRegInfo[i].Kills[j].second,
+        RegistersKilled.insert(std::make_pair(VirtRegInfo[i].Kills[j],
                                i + MRegisterInfo::FirstVirtualRegister));
     }
 
+  // Check to make sure there are no unreachable blocks in the MC CFG for the
+  // function.  If so, it is due to a bug in the instruction selector or some
+  // other part of the code generator if this happens.
+#ifndef NDEBUG
+  for(MachineFunction::iterator i = MF.begin(), e = MF.end(); i != e; ++i) 
+    assert(Visited.count(&*i) != 0 && "unreachable basic block found");
+#endif
+
   return false;
 }