[llvm-commits] CVS: llvm/lib/CodeGen/RegAllocLinearScan.cpp LiveIntervals.h LiveIntervals.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Sun May 30 02:50:02 PDT 2004
Changes in directory llvm/lib/CodeGen:
RegAllocLinearScan.cpp updated: 1.73 -> 1.74
LiveIntervals.h updated: 1.25 -> 1.26
LiveIntervals.cpp updated: 1.75 -> 1.76
---
Log message:
Pull Interval class out of LiveIntervals.
---
Diffs of the changes: (+67 -80)
Index: llvm/lib/CodeGen/RegAllocLinearScan.cpp
diff -u llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.73 llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.74
--- llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.73 Sun May 30 02:24:39 2004
+++ llvm/lib/CodeGen/RegAllocLinearScan.cpp Sun May 30 02:46:27 2004
@@ -21,6 +21,7 @@
#include "llvm/Target/MRegisterInfo.h"
#include "llvm/Target/TargetMachine.h"
#include "Support/Debug.h"
+#include "Support/STLExtras.h"
#include "LiveIntervals.h"
#include "PhysRegTracker.h"
#include "VirtRegMap.h"
@@ -38,7 +39,7 @@
const TargetMachine* tm_;
const MRegisterInfo* mri_;
LiveIntervals* li_;
- typedef std::list<LiveIntervals::Interval*> IntervalPtrs;
+ typedef std::list<Interval*> IntervalPtrs;
IntervalPtrs unhandled_, fixed_, active_, inactive_, handled_;
std::auto_ptr<PhysRegTracker> prt_;
@@ -122,7 +123,7 @@
// if (MRegisterInfo::isVirtualRegister(i->second) &&
// (i->second == i2->second ||
// mri_->areAliases(i->second, i2->second))) {
-// const LiveIntervals::Interval
+// const Interval
// &in = li_->getInterval(i->second),
// &in2 = li_->getInterval(i2->second);
// if (in.overlaps(in2)) {
@@ -373,12 +374,12 @@
if (cur->weight <= minWeight) {
DEBUG(std::cerr << "\t\t\tspilling(c): " << *cur << '\n';);
int slot = vrm_->assignVirt2StackSlot(cur->reg);
- std::vector<LiveIntervals::Interval*> added =
+ std::vector<Interval*> added =
li_->addIntervalsForSpills(*cur, *vrm_, slot);
// merge added with unhandled
- std::vector<LiveIntervals::Interval*>::iterator addedIt = added.begin();
- std::vector<LiveIntervals::Interval*>::iterator addedItEnd = added.end();
+ std::vector<Interval*>::iterator addedIt = added.begin();
+ std::vector<Interval*>::iterator addedItEnd = added.end();
for (IntervalPtrs::iterator i = unhandled_.begin(), e = unhandled_.end();
i != e && addedIt != addedItEnd; ++i) {
if ((*i)->start() > (*addedIt)->start())
@@ -398,7 +399,7 @@
// otherwise we spill all intervals aliasing the register with
// minimum weight, rollback to the interval with the earliest
// start point and let the linear scan algorithm run again
- std::vector<LiveIntervals::Interval*> added;
+ std::vector<Interval*> added;
assert(MRegisterInfo::isPhysicalRegister(minReg) &&
"did not choose a register to spill?");
std::vector<bool> toSpill(mri_->getNumRegs(), false);
@@ -417,7 +418,7 @@
DEBUG(std::cerr << "\t\t\tspilling(a): " << **i << '\n');
earliestStart = std::min(earliestStart, (*i)->start());
int slot = vrm_->assignVirt2StackSlot((*i)->reg);
- std::vector<LiveIntervals::Interval*> newIs =
+ std::vector<Interval*> newIs =
li_->addIntervalsForSpills(**i, *vrm_, slot);
std::copy(newIs.begin(), newIs.end(), std::back_inserter(added));
spilled.insert(reg);
@@ -432,7 +433,7 @@
DEBUG(std::cerr << "\t\t\tspilling(i): " << **i << '\n');
earliestStart = std::min(earliestStart, (*i)->start());
int slot = vrm_->assignVirt2StackSlot((*i)->reg);
- std::vector<LiveIntervals::Interval*> newIs =
+ std::vector<Interval*> newIs =
li_->addIntervalsForSpills(**i, *vrm_, slot);
std::copy(newIs.begin(), newIs.end(), std::back_inserter(added));
spilled.insert(reg);
@@ -495,10 +496,10 @@
}
}
- std::sort(added.begin(), added.end(), LiveIntervals::StartPointPtrComp());
+ std::sort(added.begin(), added.end(), less_ptr<Interval>());
// merge added with unhandled
- std::vector<LiveIntervals::Interval*>::iterator addedIt = added.begin();
- std::vector<LiveIntervals::Interval*>::iterator addedItEnd = added.end();
+ std::vector<Interval*>::iterator addedIt = added.begin();
+ std::vector<Interval*>::iterator addedItEnd = added.end();
for (IntervalPtrs::iterator i = unhandled_.begin(), e = unhandled_.end();
i != e && addedIt != addedItEnd; ++i) {
if ((*i)->start() > (*addedIt)->start())
Index: llvm/lib/CodeGen/LiveIntervals.h
diff -u llvm/lib/CodeGen/LiveIntervals.h:1.25 llvm/lib/CodeGen/LiveIntervals.h:1.26
--- llvm/lib/CodeGen/LiveIntervals.h:1.25 Sun May 30 02:24:39 2004
+++ llvm/lib/CodeGen/LiveIntervals.h Sun May 30 02:46:27 2004
@@ -30,62 +30,60 @@
class MRegisterInfo;
class VirtRegMap;
- class LiveIntervals : public MachineFunctionPass
- {
- public:
- struct Interval {
- typedef std::pair<unsigned, unsigned> Range;
- typedef std::vector<Range> Ranges;
- unsigned reg; // the register of this interval
- float weight; // weight of this interval (number of uses
- // * 10^loopDepth)
- Ranges ranges; // the ranges in which this register is live
- Interval(unsigned r);
+ struct Interval {
+ typedef std::pair<unsigned, unsigned> Range;
+ typedef std::vector<Range> Ranges;
+ unsigned reg; // the register of this interval
+ float weight; // weight of this interval:
+ // (number of uses *10^loopDepth)
+ Ranges ranges; // the ranges in which this register is live
- bool empty() const { return ranges.empty(); }
+ explicit Interval(unsigned r);
- bool spilled() const;
+ bool empty() const { return ranges.empty(); }
- unsigned start() const {
- assert(!empty() && "empty interval for register");
- return ranges.front().first;
- }
+ bool spilled() const;
- unsigned end() const {
- assert(!empty() && "empty interval for register");
- return ranges.back().second;
- }
+ unsigned start() const {
+ assert(!empty() && "empty interval for register");
+ return ranges.front().first;
+ }
- bool expiredAt(unsigned index) const {
- return end() <= (index + 1);
- }
+ unsigned end() const {
+ assert(!empty() && "empty interval for register");
+ return ranges.back().second;
+ }
- bool liveAt(unsigned index) const;
+ bool expiredAt(unsigned index) const {
+ return end() <= (index + 1);
+ }
- bool overlaps(const Interval& other) const;
+ bool liveAt(unsigned index) const;
- void addRange(unsigned start, unsigned end);
+ bool overlaps(const Interval& other) const;
- void join(const Interval& other);
+ void addRange(unsigned start, unsigned end);
- private:
- Ranges::iterator mergeRangesForward(Ranges::iterator it);
+ void join(const Interval& other);
- Ranges::iterator mergeRangesBackward(Ranges::iterator it);
- };
+ bool operator<(const Interval& other) const {
+ return start() < other.start();
+ }
- struct StartPointComp {
- bool operator()(const Interval& lhs, const Interval& rhs) {
- return lhs.ranges.front().first < rhs.ranges.front().first;
- }
- };
+ bool operator==(const Interval& other) const {
+ return reg == other.reg;
+ }
- struct StartPointPtrComp {
- bool operator()(const Interval* lhs, const Interval* rhs) {
- return lhs->ranges.front().first < rhs->ranges.front().first;
- }
- };
+ private:
+ Ranges::iterator mergeRangesForward(Ranges::iterator it);
+ Ranges::iterator mergeRangesBackward(Ranges::iterator it);
+ };
+ std::ostream& operator<<(std::ostream& os, const Interval& li);
+
+ class LiveIntervals : public MachineFunctionPass
+ {
+ public:
typedef std::list<Interval> Intervals;
private:
@@ -205,14 +203,6 @@
void printRegName(unsigned reg) const;
};
- inline bool operator==(const LiveIntervals::Interval& lhs,
- const LiveIntervals::Interval& rhs) {
- return lhs.reg == rhs.reg;
- }
-
- std::ostream& operator<<(std::ostream& os,
- const LiveIntervals::Interval& li);
-
} // End llvm namespace
#endif
Index: llvm/lib/CodeGen/LiveIntervals.cpp
diff -u llvm/lib/CodeGen/LiveIntervals.cpp:1.75 llvm/lib/CodeGen/LiveIntervals.cpp:1.76
--- llvm/lib/CodeGen/LiveIntervals.cpp:1.75 Sun May 30 02:24:39 2004
+++ llvm/lib/CodeGen/LiveIntervals.cpp Sun May 30 02:46:27 2004
@@ -167,7 +167,7 @@
}
}
- intervals_.sort(StartPointComp());
+ intervals_.sort();
DEBUG(std::cerr << "********** INTERVALS **********\n");
DEBUG(std::copy(intervals_.begin(), intervals_.end(),
std::ostream_iterator<Interval>(std::cerr, "\n")));
@@ -186,10 +186,9 @@
return true;
}
-std::vector<LiveIntervals::Interval*>
-LiveIntervals::addIntervalsForSpills(const Interval& li,
- VirtRegMap& vrm,
- int slot)
+std::vector<Interval*> LiveIntervals::addIntervalsForSpills(const Interval& li,
+ VirtRegMap& vrm,
+ int slot)
{
std::vector<Interval*> added;
@@ -554,7 +553,7 @@
return false;
}
-LiveIntervals::Interval& LiveIntervals::getOrCreateInterval(unsigned reg)
+Interval& LiveIntervals::getOrCreateInterval(unsigned reg)
{
Reg2IntervalMap::iterator r2iit = r2iMap_.lower_bound(reg);
if (r2iit == r2iMap_.end() || r2iit->first != reg) {
@@ -565,13 +564,13 @@
return *r2iit->second;
}
-LiveIntervals::Interval::Interval(unsigned r)
+Interval::Interval(unsigned r)
: reg(r),
weight((MRegisterInfo::isPhysicalRegister(r) ? HUGE_VAL : 0.0F))
{
}
-bool LiveIntervals::Interval::spilled() const
+bool Interval::spilled() const
{
return (weight == HUGE_VAL &&
MRegisterInfo::isVirtualRegister(reg));
@@ -584,7 +583,7 @@
// definition of the variable it represents. This is because slot 1 is
// used (def slot) and spans up to slot 3 (store slot).
//
-bool LiveIntervals::Interval::liveAt(unsigned index) const
+bool Interval::liveAt(unsigned index) const
{
Range dummy(index, index+1);
Ranges::const_iterator r = std::upper_bound(ranges.begin(),
@@ -611,7 +610,7 @@
//
// A->overlaps(C) should return false since we want to be able to join
// A and C.
-bool LiveIntervals::Interval::overlaps(const Interval& other) const
+bool Interval::overlaps(const Interval& other) const
{
Ranges::const_iterator i = ranges.begin();
Ranges::const_iterator ie = ranges.end();
@@ -649,7 +648,7 @@
return false;
}
-void LiveIntervals::Interval::addRange(unsigned start, unsigned end)
+void Interval::addRange(unsigned start, unsigned end)
{
assert(start < end && "Invalid range to add!");
DEBUG(std::cerr << " +[" << start << ',' << end << ")");
@@ -663,7 +662,7 @@
it = mergeRangesBackward(it);
}
-void LiveIntervals::Interval::join(const LiveIntervals::Interval& other)
+void Interval::join(const Interval& other)
{
DEBUG(std::cerr << "\t\tjoining " << *this << " with " << other << '\n');
Ranges::iterator cur = ranges.begin();
@@ -678,8 +677,7 @@
++numJoins;
}
-LiveIntervals::Interval::Ranges::iterator
-LiveIntervals::Interval::mergeRangesForward(Ranges::iterator it)
+Interval::Ranges::iterator Interval::mergeRangesForward(Ranges::iterator it)
{
Ranges::iterator n;
while ((n = next(it)) != ranges.end()) {
@@ -691,8 +689,7 @@
return it;
}
-LiveIntervals::Interval::Ranges::iterator
-LiveIntervals::Interval::mergeRangesBackward(Ranges::iterator it)
+Interval::Ranges::iterator Interval::mergeRangesBackward(Ranges::iterator it)
{
while (it != ranges.begin()) {
Ranges::iterator p = prior(it);
@@ -707,15 +704,14 @@
return it;
}
-std::ostream& llvm::operator<<(std::ostream& os,
- const LiveIntervals::Interval& li)
+std::ostream& llvm::operator<<(std::ostream& os, const Interval& li)
{
os << "%reg" << li.reg << ',' << li.weight;
if (li.empty())
return os << "EMPTY";
os << " = ";
- for (LiveIntervals::Interval::Ranges::const_iterator
+ for (Interval::Ranges::const_iterator
i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) {
os << "[" << i->first << "," << i->second << ")";
}
More information about the llvm-commits
mailing list