Remove trailing whitespace to reduce later commit patch noise.
[oota-llvm.git] / lib / CodeGen / LiveVariables.cpp
index 632cd8210ab0295363fb98a1a3072703120cc59b..a7bdbd92ff2dd281b26008c61a1d387289075755 100644 (file)
@@ -52,11 +52,11 @@ void LiveVariables::getAnalysisUsage(AnalysisUsage &AU) const {
 
 void LiveVariables::VarInfo::dump() const {
   cerr << "  Alive in blocks: ";
-  for (unsigned i = 0, e = AliveBlocks.size(); i != e; ++i)
-    if (AliveBlocks[i]) cerr << i << ", ";
+  for (int i = AliveBlocks.find_first(); i != -1; i = AliveBlocks.find_next(i))
+    cerr << i << ", ";
   cerr << "  Used in blocks: ";
-  for (unsigned i = 0, e = UsedBlocks.size(); i != e; ++i)
-    if (UsedBlocks[i]) cerr << i << ", ";
+  for (int i = UsedBlocks.find_first(); i != -1; i = UsedBlocks.find_next(i))
+    cerr << i << ", ";
   cerr << "\n  Killed by:";
   if (Kills.empty())
     cerr << " No instructions.\n";
@@ -335,7 +335,7 @@ bool LiveVariables::hasRegisterUseBelow(unsigned Reg,
   return true;
 }
 
-bool LiveVariables::HandlePhysRegKill(unsigned Reg) {
+bool LiveVariables::HandlePhysRegKill(unsigned Reg, MachineInstr *MI) {
   if (!PhysRegUse[Reg] && !PhysRegDef[Reg])
     return false;
 
@@ -373,8 +373,10 @@ bool LiveVariables::HandlePhysRegKill(unsigned Reg) {
       }
     }
   }
-  if (LastRefOrPartRef == PhysRegDef[Reg])
-    // Not used at all.
+
+  if (LastRefOrPartRef == PhysRegDef[Reg] && LastRefOrPartRef != MI)
+    // If the last reference is the last def, then it's not used at all.
+    // That is, unless we are currently processing the last reference itself.
     LastRefOrPartRef->addRegisterDead(Reg, TRI, true);
 
   /* Partial uses. Mark register def dead and add implicit def of
@@ -427,14 +429,14 @@ void LiveVariables::HandlePhysRegDef(unsigned Reg, MachineInstr *MI) {
 
   // Start from the largest piece, find the last time any part of the register
   // is referenced.
-  if (!HandlePhysRegKill(Reg)) {
+  if (!HandlePhysRegKill(Reg, MI)) {
     // Only some of the sub-registers are used.
     for (const unsigned *SubRegs = TRI->getSubRegisters(Reg);
          unsigned SubReg = *SubRegs; ++SubRegs) {
       if (!Live.count(SubReg))
         // Skip if this sub-register isn't defined.
         continue;
-      if (HandlePhysRegKill(SubReg)) {
+      if (HandlePhysRegKill(SubReg, MI)) {
         Live.erase(SubReg);
         for (const unsigned *SS = TRI->getSubRegisters(SubReg); *SS; ++SS)
           Live.erase(*SS);
@@ -475,7 +477,7 @@ void LiveVariables::HandlePhysRegDef(unsigned Reg, MachineInstr *MI) {
           }
         } else {
           // Otherwise, the super register is killed.
-          if (HandlePhysRegKill(SuperReg)) {
+          if (HandlePhysRegKill(SuperReg, MI)) {
             PhysRegDef[SuperReg]  = NULL;
             PhysRegUse[SuperReg]  = NULL;
             for (const unsigned *SS = TRI->getSubRegisters(SuperReg); *SS; ++SS) {
@@ -558,13 +560,13 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &mf) {
       SmallVector<unsigned, 4> DefRegs;
       for (unsigned i = 0; i != NumOperandsToProcess; ++i) {
         const MachineOperand &MO = MI->getOperand(i);
-        if (MO.isReg() && MO.getReg()) {
-          unsigned MOReg = MO.getReg();
-          if (MO.isUse())
-            UseRegs.push_back(MOReg);
-          if (MO.isDef())
-            DefRegs.push_back(MOReg);
-        }
+        if (!MO.isReg() || MO.getReg() == 0)
+          continue;
+        unsigned MOReg = MO.getReg();
+        if (MO.isUse())
+          UseRegs.push_back(MOReg);
+        if (MO.isDef())
+          DefRegs.push_back(MOReg);
       }
 
       // Process all uses.
@@ -678,6 +680,7 @@ void LiveVariables::removeVirtualRegistersKilled(MachineInstr *MI) {
       if (TargetRegisterInfo::isVirtualRegister(Reg)) {
         bool removed = getVarInfo(Reg).removeKill(MI);
         assert(removed && "kill not in register's VarInfo?");
+        removed = true;
       }
     }
   }