blob: 89ce24b28a974fd1537dcd1afcab0bb5168b1c44 [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 Olesendb529a82011-04-06 03:57:00 +000018#include "llvm/ADT/ArrayRef.h"
Jakob Stoklund Olesen13ba2da2011-03-04 00:15:36 +000019#include "llvm/ADT/BitVector.h"
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000020#include "llvm/ADT/DenseMap.h"
Jakob Stoklund Olesen13ba2da2011-03-04 00:15:36 +000021#include "llvm/ADT/IndexedMap.h"
Eric Christopher0f438112011-02-03 06:18:29 +000022#include "llvm/ADT/IntervalMap.h"
Jakob Stoklund Olesen8d0963f2010-12-21 01:50:21 +000023#include "llvm/ADT/SmallPtrSet.h"
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +000024#include "llvm/CodeGen/SlotIndexes.h"
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000025
26namespace llvm {
27
Eric Christopher0f438112011-02-03 06:18:29 +000028class ConnectedVNInfoEqClasses;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000029class LiveInterval;
30class LiveIntervals;
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +000031class LiveRangeEdit;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000032class MachineInstr;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000033class MachineLoopInfo;
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +000034class MachineRegisterInfo;
Jakob Stoklund Olesen6a0dc072010-07-20 21:46:58 +000035class TargetInstrInfo;
Jakob Stoklund Olesencfa71342010-11-10 19:31:50 +000036class TargetRegisterInfo;
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +000037class VirtRegMap;
38class VNInfo;
Jakob Stoklund Olesen532de3d2010-10-22 20:28:21 +000039class raw_ostream;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000040
Jakob Stoklund Olesene1dde7b2010-10-28 20:34:52 +000041/// At some point we should just include MachineDominators.h:
42class MachineDominatorTree;
43template <class NodeT> class DomTreeNodeBase;
44typedef DomTreeNodeBase<MachineBasicBlock> MachineDomTreeNode;
45
Jakob Stoklund Olesen8d0963f2010-12-21 01:50:21 +000046
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +000047/// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting
48/// opportunities.
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000049class SplitAnalysis {
Jakob Stoklund Olesen08e93b12010-08-10 17:07:22 +000050public:
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +000051 const MachineFunction &MF;
Jakob Stoklund Olesen1b847de2011-02-19 00:53:42 +000052 const VirtRegMap &VRM;
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +000053 const LiveIntervals &LIS;
54 const MachineLoopInfo &Loops;
55 const TargetInstrInfo &TII;
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +000056
Jakob Stoklund Olesenb5fa9332011-01-18 21:13:27 +000057 // Sorted slot indexes of using instructions.
58 SmallVector<SlotIndex, 8> UseSlots;
59
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +000060 /// Additional information about basic blocks where the current variable is
61 /// live. Such a block will look like one of these templates:
62 ///
63 /// 1. | o---x | Internal to block. Variable is only live in this block.
64 /// 2. |---x | Live-in, kill.
65 /// 3. | o---| Def, live-out.
Jakob Stoklund Olesena2e79ef2011-05-30 01:33:26 +000066 /// 4. |---x o---| Live-in, kill, def, live-out. Counted by NumGapBlocks.
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +000067 /// 5. |---o---o---| Live-through with uses or defs.
Jakob Stoklund Olesena2e79ef2011-05-30 01:33:26 +000068 /// 6. |-----------| Live-through without uses. Counted by NumThroughBlocks.
69 ///
70 /// Two BlockInfo entries are created for template 4. One for the live-in
71 /// segment, and one for the live-out segment. These entries look as if the
72 /// block were split in the middle where the live range isn't live.
73 ///
74 /// Live-through blocks without any uses don't get BlockInfo entries. They
75 /// are simply listed in ThroughBlocks instead.
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +000076 ///
77 struct BlockInfo {
78 MachineBasicBlock *MBB;
Jakob Stoklund Olesenfe62d922011-08-02 22:54:14 +000079 SlotIndex FirstInstr; ///< First instr accessing current reg.
80 SlotIndex LastInstr; ///< Last instr accessing current reg.
Jakob Stoklund Olesen77ee1142011-08-02 22:37:22 +000081 SlotIndex FirstDef; ///< First non-phi valno->def, or SlotIndex().
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +000082 bool LiveIn; ///< Current reg is live in.
83 bool LiveOut; ///< Current reg is live out.
Jakob Stoklund Olesen87360f72011-06-30 01:30:39 +000084
85 /// isOneInstr - Returns true when this BlockInfo describes a single
86 /// instruction.
87 bool isOneInstr() const {
Jakob Stoklund Olesenfe62d922011-08-02 22:54:14 +000088 return SlotIndex::isSameInstr(FirstInstr, LastInstr);
Jakob Stoklund Olesen87360f72011-06-30 01:30:39 +000089 }
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +000090 };
91
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +000092private:
93 // Current live interval.
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +000094 const LiveInterval *CurLI;
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +000095
Jakob Stoklund Olesen1a774452011-04-05 04:20:27 +000096 /// LastSplitPoint - Last legal split point in each basic block in the current
97 /// function. The first entry is the first terminator, the second entry is the
98 /// last valid split point for a variable that is live in to a landing pad
99 /// successor.
100 SmallVector<std::pair<SlotIndex, SlotIndex>, 8> LastSplitPoint;
101
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000102 /// UseBlocks - Blocks where CurLI has uses.
103 SmallVector<BlockInfo, 8> UseBlocks;
104
Jakob Stoklund Olesena2e79ef2011-05-30 01:33:26 +0000105 /// NumGapBlocks - Number of duplicate entries in UseBlocks for blocks where
106 /// the live range has a gap.
107 unsigned NumGapBlocks;
108
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000109 /// ThroughBlocks - Block numbers where CurLI is live through without uses.
Jakob Stoklund Olesenf4afdfc2011-04-09 02:59:09 +0000110 BitVector ThroughBlocks;
111
112 /// NumThroughBlocks - Number of live-through blocks.
113 unsigned NumThroughBlocks;
Jakob Stoklund Olesendb529a82011-04-06 03:57:00 +0000114
Jakob Stoklund Olesen7d6b6a02011-05-03 20:42:13 +0000115 /// DidRepairRange - analyze was forced to shrinkToUses().
116 bool DidRepairRange;
117
Jakob Stoklund Olesen1a774452011-04-05 04:20:27 +0000118 SlotIndex computeLastSplitPoint(unsigned Num);
119
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +0000120 // Sumarize statistics by counting instructions using CurLI.
Jakob Stoklund Olesenabff2802010-07-20 16:12:37 +0000121 void analyzeUses();
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000122
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +0000123 /// calcLiveBlockInfo - Compute per-block information about CurLI.
Jakob Stoklund Olesen2b0f9e72011-03-05 18:33:49 +0000124 bool calcLiveBlockInfo();
Jakob Stoklund Olesenf0ac26c2011-02-09 22:50:26 +0000125
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000126public:
Jakob Stoklund Olesen1b847de2011-02-19 00:53:42 +0000127 SplitAnalysis(const VirtRegMap &vrm, const LiveIntervals &lis,
Jakob Stoklund Olesenf2c6e362010-07-20 23:50:15 +0000128 const MachineLoopInfo &mli);
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000129
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +0000130 /// analyze - set CurLI to the specified interval, and analyze how it may be
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000131 /// split.
132 void analyze(const LiveInterval *li);
133
Jakob Stoklund Olesen7d6b6a02011-05-03 20:42:13 +0000134 /// didRepairRange() - Returns true if CurLI was invalid and has been repaired
135 /// by analyze(). This really shouldn't happen, but sometimes the coalescer
136 /// can create live ranges that end in mid-air.
137 bool didRepairRange() const { return DidRepairRange; }
138
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000139 /// clear - clear all data structures so SplitAnalysis is ready to analyze a
140 /// new interval.
141 void clear();
142
Jakob Stoklund Olesen034a80d2011-02-17 19:13:53 +0000143 /// getParent - Return the last analyzed interval.
144 const LiveInterval &getParent() const { return *CurLI; }
145
Jakob Stoklund Olesen1a774452011-04-05 04:20:27 +0000146 /// getLastSplitPoint - Return that base index of the last valid split point
147 /// in the basic block numbered Num.
148 SlotIndex getLastSplitPoint(unsigned Num) {
149 // Inline the common simple case.
150 if (LastSplitPoint[Num].first.isValid() &&
151 !LastSplitPoint[Num].second.isValid())
152 return LastSplitPoint[Num].first;
153 return computeLastSplitPoint(Num);
154 }
155
Jakob Stoklund Olesen06c0f252011-02-21 23:09:46 +0000156 /// isOriginalEndpoint - Return true if the original live range was killed or
157 /// (re-)defined at Idx. Idx should be the 'def' slot for a normal kill/def,
158 /// and 'use' for an early-clobber def.
159 /// This can be used to recognize code inserted by earlier live range
160 /// splitting.
161 bool isOriginalEndpoint(SlotIndex Idx) const;
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;
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000219
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +0000220 /// Edit - The current parent register and new intervals created.
Jakob Stoklund Olesena2cae582011-03-02 23:31:50 +0000221 LiveRangeEdit *Edit;
Jakob Stoklund Olesena17768f2010-10-14 23:49:52 +0000222
Eric Christopher0f438112011-02-03 06:18:29 +0000223 /// Index into Edit of the currently open interval.
224 /// The index 0 is used for the complement, so the first interval started by
225 /// openIntv will be 1.
226 unsigned OpenIdx;
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000227
Eric Christopher0f438112011-02-03 06:18:29 +0000228 typedef IntervalMap<SlotIndex, unsigned> RegAssignMap;
229
230 /// Allocator for the interval map. This will eventually be shared with
231 /// SlotIndexes and LiveIntervals.
232 RegAssignMap::Allocator Allocator;
233
234 /// RegAssign - Map of the assigned register indexes.
235 /// Edit.get(RegAssign.lookup(Idx)) is the register that should be live at
236 /// Idx.
237 RegAssignMap RegAssign;
238
Jakob Stoklund Olesen670ccd12011-03-01 23:14:53 +0000239 typedef DenseMap<std::pair<unsigned, unsigned>, VNInfo*> ValueMap;
240
241 /// Values - keep track of the mapping from parent values to values in the new
242 /// intervals. Given a pair (RegIdx, ParentVNI->id), Values contains:
243 ///
244 /// 1. No entry - the value is not mapped to Edit.get(RegIdx).
245 /// 2. Null - the value is mapped to multiple values in Edit.get(RegIdx).
246 /// Each value is represented by a minimal live range at its def.
247 /// 3. A non-null VNInfo - the value is mapped to a single new value.
248 /// The new value has no live ranges anywhere.
249 ValueMap Values;
250
Jakob Stoklund Olesen1c38ba62011-03-02 01:59:34 +0000251 typedef std::pair<VNInfo*, MachineDomTreeNode*> LiveOutPair;
Jakob Stoklund Olesen13ba2da2011-03-04 00:15:36 +0000252 typedef IndexedMap<LiveOutPair, MBB2NumberFunctor> LiveOutMap;
Jakob Stoklund Olesen1c38ba62011-03-02 01:59:34 +0000253
254 // LiveOutCache - Map each basic block where a new register is live out to the
255 // live-out value and its defining block.
256 // One of these conditions shall be true:
257 //
258 // 1. !LiveOutCache.count(MBB)
259 // 2. LiveOutCache[MBB].second.getNode() == MBB
260 // 3. forall P in preds(MBB): LiveOutCache[P] == LiveOutCache[MBB]
261 //
262 // This is only a cache, the values can be computed as:
263 //
264 // VNI = Edit.get(RegIdx)->getVNInfoAt(LIS.getMBBEndIdx(MBB))
265 // Node = mbt_[LIS.getMBBFromIndex(VNI->def)]
266 //
267 // The cache is also used as a visited set by extendRange(). It can be shared
268 // by all the new registers because at most one is live out of each block.
269 LiveOutMap LiveOutCache;
270
Jakob Stoklund Olesen13ba2da2011-03-04 00:15:36 +0000271 // LiveOutSeen - Indexed by MBB->getNumber(), a bit is set for each valid
272 // entry in LiveOutCache.
273 BitVector LiveOutSeen;
274
Jakob Stoklund Olesen44b7ae22011-04-15 17:24:49 +0000275 /// LiveInBlock - Info for updateSSA() about a block where a register is
276 /// live-in.
277 /// The updateSSA caller provides DomNode and Kill inside MBB, updateSSA()
278 /// adds the computed live-in value.
279 struct LiveInBlock {
280 // Dominator tree node for the block.
281 // Cleared by updateSSA when the final value has been determined.
282 MachineDomTreeNode *DomNode;
283
284 // Live-in value filled in by updateSSA once it is known.
285 VNInfo *Value;
286
287 // Position in block where the live-in range ends, or SlotIndex() if the
288 // range passes through the block.
289 SlotIndex Kill;
290
291 LiveInBlock(MachineDomTreeNode *node) : DomNode(node), Value(0) {}
292 };
293
294 /// LiveInBlocks - List of live-in blocks used by findReachingDefs() and
295 /// updateSSA(). This list is usually empty, it exists here to avoid frequent
296 /// reallocations.
297 SmallVector<LiveInBlock, 16> LiveInBlocks;
298
Jakob Stoklund Olesen670ccd12011-03-01 23:14:53 +0000299 /// defValue - define a value in RegIdx from ParentVNI at Idx.
300 /// Idx does not have to be ParentVNI->def, but it must be contained within
301 /// ParentVNI's live range in ParentLI. The new value is added to the value
302 /// map.
303 /// Return the new LI value.
304 VNInfo *defValue(unsigned RegIdx, const VNInfo *ParentVNI, SlotIndex Idx);
305
306 /// markComplexMapped - Mark ParentVNI as complex mapped in RegIdx regardless
307 /// of the number of defs.
308 void markComplexMapped(unsigned RegIdx, const VNInfo *ParentVNI);
309
Jakob Stoklund Olesencfa71342010-11-10 19:31:50 +0000310 /// defFromParent - Define Reg from ParentVNI at UseIdx using either
311 /// rematerialization or a COPY from parent. Return the new value.
Eric Christopher0f438112011-02-03 06:18:29 +0000312 VNInfo *defFromParent(unsigned RegIdx,
Jakob Stoklund Olesencfa71342010-11-10 19:31:50 +0000313 VNInfo *ParentVNI,
314 SlotIndex UseIdx,
315 MachineBasicBlock &MBB,
316 MachineBasicBlock::iterator I);
317
Jakob Stoklund Olesen1c38ba62011-03-02 01:59:34 +0000318 /// extendRange - Extend the live range of Edit.get(RegIdx) so it reaches Idx.
319 /// Insert PHIDefs as needed to preserve SSA form.
320 void extendRange(unsigned RegIdx, SlotIndex Idx);
321
Jakob Stoklund Olesen44b7ae22011-04-15 17:24:49 +0000322 /// findReachingDefs - Starting from MBB, add blocks to LiveInBlocks until all
323 /// reaching defs for LI are found.
324 /// @param LI Live interval whose value is needed.
325 /// @param MBB Block where LI should be live-in.
326 /// @param Kill Kill point in MBB.
327 /// @return Unique value seen, or NULL.
328 VNInfo *findReachingDefs(LiveInterval *LI, MachineBasicBlock *MBB,
329 SlotIndex Kill);
Jakob Stoklund Olesen1c38ba62011-03-02 01:59:34 +0000330
Jakob Stoklund Olesen44b7ae22011-04-15 17:24:49 +0000331 /// updateSSA - Compute and insert PHIDefs such that all blocks in
332 // LiveInBlocks get a known live-in value. Add live ranges to the blocks.
333 void updateSSA();
334
335 /// transferValues - Transfer values to the new ranges.
336 /// Return true if any ranges were skipped.
337 bool transferValues();
Jakob Stoklund Olesen46703532011-03-02 23:05:19 +0000338
Jakob Stoklund Olesene2dc0c92011-03-02 23:05:16 +0000339 /// extendPHIKillRanges - Extend the ranges of all values killed by original
340 /// parent PHIDefs.
341 void extendPHIKillRanges();
342
Eric Christopher0f438112011-02-03 06:18:29 +0000343 /// rewriteAssigned - Rewrite all uses of Edit.getReg() to assigned registers.
Jakob Stoklund Olesen46703532011-03-02 23:05:19 +0000344 void rewriteAssigned(bool ExtendRanges);
Jakob Stoklund Olesen5fa42a42010-09-21 22:32:21 +0000345
Jakob Stoklund Olesen58817992011-03-08 22:46:11 +0000346 /// deleteRematVictims - Delete defs that are dead after rematerializing.
347 void deleteRematVictims();
348
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000349public:
350 /// Create a new SplitEditor for editing the LiveInterval analyzed by SA.
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000351 /// Newly created intervals will be appended to newIntervals.
Jakob Stoklund Olesend68f4582010-10-28 20:34:50 +0000352 SplitEditor(SplitAnalysis &SA, LiveIntervals&, VirtRegMap&,
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +0000353 MachineDominatorTree&);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000354
Jakob Stoklund Olesenbece06f2011-03-03 01:29:13 +0000355 /// reset - Prepare for a new split.
356 void reset(LiveRangeEdit&);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000357
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000358 /// Create a new virtual register and live interval.
Jakob Stoklund Olesene1b43c32011-04-12 18:11:31 +0000359 /// Return the interval index, starting from 1. Interval index 0 is the
360 /// implicit complement interval.
361 unsigned openIntv();
362
363 /// currentIntv - Return the current interval index.
364 unsigned currentIntv() const { return OpenIdx; }
365
366 /// selectIntv - Select a previously opened interval index.
367 void selectIntv(unsigned Idx);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000368
Jakob Stoklund Olesen207c8682011-02-03 17:04:16 +0000369 /// enterIntvBefore - Enter the open interval before the instruction at Idx.
370 /// If the parent interval is not live before Idx, a COPY is not inserted.
371 /// Return the beginning of the new live range.
372 SlotIndex enterIntvBefore(SlotIndex Idx);
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000373
Jakob Stoklund Olesen87360f72011-06-30 01:30:39 +0000374 /// enterIntvAfter - Enter the open interval after the instruction at Idx.
375 /// Return the beginning of the new live range.
376 SlotIndex enterIntvAfter(SlotIndex Idx);
377
Jakob Stoklund Olesen207c8682011-02-03 17:04:16 +0000378 /// enterIntvAtEnd - Enter the open interval at the end of MBB.
379 /// Use the open interval from he inserted copy to the MBB end.
380 /// Return the beginning of the new live range.
381 SlotIndex enterIntvAtEnd(MachineBasicBlock &MBB);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000382
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +0000383 /// useIntv - indicate that all instructions in MBB should use OpenLI.
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000384 void useIntv(const MachineBasicBlock &MBB);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000385
Jakob Stoklund Olesen07862842011-01-26 00:50:53 +0000386 /// useIntv - indicate that all instructions in range should use OpenLI.
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000387 void useIntv(SlotIndex Start, SlotIndex End);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000388
Jakob Stoklund Olesen207c8682011-02-03 17:04:16 +0000389 /// leaveIntvAfter - Leave the open interval after the instruction at Idx.
390 /// Return the end of the live range.
391 SlotIndex leaveIntvAfter(SlotIndex Idx);
Jakob Stoklund Olesenf1b05f22010-08-12 17:07:14 +0000392
Jakob Stoklund Olesen9b057772011-02-09 23:30:25 +0000393 /// leaveIntvBefore - Leave the open interval before the instruction at Idx.
394 /// Return the end of the live range.
395 SlotIndex leaveIntvBefore(SlotIndex Idx);
396
Jakob Stoklund Olesen7536f722010-08-04 22:08:39 +0000397 /// leaveIntvAtTop - Leave the interval at the top of MBB.
Jakob Stoklund Olesen207c8682011-02-03 17:04:16 +0000398 /// Add liveness from the MBB top to the copy.
399 /// Return the end of the live range.
400 SlotIndex leaveIntvAtTop(MachineBasicBlock &MBB);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000401
Jakob Stoklund Olesen5c716bd2011-02-08 18:50:21 +0000402 /// overlapIntv - Indicate that all instructions in range should use the open
403 /// interval, but also let the complement interval be live.
404 ///
405 /// This doubles the register pressure, but is sometimes required to deal with
406 /// register uses after the last valid split point.
407 ///
408 /// The Start index should be a return value from a leaveIntv* call, and End
409 /// should be in the same basic block. The parent interval must have the same
410 /// value across the range.
411 ///
412 void overlapIntv(SlotIndex Start, SlotIndex End);
413
Jakob Stoklund Olesen74669272010-10-08 23:42:21 +0000414 /// finish - after all the new live ranges have been created, compute the
415 /// remaining live range, and rewrite instructions to use the new registers.
Jakob Stoklund Olesen59280462011-04-21 18:38:15 +0000416 /// @param LRMap When not null, this vector will map each live range in Edit
417 /// back to the indices returned by openIntv.
418 /// There may be extra indices created by dead code elimination.
419 void finish(SmallVectorImpl<unsigned> *LRMap = 0);
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000420
Eric Christopher0f438112011-02-03 06:18:29 +0000421 /// dump - print the current interval maping to dbgs().
422 void dump() const;
423
Jakob Stoklund Olesenf0179002010-07-26 23:44:11 +0000424 // ===--- High level methods ---===
425
Jakob Stoklund Olesenfd5c5132011-04-12 19:32:53 +0000426 /// splitSingleBlock - Split CurLI into a separate live interval around the
427 /// uses in a single block. This is intended to be used as part of a larger
428 /// split, and doesn't call finish().
429 void splitSingleBlock(const SplitAnalysis::BlockInfo &BI);
430
Jakob Stoklund Olesenb4ddedc2011-07-15 21:47:57 +0000431 /// splitLiveThroughBlock - Split CurLI in the given block such that it
432 /// enters the block in IntvIn and leaves it in IntvOut. There may be uses in
433 /// the block, but they will be ignored when placing split points.
434 ///
435 /// @param MBBNum Block number.
436 /// @param IntvIn Interval index entering the block.
437 /// @param LeaveBefore When set, leave IntvIn before this point.
438 /// @param IntvOut Interval index leaving the block.
439 /// @param EnterAfter When set, enter IntvOut after this point.
440 void splitLiveThroughBlock(unsigned MBBNum,
441 unsigned IntvIn, SlotIndex LeaveBefore,
442 unsigned IntvOut, SlotIndex EnterAfter);
443
444 /// splitRegInBlock - Split CurLI in the given block such that it enters the
445 /// block in IntvIn and leaves it on the stack (or not at all). Split points
446 /// are placed in a way that avoids putting uses in the stack interval. This
447 /// may require creating a local interval when there is interference.
448 ///
449 /// @param BI Block descriptor.
450 /// @param IntvIn Interval index entering the block. Not 0.
451 /// @param LeaveBefore When set, leave IntvIn before this point.
452 void splitRegInBlock(const SplitAnalysis::BlockInfo &BI,
453 unsigned IntvIn, SlotIndex LeaveBefore);
454
455 /// splitRegOutBlock - Split CurLI in the given block such that it enters the
456 /// block on the stack (or isn't live-in at all) and leaves it in IntvOut.
457 /// Split points are placed to avoid interference and such that the uses are
458 /// not in the stack interval. This may require creating a local interval
459 /// when there is interference.
460 ///
461 /// @param BI Block descriptor.
462 /// @param IntvOut Interval index leaving the block.
463 /// @param EnterAfter When set, enter IntvOut after this point.
464 void splitRegOutBlock(const SplitAnalysis::BlockInfo &BI,
465 unsigned IntvOut, SlotIndex EnterAfter);
Jakob Stoklund Olesenfc412d82010-08-13 21:18:48 +0000466};
Jakob Stoklund Olesen8ae02632010-07-20 15:41:07 +0000467
468}
Sebastian Redl6796e4f2011-04-24 15:46:51 +0000469
470#endif