blob: c9255b04dadc3c4ce47b7d8d5fe2b09079d49bd6 [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,
Andrew Trick5e920d72012-01-14 02:17:12 +000036 const MachineDominatorTree &mdt,
37 bool IsPostRAFlag)
Evan Cheng3ef1c872010-09-10 01:29:16 +000038 : ScheduleDAG(mf), MLI(mli), MDT(mdt), MFI(mf.getFrameInfo()),
Andrew Trick5e920d72012-01-14 02:17:12 +000039 InstrItins(mf.getTarget().getInstrItineraryData()), IsPostRA(IsPostRAFlag),
Andrew Trick4563bba2011-10-07 06:27:02 +000040 Defs(TRI->getNumRegs()), Uses(TRI->getNumRegs()),
Devang Patele29e8e12011-06-02 21:26:52 +000041 LoopRegs(MLI, MDT), FirstDbgValue(0) {
Devang Patelcf4cc842011-06-02 20:07:12 +000042 DbgValues.clear();
Evan Cheng38bdfc62009-10-18 19:58:47 +000043}
Dan Gohman343f0c02008-11-19 23:18:57 +000044
Dan Gohman47ac0f02009-02-11 04:27:20 +000045/// Run - perform scheduling.
46///
47void ScheduleDAGInstrs::Run(MachineBasicBlock *bb,
48 MachineBasicBlock::iterator begin,
49 MachineBasicBlock::iterator end,
50 unsigned endcount) {
51 BB = bb;
52 Begin = begin;
53 InsertPosIndex = endcount;
54
55 ScheduleDAG::Run(bb, end);
56}
57
Dan Gohman3311a1f2009-01-30 02:49:14 +000058/// getUnderlyingObjectFromInt - This is the function that does the work of
59/// looking through basic ptrtoint+arithmetic+inttoptr sequences.
60static const Value *getUnderlyingObjectFromInt(const Value *V) {
61 do {
Dan Gohman8906f952009-07-17 20:58:59 +000062 if (const Operator *U = dyn_cast<Operator>(V)) {
Dan Gohman3311a1f2009-01-30 02:49:14 +000063 // If we find a ptrtoint, we can transfer control back to the
64 // regular getUnderlyingObjectFromInt.
Dan Gohman8906f952009-07-17 20:58:59 +000065 if (U->getOpcode() == Instruction::PtrToInt)
Dan Gohman3311a1f2009-01-30 02:49:14 +000066 return U->getOperand(0);
67 // If we find an add of a constant or a multiplied value, it's
68 // likely that the other operand will lead us to the base
69 // object. We don't have to worry about the case where the
Dan Gohman748f98f2009-08-07 01:26:06 +000070 // object address is somehow being computed by the multiply,
Dan Gohman3311a1f2009-01-30 02:49:14 +000071 // because our callers only care when the result is an
72 // identifibale object.
Dan Gohman8906f952009-07-17 20:58:59 +000073 if (U->getOpcode() != Instruction::Add ||
Dan Gohman3311a1f2009-01-30 02:49:14 +000074 (!isa<ConstantInt>(U->getOperand(1)) &&
Dan Gohman8906f952009-07-17 20:58:59 +000075 Operator::getOpcode(U->getOperand(1)) != Instruction::Mul))
Dan Gohman3311a1f2009-01-30 02:49:14 +000076 return V;
77 V = U->getOperand(0);
78 } else {
79 return V;
80 }
Duncan Sands1df98592010-02-16 11:11:14 +000081 assert(V->getType()->isIntegerTy() && "Unexpected operand type!");
Dan Gohman3311a1f2009-01-30 02:49:14 +000082 } while (1);
83}
84
Dan Gohman5034dd32010-12-15 20:02:24 +000085/// getUnderlyingObject - This is a wrapper around GetUnderlyingObject
Dan Gohman3311a1f2009-01-30 02:49:14 +000086/// and adds support for basic ptrtoint+arithmetic+inttoptr sequences.
87static const Value *getUnderlyingObject(const Value *V) {
88 // First just call Value::getUnderlyingObject to let it do what it does.
89 do {
Dan Gohman5034dd32010-12-15 20:02:24 +000090 V = GetUnderlyingObject(V);
Dan Gohman3311a1f2009-01-30 02:49:14 +000091 // If it found an inttoptr, use special code to continue climing.
Dan Gohman8906f952009-07-17 20:58:59 +000092 if (Operator::getOpcode(V) != Instruction::IntToPtr)
Dan Gohman3311a1f2009-01-30 02:49:14 +000093 break;
94 const Value *O = getUnderlyingObjectFromInt(cast<User>(V)->getOperand(0));
95 // If that succeeded in finding a pointer, continue the search.
Duncan Sands1df98592010-02-16 11:11:14 +000096 if (!O->getType()->isPointerTy())
Dan Gohman3311a1f2009-01-30 02:49:14 +000097 break;
98 V = O;
99 } while (1);
100 return V;
101}
102
103/// getUnderlyingObjectForInstr - If this machine instr has memory reference
104/// information and it can be tracked to a normal reference to a known
105/// object, return the Value for that object. Otherwise return null.
Evan Cheng38bdfc62009-10-18 19:58:47 +0000106static const Value *getUnderlyingObjectForInstr(const MachineInstr *MI,
David Goodwina9e61072009-11-03 20:15:00 +0000107 const MachineFrameInfo *MFI,
108 bool &MayAlias) {
109 MayAlias = true;
Dan Gohman3311a1f2009-01-30 02:49:14 +0000110 if (!MI->hasOneMemOperand() ||
Dan Gohmanc76909a2009-09-25 20:36:54 +0000111 !(*MI->memoperands_begin())->getValue() ||
112 (*MI->memoperands_begin())->isVolatile())
Dan Gohman3311a1f2009-01-30 02:49:14 +0000113 return 0;
114
Dan Gohmanc76909a2009-09-25 20:36:54 +0000115 const Value *V = (*MI->memoperands_begin())->getValue();
Dan Gohman3311a1f2009-01-30 02:49:14 +0000116 if (!V)
117 return 0;
118
119 V = getUnderlyingObject(V);
Evan Chengff89dcb2009-10-18 18:16:27 +0000120 if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) {
121 // For now, ignore PseudoSourceValues which may alias LLVM IR values
122 // because the code that uses this function has no way to cope with
123 // such aliases.
Evan Cheng38bdfc62009-10-18 19:58:47 +0000124 if (PSV->isAliased(MFI))
Evan Chengff89dcb2009-10-18 18:16:27 +0000125 return 0;
Andrew Trickf405b1a2011-05-05 19:24:06 +0000126
David Goodwin980d4942009-11-09 19:22:17 +0000127 MayAlias = PSV->mayAlias(MFI);
Evan Chengff89dcb2009-10-18 18:16:27 +0000128 return V;
129 }
Dan Gohman3311a1f2009-01-30 02:49:14 +0000130
Evan Chengff89dcb2009-10-18 18:16:27 +0000131 if (isIdentifiedObject(V))
132 return V;
133
134 return 0;
Dan Gohman3311a1f2009-01-30 02:49:14 +0000135}
136
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000137void ScheduleDAGInstrs::StartBlock(MachineBasicBlock *BB) {
Andrew Tricke8deca82011-10-07 06:33:09 +0000138 LoopRegs.Deps.clear();
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000139 if (MachineLoop *ML = MLI.getLoopFor(BB))
Evan Cheng977679d2012-01-07 03:02:36 +0000140 if (BB == ML->getLoopLatch())
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000141 LoopRegs.VisitLoop(ML);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000142}
143
Evan Chengec6906b2010-10-23 02:10:46 +0000144/// AddSchedBarrierDeps - Add dependencies from instructions in the current
145/// list of instructions being scheduled to scheduling barrier by adding
146/// the exit SU to the register defs and use list. This is because we want to
147/// make sure instructions which define registers that are either used by
148/// the terminator or are live-out are properly scheduled. This is
149/// especially important when the definition latency of the return value(s)
150/// are too high to be hidden by the branch or when the liveout registers
151/// used by instructions in the fallthrough block.
152void ScheduleDAGInstrs::AddSchedBarrierDeps() {
153 MachineInstr *ExitMI = InsertPos != BB->end() ? &*InsertPos : 0;
154 ExitSU.setInstr(ExitMI);
155 bool AllDepKnown = ExitMI &&
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000156 (ExitMI->isCall() || ExitMI->isBarrier());
Evan Chengec6906b2010-10-23 02:10:46 +0000157 if (ExitMI && AllDepKnown) {
158 // If it's a call or a barrier, add dependencies on the defs and uses of
159 // instruction.
160 for (unsigned i = 0, e = ExitMI->getNumOperands(); i != e; ++i) {
161 const MachineOperand &MO = ExitMI->getOperand(i);
162 if (!MO.isReg() || MO.isDef()) continue;
163 unsigned Reg = MO.getReg();
164 if (Reg == 0) continue;
165
166 assert(TRI->isPhysicalRegister(Reg) && "Virtual register encountered!");
167 Uses[Reg].push_back(&ExitSU);
168 }
169 } else {
170 // For others, e.g. fallthrough, conditional branch, assume the exit
Evan Chengde5fa932010-10-27 23:17:17 +0000171 // uses all the registers that are livein to the successor blocks.
172 SmallSet<unsigned, 8> Seen;
173 for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
174 SE = BB->succ_end(); SI != SE; ++SI)
175 for (MachineBasicBlock::livein_iterator I = (*SI)->livein_begin(),
Andrew Trickf405b1a2011-05-05 19:24:06 +0000176 E = (*SI)->livein_end(); I != E; ++I) {
Evan Chengde5fa932010-10-27 23:17:17 +0000177 unsigned Reg = *I;
178 if (Seen.insert(Reg))
179 Uses[Reg].push_back(&ExitSU);
180 }
Evan Chengec6906b2010-10-23 02:10:46 +0000181 }
182}
183
Dan Gohmana70dca12009-10-09 23:27:56 +0000184void ScheduleDAGInstrs::BuildSchedGraph(AliasAnalysis *AA) {
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000185 // We'll be allocating one SUnit for each instruction, plus one for
186 // the region exit node.
Dan Gohman343f0c02008-11-19 23:18:57 +0000187 SUnits.reserve(BB->size());
188
Dan Gohman6a9041e2008-12-04 01:35:46 +0000189 // We build scheduling units by walking a block's instruction list from bottom
190 // to top.
191
David Goodwin980d4942009-11-09 19:22:17 +0000192 // Remember where a generic side-effecting instruction is as we procede.
193 SUnit *BarrierChain = 0, *AliasChain = 0;
Dan Gohman6a9041e2008-12-04 01:35:46 +0000194
David Goodwin980d4942009-11-09 19:22:17 +0000195 // Memory references to specific known memory locations are tracked
196 // so that they can be given more precise dependencies. We track
197 // separately the known memory locations that may alias and those
198 // that are known not to alias
199 std::map<const Value *, SUnit *> AliasMemDefs, NonAliasMemDefs;
200 std::map<const Value *, std::vector<SUnit *> > AliasMemUses, NonAliasMemUses;
Dan Gohman6a9041e2008-12-04 01:35:46 +0000201
Dan Gohman3f237442008-12-16 03:25:46 +0000202 // Check to see if the scheduler cares about latencies.
203 bool UnitLatencies = ForceUnitLatencies();
204
Dan Gohman8749b612008-12-16 03:35:01 +0000205 // Ask the target if address-backscheduling is desirable, and if so how much.
Evan Cheng5b1b44892011-07-01 21:01:15 +0000206 const TargetSubtargetInfo &ST = TM.getSubtarget<TargetSubtargetInfo>();
David Goodwin71046162009-08-13 16:05:04 +0000207 unsigned SpecialAddressLatency = ST.getSpecialAddressLatency();
Dan Gohman8749b612008-12-16 03:35:01 +0000208
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000209 // Remove any stale debug info; sometimes BuildSchedGraph is called again
210 // without emitting the info from the previous call.
Devang Patelcf4cc842011-06-02 20:07:12 +0000211 DbgValues.clear();
212 FirstDbgValue = NULL;
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000213
Evan Chengec6906b2010-10-23 02:10:46 +0000214 // Model data dependencies between instructions being scheduled and the
215 // ExitSU.
216 AddSchedBarrierDeps();
217
Andrew Trick9b668532011-05-06 21:52:52 +0000218 for (int i = 0, e = TRI->getNumRegs(); i != e; ++i) {
219 assert(Defs[i].empty() && "Only BuildGraph should push/pop Defs");
220 }
221
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000222 // Walk the list of instructions, from bottom moving up.
Devang Patelcf4cc842011-06-02 20:07:12 +0000223 MachineInstr *PrevMI = NULL;
Dan Gohman47ac0f02009-02-11 04:27:20 +0000224 for (MachineBasicBlock::iterator MII = InsertPos, MIE = Begin;
Dan Gohman343f0c02008-11-19 23:18:57 +0000225 MII != MIE; --MII) {
226 MachineInstr *MI = prior(MII);
Devang Patelcf4cc842011-06-02 20:07:12 +0000227 if (MI && PrevMI) {
228 DbgValues.push_back(std::make_pair(PrevMI, MI));
229 PrevMI = NULL;
230 }
231
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000232 if (MI->isDebugValue()) {
Devang Patelcf4cc842011-06-02 20:07:12 +0000233 PrevMI = MI;
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000234 continue;
235 }
Devang Patelcf4cc842011-06-02 20:07:12 +0000236
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000237 assert(!MI->isTerminator() && !MI->isLabel() &&
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000238 "Cannot schedule terminators or labels!");
239 // Create the SUnit for this MI.
Dan Gohman343f0c02008-11-19 23:18:57 +0000240 SUnit *SU = NewSUnit(MI);
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000241 SU->isCall = MI->isCall();
242 SU->isCommutable = MI->isCommutable();
Dan Gohman343f0c02008-11-19 23:18:57 +0000243
Dan Gohman54e4c362008-12-09 22:54:47 +0000244 // Assign the Latency field of SU using target-provided information.
Dan Gohman3f237442008-12-16 03:25:46 +0000245 if (UnitLatencies)
246 SU->Latency = 1;
247 else
248 ComputeLatency(SU);
Dan Gohman54e4c362008-12-09 22:54:47 +0000249
Dan Gohman6a9041e2008-12-04 01:35:46 +0000250 // Add register-based dependencies (data, anti, and output).
Dan Gohman343f0c02008-11-19 23:18:57 +0000251 for (unsigned j = 0, n = MI->getNumOperands(); j != n; ++j) {
252 const MachineOperand &MO = MI->getOperand(j);
253 if (!MO.isReg()) continue;
254 unsigned Reg = MO.getReg();
255 if (Reg == 0) continue;
256
Andrew Trick5e920d72012-01-14 02:17:12 +0000257 assert(!IsPostRA || TRI->isPhysicalRegister(Reg) &&
258 "Virtual register encountered!");
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000259
David Goodwind94a4e52009-08-10 15:55:25 +0000260 // Optionally add output and anti dependencies. For anti
261 // dependencies we use a latency of 0 because for a multi-issue
262 // target we want to allow the defining instruction to issue
263 // in the same cycle as the using instruction.
264 // TODO: Using a latency of 1 here for output dependencies assumes
265 // there's no cost for reusing registers.
Dan Gohman54e4c362008-12-09 22:54:47 +0000266 SDep::Kind Kind = MO.isUse() ? SDep::Anti : SDep::Output;
Andrew Trick877ae2e2012-01-05 02:52:11 +0000267 for (const unsigned *Alias = TRI->getOverlaps(Reg); *Alias; ++Alias) {
268 std::vector<SUnit *> &DefList = Defs[*Alias];
269 for (unsigned i = 0, e = DefList.size(); i != e; ++i) {
270 SUnit *DefSU = DefList[i];
Evan Chengec6906b2010-10-23 02:10:46 +0000271 if (DefSU == &ExitSU)
272 continue;
Dan Gohman3f237442008-12-16 03:25:46 +0000273 if (DefSU != SU &&
274 (Kind != SDep::Output || !MO.isDead() ||
Andrew Trick877ae2e2012-01-05 02:52:11 +0000275 !DefSU->getInstr()->registerDefIsDead(*Alias))) {
276 if (Kind == SDep::Anti)
277 DefSU->addPred(SDep(SU, Kind, 0, /*Reg=*/*Alias));
278 else {
279 unsigned AOLat = TII->getOutputLatency(InstrItins, MI, j,
280 DefSU->getInstr());
281 DefSU->addPred(SDep(SU, Kind, AOLat, /*Reg=*/*Alias));
282 }
283 }
Dan Gohman3f237442008-12-16 03:25:46 +0000284 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000285 }
286
Andrew Trick877ae2e2012-01-05 02:52:11 +0000287 // Retrieve the UseList to add data dependencies and update uses.
288 std::vector<SUnit *> &UseList = Uses[Reg];
Dan Gohman343f0c02008-11-19 23:18:57 +0000289 if (MO.isDef()) {
Andrew Trick877ae2e2012-01-05 02:52:11 +0000290 // Update DefList. Defs are pushed in the order they are visited and
291 // never reordered.
292 std::vector<SUnit *> &DefList = Defs[Reg];
293
Dan Gohman343f0c02008-11-19 23:18:57 +0000294 // Add any data dependencies.
Dan Gohman3f237442008-12-16 03:25:46 +0000295 unsigned DataLatency = SU->Latency;
296 for (unsigned i = 0, e = UseList.size(); i != e; ++i) {
297 SUnit *UseSU = UseList[i];
Evan Chenga69ec092010-03-22 21:24:33 +0000298 if (UseSU == SU)
299 continue;
300 unsigned LDataLatency = DataLatency;
301 // Optionally add in a special extra latency for nodes that
302 // feed addresses.
303 // TODO: Do this for register aliases too.
304 // TODO: Perhaps we should get rid of
305 // SpecialAddressLatency and just move this into
306 // adjustSchedDependency for the targets that care about it.
Evan Chengec6906b2010-10-23 02:10:46 +0000307 if (SpecialAddressLatency != 0 && !UnitLatencies &&
308 UseSU != &ExitSU) {
Evan Chenga69ec092010-03-22 21:24:33 +0000309 MachineInstr *UseMI = UseSU->getInstr();
Evan Chenge837dea2011-06-28 19:10:37 +0000310 const MCInstrDesc &UseMCID = UseMI->getDesc();
Evan Chenga69ec092010-03-22 21:24:33 +0000311 int RegUseIndex = UseMI->findRegisterUseOperandIdx(Reg);
312 assert(RegUseIndex >= 0 && "UseMI doesn's use register!");
Evan Chengec6906b2010-10-23 02:10:46 +0000313 if (RegUseIndex >= 0 &&
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000314 (UseMI->mayLoad() || UseMI->mayStore()) &&
Evan Chenge837dea2011-06-28 19:10:37 +0000315 (unsigned)RegUseIndex < UseMCID.getNumOperands() &&
316 UseMCID.OpInfo[RegUseIndex].isLookupPtrRegClass())
Evan Chenga69ec092010-03-22 21:24:33 +0000317 LDataLatency += SpecialAddressLatency;
Dan Gohman3f237442008-12-16 03:25:46 +0000318 }
Evan Chenga69ec092010-03-22 21:24:33 +0000319 // Adjust the dependence latency using operand def/use
320 // information (if any), and then allow the target to
321 // perform its own adjustments.
322 const SDep& dep = SDep(SU, SDep::Data, LDataLatency, Reg);
323 if (!UnitLatencies) {
Dan Gohman3fb150a2010-04-17 17:42:52 +0000324 ComputeOperandLatency(SU, UseSU, const_cast<SDep &>(dep));
325 ST.adjustSchedDependency(SU, UseSU, const_cast<SDep &>(dep));
Evan Chenga69ec092010-03-22 21:24:33 +0000326 }
327 UseSU->addPred(dep);
Dan Gohman3f237442008-12-16 03:25:46 +0000328 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000329 for (const unsigned *Alias = TRI->getAliasSet(Reg); *Alias; ++Alias) {
330 std::vector<SUnit *> &UseList = Uses[*Alias];
Dan Gohman3f237442008-12-16 03:25:46 +0000331 for (unsigned i = 0, e = UseList.size(); i != e; ++i) {
332 SUnit *UseSU = UseList[i];
Evan Chenga69ec092010-03-22 21:24:33 +0000333 if (UseSU == SU)
334 continue;
335 const SDep& dep = SDep(SU, SDep::Data, DataLatency, *Alias);
336 if (!UnitLatencies) {
Dan Gohman3fb150a2010-04-17 17:42:52 +0000337 ComputeOperandLatency(SU, UseSU, const_cast<SDep &>(dep));
338 ST.adjustSchedDependency(SU, UseSU, const_cast<SDep &>(dep));
David Goodwin71046162009-08-13 16:05:04 +0000339 }
Evan Chenga69ec092010-03-22 21:24:33 +0000340 UseSU->addPred(dep);
Dan Gohman3f237442008-12-16 03:25:46 +0000341 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000342 }
343
Dan Gohman8749b612008-12-16 03:35:01 +0000344 // If a def is going to wrap back around to the top of the loop,
345 // backschedule it.
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000346 if (!UnitLatencies && DefList.empty()) {
Dan Gohman8749b612008-12-16 03:35:01 +0000347 LoopDependencies::LoopDeps::iterator I = LoopRegs.Deps.find(Reg);
348 if (I != LoopRegs.Deps.end()) {
349 const MachineOperand *UseMO = I->second.first;
350 unsigned Count = I->second.second;
351 const MachineInstr *UseMI = UseMO->getParent();
352 unsigned UseMOIdx = UseMO - &UseMI->getOperand(0);
Evan Chenge837dea2011-06-28 19:10:37 +0000353 const MCInstrDesc &UseMCID = UseMI->getDesc();
Dan Gohman8749b612008-12-16 03:35:01 +0000354 // TODO: If we knew the total depth of the region here, we could
355 // handle the case where the whole loop is inside the region but
356 // is large enough that the isScheduleHigh trick isn't needed.
Evan Chenge837dea2011-06-28 19:10:37 +0000357 if (UseMOIdx < UseMCID.getNumOperands()) {
Dan Gohman8749b612008-12-16 03:35:01 +0000358 // Currently, we only support scheduling regions consisting of
359 // single basic blocks. Check to see if the instruction is in
360 // the same region by checking to see if it has the same parent.
361 if (UseMI->getParent() != MI->getParent()) {
362 unsigned Latency = SU->Latency;
Evan Chenge837dea2011-06-28 19:10:37 +0000363 if (UseMCID.OpInfo[UseMOIdx].isLookupPtrRegClass())
Dan Gohman8749b612008-12-16 03:35:01 +0000364 Latency += SpecialAddressLatency;
365 // This is a wild guess as to the portion of the latency which
366 // will be overlapped by work done outside the current
367 // scheduling region.
368 Latency -= std::min(Latency, Count);
Chris Lattner7a2bdde2011-04-15 05:18:47 +0000369 // Add the artificial edge.
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000370 ExitSU.addPred(SDep(SU, SDep::Order, Latency,
371 /*Reg=*/0, /*isNormalMemory=*/false,
372 /*isMustAlias=*/false,
373 /*isArtificial=*/true));
Dan Gohman8749b612008-12-16 03:35:01 +0000374 } else if (SpecialAddressLatency > 0 &&
Evan Chenge837dea2011-06-28 19:10:37 +0000375 UseMCID.OpInfo[UseMOIdx].isLookupPtrRegClass()) {
Dan Gohman8749b612008-12-16 03:35:01 +0000376 // The entire loop body is within the current scheduling region
377 // and the latency of this operation is assumed to be greater
378 // than the latency of the loop.
379 // TODO: Recursively mark data-edge predecessors as
380 // isScheduleHigh too.
381 SU->isScheduleHigh = true;
382 }
383 }
384 LoopRegs.Deps.erase(I);
385 }
386 }
387
Dan Gohman343f0c02008-11-19 23:18:57 +0000388 UseList.clear();
Dan Gohman3f237442008-12-16 03:25:46 +0000389 if (!MO.isDead())
390 DefList.clear();
Andrew Trickee109152011-05-05 19:32:21 +0000391
392 // Calls will not be reordered because of chain dependencies (see
393 // below). Since call operands are dead, calls may continue to be added
394 // to the DefList making dependence checking quadratic in the size of
395 // the block. Instead, we leave only one call at the back of the
396 // DefList.
Andrew Trickee109152011-05-05 19:32:21 +0000397 if (SU->isCall) {
398 while (!DefList.empty() && DefList.back()->isCall)
399 DefList.pop_back();
400 }
Dan Gohman3f237442008-12-16 03:25:46 +0000401 DefList.push_back(SU);
Dan Gohman343f0c02008-11-19 23:18:57 +0000402 } else {
403 UseList.push_back(SU);
404 }
405 }
Dan Gohman6a9041e2008-12-04 01:35:46 +0000406
407 // Add chain dependencies.
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000408 // Chain dependencies used to enforce memory order should have
409 // latency of 0 (except for true dependency of Store followed by
410 // aliased Load... we estimate that with a single cycle of latency
411 // assuming the hardware will bypass)
Dan Gohman6a9041e2008-12-04 01:35:46 +0000412 // Note that isStoreToStackSlot and isLoadFromStackSLot are not usable
413 // after stack slots are lowered to actual addresses.
414 // TODO: Use an AliasAnalysis and do real alias-analysis queries, and
415 // produce more precise dependence information.
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000416#define STORE_LOAD_LATENCY 1
417 unsigned TrueMemOrderLatency = 0;
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000418 if (MI->isCall() || MI->hasUnmodeledSideEffects() ||
Andrew Trickf405b1a2011-05-05 19:24:06 +0000419 (MI->hasVolatileMemoryRef() &&
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000420 (!MI->mayLoad() || !MI->isInvariantLoad(AA)))) {
David Goodwin980d4942009-11-09 19:22:17 +0000421 // Be conservative with these and add dependencies on all memory
422 // references, even those that are known to not alias.
Andrew Trickf405b1a2011-05-05 19:24:06 +0000423 for (std::map<const Value *, SUnit *>::iterator I =
David Goodwin980d4942009-11-09 19:22:17 +0000424 NonAliasMemDefs.begin(), E = NonAliasMemDefs.end(); I != E; ++I) {
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000425 I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000426 }
427 for (std::map<const Value *, std::vector<SUnit *> >::iterator I =
David Goodwin980d4942009-11-09 19:22:17 +0000428 NonAliasMemUses.begin(), E = NonAliasMemUses.end(); I != E; ++I) {
Dan Gohman6a9041e2008-12-04 01:35:46 +0000429 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000430 I->second[i]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000431 }
David Goodwin980d4942009-11-09 19:22:17 +0000432 NonAliasMemDefs.clear();
433 NonAliasMemUses.clear();
434 // Add SU to the barrier chain.
435 if (BarrierChain)
436 BarrierChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
437 BarrierChain = SU;
438
439 // fall-through
440 new_alias_chain:
441 // Chain all possibly aliasing memory references though SU.
442 if (AliasChain)
443 AliasChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
444 AliasChain = SU;
445 for (unsigned k = 0, m = PendingLoads.size(); k != m; ++k)
446 PendingLoads[k]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency));
447 for (std::map<const Value *, SUnit *>::iterator I = AliasMemDefs.begin(),
448 E = AliasMemDefs.end(); I != E; ++I) {
449 I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
450 }
451 for (std::map<const Value *, std::vector<SUnit *> >::iterator I =
452 AliasMemUses.begin(), E = AliasMemUses.end(); I != E; ++I) {
453 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
454 I->second[i]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency));
455 }
456 PendingLoads.clear();
457 AliasMemDefs.clear();
458 AliasMemUses.clear();
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000459 } else if (MI->mayStore()) {
David Goodwina9e61072009-11-03 20:15:00 +0000460 bool MayAlias = true;
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000461 TrueMemOrderLatency = STORE_LOAD_LATENCY;
David Goodwina9e61072009-11-03 20:15:00 +0000462 if (const Value *V = getUnderlyingObjectForInstr(MI, MFI, MayAlias)) {
Dan Gohman6a9041e2008-12-04 01:35:46 +0000463 // A store to a specific PseudoSourceValue. Add precise dependencies.
David Goodwin980d4942009-11-09 19:22:17 +0000464 // Record the def in MemDefs, first adding a dep if there is
465 // an existing def.
Andrew Trickf405b1a2011-05-05 19:24:06 +0000466 std::map<const Value *, SUnit *>::iterator I =
David Goodwin980d4942009-11-09 19:22:17 +0000467 ((MayAlias) ? AliasMemDefs.find(V) : NonAliasMemDefs.find(V));
Andrew Trickf405b1a2011-05-05 19:24:06 +0000468 std::map<const Value *, SUnit *>::iterator IE =
David Goodwin980d4942009-11-09 19:22:17 +0000469 ((MayAlias) ? AliasMemDefs.end() : NonAliasMemDefs.end());
470 if (I != IE) {
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000471 I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0, /*Reg=*/0,
Dan Gohman54e4c362008-12-09 22:54:47 +0000472 /*isNormalMemory=*/true));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000473 I->second = SU;
474 } else {
David Goodwin980d4942009-11-09 19:22:17 +0000475 if (MayAlias)
476 AliasMemDefs[V] = SU;
477 else
478 NonAliasMemDefs[V] = SU;
Dan Gohman6a9041e2008-12-04 01:35:46 +0000479 }
480 // Handle the uses in MemUses, if there are any.
Dan Gohmana629b482008-12-08 17:50:35 +0000481 std::map<const Value *, std::vector<SUnit *> >::iterator J =
David Goodwin980d4942009-11-09 19:22:17 +0000482 ((MayAlias) ? AliasMemUses.find(V) : NonAliasMemUses.find(V));
483 std::map<const Value *, std::vector<SUnit *> >::iterator JE =
484 ((MayAlias) ? AliasMemUses.end() : NonAliasMemUses.end());
485 if (J != JE) {
Dan Gohman6a9041e2008-12-04 01:35:46 +0000486 for (unsigned i = 0, e = J->second.size(); i != e; ++i)
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000487 J->second[i]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency,
488 /*Reg=*/0, /*isNormalMemory=*/true));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000489 J->second.clear();
490 }
David Goodwina9e61072009-11-03 20:15:00 +0000491 if (MayAlias) {
David Goodwin980d4942009-11-09 19:22:17 +0000492 // Add dependencies from all the PendingLoads, i.e. loads
493 // with no underlying object.
David Goodwina9e61072009-11-03 20:15:00 +0000494 for (unsigned k = 0, m = PendingLoads.size(); k != m; ++k)
495 PendingLoads[k]->addPred(SDep(SU, SDep::Order, TrueMemOrderLatency));
David Goodwin980d4942009-11-09 19:22:17 +0000496 // Add dependence on alias chain, if needed.
497 if (AliasChain)
498 AliasChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
David Goodwina9e61072009-11-03 20:15:00 +0000499 }
David Goodwin980d4942009-11-09 19:22:17 +0000500 // Add dependence on barrier chain, if needed.
501 if (BarrierChain)
502 BarrierChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
David Goodwin5be870a2009-11-05 00:16:44 +0000503 } else {
Dan Gohman6a9041e2008-12-04 01:35:46 +0000504 // Treat all other stores conservatively.
David Goodwin980d4942009-11-09 19:22:17 +0000505 goto new_alias_chain;
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000506 }
Evan Chengec6906b2010-10-23 02:10:46 +0000507
508 if (!ExitSU.isPred(SU))
509 // Push store's up a bit to avoid them getting in between cmp
510 // and branches.
511 ExitSU.addPred(SDep(SU, SDep::Order, 0,
512 /*Reg=*/0, /*isNormalMemory=*/false,
513 /*isMustAlias=*/false,
514 /*isArtificial=*/true));
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000515 } else if (MI->mayLoad()) {
David Goodwina9e61072009-11-03 20:15:00 +0000516 bool MayAlias = true;
David Goodwin7c9b1ac2009-11-02 17:06:28 +0000517 TrueMemOrderLatency = 0;
Dan Gohmana70dca12009-10-09 23:27:56 +0000518 if (MI->isInvariantLoad(AA)) {
Dan Gohman6a9041e2008-12-04 01:35:46 +0000519 // Invariant load, no chain dependencies needed!
David Goodwin5be870a2009-11-05 00:16:44 +0000520 } else {
Andrew Trickf405b1a2011-05-05 19:24:06 +0000521 if (const Value *V =
David Goodwin980d4942009-11-09 19:22:17 +0000522 getUnderlyingObjectForInstr(MI, MFI, MayAlias)) {
523 // A load from a specific PseudoSourceValue. Add precise dependencies.
Andrew Trickf405b1a2011-05-05 19:24:06 +0000524 std::map<const Value *, SUnit *>::iterator I =
David Goodwin980d4942009-11-09 19:22:17 +0000525 ((MayAlias) ? AliasMemDefs.find(V) : NonAliasMemDefs.find(V));
Andrew Trickf405b1a2011-05-05 19:24:06 +0000526 std::map<const Value *, SUnit *>::iterator IE =
David Goodwin980d4942009-11-09 19:22:17 +0000527 ((MayAlias) ? AliasMemDefs.end() : NonAliasMemDefs.end());
528 if (I != IE)
529 I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0, /*Reg=*/0,
530 /*isNormalMemory=*/true));
531 if (MayAlias)
532 AliasMemUses[V].push_back(SU);
Andrew Trickf405b1a2011-05-05 19:24:06 +0000533 else
David Goodwin980d4942009-11-09 19:22:17 +0000534 NonAliasMemUses[V].push_back(SU);
535 } else {
536 // A load with no underlying object. Depend on all
537 // potentially aliasing stores.
Andrew Trickf405b1a2011-05-05 19:24:06 +0000538 for (std::map<const Value *, SUnit *>::iterator I =
David Goodwin980d4942009-11-09 19:22:17 +0000539 AliasMemDefs.begin(), E = AliasMemDefs.end(); I != E; ++I)
540 I->second->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
Andrew Trickf405b1a2011-05-05 19:24:06 +0000541
David Goodwin980d4942009-11-09 19:22:17 +0000542 PendingLoads.push_back(SU);
543 MayAlias = true;
David Goodwina9e61072009-11-03 20:15:00 +0000544 }
Andrew Trickf405b1a2011-05-05 19:24:06 +0000545
David Goodwin980d4942009-11-09 19:22:17 +0000546 // Add dependencies on alias and barrier chains, if needed.
547 if (MayAlias && AliasChain)
548 AliasChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
549 if (BarrierChain)
550 BarrierChain->addPred(SDep(SU, SDep::Order, /*Latency=*/0));
Andrew Trickf405b1a2011-05-05 19:24:06 +0000551 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000552 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000553 }
Devang Patelcf4cc842011-06-02 20:07:12 +0000554 if (PrevMI)
555 FirstDbgValue = PrevMI;
Dan Gohman79ce2762009-01-15 19:20:50 +0000556
557 for (int i = 0, e = TRI->getNumRegs(); i != e; ++i) {
558 Defs[i].clear();
559 Uses[i].clear();
560 }
561 PendingLoads.clear();
Dan Gohman343f0c02008-11-19 23:18:57 +0000562}
563
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000564void ScheduleDAGInstrs::FinishBlock() {
565 // Nothing to do.
566}
567
Dan Gohmanc8c28272008-11-21 00:12:10 +0000568void ScheduleDAGInstrs::ComputeLatency(SUnit *SU) {
David Goodwind94a4e52009-08-10 15:55:25 +0000569 // Compute the latency for the node.
Evan Cheng3ef1c872010-09-10 01:29:16 +0000570 if (!InstrItins || InstrItins->isEmpty()) {
571 SU->Latency = 1;
Dan Gohman4ea8e852008-12-16 02:38:22 +0000572
Evan Cheng3ef1c872010-09-10 01:29:16 +0000573 // Simplistic target-independent heuristic: assume that loads take
574 // extra time.
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000575 if (SU->getInstr()->mayLoad())
Dan Gohman4ea8e852008-12-16 02:38:22 +0000576 SU->Latency += 2;
Evan Cheng8239daf2010-11-03 00:45:17 +0000577 } else {
578 SU->Latency = TII->getInstrLatency(InstrItins, SU->getInstr());
579 }
Dan Gohmanc8c28272008-11-21 00:12:10 +0000580}
581
Andrew Trickf405b1a2011-05-05 19:24:06 +0000582void ScheduleDAGInstrs::ComputeOperandLatency(SUnit *Def, SUnit *Use,
David Goodwindc4bdcd2009-08-19 16:08:58 +0000583 SDep& dep) const {
Evan Cheng3ef1c872010-09-10 01:29:16 +0000584 if (!InstrItins || InstrItins->isEmpty())
David Goodwindc4bdcd2009-08-19 16:08:58 +0000585 return;
Andrew Trickf405b1a2011-05-05 19:24:06 +0000586
David Goodwindc4bdcd2009-08-19 16:08:58 +0000587 // For a data dependency with a known register...
588 if ((dep.getKind() != SDep::Data) || (dep.getReg() == 0))
589 return;
590
591 const unsigned Reg = dep.getReg();
592
593 // ... find the definition of the register in the defining
594 // instruction
595 MachineInstr *DefMI = Def->getInstr();
596 int DefIdx = DefMI->findRegisterDefOperandIdx(Reg);
597 if (DefIdx != -1) {
Evan Cheng1aca5bc2010-10-08 18:42:25 +0000598 const MachineOperand &MO = DefMI->getOperand(DefIdx);
599 if (MO.isReg() && MO.isImplicit() &&
Evan Chengd82de832010-10-08 23:01:57 +0000600 DefIdx >= (int)DefMI->getDesc().getNumOperands()) {
Evan Cheng1aca5bc2010-10-08 18:42:25 +0000601 // This is an implicit def, getOperandLatency() won't return the correct
602 // latency. e.g.
603 // %D6<def>, %D7<def> = VLD1q16 %R2<kill>, 0, ..., %Q3<imp-def>
604 // %Q1<def> = VMULv8i16 %Q1<kill>, %Q3<kill>, ...
605 // What we want is to compute latency between def of %D6/%D7 and use of
606 // %Q3 instead.
607 DefIdx = DefMI->findRegisterDefOperandIdx(Reg, false, true, TRI);
608 }
Evan Chenga0792de2010-10-06 06:27:31 +0000609 MachineInstr *UseMI = Use->getInstr();
Evan Cheng3881cb72010-09-29 22:42:35 +0000610 // For all uses of the register, calculate the maxmimum latency
611 int Latency = -1;
Evan Chengec6906b2010-10-23 02:10:46 +0000612 if (UseMI) {
613 for (unsigned i = 0, e = UseMI->getNumOperands(); i != e; ++i) {
614 const MachineOperand &MO = UseMI->getOperand(i);
615 if (!MO.isReg() || !MO.isUse())
616 continue;
617 unsigned MOReg = MO.getReg();
618 if (MOReg != Reg)
619 continue;
David Goodwindc4bdcd2009-08-19 16:08:58 +0000620
Evan Chengec6906b2010-10-23 02:10:46 +0000621 int UseCycle = TII->getOperandLatency(InstrItins, DefMI, DefIdx,
622 UseMI, i);
623 Latency = std::max(Latency, UseCycle);
624 }
625 } else {
626 // UseMI is null, then it must be a scheduling barrier.
627 if (!InstrItins || InstrItins->isEmpty())
628 return;
629 unsigned DefClass = DefMI->getDesc().getSchedClass();
630 Latency = InstrItins->getOperandCycle(DefClass, DefIdx);
David Goodwindc4bdcd2009-08-19 16:08:58 +0000631 }
Evan Chengec6906b2010-10-23 02:10:46 +0000632
633 // If we found a latency, then replace the existing dependence latency.
634 if (Latency >= 0)
635 dep.setLatency(Latency);
David Goodwindc4bdcd2009-08-19 16:08:58 +0000636 }
637}
638
Dan Gohman343f0c02008-11-19 23:18:57 +0000639void ScheduleDAGInstrs::dumpNode(const SUnit *SU) const {
640 SU->getInstr()->dump();
641}
642
643std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const {
644 std::string s;
645 raw_string_ostream oss(s);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000646 if (SU == &EntrySU)
647 oss << "<entry>";
648 else if (SU == &ExitSU)
649 oss << "<exit>";
650 else
651 SU->getInstr()->print(oss);
Dan Gohman343f0c02008-11-19 23:18:57 +0000652 return oss.str();
653}
654
655// EmitSchedule - Emit the machine code in scheduled order.
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000656MachineBasicBlock *ScheduleDAGInstrs::EmitSchedule() {
Evan Chengddfd1372011-12-14 02:11:42 +0000657 Begin = InsertPos;
Dan Gohman343f0c02008-11-19 23:18:57 +0000658
Devang Patelcf4cc842011-06-02 20:07:12 +0000659 // If first instruction was a DBG_VALUE then put it back.
660 if (FirstDbgValue)
Evan Chengddfd1372011-12-14 02:11:42 +0000661 BB->splice(InsertPos, BB, FirstDbgValue);
Dale Johannesenbfdf7f32010-03-10 22:13:47 +0000662
Dan Gohman0b1d4a72008-12-23 21:37:04 +0000663 // Then re-insert them according to the given schedule.
Dan Gohman343f0c02008-11-19 23:18:57 +0000664 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
Devang Patelee1f8782011-06-02 21:31:00 +0000665 if (SUnit *SU = Sequence[i])
Evan Chengddfd1372011-12-14 02:11:42 +0000666 BB->splice(InsertPos, BB, SU->getInstr());
Devang Patelee1f8782011-06-02 21:31:00 +0000667 else
Dan Gohman343f0c02008-11-19 23:18:57 +0000668 // Null SUnit* is a noop.
669 EmitNoop();
Dan Gohman343f0c02008-11-19 23:18:57 +0000670
Hal Finkeldb809e02011-12-02 04:58:07 +0000671 // Update the Begin iterator, as the first instruction in the block
672 // may have been scheduled later.
673 if (i == 0)
674 Begin = prior(InsertPos);
675 }
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000676
Devang Patelcf4cc842011-06-02 20:07:12 +0000677 // Reinsert any remaining debug_values.
678 for (std::vector<std::pair<MachineInstr *, MachineInstr *> >::iterator
679 DI = DbgValues.end(), DE = DbgValues.begin(); DI != DE; --DI) {
680 std::pair<MachineInstr *, MachineInstr *> P = *prior(DI);
681 MachineInstr *DbgValue = P.first;
Evan Cheng7c2a4a32011-12-06 22:12:01 +0000682 MachineBasicBlock::iterator OrigPrivMI = P.second;
Evan Chengddfd1372011-12-14 02:11:42 +0000683 BB->splice(++OrigPrivMI, BB, DbgValue);
Devang Patelcf4cc842011-06-02 20:07:12 +0000684 }
685 DbgValues.clear();
686 FirstDbgValue = NULL;
Dan Gohman343f0c02008-11-19 23:18:57 +0000687 return BB;
688}