No need to clear the map here, it will always be empty
[oota-llvm.git] / lib / CodeGen / LiveIntervalAnalysis.h
index f322ae33c91c4c59722422b5feb041c5ef14e801..24bc8956b3f94b1caedc5a73f7b1f33c59e915f5 100644 (file)
@@ -42,13 +42,17 @@ namespace llvm {
 
             Interval(unsigned r);
 
+            bool empty() const { return ranges.empty(); }
+
+            bool spilled() const;
+
             unsigned start() const {
-                assert(!ranges.empty() && "empty interval for register");
+                assert(!empty() && "empty interval for register");
                 return ranges.front().first;
             }
 
             unsigned end() const {
-                assert(!ranges.empty() && "empty interval for register");
+                assert(!empty() && "empty interval for register");
                 return ranges.back().second;
             }
 
@@ -83,8 +87,6 @@ namespace llvm {
         };
 
         typedef std::list<Interval> Intervals;
-        typedef std::map<unsigned, unsigned> Reg2RegMap;
-        typedef std::vector<MachineBasicBlock*> MachineBasicBlockPtrs;
 
     private:
         MachineFunction* mf_;
@@ -100,28 +102,69 @@ namespace llvm {
         typedef std::map<MachineInstr*, unsigned> Mi2IndexMap;
         Mi2IndexMap mi2iMap_;
 
+        typedef std::vector<MachineInstr*> Index2MiMap;
+        Index2MiMap i2miMap_;
+
         typedef std::map<unsigned, Intervals::iterator> Reg2IntervalMap;
         Reg2IntervalMap r2iMap_;
 
+        typedef std::map<unsigned, unsigned> Reg2RegMap;
         Reg2RegMap r2rMap_;
 
         Intervals intervals_;
 
     public:
+        struct InstrSlots
+        {
+            enum {
+                LOAD  = 0,
+                USE   = 1,
+                DEF   = 2,
+                STORE = 3,
+                NUM   = 4,
+            };
+        };
+
+        static unsigned getBaseIndex(unsigned index) {
+            return index - (index % InstrSlots::NUM);
+        }
+        static unsigned getBoundaryIndex(unsigned index) {
+            return getBaseIndex(index + InstrSlots::NUM - 1);
+        }
+        static unsigned getLoadIndex(unsigned index) {
+            return getBaseIndex(index) + InstrSlots::LOAD;
+        }
+        static unsigned getUseIndex(unsigned index) {
+            return getBaseIndex(index) + InstrSlots::USE;
+        }
+        static unsigned getDefIndex(unsigned index) {
+            return getBaseIndex(index) + InstrSlots::DEF;
+        }
+        static unsigned getStoreIndex(unsigned index) {
+            return getBaseIndex(index) + InstrSlots::STORE;
+        }
+
         virtual void getAnalysisUsage(AnalysisUsage &AU) const;
         virtual void releaseMemory();
 
         /// runOnMachineFunction - pass entry point
         virtual bool runOnMachineFunction(MachineFunction&);
 
-        Intervals& getIntervals() { return intervals_; }
-
-        const Reg2RegMap& getJoinedRegMap() const {
-            return r2rMap_;
+        Interval& getInterval(unsigned reg) {
+            assert(r2iMap_.count(reg)&& "Interval does not exist for register");
+            return *r2iMap_.find(reg)->second;
         }
 
-        /// rep - returns the representative of this register
-        unsigned rep(unsigned reg);
+        /// getInstructionIndex - returns the base index of instr
+        unsigned getInstructionIndex(MachineInstr* instr) const;
+
+        /// getInstructionFromIndex - given an index in any slot of an
+        /// instruction return a pointer the instruction
+        MachineInstr* getInstructionFromIndex(unsigned index) const;
+
+        Intervals& getIntervals() { return intervals_; }
+
+        void updateSpilledInterval(Interval& i, int slot);
 
     private:
         /// computeIntervals - compute live intervals
@@ -151,7 +194,8 @@ namespace llvm {
 
         bool overlapsAliases(const Interval& lhs, const Interval& rhs) const;
 
-        unsigned getInstructionIndex(MachineInstr* instr) const;
+        /// rep - returns the representative of this register
+        unsigned rep(unsigned reg);
 
         void printRegName(unsigned reg) const;
     };