comparison lib/CodeGen/SplitKit.h @ 120:1172e4bd9c6f

update 4.0.0
author mir3636
date Fri, 25 Nov 2016 19:14:25 +0900
parents afa8332a0e37
children 803732b1fca8
comparison
equal deleted inserted replaced
101:34baf5011add 120:1172e4bd9c6f
16 #define LLVM_LIB_CODEGEN_SPLITKIT_H 16 #define LLVM_LIB_CODEGEN_SPLITKIT_H
17 17
18 #include "LiveRangeCalc.h" 18 #include "LiveRangeCalc.h"
19 #include "llvm/ADT/ArrayRef.h" 19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/DenseMap.h" 20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/DenseSet.h"
21 #include "llvm/ADT/IntervalMap.h" 22 #include "llvm/ADT/IntervalMap.h"
22 #include "llvm/ADT/SmallPtrSet.h" 23 #include "llvm/ADT/SmallPtrSet.h"
23 24
24 namespace llvm { 25 namespace llvm {
25 26
35 class TargetRegisterInfo; 36 class TargetRegisterInfo;
36 class VirtRegMap; 37 class VirtRegMap;
37 class VNInfo; 38 class VNInfo;
38 class raw_ostream; 39 class raw_ostream;
39 40
41 /// Determines the latest safe point in a block in which we can insert a split,
42 /// spill or other instruction related with CurLI.
43 class LLVM_LIBRARY_VISIBILITY InsertPointAnalysis {
44 private:
45 const LiveIntervals &LIS;
46
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
53 SlotIndex computeLastInsertPoint(const LiveInterval &CurLI,
54 const MachineBasicBlock &MBB);
55
56 public:
57 InsertPointAnalysis(const LiveIntervals &lis, unsigned BBNum);
58
59 /// Return the base index of the last valid insert point for \pCurLI in \pMBB.
60 SlotIndex getLastInsertPoint(const LiveInterval &CurLI,
61 const MachineBasicBlock &MBB) {
62 unsigned Num = MBB.getNumber();
63 // Inline the common simple case.
64 if (LastInsertPoint[Num].first.isValid() &&
65 !LastInsertPoint[Num].second.isValid())
66 return LastInsertPoint[Num].first;
67 return computeLastInsertPoint(CurLI, MBB);
68 }
69
70 /// Returns the last insert point as an iterator for \pCurLI in \pMBB.
71 MachineBasicBlock::iterator getLastInsertPointIter(const LiveInterval &CurLI,
72 MachineBasicBlock &MBB);
73 };
74
40 /// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting 75 /// SplitAnalysis - Analyze a LiveInterval, looking for live range splitting
41 /// opportunities. 76 /// opportunities.
42 class LLVM_LIBRARY_VISIBILITY SplitAnalysis { 77 class LLVM_LIBRARY_VISIBILITY SplitAnalysis {
43 public: 78 public:
44 const MachineFunction &MF; 79 const MachineFunction &MF;
81 116
82 private: 117 private:
83 // Current live interval. 118 // Current live interval.
84 const LiveInterval *CurLI; 119 const LiveInterval *CurLI;
85 120
121 /// Insert Point Analysis.
122 InsertPointAnalysis IPA;
123
86 // Sorted slot indexes of using instructions. 124 // Sorted slot indexes of using instructions.
87 SmallVector<SlotIndex, 8> UseSlots; 125 SmallVector<SlotIndex, 8> UseSlots;
88
89 /// LastSplitPoint - Last legal split point in each basic block in the current
90 /// function. The first entry is the first terminator, the second entry is the
91 /// last valid split point for a variable that is live in to a landing pad
92 /// successor.
93 SmallVector<std::pair<SlotIndex, SlotIndex>, 8> LastSplitPoint;
94 126
95 /// UseBlocks - Blocks where CurLI has uses. 127 /// UseBlocks - Blocks where CurLI has uses.
96 SmallVector<BlockInfo, 8> UseBlocks; 128 SmallVector<BlockInfo, 8> UseBlocks;
97 129
98 /// NumGapBlocks - Number of duplicate entries in UseBlocks for blocks where 130 /// NumGapBlocks - Number of duplicate entries in UseBlocks for blocks where
105 /// NumThroughBlocks - Number of live-through blocks. 137 /// NumThroughBlocks - Number of live-through blocks.
106 unsigned NumThroughBlocks; 138 unsigned NumThroughBlocks;
107 139
108 /// DidRepairRange - analyze was forced to shrinkToUses(). 140 /// DidRepairRange - analyze was forced to shrinkToUses().
109 bool DidRepairRange; 141 bool DidRepairRange;
110
111 SlotIndex computeLastSplitPoint(unsigned Num);
112 142
113 // Sumarize statistics by counting instructions using CurLI. 143 // Sumarize statistics by counting instructions using CurLI.
114 void analyzeUses(); 144 void analyzeUses();
115 145
116 /// calcLiveBlockInfo - Compute per-block information about CurLI. 146 /// calcLiveBlockInfo - Compute per-block information about CurLI.
133 /// new interval. 163 /// new interval.
134 void clear(); 164 void clear();
135 165
136 /// getParent - Return the last analyzed interval. 166 /// getParent - Return the last analyzed interval.
137 const LiveInterval &getParent() const { return *CurLI; } 167 const LiveInterval &getParent() const { return *CurLI; }
138
139 /// getLastSplitPoint - Return the base index of the last valid split point
140 /// in the basic block numbered Num.
141 SlotIndex getLastSplitPoint(unsigned Num) {
142 // Inline the common simple case.
143 if (LastSplitPoint[Num].first.isValid() &&
144 !LastSplitPoint[Num].second.isValid())
145 return LastSplitPoint[Num].first;
146 return computeLastSplitPoint(Num);
147 }
148
149 /// getLastSplitPointIter - Returns the last split point as an iterator.
150 MachineBasicBlock::iterator getLastSplitPointIter(MachineBasicBlock*);
151 168
152 /// isOriginalEndpoint - Return true if the original live range was killed or 169 /// isOriginalEndpoint - Return true if the original live range was killed or
153 /// (re-)defined at Idx. Idx should be the 'def' slot for a normal kill/def, 170 /// (re-)defined at Idx. Idx should be the 'def' slot for a normal kill/def,
154 /// and 'use' for an early-clobber def. 171 /// and 'use' for an early-clobber def.
155 /// This can be used to recognize code inserted by earlier live range 172 /// This can be used to recognize code inserted by earlier live range
192 /// class. 209 /// class.
193 /// 210 ///
194 /// @param BI The block to be isolated. 211 /// @param BI The block to be isolated.
195 /// @param SingleInstrs True when single instructions should be isolated. 212 /// @param SingleInstrs True when single instructions should be isolated.
196 bool shouldSplitSingleBlock(const BlockInfo &BI, bool SingleInstrs) const; 213 bool shouldSplitSingleBlock(const BlockInfo &BI, bool SingleInstrs) const;
214
215 SlotIndex getLastSplitPoint(unsigned Num) {
216 return IPA.getLastInsertPoint(*CurLI, *MF.getBlockNumbered(Num));
217 }
218
219 MachineBasicBlock::iterator getLastSplitPointIter(MachineBasicBlock *BB) {
220 return IPA.getLastInsertPointIter(*CurLI, *BB);
221 }
197 }; 222 };
198 223
199 224
200 /// SplitEditor - Edit machine code and LiveIntervals for live range 225 /// SplitEditor - Edit machine code and LiveIntervals for live range
201 /// splitting. 226 /// splitting.
208 /// - Finish the current interval with closeIntv and repeat from 2. 233 /// - Finish the current interval with closeIntv and repeat from 2.
209 /// - Rewrite instructions with finish(). 234 /// - Rewrite instructions with finish().
210 /// 235 ///
211 class LLVM_LIBRARY_VISIBILITY SplitEditor { 236 class LLVM_LIBRARY_VISIBILITY SplitEditor {
212 SplitAnalysis &SA; 237 SplitAnalysis &SA;
238 AliasAnalysis &AA;
213 LiveIntervals &LIS; 239 LiveIntervals &LIS;
214 VirtRegMap &VRM; 240 VirtRegMap &VRM;
215 MachineRegisterInfo &MRI; 241 MachineRegisterInfo &MRI;
216 MachineDominatorTree &MDT; 242 MachineDominatorTree &MDT;
217 const TargetInstrInfo &TII; 243 const TargetInstrInfo &TII;
297 /// LRCalc instance. When not in spill mode, all intervals can share one. 323 /// LRCalc instance. When not in spill mode, all intervals can share one.
298 LiveRangeCalc &getLRCalc(unsigned RegIdx) { 324 LiveRangeCalc &getLRCalc(unsigned RegIdx) {
299 return LRCalc[SpillMode != SM_Partition && RegIdx != 0]; 325 return LRCalc[SpillMode != SM_Partition && RegIdx != 0];
300 } 326 }
301 327
328 /// Find a subrange corresponding to the lane mask @p LM in the live
329 /// interval @p LI. The interval @p LI is assumed to contain such a subrange.
330 /// This function is used to find corresponding subranges between the
331 /// original interval and the new intervals.
332 LiveInterval::SubRange &getSubRangeForMask(LaneBitmask LM, LiveInterval &LI);
333
334 /// Add a segment to the interval LI for the value number VNI. If LI has
335 /// subranges, corresponding segments will be added to them as well, but
336 /// with newly created value numbers. If Original is true, dead def will
337 /// only be added a subrange of LI if the corresponding subrange of the
338 /// original interval has a def at this index. Otherwise, all subranges
339 /// of LI will be updated.
340 void addDeadDef(LiveInterval &LI, VNInfo *VNI, bool Original);
341
302 /// defValue - define a value in RegIdx from ParentVNI at Idx. 342 /// defValue - define a value in RegIdx from ParentVNI at Idx.
303 /// Idx does not have to be ParentVNI->def, but it must be contained within 343 /// Idx does not have to be ParentVNI->def, but it must be contained within
304 /// ParentVNI's live range in ParentLI. The new value is added to the value 344 /// ParentVNI's live range in ParentLI. The new value is added to the value
305 /// map. 345 /// map. The value being defined may either come from rematerialization
346 /// (or an inserted copy), or it may be coming from the original interval.
347 /// The parameter Original should be true in the latter case, otherwise
348 /// it should be false.
306 /// Return the new LI value. 349 /// Return the new LI value.
307 VNInfo *defValue(unsigned RegIdx, const VNInfo *ParentVNI, SlotIndex Idx); 350 VNInfo *defValue(unsigned RegIdx, const VNInfo *ParentVNI, SlotIndex Idx,
351 bool Original);
308 352
309 /// forceRecompute - Force the live range of ParentVNI in RegIdx to be 353 /// forceRecompute - Force the live range of ParentVNI in RegIdx to be
310 /// recomputed by LiveRangeCalc::extend regardless of the number of defs. 354 /// recomputed by LiveRangeCalc::extend regardless of the number of defs.
311 /// This is used for values whose live range doesn't match RegAssign exactly. 355 /// This is used for values whose live range doesn't match RegAssign exactly.
312 /// They could have rematerialized, or back-copies may have been moved. 356 /// They could have rematerialized, or back-copies may have been moved.
327 /// getShallowDominator - Returns the least busy dominator of MBB that is 371 /// getShallowDominator - Returns the least busy dominator of MBB that is
328 /// also dominated by DefMBB. Busy is measured by loop depth. 372 /// also dominated by DefMBB. Busy is measured by loop depth.
329 MachineBasicBlock *findShallowDominator(MachineBasicBlock *MBB, 373 MachineBasicBlock *findShallowDominator(MachineBasicBlock *MBB,
330 MachineBasicBlock *DefMBB); 374 MachineBasicBlock *DefMBB);
331 375
332 /// hoistCopiesForSize - Hoist back-copies to the complement interval in a 376 /// Find out all the backCopies dominated by others.
333 /// way that minimizes code size. This implements the SM_Size spill mode. 377 void computeRedundantBackCopies(DenseSet<unsigned> &NotToHoistSet,
334 void hoistCopiesForSize(); 378 SmallVectorImpl<VNInfo *> &BackCopies);
379
380 /// Hoist back-copies to the complement interval. It tries to hoist all
381 /// the back-copies to one BB if it is beneficial, or else simply remove
382 /// redundant backcopies dominated by others.
383 void hoistCopies();
335 384
336 /// transferValues - Transfer values to the new ranges. 385 /// transferValues - Transfer values to the new ranges.
337 /// Return true if any ranges were skipped. 386 /// Return true if any ranges were skipped.
338 bool transferValues(); 387 bool transferValues();
339 388
389 /// Live range @p LR corresponding to the lane Mask @p LM has a live
390 /// PHI def at the beginning of block @p B. Extend the range @p LR of
391 /// all predecessor values that reach this def. If @p LR is a subrange,
392 /// the array @p Undefs is the set of all locations where it is undefined
393 /// via <def,read-undef> in other subranges for the same register.
394 void extendPHIRange(MachineBasicBlock &B, LiveRangeCalc &LRC,
395 LiveRange &LR, LaneBitmask LM,
396 ArrayRef<SlotIndex> Undefs);
397
340 /// extendPHIKillRanges - Extend the ranges of all values killed by original 398 /// extendPHIKillRanges - Extend the ranges of all values killed by original
341 /// parent PHIDefs. 399 /// parent PHIDefs.
342 void extendPHIKillRanges(); 400 void extendPHIKillRanges();
343 401
344 /// rewriteAssigned - Rewrite all uses of Edit.getReg() to assigned registers. 402 /// rewriteAssigned - Rewrite all uses of Edit.getReg() to assigned registers.
348 void deleteRematVictims(); 406 void deleteRematVictims();
349 407
350 public: 408 public:
351 /// Create a new SplitEditor for editing the LiveInterval analyzed by SA. 409 /// Create a new SplitEditor for editing the LiveInterval analyzed by SA.
352 /// Newly created intervals will be appended to newIntervals. 410 /// Newly created intervals will be appended to newIntervals.
353 SplitEditor(SplitAnalysis &SA, LiveIntervals&, VirtRegMap&, 411 SplitEditor(SplitAnalysis &SA, AliasAnalysis &AA, LiveIntervals&,
354 MachineDominatorTree&, MachineBlockFrequencyInfo &); 412 VirtRegMap&, MachineDominatorTree&,
413 MachineBlockFrequencyInfo &);
355 414
356 /// reset - Prepare for a new split. 415 /// reset - Prepare for a new split.
357 void reset(LiveRangeEdit&, ComplementSpillMode = SM_Partition); 416 void reset(LiveRangeEdit&, ComplementSpillMode = SM_Partition);
358 417
359 /// Create a new virtual register and live interval. 418 /// Create a new virtual register and live interval.