SplitKit.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. //===- SplitKit.h - Toolkit for splitting live ranges -----------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file contains the SplitAnalysis class as well as mutator functions for
  10. // live range splitting.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LIB_CODEGEN_SPLITKIT_H
  14. #define LLVM_LIB_CODEGEN_SPLITKIT_H
  15. #include "LiveRangeCalc.h"
  16. #include "llvm/ADT/ArrayRef.h"
  17. #include "llvm/ADT/BitVector.h"
  18. #include "llvm/ADT/DenseMap.h"
  19. #include "llvm/ADT/DenseSet.h"
  20. #include "llvm/ADT/IntervalMap.h"
  21. #include "llvm/ADT/PointerIntPair.h"
  22. #include "llvm/ADT/SmallPtrSet.h"
  23. #include "llvm/ADT/SmallVector.h"
  24. #include "llvm/CodeGen/LiveInterval.h"
  25. #include "llvm/CodeGen/LiveIntervals.h"
  26. #include "llvm/CodeGen/MachineBasicBlock.h"
  27. #include "llvm/CodeGen/MachineFunction.h"
  28. #include "llvm/CodeGen/SlotIndexes.h"
  29. #include "llvm/MC/LaneBitmask.h"
  30. #include "llvm/Support/Compiler.h"
  31. #include <utility>
  32. namespace llvm {
  33. class LiveIntervals;
  34. class LiveRangeEdit;
  35. class MachineBlockFrequencyInfo;
  36. class MachineDominatorTree;
  37. class MachineLoopInfo;
  38. class MachineRegisterInfo;
  39. class TargetInstrInfo;
  40. class TargetRegisterInfo;
  41. class VirtRegMap;
  42. /// Determines the latest safe point in a block in which we can insert a split,
  43. /// spill or other instruction related with CurLI.
  44. class LLVM_LIBRARY_VISIBILITY InsertPointAnalysis {
  45. private:
  46. const LiveIntervals &LIS;
  47. /// Last legal insert point in each basic block in the current function.
  48. /// The first entry is the first terminator, the second entry is the
  49. /// last valid point to insert a split or spill for a variable that is
  50. /// live into a landing pad successor.
  51. SmallVector<std::pair<SlotIndex, SlotIndex>, 8> LastInsertPoint;
  52. SlotIndex computeLastInsertPoint(const LiveInterval &CurLI,
  53. const MachineBasicBlock &MBB);
  54. public:
  55. InsertPointAnalysis(const LiveIntervals &lis, unsigned BBNum);
  56. /// Return the base index of the last valid insert point for \pCurLI in \pMBB.
  57. SlotIndex getLastInsertPoint(const LiveInterval &CurLI,
  58. const MachineBasicBlock &MBB) {
  59. unsigned Num = MBB.getNumber();
  60. // Inline the common simple case.
  61. if (LastInsertPoint[Num].first.isValid() &&
  62. !LastInsertPoint[Num].second.isValid())
  63. return LastInsertPoint[Num].first;
  64. return computeLastInsertPoint(CurLI, MBB);
  65. }
  66. /// Returns the last insert point as an iterator for \pCurLI in \pMBB.
  67. MachineBasicBlock::iterator getLastInsertPointIter(const LiveInterval &CurLI,
  68. MachineBasicBlock &MBB);
  69. /// Return the base index of the first insert point in \pMBB.
  70. SlotIndex getFirstInsertPoint(MachineBasicBlock &MBB) {
  71. SlotIndex Res = LIS.getMBBStartIdx(&MBB);
  72. if (!MBB.empty()) {
  73. MachineBasicBlock::iterator MII = MBB.SkipPHIsLabelsAndDebug(MBB.begin());
  74. if (MII != MBB.end())
  75. Res = LIS.getInstructionIndex(*MII);
  76. }
  77. return Res;
  78. }
  79. };
  80. /// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting
  81. /// opportunities.
  82. class LLVM_LIBRARY_VISIBILITY SplitAnalysis {
  83. public:
  84. const MachineFunction &MF;
  85. const VirtRegMap &VRM;
  86. const LiveIntervals &LIS;
  87. const MachineLoopInfo &Loops;
  88. const TargetInstrInfo &TII;
  89. /// Additional information about basic blocks where the current variable is
  90. /// live. Such a block will look like one of these templates:
  91. ///
  92. /// 1. | o---x | Internal to block. Variable is only live in this block.
  93. /// 2. |---x | Live-in, kill.
  94. /// 3. | o---| Def, live-out.
  95. /// 4. |---x o---| Live-in, kill, def, live-out. Counted by NumGapBlocks.
  96. /// 5. |---o---o---| Live-through with uses or defs.
  97. /// 6. |-----------| Live-through without uses. Counted by NumThroughBlocks.
  98. ///
  99. /// Two BlockInfo entries are created for template 4. One for the live-in
  100. /// segment, and one for the live-out segment. These entries look as if the
  101. /// block were split in the middle where the live range isn't live.
  102. ///
  103. /// Live-through blocks without any uses don't get BlockInfo entries. They
  104. /// are simply listed in ThroughBlocks instead.
  105. ///
  106. struct BlockInfo {
  107. MachineBasicBlock *MBB;
  108. SlotIndex FirstInstr; ///< First instr accessing current reg.
  109. SlotIndex LastInstr; ///< Last instr accessing current reg.
  110. SlotIndex FirstDef; ///< First non-phi valno->def, or SlotIndex().
  111. bool LiveIn; ///< Current reg is live in.
  112. bool LiveOut; ///< Current reg is live out.
  113. /// isOneInstr - Returns true when this BlockInfo describes a single
  114. /// instruction.
  115. bool isOneInstr() const {
  116. return SlotIndex::isSameInstr(FirstInstr, LastInstr);
  117. }
  118. };
  119. private:
  120. // Current live interval.
  121. const LiveInterval *CurLI = nullptr;
  122. /// Insert Point Analysis.
  123. InsertPointAnalysis IPA;
  124. // Sorted slot indexes of using instructions.
  125. SmallVector<SlotIndex, 8> UseSlots;
  126. /// UseBlocks - Blocks where CurLI has uses.
  127. SmallVector<BlockInfo, 8> UseBlocks;
  128. /// NumGapBlocks - Number of duplicate entries in UseBlocks for blocks where
  129. /// the live range has a gap.
  130. unsigned NumGapBlocks;
  131. /// ThroughBlocks - Block numbers where CurLI is live through without uses.
  132. BitVector ThroughBlocks;
  133. /// NumThroughBlocks - Number of live-through blocks.
  134. unsigned NumThroughBlocks;
  135. /// DidRepairRange - analyze was forced to shrinkToUses().
  136. bool DidRepairRange;
  137. // Sumarize statistics by counting instructions using CurLI.
  138. void analyzeUses();
  139. /// calcLiveBlockInfo - Compute per-block information about CurLI.
  140. bool calcLiveBlockInfo();
  141. public:
  142. SplitAnalysis(const VirtRegMap &vrm, const LiveIntervals &lis,
  143. const MachineLoopInfo &mli);
  144. /// analyze - set CurLI to the specified interval, and analyze how it may be
  145. /// split.
  146. void analyze(const LiveInterval *li);
  147. /// didRepairRange() - Returns true if CurLI was invalid and has been repaired
  148. /// by analyze(). This really shouldn't happen, but sometimes the coalescer
  149. /// can create live ranges that end in mid-air.
  150. bool didRepairRange() const { return DidRepairRange; }
  151. /// clear - clear all data structures so SplitAnalysis is ready to analyze a
  152. /// new interval.
  153. void clear();
  154. /// getParent - Return the last analyzed interval.
  155. const LiveInterval &getParent() const { return *CurLI; }
  156. /// 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. /// getUseSlots - Return an array of SlotIndexes of instructions using CurLI.
  163. /// This include both use and def operands, at most one entry per instruction.
  164. ArrayRef<SlotIndex> getUseSlots() const { return UseSlots; }
  165. /// getUseBlocks - Return an array of BlockInfo objects for the basic blocks
  166. /// where CurLI has uses.
  167. ArrayRef<BlockInfo> getUseBlocks() const { return UseBlocks; }
  168. /// getNumThroughBlocks - Return the number of through blocks.
  169. unsigned getNumThroughBlocks() const { return NumThroughBlocks; }
  170. /// isThroughBlock - Return true if CurLI is live through MBB without uses.
  171. bool isThroughBlock(unsigned MBB) const { return ThroughBlocks.test(MBB); }
  172. /// getThroughBlocks - Return the set of through blocks.
  173. const BitVector &getThroughBlocks() const { return ThroughBlocks; }
  174. /// getNumLiveBlocks - Return the number of blocks where CurLI is live.
  175. unsigned getNumLiveBlocks() const {
  176. return getUseBlocks().size() - NumGapBlocks + getNumThroughBlocks();
  177. }
  178. /// countLiveBlocks - Return the number of blocks where li is live. This is
  179. /// guaranteed to return the same number as getNumLiveBlocks() after calling
  180. /// analyze(li).
  181. unsigned countLiveBlocks(const LiveInterval *li) const;
  182. using BlockPtrSet = SmallPtrSet<const MachineBasicBlock *, 16>;
  183. /// shouldSplitSingleBlock - Returns true if it would help to create a local
  184. /// live range for the instructions in BI. There is normally no benefit to
  185. /// creating a live range for a single instruction, but it does enable
  186. /// register class inflation if the instruction has a restricted register
  187. /// class.
  188. ///
  189. /// @param BI The block to be isolated.
  190. /// @param SingleInstrs True when single instructions should be isolated.
  191. bool shouldSplitSingleBlock(const BlockInfo &BI, bool SingleInstrs) const;
  192. SlotIndex getLastSplitPoint(unsigned Num) {
  193. return IPA.getLastInsertPoint(*CurLI, *MF.getBlockNumbered(Num));
  194. }
  195. MachineBasicBlock::iterator getLastSplitPointIter(MachineBasicBlock *BB) {
  196. return IPA.getLastInsertPointIter(*CurLI, *BB);
  197. }
  198. SlotIndex getFirstSplitPoint(unsigned Num) {
  199. return IPA.getFirstInsertPoint(*MF.getBlockNumbered(Num));
  200. }
  201. };
  202. /// SplitEditor - Edit machine code and LiveIntervals for live range
  203. /// splitting.
  204. ///
  205. /// - Create a SplitEditor from a SplitAnalysis.
  206. /// - Start a new live interval with openIntv.
  207. /// - Mark the places where the new interval is entered using enterIntv*
  208. /// - Mark the ranges where the new interval is used with useIntv*
  209. /// - Mark the places where the interval is exited with exitIntv*.
  210. /// - Finish the current interval with closeIntv and repeat from 2.
  211. /// - Rewrite instructions with finish().
  212. ///
  213. class LLVM_LIBRARY_VISIBILITY SplitEditor {
  214. SplitAnalysis &SA;
  215. AliasAnalysis &AA;
  216. LiveIntervals &LIS;
  217. VirtRegMap &VRM;
  218. MachineRegisterInfo &MRI;
  219. MachineDominatorTree &MDT;
  220. const TargetInstrInfo &TII;
  221. const TargetRegisterInfo &TRI;
  222. const MachineBlockFrequencyInfo &MBFI;
  223. public:
  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. /// 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. /// SM_Speed - Overlap intervals to minimize the expected execution
  243. /// frequency of the inserted copies. This is very similar to SM_Size, but
  244. /// the complement interval may get some extra PHI-defs.
  245. SM_Speed
  246. };
  247. private:
  248. /// Edit - The current parent register and new intervals created.
  249. LiveRangeEdit *Edit = nullptr;
  250. /// Index into Edit of the currently open interval.
  251. /// The index 0 is used for the complement, so the first interval started by
  252. /// openIntv will be 1.
  253. unsigned OpenIdx = 0;
  254. /// The current spill mode, selected by reset().
  255. ComplementSpillMode SpillMode = SM_Partition;
  256. using RegAssignMap = IntervalMap<SlotIndex, unsigned>;
  257. /// Allocator for the interval map. This will eventually be shared with
  258. /// SlotIndexes and LiveIntervals.
  259. RegAssignMap::Allocator Allocator;
  260. /// RegAssign - Map of the assigned register indexes.
  261. /// Edit.get(RegAssign.lookup(Idx)) is the register that should be live at
  262. /// Idx.
  263. RegAssignMap RegAssign;
  264. using ValueForcePair = PointerIntPair<VNInfo *, 1>;
  265. using ValueMap = DenseMap<std::pair<unsigned, unsigned>, ValueForcePair>;
  266. /// Values - keep track of the mapping from parent values to values in the new
  267. /// intervals. Given a pair (RegIdx, ParentVNI->id), Values contains:
  268. ///
  269. /// 1. No entry - the value is not mapped to Edit.get(RegIdx).
  270. /// 2. (Null, false) - the value is mapped to multiple values in
  271. /// Edit.get(RegIdx). Each value is represented by a minimal live range at
  272. /// its def. The full live range can be inferred exactly from the range
  273. /// of RegIdx in RegAssign.
  274. /// 3. (Null, true). As above, but the ranges in RegAssign are too large, and
  275. /// the live range must be recomputed using LiveRangeCalc::extend().
  276. /// 4. (VNI, false) The value is mapped to a single new value.
  277. /// The new value has no live ranges anywhere.
  278. ValueMap Values;
  279. /// LRCalc - Cache for computing live ranges and SSA update. Each instance
  280. /// can only handle non-overlapping live ranges, so use a separate
  281. /// LiveRangeCalc instance for the complement interval when in spill mode.
  282. LiveRangeCalc LRCalc[2];
  283. /// getLRCalc - Return the LRCalc to use for RegIdx. In spill mode, the
  284. /// complement interval can overlap the other intervals, so it gets its own
  285. /// LRCalc instance. When not in spill mode, all intervals can share one.
  286. LiveRangeCalc &getLRCalc(unsigned RegIdx) {
  287. return LRCalc[SpillMode != SM_Partition && RegIdx != 0];
  288. }
  289. /// Find a subrange corresponding to the lane mask @p LM in the live
  290. /// interval @p LI. The interval @p LI is assumed to contain such a subrange.
  291. /// This function is used to find corresponding subranges between the
  292. /// original interval and the new intervals.
  293. LiveInterval::SubRange &getSubRangeForMask(LaneBitmask LM, LiveInterval &LI);
  294. /// Add a segment to the interval LI for the value number VNI. If LI has
  295. /// subranges, corresponding segments will be added to them as well, but
  296. /// with newly created value numbers. If Original is true, dead def will
  297. /// only be added a subrange of LI if the corresponding subrange of the
  298. /// original interval has a def at this index. Otherwise, all subranges
  299. /// of LI will be updated.
  300. void addDeadDef(LiveInterval &LI, VNInfo *VNI, bool Original);
  301. /// defValue - define a value in RegIdx from ParentVNI at Idx.
  302. /// Idx does not have to be ParentVNI->def, but it must be contained within
  303. /// ParentVNI's live range in ParentLI. The new value is added to the value
  304. /// map. The value being defined may either come from rematerialization
  305. /// (or an inserted copy), or it may be coming from the original interval.
  306. /// The parameter Original should be true in the latter case, otherwise
  307. /// it should be false.
  308. /// Return the new LI value.
  309. VNInfo *defValue(unsigned RegIdx, const VNInfo *ParentVNI, SlotIndex Idx,
  310. bool Original);
  311. /// forceRecompute - Force the live range of ParentVNI in RegIdx to be
  312. /// recomputed by LiveRangeCalc::extend regardless of the number of defs.
  313. /// This is used for values whose live range doesn't match RegAssign exactly.
  314. /// They could have rematerialized, or back-copies may have been moved.
  315. void forceRecompute(unsigned RegIdx, const VNInfo &ParentVNI);
  316. /// Calls forceRecompute() on any affected regidx and on ParentVNI
  317. /// predecessors in case of a phi definition.
  318. void forceRecomputeVNI(const VNInfo &ParentVNI);
  319. /// defFromParent - Define Reg from ParentVNI at UseIdx using either
  320. /// rematerialization or a COPY from parent. Return the new value.
  321. VNInfo *defFromParent(unsigned RegIdx,
  322. VNInfo *ParentVNI,
  323. SlotIndex UseIdx,
  324. MachineBasicBlock &MBB,
  325. MachineBasicBlock::iterator I);
  326. /// removeBackCopies - Remove the copy instructions that defines the values
  327. /// in the vector in the complement interval.
  328. void removeBackCopies(SmallVectorImpl<VNInfo*> &Copies);
  329. /// getShallowDominator - Returns the least busy dominator of MBB that is
  330. /// also dominated by DefMBB. Busy is measured by loop depth.
  331. MachineBasicBlock *findShallowDominator(MachineBasicBlock *MBB,
  332. MachineBasicBlock *DefMBB);
  333. /// Find out all the backCopies dominated by others.
  334. void computeRedundantBackCopies(DenseSet<unsigned> &NotToHoistSet,
  335. SmallVectorImpl<VNInfo *> &BackCopies);
  336. /// Hoist back-copies to the complement interval. It tries to hoist all
  337. /// the back-copies to one BB if it is beneficial, or else simply remove
  338. /// redundant backcopies dominated by others.
  339. void hoistCopies();
  340. /// transferValues - Transfer values to the new ranges.
  341. /// Return true if any ranges were skipped.
  342. bool transferValues();
  343. /// Live range @p LR corresponding to the lane Mask @p LM has a live
  344. /// PHI def at the beginning of block @p B. Extend the range @p LR of
  345. /// all predecessor values that reach this def. If @p LR is a subrange,
  346. /// the array @p Undefs is the set of all locations where it is undefined
  347. /// via <def,read-undef> in other subranges for the same register.
  348. void extendPHIRange(MachineBasicBlock &B, LiveRangeCalc &LRC,
  349. LiveRange &LR, LaneBitmask LM,
  350. ArrayRef<SlotIndex> Undefs);
  351. /// extendPHIKillRanges - Extend the ranges of all values killed by original
  352. /// parent PHIDefs.
  353. void extendPHIKillRanges();
  354. /// rewriteAssigned - Rewrite all uses of Edit.getReg() to assigned registers.
  355. void rewriteAssigned(bool ExtendRanges);
  356. /// deleteRematVictims - Delete defs that are dead after rematerializing.
  357. void deleteRematVictims();
  358. /// Add a copy instruction copying \p FromReg to \p ToReg before
  359. /// \p InsertBefore. This can be invoked with a \p LaneMask which may make it
  360. /// necessary to construct a sequence of copies to cover it exactly.
  361. SlotIndex buildCopy(unsigned FromReg, unsigned ToReg, LaneBitmask LaneMask,
  362. MachineBasicBlock &MBB, MachineBasicBlock::iterator InsertBefore,
  363. bool Late, unsigned RegIdx);
  364. SlotIndex buildSingleSubRegCopy(unsigned FromReg, unsigned ToReg,
  365. MachineBasicBlock &MB, MachineBasicBlock::iterator InsertBefore,
  366. unsigned SubIdx, LiveInterval &DestLI, bool Late, SlotIndex Def);
  367. public:
  368. /// Create a new SplitEditor for editing the LiveInterval analyzed by SA.
  369. /// Newly created intervals will be appended to newIntervals.
  370. SplitEditor(SplitAnalysis &sa, AliasAnalysis &aa, LiveIntervals &lis,
  371. VirtRegMap &vrm, MachineDominatorTree &mdt,
  372. MachineBlockFrequencyInfo &mbfi);
  373. /// reset - Prepare for a new split.
  374. void reset(LiveRangeEdit&, ComplementSpillMode = SM_Partition);
  375. /// Create a new virtual register and live interval.
  376. /// Return the interval index, starting from 1. Interval index 0 is the
  377. /// implicit complement interval.
  378. unsigned openIntv();
  379. /// currentIntv - Return the current interval index.
  380. unsigned currentIntv() const { return OpenIdx; }
  381. /// selectIntv - Select a previously opened interval index.
  382. void selectIntv(unsigned Idx);
  383. /// enterIntvBefore - Enter the open interval before the instruction at Idx.
  384. /// If the parent interval is not live before Idx, a COPY is not inserted.
  385. /// Return the beginning of the new live range.
  386. SlotIndex enterIntvBefore(SlotIndex Idx);
  387. /// enterIntvAfter - Enter the open interval after the instruction at Idx.
  388. /// Return the beginning of the new live range.
  389. SlotIndex enterIntvAfter(SlotIndex Idx);
  390. /// enterIntvAtEnd - Enter the open interval at the end of MBB.
  391. /// Use the open interval from the inserted copy to the MBB end.
  392. /// Return the beginning of the new live range.
  393. SlotIndex enterIntvAtEnd(MachineBasicBlock &MBB);
  394. /// useIntv - indicate that all instructions in MBB should use OpenLI.
  395. void useIntv(const MachineBasicBlock &MBB);
  396. /// useIntv - indicate that all instructions in range should use OpenLI.
  397. void useIntv(SlotIndex Start, SlotIndex End);
  398. /// leaveIntvAfter - Leave the open interval after the instruction at Idx.
  399. /// Return the end of the live range.
  400. SlotIndex leaveIntvAfter(SlotIndex Idx);
  401. /// leaveIntvBefore - Leave the open interval before the instruction at Idx.
  402. /// Return the end of the live range.
  403. SlotIndex leaveIntvBefore(SlotIndex Idx);
  404. /// leaveIntvAtTop - Leave the interval at the top of MBB.
  405. /// Add liveness from the MBB top to the copy.
  406. /// Return the end of the live range.
  407. SlotIndex leaveIntvAtTop(MachineBasicBlock &MBB);
  408. /// overlapIntv - Indicate that all instructions in range should use the open
  409. /// interval, but also let the complement interval be live.
  410. ///
  411. /// This doubles the register pressure, but is sometimes required to deal with
  412. /// register uses after the last valid split point.
  413. ///
  414. /// The Start index should be a return value from a leaveIntv* call, and End
  415. /// should be in the same basic block. The parent interval must have the same
  416. /// value across the range.
  417. ///
  418. void overlapIntv(SlotIndex Start, SlotIndex End);
  419. /// finish - after all the new live ranges have been created, compute the
  420. /// remaining live range, and rewrite instructions to use the new registers.
  421. /// @param LRMap When not null, this vector will map each live range in Edit
  422. /// back to the indices returned by openIntv.
  423. /// There may be extra indices created by dead code elimination.
  424. void finish(SmallVectorImpl<unsigned> *LRMap = nullptr);
  425. /// dump - print the current interval mapping to dbgs().
  426. void dump() const;
  427. // ===--- High level methods ---===
  428. /// splitSingleBlock - Split CurLI into a separate live interval around the
  429. /// uses in a single block. This is intended to be used as part of a larger
  430. /// split, and doesn't call finish().
  431. void splitSingleBlock(const SplitAnalysis::BlockInfo &BI);
  432. /// 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. /// 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. /// splitRegOutBlock - Split CurLI in the given block such that it enters the
  455. /// block on the stack (or isn't live-in at all) and leaves it in IntvOut.
  456. /// Split points are placed to avoid interference and such that the uses are
  457. /// not in the stack interval. This may require creating a local interval
  458. /// when there is interference.
  459. ///
  460. /// @param BI Block descriptor.
  461. /// @param IntvOut Interval index leaving the block.
  462. /// @param EnterAfter When set, enter IntvOut after this point.
  463. void splitRegOutBlock(const SplitAnalysis::BlockInfo &BI,
  464. unsigned IntvOut, SlotIndex EnterAfter);
  465. };
  466. } // end namespace llvm
  467. #endif // LLVM_LIB_CODEGEN_SPLITKIT_H