[llvm-commits] [llvm] r48719 - /llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp

Owen Anderson resistor at mac.com
Sun Mar 23 21:11:28 PDT 2008


Author: resistor
Date: Sun Mar 23 23:11:27 2008
New Revision: 48719

URL: http://llvm.org/viewvc/llvm-project?rev=48719&view=rev
Log:
Be sure to remove intervals after we've joined them.  Also, remove some duplicated code.

With this pass, StrongPHIElim can compile very simple testcases correctly.  There's still a ways
to go before it's ready for prime time, though.

Modified:
    llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp

Modified: llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp?rev=48719&r1=48718&r2=48719&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp (original)
+++ llvm/trunk/lib/CodeGen/StrongPHIElimination.cpp Sun Mar 23 23:11:27 2008
@@ -136,7 +136,8 @@
                          std::vector<StrongPHIElimination::DomForestNode*>& DF,
                          std::vector<std::pair<unsigned, unsigned> >& locals);
     void ScheduleCopies(MachineBasicBlock* MBB, std::set<unsigned>& pushed);
-    void InsertCopies(MachineBasicBlock* MBB, std::set<MachineBasicBlock*>& v);
+    void InsertCopies(MachineBasicBlock* MBB,
+                      SmallPtrSet<MachineBasicBlock*, 16>& v);
     void mergeLiveIntervals(unsigned primary, unsigned secondary, unsigned VN);
   };
 
@@ -423,7 +424,7 @@
     // is refinded over the course of this function.  UnionedBlocks is the set
     // of corresponding MBBs.
     std::map<unsigned, unsigned> PHIUnion;
-    std::set<MachineBasicBlock*> UnionedBlocks;
+    SmallPtrSet<MachineBasicBlock*, 8> UnionedBlocks;
   
     // Iterate over the operands of the PHI node
     for (int i = P->getNumOperands() - 1; i >= 2; i-=2) {
@@ -708,7 +709,7 @@
 
 /// InsertCopies - insert copies into MBB and all of its successors
 void StrongPHIElimination::InsertCopies(MachineBasicBlock* MBB,
-                                        std::set<MachineBasicBlock*>& visited) {
+                                 SmallPtrSet<MachineBasicBlock*, 16>& visited) {
   visited.insert(MBB);
   
   std::set<unsigned> pushed;
@@ -789,9 +790,11 @@
   return ThisValNoAssignments[VN] = UltimateVN;
 }
 
+#include <iostream>
+
 void StrongPHIElimination::mergeLiveIntervals(unsigned primary,
-                                              unsigned secondary, unsigned secondaryVN) {
-  unsigned primaryVN = PhiValueNumber[primary];
+                                              unsigned secondary,
+                                              unsigned secondaryVN) {
   
   LiveIntervals& LI = getAnalysis<LiveIntervals>();
   LiveInterval& LHS = LI.getOrCreateInterval(primary);
@@ -807,44 +810,6 @@
   
   LHSValNoAssignments.resize(LHS.getNumValNums(), -1);
   RHSValNoAssignments.resize(RHS.getNumValNums(), -1);
-  NewVNInfo.resize(LHS.getNumValNums(), NULL);
-  
-  // Loop over the value numbers of the LHS, seeing if any are defined from
-  // the RHS.
-  for (LiveInterval::vni_iterator I = LHS.vni_begin(), E = LHS.vni_end();
-       I != E; ++E) {
-    VNInfo *VNI = *I;
-    if (VNI->def == ~1U || VNI->copy == 0)  // Src not defined by a copy?
-      continue;
-    
-    // DstReg is known to be a register in the LHS interval.  If the src is
-    // from the RHS interval, we can use its value #.
-    if (LI.getVNInfoSourceReg(VNI) != RHS.reg)
-      continue;
-    
-    // Figure out the value # from the RHS.
-    LHSValsDefinedFromRHS[VNI]=RHS.getLiveRangeContaining(VNI->def-1)->valno;
-  }
-  
-  // Loop over the value numbers of the RHS, seeing if any are defined from
-  // the LHS.
-  for (LiveInterval::vni_iterator i = RHS.vni_begin(), e = RHS.vni_end();
-       i != e; ++i) {
-    VNInfo *VNI = *i;
-    if (VNI->def == ~1U || VNI->copy == 0)  // Src not defined by a copy?
-      continue;
-    
-    // DstReg is known to be a register in the RHS interval.  If the src is
-    // from the LHS interval, we can use its value #.
-    if (LI.getVNInfoSourceReg(VNI) != LHS.reg)
-      continue;
-    
-    // Figure out the value # from the LHS.
-    RHSValsDefinedFromLHS[VNI]=LHS.getLiveRangeContaining(VNI->def-1)->valno;
-  }
-  
-  LHSValNoAssignments.resize(LHS.getNumValNums(), -1);
-  RHSValNoAssignments.resize(RHS.getNumValNums(), -1);
   NewVNInfo.reserve(LHS.getNumValNums() + RHS.getNumValNums());
   
   for (LiveInterval::vni_iterator I = LHS.vni_begin(), E = LHS.vni_end();
@@ -898,7 +863,8 @@
 
   // Use the VNInfo we collected earlier to ensure that the phi copy is
   // merged correctly.
-  RHSValNoAssignments[secondaryVN] = primaryVN;
+  // FIXME: This is not working correctly yet.
+  // RHSValNoAssignments[secondaryVN] = primaryVN;
 
   // If we get here, we know that we can coalesce the live ranges.  Ask the
   // intervals to coalesce themselves now.
@@ -906,8 +872,10 @@
       TargetRegisterInfo::isVirtualRegister(LHS.reg)) ||
       TargetRegisterInfo::isPhysicalRegister(RHS.reg)) {
     RHS.join(LHS, &RHSValNoAssignments[0], &LHSValNoAssignments[0], NewVNInfo);
+    LI.removeInterval(primary);
   } else {
     LHS.join(RHS, &LHSValNoAssignments[0], &RHSValNoAssignments[0], NewVNInfo);
+    LI.removeInterval(secondary);
   }
 }
 
@@ -923,7 +891,7 @@
   
   // Insert copies
   // FIXME: This process should probably preserve LiveVariables
-  std::set<MachineBasicBlock*> visited;
+  SmallPtrSet<MachineBasicBlock*, 16> visited;
   InsertCopies(Fn.begin(), visited);
   
   // Perform renaming
@@ -947,9 +915,13 @@
         phis.push_back(BI);
   }
   
+  LiveIntervals& LI = getAnalysis<LiveIntervals>();
+  
   for (std::vector<MachineInstr*>::iterator I = phis.begin(), E = phis.end();
-       I != E; ++I)
+       I != E; ++I) {
+    LI.RemoveMachineInstrFromMaps(*I);
     (*I)->eraseFromParent();
+  }
   
   return false;
 }





More information about the llvm-commits mailing list