Reduce the offsets in DwarfDebugInfoEntry to 32 bit, they're printed with %x and
[oota-llvm.git] / lib / CodeGen / StrongPHIElimination.cpp
index 5c70423cceccb980a95750866dc1de066771d59b..260cc0ee50a56950b0bd68b35cd66afa3783d317 100644 (file)
@@ -47,6 +47,8 @@
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/Target/TargetInstrInfo.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/Statistic.h"
 #include "llvm/Support/Debug.h"
 using namespace llvm;
 
@@ -89,7 +91,15 @@ namespace {
     /// Add a register in a new congruence class containing only itself.
     void addReg(unsigned);
 
-    /// Join the congruence classes of two registers.
+    /// Join the congruence classes of two registers. This function is biased
+    /// towards the left argument, i.e. after
+    ///
+    /// addReg(r2);
+    /// unionRegs(r1, r2);
+    ///
+    /// the leader of the unioned congruence class is the same as the leader of
+    /// r1's congruence class prior to the union. This is actually relied upon
+    /// in the copy insertion code.
     void unionRegs(unsigned, unsigned);
 
     /// Get the color of a register. The color is 0 if the register has been
@@ -179,6 +189,10 @@ namespace {
   };
 } // namespace
 
+STATISTIC(NumPHIsLowered, "Number of PHIs lowered");
+STATISTIC(NumDestCopiesInserted, "Number of destination copies inserted");
+STATISTIC(NumSrcCopiesInserted, "Number of source copies inserted");
+
 char StrongPHIElimination::ID = 0;
 INITIALIZE_PASS_BEGIN(StrongPHIElimination, "strong-phi-node-elimination",
   "Eliminate PHI nodes for register allocation, intelligently", false, false)
@@ -543,7 +557,8 @@ StrongPHIElimination::SplitInterferencesForBasicBlock(
       // handle it here by tracking defining machine instructions rather than
       // virtual registers. For now, we just handle the situation conservatively
       // in a way that will possibly lead to false interferences.
-      unsigned NewParent = CurrentDominatingParent[DestColor];
+      unsigned &CurrentParent = CurrentDominatingParent[DestColor];
+      unsigned NewParent = CurrentParent;
       if (NewParent == DestReg)
         continue;
 
@@ -562,18 +577,18 @@ StrongPHIElimination::SplitInterferencesForBasicBlock(
         // could be improved by using a heuristic that decides which of the two
         // registers to isolate.
         isolateReg(DestReg);
-        CurrentDominatingParent[DestColor] = NewParent;
+        CurrentParent = NewParent;
       } else {
         // If there is no interference, update ImmediateDominatingParent and set
         // the CurrentDominatingParent for this color to the current register.
         ImmediateDominatingParent[DestReg] = NewParent;
-        CurrentDominatingParent[DestColor] = DestReg;
+        CurrentParent = DestReg;
       }
     }
   }
 
   // We now walk the PHIs in successor blocks and check for interferences. This
-  // is necesary because the use of a PHI's operands are logically contained in
+  // is necessary because the use of a PHI's operands are logically contained in
   // the predecessor block. The def of a PHI's destination register is processed
   // along with the other defs in a basic block.
 
@@ -602,12 +617,13 @@ StrongPHIElimination::SplitInterferencesForBasicBlock(
 
       // Pop registers from the stack represented by ImmediateDominatingParent
       // until we find a parent that dominates the current instruction.
-      unsigned NewParent = CurrentDominatingParent[Color];
+      unsigned &CurrentParent = CurrentDominatingParent[Color];
+      unsigned NewParent = CurrentParent;
       while (NewParent
              && (!DT->dominates(MRI->getVRegDef(NewParent)->getParent(), &MBB)
                  || !getRegColor(NewParent)))
         NewParent = ImmediateDominatingParent[NewParent];
-      CurrentDominatingParent[Color] = NewParent;
+      CurrentParent = NewParent;
 
       // If there is an interference with a register, always isolate the
       // register rather than the PHI. It is also possible to isolate the
@@ -617,7 +633,8 @@ StrongPHIElimination::SplitInterferencesForBasicBlock(
                     && NewParent != PredOperandReg)
         isolateReg(NewParent);
 
-      std::pair<MachineInstr*, unsigned> CurrentPHI = CurrentPHIForColor[Color];
+      std::pair<MachineInstr*, unsigned>
+        &CurrentPHI = CurrentPHIForColor[Color];
 
       // If two PHIs have the same operand from every shared predecessor, then
       // they don't actually interfere. Otherwise, isolate the current PHI. This
@@ -626,7 +643,7 @@ StrongPHIElimination::SplitInterferencesForBasicBlock(
       if (CurrentPHI.first && CurrentPHI.second != PredOperandReg)
         isolatePHI(PHI);
       else
-        CurrentPHIForColor[Color] = std::make_pair(PHI, PredOperandReg);
+        CurrentPHI = std::make_pair(PHI, PredOperandReg);
     }
   }
 }
@@ -634,6 +651,7 @@ StrongPHIElimination::SplitInterferencesForBasicBlock(
 void StrongPHIElimination::InsertCopiesForPHI(MachineInstr *PHI,
                                               MachineBasicBlock *MBB) {
   assert(PHI->isPHI());
+  ++NumPHIsLowered;
   unsigned PHIColor = getPHIColor(PHI);
 
   for (unsigned i = 1; i < PHI->getNumOperands(); i += 2) {
@@ -656,7 +674,7 @@ void StrongPHIElimination::InsertCopiesForPHI(MachineInstr *PHI,
     if (PHIColor && SrcColor == PHIColor) {
       LiveInterval &SrcInterval = LI->getInterval(SrcReg);
       SlotIndex PredIndex = LI->getMBBEndIdx(PredBB);
-      VNInfo *SrcVNI = SrcInterval.getVNInfoAt(PredIndex.getPrevIndex());
+      VNInfo *SrcVNI = SrcInterval.getVNInfoBefore(PredIndex);
       assert(SrcVNI);
       SrcVNI->setHasPHIKill(true);
       continue;
@@ -683,6 +701,7 @@ void StrongPHIElimination::InsertCopiesForPHI(MachineInstr *PHI,
                                         TII->get(TargetOpcode::COPY),
                                         CopyReg).addReg(SrcReg, 0, SrcSubReg);
       LI->InsertMachineInstrInMaps(CopyInstr);
+      ++NumSrcCopiesInserted;
 
       // addLiveRangeToEndOfBlock() also adds the phikill flag to the VNInfo for
       // the newly added range.
@@ -752,6 +771,7 @@ void StrongPHIElimination::InsertCopiesForPHI(MachineInstr *PHI,
                                     DestReg).addReg(CopyReg);
   LI->InsertMachineInstrInMaps(CopyInstr);
   PHI->getOperand(0).setReg(CopyReg);
+  ++NumDestCopiesInserted;
 
   // Add the region from the beginning of MBB to the copy instruction to
   // CopyReg's live interval, and give the VNInfo the phidef flag.