[llvm-commits] CVS: llvm/lib/CodeGen/RegAllocLinearScan.cpp RegAllocIterativeScan.cpp LiveIntervalAnalysis.h LiveIntervalAnalysis.cpp LiveInterval.h LiveInterval.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Sat Jul 24 04:44:25 PDT 2004



Changes in directory llvm/lib/CodeGen:

RegAllocLinearScan.cpp updated: 1.84 -> 1.85
RegAllocIterativeScan.cpp updated: 1.9 -> 1.10
LiveIntervalAnalysis.h updated: 1.37 -> 1.38
LiveIntervalAnalysis.cpp updated: 1.110 -> 1.111
LiveInterval.h updated: 1.5 -> 1.6
LiveInterval.cpp updated: 1.6 -> 1.7

---
Log message:

Change std::map<unsigned, LiveInterval*> into a std::map<unsigned,
LiveInterval>. This saves some space and removes the pointer
indirection caused by following the pointer.


---
Diffs of the changes:  (+50 -36)

Index: llvm/lib/CodeGen/RegAllocLinearScan.cpp
diff -u llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.84 llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.85
--- llvm/lib/CodeGen/RegAllocLinearScan.cpp:1.84	Fri Jul 23 22:32:06 2004
+++ llvm/lib/CodeGen/RegAllocLinearScan.cpp	Sat Jul 24 06:44:15 2004
@@ -224,9 +224,9 @@
            "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);
     }
 }
 


Index: llvm/lib/CodeGen/RegAllocIterativeScan.cpp
diff -u llvm/lib/CodeGen/RegAllocIterativeScan.cpp:1.9 llvm/lib/CodeGen/RegAllocIterativeScan.cpp:1.10
--- llvm/lib/CodeGen/RegAllocIterativeScan.cpp:1.9	Fri Jul 23 22:32:06 2004
+++ llvm/lib/CodeGen/RegAllocIterativeScan.cpp	Sat Jul 24 06:44:15 2004
@@ -257,9 +257,9 @@
            "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: llvm/lib/CodeGen/LiveIntervalAnalysis.h
diff -u llvm/lib/CodeGen/LiveIntervalAnalysis.h:1.37 llvm/lib/CodeGen/LiveIntervalAnalysis.h:1.38
--- llvm/lib/CodeGen/LiveIntervalAnalysis.h:1.37	Fri Jul 23 22:32:06 2004
+++ llvm/lib/CodeGen/LiveIntervalAnalysis.h	Sat Jul 24 06:44:15 2004
@@ -41,10 +41,8 @@
         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 @@
             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(); }
-
-        LiveInterval &getInterval(unsigned reg) const {
-          std::map<unsigned, LiveInterval*>::const_iterator I =
-              r2iMap_.find(reg);
+        // 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) {
+          Reg2IntervalMap::iterator I = r2iMap_.find(reg);
+          assert(I != r2iMap_.end() && "Interval does not exist for register");
+          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;
+          return I->second;
         }
 
         /// getInstructionIndex - returns the base index of instr
@@ -155,13 +159,13 @@
         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: llvm/lib/CodeGen/LiveIntervalAnalysis.cpp
diff -u llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.110 llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.111
--- llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.110	Fri Jul 23 23:32:22 2004
+++ llvm/lib/CodeGen/LiveIntervalAnalysis.cpp	Sat Jul 24 06:44:15 2004
@@ -76,11 +76,7 @@
 {
     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 @@
 #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 @@
 
     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 @@
       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 @@
           // 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 @@
   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: llvm/lib/CodeGen/LiveInterval.h
diff -u llvm/lib/CodeGen/LiveInterval.h:1.5 llvm/lib/CodeGen/LiveInterval.h:1.6
--- llvm/lib/CodeGen/LiveInterval.h:1.5	Fri Jul 23 21:52:23 2004
+++ llvm/lib/CodeGen/LiveInterval.h	Sat Jul 24 06:44:15 2004
@@ -76,6 +76,21 @@
       : 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: llvm/lib/CodeGen/LiveInterval.cpp
diff -u llvm/lib/CodeGen/LiveInterval.cpp:1.6 llvm/lib/CodeGen/LiveInterval.cpp:1.7
--- llvm/lib/CodeGen/LiveInterval.cpp:1.6	Fri Jul 23 22:41:50 2004
+++ llvm/lib/CodeGen/LiveInterval.cpp	Sat Jul 24 06:44:15 2004
@@ -75,8 +75,8 @@
       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);
 





More information about the llvm-commits mailing list