Dan Gohman | a629b48 | 2008-12-08 17:50:35 +0000 | [diff] [blame] | 1 | //===---- ScheduleDAGInstrs.cpp - MachineInstr Rescheduling ---------------===// |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 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 | a629b48 | 2008-12-08 17:50:35 +0000 | [diff] [blame] | 10 | // This implements the ScheduleDAGInstrs class, which implements re-scheduling |
| 11 | // of MachineInstrs. |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #define DEBUG_TYPE "sched-instrs" |
Dan Gohman | 6dc75fe | 2009-02-06 17:12:10 +0000 | [diff] [blame] | 16 | #include "ScheduleDAGInstrs.h" |
Dan Gohman | 8906f95 | 2009-07-17 20:58:59 +0000 | [diff] [blame] | 17 | #include "llvm/Operator.h" |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 18 | #include "llvm/Analysis/AliasAnalysis.h" |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineMemOperand.h" |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetMachine.h" |
| 24 | #include "llvm/Target/TargetInstrInfo.h" |
| 25 | #include "llvm/Target/TargetRegisterInfo.h" |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetSubtarget.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Debug.h" |
| 28 | #include "llvm/Support/raw_ostream.h" |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/SmallSet.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 32 | ScheduleDAGInstrs::ScheduleDAGInstrs(MachineFunction &mf, |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 33 | const MachineLoopInfo &mli, |
| 34 | const MachineDominatorTree &mdt) |
Evan Cheng | 38bdfc6 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 35 | : ScheduleDAG(mf), MLI(mli), MDT(mdt), LoopRegs(MLI, MDT) { |
| 36 | MFI = mf.getFrameInfo(); |
| 37 | } |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 38 | |
Dan Gohman | 47ac0f0 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 39 | /// Run - perform scheduling. |
| 40 | /// |
| 41 | void ScheduleDAGInstrs::Run(MachineBasicBlock *bb, |
| 42 | MachineBasicBlock::iterator begin, |
| 43 | MachineBasicBlock::iterator end, |
| 44 | unsigned endcount) { |
| 45 | BB = bb; |
| 46 | Begin = begin; |
| 47 | InsertPosIndex = endcount; |
| 48 | |
| 49 | ScheduleDAG::Run(bb, end); |
| 50 | } |
| 51 | |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 52 | /// getUnderlyingObjectFromInt - This is the function that does the work of |
| 53 | /// looking through basic ptrtoint+arithmetic+inttoptr sequences. |
| 54 | static const Value *getUnderlyingObjectFromInt(const Value *V) { |
| 55 | do { |
Dan Gohman | 8906f95 | 2009-07-17 20:58:59 +0000 | [diff] [blame] | 56 | if (const Operator *U = dyn_cast<Operator>(V)) { |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 57 | // If we find a ptrtoint, we can transfer control back to the |
| 58 | // regular getUnderlyingObjectFromInt. |
Dan Gohman | 8906f95 | 2009-07-17 20:58:59 +0000 | [diff] [blame] | 59 | if (U->getOpcode() == Instruction::PtrToInt) |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 60 | return U->getOperand(0); |
| 61 | // If we find an add of a constant or a multiplied value, it's |
| 62 | // likely that the other operand will lead us to the base |
| 63 | // object. We don't have to worry about the case where the |
Dan Gohman | 748f98f | 2009-08-07 01:26:06 +0000 | [diff] [blame] | 64 | // object address is somehow being computed by the multiply, |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 65 | // because our callers only care when the result is an |
| 66 | // identifibale object. |
Dan Gohman | 8906f95 | 2009-07-17 20:58:59 +0000 | [diff] [blame] | 67 | if (U->getOpcode() != Instruction::Add || |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 68 | (!isa<ConstantInt>(U->getOperand(1)) && |
Dan Gohman | 8906f95 | 2009-07-17 20:58:59 +0000 | [diff] [blame] | 69 | Operator::getOpcode(U->getOperand(1)) != Instruction::Mul)) |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 70 | return V; |
| 71 | V = U->getOperand(0); |
| 72 | } else { |
| 73 | return V; |
| 74 | } |
Duncan Sands | 1df9859 | 2010-02-16 11:11:14 +0000 | [diff] [blame^] | 75 | assert(V->getType()->isIntegerTy() && "Unexpected operand type!"); |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 76 | } while (1); |
| 77 | } |
| 78 | |
| 79 | /// getUnderlyingObject - This is a wrapper around Value::getUnderlyingObject |
| 80 | /// and adds support for basic ptrtoint+arithmetic+inttoptr sequences. |
| 81 | static const Value *getUnderlyingObject(const Value *V) { |
| 82 | // First just call Value::getUnderlyingObject to let it do what it does. |
| 83 | do { |
| 84 | V = V->getUnderlyingObject(); |
| 85 | // If it found an inttoptr, use special code to continue climing. |
Dan Gohman | 8906f95 | 2009-07-17 20:58:59 +0000 | [diff] [blame] | 86 | if (Operator::getOpcode(V) != Instruction::IntToPtr) |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 87 | break; |
| 88 | const Value *O = getUnderlyingObjectFromInt(cast<User>(V)->getOperand(0)); |
| 89 | // If that succeeded in finding a pointer, continue the search. |
Duncan Sands | 1df9859 | 2010-02-16 11:11:14 +0000 | [diff] [blame^] | 90 | if (!O->getType()->isPointerTy()) |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 91 | break; |
| 92 | V = O; |
| 93 | } while (1); |
| 94 | return V; |
| 95 | } |
| 96 | |
| 97 | /// getUnderlyingObjectForInstr - If this machine instr has memory reference |
| 98 | /// information and it can be tracked to a normal reference to a known |
| 99 | /// object, return the Value for that object. Otherwise return null. |
Evan Cheng | 38bdfc6 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 100 | static const Value *getUnderlyingObjectForInstr(const MachineInstr *MI, |
David Goodwin | a9e6107 | 2009-11-03 20:15:00 +0000 | [diff] [blame] | 101 | const MachineFrameInfo *MFI, |
| 102 | bool &MayAlias) { |
| 103 | MayAlias = true; |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 104 | if (!MI->hasOneMemOperand() || |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 105 | !(*MI->memoperands_begin())->getValue() || |
| 106 | (*MI->memoperands_begin())->isVolatile()) |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 107 | return 0; |
| 108 | |
Dan Gohman | c76909a | 2009-09-25 20:36:54 +0000 | [diff] [blame] | 109 | const Value *V = (*MI->memoperands_begin())->getValue(); |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 110 | if (!V) |
| 111 | return 0; |
| 112 | |
| 113 | V = getUnderlyingObject(V); |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 114 | if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) { |
| 115 | // For now, ignore PseudoSourceValues which may alias LLVM IR values |
| 116 | // because the code that uses this function has no way to cope with |
| 117 | // such aliases. |
Evan Cheng | 38bdfc6 | 2009-10-18 19:58:47 +0000 | [diff] [blame] | 118 | if (PSV->isAliased(MFI)) |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 119 | return 0; |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 120 | |
| 121 | MayAlias = PSV->mayAlias(MFI); |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 122 | return V; |
| 123 | } |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 124 | |
Evan Cheng | ff89dcb | 2009-10-18 18:16:27 +0000 | [diff] [blame] | 125 | if (isIdentifiedObject(V)) |
| 126 | return V; |
| 127 | |
| 128 | return 0; |
Dan Gohman | 3311a1f | 2009-01-30 02:49:14 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Dan Gohman | 9e64bbb | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 131 | void ScheduleDAGInstrs::StartBlock(MachineBasicBlock *BB) { |
| 132 | if (MachineLoop *ML = MLI.getLoopFor(BB)) |
| 133 | if (BB == ML->getLoopLatch()) { |
| 134 | MachineBasicBlock *Header = ML->getHeader(); |
| 135 | for (MachineBasicBlock::livein_iterator I = Header->livein_begin(), |
| 136 | E = Header->livein_end(); I != E; ++I) |
| 137 | LoopLiveInRegs.insert(*I); |
| 138 | LoopRegs.VisitLoop(ML); |
| 139 | } |
| 140 | } |
| 141 | |
Dan Gohman | a70dca1 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 142 | void ScheduleDAGInstrs::BuildSchedGraph(AliasAnalysis *AA) { |
Dan Gohman | 9e64bbb | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 143 | // We'll be allocating one SUnit for each instruction, plus one for |
| 144 | // the region exit node. |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 145 | SUnits.reserve(BB->size()); |
| 146 | |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 147 | // We build scheduling units by walking a block's instruction list from bottom |
| 148 | // to top. |
| 149 | |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 150 | // Remember where a generic side-effecting instruction is as we procede. |
| 151 | SUnit *BarrierChain = 0, *AliasChain = 0; |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 152 | |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 153 | // Memory references to specific known memory locations are tracked |
| 154 | // so that they can be given more precise dependencies. We track |
| 155 | // separately the known memory locations that may alias and those |
| 156 | // that are known not to alias |
| 157 | std::map<const Value *, SUnit *> AliasMemDefs, NonAliasMemDefs; |
| 158 | std::map<const Value *, std::vector<SUnit *> > AliasMemUses, NonAliasMemUses; |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 159 | |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 160 | // Check to see if the scheduler cares about latencies. |
| 161 | bool UnitLatencies = ForceUnitLatencies(); |
| 162 | |
Dan Gohman | 8749b61 | 2008-12-16 03:35:01 +0000 | [diff] [blame] | 163 | // Ask the target if address-backscheduling is desirable, and if so how much. |
David Goodwin | 7104616 | 2009-08-13 16:05:04 +0000 | [diff] [blame] | 164 | const TargetSubtarget &ST = TM.getSubtarget<TargetSubtarget>(); |
| 165 | unsigned SpecialAddressLatency = ST.getSpecialAddressLatency(); |
Dan Gohman | 8749b61 | 2008-12-16 03:35:01 +0000 | [diff] [blame] | 166 | |
Dan Gohman | 9e64bbb | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 167 | // Walk the list of instructions, from bottom moving up. |
Dan Gohman | 47ac0f0 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 168 | for (MachineBasicBlock::iterator MII = InsertPos, MIE = Begin; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 169 | MII != MIE; --MII) { |
| 170 | MachineInstr *MI = prior(MII); |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 171 | const TargetInstrDesc &TID = MI->getDesc(); |
Dan Gohman | 9e64bbb | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 172 | assert(!TID.isTerminator() && !MI->isLabel() && |
| 173 | "Cannot schedule terminators or labels!"); |
| 174 | // Create the SUnit for this MI. |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 175 | SUnit *SU = NewSUnit(MI); |
| 176 | |
Dan Gohman | 54e4c36 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 177 | // Assign the Latency field of SU using target-provided information. |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 178 | if (UnitLatencies) |
| 179 | SU->Latency = 1; |
| 180 | else |
| 181 | ComputeLatency(SU); |
Dan Gohman | 54e4c36 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 182 | |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 183 | // Add register-based dependencies (data, anti, and output). |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 184 | for (unsigned j = 0, n = MI->getNumOperands(); j != n; ++j) { |
| 185 | const MachineOperand &MO = MI->getOperand(j); |
| 186 | if (!MO.isReg()) continue; |
| 187 | unsigned Reg = MO.getReg(); |
| 188 | if (Reg == 0) continue; |
| 189 | |
| 190 | assert(TRI->isPhysicalRegister(Reg) && "Virtual register encountered!"); |
| 191 | std::vector<SUnit *> &UseList = Uses[Reg]; |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 192 | std::vector<SUnit *> &DefList = Defs[Reg]; |
David Goodwin | d94a4e5 | 2009-08-10 15:55:25 +0000 | [diff] [blame] | 193 | // Optionally add output and anti dependencies. For anti |
| 194 | // dependencies we use a latency of 0 because for a multi-issue |
| 195 | // target we want to allow the defining instruction to issue |
| 196 | // in the same cycle as the using instruction. |
| 197 | // TODO: Using a latency of 1 here for output dependencies assumes |
| 198 | // there's no cost for reusing registers. |
Dan Gohman | 54e4c36 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 199 | SDep::Kind Kind = MO.isUse() ? SDep::Anti : SDep::Output; |
David Goodwin | d94a4e5 | 2009-08-10 15:55:25 +0000 | [diff] [blame] | 200 | unsigned AOLatency = (Kind == SDep::Anti) ? 0 : 1; |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 201 | for (unsigned i = 0, e = DefList.size(); i != e; ++i) { |
| 202 | SUnit *DefSU = DefList[i]; |
| 203 | if (DefSU != SU && |
| 204 | (Kind != SDep::Output || !MO.isDead() || |
| 205 | !DefSU->getInstr()->registerDefIsDead(Reg))) |
David Goodwin | d94a4e5 | 2009-08-10 15:55:25 +0000 | [diff] [blame] | 206 | DefSU->addPred(SDep(SU, Kind, AOLatency, /*Reg=*/Reg)); |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 207 | } |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 208 | for (const unsigned *Alias = TRI->getAliasSet(Reg); *Alias; ++Alias) { |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 209 | std::vector<SUnit *> &DefList = Defs[*Alias]; |
| 210 | for (unsigned i = 0, e = DefList.size(); i != e; ++i) { |
| 211 | SUnit *DefSU = DefList[i]; |
| 212 | if (DefSU != SU && |
| 213 | (Kind != SDep::Output || !MO.isDead() || |
Dan Gohman | 91203cf | 2009-10-26 18:26:18 +0000 | [diff] [blame] | 214 | !DefSU->getInstr()->registerDefIsDead(*Alias))) |
David Goodwin | d94a4e5 | 2009-08-10 15:55:25 +0000 | [diff] [blame] | 215 | DefSU->addPred(SDep(SU, Kind, AOLatency, /*Reg=*/ *Alias)); |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 216 | } |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | if (MO.isDef()) { |
| 220 | // Add any data dependencies. |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 221 | unsigned DataLatency = SU->Latency; |
| 222 | for (unsigned i = 0, e = UseList.size(); i != e; ++i) { |
| 223 | SUnit *UseSU = UseList[i]; |
| 224 | if (UseSU != SU) { |
Dan Gohman | 8749b61 | 2008-12-16 03:35:01 +0000 | [diff] [blame] | 225 | unsigned LDataLatency = DataLatency; |
| 226 | // Optionally add in a special extra latency for nodes that |
| 227 | // feed addresses. |
| 228 | // TODO: Do this for register aliases too. |
David Goodwin | dc4bdcd | 2009-08-19 16:08:58 +0000 | [diff] [blame] | 229 | // TODO: Perhaps we should get rid of |
| 230 | // SpecialAddressLatency and just move this into |
| 231 | // adjustSchedDependency for the targets that care about |
| 232 | // it. |
Dan Gohman | 8749b61 | 2008-12-16 03:35:01 +0000 | [diff] [blame] | 233 | if (SpecialAddressLatency != 0 && !UnitLatencies) { |
| 234 | MachineInstr *UseMI = UseSU->getInstr(); |
| 235 | const TargetInstrDesc &UseTID = UseMI->getDesc(); |
| 236 | int RegUseIndex = UseMI->findRegisterUseOperandIdx(Reg); |
| 237 | assert(RegUseIndex >= 0 && "UseMI doesn's use register!"); |
| 238 | if ((UseTID.mayLoad() || UseTID.mayStore()) && |
| 239 | (unsigned)RegUseIndex < UseTID.getNumOperands() && |
| 240 | UseTID.OpInfo[RegUseIndex].isLookupPtrRegClass()) |
| 241 | LDataLatency += SpecialAddressLatency; |
| 242 | } |
David Goodwin | dc4bdcd | 2009-08-19 16:08:58 +0000 | [diff] [blame] | 243 | // Adjust the dependence latency using operand def/use |
| 244 | // information (if any), and then allow the target to |
| 245 | // perform its own adjustments. |
David Goodwin | 7104616 | 2009-08-13 16:05:04 +0000 | [diff] [blame] | 246 | const SDep& dep = SDep(SU, SDep::Data, LDataLatency, Reg); |
David Goodwin | dc4bdcd | 2009-08-19 16:08:58 +0000 | [diff] [blame] | 247 | if (!UnitLatencies) { |
| 248 | ComputeOperandLatency(SU, UseSU, (SDep &)dep); |
| 249 | ST.adjustSchedDependency(SU, UseSU, (SDep &)dep); |
| 250 | } |
David Goodwin | 7104616 | 2009-08-13 16:05:04 +0000 | [diff] [blame] | 251 | UseSU->addPred(dep); |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 252 | } |
| 253 | } |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 254 | for (const unsigned *Alias = TRI->getAliasSet(Reg); *Alias; ++Alias) { |
| 255 | std::vector<SUnit *> &UseList = Uses[*Alias]; |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 256 | for (unsigned i = 0, e = UseList.size(); i != e; ++i) { |
| 257 | SUnit *UseSU = UseList[i]; |
David Goodwin | 7104616 | 2009-08-13 16:05:04 +0000 | [diff] [blame] | 258 | if (UseSU != SU) { |
| 259 | const SDep& dep = SDep(SU, SDep::Data, DataLatency, *Alias); |
David Goodwin | dc4bdcd | 2009-08-19 16:08:58 +0000 | [diff] [blame] | 260 | if (!UnitLatencies) { |
| 261 | ComputeOperandLatency(SU, UseSU, (SDep &)dep); |
| 262 | ST.adjustSchedDependency(SU, UseSU, (SDep &)dep); |
| 263 | } |
David Goodwin | 7104616 | 2009-08-13 16:05:04 +0000 | [diff] [blame] | 264 | UseSU->addPred(dep); |
| 265 | } |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 266 | } |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Dan Gohman | 8749b61 | 2008-12-16 03:35:01 +0000 | [diff] [blame] | 269 | // If a def is going to wrap back around to the top of the loop, |
| 270 | // backschedule it. |
Dan Gohman | 9e64bbb | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 271 | if (!UnitLatencies && DefList.empty()) { |
Dan Gohman | 8749b61 | 2008-12-16 03:35:01 +0000 | [diff] [blame] | 272 | LoopDependencies::LoopDeps::iterator I = LoopRegs.Deps.find(Reg); |
| 273 | if (I != LoopRegs.Deps.end()) { |
| 274 | const MachineOperand *UseMO = I->second.first; |
| 275 | unsigned Count = I->second.second; |
| 276 | const MachineInstr *UseMI = UseMO->getParent(); |
| 277 | unsigned UseMOIdx = UseMO - &UseMI->getOperand(0); |
| 278 | const TargetInstrDesc &UseTID = UseMI->getDesc(); |
| 279 | // TODO: If we knew the total depth of the region here, we could |
| 280 | // handle the case where the whole loop is inside the region but |
| 281 | // is large enough that the isScheduleHigh trick isn't needed. |
| 282 | if (UseMOIdx < UseTID.getNumOperands()) { |
| 283 | // Currently, we only support scheduling regions consisting of |
| 284 | // single basic blocks. Check to see if the instruction is in |
| 285 | // the same region by checking to see if it has the same parent. |
| 286 | if (UseMI->getParent() != MI->getParent()) { |
| 287 | unsigned Latency = SU->Latency; |
| 288 | if (UseTID.OpInfo[UseMOIdx].isLookupPtrRegClass()) |
| 289 | Latency += SpecialAddressLatency; |
| 290 | // This is a wild guess as to the portion of the latency which |
| 291 | // will be overlapped by work done outside the current |
| 292 | // scheduling region. |
| 293 | Latency -= std::min(Latency, Count); |
| 294 | // Add the artifical edge. |
Dan Gohman | 9e64bbb | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 295 | ExitSU.addPred(SDep(SU, SDep::Order, Latency, |
| 296 | /*Reg=*/0, /*isNormalMemory=*/false, |
| 297 | /*isMustAlias=*/false, |
| 298 | /*isArtificial=*/true)); |
Dan Gohman | 8749b61 | 2008-12-16 03:35:01 +0000 | [diff] [blame] | 299 | } else if (SpecialAddressLatency > 0 && |
| 300 | UseTID.OpInfo[UseMOIdx].isLookupPtrRegClass()) { |
| 301 | // The entire loop body is within the current scheduling region |
| 302 | // and the latency of this operation is assumed to be greater |
| 303 | // than the latency of the loop. |
| 304 | // TODO: Recursively mark data-edge predecessors as |
| 305 | // isScheduleHigh too. |
| 306 | SU->isScheduleHigh = true; |
| 307 | } |
| 308 | } |
| 309 | LoopRegs.Deps.erase(I); |
| 310 | } |
| 311 | } |
| 312 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 313 | UseList.clear(); |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 314 | if (!MO.isDead()) |
| 315 | DefList.clear(); |
| 316 | DefList.push_back(SU); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 317 | } else { |
| 318 | UseList.push_back(SU); |
| 319 | } |
| 320 | } |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 321 | |
| 322 | // Add chain dependencies. |
David Goodwin | 7c9b1ac | 2009-11-02 17:06:28 +0000 | [diff] [blame] | 323 | // Chain dependencies used to enforce memory order should have |
| 324 | // latency of 0 (except for true dependency of Store followed by |
| 325 | // aliased Load... we estimate that with a single cycle of latency |
| 326 | // assuming the hardware will bypass) |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 327 | // Note that isStoreToStackSlot and isLoadFromStackSLot are not usable |
| 328 | // after stack slots are lowered to actual addresses. |
| 329 | // TODO: Use an AliasAnalysis and do real alias-analysis queries, and |
| 330 | // produce more precise dependence information. |
David Goodwin | 7c9b1ac | 2009-11-02 17:06:28 +0000 | [diff] [blame] | 331 | #define STORE_LOAD_LATENCY 1 |
| 332 | unsigned TrueMemOrderLatency = 0; |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 333 | if (TID.isCall() || TID.hasUnmodeledSideEffects() || |
| 334 | (MI->hasVolatileMemoryRef() && |
| 335 | (!TID.mayLoad() || !MI->isInvariantLoad(AA)))) { |
| 336 | // Be conservative with these and add dependencies on all memory |
| 337 | // references, even those that are known to not alias. |
| 338 | for (std::map<const Value *, SUnit *>::iterator I = |
| 339 | NonAliasMemDefs.begin(), E = NonAliasMemDefs.end(); I != E; ++I) { |
David Goodwin | 7c9b1ac | 2009-11-02 17:06:28 +0000 | [diff] [blame] | 340 | I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0)); |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 341 | } |
| 342 | for (std::map<const Value *, std::vector<SUnit *> >::iterator I = |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 343 | NonAliasMemUses.begin(), E = NonAliasMemUses.end(); I != E; ++I) { |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 344 | for (unsigned i = 0, e = I->second.size(); i != e; ++i) |
David Goodwin | 7c9b1ac | 2009-11-02 17:06:28 +0000 | [diff] [blame] | 345 | I->second[i]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency)); |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 346 | } |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 347 | NonAliasMemDefs.clear(); |
| 348 | NonAliasMemUses.clear(); |
| 349 | // Add SU to the barrier chain. |
| 350 | if (BarrierChain) |
| 351 | BarrierChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0)); |
| 352 | BarrierChain = SU; |
| 353 | |
| 354 | // fall-through |
| 355 | new_alias_chain: |
| 356 | // Chain all possibly aliasing memory references though SU. |
| 357 | if (AliasChain) |
| 358 | AliasChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0)); |
| 359 | AliasChain = SU; |
| 360 | for (unsigned k = 0, m = PendingLoads.size(); k != m; ++k) |
| 361 | PendingLoads[k]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency)); |
| 362 | for (std::map<const Value *, SUnit *>::iterator I = AliasMemDefs.begin(), |
| 363 | E = AliasMemDefs.end(); I != E; ++I) { |
| 364 | I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0)); |
| 365 | } |
| 366 | for (std::map<const Value *, std::vector<SUnit *> >::iterator I = |
| 367 | AliasMemUses.begin(), E = AliasMemUses.end(); I != E; ++I) { |
| 368 | for (unsigned i = 0, e = I->second.size(); i != e; ++i) |
| 369 | I->second[i]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency)); |
| 370 | } |
| 371 | PendingLoads.clear(); |
| 372 | AliasMemDefs.clear(); |
| 373 | AliasMemUses.clear(); |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 374 | } else if (TID.mayStore()) { |
David Goodwin | a9e6107 | 2009-11-03 20:15:00 +0000 | [diff] [blame] | 375 | bool MayAlias = true; |
David Goodwin | 7c9b1ac | 2009-11-02 17:06:28 +0000 | [diff] [blame] | 376 | TrueMemOrderLatency = STORE_LOAD_LATENCY; |
David Goodwin | a9e6107 | 2009-11-03 20:15:00 +0000 | [diff] [blame] | 377 | if (const Value *V = getUnderlyingObjectForInstr(MI, MFI, MayAlias)) { |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 378 | // A store to a specific PseudoSourceValue. Add precise dependencies. |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 379 | // Record the def in MemDefs, first adding a dep if there is |
| 380 | // an existing def. |
| 381 | std::map<const Value *, SUnit *>::iterator I = |
| 382 | ((MayAlias) ? AliasMemDefs.find(V) : NonAliasMemDefs.find(V)); |
| 383 | std::map<const Value *, SUnit *>::iterator IE = |
| 384 | ((MayAlias) ? AliasMemDefs.end() : NonAliasMemDefs.end()); |
| 385 | if (I != IE) { |
David Goodwin | 7c9b1ac | 2009-11-02 17:06:28 +0000 | [diff] [blame] | 386 | I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0, /*Reg=*/0, |
Dan Gohman | 54e4c36 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 387 | /*isNormalMemory=*/true)); |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 388 | I->second = SU; |
| 389 | } else { |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 390 | if (MayAlias) |
| 391 | AliasMemDefs[V] = SU; |
| 392 | else |
| 393 | NonAliasMemDefs[V] = SU; |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 394 | } |
| 395 | // Handle the uses in MemUses, if there are any. |
Dan Gohman | a629b48 | 2008-12-08 17:50:35 +0000 | [diff] [blame] | 396 | std::map<const Value *, std::vector<SUnit *> >::iterator J = |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 397 | ((MayAlias) ? AliasMemUses.find(V) : NonAliasMemUses.find(V)); |
| 398 | std::map<const Value *, std::vector<SUnit *> >::iterator JE = |
| 399 | ((MayAlias) ? AliasMemUses.end() : NonAliasMemUses.end()); |
| 400 | if (J != JE) { |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 401 | for (unsigned i = 0, e = J->second.size(); i != e; ++i) |
David Goodwin | 7c9b1ac | 2009-11-02 17:06:28 +0000 | [diff] [blame] | 402 | J->second[i]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency, |
| 403 | /*Reg=*/0, /*isNormalMemory=*/true)); |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 404 | J->second.clear(); |
| 405 | } |
David Goodwin | a9e6107 | 2009-11-03 20:15:00 +0000 | [diff] [blame] | 406 | if (MayAlias) { |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 407 | // Add dependencies from all the PendingLoads, i.e. loads |
| 408 | // with no underlying object. |
David Goodwin | a9e6107 | 2009-11-03 20:15:00 +0000 | [diff] [blame] | 409 | for (unsigned k = 0, m = PendingLoads.size(); k != m; ++k) |
| 410 | PendingLoads[k]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency)); |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 411 | // Add dependence on alias chain, if needed. |
| 412 | if (AliasChain) |
| 413 | AliasChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0)); |
David Goodwin | a9e6107 | 2009-11-03 20:15:00 +0000 | [diff] [blame] | 414 | } |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 415 | // Add dependence on barrier chain, if needed. |
| 416 | if (BarrierChain) |
| 417 | BarrierChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0)); |
David Goodwin | 5be870a | 2009-11-05 00:16:44 +0000 | [diff] [blame] | 418 | } else { |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 419 | // Treat all other stores conservatively. |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 420 | goto new_alias_chain; |
David Goodwin | 7c9b1ac | 2009-11-02 17:06:28 +0000 | [diff] [blame] | 421 | } |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 422 | } else if (TID.mayLoad()) { |
David Goodwin | a9e6107 | 2009-11-03 20:15:00 +0000 | [diff] [blame] | 423 | bool MayAlias = true; |
David Goodwin | 7c9b1ac | 2009-11-02 17:06:28 +0000 | [diff] [blame] | 424 | TrueMemOrderLatency = 0; |
Dan Gohman | a70dca1 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 425 | if (MI->isInvariantLoad(AA)) { |
Dan Gohman | 6a9041e | 2008-12-04 01:35:46 +0000 | [diff] [blame] | 426 | // Invariant load, no chain dependencies needed! |
David Goodwin | 5be870a | 2009-11-05 00:16:44 +0000 | [diff] [blame] | 427 | } else { |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 428 | if (const Value *V = |
| 429 | getUnderlyingObjectForInstr(MI, MFI, MayAlias)) { |
| 430 | // A load from a specific PseudoSourceValue. Add precise dependencies. |
| 431 | std::map<const Value *, SUnit *>::iterator I = |
| 432 | ((MayAlias) ? AliasMemDefs.find(V) : NonAliasMemDefs.find(V)); |
| 433 | std::map<const Value *, SUnit *>::iterator IE = |
| 434 | ((MayAlias) ? AliasMemDefs.end() : NonAliasMemDefs.end()); |
| 435 | if (I != IE) |
| 436 | I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0, /*Reg=*/0, |
| 437 | /*isNormalMemory=*/true)); |
| 438 | if (MayAlias) |
| 439 | AliasMemUses[V].push_back(SU); |
| 440 | else |
| 441 | NonAliasMemUses[V].push_back(SU); |
| 442 | } else { |
| 443 | // A load with no underlying object. Depend on all |
| 444 | // potentially aliasing stores. |
| 445 | for (std::map<const Value *, SUnit *>::iterator I = |
| 446 | AliasMemDefs.begin(), E = AliasMemDefs.end(); I != E; ++I) |
| 447 | I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0)); |
| 448 | |
| 449 | PendingLoads.push_back(SU); |
| 450 | MayAlias = true; |
David Goodwin | a9e6107 | 2009-11-03 20:15:00 +0000 | [diff] [blame] | 451 | } |
David Goodwin | 980d494 | 2009-11-09 19:22:17 +0000 | [diff] [blame] | 452 | |
| 453 | // Add dependencies on alias and barrier chains, if needed. |
| 454 | if (MayAlias && AliasChain) |
| 455 | AliasChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0)); |
| 456 | if (BarrierChain) |
| 457 | BarrierChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0)); |
| 458 | } |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 459 | } |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 460 | } |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 461 | |
| 462 | for (int i = 0, e = TRI->getNumRegs(); i != e; ++i) { |
| 463 | Defs[i].clear(); |
| 464 | Uses[i].clear(); |
| 465 | } |
| 466 | PendingLoads.clear(); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 467 | } |
| 468 | |
Dan Gohman | 9e64bbb | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 469 | void ScheduleDAGInstrs::FinishBlock() { |
| 470 | // Nothing to do. |
| 471 | } |
| 472 | |
Dan Gohman | c8c2827 | 2008-11-21 00:12:10 +0000 | [diff] [blame] | 473 | void ScheduleDAGInstrs::ComputeLatency(SUnit *SU) { |
| 474 | const InstrItineraryData &InstrItins = TM.getInstrItineraryData(); |
| 475 | |
David Goodwin | d94a4e5 | 2009-08-10 15:55:25 +0000 | [diff] [blame] | 476 | // Compute the latency for the node. |
Dan Gohman | c8c2827 | 2008-11-21 00:12:10 +0000 | [diff] [blame] | 477 | SU->Latency = |
David Goodwin | dc4bdcd | 2009-08-19 16:08:58 +0000 | [diff] [blame] | 478 | InstrItins.getStageLatency(SU->getInstr()->getDesc().getSchedClass()); |
Dan Gohman | 4ea8e85 | 2008-12-16 02:38:22 +0000 | [diff] [blame] | 479 | |
| 480 | // Simplistic target-independent heuristic: assume that loads take |
| 481 | // extra time. |
| 482 | if (InstrItins.isEmpty()) |
| 483 | if (SU->getInstr()->getDesc().mayLoad()) |
| 484 | SU->Latency += 2; |
Dan Gohman | c8c2827 | 2008-11-21 00:12:10 +0000 | [diff] [blame] | 485 | } |
| 486 | |
David Goodwin | dc4bdcd | 2009-08-19 16:08:58 +0000 | [diff] [blame] | 487 | void ScheduleDAGInstrs::ComputeOperandLatency(SUnit *Def, SUnit *Use, |
| 488 | SDep& dep) const { |
| 489 | const InstrItineraryData &InstrItins = TM.getInstrItineraryData(); |
| 490 | if (InstrItins.isEmpty()) |
| 491 | return; |
| 492 | |
| 493 | // For a data dependency with a known register... |
| 494 | if ((dep.getKind() != SDep::Data) || (dep.getReg() == 0)) |
| 495 | return; |
| 496 | |
| 497 | const unsigned Reg = dep.getReg(); |
| 498 | |
| 499 | // ... find the definition of the register in the defining |
| 500 | // instruction |
| 501 | MachineInstr *DefMI = Def->getInstr(); |
| 502 | int DefIdx = DefMI->findRegisterDefOperandIdx(Reg); |
| 503 | if (DefIdx != -1) { |
| 504 | int DefCycle = InstrItins.getOperandCycle(DefMI->getDesc().getSchedClass(), DefIdx); |
| 505 | if (DefCycle >= 0) { |
| 506 | MachineInstr *UseMI = Use->getInstr(); |
| 507 | const unsigned UseClass = UseMI->getDesc().getSchedClass(); |
| 508 | |
| 509 | // For all uses of the register, calculate the maxmimum latency |
| 510 | int Latency = -1; |
| 511 | for (unsigned i = 0, e = UseMI->getNumOperands(); i != e; ++i) { |
| 512 | const MachineOperand &MO = UseMI->getOperand(i); |
| 513 | if (!MO.isReg() || !MO.isUse()) |
| 514 | continue; |
| 515 | unsigned MOReg = MO.getReg(); |
| 516 | if (MOReg != Reg) |
| 517 | continue; |
| 518 | |
| 519 | int UseCycle = InstrItins.getOperandCycle(UseClass, i); |
| 520 | if (UseCycle >= 0) |
| 521 | Latency = std::max(Latency, DefCycle - UseCycle + 1); |
| 522 | } |
| 523 | |
| 524 | // If we found a latency, then replace the existing dependence latency. |
| 525 | if (Latency >= 0) |
| 526 | dep.setLatency(Latency); |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 531 | void ScheduleDAGInstrs::dumpNode(const SUnit *SU) const { |
| 532 | SU->getInstr()->dump(); |
| 533 | } |
| 534 | |
| 535 | std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const { |
| 536 | std::string s; |
| 537 | raw_string_ostream oss(s); |
Dan Gohman | 9e64bbb | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 538 | if (SU == &EntrySU) |
| 539 | oss << "<entry>"; |
| 540 | else if (SU == &ExitSU) |
| 541 | oss << "<exit>"; |
| 542 | else |
| 543 | SU->getInstr()->print(oss); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 544 | return oss.str(); |
| 545 | } |
| 546 | |
| 547 | // EmitSchedule - Emit the machine code in scheduled order. |
Evan Cheng | fb2e752 | 2009-09-18 21:02:19 +0000 | [diff] [blame] | 548 | MachineBasicBlock *ScheduleDAGInstrs:: |
| 549 | EmitSchedule(DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) { |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 550 | // For MachineInstr-based scheduling, we're rescheduling the instructions in |
| 551 | // the block, so start by removing them from the block. |
Dan Gohman | 47ac0f0 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 552 | while (Begin != InsertPos) { |
Dan Gohman | f711939 | 2009-01-16 22:10:20 +0000 | [diff] [blame] | 553 | MachineBasicBlock::iterator I = Begin; |
| 554 | ++Begin; |
| 555 | BB->remove(I); |
| 556 | } |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 557 | |
Dan Gohman | 0b1d4a7 | 2008-12-23 21:37:04 +0000 | [diff] [blame] | 558 | // Then re-insert them according to the given schedule. |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 559 | for (unsigned i = 0, e = Sequence.size(); i != e; i++) { |
| 560 | SUnit *SU = Sequence[i]; |
| 561 | if (!SU) { |
| 562 | // Null SUnit* is a noop. |
| 563 | EmitNoop(); |
| 564 | continue; |
| 565 | } |
| 566 | |
Dan Gohman | 47ac0f0 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 567 | BB->insert(InsertPos, SU->getInstr()); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Dan Gohman | 9e64bbb | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 570 | // Update the Begin iterator, as the first instruction in the block |
| 571 | // may have been scheduled later. |
| 572 | if (!Sequence.empty()) |
| 573 | Begin = Sequence[0]->getInstr(); |
| 574 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 575 | return BB; |
| 576 | } |