Match MachineFunction::UsedPhysRegs changes.
[oota-llvm.git] / lib / CodeGen / LiveInterval.cpp
index eecb570db5316988a9454bb1795726e6e9ad9c8a..45c1dd03da5881e46a9ba7a876e20ebf057c1c13 100644 (file)
 
 #include "llvm/CodeGen/LiveInterval.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Streams.h"
 #include "llvm/Target/MRegisterInfo.h"
 #include <algorithm>
-#include <iostream>
 #include <map>
+#include <ostream>
 using namespace llvm;
 
 // An example for liveAt():
@@ -289,7 +290,6 @@ void LiveInterval::join(LiveInterval &Other, int *LHSValNoAssignments,
   //
   // Also, if one range is a physreg and one is a vreg, we always merge from the
   // vreg into the physreg, which leaves the vreg intervals pristine.
-  unsigned OtherOffs = 1, ThisOffs = 0;
   if ((Other.ranges.size() > ranges.size() &&
       MRegisterInfo::isVirtualRegister(reg)) ||
       MRegisterInfo::isPhysicalRegister(Other.reg)) {
@@ -349,8 +349,27 @@ void LiveInterval::join(LiveInterval &Other, int *LHSValNoAssignments,
   ValueNumberInfo.clear();
   ValueNumberInfo.append(NewValueNumberInfo.begin(), NewValueNumberInfo.end());
   weight += Other.weight;
+  if (Other.preference && !preference)
+    preference = Other.preference;
 }
 
+/// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
+/// interval as the specified value number.  The LiveRanges in RHS are
+/// allowed to overlap with LiveRanges in the current interval, but only if
+/// the overlapping LiveRanges have the specified value number.
+void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS, 
+                                        unsigned LHSValNo) {
+  // TODO: Make this more efficient.
+  iterator InsertPos = begin();
+  for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
+    // Map the ValId in the other live range to the current live range.
+    LiveRange Tmp = *I;
+    Tmp.ValId = LHSValNo;
+    InsertPos = addRangeFrom(Tmp, InsertPos);
+  }
+}
+
+
 /// MergeInClobberRanges - For any live ranges that are not defined in the
 /// current interval, but are defined in the Clobbers interval, mark them
 /// used with an unknown definition value.
@@ -450,13 +469,19 @@ void LiveInterval::MergeValueNumberInto(unsigned V1, unsigned V2) {
   }
 }
 
+unsigned LiveInterval::getSize() const {
+  unsigned Sum = 0;
+  for (const_iterator I = begin(), E = end(); I != E; ++I)
+    Sum += I->end - I->start;
+  return Sum;
+}
 
 std::ostream& llvm::operator<<(std::ostream& os, const LiveRange &LR) {
   return os << '[' << LR.start << ',' << LR.end << ':' << LR.ValId << ")";
 }
 
 void LiveRange::dump() const {
-  std::cerr << *this << "\n";
+  cerr << *this << "\n";
 }
 
 void LiveInterval::print(std::ostream &OS, const MRegisterInfo *MRI) const {
@@ -492,5 +517,10 @@ void LiveInterval::print(std::ostream &OS, const MRegisterInfo *MRI) const {
 }
 
 void LiveInterval::dump() const {
-  std::cerr << *this << "\n";
+  cerr << *this << "\n";
+}
+
+
+void LiveRange::print(std::ostream &os) const {
+  os << *this;
 }