blob: 6bff9e882a4345064132fe7e51f10bb26c816d4c [file] [log] [blame]
Jakob Stoklund Olesenf96ae682011-01-04 21:10:05 +00001//===-------- SplitKit.h - Toolkit for splitting live ranges ----*- C++ -*-===//
Jakob Stoklund Olesen36d12c62010-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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_CODEGEN_SPLITKIT_H
16#define LLVM_LIB_CODEGEN_SPLITKIT_H
Sebastian Redlb8a62aa2011-04-24 15:46:51 +000017
Jakob Stoklund Olesen487f2a32011-09-13 01:34:21 +000018#include "LiveRangeCalc.h"
Jakob Stoklund Olesenbf91c4e2011-04-06 03:57:00 +000019#include "llvm/ADT/ArrayRef.h"
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +000020#include "llvm/ADT/DenseMap.h"
Wei Mi9a16d652016-04-13 03:08:27 +000021#include "llvm/ADT/DenseSet.h"
Eric Christopherede62672011-02-03 06:18:29 +000022#include "llvm/ADT/IntervalMap.h"
Jakob Stoklund Olesen2530cd22010-12-21 01:50:21 +000023#include "llvm/ADT/SmallPtrSet.h"
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +000024
25namespace llvm {
26
Eric Christopherede62672011-02-03 06:18:29 +000027class ConnectedVNInfoEqClasses;
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +000028class LiveInterval;
29class LiveIntervals;
Jakob Stoklund Olesen72911e42010-10-14 23:49:52 +000030class LiveRangeEdit;
Benjamin Kramere2a1d892013-06-17 19:00:36 +000031class MachineBlockFrequencyInfo;
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +000032class MachineInstr;
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +000033class MachineLoopInfo;
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +000034class MachineRegisterInfo;
Jakob Stoklund Olesened4075c2010-07-20 21:46:58 +000035class TargetInstrInfo;
Jakob Stoklund Olesen6ee7d9aa2010-11-10 19:31:50 +000036class TargetRegisterInfo;
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +000037class VirtRegMap;
38class VNInfo;
Jakob Stoklund Olesen9a743012010-10-22 20:28:21 +000039class raw_ostream;
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +000040
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +000041/// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting
42/// opportunities.
Benjamin Kramerf4c20252015-07-01 14:47:39 +000043class LLVM_LIBRARY_VISIBILITY SplitAnalysis {
Jakob Stoklund Olesen284c2db2010-08-10 17:07:22 +000044public:
Jakob Stoklund Olesenb3089022011-01-26 00:50:53 +000045 const MachineFunction &MF;
Jakob Stoklund Olesenf1a60a62011-02-19 00:53:42 +000046 const VirtRegMap &VRM;
Jakob Stoklund Olesenb3089022011-01-26 00:50:53 +000047 const LiveIntervals &LIS;
48 const MachineLoopInfo &Loops;
49 const TargetInstrInfo &TII;
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +000050
Jakob Stoklund Olesenb1b76ad2011-02-09 22:50:26 +000051 /// Additional information about basic blocks where the current variable is
52 /// live. Such a block will look like one of these templates:
53 ///
54 /// 1. | o---x | Internal to block. Variable is only live in this block.
55 /// 2. |---x | Live-in, kill.
56 /// 3. | o---| Def, live-out.
Jakob Stoklund Olesenec43d5d2011-05-30 01:33:26 +000057 /// 4. |---x o---| Live-in, kill, def, live-out. Counted by NumGapBlocks.
Jakob Stoklund Olesenb1b76ad2011-02-09 22:50:26 +000058 /// 5. |---o---o---| Live-through with uses or defs.
Jakob Stoklund Olesenec43d5d2011-05-30 01:33:26 +000059 /// 6. |-----------| Live-through without uses. Counted by NumThroughBlocks.
60 ///
61 /// Two BlockInfo entries are created for template 4. One for the live-in
62 /// segment, and one for the live-out segment. These entries look as if the
63 /// block were split in the middle where the live range isn't live.
64 ///
65 /// Live-through blocks without any uses don't get BlockInfo entries. They
66 /// are simply listed in ThroughBlocks instead.
Jakob Stoklund Olesenb1b76ad2011-02-09 22:50:26 +000067 ///
68 struct BlockInfo {
69 MachineBasicBlock *MBB;
Jakob Stoklund Olesen43859a62011-08-02 22:54:14 +000070 SlotIndex FirstInstr; ///< First instr accessing current reg.
71 SlotIndex LastInstr; ///< Last instr accessing current reg.
Jakob Stoklund Olesenae8027c2011-08-02 22:37:22 +000072 SlotIndex FirstDef; ///< First non-phi valno->def, or SlotIndex().
Jakob Stoklund Olesenb1b76ad2011-02-09 22:50:26 +000073 bool LiveIn; ///< Current reg is live in.
74 bool LiveOut; ///< Current reg is live out.
Jakob Stoklund Olesenadc6a4c2011-06-30 01:30:39 +000075
76 /// isOneInstr - Returns true when this BlockInfo describes a single
77 /// instruction.
78 bool isOneInstr() const {
Jakob Stoklund Olesen43859a62011-08-02 22:54:14 +000079 return SlotIndex::isSameInstr(FirstInstr, LastInstr);
Jakob Stoklund Olesenadc6a4c2011-06-30 01:30:39 +000080 }
Jakob Stoklund Olesenb1b76ad2011-02-09 22:50:26 +000081 };
82
Jakob Stoklund Olesen622848b2010-08-12 17:07:14 +000083private:
84 // Current live interval.
Jakob Stoklund Olesenb3089022011-01-26 00:50:53 +000085 const LiveInterval *CurLI;
Jakob Stoklund Olesen622848b2010-08-12 17:07:14 +000086
Jakob Stoklund Olesen994fed62012-01-12 17:53:44 +000087 // Sorted slot indexes of using instructions.
88 SmallVector<SlotIndex, 8> UseSlots;
89
Jakob Stoklund Olesen50b2db82011-04-05 04:20:27 +000090 /// LastSplitPoint - Last legal split point in each basic block in the current
91 /// function. The first entry is the first terminator, the second entry is the
92 /// last valid split point for a variable that is live in to a landing pad
93 /// successor.
94 SmallVector<std::pair<SlotIndex, SlotIndex>, 8> LastSplitPoint;
95
Jakob Stoklund Olesenbf91c4e2011-04-06 03:57:00 +000096 /// UseBlocks - Blocks where CurLI has uses.
97 SmallVector<BlockInfo, 8> UseBlocks;
98
Jakob Stoklund Olesenec43d5d2011-05-30 01:33:26 +000099 /// NumGapBlocks - Number of duplicate entries in UseBlocks for blocks where
100 /// the live range has a gap.
101 unsigned NumGapBlocks;
102
Jakob Stoklund Olesenbf91c4e2011-04-06 03:57:00 +0000103 /// ThroughBlocks - Block numbers where CurLI is live through without uses.
Jakob Stoklund Olesened47ed42011-04-09 02:59:09 +0000104 BitVector ThroughBlocks;
105
106 /// NumThroughBlocks - Number of live-through blocks.
107 unsigned NumThroughBlocks;
Jakob Stoklund Olesenbf91c4e2011-04-06 03:57:00 +0000108
Jakob Stoklund Oleseneaa6ed12011-05-03 20:42:13 +0000109 /// DidRepairRange - analyze was forced to shrinkToUses().
110 bool DidRepairRange;
111
Jakob Stoklund Olesen50b2db82011-04-05 04:20:27 +0000112 SlotIndex computeLastSplitPoint(unsigned Num);
113
Jakob Stoklund Olesenb3089022011-01-26 00:50:53 +0000114 // Sumarize statistics by counting instructions using CurLI.
Jakob Stoklund Olesenff095502010-07-20 16:12:37 +0000115 void analyzeUses();
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +0000116
Jakob Stoklund Olesenb1b76ad2011-02-09 22:50:26 +0000117 /// calcLiveBlockInfo - Compute per-block information about CurLI.
Jakob Stoklund Olesen27e0a4a2011-03-05 18:33:49 +0000118 bool calcLiveBlockInfo();
Jakob Stoklund Olesenb1b76ad2011-02-09 22:50:26 +0000119
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +0000120public:
Jakob Stoklund Olesenf1a60a62011-02-19 00:53:42 +0000121 SplitAnalysis(const VirtRegMap &vrm, const LiveIntervals &lis,
Jakob Stoklund Olesen0fef9dd2010-07-20 23:50:15 +0000122 const MachineLoopInfo &mli);
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +0000123
Jakob Stoklund Olesenb3089022011-01-26 00:50:53 +0000124 /// analyze - set CurLI to the specified interval, and analyze how it may be
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +0000125 /// split.
126 void analyze(const LiveInterval *li);
127
Jakob Stoklund Oleseneaa6ed12011-05-03 20:42:13 +0000128 /// didRepairRange() - Returns true if CurLI was invalid and has been repaired
129 /// by analyze(). This really shouldn't happen, but sometimes the coalescer
130 /// can create live ranges that end in mid-air.
131 bool didRepairRange() const { return DidRepairRange; }
132
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +0000133 /// clear - clear all data structures so SplitAnalysis is ready to analyze a
134 /// new interval.
135 void clear();
136
Jakob Stoklund Olesen93c87362011-02-17 19:13:53 +0000137 /// getParent - Return the last analyzed interval.
138 const LiveInterval &getParent() const { return *CurLI; }
139
Jakob Stoklund Olesen67aec122012-01-11 02:07:00 +0000140 /// getLastSplitPoint - Return the base index of the last valid split point
Jakob Stoklund Olesen50b2db82011-04-05 04:20:27 +0000141 /// in the basic block numbered Num.
142 SlotIndex getLastSplitPoint(unsigned Num) {
143 // Inline the common simple case.
144 if (LastSplitPoint[Num].first.isValid() &&
145 !LastSplitPoint[Num].second.isValid())
146 return LastSplitPoint[Num].first;
147 return computeLastSplitPoint(Num);
148 }
149
Jakob Stoklund Olesen67aec122012-01-11 02:07:00 +0000150 /// getLastSplitPointIter - Returns the last split point as an iterator.
151 MachineBasicBlock::iterator getLastSplitPointIter(MachineBasicBlock*);
152
Jakob Stoklund Olesen60a26a62011-02-21 23:09:46 +0000153 /// isOriginalEndpoint - Return true if the original live range was killed or
154 /// (re-)defined at Idx. Idx should be the 'def' slot for a normal kill/def,
155 /// and 'use' for an early-clobber def.
156 /// This can be used to recognize code inserted by earlier live range
157 /// splitting.
158 bool isOriginalEndpoint(SlotIndex Idx) const;
159
Jakob Stoklund Olesen994fed62012-01-12 17:53:44 +0000160 /// getUseSlots - Return an array of SlotIndexes of instructions using CurLI.
161 /// This include both use and def operands, at most one entry per instruction.
162 ArrayRef<SlotIndex> getUseSlots() const { return UseSlots; }
163
Jakob Stoklund Olesenbf91c4e2011-04-06 03:57:00 +0000164 /// getUseBlocks - Return an array of BlockInfo objects for the basic blocks
165 /// where CurLI has uses.
Jakob Stoklund Olesen5cc91b22011-05-28 02:32:57 +0000166 ArrayRef<BlockInfo> getUseBlocks() const { return UseBlocks; }
Jakob Stoklund Olesenbf91c4e2011-04-06 03:57:00 +0000167
Jakob Stoklund Olesened47ed42011-04-09 02:59:09 +0000168 /// getNumThroughBlocks - Return the number of through blocks.
169 unsigned getNumThroughBlocks() const { return NumThroughBlocks; }
170
171 /// isThroughBlock - Return true if CurLI is live through MBB without uses.
172 bool isThroughBlock(unsigned MBB) const { return ThroughBlocks.test(MBB); }
Jakob Stoklund Olesenbf91c4e2011-04-06 03:57:00 +0000173
Jakob Stoklund Olesenc49df2c2011-04-12 21:30:53 +0000174 /// getThroughBlocks - Return the set of through blocks.
175 const BitVector &getThroughBlocks() const { return ThroughBlocks; }
176
Jakob Stoklund Olesen5cc91b22011-05-28 02:32:57 +0000177 /// getNumLiveBlocks - Return the number of blocks where CurLI is live.
178 unsigned getNumLiveBlocks() const {
Jakob Stoklund Olesenec43d5d2011-05-30 01:33:26 +0000179 return getUseBlocks().size() - NumGapBlocks + getNumThroughBlocks();
Jakob Stoklund Olesen5cc91b22011-05-28 02:32:57 +0000180 }
181
182 /// countLiveBlocks - Return the number of blocks where li is live. This is
183 /// guaranteed to return the same number as getNumLiveBlocks() after calling
184 /// analyze(li).
Jakob Stoklund Oleseneef23272011-04-26 22:33:12 +0000185 unsigned countLiveBlocks(const LiveInterval *li) const;
186
Jakob Stoklund Olesened4075c2010-07-20 21:46:58 +0000187 typedef SmallPtrSet<const MachineBasicBlock*, 16> BlockPtrSet;
188
Jakob Stoklund Olesen8627ea92011-08-05 22:20:45 +0000189 /// shouldSplitSingleBlock - Returns true if it would help to create a local
190 /// live range for the instructions in BI. There is normally no benefit to
191 /// creating a live range for a single instruction, but it does enable
192 /// register class inflation if the instruction has a restricted register
193 /// class.
194 ///
195 /// @param BI The block to be isolated.
196 /// @param SingleInstrs True when single instructions should be isolated.
197 bool shouldSplitSingleBlock(const BlockInfo &BI, bool SingleInstrs) const;
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +0000198};
199
Jakob Stoklund Olesence6f0552010-08-18 19:00:08 +0000200
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000201/// SplitEditor - Edit machine code and LiveIntervals for live range
202/// splitting.
203///
Jakob Stoklund Olesen45e07c82010-08-06 22:17:33 +0000204/// - Create a SplitEditor from a SplitAnalysis.
Jakob Stoklund Olesendc96e282010-08-04 22:08:39 +0000205/// - Start a new live interval with openIntv.
206/// - Mark the places where the new interval is entered using enterIntv*
207/// - Mark the ranges where the new interval is used with useIntv*
208/// - Mark the places where the interval is exited with exitIntv*.
209/// - Finish the current interval with closeIntv and repeat from 2.
Jakob Stoklund Olesen959fcc62010-10-08 23:42:21 +0000210/// - Rewrite instructions with finish().
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000211///
Benjamin Kramerf4c20252015-07-01 14:47:39 +0000212class LLVM_LIBRARY_VISIBILITY SplitEditor {
Jakob Stoklund Olesen04aff702011-02-19 00:42:33 +0000213 SplitAnalysis &SA;
Jakob Stoklund Olesenb3089022011-01-26 00:50:53 +0000214 LiveIntervals &LIS;
215 VirtRegMap &VRM;
216 MachineRegisterInfo &MRI;
Eric Christopherede62672011-02-03 06:18:29 +0000217 MachineDominatorTree &MDT;
Jakob Stoklund Olesenb3089022011-01-26 00:50:53 +0000218 const TargetInstrInfo &TII;
219 const TargetRegisterInfo &TRI;
Benjamin Kramere2a1d892013-06-17 19:00:36 +0000220 const MachineBlockFrequencyInfo &MBFI;
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000221
Jakob Stoklund Oleseneecb2fb2011-09-12 16:49:21 +0000222public:
223
224 /// ComplementSpillMode - Select how the complement live range should be
225 /// created. SplitEditor automatically creates interval 0 to contain
226 /// anything that isn't added to another interval. This complement interval
227 /// can get quite complicated, and it can sometimes be an advantage to allow
228 /// it to overlap the other intervals. If it is going to spill anyway, no
229 /// registers are wasted by keeping a value in two places at the same time.
230 enum ComplementSpillMode {
231 /// SM_Partition(Default) - Try to create the complement interval so it
232 /// doesn't overlap any other intervals, and the original interval is
233 /// partitioned. This may require a large number of back copies and extra
234 /// PHI-defs. Only segments marked with overlapIntv will be overlapping.
235 SM_Partition,
236
237 /// SM_Size - Overlap intervals to minimize the number of inserted COPY
238 /// instructions. Copies to the complement interval are hoisted to their
239 /// common dominator, so only one COPY is required per value in the
240 /// complement interval. This also means that no extra PHI-defs need to be
241 /// inserted in the complement interval.
242 SM_Size,
243
244 /// SM_Speed - Overlap intervals to minimize the expected execution
245 /// frequency of the inserted copies. This is very similar to SM_Size, but
246 /// the complement interval may get some extra PHI-defs.
247 SM_Speed
248 };
249
250private:
251
Jakob Stoklund Olesenb3089022011-01-26 00:50:53 +0000252 /// Edit - The current parent register and new intervals created.
Jakob Stoklund Olesen815196c2011-03-02 23:31:50 +0000253 LiveRangeEdit *Edit;
Jakob Stoklund Olesen72911e42010-10-14 23:49:52 +0000254
Eric Christopherede62672011-02-03 06:18:29 +0000255 /// Index into Edit of the currently open interval.
256 /// The index 0 is used for the complement, so the first interval started by
257 /// openIntv will be 1.
258 unsigned OpenIdx;
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000259
Jakob Stoklund Oleseneecb2fb2011-09-12 16:49:21 +0000260 /// The current spill mode, selected by reset().
261 ComplementSpillMode SpillMode;
262
Eric Christopherede62672011-02-03 06:18:29 +0000263 typedef IntervalMap<SlotIndex, unsigned> RegAssignMap;
264
265 /// Allocator for the interval map. This will eventually be shared with
266 /// SlotIndexes and LiveIntervals.
267 RegAssignMap::Allocator Allocator;
268
269 /// RegAssign - Map of the assigned register indexes.
270 /// Edit.get(RegAssign.lookup(Idx)) is the register that should be live at
271 /// Idx.
272 RegAssignMap RegAssign;
273
Jakob Stoklund Olesen5d4277d2011-09-13 23:09:04 +0000274 typedef PointerIntPair<VNInfo*, 1> ValueForcePair;
275 typedef DenseMap<std::pair<unsigned, unsigned>, ValueForcePair> ValueMap;
Jakob Stoklund Olesen8ef91fc2011-03-01 23:14:53 +0000276
277 /// Values - keep track of the mapping from parent values to values in the new
278 /// intervals. Given a pair (RegIdx, ParentVNI->id), Values contains:
279 ///
280 /// 1. No entry - the value is not mapped to Edit.get(RegIdx).
Jakob Stoklund Olesen5d4277d2011-09-13 23:09:04 +0000281 /// 2. (Null, false) - the value is mapped to multiple values in
282 /// Edit.get(RegIdx). Each value is represented by a minimal live range at
283 /// its def. The full live range can be inferred exactly from the range
284 /// of RegIdx in RegAssign.
285 /// 3. (Null, true). As above, but the ranges in RegAssign are too large, and
286 /// the live range must be recomputed using LiveRangeCalc::extend().
287 /// 4. (VNI, false) The value is mapped to a single new value.
Jakob Stoklund Olesen8ef91fc2011-03-01 23:14:53 +0000288 /// The new value has no live ranges anywhere.
289 ValueMap Values;
290
Jakob Stoklund Olesen054984d2011-09-13 16:47:53 +0000291 /// LRCalc - Cache for computing live ranges and SSA update. Each instance
292 /// can only handle non-overlapping live ranges, so use a separate
293 /// LiveRangeCalc instance for the complement interval when in spill mode.
294 LiveRangeCalc LRCalc[2];
295
296 /// getLRCalc - Return the LRCalc to use for RegIdx. In spill mode, the
297 /// complement interval can overlap the other intervals, so it gets its own
298 /// LRCalc instance. When not in spill mode, all intervals can share one.
299 LiveRangeCalc &getLRCalc(unsigned RegIdx) {
300 return LRCalc[SpillMode != SM_Partition && RegIdx != 0];
301 }
Jakob Stoklund Olesen1af8b4d2011-04-15 17:24:49 +0000302
Jakob Stoklund Olesen8ef91fc2011-03-01 23:14:53 +0000303 /// defValue - define a value in RegIdx from ParentVNI at Idx.
304 /// Idx does not have to be ParentVNI->def, but it must be contained within
305 /// ParentVNI's live range in ParentLI. The new value is added to the value
306 /// map.
307 /// Return the new LI value.
308 VNInfo *defValue(unsigned RegIdx, const VNInfo *ParentVNI, SlotIndex Idx);
309
Jakob Stoklund Olesen5d4277d2011-09-13 23:09:04 +0000310 /// forceRecompute - Force the live range of ParentVNI in RegIdx to be
311 /// recomputed by LiveRangeCalc::extend regardless of the number of defs.
312 /// This is used for values whose live range doesn't match RegAssign exactly.
313 /// They could have rematerialized, or back-copies may have been moved.
314 void forceRecompute(unsigned RegIdx, const VNInfo *ParentVNI);
Jakob Stoklund Olesen4484f992011-09-13 18:05:29 +0000315
Jakob Stoklund Olesen6ee7d9aa2010-11-10 19:31:50 +0000316 /// defFromParent - Define Reg from ParentVNI at UseIdx using either
317 /// rematerialization or a COPY from parent. Return the new value.
Eric Christopherede62672011-02-03 06:18:29 +0000318 VNInfo *defFromParent(unsigned RegIdx,
Jakob Stoklund Olesen6ee7d9aa2010-11-10 19:31:50 +0000319 VNInfo *ParentVNI,
320 SlotIndex UseIdx,
321 MachineBasicBlock &MBB,
322 MachineBasicBlock::iterator I);
323
Jakob Stoklund Olesena25330f2011-09-13 22:22:39 +0000324 /// removeBackCopies - Remove the copy instructions that defines the values
325 /// in the vector in the complement interval.
326 void removeBackCopies(SmallVectorImpl<VNInfo*> &Copies);
327
Jakob Stoklund Olesena98af392011-09-14 16:45:39 +0000328 /// getShallowDominator - Returns the least busy dominator of MBB that is
329 /// also dominated by DefMBB. Busy is measured by loop depth.
330 MachineBasicBlock *findShallowDominator(MachineBasicBlock *MBB,
331 MachineBasicBlock *DefMBB);
332
Wei Mi9a16d652016-04-13 03:08:27 +0000333 /// Find out all the backCopies dominated by others.
334 void computeRedundantBackCopies(DenseSet<unsigned> &NotToHoistSet,
335 SmallVectorImpl<VNInfo *> &BackCopies);
336
337 /// Hoist back-copies to the complement interval. It tries to hoist all
338 /// the back-copies to one BB if it is beneficial, or else simply remove
339 /// redundent backcopies dominated by others.
340 void hoistCopies();
Jakob Stoklund Olesena25330f2011-09-13 22:22:39 +0000341
Jakob Stoklund Olesen1af8b4d2011-04-15 17:24:49 +0000342 /// transferValues - Transfer values to the new ranges.
343 /// Return true if any ranges were skipped.
344 bool transferValues();
Jakob Stoklund Olesen503b1432011-03-02 23:05:19 +0000345
Jakob Stoklund Olesen36482632011-03-02 23:05:16 +0000346 /// extendPHIKillRanges - Extend the ranges of all values killed by original
347 /// parent PHIDefs.
348 void extendPHIKillRanges();
349
Eric Christopherede62672011-02-03 06:18:29 +0000350 /// rewriteAssigned - Rewrite all uses of Edit.getReg() to assigned registers.
Jakob Stoklund Olesen503b1432011-03-02 23:05:19 +0000351 void rewriteAssigned(bool ExtendRanges);
Jakob Stoklund Olesen6f8bd422010-09-21 22:32:21 +0000352
Jakob Stoklund Olesenea5ebfe2011-03-08 22:46:11 +0000353 /// deleteRematVictims - Delete defs that are dead after rematerializing.
354 void deleteRematVictims();
355
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000356public:
357 /// Create a new SplitEditor for editing the LiveInterval analyzed by SA.
Jakob Stoklund Olesendc96e282010-08-04 22:08:39 +0000358 /// Newly created intervals will be appended to newIntervals.
Jakob Stoklund Olesene172a8b2010-10-28 20:34:50 +0000359 SplitEditor(SplitAnalysis &SA, LiveIntervals&, VirtRegMap&,
Benjamin Kramere2a1d892013-06-17 19:00:36 +0000360 MachineDominatorTree&, MachineBlockFrequencyInfo &);
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000361
Jakob Stoklund Olesenc9601982011-03-03 01:29:13 +0000362 /// reset - Prepare for a new split.
Jakob Stoklund Oleseneecb2fb2011-09-12 16:49:21 +0000363 void reset(LiveRangeEdit&, ComplementSpillMode = SM_Partition);
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000364
Jakob Stoklund Olesendc96e282010-08-04 22:08:39 +0000365 /// Create a new virtual register and live interval.
Jakob Stoklund Olesen0840f502011-04-12 18:11:31 +0000366 /// Return the interval index, starting from 1. Interval index 0 is the
367 /// implicit complement interval.
368 unsigned openIntv();
369
370 /// currentIntv - Return the current interval index.
371 unsigned currentIntv() const { return OpenIdx; }
372
373 /// selectIntv - Select a previously opened interval index.
374 void selectIntv(unsigned Idx);
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000375
Jakob Stoklund Olesenf12e1202011-02-03 17:04:16 +0000376 /// enterIntvBefore - Enter the open interval before the instruction at Idx.
377 /// If the parent interval is not live before Idx, a COPY is not inserted.
378 /// Return the beginning of the new live range.
379 SlotIndex enterIntvBefore(SlotIndex Idx);
Jakob Stoklund Olesen622848b2010-08-12 17:07:14 +0000380
Jakob Stoklund Olesenadc6a4c2011-06-30 01:30:39 +0000381 /// enterIntvAfter - Enter the open interval after the instruction at Idx.
382 /// Return the beginning of the new live range.
383 SlotIndex enterIntvAfter(SlotIndex Idx);
384
Jakob Stoklund Olesenf12e1202011-02-03 17:04:16 +0000385 /// enterIntvAtEnd - Enter the open interval at the end of MBB.
Eric Christopher650c8f22014-05-20 17:11:11 +0000386 /// Use the open interval from the inserted copy to the MBB end.
Jakob Stoklund Olesenf12e1202011-02-03 17:04:16 +0000387 /// Return the beginning of the new live range.
388 SlotIndex enterIntvAtEnd(MachineBasicBlock &MBB);
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000389
Jakob Stoklund Olesenb3089022011-01-26 00:50:53 +0000390 /// useIntv - indicate that all instructions in MBB should use OpenLI.
Jakob Stoklund Olesendc96e282010-08-04 22:08:39 +0000391 void useIntv(const MachineBasicBlock &MBB);
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000392
Jakob Stoklund Olesenb3089022011-01-26 00:50:53 +0000393 /// useIntv - indicate that all instructions in range should use OpenLI.
Jakob Stoklund Olesendc96e282010-08-04 22:08:39 +0000394 void useIntv(SlotIndex Start, SlotIndex End);
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000395
Jakob Stoklund Olesenf12e1202011-02-03 17:04:16 +0000396 /// leaveIntvAfter - Leave the open interval after the instruction at Idx.
397 /// Return the end of the live range.
398 SlotIndex leaveIntvAfter(SlotIndex Idx);
Jakob Stoklund Olesen622848b2010-08-12 17:07:14 +0000399
Jakob Stoklund Olesen7cb57b32011-02-09 23:30:25 +0000400 /// leaveIntvBefore - Leave the open interval before the instruction at Idx.
401 /// Return the end of the live range.
402 SlotIndex leaveIntvBefore(SlotIndex Idx);
403
Jakob Stoklund Olesendc96e282010-08-04 22:08:39 +0000404 /// leaveIntvAtTop - Leave the interval at the top of MBB.
Jakob Stoklund Olesenf12e1202011-02-03 17:04:16 +0000405 /// Add liveness from the MBB top to the copy.
406 /// Return the end of the live range.
407 SlotIndex leaveIntvAtTop(MachineBasicBlock &MBB);
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000408
Jakob Stoklund Olesen17499352011-02-08 18:50:21 +0000409 /// overlapIntv - Indicate that all instructions in range should use the open
410 /// interval, but also let the complement interval be live.
411 ///
412 /// This doubles the register pressure, but is sometimes required to deal with
413 /// register uses after the last valid split point.
414 ///
415 /// The Start index should be a return value from a leaveIntv* call, and End
416 /// should be in the same basic block. The parent interval must have the same
417 /// value across the range.
418 ///
419 void overlapIntv(SlotIndex Start, SlotIndex End);
420
Jakob Stoklund Olesen959fcc62010-10-08 23:42:21 +0000421 /// finish - after all the new live ranges have been created, compute the
422 /// remaining live range, and rewrite instructions to use the new registers.
Jakob Stoklund Olesen6a663b82011-04-21 18:38:15 +0000423 /// @param LRMap When not null, this vector will map each live range in Edit
424 /// back to the indices returned by openIntv.
425 /// There may be extra indices created by dead code elimination.
Craig Topperada08572014-04-16 04:21:27 +0000426 void finish(SmallVectorImpl<unsigned> *LRMap = nullptr);
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000427
Jim Grosbachbfe3a9c2015-05-02 00:44:07 +0000428 /// dump - print the current interval mapping to dbgs().
Eric Christopherede62672011-02-03 06:18:29 +0000429 void dump() const;
430
Jakob Stoklund Olesenc6984172010-07-26 23:44:11 +0000431 // ===--- High level methods ---===
432
Jakob Stoklund Olesenc70b6972011-04-12 19:32:53 +0000433 /// splitSingleBlock - Split CurLI into a separate live interval around the
434 /// uses in a single block. This is intended to be used as part of a larger
435 /// split, and doesn't call finish().
436 void splitSingleBlock(const SplitAnalysis::BlockInfo &BI);
437
Jakob Stoklund Olesen795da1c2011-07-15 21:47:57 +0000438 /// splitLiveThroughBlock - Split CurLI in the given block such that it
439 /// enters the block in IntvIn and leaves it in IntvOut. There may be uses in
440 /// the block, but they will be ignored when placing split points.
441 ///
442 /// @param MBBNum Block number.
443 /// @param IntvIn Interval index entering the block.
444 /// @param LeaveBefore When set, leave IntvIn before this point.
445 /// @param IntvOut Interval index leaving the block.
446 /// @param EnterAfter When set, enter IntvOut after this point.
447 void splitLiveThroughBlock(unsigned MBBNum,
448 unsigned IntvIn, SlotIndex LeaveBefore,
449 unsigned IntvOut, SlotIndex EnterAfter);
450
451 /// splitRegInBlock - Split CurLI in the given block such that it enters the
452 /// block in IntvIn and leaves it on the stack (or not at all). Split points
453 /// are placed in a way that avoids putting uses in the stack interval. This
454 /// may require creating a local interval when there is interference.
455 ///
456 /// @param BI Block descriptor.
457 /// @param IntvIn Interval index entering the block. Not 0.
458 /// @param LeaveBefore When set, leave IntvIn before this point.
459 void splitRegInBlock(const SplitAnalysis::BlockInfo &BI,
460 unsigned IntvIn, SlotIndex LeaveBefore);
461
462 /// splitRegOutBlock - Split CurLI in the given block such that it enters the
463 /// block on the stack (or isn't live-in at all) and leaves it in IntvOut.
464 /// Split points are placed to avoid interference and such that the uses are
465 /// not in the stack interval. This may require creating a local interval
466 /// when there is interference.
467 ///
468 /// @param BI Block descriptor.
469 /// @param IntvOut Interval index leaving the block.
470 /// @param EnterAfter When set, enter IntvOut after this point.
471 void splitRegOutBlock(const SplitAnalysis::BlockInfo &BI,
472 unsigned IntvOut, SlotIndex EnterAfter);
Jakob Stoklund Olesend1191ee2010-08-13 21:18:48 +0000473};
Jakob Stoklund Olesen36d12c62010-07-20 15:41:07 +0000474
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000475}
Sebastian Redlb8a62aa2011-04-24 15:46:51 +0000476
477#endif