blob: a13e51f1d485b9ab499c6c0b69cdeeb2b79a16a6 [file] [log] [blame]
Dale Johannesen72f15962007-07-13 17:31:29 +00001//===----- SchedulePostRAList.cpp - list scheduler ------------------------===//
Dale Johannesene7e7d0d2007-07-13 17:13:54 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dale Johannesene7e7d0d2007-07-13 17:13:54 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This implements a top-down list scheduler, using standard algorithms.
11// The basic approach uses a priority queue of available nodes to schedule.
12// One at a time, nodes are taken from the priority queue (thus in priority
13// order), checked for legality to schedule, and emitted if legal.
14//
15// Nodes may not be legal to schedule either due to structural hazards (e.g.
16// pipeline or resource constraints) or because an input to the instruction has
17// not completed execution.
18//
19//===----------------------------------------------------------------------===//
20
21#define DEBUG_TYPE "post-RA-sched"
22#include "llvm/CodeGen/Passes.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000023#include "AggressiveAntiDepBreaker.h"
24#include "AntiDepBreaker.h"
25#include "CriticalAntiDepBreaker.h"
26#include "llvm/ADT/BitVector.h"
27#include "llvm/ADT/Statistic.h"
28#include "llvm/Analysis/AliasAnalysis.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000029#include "llvm/CodeGen/LatencyPriorityQueue.h"
Dan Gohman3f237442008-12-16 03:25:46 +000030#include "llvm/CodeGen/MachineDominators.h"
David Goodwinc7951f82009-10-01 19:45:32 +000031#include "llvm/CodeGen/MachineFrameInfo.h"
Dale Johannesene7e7d0d2007-07-13 17:13:54 +000032#include "llvm/CodeGen/MachineFunctionPass.h"
Dan Gohman3f237442008-12-16 03:25:46 +000033#include "llvm/CodeGen/MachineLoopInfo.h"
Dan Gohman21d90032008-11-25 00:52:40 +000034#include "llvm/CodeGen/MachineRegisterInfo.h"
Andrew Trick15252602012-06-06 20:29:31 +000035#include "llvm/CodeGen/RegisterClassInfo.h"
Andrew Tricked395c82012-03-07 23:01:06 +000036#include "llvm/CodeGen/ScheduleDAGInstrs.h"
Dan Gohman2836c282009-01-16 01:33:36 +000037#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000038#include "llvm/CodeGen/SchedulerRegistry.h"
David Goodwine10deca2009-10-26 22:31:16 +000039#include "llvm/Support/CommandLine.h"
Dale Johannesene7e7d0d2007-07-13 17:13:54 +000040#include "llvm/Support/Debug.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000041#include "llvm/Support/ErrorHandling.h"
David Goodwin3a5f0d42009-08-11 01:44:26 +000042#include "llvm/Support/raw_ostream.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000043#include "llvm/Target/TargetInstrInfo.h"
44#include "llvm/Target/TargetLowering.h"
45#include "llvm/Target/TargetMachine.h"
46#include "llvm/Target/TargetRegisterInfo.h"
47#include "llvm/Target/TargetSubtargetInfo.h"
Dale Johannesene7e7d0d2007-07-13 17:13:54 +000048using namespace llvm;
49
Dan Gohman2836c282009-01-16 01:33:36 +000050STATISTIC(NumNoops, "Number of noops inserted");
Dan Gohman343f0c02008-11-19 23:18:57 +000051STATISTIC(NumStalls, "Number of pipeline stalls");
David Goodwin2e7be612009-10-26 16:59:04 +000052STATISTIC(NumFixedAnti, "Number of fixed anti-dependencies");
Dan Gohman343f0c02008-11-19 23:18:57 +000053
David Goodwin471850a2009-10-01 21:46:35 +000054// Post-RA scheduling is enabled with
Evan Cheng5b1b44892011-07-01 21:01:15 +000055// TargetSubtargetInfo.enablePostRAScheduler(). This flag can be used to
David Goodwin471850a2009-10-01 21:46:35 +000056// override the target.
57static cl::opt<bool>
58EnablePostRAScheduler("post-RA-scheduler",
59 cl::desc("Enable scheduling after register allocation"),
David Goodwin9843a932009-10-01 22:19:57 +000060 cl::init(false), cl::Hidden);
David Goodwin2e7be612009-10-26 16:59:04 +000061static cl::opt<std::string>
Dan Gohman21d90032008-11-25 00:52:40 +000062EnableAntiDepBreaking("break-anti-dependencies",
David Goodwin2e7be612009-10-26 16:59:04 +000063 cl::desc("Break post-RA scheduling anti-dependencies: "
64 "\"critical\", \"all\", or \"none\""),
65 cl::init("none"), cl::Hidden);
Dan Gohman2836c282009-01-16 01:33:36 +000066
David Goodwin1f152282009-09-01 18:34:03 +000067// If DebugDiv > 0 then only schedule MBB with (ID % DebugDiv) == DebugMod
68static cl::opt<int>
69DebugDiv("postra-sched-debugdiv",
70 cl::desc("Debug control MBBs that are scheduled"),
71 cl::init(0), cl::Hidden);
72static cl::opt<int>
73DebugMod("postra-sched-debugmod",
74 cl::desc("Debug control MBBs that are scheduled"),
75 cl::init(0), cl::Hidden);
76
David Goodwinada0ef82009-10-26 19:41:00 +000077AntiDepBreaker::~AntiDepBreaker() { }
78
Dale Johannesene7e7d0d2007-07-13 17:13:54 +000079namespace {
Nick Lewycky6726b6d2009-10-25 06:33:48 +000080 class PostRAScheduler : public MachineFunctionPass {
Evan Cheng86050dc2010-06-18 23:09:54 +000081 const TargetInstrInfo *TII;
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +000082 RegisterClassInfo RegClassInfo;
Dan Gohmana70dca12009-10-09 23:27:56 +000083
Dale Johannesene7e7d0d2007-07-13 17:13:54 +000084 public:
85 static char ID;
Andrew Trickc7d081b2012-02-08 21:22:53 +000086 PostRAScheduler() : MachineFunctionPass(ID) {}
Dan Gohman21d90032008-11-25 00:52:40 +000087
Stephen Hines36b56882014-04-23 16:57:46 -070088 void getAnalysisUsage(AnalysisUsage &AU) const override {
Dan Gohman845012e2009-07-31 23:37:33 +000089 AU.setPreservesCFG();
Dan Gohmana70dca12009-10-09 23:27:56 +000090 AU.addRequired<AliasAnalysis>();
Andrew Trickc7d081b2012-02-08 21:22:53 +000091 AU.addRequired<TargetPassConfig>();
Dan Gohman3f237442008-12-16 03:25:46 +000092 AU.addRequired<MachineDominatorTree>();
93 AU.addPreserved<MachineDominatorTree>();
94 AU.addRequired<MachineLoopInfo>();
95 AU.addPreserved<MachineLoopInfo>();
96 MachineFunctionPass::getAnalysisUsage(AU);
97 }
98
Stephen Hines36b56882014-04-23 16:57:46 -070099 bool runOnMachineFunction(MachineFunction &Fn) override;
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000100 };
Dan Gohman343f0c02008-11-19 23:18:57 +0000101 char PostRAScheduler::ID = 0;
102
Nick Lewycky6726b6d2009-10-25 06:33:48 +0000103 class SchedulePostRATDList : public ScheduleDAGInstrs {
Dan Gohman343f0c02008-11-19 23:18:57 +0000104 /// AvailableQueue - The priority queue to use for the available SUnits.
Dan Gohmanc1ae8c92009-10-21 01:44:44 +0000105 ///
Dan Gohman343f0c02008-11-19 23:18:57 +0000106 LatencyPriorityQueue AvailableQueue;
Jim Grosbach90013032010-05-14 21:19:48 +0000107
Dan Gohman343f0c02008-11-19 23:18:57 +0000108 /// PendingQueue - This contains all of the instructions whose operands have
109 /// been issued, but their results are not ready yet (due to the latency of
110 /// the operation). Once the operands becomes available, the instruction is
111 /// added to the AvailableQueue.
112 std::vector<SUnit*> PendingQueue;
113
Dan Gohman2836c282009-01-16 01:33:36 +0000114 /// HazardRec - The hazard recognizer to use.
115 ScheduleHazardRecognizer *HazardRec;
116
David Goodwin2e7be612009-10-26 16:59:04 +0000117 /// AntiDepBreak - Anti-dependence breaking object, or NULL if none
118 AntiDepBreaker *AntiDepBreak;
119
Dan Gohmana70dca12009-10-09 23:27:56 +0000120 /// AA - AliasAnalysis for making memory reference queries.
121 AliasAnalysis *AA;
122
Andrew Trick47c14452012-03-07 05:21:52 +0000123 /// The schedule. Null SUnit*'s represent noop instructions.
124 std::vector<SUnit*> Sequence;
125
Andrew Trickd2763f62013-08-23 17:48:33 +0000126 /// The index in BB of RegionEnd.
127 ///
128 /// This is the instruction number from the top of the current block, not
129 /// the SlotIndex. It is only used by the AntiDepBreaker.
130 unsigned EndIndex;
131
Dan Gohman21d90032008-11-25 00:52:40 +0000132 public:
Andrew Trick2da8bc82010-12-24 05:03:26 +0000133 SchedulePostRATDList(
134 MachineFunction &MF, MachineLoopInfo &MLI, MachineDominatorTree &MDT,
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +0000135 AliasAnalysis *AA, const RegisterClassInfo&,
Evan Cheng5b1b44892011-07-01 21:01:15 +0000136 TargetSubtargetInfo::AntiDepBreakMode AntiDepMode,
Craig Topper44d23822012-02-22 05:59:10 +0000137 SmallVectorImpl<const TargetRegisterClass*> &CriticalPathRCs);
Dan Gohman2836c282009-01-16 01:33:36 +0000138
Andrew Trick2da8bc82010-12-24 05:03:26 +0000139 ~SchedulePostRATDList();
Dan Gohman343f0c02008-11-19 23:18:57 +0000140
Andrew Trick953be892012-03-07 23:00:49 +0000141 /// startBlock - Initialize register live-range state for scheduling in
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000142 /// this block.
143 ///
Stephen Hines36b56882014-04-23 16:57:46 -0700144 void startBlock(MachineBasicBlock *BB) override;
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000145
Andrew Trickd2763f62013-08-23 17:48:33 +0000146 // Set the index of RegionEnd within the current BB.
147 void setEndIndex(unsigned EndIdx) { EndIndex = EndIdx; }
148
Andrew Trick47c14452012-03-07 05:21:52 +0000149 /// Initialize the scheduler state for the next scheduling region.
Stephen Hines36b56882014-04-23 16:57:46 -0700150 void enterRegion(MachineBasicBlock *bb,
151 MachineBasicBlock::iterator begin,
152 MachineBasicBlock::iterator end,
153 unsigned regioninstrs) override;
Andrew Trick47c14452012-03-07 05:21:52 +0000154
155 /// Notify that the scheduler has finished scheduling the current region.
Stephen Hines36b56882014-04-23 16:57:46 -0700156 void exitRegion() override;
Andrew Trick47c14452012-03-07 05:21:52 +0000157
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000158 /// Schedule - Schedule the instruction range using list scheduling.
159 ///
Stephen Hines36b56882014-04-23 16:57:46 -0700160 void schedule() override;
Jim Grosbach90013032010-05-14 21:19:48 +0000161
Andrew Trick84b454d2012-03-07 05:21:44 +0000162 void EmitSchedule();
163
Dan Gohmanc1ae8c92009-10-21 01:44:44 +0000164 /// Observe - Update liveness information to account for the current
165 /// instruction, which will not be scheduled.
166 ///
167 void Observe(MachineInstr *MI, unsigned Count);
168
Andrew Trick953be892012-03-07 23:00:49 +0000169 /// finishBlock - Clean up register live-range state.
Dan Gohmanc1ae8c92009-10-21 01:44:44 +0000170 ///
Stephen Hines36b56882014-04-23 16:57:46 -0700171 void finishBlock() override;
David Goodwin2e7be612009-10-26 16:59:04 +0000172
Dan Gohman343f0c02008-11-19 23:18:57 +0000173 private:
David Goodwin557bbe62009-11-20 19:32:48 +0000174 void ReleaseSucc(SUnit *SU, SDep *SuccEdge);
175 void ReleaseSuccessors(SUnit *SU);
176 void ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle);
177 void ListScheduleTopDown();
Andrew Trick73ba69b2012-03-07 05:21:40 +0000178
179 void dumpSchedule() const;
Stephen Hines36b56882014-04-23 16:57:46 -0700180 void emitNoop(unsigned CurCycle);
Dan Gohman343f0c02008-11-19 23:18:57 +0000181 };
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000182}
183
Andrew Trick1dd8c852012-02-08 21:23:13 +0000184char &llvm::PostRASchedulerID = PostRAScheduler::ID;
185
186INITIALIZE_PASS(PostRAScheduler, "post-RA-sched",
187 "Post RA top-down list latency scheduler", false, false)
188
Andrew Trick2da8bc82010-12-24 05:03:26 +0000189SchedulePostRATDList::SchedulePostRATDList(
190 MachineFunction &MF, MachineLoopInfo &MLI, MachineDominatorTree &MDT,
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +0000191 AliasAnalysis *AA, const RegisterClassInfo &RCI,
Evan Cheng5b1b44892011-07-01 21:01:15 +0000192 TargetSubtargetInfo::AntiDepBreakMode AntiDepMode,
Craig Topper44d23822012-02-22 05:59:10 +0000193 SmallVectorImpl<const TargetRegisterClass*> &CriticalPathRCs)
Stephen Hines36b56882014-04-23 16:57:46 -0700194 : ScheduleDAGInstrs(MF, MLI, MDT, /*IsPostRA=*/true), AA(AA), EndIndex(0) {
195
Andrew Trick2da8bc82010-12-24 05:03:26 +0000196 const TargetMachine &TM = MF.getTarget();
197 const InstrItineraryData *InstrItins = TM.getInstrItineraryData();
198 HazardRec =
199 TM.getInstrInfo()->CreateTargetPostRAHazardRecognizer(InstrItins, this);
Preston Gurd6a8c7bf2012-04-23 21:39:35 +0000200
201 assert((AntiDepMode == TargetSubtargetInfo::ANTIDEP_NONE ||
202 MRI.tracksLiveness()) &&
203 "Live-ins must be accurate for anti-dependency breaking");
Andrew Trick2da8bc82010-12-24 05:03:26 +0000204 AntiDepBreak =
Evan Cheng5b1b44892011-07-01 21:01:15 +0000205 ((AntiDepMode == TargetSubtargetInfo::ANTIDEP_ALL) ?
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +0000206 (AntiDepBreaker *)new AggressiveAntiDepBreaker(MF, RCI, CriticalPathRCs) :
Evan Cheng5b1b44892011-07-01 21:01:15 +0000207 ((AntiDepMode == TargetSubtargetInfo::ANTIDEP_CRITICAL) ?
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +0000208 (AntiDepBreaker *)new CriticalAntiDepBreaker(MF, RCI) : NULL));
Andrew Trick2da8bc82010-12-24 05:03:26 +0000209}
210
211SchedulePostRATDList::~SchedulePostRATDList() {
212 delete HazardRec;
213 delete AntiDepBreak;
214}
215
Andrew Trick47c14452012-03-07 05:21:52 +0000216/// Initialize state associated with the next scheduling region.
217void SchedulePostRATDList::enterRegion(MachineBasicBlock *bb,
218 MachineBasicBlock::iterator begin,
219 MachineBasicBlock::iterator end,
Andrew Trickd2763f62013-08-23 17:48:33 +0000220 unsigned regioninstrs) {
221 ScheduleDAGInstrs::enterRegion(bb, begin, end, regioninstrs);
Andrew Trick47c14452012-03-07 05:21:52 +0000222 Sequence.clear();
223}
224
225/// Print the schedule before exiting the region.
226void SchedulePostRATDList::exitRegion() {
227 DEBUG({
228 dbgs() << "*** Final schedule ***\n";
229 dumpSchedule();
230 dbgs() << '\n';
231 });
232 ScheduleDAGInstrs::exitRegion();
233}
234
Manman Renb720be62012-09-11 22:23:19 +0000235#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Andrew Trick73ba69b2012-03-07 05:21:40 +0000236/// dumpSchedule - dump the scheduled Sequence.
237void SchedulePostRATDList::dumpSchedule() const {
238 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
239 if (SUnit *SU = Sequence[i])
240 SU->dump(this);
241 else
242 dbgs() << "**** NOOP ****\n";
243 }
244}
Manman Ren77e300e2012-09-06 19:06:06 +0000245#endif
Andrew Trick73ba69b2012-03-07 05:21:40 +0000246
Dan Gohman343f0c02008-11-19 23:18:57 +0000247bool PostRAScheduler::runOnMachineFunction(MachineFunction &Fn) {
Stephen Hines36b56882014-04-23 16:57:46 -0700248 if (skipOptnoneFunction(*Fn.getFunction()))
249 return false;
250
Evan Cheng86050dc2010-06-18 23:09:54 +0000251 TII = Fn.getTarget().getInstrInfo();
Andrew Trick2da8bc82010-12-24 05:03:26 +0000252 MachineLoopInfo &MLI = getAnalysis<MachineLoopInfo>();
253 MachineDominatorTree &MDT = getAnalysis<MachineDominatorTree>();
254 AliasAnalysis *AA = &getAnalysis<AliasAnalysis>();
Andrew Trickc7d081b2012-02-08 21:22:53 +0000255 TargetPassConfig *PassConfig = &getAnalysis<TargetPassConfig>();
256
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +0000257 RegClassInfo.runOnMachineFunction(Fn);
Dan Gohman5bf7c2a2009-10-10 00:15:38 +0000258
David Goodwin471850a2009-10-01 21:46:35 +0000259 // Check for explicit enable/disable of post-ra scheduling.
Evan Chengddfd1372011-12-14 02:11:42 +0000260 TargetSubtargetInfo::AntiDepBreakMode AntiDepMode =
261 TargetSubtargetInfo::ANTIDEP_NONE;
Craig Topper44d23822012-02-22 05:59:10 +0000262 SmallVector<const TargetRegisterClass*, 4> CriticalPathRCs;
David Goodwin471850a2009-10-01 21:46:35 +0000263 if (EnablePostRAScheduler.getPosition() > 0) {
264 if (!EnablePostRAScheduler)
Evan Chengc83da2f92009-10-16 06:10:34 +0000265 return false;
David Goodwin471850a2009-10-01 21:46:35 +0000266 } else {
Evan Chengc83da2f92009-10-16 06:10:34 +0000267 // Check that post-RA scheduling is enabled for this target.
Andrew Trick2da8bc82010-12-24 05:03:26 +0000268 // This may upgrade the AntiDepMode.
Evan Cheng5b1b44892011-07-01 21:01:15 +0000269 const TargetSubtargetInfo &ST = Fn.getTarget().getSubtarget<TargetSubtargetInfo>();
Andrew Trickc7d081b2012-02-08 21:22:53 +0000270 if (!ST.enablePostRAScheduler(PassConfig->getOptLevel(), AntiDepMode,
271 CriticalPathRCs))
Evan Chengc83da2f92009-10-16 06:10:34 +0000272 return false;
David Goodwin471850a2009-10-01 21:46:35 +0000273 }
David Goodwin0dad89f2009-09-30 00:10:16 +0000274
David Goodwin4c3715c2009-10-22 23:19:17 +0000275 // Check for antidep breaking override...
276 if (EnableAntiDepBreaking.getPosition() > 0) {
Evan Cheng5b1b44892011-07-01 21:01:15 +0000277 AntiDepMode = (EnableAntiDepBreaking == "all")
278 ? TargetSubtargetInfo::ANTIDEP_ALL
279 : ((EnableAntiDepBreaking == "critical")
280 ? TargetSubtargetInfo::ANTIDEP_CRITICAL
281 : TargetSubtargetInfo::ANTIDEP_NONE);
David Goodwin4c3715c2009-10-22 23:19:17 +0000282 }
283
David Greenee1b21292010-01-05 01:26:01 +0000284 DEBUG(dbgs() << "PostRAScheduler\n");
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000285
Jakob Stoklund Olesenfa796dd2011-06-16 21:56:21 +0000286 SchedulePostRATDList Scheduler(Fn, MLI, MDT, AA, RegClassInfo, AntiDepMode,
Andrew Trick2da8bc82010-12-24 05:03:26 +0000287 CriticalPathRCs);
Dan Gohman79ce2762009-01-15 19:20:50 +0000288
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000289 // Loop over all of the basic blocks
290 for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end();
Dan Gohman343f0c02008-11-19 23:18:57 +0000291 MBB != MBBe; ++MBB) {
David Goodwin1f152282009-09-01 18:34:03 +0000292#ifndef NDEBUG
293 // If DebugDiv > 0 then only schedule MBB with (ID % DebugDiv) == DebugMod
294 if (DebugDiv > 0) {
295 static int bbcnt = 0;
296 if (bbcnt++ % DebugDiv != DebugMod)
297 continue;
Craig Topper96601ca2012-08-22 06:07:19 +0000298 dbgs() << "*** DEBUG scheduling " << Fn.getName()
Benjamin Kramera7b0cb72011-11-15 16:27:03 +0000299 << ":BB#" << MBB->getNumber() << " ***\n";
David Goodwin1f152282009-09-01 18:34:03 +0000300 }
301#endif
302
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000303 // Initialize register live-range state for scheduling in this block.
Andrew Trick953be892012-03-07 23:00:49 +0000304 Scheduler.startBlock(MBB);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000305
Dan Gohmanf7119392009-01-16 22:10:20 +0000306 // Schedule each sequence of instructions not interrupted by a label
307 // or anything else that effectively needs to shut down scheduling.
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000308 MachineBasicBlock::iterator Current = MBB->end();
Dan Gohman47ac0f02009-02-11 04:27:20 +0000309 unsigned Count = MBB->size(), CurrentCount = Count;
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000310 for (MachineBasicBlock::iterator I = Current; I != MBB->begin(); ) {
Stephen Hines36b56882014-04-23 16:57:46 -0700311 MachineInstr *MI = std::prev(I);
Andrew Trickd2763f62013-08-23 17:48:33 +0000312 --Count;
Jakob Stoklund Olesen976647d2012-02-23 17:54:21 +0000313 // Calls are not scheduling boundaries before register allocation, but
314 // post-ra we don't gain anything by scheduling across calls since we
315 // don't need to worry about register pressure.
316 if (MI->isCall() || TII->isSchedulingBoundary(MI, MBB, Fn)) {
Andrew Trickd2763f62013-08-23 17:48:33 +0000317 Scheduler.enterRegion(MBB, I, Current, CurrentCount - Count);
318 Scheduler.setEndIndex(CurrentCount);
Andrew Trick953be892012-03-07 23:00:49 +0000319 Scheduler.schedule();
Andrew Trick47c14452012-03-07 05:21:52 +0000320 Scheduler.exitRegion();
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000321 Scheduler.EmitSchedule();
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000322 Current = MI;
Andrew Trickd2763f62013-08-23 17:48:33 +0000323 CurrentCount = Count;
Dan Gohman1274ced2009-03-10 18:10:43 +0000324 Scheduler.Observe(MI, CurrentCount);
Dan Gohmanf7119392009-01-16 22:10:20 +0000325 }
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000326 I = MI;
Evan Chengddfd1372011-12-14 02:11:42 +0000327 if (MI->isBundle())
328 Count -= MI->getBundleSize();
Dan Gohman43f07fb2009-02-03 18:57:45 +0000329 }
Dan Gohman47ac0f02009-02-11 04:27:20 +0000330 assert(Count == 0 && "Instruction count mismatch!");
Duncan Sands9e8bd0b2009-03-11 09:04:34 +0000331 assert((MBB->begin() == Current || CurrentCount != 0) &&
Dan Gohman1274ced2009-03-10 18:10:43 +0000332 "Instruction count mismatch!");
Andrew Trick47c14452012-03-07 05:21:52 +0000333 Scheduler.enterRegion(MBB, MBB->begin(), Current, CurrentCount);
Andrew Trickd2763f62013-08-23 17:48:33 +0000334 Scheduler.setEndIndex(CurrentCount);
Andrew Trick953be892012-03-07 23:00:49 +0000335 Scheduler.schedule();
Andrew Trick47c14452012-03-07 05:21:52 +0000336 Scheduler.exitRegion();
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000337 Scheduler.EmitSchedule();
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000338
339 // Clean up register live-range state.
Andrew Trick953be892012-03-07 23:00:49 +0000340 Scheduler.finishBlock();
David Goodwin88a589c2009-08-25 17:03:05 +0000341
David Goodwin5e411782009-09-03 22:15:25 +0000342 // Update register kills
Stephen Hines36b56882014-04-23 16:57:46 -0700343 Scheduler.fixupKills(MBB);
Dan Gohman343f0c02008-11-19 23:18:57 +0000344 }
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000345
346 return true;
347}
Jim Grosbach90013032010-05-14 21:19:48 +0000348
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000349/// StartBlock - Initialize register live-range state for scheduling in
350/// this block.
Dan Gohman21d90032008-11-25 00:52:40 +0000351///
Andrew Trick953be892012-03-07 23:00:49 +0000352void SchedulePostRATDList::startBlock(MachineBasicBlock *BB) {
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000353 // Call the superclass.
Andrew Trick953be892012-03-07 23:00:49 +0000354 ScheduleDAGInstrs::startBlock(BB);
Dan Gohman21d90032008-11-25 00:52:40 +0000355
David Goodwin2e7be612009-10-26 16:59:04 +0000356 // Reset the hazard recognizer and anti-dep breaker.
David Goodwind94a4e52009-08-10 15:55:25 +0000357 HazardRec->Reset();
David Goodwin2e7be612009-10-26 16:59:04 +0000358 if (AntiDepBreak != NULL)
359 AntiDepBreak->StartBlock(BB);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000360}
361
362/// Schedule - Schedule the instruction range using list scheduling.
363///
Andrew Trick953be892012-03-07 23:00:49 +0000364void SchedulePostRATDList::schedule() {
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000365 // Build the scheduling graph.
Andrew Trick953be892012-03-07 23:00:49 +0000366 buildSchedGraph(AA);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000367
David Goodwin2e7be612009-10-26 16:59:04 +0000368 if (AntiDepBreak != NULL) {
Jim Grosbach90013032010-05-14 21:19:48 +0000369 unsigned Broken =
Andrew Trick68675c62012-03-09 04:29:02 +0000370 AntiDepBreak->BreakAntiDependencies(SUnits, RegionBegin, RegionEnd,
371 EndIndex, DbgValues);
Jim Grosbach90013032010-05-14 21:19:48 +0000372
David Goodwin557bbe62009-11-20 19:32:48 +0000373 if (Broken != 0) {
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000374 // We made changes. Update the dependency graph.
375 // Theoretically we could update the graph in place:
376 // When a live range is changed to use a different register, remove
377 // the def's anti-dependence *and* output-dependence edges due to
378 // that register, and add new anti-dependence and output-dependence
379 // edges based on the next live range of the register.
Andrew Trick47c14452012-03-07 05:21:52 +0000380 ScheduleDAG::clearDAG();
Andrew Trick953be892012-03-07 23:00:49 +0000381 buildSchedGraph(AA);
Jim Grosbach90013032010-05-14 21:19:48 +0000382
David Goodwin2e7be612009-10-26 16:59:04 +0000383 NumFixedAnti += Broken;
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000384 }
385 }
386
David Greenee1b21292010-01-05 01:26:01 +0000387 DEBUG(dbgs() << "********** List Scheduling **********\n");
David Goodwind94a4e52009-08-10 15:55:25 +0000388 DEBUG(for (unsigned su = 0, e = SUnits.size(); su != e; ++su)
389 SUnits[su].dumpAll(this));
390
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000391 AvailableQueue.initNodes(SUnits);
David Goodwin557bbe62009-11-20 19:32:48 +0000392 ListScheduleTopDown();
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000393 AvailableQueue.releaseState();
394}
395
396/// Observe - Update liveness information to account for the current
397/// instruction, which will not be scheduled.
398///
Dan Gohman47ac0f02009-02-11 04:27:20 +0000399void SchedulePostRATDList::Observe(MachineInstr *MI, unsigned Count) {
David Goodwin2e7be612009-10-26 16:59:04 +0000400 if (AntiDepBreak != NULL)
Andrew Trickcf46b5a2012-03-07 23:00:52 +0000401 AntiDepBreak->Observe(MI, Count, EndIndex);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000402}
403
404/// FinishBlock - Clean up register live-range state.
405///
Andrew Trick953be892012-03-07 23:00:49 +0000406void SchedulePostRATDList::finishBlock() {
David Goodwin2e7be612009-10-26 16:59:04 +0000407 if (AntiDepBreak != NULL)
408 AntiDepBreak->FinishBlock();
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000409
410 // Call the superclass.
Andrew Trick953be892012-03-07 23:00:49 +0000411 ScheduleDAGInstrs::finishBlock();
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000412}
413
Dan Gohman343f0c02008-11-19 23:18:57 +0000414//===----------------------------------------------------------------------===//
415// Top-Down Scheduling
416//===----------------------------------------------------------------------===//
417
418/// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to
Andrew Trickae692f22012-11-12 19:28:57 +0000419/// the PendingQueue if the count reaches zero.
David Goodwin557bbe62009-11-20 19:32:48 +0000420void SchedulePostRATDList::ReleaseSucc(SUnit *SU, SDep *SuccEdge) {
Dan Gohman54e4c362008-12-09 22:54:47 +0000421 SUnit *SuccSU = SuccEdge->getSUnit();
Reid Klecknerc277ab02009-09-30 20:15:38 +0000422
Andrew Trickcf6b6132012-11-13 02:35:06 +0000423 if (SuccEdge->isWeak()) {
Andrew Trickae692f22012-11-12 19:28:57 +0000424 --SuccSU->WeakPredsLeft;
425 return;
426 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000427#ifndef NDEBUG
Reid Klecknerc277ab02009-09-30 20:15:38 +0000428 if (SuccSU->NumPredsLeft == 0) {
David Greenee1b21292010-01-05 01:26:01 +0000429 dbgs() << "*** Scheduling failed! ***\n";
Dan Gohman343f0c02008-11-19 23:18:57 +0000430 SuccSU->dump(this);
David Greenee1b21292010-01-05 01:26:01 +0000431 dbgs() << " has been released too many times!\n";
Torok Edwinc23197a2009-07-14 16:55:14 +0000432 llvm_unreachable(0);
Dan Gohman343f0c02008-11-19 23:18:57 +0000433 }
434#endif
Reid Klecknerc277ab02009-09-30 20:15:38 +0000435 --SuccSU->NumPredsLeft;
436
Andrew Trick89fd4372011-05-06 18:14:32 +0000437 // Standard scheduler algorithms will recompute the depth of the successor
Andrew Trick15ab3592011-05-06 17:09:08 +0000438 // here as such:
439 // SuccSU->setDepthToAtLeast(SU->getDepth() + SuccEdge->getLatency());
440 //
441 // However, we lazily compute node depth instead. Note that
442 // ScheduleNodeTopDown has already updated the depth of this node which causes
443 // all descendents to be marked dirty. Setting the successor depth explicitly
444 // here would cause depth to be recomputed for all its ancestors. If the
445 // successor is not yet ready (because of a transitively redundant edge) then
446 // this causes depth computation to be quadratic in the size of the DAG.
Jim Grosbach90013032010-05-14 21:19:48 +0000447
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000448 // If all the node's predecessors are scheduled, this node is ready
449 // to be scheduled. Ignore the special ExitSU node.
450 if (SuccSU->NumPredsLeft == 0 && SuccSU != &ExitSU)
Dan Gohman343f0c02008-11-19 23:18:57 +0000451 PendingQueue.push_back(SuccSU);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000452}
453
454/// ReleaseSuccessors - Call ReleaseSucc on each of SU's successors.
David Goodwin557bbe62009-11-20 19:32:48 +0000455void SchedulePostRATDList::ReleaseSuccessors(SUnit *SU) {
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000456 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
David Goodwin4de099d2009-11-03 20:57:50 +0000457 I != E; ++I) {
David Goodwin557bbe62009-11-20 19:32:48 +0000458 ReleaseSucc(SU, &*I);
David Goodwin4de099d2009-11-03 20:57:50 +0000459 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000460}
461
462/// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending
463/// count of its successors. If a successor pending count is zero, add it to
464/// the Available queue.
David Goodwin557bbe62009-11-20 19:32:48 +0000465void SchedulePostRATDList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) {
David Greenee1b21292010-01-05 01:26:01 +0000466 DEBUG(dbgs() << "*** Scheduling [" << CurCycle << "]: ");
Dan Gohman343f0c02008-11-19 23:18:57 +0000467 DEBUG(SU->dump(this));
Jim Grosbach90013032010-05-14 21:19:48 +0000468
Dan Gohman343f0c02008-11-19 23:18:57 +0000469 Sequence.push_back(SU);
Jim Grosbach90013032010-05-14 21:19:48 +0000470 assert(CurCycle >= SU->getDepth() &&
David Goodwin4de099d2009-11-03 20:57:50 +0000471 "Node scheduled above its depth!");
David Goodwin557bbe62009-11-20 19:32:48 +0000472 SU->setDepthToAtLeast(CurCycle);
Dan Gohman343f0c02008-11-19 23:18:57 +0000473
David Goodwin557bbe62009-11-20 19:32:48 +0000474 ReleaseSuccessors(SU);
Dan Gohman343f0c02008-11-19 23:18:57 +0000475 SU->isScheduled = true;
Andrew Trick953be892012-03-07 23:00:49 +0000476 AvailableQueue.scheduledNode(SU);
Dan Gohman343f0c02008-11-19 23:18:57 +0000477}
478
Stephen Hines36b56882014-04-23 16:57:46 -0700479/// emitNoop - Add a noop to the current instruction sequence.
480void SchedulePostRATDList::emitNoop(unsigned CurCycle) {
481 DEBUG(dbgs() << "*** Emitting noop in cycle " << CurCycle << '\n');
482 HazardRec->EmitNoop();
483 Sequence.push_back(0); // NULL here means noop
484 ++NumNoops;
485}
486
Dan Gohman343f0c02008-11-19 23:18:57 +0000487/// ListScheduleTopDown - The main loop of list scheduling for top-down
488/// schedulers.
David Goodwin557bbe62009-11-20 19:32:48 +0000489void SchedulePostRATDList::ListScheduleTopDown() {
Dan Gohman343f0c02008-11-19 23:18:57 +0000490 unsigned CurCycle = 0;
Jim Grosbach90013032010-05-14 21:19:48 +0000491
David Goodwin4de099d2009-11-03 20:57:50 +0000492 // We're scheduling top-down but we're visiting the regions in
493 // bottom-up order, so we don't know the hazards at the start of a
494 // region. So assume no hazards (this should usually be ok as most
495 // blocks are a single region).
496 HazardRec->Reset();
497
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000498 // Release any successors of the special Entry node.
David Goodwin557bbe62009-11-20 19:32:48 +0000499 ReleaseSuccessors(&EntrySU);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000500
David Goodwin557bbe62009-11-20 19:32:48 +0000501 // Add all leaves to Available queue.
Dan Gohman343f0c02008-11-19 23:18:57 +0000502 for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
503 // It is available if it has no predecessors.
Andrew Trickae692f22012-11-12 19:28:57 +0000504 if (!SUnits[i].NumPredsLeft && !SUnits[i].isAvailable) {
Dan Gohman343f0c02008-11-19 23:18:57 +0000505 AvailableQueue.push(&SUnits[i]);
506 SUnits[i].isAvailable = true;
507 }
508 }
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000509
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000510 // In any cycle where we can't schedule any instructions, we must
511 // stall or emit a noop, depending on the target.
Benjamin Kramerbe441c02009-09-06 12:10:17 +0000512 bool CycleHasInsts = false;
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000513
Dan Gohman343f0c02008-11-19 23:18:57 +0000514 // While Available queue is not empty, grab the node with the highest
515 // priority. If it is not ready put it back. Schedule the node.
Dan Gohman2836c282009-01-16 01:33:36 +0000516 std::vector<SUnit*> NotReady;
Dan Gohman343f0c02008-11-19 23:18:57 +0000517 Sequence.reserve(SUnits.size());
518 while (!AvailableQueue.empty() || !PendingQueue.empty()) {
519 // Check to see if any of the pending instructions are ready to issue. If
520 // so, add them to the available queue.
Dan Gohman3f237442008-12-16 03:25:46 +0000521 unsigned MinDepth = ~0u;
Dan Gohman343f0c02008-11-19 23:18:57 +0000522 for (unsigned i = 0, e = PendingQueue.size(); i != e; ++i) {
David Goodwin557bbe62009-11-20 19:32:48 +0000523 if (PendingQueue[i]->getDepth() <= CurCycle) {
Dan Gohman343f0c02008-11-19 23:18:57 +0000524 AvailableQueue.push(PendingQueue[i]);
525 PendingQueue[i]->isAvailable = true;
526 PendingQueue[i] = PendingQueue.back();
527 PendingQueue.pop_back();
528 --i; --e;
David Goodwin557bbe62009-11-20 19:32:48 +0000529 } else if (PendingQueue[i]->getDepth() < MinDepth)
530 MinDepth = PendingQueue[i]->getDepth();
Dan Gohman343f0c02008-11-19 23:18:57 +0000531 }
David Goodwinc93d8372009-08-11 17:35:23 +0000532
Andrew Trick2da8bc82010-12-24 05:03:26 +0000533 DEBUG(dbgs() << "\n*** Examining Available\n"; AvailableQueue.dump(this));
David Goodwinc93d8372009-08-11 17:35:23 +0000534
Stephen Hines36b56882014-04-23 16:57:46 -0700535 SUnit *FoundSUnit = 0, *NotPreferredSUnit = 0;
Dan Gohman2836c282009-01-16 01:33:36 +0000536 bool HasNoopHazards = false;
537 while (!AvailableQueue.empty()) {
538 SUnit *CurSUnit = AvailableQueue.pop();
539
540 ScheduleHazardRecognizer::HazardType HT =
Andrew Trick2da8bc82010-12-24 05:03:26 +0000541 HazardRec->getHazardType(CurSUnit, 0/*no stalls*/);
Dan Gohman2836c282009-01-16 01:33:36 +0000542 if (HT == ScheduleHazardRecognizer::NoHazard) {
Stephen Hines36b56882014-04-23 16:57:46 -0700543 if (HazardRec->ShouldPreferAnother(CurSUnit)) {
544 if (!NotPreferredSUnit) {
545 // If this is the first non-preferred node for this cycle, then
546 // record it and continue searching for a preferred node. If this
547 // is not the first non-preferred node, then treat it as though
548 // there had been a hazard.
549 NotPreferredSUnit = CurSUnit;
550 continue;
551 }
552 } else {
553 FoundSUnit = CurSUnit;
554 break;
555 }
Dan Gohman2836c282009-01-16 01:33:36 +0000556 }
557
558 // Remember if this is a noop hazard.
559 HasNoopHazards |= HT == ScheduleHazardRecognizer::NoopHazard;
560
561 NotReady.push_back(CurSUnit);
562 }
563
Stephen Hines36b56882014-04-23 16:57:46 -0700564 // If we have a non-preferred node, push it back onto the available list.
565 // If we did not find a preferred node, then schedule this first
566 // non-preferred node.
567 if (NotPreferredSUnit) {
568 if (!FoundSUnit) {
569 DEBUG(dbgs() << "*** Will schedule a non-preferred instruction...\n");
570 FoundSUnit = NotPreferredSUnit;
571 } else {
572 AvailableQueue.push(NotPreferredSUnit);
573 }
574
575 NotPreferredSUnit = 0;
576 }
577
Dan Gohman2836c282009-01-16 01:33:36 +0000578 // Add the nodes that aren't ready back onto the available list.
579 if (!NotReady.empty()) {
580 AvailableQueue.push_all(NotReady);
581 NotReady.clear();
582 }
583
David Goodwin4de099d2009-11-03 20:57:50 +0000584 // If we found a node to schedule...
Dan Gohman343f0c02008-11-19 23:18:57 +0000585 if (FoundSUnit) {
Stephen Hines36b56882014-04-23 16:57:46 -0700586 // If we need to emit noops prior to this instruction, then do so.
587 unsigned NumPreNoops = HazardRec->PreEmitNoops(FoundSUnit);
588 for (unsigned i = 0; i != NumPreNoops; ++i)
589 emitNoop(CurCycle);
590
David Goodwin4de099d2009-11-03 20:57:50 +0000591 // ... schedule the node...
David Goodwin557bbe62009-11-20 19:32:48 +0000592 ScheduleNodeTopDown(FoundSUnit, CurCycle);
Dan Gohman2836c282009-01-16 01:33:36 +0000593 HazardRec->EmitInstruction(FoundSUnit);
Benjamin Kramerbe441c02009-09-06 12:10:17 +0000594 CycleHasInsts = true;
Andrew Trickcf9aa282011-06-01 03:27:56 +0000595 if (HazardRec->atIssueLimit()) {
596 DEBUG(dbgs() << "*** Max instructions per cycle " << CurCycle << '\n');
597 HazardRec->AdvanceCycle();
598 ++CurCycle;
599 CycleHasInsts = false;
600 }
Dan Gohman2836c282009-01-16 01:33:36 +0000601 } else {
Benjamin Kramerbe441c02009-09-06 12:10:17 +0000602 if (CycleHasInsts) {
David Greenee1b21292010-01-05 01:26:01 +0000603 DEBUG(dbgs() << "*** Finished cycle " << CurCycle << '\n');
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000604 HazardRec->AdvanceCycle();
605 } else if (!HasNoopHazards) {
606 // Otherwise, we have a pipeline stall, but no other problem,
607 // just advance the current cycle and try again.
David Greenee1b21292010-01-05 01:26:01 +0000608 DEBUG(dbgs() << "*** Stall in cycle " << CurCycle << '\n');
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000609 HazardRec->AdvanceCycle();
David Goodwin557bbe62009-11-20 19:32:48 +0000610 ++NumStalls;
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000611 } else {
612 // Otherwise, we have no instructions to issue and we have instructions
613 // that will fault if we don't do this right. This is the case for
614 // processors without pipeline interlocks and other cases.
Stephen Hines36b56882014-04-23 16:57:46 -0700615 emitNoop(CurCycle);
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000616 }
617
Dan Gohman2836c282009-01-16 01:33:36 +0000618 ++CurCycle;
Benjamin Kramerbe441c02009-09-06 12:10:17 +0000619 CycleHasInsts = false;
Dan Gohman343f0c02008-11-19 23:18:57 +0000620 }
621 }
622
623#ifndef NDEBUG
Andrew Trick4c727202012-03-07 05:21:36 +0000624 unsigned ScheduledNodes = VerifyScheduledDAG(/*isBottomUp=*/false);
625 unsigned Noops = 0;
626 for (unsigned i = 0, e = Sequence.size(); i != e; ++i)
627 if (!Sequence[i])
628 ++Noops;
629 assert(Sequence.size() - Noops == ScheduledNodes &&
630 "The number of nodes scheduled doesn't match the expected number!");
631#endif // NDEBUG
Dan Gohman343f0c02008-11-19 23:18:57 +0000632}
Andrew Trick84b454d2012-03-07 05:21:44 +0000633
634// EmitSchedule - Emit the machine code in scheduled order.
635void SchedulePostRATDList::EmitSchedule() {
Andrew Trick68675c62012-03-09 04:29:02 +0000636 RegionBegin = RegionEnd;
Andrew Trick84b454d2012-03-07 05:21:44 +0000637
638 // If first instruction was a DBG_VALUE then put it back.
639 if (FirstDbgValue)
Andrew Trick68675c62012-03-09 04:29:02 +0000640 BB->splice(RegionEnd, BB, FirstDbgValue);
Andrew Trick84b454d2012-03-07 05:21:44 +0000641
642 // Then re-insert them according to the given schedule.
643 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
644 if (SUnit *SU = Sequence[i])
Andrew Trick68675c62012-03-09 04:29:02 +0000645 BB->splice(RegionEnd, BB, SU->getInstr());
Andrew Trick84b454d2012-03-07 05:21:44 +0000646 else
647 // Null SUnit* is a noop.
Andrew Trick68675c62012-03-09 04:29:02 +0000648 TII->insertNoop(*BB, RegionEnd);
Andrew Trick84b454d2012-03-07 05:21:44 +0000649
650 // Update the Begin iterator, as the first instruction in the block
651 // may have been scheduled later.
652 if (i == 0)
Stephen Hines36b56882014-04-23 16:57:46 -0700653 RegionBegin = std::prev(RegionEnd);
Andrew Trick84b454d2012-03-07 05:21:44 +0000654 }
655
656 // Reinsert any remaining debug_values.
657 for (std::vector<std::pair<MachineInstr *, MachineInstr *> >::iterator
658 DI = DbgValues.end(), DE = DbgValues.begin(); DI != DE; --DI) {
Stephen Hines36b56882014-04-23 16:57:46 -0700659 std::pair<MachineInstr *, MachineInstr *> P = *std::prev(DI);
Andrew Trick84b454d2012-03-07 05:21:44 +0000660 MachineInstr *DbgValue = P.first;
661 MachineBasicBlock::iterator OrigPrivMI = P.second;
662 BB->splice(++OrigPrivMI, BB, DbgValue);
663 }
664 DbgValues.clear();
665 FirstDbgValue = NULL;
666}