Ranges::const_iterator ie = ranges.end();
Ranges::const_iterator j = other.ranges.begin();
Ranges::const_iterator je = other.ranges.end();
+
if (i->start < j->start) {
i = std::upper_bound(i, ie, j->start);
if (i != ranges.begin()) --i;
/// or if the destination of the copy is a single assignment value, and it
/// only overlaps with one value in the source interval.
bool LiveInterval::joinable(const LiveInterval &other, unsigned CopyIdx) const {
- return overlaps(other);
+ const LiveRange *SourceLR = other.getLiveRangeContaining(CopyIdx-1);
+ const LiveRange *DestLR = getLiveRangeContaining(CopyIdx);
+ assert(SourceLR && DestLR && "Not joining due to a copy?");
+ unsigned OtherValIdx = SourceLR->ValId;
+ unsigned ThisValIdx = DestLR->ValId;
+
+ Ranges::const_iterator i = ranges.begin();
+ Ranges::const_iterator ie = ranges.end();
+ Ranges::const_iterator j = other.ranges.begin();
+ Ranges::const_iterator je = other.ranges.end();
+
+ if (i->start < j->start) {
+ i = std::upper_bound(i, ie, j->start);
+ if (i != ranges.begin()) --i;
+ } else if (j->start < i->start) {
+ j = std::upper_bound(j, je, i->start);
+ if (j != other.ranges.begin()) --j;
+ }
+
+ while (i != ie && j != je) {
+ if (i->start == j->start) {
+ // If this is not the allowed value merge, we cannot join.
+ if (i->ValId != ThisValIdx || j->ValId != OtherValIdx)
+ return false;
+ } else if (i->start < j->start) {
+ if (i->end > j->start) {
+ if (i->ValId != ThisValIdx || j->ValId != OtherValIdx)
+ return false;
+ }
+ } else {
+ if (j->end > i->start) {
+ if (i->ValId != ThisValIdx || j->ValId != OtherValIdx)
+ return false;
+ }
+ }
+ if (i->end < j->end)
+ ++i;
+ else
+ ++j;
+ }
+
+ return true;
}
/// getLiveRangeContaining - Return the live range that contains the
/// specified index, or null if there is none.
-LiveRange *LiveInterval::getLiveRangeContaining(unsigned Idx) {
- Ranges::iterator It = std::upper_bound(ranges.begin(), ranges.end(), Idx);
+const LiveRange *LiveInterval::getLiveRangeContaining(unsigned Idx) const {
+ Ranges::const_iterator It = std::upper_bound(ranges.begin(),ranges.end(),Idx);
if (It != ranges.begin()) {
- LiveRange &LR = *prior(It);
+ const LiveRange &LR = *prior(It);
if (LR.contains(Idx))
return &LR;
}
/// is the result of a copy instruction in the source program, that occurs at
/// index 'CopyIdx' that copies from 'Other' to 'this'.
void LiveInterval::join(LiveInterval &Other, unsigned CopyIdx) {
- LiveRange *SourceLR = Other.getLiveRangeContaining(CopyIdx-1);
- LiveRange *DestLR = getLiveRangeContaining(CopyIdx);
+ const LiveRange *SourceLR = Other.getLiveRangeContaining(CopyIdx-1);
+ const LiveRange *DestLR = getLiveRangeContaining(CopyIdx);
assert(SourceLR && DestLR && "Not joining due to a copy?");
unsigned MergedSrcValIdx = SourceLR->ValId;
unsigned MergedDstValIdx = DestLR->ValId;