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