blob: 649b7515517e1c875e210a89d8242d3349f0d4e3 [file] [log] [blame]
Dale Johannesen4dc35db2007-07-13 17:31:29 +00001//===----- SchedulePostRAList.cpp - list scheduler ------------------------===//
Dale Johannesen2182f062007-07-13 17:13:54 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Johannesen2182f062007-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 Carruthed0881b2012-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 Gohman60cb69e2008-11-19 23:18:57 +000029#include "llvm/CodeGen/LatencyPriorityQueue.h"
Dan Gohmandddc1ac2008-12-16 03:25:46 +000030#include "llvm/CodeGen/MachineDominators.h"
David Goodwinbe3039e2009-10-01 19:45:32 +000031#include "llvm/CodeGen/MachineFrameInfo.h"
Dale Johannesen2182f062007-07-13 17:13:54 +000032#include "llvm/CodeGen/MachineFunctionPass.h"
Dan Gohmandddc1ac2008-12-16 03:25:46 +000033#include "llvm/CodeGen/MachineLoopInfo.h"
Dan Gohmanad2134d2008-11-25 00:52:40 +000034#include "llvm/CodeGen/MachineRegisterInfo.h"
Andrew Trick05ff4662012-06-06 20:29:31 +000035#include "llvm/CodeGen/RegisterClassInfo.h"
Andrew Trick9a0c5832012-03-07 23:01:06 +000036#include "llvm/CodeGen/ScheduleDAGInstrs.h"
Dan Gohmanceac7c32009-01-16 01:33:36 +000037#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000038#include "llvm/CodeGen/SchedulerRegistry.h"
David Goodwine056d102009-10-26 22:31:16 +000039#include "llvm/Support/CommandLine.h"
Dale Johannesen2182f062007-07-13 17:13:54 +000040#include "llvm/Support/Debug.h"
Torok Edwin56d06592009-07-11 20:10:48 +000041#include "llvm/Support/ErrorHandling.h"
David Goodwinf20236a2009-08-11 01:44:26 +000042#include "llvm/Support/raw_ostream.h"
Chandler Carruthed0881b2012-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 Johannesen2182f062007-07-13 17:13:54 +000048using namespace llvm;
49
Dan Gohmanceac7c32009-01-16 01:33:36 +000050STATISTIC(NumNoops, "Number of noops inserted");
Dan Gohman60cb69e2008-11-19 23:18:57 +000051STATISTIC(NumStalls, "Number of pipeline stalls");
David Goodwin83704852009-10-26 16:59:04 +000052STATISTIC(NumFixedAnti, "Number of fixed anti-dependencies");
Dan Gohman60cb69e2008-11-19 23:18:57 +000053
David Goodwin9a051a52009-10-01 21:46:35 +000054// Post-RA scheduling is enabled with
Evan Cheng0d639a22011-07-01 21:01:15 +000055// TargetSubtargetInfo.enablePostRAScheduler(). This flag can be used to
David Goodwin9a051a52009-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 Goodwin1cc6dd92009-10-01 22:19:57 +000060 cl::init(false), cl::Hidden);
David Goodwin83704852009-10-26 16:59:04 +000061static cl::opt<std::string>
Dan Gohmanad2134d2008-11-25 00:52:40 +000062EnableAntiDepBreaking("break-anti-dependencies",
David Goodwin83704852009-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 Gohmanceac7c32009-01-16 01:33:36 +000066
David Goodwin7f651692009-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 Goodwin661ea982009-10-26 19:41:00 +000077AntiDepBreaker::~AntiDepBreaker() { }
78
Dale Johannesen2182f062007-07-13 17:13:54 +000079namespace {
Nick Lewycky02d5f772009-10-25 06:33:48 +000080 class PostRAScheduler : public MachineFunctionPass {
Evan Cheng2d51c7c2010-06-18 23:09:54 +000081 const TargetInstrInfo *TII;
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +000082 RegisterClassInfo RegClassInfo;
Dan Gohman87b02d52009-10-09 23:27:56 +000083
Dale Johannesen2182f062007-07-13 17:13:54 +000084 public:
85 static char ID;
Andrew Trickdf7e3762012-02-08 21:22:53 +000086 PostRAScheduler() : MachineFunctionPass(ID) {}
Dan Gohmanad2134d2008-11-25 00:52:40 +000087
Craig Topper4584cd52014-03-07 09:26:03 +000088 void getAnalysisUsage(AnalysisUsage &AU) const override {
Dan Gohman04023152009-07-31 23:37:33 +000089 AU.setPreservesCFG();
Dan Gohman87b02d52009-10-09 23:27:56 +000090 AU.addRequired<AliasAnalysis>();
Andrew Trickdf7e3762012-02-08 21:22:53 +000091 AU.addRequired<TargetPassConfig>();
Dan Gohmandddc1ac2008-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
Craig Topper4584cd52014-03-07 09:26:03 +000099 bool runOnMachineFunction(MachineFunction &Fn) override;
Dale Johannesen2182f062007-07-13 17:13:54 +0000100 };
Dan Gohman60cb69e2008-11-19 23:18:57 +0000101 char PostRAScheduler::ID = 0;
102
Nick Lewycky02d5f772009-10-25 06:33:48 +0000103 class SchedulePostRATDList : public ScheduleDAGInstrs {
Dan Gohman60cb69e2008-11-19 23:18:57 +0000104 /// AvailableQueue - The priority queue to use for the available SUnits.
Dan Gohman682a2d12009-10-21 01:44:44 +0000105 ///
Dan Gohman60cb69e2008-11-19 23:18:57 +0000106 LatencyPriorityQueue AvailableQueue;
Jim Grosbachd772bde2010-05-14 21:19:48 +0000107
Dan Gohman60cb69e2008-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 Gohmanceac7c32009-01-16 01:33:36 +0000114 /// HazardRec - The hazard recognizer to use.
115 ScheduleHazardRecognizer *HazardRec;
116
David Goodwin83704852009-10-26 16:59:04 +0000117 /// AntiDepBreak - Anti-dependence breaking object, or NULL if none
118 AntiDepBreaker *AntiDepBreak;
119
Dan Gohman87b02d52009-10-09 23:27:56 +0000120 /// AA - AliasAnalysis for making memory reference queries.
121 AliasAnalysis *AA;
122
Andrew Trick60cf03e2012-03-07 05:21:52 +0000123 /// The schedule. Null SUnit*'s represent noop instructions.
124 std::vector<SUnit*> Sequence;
125
Andrew Tricka53e1012013-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 Gohmanad2134d2008-11-25 00:52:40 +0000132 public:
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000133 SchedulePostRATDList(
134 MachineFunction &MF, MachineLoopInfo &MLI, MachineDominatorTree &MDT,
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +0000135 AliasAnalysis *AA, const RegisterClassInfo&,
Evan Cheng0d639a22011-07-01 21:01:15 +0000136 TargetSubtargetInfo::AntiDepBreakMode AntiDepMode,
Craig Topper760b1342012-02-22 05:59:10 +0000137 SmallVectorImpl<const TargetRegisterClass*> &CriticalPathRCs);
Dan Gohmanceac7c32009-01-16 01:33:36 +0000138
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000139 ~SchedulePostRATDList();
Dan Gohman60cb69e2008-11-19 23:18:57 +0000140
Andrew Trick52226d42012-03-07 23:00:49 +0000141 /// startBlock - Initialize register live-range state for scheduling in
Dan Gohmanb9543432009-02-10 23:27:53 +0000142 /// this block.
143 ///
Craig Topper4584cd52014-03-07 09:26:03 +0000144 void startBlock(MachineBasicBlock *BB) override;
Dan Gohmanb9543432009-02-10 23:27:53 +0000145
Andrew Tricka53e1012013-08-23 17:48:33 +0000146 // Set the index of RegionEnd within the current BB.
147 void setEndIndex(unsigned EndIdx) { EndIndex = EndIdx; }
148
Andrew Trick60cf03e2012-03-07 05:21:52 +0000149 /// Initialize the scheduler state for the next scheduling region.
Craig Topper4584cd52014-03-07 09:26:03 +0000150 void enterRegion(MachineBasicBlock *bb,
151 MachineBasicBlock::iterator begin,
152 MachineBasicBlock::iterator end,
153 unsigned regioninstrs) override;
Andrew Trick60cf03e2012-03-07 05:21:52 +0000154
155 /// Notify that the scheduler has finished scheduling the current region.
Craig Topper4584cd52014-03-07 09:26:03 +0000156 void exitRegion() override;
Andrew Trick60cf03e2012-03-07 05:21:52 +0000157
Dan Gohmanb9543432009-02-10 23:27:53 +0000158 /// Schedule - Schedule the instruction range using list scheduling.
159 ///
Craig Topper4584cd52014-03-07 09:26:03 +0000160 void schedule() override;
Jim Grosbachd772bde2010-05-14 21:19:48 +0000161
Andrew Tricke932bb72012-03-07 05:21:44 +0000162 void EmitSchedule();
163
Dan Gohman682a2d12009-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 Trick52226d42012-03-07 23:00:49 +0000169 /// finishBlock - Clean up register live-range state.
Dan Gohman682a2d12009-10-21 01:44:44 +0000170 ///
Craig Topper4584cd52014-03-07 09:26:03 +0000171 void finishBlock() override;
Dan Gohman682a2d12009-10-21 01:44:44 +0000172
Dan Gohman60cb69e2008-11-19 23:18:57 +0000173 private:
David Goodwin80a03cc2009-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();
David Goodwin6c08cfc2009-09-03 22:15:25 +0000178 void StartBlockForKills(MachineBasicBlock *BB);
Jim Grosbachd772bde2010-05-14 21:19:48 +0000179
Andrew Trickedee68c2012-03-07 05:21:40 +0000180 void dumpSchedule() const;
Hal Finkel4fd3b1d2013-12-11 22:33:43 +0000181 void emitNoop(unsigned CurCycle);
Dan Gohman60cb69e2008-11-19 23:18:57 +0000182 };
Dale Johannesen2182f062007-07-13 17:13:54 +0000183}
184
Andrew Trick1fa5bcb2012-02-08 21:23:13 +0000185char &llvm::PostRASchedulerID = PostRAScheduler::ID;
186
187INITIALIZE_PASS(PostRAScheduler, "post-RA-sched",
188 "Post RA top-down list latency scheduler", false, false)
189
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000190SchedulePostRATDList::SchedulePostRATDList(
191 MachineFunction &MF, MachineLoopInfo &MLI, MachineDominatorTree &MDT,
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +0000192 AliasAnalysis *AA, const RegisterClassInfo &RCI,
Evan Cheng0d639a22011-07-01 21:01:15 +0000193 TargetSubtargetInfo::AntiDepBreakMode AntiDepMode,
Craig Topper760b1342012-02-22 05:59:10 +0000194 SmallVectorImpl<const TargetRegisterClass*> &CriticalPathRCs)
Andrew Trick6b104f82013-12-28 21:56:55 +0000195 : ScheduleDAGInstrs(MF, MLI, MDT, /*IsPostRA=*/true), AA(AA), EndIndex(0) {
196
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000197 const TargetMachine &TM = MF.getTarget();
198 const InstrItineraryData *InstrItins = TM.getInstrItineraryData();
199 HazardRec =
200 TM.getInstrInfo()->CreateTargetPostRAHazardRecognizer(InstrItins, this);
Preston Gurd9a091472012-04-23 21:39:35 +0000201
202 assert((AntiDepMode == TargetSubtargetInfo::ANTIDEP_NONE ||
203 MRI.tracksLiveness()) &&
204 "Live-ins must be accurate for anti-dependency breaking");
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000205 AntiDepBreak =
Evan Cheng0d639a22011-07-01 21:01:15 +0000206 ((AntiDepMode == TargetSubtargetInfo::ANTIDEP_ALL) ?
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +0000207 (AntiDepBreaker *)new AggressiveAntiDepBreaker(MF, RCI, CriticalPathRCs) :
Evan Cheng0d639a22011-07-01 21:01:15 +0000208 ((AntiDepMode == TargetSubtargetInfo::ANTIDEP_CRITICAL) ?
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +0000209 (AntiDepBreaker *)new CriticalAntiDepBreaker(MF, RCI) : NULL));
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000210}
211
212SchedulePostRATDList::~SchedulePostRATDList() {
213 delete HazardRec;
214 delete AntiDepBreak;
215}
216
Andrew Trick60cf03e2012-03-07 05:21:52 +0000217/// Initialize state associated with the next scheduling region.
218void SchedulePostRATDList::enterRegion(MachineBasicBlock *bb,
219 MachineBasicBlock::iterator begin,
220 MachineBasicBlock::iterator end,
Andrew Tricka53e1012013-08-23 17:48:33 +0000221 unsigned regioninstrs) {
222 ScheduleDAGInstrs::enterRegion(bb, begin, end, regioninstrs);
Andrew Trick60cf03e2012-03-07 05:21:52 +0000223 Sequence.clear();
224}
225
226/// Print the schedule before exiting the region.
227void SchedulePostRATDList::exitRegion() {
228 DEBUG({
229 dbgs() << "*** Final schedule ***\n";
230 dumpSchedule();
231 dbgs() << '\n';
232 });
233 ScheduleDAGInstrs::exitRegion();
234}
235
Manman Ren19f49ac2012-09-11 22:23:19 +0000236#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Andrew Trickedee68c2012-03-07 05:21:40 +0000237/// dumpSchedule - dump the scheduled Sequence.
238void SchedulePostRATDList::dumpSchedule() const {
239 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
240 if (SUnit *SU = Sequence[i])
241 SU->dump(this);
242 else
243 dbgs() << "**** NOOP ****\n";
244 }
245}
Manman Ren742534c2012-09-06 19:06:06 +0000246#endif
Andrew Trickedee68c2012-03-07 05:21:40 +0000247
Dan Gohman60cb69e2008-11-19 23:18:57 +0000248bool PostRAScheduler::runOnMachineFunction(MachineFunction &Fn) {
Evan Cheng2d51c7c2010-06-18 23:09:54 +0000249 TII = Fn.getTarget().getInstrInfo();
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000250 MachineLoopInfo &MLI = getAnalysis<MachineLoopInfo>();
251 MachineDominatorTree &MDT = getAnalysis<MachineDominatorTree>();
252 AliasAnalysis *AA = &getAnalysis<AliasAnalysis>();
Andrew Trickdf7e3762012-02-08 21:22:53 +0000253 TargetPassConfig *PassConfig = &getAnalysis<TargetPassConfig>();
254
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +0000255 RegClassInfo.runOnMachineFunction(Fn);
Dan Gohman26e9b892009-10-10 00:15:38 +0000256
David Goodwin9a051a52009-10-01 21:46:35 +0000257 // Check for explicit enable/disable of post-ra scheduling.
Evan Cheng7fae11b2011-12-14 02:11:42 +0000258 TargetSubtargetInfo::AntiDepBreakMode AntiDepMode =
259 TargetSubtargetInfo::ANTIDEP_NONE;
Craig Topper760b1342012-02-22 05:59:10 +0000260 SmallVector<const TargetRegisterClass*, 4> CriticalPathRCs;
David Goodwin9a051a52009-10-01 21:46:35 +0000261 if (EnablePostRAScheduler.getPosition() > 0) {
262 if (!EnablePostRAScheduler)
Evan Cheng8b614762009-10-16 06:10:34 +0000263 return false;
David Goodwin9a051a52009-10-01 21:46:35 +0000264 } else {
Evan Cheng8b614762009-10-16 06:10:34 +0000265 // Check that post-RA scheduling is enabled for this target.
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000266 // This may upgrade the AntiDepMode.
Evan Cheng0d639a22011-07-01 21:01:15 +0000267 const TargetSubtargetInfo &ST = Fn.getTarget().getSubtarget<TargetSubtargetInfo>();
Andrew Trickdf7e3762012-02-08 21:22:53 +0000268 if (!ST.enablePostRAScheduler(PassConfig->getOptLevel(), AntiDepMode,
269 CriticalPathRCs))
Evan Cheng8b614762009-10-16 06:10:34 +0000270 return false;
David Goodwin9a051a52009-10-01 21:46:35 +0000271 }
David Goodwin17199b52009-09-30 00:10:16 +0000272
David Goodwin02ad4cb2009-10-22 23:19:17 +0000273 // Check for antidep breaking override...
274 if (EnableAntiDepBreaking.getPosition() > 0) {
Evan Cheng0d639a22011-07-01 21:01:15 +0000275 AntiDepMode = (EnableAntiDepBreaking == "all")
276 ? TargetSubtargetInfo::ANTIDEP_ALL
277 : ((EnableAntiDepBreaking == "critical")
278 ? TargetSubtargetInfo::ANTIDEP_CRITICAL
279 : TargetSubtargetInfo::ANTIDEP_NONE);
David Goodwin02ad4cb2009-10-22 23:19:17 +0000280 }
281
David Greeneaa8ce382010-01-05 01:26:01 +0000282 DEBUG(dbgs() << "PostRAScheduler\n");
Dale Johannesen2182f062007-07-13 17:13:54 +0000283
Jakob Stoklund Olesen4f5f84c2011-06-16 21:56:21 +0000284 SchedulePostRATDList Scheduler(Fn, MLI, MDT, AA, RegClassInfo, AntiDepMode,
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000285 CriticalPathRCs);
Dan Gohman619ef482009-01-15 19:20:50 +0000286
Dale Johannesen2182f062007-07-13 17:13:54 +0000287 // Loop over all of the basic blocks
288 for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end();
Dan Gohman60cb69e2008-11-19 23:18:57 +0000289 MBB != MBBe; ++MBB) {
David Goodwin7f651692009-09-01 18:34:03 +0000290#ifndef NDEBUG
291 // If DebugDiv > 0 then only schedule MBB with (ID % DebugDiv) == DebugMod
292 if (DebugDiv > 0) {
293 static int bbcnt = 0;
294 if (bbcnt++ % DebugDiv != DebugMod)
295 continue;
Craig Toppera538d832012-08-22 06:07:19 +0000296 dbgs() << "*** DEBUG scheduling " << Fn.getName()
Benjamin Kramer1f97a5a2011-11-15 16:27:03 +0000297 << ":BB#" << MBB->getNumber() << " ***\n";
David Goodwin7f651692009-09-01 18:34:03 +0000298 }
299#endif
300
Dan Gohmanb9543432009-02-10 23:27:53 +0000301 // Initialize register live-range state for scheduling in this block.
Andrew Trick52226d42012-03-07 23:00:49 +0000302 Scheduler.startBlock(MBB);
Dan Gohmanb9543432009-02-10 23:27:53 +0000303
Dan Gohman5f8a2592009-01-16 22:10:20 +0000304 // Schedule each sequence of instructions not interrupted by a label
305 // or anything else that effectively needs to shut down scheduling.
Dan Gohmanb9543432009-02-10 23:27:53 +0000306 MachineBasicBlock::iterator Current = MBB->end();
Dan Gohmandfaf6462009-02-11 04:27:20 +0000307 unsigned Count = MBB->size(), CurrentCount = Count;
Dan Gohmanb9543432009-02-10 23:27:53 +0000308 for (MachineBasicBlock::iterator I = Current; I != MBB->begin(); ) {
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000309 MachineInstr *MI = std::prev(I);
Andrew Tricka53e1012013-08-23 17:48:33 +0000310 --Count;
Jakob Stoklund Olesena793a592012-02-23 17:54:21 +0000311 // Calls are not scheduling boundaries before register allocation, but
312 // post-ra we don't gain anything by scheduling across calls since we
313 // don't need to worry about register pressure.
314 if (MI->isCall() || TII->isSchedulingBoundary(MI, MBB, Fn)) {
Andrew Tricka53e1012013-08-23 17:48:33 +0000315 Scheduler.enterRegion(MBB, I, Current, CurrentCount - Count);
316 Scheduler.setEndIndex(CurrentCount);
Andrew Trick52226d42012-03-07 23:00:49 +0000317 Scheduler.schedule();
Andrew Trick60cf03e2012-03-07 05:21:52 +0000318 Scheduler.exitRegion();
Dan Gohman25c16532010-05-01 00:01:06 +0000319 Scheduler.EmitSchedule();
Dan Gohmanb9543432009-02-10 23:27:53 +0000320 Current = MI;
Andrew Tricka53e1012013-08-23 17:48:33 +0000321 CurrentCount = Count;
Dan Gohman64613ac2009-03-10 18:10:43 +0000322 Scheduler.Observe(MI, CurrentCount);
Dan Gohman5f8a2592009-01-16 22:10:20 +0000323 }
Dan Gohmanb9543432009-02-10 23:27:53 +0000324 I = MI;
Evan Cheng7fae11b2011-12-14 02:11:42 +0000325 if (MI->isBundle())
326 Count -= MI->getBundleSize();
Dan Gohmand5643532009-02-03 18:57:45 +0000327 }
Dan Gohmandfaf6462009-02-11 04:27:20 +0000328 assert(Count == 0 && "Instruction count mismatch!");
Duncan Sandsbe69d602009-03-11 09:04:34 +0000329 assert((MBB->begin() == Current || CurrentCount != 0) &&
Dan Gohman64613ac2009-03-10 18:10:43 +0000330 "Instruction count mismatch!");
Andrew Trick60cf03e2012-03-07 05:21:52 +0000331 Scheduler.enterRegion(MBB, MBB->begin(), Current, CurrentCount);
Andrew Tricka53e1012013-08-23 17:48:33 +0000332 Scheduler.setEndIndex(CurrentCount);
Andrew Trick52226d42012-03-07 23:00:49 +0000333 Scheduler.schedule();
Andrew Trick60cf03e2012-03-07 05:21:52 +0000334 Scheduler.exitRegion();
Dan Gohman25c16532010-05-01 00:01:06 +0000335 Scheduler.EmitSchedule();
Dan Gohmanb9543432009-02-10 23:27:53 +0000336
337 // Clean up register live-range state.
Andrew Trick52226d42012-03-07 23:00:49 +0000338 Scheduler.finishBlock();
David Goodwinae6bc822009-08-25 17:03:05 +0000339
David Goodwin6c08cfc2009-09-03 22:15:25 +0000340 // Update register kills
Andrew Trick6b104f82013-12-28 21:56:55 +0000341 Scheduler.fixupKills(MBB);
Dan Gohman60cb69e2008-11-19 23:18:57 +0000342 }
Dale Johannesen2182f062007-07-13 17:13:54 +0000343
344 return true;
345}
Jim Grosbachd772bde2010-05-14 21:19:48 +0000346
Dan Gohmanb9543432009-02-10 23:27:53 +0000347/// StartBlock - Initialize register live-range state for scheduling in
348/// this block.
Dan Gohmanad2134d2008-11-25 00:52:40 +0000349///
Andrew Trick52226d42012-03-07 23:00:49 +0000350void SchedulePostRATDList::startBlock(MachineBasicBlock *BB) {
Dan Gohmanb9543432009-02-10 23:27:53 +0000351 // Call the superclass.
Andrew Trick52226d42012-03-07 23:00:49 +0000352 ScheduleDAGInstrs::startBlock(BB);
Dan Gohmanad2134d2008-11-25 00:52:40 +0000353
David Goodwin83704852009-10-26 16:59:04 +0000354 // Reset the hazard recognizer and anti-dep breaker.
David Goodwin6021b4d2009-08-10 15:55:25 +0000355 HazardRec->Reset();
David Goodwin83704852009-10-26 16:59:04 +0000356 if (AntiDepBreak != NULL)
357 AntiDepBreak->StartBlock(BB);
Dan Gohmanb9543432009-02-10 23:27:53 +0000358}
359
360/// Schedule - Schedule the instruction range using list scheduling.
361///
Andrew Trick52226d42012-03-07 23:00:49 +0000362void SchedulePostRATDList::schedule() {
Dan Gohmanb9543432009-02-10 23:27:53 +0000363 // Build the scheduling graph.
Andrew Trick52226d42012-03-07 23:00:49 +0000364 buildSchedGraph(AA);
Dan Gohmanb9543432009-02-10 23:27:53 +0000365
David Goodwin83704852009-10-26 16:59:04 +0000366 if (AntiDepBreak != NULL) {
Jim Grosbachd772bde2010-05-14 21:19:48 +0000367 unsigned Broken =
Andrew Trick8c207e42012-03-09 04:29:02 +0000368 AntiDepBreak->BreakAntiDependencies(SUnits, RegionBegin, RegionEnd,
369 EndIndex, DbgValues);
Jim Grosbachd772bde2010-05-14 21:19:48 +0000370
David Goodwin80a03cc2009-11-20 19:32:48 +0000371 if (Broken != 0) {
Dan Gohmanb9543432009-02-10 23:27:53 +0000372 // We made changes. Update the dependency graph.
373 // Theoretically we could update the graph in place:
374 // When a live range is changed to use a different register, remove
375 // the def's anti-dependence *and* output-dependence edges due to
376 // that register, and add new anti-dependence and output-dependence
377 // edges based on the next live range of the register.
Andrew Trick60cf03e2012-03-07 05:21:52 +0000378 ScheduleDAG::clearDAG();
Andrew Trick52226d42012-03-07 23:00:49 +0000379 buildSchedGraph(AA);
Jim Grosbachd772bde2010-05-14 21:19:48 +0000380
David Goodwin83704852009-10-26 16:59:04 +0000381 NumFixedAnti += Broken;
Dan Gohmanb9543432009-02-10 23:27:53 +0000382 }
383 }
384
David Greeneaa8ce382010-01-05 01:26:01 +0000385 DEBUG(dbgs() << "********** List Scheduling **********\n");
David Goodwin6021b4d2009-08-10 15:55:25 +0000386 DEBUG(for (unsigned su = 0, e = SUnits.size(); su != e; ++su)
387 SUnits[su].dumpAll(this));
388
Dan Gohmanb9543432009-02-10 23:27:53 +0000389 AvailableQueue.initNodes(SUnits);
David Goodwin80a03cc2009-11-20 19:32:48 +0000390 ListScheduleTopDown();
Dan Gohmanb9543432009-02-10 23:27:53 +0000391 AvailableQueue.releaseState();
392}
393
394/// Observe - Update liveness information to account for the current
395/// instruction, which will not be scheduled.
396///
Dan Gohmandfaf6462009-02-11 04:27:20 +0000397void SchedulePostRATDList::Observe(MachineInstr *MI, unsigned Count) {
David Goodwin83704852009-10-26 16:59:04 +0000398 if (AntiDepBreak != NULL)
Andrew Tricka316faa2012-03-07 23:00:52 +0000399 AntiDepBreak->Observe(MI, Count, EndIndex);
Dan Gohmanb9543432009-02-10 23:27:53 +0000400}
401
402/// FinishBlock - Clean up register live-range state.
403///
Andrew Trick52226d42012-03-07 23:00:49 +0000404void SchedulePostRATDList::finishBlock() {
David Goodwin83704852009-10-26 16:59:04 +0000405 if (AntiDepBreak != NULL)
406 AntiDepBreak->FinishBlock();
Dan Gohmanb9543432009-02-10 23:27:53 +0000407
408 // Call the superclass.
Andrew Trick52226d42012-03-07 23:00:49 +0000409 ScheduleDAGInstrs::finishBlock();
Dan Gohmanb9543432009-02-10 23:27:53 +0000410}
411
Dan Gohman60cb69e2008-11-19 23:18:57 +0000412//===----------------------------------------------------------------------===//
413// Top-Down Scheduling
414//===----------------------------------------------------------------------===//
415
416/// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to
Andrew Trickf1ff84c2012-11-12 19:28:57 +0000417/// the PendingQueue if the count reaches zero.
David Goodwin80a03cc2009-11-20 19:32:48 +0000418void SchedulePostRATDList::ReleaseSucc(SUnit *SU, SDep *SuccEdge) {
Dan Gohman2d170892008-12-09 22:54:47 +0000419 SUnit *SuccSU = SuccEdge->getSUnit();
Reid Kleckner8ff5c192009-09-30 20:15:38 +0000420
Andrew Trick4b1f9e32012-11-13 02:35:06 +0000421 if (SuccEdge->isWeak()) {
Andrew Trickf1ff84c2012-11-12 19:28:57 +0000422 --SuccSU->WeakPredsLeft;
423 return;
424 }
Dan Gohman60cb69e2008-11-19 23:18:57 +0000425#ifndef NDEBUG
Reid Kleckner8ff5c192009-09-30 20:15:38 +0000426 if (SuccSU->NumPredsLeft == 0) {
David Greeneaa8ce382010-01-05 01:26:01 +0000427 dbgs() << "*** Scheduling failed! ***\n";
Dan Gohman60cb69e2008-11-19 23:18:57 +0000428 SuccSU->dump(this);
David Greeneaa8ce382010-01-05 01:26:01 +0000429 dbgs() << " has been released too many times!\n";
Torok Edwinfbcc6632009-07-14 16:55:14 +0000430 llvm_unreachable(0);
Dan Gohman60cb69e2008-11-19 23:18:57 +0000431 }
432#endif
Reid Kleckner8ff5c192009-09-30 20:15:38 +0000433 --SuccSU->NumPredsLeft;
434
Andrew Trick84f9ad92011-05-06 18:14:32 +0000435 // Standard scheduler algorithms will recompute the depth of the successor
Andrew Trickaab77fe2011-05-06 17:09:08 +0000436 // here as such:
437 // SuccSU->setDepthToAtLeast(SU->getDepth() + SuccEdge->getLatency());
438 //
439 // However, we lazily compute node depth instead. Note that
440 // ScheduleNodeTopDown has already updated the depth of this node which causes
441 // all descendents to be marked dirty. Setting the successor depth explicitly
442 // here would cause depth to be recomputed for all its ancestors. If the
443 // successor is not yet ready (because of a transitively redundant edge) then
444 // this causes depth computation to be quadratic in the size of the DAG.
Jim Grosbachd772bde2010-05-14 21:19:48 +0000445
Dan Gohmanb9543432009-02-10 23:27:53 +0000446 // If all the node's predecessors are scheduled, this node is ready
447 // to be scheduled. Ignore the special ExitSU node.
448 if (SuccSU->NumPredsLeft == 0 && SuccSU != &ExitSU)
Dan Gohman60cb69e2008-11-19 23:18:57 +0000449 PendingQueue.push_back(SuccSU);
Dan Gohmanb9543432009-02-10 23:27:53 +0000450}
451
452/// ReleaseSuccessors - Call ReleaseSucc on each of SU's successors.
David Goodwin80a03cc2009-11-20 19:32:48 +0000453void SchedulePostRATDList::ReleaseSuccessors(SUnit *SU) {
Dan Gohmanb9543432009-02-10 23:27:53 +0000454 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
David Goodwin8501dbbe2009-11-03 20:57:50 +0000455 I != E; ++I) {
David Goodwin80a03cc2009-11-20 19:32:48 +0000456 ReleaseSucc(SU, &*I);
David Goodwin8501dbbe2009-11-03 20:57:50 +0000457 }
Dan Gohman60cb69e2008-11-19 23:18:57 +0000458}
459
460/// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending
461/// count of its successors. If a successor pending count is zero, add it to
462/// the Available queue.
David Goodwin80a03cc2009-11-20 19:32:48 +0000463void SchedulePostRATDList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) {
David Greeneaa8ce382010-01-05 01:26:01 +0000464 DEBUG(dbgs() << "*** Scheduling [" << CurCycle << "]: ");
Dan Gohman60cb69e2008-11-19 23:18:57 +0000465 DEBUG(SU->dump(this));
Jim Grosbachd772bde2010-05-14 21:19:48 +0000466
Dan Gohman60cb69e2008-11-19 23:18:57 +0000467 Sequence.push_back(SU);
Jim Grosbachd772bde2010-05-14 21:19:48 +0000468 assert(CurCycle >= SU->getDepth() &&
David Goodwin8501dbbe2009-11-03 20:57:50 +0000469 "Node scheduled above its depth!");
David Goodwin80a03cc2009-11-20 19:32:48 +0000470 SU->setDepthToAtLeast(CurCycle);
Dan Gohman60cb69e2008-11-19 23:18:57 +0000471
David Goodwin80a03cc2009-11-20 19:32:48 +0000472 ReleaseSuccessors(SU);
Dan Gohman60cb69e2008-11-19 23:18:57 +0000473 SU->isScheduled = true;
Andrew Trick52226d42012-03-07 23:00:49 +0000474 AvailableQueue.scheduledNode(SU);
Dan Gohman60cb69e2008-11-19 23:18:57 +0000475}
476
Hal Finkel4fd3b1d2013-12-11 22:33:43 +0000477/// emitNoop - Add a noop to the current instruction sequence.
478void SchedulePostRATDList::emitNoop(unsigned CurCycle) {
479 DEBUG(dbgs() << "*** Emitting noop in cycle " << CurCycle << '\n');
480 HazardRec->EmitNoop();
481 Sequence.push_back(0); // NULL here means noop
482 ++NumNoops;
483}
484
Dan Gohman60cb69e2008-11-19 23:18:57 +0000485/// ListScheduleTopDown - The main loop of list scheduling for top-down
486/// schedulers.
David Goodwin80a03cc2009-11-20 19:32:48 +0000487void SchedulePostRATDList::ListScheduleTopDown() {
Dan Gohman60cb69e2008-11-19 23:18:57 +0000488 unsigned CurCycle = 0;
Jim Grosbachd772bde2010-05-14 21:19:48 +0000489
David Goodwin8501dbbe2009-11-03 20:57:50 +0000490 // We're scheduling top-down but we're visiting the regions in
491 // bottom-up order, so we don't know the hazards at the start of a
492 // region. So assume no hazards (this should usually be ok as most
493 // blocks are a single region).
494 HazardRec->Reset();
495
Dan Gohmanb9543432009-02-10 23:27:53 +0000496 // Release any successors of the special Entry node.
David Goodwin80a03cc2009-11-20 19:32:48 +0000497 ReleaseSuccessors(&EntrySU);
Dan Gohmanb9543432009-02-10 23:27:53 +0000498
David Goodwin80a03cc2009-11-20 19:32:48 +0000499 // Add all leaves to Available queue.
Dan Gohman60cb69e2008-11-19 23:18:57 +0000500 for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
501 // It is available if it has no predecessors.
Andrew Trickf1ff84c2012-11-12 19:28:57 +0000502 if (!SUnits[i].NumPredsLeft && !SUnits[i].isAvailable) {
Dan Gohman60cb69e2008-11-19 23:18:57 +0000503 AvailableQueue.push(&SUnits[i]);
504 SUnits[i].isAvailable = true;
505 }
506 }
Dan Gohmanb9543432009-02-10 23:27:53 +0000507
David Goodwin1f8c7a72009-08-12 21:47:46 +0000508 // In any cycle where we can't schedule any instructions, we must
509 // stall or emit a noop, depending on the target.
Benjamin Kramere3c9d232009-09-06 12:10:17 +0000510 bool CycleHasInsts = false;
David Goodwin1f8c7a72009-08-12 21:47:46 +0000511
Dan Gohman60cb69e2008-11-19 23:18:57 +0000512 // While Available queue is not empty, grab the node with the highest
513 // priority. If it is not ready put it back. Schedule the node.
Dan Gohmanceac7c32009-01-16 01:33:36 +0000514 std::vector<SUnit*> NotReady;
Dan Gohman60cb69e2008-11-19 23:18:57 +0000515 Sequence.reserve(SUnits.size());
516 while (!AvailableQueue.empty() || !PendingQueue.empty()) {
517 // Check to see if any of the pending instructions are ready to issue. If
518 // so, add them to the available queue.
Dan Gohmandddc1ac2008-12-16 03:25:46 +0000519 unsigned MinDepth = ~0u;
Dan Gohman60cb69e2008-11-19 23:18:57 +0000520 for (unsigned i = 0, e = PendingQueue.size(); i != e; ++i) {
David Goodwin80a03cc2009-11-20 19:32:48 +0000521 if (PendingQueue[i]->getDepth() <= CurCycle) {
Dan Gohman60cb69e2008-11-19 23:18:57 +0000522 AvailableQueue.push(PendingQueue[i]);
523 PendingQueue[i]->isAvailable = true;
524 PendingQueue[i] = PendingQueue.back();
525 PendingQueue.pop_back();
526 --i; --e;
David Goodwin80a03cc2009-11-20 19:32:48 +0000527 } else if (PendingQueue[i]->getDepth() < MinDepth)
528 MinDepth = PendingQueue[i]->getDepth();
Dan Gohman60cb69e2008-11-19 23:18:57 +0000529 }
David Goodwinebd694b2009-08-11 17:35:23 +0000530
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000531 DEBUG(dbgs() << "\n*** Examining Available\n"; AvailableQueue.dump(this));
David Goodwinebd694b2009-08-11 17:35:23 +0000532
Hal Finkel4fd3b1d2013-12-11 22:33:43 +0000533 SUnit *FoundSUnit = 0, *NotPreferredSUnit = 0;
Dan Gohmanceac7c32009-01-16 01:33:36 +0000534 bool HasNoopHazards = false;
535 while (!AvailableQueue.empty()) {
536 SUnit *CurSUnit = AvailableQueue.pop();
537
538 ScheduleHazardRecognizer::HazardType HT =
Andrew Trick10ffc2b2010-12-24 05:03:26 +0000539 HazardRec->getHazardType(CurSUnit, 0/*no stalls*/);
Dan Gohmanceac7c32009-01-16 01:33:36 +0000540 if (HT == ScheduleHazardRecognizer::NoHazard) {
Hal Finkel4fd3b1d2013-12-11 22:33:43 +0000541 if (HazardRec->ShouldPreferAnother(CurSUnit)) {
542 if (!NotPreferredSUnit) {
543 // If this is the first non-preferred node for this cycle, then
544 // record it and continue searching for a preferred node. If this
545 // is not the first non-preferred node, then treat it as though
546 // there had been a hazard.
547 NotPreferredSUnit = CurSUnit;
548 continue;
549 }
550 } else {
551 FoundSUnit = CurSUnit;
552 break;
553 }
Dan Gohmanceac7c32009-01-16 01:33:36 +0000554 }
555
556 // Remember if this is a noop hazard.
557 HasNoopHazards |= HT == ScheduleHazardRecognizer::NoopHazard;
558
559 NotReady.push_back(CurSUnit);
560 }
561
Hal Finkel4fd3b1d2013-12-11 22:33:43 +0000562 // If we have a non-preferred node, push it back onto the available list.
563 // If we did not find a preferred node, then schedule this first
564 // non-preferred node.
565 if (NotPreferredSUnit) {
566 if (!FoundSUnit) {
567 DEBUG(dbgs() << "*** Will schedule a non-preferred instruction...\n");
568 FoundSUnit = NotPreferredSUnit;
569 } else {
570 AvailableQueue.push(NotPreferredSUnit);
571 }
572
573 NotPreferredSUnit = 0;
574 }
575
Dan Gohmanceac7c32009-01-16 01:33:36 +0000576 // Add the nodes that aren't ready back onto the available list.
577 if (!NotReady.empty()) {
578 AvailableQueue.push_all(NotReady);
579 NotReady.clear();
580 }
581
David Goodwin8501dbbe2009-11-03 20:57:50 +0000582 // If we found a node to schedule...
Dan Gohman60cb69e2008-11-19 23:18:57 +0000583 if (FoundSUnit) {
Hal Finkel4fd3b1d2013-12-11 22:33:43 +0000584 // If we need to emit noops prior to this instruction, then do so.
585 unsigned NumPreNoops = HazardRec->PreEmitNoops(FoundSUnit);
586 for (unsigned i = 0; i != NumPreNoops; ++i)
587 emitNoop(CurCycle);
588
David Goodwin8501dbbe2009-11-03 20:57:50 +0000589 // ... schedule the node...
David Goodwin80a03cc2009-11-20 19:32:48 +0000590 ScheduleNodeTopDown(FoundSUnit, CurCycle);
Dan Gohmanceac7c32009-01-16 01:33:36 +0000591 HazardRec->EmitInstruction(FoundSUnit);
Benjamin Kramere3c9d232009-09-06 12:10:17 +0000592 CycleHasInsts = true;
Andrew Trick18c9b372011-06-01 03:27:56 +0000593 if (HazardRec->atIssueLimit()) {
594 DEBUG(dbgs() << "*** Max instructions per cycle " << CurCycle << '\n');
595 HazardRec->AdvanceCycle();
596 ++CurCycle;
597 CycleHasInsts = false;
598 }
Dan Gohmanceac7c32009-01-16 01:33:36 +0000599 } else {
Benjamin Kramere3c9d232009-09-06 12:10:17 +0000600 if (CycleHasInsts) {
David Greeneaa8ce382010-01-05 01:26:01 +0000601 DEBUG(dbgs() << "*** Finished cycle " << CurCycle << '\n');
David Goodwin1f8c7a72009-08-12 21:47:46 +0000602 HazardRec->AdvanceCycle();
603 } else if (!HasNoopHazards) {
604 // Otherwise, we have a pipeline stall, but no other problem,
605 // just advance the current cycle and try again.
David Greeneaa8ce382010-01-05 01:26:01 +0000606 DEBUG(dbgs() << "*** Stall in cycle " << CurCycle << '\n');
David Goodwin1f8c7a72009-08-12 21:47:46 +0000607 HazardRec->AdvanceCycle();
David Goodwin80a03cc2009-11-20 19:32:48 +0000608 ++NumStalls;
David Goodwin1f8c7a72009-08-12 21:47:46 +0000609 } else {
610 // Otherwise, we have no instructions to issue and we have instructions
611 // that will fault if we don't do this right. This is the case for
612 // processors without pipeline interlocks and other cases.
Hal Finkel4fd3b1d2013-12-11 22:33:43 +0000613 emitNoop(CurCycle);
David Goodwin1f8c7a72009-08-12 21:47:46 +0000614 }
615
Dan Gohmanceac7c32009-01-16 01:33:36 +0000616 ++CurCycle;
Benjamin Kramere3c9d232009-09-06 12:10:17 +0000617 CycleHasInsts = false;
Dan Gohman60cb69e2008-11-19 23:18:57 +0000618 }
619 }
620
621#ifndef NDEBUG
Andrew Trick46a58662012-03-07 05:21:36 +0000622 unsigned ScheduledNodes = VerifyScheduledDAG(/*isBottomUp=*/false);
623 unsigned Noops = 0;
624 for (unsigned i = 0, e = Sequence.size(); i != e; ++i)
625 if (!Sequence[i])
626 ++Noops;
627 assert(Sequence.size() - Noops == ScheduledNodes &&
628 "The number of nodes scheduled doesn't match the expected number!");
629#endif // NDEBUG
Dan Gohman60cb69e2008-11-19 23:18:57 +0000630}
Andrew Tricke932bb72012-03-07 05:21:44 +0000631
632// EmitSchedule - Emit the machine code in scheduled order.
633void SchedulePostRATDList::EmitSchedule() {
Andrew Trick8c207e42012-03-09 04:29:02 +0000634 RegionBegin = RegionEnd;
Andrew Tricke932bb72012-03-07 05:21:44 +0000635
636 // If first instruction was a DBG_VALUE then put it back.
637 if (FirstDbgValue)
Andrew Trick8c207e42012-03-09 04:29:02 +0000638 BB->splice(RegionEnd, BB, FirstDbgValue);
Andrew Tricke932bb72012-03-07 05:21:44 +0000639
640 // Then re-insert them according to the given schedule.
641 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
642 if (SUnit *SU = Sequence[i])
Andrew Trick8c207e42012-03-09 04:29:02 +0000643 BB->splice(RegionEnd, BB, SU->getInstr());
Andrew Tricke932bb72012-03-07 05:21:44 +0000644 else
645 // Null SUnit* is a noop.
Andrew Trick8c207e42012-03-09 04:29:02 +0000646 TII->insertNoop(*BB, RegionEnd);
Andrew Tricke932bb72012-03-07 05:21:44 +0000647
648 // Update the Begin iterator, as the first instruction in the block
649 // may have been scheduled later.
650 if (i == 0)
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000651 RegionBegin = std::prev(RegionEnd);
Andrew Tricke932bb72012-03-07 05:21:44 +0000652 }
653
654 // Reinsert any remaining debug_values.
655 for (std::vector<std::pair<MachineInstr *, MachineInstr *> >::iterator
656 DI = DbgValues.end(), DE = DbgValues.begin(); DI != DE; --DI) {
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000657 std::pair<MachineInstr *, MachineInstr *> P = *std::prev(DI);
Andrew Tricke932bb72012-03-07 05:21:44 +0000658 MachineInstr *DbgValue = P.first;
659 MachineBasicBlock::iterator OrigPrivMI = P.second;
660 BB->splice(++OrigPrivMI, BB, DbgValue);
661 }
662 DbgValues.clear();
663 FirstDbgValue = NULL;
664}