SplitKit.h 24 KB

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