blob: f029c73d122a927b911fd439b998590c4bdaa1e7 [file] [log] [blame]
Jakob Stoklund Olesen8dd070e2011-01-04 21:10:05 +00001//===-------- SplitKit.h - Toolkit for splitting live ranges ----*- C++ -*-===//
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +00002//
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
Sebastian Redl6796e4f2011-04-24 15:46:51 +000015#ifndef LLVM_CODEGEN_SPLITKIT_H
16#define LLVM_CODEGEN_SPLITKIT_H
17
Jakob Stoklund Olesenb5a457c2011-09-13 01:34:21 +000018#include "LiveRangeCalc.h"
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +000019#include "llvm/ADT/ArrayRef.h"
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000020#include "llvm/ADT/DenseMap.h"
Eric Christopher0f438112011-02-03 06:18:29 +000021#include "llvm/ADT/IntervalMap.h"
Jakob Stoklund Olesen8d0963f2010-12-21 01:50:21 +000022#include "llvm/ADT/SmallPtrSet.h"
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000023
24namespace llvm {
25
Eric Christopher0f438112011-02-03 06:18:29 +000026class ConnectedVNInfoEqClasses;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000027class LiveInterval;
28class LiveIntervals;
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +000029class LiveRangeEdit;
Benjamin Kramer4eed7562013-06-17 19:00:36 +000030class MachineBlockFrequencyInfo;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000031class MachineInstr;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000032class MachineLoopInfo;
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +000033class MachineRegisterInfo;
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +000034class TargetInstrInfo;
Jakob Stoklund Olesencfa71342010-11-10 19:31:50 +000035class TargetRegisterInfo;
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +000036class VirtRegMap;
37class VNInfo;
Jakob Stoklund Olesen532de3d2010-10-22 20:28:21 +000038class raw_ostream;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000039
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +000040/// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting
41/// opportunities.
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000042class SplitAnalysis {
Jakob Stoklund Olesen08e93b12010-08-10 17:07:22 +000043public:
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +000044 const MachineFunction &MF;
Jakob Stoklund Olesen1b847de2011-02-19 00:53:42 +000045 const VirtRegMap &VRM;
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +000046 const LiveIntervals &LIS;
47 const MachineLoopInfo &Loops;
48 const TargetInstrInfo &TII;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000049
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +000050 /// Additional information about basic blocks where the current variable is
51 /// live. Such a block will look like one of these templates:
52 ///
53 /// 1. | o---x | Internal to block. Variable is only live in this block.
54 /// 2. |---x | Live-in, kill.
55 /// 3. | o---| Def, live-out.
Jakob Stoklund Olesena2e79ef2011-05-30 01:33:26 +000056 /// 4. |---x o---| Live-in, kill, def, live-out. Counted by NumGapBlocks.
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +000057 /// 5. |---o---o---| Live-through with uses or defs.
Jakob Stoklund Olesena2e79ef2011-05-30 01:33:26 +000058 /// 6. |-----------| Live-through without uses. Counted by NumThroughBlocks.
59 ///
60 /// Two BlockInfo entries are created for template 4. One for the live-in
61 /// segment, and one for the live-out segment. These entries look as if the
62 /// block were split in the middle where the live range isn't live.
63 ///
64 /// Live-through blocks without any uses don't get BlockInfo entries. They
65 /// are simply listed in ThroughBlocks instead.
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +000066 ///
67 struct BlockInfo {
68 MachineBasicBlock *MBB;
Jakob Stoklund Olesenfe62d922011-08-02 22:54:14 +000069 SlotIndex FirstInstr; ///< First instr accessing current reg.
70 SlotIndex LastInstr; ///< Last instr accessing current reg.
Jakob Stoklund Olesen77ee1142011-08-02 22:37:22 +000071 SlotIndex FirstDef; ///< First non-phi valno->def, or SlotIndex().
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +000072 bool LiveIn; ///< Current reg is live in.
73 bool LiveOut; ///< Current reg is live out.
Jakob Stoklund Olesen87360f72011-06-30 01:30:39 +000074
75 /// isOneInstr - Returns true when this BlockInfo describes a single
76 /// instruction.
77 bool isOneInstr() const {
Jakob Stoklund Olesenfe62d922011-08-02 22:54:14 +000078 return SlotIndex::isSameInstr(FirstInstr, LastInstr);
Jakob Stoklund Olesen87360f72011-06-30 01:30:39 +000079 }
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +000080 };
81
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +000082private:
83 // Current live interval.
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +000084 const LiveInterval *CurLI;
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +000085
Jakob Stoklund Olesenb20b5182012-01-12 17:53:44 +000086 // Sorted slot indexes of using instructions.
87 SmallVector<SlotIndex, 8> UseSlots;
88
Jakob Stoklund Olesen1a774452011-04-05 04:20:27 +000089 /// LastSplitPoint - Last legal split point in each basic block in the current
90 /// function. The first entry is the first terminator, the second entry is the
91 /// last valid split point for a variable that is live in to a landing pad
92 /// successor.
93 SmallVector<std::pair<SlotIndex, SlotIndex>, 8> LastSplitPoint;
94
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +000095 /// UseBlocks - Blocks where CurLI has uses.
96 SmallVector<BlockInfo, 8> UseBlocks;
97
Jakob Stoklund Olesena2e79ef2011-05-30 01:33:26 +000098 /// NumGapBlocks - Number of duplicate entries in UseBlocks for blocks where
99 /// the live range has a gap.
100 unsigned NumGapBlocks;
101
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000102 /// ThroughBlocks - Block numbers where CurLI is live through without uses.
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000103 BitVector ThroughBlocks;
104
105 /// NumThroughBlocks - Number of live-through blocks.
106 unsigned NumThroughBlocks;
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000107
Jakob Stoklund Olesen7d6b6a02011-05-03 20:42:13 +0000108 /// DidRepairRange - analyze was forced to shrinkToUses().
109 bool DidRepairRange;
110
Jakob Stoklund Olesen1a774452011-04-05 04:20:27 +0000111 SlotIndex computeLastSplitPoint(unsigned Num);
112
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +0000113 // Sumarize statistics by counting instructions using CurLI.
Jakob Stoklund Olesenabff2802010-07-20 16:12:37 +0000114 void analyzeUses();
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000115
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +0000116 /// calcLiveBlockInfo - Compute per-block information about CurLI.
Jakob Stoklund Olesen2b0f9e72011-03-05 18:33:49 +0000117 bool calcLiveBlockInfo();
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +0000118
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000119public:
Jakob Stoklund Olesen1b847de2011-02-19 00:53:42 +0000120 SplitAnalysis(const VirtRegMap &vrm, const LiveIntervals &lis,
Jakob Stoklund Olesenf2c6e362010-07-20 23:50:15 +0000121 const MachineLoopInfo &mli);
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000122
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +0000123 /// analyze - set CurLI to the specified interval, and analyze how it may be
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000124 /// split.
125 void analyze(const LiveInterval *li);
126
Jakob Stoklund Olesen7d6b6a02011-05-03 20:42:13 +0000127 /// didRepairRange() - Returns true if CurLI was invalid and has been repaired
128 /// by analyze(). This really shouldn't happen, but sometimes the coalescer
129 /// can create live ranges that end in mid-air.
130 bool didRepairRange() const { return DidRepairRange; }
131
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000132 /// clear - clear all data structures so SplitAnalysis is ready to analyze a
133 /// new interval.
134 void clear();
135
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +0000136 /// getParent - Return the last analyzed interval.
137 const LiveInterval &getParent() const { return *CurLI; }
138
Jakob Stoklund Olesen74c4f972012-01-11 02:07:00 +0000139 /// getLastSplitPoint - Return the base index of the last valid split point
Jakob Stoklund Olesen1a774452011-04-05 04:20:27 +0000140 /// in the basic block numbered Num.
141 SlotIndex getLastSplitPoint(unsigned Num) {
142 // Inline the common simple case.
143 if (LastSplitPoint[Num].first.isValid() &&
144 !LastSplitPoint[Num].second.isValid())
145 return LastSplitPoint[Num].first;
146 return computeLastSplitPoint(Num);
147 }
148
Jakob Stoklund Olesen74c4f972012-01-11 02:07:00 +0000149 /// getLastSplitPointIter - Returns the last split point as an iterator.
150 MachineBasicBlock::iterator getLastSplitPointIter(MachineBasicBlock*);
151
Jakob Stoklund Olesen06c0f252011-02-21 23:09:46 +0000152 /// isOriginalEndpoint - Return true if the original live range was killed or
153 /// (re-)defined at Idx. Idx should be the 'def' slot for a normal kill/def,
154 /// and 'use' for an early-clobber def.
155 /// This can be used to recognize code inserted by earlier live range
156 /// splitting.
157 bool isOriginalEndpoint(SlotIndex Idx) const;
158
Jakob Stoklund Olesenb20b5182012-01-12 17:53:44 +0000159 /// getUseSlots - Return an array of SlotIndexes of instructions using CurLI.
160 /// This include both use and def operands, at most one entry per instruction.
161 ArrayRef<SlotIndex> getUseSlots() const { return UseSlots; }
162
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000163 /// getUseBlocks - Return an array of BlockInfo objects for the basic blocks
164 /// where CurLI has uses.
Jakob Stoklund Olesenb2abfa02011-05-28 02:32:57 +0000165 ArrayRef<BlockInfo> getUseBlocks() const { return UseBlocks; }
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000166
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000167 /// getNumThroughBlocks - Return the number of through blocks.
168 unsigned getNumThroughBlocks() const { return NumThroughBlocks; }
169
170 /// isThroughBlock - Return true if CurLI is live through MBB without uses.
171 bool isThroughBlock(unsigned MBB) const { return ThroughBlocks.test(MBB); }
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000172
Jakob Stoklund Olesen5db42892011-04-12 21:30:53 +0000173 /// getThroughBlocks - Return the set of through blocks.
174 const BitVector &getThroughBlocks() const { return ThroughBlocks; }
175
Jakob Stoklund Olesenb2abfa02011-05-28 02:32:57 +0000176 /// getNumLiveBlocks - Return the number of blocks where CurLI is live.
177 unsigned getNumLiveBlocks() const {
Jakob Stoklund Olesena2e79ef2011-05-30 01:33:26 +0000178 return getUseBlocks().size() - NumGapBlocks + getNumThroughBlocks();
Jakob Stoklund Olesenb2abfa02011-05-28 02:32:57 +0000179 }
180
181 /// countLiveBlocks - Return the number of blocks where li is live. This is
182 /// guaranteed to return the same number as getNumLiveBlocks() after calling
183 /// analyze(li).
Jakob Stoklund Olesen9f4b8932011-04-26 22:33:12 +0000184 unsigned countLiveBlocks(const LiveInterval *li) const;
185
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +0000186 typedef SmallPtrSet<const MachineBasicBlock*, 16> BlockPtrSet;
187
Jakob Stoklund Olesen2d6d86b2011-08-05 22:20:45 +0000188 /// shouldSplitSingleBlock - Returns true if it would help to create a local
189 /// live range for the instructions in BI. There is normally no benefit to
190 /// creating a live range for a single instruction, but it does enable
191 /// register class inflation if the instruction has a restricted register
192 /// class.
193 ///
194 /// @param BI The block to be isolated.
195 /// @param SingleInstrs True when single instructions should be isolated.
196 bool shouldSplitSingleBlock(const BlockInfo &BI, bool SingleInstrs) const;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000197};
198
Jakob Stoklund Olesen1407c842010-08-18 19:00:08 +0000199
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000200/// SplitEditor - Edit machine code and LiveIntervals for live range
201/// splitting.
202///
Jakob Stoklund Olesen5eb308b2010-08-06 22:17:33 +0000203/// - Create a SplitEditor from a SplitAnalysis.
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000204/// - Start a new live interval with openIntv.
205/// - Mark the places where the new interval is entered using enterIntv*
206/// - Mark the ranges where the new interval is used with useIntv*
207/// - Mark the places where the interval is exited with exitIntv*.
208/// - Finish the current interval with closeIntv and repeat from 2.
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +0000209/// - Rewrite instructions with finish().
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000210///
211class SplitEditor {
Jakob Stoklund Olesen0eeca442011-02-19 00:42:33 +0000212 SplitAnalysis &SA;
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +0000213 LiveIntervals &LIS;
214 VirtRegMap &VRM;
215 MachineRegisterInfo &MRI;
Eric Christopher0f438112011-02-03 06:18:29 +0000216 MachineDominatorTree &MDT;
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +0000217 const TargetInstrInfo &TII;
218 const TargetRegisterInfo &TRI;
Benjamin Kramer4eed7562013-06-17 19:00:36 +0000219 const MachineBlockFrequencyInfo &MBFI;
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000220
Jakob Stoklund Olesen708d06f2011-09-12 16:49:21 +0000221public:
222
223 /// ComplementSpillMode - Select how the complement live range should be
224 /// created. SplitEditor automatically creates interval 0 to contain
225 /// anything that isn't added to another interval. This complement interval
226 /// can get quite complicated, and it can sometimes be an advantage to allow
227 /// it to overlap the other intervals. If it is going to spill anyway, no
228 /// registers are wasted by keeping a value in two places at the same time.
229 enum ComplementSpillMode {
230 /// SM_Partition(Default) - Try to create the complement interval so it
231 /// doesn't overlap any other intervals, and the original interval is
232 /// partitioned. This may require a large number of back copies and extra
233 /// PHI-defs. Only segments marked with overlapIntv will be overlapping.
234 SM_Partition,
235
236 /// SM_Size - Overlap intervals to minimize the number of inserted COPY
237 /// instructions. Copies to the complement interval are hoisted to their
238 /// common dominator, so only one COPY is required per value in the
239 /// complement interval. This also means that no extra PHI-defs need to be
240 /// inserted in the complement interval.
241 SM_Size,
242
243 /// SM_Speed - Overlap intervals to minimize the expected execution
244 /// frequency of the inserted copies. This is very similar to SM_Size, but
245 /// the complement interval may get some extra PHI-defs.
246 SM_Speed
247 };
248
249private:
250
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +0000251 /// Edit - The current parent register and new intervals created.
Jakob Stoklund Olesena2cae582011-03-02 23:31:50 +0000252 LiveRangeEdit *Edit;
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000253
Eric Christopher0f438112011-02-03 06:18:29 +0000254 /// Index into Edit of the currently open interval.
255 /// The index 0 is used for the complement, so the first interval started by
256 /// openIntv will be 1.
257 unsigned OpenIdx;
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000258
Jakob Stoklund Olesen708d06f2011-09-12 16:49:21 +0000259 /// The current spill mode, selected by reset().
260 ComplementSpillMode SpillMode;
261
Eric Christopher0f438112011-02-03 06:18:29 +0000262 typedef IntervalMap<SlotIndex, unsigned> RegAssignMap;
263
264 /// Allocator for the interval map. This will eventually be shared with
265 /// SlotIndexes and LiveIntervals.
266 RegAssignMap::Allocator Allocator;
267
268 /// RegAssign - Map of the assigned register indexes.
269 /// Edit.get(RegAssign.lookup(Idx)) is the register that should be live at
270 /// Idx.
271 RegAssignMap RegAssign;
272
Jakob Stoklund Olesen393bfcb2011-09-13 23:09:04 +0000273 typedef PointerIntPair<VNInfo*, 1> ValueForcePair;
274 typedef DenseMap<std::pair<unsigned, unsigned>, ValueForcePair> ValueMap;
Jakob Stoklund Olesen670ccd12011-03-01 23:14:53 +0000275
276 /// Values - keep track of the mapping from parent values to values in the new
277 /// intervals. Given a pair (RegIdx, ParentVNI->id), Values contains:
278 ///
279 /// 1. No entry - the value is not mapped to Edit.get(RegIdx).
Jakob Stoklund Olesen393bfcb2011-09-13 23:09:04 +0000280 /// 2. (Null, false) - the value is mapped to multiple values in
281 /// Edit.get(RegIdx). Each value is represented by a minimal live range at
282 /// its def. The full live range can be inferred exactly from the range
283 /// of RegIdx in RegAssign.
284 /// 3. (Null, true). As above, but the ranges in RegAssign are too large, and
285 /// the live range must be recomputed using LiveRangeCalc::extend().
286 /// 4. (VNI, false) The value is mapped to a single new value.
Jakob Stoklund Olesen670ccd12011-03-01 23:14:53 +0000287 /// The new value has no live ranges anywhere.
288 ValueMap Values;
289
Jakob Stoklund Olesenc1c622e2011-09-13 16:47:53 +0000290 /// LRCalc - Cache for computing live ranges and SSA update. Each instance
291 /// can only handle non-overlapping live ranges, so use a separate
292 /// LiveRangeCalc instance for the complement interval when in spill mode.
293 LiveRangeCalc LRCalc[2];
294
295 /// getLRCalc - Return the LRCalc to use for RegIdx. In spill mode, the
296 /// complement interval can overlap the other intervals, so it gets its own
297 /// LRCalc instance. When not in spill mode, all intervals can share one.
298 LiveRangeCalc &getLRCalc(unsigned RegIdx) {
299 return LRCalc[SpillMode != SM_Partition && RegIdx != 0];
300 }
Jakob Stoklund Olesen44b7ae22011-04-15 17:24:49 +0000301
Jakob Stoklund Olesen670ccd12011-03-01 23:14:53 +0000302 /// defValue - define a value in RegIdx from ParentVNI at Idx.
303 /// Idx does not have to be ParentVNI->def, but it must be contained within
304 /// ParentVNI's live range in ParentLI. The new value is added to the value
305 /// map.
306 /// Return the new LI value.
307 VNInfo *defValue(unsigned RegIdx, const VNInfo *ParentVNI, SlotIndex Idx);
308
Jakob Stoklund Olesen393bfcb2011-09-13 23:09:04 +0000309 /// forceRecompute - Force the live range of ParentVNI in RegIdx to be
310 /// recomputed by LiveRangeCalc::extend regardless of the number of defs.
311 /// This is used for values whose live range doesn't match RegAssign exactly.
312 /// They could have rematerialized, or back-copies may have been moved.
313 void forceRecompute(unsigned RegIdx, const VNInfo *ParentVNI);
Jakob Stoklund Olesene5a2e362011-09-13 18:05:29 +0000314
Jakob Stoklund Olesencfa71342010-11-10 19:31:50 +0000315 /// defFromParent - Define Reg from ParentVNI at UseIdx using either
316 /// rematerialization or a COPY from parent. Return the new value.
Eric Christopher0f438112011-02-03 06:18:29 +0000317 VNInfo *defFromParent(unsigned RegIdx,
Jakob Stoklund Olesencfa71342010-11-10 19:31:50 +0000318 VNInfo *ParentVNI,
319 SlotIndex UseIdx,
320 MachineBasicBlock &MBB,
321 MachineBasicBlock::iterator I);
322
Jakob Stoklund Olesenb21abfe2011-09-13 22:22:39 +0000323 /// removeBackCopies - Remove the copy instructions that defines the values
324 /// in the vector in the complement interval.
325 void removeBackCopies(SmallVectorImpl<VNInfo*> &Copies);
326
Jakob Stoklund Olesenc4c63382011-09-14 16:45:39 +0000327 /// getShallowDominator - Returns the least busy dominator of MBB that is
328 /// also dominated by DefMBB. Busy is measured by loop depth.
329 MachineBasicBlock *findShallowDominator(MachineBasicBlock *MBB,
330 MachineBasicBlock *DefMBB);
331
Jakob Stoklund Olesenb21abfe2011-09-13 22:22:39 +0000332 /// hoistCopiesForSize - Hoist back-copies to the complement interval in a
333 /// way that minimizes code size. This implements the SM_Size spill mode.
334 void hoistCopiesForSize();
335
Jakob Stoklund Olesen44b7ae22011-04-15 17:24:49 +0000336 /// transferValues - Transfer values to the new ranges.
337 /// Return true if any ranges were skipped.
338 bool transferValues();
Jakob Stoklund Olesen46703532011-03-02 23:05:19 +0000339
Jakob Stoklund Olesene2dc0c92011-03-02 23:05:16 +0000340 /// extendPHIKillRanges - Extend the ranges of all values killed by original
341 /// parent PHIDefs.
342 void extendPHIKillRanges();
343
Eric Christopher0f438112011-02-03 06:18:29 +0000344 /// rewriteAssigned - Rewrite all uses of Edit.getReg() to assigned registers.
Jakob Stoklund Olesen46703532011-03-02 23:05:19 +0000345 void rewriteAssigned(bool ExtendRanges);
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000346
Jakob Stoklund Olesen58817992011-03-08 22:46:11 +0000347 /// deleteRematVictims - Delete defs that are dead after rematerializing.
348 void deleteRematVictims();
349
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000350public:
351 /// Create a new SplitEditor for editing the LiveInterval analyzed by SA.
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000352 /// Newly created intervals will be appended to newIntervals.
Jakob Stoklund Olesend68f4582010-10-28 20:34:50 +0000353 SplitEditor(SplitAnalysis &SA, LiveIntervals&, VirtRegMap&,
Benjamin Kramer4eed7562013-06-17 19:00:36 +0000354 MachineDominatorTree&, MachineBlockFrequencyInfo &);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000355
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +0000356 /// reset - Prepare for a new split.
Jakob Stoklund Olesen708d06f2011-09-12 16:49:21 +0000357 void reset(LiveRangeEdit&, ComplementSpillMode = SM_Partition);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000358
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000359 /// Create a new virtual register and live interval.
Jakob Stoklund Olesene1b43c32011-04-12 18:11:31 +0000360 /// Return the interval index, starting from 1. Interval index 0 is the
361 /// implicit complement interval.
362 unsigned openIntv();
363
364 /// currentIntv - Return the current interval index.
365 unsigned currentIntv() const { return OpenIdx; }
366
367 /// selectIntv - Select a previously opened interval index.
368 void selectIntv(unsigned Idx);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000369
Jakob Stoklund Olesen207c8682011-02-03 17:04:16 +0000370 /// enterIntvBefore - Enter the open interval before the instruction at Idx.
371 /// If the parent interval is not live before Idx, a COPY is not inserted.
372 /// Return the beginning of the new live range.
373 SlotIndex enterIntvBefore(SlotIndex Idx);
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000374
Jakob Stoklund Olesen87360f72011-06-30 01:30:39 +0000375 /// enterIntvAfter - Enter the open interval after the instruction at Idx.
376 /// Return the beginning of the new live range.
377 SlotIndex enterIntvAfter(SlotIndex Idx);
378
Jakob Stoklund Olesen207c8682011-02-03 17:04:16 +0000379 /// enterIntvAtEnd - Enter the open interval at the end of MBB.
380 /// Use the open interval from he inserted copy to the MBB end.
381 /// Return the beginning of the new live range.
382 SlotIndex enterIntvAtEnd(MachineBasicBlock &MBB);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000383
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +0000384 /// useIntv - indicate that all instructions in MBB should use OpenLI.
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000385 void useIntv(const MachineBasicBlock &MBB);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000386
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +0000387 /// useIntv - indicate that all instructions in range should use OpenLI.
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000388 void useIntv(SlotIndex Start, SlotIndex End);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000389
Jakob Stoklund Olesen207c8682011-02-03 17:04:16 +0000390 /// leaveIntvAfter - Leave the open interval after the instruction at Idx.
391 /// Return the end of the live range.
392 SlotIndex leaveIntvAfter(SlotIndex Idx);
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000393
Jakob Stoklund Olesen9b057772011-02-09 23:30:25 +0000394 /// leaveIntvBefore - Leave the open interval before the instruction at Idx.
395 /// Return the end of the live range.
396 SlotIndex leaveIntvBefore(SlotIndex Idx);
397
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000398 /// leaveIntvAtTop - Leave the interval at the top of MBB.
Jakob Stoklund Olesen207c8682011-02-03 17:04:16 +0000399 /// Add liveness from the MBB top to the copy.
400 /// Return the end of the live range.
401 SlotIndex leaveIntvAtTop(MachineBasicBlock &MBB);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000402
Jakob Stoklund Olesen5c716bd2011-02-08 18:50:21 +0000403 /// overlapIntv - Indicate that all instructions in range should use the open
404 /// interval, but also let the complement interval be live.
405 ///
406 /// This doubles the register pressure, but is sometimes required to deal with
407 /// register uses after the last valid split point.
408 ///
409 /// The Start index should be a return value from a leaveIntv* call, and End
410 /// should be in the same basic block. The parent interval must have the same
411 /// value across the range.
412 ///
413 void overlapIntv(SlotIndex Start, SlotIndex End);
414
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +0000415 /// finish - after all the new live ranges have been created, compute the
416 /// remaining live range, and rewrite instructions to use the new registers.
Jakob Stoklund Olesen59280462011-04-21 18:38:15 +0000417 /// @param LRMap When not null, this vector will map each live range in Edit
418 /// back to the indices returned by openIntv.
419 /// There may be extra indices created by dead code elimination.
420 void finish(SmallVectorImpl<unsigned> *LRMap = 0);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000421
Eric Christopher0f438112011-02-03 06:18:29 +0000422 /// dump - print the current interval maping to dbgs().
423 void dump() const;
424
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000425 // ===--- High level methods ---===
426
Jakob Stoklund Olesenfd5c5132011-04-12 19:32:53 +0000427 /// splitSingleBlock - Split CurLI into a separate live interval around the
428 /// uses in a single block. This is intended to be used as part of a larger
429 /// split, and doesn't call finish().
430 void splitSingleBlock(const SplitAnalysis::BlockInfo &BI);
431
Jakob Stoklund Olesenb4ddedc2011-07-15 21:47:57 +0000432 /// splitLiveThroughBlock - Split CurLI in the given block such that it
433 /// enters the block in IntvIn and leaves it in IntvOut. There may be uses in
434 /// the block, but they will be ignored when placing split points.
435 ///
436 /// @param MBBNum Block number.
437 /// @param IntvIn Interval index entering the block.
438 /// @param LeaveBefore When set, leave IntvIn before this point.
439 /// @param IntvOut Interval index leaving the block.
440 /// @param EnterAfter When set, enter IntvOut after this point.
441 void splitLiveThroughBlock(unsigned MBBNum,
442 unsigned IntvIn, SlotIndex LeaveBefore,
443 unsigned IntvOut, SlotIndex EnterAfter);
444
445 /// splitRegInBlock - Split CurLI in the given block such that it enters the
446 /// block in IntvIn and leaves it on the stack (or not at all). Split points
447 /// are placed in a way that avoids putting uses in the stack interval. This
448 /// may require creating a local interval when there is interference.
449 ///
450 /// @param BI Block descriptor.
451 /// @param IntvIn Interval index entering the block. Not 0.
452 /// @param LeaveBefore When set, leave IntvIn before this point.
453 void splitRegInBlock(const SplitAnalysis::BlockInfo &BI,
454 unsigned IntvIn, SlotIndex LeaveBefore);
455
456 /// splitRegOutBlock - Split CurLI in the given block such that it enters the
457 /// block on the stack (or isn't live-in at all) and leaves it in IntvOut.
458 /// Split points are placed to avoid interference and such that the uses are
459 /// not in the stack interval. This may require creating a local interval
460 /// when there is interference.
461 ///
462 /// @param BI Block descriptor.
463 /// @param IntvOut Interval index leaving the block.
464 /// @param EnterAfter When set, enter IntvOut after this point.
465 void splitRegOutBlock(const SplitAnalysis::BlockInfo &BI,
466 unsigned IntvOut, SlotIndex EnterAfter);
Jakob Stoklund Olesenfc412d82010-08-13 21:18:48 +0000467};
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000468
469}
Sebastian Redl6796e4f2011-04-24 15:46:51 +0000470
471#endif