blob: b382169a3613db5a7f578f3036559bcb78f5d6f4 [file] [log] [blame]
Dan Gohmana629b482008-12-08 17:50:35 +00001//===---- ScheduleDAGInstrs.cpp - MachineInstr Rescheduling ---------------===//
Dan Gohman343f0c02008-11-19 23:18:57 +00002//
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 Gohmana629b482008-12-08 17:50:35 +000010// This implements the ScheduleDAGInstrs class, which implements re-scheduling
11// of MachineInstrs.
Dan Gohman343f0c02008-11-19 23:18:57 +000012//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "sched-instrs"
Dan Gohman6dc75fe2009-02-06 17:12:10 +000016#include "ScheduleDAGInstrs.h"
Dan Gohman8906f952009-07-17 20:58:59 +000017#include "llvm/Operator.h"
Dan Gohman3311a1f2009-01-30 02:49:14 +000018#include "llvm/Analysis/AliasAnalysis.h"
Dan Gohman5034dd32010-12-15 20:02:24 +000019#include "llvm/Analysis/ValueTracking.h"
Dan Gohman3f237442008-12-16 03:25:46 +000020#include "llvm/CodeGen/MachineFunctionPass.h"
Dan Gohmanc76909a2009-09-25 20:36:54 +000021#include "llvm/CodeGen/MachineMemOperand.h"
Dan Gohman3f237442008-12-16 03:25:46 +000022#include "llvm/CodeGen/MachineRegisterInfo.h"
Dan Gohman6a9041e2008-12-04 01:35:46 +000023#include "llvm/CodeGen/PseudoSourceValue.h"
Evan Chengab8be962011-06-29 01:14:12 +000024#include "llvm/MC/MCInstrItineraries.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000025#include "llvm/Target/TargetMachine.h"
26#include "llvm/Target/TargetInstrInfo.h"
27#include "llvm/Target/TargetRegisterInfo.h"
Evan Cheng5b1b44892011-07-01 21:01:15 +000028#include "llvm/Target/TargetSubtargetInfo.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000029#include "llvm/Support/Debug.h"
30#include "llvm/Support/raw_ostream.h"
Dan Gohman3f237442008-12-16 03:25:46 +000031#include "llvm/ADT/SmallSet.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000032using namespace llvm;
33
Dan Gohman79ce2762009-01-15 19:20:50 +000034ScheduleDAGInstrs::ScheduleDAGInstrs(MachineFunction &mf,
Dan Gohman3f237442008-12-16 03:25:46 +000035 const MachineLoopInfo &mli,
36 const MachineDominatorTree &mdt)
Evan Cheng3ef1c872010-09-10 01:29:16 +000037 : ScheduleDAG(mf), MLI(mli), MDT(mdt), MFI(mf.getFrameInfo()),
38 InstrItins(mf.getTarget().getInstrItineraryData()),
Andrew Trick4563bba2011-10-07 06:27:02 +000039 Defs(TRI->getNumRegs()), Uses(TRI->getNumRegs()),
Devang Patele29e8e12011-06-02 21:26:52 +000040 LoopRegs(MLI, MDT), FirstDbgValue(0) {
Devang Patelcf4cc842011-06-02 20:07:12 +000041 DbgValues.clear();
Evan Cheng38bdfc62009-10-18 19:58:47 +000042}
Dan Gohman343f0c02008-11-19 23:18:57 +000043
Dan Gohman47ac0f02009-02-11 04:27:20 +000044/// Run - perform scheduling.
45///
46void ScheduleDAGInstrs::Run(MachineBasicBlock *bb,
47 MachineBasicBlock::iterator begin,
48 MachineBasicBlock::iterator end,
49 unsigned endcount) {
50 BB = bb;
51 Begin = begin;
52 InsertPosIndex = endcount;
53
54 ScheduleDAG::Run(bb, end);
55}
56
Dan Gohman3311a1f2009-01-30 02:49:14 +000057/// getUnderlyingObjectFromInt - This is the function that does the work of
58/// looking through basic ptrtoint+arithmetic+inttoptr sequences.
59static const Value *getUnderlyingObjectFromInt(const Value *V) {
60 do {
Dan Gohman8906f952009-07-17 20:58:59 +000061 if (const Operator *U = dyn_cast<Operator>(V)) {
Dan Gohman3311a1f2009-01-30 02:49:14 +000062 // If we find a ptrtoint, we can transfer control back to the
63 // regular getUnderlyingObjectFromInt.
Dan Gohman8906f952009-07-17 20:58:59 +000064 if (U->getOpcode() == Instruction::PtrToInt)
Dan Gohman3311a1f2009-01-30 02:49:14 +000065 return U->getOperand(0);
66 // If we find an add of a constant or a multiplied value, it's
67 // likely that the other operand will lead us to the base
68 // object. We don't have to worry about the case where the
Dan Gohman748f98f2009-08-07 01:26:06 +000069 // object address is somehow being computed by the multiply,
Dan Gohman3311a1f2009-01-30 02:49:14 +000070 // because our callers only care when the result is an
71 // identifibale object.
Dan Gohman8906f952009-07-17 20:58:59 +000072 if (U->getOpcode() != Instruction::Add ||
Dan Gohman3311a1f2009-01-30 02:49:14 +000073 (!isa<ConstantInt>(U->getOperand(1)) &&
Dan Gohman8906f952009-07-17 20:58:59 +000074 Operator::getOpcode(U->getOperand(1)) != Instruction::Mul))
Dan Gohman3311a1f2009-01-30 02:49:14 +000075 return V;
76 V = U->getOperand(0);
77 } else {
78 return V;
79 }
Duncan Sands1df98592010-02-16 11:11:14 +000080 assert(V->getType()->isIntegerTy() && "Unexpected operand type!");
Dan Gohman3311a1f2009-01-30 02:49:14 +000081 } while (1);
82}
83
Dan Gohman5034dd32010-12-15 20:02:24 +000084/// getUnderlyingObject - This is a wrapper around GetUnderlyingObject
Dan Gohman3311a1f2009-01-30 02:49:14 +000085/// and adds support for basic ptrtoint+arithmetic+inttoptr sequences.
86static const Value *getUnderlyingObject(const Value *V) {
87 // First just call Value::getUnderlyingObject to let it do what it does.
88 do {
Dan Gohman5034dd32010-12-15 20:02:24 +000089 V = GetUnderlyingObject(V);
Dan Gohman3311a1f2009-01-30 02:49:14 +000090 // If it found an inttoptr, use special code to continue climing.
Dan Gohman8906f952009-07-17 20:58:59 +000091 if (Operator::getOpcode(V) != Instruction::IntToPtr)
Dan Gohman3311a1f2009-01-30 02:49:14 +000092 break;
93 const Value *O = getUnderlyingObjectFromInt(cast<User>(V)->getOperand(0));
94 // If that succeeded in finding a pointer, continue the search.
Duncan Sands1df98592010-02-16 11:11:14 +000095 if (!O->getType()->isPointerTy())
Dan Gohman3311a1f2009-01-30 02:49:14 +000096 break;
97 V = O;
98 } while (1);
99 return V;
100}
101
102/// getUnderlyingObjectForInstr - If this machine instr has memory reference
103/// information and it can be tracked to a normal reference to a known
104/// object, return the Value for that object. Otherwise return null.
Evan Cheng38bdfc62009-10-18 19:58:47 +0000105static const Value *getUnderlyingObjectForInstr(const MachineInstr *MI,
David Goodwina9e61072009-11-03 20:15:00 +0000106 const MachineFrameInfo *MFI,
107 bool &MayAlias) {
108 MayAlias = true;
Dan Gohman3311a1f2009-01-30 02:49:14 +0000109 if (!MI->hasOneMemOperand() ||
Dan Gohmanc76909a2009-09-25 20:36:54 +0000110 !(*MI->memoperands_begin())->getValue() ||
111 (*MI->memoperands_begin())->isVolatile())
Dan Gohman3311a1f2009-01-30 02:49:14 +0000112 return 0;
113
Dan Gohmanc76909a2009-09-25 20:36:54 +0000114 const Value *V = (*MI->memoperands_begin())->getValue();
Dan Gohman3311a1f2009-01-30 02:49:14 +0000115 if (!V)
116 return 0;
117
118 V = getUnderlyingObject(V);
Evan Chengff89dcb2009-10-18 18:16:27 +0000119 if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) {
120 // For now, ignore PseudoSourceValues which may alias LLVM IR values
121 // because the code that uses this function has no way to cope with
122 // such aliases.
Evan Cheng38bdfc62009-10-18 19:58:47 +0000123 if (PSV->isAliased(MFI))
Evan Chengff89dcb2009-10-18 18:16:27 +0000124 return 0;
Andrew Trickf405b1a2011-05-05 19:24:06 +0000125
David Goodwin980d4942009-11-09 19:22:17 +0000126 MayAlias = PSV->mayAlias(MFI);
Evan Chengff89dcb2009-10-18 18:16:27 +0000127 return V;
128 }
Dan Gohman3311a1f2009-01-30 02:49:14 +0000129
Evan Chengff89dcb2009-10-18 18:16:27 +0000130 if (isIdentifiedObject(V))
131 return V;
132
133 return 0;
Dan Gohman3311a1f2009-01-30 02:49:14 +0000134}
135
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000136void ScheduleDAGInstrs::StartBlock(MachineBasicBlock *BB) {
Andrew Tricke8deca82011-10-07 06:33:09 +0000137 LoopRegs.Deps.clear();
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000138 if (MachineLoop *ML = MLI.getLoopFor(BB))
139 if (BB == ML->getLoopLatch()) {
140 MachineBasicBlock *Header = ML->getHeader();
141 for (MachineBasicBlock::livein_iterator I = Header->livein_begin(),
142 E = Header->livein_end(); I != E; ++I)
143 LoopLiveInRegs.insert(*I);
144 LoopRegs.VisitLoop(ML);
145 }
146}
147
Evan Chengec6906b2010-10-23 02:10:46 +0000148/// AddSchedBarrierDeps - Add dependencies from instructions in the current
149/// list of instructions being scheduled to scheduling barrier by adding
150/// the exit SU to the register defs and use list. This is because we want to
151/// make sure instructions which define registers that are either used by
152/// the terminator or are live-out are properly scheduled. This is
153/// especially important when the definition latency of the return value(s)
154/// are too high to be hidden by the branch or when the liveout registers
155/// used by instructions in the fallthrough block.
156void ScheduleDAGInstrs::AddSchedBarrierDeps() {
157 MachineInstr *ExitMI = InsertPos != BB->end() ? &*InsertPos : 0;
158 ExitSU.setInstr(ExitMI);
159 bool AllDepKnown = ExitMI &&
160 (ExitMI->getDesc().isCall() || ExitMI->getDesc().isBarrier());
161 if (ExitMI && AllDepKnown) {
162 // If it's a call or a barrier, add dependencies on the defs and uses of
163 // instruction.
164 for (unsigned i = 0, e = ExitMI->getNumOperands(); i != e; ++i) {
165 const MachineOperand &MO = ExitMI->getOperand(i);
166 if (!MO.isReg() || MO.isDef()) continue;
167 unsigned Reg = MO.getReg();
168 if (Reg == 0) continue;
169
170 assert(TRI->isPhysicalRegister(Reg) && "Virtual register encountered!");
171 Uses[Reg].push_back(&ExitSU);
172 }
173 } else {
174 // For others, e.g. fallthrough, conditional branch, assume the exit
Evan Chengde5fa932010-10-27 23:17:17 +0000175 // uses all the registers that are livein to the successor blocks.
176 SmallSet<unsigned, 8> Seen;
177 for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
178 SE = BB->succ_end(); SI != SE; ++SI)
179 for (MachineBasicBlock::livein_iterator I = (*SI)->livein_begin(),
Andrew Trickf405b1a2011-05-05 19:24:06 +0000180 E = (*SI)->livein_end(); I != E; ++I) {
Evan Chengde5fa932010-10-27 23:17:17 +0000181 unsigned Reg = *I;
182 if (Seen.insert(Reg))
183 Uses[Reg].push_back(&ExitSU);
184 }
Evan Chengec6906b2010-10-23 02:10:46 +0000185 }
186}
187
Dan Gohmana70dca12009-10-09 23:27:56 +0000188void ScheduleDAGInstrs::BuildSchedGraph(AliasAnalysis *AA) {
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000189 // We'll be allocating one SUnit for each instruction, plus one for
190 // the region exit node.
Dan Gohman343f0c02008-11-19 23:18:57 +0000191 SUnits.reserve(BB->size());
192
Dan Gohman6a9041e2008-12-04 01:35:46 +0000193 // We build scheduling units by walking a block's instruction list from bottom
194 // to top.
195
David Goodwin980d4942009-11-09 19:22:17 +0000196 // Remember where a generic side-effecting instruction is as we procede.
197 SUnit *BarrierChain = 0, *AliasChain = 0;
Dan Gohman6a9041e2008-12-04 01:35:46 +0000198
David Goodwin980d4942009-11-09 19:22:17 +0000199 // Memory references to specific known memory locations are tracked
200 // so that they can be given more precise dependencies. We track
201 // separately the known memory locations that may alias and those
202 // that are known not to alias
203 std::map<const Value *, SUnit *> AliasMemDefs, NonAliasMemDefs;
204 std::map<const Value *, std::vector<SUnit *> > AliasMemUses, NonAliasMemUses;
Dan Gohman6a9041e2008-12-04 01:35:46 +0000205
Dan Gohman3f237442008-12-16 03:25:46 +0000206 // Check to see if the scheduler cares about latencies.
207 bool UnitLatencies = ForceUnitLatencies();
208
Dan Gohman8749b612008-12-16 03:35:01 +0000209 // Ask the target if address-backscheduling is desirable, and if so how much.
Evan Cheng5b1b44892011-07-01 21:01:15 +0000210 const TargetSubtargetInfo &ST = TM.getSubtarget<TargetSubtargetInfo>();
David Goodwin71046162009-08-13 16:05:04 +0000211 unsigned SpecialAddressLatency = ST.getSpecialAddressLatency();
Dan Gohman8749b612008-12-16 03:35:01 +0000212
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000213 // Remove any stale debug info; sometimes BuildSchedGraph is called again
214 // without emitting the info from the previous call.
Devang Patelcf4cc842011-06-02 20:07:12 +0000215 DbgValues.clear();
216 FirstDbgValue = NULL;
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000217
Evan Chengec6906b2010-10-23 02:10:46 +0000218 // Model data dependencies between instructions being scheduled and the
219 // ExitSU.
220 AddSchedBarrierDeps();
221
Andrew Trick9b668532011-05-06 21:52:52 +0000222 for (int i = 0, e = TRI->getNumRegs(); i != e; ++i) {
223 assert(Defs[i].empty() && "Only BuildGraph should push/pop Defs");
224 }
225
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000226 // Walk the list of instructions, from bottom moving up.
Devang Patelcf4cc842011-06-02 20:07:12 +0000227 MachineInstr *PrevMI = NULL;
Dan Gohman47ac0f02009-02-11 04:27:20 +0000228 for (MachineBasicBlock::iterator MII = InsertPos, MIE = Begin;
Dan Gohman343f0c02008-11-19 23:18:57 +0000229 MII != MIE; --MII) {
230 MachineInstr *MI = prior(MII);
Devang Patelcf4cc842011-06-02 20:07:12 +0000231 if (MI && PrevMI) {
232 DbgValues.push_back(std::make_pair(PrevMI, MI));
233 PrevMI = NULL;
234 }
235
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000236 if (MI->isDebugValue()) {
Devang Patelcf4cc842011-06-02 20:07:12 +0000237 PrevMI = MI;
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000238 continue;
239 }
Devang Patelcf4cc842011-06-02 20:07:12 +0000240
Evan Chenge837dea2011-06-28 19:10:37 +0000241 const MCInstrDesc &MCID = MI->getDesc();
242 assert(!MCID.isTerminator() && !MI->isLabel() &&
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000243 "Cannot schedule terminators or labels!");
244 // Create the SUnit for this MI.
Dan Gohman343f0c02008-11-19 23:18:57 +0000245 SUnit *SU = NewSUnit(MI);
Evan Chenge837dea2011-06-28 19:10:37 +0000246 SU->isCall = MCID.isCall();
247 SU->isCommutable = MCID.isCommutable();
Dan Gohman343f0c02008-11-19 23:18:57 +0000248
Dan Gohman54e4c362008-12-09 22:54:47 +0000249 // Assign the Latency field of SU using target-provided information.
Dan Gohman3f237442008-12-16 03:25:46 +0000250 if (UnitLatencies)
251 SU->Latency = 1;
252 else
253 ComputeLatency(SU);
Dan Gohman54e4c362008-12-09 22:54:47 +0000254
Dan Gohman6a9041e2008-12-04 01:35:46 +0000255 // Add register-based dependencies (data, anti, and output).
Dan Gohman343f0c02008-11-19 23:18:57 +0000256 for (unsigned j = 0, n = MI->getNumOperands(); j != n; ++j) {
257 const MachineOperand &MO = MI->getOperand(j);
258 if (!MO.isReg()) continue;
259 unsigned Reg = MO.getReg();
260 if (Reg == 0) continue;
261
262 assert(TRI->isPhysicalRegister(Reg) && "Virtual register encountered!");
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000263
Dan Gohman343f0c02008-11-19 23:18:57 +0000264 std::vector<SUnit *> &UseList = Uses[Reg];
Andrew Trick9b668532011-05-06 21:52:52 +0000265 // Defs are push in the order they are visited and never reordered.
Dan Gohman3f237442008-12-16 03:25:46 +0000266 std::vector<SUnit *> &DefList = Defs[Reg];
David Goodwind94a4e52009-08-10 15:55:25 +0000267 // Optionally add output and anti dependencies. For anti
268 // dependencies we use a latency of 0 because for a multi-issue
269 // target we want to allow the defining instruction to issue
270 // in the same cycle as the using instruction.
271 // TODO: Using a latency of 1 here for output dependencies assumes
272 // there's no cost for reusing registers.
Dan Gohman54e4c362008-12-09 22:54:47 +0000273 SDep::Kind Kind = MO.isUse() ? SDep::Anti : SDep::Output;
David Goodwind94a4e52009-08-10 15:55:25 +0000274 unsigned AOLatency = (Kind == SDep::Anti) ? 0 : 1;
Dan Gohman3f237442008-12-16 03:25:46 +0000275 for (unsigned i = 0, e = DefList.size(); i != e; ++i) {
276 SUnit *DefSU = DefList[i];
Evan Chengec6906b2010-10-23 02:10:46 +0000277 if (DefSU == &ExitSU)
278 continue;
Dan Gohman3f237442008-12-16 03:25:46 +0000279 if (DefSU != SU &&
280 (Kind != SDep::Output || !MO.isDead() ||
281 !DefSU->getInstr()->registerDefIsDead(Reg)))
David Goodwind94a4e52009-08-10 15:55:25 +0000282 DefSU->addPred(SDep(SU, Kind, AOLatency, /*Reg=*/Reg));
Dan Gohman3f237442008-12-16 03:25:46 +0000283 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000284 for (const unsigned *Alias = TRI->getAliasSet(Reg); *Alias; ++Alias) {
Andrew Trick9b668532011-05-06 21:52:52 +0000285 std::vector<SUnit *> &MemDefList = Defs[*Alias];
286 for (unsigned i = 0, e = MemDefList.size(); i != e; ++i) {
287 SUnit *DefSU = MemDefList[i];
Evan Chengec6906b2010-10-23 02:10:46 +0000288 if (DefSU == &ExitSU)
289 continue;
Dan Gohman3f237442008-12-16 03:25:46 +0000290 if (DefSU != SU &&
291 (Kind != SDep::Output || !MO.isDead() ||
Dan Gohman91203cf2009-10-26 18:26:18 +0000292 !DefSU->getInstr()->registerDefIsDead(*Alias)))
David Goodwind94a4e52009-08-10 15:55:25 +0000293 DefSU->addPred(SDep(SU, Kind, AOLatency, /*Reg=*/ *Alias));
Dan Gohman3f237442008-12-16 03:25:46 +0000294 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000295 }
296
297 if (MO.isDef()) {
298 // Add any data dependencies.
Dan Gohman3f237442008-12-16 03:25:46 +0000299 unsigned DataLatency = SU->Latency;
300 for (unsigned i = 0, e = UseList.size(); i != e; ++i) {
301 SUnit *UseSU = UseList[i];
Evan Chenga69ec092010-03-22 21:24:33 +0000302 if (UseSU == SU)
303 continue;
304 unsigned LDataLatency = DataLatency;
305 // Optionally add in a special extra latency for nodes that
306 // feed addresses.
307 // TODO: Do this for register aliases too.
308 // TODO: Perhaps we should get rid of
309 // SpecialAddressLatency and just move this into
310 // adjustSchedDependency for the targets that care about it.
Evan Chengec6906b2010-10-23 02:10:46 +0000311 if (SpecialAddressLatency != 0 && !UnitLatencies &&
312 UseSU != &ExitSU) {
Evan Chenga69ec092010-03-22 21:24:33 +0000313 MachineInstr *UseMI = UseSU->getInstr();
Evan Chenge837dea2011-06-28 19:10:37 +0000314 const MCInstrDesc &UseMCID = UseMI->getDesc();
Evan Chenga69ec092010-03-22 21:24:33 +0000315 int RegUseIndex = UseMI->findRegisterUseOperandIdx(Reg);
316 assert(RegUseIndex >= 0 && "UseMI doesn's use register!");
Evan Chengec6906b2010-10-23 02:10:46 +0000317 if (RegUseIndex >= 0 &&
Evan Chenge837dea2011-06-28 19:10:37 +0000318 (UseMCID.mayLoad() || UseMCID.mayStore()) &&
319 (unsigned)RegUseIndex < UseMCID.getNumOperands() &&
320 UseMCID.OpInfo[RegUseIndex].isLookupPtrRegClass())
Evan Chenga69ec092010-03-22 21:24:33 +0000321 LDataLatency += SpecialAddressLatency;
Dan Gohman3f237442008-12-16 03:25:46 +0000322 }
Evan Chenga69ec092010-03-22 21:24:33 +0000323 // Adjust the dependence latency using operand def/use
324 // information (if any), and then allow the target to
325 // perform its own adjustments.
326 const SDep& dep = SDep(SU, SDep::Data, LDataLatency, Reg);
327 if (!UnitLatencies) {
Dan Gohman3fb150a2010-04-17 17:42:52 +0000328 ComputeOperandLatency(SU, UseSU, const_cast<SDep &>(dep));
329 ST.adjustSchedDependency(SU, UseSU, const_cast<SDep &>(dep));
Evan Chenga69ec092010-03-22 21:24:33 +0000330 }
331 UseSU->addPred(dep);
Dan Gohman3f237442008-12-16 03:25:46 +0000332 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000333 for (const unsigned *Alias = TRI->getAliasSet(Reg); *Alias; ++Alias) {
334 std::vector<SUnit *> &UseList = Uses[*Alias];
Dan Gohman3f237442008-12-16 03:25:46 +0000335 for (unsigned i = 0, e = UseList.size(); i != e; ++i) {
336 SUnit *UseSU = UseList[i];
Evan Chenga69ec092010-03-22 21:24:33 +0000337 if (UseSU == SU)
338 continue;
339 const SDep& dep = SDep(SU, SDep::Data, DataLatency, *Alias);
340 if (!UnitLatencies) {
Dan Gohman3fb150a2010-04-17 17:42:52 +0000341 ComputeOperandLatency(SU, UseSU, const_cast<SDep &>(dep));
342 ST.adjustSchedDependency(SU, UseSU, const_cast<SDep &>(dep));
David Goodwin71046162009-08-13 16:05:04 +0000343 }
Evan Chenga69ec092010-03-22 21:24:33 +0000344 UseSU->addPred(dep);
Dan Gohman3f237442008-12-16 03:25:46 +0000345 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000346 }
347
Dan Gohman8749b612008-12-16 03:35:01 +0000348 // If a def is going to wrap back around to the top of the loop,
349 // backschedule it.
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000350 if (!UnitLatencies && DefList.empty()) {
Dan Gohman8749b612008-12-16 03:35:01 +0000351 LoopDependencies::LoopDeps::iterator I = LoopRegs.Deps.find(Reg);
352 if (I != LoopRegs.Deps.end()) {
353 const MachineOperand *UseMO = I->second.first;
354 unsigned Count = I->second.second;
355 const MachineInstr *UseMI = UseMO->getParent();
356 unsigned UseMOIdx = UseMO - &UseMI->getOperand(0);
Evan Chenge837dea2011-06-28 19:10:37 +0000357 const MCInstrDesc &UseMCID = UseMI->getDesc();
Dan Gohman8749b612008-12-16 03:35:01 +0000358 // TODO: If we knew the total depth of the region here, we could
359 // handle the case where the whole loop is inside the region but
360 // is large enough that the isScheduleHigh trick isn't needed.
Evan Chenge837dea2011-06-28 19:10:37 +0000361 if (UseMOIdx < UseMCID.getNumOperands()) {
Dan Gohman8749b612008-12-16 03:35:01 +0000362 // Currently, we only support scheduling regions consisting of
363 // single basic blocks. Check to see if the instruction is in
364 // the same region by checking to see if it has the same parent.
365 if (UseMI->getParent() != MI->getParent()) {
366 unsigned Latency = SU->Latency;
Evan Chenge837dea2011-06-28 19:10:37 +0000367 if (UseMCID.OpInfo[UseMOIdx].isLookupPtrRegClass())
Dan Gohman8749b612008-12-16 03:35:01 +0000368 Latency += SpecialAddressLatency;
369 // This is a wild guess as to the portion of the latency which
370 // will be overlapped by work done outside the current
371 // scheduling region.
372 Latency -= std::min(Latency, Count);
Chris Lattner7a2bdde2011-04-15 05:18:47 +0000373 // Add the artificial edge.
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000374 ExitSU.addPred(SDep(SU, SDep::Order, Latency,
375 /*Reg=*/0, /*isNormalMemory=*/false,
376 /*isMustAlias=*/false,
377 /*isArtificial=*/true));
Dan Gohman8749b612008-12-16 03:35:01 +0000378 } else if (SpecialAddressLatency > 0 &&
Evan Chenge837dea2011-06-28 19:10:37 +0000379 UseMCID.OpInfo[UseMOIdx].isLookupPtrRegClass()) {
Dan Gohman8749b612008-12-16 03:35:01 +0000380 // The entire loop body is within the current scheduling region
381 // and the latency of this operation is assumed to be greater
382 // than the latency of the loop.
383 // TODO: Recursively mark data-edge predecessors as
384 // isScheduleHigh too.
385 SU->isScheduleHigh = true;
386 }
387 }
388 LoopRegs.Deps.erase(I);
389 }
390 }
391
Dan Gohman343f0c02008-11-19 23:18:57 +0000392 UseList.clear();
Dan Gohman3f237442008-12-16 03:25:46 +0000393 if (!MO.isDead())
394 DefList.clear();
Andrew Trickee109152011-05-05 19:32:21 +0000395
396 // Calls will not be reordered because of chain dependencies (see
397 // below). Since call operands are dead, calls may continue to be added
398 // to the DefList making dependence checking quadratic in the size of
399 // the block. Instead, we leave only one call at the back of the
400 // DefList.
Andrew Trickee109152011-05-05 19:32:21 +0000401 if (SU->isCall) {
402 while (!DefList.empty() && DefList.back()->isCall)
403 DefList.pop_back();
404 }
Dan Gohman3f237442008-12-16 03:25:46 +0000405 DefList.push_back(SU);
Dan Gohman343f0c02008-11-19 23:18:57 +0000406 } else {
407 UseList.push_back(SU);
408 }
409 }
Dan Gohman6a9041e2008-12-04 01:35:46 +0000410
411 // Add chain dependencies.
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000412 // Chain dependencies used to enforce memory order should have
413 // latency of 0 (except for true dependency of Store followed by
414 // aliased Load... we estimate that with a single cycle of latency
415 // assuming the hardware will bypass)
Dan Gohman6a9041e2008-12-04 01:35:46 +0000416 // Note that isStoreToStackSlot and isLoadFromStackSLot are not usable
417 // after stack slots are lowered to actual addresses.
418 // TODO: Use an AliasAnalysis and do real alias-analysis queries, and
419 // produce more precise dependence information.
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000420#define STORE_LOAD_LATENCY 1
421 unsigned TrueMemOrderLatency = 0;
Evan Chenge837dea2011-06-28 19:10:37 +0000422 if (MCID.isCall() || MI->hasUnmodeledSideEffects() ||
Andrew Trickf405b1a2011-05-05 19:24:06 +0000423 (MI->hasVolatileMemoryRef() &&
Evan Chenge837dea2011-06-28 19:10:37 +0000424 (!MCID.mayLoad() || !MI->isInvariantLoad(AA)))) {
David Goodwin980d4942009-11-09 19:22:17 +0000425 // Be conservative with these and add dependencies on all memory
426 // references, even those that are known to not alias.
Andrew Trickf405b1a2011-05-05 19:24:06 +0000427 for (std::map<const Value *, SUnit *>::iterator I =
David Goodwin980d4942009-11-09 19:22:17 +0000428 NonAliasMemDefs.begin(), E = NonAliasMemDefs.end(); I != E; ++I) {
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000429 I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000430 }
431 for (std::map<const Value *, std::vector<SUnit *> >::iterator I =
David Goodwin980d4942009-11-09 19:22:17 +0000432 NonAliasMemUses.begin(), E = NonAliasMemUses.end(); I != E; ++I) {
Dan Gohman6a9041e2008-12-04 01:35:46 +0000433 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000434 I->second[i]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000435 }
David Goodwin980d4942009-11-09 19:22:17 +0000436 NonAliasMemDefs.clear();
437 NonAliasMemUses.clear();
438 // Add SU to the barrier chain.
439 if (BarrierChain)
440 BarrierChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
441 BarrierChain = SU;
442
443 // fall-through
444 new_alias_chain:
445 // Chain all possibly aliasing memory references though SU.
446 if (AliasChain)
447 AliasChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
448 AliasChain = SU;
449 for (unsigned k = 0, m = PendingLoads.size(); k != m; ++k)
450 PendingLoads[k]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency));
451 for (std::map<const Value *, SUnit *>::iterator I = AliasMemDefs.begin(),
452 E = AliasMemDefs.end(); I != E; ++I) {
453 I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
454 }
455 for (std::map<const Value *, std::vector<SUnit *> >::iterator I =
456 AliasMemUses.begin(), E = AliasMemUses.end(); I != E; ++I) {
457 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
458 I->second[i]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency));
459 }
460 PendingLoads.clear();
461 AliasMemDefs.clear();
462 AliasMemUses.clear();
Evan Chenge837dea2011-06-28 19:10:37 +0000463 } else if (MCID.mayStore()) {
David Goodwina9e61072009-11-03 20:15:00 +0000464 bool MayAlias = true;
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000465 TrueMemOrderLatency = STORE_LOAD_LATENCY;
David Goodwina9e61072009-11-03 20:15:00 +0000466 if (const Value *V = getUnderlyingObjectForInstr(MI, MFI, MayAlias)) {
Dan Gohman6a9041e2008-12-04 01:35:46 +0000467 // A store to a specific PseudoSourceValue. Add precise dependencies.
David Goodwin980d4942009-11-09 19:22:17 +0000468 // Record the def in MemDefs, first adding a dep if there is
469 // an existing def.
Andrew Trickf405b1a2011-05-05 19:24:06 +0000470 std::map<const Value *, SUnit *>::iterator I =
David Goodwin980d4942009-11-09 19:22:17 +0000471 ((MayAlias) ? AliasMemDefs.find(V) : NonAliasMemDefs.find(V));
Andrew Trickf405b1a2011-05-05 19:24:06 +0000472 std::map<const Value *, SUnit *>::iterator IE =
David Goodwin980d4942009-11-09 19:22:17 +0000473 ((MayAlias) ? AliasMemDefs.end() : NonAliasMemDefs.end());
474 if (I != IE) {
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000475 I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0, /*Reg=*/0,
Dan Gohman54e4c362008-12-09 22:54:47 +0000476 /*isNormalMemory=*/true));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000477 I->second = SU;
478 } else {
David Goodwin980d4942009-11-09 19:22:17 +0000479 if (MayAlias)
480 AliasMemDefs[V] = SU;
481 else
482 NonAliasMemDefs[V] = SU;
Dan Gohman6a9041e2008-12-04 01:35:46 +0000483 }
484 // Handle the uses in MemUses, if there are any.
Dan Gohmana629b482008-12-08 17:50:35 +0000485 std::map<const Value *, std::vector<SUnit *> >::iterator J =
David Goodwin980d4942009-11-09 19:22:17 +0000486 ((MayAlias) ? AliasMemUses.find(V) : NonAliasMemUses.find(V));
487 std::map<const Value *, std::vector<SUnit *> >::iterator JE =
488 ((MayAlias) ? AliasMemUses.end() : NonAliasMemUses.end());
489 if (J != JE) {
Dan Gohman6a9041e2008-12-04 01:35:46 +0000490 for (unsigned i = 0, e = J->second.size(); i != e; ++i)
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000491 J->second[i]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency,
492 /*Reg=*/0, /*isNormalMemory=*/true));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000493 J->second.clear();
494 }
David Goodwina9e61072009-11-03 20:15:00 +0000495 if (MayAlias) {
David Goodwin980d4942009-11-09 19:22:17 +0000496 // Add dependencies from all the PendingLoads, i.e. loads
497 // with no underlying object.
David Goodwina9e61072009-11-03 20:15:00 +0000498 for (unsigned k = 0, m = PendingLoads.size(); k != m; ++k)
499 PendingLoads[k]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency));
David Goodwin980d4942009-11-09 19:22:17 +0000500 // Add dependence on alias chain, if needed.
501 if (AliasChain)
502 AliasChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
David Goodwina9e61072009-11-03 20:15:00 +0000503 }
David Goodwin980d4942009-11-09 19:22:17 +0000504 // Add dependence on barrier chain, if needed.
505 if (BarrierChain)
506 BarrierChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
David Goodwin5be870a2009-11-05 00:16:44 +0000507 } else {
Dan Gohman6a9041e2008-12-04 01:35:46 +0000508 // Treat all other stores conservatively.
David Goodwin980d4942009-11-09 19:22:17 +0000509 goto new_alias_chain;
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000510 }
Evan Chengec6906b2010-10-23 02:10:46 +0000511
512 if (!ExitSU.isPred(SU))
513 // Push store's up a bit to avoid them getting in between cmp
514 // and branches.
515 ExitSU.addPred(SDep(SU, SDep::Order, 0,
516 /*Reg=*/0, /*isNormalMemory=*/false,
517 /*isMustAlias=*/false,
518 /*isArtificial=*/true));
Evan Chenge837dea2011-06-28 19:10:37 +0000519 } else if (MCID.mayLoad()) {
David Goodwina9e61072009-11-03 20:15:00 +0000520 bool MayAlias = true;
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000521 TrueMemOrderLatency = 0;
Dan Gohmana70dca12009-10-09 23:27:56 +0000522 if (MI->isInvariantLoad(AA)) {
Dan Gohman6a9041e2008-12-04 01:35:46 +0000523 // Invariant load, no chain dependencies needed!
David Goodwin5be870a2009-11-05 00:16:44 +0000524 } else {
Andrew Trickf405b1a2011-05-05 19:24:06 +0000525 if (const Value *V =
David Goodwin980d4942009-11-09 19:22:17 +0000526 getUnderlyingObjectForInstr(MI, MFI, MayAlias)) {
527 // A load from a specific PseudoSourceValue. Add precise dependencies.
Andrew Trickf405b1a2011-05-05 19:24:06 +0000528 std::map<const Value *, SUnit *>::iterator I =
David Goodwin980d4942009-11-09 19:22:17 +0000529 ((MayAlias) ? AliasMemDefs.find(V) : NonAliasMemDefs.find(V));
Andrew Trickf405b1a2011-05-05 19:24:06 +0000530 std::map<const Value *, SUnit *>::iterator IE =
David Goodwin980d4942009-11-09 19:22:17 +0000531 ((MayAlias) ? AliasMemDefs.end() : NonAliasMemDefs.end());
532 if (I != IE)
533 I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0, /*Reg=*/0,
534 /*isNormalMemory=*/true));
535 if (MayAlias)
536 AliasMemUses[V].push_back(SU);
Andrew Trickf405b1a2011-05-05 19:24:06 +0000537 else
David Goodwin980d4942009-11-09 19:22:17 +0000538 NonAliasMemUses[V].push_back(SU);
539 } else {
540 // A load with no underlying object. Depend on all
541 // potentially aliasing stores.
Andrew Trickf405b1a2011-05-05 19:24:06 +0000542 for (std::map<const Value *, SUnit *>::iterator I =
David Goodwin980d4942009-11-09 19:22:17 +0000543 AliasMemDefs.begin(), E = AliasMemDefs.end(); I != E; ++I)
544 I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
Andrew Trickf405b1a2011-05-05 19:24:06 +0000545
David Goodwin980d4942009-11-09 19:22:17 +0000546 PendingLoads.push_back(SU);
547 MayAlias = true;
David Goodwina9e61072009-11-03 20:15:00 +0000548 }
Andrew Trickf405b1a2011-05-05 19:24:06 +0000549
David Goodwin980d4942009-11-09 19:22:17 +0000550 // Add dependencies on alias and barrier chains, if needed.
551 if (MayAlias && AliasChain)
552 AliasChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
553 if (BarrierChain)
554 BarrierChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
Andrew Trickf405b1a2011-05-05 19:24:06 +0000555 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000556 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000557 }
Devang Patelcf4cc842011-06-02 20:07:12 +0000558 if (PrevMI)
559 FirstDbgValue = PrevMI;
Dan Gohman79ce2762009-01-15 19:20:50 +0000560
561 for (int i = 0, e = TRI->getNumRegs(); i != e; ++i) {
562 Defs[i].clear();
563 Uses[i].clear();
564 }
565 PendingLoads.clear();
Dan Gohman343f0c02008-11-19 23:18:57 +0000566}
567
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000568void ScheduleDAGInstrs::FinishBlock() {
569 // Nothing to do.
570}
571
Dan Gohmanc8c28272008-11-21 00:12:10 +0000572void ScheduleDAGInstrs::ComputeLatency(SUnit *SU) {
David Goodwind94a4e52009-08-10 15:55:25 +0000573 // Compute the latency for the node.
Evan Cheng3ef1c872010-09-10 01:29:16 +0000574 if (!InstrItins || InstrItins->isEmpty()) {
575 SU->Latency = 1;
Dan Gohman4ea8e852008-12-16 02:38:22 +0000576
Evan Cheng3ef1c872010-09-10 01:29:16 +0000577 // Simplistic target-independent heuristic: assume that loads take
578 // extra time.
Dan Gohman4ea8e852008-12-16 02:38:22 +0000579 if (SU->getInstr()->getDesc().mayLoad())
580 SU->Latency += 2;
Evan Cheng8239daf2010-11-03 00:45:17 +0000581 } else {
582 SU->Latency = TII->getInstrLatency(InstrItins, SU->getInstr());
583 }
Dan Gohmanc8c28272008-11-21 00:12:10 +0000584}
585
Andrew Trickf405b1a2011-05-05 19:24:06 +0000586void ScheduleDAGInstrs::ComputeOperandLatency(SUnit *Def, SUnit *Use,
David Goodwindc4bdcd2009-08-19 16:08:58 +0000587 SDep& dep) const {
Evan Cheng3ef1c872010-09-10 01:29:16 +0000588 if (!InstrItins || InstrItins->isEmpty())
David Goodwindc4bdcd2009-08-19 16:08:58 +0000589 return;
Andrew Trickf405b1a2011-05-05 19:24:06 +0000590
David Goodwindc4bdcd2009-08-19 16:08:58 +0000591 // For a data dependency with a known register...
592 if ((dep.getKind() != SDep::Data) || (dep.getReg() == 0))
593 return;
594
595 const unsigned Reg = dep.getReg();
596
597 // ... find the definition of the register in the defining
598 // instruction
599 MachineInstr *DefMI = Def->getInstr();
600 int DefIdx = DefMI->findRegisterDefOperandIdx(Reg);
601 if (DefIdx != -1) {
Evan Cheng1aca5bc2010-10-08 18:42:25 +0000602 const MachineOperand &MO = DefMI->getOperand(DefIdx);
603 if (MO.isReg() && MO.isImplicit() &&
Evan Chengd82de832010-10-08 23:01:57 +0000604 DefIdx >= (int)DefMI->getDesc().getNumOperands()) {
Evan Cheng1aca5bc2010-10-08 18:42:25 +0000605 // This is an implicit def, getOperandLatency() won't return the correct
606 // latency. e.g.
607 // %D6<def>, %D7<def> = VLD1q16 %R2<kill>, 0, ..., %Q3<imp-def>
608 // %Q1<def> = VMULv8i16 %Q1<kill>, %Q3<kill>, ...
609 // What we want is to compute latency between def of %D6/%D7 and use of
610 // %Q3 instead.
611 DefIdx = DefMI->findRegisterDefOperandIdx(Reg, false, true, TRI);
612 }
Evan Chenga0792de2010-10-06 06:27:31 +0000613 MachineInstr *UseMI = Use->getInstr();
Evan Cheng3881cb72010-09-29 22:42:35 +0000614 // For all uses of the register, calculate the maxmimum latency
615 int Latency = -1;
Evan Chengec6906b2010-10-23 02:10:46 +0000616 if (UseMI) {
617 for (unsigned i = 0, e = UseMI->getNumOperands(); i != e; ++i) {
618 const MachineOperand &MO = UseMI->getOperand(i);
619 if (!MO.isReg() || !MO.isUse())
620 continue;
621 unsigned MOReg = MO.getReg();
622 if (MOReg != Reg)
623 continue;
David Goodwindc4bdcd2009-08-19 16:08:58 +0000624
Evan Chengec6906b2010-10-23 02:10:46 +0000625 int UseCycle = TII->getOperandLatency(InstrItins, DefMI, DefIdx,
626 UseMI, i);
627 Latency = std::max(Latency, UseCycle);
628 }
629 } else {
630 // UseMI is null, then it must be a scheduling barrier.
631 if (!InstrItins || InstrItins->isEmpty())
632 return;
633 unsigned DefClass = DefMI->getDesc().getSchedClass();
634 Latency = InstrItins->getOperandCycle(DefClass, DefIdx);
David Goodwindc4bdcd2009-08-19 16:08:58 +0000635 }
Evan Chengec6906b2010-10-23 02:10:46 +0000636
637 // If we found a latency, then replace the existing dependence latency.
638 if (Latency >= 0)
639 dep.setLatency(Latency);
David Goodwindc4bdcd2009-08-19 16:08:58 +0000640 }
641}
642
Dan Gohman343f0c02008-11-19 23:18:57 +0000643void ScheduleDAGInstrs::dumpNode(const SUnit *SU) const {
644 SU->getInstr()->dump();
645}
646
647std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const {
648 std::string s;
649 raw_string_ostream oss(s);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000650 if (SU == &EntrySU)
651 oss << "<entry>";
652 else if (SU == &ExitSU)
653 oss << "<exit>";
654 else
655 SU->getInstr()->print(oss);
Dan Gohman343f0c02008-11-19 23:18:57 +0000656 return oss.str();
657}
658
659// EmitSchedule - Emit the machine code in scheduled order.
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000660MachineBasicBlock *ScheduleDAGInstrs::EmitSchedule() {
Dan Gohman343f0c02008-11-19 23:18:57 +0000661 // For MachineInstr-based scheduling, we're rescheduling the instructions in
662 // the block, so start by removing them from the block.
Dan Gohman47ac0f02009-02-11 04:27:20 +0000663 while (Begin != InsertPos) {
Dan Gohmanf7119392009-01-16 22:10:20 +0000664 MachineBasicBlock::iterator I = Begin;
665 ++Begin;
666 BB->remove(I);
667 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000668
Devang Patelcf4cc842011-06-02 20:07:12 +0000669 // If first instruction was a DBG_VALUE then put it back.
670 if (FirstDbgValue)
671 BB->insert(InsertPos, FirstDbgValue);
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000672
Dan Gohman0b1d4a72008-12-23 21:37:04 +0000673 // Then re-insert them according to the given schedule.
Dan Gohman343f0c02008-11-19 23:18:57 +0000674 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
Devang Patelee1f8782011-06-02 21:31:00 +0000675 if (SUnit *SU = Sequence[i])
676 BB->insert(InsertPos, SU->getInstr());
677 else
Dan Gohman343f0c02008-11-19 23:18:57 +0000678 // Null SUnit* is a noop.
679 EmitNoop();
Dan Gohman343f0c02008-11-19 23:18:57 +0000680
Hal Finkeldb809e02011-12-02 04:58:07 +0000681 // Update the Begin iterator, as the first instruction in the block
682 // may have been scheduled later.
683 if (i == 0)
684 Begin = prior(InsertPos);
685 }
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000686
Devang Patelcf4cc842011-06-02 20:07:12 +0000687 // Reinsert any remaining debug_values.
688 for (std::vector<std::pair<MachineInstr *, MachineInstr *> >::iterator
689 DI = DbgValues.end(), DE = DbgValues.begin(); DI != DE; --DI) {
690 std::pair<MachineInstr *, MachineInstr *> P = *prior(DI);
691 MachineInstr *DbgValue = P.first;
Evan Cheng7c2a4a32011-12-06 22:12:01 +0000692 MachineBasicBlock::iterator OrigPrivMI = P.second;
Devang Patelcf4cc842011-06-02 20:07:12 +0000693 BB->insertAfter(OrigPrivMI, DbgValue);
694 }
695 DbgValues.clear();
696 FirstDbgValue = NULL;
Dan Gohman343f0c02008-11-19 23:18:57 +0000697 return BB;
698}