Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 1 | /* Title: PhyRegAlloc.h |
| 2 | Author: Ruchira Sasanka |
| 3 | Date: Aug 20, 01 |
| 4 | Purpose: This is the main entry point for register allocation. |
| 5 | |
| 6 | Notes: |
| 7 | |
| 8 | * RegisterClasses: Each RegClass accepts a |
| 9 | MachineRegClass which contains machine specific info about that register |
| 10 | class. The code in the RegClass is machine independent and they use |
| 11 | access functions in the MachineRegClass object passed into it to get |
| 12 | machine specific info. |
| 13 | |
| 14 | * Machine dependent work: All parts of the register coloring algorithm |
| 15 | except coloring of an individual node are machine independent. |
| 16 | |
| 17 | Register allocation must be done as: |
| 18 | |
| 19 | static const MachineRegInfo MRI = MachineRegInfo(); // machine reg info |
| 20 | |
| 21 | MethodLiveVarInfo LVI(*MethodI ); // compute LV info |
| 22 | LVI.analyze(); |
| 23 | |
| 24 | PhyRegAlloc PRA(*MethodI, &MRI, &LVI); // allocate regs |
| 25 | PRA.allocateRegisters(); |
| 26 | |
| 27 | Assumptions: |
| 28 | All values in a live range will be of the same physical reg class. |
| 29 | |
| 30 | */ |
| 31 | |
| 32 | |
| 33 | |
| 34 | #ifndef PHY_REG_ALLOC_H |
| 35 | #define PHY_REG_ALLOC_H |
| 36 | |
| 37 | #include "llvm/CodeGen/MachineInstr.h" |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 38 | #include "llvm/CodeGen/RegClass.h" |
| 39 | #include "llvm/CodeGen/LiveRangeInfo.h" |
| 40 | #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" |
| 41 | |
Ruchira Sasanka | 21721b6 | 2001-10-15 16:22:44 +0000 | [diff] [blame] | 42 | #include <deque> |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 43 | |
| 44 | class AddedInstrns |
| 45 | { |
| 46 | public: |
Ruchira Sasanka | 21721b6 | 2001-10-15 16:22:44 +0000 | [diff] [blame] | 47 | deque<MachineInstr *> InstrnsBefore; |
| 48 | deque<MachineInstr *> InstrnsAfter; |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 49 | |
| 50 | AddedInstrns() : InstrnsBefore(), InstrnsAfter() { } |
| 51 | }; |
| 52 | |
| 53 | typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType; |
| 54 | |
| 55 | |
| 56 | |
| 57 | class PhyRegAlloc |
| 58 | { |
| 59 | |
| 60 | vector<RegClass *> RegClassList ; // vector of register classes |
| 61 | const Method *const Meth; // name of the method we work on |
| 62 | const TargetMachine &TM; // target machine |
| 63 | MethodLiveVarInfo *const LVI; // LV information for this method |
| 64 | // (already computed for BBs) |
| 65 | LiveRangeInfo LRI; // LR info (will be computed) |
| 66 | const MachineRegInfo &MRI; // Machine Register information |
| 67 | const unsigned NumOfRegClasses; // recorded here for efficiency |
| 68 | |
Ruchira Sasanka | ab304c4 | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 69 | //vector<const Instruction *> CallInstrList; // a list of all call instrs |
| 70 | //vector<const Instruction *> RetInstrList; // a list of all return instrs |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 71 | |
| 72 | AddedInstrMapType AddedInstrMap; // to store instrns added in this phase |
| 73 | |
| 74 | |
Ruchira Sasanka | 1bf6d64 | 2001-09-15 00:33:26 +0000 | [diff] [blame] | 75 | |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 76 | //------- private methods --------------------------------------------------- |
| 77 | |
| 78 | void addInterference(const Value *const Def, const LiveVarSet *const LVSet, |
| 79 | const bool isCallInst); |
| 80 | |
| 81 | void addInterferencesForArgs(); |
| 82 | void createIGNodeListsAndIGs(); |
| 83 | void buildInterferenceGraphs(); |
Ruchira Sasanka | c4d4b76 | 2001-10-16 01:23:19 +0000 | [diff] [blame] | 84 | void insertCallerSavingCode(const MachineInstr *MInst, |
| 85 | const BasicBlock *BB ); |
| 86 | |
Ruchira Sasanka | 36f7707 | 2001-10-19 17:21:59 +0000 | [diff] [blame] | 87 | void setCallInterferences(const MachineInstr *MInst, |
| 88 | const LiveVarSet *const LVSetAft ); |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 89 | |
Ruchira Sasanka | 44d2b94 | 2001-10-19 21:42:06 +0000 | [diff] [blame^] | 90 | void markUnusableSugColors(); |
| 91 | |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 92 | inline void constructLiveRanges() |
| 93 | { LRI.constructLiveRanges(); } |
| 94 | |
| 95 | void colorIncomingArgs(); |
Ruchira Sasanka | ab304c4 | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 96 | void colorCallRetArgs(); |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 97 | void updateMachineCode(); |
Ruchira Sasanka | ab304c4 | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 98 | |
Ruchira Sasanka | 6053b93 | 2001-09-15 19:08:41 +0000 | [diff] [blame] | 99 | void printLabel(const Value *const Val); |
| 100 | void printMachineCode(); |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 101 | |
| 102 | public: |
| 103 | PhyRegAlloc(const Method *const M, const TargetMachine& TM, |
| 104 | MethodLiveVarInfo *const Lvi); |
| 105 | |
| 106 | void allocateRegisters(); // main method called for allocatin |
| 107 | |
| 108 | }; |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | #endif |
| 118 | |