Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 1 | //===-- MachineLICM.cpp - Machine Loop Invariant Code Motion Pass ---------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Bill Wendling and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This pass performs loop invariant code motion on machine instructions. We |
| 11 | // attempt to remove as much code from the body of a loop as possible. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #define DEBUG_TYPE "machine-licm" |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/IndexedMap.h" |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/SmallVector.h" |
| 18 | #include "llvm/ADT/Statistic.h" |
| 19 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 20 | #include "llvm/CodeGen/MachineDominators.h" |
| 21 | #include "llvm/CodeGen/MachineInstr.h" |
| 22 | #include "llvm/CodeGen/MachineLoopInfo.h" |
| 23 | #include "llvm/CodeGen/Passes.h" |
| 24 | #include "llvm/Target/TargetInstrInfo.h" |
| 25 | #include "llvm/Support/CFG.h" |
| 26 | #include "llvm/Support/CommandLine.h" |
| 27 | #include "llvm/Support/Compiler.h" |
| 28 | #include "llvm/Support/Debug.h" |
| 29 | #include "llvm/Target/MRegisterInfo.h" |
| 30 | #include "llvm/Target/TargetMachine.h" |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 31 | |
| 32 | using namespace llvm; |
| 33 | |
| 34 | namespace { |
| 35 | // Hidden options to help debugging |
| 36 | cl::opt<bool> |
| 37 | PerformLICM("machine-licm", |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 38 | cl::init(false), cl::Hidden, |
| 39 | cl::desc("Perform loop-invariant code motion on machine code")); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Bill Wendling | 0fe34c2 | 2007-12-08 23:58:46 +0000 | [diff] [blame] | 42 | STATISTIC(NumHoisted, "Number of machine instructions hoisted out of loops"); |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 43 | |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 44 | namespace { |
| 45 | class VISIBILITY_HIDDEN MachineLICM : public MachineFunctionPass { |
Bill Wendling | d9b9be6 | 2007-12-11 19:40:06 +0000 | [diff] [blame] | 46 | MachineFunction *CurMF;// Current MachineFunction |
| 47 | |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 48 | // Various analyses that we use... |
| 49 | MachineLoopInfo *LI; // Current MachineLoopInfo |
| 50 | MachineDominatorTree *DT; // Machine dominator tree for the current Loop |
| 51 | |
| 52 | const TargetInstrInfo *TII; |
| 53 | |
| 54 | // State that is updated as we process loops |
| 55 | bool Changed; // True if a loop is changed. |
| 56 | MachineLoop *CurLoop; // The current loop we are working on. |
| 57 | |
| 58 | // Map the def of a virtual register to the machine instruction. |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 59 | IndexedMap<const MachineInstr*, VirtReg2IndexFunctor> VRegDefs; |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 60 | public: |
| 61 | static char ID; // Pass identification, replacement for typeid |
| 62 | MachineLICM() : MachineFunctionPass((intptr_t)&ID) {} |
| 63 | |
| 64 | virtual bool runOnMachineFunction(MachineFunction &MF); |
| 65 | |
| 66 | /// FIXME: Loop preheaders? |
| 67 | /// |
| 68 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 69 | AU.setPreservesCFG(); |
| 70 | AU.addRequired<MachineLoopInfo>(); |
| 71 | AU.addRequired<MachineDominatorTree>(); |
| 72 | } |
| 73 | private: |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 74 | /// VisitAllLoops - Visit all of the loops in depth first order and try to |
| 75 | /// hoist invariant instructions from them. |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 76 | /// |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 77 | void VisitAllLoops(MachineLoop *L) { |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 78 | const std::vector<MachineLoop*> &SubLoops = L->getSubLoops(); |
| 79 | |
| 80 | for (MachineLoop::iterator |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 81 | I = SubLoops.begin(), E = SubLoops.end(); I != E; ++I) { |
| 82 | MachineLoop *ML = *I; |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 83 | |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 84 | // Traverse the body of the loop in depth first order on the dominator |
| 85 | // tree so that we are guaranteed to see definitions before we see uses. |
| 86 | VisitAllLoops(ML); |
| 87 | HoistRegion(DT->getNode(ML->getHeader())); |
| 88 | } |
| 89 | |
| 90 | HoistRegion(DT->getNode(L->getHeader())); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /// MapVirtualRegisterDefs - Create a map of which machine instruction |
| 94 | /// defines a virtual register. |
| 95 | /// |
Bill Wendling | d9b9be6 | 2007-12-11 19:40:06 +0000 | [diff] [blame] | 96 | void MapVirtualRegisterDefs(); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 97 | |
Bill Wendling | 0fe34c2 | 2007-12-08 23:58:46 +0000 | [diff] [blame] | 98 | /// IsInSubLoop - A little predicate that returns true if the specified |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 99 | /// basic block is in a subloop of the current one, not the current one |
| 100 | /// itself. |
| 101 | /// |
Bill Wendling | 0fe34c2 | 2007-12-08 23:58:46 +0000 | [diff] [blame] | 102 | bool IsInSubLoop(MachineBasicBlock *BB) { |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 103 | assert(CurLoop->contains(BB) && "Only valid if BB is IN the loop"); |
Bill Wendling | 2dfc9eb | 2007-12-11 18:45:11 +0000 | [diff] [blame] | 104 | return LI->getLoopFor(BB) != CurLoop; |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /// CanHoistInst - Checks that this instructions is one that can be hoisted |
| 108 | /// out of the loop. I.e., it has no side effects, isn't a control flow |
| 109 | /// instr, etc. |
| 110 | /// |
| 111 | bool CanHoistInst(MachineInstr &I) const { |
| 112 | const TargetInstrDescriptor *TID = I.getInstrDescriptor(); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 113 | |
Bill Wendling | 2dfc9eb | 2007-12-11 18:45:11 +0000 | [diff] [blame] | 114 | // Don't hoist if this instruction implicitly reads physical registers. |
| 115 | if (TID->ImplicitUses) return false; |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 116 | |
| 117 | MachineOpCode Opcode = TID->Opcode; |
Bill Wendling | 0fe34c2 | 2007-12-08 23:58:46 +0000 | [diff] [blame] | 118 | return TII->isTriviallyReMaterializable(&I) && |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 119 | // FIXME: Below necessary? |
| 120 | !(TII->isReturn(Opcode) || |
| 121 | TII->isTerminatorInstr(Opcode) || |
| 122 | TII->isBranch(Opcode) || |
| 123 | TII->isIndirectBranch(Opcode) || |
| 124 | TII->isBarrier(Opcode) || |
| 125 | TII->isCall(Opcode) || |
| 126 | TII->isLoad(Opcode) || // TODO: Do loads and stores. |
| 127 | TII->isStore(Opcode)); |
| 128 | } |
| 129 | |
Bill Wendling | 0fe34c2 | 2007-12-08 23:58:46 +0000 | [diff] [blame] | 130 | /// IsLoopInvariantInst - Returns true if the instruction is loop |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 131 | /// invariant. I.e., all virtual register operands are defined outside of |
| 132 | /// the loop, physical registers aren't accessed (explicitly or implicitly), |
| 133 | /// and the instruction is hoistable. |
| 134 | /// |
Bill Wendling | 0fe34c2 | 2007-12-08 23:58:46 +0000 | [diff] [blame] | 135 | bool IsLoopInvariantInst(MachineInstr &I); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 136 | |
| 137 | /// FindPredecessors - Get all of the predecessors of the loop that are not |
| 138 | /// back-edges. |
| 139 | /// |
Bill Wendling | 2dfc9eb | 2007-12-11 18:45:11 +0000 | [diff] [blame] | 140 | void FindPredecessors(std::vector<MachineBasicBlock*> &Preds) { |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 141 | const MachineBasicBlock *Header = CurLoop->getHeader(); |
| 142 | |
| 143 | for (MachineBasicBlock::const_pred_iterator |
| 144 | I = Header->pred_begin(), E = Header->pred_end(); I != E; ++I) |
| 145 | if (!CurLoop->contains(*I)) |
| 146 | Preds.push_back(*I); |
| 147 | } |
| 148 | |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 149 | /// MoveInstToEndOfBlock - Moves the machine instruction to the bottom of |
| 150 | /// the predecessor basic block (but before the terminator instructions). |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 151 | /// |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 152 | void MoveInstToEndOfBlock(MachineBasicBlock *MBB, MachineInstr *MI) { |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 153 | MachineBasicBlock::iterator Iter = MBB->getFirstTerminator(); |
| 154 | MBB->insert(Iter, MI); |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 155 | ++NumHoisted; |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /// HoistRegion - Walk the specified region of the CFG (defined by all |
| 159 | /// blocks dominated by the specified block, and that are in the current |
| 160 | /// loop) in depth first order w.r.t the DominatorTree. This allows us to |
| 161 | /// visit definitions before uses, allowing us to hoist a loop body in one |
| 162 | /// pass without iteration. |
| 163 | /// |
| 164 | void HoistRegion(MachineDomTreeNode *N); |
| 165 | |
| 166 | /// Hoist - When an instruction is found to only use loop invariant operands |
| 167 | /// that is safe to hoist, this instruction is called to do the dirty work. |
| 168 | /// |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 169 | void Hoist(MachineInstr &MI); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | char MachineLICM::ID = 0; |
| 173 | RegisterPass<MachineLICM> X("machine-licm", |
| 174 | "Machine Loop Invariant Code Motion"); |
| 175 | } // end anonymous namespace |
| 176 | |
| 177 | FunctionPass *llvm::createMachineLICMPass() { return new MachineLICM(); } |
| 178 | |
| 179 | /// Hoist expressions out of the specified loop. Note, alias info for inner loop |
| 180 | /// is not preserved so it is not a good idea to run LICM multiple times on one |
| 181 | /// loop. |
| 182 | /// |
| 183 | bool MachineLICM::runOnMachineFunction(MachineFunction &MF) { |
| 184 | if (!PerformLICM) return false; // For debugging. |
| 185 | |
| 186 | Changed = false; |
Bill Wendling | d9b9be6 | 2007-12-11 19:40:06 +0000 | [diff] [blame] | 187 | CurMF = &MF; |
| 188 | TII = CurMF->getTarget().getInstrInfo(); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 189 | |
| 190 | // Get our Loop information... |
| 191 | LI = &getAnalysis<MachineLoopInfo>(); |
| 192 | DT = &getAnalysis<MachineDominatorTree>(); |
| 193 | |
Bill Wendling | d9b9be6 | 2007-12-11 19:40:06 +0000 | [diff] [blame] | 194 | MapVirtualRegisterDefs(); |
| 195 | |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 196 | for (MachineLoopInfo::iterator |
| 197 | I = LI->begin(), E = LI->end(); I != E; ++I) { |
| 198 | MachineLoop *L = *I; |
| 199 | CurLoop = L; |
| 200 | |
| 201 | // Visit all of the instructions of the loop. We want to visit the subloops |
| 202 | // first, though, so that we can hoist their invariants first into their |
| 203 | // containing loop before we process that loop. |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 204 | VisitAllLoops(L); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | return Changed; |
| 208 | } |
| 209 | |
| 210 | /// MapVirtualRegisterDefs - Create a map of which machine instruction defines a |
| 211 | /// virtual register. |
| 212 | /// |
Bill Wendling | d9b9be6 | 2007-12-11 19:40:06 +0000 | [diff] [blame] | 213 | void MachineLICM::MapVirtualRegisterDefs() { |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 214 | for (MachineFunction::const_iterator |
Bill Wendling | d9b9be6 | 2007-12-11 19:40:06 +0000 | [diff] [blame] | 215 | I = CurMF->begin(), E = CurMF->end(); I != E; ++I) { |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 216 | const MachineBasicBlock &MBB = *I; |
| 217 | |
| 218 | for (MachineBasicBlock::const_iterator |
| 219 | II = MBB.begin(), IE = MBB.end(); II != IE; ++II) { |
| 220 | const MachineInstr &MI = *II; |
| 221 | |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 222 | for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) { |
Bill Wendling | e91b2ef | 2007-12-11 19:17:04 +0000 | [diff] [blame] | 223 | const MachineOperand &MO = MI.getOperand(i); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 224 | |
| 225 | if (MO.isRegister() && MO.isDef() && |
| 226 | MRegisterInfo::isVirtualRegister(MO.getReg())) |
| 227 | VRegDefs[MO.getReg()] = &MI; |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /// HoistRegion - Walk the specified region of the CFG (defined by all blocks |
| 234 | /// dominated by the specified block, and that are in the current loop) in depth |
| 235 | /// first order w.r.t the DominatorTree. This allows us to visit definitions |
| 236 | /// before uses, allowing us to hoist a loop body in one pass without iteration. |
| 237 | /// |
| 238 | void MachineLICM::HoistRegion(MachineDomTreeNode *N) { |
| 239 | assert(N != 0 && "Null dominator tree node?"); |
| 240 | MachineBasicBlock *BB = N->getBlock(); |
| 241 | |
| 242 | // If this subregion is not in the top level loop at all, exit. |
| 243 | if (!CurLoop->contains(BB)) return; |
| 244 | |
| 245 | // Only need to process the contents of this block if it is not part of a |
| 246 | // subloop (which would already have been processed). |
Bill Wendling | 0fe34c2 | 2007-12-08 23:58:46 +0000 | [diff] [blame] | 247 | if (!IsInSubLoop(BB)) |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 248 | for (MachineBasicBlock::iterator |
| 249 | I = BB->begin(), E = BB->end(); I != E; ) { |
| 250 | MachineInstr &MI = *I++; |
| 251 | |
| 252 | // Try hoisting the instruction out of the loop. We can only do this if |
| 253 | // all of the operands of the instruction are loop invariant and if it is |
| 254 | // safe to hoist the instruction. |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 255 | Hoist(MI); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | const std::vector<MachineDomTreeNode*> &Children = N->getChildren(); |
| 259 | |
| 260 | for (unsigned I = 0, E = Children.size(); I != E; ++I) |
| 261 | HoistRegion(Children[I]); |
| 262 | } |
| 263 | |
Bill Wendling | 0fe34c2 | 2007-12-08 23:58:46 +0000 | [diff] [blame] | 264 | /// IsLoopInvariantInst - Returns true if the instruction is loop |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 265 | /// invariant. I.e., all virtual register operands are defined outside of the |
| 266 | /// loop, physical registers aren't accessed (explicitly or implicitly), and the |
| 267 | /// instruction is hoistable. |
| 268 | /// |
Bill Wendling | 0fe34c2 | 2007-12-08 23:58:46 +0000 | [diff] [blame] | 269 | bool MachineLICM::IsLoopInvariantInst(MachineInstr &I) { |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 270 | if (!CanHoistInst(I)) return false; |
| 271 | |
| 272 | // The instruction is loop invariant if all of its operands are loop-invariant |
| 273 | for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) { |
| 274 | const MachineOperand &MO = I.getOperand(i); |
| 275 | |
| 276 | if (!MO.isRegister() || !MO.isUse()) |
| 277 | continue; |
| 278 | |
| 279 | unsigned Reg = MO.getReg(); |
| 280 | |
| 281 | // Don't hoist instructions that access physical registers. |
| 282 | if (!MRegisterInfo::isVirtualRegister(Reg)) |
| 283 | return false; |
| 284 | |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 285 | assert(VRegDefs[Reg] && "Machine instr not mapped for this vreg?"); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 286 | |
| 287 | // If the loop contains the definition of an operand, then the instruction |
| 288 | // isn't loop invariant. |
| 289 | if (CurLoop->contains(VRegDefs[Reg]->getParent())) |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | // If we got this far, the instruction is loop invariant! |
| 294 | return true; |
| 295 | } |
| 296 | |
| 297 | /// Hoist - When an instruction is found to only use loop invariant operands |
| 298 | /// that is safe to hoist, this instruction is called to do the dirty work. |
| 299 | /// |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 300 | void MachineLICM::Hoist(MachineInstr &MI) { |
Bill Wendling | 0fe34c2 | 2007-12-08 23:58:46 +0000 | [diff] [blame] | 301 | if (!IsLoopInvariantInst(MI)) return; |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 302 | |
| 303 | std::vector<MachineBasicBlock*> Preds; |
| 304 | |
| 305 | // Non-back-edge predecessors. |
| 306 | FindPredecessors(Preds); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 307 | |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 308 | // Either we don't have any predecessors(?!) or we have more than one, which |
| 309 | // is forbidden. |
| 310 | if (Preds.empty() || Preds.size() != 1) return; |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 311 | |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 312 | // Check that the predecessor is qualified to take the hoisted |
| 313 | // instruction. I.e., there is only one edge from the predecessor, and it's to |
| 314 | // the loop header. |
| 315 | MachineBasicBlock *MBB = Preds.front(); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 316 | |
Bill Wendling | 0fe34c2 | 2007-12-08 23:58:46 +0000 | [diff] [blame] | 317 | // FIXME: We are assuming at first that the basic block coming into this loop |
| 318 | // has only one successor. This isn't the case in general because we haven't |
| 319 | // broken critical edges or added preheaders. |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 320 | if (MBB->succ_size() != 1) return; |
| 321 | assert(*MBB->succ_begin() == CurLoop->getHeader() && |
| 322 | "The predecessor doesn't feed directly into the loop header!"); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 323 | |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 324 | // Now move the instructions to the predecessor. |
Bill Wendling | e91b2ef | 2007-12-11 19:17:04 +0000 | [diff] [blame] | 325 | MachineInstr *NewMI = MI.clone(); |
| 326 | MoveInstToEndOfBlock(MBB, NewMI); |
| 327 | |
| 328 | // Update VRegDefs. |
| 329 | for (unsigned i = 0, e = NewMI->getNumOperands(); i != e; ++i) { |
| 330 | const MachineOperand &MO = NewMI->getOperand(i); |
| 331 | |
| 332 | if (MO.isRegister() && MO.isDef() && |
| 333 | MRegisterInfo::isVirtualRegister(MO.getReg())) |
| 334 | VRegDefs[MO.getReg()] = NewMI; |
| 335 | } |
Bill Wendling | 7c7888b | 2007-12-08 01:47:01 +0000 | [diff] [blame] | 336 | |
| 337 | // Hoisting was successful! Remove bothersome instruction now. |
| 338 | MI.getParent()->remove(&MI); |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 339 | Changed = true; |
Bill Wendling | b958b0d | 2007-12-07 21:42:31 +0000 | [diff] [blame] | 340 | } |