Add a utility function for conservatively clearing kill flags, and make
authorDan Gohman <gohman@apple.com>
Thu, 13 May 2010 19:24:00 +0000 (19:24 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 13 May 2010 19:24:00 +0000 (19:24 +0000)
use of it in MachineCSE.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103726 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineRegisterInfo.h
lib/CodeGen/MachineCSE.cpp
lib/CodeGen/MachineRegisterInfo.cpp

index 905be96c35ab94904f5f0eebcc5b3a7c51566964..131231e5ba0c4ba02fabb00a7c49bbb49af49c4c 100644 (file)
@@ -162,6 +162,12 @@ public:
   /// register or null if none is found.  This assumes that the code is in SSA
   /// form, so there should only be one definition.
   MachineInstr *getVRegDef(unsigned Reg) const;
+
+  /// clearKillFlags - Iterate over all the uses of the given register and
+  /// clear the kill flag from the MachineOperand. This function is used by
+  /// optimization passes which extend register lifetimes and need only
+  /// preserve conservative kill flag information.
+  void clearKillFlags(unsigned Reg) const;
   
 #ifndef NDEBUG
   void dumpUses(unsigned RegNo) const;
index 84c3d717f7f9a0456c7386a01e33b0b105377915..cfe50408e6e316ebff326e278f04521de3724f1e 100644 (file)
@@ -112,6 +112,7 @@ bool MachineCSE::PerformTrivialCoalescing(MachineInstr *MI,
       DEBUG(dbgs() << "Coalescing: " << *DefMI);
       DEBUG(dbgs() << "*** to: " << *MI);
       MO.setReg(SrcReg);
+      MRI->clearKillFlags(SrcReg);
       if (NewRC != SRC)
         MRI->setRegClass(SrcReg, NewRC);
       DefMI->eraseFromParent();
@@ -365,8 +366,10 @@ bool MachineCSE::ProcessBlock(MachineBasicBlock *MBB) {
 
     // Actually perform the elimination.
     if (DoCSE) {
-      for (unsigned i = 0, e = CSEPairs.size(); i != e; ++i)
+      for (unsigned i = 0, e = CSEPairs.size(); i != e; ++i) {
         MRI->replaceRegWith(CSEPairs[i].first, CSEPairs[i].second);
+        MRI->clearKillFlags(CSEPairs[i].second);
+      }
       MI->eraseFromParent();
       ++NumCSEs;
     } else {
index 5465fca05f7b81c88420c6535f280cab636ebe31..402be479eac305be81caeca43a6f921d4d7ec5c2 100644 (file)
@@ -133,6 +133,15 @@ bool MachineRegisterInfo::hasOneNonDBGUse(unsigned RegNo) const {
   return ++UI == use_nodbg_end();
 }
 
+/// clearKillFlags - Iterate over all the uses of the given register and
+/// clear the kill flag from the MachineOperand. This function is used by
+/// optimization passes which extend register lifetimes and need only
+/// preserve conservative kill flag information.
+void MachineRegisterInfo::clearKillFlags(unsigned Reg) const {
+  for (use_iterator UI = use_begin(Reg), UE = use_end(); UI != UE; ++UI)
+    UI.getOperand().setIsKill(false);
+}
+
 bool MachineRegisterInfo::isLiveIn(unsigned Reg) const {
   for (livein_iterator I = livein_begin(), E = livein_end(); I != E; ++I)
     if (I->first == Reg || I->second == Reg)