Change std::map<unsigned, LiveInterval*> into a std::map<unsigned,
authorAlkis Evlogimenos <alkis@evlogimenos.com>
Sat, 24 Jul 2004 11:44:15 +0000 (11:44 +0000)
committerAlkis Evlogimenos <alkis@evlogimenos.com>
Sat, 24 Jul 2004 11:44:15 +0000 (11:44 +0000)
LiveInterval>. 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
include/llvm/CodeGen/LiveIntervalAnalysis.h
lib/CodeGen/LiveInterval.cpp
lib/CodeGen/LiveInterval.h
lib/CodeGen/LiveIntervalAnalysis.cpp
lib/CodeGen/LiveIntervalAnalysis.h
lib/CodeGen/RegAllocIterativeScan.cpp
lib/CodeGen/RegAllocLinearScan.cpp

index 75acf52c4acce2d9df3e488971afa7c1f785c6b5..dde7a86712cdc583e25b08c4867c78558546eb6e 100644 (file)
@@ -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() {
index c1fa5c591fbdb46e9f929ecaaec09302c7370933..e4e31ec24933da3a090527714d857f19e46fac73 100644 (file)
@@ -41,10 +41,8 @@ namespace llvm {
         typedef std::vector<MachineInstr*> 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<unsigned, LiveInterval*> r2iMap_;
+        typedef std::map<unsigned, LiveInterval> Reg2IntervalMap;
+        Reg2IntervalMap r2iMap_;
 
         typedef std::map<unsigned, unsigned> Reg2RegMap;
         Reg2RegMap r2rMap_;
@@ -80,16 +78,22 @@ namespace llvm {
             return getBaseIndex(index) + InstrSlots::STORE;
         }
 
-        typedef std::map<unsigned, LiveInterval*>::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<unsigned, LiveInterval*>::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
index 79aa710c03b94f1564b0ec2543588444d2fb1488..11eb0fe7de4ee4e51fd67309a44be44cae18e8b2 100644 (file)
@@ -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);
 
index 75acf52c4acce2d9df3e488971afa7c1f785c6b5..dde7a86712cdc583e25b08c4867c78558546eb6e 100644 (file)
@@ -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() {
index 6021e9e56ff7f320e4d4e55618608f31f901161c..c21a9c05401e0699bd511c5e5a6a3a372c179b17 100644 (file)
@@ -76,11 +76,7 @@ void LiveIntervals::releaseMemory()
 {
     mi2iMap_.clear();
     i2miMap_.clear();
-    for (std::map<unsigned, LiveInterval*>::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);
 }
 
index c1fa5c591fbdb46e9f929ecaaec09302c7370933..e4e31ec24933da3a090527714d857f19e46fac73 100644 (file)
@@ -41,10 +41,8 @@ namespace llvm {
         typedef std::vector<MachineInstr*> 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<unsigned, LiveInterval*> r2iMap_;
+        typedef std::map<unsigned, LiveInterval> Reg2IntervalMap;
+        Reg2IntervalMap r2iMap_;
 
         typedef std::map<unsigned, unsigned> Reg2RegMap;
         Reg2RegMap r2rMap_;
@@ -80,16 +78,22 @@ namespace llvm {
             return getBaseIndex(index) + InstrSlots::STORE;
         }
 
-        typedef std::map<unsigned, LiveInterval*>::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<unsigned, LiveInterval*>::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
index d2f5d5b0bfe1f7d396ca8dfbeddb3855680a06e5..e9e9fd8e13603b4a5c08b4c6761172ec3b7fd23a 100644 (file)
@@ -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);
     }
 }
 
index 382cff4ad7ca56a6da139d07a1900c27f32d9bd8..694be5f7f1a05d6e09104a15736a906cdd9fdb6f 100644 (file)
@@ -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);
     }
 }