Mercurial > hg > CbC > CbC_llvm
comparison lib/CodeGen/LiveRangeCalc.h @ 121:803732b1fca8
LLVM 5.0
author | kono |
---|---|
date | Fri, 27 Oct 2017 17:07:41 +0900 |
parents | 1172e4bd9c6f |
children | c2174574ed3a |
comparison
equal
deleted
inserted
replaced
120:1172e4bd9c6f | 121:803732b1fca8 |
---|---|
1 //===---- LiveRangeCalc.h - Calculate live ranges ---------------*- C++ -*-===// | 1 //===- LiveRangeCalc.h - Calculate live ranges ------------------*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
22 #ifndef LLVM_LIB_CODEGEN_LIVERANGECALC_H | 22 #ifndef LLVM_LIB_CODEGEN_LIVERANGECALC_H |
23 #define LLVM_LIB_CODEGEN_LIVERANGECALC_H | 23 #define LLVM_LIB_CODEGEN_LIVERANGECALC_H |
24 | 24 |
25 #include "llvm/ADT/ArrayRef.h" | 25 #include "llvm/ADT/ArrayRef.h" |
26 #include "llvm/ADT/BitVector.h" | 26 #include "llvm/ADT/BitVector.h" |
27 #include "llvm/ADT/DenseMap.h" | |
27 #include "llvm/ADT/IndexedMap.h" | 28 #include "llvm/ADT/IndexedMap.h" |
29 #include "llvm/ADT/SmallVector.h" | |
28 #include "llvm/CodeGen/LiveInterval.h" | 30 #include "llvm/CodeGen/LiveInterval.h" |
31 #include "llvm/CodeGen/MachineBasicBlock.h" | |
32 #include "llvm/CodeGen/SlotIndexes.h" | |
33 #include "llvm/MC/LaneBitmask.h" | |
34 #include <utility> | |
29 | 35 |
30 namespace llvm { | 36 namespace llvm { |
31 | 37 |
32 /// Forward declarations for MachineDominators.h: | 38 template <class NodeT> class DomTreeNodeBase; |
33 class MachineDominatorTree; | 39 class MachineDominatorTree; |
34 template <class NodeT> class DomTreeNodeBase; | 40 class MachineFunction; |
35 typedef DomTreeNodeBase<MachineBasicBlock> MachineDomTreeNode; | 41 class MachineRegisterInfo; |
42 | |
43 using MachineDomTreeNode = DomTreeNodeBase<MachineBasicBlock>; | |
36 | 44 |
37 class LiveRangeCalc { | 45 class LiveRangeCalc { |
38 const MachineFunction *MF; | 46 const MachineFunction *MF = nullptr; |
39 const MachineRegisterInfo *MRI; | 47 const MachineRegisterInfo *MRI = nullptr; |
40 SlotIndexes *Indexes; | 48 SlotIndexes *Indexes = nullptr; |
41 MachineDominatorTree *DomTree; | 49 MachineDominatorTree *DomTree = nullptr; |
42 VNInfo::Allocator *Alloc; | 50 VNInfo::Allocator *Alloc = nullptr; |
43 | 51 |
44 /// LiveOutPair - A value and the block that defined it. The domtree node is | 52 /// LiveOutPair - A value and the block that defined it. The domtree node is |
45 /// redundant, it can be computed as: MDT[Indexes.getMBBFromIndex(VNI->def)]. | 53 /// redundant, it can be computed as: MDT[Indexes.getMBBFromIndex(VNI->def)]. |
46 typedef std::pair<VNInfo*, MachineDomTreeNode*> LiveOutPair; | 54 using LiveOutPair = std::pair<VNInfo *, MachineDomTreeNode *>; |
47 | 55 |
48 /// LiveOutMap - Map basic blocks to the value leaving the block. | 56 /// LiveOutMap - Map basic blocks to the value leaving the block. |
49 typedef IndexedMap<LiveOutPair, MBB2NumberFunctor> LiveOutMap; | 57 using LiveOutMap = IndexedMap<LiveOutPair, MBB2NumberFunctor>; |
50 | 58 |
51 /// Bit vector of active entries in LiveOut, also used as a visited set by | 59 /// Bit vector of active entries in LiveOut, also used as a visited set by |
52 /// findReachingDefs. One entry per basic block, indexed by block number. | 60 /// findReachingDefs. One entry per basic block, indexed by block number. |
53 /// This is kept as a separate bit vector because it can be cleared quickly | 61 /// This is kept as a separate bit vector because it can be cleared quickly |
54 /// when switching live ranges. | 62 /// when switching live ranges. |
63 /// object is used to track live-out information for multiple registers | 71 /// object is used to track live-out information for multiple registers |
64 /// in live range splitting (which is ok, since the live ranges of these | 72 /// in live range splitting (which is ok, since the live ranges of these |
65 /// registers do not overlap), but the defined/undefined information must | 73 /// registers do not overlap), but the defined/undefined information must |
66 /// be kept separate for each individual range. | 74 /// be kept separate for each individual range. |
67 /// By convention, EntryInfoMap[&LR] = { Defined, Undefined }. | 75 /// By convention, EntryInfoMap[&LR] = { Defined, Undefined }. |
68 std::map<LiveRange*,std::pair<BitVector,BitVector>> EntryInfoMap; | 76 using EntryInfoMap = DenseMap<LiveRange *, std::pair<BitVector, BitVector>>; |
77 EntryInfoMap EntryInfos; | |
69 | 78 |
70 /// Map each basic block where a live range is live out to the live-out value | 79 /// Map each basic block where a live range is live out to the live-out value |
71 /// and its defining block. | 80 /// and its defining block. |
72 /// | 81 /// |
73 /// For every basic block, MBB, one of these conditions shall be true: | 82 /// For every basic block, MBB, one of these conditions shall be true: |
101 // range passes through the block. When the final value has been | 110 // range passes through the block. When the final value has been |
102 // determined, the range from the block start to Kill will be added to LI. | 111 // determined, the range from the block start to Kill will be added to LI. |
103 SlotIndex Kill; | 112 SlotIndex Kill; |
104 | 113 |
105 // Live-in value filled in by updateSSA once it is known. | 114 // Live-in value filled in by updateSSA once it is known. |
106 VNInfo *Value; | 115 VNInfo *Value = nullptr; |
107 | 116 |
108 LiveInBlock(LiveRange &LR, MachineDomTreeNode *node, SlotIndex kill) | 117 LiveInBlock(LiveRange &LR, MachineDomTreeNode *node, SlotIndex kill) |
109 : LR(LR), DomNode(node), Kill(kill), Value(nullptr) {} | 118 : LR(LR), DomNode(node), Kill(kill) {} |
110 }; | 119 }; |
111 | 120 |
112 /// LiveIn - Work list of blocks where the live-in value has yet to be | 121 /// LiveIn - Work list of blocks where the live-in value has yet to be |
113 /// determined. This list is typically computed by findReachingDefs() and | 122 /// determined. This list is typically computed by findReachingDefs() and |
114 /// used as a work list by updateSSA(). The low-level interface may also be | 123 /// used as a work list by updateSSA(). The low-level interface may also be |
158 /// jointly dominated by the definitions from @p LR. If @p LR is a subrange | 167 /// jointly dominated by the definitions from @p LR. If @p LR is a subrange |
159 /// of the live interval @p LI, corresponding to lane mask @p LaneMask, | 168 /// of the live interval @p LI, corresponding to lane mask @p LaneMask, |
160 /// all uses must be jointly dominated by the definitions from @p LR | 169 /// all uses must be jointly dominated by the definitions from @p LR |
161 /// together with definitions of other lanes where @p LR becomes undefined | 170 /// together with definitions of other lanes where @p LR becomes undefined |
162 /// (via <def,read-undef> operands). | 171 /// (via <def,read-undef> operands). |
163 /// If @p LR is a main range, the @p LaneMask should be set to ~0. | 172 /// If @p LR is a main range, the @p LaneMask should be set to ~0, i.e. |
173 /// LaneBitmask::getAll(). | |
164 void extendToUses(LiveRange &LR, unsigned Reg, LaneBitmask LaneMask, | 174 void extendToUses(LiveRange &LR, unsigned Reg, LaneBitmask LaneMask, |
165 LiveInterval *LI = nullptr); | 175 LiveInterval *LI = nullptr); |
166 | 176 |
167 /// Reset Map and Seen fields. | 177 /// Reset Map and Seen fields. |
168 void resetLiveOutMap(); | 178 void resetLiveOutMap(); |
169 | 179 |
170 public: | 180 public: |
171 LiveRangeCalc() : MF(nullptr), MRI(nullptr), Indexes(nullptr), | 181 LiveRangeCalc() = default; |
172 DomTree(nullptr), Alloc(nullptr) {} | |
173 | 182 |
174 //===--------------------------------------------------------------------===// | 183 //===--------------------------------------------------------------------===// |
175 // High-level interface. | 184 // High-level interface. |
176 //===--------------------------------------------------------------------===// | 185 //===--------------------------------------------------------------------===// |
177 // | 186 // |
181 /// reset - Prepare caches for a new set of non-overlapping live ranges. The | 190 /// reset - Prepare caches for a new set of non-overlapping live ranges. The |
182 /// caches must be reset before attempting calculations with a live range | 191 /// caches must be reset before attempting calculations with a live range |
183 /// that may overlap a previously computed live range, and before the first | 192 /// that may overlap a previously computed live range, and before the first |
184 /// live range in a function. If live ranges are not known to be | 193 /// live range in a function. If live ranges are not known to be |
185 /// non-overlapping, call reset before each. | 194 /// non-overlapping, call reset before each. |
186 void reset(const MachineFunction *MF, | 195 void reset(const MachineFunction *mf, SlotIndexes *SI, |
187 SlotIndexes*, | 196 MachineDominatorTree *MDT, VNInfo::Allocator *VNIA); |
188 MachineDominatorTree*, | |
189 VNInfo::Allocator*); | |
190 | 197 |
191 //===--------------------------------------------------------------------===// | 198 //===--------------------------------------------------------------------===// |
192 // Mid-level interface. | 199 // Mid-level interface. |
193 //===--------------------------------------------------------------------===// | 200 //===--------------------------------------------------------------------===// |
194 // | 201 // |
213 /// Extend the live range of @p LR to reach all uses of Reg. | 220 /// Extend the live range of @p LR to reach all uses of Reg. |
214 /// | 221 /// |
215 /// All uses must be jointly dominated by existing liveness. PHI-defs are | 222 /// All uses must be jointly dominated by existing liveness. PHI-defs are |
216 /// inserted as needed to preserve SSA form. | 223 /// inserted as needed to preserve SSA form. |
217 void extendToUses(LiveRange &LR, unsigned PhysReg) { | 224 void extendToUses(LiveRange &LR, unsigned PhysReg) { |
218 extendToUses(LR, PhysReg, ~0u); | 225 extendToUses(LR, PhysReg, LaneBitmask::getAll()); |
219 } | 226 } |
220 | 227 |
221 /// Calculates liveness for the register specified in live interval @p LI. | 228 /// Calculates liveness for the register specified in live interval @p LI. |
222 /// Creates subregister live ranges as needed if subreg liveness tracking is | 229 /// Creates subregister live ranges as needed if subreg liveness tracking is |
223 /// enabled. | 230 /// enabled. |
277 void calculateValues(); | 284 void calculateValues(); |
278 }; | 285 }; |
279 | 286 |
280 } // end namespace llvm | 287 } // end namespace llvm |
281 | 288 |
282 #endif | 289 #endif // LLVM_LIB_CODEGEN_LIVERANGECALC_H |