Add LiveIntervals::addKillFlags() to recompute kill flags after register allocation.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Tue, 8 Feb 2011 21:13:03 +0000 (21:13 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Tue, 8 Feb 2011 21:13:03 +0000 (21:13 +0000)
This is a lot easier than trying to get kill flags right during live range
splitting and rematerialization.

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

include/llvm/CodeGen/LiveIntervalAnalysis.h
lib/CodeGen/LiveIntervalAnalysis.cpp
lib/CodeGen/RegAllocGreedy.cpp

index 8299f01edef406d30c47b4c9aa77489c3542fb34..daa4b792f7ecb9a1dd563575fcb4eaa59dd31db8 100644 (file)
@@ -320,6 +320,10 @@ namespace llvm {
     MachineBasicBlock::iterator getLastSplitPoint(const LiveInterval &li,
                                                   MachineBasicBlock *mbb);
 
+    /// addKillFlags - Add kill flags to any instruction that kills a virtual
+    /// register.
+    void addKillFlags();
+
   private:
     /// computeIntervals - Compute live intervals.
     void computeIntervals();
index 4ff888a7fd046d8823fc24dd2bcf36e5d2a5ff24..3739d28bfdce42b9d9060c50530d20452e4c4d69 100644 (file)
@@ -890,6 +890,29 @@ LiveIntervals::getLastSplitPoint(const LiveInterval &li,
   return mbb->getFirstTerminator();
 }
 
+void LiveIntervals::addKillFlags() {
+  for (iterator I = begin(), E = end(); I != E; ++I) {
+    unsigned Reg = I->first;
+    if (TargetRegisterInfo::isPhysicalRegister(Reg))
+      continue;
+    if (mri_->reg_nodbg_empty(Reg))
+      continue;
+    LiveInterval *LI = I->second;
+
+    // Every instruction that kills Reg corresponds to a live range end point.
+    for (LiveInterval::iterator RI = LI->begin(), RE = LI->end(); RI != RE;
+         ++RI) {
+      // A LOAD index indicates an MBB edge.
+      if (RI->end.isLoad())
+        continue;
+      MachineInstr *MI = getInstructionFromIndex(RI->end);
+      if (!MI)
+        continue;
+      MI->addRegisterKilled(Reg, NULL);
+    }
+  }
+}
+
 /// getReMatImplicitUse - If the remat definition MI has one (for now, we only
 /// allow one) virtual register operand, then its uses are implicitly using
 /// the register. Returns the virtual register.
index 4957847348e1ed193c3f53abaccd0de450ab54a8..4713da8a9afa6c1f1f14196aab51145c487b66ef 100644 (file)
@@ -1087,6 +1087,7 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
 
   allocatePhysRegs();
   addMBBLiveIns(MF);
+  LIS->addKillFlags();
 
   // Run rewriter
   {