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