[llvm-commits] [regalloc_linearscan] CVS: llvm/include/llvm/CodeGen/LiveIntervals.h
Alkis Evlogimenos
alkis at cs.uiuc.edu
Wed Nov 12 00:51:12 PST 2003
Changes in directory llvm/include/llvm/CodeGen:
LiveIntervals.h updated: 1.1.2.7 -> 1.1.2.8
---
Log message:
Put classes the were developed in the regalloc_linearscan branch in
the llvm namespace.
---
Diffs of the changes: (+142 -139)
Index: llvm/include/llvm/CodeGen/LiveIntervals.h
diff -u llvm/include/llvm/CodeGen/LiveIntervals.h:1.1.2.7 llvm/include/llvm/CodeGen/LiveIntervals.h:1.1.2.8
--- llvm/include/llvm/CodeGen/LiveIntervals.h:1.1.2.7 Fri Nov 7 18:23:05 2003
+++ llvm/include/llvm/CodeGen/LiveIntervals.h Wed Nov 12 00:49:56 2003
@@ -26,172 +26,175 @@
#include <iostream>
#include <map>
-class LiveVariables;
-class MRegisterInfo;
+namespace llvm {
-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
- Ranges ranges; // the ranges this register is valid
+ class LiveVariables;
+ class MRegisterInfo;
- Interval(unsigned r)
- : reg(r) {
+ 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
+ Ranges ranges; // the ranges this register is valid
- }
-
- unsigned start() const {
- assert(!ranges.empty() && "empty interval for register");
- return ranges.front().first;
- }
+ Interval(unsigned r)
+ : reg(r) {
- unsigned end() const {
- assert(!ranges.empty() && "empty interval for register");
- return ranges.back().second;
- }
+ }
- bool expired(unsigned index) const {
- return end() <= index;
- }
+ unsigned start() const {
+ assert(!ranges.empty() && "empty interval for register");
+ return ranges.front().first;
+ }
- bool overlaps(unsigned index) const {
- for (Ranges::const_iterator i = ranges.begin(), e = ranges.end();
- i != e; ++i) {
- if (index >= i->first && index < i->second) {
- return true;
- }
+ unsigned end() const {
+ assert(!ranges.empty() && "empty interval for register");
+ return ranges.back().second;
}
- return false;
- }
- void addRange(unsigned start, unsigned end) {
- Range range = std::make_pair(start, end);
- Ranges::iterator it =
- std::lower_bound(ranges.begin(), ranges.end(), range);
-
- if (it == ranges.end()) {
- it = ranges.insert(it, range);
- goto exit;
+ bool expired(unsigned index) const {
+ return end() <= index;
}
- assert(range.first <= it->first && "got wrong iterator?");
- // merge ranges if necesary
- if (range.first < it->first) {
- if (range.second >= it->first) {
- it->first = range.first;
+ bool overlaps(unsigned index) const {
+ for (Ranges::const_iterator
+ i = ranges.begin(), e = ranges.end(); i != e; ++i) {
+ if (index >= i->first && index < i->second) {
+ return true;
+ }
}
- else {
+ return false;
+ }
+
+ void addRange(unsigned start, unsigned end) {
+ Range range = std::make_pair(start, end);
+ Ranges::iterator it =
+ std::lower_bound(ranges.begin(), ranges.end(), range);
+
+ if (it == ranges.end()) {
it = ranges.insert(it, range);
- assert(it != ranges.end() && "wtf?");
goto exit;
}
+
+ assert(range.first <= it->first && "got wrong iterator?");
+ // merge ranges if necesary
+ if (range.first < it->first) {
+ if (range.second >= it->first) {
+ it->first = range.first;
+ }
+ else {
+ it = ranges.insert(it, range);
+ assert(it != ranges.end() && "wtf?");
+ goto exit;
+ }
+ }
+
+ exit:
+ mergeRangesIfNecessary(it);
}
- exit:
- mergeRangesIfNecessary(it);
- }
+ private:
+ void mergeRangesIfNecessary(Ranges::iterator it) {
+ while (it != ranges.begin()) {
+ Ranges::iterator prev = it - 1;
+ if (prev->second < it->first) {
+ break;
+ }
+ prev->second = it->second;
+ ranges.erase(it);
+ it = prev;
+ }
+ }
+ };
+
+ struct StartPointComp {
+ bool operator()(const Interval& lhs, const Interval& rhs) {
+ return lhs.ranges.front().first < rhs.ranges.front().first;
+ }
+ };
+
+ struct EndPointComp {
+ bool operator()(const Interval& lhs, const Interval& rhs) {
+ return lhs.ranges.back().second < rhs.ranges.back().second;
+ }
+ };
+
+ typedef std::vector<Interval> Intervals;
+ typedef std::map<unsigned, MachineBasicBlock*> MiIndex2MbbMap;
+ typedef std::map<MachineBasicBlock*, unsigned> Mbb2MiIndexMap;
+ typedef std::vector<MachineBasicBlock*> MachineBasicBlockPtrs;
private:
- void mergeRangesIfNecessary(Ranges::iterator it) {
- while (it != ranges.begin()) {
- Ranges::iterator prev = it - 1;
- if (prev->second < it->first) {
- break;
- }
- prev->second = it->second;
- ranges.erase(it);
- it = prev;
+ MachineFunction* mf_;
+ const TargetMachine* tm_;
+ const MRegisterInfo* mri_;
+ MachineBasicBlock* currentMbb_;
+ MachineBasicBlock::iterator currentInstr_;
+ LiveVariables* lv_;
+
+ typedef std::map<unsigned, MachineBasicBlock*> MbbIndex2MbbMap;
+ MbbIndex2MbbMap mbbi2mbbMap_;
+
+ typedef std::map<MachineInstr*, unsigned> Mi2IndexMap;
+ Mi2IndexMap mi2iMap_;
+
+ typedef std::map<unsigned, unsigned> Reg2IntervalMap;
+ Reg2IntervalMap r2iMap_;
+
+ Intervals intervals_;
+ MiIndex2MbbMap mii2mbbMap_;
+ Mbb2MiIndexMap mbb2miiMap_;
+
+ public:
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const;
+ const Intervals& getIntervals() const { return intervals_; }
+ MiIndex2MbbMap& getMiIndex2MbbMap() { return mii2mbbMap_; }
+ Mbb2MiIndexMap& getMbb2MiIndexMap() { return mbb2miiMap_; }
+ MachineBasicBlockPtrs getOrderedMachineBasicBlockPtrs() const {
+ MachineBasicBlockPtrs result;
+ for (MbbIndex2MbbMap::const_iterator
+ it = mbbi2mbbMap_.begin(), itEnd = mbbi2mbbMap_.end();
+ it != itEnd; ++it) {
+ result.push_back(it->second);
}
+ return result;
}
- };
- struct StartPointComp {
- bool operator()(const Interval& lhs, const Interval& rhs) {
- return lhs.ranges.front().first < rhs.ranges.front().first;
- }
- };
+ private:
+ /// runOnMachineFunction - pass entry point
+ bool runOnMachineFunction(MachineFunction&);
- struct EndPointComp {
- bool operator()(const Interval& lhs, const Interval& rhs) {
- return lhs.ranges.back().second < rhs.ranges.back().second;
- }
+ /// computeIntervals - compute live intervals
+ void computeIntervals();
+
+ /// handleRegisterDef - update intervals for a register def
+ void handleRegisterDef(MachineBasicBlock* mbb,
+ MachineInstr* instr,
+ unsigned reg);
+
+ unsigned getInstructionIndex(MachineInstr* instr) const;
+
+ void printRegName(unsigned reg) const;
};
- typedef std::vector<Interval> Intervals;
- typedef std::map<unsigned, MachineBasicBlock*> MiIndex2MbbMap;
- typedef std::map<MachineBasicBlock*, unsigned> Mbb2MiIndexMap;
- typedef std::vector<MachineBasicBlock*> MachineBasicBlockPtrs;
-
-private:
- MachineFunction* mf_;
- const TargetMachine* tm_;
- const MRegisterInfo* mri_;
- MachineBasicBlock* currentMbb_;
- MachineBasicBlock::iterator currentInstr_;
- LiveVariables* lv_;
-
- typedef std::map<unsigned, MachineBasicBlock*> MbbIndex2MbbMap;
- MbbIndex2MbbMap mbbi2mbbMap_;
-
- typedef std::map<MachineInstr*, unsigned> Mi2IndexMap;
- Mi2IndexMap mi2iMap_;
-
- typedef std::map<unsigned, unsigned> Reg2IntervalMap;
- Reg2IntervalMap r2iMap_;
-
- Intervals intervals_;
- MiIndex2MbbMap mii2mbbMap_;
- Mbb2MiIndexMap mbb2miiMap_;
-
-public:
- virtual void getAnalysisUsage(AnalysisUsage &AU) const;
- const Intervals& getIntervals() const { return intervals_; }
- MiIndex2MbbMap& getMiIndex2MbbMap() { return mii2mbbMap_; }
- Mbb2MiIndexMap& getMbb2MiIndexMap() { return mbb2miiMap_; }
- MachineBasicBlockPtrs getOrderedMachineBasicBlockPtrs() const {
- MachineBasicBlockPtrs result;
- for (MbbIndex2MbbMap::const_iterator
- it = mbbi2mbbMap_.begin(), itEnd = mbbi2mbbMap_.end();
- it != itEnd; ++it) {
- result.push_back(it->second);
- }
- return result;
+ inline bool operator==(const LiveIntervals::Interval& lhs,
+ const LiveIntervals::Interval& rhs) {
+ return lhs.reg == rhs.reg;
}
-private:
- /// runOnMachineFunction - pass entry point
- bool runOnMachineFunction(MachineFunction&);
-
- /// computeIntervals - compute live intervals
- void computeIntervals();
-
- /// handleRegisterDef - update intervals for a register def
- void handleRegisterDef(MachineBasicBlock* mbb,
- MachineInstr* instr,
- unsigned reg);
-
- unsigned getInstructionIndex(MachineInstr* instr) const;
-
- void printRegName(unsigned reg) const;
-};
-
-inline bool operator==(const LiveIntervals::Interval& lhs,
- const LiveIntervals::Interval& rhs) {
- return lhs.reg == rhs.reg;
-}
-
-inline std::ostream& operator<<(std::ostream& os,
- const LiveIntervals::Interval& li) {
- os << "%reg" << li.reg << " = ";
- for (LiveIntervals::Interval::Ranges::const_iterator
- i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) {
- os << "[" << i->first << ", " << i->second << "]";
+ inline std::ostream& operator<<(std::ostream& os,
+ const LiveIntervals::Interval& li) {
+ os << "%reg" << li.reg << " = ";
+ for (LiveIntervals::Interval::Ranges::const_iterator
+ i = li.ranges.begin(), e = li.ranges.end(); i != e; ++i) {
+ os << "[" << i->first << ", " << i->second << "]";
+ }
+ return os;
}
- return os;
-}
+} // End llvm namespace
#endif
More information about the llvm-commits
mailing list