Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 1 | /* Title: LiveRangeInfo.h |
| 2 | Author: Ruchira Sasanka |
| 3 | Date: Jun 30, 01 |
| 4 | Purpose: |
| 5 | |
| 6 | This file constructs and keeps the LiveRang map which contains all the live |
| 7 | ranges used in a method. |
| 8 | |
| 9 | Assumptions: |
| 10 | |
| 11 | All variables (llvm Values) are defined before they are used. However, a |
| 12 | constant may not be defined in the machine instruction stream if it can be |
| 13 | used as an immediate value within a machine instruction. However, register |
| 14 | allocation does not have to worry about immediate constants since they |
| 15 | do not require registers. |
| 16 | |
| 17 | Since an llvm Value has a list of uses associated, it is sufficient to |
| 18 | record only the defs in a Live Range. |
| 19 | |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | #ifndef LIVE_RANGE_INFO_H |
| 24 | #define LIVE_RANGE_INFO_H |
| 25 | |
| 26 | |
| 27 | #include "llvm/Type.h" |
| 28 | #include "llvm/Method.h" |
| 29 | #include "llvm/CodeGen/MachineInstr.h" |
| 30 | |
| 31 | #include "llvm/Analysis/LiveVar/LiveVarSet.h" |
| 32 | |
| 33 | #include "llvm/CodeGen/IGNode.h" |
| 34 | #include "llvm/CodeGen/LiveRange.h" |
| 35 | #include "llvm/CodeGen/RegClass.h" |
| 36 | |
| 37 | /* |
| 38 | #ifndef size_type |
| 39 | #define size_type (unsigned int) |
| 40 | #endif |
| 41 | */ |
| 42 | |
| 43 | |
| 44 | typedef hash_map <const Value *, LiveRange *, hashFuncValue> LiveRangeMapType; |
Ruchira Sasanka | 560b0ad | 2001-09-30 23:19:57 +0000 | [diff] [blame^] | 45 | typedef vector <const Instruction *> CallRetInstrListType; |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 46 | |
| 47 | class LiveRangeInfo |
| 48 | { |
| 49 | |
| 50 | private: |
| 51 | |
| 52 | const Method *const Meth; // Method for which live range info is held |
| 53 | |
| 54 | LiveRangeMapType LiveRangeMap; // A map from Value * to LiveRange * |
| 55 | // created by constructLiveRanges |
| 56 | |
Ruchira Sasanka | f60342a | 2001-09-15 00:33:26 +0000 | [diff] [blame] | 57 | const TargetMachine& TM; // target machine description |
| 58 | vector<RegClass *> & RegClassList;// a vector containing register classess |
Ruchira Sasanka | 560b0ad | 2001-09-30 23:19:57 +0000 | [diff] [blame^] | 59 | const MachineRegInfo& MRI; // machine reg info |
Ruchira Sasanka | f60342a | 2001-09-15 00:33:26 +0000 | [diff] [blame] | 60 | |
Ruchira Sasanka | 560b0ad | 2001-09-30 23:19:57 +0000 | [diff] [blame^] | 61 | CallRetInstrListType CallRetInstrList; // a list of all call/ret instrs |
Ruchira Sasanka | f60342a | 2001-09-15 00:33:26 +0000 | [diff] [blame] | 62 | |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 63 | void unionAndUpdateLRs(LiveRange *L1, LiveRange *L2); |
| 64 | |
| 65 | void addInterference(const Instruction *const Inst, |
| 66 | const LiveVarSet *const LVSet); |
| 67 | |
| 68 | |
| 69 | public: |
| 70 | |
Ruchira Sasanka | f60342a | 2001-09-15 00:33:26 +0000 | [diff] [blame] | 71 | LiveRangeInfo(const Method *const M, |
| 72 | const TargetMachine& tm, |
| 73 | vector<RegClass *> & RCList); |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 74 | |
| 75 | void constructLiveRanges(); |
| 76 | |
Ruchira Sasanka | 560b0ad | 2001-09-30 23:19:57 +0000 | [diff] [blame^] | 77 | inline void addLRToMap(const Value *Val, LiveRange *LR) { |
| 78 | assert( Val && LR && "Val/LR is NULL!\n"); |
| 79 | assert( (! LiveRangeMap[ Val ]) && "LR already set in map"); |
| 80 | LiveRangeMap[ Val ] = LR; |
| 81 | } |
| 82 | |
| 83 | |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 84 | inline const LiveRangeMapType *const getLiveRangeMap() const |
| 85 | { return &LiveRangeMap; } |
| 86 | |
| 87 | inline LiveRange *getLiveRangeForValue( const Value *const Val) |
| 88 | { return LiveRangeMap[ Val ]; } |
| 89 | |
Ruchira Sasanka | 560b0ad | 2001-09-30 23:19:57 +0000 | [diff] [blame^] | 90 | inline CallRetInstrListType &getCallRetInstrList() { |
| 91 | return CallRetInstrList; |
| 92 | } |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 93 | |
| 94 | |
| 95 | |
| 96 | void coalesceLRs(); |
| 97 | |
| 98 | void printLiveRanges(); |
| 99 | |
| 100 | }; |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | #endif |