Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 1 | //===-- MachineSink.cpp - Sinking for machine instructions ----------------===// |
| 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 | // |
Dan Gohman | a5225ad | 2009-08-05 01:19:01 +0000 | [diff] [blame] | 10 | // This pass moves instructions into successor blocks, when possible, so that |
| 11 | // they aren't executed on paths where their results aren't needed. |
| 12 | // |
| 13 | // This pass is not intended to be a replacement or a complete alternative |
| 14 | // for an LLVM-IR-level sinking pass. It is only designed to sink simple |
| 15 | // constructs that are not exposed before lowering and instruction selection. |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 16 | // |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
| 19 | #define DEBUG_TYPE "machine-sink" |
| 20 | #include "llvm/CodeGen/Passes.h" |
| 21 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 22 | #include "llvm/CodeGen/MachineDominators.h" |
Jakob Stoklund Olesen | 626f3d7 | 2010-04-15 23:41:02 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineLoopInfo.h" |
Dan Gohman | a70dca1 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/AliasAnalysis.h" |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetRegisterInfo.h" |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetInstrInfo.h" |
| 27 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/Statistic.h" |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Debug.h" |
Bill Wendling | 1e973aa | 2009-08-22 20:26:23 +0000 | [diff] [blame] | 30 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 31 | using namespace llvm; |
| 32 | |
| 33 | STATISTIC(NumSunk, "Number of machine instructions sunk"); |
| 34 | |
| 35 | namespace { |
Nick Lewycky | 6726b6d | 2009-10-25 06:33:48 +0000 | [diff] [blame] | 36 | class MachineSinking : public MachineFunctionPass { |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 37 | const TargetInstrInfo *TII; |
Dan Gohman | 19778e7 | 2009-09-25 22:53:29 +0000 | [diff] [blame] | 38 | const TargetRegisterInfo *TRI; |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 39 | MachineRegisterInfo *RegInfo; // Machine register information |
Dan Gohman | a5225ad | 2009-08-05 01:19:01 +0000 | [diff] [blame] | 40 | MachineDominatorTree *DT; // Machine dominator tree |
Jakob Stoklund Olesen | 626f3d7 | 2010-04-15 23:41:02 +0000 | [diff] [blame] | 41 | MachineLoopInfo *LI; |
Dan Gohman | a70dca1 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 42 | AliasAnalysis *AA; |
Dan Gohman | 45094e3 | 2009-09-26 02:34:00 +0000 | [diff] [blame] | 43 | BitVector AllocatableSet; // Which physregs are allocatable? |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 44 | |
| 45 | public: |
| 46 | static char ID; // Pass identification |
Dan Gohman | ae73dc1 | 2008-09-04 17:05:41 +0000 | [diff] [blame] | 47 | MachineSinking() : MachineFunctionPass(&ID) {} |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 48 | |
| 49 | virtual bool runOnMachineFunction(MachineFunction &MF); |
| 50 | |
| 51 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
Dan Gohman | 845012e | 2009-07-31 23:37:33 +0000 | [diff] [blame] | 52 | AU.setPreservesCFG(); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 53 | MachineFunctionPass::getAnalysisUsage(AU); |
Dan Gohman | a70dca1 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 54 | AU.addRequired<AliasAnalysis>(); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 55 | AU.addRequired<MachineDominatorTree>(); |
Jakob Stoklund Olesen | 626f3d7 | 2010-04-15 23:41:02 +0000 | [diff] [blame] | 56 | AU.addRequired<MachineLoopInfo>(); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 57 | AU.addPreserved<MachineDominatorTree>(); |
Jakob Stoklund Olesen | 626f3d7 | 2010-04-15 23:41:02 +0000 | [diff] [blame] | 58 | AU.addPreserved<MachineLoopInfo>(); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 59 | } |
| 60 | private: |
| 61 | bool ProcessBlock(MachineBasicBlock &MBB); |
Chris Lattner | aad193a | 2008-01-12 00:17:41 +0000 | [diff] [blame] | 62 | bool SinkInstruction(MachineInstr *MI, bool &SawStore); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 63 | bool AllUsesDominatedByBlock(unsigned Reg, MachineBasicBlock *MBB) const; |
| 64 | }; |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 65 | } // end anonymous namespace |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 66 | |
| 67 | char MachineSinking::ID = 0; |
| 68 | static RegisterPass<MachineSinking> |
| 69 | X("machine-sink", "Machine code sinking"); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 70 | |
| 71 | FunctionPass *llvm::createMachineSinkingPass() { return new MachineSinking(); } |
| 72 | |
| 73 | /// AllUsesDominatedByBlock - Return true if all uses of the specified register |
| 74 | /// occur in blocks dominated by the specified block. |
| 75 | bool MachineSinking::AllUsesDominatedByBlock(unsigned Reg, |
| 76 | MachineBasicBlock *MBB) const { |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 77 | assert(TargetRegisterInfo::isVirtualRegister(Reg) && |
| 78 | "Only makes sense for vregs"); |
Dale Johannesen | b0812f1 | 2010-03-05 00:02:59 +0000 | [diff] [blame] | 79 | // Ignoring debug uses is necessary so debug info doesn't affect the code. |
| 80 | // This may leave a referencing dbg_value in the original block, before |
| 81 | // the definition of the vreg. Dwarf generator handles this although the |
| 82 | // user might not get the right info at runtime. |
| 83 | for (MachineRegisterInfo::use_nodbg_iterator I = |
| 84 | RegInfo->use_nodbg_begin(Reg), |
| 85 | E = RegInfo->use_nodbg_end(); I != E; ++I) { |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 86 | // Determine the block of the use. |
| 87 | MachineInstr *UseInst = &*I; |
| 88 | MachineBasicBlock *UseBlock = UseInst->getParent(); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 89 | if (UseInst->isPHI()) { |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 90 | // PHI nodes use the operand in the predecessor block, not the block with |
| 91 | // the PHI. |
| 92 | UseBlock = UseInst->getOperand(I.getOperandNo()+1).getMBB(); |
| 93 | } |
| 94 | // Check that it dominates. |
| 95 | if (!DT->dominates(MBB, UseBlock)) |
| 96 | return false; |
| 97 | } |
| 98 | return true; |
| 99 | } |
| 100 | |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 101 | bool MachineSinking::runOnMachineFunction(MachineFunction &MF) { |
David Greene | c19a9cd | 2010-01-05 01:26:00 +0000 | [diff] [blame] | 102 | DEBUG(dbgs() << "******** Machine Sinking ********\n"); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 103 | |
Dan Gohman | 4e9785e | 2009-10-19 14:52:05 +0000 | [diff] [blame] | 104 | const TargetMachine &TM = MF.getTarget(); |
| 105 | TII = TM.getInstrInfo(); |
| 106 | TRI = TM.getRegisterInfo(); |
| 107 | RegInfo = &MF.getRegInfo(); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 108 | DT = &getAnalysis<MachineDominatorTree>(); |
Jakob Stoklund Olesen | 626f3d7 | 2010-04-15 23:41:02 +0000 | [diff] [blame] | 109 | LI = &getAnalysis<MachineLoopInfo>(); |
Dan Gohman | a70dca1 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 110 | AA = &getAnalysis<AliasAnalysis>(); |
Dan Gohman | 4e9785e | 2009-10-19 14:52:05 +0000 | [diff] [blame] | 111 | AllocatableSet = TRI->getAllocatableSet(MF); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 112 | |
| 113 | bool EverMadeChange = false; |
| 114 | |
| 115 | while (1) { |
| 116 | bool MadeChange = false; |
| 117 | |
| 118 | // Process all basic blocks. |
Dan Gohman | 4e9785e | 2009-10-19 14:52:05 +0000 | [diff] [blame] | 119 | for (MachineFunction::iterator I = MF.begin(), E = MF.end(); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 120 | I != E; ++I) |
| 121 | MadeChange |= ProcessBlock(*I); |
| 122 | |
| 123 | // If this iteration over the code changed anything, keep iterating. |
| 124 | if (!MadeChange) break; |
| 125 | EverMadeChange = true; |
| 126 | } |
| 127 | return EverMadeChange; |
| 128 | } |
| 129 | |
| 130 | bool MachineSinking::ProcessBlock(MachineBasicBlock &MBB) { |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 131 | // Can't sink anything out of a block that has less than two successors. |
Chris Lattner | 296185c | 2009-04-10 16:38:36 +0000 | [diff] [blame] | 132 | if (MBB.succ_size() <= 1 || MBB.empty()) return false; |
| 133 | |
Dan Gohman | c4ae94d | 2010-04-05 19:17:22 +0000 | [diff] [blame] | 134 | // Don't bother sinking code out of unreachable blocks. In addition to being |
| 135 | // unprofitable, it can also lead to infinite looping, because in an unreachable |
| 136 | // loop there may be nowhere to stop. |
| 137 | if (!DT->isReachableFromEntry(&MBB)) return false; |
| 138 | |
Chris Lattner | 296185c | 2009-04-10 16:38:36 +0000 | [diff] [blame] | 139 | bool MadeChange = false; |
| 140 | |
Chris Lattner | aad193a | 2008-01-12 00:17:41 +0000 | [diff] [blame] | 141 | // Walk the basic block bottom-up. Remember if we saw a store. |
Chris Lattner | 296185c | 2009-04-10 16:38:36 +0000 | [diff] [blame] | 142 | MachineBasicBlock::iterator I = MBB.end(); |
| 143 | --I; |
| 144 | bool ProcessedBegin, SawStore = false; |
| 145 | do { |
| 146 | MachineInstr *MI = I; // The instruction to sink. |
| 147 | |
| 148 | // Predecrement I (if it's not begin) so that it isn't invalidated by |
| 149 | // sinking. |
| 150 | ProcessedBegin = I == MBB.begin(); |
| 151 | if (!ProcessedBegin) |
| 152 | --I; |
Dale Johannesen | b0812f1 | 2010-03-05 00:02:59 +0000 | [diff] [blame] | 153 | |
| 154 | if (MI->isDebugValue()) |
| 155 | continue; |
| 156 | |
Chris Lattner | 296185c | 2009-04-10 16:38:36 +0000 | [diff] [blame] | 157 | if (SinkInstruction(MI, SawStore)) |
| 158 | ++NumSunk, MadeChange = true; |
| 159 | |
| 160 | // If we just processed the first instruction in the block, we're done. |
| 161 | } while (!ProcessedBegin); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 162 | |
| 163 | return MadeChange; |
| 164 | } |
| 165 | |
| 166 | /// SinkInstruction - Determine whether it is safe to sink the specified machine |
| 167 | /// instruction out of its current block into a successor. |
Chris Lattner | aad193a | 2008-01-12 00:17:41 +0000 | [diff] [blame] | 168 | bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) { |
Evan Cheng | b27087f | 2008-03-13 00:44:09 +0000 | [diff] [blame] | 169 | // Check if it's safe to move the instruction. |
Evan Cheng | ac1abde | 2010-03-02 19:03:01 +0000 | [diff] [blame] | 170 | if (!MI->isSafeToMove(TII, AA, SawStore)) |
Chris Lattner | aad193a | 2008-01-12 00:17:41 +0000 | [diff] [blame] | 171 | return false; |
Chris Lattner | e430e1c | 2008-01-05 06:47:58 +0000 | [diff] [blame] | 172 | |
| 173 | // FIXME: This should include support for sinking instructions within the |
| 174 | // block they are currently in to shorten the live ranges. We often get |
| 175 | // instructions sunk into the top of a large block, but it would be better to |
| 176 | // also sink them down before their first use in the block. This xform has to |
| 177 | // be careful not to *increase* register pressure though, e.g. sinking |
| 178 | // "x = y + z" down if it kills y and z would increase the live ranges of y |
Dan Gohman | a5225ad | 2009-08-05 01:19:01 +0000 | [diff] [blame] | 179 | // and z and only shrink the live range of x. |
Chris Lattner | e430e1c | 2008-01-05 06:47:58 +0000 | [diff] [blame] | 180 | |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 181 | // Loop over all the operands of the specified instruction. If there is |
| 182 | // anything we can't handle, bail out. |
| 183 | MachineBasicBlock *ParentBlock = MI->getParent(); |
| 184 | |
| 185 | // SuccToSinkTo - This is the successor to sink this instruction to, once we |
| 186 | // decide. |
| 187 | MachineBasicBlock *SuccToSinkTo = 0; |
| 188 | |
| 189 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 190 | const MachineOperand &MO = MI->getOperand(i); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 191 | if (!MO.isReg()) continue; // Ignore non-register operands. |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 192 | |
| 193 | unsigned Reg = MO.getReg(); |
| 194 | if (Reg == 0) continue; |
| 195 | |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 196 | if (TargetRegisterInfo::isPhysicalRegister(Reg)) { |
Dan Gohman | 19778e7 | 2009-09-25 22:53:29 +0000 | [diff] [blame] | 197 | if (MO.isUse()) { |
| 198 | // If the physreg has no defs anywhere, it's just an ambient register |
Dan Gohman | 45094e3 | 2009-09-26 02:34:00 +0000 | [diff] [blame] | 199 | // and we can freely move its uses. Alternatively, if it's allocatable, |
| 200 | // it could get allocated to something with a def during allocation. |
Dan Gohman | 19778e7 | 2009-09-25 22:53:29 +0000 | [diff] [blame] | 201 | if (!RegInfo->def_empty(Reg)) |
| 202 | return false; |
Dan Gohman | 45094e3 | 2009-09-26 02:34:00 +0000 | [diff] [blame] | 203 | if (AllocatableSet.test(Reg)) |
| 204 | return false; |
Dan Gohman | 19778e7 | 2009-09-25 22:53:29 +0000 | [diff] [blame] | 205 | // Check for a def among the register's aliases too. |
Dan Gohman | 45094e3 | 2009-09-26 02:34:00 +0000 | [diff] [blame] | 206 | for (const unsigned *Alias = TRI->getAliasSet(Reg); *Alias; ++Alias) { |
| 207 | unsigned AliasReg = *Alias; |
| 208 | if (!RegInfo->def_empty(AliasReg)) |
Dan Gohman | 19778e7 | 2009-09-25 22:53:29 +0000 | [diff] [blame] | 209 | return false; |
Dan Gohman | 45094e3 | 2009-09-26 02:34:00 +0000 | [diff] [blame] | 210 | if (AllocatableSet.test(AliasReg)) |
| 211 | return false; |
| 212 | } |
Dan Gohman | 19778e7 | 2009-09-25 22:53:29 +0000 | [diff] [blame] | 213 | } else if (!MO.isDead()) { |
| 214 | // A def that isn't dead. We can't move it. |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 215 | return false; |
Dan Gohman | 19778e7 | 2009-09-25 22:53:29 +0000 | [diff] [blame] | 216 | } |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 217 | } else { |
| 218 | // Virtual register uses are always safe to sink. |
| 219 | if (MO.isUse()) continue; |
Evan Cheng | b6f5417 | 2009-02-07 01:21:47 +0000 | [diff] [blame] | 220 | |
| 221 | // If it's not safe to move defs of the register class, then abort. |
| 222 | if (!TII->isSafeToMoveRegClassDefs(RegInfo->getRegClass(Reg))) |
| 223 | return false; |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 224 | |
Chris Lattner | e430e1c | 2008-01-05 06:47:58 +0000 | [diff] [blame] | 225 | // FIXME: This picks a successor to sink into based on having one |
| 226 | // successor that dominates all the uses. However, there are cases where |
| 227 | // sinking can happen but where the sink point isn't a successor. For |
| 228 | // example: |
| 229 | // x = computation |
| 230 | // if () {} else {} |
| 231 | // use x |
| 232 | // the instruction could be sunk over the whole diamond for the |
| 233 | // if/then/else (or loop, etc), allowing it to be sunk into other blocks |
| 234 | // after that. |
| 235 | |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 236 | // Virtual register defs can only be sunk if all their uses are in blocks |
| 237 | // dominated by one of the successors. |
| 238 | if (SuccToSinkTo) { |
| 239 | // If a previous operand picked a block to sink to, then this operand |
| 240 | // must be sinkable to the same block. |
| 241 | if (!AllUsesDominatedByBlock(Reg, SuccToSinkTo)) |
| 242 | return false; |
| 243 | continue; |
| 244 | } |
| 245 | |
| 246 | // Otherwise, we should look at all the successors and decide which one |
| 247 | // we should sink to. |
| 248 | for (MachineBasicBlock::succ_iterator SI = ParentBlock->succ_begin(), |
| 249 | E = ParentBlock->succ_end(); SI != E; ++SI) { |
| 250 | if (AllUsesDominatedByBlock(Reg, *SI)) { |
| 251 | SuccToSinkTo = *SI; |
| 252 | break; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | // If we couldn't find a block to sink to, ignore this instruction. |
| 257 | if (SuccToSinkTo == 0) |
| 258 | return false; |
| 259 | } |
| 260 | } |
| 261 | |
Chris Lattner | 9bb459b | 2008-01-05 01:39:17 +0000 | [diff] [blame] | 262 | // If there are no outputs, it must have side-effects. |
| 263 | if (SuccToSinkTo == 0) |
| 264 | return false; |
Evan Cheng | b599979 | 2009-02-15 08:36:12 +0000 | [diff] [blame] | 265 | |
| 266 | // It's not safe to sink instructions to EH landing pad. Control flow into |
| 267 | // landing pad is implicitly defined. |
| 268 | if (SuccToSinkTo->isLandingPad()) |
| 269 | return false; |
Chris Lattner | 9bb459b | 2008-01-05 01:39:17 +0000 | [diff] [blame] | 270 | |
Dan Gohman | dfffba6 | 2009-10-19 14:56:05 +0000 | [diff] [blame] | 271 | // It is not possible to sink an instruction into its own block. This can |
Chris Lattner | 296185c | 2009-04-10 16:38:36 +0000 | [diff] [blame] | 272 | // happen with loops. |
| 273 | if (MI->getParent() == SuccToSinkTo) |
| 274 | return false; |
| 275 | |
David Greene | c19a9cd | 2010-01-05 01:26:00 +0000 | [diff] [blame] | 276 | DEBUG(dbgs() << "Sink instr " << *MI); |
| 277 | DEBUG(dbgs() << "to block " << *SuccToSinkTo); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 278 | |
| 279 | // If the block has multiple predecessors, this would introduce computation on |
| 280 | // a path that it doesn't already exist. We could split the critical edge, |
| 281 | // but for now we just punt. |
Chris Lattner | e430e1c | 2008-01-05 06:47:58 +0000 | [diff] [blame] | 282 | // FIXME: Split critical edges if not backedges. |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 283 | if (SuccToSinkTo->pred_size() > 1) { |
Jakob Stoklund Olesen | 8d17160 | 2010-04-13 19:06:14 +0000 | [diff] [blame] | 284 | // We cannot sink a load across a critical edge - there may be stores in |
| 285 | // other code paths. |
| 286 | bool store = true; |
| 287 | if (!MI->isSafeToMove(TII, AA, store)) { |
| 288 | DEBUG(dbgs() << " *** PUNTING: Wont sink load along critical edge.\n"); |
| 289 | return false; |
| 290 | } |
| 291 | |
| 292 | // We don't want to sink across a critical edge if we don't dominate the |
| 293 | // successor. We could be introducing calculations to new code paths. |
| 294 | if (!DT->dominates(ParentBlock, SuccToSinkTo)) { |
| 295 | DEBUG(dbgs() << " *** PUNTING: Critical edge found\n"); |
| 296 | return false; |
| 297 | } |
| 298 | |
Jakob Stoklund Olesen | 626f3d7 | 2010-04-15 23:41:02 +0000 | [diff] [blame] | 299 | // Don't sink instructions into a loop. |
| 300 | if (LI->isLoopHeader(SuccToSinkTo)) { |
| 301 | DEBUG(dbgs() << " *** PUNTING: Loop header found\n"); |
| 302 | return false; |
| 303 | } |
| 304 | |
Jakob Stoklund Olesen | 8d17160 | 2010-04-13 19:06:14 +0000 | [diff] [blame] | 305 | // Otherwise we are OK with sinking along a critical edge. |
| 306 | DEBUG(dbgs() << "Sinking along critical edge.\n"); |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | // Determine where to insert into. Skip phi nodes. |
| 310 | MachineBasicBlock::iterator InsertPos = SuccToSinkTo->begin(); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 311 | while (InsertPos != SuccToSinkTo->end() && InsertPos->isPHI()) |
Chris Lattner | c4ce73f | 2008-01-04 07:36:53 +0000 | [diff] [blame] | 312 | ++InsertPos; |
| 313 | |
| 314 | // Move the instruction. |
| 315 | SuccToSinkTo->splice(InsertPos, ParentBlock, MI, |
| 316 | ++MachineBasicBlock::iterator(MI)); |
| 317 | return true; |
| 318 | } |