More templatization.
[oota-llvm.git] / lib / CodeGen / LiveVariables.cpp
index 57396b7416815ce4fa0a94130a8696ee36a2826e..2af8bf316e15aa4d48dbfa814dc3adcfa457e911 100644 (file)
@@ -50,6 +50,9 @@ void LiveVariables::VarInfo::dump() const {
   cerr << "  Alive in blocks: ";
   for (unsigned i = 0, e = AliveBlocks.size(); i != e; ++i)
     if (AliveBlocks[i]) cerr << i << ", ";
+  cerr << "  Used in blocks: ";
+  for (unsigned i = 0, e = UsedBlocks.size(); i != e; ++i)
+    if (UsedBlocks[i]) cerr << i << ", ";
   cerr << "\n  Killed by:";
   if (Kills.empty())
     cerr << " No instructions.\n";
@@ -72,6 +75,7 @@ LiveVariables::VarInfo &LiveVariables::getVarInfo(unsigned RegIdx) {
   }
   VarInfo &VI = VirtRegInfo[RegIdx];
   VI.AliveBlocks.resize(MF->getNumBlockIDs());
+  VI.UsedBlocks.resize(MF->getNumBlockIDs());
   return VI;
 }
 
@@ -154,6 +158,9 @@ void LiveVariables::HandleVirtRegUse(VarInfo &VRInfo, MachineBasicBlock *MBB,
                                      MachineInstr *MI) {
   assert(VRInfo.DefInst && "Register use before def!");
 
+  unsigned BBNum = MBB->getNumber();
+
+  VRInfo.UsedBlocks[BBNum] = true;
   VRInfo.NumUses++;
 
   // Check to see if this basic block is already a kill block...
@@ -176,7 +183,7 @@ void LiveVariables::HandleVirtRegUse(VarInfo &VRInfo, MachineBasicBlock *MBB,
   // If this virtual register is already marked as alive in this basic block,
   // that means it is alive in at least one of the successor block, it's not
   // a kill.
-  if (!VRInfo.AliveBlocks[MBB->getNumber()])
+  if (!VRInfo.AliveBlocks[BBNum])
     VRInfo.Kills.push_back(MI);
 
   // Update all dominating blocks to mark them known live.
@@ -203,7 +210,7 @@ bool LiveVariables::addRegisterKilled(unsigned IncomingReg, MachineInstr *MI,
                  RegInfo->isSuperRegister(IncomingReg, Reg) &&
                  MO.isKill())
         // A super-register kill already exists.
-        return true;
+        Found = true;
     }
   }
 
@@ -357,7 +364,9 @@ void LiveVariables::HandlePhysRegDef(unsigned Reg, MachineInstr *MI) {
     } else if (PhysRegPartUse[Reg])
       // Add implicit use / kill to last partial use.
       addRegisterKilled(Reg, PhysRegPartUse[Reg], true);
-    else
+    else if (LastRef != MI)
+      // Defined, but not used. However, watch out for cases where a super-reg
+      // is also defined on the same MI.
       addRegisterDead(Reg, LastRef);
   }