Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1 | //===-- RegAllocFast.cpp - A fast register allocator for debug code -------===// |
| 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 register allocator allocates registers to a basic block at a time, |
| 11 | // attempting to keep values in registers and reusing registers as appropriate. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/Passes.h" |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/DenseMap.h" |
| 17 | #include "llvm/ADT/IndexedMap.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/STLExtras.h" |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/SmallSet.h" |
| 20 | #include "llvm/ADT/SmallVector.h" |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SparseSet.h" |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/Statistic.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 24 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 25 | #include "llvm/CodeGen/MachineInstr.h" |
| 26 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 27 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 28 | #include "llvm/CodeGen/RegAllocRegistry.h" |
| 29 | #include "llvm/CodeGen/RegisterClassInfo.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 30 | #include "llvm/IR/BasicBlock.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 31 | #include "llvm/Support/CommandLine.h" |
| 32 | #include "llvm/Support/Debug.h" |
| 33 | #include "llvm/Support/ErrorHandling.h" |
| 34 | #include "llvm/Support/raw_ostream.h" |
| 35 | #include "llvm/Target/TargetInstrInfo.h" |
| 36 | #include "llvm/Target/TargetMachine.h" |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 37 | #include <algorithm> |
| 38 | using namespace llvm; |
| 39 | |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 40 | #define DEBUG_TYPE "regalloc" |
| 41 | |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 42 | STATISTIC(NumStores, "Number of stores added"); |
| 43 | STATISTIC(NumLoads , "Number of loads added"); |
Jakob Stoklund Olesen | 8a65c51 | 2010-05-14 21:55:50 +0000 | [diff] [blame] | 44 | STATISTIC(NumCopies, "Number of copies coalesced"); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 45 | |
| 46 | static RegisterRegAlloc |
| 47 | fastRegAlloc("fast", "fast register allocator", createFastRegisterAllocator); |
| 48 | |
| 49 | namespace { |
| 50 | class RAFast : public MachineFunctionPass { |
| 51 | public: |
| 52 | static char ID; |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 53 | RAFast() : MachineFunctionPass(ID), StackSlotForVirtReg(-1), |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 54 | isBulkSpilling(false) {} |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 55 | private: |
| 56 | const TargetMachine *TM; |
| 57 | MachineFunction *MF; |
Jakob Stoklund Olesen | 4bf4baf | 2010-05-13 00:19:43 +0000 | [diff] [blame] | 58 | MachineRegisterInfo *MRI; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 59 | const TargetRegisterInfo *TRI; |
| 60 | const TargetInstrInfo *TII; |
Jakob Stoklund Olesen | 5d20c31 | 2011-06-02 18:35:30 +0000 | [diff] [blame] | 61 | RegisterClassInfo RegClassInfo; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 62 | |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 63 | // Basic block currently being allocated. |
| 64 | MachineBasicBlock *MBB; |
| 65 | |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 66 | // StackSlotForVirtReg - Maps virtual regs to the frame index where these |
| 67 | // values are spilled. |
| 68 | IndexedMap<int, VirtReg2IndexFunctor> StackSlotForVirtReg; |
| 69 | |
Jakob Stoklund Olesen | 76b4d5a | 2010-05-11 23:24:45 +0000 | [diff] [blame] | 70 | // Everything we know about a live virtual register. |
| 71 | struct LiveReg { |
Jakob Stoklund Olesen | 210e2af | 2010-05-11 23:24:47 +0000 | [diff] [blame] | 72 | MachineInstr *LastUse; // Last instr to use reg. |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 73 | unsigned VirtReg; // Virtual register number. |
Jakob Stoklund Olesen | 210e2af | 2010-05-11 23:24:47 +0000 | [diff] [blame] | 74 | unsigned PhysReg; // Currently held here. |
| 75 | unsigned short LastOpNum; // OpNum on LastUse. |
| 76 | bool Dirty; // Register needs spill. |
Jakob Stoklund Olesen | 76b4d5a | 2010-05-11 23:24:45 +0000 | [diff] [blame] | 77 | |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 78 | explicit LiveReg(unsigned v) |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 79 | : LastUse(nullptr), VirtReg(v), PhysReg(0), LastOpNum(0), Dirty(false){} |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 80 | |
Andrew Trick | c0ccb8b | 2012-04-20 20:05:28 +0000 | [diff] [blame] | 81 | unsigned getSparseSetIndex() const { |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 82 | return TargetRegisterInfo::virtReg2Index(VirtReg); |
| 83 | } |
Jakob Stoklund Olesen | 76b4d5a | 2010-05-11 23:24:45 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 86 | typedef SparseSet<LiveReg> LiveRegMap; |
Jakob Stoklund Olesen | 76b4d5a | 2010-05-11 23:24:45 +0000 | [diff] [blame] | 87 | |
| 88 | // LiveVirtRegs - This map contains entries for each virtual register |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 89 | // that is currently available in a physical register. |
Jakob Stoklund Olesen | 76b4d5a | 2010-05-11 23:24:45 +0000 | [diff] [blame] | 90 | LiveRegMap LiveVirtRegs; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 91 | |
Devang Patel | 72d9b0e | 2011-06-21 22:36:03 +0000 | [diff] [blame] | 92 | DenseMap<unsigned, SmallVector<MachineInstr *, 4> > LiveDbgValueMap; |
Devang Patel | 459a36b | 2010-08-04 18:42:02 +0000 | [diff] [blame] | 93 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 94 | // RegState - Track the state of a physical register. |
| 95 | enum RegState { |
| 96 | // A disabled register is not available for allocation, but an alias may |
| 97 | // be in use. A register can only be moved out of the disabled state if |
| 98 | // all aliases are disabled. |
| 99 | regDisabled, |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 100 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 101 | // A free register is not currently in use and can be allocated |
| 102 | // immediately without checking aliases. |
| 103 | regFree, |
| 104 | |
Evan Cheng | d8a1624 | 2011-04-22 01:40:20 +0000 | [diff] [blame] | 105 | // A reserved register has been assigned explicitly (e.g., setting up a |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 106 | // call parameter), and it remains reserved until it is used. |
| 107 | regReserved |
| 108 | |
| 109 | // A register state may also be a virtual register number, indication that |
| 110 | // the physical register is currently allocated to a virtual register. In |
Jakob Stoklund Olesen | 76b4d5a | 2010-05-11 23:24:45 +0000 | [diff] [blame] | 111 | // that case, LiveVirtRegs contains the inverse mapping. |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | // PhysRegState - One of the RegState enums, or a virtreg. |
| 115 | std::vector<unsigned> PhysRegState; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 116 | |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 117 | // Set of register units. |
Jakob Stoklund Olesen | d7ea7d5 | 2012-10-17 01:37:59 +0000 | [diff] [blame] | 118 | typedef SparseSet<unsigned> UsedInInstrSet; |
| 119 | |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 120 | // Set of register units that are used in the current instruction, and so |
| 121 | // cannot be allocated. |
Jakob Stoklund Olesen | d7ea7d5 | 2012-10-17 01:37:59 +0000 | [diff] [blame] | 122 | UsedInInstrSet UsedInInstr; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 123 | |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 124 | // Mark a physreg as used in this instruction. |
| 125 | void markRegUsedInInstr(unsigned PhysReg) { |
| 126 | for (MCRegUnitIterator Units(PhysReg, TRI); Units.isValid(); ++Units) |
| 127 | UsedInInstr.insert(*Units); |
| 128 | } |
| 129 | |
| 130 | // Check if a physreg or any of its aliases are used in this instruction. |
| 131 | bool isRegUsedInInstr(unsigned PhysReg) const { |
| 132 | for (MCRegUnitIterator Units(PhysReg, TRI); Units.isValid(); ++Units) |
| 133 | if (UsedInInstr.count(*Units)) |
| 134 | return true; |
| 135 | return false; |
| 136 | } |
| 137 | |
Jim Grosbach | 07cb689 | 2010-09-01 19:16:29 +0000 | [diff] [blame] | 138 | // SkippedInstrs - Descriptors of instructions whose clobber list was |
| 139 | // ignored because all registers were spilled. It is still necessary to |
| 140 | // mark all the clobbered registers as used by the function. |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 141 | SmallPtrSet<const MCInstrDesc*, 4> SkippedInstrs; |
Jakob Stoklund Olesen | 6de0717 | 2010-06-04 18:08:29 +0000 | [diff] [blame] | 142 | |
Jakob Stoklund Olesen | e6aba83 | 2010-05-17 02:07:32 +0000 | [diff] [blame] | 143 | // isBulkSpilling - This flag is set when LiveRegMap will be cleared |
| 144 | // completely after spilling all live registers. LiveRegMap entries should |
| 145 | // not be erased. |
| 146 | bool isBulkSpilling; |
Jakob Stoklund Olesen | 7d4f259 | 2010-05-14 00:02:20 +0000 | [diff] [blame] | 147 | |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 148 | enum : unsigned { |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 149 | spillClean = 1, |
| 150 | spillDirty = 100, |
| 151 | spillImpossible = ~0u |
| 152 | }; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 153 | public: |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 154 | const char *getPassName() const override { |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 155 | return "Fast Register Allocator"; |
| 156 | } |
| 157 | |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 158 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 159 | AU.setPreservesCFG(); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 160 | MachineFunctionPass::getAnalysisUsage(AU); |
| 161 | } |
| 162 | |
| 163 | private: |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 164 | bool runOnMachineFunction(MachineFunction &Fn) override; |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 165 | void AllocateBasicBlock(); |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 166 | void handleThroughOperands(MachineInstr *MI, |
| 167 | SmallVectorImpl<unsigned> &VirtDead); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 168 | int getStackSpaceFor(unsigned VirtReg, const TargetRegisterClass *RC); |
Jakob Stoklund Olesen | 1e03ff4 | 2010-05-15 06:09:08 +0000 | [diff] [blame] | 169 | bool isLastUseOfLocalReg(MachineOperand&); |
| 170 | |
Jakob Stoklund Olesen | 01dcbf8 | 2010-05-17 02:07:29 +0000 | [diff] [blame] | 171 | void addKillFlag(const LiveReg&); |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 172 | void killVirtReg(LiveRegMap::iterator); |
Jakob Stoklund Olesen | 804291e | 2010-05-12 18:46:03 +0000 | [diff] [blame] | 173 | void killVirtReg(unsigned VirtReg); |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 174 | void spillVirtReg(MachineBasicBlock::iterator MI, LiveRegMap::iterator); |
Jakob Stoklund Olesen | e6aba83 | 2010-05-17 02:07:32 +0000 | [diff] [blame] | 175 | void spillVirtReg(MachineBasicBlock::iterator MI, unsigned VirtReg); |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 176 | |
| 177 | void usePhysReg(MachineOperand&); |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 178 | void definePhysReg(MachineInstr *MI, unsigned PhysReg, RegState NewState); |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 179 | unsigned calcSpillCost(unsigned PhysReg) const; |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 180 | void assignVirtToPhysReg(LiveReg&, unsigned PhysReg); |
| 181 | LiveRegMap::iterator findLiveVirtReg(unsigned VirtReg) { |
| 182 | return LiveVirtRegs.find(TargetRegisterInfo::virtReg2Index(VirtReg)); |
| 183 | } |
| 184 | LiveRegMap::const_iterator findLiveVirtReg(unsigned VirtReg) const { |
| 185 | return LiveVirtRegs.find(TargetRegisterInfo::virtReg2Index(VirtReg)); |
| 186 | } |
| 187 | LiveRegMap::iterator assignVirtToPhysReg(unsigned VReg, unsigned PhysReg); |
| 188 | LiveRegMap::iterator allocVirtReg(MachineInstr *MI, LiveRegMap::iterator, |
| 189 | unsigned Hint); |
Jakob Stoklund Olesen | 646dd7c | 2010-05-17 03:26:09 +0000 | [diff] [blame] | 190 | LiveRegMap::iterator defineVirtReg(MachineInstr *MI, unsigned OpNum, |
| 191 | unsigned VirtReg, unsigned Hint); |
| 192 | LiveRegMap::iterator reloadVirtReg(MachineInstr *MI, unsigned OpNum, |
| 193 | unsigned VirtReg, unsigned Hint); |
Akira Hatanaka | bab2421 | 2012-10-31 00:56:01 +0000 | [diff] [blame] | 194 | void spillAll(MachineBasicBlock::iterator MI); |
Jakob Stoklund Olesen | 0eeb05c | 2010-05-18 21:10:50 +0000 | [diff] [blame] | 195 | bool setPhysReg(MachineInstr *MI, unsigned OpNum, unsigned PhysReg); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 196 | }; |
| 197 | char RAFast::ID = 0; |
| 198 | } |
| 199 | |
| 200 | /// getStackSpaceFor - This allocates space for the specified virtual register |
| 201 | /// to be held on the stack. |
| 202 | int RAFast::getStackSpaceFor(unsigned VirtReg, const TargetRegisterClass *RC) { |
| 203 | // Find the location Reg would belong... |
| 204 | int SS = StackSlotForVirtReg[VirtReg]; |
| 205 | if (SS != -1) |
| 206 | return SS; // Already has space allocated? |
| 207 | |
| 208 | // Allocate a new stack object for this spill location... |
| 209 | int FrameIdx = MF->getFrameInfo()->CreateSpillStackObject(RC->getSize(), |
| 210 | RC->getAlignment()); |
| 211 | |
| 212 | // Assign the slot. |
| 213 | StackSlotForVirtReg[VirtReg] = FrameIdx; |
| 214 | return FrameIdx; |
| 215 | } |
| 216 | |
Jakob Stoklund Olesen | 1e03ff4 | 2010-05-15 06:09:08 +0000 | [diff] [blame] | 217 | /// isLastUseOfLocalReg - Return true if MO is the only remaining reference to |
| 218 | /// its virtual register, and it is guaranteed to be a block-local register. |
| 219 | /// |
| 220 | bool RAFast::isLastUseOfLocalReg(MachineOperand &MO) { |
Jakob Stoklund Olesen | 1e03ff4 | 2010-05-15 06:09:08 +0000 | [diff] [blame] | 221 | // If the register has ever been spilled or reloaded, we conservatively assume |
| 222 | // it is a global register used in multiple blocks. |
| 223 | if (StackSlotForVirtReg[MO.getReg()] != -1) |
| 224 | return false; |
| 225 | |
| 226 | // Check that the use/def chain has exactly one operand - MO. |
Jakob Stoklund Olesen | 4e69662 | 2012-08-08 23:44:01 +0000 | [diff] [blame] | 227 | MachineRegisterInfo::reg_nodbg_iterator I = MRI->reg_nodbg_begin(MO.getReg()); |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 228 | if (&*I != &MO) |
Jakob Stoklund Olesen | 4e69662 | 2012-08-08 23:44:01 +0000 | [diff] [blame] | 229 | return false; |
| 230 | return ++I == MRI->reg_nodbg_end(); |
Jakob Stoklund Olesen | 1e03ff4 | 2010-05-15 06:09:08 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Jakob Stoklund Olesen | 804291e | 2010-05-12 18:46:03 +0000 | [diff] [blame] | 233 | /// addKillFlag - Set kill flags on last use of a virtual register. |
Jakob Stoklund Olesen | 01dcbf8 | 2010-05-17 02:07:29 +0000 | [diff] [blame] | 234 | void RAFast::addKillFlag(const LiveReg &LR) { |
| 235 | if (!LR.LastUse) return; |
| 236 | MachineOperand &MO = LR.LastUse->getOperand(LR.LastOpNum); |
Jakob Stoklund Olesen | d32e735 | 2010-05-19 21:36:05 +0000 | [diff] [blame] | 237 | if (MO.isUse() && !LR.LastUse->isRegTiedToDefOperand(LR.LastOpNum)) { |
| 238 | if (MO.getReg() == LR.PhysReg) |
Jakob Stoklund Olesen | 0eeb05c | 2010-05-18 21:10:50 +0000 | [diff] [blame] | 239 | MO.setIsKill(); |
Jakob Stoklund Olesen | 0eeb05c | 2010-05-18 21:10:50 +0000 | [diff] [blame] | 240 | else |
| 241 | LR.LastUse->addRegisterKilled(LR.PhysReg, TRI, true); |
| 242 | } |
Jakob Stoklund Olesen | 804291e | 2010-05-12 18:46:03 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /// killVirtReg - Mark virtreg as no longer available. |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 246 | void RAFast::killVirtReg(LiveRegMap::iterator LRI) { |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 247 | addKillFlag(*LRI); |
Jakob Stoklund Olesen | 91ba63d | 2012-02-22 16:50:46 +0000 | [diff] [blame] | 248 | assert(PhysRegState[LRI->PhysReg] == LRI->VirtReg && |
| 249 | "Broken RegState mapping"); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 250 | PhysRegState[LRI->PhysReg] = regFree; |
Jakob Stoklund Olesen | e6aba83 | 2010-05-17 02:07:32 +0000 | [diff] [blame] | 251 | // Erase from LiveVirtRegs unless we're spilling in bulk. |
| 252 | if (!isBulkSpilling) |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 253 | LiveVirtRegs.erase(LRI); |
Jakob Stoklund Olesen | 76b4d5a | 2010-05-11 23:24:45 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /// killVirtReg - Mark virtreg as no longer available. |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 257 | void RAFast::killVirtReg(unsigned VirtReg) { |
| 258 | assert(TargetRegisterInfo::isVirtualRegister(VirtReg) && |
| 259 | "killVirtReg needs a virtual register"); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 260 | LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg); |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 261 | if (LRI != LiveVirtRegs.end()) |
| 262 | killVirtReg(LRI); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 265 | /// spillVirtReg - This method spills the value specified by VirtReg into the |
Eli Friedman | 24a1182 | 2010-08-21 20:19:51 +0000 | [diff] [blame] | 266 | /// corresponding stack slot if needed. |
Jakob Stoklund Olesen | e6aba83 | 2010-05-17 02:07:32 +0000 | [diff] [blame] | 267 | void RAFast::spillVirtReg(MachineBasicBlock::iterator MI, unsigned VirtReg) { |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 268 | assert(TargetRegisterInfo::isVirtualRegister(VirtReg) && |
| 269 | "Spilling a physical register is illegal!"); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 270 | LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg); |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 271 | assert(LRI != LiveVirtRegs.end() && "Spilling unmapped virtual register"); |
| 272 | spillVirtReg(MI, LRI); |
Jakob Stoklund Olesen | 7d4f259 | 2010-05-14 00:02:20 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | /// spillVirtReg - Do the actual work of spilling. |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 276 | void RAFast::spillVirtReg(MachineBasicBlock::iterator MI, |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 277 | LiveRegMap::iterator LRI) { |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 278 | LiveReg &LR = *LRI; |
| 279 | assert(PhysRegState[LR.PhysReg] == LRI->VirtReg && "Broken RegState mapping"); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 280 | |
Jakob Stoklund Olesen | 210e2af | 2010-05-11 23:24:47 +0000 | [diff] [blame] | 281 | if (LR.Dirty) { |
Jakob Stoklund Olesen | e6aba83 | 2010-05-17 02:07:32 +0000 | [diff] [blame] | 282 | // If this physreg is used by the instruction, we want to kill it on the |
| 283 | // instruction, not on the spill. |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 284 | bool SpillKill = LR.LastUse != MI; |
Jakob Stoklund Olesen | 210e2af | 2010-05-11 23:24:47 +0000 | [diff] [blame] | 285 | LR.Dirty = false; |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 286 | DEBUG(dbgs() << "Spilling " << PrintReg(LRI->VirtReg, TRI) |
Jakob Stoklund Olesen | 4314268 | 2011-01-09 03:05:53 +0000 | [diff] [blame] | 287 | << " in " << PrintReg(LR.PhysReg, TRI)); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 288 | const TargetRegisterClass *RC = MRI->getRegClass(LRI->VirtReg); |
| 289 | int FI = getStackSpaceFor(LRI->VirtReg, RC); |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 290 | DEBUG(dbgs() << " to stack slot #" << FI << "\n"); |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 291 | TII->storeRegToStackSlot(*MBB, MI, LR.PhysReg, SpillKill, FI, RC, TRI); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 292 | ++NumStores; // Update statistics |
Jakob Stoklund Olesen | 76b4d5a | 2010-05-11 23:24:45 +0000 | [diff] [blame] | 293 | |
Jim Grosbach | 07cb689 | 2010-09-01 19:16:29 +0000 | [diff] [blame] | 294 | // If this register is used by DBG_VALUE then insert new DBG_VALUE to |
Devang Patel | 459a36b | 2010-08-04 18:42:02 +0000 | [diff] [blame] | 295 | // identify spilled location as the place to find corresponding variable's |
| 296 | // value. |
Craig Topper | a0ec3f9 | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 297 | SmallVectorImpl<MachineInstr *> &LRIDbgValues = |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 298 | LiveDbgValueMap[LRI->VirtReg]; |
Devang Patel | 72d9b0e | 2011-06-21 22:36:03 +0000 | [diff] [blame] | 299 | for (unsigned li = 0, le = LRIDbgValues.size(); li != le; ++li) { |
| 300 | MachineInstr *DBG = LRIDbgValues[li]; |
David Blaikie | 6d9dbd5 | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 301 | const MDNode *MDPtr = DBG->getOperand(2).getMetadata(); |
Adrian Prantl | 818833f | 2013-09-16 23:29:03 +0000 | [diff] [blame] | 302 | bool IsIndirect = DBG->isIndirectDebugValue(); |
Adrian Prantl | 43ae5e8 | 2013-07-10 16:56:52 +0000 | [diff] [blame] | 303 | uint64_t Offset = IsIndirect ? DBG->getOperand(1).getImm() : 0; |
Devang Patel | 31defcf | 2010-08-06 00:26:18 +0000 | [diff] [blame] | 304 | DebugLoc DL; |
| 305 | if (MI == MBB->end()) { |
| 306 | // If MI is at basic block end then use last instruction's location. |
| 307 | MachineBasicBlock::iterator EI = MI; |
| 308 | DL = (--EI)->getDebugLoc(); |
David Blaikie | 6d9dbd5 | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 309 | } else |
Devang Patel | 31defcf | 2010-08-06 00:26:18 +0000 | [diff] [blame] | 310 | DL = MI->getDebugLoc(); |
David Blaikie | 6d9dbd5 | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 311 | MachineBasicBlock *MBB = DBG->getParent(); |
| 312 | MachineInstr *NewDV = |
| 313 | BuildMI(*MBB, MI, DL, TII->get(TargetOpcode::DBG_VALUE)) |
| 314 | .addFrameIndex(FI).addImm(Offset).addMetadata(MDPtr); |
| 315 | (void)NewDV; |
| 316 | DEBUG(dbgs() << "Inserting debug info due to spill:" << "\n" << *NewDV); |
Devang Patel | 459a36b | 2010-08-04 18:42:02 +0000 | [diff] [blame] | 317 | } |
Jakob Stoklund Olesen | 91ba63d | 2012-02-22 16:50:46 +0000 | [diff] [blame] | 318 | // Now this register is spilled there is should not be any DBG_VALUE |
| 319 | // pointing to this register because they are all pointing to spilled value |
| 320 | // now. |
Devang Patel | 6f373a8 | 2011-06-21 23:02:36 +0000 | [diff] [blame] | 321 | LRIDbgValues.clear(); |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 322 | if (SpillKill) |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame^] | 323 | LR.LastUse = nullptr; // Don't kill register again |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 324 | } |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 325 | killVirtReg(LRI); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 328 | /// spillAll - Spill all dirty virtregs without killing them. |
Akira Hatanaka | bab2421 | 2012-10-31 00:56:01 +0000 | [diff] [blame] | 329 | void RAFast::spillAll(MachineBasicBlock::iterator MI) { |
Jakob Stoklund Olesen | f3ea06b | 2010-05-17 15:30:37 +0000 | [diff] [blame] | 330 | if (LiveVirtRegs.empty()) return; |
Jakob Stoklund Olesen | e6aba83 | 2010-05-17 02:07:32 +0000 | [diff] [blame] | 331 | isBulkSpilling = true; |
Jakob Stoklund Olesen | 2997985 | 2010-05-17 20:01:22 +0000 | [diff] [blame] | 332 | // The LiveRegMap is keyed by an unsigned (the virtreg number), so the order |
| 333 | // of spilling here is deterministic, if arbitrary. |
| 334 | for (LiveRegMap::iterator i = LiveVirtRegs.begin(), e = LiveVirtRegs.end(); |
| 335 | i != e; ++i) |
Jakob Stoklund Olesen | e6aba83 | 2010-05-17 02:07:32 +0000 | [diff] [blame] | 336 | spillVirtReg(MI, i); |
| 337 | LiveVirtRegs.clear(); |
| 338 | isBulkSpilling = false; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 339 | } |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 340 | |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 341 | /// usePhysReg - Handle the direct use of a physical register. |
| 342 | /// Check that the register is not used by a virtreg. |
| 343 | /// Kill the physreg, marking it free. |
| 344 | /// This may add implicit kills to MO->getParent() and invalidate MO. |
| 345 | void RAFast::usePhysReg(MachineOperand &MO) { |
| 346 | unsigned PhysReg = MO.getReg(); |
| 347 | assert(TargetRegisterInfo::isPhysicalRegister(PhysReg) && |
| 348 | "Bad usePhysReg operand"); |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 349 | markRegUsedInInstr(PhysReg); |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 350 | switch (PhysRegState[PhysReg]) { |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 351 | case regDisabled: |
| 352 | break; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 353 | case regReserved: |
| 354 | PhysRegState[PhysReg] = regFree; |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 355 | // Fall through |
| 356 | case regFree: |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 357 | MO.setIsKill(); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 358 | return; |
| 359 | default: |
Eric Christopher | f299da8 | 2010-12-08 21:35:09 +0000 | [diff] [blame] | 360 | // The physreg was allocated to a virtual register. That means the value we |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 361 | // wanted has been clobbered. |
| 362 | llvm_unreachable("Instruction uses an allocated register"); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 365 | // Maybe a superregister is reserved? |
Jakob Stoklund Olesen | 396618b | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 366 | for (MCRegAliasIterator AI(PhysReg, TRI, false); AI.isValid(); ++AI) { |
| 367 | unsigned Alias = *AI; |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 368 | switch (PhysRegState[Alias]) { |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 369 | case regDisabled: |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 370 | break; |
| 371 | case regReserved: |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 372 | assert(TRI->isSuperRegister(PhysReg, Alias) && |
| 373 | "Instruction is not using a subregister of a reserved register"); |
| 374 | // Leave the superregister in the working set. |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 375 | PhysRegState[Alias] = regFree; |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 376 | MO.getParent()->addRegisterKilled(Alias, TRI, true); |
| 377 | return; |
| 378 | case regFree: |
| 379 | if (TRI->isSuperRegister(PhysReg, Alias)) { |
| 380 | // Leave the superregister in the working set. |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 381 | MO.getParent()->addRegisterKilled(Alias, TRI, true); |
| 382 | return; |
| 383 | } |
| 384 | // Some other alias was in the working set - clear it. |
| 385 | PhysRegState[Alias] = regDisabled; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 386 | break; |
| 387 | default: |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 388 | llvm_unreachable("Instruction uses an alias of an allocated register"); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 389 | } |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 390 | } |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 391 | |
| 392 | // All aliases are disabled, bring register into working set. |
| 393 | PhysRegState[PhysReg] = regFree; |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 394 | MO.setIsKill(); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 397 | /// definePhysReg - Mark PhysReg as reserved or free after spilling any |
| 398 | /// virtregs. This is very similar to defineVirtReg except the physreg is |
| 399 | /// reserved instead of allocated. |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 400 | void RAFast::definePhysReg(MachineInstr *MI, unsigned PhysReg, |
| 401 | RegState NewState) { |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 402 | markRegUsedInInstr(PhysReg); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 403 | switch (unsigned VirtReg = PhysRegState[PhysReg]) { |
| 404 | case regDisabled: |
| 405 | break; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 406 | default: |
Jakob Stoklund Olesen | e6aba83 | 2010-05-17 02:07:32 +0000 | [diff] [blame] | 407 | spillVirtReg(MI, VirtReg); |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 408 | // Fall through. |
| 409 | case regFree: |
| 410 | case regReserved: |
| 411 | PhysRegState[PhysReg] = NewState; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 412 | return; |
| 413 | } |
| 414 | |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 415 | // This is a disabled register, disable all aliases. |
| 416 | PhysRegState[PhysReg] = NewState; |
Jakob Stoklund Olesen | 396618b | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 417 | for (MCRegAliasIterator AI(PhysReg, TRI, false); AI.isValid(); ++AI) { |
| 418 | unsigned Alias = *AI; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 419 | switch (unsigned VirtReg = PhysRegState[Alias]) { |
| 420 | case regDisabled: |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 421 | break; |
| 422 | default: |
Jakob Stoklund Olesen | e6aba83 | 2010-05-17 02:07:32 +0000 | [diff] [blame] | 423 | spillVirtReg(MI, VirtReg); |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 424 | // Fall through. |
| 425 | case regFree: |
| 426 | case regReserved: |
| 427 | PhysRegState[Alias] = regDisabled; |
| 428 | if (TRI->isSuperRegister(PhysReg, Alias)) |
| 429 | return; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 430 | break; |
| 431 | } |
| 432 | } |
| 433 | } |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 434 | |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 435 | |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 436 | // calcSpillCost - Return the cost of spilling clearing out PhysReg and |
| 437 | // aliases so it is free for allocation. |
| 438 | // Returns 0 when PhysReg is free or disabled with all aliases disabled - it |
| 439 | // can be allocated directly. |
| 440 | // Returns spillImpossible when PhysReg or an alias can't be spilled. |
| 441 | unsigned RAFast::calcSpillCost(unsigned PhysReg) const { |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 442 | if (isRegUsedInInstr(PhysReg)) { |
Jakob Stoklund Olesen | 27ce3b9 | 2011-06-28 17:24:32 +0000 | [diff] [blame] | 443 | DEBUG(dbgs() << PrintReg(PhysReg, TRI) << " is already used in instr.\n"); |
Jakob Stoklund Olesen | b8acb7b | 2010-05-17 21:02:08 +0000 | [diff] [blame] | 444 | return spillImpossible; |
Eric Christopher | 0b75634 | 2011-04-12 22:17:44 +0000 | [diff] [blame] | 445 | } |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 446 | switch (unsigned VirtReg = PhysRegState[PhysReg]) { |
| 447 | case regDisabled: |
| 448 | break; |
| 449 | case regFree: |
| 450 | return 0; |
| 451 | case regReserved: |
Jakob Stoklund Olesen | 27ce3b9 | 2011-06-28 17:24:32 +0000 | [diff] [blame] | 452 | DEBUG(dbgs() << PrintReg(VirtReg, TRI) << " corresponding " |
| 453 | << PrintReg(PhysReg, TRI) << " is reserved already.\n"); |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 454 | return spillImpossible; |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 455 | default: { |
| 456 | LiveRegMap::const_iterator I = findLiveVirtReg(VirtReg); |
| 457 | assert(I != LiveVirtRegs.end() && "Missing VirtReg entry"); |
| 458 | return I->Dirty ? spillDirty : spillClean; |
| 459 | } |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Eric Christopher | bbfc3b3 | 2011-04-12 00:48:08 +0000 | [diff] [blame] | 462 | // This is a disabled register, add up cost of aliases. |
Jakob Stoklund Olesen | 27ce3b9 | 2011-06-28 17:24:32 +0000 | [diff] [blame] | 463 | DEBUG(dbgs() << PrintReg(PhysReg, TRI) << " is disabled.\n"); |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 464 | unsigned Cost = 0; |
Jakob Stoklund Olesen | 396618b | 2012-06-01 23:28:30 +0000 | [diff] [blame] | 465 | for (MCRegAliasIterator AI(PhysReg, TRI, false); AI.isValid(); ++AI) { |
| 466 | unsigned Alias = *AI; |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 467 | switch (unsigned VirtReg = PhysRegState[Alias]) { |
| 468 | case regDisabled: |
| 469 | break; |
| 470 | case regFree: |
| 471 | ++Cost; |
| 472 | break; |
| 473 | case regReserved: |
| 474 | return spillImpossible; |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 475 | default: { |
| 476 | LiveRegMap::const_iterator I = findLiveVirtReg(VirtReg); |
| 477 | assert(I != LiveVirtRegs.end() && "Missing VirtReg entry"); |
| 478 | Cost += I->Dirty ? spillDirty : spillClean; |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 479 | break; |
| 480 | } |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 481 | } |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 482 | } |
| 483 | return Cost; |
| 484 | } |
| 485 | |
| 486 | |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 487 | /// assignVirtToPhysReg - This method updates local state so that we know |
| 488 | /// that PhysReg is the proper container for VirtReg now. The physical |
| 489 | /// register must not be used for anything else when this is called. |
| 490 | /// |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 491 | void RAFast::assignVirtToPhysReg(LiveReg &LR, unsigned PhysReg) { |
| 492 | DEBUG(dbgs() << "Assigning " << PrintReg(LR.VirtReg, TRI) << " to " |
Jakob Stoklund Olesen | 4314268 | 2011-01-09 03:05:53 +0000 | [diff] [blame] | 493 | << PrintReg(PhysReg, TRI) << "\n"); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 494 | PhysRegState[PhysReg] = LR.VirtReg; |
| 495 | assert(!LR.PhysReg && "Already assigned a physreg"); |
| 496 | LR.PhysReg = PhysReg; |
| 497 | } |
| 498 | |
| 499 | RAFast::LiveRegMap::iterator |
| 500 | RAFast::assignVirtToPhysReg(unsigned VirtReg, unsigned PhysReg) { |
| 501 | LiveRegMap::iterator LRI = findLiveVirtReg(VirtReg); |
| 502 | assert(LRI != LiveVirtRegs.end() && "VirtReg disappeared"); |
| 503 | assignVirtToPhysReg(*LRI, PhysReg); |
| 504 | return LRI; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 507 | /// allocVirtReg - Allocate a physical register for VirtReg. |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 508 | RAFast::LiveRegMap::iterator RAFast::allocVirtReg(MachineInstr *MI, |
| 509 | LiveRegMap::iterator LRI, |
| 510 | unsigned Hint) { |
| 511 | const unsigned VirtReg = LRI->VirtReg; |
Jakob Stoklund Olesen | 01dcbf8 | 2010-05-17 02:07:29 +0000 | [diff] [blame] | 512 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 513 | assert(TargetRegisterInfo::isVirtualRegister(VirtReg) && |
| 514 | "Can only allocate virtual registers"); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 515 | |
Jakob Stoklund Olesen | 4bf4baf | 2010-05-13 00:19:43 +0000 | [diff] [blame] | 516 | const TargetRegisterClass *RC = MRI->getRegClass(VirtReg); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 517 | |
Jakob Stoklund Olesen | 4bf4baf | 2010-05-13 00:19:43 +0000 | [diff] [blame] | 518 | // Ignore invalid hints. |
| 519 | if (Hint && (!TargetRegisterInfo::isPhysicalRegister(Hint) || |
Jakob Stoklund Olesen | 14d1dd9 | 2012-10-15 22:41:03 +0000 | [diff] [blame] | 520 | !RC->contains(Hint) || !MRI->isAllocatable(Hint))) |
Jakob Stoklund Olesen | 4bf4baf | 2010-05-13 00:19:43 +0000 | [diff] [blame] | 521 | Hint = 0; |
| 522 | |
Jakob Stoklund Olesen | 4bf4baf | 2010-05-13 00:19:43 +0000 | [diff] [blame] | 523 | // Take hint when possible. |
| 524 | if (Hint) { |
Jakob Stoklund Olesen | 5e5ed44 | 2011-06-13 03:26:46 +0000 | [diff] [blame] | 525 | // Ignore the hint if we would have to spill a dirty register. |
| 526 | unsigned Cost = calcSpillCost(Hint); |
| 527 | if (Cost < spillDirty) { |
| 528 | if (Cost) |
| 529 | definePhysReg(MI, Hint, regFree); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 530 | // definePhysReg may kill virtual registers and modify LiveVirtRegs. |
| 531 | // That invalidates LRI, so run a new lookup for VirtReg. |
| 532 | return assignVirtToPhysReg(VirtReg, Hint); |
Jakob Stoklund Olesen | 4bf4baf | 2010-05-13 00:19:43 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
Jakob Stoklund Olesen | 39b5c0c | 2012-11-29 03:34:17 +0000 | [diff] [blame] | 536 | ArrayRef<MCPhysReg> AO = RegClassInfo.getOrder(RC); |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 537 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 538 | // First try to find a completely free register. |
Jakob Stoklund Olesen | 39b5c0c | 2012-11-29 03:34:17 +0000 | [diff] [blame] | 539 | for (ArrayRef<MCPhysReg>::iterator I = AO.begin(), E = AO.end(); I != E; ++I){ |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 540 | unsigned PhysReg = *I; |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 541 | if (PhysRegState[PhysReg] == regFree && !isRegUsedInInstr(PhysReg)) { |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 542 | assignVirtToPhysReg(*LRI, PhysReg); |
| 543 | return LRI; |
| 544 | } |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Jakob Stoklund Olesen | 4314268 | 2011-01-09 03:05:53 +0000 | [diff] [blame] | 547 | DEBUG(dbgs() << "Allocating " << PrintReg(VirtReg) << " from " |
| 548 | << RC->getName() << "\n"); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 549 | |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 550 | unsigned BestReg = 0, BestCost = spillImpossible; |
Jakob Stoklund Olesen | 39b5c0c | 2012-11-29 03:34:17 +0000 | [diff] [blame] | 551 | for (ArrayRef<MCPhysReg>::iterator I = AO.begin(), E = AO.end(); I != E; ++I){ |
Jakob Stoklund Olesen | 548643c | 2010-05-17 15:30:32 +0000 | [diff] [blame] | 552 | unsigned Cost = calcSpillCost(*I); |
Jakob Stoklund Olesen | 27ce3b9 | 2011-06-28 17:24:32 +0000 | [diff] [blame] | 553 | DEBUG(dbgs() << "\tRegister: " << PrintReg(*I, TRI) << "\n"); |
Eric Christopher | 0b75634 | 2011-04-12 22:17:44 +0000 | [diff] [blame] | 554 | DEBUG(dbgs() << "\tCost: " << Cost << "\n"); |
| 555 | DEBUG(dbgs() << "\tBestCost: " << BestCost << "\n"); |
Jakob Stoklund Olesen | f3ea06b | 2010-05-17 15:30:37 +0000 | [diff] [blame] | 556 | // Cost is 0 when all aliases are already disabled. |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 557 | if (Cost == 0) { |
| 558 | assignVirtToPhysReg(*LRI, *I); |
| 559 | return LRI; |
| 560 | } |
Jakob Stoklund Olesen | f3ea06b | 2010-05-17 15:30:37 +0000 | [diff] [blame] | 561 | if (Cost < BestCost) |
| 562 | BestReg = *I, BestCost = Cost; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | if (BestReg) { |
Jakob Stoklund Olesen | f3ea06b | 2010-05-17 15:30:37 +0000 | [diff] [blame] | 566 | definePhysReg(MI, BestReg, regFree); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 567 | // definePhysReg may kill virtual registers and modify LiveVirtRegs. |
| 568 | // That invalidates LRI, so run a new lookup for VirtReg. |
| 569 | return assignVirtToPhysReg(VirtReg, BestReg); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Jakob Stoklund Olesen | 9d812a2 | 2011-07-02 07:17:37 +0000 | [diff] [blame] | 572 | // Nothing we can do. Report an error and keep going with a bad allocation. |
Benjamin Kramer | 87855d3 | 2013-10-05 19:33:37 +0000 | [diff] [blame] | 573 | if (MI->isInlineAsm()) |
| 574 | MI->emitError("inline assembly requires more registers than available"); |
| 575 | else |
| 576 | MI->emitError("ran out of registers during register allocation"); |
Jakob Stoklund Olesen | 9d812a2 | 2011-07-02 07:17:37 +0000 | [diff] [blame] | 577 | definePhysReg(MI, *AO.begin(), regFree); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 578 | return assignVirtToPhysReg(VirtReg, *AO.begin()); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 581 | /// defineVirtReg - Allocate a register for VirtReg and mark it as dirty. |
Jakob Stoklund Olesen | 646dd7c | 2010-05-17 03:26:09 +0000 | [diff] [blame] | 582 | RAFast::LiveRegMap::iterator |
| 583 | RAFast::defineVirtReg(MachineInstr *MI, unsigned OpNum, |
| 584 | unsigned VirtReg, unsigned Hint) { |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 585 | assert(TargetRegisterInfo::isVirtualRegister(VirtReg) && |
| 586 | "Not a virtual register"); |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 587 | LiveRegMap::iterator LRI; |
Jakob Stoklund Olesen | 01dcbf8 | 2010-05-17 02:07:29 +0000 | [diff] [blame] | 588 | bool New; |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 589 | std::tie(LRI, New) = LiveVirtRegs.insert(LiveReg(VirtReg)); |
Jakob Stoklund Olesen | 0c9e4f5 | 2010-05-17 04:50:57 +0000 | [diff] [blame] | 590 | if (New) { |
| 591 | // If there is no hint, peek at the only use of this register. |
| 592 | if ((!Hint || !TargetRegisterInfo::isPhysicalRegister(Hint)) && |
| 593 | MRI->hasOneNonDBGUse(VirtReg)) { |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 594 | const MachineInstr &UseMI = *MRI->use_instr_nodbg_begin(VirtReg); |
Jakob Stoklund Olesen | 0c9e4f5 | 2010-05-17 04:50:57 +0000 | [diff] [blame] | 595 | // It's a copy, use the destination register as a hint. |
Jakob Stoklund Olesen | 273f7e4 | 2010-07-03 00:04:37 +0000 | [diff] [blame] | 596 | if (UseMI.isCopyLike()) |
| 597 | Hint = UseMI.getOperand(0).getReg(); |
Jakob Stoklund Olesen | 0c9e4f5 | 2010-05-17 04:50:57 +0000 | [diff] [blame] | 598 | } |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 599 | LRI = allocVirtReg(MI, LRI, Hint); |
| 600 | } else if (LRI->LastUse) { |
Jakob Stoklund Olesen | 0eeb05c | 2010-05-18 21:10:50 +0000 | [diff] [blame] | 601 | // Redefining a live register - kill at the last use, unless it is this |
| 602 | // instruction defining VirtReg multiple times. |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 603 | if (LRI->LastUse != MI || LRI->LastUse->getOperand(LRI->LastOpNum).isUse()) |
| 604 | addKillFlag(*LRI); |
Jakob Stoklund Olesen | 0eeb05c | 2010-05-18 21:10:50 +0000 | [diff] [blame] | 605 | } |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 606 | assert(LRI->PhysReg && "Register not assigned"); |
| 607 | LRI->LastUse = MI; |
| 608 | LRI->LastOpNum = OpNum; |
| 609 | LRI->Dirty = true; |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 610 | markRegUsedInInstr(LRI->PhysReg); |
Jakob Stoklund Olesen | 646dd7c | 2010-05-17 03:26:09 +0000 | [diff] [blame] | 611 | return LRI; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 612 | } |
| 613 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 614 | /// reloadVirtReg - Make sure VirtReg is available in a physreg and return it. |
Jakob Stoklund Olesen | 646dd7c | 2010-05-17 03:26:09 +0000 | [diff] [blame] | 615 | RAFast::LiveRegMap::iterator |
| 616 | RAFast::reloadVirtReg(MachineInstr *MI, unsigned OpNum, |
| 617 | unsigned VirtReg, unsigned Hint) { |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 618 | assert(TargetRegisterInfo::isVirtualRegister(VirtReg) && |
| 619 | "Not a virtual register"); |
Jakob Stoklund Olesen | 844db9c | 2010-05-17 02:49:15 +0000 | [diff] [blame] | 620 | LiveRegMap::iterator LRI; |
Jakob Stoklund Olesen | 01dcbf8 | 2010-05-17 02:07:29 +0000 | [diff] [blame] | 621 | bool New; |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 622 | std::tie(LRI, New) = LiveVirtRegs.insert(LiveReg(VirtReg)); |
Jakob Stoklund Olesen | ac3e529 | 2010-05-17 03:26:06 +0000 | [diff] [blame] | 623 | MachineOperand &MO = MI->getOperand(OpNum); |
Jakob Stoklund Olesen | 01dcbf8 | 2010-05-17 02:07:29 +0000 | [diff] [blame] | 624 | if (New) { |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 625 | LRI = allocVirtReg(MI, LRI, Hint); |
Jakob Stoklund Olesen | 4bf4baf | 2010-05-13 00:19:43 +0000 | [diff] [blame] | 626 | const TargetRegisterClass *RC = MRI->getRegClass(VirtReg); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 627 | int FrameIndex = getStackSpaceFor(VirtReg, RC); |
Jakob Stoklund Olesen | 4314268 | 2011-01-09 03:05:53 +0000 | [diff] [blame] | 628 | DEBUG(dbgs() << "Reloading " << PrintReg(VirtReg, TRI) << " into " |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 629 | << PrintReg(LRI->PhysReg, TRI) << "\n"); |
| 630 | TII->loadRegFromStackSlot(*MBB, MI, LRI->PhysReg, FrameIndex, RC, TRI); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 631 | ++NumLoads; |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 632 | } else if (LRI->Dirty) { |
Jakob Stoklund Olesen | 1e03ff4 | 2010-05-15 06:09:08 +0000 | [diff] [blame] | 633 | if (isLastUseOfLocalReg(MO)) { |
| 634 | DEBUG(dbgs() << "Killing last use: " << MO << "\n"); |
Jakob Stoklund Olesen | d1303d2 | 2010-06-29 19:15:30 +0000 | [diff] [blame] | 635 | if (MO.isUse()) |
| 636 | MO.setIsKill(); |
| 637 | else |
| 638 | MO.setIsDead(); |
Jakob Stoklund Olesen | 1e03ff4 | 2010-05-15 06:09:08 +0000 | [diff] [blame] | 639 | } else if (MO.isKill()) { |
| 640 | DEBUG(dbgs() << "Clearing dubious kill: " << MO << "\n"); |
| 641 | MO.setIsKill(false); |
Jakob Stoklund Olesen | d1303d2 | 2010-06-29 19:15:30 +0000 | [diff] [blame] | 642 | } else if (MO.isDead()) { |
| 643 | DEBUG(dbgs() << "Clearing dubious dead: " << MO << "\n"); |
| 644 | MO.setIsDead(false); |
Jakob Stoklund Olesen | 1e03ff4 | 2010-05-15 06:09:08 +0000 | [diff] [blame] | 645 | } |
Jakob Stoklund Olesen | ac3e529 | 2010-05-17 03:26:06 +0000 | [diff] [blame] | 646 | } else if (MO.isKill()) { |
| 647 | // We must remove kill flags from uses of reloaded registers because the |
| 648 | // register would be killed immediately, and there might be a second use: |
| 649 | // %foo = OR %x<kill>, %x |
| 650 | // This would cause a second reload of %x into a different register. |
| 651 | DEBUG(dbgs() << "Clearing clean kill: " << MO << "\n"); |
| 652 | MO.setIsKill(false); |
Jakob Stoklund Olesen | d1303d2 | 2010-06-29 19:15:30 +0000 | [diff] [blame] | 653 | } else if (MO.isDead()) { |
| 654 | DEBUG(dbgs() << "Clearing clean dead: " << MO << "\n"); |
| 655 | MO.setIsDead(false); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 656 | } |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 657 | assert(LRI->PhysReg && "Register not assigned"); |
| 658 | LRI->LastUse = MI; |
| 659 | LRI->LastOpNum = OpNum; |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 660 | markRegUsedInInstr(LRI->PhysReg); |
Jakob Stoklund Olesen | 646dd7c | 2010-05-17 03:26:09 +0000 | [diff] [blame] | 661 | return LRI; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 662 | } |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 663 | |
Jakob Stoklund Olesen | 0eeb05c | 2010-05-18 21:10:50 +0000 | [diff] [blame] | 664 | // setPhysReg - Change operand OpNum in MI the refer the PhysReg, considering |
| 665 | // subregs. This may invalidate any operand pointers. |
| 666 | // Return true if the operand kills its register. |
| 667 | bool RAFast::setPhysReg(MachineInstr *MI, unsigned OpNum, unsigned PhysReg) { |
| 668 | MachineOperand &MO = MI->getOperand(OpNum); |
Jakob Stoklund Olesen | 6565a70 | 2012-05-14 21:30:58 +0000 | [diff] [blame] | 669 | bool Dead = MO.isDead(); |
Jakob Stoklund Olesen | 41e1401 | 2010-05-17 02:49:21 +0000 | [diff] [blame] | 670 | if (!MO.getSubReg()) { |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 671 | MO.setReg(PhysReg); |
Jakob Stoklund Olesen | 6565a70 | 2012-05-14 21:30:58 +0000 | [diff] [blame] | 672 | return MO.isKill() || Dead; |
Jakob Stoklund Olesen | 41e1401 | 2010-05-17 02:49:21 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | // Handle subregister index. |
| 676 | MO.setReg(PhysReg ? TRI->getSubReg(PhysReg, MO.getSubReg()) : 0); |
| 677 | MO.setSubReg(0); |
Jakob Stoklund Olesen | d32e735 | 2010-05-19 21:36:05 +0000 | [diff] [blame] | 678 | |
| 679 | // A kill flag implies killing the full register. Add corresponding super |
| 680 | // register kill. |
| 681 | if (MO.isKill()) { |
| 682 | MI->addRegisterKilled(PhysReg, TRI, true); |
Jakob Stoklund Olesen | 41e1401 | 2010-05-17 02:49:21 +0000 | [diff] [blame] | 683 | return true; |
| 684 | } |
Jakob Stoklund Olesen | 4d10829 | 2012-05-14 21:10:25 +0000 | [diff] [blame] | 685 | |
| 686 | // A <def,read-undef> of a sub-register requires an implicit def of the full |
| 687 | // register. |
| 688 | if (MO.isDef() && MO.isUndef()) |
| 689 | MI->addRegisterDefined(PhysReg, TRI); |
| 690 | |
Jakob Stoklund Olesen | 6565a70 | 2012-05-14 21:30:58 +0000 | [diff] [blame] | 691 | return Dead; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 692 | } |
| 693 | |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 694 | // Handle special instruction operand like early clobbers and tied ops when |
| 695 | // there are additional physreg defines. |
| 696 | void RAFast::handleThroughOperands(MachineInstr *MI, |
| 697 | SmallVectorImpl<unsigned> &VirtDead) { |
| 698 | DEBUG(dbgs() << "Scanning for through registers:"); |
| 699 | SmallSet<unsigned, 8> ThroughRegs; |
| 700 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 701 | MachineOperand &MO = MI->getOperand(i); |
| 702 | if (!MO.isReg()) continue; |
| 703 | unsigned Reg = MO.getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 704 | if (!TargetRegisterInfo::isVirtualRegister(Reg)) |
| 705 | continue; |
Jakob Stoklund Olesen | d1303d2 | 2010-06-29 19:15:30 +0000 | [diff] [blame] | 706 | if (MO.isEarlyClobber() || MI->isRegTiedToDefOperand(i) || |
| 707 | (MO.getSubReg() && MI->readsVirtualRegister(Reg))) { |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 708 | if (ThroughRegs.insert(Reg)) |
Jakob Stoklund Olesen | 4314268 | 2011-01-09 03:05:53 +0000 | [diff] [blame] | 709 | DEBUG(dbgs() << ' ' << PrintReg(Reg)); |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
| 713 | // If any physreg defines collide with preallocated through registers, |
| 714 | // we must spill and reallocate. |
| 715 | DEBUG(dbgs() << "\nChecking for physdef collisions.\n"); |
| 716 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 717 | MachineOperand &MO = MI->getOperand(i); |
| 718 | if (!MO.isReg() || !MO.isDef()) continue; |
| 719 | unsigned Reg = MO.getReg(); |
| 720 | if (!Reg || !TargetRegisterInfo::isPhysicalRegister(Reg)) continue; |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 721 | markRegUsedInInstr(Reg); |
Jakob Stoklund Olesen | 8c70ea4 | 2012-06-01 22:38:17 +0000 | [diff] [blame] | 722 | for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI) { |
Jakob Stoklund Olesen | 8c70ea4 | 2012-06-01 22:38:17 +0000 | [diff] [blame] | 723 | if (ThroughRegs.count(PhysRegState[*AI])) |
| 724 | definePhysReg(MI, *AI, regFree); |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 725 | } |
| 726 | } |
| 727 | |
Jakob Stoklund Olesen | d1303d2 | 2010-06-29 19:15:30 +0000 | [diff] [blame] | 728 | SmallVector<unsigned, 8> PartialDefs; |
Rafael Espindola | 254a132 | 2011-11-22 06:27:18 +0000 | [diff] [blame] | 729 | DEBUG(dbgs() << "Allocating tied uses.\n"); |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 730 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 731 | MachineOperand &MO = MI->getOperand(i); |
| 732 | if (!MO.isReg()) continue; |
| 733 | unsigned Reg = MO.getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 734 | if (!TargetRegisterInfo::isVirtualRegister(Reg)) continue; |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 735 | if (MO.isUse()) { |
| 736 | unsigned DefIdx = 0; |
| 737 | if (!MI->isRegTiedToDefOperand(i, &DefIdx)) continue; |
| 738 | DEBUG(dbgs() << "Operand " << i << "("<< MO << ") is tied to operand " |
| 739 | << DefIdx << ".\n"); |
| 740 | LiveRegMap::iterator LRI = reloadVirtReg(MI, i, Reg, 0); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 741 | unsigned PhysReg = LRI->PhysReg; |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 742 | setPhysReg(MI, i, PhysReg); |
Jakob Stoklund Olesen | d1303d2 | 2010-06-29 19:15:30 +0000 | [diff] [blame] | 743 | // Note: we don't update the def operand yet. That would cause the normal |
| 744 | // def-scan to attempt spilling. |
| 745 | } else if (MO.getSubReg() && MI->readsVirtualRegister(Reg)) { |
| 746 | DEBUG(dbgs() << "Partial redefine: " << MO << "\n"); |
| 747 | // Reload the register, but don't assign to the operand just yet. |
| 748 | // That would confuse the later phys-def processing pass. |
| 749 | LiveRegMap::iterator LRI = reloadVirtReg(MI, i, Reg, 0); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 750 | PartialDefs.push_back(LRI->PhysReg); |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | |
Rafael Espindola | 254a132 | 2011-11-22 06:27:18 +0000 | [diff] [blame] | 754 | DEBUG(dbgs() << "Allocating early clobbers.\n"); |
| 755 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 756 | MachineOperand &MO = MI->getOperand(i); |
| 757 | if (!MO.isReg()) continue; |
| 758 | unsigned Reg = MO.getReg(); |
| 759 | if (!TargetRegisterInfo::isVirtualRegister(Reg)) continue; |
| 760 | if (!MO.isEarlyClobber()) |
| 761 | continue; |
| 762 | // Note: defineVirtReg may invalidate MO. |
| 763 | LiveRegMap::iterator LRI = defineVirtReg(MI, i, Reg, 0); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 764 | unsigned PhysReg = LRI->PhysReg; |
Rafael Espindola | 254a132 | 2011-11-22 06:27:18 +0000 | [diff] [blame] | 765 | if (setPhysReg(MI, i, PhysReg)) |
| 766 | VirtDead.push_back(Reg); |
| 767 | } |
| 768 | |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 769 | // Restore UsedInInstr to a state usable for allocating normal virtual uses. |
Jakob Stoklund Olesen | d7ea7d5 | 2012-10-17 01:37:59 +0000 | [diff] [blame] | 770 | UsedInInstr.clear(); |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 771 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 772 | MachineOperand &MO = MI->getOperand(i); |
| 773 | if (!MO.isReg() || (MO.isDef() && !MO.isEarlyClobber())) continue; |
| 774 | unsigned Reg = MO.getReg(); |
| 775 | if (!Reg || !TargetRegisterInfo::isPhysicalRegister(Reg)) continue; |
Jakob Stoklund Olesen | 27ce3b9 | 2011-06-28 17:24:32 +0000 | [diff] [blame] | 776 | DEBUG(dbgs() << "\tSetting " << PrintReg(Reg, TRI) |
| 777 | << " as used in instr\n"); |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 778 | markRegUsedInInstr(Reg); |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 779 | } |
Jakob Stoklund Olesen | d1303d2 | 2010-06-29 19:15:30 +0000 | [diff] [blame] | 780 | |
| 781 | // Also mark PartialDefs as used to avoid reallocation. |
| 782 | for (unsigned i = 0, e = PartialDefs.size(); i != e; ++i) |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 783 | markRegUsedInInstr(PartialDefs[i]); |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 784 | } |
| 785 | |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 786 | void RAFast::AllocateBasicBlock() { |
| 787 | DEBUG(dbgs() << "\nAllocating " << *MBB); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 788 | |
| 789 | PhysRegState.assign(TRI->getNumRegs(), regDisabled); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 790 | assert(LiveVirtRegs.empty() && "Mapping not cleared from last block?"); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 791 | |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 792 | MachineBasicBlock::iterator MII = MBB->begin(); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 793 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 794 | // Add live-in registers as live. |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 795 | for (MachineBasicBlock::livein_iterator I = MBB->livein_begin(), |
| 796 | E = MBB->livein_end(); I != E; ++I) |
Jakob Stoklund Olesen | 14d1dd9 | 2012-10-15 22:41:03 +0000 | [diff] [blame] | 797 | if (MRI->isAllocatable(*I)) |
Jakob Stoklund Olesen | 9d4b51b | 2010-08-31 19:54:25 +0000 | [diff] [blame] | 798 | definePhysReg(MII, *I, regReserved); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 799 | |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 800 | SmallVector<unsigned, 8> VirtDead; |
Jakob Stoklund Olesen | 7ff82e1 | 2010-05-14 04:30:51 +0000 | [diff] [blame] | 801 | SmallVector<MachineInstr*, 32> Coalesced; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 802 | |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 803 | // Otherwise, sequentially allocate each instruction in the MBB. |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 804 | while (MII != MBB->end()) { |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 805 | MachineInstr *MI = MII++; |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 806 | const MCInstrDesc &MCID = MI->getDesc(); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 807 | DEBUG({ |
Jakob Stoklund Olesen | c9c4dac | 2010-05-13 20:43:17 +0000 | [diff] [blame] | 808 | dbgs() << "\n>> " << *MI << "Regs:"; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 809 | for (unsigned Reg = 1, E = TRI->getNumRegs(); Reg != E; ++Reg) { |
| 810 | if (PhysRegState[Reg] == regDisabled) continue; |
| 811 | dbgs() << " " << TRI->getName(Reg); |
| 812 | switch(PhysRegState[Reg]) { |
| 813 | case regFree: |
| 814 | break; |
| 815 | case regReserved: |
Jakob Stoklund Olesen | c9c4dac | 2010-05-13 20:43:17 +0000 | [diff] [blame] | 816 | dbgs() << "*"; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 817 | break; |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 818 | default: { |
Jakob Stoklund Olesen | 4314268 | 2011-01-09 03:05:53 +0000 | [diff] [blame] | 819 | dbgs() << '=' << PrintReg(PhysRegState[Reg]); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 820 | LiveRegMap::iterator I = findLiveVirtReg(PhysRegState[Reg]); |
| 821 | assert(I != LiveVirtRegs.end() && "Missing VirtReg entry"); |
| 822 | if (I->Dirty) |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 823 | dbgs() << "*"; |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 824 | assert(I->PhysReg == Reg && "Bad inverse map"); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 825 | break; |
| 826 | } |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 827 | } |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 828 | } |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 829 | dbgs() << '\n'; |
Jakob Stoklund Olesen | 76b4d5a | 2010-05-11 23:24:45 +0000 | [diff] [blame] | 830 | // Check that LiveVirtRegs is the inverse. |
| 831 | for (LiveRegMap::iterator i = LiveVirtRegs.begin(), |
| 832 | e = LiveVirtRegs.end(); i != e; ++i) { |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 833 | assert(TargetRegisterInfo::isVirtualRegister(i->VirtReg) && |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 834 | "Bad map key"); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 835 | assert(TargetRegisterInfo::isPhysicalRegister(i->PhysReg) && |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 836 | "Bad map value"); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 837 | assert(PhysRegState[i->PhysReg] == i->VirtReg && "Bad inverse map"); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 838 | } |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 839 | }); |
| 840 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 841 | // Debug values are not allowed to change codegen in any way. |
| 842 | if (MI->isDebugValue()) { |
Devang Patel | 58b8176 | 2010-07-19 23:25:39 +0000 | [diff] [blame] | 843 | bool ScanDbgValue = true; |
| 844 | while (ScanDbgValue) { |
| 845 | ScanDbgValue = false; |
| 846 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 847 | MachineOperand &MO = MI->getOperand(i); |
| 848 | if (!MO.isReg()) continue; |
| 849 | unsigned Reg = MO.getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 850 | if (!TargetRegisterInfo::isVirtualRegister(Reg)) continue; |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 851 | LiveRegMap::iterator LRI = findLiveVirtReg(Reg); |
Devang Patel | 58b8176 | 2010-07-19 23:25:39 +0000 | [diff] [blame] | 852 | if (LRI != LiveVirtRegs.end()) |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 853 | setPhysReg(MI, i, LRI->PhysReg); |
Devang Patel | 7a029b6 | 2010-07-09 21:48:31 +0000 | [diff] [blame] | 854 | else { |
Devang Patel | 58b8176 | 2010-07-19 23:25:39 +0000 | [diff] [blame] | 855 | int SS = StackSlotForVirtReg[Reg]; |
Devang Patel | 4bafda9 | 2010-09-10 20:32:09 +0000 | [diff] [blame] | 856 | if (SS == -1) { |
Jim Grosbach | 07cb689 | 2010-09-01 19:16:29 +0000 | [diff] [blame] | 857 | // We can't allocate a physreg for a DebugValue, sorry! |
Devang Patel | 4bafda9 | 2010-09-10 20:32:09 +0000 | [diff] [blame] | 858 | DEBUG(dbgs() << "Unable to allocate vreg used by DBG_VALUE"); |
Jim Grosbach | 07cb689 | 2010-09-01 19:16:29 +0000 | [diff] [blame] | 859 | MO.setReg(0); |
Devang Patel | 4bafda9 | 2010-09-10 20:32:09 +0000 | [diff] [blame] | 860 | } |
Devang Patel | 58b8176 | 2010-07-19 23:25:39 +0000 | [diff] [blame] | 861 | else { |
| 862 | // Modify DBG_VALUE now that the value is in a spill slot. |
Adrian Prantl | 818833f | 2013-09-16 23:29:03 +0000 | [diff] [blame] | 863 | bool IsIndirect = MI->isIndirectDebugValue(); |
Adrian Prantl | 43ae5e8 | 2013-07-10 16:56:52 +0000 | [diff] [blame] | 864 | uint64_t Offset = IsIndirect ? MI->getOperand(1).getImm() : 0; |
Jim Grosbach | 07cb689 | 2010-09-01 19:16:29 +0000 | [diff] [blame] | 865 | const MDNode *MDPtr = |
Devang Patel | 58b8176 | 2010-07-19 23:25:39 +0000 | [diff] [blame] | 866 | MI->getOperand(MI->getNumOperands()-1).getMetadata(); |
| 867 | DebugLoc DL = MI->getDebugLoc(); |
David Blaikie | 6d9dbd5 | 2013-06-16 20:34:15 +0000 | [diff] [blame] | 868 | MachineBasicBlock *MBB = MI->getParent(); |
| 869 | MachineInstr *NewDV = BuildMI(*MBB, MBB->erase(MI), DL, |
| 870 | TII->get(TargetOpcode::DBG_VALUE)) |
| 871 | .addFrameIndex(SS).addImm(Offset).addMetadata(MDPtr); |
| 872 | DEBUG(dbgs() << "Modifying debug info due to spill:" |
| 873 | << "\t" << *NewDV); |
| 874 | // Scan NewDV operands from the beginning. |
| 875 | MI = NewDV; |
| 876 | ScanDbgValue = true; |
| 877 | break; |
Devang Patel | 58b8176 | 2010-07-19 23:25:39 +0000 | [diff] [blame] | 878 | } |
Devang Patel | 7a029b6 | 2010-07-09 21:48:31 +0000 | [diff] [blame] | 879 | } |
Devang Patel | d2df64f | 2011-11-15 21:03:58 +0000 | [diff] [blame] | 880 | LiveDbgValueMap[Reg].push_back(MI); |
Devang Patel | 7a029b6 | 2010-07-09 21:48:31 +0000 | [diff] [blame] | 881 | } |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 882 | } |
| 883 | // Next instruction. |
| 884 | continue; |
| 885 | } |
| 886 | |
Jakob Stoklund Olesen | 4bf4baf | 2010-05-13 00:19:43 +0000 | [diff] [blame] | 887 | // If this is a copy, we may be able to coalesce. |
Jakob Stoklund Olesen | 04c528a | 2010-07-16 04:45:42 +0000 | [diff] [blame] | 888 | unsigned CopySrc = 0, CopyDst = 0, CopySrcSub = 0, CopyDstSub = 0; |
Jakob Stoklund Olesen | 273f7e4 | 2010-07-03 00:04:37 +0000 | [diff] [blame] | 889 | if (MI->isCopy()) { |
| 890 | CopyDst = MI->getOperand(0).getReg(); |
| 891 | CopySrc = MI->getOperand(1).getReg(); |
| 892 | CopyDstSub = MI->getOperand(0).getSubReg(); |
| 893 | CopySrcSub = MI->getOperand(1).getSubReg(); |
Jakob Stoklund Olesen | 04c528a | 2010-07-16 04:45:42 +0000 | [diff] [blame] | 894 | } |
Jakob Stoklund Olesen | 4bf4baf | 2010-05-13 00:19:43 +0000 | [diff] [blame] | 895 | |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 896 | // Track registers used by instruction. |
Jakob Stoklund Olesen | d7ea7d5 | 2012-10-17 01:37:59 +0000 | [diff] [blame] | 897 | UsedInInstr.clear(); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 898 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 899 | // First scan. |
| 900 | // Mark physreg uses and early clobbers as used. |
Jakob Stoklund Olesen | e97dda4 | 2010-05-14 21:55:52 +0000 | [diff] [blame] | 901 | // Find the end of the virtreg operands |
| 902 | unsigned VirtOpEnd = 0; |
Jakob Stoklund Olesen | d1303d2 | 2010-06-29 19:15:30 +0000 | [diff] [blame] | 903 | bool hasTiedOps = false; |
| 904 | bool hasEarlyClobbers = false; |
| 905 | bool hasPartialRedefs = false; |
| 906 | bool hasPhysDefs = false; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 907 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 908 | MachineOperand &MO = MI->getOperand(i); |
Chad Rosier | 7979b24 | 2012-11-06 22:52:42 +0000 | [diff] [blame] | 909 | // Make sure MRI knows about registers clobbered by regmasks. |
| 910 | if (MO.isRegMask()) { |
| 911 | MRI->addPhysRegsUsedFromRegMask(MO.getRegMask()); |
| 912 | continue; |
| 913 | } |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 914 | if (!MO.isReg()) continue; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 915 | unsigned Reg = MO.getReg(); |
Jakob Stoklund Olesen | e97dda4 | 2010-05-14 21:55:52 +0000 | [diff] [blame] | 916 | if (!Reg) continue; |
| 917 | if (TargetRegisterInfo::isVirtualRegister(Reg)) { |
| 918 | VirtOpEnd = i+1; |
Jakob Stoklund Olesen | d1303d2 | 2010-06-29 19:15:30 +0000 | [diff] [blame] | 919 | if (MO.isUse()) { |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 920 | hasTiedOps = hasTiedOps || |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 921 | MCID.getOperandConstraint(i, MCOI::TIED_TO) != -1; |
Jakob Stoklund Olesen | d1303d2 | 2010-06-29 19:15:30 +0000 | [diff] [blame] | 922 | } else { |
| 923 | if (MO.isEarlyClobber()) |
| 924 | hasEarlyClobbers = true; |
| 925 | if (MO.getSubReg() && MI->readsVirtualRegister(Reg)) |
| 926 | hasPartialRedefs = true; |
| 927 | } |
Jakob Stoklund Olesen | e97dda4 | 2010-05-14 21:55:52 +0000 | [diff] [blame] | 928 | continue; |
| 929 | } |
Jakob Stoklund Olesen | 14d1dd9 | 2012-10-15 22:41:03 +0000 | [diff] [blame] | 930 | if (!MRI->isAllocatable(Reg)) continue; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 931 | if (MO.isUse()) { |
Jakob Stoklund Olesen | 4ed1082 | 2010-05-14 18:03:25 +0000 | [diff] [blame] | 932 | usePhysReg(MO); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 933 | } else if (MO.isEarlyClobber()) { |
Jakob Stoklund Olesen | 75ac4d9 | 2010-06-15 16:20:57 +0000 | [diff] [blame] | 934 | definePhysReg(MI, Reg, (MO.isImplicit() || MO.isDead()) ? |
| 935 | regFree : regReserved); |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 936 | hasEarlyClobbers = true; |
| 937 | } else |
| 938 | hasPhysDefs = true; |
| 939 | } |
| 940 | |
| 941 | // The instruction may have virtual register operands that must be allocated |
| 942 | // the same register at use-time and def-time: early clobbers and tied |
| 943 | // operands. If there are also physical defs, these registers must avoid |
| 944 | // both physical defs and uses, making them more constrained than normal |
| 945 | // operands. |
Jim Grosbach | 07cb689 | 2010-09-01 19:16:29 +0000 | [diff] [blame] | 946 | // Similarly, if there are multiple defs and tied operands, we must make |
| 947 | // sure the same register is allocated to uses and defs. |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 948 | // We didn't detect inline asm tied operands above, so just make this extra |
| 949 | // pass for all inline asm. |
Jakob Stoklund Olesen | d1303d2 | 2010-06-29 19:15:30 +0000 | [diff] [blame] | 950 | if (MI->isInlineAsm() || hasEarlyClobbers || hasPartialRedefs || |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 951 | (hasTiedOps && (hasPhysDefs || MCID.getNumDefs() > 1))) { |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 952 | handleThroughOperands(MI, VirtDead); |
| 953 | // Don't attempt coalescing when we have funny stuff going on. |
| 954 | CopyDst = 0; |
Jakob Stoklund Olesen | 4bd94f7 | 2010-07-29 00:52:19 +0000 | [diff] [blame] | 955 | // Pretend we have early clobbers so the use operands get marked below. |
| 956 | // This is not necessary for the common case of a single tied use. |
| 957 | hasEarlyClobbers = true; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 960 | // Second scan. |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 961 | // Allocate virtreg uses. |
Jakob Stoklund Olesen | e97dda4 | 2010-05-14 21:55:52 +0000 | [diff] [blame] | 962 | for (unsigned i = 0; i != VirtOpEnd; ++i) { |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 963 | MachineOperand &MO = MI->getOperand(i); |
| 964 | if (!MO.isReg()) continue; |
| 965 | unsigned Reg = MO.getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 966 | if (!TargetRegisterInfo::isVirtualRegister(Reg)) continue; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 967 | if (MO.isUse()) { |
Jakob Stoklund Olesen | 646dd7c | 2010-05-17 03:26:09 +0000 | [diff] [blame] | 968 | LiveRegMap::iterator LRI = reloadVirtReg(MI, i, Reg, CopyDst); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 969 | unsigned PhysReg = LRI->PhysReg; |
Jakob Stoklund Olesen | 7ff82e1 | 2010-05-14 04:30:51 +0000 | [diff] [blame] | 970 | CopySrc = (CopySrc == Reg || CopySrc == PhysReg) ? PhysReg : 0; |
Jakob Stoklund Olesen | 0eeb05c | 2010-05-18 21:10:50 +0000 | [diff] [blame] | 971 | if (setPhysReg(MI, i, PhysReg)) |
Jakob Stoklund Olesen | 646dd7c | 2010-05-17 03:26:09 +0000 | [diff] [blame] | 972 | killVirtReg(LRI); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | |
Jakob Stoklund Olesen | d7ea7d5 | 2012-10-17 01:37:59 +0000 | [diff] [blame] | 976 | for (UsedInInstrSet::iterator |
| 977 | I = UsedInInstr.begin(), E = UsedInInstr.end(); I != E; ++I) |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 978 | MRI->setRegUnitUsed(*I); |
Jakob Stoklund Olesen | 82b07dc | 2010-05-11 20:30:28 +0000 | [diff] [blame] | 979 | |
Jakob Stoklund Olesen | 4bd94f7 | 2010-07-29 00:52:19 +0000 | [diff] [blame] | 980 | // Track registers defined by instruction - early clobbers and tied uses at |
| 981 | // this point. |
Jakob Stoklund Olesen | d7ea7d5 | 2012-10-17 01:37:59 +0000 | [diff] [blame] | 982 | UsedInInstr.clear(); |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 983 | if (hasEarlyClobbers) { |
| 984 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 985 | MachineOperand &MO = MI->getOperand(i); |
Jakob Stoklund Olesen | 4bd94f7 | 2010-07-29 00:52:19 +0000 | [diff] [blame] | 986 | if (!MO.isReg()) continue; |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 987 | unsigned Reg = MO.getReg(); |
| 988 | if (!Reg || !TargetRegisterInfo::isPhysicalRegister(Reg)) continue; |
Jakob Stoklund Olesen | 4bd94f7 | 2010-07-29 00:52:19 +0000 | [diff] [blame] | 989 | // Look for physreg defs and tied uses. |
| 990 | if (!MO.isDef() && !MI->isRegTiedToDefOperand(i)) continue; |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 991 | markRegUsedInInstr(Reg); |
Jakob Stoklund Olesen | d843b39 | 2010-06-28 18:34:34 +0000 | [diff] [blame] | 992 | } |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 993 | } |
| 994 | |
Jakob Stoklund Olesen | 4b6bbe8 | 2010-05-17 02:49:18 +0000 | [diff] [blame] | 995 | unsigned DefOpEnd = MI->getNumOperands(); |
Evan Cheng | 5a96b3d | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 996 | if (MI->isCall()) { |
Jakob Stoklund Olesen | 4b6bbe8 | 2010-05-17 02:49:18 +0000 | [diff] [blame] | 997 | // Spill all virtregs before a call. This serves two purposes: 1. If an |
Jim Grosbach | 07cb689 | 2010-09-01 19:16:29 +0000 | [diff] [blame] | 998 | // exception is thrown, the landing pad is going to expect to find |
| 999 | // registers in their spill slots, and 2. we don't have to wade through |
| 1000 | // all the <imp-def> operands on the call instruction. |
Jakob Stoklund Olesen | 4b6bbe8 | 2010-05-17 02:49:18 +0000 | [diff] [blame] | 1001 | DefOpEnd = VirtOpEnd; |
| 1002 | DEBUG(dbgs() << " Spilling remaining registers before call.\n"); |
| 1003 | spillAll(MI); |
Jakob Stoklund Olesen | 6de0717 | 2010-06-04 18:08:29 +0000 | [diff] [blame] | 1004 | |
| 1005 | // The imp-defs are skipped below, but we still need to mark those |
| 1006 | // registers as used by the function. |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1007 | SkippedInstrs.insert(&MCID); |
Jakob Stoklund Olesen | 4b6bbe8 | 2010-05-17 02:49:18 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 1010 | // Third scan. |
| 1011 | // Allocate defs and collect dead defs. |
Jakob Stoklund Olesen | 4b6bbe8 | 2010-05-17 02:49:18 +0000 | [diff] [blame] | 1012 | for (unsigned i = 0; i != DefOpEnd; ++i) { |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 1013 | MachineOperand &MO = MI->getOperand(i); |
Jakob Stoklund Olesen | 75ac4d9 | 2010-06-15 16:20:57 +0000 | [diff] [blame] | 1014 | if (!MO.isReg() || !MO.isDef() || !MO.getReg() || MO.isEarlyClobber()) |
| 1015 | continue; |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 1016 | unsigned Reg = MO.getReg(); |
| 1017 | |
| 1018 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) { |
Jakob Stoklund Olesen | 14d1dd9 | 2012-10-15 22:41:03 +0000 | [diff] [blame] | 1019 | if (!MRI->isAllocatable(Reg)) continue; |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 1020 | definePhysReg(MI, Reg, (MO.isImplicit() || MO.isDead()) ? |
| 1021 | regFree : regReserved); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1022 | continue; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1023 | } |
Jakob Stoklund Olesen | 646dd7c | 2010-05-17 03:26:09 +0000 | [diff] [blame] | 1024 | LiveRegMap::iterator LRI = defineVirtReg(MI, i, Reg, CopySrc); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 1025 | unsigned PhysReg = LRI->PhysReg; |
Jakob Stoklund Olesen | 0eeb05c | 2010-05-18 21:10:50 +0000 | [diff] [blame] | 1026 | if (setPhysReg(MI, i, PhysReg)) { |
| 1027 | VirtDead.push_back(Reg); |
Jakob Stoklund Olesen | 7ff82e1 | 2010-05-14 04:30:51 +0000 | [diff] [blame] | 1028 | CopyDst = 0; // cancel coalescing; |
| 1029 | } else |
| 1030 | CopyDst = (CopyDst == Reg || CopyDst == PhysReg) ? PhysReg : 0; |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
Jakob Stoklund Olesen | 0eeb05c | 2010-05-18 21:10:50 +0000 | [diff] [blame] | 1033 | // Kill dead defs after the scan to ensure that multiple defs of the same |
| 1034 | // register are allocated identically. We didn't need to do this for uses |
| 1035 | // because we are crerating our own kill flags, and they are always at the |
| 1036 | // last use. |
| 1037 | for (unsigned i = 0, e = VirtDead.size(); i != e; ++i) |
| 1038 | killVirtReg(VirtDead[i]); |
| 1039 | VirtDead.clear(); |
| 1040 | |
Jakob Stoklund Olesen | d7ea7d5 | 2012-10-17 01:37:59 +0000 | [diff] [blame] | 1041 | for (UsedInInstrSet::iterator |
| 1042 | I = UsedInInstr.begin(), E = UsedInInstr.end(); I != E; ++I) |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 1043 | MRI->setRegUnitUsed(*I); |
Jakob Stoklund Olesen | c9c4dac | 2010-05-13 20:43:17 +0000 | [diff] [blame] | 1044 | |
Jakob Stoklund Olesen | 7ff82e1 | 2010-05-14 04:30:51 +0000 | [diff] [blame] | 1045 | if (CopyDst && CopyDst == CopySrc && CopyDstSub == CopySrcSub) { |
| 1046 | DEBUG(dbgs() << "-- coalescing: " << *MI); |
| 1047 | Coalesced.push_back(MI); |
| 1048 | } else { |
| 1049 | DEBUG(dbgs() << "<< " << *MI); |
| 1050 | } |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1053 | // Spill all physical registers holding virtual registers now. |
Jakob Stoklund Olesen | e6aba83 | 2010-05-17 02:07:32 +0000 | [diff] [blame] | 1054 | DEBUG(dbgs() << "Spilling live registers at end of block.\n"); |
| 1055 | spillAll(MBB->getFirstTerminator()); |
Jakob Stoklund Olesen | bbf33b3 | 2010-05-11 18:54:45 +0000 | [diff] [blame] | 1056 | |
Jakob Stoklund Olesen | 7ff82e1 | 2010-05-14 04:30:51 +0000 | [diff] [blame] | 1057 | // Erase all the coalesced copies. We are delaying it until now because |
Jakob Stoklund Olesen | e6aba83 | 2010-05-17 02:07:32 +0000 | [diff] [blame] | 1058 | // LiveVirtRegs might refer to the instrs. |
Jakob Stoklund Olesen | 7ff82e1 | 2010-05-14 04:30:51 +0000 | [diff] [blame] | 1059 | for (unsigned i = 0, e = Coalesced.size(); i != e; ++i) |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 1060 | MBB->erase(Coalesced[i]); |
Jakob Stoklund Olesen | 8a65c51 | 2010-05-14 21:55:50 +0000 | [diff] [blame] | 1061 | NumCopies += Coalesced.size(); |
Jakob Stoklund Olesen | 7ff82e1 | 2010-05-14 04:30:51 +0000 | [diff] [blame] | 1062 | |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 1063 | DEBUG(MBB->dump()); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | /// runOnMachineFunction - Register allocate the whole function |
| 1067 | /// |
| 1068 | bool RAFast::runOnMachineFunction(MachineFunction &Fn) { |
Jakob Stoklund Olesen | c9c4dac | 2010-05-13 20:43:17 +0000 | [diff] [blame] | 1069 | DEBUG(dbgs() << "********** FAST REGISTER ALLOCATION **********\n" |
David Blaikie | 986d76d | 2012-08-22 17:18:53 +0000 | [diff] [blame] | 1070 | << "********** Function: " << Fn.getName() << '\n'); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1071 | MF = &Fn; |
Jakob Stoklund Olesen | 4bf4baf | 2010-05-13 00:19:43 +0000 | [diff] [blame] | 1072 | MRI = &MF->getRegInfo(); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1073 | TM = &Fn.getTarget(); |
| 1074 | TRI = TM->getRegisterInfo(); |
| 1075 | TII = TM->getInstrInfo(); |
Chad Rosier | 18bb054 | 2012-11-28 00:21:29 +0000 | [diff] [blame] | 1076 | MRI->freezeReservedRegs(Fn); |
Jakob Stoklund Olesen | 5d20c31 | 2011-06-02 18:35:30 +0000 | [diff] [blame] | 1077 | RegClassInfo.runOnMachineFunction(Fn); |
Jakob Stoklund Olesen | d7ea7d5 | 2012-10-17 01:37:59 +0000 | [diff] [blame] | 1078 | UsedInInstr.clear(); |
Jakob Stoklund Olesen | 601158a | 2013-02-21 19:35:21 +0000 | [diff] [blame] | 1079 | UsedInInstr.setUniverse(TRI->getNumRegUnits()); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1080 | |
Andrew Trick | 8dd2625 | 2012-02-10 04:10:36 +0000 | [diff] [blame] | 1081 | assert(!MRI->isSSA() && "regalloc requires leaving SSA"); |
| 1082 | |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1083 | // initialize the virtual->physical register map to have a 'null' |
| 1084 | // mapping for all virtual registers |
Jakob Stoklund Olesen | 42e9c96 | 2011-01-09 21:58:20 +0000 | [diff] [blame] | 1085 | StackSlotForVirtReg.resize(MRI->getNumVirtRegs()); |
Jakob Stoklund Olesen | a240743 | 2012-02-22 01:02:37 +0000 | [diff] [blame] | 1086 | LiveVirtRegs.setUniverse(MRI->getNumVirtRegs()); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1087 | |
| 1088 | // Loop over all of the basic blocks, eliminating virtual register references |
Jakob Stoklund Olesen | 6fb69d8 | 2010-05-17 02:07:22 +0000 | [diff] [blame] | 1089 | for (MachineFunction::iterator MBBi = Fn.begin(), MBBe = Fn.end(); |
| 1090 | MBBi != MBBe; ++MBBi) { |
| 1091 | MBB = &*MBBi; |
| 1092 | AllocateBasicBlock(); |
| 1093 | } |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1094 | |
Jakob Stoklund Olesen | 6de0717 | 2010-06-04 18:08:29 +0000 | [diff] [blame] | 1095 | // Add the clobber lists for all the instructions we skipped earlier. |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1096 | for (SmallPtrSet<const MCInstrDesc*, 4>::const_iterator |
Jakob Stoklund Olesen | 6de0717 | 2010-06-04 18:08:29 +0000 | [diff] [blame] | 1097 | I = SkippedInstrs.begin(), E = SkippedInstrs.end(); I != E; ++I) |
Craig Topper | fac2598 | 2012-03-08 08:22:45 +0000 | [diff] [blame] | 1098 | if (const uint16_t *Defs = (*I)->getImplicitDefs()) |
Jakob Stoklund Olesen | 6de0717 | 2010-06-04 18:08:29 +0000 | [diff] [blame] | 1099 | while (*Defs) |
| 1100 | MRI->setPhysRegUsed(*Defs++); |
| 1101 | |
Andrew Trick | 19273ae | 2012-02-21 04:51:23 +0000 | [diff] [blame] | 1102 | // All machine operands and other references to virtual registers have been |
| 1103 | // replaced. Remove the virtual registers. |
| 1104 | MRI->clearVirtRegs(); |
| 1105 | |
Jakob Stoklund Olesen | 6de0717 | 2010-06-04 18:08:29 +0000 | [diff] [blame] | 1106 | SkippedInstrs.clear(); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1107 | StackSlotForVirtReg.clear(); |
Devang Patel | 459a36b | 2010-08-04 18:42:02 +0000 | [diff] [blame] | 1108 | LiveDbgValueMap.clear(); |
Jakob Stoklund Olesen | 0020723 | 2010-04-21 18:02:42 +0000 | [diff] [blame] | 1109 | return true; |
| 1110 | } |
| 1111 | |
| 1112 | FunctionPass *llvm::createFastRegisterAllocator() { |
| 1113 | return new RAFast(); |
| 1114 | } |