aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/LiveIntervalAnalysis.cpp
diff options
context:
space:
mode:
authorAlkis Evlogimenos <alkis@evlogimenos.com>2004-01-31 16:54:54 +0000
committerAlkis Evlogimenos <alkis@evlogimenos.com>2004-01-31 16:54:54 +0000
commit97017de1872e08ffcdde2fccdfd399647c1ccc4a (patch)
tree8bf105a6bd5f7ec301ea4250cbcc81478f2b704f /lib/CodeGen/LiveIntervalAnalysis.cpp
parent4d46e1e521c0df1990ea50f8146d22bd77ea71a6 (diff)
Optimize liveAt() and overlaps(). We now use a binary search instead
of a linear search to find the first range for comparisons. This cuts down the linear scan register allocator running time by a factor of 3 in 254.perlbmk and by a factor of 2.2 in 176.gcc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11030 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/LiveIntervalAnalysis.cpp')
-rw-r--r--lib/CodeGen/LiveIntervalAnalysis.cpp50
1 files changed, 30 insertions, 20 deletions
diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp
index 75fcfd09ea..21f545fe80 100644
--- a/lib/CodeGen/LiveIntervalAnalysis.cpp
+++ b/lib/CodeGen/LiveIntervalAnalysis.cpp
@@ -463,22 +463,43 @@ LiveIntervals::Interval::Interval(unsigned r)
bool LiveIntervals::Interval::liveAt(unsigned index) const
{
- Ranges::const_iterator r = ranges.begin();
- while (r != ranges.end() && index < (r->second - 1)) {
- if (index >= r->first)
- return true;
- ++r;
- }
- return false;
+ Range dummy(index, index+1);
+ Ranges::const_iterator r = std::upper_bound(ranges.begin(),
+ ranges.end(),
+ dummy);
+ if (r == ranges.begin())
+ return false;
+
+ --r;
+ return index >= r->first && index < (r->second - 1);
}
bool LiveIntervals::Interval::overlaps(const Interval& other) const
{
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->first < j->first) {
+ i = std::upper_bound(i, ie, *j);
+ if (i != ranges.begin()) --i;
+ }
+ else if (j->first < i->first) {
+ j = std::upper_bound(j, je, *i);
+ if (j != other.ranges.begin()) --j;
+ }
+
+ while (i != ie && j != je) {
+ if (i->first == j->first) {
+ return true;
+ }
+ else {
+ if (i->first > j->first) {
+ swap(i, j);
+ swap(ie, je);
+ }
+ assert(i->first < j->first);
- while (i != ranges.end() && j != other.ranges.end()) {
- if (i->first < j->first) {
if ((i->second - 1) > j->first) {
return true;
}
@@ -486,17 +507,6 @@ bool LiveIntervals::Interval::overlaps(const Interval& other) const
++i;
}
}
- else if (j->first < i->first) {
- if ((j->second - 1) > i->first) {
- return true;
- }
- else {
- ++j;
- }
- }
- else {
- return true;
- }
}
return false;