Factor local liveness computation out into its own function.
[oota-llvm.git] / lib / CodeGen / TwoAddressInstructionPass.cpp
index f6e2f55b3060c609247c0b89bf43c1649056691e..08f576c956fc84ca8bf5c6d9686085787c8c4fa9 100644 (file)
@@ -184,11 +184,8 @@ bool TwoAddressInstructionPass::Sink3AddrInstruction(MachineBasicBlock *MBB,
   KillMO = MI->findRegisterUseOperand(SavedReg, false, TRI);
   KillMO->setIsKill(true);
   
-  if (LV) {
-    LiveVariables::VarInfo& VarInfo = LV->getVarInfo(SavedReg);
-    VarInfo.removeKill(KillMI);
-    VarInfo.Kills.push_back(MI);
-  }
+  if (LV)
+    LV->replaceKillInstruction(SavedReg, KillMI, MI);
 
   // Move instruction to its destination.
   MBB->remove(MI);
@@ -375,31 +372,9 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
                   DOUT << "2addr: COMMUTED TO: " << *NewMI;
                   // If the instruction changed to commute it, update livevar.
                   if (NewMI != mi) {
-                    if (LV) {
+                    if (LV)
                       // Update live variables
-                      LV->instructionChanged(mi, NewMI); 
-                    } else {
-                      // Update flags manually
-                      for (unsigned i = 0, e = mi->getNumOperands();
-                           i != e; ++i) {
-                        MachineOperand &MO = mi->getOperand(i);
-                        if (MO.isRegister() && MO.getReg() &&
-                          TargetRegisterInfo::isVirtualRegister(MO.getReg())) {
-                          unsigned Reg = MO.getReg();
-                          if (MO.isDef()) {
-                            if (MO.isDead()) {
-                              MO.setIsDead(false);
-                              NewMI->addRegisterDead(Reg, TRI);
-                            }
-                          }
-                          
-                          if (MO.isKill()) {
-                            MO.setIsKill(false);
-                            NewMI->addRegisterKilled(Reg, TRI);
-                          }
-                        }
-                      }
-                    }
+                      LV->replaceKillInstruction(regC, mi, NewMI);
                     
                     mbbi->insert(mi, NewMI);           // Insert the new inst
                     mbbi->erase(mi);                   // Nuke the old inst.
@@ -424,7 +399,7 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
                 assert(TID.getOperandConstraint(i, TOI::TIED_TO) == -1);
 #endif
 
-              MachineInstr *NewMI = TII->convertToThreeAddress(mbbi, mi, *LV);
+              MachineInstr *NewMI = TII->convertToThreeAddress(mbbi, mi, LV);
               if (NewMI) {
                 DOUT << "2addr: CONVERTING 2-ADDR: " << *mi;
                 DOUT << "2addr:         TO 3-ADDR: " << *NewMI;
@@ -476,35 +451,11 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
             // regB is used in this BB.
             varInfoB.UsedBlocks[mbbi->getNumber()] = true;
 
-            if (LV->removeVirtualRegisterKilled(regB, mbbi, mi))
+            if (LV->removeVirtualRegisterKilled(regB,  mi))
               LV->addVirtualRegisterKilled(regB, prevMi);
 
-            if (LV->removeVirtualRegisterDead(regB, mbbi, mi))
+            if (LV->removeVirtualRegisterDead(regB, mi))
               LV->addVirtualRegisterDead(regB, prevMi);
-          } else {
-            // Manually update kill/dead flags.
-            bool RemovedKill = false;
-            bool RemovedDead = false;
-            for (unsigned i = 0, e = mi->getNumOperands(); i != e; ++i) {
-              MachineOperand &MO = mi->getOperand(i);
-              if (MO.isRegister() && MO.isKill() && MO.getReg() == regB) {
-                MO.setIsKill(false);
-                RemovedKill = true;
-                break;
-              } 
-              
-              if (MO.isRegister() && MO.isDef() && MO.getReg() == regB) {
-                MO.setIsDead(false);
-                RemovedDead = true;
-              }
-              
-              if (RemovedKill && RemovedDead) break;
-            }
-            
-            if (RemovedKill)
-              prevMi->addRegisterKilled(regB, TRI);
-            if (RemovedDead)
-              prevMi->addRegisterDead(regB, TRI);
           }
           
           // Replace all occurences of regB with regA.