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