#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():
/// the intervals are not joinable, this aborts.
void LiveInterval::join(LiveInterval &Other, int *LHSValNoAssignments,
int *RHSValNoAssignments,
- SmallVector<unsigned, 16> &NewInstDefiningValue) {
+ SmallVector<std::pair<unsigned,
+ unsigned>, 16> &NewValueNumberInfo) {
// Try to do the least amount of work possible. In particular, if there are
// more liverange chunks in the other set than there are in the 'this' set,
//
// 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)) {
// we want to avoid the interval scan if not.
bool MustMapCurValNos = false;
for (unsigned i = 0, e = getNumValNums(); i != e; ++i) {
- if (InstDefiningValue[i] == ~2U) continue; // tombstone value #
+ if (ValueNumberInfo[i].first == ~2U) continue; // tombstone value #
if (i != (unsigned)LHSValNoAssignments[i]) {
MustMapCurValNos = true;
break;
InsertPos = addRangeFrom(*I, InsertPos);
}
- InstDefiningValue.clear();
- InstDefiningValue.append(NewInstDefiningValue.begin(),
- NewInstDefiningValue.end());
+ ValueNumberInfo.clear();
+ ValueNumberInfo.append(NewValueNumberInfo.begin(), NewValueNumberInfo.end());
weight += Other.weight;
}
+/// 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.
// Find a value # to use for the clobber ranges. If there is already a value#
// for unknown values, use it.
// FIXME: Use a single sentinal number for these!
- unsigned ClobberValNo = getNextValue(~0U);
+ unsigned ClobberValNo = getNextValue(~0U, 0);
iterator IP = begin();
for (const_iterator I = Clobbers.begin(), E = Clobbers.end(); I != E; ++I) {
// Make sure V2 is smaller than V1.
if (V1 < V2) {
- setInstDefiningValNum(V1, getInstForValNum(V2));
+ setValueNumberInfo(V1, getValNumInfo(V2));
std::swap(V1, V2);
}
// ~1U so it can be nuked later.
if (V1 == getNumValNums()-1) {
do {
- InstDefiningValue.pop_back();
- } while (InstDefiningValue.back() == ~1U);
+ ValueNumberInfo.pop_back();
+ } while (ValueNumberInfo.back().first == ~1U);
} else {
- InstDefiningValue[V1] = ~1U;
+ ValueNumberInfo[V1].first = ~1U;
}
}
-
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 {
for (unsigned i = 0; i != getNumValNums(); ++i) {
if (i) OS << " ";
OS << i << "@";
- if (InstDefiningValue[i] == ~0U) {
+ if (ValueNumberInfo[i].first == ~0U) {
OS << "?";
} else {
- OS << InstDefiningValue[i];
+ OS << ValueNumberInfo[i].first;
}
}
}
}
void LiveInterval::dump() const {
- std::cerr << *this << "\n";
+ cerr << *this << "\n";
+}
+
+
+void LiveRange::print(std::ostream &os) const {
+ os << *this;
}