[llvm-commits] [llvm] r42961 - in /llvm/trunk: include/llvm/CodeGen/LiveInterval.h lib/CodeGen/LiveInterval.cpp lib/CodeGen/SimpleRegisterCoalescing.cpp

Evan Cheng evan.cheng at apple.com
Sun Oct 14 03:08:35 PDT 2007


Author: evancheng
Date: Sun Oct 14 05:08:34 2007
New Revision: 42961

URL: http://llvm.org/viewvc/llvm-project?rev=42961&view=rev
Log:
When coalescing an EXTRACT_SUBREG and the dst register is a physical register,
the source register will be coalesced to the super register of the LHS. Properly
merge in the live ranges of the resulting coalesced interval that were part of
the original source interval to the live interval of the super-register.

Modified:
    llvm/trunk/include/llvm/CodeGen/LiveInterval.h
    llvm/trunk/lib/CodeGen/LiveInterval.cpp
    llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp

Modified: llvm/trunk/include/llvm/CodeGen/LiveInterval.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/LiveInterval.h?rev=42961&r1=42960&r2=42961&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/LiveInterval.h (original)
+++ llvm/trunk/include/llvm/CodeGen/LiveInterval.h Sun Oct 14 05:08:34 2007
@@ -253,7 +253,7 @@
     /// current interval, but only if the overlapping LiveRanges have the
     /// specified value number.
     void MergeValueInAsValue(const LiveInterval &RHS,
-                             VNInfo *RHSValNo, VNInfo *LHSValNo);
+                             const VNInfo *RHSValNo, VNInfo *LHSValNo);
 
     /// Copy - Copy the specified live interval. This copies all the fields
     /// except for the register of the interval.

Modified: llvm/trunk/lib/CodeGen/LiveInterval.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LiveInterval.cpp?rev=42961&r1=42960&r2=42961&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/LiveInterval.cpp (original)
+++ llvm/trunk/lib/CodeGen/LiveInterval.cpp Sun Oct 14 05:08:34 2007
@@ -389,7 +389,7 @@
 /// current interval, but only if the overlapping LiveRanges have the
 /// specified value number.
 void LiveInterval::MergeValueInAsValue(const LiveInterval &RHS,
-                                       VNInfo *RHSValNo, VNInfo *LHSValNo) {
+                                     const VNInfo *RHSValNo, VNInfo *LHSValNo) {
   // TODO: Make this more efficient.
   iterator InsertPos = begin();
   for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {

Modified: llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp?rev=42961&r1=42960&r2=42961&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp (original)
+++ llvm/trunk/lib/CodeGen/SimpleRegisterCoalescing.cpp Sun Oct 14 05:08:34 2007
@@ -421,14 +421,16 @@
     // cl = EXTRACT_SUBREG reg1024, 1
     // then create and update the actual physical register allocated to RHS.
     if (RealDstReg) {
-      unsigned CopyIdx = li_->getInstructionIndex(CopyMI);
-      VNInfo *DstValNo =
-        ResDstInt->getLiveRangeContaining(li_->getUseIndex(CopyIdx))->valno;
       LiveInterval &RealDstInt = li_->getOrCreateInterval(RealDstReg);
-      VNInfo *ValNo = RealDstInt.getNextValue(DstValNo->def, DstValNo->reg,
-                                              li_->getVNInfoAllocator());
-      RealDstInt.addKills(ValNo, DstValNo->kills);
-      RealDstInt.MergeValueInAsValue(*ResDstInt, DstValNo, ValNo);
+      for (unsigned i = 0, e = ResSrcInt->getNumValNums(); i != e; ++i) {
+        const VNInfo *SrcValNo = ResSrcInt->getValNumInfo(i);
+        const VNInfo *DstValNo =
+          ResDstInt->FindLiveRangeContaining(SrcValNo->def)->valno;
+        VNInfo *ValNo = RealDstInt.getNextValue(DstValNo->def, DstValNo->reg,
+                                                li_->getVNInfoAllocator());
+        RealDstInt.addKills(ValNo, DstValNo->kills);
+        RealDstInt.MergeValueInAsValue(*ResDstInt, DstValNo, ValNo);
+      }
       repDstReg = RealDstReg;
     }
 
@@ -879,32 +881,32 @@
     }
   }
 
+  // Update kill info. Some live ranges are extended due to copy coalescing.
+  for (DenseMap<VNInfo*, VNInfo*>::iterator I = LHSValsDefinedFromRHS.begin(),
+         E = LHSValsDefinedFromRHS.end(); I != E; ++I) {
+    VNInfo *VNI = I->first;
+    unsigned LHSValID = LHSValNoAssignments[VNI->id];
+    LiveInterval::removeKill(NewVNInfo[LHSValID], VNI->def);
+    RHS.addKills(NewVNInfo[LHSValID], VNI->kills);
+  }
+
+  // Update kill info. Some live ranges are extended due to copy coalescing.
+  for (DenseMap<VNInfo*, VNInfo*>::iterator I = RHSValsDefinedFromLHS.begin(),
+         E = RHSValsDefinedFromLHS.end(); I != E; ++I) {
+    VNInfo *VNI = I->first;
+    unsigned RHSValID = RHSValNoAssignments[VNI->id];
+    LiveInterval::removeKill(NewVNInfo[RHSValID], VNI->def);
+    LHS.addKills(NewVNInfo[RHSValID], VNI->kills);
+  }
+
   // If we get here, we know that we can coalesce the live ranges.  Ask the
   // intervals to coalesce themselves now.
   if ((RHS.ranges.size() > LHS.ranges.size() &&
       MRegisterInfo::isVirtualRegister(LHS.reg)) ||
       MRegisterInfo::isPhysicalRegister(RHS.reg)) {
-    // Update kill info. Some live ranges are extended due to copy coalescing.
-    for (DenseMap<VNInfo*, VNInfo*>::iterator I = LHSValsDefinedFromRHS.begin(),
-           E = LHSValsDefinedFromRHS.end(); I != E; ++I) {
-      VNInfo *VNI = I->first;
-      unsigned LHSValID = LHSValNoAssignments[VNI->id];
-      LiveInterval::removeKill(NewVNInfo[LHSValID], VNI->def);
-      RHS.addKills(NewVNInfo[LHSValID], VNI->kills);
-    }
-
     RHS.join(LHS, &RHSValNoAssignments[0], &LHSValNoAssignments[0], NewVNInfo);
     Swapped = true;
   } else {
-    // Update kill info. Some live ranges are extended due to copy coalescing.
-    for (DenseMap<VNInfo*, VNInfo*>::iterator I = RHSValsDefinedFromLHS.begin(),
-           E = RHSValsDefinedFromLHS.end(); I != E; ++I) {
-      VNInfo *VNI = I->first;
-      unsigned RHSValID = RHSValNoAssignments[VNI->id];
-      LiveInterval::removeKill(NewVNInfo[RHSValID], VNI->def);
-      LHS.addKills(NewVNInfo[RHSValID], VNI->kills);
-    }
-
     LHS.join(RHS, &LHSValNoAssignments[0], &RHSValNoAssignments[0], NewVNInfo);
     Swapped = false;
   }





More information about the llvm-commits mailing list