Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 1 | //===- SplitKit.h - 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 | |
Benjamin Kramer | 00e08fc | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 15 | #ifndef LLVM_LIB_CODEGEN_SPLITKIT_H |
| 16 | #define LLVM_LIB_CODEGEN_SPLITKIT_H |
Sebastian Redl | 6796e4f | 2011-04-24 15:46:51 +0000 | [diff] [blame] | 17 | |
Jakob Stoklund Olesen | b5a457c | 2011-09-13 01:34:21 +0000 | [diff] [blame] | 18 | #include "LiveRangeCalc.h" |
Jakob Stoklund Olesen | db529a8 | 2011-04-06 03:57:00 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/ArrayRef.h" |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/BitVector.h" |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/DenseMap.h" |
Wei Mi | 815b02e | 2016-04-13 03:08:27 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/DenseSet.h" |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/IntervalMap.h" |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/PointerIntPair.h" |
Jakob Stoklund Olesen | 8d0963f7 | 2010-12-21 01:50:21 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallPtrSet.h" |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/SmallVector.h" |
| 27 | #include "llvm/CodeGen/LiveInterval.h" |
Daniil Fukalov | 5bcb2da | 2018-09-25 18:37:38 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/LiveIntervals.h" |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 30 | #include "llvm/CodeGen/MachineFunction.h" |
| 31 | #include "llvm/CodeGen/SlotIndexes.h" |
| 32 | #include "llvm/MC/LaneBitmask.h" |
| 33 | #include "llvm/Support/Compiler.h" |
| 34 | #include <utility> |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 35 | |
| 36 | namespace llvm { |
| 37 | |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 38 | class LiveIntervals; |
Jakob Stoklund Olesen | a17768f | 2010-10-14 23:49:52 +0000 | [diff] [blame] | 39 | class LiveRangeEdit; |
Benjamin Kramer | 4eed756 | 2013-06-17 19:00:36 +0000 | [diff] [blame] | 40 | class MachineBlockFrequencyInfo; |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 41 | class MachineDominatorTree; |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 42 | class MachineLoopInfo; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 43 | class MachineRegisterInfo; |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 44 | class TargetInstrInfo; |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 45 | class TargetRegisterInfo; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 46 | class VirtRegMap; |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 47 | |
Wei Mi | 723d45a | 2016-05-11 22:28:29 +0000 | [diff] [blame] | 48 | /// Determines the latest safe point in a block in which we can insert a split, |
| 49 | /// spill or other instruction related with CurLI. |
| 50 | class LLVM_LIBRARY_VISIBILITY InsertPointAnalysis { |
| 51 | private: |
| 52 | const LiveIntervals &LIS; |
| 53 | |
Wei Mi | 723d45a | 2016-05-11 22:28:29 +0000 | [diff] [blame] | 54 | /// Last legal insert point in each basic block in the current function. |
| 55 | /// The first entry is the first terminator, the second entry is the |
| 56 | /// last valid point to insert a split or spill for a variable that is |
| 57 | /// live into a landing pad successor. |
| 58 | SmallVector<std::pair<SlotIndex, SlotIndex>, 8> LastInsertPoint; |
| 59 | |
Wei Mi | 14a29ca | 2016-05-23 19:39:19 +0000 | [diff] [blame] | 60 | SlotIndex computeLastInsertPoint(const LiveInterval &CurLI, |
| 61 | const MachineBasicBlock &MBB); |
Wei Mi | 723d45a | 2016-05-11 22:28:29 +0000 | [diff] [blame] | 62 | |
| 63 | public: |
| 64 | InsertPointAnalysis(const LiveIntervals &lis, unsigned BBNum); |
| 65 | |
Wei Mi | 14a29ca | 2016-05-23 19:39:19 +0000 | [diff] [blame] | 66 | /// Return the base index of the last valid insert point for \pCurLI in \pMBB. |
| 67 | SlotIndex getLastInsertPoint(const LiveInterval &CurLI, |
| 68 | const MachineBasicBlock &MBB) { |
Wei Mi | 723d45a | 2016-05-11 22:28:29 +0000 | [diff] [blame] | 69 | unsigned Num = MBB.getNumber(); |
| 70 | // Inline the common simple case. |
| 71 | if (LastInsertPoint[Num].first.isValid() && |
| 72 | !LastInsertPoint[Num].second.isValid()) |
| 73 | return LastInsertPoint[Num].first; |
Wei Mi | 14a29ca | 2016-05-23 19:39:19 +0000 | [diff] [blame] | 74 | return computeLastInsertPoint(CurLI, MBB); |
Wei Mi | 723d45a | 2016-05-11 22:28:29 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Wei Mi | 14a29ca | 2016-05-23 19:39:19 +0000 | [diff] [blame] | 77 | /// Returns the last insert point as an iterator for \pCurLI in \pMBB. |
| 78 | MachineBasicBlock::iterator getLastInsertPointIter(const LiveInterval &CurLI, |
| 79 | MachineBasicBlock &MBB); |
Daniil Fukalov | 5bcb2da | 2018-09-25 18:37:38 +0000 | [diff] [blame] | 80 | |
| 81 | /// Return the base index of the first insert point in \pMBB. |
| 82 | SlotIndex getFirstInsertPoint(MachineBasicBlock &MBB) { |
| 83 | SlotIndex Res = LIS.getMBBStartIdx(&MBB); |
| 84 | if (!MBB.empty()) { |
| 85 | MachineBasicBlock::iterator MII = MBB.SkipPHIsLabelsAndDebug(MBB.begin()); |
| 86 | if (MII != MBB.end()) |
| 87 | Res = LIS.getInstructionIndex(*MII); |
| 88 | } |
| 89 | return Res; |
| 90 | } |
| 91 | |
Wei Mi | 723d45a | 2016-05-11 22:28:29 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 94 | /// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting |
| 95 | /// opportunities. |
Benjamin Kramer | b453775 | 2015-07-01 14:47:39 +0000 | [diff] [blame] | 96 | class LLVM_LIBRARY_VISIBILITY SplitAnalysis { |
Jakob Stoklund Olesen | 08e93b1 | 2010-08-10 17:07:22 +0000 | [diff] [blame] | 97 | public: |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 98 | const MachineFunction &MF; |
Jakob Stoklund Olesen | 1b847de | 2011-02-19 00:53:42 +0000 | [diff] [blame] | 99 | const VirtRegMap &VRM; |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 100 | const LiveIntervals &LIS; |
| 101 | const MachineLoopInfo &Loops; |
| 102 | const TargetInstrInfo &TII; |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 103 | |
Jakob Stoklund Olesen | f0ac26c | 2011-02-09 22:50:26 +0000 | [diff] [blame] | 104 | /// Additional information about basic blocks where the current variable is |
| 105 | /// live. Such a block will look like one of these templates: |
| 106 | /// |
| 107 | /// 1. | o---x | Internal to block. Variable is only live in this block. |
| 108 | /// 2. |---x | Live-in, kill. |
| 109 | /// 3. | o---| Def, live-out. |
Jakob Stoklund Olesen | a2e79ef | 2011-05-30 01:33:26 +0000 | [diff] [blame] | 110 | /// 4. |---x o---| Live-in, kill, def, live-out. Counted by NumGapBlocks. |
Jakob Stoklund Olesen | f0ac26c | 2011-02-09 22:50:26 +0000 | [diff] [blame] | 111 | /// 5. |---o---o---| Live-through with uses or defs. |
Jakob Stoklund Olesen | a2e79ef | 2011-05-30 01:33:26 +0000 | [diff] [blame] | 112 | /// 6. |-----------| Live-through without uses. Counted by NumThroughBlocks. |
| 113 | /// |
| 114 | /// Two BlockInfo entries are created for template 4. One for the live-in |
| 115 | /// segment, and one for the live-out segment. These entries look as if the |
| 116 | /// block were split in the middle where the live range isn't live. |
| 117 | /// |
| 118 | /// Live-through blocks without any uses don't get BlockInfo entries. They |
| 119 | /// are simply listed in ThroughBlocks instead. |
Jakob Stoklund Olesen | f0ac26c | 2011-02-09 22:50:26 +0000 | [diff] [blame] | 120 | /// |
| 121 | struct BlockInfo { |
| 122 | MachineBasicBlock *MBB; |
Jakob Stoklund Olesen | fe62d92 | 2011-08-02 22:54:14 +0000 | [diff] [blame] | 123 | SlotIndex FirstInstr; ///< First instr accessing current reg. |
| 124 | SlotIndex LastInstr; ///< Last instr accessing current reg. |
Jakob Stoklund Olesen | 77ee114 | 2011-08-02 22:37:22 +0000 | [diff] [blame] | 125 | SlotIndex FirstDef; ///< First non-phi valno->def, or SlotIndex(). |
Jakob Stoklund Olesen | f0ac26c | 2011-02-09 22:50:26 +0000 | [diff] [blame] | 126 | bool LiveIn; ///< Current reg is live in. |
| 127 | bool LiveOut; ///< Current reg is live out. |
Jakob Stoklund Olesen | 87360f7 | 2011-06-30 01:30:39 +0000 | [diff] [blame] | 128 | |
| 129 | /// isOneInstr - Returns true when this BlockInfo describes a single |
| 130 | /// instruction. |
| 131 | bool isOneInstr() const { |
Jakob Stoklund Olesen | fe62d92 | 2011-08-02 22:54:14 +0000 | [diff] [blame] | 132 | return SlotIndex::isSameInstr(FirstInstr, LastInstr); |
Jakob Stoklund Olesen | 87360f7 | 2011-06-30 01:30:39 +0000 | [diff] [blame] | 133 | } |
Jakob Stoklund Olesen | f0ac26c | 2011-02-09 22:50:26 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 136 | private: |
| 137 | // Current live interval. |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 138 | const LiveInterval *CurLI = nullptr; |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 139 | |
Wei Mi | 723d45a | 2016-05-11 22:28:29 +0000 | [diff] [blame] | 140 | /// Insert Point Analysis. |
| 141 | InsertPointAnalysis IPA; |
| 142 | |
Jakob Stoklund Olesen | b20b518 | 2012-01-12 17:53:44 +0000 | [diff] [blame] | 143 | // Sorted slot indexes of using instructions. |
| 144 | SmallVector<SlotIndex, 8> UseSlots; |
| 145 | |
Jakob Stoklund Olesen | db529a8 | 2011-04-06 03:57:00 +0000 | [diff] [blame] | 146 | /// UseBlocks - Blocks where CurLI has uses. |
| 147 | SmallVector<BlockInfo, 8> UseBlocks; |
| 148 | |
Jakob Stoklund Olesen | a2e79ef | 2011-05-30 01:33:26 +0000 | [diff] [blame] | 149 | /// NumGapBlocks - Number of duplicate entries in UseBlocks for blocks where |
| 150 | /// the live range has a gap. |
| 151 | unsigned NumGapBlocks; |
| 152 | |
Jakob Stoklund Olesen | db529a8 | 2011-04-06 03:57:00 +0000 | [diff] [blame] | 153 | /// ThroughBlocks - Block numbers where CurLI is live through without uses. |
Jakob Stoklund Olesen | f4afdfc | 2011-04-09 02:59:09 +0000 | [diff] [blame] | 154 | BitVector ThroughBlocks; |
| 155 | |
| 156 | /// NumThroughBlocks - Number of live-through blocks. |
| 157 | unsigned NumThroughBlocks; |
Jakob Stoklund Olesen | db529a8 | 2011-04-06 03:57:00 +0000 | [diff] [blame] | 158 | |
Jakob Stoklund Olesen | 7d6b6a0 | 2011-05-03 20:42:13 +0000 | [diff] [blame] | 159 | /// DidRepairRange - analyze was forced to shrinkToUses(). |
| 160 | bool DidRepairRange; |
| 161 | |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 162 | // Sumarize statistics by counting instructions using CurLI. |
Jakob Stoklund Olesen | abff280 | 2010-07-20 16:12:37 +0000 | [diff] [blame] | 163 | void analyzeUses(); |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 164 | |
Jakob Stoklund Olesen | f0ac26c | 2011-02-09 22:50:26 +0000 | [diff] [blame] | 165 | /// calcLiveBlockInfo - Compute per-block information about CurLI. |
Jakob Stoklund Olesen | 2b0f9e7 | 2011-03-05 18:33:49 +0000 | [diff] [blame] | 166 | bool calcLiveBlockInfo(); |
Jakob Stoklund Olesen | f0ac26c | 2011-02-09 22:50:26 +0000 | [diff] [blame] | 167 | |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 168 | public: |
Jakob Stoklund Olesen | 1b847de | 2011-02-19 00:53:42 +0000 | [diff] [blame] | 169 | SplitAnalysis(const VirtRegMap &vrm, const LiveIntervals &lis, |
Jakob Stoklund Olesen | f2c6e36 | 2010-07-20 23:50:15 +0000 | [diff] [blame] | 170 | const MachineLoopInfo &mli); |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 171 | |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 172 | /// analyze - set CurLI to the specified interval, and analyze how it may be |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 173 | /// split. |
| 174 | void analyze(const LiveInterval *li); |
| 175 | |
Jakob Stoklund Olesen | 7d6b6a0 | 2011-05-03 20:42:13 +0000 | [diff] [blame] | 176 | /// didRepairRange() - Returns true if CurLI was invalid and has been repaired |
| 177 | /// by analyze(). This really shouldn't happen, but sometimes the coalescer |
| 178 | /// can create live ranges that end in mid-air. |
| 179 | bool didRepairRange() const { return DidRepairRange; } |
| 180 | |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 181 | /// clear - clear all data structures so SplitAnalysis is ready to analyze a |
| 182 | /// new interval. |
| 183 | void clear(); |
| 184 | |
Jakob Stoklund Olesen | 034a80d | 2011-02-17 19:13:53 +0000 | [diff] [blame] | 185 | /// getParent - Return the last analyzed interval. |
| 186 | const LiveInterval &getParent() const { return *CurLI; } |
| 187 | |
Jakob Stoklund Olesen | 06c0f25 | 2011-02-21 23:09:46 +0000 | [diff] [blame] | 188 | /// isOriginalEndpoint - Return true if the original live range was killed or |
| 189 | /// (re-)defined at Idx. Idx should be the 'def' slot for a normal kill/def, |
| 190 | /// and 'use' for an early-clobber def. |
| 191 | /// This can be used to recognize code inserted by earlier live range |
| 192 | /// splitting. |
| 193 | bool isOriginalEndpoint(SlotIndex Idx) const; |
| 194 | |
Jakob Stoklund Olesen | b20b518 | 2012-01-12 17:53:44 +0000 | [diff] [blame] | 195 | /// getUseSlots - Return an array of SlotIndexes of instructions using CurLI. |
| 196 | /// This include both use and def operands, at most one entry per instruction. |
| 197 | ArrayRef<SlotIndex> getUseSlots() const { return UseSlots; } |
| 198 | |
Jakob Stoklund Olesen | db529a8 | 2011-04-06 03:57:00 +0000 | [diff] [blame] | 199 | /// getUseBlocks - Return an array of BlockInfo objects for the basic blocks |
| 200 | /// where CurLI has uses. |
Jakob Stoklund Olesen | b2abfa0 | 2011-05-28 02:32:57 +0000 | [diff] [blame] | 201 | ArrayRef<BlockInfo> getUseBlocks() const { return UseBlocks; } |
Jakob Stoklund Olesen | db529a8 | 2011-04-06 03:57:00 +0000 | [diff] [blame] | 202 | |
Jakob Stoklund Olesen | f4afdfc | 2011-04-09 02:59:09 +0000 | [diff] [blame] | 203 | /// getNumThroughBlocks - Return the number of through blocks. |
| 204 | unsigned getNumThroughBlocks() const { return NumThroughBlocks; } |
| 205 | |
| 206 | /// isThroughBlock - Return true if CurLI is live through MBB without uses. |
| 207 | bool isThroughBlock(unsigned MBB) const { return ThroughBlocks.test(MBB); } |
Jakob Stoklund Olesen | db529a8 | 2011-04-06 03:57:00 +0000 | [diff] [blame] | 208 | |
Jakob Stoklund Olesen | 5db4289 | 2011-04-12 21:30:53 +0000 | [diff] [blame] | 209 | /// getThroughBlocks - Return the set of through blocks. |
| 210 | const BitVector &getThroughBlocks() const { return ThroughBlocks; } |
| 211 | |
Jakob Stoklund Olesen | b2abfa0 | 2011-05-28 02:32:57 +0000 | [diff] [blame] | 212 | /// getNumLiveBlocks - Return the number of blocks where CurLI is live. |
| 213 | unsigned getNumLiveBlocks() const { |
Jakob Stoklund Olesen | a2e79ef | 2011-05-30 01:33:26 +0000 | [diff] [blame] | 214 | return getUseBlocks().size() - NumGapBlocks + getNumThroughBlocks(); |
Jakob Stoklund Olesen | b2abfa0 | 2011-05-28 02:32:57 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /// countLiveBlocks - Return the number of blocks where li is live. This is |
| 218 | /// guaranteed to return the same number as getNumLiveBlocks() after calling |
| 219 | /// analyze(li). |
Jakob Stoklund Olesen | 9f4b893 | 2011-04-26 22:33:12 +0000 | [diff] [blame] | 220 | unsigned countLiveBlocks(const LiveInterval *li) const; |
| 221 | |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 222 | using BlockPtrSet = SmallPtrSet<const MachineBasicBlock *, 16>; |
Jakob Stoklund Olesen | 6a0dc07 | 2010-07-20 21:46:58 +0000 | [diff] [blame] | 223 | |
Jakob Stoklund Olesen | 2d6d86b | 2011-08-05 22:20:45 +0000 | [diff] [blame] | 224 | /// shouldSplitSingleBlock - Returns true if it would help to create a local |
| 225 | /// live range for the instructions in BI. There is normally no benefit to |
| 226 | /// creating a live range for a single instruction, but it does enable |
| 227 | /// register class inflation if the instruction has a restricted register |
| 228 | /// class. |
| 229 | /// |
| 230 | /// @param BI The block to be isolated. |
| 231 | /// @param SingleInstrs True when single instructions should be isolated. |
| 232 | bool shouldSplitSingleBlock(const BlockInfo &BI, bool SingleInstrs) const; |
Wei Mi | 723d45a | 2016-05-11 22:28:29 +0000 | [diff] [blame] | 233 | |
| 234 | SlotIndex getLastSplitPoint(unsigned Num) { |
Wei Mi | 14a29ca | 2016-05-23 19:39:19 +0000 | [diff] [blame] | 235 | return IPA.getLastInsertPoint(*CurLI, *MF.getBlockNumbered(Num)); |
Wei Mi | 723d45a | 2016-05-11 22:28:29 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | MachineBasicBlock::iterator getLastSplitPointIter(MachineBasicBlock *BB) { |
Wei Mi | 14a29ca | 2016-05-23 19:39:19 +0000 | [diff] [blame] | 239 | return IPA.getLastInsertPointIter(*CurLI, *BB); |
Wei Mi | 723d45a | 2016-05-11 22:28:29 +0000 | [diff] [blame] | 240 | } |
Daniil Fukalov | 5bcb2da | 2018-09-25 18:37:38 +0000 | [diff] [blame] | 241 | |
| 242 | SlotIndex getFirstSplitPoint(unsigned Num) { |
| 243 | return IPA.getFirstInsertPoint(*MF.getBlockNumbered(Num)); |
| 244 | } |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 245 | }; |
| 246 | |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 247 | /// SplitEditor - Edit machine code and LiveIntervals for live range |
| 248 | /// splitting. |
| 249 | /// |
Jakob Stoklund Olesen | 5eb308b | 2010-08-06 22:17:33 +0000 | [diff] [blame] | 250 | /// - Create a SplitEditor from a SplitAnalysis. |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 251 | /// - Start a new live interval with openIntv. |
| 252 | /// - Mark the places where the new interval is entered using enterIntv* |
Fangrui Song | af7b183 | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 253 | /// - Mark the ranges where the new interval is used with useIntv* |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 254 | /// - Mark the places where the interval is exited with exitIntv*. |
| 255 | /// - Finish the current interval with closeIntv and repeat from 2. |
Jakob Stoklund Olesen | 7466927 | 2010-10-08 23:42:21 +0000 | [diff] [blame] | 256 | /// - Rewrite instructions with finish(). |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 257 | /// |
Benjamin Kramer | b453775 | 2015-07-01 14:47:39 +0000 | [diff] [blame] | 258 | class LLVM_LIBRARY_VISIBILITY SplitEditor { |
Jakob Stoklund Olesen | 0eeca44 | 2011-02-19 00:42:33 +0000 | [diff] [blame] | 259 | SplitAnalysis &SA; |
Wei Mi | 4eae278 | 2016-07-08 21:08:09 +0000 | [diff] [blame] | 260 | AliasAnalysis &AA; |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 261 | LiveIntervals &LIS; |
| 262 | VirtRegMap &VRM; |
| 263 | MachineRegisterInfo &MRI; |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 264 | MachineDominatorTree &MDT; |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 265 | const TargetInstrInfo &TII; |
| 266 | const TargetRegisterInfo &TRI; |
Benjamin Kramer | 4eed756 | 2013-06-17 19:00:36 +0000 | [diff] [blame] | 267 | const MachineBlockFrequencyInfo &MBFI; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 268 | |
Jakob Stoklund Olesen | 708d06f | 2011-09-12 16:49:21 +0000 | [diff] [blame] | 269 | public: |
Jakob Stoklund Olesen | 708d06f | 2011-09-12 16:49:21 +0000 | [diff] [blame] | 270 | /// ComplementSpillMode - Select how the complement live range should be |
| 271 | /// created. SplitEditor automatically creates interval 0 to contain |
| 272 | /// anything that isn't added to another interval. This complement interval |
| 273 | /// can get quite complicated, and it can sometimes be an advantage to allow |
| 274 | /// it to overlap the other intervals. If it is going to spill anyway, no |
| 275 | /// registers are wasted by keeping a value in two places at the same time. |
| 276 | enum ComplementSpillMode { |
| 277 | /// SM_Partition(Default) - Try to create the complement interval so it |
| 278 | /// doesn't overlap any other intervals, and the original interval is |
| 279 | /// partitioned. This may require a large number of back copies and extra |
| 280 | /// PHI-defs. Only segments marked with overlapIntv will be overlapping. |
| 281 | SM_Partition, |
| 282 | |
| 283 | /// SM_Size - Overlap intervals to minimize the number of inserted COPY |
| 284 | /// instructions. Copies to the complement interval are hoisted to their |
| 285 | /// common dominator, so only one COPY is required per value in the |
| 286 | /// complement interval. This also means that no extra PHI-defs need to be |
| 287 | /// inserted in the complement interval. |
| 288 | SM_Size, |
| 289 | |
| 290 | /// SM_Speed - Overlap intervals to minimize the expected execution |
| 291 | /// frequency of the inserted copies. This is very similar to SM_Size, but |
| 292 | /// the complement interval may get some extra PHI-defs. |
| 293 | SM_Speed |
| 294 | }; |
| 295 | |
| 296 | private: |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 297 | /// Edit - The current parent register and new intervals created. |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 298 | LiveRangeEdit *Edit = nullptr; |
Jakob Stoklund Olesen | a17768f | 2010-10-14 23:49:52 +0000 | [diff] [blame] | 299 | |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 300 | /// Index into Edit of the currently open interval. |
| 301 | /// The index 0 is used for the complement, so the first interval started by |
| 302 | /// openIntv will be 1. |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 303 | unsigned OpenIdx = 0; |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 304 | |
Jakob Stoklund Olesen | 708d06f | 2011-09-12 16:49:21 +0000 | [diff] [blame] | 305 | /// The current spill mode, selected by reset(). |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 306 | ComplementSpillMode SpillMode = SM_Partition; |
Jakob Stoklund Olesen | 708d06f | 2011-09-12 16:49:21 +0000 | [diff] [blame] | 307 | |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 308 | using RegAssignMap = IntervalMap<SlotIndex, unsigned>; |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 309 | |
| 310 | /// Allocator for the interval map. This will eventually be shared with |
| 311 | /// SlotIndexes and LiveIntervals. |
| 312 | RegAssignMap::Allocator Allocator; |
| 313 | |
| 314 | /// RegAssign - Map of the assigned register indexes. |
| 315 | /// Edit.get(RegAssign.lookup(Idx)) is the register that should be live at |
| 316 | /// Idx. |
| 317 | RegAssignMap RegAssign; |
| 318 | |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 319 | using ValueForcePair = PointerIntPair<VNInfo *, 1>; |
| 320 | using ValueMap = DenseMap<std::pair<unsigned, unsigned>, ValueForcePair>; |
Jakob Stoklund Olesen | 670ccd1 | 2011-03-01 23:14:53 +0000 | [diff] [blame] | 321 | |
| 322 | /// Values - keep track of the mapping from parent values to values in the new |
| 323 | /// intervals. Given a pair (RegIdx, ParentVNI->id), Values contains: |
| 324 | /// |
| 325 | /// 1. No entry - the value is not mapped to Edit.get(RegIdx). |
Jakob Stoklund Olesen | 393bfcb | 2011-09-13 23:09:04 +0000 | [diff] [blame] | 326 | /// 2. (Null, false) - the value is mapped to multiple values in |
| 327 | /// Edit.get(RegIdx). Each value is represented by a minimal live range at |
| 328 | /// its def. The full live range can be inferred exactly from the range |
| 329 | /// of RegIdx in RegAssign. |
| 330 | /// 3. (Null, true). As above, but the ranges in RegAssign are too large, and |
| 331 | /// the live range must be recomputed using LiveRangeCalc::extend(). |
| 332 | /// 4. (VNI, false) The value is mapped to a single new value. |
Jakob Stoklund Olesen | 670ccd1 | 2011-03-01 23:14:53 +0000 | [diff] [blame] | 333 | /// The new value has no live ranges anywhere. |
| 334 | ValueMap Values; |
| 335 | |
Jakob Stoklund Olesen | c1c622e | 2011-09-13 16:47:53 +0000 | [diff] [blame] | 336 | /// LRCalc - Cache for computing live ranges and SSA update. Each instance |
| 337 | /// can only handle non-overlapping live ranges, so use a separate |
| 338 | /// LiveRangeCalc instance for the complement interval when in spill mode. |
| 339 | LiveRangeCalc LRCalc[2]; |
| 340 | |
| 341 | /// getLRCalc - Return the LRCalc to use for RegIdx. In spill mode, the |
| 342 | /// complement interval can overlap the other intervals, so it gets its own |
| 343 | /// LRCalc instance. When not in spill mode, all intervals can share one. |
| 344 | LiveRangeCalc &getLRCalc(unsigned RegIdx) { |
| 345 | return LRCalc[SpillMode != SM_Partition && RegIdx != 0]; |
| 346 | } |
Jakob Stoklund Olesen | 44b7ae2 | 2011-04-15 17:24:49 +0000 | [diff] [blame] | 347 | |
Krzysztof Parzyszek | 31a5f88 | 2016-08-24 13:37:55 +0000 | [diff] [blame] | 348 | /// Find a subrange corresponding to the lane mask @p LM in the live |
| 349 | /// interval @p LI. The interval @p LI is assumed to contain such a subrange. |
| 350 | /// This function is used to find corresponding subranges between the |
| 351 | /// original interval and the new intervals. |
| 352 | LiveInterval::SubRange &getSubRangeForMask(LaneBitmask LM, LiveInterval &LI); |
| 353 | |
| 354 | /// Add a segment to the interval LI for the value number VNI. If LI has |
| 355 | /// subranges, corresponding segments will be added to them as well, but |
| 356 | /// with newly created value numbers. If Original is true, dead def will |
| 357 | /// only be added a subrange of LI if the corresponding subrange of the |
| 358 | /// original interval has a def at this index. Otherwise, all subranges |
| 359 | /// of LI will be updated. |
| 360 | void addDeadDef(LiveInterval &LI, VNInfo *VNI, bool Original); |
| 361 | |
Jakob Stoklund Olesen | 670ccd1 | 2011-03-01 23:14:53 +0000 | [diff] [blame] | 362 | /// defValue - define a value in RegIdx from ParentVNI at Idx. |
| 363 | /// Idx does not have to be ParentVNI->def, but it must be contained within |
| 364 | /// ParentVNI's live range in ParentLI. The new value is added to the value |
Krzysztof Parzyszek | 31a5f88 | 2016-08-24 13:37:55 +0000 | [diff] [blame] | 365 | /// map. The value being defined may either come from rematerialization |
| 366 | /// (or an inserted copy), or it may be coming from the original interval. |
| 367 | /// The parameter Original should be true in the latter case, otherwise |
| 368 | /// it should be false. |
Jakob Stoklund Olesen | 670ccd1 | 2011-03-01 23:14:53 +0000 | [diff] [blame] | 369 | /// Return the new LI value. |
Krzysztof Parzyszek | 31a5f88 | 2016-08-24 13:37:55 +0000 | [diff] [blame] | 370 | VNInfo *defValue(unsigned RegIdx, const VNInfo *ParentVNI, SlotIndex Idx, |
| 371 | bool Original); |
Jakob Stoklund Olesen | 670ccd1 | 2011-03-01 23:14:53 +0000 | [diff] [blame] | 372 | |
Jakob Stoklund Olesen | 393bfcb | 2011-09-13 23:09:04 +0000 | [diff] [blame] | 373 | /// forceRecompute - Force the live range of ParentVNI in RegIdx to be |
| 374 | /// recomputed by LiveRangeCalc::extend regardless of the number of defs. |
| 375 | /// This is used for values whose live range doesn't match RegAssign exactly. |
| 376 | /// They could have rematerialized, or back-copies may have been moved. |
Matthias Braun | ffc6b46 | 2018-02-02 00:08:19 +0000 | [diff] [blame] | 377 | void forceRecompute(unsigned RegIdx, const VNInfo &ParentVNI); |
| 378 | |
| 379 | /// Calls forceRecompute() on any affected regidx and on ParentVNI |
| 380 | /// predecessors in case of a phi definition. |
| 381 | void forceRecomputeVNI(const VNInfo &ParentVNI); |
Jakob Stoklund Olesen | e5a2e36 | 2011-09-13 18:05:29 +0000 | [diff] [blame] | 382 | |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 383 | /// defFromParent - Define Reg from ParentVNI at UseIdx using either |
| 384 | /// rematerialization or a COPY from parent. Return the new value. |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 385 | VNInfo *defFromParent(unsigned RegIdx, |
Jakob Stoklund Olesen | cfa7134 | 2010-11-10 19:31:50 +0000 | [diff] [blame] | 386 | VNInfo *ParentVNI, |
| 387 | SlotIndex UseIdx, |
| 388 | MachineBasicBlock &MBB, |
| 389 | MachineBasicBlock::iterator I); |
| 390 | |
Jakob Stoklund Olesen | b21abfe | 2011-09-13 22:22:39 +0000 | [diff] [blame] | 391 | /// removeBackCopies - Remove the copy instructions that defines the values |
| 392 | /// in the vector in the complement interval. |
| 393 | void removeBackCopies(SmallVectorImpl<VNInfo*> &Copies); |
| 394 | |
Jakob Stoklund Olesen | c4c6338 | 2011-09-14 16:45:39 +0000 | [diff] [blame] | 395 | /// getShallowDominator - Returns the least busy dominator of MBB that is |
| 396 | /// also dominated by DefMBB. Busy is measured by loop depth. |
| 397 | MachineBasicBlock *findShallowDominator(MachineBasicBlock *MBB, |
| 398 | MachineBasicBlock *DefMBB); |
| 399 | |
Wei Mi | 815b02e | 2016-04-13 03:08:27 +0000 | [diff] [blame] | 400 | /// Find out all the backCopies dominated by others. |
| 401 | void computeRedundantBackCopies(DenseSet<unsigned> &NotToHoistSet, |
| 402 | SmallVectorImpl<VNInfo *> &BackCopies); |
| 403 | |
| 404 | /// Hoist back-copies to the complement interval. It tries to hoist all |
| 405 | /// the back-copies to one BB if it is beneficial, or else simply remove |
Eric Christopher | 4449a75 | 2016-05-04 21:45:36 +0000 | [diff] [blame] | 406 | /// redundant backcopies dominated by others. |
Wei Mi | 815b02e | 2016-04-13 03:08:27 +0000 | [diff] [blame] | 407 | void hoistCopies(); |
Jakob Stoklund Olesen | b21abfe | 2011-09-13 22:22:39 +0000 | [diff] [blame] | 408 | |
Jakob Stoklund Olesen | 44b7ae2 | 2011-04-15 17:24:49 +0000 | [diff] [blame] | 409 | /// transferValues - Transfer values to the new ranges. |
| 410 | /// Return true if any ranges were skipped. |
| 411 | bool transferValues(); |
Jakob Stoklund Olesen | 4670353 | 2011-03-02 23:05:19 +0000 | [diff] [blame] | 412 | |
Krzysztof Parzyszek | f5fef36 | 2016-11-21 20:24:12 +0000 | [diff] [blame] | 413 | /// Live range @p LR corresponding to the lane Mask @p LM has a live |
| 414 | /// PHI def at the beginning of block @p B. Extend the range @p LR of |
| 415 | /// all predecessor values that reach this def. If @p LR is a subrange, |
| 416 | /// the array @p Undefs is the set of all locations where it is undefined |
| 417 | /// via <def,read-undef> in other subranges for the same register. |
Krzysztof Parzyszek | 31a5f88 | 2016-08-24 13:37:55 +0000 | [diff] [blame] | 418 | void extendPHIRange(MachineBasicBlock &B, LiveRangeCalc &LRC, |
Krzysztof Parzyszek | f5fef36 | 2016-11-21 20:24:12 +0000 | [diff] [blame] | 419 | LiveRange &LR, LaneBitmask LM, |
| 420 | ArrayRef<SlotIndex> Undefs); |
Krzysztof Parzyszek | 31a5f88 | 2016-08-24 13:37:55 +0000 | [diff] [blame] | 421 | |
Jakob Stoklund Olesen | e2dc0c9 | 2011-03-02 23:05:16 +0000 | [diff] [blame] | 422 | /// extendPHIKillRanges - Extend the ranges of all values killed by original |
| 423 | /// parent PHIDefs. |
| 424 | void extendPHIKillRanges(); |
| 425 | |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 426 | /// rewriteAssigned - Rewrite all uses of Edit.getReg() to assigned registers. |
Jakob Stoklund Olesen | 4670353 | 2011-03-02 23:05:19 +0000 | [diff] [blame] | 427 | void rewriteAssigned(bool ExtendRanges); |
Jakob Stoklund Olesen | 5fa42a4 | 2010-09-21 22:32:21 +0000 | [diff] [blame] | 428 | |
Jakob Stoklund Olesen | 5881799 | 2011-03-08 22:46:11 +0000 | [diff] [blame] | 429 | /// deleteRematVictims - Delete defs that are dead after rematerializing. |
| 430 | void deleteRematVictims(); |
| 431 | |
Matthias Braun | 94ebfcb | 2017-03-17 00:41:39 +0000 | [diff] [blame] | 432 | /// Add a copy instruction copying \p FromReg to \p ToReg before |
| 433 | /// \p InsertBefore. This can be invoked with a \p LaneMask which may make it |
| 434 | /// necessary to construct a sequence of copies to cover it exactly. |
| 435 | SlotIndex buildCopy(unsigned FromReg, unsigned ToReg, LaneBitmask LaneMask, |
| 436 | MachineBasicBlock &MBB, MachineBasicBlock::iterator InsertBefore, |
| 437 | bool Late, unsigned RegIdx); |
| 438 | |
| 439 | SlotIndex buildSingleSubRegCopy(unsigned FromReg, unsigned ToReg, |
| 440 | MachineBasicBlock &MB, MachineBasicBlock::iterator InsertBefore, |
Fangrui Song | 7d88286 | 2018-07-16 18:51:40 +0000 | [diff] [blame] | 441 | unsigned SubIdx, LiveInterval &DestLI, bool Late, SlotIndex Def); |
Matthias Braun | 94ebfcb | 2017-03-17 00:41:39 +0000 | [diff] [blame] | 442 | |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 443 | public: |
| 444 | /// Create a new SplitEditor for editing the LiveInterval analyzed by SA. |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 445 | /// Newly created intervals will be appended to newIntervals. |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 446 | SplitEditor(SplitAnalysis &sa, AliasAnalysis &aa, LiveIntervals &lis, |
| 447 | VirtRegMap &vrm, MachineDominatorTree &mdt, |
| 448 | MachineBlockFrequencyInfo &mbfi); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 449 | |
Jakob Stoklund Olesen | bece06f | 2011-03-03 01:29:13 +0000 | [diff] [blame] | 450 | /// reset - Prepare for a new split. |
Jakob Stoklund Olesen | 708d06f | 2011-09-12 16:49:21 +0000 | [diff] [blame] | 451 | void reset(LiveRangeEdit&, ComplementSpillMode = SM_Partition); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 452 | |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 453 | /// Create a new virtual register and live interval. |
Jakob Stoklund Olesen | e1b43c3 | 2011-04-12 18:11:31 +0000 | [diff] [blame] | 454 | /// Return the interval index, starting from 1. Interval index 0 is the |
| 455 | /// implicit complement interval. |
| 456 | unsigned openIntv(); |
| 457 | |
| 458 | /// currentIntv - Return the current interval index. |
| 459 | unsigned currentIntv() const { return OpenIdx; } |
| 460 | |
| 461 | /// selectIntv - Select a previously opened interval index. |
| 462 | void selectIntv(unsigned Idx); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 463 | |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 464 | /// enterIntvBefore - Enter the open interval before the instruction at Idx. |
| 465 | /// If the parent interval is not live before Idx, a COPY is not inserted. |
| 466 | /// Return the beginning of the new live range. |
| 467 | SlotIndex enterIntvBefore(SlotIndex Idx); |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 468 | |
Jakob Stoklund Olesen | 87360f7 | 2011-06-30 01:30:39 +0000 | [diff] [blame] | 469 | /// enterIntvAfter - Enter the open interval after the instruction at Idx. |
| 470 | /// Return the beginning of the new live range. |
| 471 | SlotIndex enterIntvAfter(SlotIndex Idx); |
| 472 | |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 473 | /// enterIntvAtEnd - Enter the open interval at the end of MBB. |
Eric Christopher | 68c7a1c | 2014-05-20 17:11:11 +0000 | [diff] [blame] | 474 | /// Use the open interval from the inserted copy to the MBB end. |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 475 | /// Return the beginning of the new live range. |
| 476 | SlotIndex enterIntvAtEnd(MachineBasicBlock &MBB); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 477 | |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 478 | /// useIntv - indicate that all instructions in MBB should use OpenLI. |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 479 | void useIntv(const MachineBasicBlock &MBB); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 480 | |
Jakob Stoklund Olesen | 0786284 | 2011-01-26 00:50:53 +0000 | [diff] [blame] | 481 | /// useIntv - indicate that all instructions in range should use OpenLI. |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 482 | void useIntv(SlotIndex Start, SlotIndex End); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 483 | |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 484 | /// leaveIntvAfter - Leave the open interval after the instruction at Idx. |
| 485 | /// Return the end of the live range. |
| 486 | SlotIndex leaveIntvAfter(SlotIndex Idx); |
Jakob Stoklund Olesen | f1b05f2 | 2010-08-12 17:07:14 +0000 | [diff] [blame] | 487 | |
Jakob Stoklund Olesen | 9b05777 | 2011-02-09 23:30:25 +0000 | [diff] [blame] | 488 | /// leaveIntvBefore - Leave the open interval before the instruction at Idx. |
| 489 | /// Return the end of the live range. |
| 490 | SlotIndex leaveIntvBefore(SlotIndex Idx); |
| 491 | |
Jakob Stoklund Olesen | 7536f72 | 2010-08-04 22:08:39 +0000 | [diff] [blame] | 492 | /// leaveIntvAtTop - Leave the interval at the top of MBB. |
Jakob Stoklund Olesen | 207c868 | 2011-02-03 17:04:16 +0000 | [diff] [blame] | 493 | /// Add liveness from the MBB top to the copy. |
| 494 | /// Return the end of the live range. |
| 495 | SlotIndex leaveIntvAtTop(MachineBasicBlock &MBB); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 496 | |
Jakob Stoklund Olesen | 5c716bd | 2011-02-08 18:50:21 +0000 | [diff] [blame] | 497 | /// overlapIntv - Indicate that all instructions in range should use the open |
| 498 | /// interval, but also let the complement interval be live. |
| 499 | /// |
| 500 | /// This doubles the register pressure, but is sometimes required to deal with |
| 501 | /// register uses after the last valid split point. |
| 502 | /// |
| 503 | /// The Start index should be a return value from a leaveIntv* call, and End |
| 504 | /// should be in the same basic block. The parent interval must have the same |
| 505 | /// value across the range. |
| 506 | /// |
| 507 | void overlapIntv(SlotIndex Start, SlotIndex End); |
| 508 | |
Jakob Stoklund Olesen | 7466927 | 2010-10-08 23:42:21 +0000 | [diff] [blame] | 509 | /// finish - after all the new live ranges have been created, compute the |
| 510 | /// remaining live range, and rewrite instructions to use the new registers. |
Jakob Stoklund Olesen | 5928046 | 2011-04-21 18:38:15 +0000 | [diff] [blame] | 511 | /// @param LRMap When not null, this vector will map each live range in Edit |
| 512 | /// back to the indices returned by openIntv. |
| 513 | /// There may be extra indices created by dead code elimination. |
Craig Topper | 695aa80 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 514 | void finish(SmallVectorImpl<unsigned> *LRMap = nullptr); |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 515 | |
Jim Grosbach | 000564c | 2015-05-02 00:44:07 +0000 | [diff] [blame] | 516 | /// dump - print the current interval mapping to dbgs(). |
Eric Christopher | 0f43811 | 2011-02-03 06:18:29 +0000 | [diff] [blame] | 517 | void dump() const; |
| 518 | |
Jakob Stoklund Olesen | f017900 | 2010-07-26 23:44:11 +0000 | [diff] [blame] | 519 | // ===--- High level methods ---=== |
| 520 | |
Jakob Stoklund Olesen | fd5c513 | 2011-04-12 19:32:53 +0000 | [diff] [blame] | 521 | /// splitSingleBlock - Split CurLI into a separate live interval around the |
| 522 | /// uses in a single block. This is intended to be used as part of a larger |
| 523 | /// split, and doesn't call finish(). |
| 524 | void splitSingleBlock(const SplitAnalysis::BlockInfo &BI); |
| 525 | |
Jakob Stoklund Olesen | b4ddedc | 2011-07-15 21:47:57 +0000 | [diff] [blame] | 526 | /// splitLiveThroughBlock - Split CurLI in the given block such that it |
| 527 | /// enters the block in IntvIn and leaves it in IntvOut. There may be uses in |
| 528 | /// the block, but they will be ignored when placing split points. |
| 529 | /// |
| 530 | /// @param MBBNum Block number. |
| 531 | /// @param IntvIn Interval index entering the block. |
| 532 | /// @param LeaveBefore When set, leave IntvIn before this point. |
| 533 | /// @param IntvOut Interval index leaving the block. |
| 534 | /// @param EnterAfter When set, enter IntvOut after this point. |
| 535 | void splitLiveThroughBlock(unsigned MBBNum, |
| 536 | unsigned IntvIn, SlotIndex LeaveBefore, |
| 537 | unsigned IntvOut, SlotIndex EnterAfter); |
| 538 | |
| 539 | /// splitRegInBlock - Split CurLI in the given block such that it enters the |
| 540 | /// block in IntvIn and leaves it on the stack (or not at all). Split points |
| 541 | /// are placed in a way that avoids putting uses in the stack interval. This |
| 542 | /// may require creating a local interval when there is interference. |
| 543 | /// |
| 544 | /// @param BI Block descriptor. |
| 545 | /// @param IntvIn Interval index entering the block. Not 0. |
| 546 | /// @param LeaveBefore When set, leave IntvIn before this point. |
| 547 | void splitRegInBlock(const SplitAnalysis::BlockInfo &BI, |
| 548 | unsigned IntvIn, SlotIndex LeaveBefore); |
| 549 | |
| 550 | /// splitRegOutBlock - Split CurLI in the given block such that it enters the |
| 551 | /// block on the stack (or isn't live-in at all) and leaves it in IntvOut. |
| 552 | /// Split points are placed to avoid interference and such that the uses are |
| 553 | /// not in the stack interval. This may require creating a local interval |
| 554 | /// when there is interference. |
| 555 | /// |
| 556 | /// @param BI Block descriptor. |
| 557 | /// @param IntvOut Interval index leaving the block. |
| 558 | /// @param EnterAfter When set, enter IntvOut after this point. |
| 559 | void splitRegOutBlock(const SplitAnalysis::BlockInfo &BI, |
| 560 | unsigned IntvOut, SlotIndex EnterAfter); |
Jakob Stoklund Olesen | fc412d8 | 2010-08-13 21:18:48 +0000 | [diff] [blame] | 561 | }; |
Jakob Stoklund Olesen | 8ae0263 | 2010-07-20 15:41:07 +0000 | [diff] [blame] | 562 | |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 563 | } // end namespace llvm |
Sebastian Redl | 6796e4f | 2011-04-24 15:46:51 +0000 | [diff] [blame] | 564 | |
Eugene Zelenko | 7cf6af5 | 2017-08-29 22:32:07 +0000 | [diff] [blame] | 565 | #endif // LLVM_LIB_CODEGEN_SPLITKIT_H |