Chris Lattner | 4e8c487 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 1 | //===-- LiveRangeInfo.h - Track all LiveRanges for a Function ----*- C++ -*-==// |
Chris Lattner | b0da8b2 | 2002-02-04 05:52:08 +0000 | [diff] [blame] | 2 | // |
| 3 | // This file contains the class LiveRangeInfo which constructs and keeps |
| 4 | // the LiveRangMap which contains all the live ranges used in a method. |
| 5 | // |
| 6 | // Assumptions: |
| 7 | // |
| 8 | // All variables (llvm Values) are defined before they are used. However, a |
| 9 | // constant may not be defined in the machine instruction stream if it can be |
| 10 | // used as an immediate value within a machine instruction. However, register |
| 11 | // allocation does not have to worry about immediate constants since they |
| 12 | // do not require registers. |
| 13 | // |
| 14 | // Since an llvm Value has a list of uses associated, it is sufficient to |
| 15 | // record only the defs in a Live Range. |
| 16 | // |
| 17 | //===----------------------------------------------------------------------===// |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 18 | |
| 19 | #ifndef LIVE_RANGE_INFO_H |
| 20 | #define LIVE_RANGE_INFO_H |
| 21 | |
Chris Lattner | b0da8b2 | 2002-02-04 05:52:08 +0000 | [diff] [blame] | 22 | #include "Support/HashExtras.h" |
Chris Lattner | b1def73 | 2002-02-05 02:51:01 +0000 | [diff] [blame] | 23 | #include "llvm/Analysis/LiveVar/ValueSet.h" |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 24 | |
Chris Lattner | b0da8b2 | 2002-02-04 05:52:08 +0000 | [diff] [blame] | 25 | class LiveRange; |
| 26 | class MachineInstr; |
Chris Lattner | b0da8b2 | 2002-02-04 05:52:08 +0000 | [diff] [blame] | 27 | class RegClass; |
| 28 | class MachineRegInfo; |
| 29 | class TargetMachine; |
| 30 | class Value; |
Chris Lattner | 4e8c487 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 31 | class Function; |
Chris Lattner | b0da8b2 | 2002-02-04 05:52:08 +0000 | [diff] [blame] | 32 | class Instruction; |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 33 | |
Chris Lattner | e583333 | 2002-07-24 21:21:33 +0000 | [diff] [blame] | 34 | typedef hash_map<const Value*, LiveRange*> LiveRangeMapType; |
Vikram S. Adve | ff045b2 | 2002-07-08 22:34:40 +0000 | [diff] [blame] | 35 | typedef std::vector<MachineInstr*> CallRetInstrListType; |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 36 | |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 37 | //---------------------------------------------------------------------------- |
| 38 | // Class LiveRangeInfo |
| 39 | // |
| 40 | // Constructs and keeps the LiveRangMap which contains all the live |
| 41 | // ranges used in a method. Also contain methods to coalesce live ranges. |
| 42 | //---------------------------------------------------------------------------- |
| 43 | |
Chris Lattner | b0da8b2 | 2002-02-04 05:52:08 +0000 | [diff] [blame] | 44 | class LiveRangeInfo { |
Chris Lattner | 4e8c487 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 45 | const Function *const Meth; // Func for which live range info is held |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 46 | LiveRangeMapType LiveRangeMap; // A map from Value * to LiveRange * to |
| 47 | // record all live ranges in a method |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 48 | // created by constructLiveRanges |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 49 | |
Ruchira Sasanka | f60342a | 2001-09-15 00:33:26 +0000 | [diff] [blame] | 50 | const TargetMachine& TM; // target machine description |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 51 | |
Chris Lattner | 7f74a56 | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 52 | std::vector<RegClass *> & RegClassList;// vector containing register classess |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 53 | |
Ruchira Sasanka | 560b0ad | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 54 | const MachineRegInfo& MRI; // machine reg info |
Ruchira Sasanka | f60342a | 2001-09-15 00:33:26 +0000 | [diff] [blame] | 55 | |
Ruchira Sasanka | 560b0ad | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 56 | CallRetInstrListType CallRetInstrList; // a list of all call/ret instrs |
Ruchira Sasanka | f60342a | 2001-09-15 00:33:26 +0000 | [diff] [blame] | 57 | |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 58 | |
| 59 | //------------ Private methods (see LiveRangeInfo.cpp for description)------- |
| 60 | |
Vikram S. Adve | 9011903 | 2002-09-28 17:05:43 +0000 | [diff] [blame^] | 61 | LiveRange* createNewLiveRange (const Value* Def, |
| 62 | bool isCC = false); |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 63 | |
Vikram S. Adve | 9011903 | 2002-09-28 17:05:43 +0000 | [diff] [blame^] | 64 | LiveRange* createOrAddToLiveRange (const Value* Def, |
| 65 | bool isCC = false); |
| 66 | |
| 67 | void unionAndUpdateLRs (LiveRange *L1, |
| 68 | LiveRange *L2); |
| 69 | |
| 70 | void addInterference (const Instruction *Inst, |
| 71 | const ValueSet *LVSet); |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 72 | |
Vikram S. Adve | 9011903 | 2002-09-28 17:05:43 +0000 | [diff] [blame^] | 73 | void suggestRegs4CallRets (); |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 74 | |
Vikram S. Adve | 9011903 | 2002-09-28 17:05:43 +0000 | [diff] [blame^] | 75 | const Function *getMethod () const { return Meth; } |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 76 | |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 77 | public: |
| 78 | |
Chris Lattner | 4e8c487 | 2002-03-23 22:51:58 +0000 | [diff] [blame] | 79 | LiveRangeInfo(const Function *F, |
Ruchira Sasanka | f60342a | 2001-09-15 00:33:26 +0000 | [diff] [blame] | 80 | const TargetMachine& tm, |
Chris Lattner | 7f74a56 | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 81 | std::vector<RegClass *> & RCList); |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 82 | |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 83 | |
| 84 | // Destructor to destroy all LiveRanges in the LiveRange Map |
| 85 | ~LiveRangeInfo(); |
| 86 | |
| 87 | // Main entry point for live range construction |
| 88 | // |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 89 | void constructLiveRanges(); |
Ruchira Sasanka | 560b0ad | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 90 | |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 91 | // return the common live range map for this method |
| 92 | // |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 93 | inline const LiveRangeMapType *const getLiveRangeMap() const |
| 94 | { return &LiveRangeMap; } |
| 95 | |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 96 | // Method sed to get the corresponding live range of a Value |
| 97 | // |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 98 | inline LiveRange *getLiveRangeForValue( const Value *const Val) |
Chris Lattner | b0da8b2 | 2002-02-04 05:52:08 +0000 | [diff] [blame] | 99 | { return LiveRangeMap[Val]; } |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 100 | |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 101 | // Method used to get the Call and Return instruction list |
| 102 | // |
Ruchira Sasanka | 560b0ad | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 103 | inline CallRetInstrListType &getCallRetInstrList() { |
| 104 | return CallRetInstrList; |
| 105 | } |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 106 | |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 107 | // Method for coalescing live ranges. Called only after interference info |
| 108 | // is calculated. |
| 109 | // |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 110 | void coalesceLRs(); |
| 111 | |
Ruchira Sasanka | f20079d | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 112 | // debugging method to print the live ranges |
| 113 | // |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 114 | void printLiveRanges(); |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
Ruchira Sasanka | e5d0fb8 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 117 | #endif |