Chris Lattner | a3b8b5c | 2004-07-23 17:56:30 +0000 | [diff] [blame] | 1 | //===-- LiveIntervalAnalysis.h - Live Interval Analysis ---------*- C++ -*-===// |
Alkis Evlogimenos | ff0cbe1 | 2003-11-20 03:32:25 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 7ed47a1 | 2007-12-29 19:59:42 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Alkis Evlogimenos | ff0cbe1 | 2003-11-20 03:32:25 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | 6b92906 | 2004-07-19 02:13:59 +0000 | [diff] [blame] | 10 | // This file implements the LiveInterval analysis pass. Given some numbering of |
| 11 | // each the machine instructions (in this implemention depth-first order) an |
| 12 | // interval [i, j) is said to be a live interval for register v if there is no |
Dan Gohman | 8131a50 | 2008-03-13 23:04:27 +0000 | [diff] [blame] | 13 | // instruction with number j' > j such that v is live at j' and there is no |
Chris Lattner | 6b92906 | 2004-07-19 02:13:59 +0000 | [diff] [blame] | 14 | // instruction with number i' < i such that v is live at i'. In this |
| 15 | // implementation intervals can have holes, i.e. an interval might look like |
| 16 | // [1,20), [50,65), [1000,1001). |
Alkis Evlogimenos | ff0cbe1 | 2003-11-20 03:32:25 +0000 | [diff] [blame] | 17 | // |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | |
Chris Lattner | a3b8b5c | 2004-07-23 17:56:30 +0000 | [diff] [blame] | 20 | #ifndef LLVM_CODEGEN_LIVEINTERVAL_ANALYSIS_H |
| 21 | #define LLVM_CODEGEN_LIVEINTERVAL_ANALYSIS_H |
Alkis Evlogimenos | ff0cbe1 | 2003-11-20 03:32:25 +0000 | [diff] [blame] | 22 | |
Jakob Stoklund Olesen | 7fa6784 | 2012-06-22 20:37:52 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetRegisterInfo.h" |
David Greene | de0cc5a | 2009-08-19 20:52:54 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Alkis Evlogimenos | ff0cbe1 | 2003-11-20 03:32:25 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Chris Lattner | 779a651 | 2005-09-21 04:18:25 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/LiveInterval.h" |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/SlotIndexes.h" |
Evan Cheng | 61de82d | 2007-02-15 05:59:24 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/BitVector.h" |
Jakob Stoklund Olesen | 7fa6784 | 2012-06-22 20:37:52 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/IndexedMap.h" |
Evan Cheng | 8f90b6e | 2009-01-07 02:08:57 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/SmallPtrSet.h" |
Evan Cheng | 549f27d3 | 2007-08-13 23:45:17 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/SmallVector.h" |
Evan Cheng | f3bb2e6 | 2007-09-05 21:46:51 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Allocator.h" |
Hartmut Kaiser | ffb15de | 2007-11-13 23:04:28 +0000 | [diff] [blame] | 33 | #include <cmath> |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 34 | #include <iterator> |
Alkis Evlogimenos | ff0cbe1 | 2003-11-20 03:32:25 +0000 | [diff] [blame] | 35 | |
| 36 | namespace llvm { |
| 37 | |
Dan Gohman | 6d69ba8 | 2008-07-25 00:02:30 +0000 | [diff] [blame] | 38 | class AliasAnalysis; |
Jakob Stoklund Olesen | 34c6f98 | 2012-06-05 22:02:15 +0000 | [diff] [blame] | 39 | class LiveRangeCalc; |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 40 | class LiveVariables; |
Jakob Stoklund Olesen | 34c6f98 | 2012-06-05 22:02:15 +0000 | [diff] [blame] | 41 | class MachineDominatorTree; |
Evan Cheng | 22f07ff | 2007-12-11 02:09:15 +0000 | [diff] [blame] | 42 | class MachineLoopInfo; |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 43 | class TargetRegisterInfo; |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 44 | class MachineRegisterInfo; |
Chris Lattner | f768bba | 2005-03-09 23:05:19 +0000 | [diff] [blame] | 45 | class TargetInstrInfo; |
Evan Cheng | 20b0abc | 2007-04-17 20:32:26 +0000 | [diff] [blame] | 46 | class TargetRegisterClass; |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 47 | class VirtRegMap; |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 48 | |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 49 | class LiveIntervals : public MachineFunctionPass { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 50 | MachineFunction* MF; |
| 51 | MachineRegisterInfo* MRI; |
| 52 | const TargetMachine* TM; |
| 53 | const TargetRegisterInfo* TRI; |
| 54 | const TargetInstrInfo* TII; |
| 55 | AliasAnalysis *AA; |
| 56 | LiveVariables* LV; |
| 57 | SlotIndexes* Indexes; |
Jakob Stoklund Olesen | 34c6f98 | 2012-06-05 22:02:15 +0000 | [diff] [blame] | 58 | MachineDominatorTree *DomTree; |
| 59 | LiveRangeCalc *LRCalc; |
Alkis Evlogimenos | ff0cbe1 | 2003-11-20 03:32:25 +0000 | [diff] [blame] | 60 | |
Evan Cheng | f3bb2e6 | 2007-09-05 21:46:51 +0000 | [diff] [blame] | 61 | /// Special pool allocator for VNInfo's (LiveInterval val#). |
| 62 | /// |
Benjamin Kramer | 991de14 | 2010-03-30 20:16:45 +0000 | [diff] [blame] | 63 | VNInfo::Allocator VNInfoAllocator; |
Evan Cheng | f3bb2e6 | 2007-09-05 21:46:51 +0000 | [diff] [blame] | 64 | |
Jakob Stoklund Olesen | 7fa6784 | 2012-06-22 20:37:52 +0000 | [diff] [blame] | 65 | /// Live interval pointers for all the virtual registers. |
| 66 | IndexedMap<LiveInterval*, VirtReg2IndexFunctor> VirtRegIntervals; |
Alkis Evlogimenos | ff0cbe1 | 2003-11-20 03:32:25 +0000 | [diff] [blame] | 67 | |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 68 | /// AllocatableRegs - A bit vector of allocatable registers. |
| 69 | BitVector AllocatableRegs; |
Evan Cheng | 88d1f58 | 2007-03-01 02:03:03 +0000 | [diff] [blame] | 70 | |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 71 | /// ReservedRegs - A bit vector of reserved registers. |
| 72 | BitVector ReservedRegs; |
Lang Hames | 342c64c | 2012-02-14 18:51:53 +0000 | [diff] [blame] | 73 | |
Jakob Stoklund Olesen | 3fd3a84 | 2012-02-08 17:33:45 +0000 | [diff] [blame] | 74 | /// RegMaskSlots - Sorted list of instructions with register mask operands. |
| 75 | /// Always use the 'r' slot, RegMasks are normal clobbers, not early |
| 76 | /// clobbers. |
| 77 | SmallVector<SlotIndex, 8> RegMaskSlots; |
| 78 | |
| 79 | /// RegMaskBits - This vector is parallel to RegMaskSlots, it holds a |
| 80 | /// pointer to the corresponding register mask. This pointer can be |
| 81 | /// recomputed as: |
| 82 | /// |
| 83 | /// MI = Indexes->getInstructionFromIndex(RegMaskSlot[N]); |
| 84 | /// unsigned OpNum = findRegMaskOperand(MI); |
| 85 | /// RegMaskBits[N] = MI->getOperand(OpNum).getRegMask(); |
| 86 | /// |
| 87 | /// This is kept in a separate vector partly because some standard |
| 88 | /// libraries don't support lower_bound() with mixed objects, partly to |
| 89 | /// improve locality when searching in RegMaskSlots. |
| 90 | /// Also see the comment in LiveInterval::find(). |
| 91 | SmallVector<const uint32_t*, 8> RegMaskBits; |
| 92 | |
Jakob Stoklund Olesen | 34e85d0 | 2012-02-10 01:26:29 +0000 | [diff] [blame] | 93 | /// For each basic block number, keep (begin, size) pairs indexing into the |
| 94 | /// RegMaskSlots and RegMaskBits arrays. |
| 95 | /// Note that basic block numbers may not be layout contiguous, that's why |
| 96 | /// we can't just keep track of the first register mask in each basic |
| 97 | /// block. |
| 98 | SmallVector<std::pair<unsigned, unsigned>, 8> RegMaskBlocks; |
| 99 | |
Jakob Stoklund Olesen | 34c6f98 | 2012-06-05 22:02:15 +0000 | [diff] [blame] | 100 | /// RegUnitIntervals - Keep a live interval for each register unit as a way |
| 101 | /// of tracking fixed physreg interference. |
| 102 | SmallVector<LiveInterval*, 0> RegUnitIntervals; |
| 103 | |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 104 | public: |
Nick Lewycky | ecd94c8 | 2007-05-06 13:37:16 +0000 | [diff] [blame] | 105 | static char ID; // Pass identification, replacement for typeid |
Jakob Stoklund Olesen | 34c6f98 | 2012-06-05 22:02:15 +0000 | [diff] [blame] | 106 | LiveIntervals(); |
| 107 | virtual ~LiveIntervals(); |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 108 | |
Jakob Stoklund Olesen | e5d9041 | 2010-03-01 20:59:38 +0000 | [diff] [blame] | 109 | // Calculate the spill weight to assign to a single instruction. |
| 110 | static float getSpillWeight(bool isDef, bool isUse, unsigned loopDepth); |
Evan Cheng | f2fbca6 | 2007-11-12 06:35:08 +0000 | [diff] [blame] | 111 | |
Jakob Stoklund Olesen | 7fa6784 | 2012-06-22 20:37:52 +0000 | [diff] [blame] | 112 | LiveInterval &getInterval(unsigned Reg) { |
| 113 | LiveInterval *LI = VirtRegIntervals[Reg]; |
| 114 | assert(LI && "Interval does not exist for virtual register"); |
| 115 | return *LI; |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Jakob Stoklund Olesen | 7fa6784 | 2012-06-22 20:37:52 +0000 | [diff] [blame] | 118 | const LiveInterval &getInterval(unsigned Reg) const { |
| 119 | return const_cast<LiveIntervals*>(this)->getInterval(Reg); |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Jakob Stoklund Olesen | 7fa6784 | 2012-06-22 20:37:52 +0000 | [diff] [blame] | 122 | bool hasInterval(unsigned Reg) const { |
| 123 | return VirtRegIntervals.inBounds(Reg) && VirtRegIntervals[Reg]; |
Evan Cheng | b371f45 | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 126 | /// isAllocatable - is the physical register reg allocatable in the current |
| 127 | /// function? |
| 128 | bool isAllocatable(unsigned reg) const { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 129 | return AllocatableRegs.test(reg); |
Jakob Stoklund Olesen | df30cf9 | 2010-08-10 00:02:26 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Lang Hames | 342c64c | 2012-02-14 18:51:53 +0000 | [diff] [blame] | 132 | /// isReserved - is the physical register reg reserved in the current |
| 133 | /// function |
| 134 | bool isReserved(unsigned reg) const { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 135 | return ReservedRegs.test(reg); |
Lang Hames | 342c64c | 2012-02-14 18:51:53 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Jakob Stoklund Olesen | 7fa6784 | 2012-06-22 20:37:52 +0000 | [diff] [blame] | 138 | // Interval creation. |
| 139 | LiveInterval &getOrCreateInterval(unsigned Reg) { |
| 140 | if (!hasInterval(Reg)) { |
| 141 | VirtRegIntervals.grow(Reg); |
| 142 | VirtRegIntervals[Reg] = createInterval(Reg); |
| 143 | } |
| 144 | return getInterval(Reg); |
| 145 | } |
| 146 | |
| 147 | // Interval removal. |
| 148 | void removeInterval(unsigned Reg) { |
| 149 | delete VirtRegIntervals[Reg]; |
| 150 | VirtRegIntervals[Reg] = 0; |
David Greene | 2513330 | 2007-06-08 17:18:56 +0000 | [diff] [blame] | 151 | } |
Evan Cheng | 0a1fcce | 2009-02-08 11:04:35 +0000 | [diff] [blame] | 152 | |
Owen Anderson | c4dc132 | 2008-06-05 17:15:43 +0000 | [diff] [blame] | 153 | /// addLiveRangeToEndOfBlock - Given a register and an instruction, |
| 154 | /// adds a live range from that instruction to the end of its MBB. |
| 155 | LiveRange addLiveRangeToEndOfBlock(unsigned reg, |
Lang Hames | 8651125 | 2009-09-04 20:41:11 +0000 | [diff] [blame] | 156 | MachineInstr* startInst); |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 157 | |
Jakob Stoklund Olesen | 11513e5 | 2011-02-08 00:03:05 +0000 | [diff] [blame] | 158 | /// shrinkToUses - After removing some uses of a register, shrink its live |
| 159 | /// range to just the remaining uses. This method does not compute reaching |
| 160 | /// defs for new uses, and it doesn't remove dead defs. |
| 161 | /// Dead PHIDef values are marked as unused. |
Jakob Stoklund Olesen | 0d8ccaa | 2011-03-07 23:29:10 +0000 | [diff] [blame] | 162 | /// New dead machine instructions are added to the dead vector. |
Jakob Stoklund Olesen | 6a3dbd3 | 2011-03-17 20:37:07 +0000 | [diff] [blame] | 163 | /// Return true if the interval may have been separated into multiple |
| 164 | /// connected components. |
| 165 | bool shrinkToUses(LiveInterval *li, |
Jakob Stoklund Olesen | 0d8ccaa | 2011-03-07 23:29:10 +0000 | [diff] [blame] | 166 | SmallVectorImpl<MachineInstr*> *dead = 0); |
Jakob Stoklund Olesen | 11513e5 | 2011-02-08 00:03:05 +0000 | [diff] [blame] | 167 | |
Jakob Stoklund Olesen | 7fd747b | 2011-01-12 22:28:48 +0000 | [diff] [blame] | 168 | SlotIndexes *getSlotIndexes() const { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 169 | return Indexes; |
Jakob Stoklund Olesen | 7fd747b | 2011-01-12 22:28:48 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Jakob Stoklund Olesen | 3dfd59b | 2012-06-05 01:06:12 +0000 | [diff] [blame] | 172 | AliasAnalysis *getAliasAnalysis() const { |
| 173 | return AA; |
| 174 | } |
| 175 | |
Evan Cheng | 5b69eba | 2009-04-21 22:46:52 +0000 | [diff] [blame] | 176 | /// isNotInMIMap - returns true if the specified machine instr has been |
| 177 | /// removed or was never entered in the map. |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 178 | bool isNotInMIMap(const MachineInstr* Instr) const { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 179 | return !Indexes->hasIndex(Instr); |
Evan Cheng | 30cac02 | 2007-02-22 23:03:39 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 182 | /// Returns the base index of the given instruction. |
| 183 | SlotIndex getInstructionIndex(const MachineInstr *instr) const { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 184 | return Indexes->getInstructionIndex(instr); |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 185 | } |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 186 | |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 187 | /// Returns the instruction associated with the given index. |
| 188 | MachineInstr* getInstructionFromIndex(SlotIndex index) const { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 189 | return Indexes->getInstructionFromIndex(index); |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /// Return the first index in the given basic block. |
| 193 | SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 194 | return Indexes->getMBBStartIdx(mbb); |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 195 | } |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 196 | |
| 197 | /// Return the last index in the given basic block. |
| 198 | SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 199 | return Indexes->getMBBEndIdx(mbb); |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 200 | } |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 201 | |
Lang Hames | 60f422f | 2010-07-17 07:34:01 +0000 | [diff] [blame] | 202 | bool isLiveInToMBB(const LiveInterval &li, |
| 203 | const MachineBasicBlock *mbb) const { |
| 204 | return li.liveAt(getMBBStartIdx(mbb)); |
| 205 | } |
| 206 | |
Lang Hames | 60f422f | 2010-07-17 07:34:01 +0000 | [diff] [blame] | 207 | bool isLiveOutOfMBB(const LiveInterval &li, |
| 208 | const MachineBasicBlock *mbb) const { |
| 209 | return li.liveAt(getMBBEndIdx(mbb).getPrevSlot()); |
| 210 | } |
| 211 | |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 212 | MachineBasicBlock* getMBBFromIndex(SlotIndex index) const { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 213 | return Indexes->getMBBFromIndex(index); |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Lang Hames | b366158 | 2009-11-14 00:02:51 +0000 | [diff] [blame] | 216 | SlotIndex InsertMachineInstrInMaps(MachineInstr *MI) { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 217 | return Indexes->insertMachineInstrInMaps(MI); |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Chris Lattner | f7da2c7 | 2006-08-24 22:43:55 +0000 | [diff] [blame] | 220 | void RemoveMachineInstrFromMaps(MachineInstr *MI) { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 221 | Indexes->removeMachineInstrFromMaps(MI); |
Chris Lattner | f7da2c7 | 2006-08-24 22:43:55 +0000 | [diff] [blame] | 222 | } |
David Greene | 2513330 | 2007-06-08 17:18:56 +0000 | [diff] [blame] | 223 | |
Evan Cheng | 7007143 | 2008-02-13 03:01:43 +0000 | [diff] [blame] | 224 | void ReplaceMachineInstrInMaps(MachineInstr *MI, MachineInstr *NewMI) { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 225 | Indexes->replaceMachineInstrInMaps(MI, NewMI); |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | bool findLiveInMBBs(SlotIndex Start, SlotIndex End, |
| 229 | SmallVectorImpl<MachineBasicBlock*> &MBBs) const { |
Jakob Stoklund Olesen | 15f1d8c | 2012-06-04 22:39:14 +0000 | [diff] [blame] | 230 | return Indexes->findLiveInMBBs(Start, End, MBBs); |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Benjamin Kramer | 991de14 | 2010-03-30 20:16:45 +0000 | [diff] [blame] | 233 | VNInfo::Allocator& getVNInfoAllocator() { return VNInfoAllocator; } |
Evan Cheng | f3bb2e6 | 2007-09-05 21:46:51 +0000 | [diff] [blame] | 234 | |
David Greene | 2513330 | 2007-06-08 17:18:56 +0000 | [diff] [blame] | 235 | virtual void getAnalysisUsage(AnalysisUsage &AU) const; |
| 236 | virtual void releaseMemory(); |
| 237 | |
| 238 | /// runOnMachineFunction - pass entry point |
| 239 | virtual bool runOnMachineFunction(MachineFunction&); |
| 240 | |
| 241 | /// print - Implement the dump method. |
Chris Lattner | 45cfe54 | 2009-08-23 06:03:38 +0000 | [diff] [blame] | 242 | virtual void print(raw_ostream &O, const Module* = 0) const; |
David Greene | 2513330 | 2007-06-08 17:18:56 +0000 | [diff] [blame] | 243 | |
Evan Cheng | 5ef3a04 | 2007-12-06 00:01:56 +0000 | [diff] [blame] | 244 | /// isReMaterializable - Returns true if every definition of MI of every |
| 245 | /// val# of the specified interval is re-materializable. Also returns true |
| 246 | /// by reference if all of the defs are load instructions. |
Evan Cheng | dc37786 | 2008-09-30 15:44:16 +0000 | [diff] [blame] | 247 | bool isReMaterializable(const LiveInterval &li, |
Jakob Stoklund Olesen | 38f6bd0 | 2011-03-10 01:21:58 +0000 | [diff] [blame] | 248 | const SmallVectorImpl<LiveInterval*> *SpillIs, |
Evan Cheng | dc37786 | 2008-09-30 15:44:16 +0000 | [diff] [blame] | 249 | bool &isLoad); |
Evan Cheng | 5ef3a04 | 2007-12-06 00:01:56 +0000 | [diff] [blame] | 250 | |
Jakob Stoklund Olesen | ebf2750 | 2012-02-10 01:23:55 +0000 | [diff] [blame] | 251 | /// intervalIsInOneMBB - If LI is confined to a single basic block, return |
| 252 | /// a pointer to that block. If LI is live in to or out of any block, |
| 253 | /// return NULL. |
| 254 | MachineBasicBlock *intervalIsInOneMBB(const LiveInterval &LI) const; |
Owen Anderson | 0c2e7b9 | 2009-01-13 06:05:10 +0000 | [diff] [blame] | 255 | |
Jakob Stoklund Olesen | 8a61da8 | 2011-02-08 21:13:03 +0000 | [diff] [blame] | 256 | /// addKillFlags - Add kill flags to any instruction that kills a virtual |
| 257 | /// register. |
| 258 | void addKillFlags(); |
| 259 | |
Lang Hames | da7984f | 2012-02-15 01:23:52 +0000 | [diff] [blame] | 260 | /// handleMove - call this method to notify LiveIntervals that |
| 261 | /// instruction 'mi' has been moved within a basic block. This will update |
| 262 | /// the live intervals for all operands of mi. Moves between basic blocks |
| 263 | /// are not supported. |
Lang Hames | 4586d25 | 2012-02-21 22:29:38 +0000 | [diff] [blame] | 264 | void handleMove(MachineInstr* MI); |
| 265 | |
| 266 | /// moveIntoBundle - Update intervals for operands of MI so that they |
| 267 | /// begin/end on the SlotIndex for BundleStart. |
| 268 | /// |
| 269 | /// Requires MI and BundleStart to have SlotIndexes, and assumes |
| 270 | /// existing liveness is accurate. BundleStart should be the first |
| 271 | /// instruction in the Bundle. |
| 272 | void handleMoveIntoBundle(MachineInstr* MI, MachineInstr* BundleStart); |
Lang Hames | 907cc8f | 2012-01-27 22:36:19 +0000 | [diff] [blame] | 273 | |
Jakob Stoklund Olesen | 3fd3a84 | 2012-02-08 17:33:45 +0000 | [diff] [blame] | 274 | // Register mask functions. |
| 275 | // |
| 276 | // Machine instructions may use a register mask operand to indicate that a |
| 277 | // large number of registers are clobbered by the instruction. This is |
| 278 | // typically used for calls. |
| 279 | // |
| 280 | // For compile time performance reasons, these clobbers are not recorded in |
| 281 | // the live intervals for individual physical registers. Instead, |
| 282 | // LiveIntervalAnalysis maintains a sorted list of instructions with |
| 283 | // register mask operands. |
| 284 | |
Jakob Stoklund Olesen | 34e85d0 | 2012-02-10 01:26:29 +0000 | [diff] [blame] | 285 | /// getRegMaskSlots - Returns a sorted array of slot indices of all |
Jakob Stoklund Olesen | 3fd3a84 | 2012-02-08 17:33:45 +0000 | [diff] [blame] | 286 | /// instructions with register mask operands. |
| 287 | ArrayRef<SlotIndex> getRegMaskSlots() const { return RegMaskSlots; } |
| 288 | |
Jakob Stoklund Olesen | 34e85d0 | 2012-02-10 01:26:29 +0000 | [diff] [blame] | 289 | /// getRegMaskSlotsInBlock - Returns a sorted array of slot indices of all |
| 290 | /// instructions with register mask operands in the basic block numbered |
| 291 | /// MBBNum. |
| 292 | ArrayRef<SlotIndex> getRegMaskSlotsInBlock(unsigned MBBNum) const { |
| 293 | std::pair<unsigned, unsigned> P = RegMaskBlocks[MBBNum]; |
| 294 | return getRegMaskSlots().slice(P.first, P.second); |
| 295 | } |
| 296 | |
| 297 | /// getRegMaskBits() - Returns an array of register mask pointers |
| 298 | /// corresponding to getRegMaskSlots(). |
| 299 | ArrayRef<const uint32_t*> getRegMaskBits() const { return RegMaskBits; } |
| 300 | |
| 301 | /// getRegMaskBitsInBlock - Returns an array of mask pointers corresponding |
| 302 | /// to getRegMaskSlotsInBlock(MBBNum). |
| 303 | ArrayRef<const uint32_t*> getRegMaskBitsInBlock(unsigned MBBNum) const { |
| 304 | std::pair<unsigned, unsigned> P = RegMaskBlocks[MBBNum]; |
| 305 | return getRegMaskBits().slice(P.first, P.second); |
| 306 | } |
| 307 | |
Jakob Stoklund Olesen | 3fd3a84 | 2012-02-08 17:33:45 +0000 | [diff] [blame] | 308 | /// checkRegMaskInterference - Test if LI is live across any register mask |
| 309 | /// instructions, and compute a bit mask of physical registers that are not |
| 310 | /// clobbered by any of them. |
| 311 | /// |
| 312 | /// Returns false if LI doesn't cross any register mask instructions. In |
| 313 | /// that case, the bit vector is not filled in. |
| 314 | bool checkRegMaskInterference(LiveInterval &LI, |
| 315 | BitVector &UsableRegs); |
| 316 | |
Jakob Stoklund Olesen | 34c6f98 | 2012-06-05 22:02:15 +0000 | [diff] [blame] | 317 | // Register unit functions. |
| 318 | // |
| 319 | // Fixed interference occurs when MachineInstrs use physregs directly |
| 320 | // instead of virtual registers. This typically happens when passing |
| 321 | // arguments to a function call, or when instructions require operands in |
| 322 | // fixed registers. |
| 323 | // |
| 324 | // Each physreg has one or more register units, see MCRegisterInfo. We |
| 325 | // track liveness per register unit to handle aliasing registers more |
| 326 | // efficiently. |
| 327 | |
| 328 | /// getRegUnit - Return the live range for Unit. |
| 329 | /// It will be computed if it doesn't exist. |
| 330 | LiveInterval &getRegUnit(unsigned Unit) { |
| 331 | LiveInterval *LI = RegUnitIntervals[Unit]; |
| 332 | if (!LI) { |
| 333 | // Compute missing ranges on demand. |
| 334 | RegUnitIntervals[Unit] = LI = new LiveInterval(Unit, HUGE_VALF); |
| 335 | computeRegUnitInterval(LI); |
| 336 | } |
| 337 | return *LI; |
| 338 | } |
| 339 | |
Jakob Stoklund Olesen | 7824152 | 2012-06-20 18:00:57 +0000 | [diff] [blame] | 340 | /// getCachedRegUnit - Return the live range for Unit if it has already |
| 341 | /// been computed, or NULL if it hasn't been computed yet. |
| 342 | LiveInterval *getCachedRegUnit(unsigned Unit) { |
| 343 | return RegUnitIntervals[Unit]; |
| 344 | } |
| 345 | |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 346 | private: |
Chris Lattner | 428b92e | 2006-09-15 03:57:23 +0000 | [diff] [blame] | 347 | /// computeIntervals - Compute live intervals. |
Chris Lattner | c7695eb | 2006-09-14 06:42:17 +0000 | [diff] [blame] | 348 | void computeIntervals(); |
Evan Cheng | 752195e | 2009-09-14 21:33:42 +0000 | [diff] [blame] | 349 | |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 350 | /// handleRegisterDef - update intervals for a register def |
Jakob Stoklund Olesen | 27b7669 | 2012-06-22 18:20:50 +0000 | [diff] [blame] | 351 | /// (calls handleVirtualRegisterDef) |
Chris Lattner | 6b128bd | 2006-09-03 08:07:11 +0000 | [diff] [blame] | 352 | void handleRegisterDef(MachineBasicBlock *MBB, |
Lang Hames | 8651125 | 2009-09-04 20:41:11 +0000 | [diff] [blame] | 353 | MachineBasicBlock::iterator MI, |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 354 | SlotIndex MIIdx, |
Evan Cheng | ef0732d | 2008-07-10 07:35:43 +0000 | [diff] [blame] | 355 | MachineOperand& MO, unsigned MOIdx); |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 356 | |
Evan Cheng | 3749943 | 2010-05-05 18:27:40 +0000 | [diff] [blame] | 357 | /// isPartialRedef - Return true if the specified def at the specific index |
| 358 | /// is partially re-defining the specified live interval. A common case of |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 359 | /// this is a definition of the sub-register. |
Evan Cheng | 3749943 | 2010-05-05 18:27:40 +0000 | [diff] [blame] | 360 | bool isPartialRedef(SlotIndex MIIdx, MachineOperand &MO, |
| 361 | LiveInterval &interval); |
| 362 | |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 363 | /// handleVirtualRegisterDef - update intervals for a virtual |
| 364 | /// register def |
Chris Lattner | 6b128bd | 2006-09-03 08:07:11 +0000 | [diff] [blame] | 365 | void handleVirtualRegisterDef(MachineBasicBlock *MBB, |
| 366 | MachineBasicBlock::iterator MI, |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 367 | SlotIndex MIIdx, MachineOperand& MO, |
Lang Hames | 8651125 | 2009-09-04 20:41:11 +0000 | [diff] [blame] | 368 | unsigned MOIdx, |
| 369 | LiveInterval& interval); |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 370 | |
Owen Anderson | 03857b2 | 2008-08-13 21:49:13 +0000 | [diff] [blame] | 371 | static LiveInterval* createInterval(unsigned Reg); |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 372 | |
Evan Cheng | 752195e | 2009-09-14 21:33:42 +0000 | [diff] [blame] | 373 | void printInstrs(raw_ostream &O) const; |
| 374 | void dumpInstrs() const; |
Lang Hames | 3dc7c51 | 2012-02-17 18:44:18 +0000 | [diff] [blame] | 375 | |
Jakob Stoklund Olesen | 34c6f98 | 2012-06-05 22:02:15 +0000 | [diff] [blame] | 376 | void computeLiveInRegUnits(); |
| 377 | void computeRegUnitInterval(LiveInterval*); |
Jakob Stoklund Olesen | 3dfa38a | 2012-07-27 20:58:46 +0000 | [diff] [blame^] | 378 | void computeVirtRegInterval(LiveInterval*); |
Jakob Stoklund Olesen | 34c6f98 | 2012-06-05 22:02:15 +0000 | [diff] [blame] | 379 | |
Lang Hames | 3dc7c51 | 2012-02-17 18:44:18 +0000 | [diff] [blame] | 380 | class HMEditor; |
Alkis Evlogimenos | 1a8ea01 | 2004-08-04 09:46:26 +0000 | [diff] [blame] | 381 | }; |
Alkis Evlogimenos | ff0cbe1 | 2003-11-20 03:32:25 +0000 | [diff] [blame] | 382 | } // End llvm namespace |
| 383 | |
| 384 | #endif |