From c7d6078a3a7b2836f045c32cd9129e9bb0776ac3 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 20 May 2014 13:36:40 -0700 Subject: [PATCH] Bug 1012964 - IonMonkey: Optimize LiveInterval::addRange. r=bhackett --- js/src/jit/LiveRangeAllocator.cpp | 30 ++++++++++++++++++------------ mfbt/Vector.h | 22 ++++++++++++++++++++-- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/js/src/jit/LiveRangeAllocator.cpp b/js/src/jit/LiveRangeAllocator.cpp index d8ce72de694..5cac4eef048 100644 --- a/js/src/jit/LiveRangeAllocator.cpp +++ b/js/src/jit/LiveRangeAllocator.cpp @@ -76,6 +76,7 @@ bool LiveInterval::addRangeAtHead(CodePosition from, CodePosition to) { JS_ASSERT(from < to); + JS_ASSERT(ranges_.empty() || from <= ranges_.back().from); Range newRange(from, to); @@ -110,23 +111,28 @@ LiveInterval::addRange(CodePosition from, CodePosition to) Range *i; // Find the location to insert the new range - for (i = ranges_.end() - 1; i >= ranges_.begin(); i--) { - if (newRange.from <= i->to) { - if (i->from < newRange.from) - newRange.from = i->from; + for (i = ranges_.end(); i > ranges_.begin(); i--) { + if (newRange.from <= i[-1].to) { + if (i[-1].from < newRange.from) + newRange.from = i[-1].from; break; } } // Perform coalescing on overlapping ranges - for (; i >= ranges_.begin(); i--) { - if (newRange.to < i->from) + Range *j = i; + for (; i > ranges_.begin(); i--) { + if (newRange.to < i[-1].from) break; - if (newRange.to < i->to) - newRange.to = i->to; - ranges_.erase(i); + if (newRange.to < i[-1].to) + newRange.to = i[-1].to; } - return ranges_.insert(i + 1, newRange); + if (i == j) + return ranges_.insert(i, newRange); + + i[0] = newRange; + ranges_.erase(i + 1, j); + return true; } void @@ -134,10 +140,10 @@ LiveInterval::setFrom(CodePosition from) { while (!ranges_.empty()) { if (ranges_.back().to < from) { - ranges_.erase(&ranges_.back()); + ranges_.popBack(); } else { if (from == ranges_.back().to) - ranges_.erase(&ranges_.back()); + ranges_.popBack(); else ranges_.back().from = from; break; diff --git a/mfbt/Vector.h b/mfbt/Vector.h index 4d283dfd5b6..9f4f898d74c 100644 --- a/mfbt/Vector.h +++ b/mfbt/Vector.h @@ -543,6 +543,12 @@ class VectorBase : private AllocPolicy */ void erase(T* t); + /** + * Removes the elements [|b|, |e|), which must fall in the bounds [begin, end), + * shifting existing elements from |e + 1| onward to b's old position. + */ + void erase(T* b, T *e); + /** * Measure the size of the vector's heap-allocated storage. */ @@ -974,10 +980,22 @@ VectorBase::erase(T* it) MOZ_ASSERT(begin() <= it); MOZ_ASSERT(it < end()); while (it + 1 < end()) { - *it = *(it + 1); + *it = Move(*(it + 1)); ++it; } - popBack(); + popBack(); +} + +template +inline void +VectorBase::erase(T* b, T *e) +{ + MOZ_ASSERT(begin() <= b); + MOZ_ASSERT(b <= e); + MOZ_ASSERT(e <= end()); + while (e < end()) + *b++ = Move(*e++); + shrinkBy(e - b); } template