Rewrote uses of deprecated `MachineFunction::get(BasicBlock *BB)'.
[oota-llvm.git] / lib / Target / SparcV9 / RegAlloc / PhyRegAlloc.h
index 9d34557b01efddb0ee26a4a17f201cb13185503b..12f0bf05ebf00c23265ed9fdfd070e249b78958b 100644 (file)
@@ -1,4 +1,4 @@
-/* Title:   PhyRegAlloc.h
+/* Title:   PhyRegAlloc.h   -*- C++ -*-
    Author:  Ruchira Sasanka
    Date:    Aug 20, 01
    Purpose: This is the main entry point for register allocation.
 
    Register allocation must be done  as:       
 
-      MethodLiveVarInfo LVI(*MethodI );           // compute LV info
+      FunctionLiveVarInfo LVI(*FunctionI );           // compute LV info
       LVI.analyze();
 
       TargetMachine &target = ....                             
 
 
-      PhyRegAlloc PRA(*MethodI, target, &LVI);     // allocate regs
+      PhyRegAlloc PRA(*FunctionI, target, &LVI);     // allocate regs
       PRA.allocateRegisters();
-
-
-
 */ 
 
 #ifndef PHY_REG_ALLOC_H
 #define PHY_REG_ALLOC_H
 
-#include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/CodeGen/RegClass.h"
 #include "llvm/CodeGen/LiveRangeInfo.h"
-#include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
-#include "llvm/Analysis/LoopDepth.h"
-
-#include <deque>
+#include <vector>
+#include <map>
 
+class MachineFunction;
+class MachineRegInfo;
+class FunctionLiveVarInfo;
+class MachineInstr;
+class LoopInfo;
 
 //----------------------------------------------------------------------------
 // Class AddedInstrns:
 // to store such instructions added before and after an existing instruction.
 //----------------------------------------------------------------------------
 
-class AddedInstrns
-{
- public:
-  deque<MachineInstr *> InstrnsBefore;  // Added insts BEFORE an existing inst
-  deque<MachineInstr *> InstrnsAfter;   // Added insts AFTER an existing inst
-
-  AddedInstrns() : InstrnsBefore(), InstrnsAfter() { }
+struct AddedInstrns {
+  std::vector<MachineInstr*> InstrnsBefore;//Insts added BEFORE an existing inst
+  std::vector<MachineInstr*> InstrnsAfter; //Insts added AFTER an existing inst
 };
 
-typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
+typedef std::map<const MachineInstr *, AddedInstrns> AddedInstrMapType;
 
 
 
 //----------------------------------------------------------------------------
 // class PhyRegAlloc:
 // Main class the register allocator. Call allocateRegisters() to allocate
-// registers for a Method.
+// registers for a Function.
 //----------------------------------------------------------------------------
 
 
-class PhyRegAlloc: public NonCopyable
-{
+class PhyRegAlloc: public NonCopyable {
 
-  vector<RegClass *> RegClassList  ;    // vector of register classes
+  std::vector<RegClass *> RegClassList; // vector of register classes
   const TargetMachine &TM;              // target machine
-  const Method* Meth;                   // name of the method we work on
-  MachineCodeForMethod& mcInfo;         // descriptor for method's native code
-  MethodLiveVarInfo *const LVI;         // LV information for this method 
+  const Function *Fn;                   // name of the function we work on
+  MachineFunction &MF;                  // descriptor for method's native code
+  FunctionLiveVarInfo *const LVI;       // LV information for this method 
                                         // (already computed for BBs) 
   LiveRangeInfo LRI;                    // LR info  (will be computed)
   const MachineRegInfo &MRI;            // Machine Register information
@@ -86,23 +80,45 @@ class PhyRegAlloc: public NonCopyable
 
   
   AddedInstrMapType AddedInstrMap;      // to store instrns added in this phase
-  LoopDepthCalculator LoopDepthCalc;    // to calculate loop depths 
+  AddedInstrns AddedInstrAtEntry;       // to store instrns added at entry
+  LoopInfo *LoopDepthCalc;              // to calculate loop depths 
   ReservedColorListType ResColList;     // A set of reserved regs if desired.
                                         // currently not used
 
+public:
+  PhyRegAlloc(Function *F, const TargetMachine& TM, FunctionLiveVarInfo *Lvi,
+              LoopInfo *LoopDepthCalc);
+  ~PhyRegAlloc();
+
+  // main method called for allocating registers
+  //
+  void allocateRegisters();           
+
+
+  // access to register classes by class ID
+  // 
+  const RegClass*  getRegClassByID(unsigned int id) const {
+                                                    return RegClassList[id];
+  }
+        RegClass*  getRegClassByID(unsigned int id)       {
+                                                    return RegClassList[id]; }
+  
+  
+private:
+
 
 
   //------- ------------------ private methods---------------------------------
 
-  void addInterference(const Value *const Def, const LiveVarSet *const LVSet, 
-                      const bool isCallInst);
+  void addInterference(const Value *Def, const ValueSet *LVSet, 
+                      bool isCallInst);
 
   void addInterferencesForArgs();
   void createIGNodeListsAndIGs();
   void buildInterferenceGraphs();
 
   void setCallInterferences(const MachineInstr *MInst, 
-                           const LiveVarSet *const LVSetAft );
+                           const ValueSet *LVSetAft );
 
   void move2DelayedInstr(const MachineInstr *OrigMI, 
                         const MachineInstr *DelayedMI );
@@ -115,8 +131,7 @@ class PhyRegAlloc: public NonCopyable
                                  const BasicBlock *BB,
                                  const unsigned OpNum);
 
-  inline void constructLiveRanges() 
-    { LRI.constructLiveRanges(); }      
+  inline void constructLiveRanges() { LRI.constructLiveRanges(); }      
 
   void colorIncomingArgs();
   void colorCallRetArgs();
@@ -128,31 +143,19 @@ class PhyRegAlloc: public NonCopyable
   friend class UltraSparcRegInfo;
 
 
-  int getUsableUniRegAtMI(RegClass *RC,  const int RegType, 
-                         const MachineInstr *MInst,
-                         const LiveVarSet *LVSetBef, MachineInstr *MIBef, 
-                         MachineInstr *MIAft );
-
+  int getUsableUniRegAtMI(int RegType, 
+                         const ValueSet *LVSetBef,
+                         MachineInstr *MInst,
+                          std::vector<MachineInstr*>& MIBef,
+                          std::vector<MachineInstr*>& MIAft);
+  
   int getUnusedUniRegAtMI(RegClass *RC,  const MachineInstr *MInst, 
-                      const LiveVarSet *LVSetBef);
+                          const ValueSet *LVSetBef);
 
   void setRelRegsUsedByThisInst(RegClass *RC, const MachineInstr *MInst );
   int getUniRegNotUsedByThisInst(RegClass *RC, const MachineInstr *MInst);
 
   void addInterf4PseudoInstr(const MachineInstr *MInst);
-
-
- public:
-
-  PhyRegAlloc(Method *const M, const TargetMachine& TM, 
-             MethodLiveVarInfo *const Lvi);
-
-  ~PhyRegAlloc(); 
-
-  // main method called for allocating registers
-  //
-  void allocateRegisters();           
-
 };