Remove Path::getDirectoryContents.
[oota-llvm.git] / lib / CodeGen / PHIElimination.cpp
index 6d8f20744463ae3a1d10a0e1b4d6e9c06b1b2704..5584708eae36bdbf5dcf22b7381fb22107a0ad72 100644 (file)
@@ -116,6 +116,7 @@ INITIALIZE_PASS_END(PHIElimination, "phi-node-elimination",
 
 void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addPreserved<LiveVariables>();
+  AU.addPreserved<SlotIndexes>();
   AU.addPreserved<LiveIntervals>();
   AU.addPreserved<MachineDominatorTree>();
   AU.addPreserved<MachineLoopInfo>();
@@ -162,8 +163,8 @@ bool PHIElimination::runOnMachineFunction(MachineFunction &MF) {
   // Clean up the lowered PHI instructions.
   for (LoweredPHIMap::iterator I = LoweredPHIs.begin(), E = LoweredPHIs.end();
        I != E; ++I) {
-   if (LIS)
-     LIS->RemoveMachineInstrFromMaps(I->first);
+    if (LIS)
+      LIS->RemoveMachineInstrFromMaps(I->first);
     MF.DeleteMachineInstr(I->first);
   }
 
@@ -171,9 +172,6 @@ bool PHIElimination::runOnMachineFunction(MachineFunction &MF) {
   ImpDefs.clear();
   VRegPHIUseCount.clear();
 
-  if (LIS)
-    MF.verify(this, "After PHI elimination");
-
   return Changed;
 }
 
@@ -305,10 +303,9 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
   // Update LiveIntervals for the new copy or implicit def.
   if (LIS) {
     MachineInstr *NewInstr = prior(AfterPHIsIt);
-    LIS->InsertMachineInstrInMaps(NewInstr);
+    SlotIndex DestCopyIndex = LIS->InsertMachineInstrInMaps(NewInstr);
 
     SlotIndex MBBStartIndex = LIS->getMBBStartIdx(&MBB);
-    SlotIndex DestCopyIndex = LIS->getInstructionIndex(NewInstr);
     if (IncomingReg) {
       // Add the region from the beginning of MBB to the copy instruction to
       // IncomingReg's live interval.
@@ -322,8 +319,10 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
                                     IncomingVNI));
     }
 
-    LiveInterval &DestLI = LIS->getOrCreateInterval(DestReg);
-    if (NewInstr->getOperand(0).isDead()) {
+    LiveInterval &DestLI = LIS->getInterval(DestReg);
+    assert(DestLI.begin() != DestLI.end() &&
+           "PHIs should have nonempty LiveIntervals.");
+    if (DestLI.endIndex().isDead()) {
       // A dead PHI's live range begins and ends at the start of the MBB, but
       // the lowered copy, which will still be dead, needs to begin and end at
       // the copy instruction.
@@ -467,7 +466,11 @@ void PHIElimination::LowerPHINode(MachineBasicBlock &MBB,
         bool isLiveOut = false;
         for (MachineBasicBlock::succ_iterator SI = opBlock.succ_begin(),
              SE = opBlock.succ_end(); SI != SE; ++SI) {
-          if (SrcLI.liveAt(LIS->getMBBStartIdx(*SI))) {
+          SlotIndex startIdx = LIS->getMBBStartIdx(*SI);
+          VNInfo *VNI = SrcLI.getVNInfoAt(startIdx);
+
+          // Definitions by other PHIs are not truly live-in for our purposes.
+          if (VNI && VNI->def != startIdx) {
             isLiveOut = true;
             break;
           }