From a1613db62fec94845aa8306232fb665273615bad Mon Sep 17 00:00:00 2001 From: Alkis Evlogimenos Date: Sat, 24 Jul 2004 11:44:15 +0000 Subject: [PATCH] Change std::map into a std::map. This saves some space and removes the pointer indirection caused by following the pointer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15167 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/LiveInterval.h | 15 ++++++++ include/llvm/CodeGen/LiveIntervalAnalysis.h | 38 ++++++++++++--------- lib/CodeGen/LiveInterval.cpp | 4 +-- lib/CodeGen/LiveInterval.h | 15 ++++++++ lib/CodeGen/LiveIntervalAnalysis.cpp | 15 +++----- lib/CodeGen/LiveIntervalAnalysis.h | 38 ++++++++++++--------- lib/CodeGen/RegAllocIterativeScan.cpp | 6 ++-- lib/CodeGen/RegAllocLinearScan.cpp | 6 ++-- 8 files changed, 85 insertions(+), 52 deletions(-) diff --git a/include/llvm/CodeGen/LiveInterval.h b/include/llvm/CodeGen/LiveInterval.h index 75acf52c4ac..dde7a86712c 100644 --- a/include/llvm/CodeGen/LiveInterval.h +++ b/include/llvm/CodeGen/LiveInterval.h @@ -76,6 +76,21 @@ namespace llvm { : reg(Reg), weight(Weight), NumValues(0) { } + LiveInterval& operator=(const LiveInterval& rhs) { + reg = rhs.reg; + weight = rhs.weight; + ranges = rhs.ranges; + NumValues = rhs.NumValues; + return *this; + } + + void swap(LiveInterval& other) { + std::swap(reg, other.reg); + std::swap(weight, other.weight); + ranges.swap(other.ranges); + std::swap(NumValues, other.NumValues); + } + bool containsOneValue() const { return NumValues == 1; } unsigned getNextValue() { diff --git a/include/llvm/CodeGen/LiveIntervalAnalysis.h b/include/llvm/CodeGen/LiveIntervalAnalysis.h index c1fa5c591fb..e4e31ec2493 100644 --- a/include/llvm/CodeGen/LiveIntervalAnalysis.h +++ b/include/llvm/CodeGen/LiveIntervalAnalysis.h @@ -41,10 +41,8 @@ namespace llvm { typedef std::vector Index2MiMap; Index2MiMap i2miMap_; - /// r2iMap_ - This map OWNS the interval pointed to by the map. When - /// this map is destroyed or when entries are modified, this intervals - /// should be destroyed or modified as well. - std::map r2iMap_; + typedef std::map Reg2IntervalMap; + Reg2IntervalMap r2iMap_; typedef std::map Reg2RegMap; Reg2RegMap r2rMap_; @@ -80,16 +78,22 @@ namespace llvm { return getBaseIndex(index) + InstrSlots::STORE; } - typedef std::map::const_iterator iterator; - iterator begin() const { return r2iMap_.begin(); } - iterator end() const { return r2iMap_.end(); } - unsigned getNumIntervals() const { return r2iMap_.size(); } + // FIXME: this should really be a const_iterator + typedef Reg2IntervalMap::iterator iterator; + iterator begin() { return r2iMap_.begin(); } + iterator end() { return r2iMap_.end(); } + unsigned getNumIntervals() const { return r2iMap_.size(); } - LiveInterval &getInterval(unsigned reg) const { - std::map::const_iterator I = - r2iMap_.find(reg); + LiveInterval &getInterval(unsigned reg) { + Reg2IntervalMap::iterator I = r2iMap_.find(reg); assert(I != r2iMap_.end() && "Interval does not exist for register"); - return *I->second; + return I->second; + } + + const LiveInterval &getInterval(unsigned reg) const { + Reg2IntervalMap::const_iterator I = r2iMap_.find(reg); + assert(I != r2iMap_.end() && "Interval does not exist for register"); + return I->second; } /// getInstructionIndex - returns the base index of instr @@ -155,13 +159,13 @@ namespace llvm { bool overlapsAliases(const LiveInterval *lhs, const LiveInterval *rhs) const; - LiveInterval *createInterval(unsigned Reg) const; + static LiveInterval createInterval(unsigned Reg); LiveInterval &getOrCreateInterval(unsigned reg) { - LiveInterval *&LI = r2iMap_[reg]; - if (LI == 0) - LI = createInterval(reg); - return *LI; + Reg2IntervalMap::iterator I = r2iMap_.find(reg); + if (I == r2iMap_.end()) + I = r2iMap_.insert(I, std::make_pair(reg, createInterval(reg))); + return I->second; } /// rep - returns the representative of this register diff --git a/lib/CodeGen/LiveInterval.cpp b/lib/CodeGen/LiveInterval.cpp index 79aa710c03b..11eb0fe7de4 100644 --- a/lib/CodeGen/LiveInterval.cpp +++ b/lib/CodeGen/LiveInterval.cpp @@ -75,8 +75,8 @@ bool LiveInterval::overlaps(const LiveInterval& other) const { return true; if (i->start > j->start) { - swap(i, j); - swap(ie, je); + std::swap(i, j); + std::swap(ie, je); } assert(i->start < j->start); diff --git a/lib/CodeGen/LiveInterval.h b/lib/CodeGen/LiveInterval.h index 75acf52c4ac..dde7a86712c 100644 --- a/lib/CodeGen/LiveInterval.h +++ b/lib/CodeGen/LiveInterval.h @@ -76,6 +76,21 @@ namespace llvm { : reg(Reg), weight(Weight), NumValues(0) { } + LiveInterval& operator=(const LiveInterval& rhs) { + reg = rhs.reg; + weight = rhs.weight; + ranges = rhs.ranges; + NumValues = rhs.NumValues; + return *this; + } + + void swap(LiveInterval& other) { + std::swap(reg, other.reg); + std::swap(weight, other.weight); + ranges.swap(other.ranges); + std::swap(NumValues, other.NumValues); + } + bool containsOneValue() const { return NumValues == 1; } unsigned getNextValue() { diff --git a/lib/CodeGen/LiveIntervalAnalysis.cpp b/lib/CodeGen/LiveIntervalAnalysis.cpp index 6021e9e56ff..c21a9c05401 100644 --- a/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -76,11 +76,7 @@ void LiveIntervals::releaseMemory() { mi2iMap_.clear(); i2miMap_.clear(); - for (std::map::iterator I = r2iMap_.begin(), - E = r2iMap_.end(); I != E; ++I) - delete I->second; // free all intervals. r2iMap_.clear(); - r2rMap_.clear(); } @@ -112,7 +108,7 @@ bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) { #if 1 DEBUG(std::cerr << "********** INTERVALS **********\n"); DEBUG(for (iterator I = begin(), E = end(); I != E; ++I) - std::cerr << *I->second << "\n"); + std::cerr << I->second << "\n"); #endif // join intervals if requested @@ -169,7 +165,7 @@ bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) { DEBUG(std::cerr << "********** INTERVALS **********\n"); DEBUG (for (iterator I = begin(), E = end(); I != E; ++I) - std::cerr << *I->second << "\n"); + std::cerr << I->second << "\n"); DEBUG(std::cerr << "********** MACHINEINSTRS **********\n"); DEBUG( for (MachineFunction::iterator mbbi = mf_->begin(), mbbe = mf_->end(); @@ -561,7 +557,6 @@ void LiveIntervals::joinIntervalsInMachineBB(MachineBasicBlock *MBB) { if ((TriviallyJoinable || !IntB.joinable(IntA, MIDefIdx)) && !overlapsAliases(&IntA, &IntB)) { IntB.join(IntA, MIDefIdx); - delete r2iMap_[regA]; // Delete the dead interval if (!MRegisterInfo::isPhysicalRegister(regA)) { r2iMap_.erase(regA); @@ -571,7 +566,7 @@ void LiveIntervals::joinIntervalsInMachineBB(MachineBasicBlock *MBB) { // the physreg information. r2rMap_[regB] = regA; IntB.reg = regA; - r2iMap_[regA] = r2iMap_[regB]; + IntA.swap(IntB); r2iMap_.erase(regB); } DEBUG(std::cerr << "Joined. Result = " << IntB << "\n"); @@ -661,8 +656,8 @@ bool LiveIntervals::overlapsAliases(const LiveInterval *LHS, return false; } -LiveInterval *LiveIntervals::createInterval(unsigned reg) const { +LiveInterval LiveIntervals::createInterval(unsigned reg) { float Weight = MRegisterInfo::isPhysicalRegister(reg) ? HUGE_VAL :0.0F; - return new LiveInterval(reg, Weight); + return LiveInterval(reg, Weight); } diff --git a/lib/CodeGen/LiveIntervalAnalysis.h b/lib/CodeGen/LiveIntervalAnalysis.h index c1fa5c591fb..e4e31ec2493 100644 --- a/lib/CodeGen/LiveIntervalAnalysis.h +++ b/lib/CodeGen/LiveIntervalAnalysis.h @@ -41,10 +41,8 @@ namespace llvm { typedef std::vector Index2MiMap; Index2MiMap i2miMap_; - /// r2iMap_ - This map OWNS the interval pointed to by the map. When - /// this map is destroyed or when entries are modified, this intervals - /// should be destroyed or modified as well. - std::map r2iMap_; + typedef std::map Reg2IntervalMap; + Reg2IntervalMap r2iMap_; typedef std::map Reg2RegMap; Reg2RegMap r2rMap_; @@ -80,16 +78,22 @@ namespace llvm { return getBaseIndex(index) + InstrSlots::STORE; } - typedef std::map::const_iterator iterator; - iterator begin() const { return r2iMap_.begin(); } - iterator end() const { return r2iMap_.end(); } - unsigned getNumIntervals() const { return r2iMap_.size(); } + // FIXME: this should really be a const_iterator + typedef Reg2IntervalMap::iterator iterator; + iterator begin() { return r2iMap_.begin(); } + iterator end() { return r2iMap_.end(); } + unsigned getNumIntervals() const { return r2iMap_.size(); } - LiveInterval &getInterval(unsigned reg) const { - std::map::const_iterator I = - r2iMap_.find(reg); + LiveInterval &getInterval(unsigned reg) { + Reg2IntervalMap::iterator I = r2iMap_.find(reg); assert(I != r2iMap_.end() && "Interval does not exist for register"); - return *I->second; + return I->second; + } + + const LiveInterval &getInterval(unsigned reg) const { + Reg2IntervalMap::const_iterator I = r2iMap_.find(reg); + assert(I != r2iMap_.end() && "Interval does not exist for register"); + return I->second; } /// getInstructionIndex - returns the base index of instr @@ -155,13 +159,13 @@ namespace llvm { bool overlapsAliases(const LiveInterval *lhs, const LiveInterval *rhs) const; - LiveInterval *createInterval(unsigned Reg) const; + static LiveInterval createInterval(unsigned Reg); LiveInterval &getOrCreateInterval(unsigned reg) { - LiveInterval *&LI = r2iMap_[reg]; - if (LI == 0) - LI = createInterval(reg); - return *LI; + Reg2IntervalMap::iterator I = r2iMap_.find(reg); + if (I == r2iMap_.end()) + I = r2iMap_.insert(I, std::make_pair(reg, createInterval(reg))); + return I->second; } /// rep - returns the representative of this register diff --git a/lib/CodeGen/RegAllocIterativeScan.cpp b/lib/CodeGen/RegAllocIterativeScan.cpp index d2f5d5b0bfe..e9e9fd8e136 100644 --- a/lib/CodeGen/RegAllocIterativeScan.cpp +++ b/lib/CodeGen/RegAllocIterativeScan.cpp @@ -257,9 +257,9 @@ void RA::initIntervalSets() { "interval sets should be empty on initialization"); for (LiveIntervals::iterator i = li_->begin(), e = li_->end(); i != e; ++i){ - unhandled_.push_back(i->second); - if (MRegisterInfo::isPhysicalRegister(i->second->reg)) - fixed_.push_back(i->second); + unhandled_.push_back(&i->second); + if (MRegisterInfo::isPhysicalRegister(i->second.reg)) + fixed_.push_back(&i->second); } } diff --git a/lib/CodeGen/RegAllocLinearScan.cpp b/lib/CodeGen/RegAllocLinearScan.cpp index 382cff4ad7c..694be5f7f1a 100644 --- a/lib/CodeGen/RegAllocLinearScan.cpp +++ b/lib/CodeGen/RegAllocLinearScan.cpp @@ -224,9 +224,9 @@ void RA::initIntervalSets() "interval sets should be empty on initialization"); for (LiveIntervals::iterator i = li_->begin(), e = li_->end(); i != e; ++i){ - unhandled_.push(i->second); - if (MRegisterInfo::isPhysicalRegister(i->second->reg)) - fixed_.push_back(i->second); + unhandled_.push(&i->second); + if (MRegisterInfo::isPhysicalRegister(i->second.reg)) + fixed_.push_back(&i->second); } }