summaryrefslogtreecommitdiff
path: root/lib/CodeGen/LiveInterval.cpp
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@boostpro.com>2011-03-11 08:54:34 +0000
committerJohn Wiegley <johnw@boostpro.com>2011-03-11 08:54:34 +0000
commit6fd2472b1b2d8f6a64b38874cbca95d3578e16a4 (patch)
tree83a05ed02ec8efa0571f9c1a0a4e7e81f5af90a8 /lib/CodeGen/LiveInterval.cpp
parent592ca3fda918c2066d9d78ed360e5fd69066fda7 (diff)
downloadllvm-6fd2472b1b2d8f6a64b38874cbca95d3578e16a4.tar.gz
llvm-6fd2472b1b2d8f6a64b38874cbca95d3578e16a4.tar.bz2
llvm-6fd2472b1b2d8f6a64b38874cbca95d3578e16a4.tar.xz
Fix use of CompEnd predicate to be standards conforming
The existing CompEnd predicate does not define a strict weak order as required by the C++03 standard; therefore, its use as a predicate to std::upper_bound is invalid. For a discussion of this issue, see http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#270 This patch replaces the asymmetrical comparison with an iterator adaptor that achieves the same effect while being strictly standard-conforming by ensuring an apples-to-apples comparison. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127462 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/LiveInterval.cpp')
-rw-r--r--lib/CodeGen/LiveInterval.cpp120
1 files changed, 111 insertions, 9 deletions
diff --git a/lib/CodeGen/LiveInterval.cpp b/lib/CodeGen/LiveInterval.cpp
index 585e3a2dc2..1b446e69d3 100644
--- a/lib/CodeGen/LiveInterval.cpp
+++ b/lib/CodeGen/LiveInterval.cpp
@@ -30,24 +30,126 @@
#include <algorithm>
using namespace llvm;
-// CompEnd - Compare LiveRange ends.
+// SlotIndexIterator - adapt an iterator over LiveRanges to look
+// like an iterator over SlotIndexes by accessing the .end member.
namespace {
-struct CompEnd {
- bool operator()(SlotIndex A, const LiveRange &B) const {
- return A < B.end;
+struct SlotIndexIterator
+ : std::iterator<std::random_access_iterator_tag, SlotIndex> {
+
+ SlotIndexIterator() {
+ }
+
+ explicit SlotIndexIterator(LiveInterval::iterator it)
+ : it(it) {
+ }
+
+ SlotIndexIterator(const SlotIndexIterator & that)
+ : it(that.it) {
+ }
+
+ SlotIndexIterator & operator=(const SlotIndexIterator & that) {
+ it = that.it;
+ return *this;
+ }
+
+ SlotIndexIterator & operator++() {
+ ++it;
+ return *this;
+ }
+
+ SlotIndexIterator operator++(int) {
+ SlotIndexIterator that(*this);
+ ++*this;
+ return that;
+ }
+
+ SlotIndexIterator & operator--() {
+ --it;
+ return *this;
+ }
+
+ SlotIndexIterator operator--(int) {
+ SlotIndexIterator that(*this);
+ --*this;
+ return that;
+ }
+
+ SlotIndexIterator & operator+=(std::ptrdiff_t n) {
+ it += n;
+ return *this;
+ }
+
+ SlotIndexIterator & operator-=(std::ptrdiff_t n) {
+ it -= n;
+ return *this;
+ }
+
+ friend bool operator==(SlotIndexIterator lhs, SlotIndexIterator rhs) {
+ return lhs.it == rhs.it;
+ }
+
+ friend bool operator!=(SlotIndexIterator lhs, SlotIndexIterator rhs) {
+ return lhs.it != rhs.it;
}
- bool operator()(const LiveRange &A, SlotIndex B) const {
- return A.end < B;
+
+ friend bool operator<(SlotIndexIterator lhs, SlotIndexIterator rhs) {
+ return lhs.it < rhs.it;
+ }
+
+ friend bool operator<=(SlotIndexIterator lhs, SlotIndexIterator rhs) {
+ return lhs.it <= rhs.it;
+ }
+
+ friend bool operator>(SlotIndexIterator lhs, SlotIndexIterator rhs) {
+ return lhs.it > rhs.it;
+ }
+
+ friend bool operator>=(SlotIndexIterator lhs, SlotIndexIterator rhs) {
+ return lhs.it >= rhs.it;
+ }
+
+ friend SlotIndexIterator operator+(SlotIndexIterator that, std::ptrdiff_t n) {
+ return SlotIndexIterator(that.it + n);
}
- bool operator()(const LiveRange &A, const LiveRange &B) const {
- return A.end < B.end;
+
+ friend SlotIndexIterator operator+(std::ptrdiff_t n, SlotIndexIterator that) {
+ return SlotIndexIterator(n + that.it);
+ }
+
+ friend SlotIndexIterator operator-(SlotIndexIterator that, std::ptrdiff_t n) {
+ return SlotIndexIterator(that.it - n);
}
+
+ friend std::ptrdiff_t operator-(SlotIndexIterator lhs, SlotIndexIterator rhs) {
+ return lhs.it - rhs.it;
+ }
+
+ reference operator*() const {
+ return it->end;
+ }
+
+ reference operator[](std::ptrdiff_t n) const {
+ return it[n].end;
+ }
+
+ pointer operator->() const {
+ return &it->end;
+ }
+
+ LiveInterval::iterator base() const {
+ return it;
+ }
+
+private:
+ LiveInterval::iterator it;
};
}
LiveInterval::iterator LiveInterval::find(SlotIndex Pos) {
assert(Pos.isValid() && "Cannot search for an invalid index");
- return std::upper_bound(begin(), end(), Pos, CompEnd());
+ return std::upper_bound(
+ SlotIndexIterator(begin()),
+ SlotIndexIterator(end()), Pos).base();
}
/// killedInRange - Return true if the interval has kills in [Start,End).