Andrew Trick | 14e8d71 | 2010-10-22 23:09:15 +0000 | [diff] [blame] | 1 | //===-------- SplitKit.cpp - Toolkit for splitting live ranges --*- C++ -*-===// |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the SplitAnalysis class as well as mutator functions for |
| 11 | // live range splitting. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/ADT/SmallPtrSet.h" |
| 16 | #include "llvm/ADT/DenseMap.h" |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/SlotIndexes.h" |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 18 | |
| 19 | namespace llvm { |
| 20 | |
| 21 | class LiveInterval; |
| 22 | class LiveIntervals; |
Jakob Stoklund Olesen | a17768f | 2010-10-14 23:49:52 +0000 | [diff] [blame] | 23 | class LiveRangeEdit; |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 24 | class MachineInstr; |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 25 | class MachineLoop; |
| 26 | class MachineLoopInfo; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 27 | class MachineRegisterInfo; |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 28 | class TargetInstrInfo; |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 29 | class TargetRegisterInfo; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 30 | class VirtRegMap; |
| 31 | class VNInfo; |
Jakob Stoklund Olesen | 532de3d | 2010-10-22 20:28:21 +0000 | [diff] [blame] | 32 | class raw_ostream; |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 33 | |
Jakob Stoklund Olesen | e1dde7b | 2010-10-28 20:34:52 +0000 | [diff] [blame] | 34 | /// At some point we should just include MachineDominators.h: |
| 35 | class MachineDominatorTree; |
| 36 | template <class NodeT> class DomTreeNodeBase; |
| 37 | typedef DomTreeNodeBase<MachineBasicBlock> MachineDomTreeNode; |
| 38 | |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 39 | /// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting |
| 40 | /// opportunities. |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 41 | class SplitAnalysis { |
Jakob Stoklund Olesen | 08e93b1 | 2010-08-10 17:07:22 +0000 | [diff] [blame] | 42 | public: |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 43 | const MachineFunction &mf_; |
| 44 | const LiveIntervals &lis_; |
| 45 | const MachineLoopInfo &loops_; |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 46 | const TargetInstrInfo &tii_; |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 47 | |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 48 | // Instructions using the the current register. |
| 49 | typedef SmallPtrSet<const MachineInstr*, 16> InstrPtrSet; |
| 50 | InstrPtrSet usingInstrs_; |
| 51 | |
| 52 | // The number of instructions using curli in each basic block. |
| 53 | typedef DenseMap<const MachineBasicBlock*, unsigned> BlockCountMap; |
| 54 | BlockCountMap usingBlocks_; |
| 55 | |
Jakob Stoklund Olesen | 2dee7a5 | 2010-08-12 23:02:55 +0000 | [diff] [blame] | 56 | // The number of basic block using curli in each loop. |
| 57 | typedef DenseMap<const MachineLoop*, unsigned> LoopCountMap; |
| 58 | LoopCountMap usingLoops_; |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 59 | |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 60 | private: |
| 61 | // Current live interval. |
| 62 | const LiveInterval *curli_; |
| 63 | |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 64 | // Sumarize statistics by counting instructions using curli_. |
Jakob Stoklund Olesen | abff280 | 2010-07-20 16:12:37 +0000 | [diff] [blame] | 65 | void analyzeUses(); |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 66 | |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 67 | /// canAnalyzeBranch - Return true if MBB ends in a branch that can be |
| 68 | /// analyzed. |
| 69 | bool canAnalyzeBranch(const MachineBasicBlock *MBB); |
| 70 | |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 71 | public: |
Jakob Stoklund Olesen | f2c6e36 | 2010-07-20 23:50:15 +0000 | [diff] [blame] | 72 | SplitAnalysis(const MachineFunction &mf, const LiveIntervals &lis, |
| 73 | const MachineLoopInfo &mli); |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 74 | |
| 75 | /// analyze - set curli to the specified interval, and analyze how it may be |
| 76 | /// split. |
| 77 | void analyze(const LiveInterval *li); |
| 78 | |
| 79 | /// clear - clear all data structures so SplitAnalysis is ready to analyze a |
| 80 | /// new interval. |
| 81 | void clear(); |
| 82 | |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 83 | typedef SmallPtrSet<const MachineBasicBlock*, 16> BlockPtrSet; |
Jakob Stoklund Olesen | 2dee7a5 | 2010-08-12 23:02:55 +0000 | [diff] [blame] | 84 | typedef SmallPtrSet<const MachineLoop*, 16> LoopPtrSet; |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 85 | |
Jakob Stoklund Olesen | 532de3d | 2010-10-22 20:28:21 +0000 | [diff] [blame] | 86 | // Print a set of blocks with use counts. |
| 87 | void print(const BlockPtrSet&, raw_ostream&) const; |
| 88 | |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 89 | // Sets of basic blocks surrounding a machine loop. |
| 90 | struct LoopBlocks { |
| 91 | BlockPtrSet Loop; // Blocks in the loop. |
| 92 | BlockPtrSet Preds; // Loop predecessor blocks. |
| 93 | BlockPtrSet Exits; // Loop exit blocks. |
| 94 | |
| 95 | void clear() { |
| 96 | Loop.clear(); |
| 97 | Preds.clear(); |
| 98 | Exits.clear(); |
| 99 | } |
| 100 | }; |
| 101 | |
Jakob Stoklund Olesen | 532de3d | 2010-10-22 20:28:21 +0000 | [diff] [blame] | 102 | // Print loop blocks with use counts. |
| 103 | void print(const LoopBlocks&, raw_ostream&) const; |
| 104 | |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 105 | // Calculate the block sets surrounding the loop. |
| 106 | void getLoopBlocks(const MachineLoop *Loop, LoopBlocks &Blocks); |
| 107 | |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 108 | /// LoopPeripheralUse - how is a variable used in and around a loop? |
| 109 | /// Peripheral blocks are the loop predecessors and exit blocks. |
| 110 | enum LoopPeripheralUse { |
| 111 | ContainedInLoop, // All uses are inside the loop. |
| 112 | SinglePeripheral, // At most one instruction per peripheral block. |
| 113 | MultiPeripheral, // Multiple instructions in some peripheral blocks. |
| 114 | OutsideLoop // Uses outside loop periphery. |
| 115 | }; |
| 116 | |
| 117 | /// analyzeLoopPeripheralUse - Return an enum describing how curli_ is used in |
| 118 | /// and around the Loop. |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 119 | LoopPeripheralUse analyzeLoopPeripheralUse(const LoopBlocks&); |
| 120 | |
| 121 | /// getCriticalExits - It may be necessary to partially break critical edges |
| 122 | /// leaving the loop if an exit block has phi uses of curli. Collect the exit |
| 123 | /// blocks that need special treatment into CriticalExits. |
| 124 | void getCriticalExits(const LoopBlocks &Blocks, BlockPtrSet &CriticalExits); |
| 125 | |
| 126 | /// canSplitCriticalExits - Return true if it is possible to insert new exit |
| 127 | /// blocks before the blocks in CriticalExits. |
| 128 | bool canSplitCriticalExits(const LoopBlocks &Blocks, |
| 129 | BlockPtrSet &CriticalExits); |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 130 | |
Jakob Stoklund Olesen | 0960a65 | 2010-10-27 00:39:05 +0000 | [diff] [blame] | 131 | /// getCriticalPreds - Get the set of loop predecessors with critical edges to |
| 132 | /// blocks outside the loop that have curli live in. We don't have to break |
| 133 | /// these edges, but they do require special treatment. |
| 134 | void getCriticalPreds(const LoopBlocks &Blocks, BlockPtrSet &CriticalPreds); |
| 135 | |
Jakob Stoklund Olesen | 521a453 | 2010-12-15 17:41:19 +0000 | [diff] [blame^] | 136 | /// getSplitLoops - Get the set of loops that have curli uses and would be |
| 137 | /// profitable to split. |
| 138 | void getSplitLoops(LoopPtrSet&); |
| 139 | |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 140 | /// getBestSplitLoop - Return the loop where curli may best be split to a |
| 141 | /// separate register, or NULL. |
| 142 | const MachineLoop *getBestSplitLoop(); |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 143 | |
| 144 | /// getMultiUseBlocks - Add basic blocks to Blocks that may benefit from |
| 145 | /// having curli split to a new live interval. Return true if Blocks can be |
| 146 | /// passed to SplitEditor::splitSingleBlocks. |
| 147 | bool getMultiUseBlocks(BlockPtrSet &Blocks); |
Jakob Stoklund Olesen | fc412d8 | 2010-08-13 21:18:48 +0000 | [diff] [blame] | 148 | |
| 149 | /// getBlockForInsideSplit - If curli is contained inside a single basic block, |
| 150 | /// and it wou pay to subdivide the interval inside that block, return it. |
| 151 | /// Otherwise return NULL. The returned block can be passed to |
| 152 | /// SplitEditor::splitInsideBlock. |
| 153 | const MachineBasicBlock *getBlockForInsideSplit(); |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 154 | }; |
| 155 | |
Jakob Stoklund Olesen | 1407c84 | 2010-08-18 19:00:08 +0000 | [diff] [blame] | 156 | |
| 157 | /// LiveIntervalMap - Map values from a large LiveInterval into a small |
| 158 | /// interval that is a subset. Insert phi-def values as needed. This class is |
| 159 | /// used by SplitEditor to create new smaller LiveIntervals. |
| 160 | /// |
| 161 | /// parentli_ is the larger interval, li_ is the subset interval. Every value |
| 162 | /// in li_ corresponds to exactly one value in parentli_, and the live range |
| 163 | /// of the value is contained within the live range of the parentli_ value. |
| 164 | /// Values in parentli_ may map to any number of openli_ values, including 0. |
| 165 | class LiveIntervalMap { |
| 166 | LiveIntervals &lis_; |
Jakob Stoklund Olesen | d68f458 | 2010-10-28 20:34:50 +0000 | [diff] [blame] | 167 | MachineDominatorTree &mdt_; |
Jakob Stoklund Olesen | 1407c84 | 2010-08-18 19:00:08 +0000 | [diff] [blame] | 168 | |
| 169 | // The parent interval is never changed. |
| 170 | const LiveInterval &parentli_; |
| 171 | |
| 172 | // The child interval's values are fully contained inside parentli_ values. |
Jakob Stoklund Olesen | 9ca2aeb | 2010-09-13 23:29:09 +0000 | [diff] [blame] | 173 | LiveInterval *li_; |
Jakob Stoklund Olesen | 1407c84 | 2010-08-18 19:00:08 +0000 | [diff] [blame] | 174 | |
| 175 | typedef DenseMap<const VNInfo*, VNInfo*> ValueMap; |
| 176 | |
| 177 | // Map parentli_ values to simple values in li_ that are defined at the same |
| 178 | // SlotIndex, or NULL for parentli_ values that have complex li_ defs. |
| 179 | // Note there is a difference between values mapping to NULL (complex), and |
| 180 | // values not present (unknown/unmapped). |
| 181 | ValueMap valueMap_; |
| 182 | |
Jakob Stoklund Olesen | e1dde7b | 2010-10-28 20:34:52 +0000 | [diff] [blame] | 183 | typedef std::pair<VNInfo*, MachineDomTreeNode*> LiveOutPair; |
| 184 | typedef DenseMap<MachineBasicBlock*,LiveOutPair> LiveOutMap; |
| 185 | |
| 186 | // liveOutCache_ - Map each basic block where li_ is live out to the live-out |
| 187 | // value and its defining block. One of these conditions shall be true: |
| 188 | // |
| 189 | // 1. !liveOutCache_.count(MBB) |
| 190 | // 2. liveOutCache_[MBB].second.getNode() == MBB |
| 191 | // 3. forall P in preds(MBB): liveOutCache_[P] == liveOutCache_[MBB] |
| 192 | // |
| 193 | // This is only a cache, the values can be computed as: |
| 194 | // |
| 195 | // VNI = li_->getVNInfoAt(lis_.getMBBEndIdx(MBB)) |
| 196 | // Node = mbt_[lis_.getMBBFromIndex(VNI->def)] |
| 197 | // |
| 198 | // The cache is also used as a visiteed set by mapValue(). |
| 199 | LiveOutMap liveOutCache_; |
| 200 | |
Jakob Stoklund Olesen | 1407c84 | 2010-08-18 19:00:08 +0000 | [diff] [blame] | 201 | public: |
| 202 | LiveIntervalMap(LiveIntervals &lis, |
Jakob Stoklund Olesen | d68f458 | 2010-10-28 20:34:50 +0000 | [diff] [blame] | 203 | MachineDominatorTree &mdt, |
Jakob Stoklund Olesen | 9ca2aeb | 2010-09-13 23:29:09 +0000 | [diff] [blame] | 204 | const LiveInterval &parentli) |
Jakob Stoklund Olesen | d68f458 | 2010-10-28 20:34:50 +0000 | [diff] [blame] | 205 | : lis_(lis), mdt_(mdt), parentli_(parentli), li_(0) {} |
Jakob Stoklund Olesen | 9ca2aeb | 2010-09-13 23:29:09 +0000 | [diff] [blame] | 206 | |
| 207 | /// reset - clear all data structures and start a new live interval. |
| 208 | void reset(LiveInterval *); |
| 209 | |
| 210 | /// getLI - return the current live interval. |
| 211 | LiveInterval *getLI() const { return li_; } |
Jakob Stoklund Olesen | 1407c84 | 2010-08-18 19:00:08 +0000 | [diff] [blame] | 212 | |
| 213 | /// defValue - define a value in li_ from the parentli_ value VNI and Idx. |
| 214 | /// Idx does not have to be ParentVNI->def, but it must be contained within |
| 215 | /// ParentVNI's live range in parentli_. |
| 216 | /// Return the new li_ value. |
| 217 | VNInfo *defValue(const VNInfo *ParentVNI, SlotIndex Idx); |
| 218 | |
| 219 | /// mapValue - map ParentVNI to the corresponding li_ value at Idx. It is |
| 220 | /// assumed that ParentVNI is live at Idx. |
| 221 | /// If ParentVNI has not been defined by defValue, it is assumed that |
| 222 | /// ParentVNI->def dominates Idx. |
| 223 | /// If ParentVNI has been defined by defValue one or more times, a value that |
| 224 | /// dominates Idx will be returned. This may require creating extra phi-def |
| 225 | /// values and adding live ranges to li_. |
Jakob Stoklund Olesen | 5fa42a4 | 2010-09-21 22:32:21 +0000 | [diff] [blame] | 226 | /// If simple is not NULL, *simple will indicate if ParentVNI is a simply |
| 227 | /// mapped value. |
| 228 | VNInfo *mapValue(const VNInfo *ParentVNI, SlotIndex Idx, bool *simple = 0); |
| 229 | |
Jakob Stoklund Olesen | fc60d77 | 2010-10-05 20:36:25 +0000 | [diff] [blame] | 230 | // extendTo - Find the last li_ value defined in MBB at or before Idx. The |
| 231 | // parentli is assumed to be live at Idx. Extend the live range to include |
| 232 | // Idx. Return the found VNInfo, or NULL. |
Jakob Stoklund Olesen | c95c146 | 2010-10-27 00:39:07 +0000 | [diff] [blame] | 233 | VNInfo *extendTo(const MachineBasicBlock *MBB, SlotIndex Idx); |
Jakob Stoklund Olesen | fc60d77 | 2010-10-05 20:36:25 +0000 | [diff] [blame] | 234 | |
Jakob Stoklund Olesen | 5fa42a4 | 2010-09-21 22:32:21 +0000 | [diff] [blame] | 235 | /// isMapped - Return true is ParentVNI is a known mapped value. It may be a |
| 236 | /// simple 1-1 mapping or a complex mapping to later defs. |
| 237 | bool isMapped(const VNInfo *ParentVNI) const { |
| 238 | return valueMap_.count(ParentVNI); |
| 239 | } |
| 240 | |
| 241 | /// isComplexMapped - Return true if ParentVNI has received new definitions |
| 242 | /// with defValue. |
| 243 | bool isComplexMapped(const VNInfo *ParentVNI) const; |
| 244 | |
| 245 | // addSimpleRange - Add a simple range from parentli_ to li_. |
| 246 | // ParentVNI must be live in the [Start;End) interval. |
| 247 | void addSimpleRange(SlotIndex Start, SlotIndex End, const VNInfo *ParentVNI); |
Jakob Stoklund Olesen | 1407c84 | 2010-08-18 19:00:08 +0000 | [diff] [blame] | 248 | |
| 249 | /// addRange - Add live ranges to li_ where [Start;End) intersects parentli_. |
| 250 | /// All needed values whose def is not inside [Start;End) must be defined |
| 251 | /// beforehand so mapValue will work. |
| 252 | void addRange(SlotIndex Start, SlotIndex End); |
| 253 | }; |
| 254 | |
| 255 | |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 256 | /// SplitEditor - Edit machine code and LiveIntervals for live range |
| 257 | /// splitting. |
| 258 | /// |
Jakob Stoklund Olesen | 5eb308b | 2010-08-06 22:17:33 +0000 | [diff] [blame] | 259 | /// - Create a SplitEditor from a SplitAnalysis. |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 260 | /// - Start a new live interval with openIntv. |
| 261 | /// - Mark the places where the new interval is entered using enterIntv* |
| 262 | /// - Mark the ranges where the new interval is used with useIntv* |
| 263 | /// - Mark the places where the interval is exited with exitIntv*. |
| 264 | /// - Finish the current interval with closeIntv and repeat from 2. |
Jakob Stoklund Olesen | 7466927 | 2010-10-08 23:42:21 +0000 | [diff] [blame] | 265 | /// - Rewrite instructions with finish(). |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 266 | /// |
| 267 | class SplitEditor { |
| 268 | SplitAnalysis &sa_; |
| 269 | LiveIntervals &lis_; |
| 270 | VirtRegMap &vrm_; |
| 271 | MachineRegisterInfo &mri_; |
| 272 | const TargetInstrInfo &tii_; |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 273 | const TargetRegisterInfo &tri_; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 274 | |
Jakob Stoklund Olesen | a17768f | 2010-10-14 23:49:52 +0000 | [diff] [blame] | 275 | /// edit_ - The current parent register and new intervals created. |
| 276 | LiveRangeEdit &edit_; |
| 277 | |
Jakob Stoklund Olesen | 5eb308b | 2010-08-06 22:17:33 +0000 | [diff] [blame] | 278 | /// dupli_ - Created as a copy of curli_, ranges are carved out as new |
| 279 | /// intervals get added through openIntv / closeIntv. This is used to avoid |
| 280 | /// editing curli_. |
Jakob Stoklund Olesen | dd9f3fd | 2010-09-13 23:29:11 +0000 | [diff] [blame] | 281 | LiveIntervalMap dupli_; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 282 | |
| 283 | /// Currently open LiveInterval. |
Jakob Stoklund Olesen | dd9f3fd | 2010-09-13 23:29:11 +0000 | [diff] [blame] | 284 | LiveIntervalMap openli_; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 285 | |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 286 | /// defFromParent - Define Reg from ParentVNI at UseIdx using either |
| 287 | /// rematerialization or a COPY from parent. Return the new value. |
| 288 | VNInfo *defFromParent(LiveIntervalMap &Reg, |
| 289 | VNInfo *ParentVNI, |
| 290 | SlotIndex UseIdx, |
| 291 | MachineBasicBlock &MBB, |
| 292 | MachineBasicBlock::iterator I); |
| 293 | |
Jakob Stoklund Olesen | 5fa42a4 | 2010-09-21 22:32:21 +0000 | [diff] [blame] | 294 | /// intervalsLiveAt - Return true if any member of intervals_ is live at Idx. |
| 295 | bool intervalsLiveAt(SlotIndex Idx) const; |
| 296 | |
| 297 | /// Values in curli whose live range has been truncated when entering an open |
| 298 | /// li. |
| 299 | SmallPtrSet<const VNInfo*, 8> truncatedValues; |
| 300 | |
| 301 | /// addTruncSimpleRange - Add the given simple range to dupli_ after |
| 302 | /// truncating any overlap with intervals_. |
| 303 | void addTruncSimpleRange(SlotIndex Start, SlotIndex End, VNInfo *VNI); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 304 | |
Jakob Stoklund Olesen | c95c146 | 2010-10-27 00:39:07 +0000 | [diff] [blame] | 305 | /// criticalPreds_ - Set of basic blocks where both dupli and openli should be |
| 306 | /// live out because of a critical edge. |
| 307 | SplitAnalysis::BlockPtrSet criticalPreds_; |
| 308 | |
Jakob Stoklund Olesen | 7466927 | 2010-10-08 23:42:21 +0000 | [diff] [blame] | 309 | /// computeRemainder - Compute the dupli liveness as the complement of all the |
| 310 | /// new intervals. |
| 311 | void computeRemainder(); |
| 312 | |
| 313 | /// rewrite - Rewrite all uses of reg to use the new registers. |
| 314 | void rewrite(unsigned reg); |
| 315 | |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 316 | public: |
| 317 | /// Create a new SplitEditor for editing the LiveInterval analyzed by SA. |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 318 | /// Newly created intervals will be appended to newIntervals. |
Jakob Stoklund Olesen | d68f458 | 2010-10-28 20:34:50 +0000 | [diff] [blame] | 319 | SplitEditor(SplitAnalysis &SA, LiveIntervals&, VirtRegMap&, |
| 320 | MachineDominatorTree&, LiveRangeEdit&); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 321 | |
Jakob Stoklund Olesen | 5eb308b | 2010-08-06 22:17:33 +0000 | [diff] [blame] | 322 | /// getAnalysis - Get the corresponding analysis. |
| 323 | SplitAnalysis &getAnalysis() { return sa_; } |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 324 | |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 325 | /// Create a new virtual register and live interval. |
| 326 | void openIntv(); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 327 | |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 328 | /// enterIntvBefore - Enter openli before the instruction at Idx. If curli is |
| 329 | /// not live before Idx, a COPY is not inserted. |
| 330 | void enterIntvBefore(SlotIndex Idx); |
| 331 | |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 332 | /// enterIntvAtEnd - Enter openli at the end of MBB. |
Jakob Stoklund Olesen | f6a129a | 2010-09-16 00:01:36 +0000 | [diff] [blame] | 333 | void enterIntvAtEnd(MachineBasicBlock &MBB); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 334 | |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 335 | /// useIntv - indicate that all instructions in MBB should use openli. |
| 336 | void useIntv(const MachineBasicBlock &MBB); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 337 | |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 338 | /// useIntv - indicate that all instructions in range should use openli. |
| 339 | void useIntv(SlotIndex Start, SlotIndex End); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 340 | |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 341 | /// leaveIntvAfter - Leave openli after the instruction at Idx. |
| 342 | void leaveIntvAfter(SlotIndex Idx); |
| 343 | |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 344 | /// leaveIntvAtTop - Leave the interval at the top of MBB. |
| 345 | /// Currently, only one value can leave the interval. |
| 346 | void leaveIntvAtTop(MachineBasicBlock &MBB); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 347 | |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 348 | /// closeIntv - Indicate that we are done editing the currently open |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 349 | /// LiveInterval, and ranges can be trimmed. |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 350 | void closeIntv(); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 351 | |
Jakob Stoklund Olesen | 7466927 | 2010-10-08 23:42:21 +0000 | [diff] [blame] | 352 | /// finish - after all the new live ranges have been created, compute the |
| 353 | /// remaining live range, and rewrite instructions to use the new registers. |
| 354 | void finish(); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 355 | |
| 356 | // ===--- High level methods ---=== |
| 357 | |
| 358 | /// splitAroundLoop - Split curli into a separate live interval inside |
Jakob Stoklund Olesen | 57d0f2d | 2010-10-05 22:19:33 +0000 | [diff] [blame] | 359 | /// the loop. |
| 360 | void splitAroundLoop(const MachineLoop*); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 361 | |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 362 | /// splitSingleBlocks - Split curli into a separate live interval inside each |
Jakob Stoklund Olesen | 57d0f2d | 2010-10-05 22:19:33 +0000 | [diff] [blame] | 363 | /// basic block in Blocks. |
| 364 | void splitSingleBlocks(const SplitAnalysis::BlockPtrSet &Blocks); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 365 | |
Jakob Stoklund Olesen | 57d0f2d | 2010-10-05 22:19:33 +0000 | [diff] [blame] | 366 | /// splitInsideBlock - Split curli into multiple intervals inside MBB. |
| 367 | void splitInsideBlock(const MachineBasicBlock *); |
Jakob Stoklund Olesen | fc412d8 | 2010-08-13 21:18:48 +0000 | [diff] [blame] | 368 | }; |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 369 | |
| 370 | } |