Fix kill info for split intervals.
authorEvan Cheng <evan.cheng@apple.com>
Wed, 5 Dec 2007 08:16:32 +0000 (08:16 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 5 Dec 2007 08:16:32 +0000 (08:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44609 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/LiveIntervalAnalysis.cpp
lib/CodeGen/VirtRegMap.cpp
lib/CodeGen/VirtRegMap.h

index 5c95eb16d83f00ddd4974a597d5ef537d9937ed1..cc2298a898c139925c8b61b1196e95ab48b30e0f 100644 (file)
@@ -1267,6 +1267,7 @@ addIntervalsForSpills(const LiveInterval &li,
   if (!TrySplit)
     return NewLIs;
 
+  SmallPtrSet<LiveInterval*, 4> AddedKill;
   SmallVector<unsigned, 2> Ops;
   if (NeedStackSlot) {
     int Id = SpillMBBs.find_first();
@@ -1316,8 +1317,13 @@ addIntervalsForSpills(const LiveInterval &li,
         }
 
         // Else tell the spiller to issue a spill.
-        if (!Folded)
-          vrm.addSpillPoint(VReg, MI);
+        if (!Folded) {
+          LiveRange *LR = &nI.ranges[nI.ranges.size()-1];
+          bool isKill = LR->end == getStoreIndex(index);
+          vrm.addSpillPoint(VReg, isKill, MI);
+          if (isKill)
+            AddedKill.insert(&nI);
+        }
       }
       Id = SpillMBBs.find_next(Id);
     }
@@ -1372,24 +1378,28 @@ addIntervalsForSpills(const LiveInterval &li,
       // load / rematerialization for us.
       if (Folded)
         nI.removeRange(getLoadIndex(index), getUseIndex(index)+1);
-      else {
+      else
         vrm.addRestorePoint(VReg, MI);
-        LiveRange *LR = &nI.ranges[nI.ranges.size()-1];
-        MachineInstr *LastUse = getInstructionFromIndex(getBaseIndex(LR->end));
-        int UseIdx = LastUse->findRegisterUseOperandIdx(VReg);
-        assert(UseIdx != -1);
-        LastUse->getOperand(UseIdx).setIsKill();
-      }
     }
     Id = RestoreMBBs.find_next(Id);
   }
 
-  // Finalize spill weights and filter out dead intervals.
+  // Finalize intervals: add kills, finalize spill weights, and filter out
+  // dead intervals.
   std::vector<LiveInterval*> RetNewLIs;
   for (unsigned i = 0, e = NewLIs.size(); i != e; ++i) {
     LiveInterval *LI = NewLIs[i];
     if (!LI->empty()) {
       LI->weight /= LI->getSize();
+      if (!AddedKill.count(LI)) {
+        LiveRange *LR = &LI->ranges[LI->ranges.size()-1];
+        MachineInstr *LastUse = getInstructionFromIndex(getBaseIndex(LR->end));
+        int UseIdx = LastUse->findRegisterUseOperandIdx(LI->reg);
+        assert(UseIdx != -1);
+        if (LastUse->getInstrDescriptor()->
+            getOperandConstraint(UseIdx, TOI::TIED_TO) == -1)
+          LastUse->getOperand(UseIdx).setIsKill();
+      }
       RetNewLIs.push_back(LI);
     }
   }
index 050f17fe7a181751afbe49be7fd9b126357e35f3..b8135bfe990b193a5d67921f8e0e2bece064036a 100644 (file)
@@ -977,15 +977,17 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) {
 
     // Insert spills here if asked to.
     if (VRM.isSpillPt(&MI)) {
-      std::vector<unsigned> &SpillRegs = VRM.getSpillPtSpills(&MI);
+      std::vector<std::pair<unsigned,bool> > &SpillRegs =
+        VRM.getSpillPtSpills(&MI);
       for (unsigned i = 0, e = SpillRegs.size(); i != e; ++i) {
-        unsigned VirtReg = SpillRegs[i];
+        unsigned VirtReg = SpillRegs[i].first;
+        bool isKill = SpillRegs[i].second;
         if (!VRM.getPreSplitReg(VirtReg))
           continue; // Split interval spilled again.
         const TargetRegisterClass *RC = RegMap->getRegClass(VirtReg);
         unsigned Phys = VRM.getPhys(VirtReg);
         int StackSlot = VRM.getStackSlot(VirtReg);
-        MRI->storeRegToStackSlot(MBB, next(MII), Phys, false, StackSlot, RC);
+        MRI->storeRegToStackSlot(MBB, next(MII), Phys, isKill, StackSlot, RC);
         MachineInstr *StoreMI = next(MII);
         DOUT << "Store:\t" << StoreMI;
         VRM.virtFolded(VirtReg, StoreMI, VirtRegMap::isMod);
index 61a9738469c32e5d64f5dfb5f6c6c7ea0f265523..df32a6566a701158df3e9699f2d46ba2fc112500 100644 (file)
@@ -80,7 +80,8 @@ namespace llvm {
     /// SpillPt2VirtMap - This records the virtual registers which should
     /// be spilled right after the MachineInstr due to live interval
     /// splitting.
-    std::map<MachineInstr*, std::vector<unsigned> > SpillPt2VirtMap;
+    std::map<MachineInstr*, std::vector<std::pair<unsigned,bool> > >
+    SpillPt2VirtMap;
 
     /// RestorePt2VirtMap - This records the virtual registers which should
     /// be restored right before the MachineInstr due to live interval
@@ -216,30 +217,31 @@ namespace llvm {
 
     /// @brief returns the virtual registers that should be spilled due to
     /// splitting right after the specified MachineInstr.
-    std::vector<unsigned> &getSpillPtSpills(MachineInstr *Pt) {
+    std::vector<std::pair<unsigned,bool> > &getSpillPtSpills(MachineInstr *Pt) {
       return SpillPt2VirtMap[Pt];
     }
 
     /// @brief records the specified MachineInstr as a spill point for virtReg.
-    void addSpillPoint(unsigned virtReg, MachineInstr *Pt) {
+    void addSpillPoint(unsigned virtReg, bool isKill, MachineInstr *Pt) {
       if (SpillPt2VirtMap.find(Pt) != SpillPt2VirtMap.end())
-        SpillPt2VirtMap[Pt].push_back(virtReg);
+        SpillPt2VirtMap[Pt].push_back(std::make_pair(virtReg, isKill));
       else {
-        std::vector<unsigned> Virts;
-        Virts.push_back(virtReg);
+        std::vector<std::pair<unsigned,bool> > Virts;
+        Virts.push_back(std::make_pair(virtReg, isKill));
         SpillPt2VirtMap.insert(std::make_pair(Pt, Virts));
       }
     }
 
     void transferSpillPts(MachineInstr *Old, MachineInstr *New) {
-      std::map<MachineInstr*,std::vector<unsigned> >::iterator I =
-        SpillPt2VirtMap.find(Old);
+      std::map<MachineInstr*,std::vector<std::pair<unsigned,bool> > >::iterator
+        I = SpillPt2VirtMap.find(Old);
       if (I == SpillPt2VirtMap.end())
         return;
       while (!I->second.empty()) {
-        unsigned virtReg = I->second.back();
+        unsigned virtReg = I->second.back().first;
+        bool isKill = I->second.back().second;
         I->second.pop_back();
-        addSpillPoint(virtReg, New);
+        addSpillPoint(virtReg, isKill, New);
       }
       SpillPt2VirtMap.erase(I);
     }