Fix an inline asm pasto from 117667; was preventing
[oota-llvm.git] / lib / CodeGen / SplitKit.cpp
index 70352fc1782209416fc010cdf6b1107043f66ee9..480fde4deff8600ca679233712afd983c5b0bc2b 100644 (file)
@@ -12,7 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#define DEBUG_TYPE "splitter"
+#define DEBUG_TYPE "regalloc"
 #include "SplitKit.h"
 #include "LiveRangeEdit.h"
 #include "VirtRegMap.h"
@@ -429,10 +429,9 @@ VNInfo *LiveIntervalMap::mapValue(const VNInfo *ParentVNI, SlotIndex Idx,
          liveOutCache_.insert(std::make_pair(Pred, LiveOutPair()));
        // Yes, we have been here before.
        if (!LOIP.second) {
-         if (VNInfo *VNI = LOIP.first->second.first) {
-           DEBUG(dbgs() << "    known valno #" << VNI->id
+         DEBUG(if (VNInfo *VNI = LOIP.first->second.first)
+                 dbgs() << "    known valno #" << VNI->id
                         << " at BB#" << Pred->getNumber() << '\n');
-         }
          continue;
        }
 
@@ -441,10 +440,11 @@ VNInfo *LiveIntervalMap::mapValue(const VNInfo *ParentVNI, SlotIndex Idx,
        if (VNInfo *VNI = extendTo(Pred, Last)) {
          MachineBasicBlock *DefMBB = lis_.getMBBFromIndex(VNI->def);
          DEBUG(dbgs() << "    found valno #" << VNI->id
-                      << " at BB#" << DefMBB->getNumber() << '\n');
+                      << " from BB#" << DefMBB->getNumber()
+                      << " at BB#" << Pred->getNumber() << '\n');
          LiveOutPair &LOP = LOIP.first->second;
          LOP.first = VNI;
-         LOP.second = mdt_[lis_.getMBBFromIndex(VNI->def)];
+         LOP.second = mdt_[DefMBB];
          continue;
        }
        // No, we need a live-in value for Pred as well
@@ -528,11 +528,14 @@ VNInfo *LiveIntervalMap::mapValue(const VNInfo *ParentVNI, SlotIndex Idx,
           I->second = LiveOutPair(VNI, Node);
         }
       } else if (IDomValue.first) {
-        // No phi-def here. Propagate IDomValue if needed.
+        // No phi-def here. Remember incoming value for IdxMBB.
         if (MBB == IdxMBB)
           IdxVNI = IDomValue.first;
+        // Propagate IDomValue if needed:
+        // MBB is live-out and doesn't define its own value.
         LiveOutMap::iterator I = liveOutCache_.find(MBB);
-        if (I != liveOutCache_.end() && I->second.first != IDomValue.first) {
+        if (I != liveOutCache_.end() && I->second.second != Node &&
+            I->second.first != IDomValue.first) {
           ++Changes;
           I->second = IDomValue;
           DEBUG(dbgs() << "    - BB#" << MBB->getNumber()
@@ -656,13 +659,13 @@ void LiveIntervalMap::addRange(SlotIndex Start, SlotIndex End) {
     addSimpleRange(I->start, std::min(End, I->end), I->valno);
 }
 
-VNInfo *LiveIntervalMap::defByCopyFrom(unsigned Reg,
-                                       const VNInfo *ParentVNI,
-                                       MachineBasicBlock &MBB,
-                                       MachineBasicBlock::iterator I) {
+VNInfo *LiveIntervalMap::defByCopy(const VNInfo *ParentVNI,
+                                   MachineBasicBlock &MBB,
+                                   MachineBasicBlock::iterator I) {
   const TargetInstrDesc &TID = MBB.getParent()->getTarget().getInstrInfo()->
     get(TargetOpcode::COPY);
-  MachineInstr *MI = BuildMI(MBB, I, DebugLoc(), TID, li_->reg).addReg(Reg);
+  MachineInstr *MI = BuildMI(MBB, I, DebugLoc(), TID, li_->reg)
+    .addReg(parentli_.reg);
   SlotIndex DefIdx = lis_.InsertMachineInstrInMaps(MI).getDefIndex();
   VNInfo *VNI = defValue(ParentVNI, DefIdx);
   VNI->setCopy(MI);
@@ -720,8 +723,7 @@ void SplitEditor::enterIntvBefore(SlotIndex Idx) {
   truncatedValues.insert(ParentVNI);
   MachineInstr *MI = lis_.getInstructionFromIndex(Idx);
   assert(MI && "enterIntvBefore called with invalid index");
-  VNInfo *VNI = openli_.defByCopyFrom(edit_.getReg(), ParentVNI,
-                                      *MI->getParent(), MI);
+  VNInfo *VNI = openli_.defByCopy(ParentVNI, *MI->getParent(), MI);
   openli_.getLI()->addRange(LiveRange(VNI->def, Idx.getDefIndex(), VNI));
   DEBUG(dbgs() << ": " << *openli_.getLI() << '\n');
 }
@@ -738,8 +740,7 @@ void SplitEditor::enterIntvAtEnd(MachineBasicBlock &MBB) {
   }
   DEBUG(dbgs() << ": valno " << ParentVNI->id);
   truncatedValues.insert(ParentVNI);
-  VNInfo *VNI = openli_.defByCopyFrom(edit_.getReg(), ParentVNI,
-                                      MBB, MBB.getFirstTerminator());
+  VNInfo *VNI = openli_.defByCopy(ParentVNI, MBB, MBB.getFirstTerminator());
   // Make sure openli is live out of MBB.
   openli_.getLI()->addRange(LiveRange(VNI->def, End, VNI));
   DEBUG(dbgs() << ": " << *openli_.getLI() << '\n');
@@ -772,8 +773,7 @@ void SplitEditor::leaveIntvAfter(SlotIndex Idx) {
 
   MachineBasicBlock::iterator MII = lis_.getInstructionFromIndex(Idx);
   MachineBasicBlock *MBB = MII->getParent();
-  VNInfo *VNI = dupli_.defByCopyFrom(openli_.getLI()->reg, ParentVNI, *MBB,
-                                     llvm::next(MII));
+  VNInfo *VNI = dupli_.defByCopy(ParentVNI, *MBB, llvm::next(MII));
 
   // Finally we must make sure that openli is properly extended from Idx to the
   // new copy.
@@ -795,8 +795,8 @@ void SplitEditor::leaveIntvAtTop(MachineBasicBlock &MBB) {
   }
 
   // We are going to insert a back copy, so we must have a dupli_.
-  VNInfo *VNI = dupli_.defByCopyFrom(openli_.getLI()->reg, ParentVNI,
-                                     MBB, MBB.begin());
+  VNInfo *VNI = dupli_.defByCopy(ParentVNI, MBB,
+                                 MBB.SkipPHIsAndLabels(MBB.begin()));
 
   // Finally we must make sure that openli is properly extended from Start to
   // the new copy.
@@ -819,6 +819,7 @@ void SplitEditor::rewrite(unsigned reg) {
   for (MachineRegisterInfo::reg_iterator RI = mri_.reg_begin(reg),
        RE = mri_.reg_end(); RI != RE;) {
     MachineOperand &MO = RI.getOperand();
+    unsigned OpNum = RI.getOperandNo();
     MachineInstr *MI = MO.getParent();
     ++RI;
     if (MI->isDebugValue()) {
@@ -841,6 +842,8 @@ void SplitEditor::rewrite(unsigned reg) {
     DEBUG(dbgs() << "  rewr BB#" << MI->getParent()->getNumber() << '\t'<< Idx);
     assert(LI && "No register was live at use");
     MO.setReg(LI->reg);
+    if (MO.isUse() && !MI->isRegTiedToDefOperand(OpNum))
+      MO.setIsKill(LI->killedAt(Idx.getDefIndex()));
     DEBUG(dbgs() << '\t' << *MI);
   }
 }
@@ -910,6 +913,9 @@ void SplitEditor::computeRemainder() {
   for (LiveInterval::const_vni_iterator I = parent.vni_begin(),
        E = parent.vni_end(); I != E; ++I) {
     const VNInfo *VNI = *I;
+    // Don't transfer unused values to the new intervals.
+    if (VNI->isUnused())
+      continue;
     // Original def is contained in the split intervals.
     if (intervalsLiveAt(VNI->def)) {
       // Did this value escape?