Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 1 | //===-- PreAllocSplitting.cpp - Pre-allocation Interval Spltting Pass. ----===// |
| 2 | // |
| 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 implements the machine instruction level pre-register allocation |
| 11 | // live interval splitting pass. It finds live interval barriers, i.e. |
| 12 | // instructions which will kill all physical registers in certain register |
| 13 | // classes, and split all live intervals which cross the barrier. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #define DEBUG_TYPE "pre-alloc-split" |
| 18 | #include "llvm/CodeGen/LiveIntervalAnalysis.h" |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/LiveStackAnalysis.h" |
Owen Anderson | f1f75b1 | 2008-11-04 22:22:41 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineDominators.h" |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 23 | #include "llvm/CodeGen/MachineLoopInfo.h" |
| 24 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 25 | #include "llvm/CodeGen/Passes.h" |
| 26 | #include "llvm/CodeGen/RegisterCoalescer.h" |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetInstrInfo.h" |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetMachine.h" |
| 29 | #include "llvm/Target/TargetOptions.h" |
| 30 | #include "llvm/Target/TargetRegisterInfo.h" |
| 31 | #include "llvm/Support/CommandLine.h" |
| 32 | #include "llvm/Support/Debug.h" |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 33 | #include "llvm/ADT/DenseMap.h" |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 34 | #include "llvm/ADT/DepthFirstIterator.h" |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 35 | #include "llvm/ADT/SmallPtrSet.h" |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 36 | #include "llvm/ADT/Statistic.h" |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 37 | using namespace llvm; |
| 38 | |
Evan Cheng | ae7fa5b | 2008-10-28 01:48:24 +0000 | [diff] [blame] | 39 | static cl::opt<int> PreSplitLimit("pre-split-limit", cl::init(-1), cl::Hidden); |
| 40 | |
| 41 | STATISTIC(NumSplits, "Number of intervals split"); |
Owen Anderson | 75fa96b | 2008-11-19 04:28:29 +0000 | [diff] [blame] | 42 | STATISTIC(NumRemats, "Number of intervals split by rematerialization"); |
Owen Anderson | 7b9d67c | 2008-12-02 18:53:47 +0000 | [diff] [blame] | 43 | STATISTIC(NumFolds, "Number of intervals split with spill folding"); |
Owen Anderson | 2ebf63f | 2008-12-18 01:27:19 +0000 | [diff] [blame] | 44 | STATISTIC(NumRenumbers, "Number of intervals renumbered into new registers"); |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 45 | STATISTIC(NumDeadSpills, "Number of dead spills removed"); |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 46 | |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 47 | namespace { |
| 48 | class VISIBILITY_HIDDEN PreAllocSplitting : public MachineFunctionPass { |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 49 | MachineFunction *CurrMF; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 50 | const TargetMachine *TM; |
| 51 | const TargetInstrInfo *TII; |
| 52 | MachineFrameInfo *MFI; |
| 53 | MachineRegisterInfo *MRI; |
| 54 | LiveIntervals *LIs; |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 55 | LiveStacks *LSs; |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 56 | |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 57 | // Barrier - Current barrier being processed. |
| 58 | MachineInstr *Barrier; |
| 59 | |
| 60 | // BarrierMBB - Basic block where the barrier resides in. |
| 61 | MachineBasicBlock *BarrierMBB; |
| 62 | |
| 63 | // Barrier - Current barrier index. |
| 64 | unsigned BarrierIdx; |
| 65 | |
| 66 | // CurrLI - Current live interval being split. |
| 67 | LiveInterval *CurrLI; |
| 68 | |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 69 | // CurrSLI - Current stack slot live interval. |
| 70 | LiveInterval *CurrSLI; |
| 71 | |
| 72 | // CurrSValNo - Current val# for the stack slot live interval. |
| 73 | VNInfo *CurrSValNo; |
| 74 | |
| 75 | // IntervalSSMap - A map from live interval to spill slots. |
| 76 | DenseMap<unsigned, int> IntervalSSMap; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 77 | |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 78 | // Def2SpillMap - A map from a def instruction index to spill index. |
| 79 | DenseMap<unsigned, unsigned> Def2SpillMap; |
Evan Cheng | 0658749 | 2008-10-24 02:05:00 +0000 | [diff] [blame] | 80 | |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 81 | public: |
| 82 | static char ID; |
| 83 | PreAllocSplitting() : MachineFunctionPass(&ID) {} |
| 84 | |
| 85 | virtual bool runOnMachineFunction(MachineFunction &MF); |
| 86 | |
| 87 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 88 | AU.addRequired<LiveIntervals>(); |
| 89 | AU.addPreserved<LiveIntervals>(); |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 90 | AU.addRequired<LiveStacks>(); |
| 91 | AU.addPreserved<LiveStacks>(); |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 92 | AU.addPreserved<RegisterCoalescer>(); |
| 93 | if (StrongPHIElim) |
| 94 | AU.addPreservedID(StrongPHIEliminationID); |
| 95 | else |
| 96 | AU.addPreservedID(PHIEliminationID); |
Owen Anderson | f1f75b1 | 2008-11-04 22:22:41 +0000 | [diff] [blame] | 97 | AU.addRequired<MachineDominatorTree>(); |
| 98 | AU.addRequired<MachineLoopInfo>(); |
| 99 | AU.addPreserved<MachineDominatorTree>(); |
| 100 | AU.addPreserved<MachineLoopInfo>(); |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 101 | MachineFunctionPass::getAnalysisUsage(AU); |
| 102 | } |
| 103 | |
| 104 | virtual void releaseMemory() { |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 105 | IntervalSSMap.clear(); |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 106 | Def2SpillMap.clear(); |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | virtual const char *getPassName() const { |
| 110 | return "Pre-Register Allocaton Live Interval Splitting"; |
| 111 | } |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 112 | |
| 113 | /// print - Implement the dump method. |
| 114 | virtual void print(std::ostream &O, const Module* M = 0) const { |
| 115 | LIs->print(O, M); |
| 116 | } |
| 117 | |
| 118 | void print(std::ostream *O, const Module* M = 0) const { |
| 119 | if (O) print(*O, M); |
| 120 | } |
| 121 | |
| 122 | private: |
| 123 | MachineBasicBlock::iterator |
| 124 | findNextEmptySlot(MachineBasicBlock*, MachineInstr*, |
| 125 | unsigned&); |
| 126 | |
| 127 | MachineBasicBlock::iterator |
Evan Cheng | 1f08cc2 | 2008-10-28 05:28:21 +0000 | [diff] [blame] | 128 | findSpillPoint(MachineBasicBlock*, MachineInstr*, MachineInstr*, |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 129 | SmallPtrSet<MachineInstr*, 4>&, unsigned&); |
| 130 | |
| 131 | MachineBasicBlock::iterator |
Evan Cheng | f62ce37 | 2008-10-28 00:47:49 +0000 | [diff] [blame] | 132 | findRestorePoint(MachineBasicBlock*, MachineInstr*, unsigned, |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 133 | SmallPtrSet<MachineInstr*, 4>&, unsigned&); |
| 134 | |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 135 | int CreateSpillStackSlot(unsigned, const TargetRegisterClass *); |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 136 | |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 137 | bool IsAvailableInStack(MachineBasicBlock*, unsigned, unsigned, unsigned, |
| 138 | unsigned&, int&) const; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 139 | |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 140 | void UpdateSpillSlotInterval(VNInfo*, unsigned, unsigned); |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 141 | |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 142 | bool SplitRegLiveInterval(LiveInterval*); |
| 143 | |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 144 | bool SplitRegLiveIntervals(const TargetRegisterClass **, |
| 145 | SmallPtrSet<LiveInterval*, 8>&); |
Owen Anderson | f1f75b1 | 2008-11-04 22:22:41 +0000 | [diff] [blame] | 146 | |
| 147 | bool createsNewJoin(LiveRange* LR, MachineBasicBlock* DefMBB, |
| 148 | MachineBasicBlock* BarrierMBB); |
Owen Anderson | 75fa96b | 2008-11-19 04:28:29 +0000 | [diff] [blame] | 149 | bool Rematerialize(unsigned vreg, VNInfo* ValNo, |
| 150 | MachineInstr* DefMI, |
| 151 | MachineBasicBlock::iterator RestorePt, |
| 152 | unsigned RestoreIdx, |
| 153 | SmallPtrSet<MachineInstr*, 4>& RefsInMBB); |
Owen Anderson | 7b9d67c | 2008-12-02 18:53:47 +0000 | [diff] [blame] | 154 | MachineInstr* FoldSpill(unsigned vreg, const TargetRegisterClass* RC, |
| 155 | MachineInstr* DefMI, |
| 156 | MachineInstr* Barrier, |
| 157 | MachineBasicBlock* MBB, |
| 158 | int& SS, |
| 159 | SmallPtrSet<MachineInstr*, 4>& RefsInMBB); |
Owen Anderson | d0b6a0d | 2008-12-16 21:35:08 +0000 | [diff] [blame] | 160 | void RenumberValno(VNInfo* VN); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 161 | void ReconstructLiveInterval(LiveInterval* LI); |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 162 | bool removeDeadSpills(SmallPtrSet<LiveInterval*, 8>& split); |
Owen Anderson | 32ca865 | 2009-01-24 10:07:43 +0000 | [diff] [blame] | 163 | unsigned getNumberOfSpills(SmallPtrSet<MachineInstr*, 4>& MIs, |
| 164 | unsigned Reg, int FrameIndex); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 165 | VNInfo* PerformPHIConstruction(MachineBasicBlock::iterator use, |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 166 | MachineBasicBlock* MBB, |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 167 | LiveInterval* LI, |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 168 | SmallPtrSet<MachineInstr*, 4>& Visited, |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 169 | DenseMap<MachineBasicBlock*, SmallPtrSet<MachineInstr*, 2> >& Defs, |
| 170 | DenseMap<MachineBasicBlock*, SmallPtrSet<MachineInstr*, 2> >& Uses, |
| 171 | DenseMap<MachineInstr*, VNInfo*>& NewVNs, |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 172 | DenseMap<MachineBasicBlock*, VNInfo*>& LiveOut, |
| 173 | DenseMap<MachineBasicBlock*, VNInfo*>& Phis, |
| 174 | bool toplevel, bool intrablock); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 175 | }; |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 176 | } // end anonymous namespace |
| 177 | |
| 178 | char PreAllocSplitting::ID = 0; |
| 179 | |
| 180 | static RegisterPass<PreAllocSplitting> |
| 181 | X("pre-alloc-splitting", "Pre-Register Allocation Live Interval Splitting"); |
| 182 | |
| 183 | const PassInfo *const llvm::PreAllocSplittingID = &X; |
| 184 | |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 185 | |
| 186 | /// findNextEmptySlot - Find a gap after the given machine instruction in the |
| 187 | /// instruction index map. If there isn't one, return end(). |
| 188 | MachineBasicBlock::iterator |
| 189 | PreAllocSplitting::findNextEmptySlot(MachineBasicBlock *MBB, MachineInstr *MI, |
| 190 | unsigned &SpotIndex) { |
| 191 | MachineBasicBlock::iterator MII = MI; |
| 192 | if (++MII != MBB->end()) { |
| 193 | unsigned Index = LIs->findGapBeforeInstr(LIs->getInstructionIndex(MII)); |
| 194 | if (Index) { |
| 195 | SpotIndex = Index; |
| 196 | return MII; |
| 197 | } |
| 198 | } |
| 199 | return MBB->end(); |
| 200 | } |
| 201 | |
| 202 | /// findSpillPoint - Find a gap as far away from the given MI that's suitable |
| 203 | /// for spilling the current live interval. The index must be before any |
| 204 | /// defs and uses of the live interval register in the mbb. Return begin() if |
| 205 | /// none is found. |
| 206 | MachineBasicBlock::iterator |
| 207 | PreAllocSplitting::findSpillPoint(MachineBasicBlock *MBB, MachineInstr *MI, |
Evan Cheng | 1f08cc2 | 2008-10-28 05:28:21 +0000 | [diff] [blame] | 208 | MachineInstr *DefMI, |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 209 | SmallPtrSet<MachineInstr*, 4> &RefsInMBB, |
| 210 | unsigned &SpillIndex) { |
| 211 | MachineBasicBlock::iterator Pt = MBB->begin(); |
| 212 | |
| 213 | // Go top down if RefsInMBB is empty. |
Evan Cheng | 1f08cc2 | 2008-10-28 05:28:21 +0000 | [diff] [blame] | 214 | if (RefsInMBB.empty() && !DefMI) { |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 215 | MachineBasicBlock::iterator MII = MBB->begin(); |
| 216 | MachineBasicBlock::iterator EndPt = MI; |
| 217 | do { |
| 218 | ++MII; |
| 219 | unsigned Index = LIs->getInstructionIndex(MII); |
| 220 | unsigned Gap = LIs->findGapBeforeInstr(Index); |
| 221 | if (Gap) { |
| 222 | Pt = MII; |
| 223 | SpillIndex = Gap; |
| 224 | break; |
| 225 | } |
| 226 | } while (MII != EndPt); |
| 227 | } else { |
| 228 | MachineBasicBlock::iterator MII = MI; |
Evan Cheng | 1f08cc2 | 2008-10-28 05:28:21 +0000 | [diff] [blame] | 229 | MachineBasicBlock::iterator EndPt = DefMI |
| 230 | ? MachineBasicBlock::iterator(DefMI) : MBB->begin(); |
| 231 | while (MII != EndPt && !RefsInMBB.count(MII)) { |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 232 | unsigned Index = LIs->getInstructionIndex(MII); |
| 233 | if (LIs->hasGapBeforeInstr(Index)) { |
| 234 | Pt = MII; |
| 235 | SpillIndex = LIs->findGapBeforeInstr(Index, true); |
| 236 | } |
| 237 | --MII; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | return Pt; |
| 242 | } |
| 243 | |
| 244 | /// findRestorePoint - Find a gap in the instruction index map that's suitable |
| 245 | /// for restoring the current live interval value. The index must be before any |
| 246 | /// uses of the live interval register in the mbb. Return end() if none is |
| 247 | /// found. |
| 248 | MachineBasicBlock::iterator |
| 249 | PreAllocSplitting::findRestorePoint(MachineBasicBlock *MBB, MachineInstr *MI, |
Evan Cheng | f62ce37 | 2008-10-28 00:47:49 +0000 | [diff] [blame] | 250 | unsigned LastIdx, |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 251 | SmallPtrSet<MachineInstr*, 4> &RefsInMBB, |
| 252 | unsigned &RestoreIndex) { |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 253 | // FIXME: Allow spill to be inserted to the beginning of the mbb. Update mbb |
| 254 | // begin index accordingly. |
Owen Anderson | 5a92d4e | 2008-11-18 20:53:59 +0000 | [diff] [blame] | 255 | MachineBasicBlock::iterator Pt = MBB->end(); |
Evan Cheng | f62ce37 | 2008-10-28 00:47:49 +0000 | [diff] [blame] | 256 | unsigned EndIdx = LIs->getMBBEndIdx(MBB); |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 257 | |
Evan Cheng | f62ce37 | 2008-10-28 00:47:49 +0000 | [diff] [blame] | 258 | // Go bottom up if RefsInMBB is empty and the end of the mbb isn't beyond |
| 259 | // the last index in the live range. |
| 260 | if (RefsInMBB.empty() && LastIdx >= EndIdx) { |
Owen Anderson | 711fd3d | 2008-11-13 21:53:14 +0000 | [diff] [blame] | 261 | MachineBasicBlock::iterator MII = MBB->getFirstTerminator(); |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 262 | MachineBasicBlock::iterator EndPt = MI; |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 263 | --MII; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 264 | do { |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 265 | unsigned Index = LIs->getInstructionIndex(MII); |
Evan Cheng | 56ab0de | 2008-10-24 18:46:44 +0000 | [diff] [blame] | 266 | unsigned Gap = LIs->findGapBeforeInstr(Index); |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 267 | if (Gap) { |
| 268 | Pt = MII; |
| 269 | RestoreIndex = Gap; |
| 270 | break; |
| 271 | } |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 272 | --MII; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 273 | } while (MII != EndPt); |
| 274 | } else { |
| 275 | MachineBasicBlock::iterator MII = MI; |
| 276 | MII = ++MII; |
Evan Cheng | f62ce37 | 2008-10-28 00:47:49 +0000 | [diff] [blame] | 277 | // FIXME: Limit the number of instructions to examine to reduce |
| 278 | // compile time? |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 279 | while (MII != MBB->end()) { |
| 280 | unsigned Index = LIs->getInstructionIndex(MII); |
Evan Cheng | f62ce37 | 2008-10-28 00:47:49 +0000 | [diff] [blame] | 281 | if (Index > LastIdx) |
| 282 | break; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 283 | unsigned Gap = LIs->findGapBeforeInstr(Index); |
| 284 | if (Gap) { |
| 285 | Pt = MII; |
| 286 | RestoreIndex = Gap; |
| 287 | } |
| 288 | if (RefsInMBB.count(MII)) |
| 289 | break; |
| 290 | ++MII; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | return Pt; |
| 295 | } |
| 296 | |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 297 | /// CreateSpillStackSlot - Create a stack slot for the live interval being |
| 298 | /// split. If the live interval was previously split, just reuse the same |
| 299 | /// slot. |
| 300 | int PreAllocSplitting::CreateSpillStackSlot(unsigned Reg, |
| 301 | const TargetRegisterClass *RC) { |
| 302 | int SS; |
| 303 | DenseMap<unsigned, int>::iterator I = IntervalSSMap.find(Reg); |
| 304 | if (I != IntervalSSMap.end()) { |
| 305 | SS = I->second; |
| 306 | } else { |
| 307 | SS = MFI->CreateStackObject(RC->getSize(), RC->getAlignment()); |
| 308 | IntervalSSMap[Reg] = SS; |
Evan Cheng | 0658749 | 2008-10-24 02:05:00 +0000 | [diff] [blame] | 309 | } |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 310 | |
| 311 | // Create live interval for stack slot. |
| 312 | CurrSLI = &LSs->getOrCreateInterval(SS); |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 313 | if (CurrSLI->hasAtLeastOneValue()) |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 314 | CurrSValNo = CurrSLI->getValNumInfo(0); |
| 315 | else |
| 316 | CurrSValNo = CurrSLI->getNextValue(~0U, 0, LSs->getVNInfoAllocator()); |
| 317 | return SS; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 320 | /// IsAvailableInStack - Return true if register is available in a split stack |
| 321 | /// slot at the specified index. |
| 322 | bool |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 323 | PreAllocSplitting::IsAvailableInStack(MachineBasicBlock *DefMBB, |
| 324 | unsigned Reg, unsigned DefIndex, |
| 325 | unsigned RestoreIndex, unsigned &SpillIndex, |
| 326 | int& SS) const { |
| 327 | if (!DefMBB) |
| 328 | return false; |
| 329 | |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 330 | DenseMap<unsigned, int>::iterator I = IntervalSSMap.find(Reg); |
| 331 | if (I == IntervalSSMap.end()) |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 332 | return false; |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 333 | DenseMap<unsigned, unsigned>::iterator II = Def2SpillMap.find(DefIndex); |
| 334 | if (II == Def2SpillMap.end()) |
| 335 | return false; |
| 336 | |
| 337 | // If last spill of def is in the same mbb as barrier mbb (where restore will |
| 338 | // be), make sure it's not below the intended restore index. |
| 339 | // FIXME: Undo the previous spill? |
| 340 | assert(LIs->getMBBFromIndex(II->second) == DefMBB); |
| 341 | if (DefMBB == BarrierMBB && II->second >= RestoreIndex) |
| 342 | return false; |
| 343 | |
| 344 | SS = I->second; |
| 345 | SpillIndex = II->second; |
| 346 | return true; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 349 | /// UpdateSpillSlotInterval - Given the specified val# of the register live |
| 350 | /// interval being split, and the spill and restore indicies, update the live |
| 351 | /// interval of the spill stack slot. |
| 352 | void |
| 353 | PreAllocSplitting::UpdateSpillSlotInterval(VNInfo *ValNo, unsigned SpillIndex, |
| 354 | unsigned RestoreIndex) { |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 355 | assert(LIs->getMBBFromIndex(RestoreIndex) == BarrierMBB && |
| 356 | "Expect restore in the barrier mbb"); |
| 357 | |
| 358 | MachineBasicBlock *MBB = LIs->getMBBFromIndex(SpillIndex); |
| 359 | if (MBB == BarrierMBB) { |
| 360 | // Intra-block spill + restore. We are done. |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 361 | LiveRange SLR(SpillIndex, RestoreIndex, CurrSValNo); |
| 362 | CurrSLI->addRange(SLR); |
| 363 | return; |
| 364 | } |
| 365 | |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 366 | SmallPtrSet<MachineBasicBlock*, 4> Processed; |
| 367 | unsigned EndIdx = LIs->getMBBEndIdx(MBB); |
| 368 | LiveRange SLR(SpillIndex, EndIdx+1, CurrSValNo); |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 369 | CurrSLI->addRange(SLR); |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 370 | Processed.insert(MBB); |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 371 | |
| 372 | // Start from the spill mbb, figure out the extend of the spill slot's |
| 373 | // live interval. |
| 374 | SmallVector<MachineBasicBlock*, 4> WorkList; |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 375 | const LiveRange *LR = CurrLI->getLiveRangeContaining(SpillIndex); |
| 376 | if (LR->end > EndIdx) |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 377 | // If live range extend beyond end of mbb, add successors to work list. |
| 378 | for (MachineBasicBlock::succ_iterator SI = MBB->succ_begin(), |
| 379 | SE = MBB->succ_end(); SI != SE; ++SI) |
| 380 | WorkList.push_back(*SI); |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 381 | |
| 382 | while (!WorkList.empty()) { |
| 383 | MachineBasicBlock *MBB = WorkList.back(); |
| 384 | WorkList.pop_back(); |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 385 | if (Processed.count(MBB)) |
| 386 | continue; |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 387 | unsigned Idx = LIs->getMBBStartIdx(MBB); |
| 388 | LR = CurrLI->getLiveRangeContaining(Idx); |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 389 | if (LR && LR->valno == ValNo) { |
| 390 | EndIdx = LIs->getMBBEndIdx(MBB); |
| 391 | if (Idx <= RestoreIndex && RestoreIndex < EndIdx) { |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 392 | // Spill slot live interval stops at the restore. |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 393 | LiveRange SLR(Idx, RestoreIndex, CurrSValNo); |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 394 | CurrSLI->addRange(SLR); |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 395 | } else if (LR->end > EndIdx) { |
| 396 | // Live range extends beyond end of mbb, process successors. |
| 397 | LiveRange SLR(Idx, EndIdx+1, CurrSValNo); |
| 398 | CurrSLI->addRange(SLR); |
| 399 | for (MachineBasicBlock::succ_iterator SI = MBB->succ_begin(), |
| 400 | SE = MBB->succ_end(); SI != SE; ++SI) |
| 401 | WorkList.push_back(*SI); |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 402 | } else { |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 403 | LiveRange SLR(Idx, LR->end, CurrSValNo); |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 404 | CurrSLI->addRange(SLR); |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 405 | } |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 406 | Processed.insert(MBB); |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 411 | /// PerformPHIConstruction - From properly set up use and def lists, use a PHI |
| 412 | /// construction algorithm to compute the ranges and valnos for an interval. |
| 413 | VNInfo* PreAllocSplitting::PerformPHIConstruction( |
| 414 | MachineBasicBlock::iterator use, |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 415 | MachineBasicBlock* MBB, |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 416 | LiveInterval* LI, |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 417 | SmallPtrSet<MachineInstr*, 4>& Visited, |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 418 | DenseMap<MachineBasicBlock*, SmallPtrSet<MachineInstr*, 2> >& Defs, |
| 419 | DenseMap<MachineBasicBlock*, SmallPtrSet<MachineInstr*, 2> >& Uses, |
| 420 | DenseMap<MachineInstr*, VNInfo*>& NewVNs, |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 421 | DenseMap<MachineBasicBlock*, VNInfo*>& LiveOut, |
| 422 | DenseMap<MachineBasicBlock*, VNInfo*>& Phis, |
| 423 | bool toplevel, bool intrablock) { |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 424 | // Return memoized result if it's available. |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 425 | if (toplevel && Visited.count(use) && NewVNs.count(use)) |
| 426 | return NewVNs[use]; |
| 427 | else if (!toplevel && intrablock && NewVNs.count(use)) |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 428 | return NewVNs[use]; |
| 429 | else if (!intrablock && LiveOut.count(MBB)) |
| 430 | return LiveOut[MBB]; |
| 431 | |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 432 | typedef DenseMap<MachineBasicBlock*, SmallPtrSet<MachineInstr*, 2> > RegMap; |
| 433 | |
| 434 | // Check if our block contains any uses or defs. |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 435 | bool ContainsDefs = Defs.count(MBB); |
| 436 | bool ContainsUses = Uses.count(MBB); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 437 | |
| 438 | VNInfo* ret = 0; |
| 439 | |
| 440 | // Enumerate the cases of use/def contaning blocks. |
| 441 | if (!ContainsDefs && !ContainsUses) { |
| 442 | Fallback: |
| 443 | // NOTE: Because this is the fallback case from other cases, we do NOT |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 444 | // assume that we are not intrablock here. |
| 445 | if (Phis.count(MBB)) return Phis[MBB]; |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 446 | |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 447 | unsigned StartIndex = LIs->getMBBStartIdx(MBB); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 448 | |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 449 | if (MBB->pred_size() == 1) { |
| 450 | Phis[MBB] = ret = PerformPHIConstruction((*MBB->pred_begin())->end(), |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 451 | *(MBB->pred_begin()), LI, Visited, |
| 452 | Defs, Uses, NewVNs, LiveOut, Phis, |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 453 | false, false); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 454 | unsigned EndIndex = 0; |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 455 | if (intrablock) { |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 456 | EndIndex = LIs->getInstructionIndex(use); |
| 457 | EndIndex = LiveIntervals::getUseIndex(EndIndex); |
| 458 | } else |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 459 | EndIndex = LIs->getMBBEndIdx(MBB); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 460 | |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 461 | LI->addRange(LiveRange(StartIndex, EndIndex+1, ret)); |
Owen Anderson | e1762c9 | 2009-01-12 03:10:40 +0000 | [diff] [blame] | 462 | if (intrablock) |
| 463 | LI->addKill(ret, EndIndex); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 464 | } else { |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 465 | Phis[MBB] = ret = LI->getNextValue(~0U, /*FIXME*/ 0, |
| 466 | LIs->getVNInfoAllocator()); |
| 467 | if (!intrablock) LiveOut[MBB] = ret; |
| 468 | |
| 469 | // If there are no uses or defs between our starting point and the |
| 470 | // beginning of the block, then recursive perform phi construction |
| 471 | // on our predecessors. |
| 472 | DenseMap<MachineBasicBlock*, VNInfo*> IncomingVNs; |
| 473 | for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(), |
| 474 | PE = MBB->pred_end(); PI != PE; ++PI) { |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 475 | VNInfo* Incoming = PerformPHIConstruction((*PI)->end(), *PI, LI, |
| 476 | Visited, Defs, Uses, NewVNs, |
| 477 | LiveOut, Phis, false, false); |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 478 | if (Incoming != 0) |
| 479 | IncomingVNs[*PI] = Incoming; |
| 480 | } |
| 481 | |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 482 | // Otherwise, merge the incoming VNInfos with a phi join. Create a new |
| 483 | // VNInfo to represent the joined value. |
| 484 | for (DenseMap<MachineBasicBlock*, VNInfo*>::iterator I = |
| 485 | IncomingVNs.begin(), E = IncomingVNs.end(); I != E; ++I) { |
| 486 | I->second->hasPHIKill = true; |
| 487 | unsigned KillIndex = LIs->getMBBEndIdx(I->first); |
| 488 | LI->addKill(I->second, KillIndex); |
| 489 | } |
| 490 | |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 491 | unsigned EndIndex = 0; |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 492 | if (intrablock) { |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 493 | EndIndex = LIs->getInstructionIndex(use); |
| 494 | EndIndex = LiveIntervals::getUseIndex(EndIndex); |
| 495 | } else |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 496 | EndIndex = LIs->getMBBEndIdx(MBB); |
| 497 | LI->addRange(LiveRange(StartIndex, EndIndex+1, ret)); |
Owen Anderson | e1762c9 | 2009-01-12 03:10:40 +0000 | [diff] [blame] | 498 | if (intrablock) |
| 499 | LI->addKill(ret, EndIndex); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 500 | } |
| 501 | } else if (ContainsDefs && !ContainsUses) { |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 502 | SmallPtrSet<MachineInstr*, 2>& BlockDefs = Defs[MBB]; |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 503 | |
| 504 | // Search for the def in this block. If we don't find it before the |
| 505 | // instruction we care about, go to the fallback case. Note that that |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 506 | // should never happen: this cannot be intrablock, so use should |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 507 | // always be an end() iterator. |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 508 | assert(use == MBB->end() && "No use marked in intrablock"); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 509 | |
| 510 | MachineBasicBlock::iterator walker = use; |
| 511 | --walker; |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 512 | while (walker != MBB->begin()) |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 513 | if (BlockDefs.count(walker)) { |
| 514 | break; |
| 515 | } else |
| 516 | --walker; |
| 517 | |
| 518 | // Once we've found it, extend its VNInfo to our instruction. |
| 519 | unsigned DefIndex = LIs->getInstructionIndex(walker); |
| 520 | DefIndex = LiveIntervals::getDefIndex(DefIndex); |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 521 | unsigned EndIndex = LIs->getMBBEndIdx(MBB); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 522 | |
| 523 | ret = NewVNs[walker]; |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 524 | LI->addRange(LiveRange(DefIndex, EndIndex+1, ret)); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 525 | } else if (!ContainsDefs && ContainsUses) { |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 526 | SmallPtrSet<MachineInstr*, 2>& BlockUses = Uses[MBB]; |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 527 | |
| 528 | // Search for the use in this block that precedes the instruction we care |
| 529 | // about, going to the fallback case if we don't find it. |
| 530 | |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 531 | if (use == MBB->begin()) |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 532 | goto Fallback; |
| 533 | |
| 534 | MachineBasicBlock::iterator walker = use; |
| 535 | --walker; |
| 536 | bool found = false; |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 537 | while (walker != MBB->begin()) |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 538 | if (BlockUses.count(walker)) { |
| 539 | found = true; |
| 540 | break; |
| 541 | } else |
| 542 | --walker; |
| 543 | |
| 544 | // Must check begin() too. |
Duncan Sands | 2b7fc1e | 2008-12-29 08:05:02 +0000 | [diff] [blame] | 545 | if (!found) { |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 546 | if (BlockUses.count(walker)) |
| 547 | found = true; |
| 548 | else |
| 549 | goto Fallback; |
Duncan Sands | 2b7fc1e | 2008-12-29 08:05:02 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 552 | unsigned UseIndex = LIs->getInstructionIndex(walker); |
| 553 | UseIndex = LiveIntervals::getUseIndex(UseIndex); |
| 554 | unsigned EndIndex = 0; |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 555 | if (intrablock) { |
| 556 | EndIndex = LIs->getInstructionIndex(use); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 557 | EndIndex = LiveIntervals::getUseIndex(EndIndex); |
| 558 | } else |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 559 | EndIndex = LIs->getMBBEndIdx(MBB); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 560 | |
| 561 | // Now, recursively phi construct the VNInfo for the use we found, |
| 562 | // and then extend it to include the instruction we care about |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 563 | ret = PerformPHIConstruction(walker, MBB, LI, Visited, Defs, Uses, |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 564 | NewVNs, LiveOut, Phis, false, true); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 565 | |
Owen Anderson | b4b8436 | 2009-01-26 21:57:31 +0000 | [diff] [blame] | 566 | LI->addRange(LiveRange(UseIndex, EndIndex+1, ret)); |
| 567 | |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 568 | // FIXME: Need to set kills properly for inter-block stuff. |
Owen Anderson | d4f6fe5 | 2008-12-28 23:35:13 +0000 | [diff] [blame] | 569 | if (LI->isKill(ret, UseIndex)) LI->removeKill(ret, UseIndex); |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 570 | if (intrablock) |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 571 | LI->addKill(ret, EndIndex); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 572 | } else if (ContainsDefs && ContainsUses){ |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 573 | SmallPtrSet<MachineInstr*, 2>& BlockDefs = Defs[MBB]; |
| 574 | SmallPtrSet<MachineInstr*, 2>& BlockUses = Uses[MBB]; |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 575 | |
| 576 | // This case is basically a merging of the two preceding case, with the |
| 577 | // special note that checking for defs must take precedence over checking |
| 578 | // for uses, because of two-address instructions. |
| 579 | |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 580 | if (use == MBB->begin()) |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 581 | goto Fallback; |
| 582 | |
| 583 | MachineBasicBlock::iterator walker = use; |
| 584 | --walker; |
| 585 | bool foundDef = false; |
| 586 | bool foundUse = false; |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 587 | while (walker != MBB->begin()) |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 588 | if (BlockDefs.count(walker)) { |
| 589 | foundDef = true; |
| 590 | break; |
| 591 | } else if (BlockUses.count(walker)) { |
| 592 | foundUse = true; |
| 593 | break; |
| 594 | } else |
| 595 | --walker; |
| 596 | |
| 597 | // Must check begin() too. |
Duncan Sands | 2b7fc1e | 2008-12-29 08:05:02 +0000 | [diff] [blame] | 598 | if (!foundDef && !foundUse) { |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 599 | if (BlockDefs.count(walker)) |
| 600 | foundDef = true; |
| 601 | else if (BlockUses.count(walker)) |
| 602 | foundUse = true; |
| 603 | else |
| 604 | goto Fallback; |
Duncan Sands | 2b7fc1e | 2008-12-29 08:05:02 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 607 | unsigned StartIndex = LIs->getInstructionIndex(walker); |
| 608 | StartIndex = foundDef ? LiveIntervals::getDefIndex(StartIndex) : |
| 609 | LiveIntervals::getUseIndex(StartIndex); |
| 610 | unsigned EndIndex = 0; |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 611 | if (intrablock) { |
| 612 | EndIndex = LIs->getInstructionIndex(use); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 613 | EndIndex = LiveIntervals::getUseIndex(EndIndex); |
| 614 | } else |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 615 | EndIndex = LIs->getMBBEndIdx(MBB); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 616 | |
| 617 | if (foundDef) |
| 618 | ret = NewVNs[walker]; |
| 619 | else |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 620 | ret = PerformPHIConstruction(walker, MBB, LI, Visited, Defs, Uses, |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 621 | NewVNs, LiveOut, Phis, false, true); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 622 | |
Owen Anderson | b4b8436 | 2009-01-26 21:57:31 +0000 | [diff] [blame] | 623 | LI->addRange(LiveRange(StartIndex, EndIndex+1, ret)); |
| 624 | |
Owen Anderson | d4f6fe5 | 2008-12-28 23:35:13 +0000 | [diff] [blame] | 625 | if (foundUse && LI->isKill(ret, StartIndex)) |
| 626 | LI->removeKill(ret, StartIndex); |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 627 | if (intrablock) { |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 628 | LI->addKill(ret, EndIndex); |
| 629 | } |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | // Memoize results so we don't have to recompute them. |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 633 | if (!intrablock) LiveOut[MBB] = ret; |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 634 | else { |
Owen Anderson | e1762c9 | 2009-01-12 03:10:40 +0000 | [diff] [blame] | 635 | if (!NewVNs.count(use)) |
| 636 | NewVNs[use] = ret; |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 637 | Visited.insert(use); |
| 638 | } |
| 639 | |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 640 | return ret; |
| 641 | } |
| 642 | |
| 643 | /// ReconstructLiveInterval - Recompute a live interval from scratch. |
| 644 | void PreAllocSplitting::ReconstructLiveInterval(LiveInterval* LI) { |
| 645 | BumpPtrAllocator& Alloc = LIs->getVNInfoAllocator(); |
| 646 | |
| 647 | // Clear the old ranges and valnos; |
| 648 | LI->clear(); |
| 649 | |
| 650 | // Cache the uses and defs of the register |
| 651 | typedef DenseMap<MachineBasicBlock*, SmallPtrSet<MachineInstr*, 2> > RegMap; |
| 652 | RegMap Defs, Uses; |
| 653 | |
| 654 | // Keep track of the new VNs we're creating. |
| 655 | DenseMap<MachineInstr*, VNInfo*> NewVNs; |
| 656 | SmallPtrSet<VNInfo*, 2> PhiVNs; |
| 657 | |
| 658 | // Cache defs, and create a new VNInfo for each def. |
| 659 | for (MachineRegisterInfo::def_iterator DI = MRI->def_begin(LI->reg), |
| 660 | DE = MRI->def_end(); DI != DE; ++DI) { |
| 661 | Defs[(*DI).getParent()].insert(&*DI); |
| 662 | |
| 663 | unsigned DefIdx = LIs->getInstructionIndex(&*DI); |
| 664 | DefIdx = LiveIntervals::getDefIndex(DefIdx); |
| 665 | |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 666 | VNInfo* NewVN = LI->getNextValue(DefIdx, 0, Alloc); |
| 667 | |
| 668 | // If the def is a move, set the copy field. |
Evan Cheng | 04ee5a1 | 2009-01-20 19:12:24 +0000 | [diff] [blame] | 669 | unsigned SrcReg, DstReg, SrcSubIdx, DstSubIdx; |
| 670 | if (TII->isMoveInstr(*DI, SrcReg, DstReg, SrcSubIdx, DstSubIdx)) |
| 671 | if (DstReg == LI->reg) |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 672 | NewVN->copy = &*DI; |
| 673 | |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 674 | NewVNs[&*DI] = NewVN; |
| 675 | } |
| 676 | |
| 677 | // Cache uses as a separate pass from actually processing them. |
| 678 | for (MachineRegisterInfo::use_iterator UI = MRI->use_begin(LI->reg), |
| 679 | UE = MRI->use_end(); UI != UE; ++UI) |
| 680 | Uses[(*UI).getParent()].insert(&*UI); |
| 681 | |
| 682 | // Now, actually process every use and use a phi construction algorithm |
| 683 | // to walk from it to its reaching definitions, building VNInfos along |
| 684 | // the way. |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 685 | DenseMap<MachineBasicBlock*, VNInfo*> LiveOut; |
| 686 | DenseMap<MachineBasicBlock*, VNInfo*> Phis; |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 687 | SmallPtrSet<MachineInstr*, 4> Visited; |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 688 | for (MachineRegisterInfo::use_iterator UI = MRI->use_begin(LI->reg), |
| 689 | UE = MRI->use_end(); UI != UE; ++UI) { |
Owen Anderson | 200ee7f | 2009-01-06 07:53:32 +0000 | [diff] [blame] | 690 | PerformPHIConstruction(&*UI, UI->getParent(), LI, Visited, Defs, |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 691 | Uses, NewVNs, LiveOut, Phis, true, true); |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 692 | } |
Owen Anderson | d4f6fe5 | 2008-12-28 23:35:13 +0000 | [diff] [blame] | 693 | |
| 694 | // Add ranges for dead defs |
| 695 | for (MachineRegisterInfo::def_iterator DI = MRI->def_begin(LI->reg), |
| 696 | DE = MRI->def_end(); DI != DE; ++DI) { |
| 697 | unsigned DefIdx = LIs->getInstructionIndex(&*DI); |
| 698 | DefIdx = LiveIntervals::getDefIndex(DefIdx); |
Owen Anderson | d4f6fe5 | 2008-12-28 23:35:13 +0000 | [diff] [blame] | 699 | |
| 700 | if (LI->liveAt(DefIdx)) continue; |
| 701 | |
| 702 | VNInfo* DeadVN = NewVNs[&*DI]; |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 703 | LI->addRange(LiveRange(DefIdx, DefIdx+1, DeadVN)); |
Owen Anderson | d4f6fe5 | 2008-12-28 23:35:13 +0000 | [diff] [blame] | 704 | LI->addKill(DeadVN, DefIdx); |
| 705 | } |
Owen Anderson | 60d4f6d | 2008-12-28 21:48:48 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Owen Anderson | d0b6a0d | 2008-12-16 21:35:08 +0000 | [diff] [blame] | 708 | /// RenumberValno - Split the given valno out into a new vreg, allowing it to |
| 709 | /// be allocated to a different register. This function creates a new vreg, |
| 710 | /// copies the valno and its live ranges over to the new vreg's interval, |
| 711 | /// removes them from the old interval, and rewrites all uses and defs of |
| 712 | /// the original reg to the new vreg within those ranges. |
| 713 | void PreAllocSplitting::RenumberValno(VNInfo* VN) { |
Owen Anderson | 2ebf63f | 2008-12-18 01:27:19 +0000 | [diff] [blame] | 714 | SmallVector<VNInfo*, 4> Stack; |
| 715 | SmallVector<VNInfo*, 4> VNsToCopy; |
| 716 | Stack.push_back(VN); |
| 717 | |
| 718 | // Walk through and copy the valno we care about, and any other valnos |
| 719 | // that are two-address redefinitions of the one we care about. These |
| 720 | // will need to be rewritten as well. We also check for safety of the |
| 721 | // renumbering here, by making sure that none of the valno involved has |
| 722 | // phi kills. |
| 723 | while (!Stack.empty()) { |
| 724 | VNInfo* OldVN = Stack.back(); |
| 725 | Stack.pop_back(); |
| 726 | |
| 727 | // Bail out if we ever encounter a valno that has a PHI kill. We can't |
| 728 | // renumber these. |
| 729 | if (OldVN->hasPHIKill) return; |
| 730 | |
| 731 | VNsToCopy.push_back(OldVN); |
| 732 | |
| 733 | // Locate two-address redefinitions |
| 734 | for (SmallVector<unsigned, 4>::iterator KI = OldVN->kills.begin(), |
| 735 | KE = OldVN->kills.end(); KI != KE; ++KI) { |
| 736 | MachineInstr* MI = LIs->getInstructionFromIndex(*KI); |
Owen Anderson | 2ebf63f | 2008-12-18 01:27:19 +0000 | [diff] [blame] | 737 | unsigned DefIdx = MI->findRegisterDefOperandIdx(CurrLI->reg); |
| 738 | if (DefIdx == ~0U) continue; |
| 739 | if (MI->isRegReDefinedByTwoAddr(DefIdx)) { |
| 740 | VNInfo* NextVN = |
| 741 | CurrLI->findDefinedVNInfo(LiveIntervals::getDefIndex(*KI)); |
Owen Anderson | b4b8436 | 2009-01-26 21:57:31 +0000 | [diff] [blame] | 742 | if (NextVN == OldVN) continue; |
Owen Anderson | 2ebf63f | 2008-12-18 01:27:19 +0000 | [diff] [blame] | 743 | Stack.push_back(NextVN); |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
Owen Anderson | d0b6a0d | 2008-12-16 21:35:08 +0000 | [diff] [blame] | 748 | // Create the new vreg |
| 749 | unsigned NewVReg = MRI->createVirtualRegister(MRI->getRegClass(CurrLI->reg)); |
| 750 | |
Owen Anderson | 2ebf63f | 2008-12-18 01:27:19 +0000 | [diff] [blame] | 751 | // Create the new live interval |
Owen Anderson | d0b6a0d | 2008-12-16 21:35:08 +0000 | [diff] [blame] | 752 | LiveInterval& NewLI = LIs->getOrCreateInterval(NewVReg); |
Owen Anderson | d0b6a0d | 2008-12-16 21:35:08 +0000 | [diff] [blame] | 753 | |
Owen Anderson | 2ebf63f | 2008-12-18 01:27:19 +0000 | [diff] [blame] | 754 | for (SmallVector<VNInfo*, 4>::iterator OI = VNsToCopy.begin(), OE = |
| 755 | VNsToCopy.end(); OI != OE; ++OI) { |
| 756 | VNInfo* OldVN = *OI; |
| 757 | |
| 758 | // Copy the valno over |
| 759 | VNInfo* NewVN = NewLI.getNextValue(OldVN->def, OldVN->copy, |
| 760 | LIs->getVNInfoAllocator()); |
| 761 | NewLI.copyValNumInfo(NewVN, OldVN); |
| 762 | NewLI.MergeValueInAsValue(*CurrLI, OldVN, NewVN); |
| 763 | |
| 764 | // Remove the valno from the old interval |
| 765 | CurrLI->removeValNo(OldVN); |
| 766 | } |
Owen Anderson | d0b6a0d | 2008-12-16 21:35:08 +0000 | [diff] [blame] | 767 | |
| 768 | // Rewrite defs and uses. This is done in two stages to avoid invalidating |
| 769 | // the reg_iterator. |
| 770 | SmallVector<std::pair<MachineInstr*, unsigned>, 8> OpsToChange; |
| 771 | |
| 772 | for (MachineRegisterInfo::reg_iterator I = MRI->reg_begin(CurrLI->reg), |
| 773 | E = MRI->reg_end(); I != E; ++I) { |
| 774 | MachineOperand& MO = I.getOperand(); |
| 775 | unsigned InstrIdx = LIs->getInstructionIndex(&*I); |
| 776 | |
| 777 | if ((MO.isUse() && NewLI.liveAt(LiveIntervals::getUseIndex(InstrIdx))) || |
| 778 | (MO.isDef() && NewLI.liveAt(LiveIntervals::getDefIndex(InstrIdx)))) |
| 779 | OpsToChange.push_back(std::make_pair(&*I, I.getOperandNo())); |
| 780 | } |
| 781 | |
| 782 | for (SmallVector<std::pair<MachineInstr*, unsigned>, 8>::iterator I = |
| 783 | OpsToChange.begin(), E = OpsToChange.end(); I != E; ++I) { |
| 784 | MachineInstr* Inst = I->first; |
| 785 | unsigned OpIdx = I->second; |
| 786 | MachineOperand& MO = Inst->getOperand(OpIdx); |
| 787 | MO.setReg(NewVReg); |
| 788 | } |
Owen Anderson | 2ebf63f | 2008-12-18 01:27:19 +0000 | [diff] [blame] | 789 | |
| 790 | NumRenumbers++; |
Owen Anderson | d0b6a0d | 2008-12-16 21:35:08 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Owen Anderson | 6002e99 | 2008-12-04 21:20:30 +0000 | [diff] [blame] | 793 | bool PreAllocSplitting::Rematerialize(unsigned vreg, VNInfo* ValNo, |
| 794 | MachineInstr* DefMI, |
| 795 | MachineBasicBlock::iterator RestorePt, |
| 796 | unsigned RestoreIdx, |
| 797 | SmallPtrSet<MachineInstr*, 4>& RefsInMBB) { |
| 798 | MachineBasicBlock& MBB = *RestorePt->getParent(); |
| 799 | |
| 800 | MachineBasicBlock::iterator KillPt = BarrierMBB->end(); |
| 801 | unsigned KillIdx = 0; |
| 802 | if (ValNo->def == ~0U || DefMI->getParent() == BarrierMBB) |
| 803 | KillPt = findSpillPoint(BarrierMBB, Barrier, NULL, RefsInMBB, KillIdx); |
| 804 | else |
| 805 | KillPt = findNextEmptySlot(DefMI->getParent(), DefMI, KillIdx); |
| 806 | |
| 807 | if (KillPt == DefMI->getParent()->end()) |
| 808 | return false; |
| 809 | |
| 810 | TII->reMaterialize(MBB, RestorePt, vreg, DefMI); |
| 811 | LIs->InsertMachineInstrInMaps(prior(RestorePt), RestoreIdx); |
| 812 | |
Owen Anderson | b4b8436 | 2009-01-26 21:57:31 +0000 | [diff] [blame] | 813 | ReconstructLiveInterval(CurrLI); |
| 814 | unsigned RematIdx = LIs->getInstructionIndex(prior(RestorePt)); |
| 815 | RematIdx = LiveIntervals::getDefIndex(RematIdx); |
| 816 | RenumberValno(CurrLI->findDefinedVNInfo(RematIdx)); |
Owen Anderson | e1762c9 | 2009-01-12 03:10:40 +0000 | [diff] [blame] | 817 | |
Owen Anderson | 75fa96b | 2008-11-19 04:28:29 +0000 | [diff] [blame] | 818 | ++NumSplits; |
| 819 | ++NumRemats; |
Owen Anderson | 7b9d67c | 2008-12-02 18:53:47 +0000 | [diff] [blame] | 820 | return true; |
| 821 | } |
| 822 | |
| 823 | MachineInstr* PreAllocSplitting::FoldSpill(unsigned vreg, |
| 824 | const TargetRegisterClass* RC, |
| 825 | MachineInstr* DefMI, |
| 826 | MachineInstr* Barrier, |
| 827 | MachineBasicBlock* MBB, |
| 828 | int& SS, |
| 829 | SmallPtrSet<MachineInstr*, 4>& RefsInMBB) { |
| 830 | MachineBasicBlock::iterator Pt = MBB->begin(); |
| 831 | |
| 832 | // Go top down if RefsInMBB is empty. |
| 833 | if (RefsInMBB.empty()) |
| 834 | return 0; |
Owen Anderson | 75fa96b | 2008-11-19 04:28:29 +0000 | [diff] [blame] | 835 | |
Owen Anderson | 7b9d67c | 2008-12-02 18:53:47 +0000 | [diff] [blame] | 836 | MachineBasicBlock::iterator FoldPt = Barrier; |
| 837 | while (&*FoldPt != DefMI && FoldPt != MBB->begin() && |
| 838 | !RefsInMBB.count(FoldPt)) |
| 839 | --FoldPt; |
| 840 | |
| 841 | int OpIdx = FoldPt->findRegisterDefOperandIdx(vreg, false); |
| 842 | if (OpIdx == -1) |
| 843 | return 0; |
| 844 | |
| 845 | SmallVector<unsigned, 1> Ops; |
| 846 | Ops.push_back(OpIdx); |
| 847 | |
| 848 | if (!TII->canFoldMemoryOperand(FoldPt, Ops)) |
| 849 | return 0; |
| 850 | |
| 851 | DenseMap<unsigned, int>::iterator I = IntervalSSMap.find(vreg); |
| 852 | if (I != IntervalSSMap.end()) { |
| 853 | SS = I->second; |
| 854 | } else { |
| 855 | SS = MFI->CreateStackObject(RC->getSize(), RC->getAlignment()); |
| 856 | |
| 857 | } |
| 858 | |
| 859 | MachineInstr* FMI = TII->foldMemoryOperand(*MBB->getParent(), |
| 860 | FoldPt, Ops, SS); |
| 861 | |
| 862 | if (FMI) { |
| 863 | LIs->ReplaceMachineInstrInMaps(FoldPt, FMI); |
| 864 | FMI = MBB->insert(MBB->erase(FoldPt), FMI); |
| 865 | ++NumFolds; |
| 866 | |
| 867 | IntervalSSMap[vreg] = SS; |
| 868 | CurrSLI = &LSs->getOrCreateInterval(SS); |
| 869 | if (CurrSLI->hasAtLeastOneValue()) |
| 870 | CurrSValNo = CurrSLI->getValNumInfo(0); |
| 871 | else |
| 872 | CurrSValNo = CurrSLI->getNextValue(~0U, 0, LSs->getVNInfoAllocator()); |
| 873 | } |
| 874 | |
| 875 | return FMI; |
Owen Anderson | 75fa96b | 2008-11-19 04:28:29 +0000 | [diff] [blame] | 876 | } |
| 877 | |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 878 | /// SplitRegLiveInterval - Split (spill and restore) the given live interval |
| 879 | /// so it would not cross the barrier that's being processed. Shrink wrap |
| 880 | /// (minimize) the live interval to the last uses. |
| 881 | bool PreAllocSplitting::SplitRegLiveInterval(LiveInterval *LI) { |
| 882 | CurrLI = LI; |
| 883 | |
| 884 | // Find live range where current interval cross the barrier. |
| 885 | LiveInterval::iterator LR = |
| 886 | CurrLI->FindLiveRangeContaining(LIs->getUseIndex(BarrierIdx)); |
| 887 | VNInfo *ValNo = LR->valno; |
| 888 | |
| 889 | if (ValNo->def == ~1U) { |
| 890 | // Defined by a dead def? How can this be? |
| 891 | assert(0 && "Val# is defined by a dead def?"); |
| 892 | abort(); |
| 893 | } |
| 894 | |
Evan Cheng | 0658749 | 2008-10-24 02:05:00 +0000 | [diff] [blame] | 895 | MachineInstr *DefMI = (ValNo->def != ~0U) |
| 896 | ? LIs->getInstructionFromIndex(ValNo->def) : NULL; |
Evan Cheng | 0658749 | 2008-10-24 02:05:00 +0000 | [diff] [blame] | 897 | |
Owen Anderson | d3be462 | 2009-01-21 08:18:03 +0000 | [diff] [blame] | 898 | // If this would create a new join point, do not split. |
| 899 | if (DefMI && createsNewJoin(LR, DefMI->getParent(), Barrier->getParent())) |
| 900 | return false; |
| 901 | |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 902 | // Find all references in the barrier mbb. |
| 903 | SmallPtrSet<MachineInstr*, 4> RefsInMBB; |
| 904 | for (MachineRegisterInfo::reg_iterator I = MRI->reg_begin(CurrLI->reg), |
| 905 | E = MRI->reg_end(); I != E; ++I) { |
| 906 | MachineInstr *RefMI = &*I; |
| 907 | if (RefMI->getParent() == BarrierMBB) |
| 908 | RefsInMBB.insert(RefMI); |
| 909 | } |
| 910 | |
| 911 | // Find a point to restore the value after the barrier. |
Evan Cheng | b964f33 | 2009-01-26 18:33:51 +0000 | [diff] [blame] | 912 | unsigned RestoreIndex = 0; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 913 | MachineBasicBlock::iterator RestorePt = |
Evan Cheng | f62ce37 | 2008-10-28 00:47:49 +0000 | [diff] [blame] | 914 | findRestorePoint(BarrierMBB, Barrier, LR->end, RefsInMBB, RestoreIndex); |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 915 | if (RestorePt == BarrierMBB->end()) |
| 916 | return false; |
| 917 | |
Owen Anderson | 75fa96b | 2008-11-19 04:28:29 +0000 | [diff] [blame] | 918 | if (DefMI && LIs->isReMaterializable(*LI, ValNo, DefMI)) |
| 919 | if (Rematerialize(LI->reg, ValNo, DefMI, RestorePt, |
| 920 | RestoreIndex, RefsInMBB)) |
| 921 | return true; |
| 922 | |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 923 | // Add a spill either before the barrier or after the definition. |
Evan Cheng | 0658749 | 2008-10-24 02:05:00 +0000 | [diff] [blame] | 924 | MachineBasicBlock *DefMBB = DefMI ? DefMI->getParent() : NULL; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 925 | const TargetRegisterClass *RC = MRI->getRegClass(CurrLI->reg); |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 926 | unsigned SpillIndex = 0; |
Evan Cheng | 0658749 | 2008-10-24 02:05:00 +0000 | [diff] [blame] | 927 | MachineInstr *SpillMI = NULL; |
Evan Cheng | 985921e | 2008-10-27 23:29:28 +0000 | [diff] [blame] | 928 | int SS = -1; |
Evan Cheng | 78dfef7 | 2008-10-25 00:52:41 +0000 | [diff] [blame] | 929 | if (ValNo->def == ~0U) { |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 930 | // If it's defined by a phi, we must split just before the barrier. |
Owen Anderson | 7b9d67c | 2008-12-02 18:53:47 +0000 | [diff] [blame] | 931 | if ((SpillMI = FoldSpill(LI->reg, RC, 0, Barrier, |
| 932 | BarrierMBB, SS, RefsInMBB))) { |
| 933 | SpillIndex = LIs->getInstructionIndex(SpillMI); |
| 934 | } else { |
| 935 | MachineBasicBlock::iterator SpillPt = |
| 936 | findSpillPoint(BarrierMBB, Barrier, NULL, RefsInMBB, SpillIndex); |
| 937 | if (SpillPt == BarrierMBB->begin()) |
| 938 | return false; // No gap to insert spill. |
| 939 | // Add spill. |
| 940 | |
| 941 | SS = CreateSpillStackSlot(CurrLI->reg, RC); |
| 942 | TII->storeRegToStackSlot(*BarrierMBB, SpillPt, CurrLI->reg, true, SS, RC); |
| 943 | SpillMI = prior(SpillPt); |
| 944 | LIs->InsertMachineInstrInMaps(SpillMI, SpillIndex); |
| 945 | } |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 946 | } else if (!IsAvailableInStack(DefMBB, CurrLI->reg, ValNo->def, |
| 947 | RestoreIndex, SpillIndex, SS)) { |
Evan Cheng | 78dfef7 | 2008-10-25 00:52:41 +0000 | [diff] [blame] | 948 | // If it's already split, just restore the value. There is no need to spill |
| 949 | // the def again. |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 950 | if (!DefMI) |
| 951 | return false; // Def is dead. Do nothing. |
Owen Anderson | 7b9d67c | 2008-12-02 18:53:47 +0000 | [diff] [blame] | 952 | |
| 953 | if ((SpillMI = FoldSpill(LI->reg, RC, DefMI, Barrier, |
| 954 | BarrierMBB, SS, RefsInMBB))) { |
| 955 | SpillIndex = LIs->getInstructionIndex(SpillMI); |
Evan Cheng | 1f08cc2 | 2008-10-28 05:28:21 +0000 | [diff] [blame] | 956 | } else { |
Owen Anderson | 7b9d67c | 2008-12-02 18:53:47 +0000 | [diff] [blame] | 957 | // Check if it's possible to insert a spill after the def MI. |
| 958 | MachineBasicBlock::iterator SpillPt; |
| 959 | if (DefMBB == BarrierMBB) { |
| 960 | // Add spill after the def and the last use before the barrier. |
| 961 | SpillPt = findSpillPoint(BarrierMBB, Barrier, DefMI, |
| 962 | RefsInMBB, SpillIndex); |
| 963 | if (SpillPt == DefMBB->begin()) |
| 964 | return false; // No gap to insert spill. |
| 965 | } else { |
| 966 | SpillPt = findNextEmptySlot(DefMBB, DefMI, SpillIndex); |
| 967 | if (SpillPt == DefMBB->end()) |
| 968 | return false; // No gap to insert spill. |
| 969 | } |
| 970 | // Add spill. The store instruction kills the register if def is before |
| 971 | // the barrier in the barrier block. |
| 972 | SS = CreateSpillStackSlot(CurrLI->reg, RC); |
| 973 | TII->storeRegToStackSlot(*DefMBB, SpillPt, CurrLI->reg, |
| 974 | DefMBB == BarrierMBB, SS, RC); |
| 975 | SpillMI = prior(SpillPt); |
| 976 | LIs->InsertMachineInstrInMaps(SpillMI, SpillIndex); |
Evan Cheng | 1f08cc2 | 2008-10-28 05:28:21 +0000 | [diff] [blame] | 977 | } |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 978 | } |
| 979 | |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 980 | // Remember def instruction index to spill index mapping. |
| 981 | if (DefMI && SpillMI) |
| 982 | Def2SpillMap[ValNo->def] = SpillIndex; |
| 983 | |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 984 | // Add restore. |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 985 | TII->loadRegFromStackSlot(*BarrierMBB, RestorePt, CurrLI->reg, SS, RC); |
| 986 | MachineInstr *LoadMI = prior(RestorePt); |
| 987 | LIs->InsertMachineInstrInMaps(LoadMI, RestoreIndex); |
| 988 | |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 989 | // Update spill stack slot live interval. |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 990 | UpdateSpillSlotInterval(ValNo, LIs->getUseIndex(SpillIndex)+1, |
| 991 | LIs->getDefIndex(RestoreIndex)); |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 992 | |
Owen Anderson | b4b8436 | 2009-01-26 21:57:31 +0000 | [diff] [blame] | 993 | ReconstructLiveInterval(CurrLI); |
| 994 | unsigned RestoreIdx = LIs->getInstructionIndex(prior(RestorePt)); |
| 995 | RestoreIdx = LiveIntervals::getDefIndex(RestoreIdx); |
| 996 | RenumberValno(CurrLI->findDefinedVNInfo(RestoreIdx)); |
Owen Anderson | 7d211e2 | 2008-12-31 02:00:25 +0000 | [diff] [blame] | 997 | |
Evan Cheng | ae7fa5b | 2008-10-28 01:48:24 +0000 | [diff] [blame] | 998 | ++NumSplits; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 999 | return true; |
| 1000 | } |
| 1001 | |
| 1002 | /// SplitRegLiveIntervals - Split all register live intervals that cross the |
| 1003 | /// barrier that's being processed. |
| 1004 | bool |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 1005 | PreAllocSplitting::SplitRegLiveIntervals(const TargetRegisterClass **RCs, |
| 1006 | SmallPtrSet<LiveInterval*, 8>& Split) { |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 1007 | // First find all the virtual registers whose live intervals are intercepted |
| 1008 | // by the current barrier. |
| 1009 | SmallVector<LiveInterval*, 8> Intervals; |
| 1010 | for (const TargetRegisterClass **RC = RCs; *RC; ++RC) { |
Evan Cheng | 2306628 | 2008-10-27 07:14:50 +0000 | [diff] [blame] | 1011 | if (TII->IgnoreRegisterClassBarriers(*RC)) |
| 1012 | continue; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 1013 | std::vector<unsigned> &VRs = MRI->getRegClassVirtRegs(*RC); |
| 1014 | for (unsigned i = 0, e = VRs.size(); i != e; ++i) { |
| 1015 | unsigned Reg = VRs[i]; |
| 1016 | if (!LIs->hasInterval(Reg)) |
| 1017 | continue; |
| 1018 | LiveInterval *LI = &LIs->getInterval(Reg); |
| 1019 | if (LI->liveAt(BarrierIdx) && !Barrier->readsRegister(Reg)) |
| 1020 | // Virtual register live interval is intercepted by the barrier. We |
| 1021 | // should split and shrink wrap its interval if possible. |
| 1022 | Intervals.push_back(LI); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | // Process the affected live intervals. |
| 1027 | bool Change = false; |
| 1028 | while (!Intervals.empty()) { |
Evan Cheng | ae7fa5b | 2008-10-28 01:48:24 +0000 | [diff] [blame] | 1029 | if (PreSplitLimit != -1 && (int)NumSplits == PreSplitLimit) |
| 1030 | break; |
Owen Anderson | e1762c9 | 2009-01-12 03:10:40 +0000 | [diff] [blame] | 1031 | else if (NumSplits == 4) |
| 1032 | Change |= Change; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 1033 | LiveInterval *LI = Intervals.back(); |
| 1034 | Intervals.pop_back(); |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 1035 | bool result = SplitRegLiveInterval(LI); |
| 1036 | if (result) Split.insert(LI); |
| 1037 | Change |= result; |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | return Change; |
| 1041 | } |
| 1042 | |
Owen Anderson | 32ca865 | 2009-01-24 10:07:43 +0000 | [diff] [blame] | 1043 | unsigned PreAllocSplitting::getNumberOfSpills( |
| 1044 | SmallPtrSet<MachineInstr*, 4>& MIs, |
| 1045 | unsigned Reg, int FrameIndex) { |
| 1046 | unsigned Spills = 0; |
| 1047 | for (SmallPtrSet<MachineInstr*, 4>::iterator UI = MIs.begin(), UE = MIs.end(); |
| 1048 | UI != UI; ++UI) { |
| 1049 | int StoreFrameIndex; |
| 1050 | unsigned StoreVReg = TII->isStoreToStackSlot(*UI, StoreFrameIndex); |
| 1051 | if (StoreVReg == Reg && StoreFrameIndex == FrameIndex) |
| 1052 | Spills++; |
| 1053 | } |
| 1054 | |
| 1055 | return Spills; |
| 1056 | } |
| 1057 | |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 1058 | /// removeDeadSpills - After doing splitting, filter through all intervals we've |
| 1059 | /// split, and see if any of the spills are unnecessary. If so, remove them. |
| 1060 | bool PreAllocSplitting::removeDeadSpills(SmallPtrSet<LiveInterval*, 8>& split) { |
| 1061 | bool changed = false; |
| 1062 | |
| 1063 | for (SmallPtrSet<LiveInterval*, 8>::iterator LI = split.begin(), |
| 1064 | LE = split.end(); LI != LE; ++LI) { |
Owen Anderson | 9ce499a | 2009-01-23 03:28:53 +0000 | [diff] [blame] | 1065 | DenseMap<VNInfo*, SmallPtrSet<MachineInstr*, 4> > VNUseCount; |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 1066 | |
| 1067 | for (MachineRegisterInfo::use_iterator UI = MRI->use_begin((*LI)->reg), |
| 1068 | UE = MRI->use_end(); UI != UE; ++UI) { |
| 1069 | unsigned index = LIs->getInstructionIndex(&*UI); |
| 1070 | index = LiveIntervals::getUseIndex(index); |
| 1071 | |
| 1072 | const LiveRange* LR = (*LI)->getLiveRangeContaining(index); |
Owen Anderson | 9ce499a | 2009-01-23 03:28:53 +0000 | [diff] [blame] | 1073 | VNUseCount[LR->valno].insert(&*UI); |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | for (LiveInterval::vni_iterator VI = (*LI)->vni_begin(), |
| 1077 | VE = (*LI)->vni_end(); VI != VE; ++VI) { |
| 1078 | VNInfo* CurrVN = *VI; |
| 1079 | if (CurrVN->hasPHIKill) continue; |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 1080 | |
| 1081 | unsigned DefIdx = CurrVN->def; |
| 1082 | if (DefIdx == ~0U || DefIdx == ~1U) continue; |
Owen Anderson | 9ce499a | 2009-01-23 03:28:53 +0000 | [diff] [blame] | 1083 | |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 1084 | MachineInstr* DefMI = LIs->getInstructionFromIndex(DefIdx); |
| 1085 | int FrameIndex; |
| 1086 | if (!TII->isLoadFromStackSlot(DefMI, FrameIndex)) continue; |
| 1087 | |
Owen Anderson | 9ce499a | 2009-01-23 03:28:53 +0000 | [diff] [blame] | 1088 | if (VNUseCount[CurrVN].size() == 0) { |
| 1089 | LIs->RemoveMachineInstrFromMaps(DefMI); |
| 1090 | (*LI)->removeValNo(CurrVN); |
| 1091 | DefMI->eraseFromParent(); |
| 1092 | NumDeadSpills++; |
| 1093 | changed = true; |
Owen Anderson | 32ca865 | 2009-01-24 10:07:43 +0000 | [diff] [blame] | 1094 | continue; |
Owen Anderson | 9ce499a | 2009-01-23 03:28:53 +0000 | [diff] [blame] | 1095 | } |
Owen Anderson | 32ca865 | 2009-01-24 10:07:43 +0000 | [diff] [blame] | 1096 | |
| 1097 | unsigned SpillCount = getNumberOfSpills(VNUseCount[CurrVN], |
| 1098 | (*LI)->reg, FrameIndex); |
| 1099 | if (SpillCount != VNUseCount[CurrVN].size()) continue; |
| 1100 | |
| 1101 | for (SmallPtrSet<MachineInstr*, 4>::iterator UI = |
| 1102 | VNUseCount[CurrVN].begin(), UE = VNUseCount[CurrVN].end(); |
| 1103 | UI != UI; ++UI) { |
| 1104 | LIs->RemoveMachineInstrFromMaps(*UI); |
| 1105 | (*UI)->eraseFromParent(); |
| 1106 | } |
| 1107 | |
| 1108 | LIs->RemoveMachineInstrFromMaps(DefMI); |
| 1109 | (*LI)->removeValNo(CurrVN); |
| 1110 | DefMI->eraseFromParent(); |
| 1111 | NumDeadSpills++; |
| 1112 | changed = true; |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | return changed; |
| 1117 | } |
| 1118 | |
Owen Anderson | f1f75b1 | 2008-11-04 22:22:41 +0000 | [diff] [blame] | 1119 | bool PreAllocSplitting::createsNewJoin(LiveRange* LR, |
| 1120 | MachineBasicBlock* DefMBB, |
| 1121 | MachineBasicBlock* BarrierMBB) { |
| 1122 | if (DefMBB == BarrierMBB) |
| 1123 | return false; |
| 1124 | |
| 1125 | if (LR->valno->hasPHIKill) |
| 1126 | return false; |
| 1127 | |
| 1128 | unsigned MBBEnd = LIs->getMBBEndIdx(BarrierMBB); |
| 1129 | if (LR->end < MBBEnd) |
| 1130 | return false; |
| 1131 | |
| 1132 | MachineLoopInfo& MLI = getAnalysis<MachineLoopInfo>(); |
| 1133 | if (MLI.getLoopFor(DefMBB) != MLI.getLoopFor(BarrierMBB)) |
| 1134 | return true; |
| 1135 | |
| 1136 | MachineDominatorTree& MDT = getAnalysis<MachineDominatorTree>(); |
| 1137 | SmallPtrSet<MachineBasicBlock*, 4> Visited; |
| 1138 | typedef std::pair<MachineBasicBlock*, |
| 1139 | MachineBasicBlock::succ_iterator> ItPair; |
| 1140 | SmallVector<ItPair, 4> Stack; |
| 1141 | Stack.push_back(std::make_pair(BarrierMBB, BarrierMBB->succ_begin())); |
| 1142 | |
| 1143 | while (!Stack.empty()) { |
| 1144 | ItPair P = Stack.back(); |
| 1145 | Stack.pop_back(); |
| 1146 | |
| 1147 | MachineBasicBlock* PredMBB = P.first; |
| 1148 | MachineBasicBlock::succ_iterator S = P.second; |
| 1149 | |
| 1150 | if (S == PredMBB->succ_end()) |
| 1151 | continue; |
| 1152 | else if (Visited.count(*S)) { |
| 1153 | Stack.push_back(std::make_pair(PredMBB, ++S)); |
| 1154 | continue; |
| 1155 | } else |
Owen Anderson | b214c69 | 2008-11-05 00:32:13 +0000 | [diff] [blame] | 1156 | Stack.push_back(std::make_pair(PredMBB, S+1)); |
Owen Anderson | f1f75b1 | 2008-11-04 22:22:41 +0000 | [diff] [blame] | 1157 | |
| 1158 | MachineBasicBlock* MBB = *S; |
| 1159 | Visited.insert(MBB); |
| 1160 | |
| 1161 | if (MBB == BarrierMBB) |
| 1162 | return true; |
| 1163 | |
| 1164 | MachineDomTreeNode* DefMDTN = MDT.getNode(DefMBB); |
| 1165 | MachineDomTreeNode* BarrierMDTN = MDT.getNode(BarrierMBB); |
| 1166 | MachineDomTreeNode* MDTN = MDT.getNode(MBB)->getIDom(); |
| 1167 | while (MDTN) { |
| 1168 | if (MDTN == DefMDTN) |
| 1169 | return true; |
| 1170 | else if (MDTN == BarrierMDTN) |
| 1171 | break; |
| 1172 | MDTN = MDTN->getIDom(); |
| 1173 | } |
| 1174 | |
| 1175 | MBBEnd = LIs->getMBBEndIdx(MBB); |
| 1176 | if (LR->end > MBBEnd) |
| 1177 | Stack.push_back(std::make_pair(MBB, MBB->succ_begin())); |
| 1178 | } |
| 1179 | |
| 1180 | return false; |
| 1181 | } |
| 1182 | |
| 1183 | |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 1184 | bool PreAllocSplitting::runOnMachineFunction(MachineFunction &MF) { |
Evan Cheng | d0e32c5 | 2008-10-29 05:06:14 +0000 | [diff] [blame] | 1185 | CurrMF = &MF; |
| 1186 | TM = &MF.getTarget(); |
| 1187 | TII = TM->getInstrInfo(); |
| 1188 | MFI = MF.getFrameInfo(); |
| 1189 | MRI = &MF.getRegInfo(); |
| 1190 | LIs = &getAnalysis<LiveIntervals>(); |
| 1191 | LSs = &getAnalysis<LiveStacks>(); |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 1192 | |
| 1193 | bool MadeChange = false; |
| 1194 | |
| 1195 | // Make sure blocks are numbered in order. |
| 1196 | MF.RenumberBlocks(); |
| 1197 | |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 1198 | MachineBasicBlock *Entry = MF.begin(); |
| 1199 | SmallPtrSet<MachineBasicBlock*,16> Visited; |
| 1200 | |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 1201 | SmallPtrSet<LiveInterval*, 8> Split; |
| 1202 | |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 1203 | for (df_ext_iterator<MachineBasicBlock*, SmallPtrSet<MachineBasicBlock*,16> > |
| 1204 | DFI = df_ext_begin(Entry, Visited), E = df_ext_end(Entry, Visited); |
| 1205 | DFI != E; ++DFI) { |
| 1206 | BarrierMBB = *DFI; |
| 1207 | for (MachineBasicBlock::iterator I = BarrierMBB->begin(), |
| 1208 | E = BarrierMBB->end(); I != E; ++I) { |
| 1209 | Barrier = &*I; |
| 1210 | const TargetRegisterClass **BarrierRCs = |
| 1211 | Barrier->getDesc().getRegClassBarriers(); |
| 1212 | if (!BarrierRCs) |
| 1213 | continue; |
| 1214 | BarrierIdx = LIs->getInstructionIndex(Barrier); |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 1215 | MadeChange |= SplitRegLiveIntervals(BarrierRCs, Split); |
Evan Cheng | 5489893 | 2008-10-29 08:39:34 +0000 | [diff] [blame] | 1216 | } |
| 1217 | } |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 1218 | |
Owen Anderson | 956ec27 | 2009-01-23 00:23:32 +0000 | [diff] [blame] | 1219 | MadeChange |= removeDeadSpills(Split); |
| 1220 | |
Evan Cheng | f5cd4f0 | 2008-10-23 20:43:13 +0000 | [diff] [blame] | 1221 | return MadeChange; |
Evan Cheng | 09e8ca8 | 2008-10-20 21:44:59 +0000 | [diff] [blame] | 1222 | } |