Rename Interval class to LiveInterval to avoid conflicting with the already

existing llvm::Interval class.

Patch contributed by Vladimir Prus!
http://mail.cs.uiuc.edu/pipermail/llvmbugs/2004-June/000710.html

llvm-svn: 14281
This commit is contained in:
Chris Lattner 2004-06-21 13:10:56 +00:00
parent 265eb6469a
commit 4fbff990b0
3 changed files with 54 additions and 50 deletions

View File

@ -136,7 +136,7 @@ bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) {
if (tii.isMoveInstr(*mii, srcReg, dstReg) && if (tii.isMoveInstr(*mii, srcReg, dstReg) &&
rep(srcReg) == rep(dstReg)) { rep(srcReg) == rep(dstReg)) {
// remove from def list // remove from def list
Interval& interval = getOrCreateInterval(rep(dstReg)); LiveInterval& interval = getOrCreateInterval(rep(dstReg));
// remove index -> MachineInstr and // remove index -> MachineInstr and
// MachineInstr -> index mappings // MachineInstr -> index mappings
Mi2IndexMap::iterator mi2i = mi2iMap_.find(mii); Mi2IndexMap::iterator mi2i = mi2iMap_.find(mii);
@ -170,7 +170,7 @@ bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) {
intervals_.sort(); intervals_.sort();
DEBUG(std::cerr << "********** INTERVALS **********\n"); DEBUG(std::cerr << "********** INTERVALS **********\n");
DEBUG(std::copy(intervals_.begin(), intervals_.end(), DEBUG(std::copy(intervals_.begin(), intervals_.end(),
std::ostream_iterator<Interval>(std::cerr, "\n"))); std::ostream_iterator<LiveInterval>(std::cerr, "\n")));
DEBUG(std::cerr << "********** MACHINEINSTRS **********\n"); DEBUG(std::cerr << "********** MACHINEINSTRS **********\n");
DEBUG( DEBUG(
for (MachineFunction::iterator mbbi = mf_->begin(), mbbe = mf_->end(); for (MachineFunction::iterator mbbi = mf_->begin(), mbbe = mf_->end();
@ -186,11 +186,12 @@ bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) {
return true; return true;
} }
std::vector<Interval*> LiveIntervals::addIntervalsForSpills(const Interval& li, std::vector<LiveInterval*> LiveIntervals::addIntervalsForSpills(
const LiveInterval& li,
VirtRegMap& vrm, VirtRegMap& vrm,
int slot) int slot)
{ {
std::vector<Interval*> added; std::vector<LiveInterval*> added;
assert(li.weight != HUGE_VAL && assert(li.weight != HUGE_VAL &&
"attempt to spill already spilled interval!"); "attempt to spill already spilled interval!");
@ -200,7 +201,7 @@ std::vector<Interval*> LiveIntervals::addIntervalsForSpills(const Interval& li,
const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(li.reg); const TargetRegisterClass* rc = mf_->getSSARegMap()->getRegClass(li.reg);
for (Interval::Ranges::const_iterator for (LiveInterval::Ranges::const_iterator
i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) { i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) {
unsigned index = getBaseIndex(i->first); unsigned index = getBaseIndex(i->first);
unsigned end = getBaseIndex(i->second-1) + InstrSlots::NUM; unsigned end = getBaseIndex(i->second-1) + InstrSlots::NUM;
@ -250,7 +251,7 @@ std::vector<Interval*> LiveIntervals::addIntervalsForSpills(const Interval& li,
mi->SetMachineOperandReg(i, nReg); mi->SetMachineOperandReg(i, nReg);
vrm.grow(); vrm.grow();
vrm.assignVirt2StackSlot(nReg, slot); vrm.assignVirt2StackSlot(nReg, slot);
Interval& nI = getOrCreateInterval(nReg); LiveInterval& nI = getOrCreateInterval(nReg);
assert(nI.empty()); assert(nI.empty());
// the spill weight is now infinity as it // the spill weight is now infinity as it
// cannot be spilled again // cannot be spilled again
@ -280,7 +281,7 @@ void LiveIntervals::printRegName(unsigned reg) const
void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock* mbb, void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock* mbb,
MachineBasicBlock::iterator mi, MachineBasicBlock::iterator mi,
Interval& interval) LiveInterval& interval)
{ {
DEBUG(std::cerr << "\t\tregister: "; printRegName(interval.reg)); DEBUG(std::cerr << "\t\tregister: "; printRegName(interval.reg));
LiveVariables::VarInfo& vi = lv_->getVarInfo(interval.reg); LiveVariables::VarInfo& vi = lv_->getVarInfo(interval.reg);
@ -334,7 +335,7 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock* mbb,
void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock* mbb, void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock* mbb,
MachineBasicBlock::iterator mi, MachineBasicBlock::iterator mi,
Interval& interval) LiveInterval& interval)
{ {
DEBUG(std::cerr << "\t\tregister: "; printRegName(interval.reg)); DEBUG(std::cerr << "\t\tregister: "; printRegName(interval.reg));
typedef LiveVariables::killed_iterator KillIter; typedef LiveVariables::killed_iterator KillIter;
@ -536,8 +537,8 @@ void LiveIntervals::joinIntervals()
} }
} }
bool LiveIntervals::overlapsAliases(const Interval& lhs, bool LiveIntervals::overlapsAliases(const LiveInterval& lhs,
const Interval& rhs) const const LiveInterval& rhs) const
{ {
assert(MRegisterInfo::isPhysicalRegister(lhs.reg) && assert(MRegisterInfo::isPhysicalRegister(lhs.reg) &&
"first interval must describe a physical register"); "first interval must describe a physical register");
@ -552,24 +553,24 @@ bool LiveIntervals::overlapsAliases(const Interval& lhs,
return false; return false;
} }
Interval& LiveIntervals::getOrCreateInterval(unsigned reg) LiveInterval& LiveIntervals::getOrCreateInterval(unsigned reg)
{ {
Reg2IntervalMap::iterator r2iit = r2iMap_.lower_bound(reg); Reg2IntervalMap::iterator r2iit = r2iMap_.lower_bound(reg);
if (r2iit == r2iMap_.end() || r2iit->first != reg) { if (r2iit == r2iMap_.end() || r2iit->first != reg) {
intervals_.push_back(Interval(reg)); intervals_.push_back(LiveInterval(reg));
r2iit = r2iMap_.insert(r2iit, std::make_pair(reg, --intervals_.end())); r2iit = r2iMap_.insert(r2iit, std::make_pair(reg, --intervals_.end()));
} }
return *r2iit->second; return *r2iit->second;
} }
Interval::Interval(unsigned r) LiveInterval::LiveInterval(unsigned r)
: reg(r), : reg(r),
weight((MRegisterInfo::isPhysicalRegister(r) ? HUGE_VAL : 0.0F)) weight((MRegisterInfo::isPhysicalRegister(r) ? HUGE_VAL : 0.0F))
{ {
} }
bool Interval::spilled() const bool LiveInterval::spilled() const
{ {
return (weight == HUGE_VAL && return (weight == HUGE_VAL &&
MRegisterInfo::isVirtualRegister(reg)); MRegisterInfo::isVirtualRegister(reg));
@ -582,7 +583,7 @@ bool Interval::spilled() const
// definition of the variable it represents. This is because slot 1 is // definition of the variable it represents. This is because slot 1 is
// used (def slot) and spans up to slot 3 (store slot). // used (def slot) and spans up to slot 3 (store slot).
// //
bool Interval::liveAt(unsigned index) const bool LiveInterval::liveAt(unsigned index) const
{ {
Range dummy(index, index+1); Range dummy(index, index+1);
Ranges::const_iterator r = std::upper_bound(ranges.begin(), Ranges::const_iterator r = std::upper_bound(ranges.begin(),
@ -609,7 +610,7 @@ bool Interval::liveAt(unsigned index) const
// //
// A->overlaps(C) should return false since we want to be able to join // A->overlaps(C) should return false since we want to be able to join
// A and C. // A and C.
bool Interval::overlaps(const Interval& other) const bool LiveInterval::overlaps(const LiveInterval& other) const
{ {
Ranges::const_iterator i = ranges.begin(); Ranges::const_iterator i = ranges.begin();
Ranges::const_iterator ie = ranges.end(); Ranges::const_iterator ie = ranges.end();
@ -647,7 +648,7 @@ bool Interval::overlaps(const Interval& other) const
return false; return false;
} }
void Interval::addRange(unsigned start, unsigned end) void LiveInterval::addRange(unsigned start, unsigned end)
{ {
assert(start < end && "Invalid range to add!"); assert(start < end && "Invalid range to add!");
DEBUG(std::cerr << " +[" << start << ',' << end << ")"); DEBUG(std::cerr << " +[" << start << ',' << end << ")");
@ -661,7 +662,7 @@ void Interval::addRange(unsigned start, unsigned end)
it = mergeRangesBackward(it); it = mergeRangesBackward(it);
} }
void Interval::join(const Interval& other) void LiveInterval::join(const LiveInterval& other)
{ {
DEBUG(std::cerr << "\t\tjoining " << *this << " with " << other << '\n'); DEBUG(std::cerr << "\t\tjoining " << *this << " with " << other << '\n');
Ranges::iterator cur = ranges.begin(); Ranges::iterator cur = ranges.begin();
@ -676,7 +677,8 @@ void Interval::join(const Interval& other)
++numJoins; ++numJoins;
} }
Interval::Ranges::iterator Interval::mergeRangesForward(Ranges::iterator it) LiveInterval::Ranges::iterator LiveInterval::
mergeRangesForward(Ranges::iterator it)
{ {
Ranges::iterator n; Ranges::iterator n;
while ((n = next(it)) != ranges.end()) { while ((n = next(it)) != ranges.end()) {
@ -688,7 +690,8 @@ Interval::Ranges::iterator Interval::mergeRangesForward(Ranges::iterator it)
return it; return it;
} }
Interval::Ranges::iterator Interval::mergeRangesBackward(Ranges::iterator it) LiveInterval::Ranges::iterator LiveInterval::
mergeRangesBackward(Ranges::iterator it)
{ {
while (it != ranges.begin()) { while (it != ranges.begin()) {
Ranges::iterator p = prior(it); Ranges::iterator p = prior(it);
@ -703,14 +706,14 @@ Interval::Ranges::iterator Interval::mergeRangesBackward(Ranges::iterator it)
return it; return it;
} }
std::ostream& llvm::operator<<(std::ostream& os, const Interval& li) std::ostream& llvm::operator<<(std::ostream& os, const LiveInterval& li)
{ {
os << "%reg" << li.reg << ',' << li.weight; os << "%reg" << li.reg << ',' << li.weight;
if (li.empty()) if (li.empty())
return os << "EMPTY"; return os << "EMPTY";
os << " = "; os << " = ";
for (Interval::Ranges::const_iterator for (LiveInterval::Ranges::const_iterator
i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) { i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) {
os << "[" << i->first << "," << i->second << ")"; os << "[" << i->first << "," << i->second << ")";
} }

View File

@ -30,7 +30,7 @@ namespace llvm {
class MRegisterInfo; class MRegisterInfo;
class VirtRegMap; class VirtRegMap;
struct Interval { struct LiveInterval {
typedef std::pair<unsigned, unsigned> Range; typedef std::pair<unsigned, unsigned> Range;
typedef std::vector<Range> Ranges; typedef std::vector<Range> Ranges;
unsigned reg; // the register of this interval unsigned reg; // the register of this interval
@ -38,7 +38,7 @@ namespace llvm {
// (number of uses *10^loopDepth) // (number of uses *10^loopDepth)
Ranges ranges; // the ranges in which this register is live Ranges ranges; // the ranges in which this register is live
explicit Interval(unsigned r); explicit LiveInterval(unsigned r);
bool empty() const { return ranges.empty(); } bool empty() const { return ranges.empty(); }
@ -60,17 +60,17 @@ namespace llvm {
bool liveAt(unsigned index) const; bool liveAt(unsigned index) const;
bool overlaps(const Interval& other) const; bool overlaps(const LiveInterval& other) const;
void addRange(unsigned start, unsigned end); void addRange(unsigned start, unsigned end);
void join(const Interval& other); void join(const LiveInterval& other);
bool operator<(const Interval& other) const { bool operator<(const LiveInterval& other) const {
return start() < other.start(); return start() < other.start();
} }
bool operator==(const Interval& other) const { bool operator==(const LiveInterval& other) const {
return reg == other.reg; return reg == other.reg;
} }
@ -79,12 +79,12 @@ namespace llvm {
Ranges::iterator mergeRangesBackward(Ranges::iterator it); Ranges::iterator mergeRangesBackward(Ranges::iterator it);
}; };
std::ostream& operator<<(std::ostream& os, const Interval& li); std::ostream& operator<<(std::ostream& os, const LiveInterval& li);
class LiveIntervals : public MachineFunctionPass class LiveIntervals : public MachineFunctionPass
{ {
public: public:
typedef std::list<Interval> Intervals; typedef std::list<LiveInterval> Intervals;
private: private:
MachineFunction* mf_; MachineFunction* mf_;
@ -148,7 +148,7 @@ namespace llvm {
/// runOnMachineFunction - pass entry point /// runOnMachineFunction - pass entry point
virtual bool runOnMachineFunction(MachineFunction&); virtual bool runOnMachineFunction(MachineFunction&);
Interval& getInterval(unsigned reg) { LiveInterval& getInterval(unsigned reg) {
assert(r2iMap_.count(reg)&& "Interval does not exist for register"); assert(r2iMap_.count(reg)&& "Interval does not exist for register");
return *r2iMap_.find(reg)->second; return *r2iMap_.find(reg)->second;
} }
@ -162,7 +162,7 @@ namespace llvm {
Intervals& getIntervals() { return intervals_; } Intervals& getIntervals() { return intervals_; }
std::vector<Interval*> addIntervalsForSpills(const Interval& i, std::vector<LiveInterval*> addIntervalsForSpills(const LiveInterval& i,
VirtRegMap& vrm, VirtRegMap& vrm,
int slot); int slot);
@ -184,18 +184,19 @@ namespace llvm {
/// register def /// register def
void handleVirtualRegisterDef(MachineBasicBlock* mbb, void handleVirtualRegisterDef(MachineBasicBlock* mbb,
MachineBasicBlock::iterator mi, MachineBasicBlock::iterator mi,
Interval& interval); LiveInterval& interval);
/// handlePhysicalRegisterDef - update intervals for a /// handlePhysicalRegisterDef - update intervals for a
/// physical register def /// physical register def
void handlePhysicalRegisterDef(MachineBasicBlock* mbb, void handlePhysicalRegisterDef(MachineBasicBlock* mbb,
MachineBasicBlock::iterator mi, MachineBasicBlock::iterator mi,
Interval& interval); LiveInterval& interval);
bool overlapsAliases(const Interval& lhs, const Interval& rhs) const; bool overlapsAliases(const LiveInterval& lhs,
const LiveInterval& rhs) const;
Interval& getOrCreateInterval(unsigned reg); LiveInterval& getOrCreateInterval(unsigned reg);
/// rep - returns the representative of this register /// rep - returns the representative of this register
unsigned rep(unsigned reg); unsigned rep(unsigned reg);

View File

@ -39,7 +39,7 @@ namespace {
const TargetMachine* tm_; const TargetMachine* tm_;
const MRegisterInfo* mri_; const MRegisterInfo* mri_;
LiveIntervals* li_; LiveIntervals* li_;
typedef std::list<Interval*> IntervalPtrs; typedef std::list<LiveInterval*> IntervalPtrs;
IntervalPtrs unhandled_, fixed_, active_, inactive_, handled_; IntervalPtrs unhandled_, fixed_, active_, inactive_, handled_;
std::auto_ptr<PhysRegTracker> prt_; std::auto_ptr<PhysRegTracker> prt_;
@ -374,12 +374,12 @@ void RA::assignRegOrStackSlotAtInterval(IntervalPtrs::value_type cur)
if (cur->weight <= minWeight) { if (cur->weight <= minWeight) {
DEBUG(std::cerr << "\t\t\tspilling(c): " << *cur << '\n';); DEBUG(std::cerr << "\t\t\tspilling(c): " << *cur << '\n';);
int slot = vrm_->assignVirt2StackSlot(cur->reg); int slot = vrm_->assignVirt2StackSlot(cur->reg);
std::vector<Interval*> added = std::vector<LiveInterval*> added =
li_->addIntervalsForSpills(*cur, *vrm_, slot); li_->addIntervalsForSpills(*cur, *vrm_, slot);
// merge added with unhandled // merge added with unhandled
std::vector<Interval*>::iterator addedIt = added.begin(); std::vector<LiveInterval*>::iterator addedIt = added.begin();
std::vector<Interval*>::iterator addedItEnd = added.end(); std::vector<LiveInterval*>::iterator addedItEnd = added.end();
for (IntervalPtrs::iterator i = unhandled_.begin(), e = unhandled_.end(); for (IntervalPtrs::iterator i = unhandled_.begin(), e = unhandled_.end();
i != e && addedIt != addedItEnd; ++i) { i != e && addedIt != addedItEnd; ++i) {
if ((*i)->start() > (*addedIt)->start()) if ((*i)->start() > (*addedIt)->start())
@ -399,7 +399,7 @@ void RA::assignRegOrStackSlotAtInterval(IntervalPtrs::value_type cur)
// otherwise we spill all intervals aliasing the register with // otherwise we spill all intervals aliasing the register with
// minimum weight, rollback to the interval with the earliest // minimum weight, rollback to the interval with the earliest
// start point and let the linear scan algorithm run again // start point and let the linear scan algorithm run again
std::vector<Interval*> added; std::vector<LiveInterval*> added;
assert(MRegisterInfo::isPhysicalRegister(minReg) && assert(MRegisterInfo::isPhysicalRegister(minReg) &&
"did not choose a register to spill?"); "did not choose a register to spill?");
std::vector<bool> toSpill(mri_->getNumRegs(), false); std::vector<bool> toSpill(mri_->getNumRegs(), false);
@ -418,7 +418,7 @@ void RA::assignRegOrStackSlotAtInterval(IntervalPtrs::value_type cur)
DEBUG(std::cerr << "\t\t\tspilling(a): " << **i << '\n'); DEBUG(std::cerr << "\t\t\tspilling(a): " << **i << '\n');
earliestStart = std::min(earliestStart, (*i)->start()); earliestStart = std::min(earliestStart, (*i)->start());
int slot = vrm_->assignVirt2StackSlot((*i)->reg); int slot = vrm_->assignVirt2StackSlot((*i)->reg);
std::vector<Interval*> newIs = std::vector<LiveInterval*> newIs =
li_->addIntervalsForSpills(**i, *vrm_, slot); li_->addIntervalsForSpills(**i, *vrm_, slot);
std::copy(newIs.begin(), newIs.end(), std::back_inserter(added)); std::copy(newIs.begin(), newIs.end(), std::back_inserter(added));
spilled.insert(reg); spilled.insert(reg);
@ -433,7 +433,7 @@ void RA::assignRegOrStackSlotAtInterval(IntervalPtrs::value_type cur)
DEBUG(std::cerr << "\t\t\tspilling(i): " << **i << '\n'); DEBUG(std::cerr << "\t\t\tspilling(i): " << **i << '\n');
earliestStart = std::min(earliestStart, (*i)->start()); earliestStart = std::min(earliestStart, (*i)->start());
int slot = vrm_->assignVirt2StackSlot((*i)->reg); int slot = vrm_->assignVirt2StackSlot((*i)->reg);
std::vector<Interval*> newIs = std::vector<LiveInterval*> newIs =
li_->addIntervalsForSpills(**i, *vrm_, slot); li_->addIntervalsForSpills(**i, *vrm_, slot);
std::copy(newIs.begin(), newIs.end(), std::back_inserter(added)); std::copy(newIs.begin(), newIs.end(), std::back_inserter(added));
spilled.insert(reg); spilled.insert(reg);
@ -496,10 +496,10 @@ void RA::assignRegOrStackSlotAtInterval(IntervalPtrs::value_type cur)
} }
} }
std::sort(added.begin(), added.end(), less_ptr<Interval>()); std::sort(added.begin(), added.end(), less_ptr<LiveInterval>());
// merge added with unhandled // merge added with unhandled
std::vector<Interval*>::iterator addedIt = added.begin(); std::vector<LiveInterval*>::iterator addedIt = added.begin();
std::vector<Interval*>::iterator addedItEnd = added.end(); std::vector<LiveInterval*>::iterator addedItEnd = added.end();
for (IntervalPtrs::iterator i = unhandled_.begin(), e = unhandled_.end(); for (IntervalPtrs::iterator i = unhandled_.begin(), e = unhandled_.end();
i != e && addedIt != addedItEnd; ++i) { i != e && addedIt != addedItEnd; ++i) {
if ((*i)->start() > (*addedIt)->start()) if ((*i)->start() > (*addedIt)->start())