blob: 4f1e04bb0e501e1ea907ff99b8dacd00d27cd83c [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"
David Goodwin82c72482009-10-28 18:29:54 +000022#include "AntiDepBreaker.h"
David Goodwin34877712009-10-26 19:32:42 +000023#include "AggressiveAntiDepBreaker.h"
David Goodwin2e7be612009-10-26 16:59:04 +000024#include "CriticalAntiDepBreaker.h"
David Goodwind94a4e52009-08-10 15:55:25 +000025#include "ExactHazardRecognizer.h"
26#include "SimpleHazardRecognizer.h"
Dan Gohman6dc75fe2009-02-06 17:12:10 +000027#include "ScheduleDAGInstrs.h"
Dale Johannesene7e7d0d2007-07-13 17:13:54 +000028#include "llvm/CodeGen/Passes.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000029#include "llvm/CodeGen/LatencyPriorityQueue.h"
30#include "llvm/CodeGen/SchedulerRegistry.h"
Dan Gohman3f237442008-12-16 03:25:46 +000031#include "llvm/CodeGen/MachineDominators.h"
David Goodwinc7951f82009-10-01 19:45:32 +000032#include "llvm/CodeGen/MachineFrameInfo.h"
Dale Johannesene7e7d0d2007-07-13 17:13:54 +000033#include "llvm/CodeGen/MachineFunctionPass.h"
Dan Gohman3f237442008-12-16 03:25:46 +000034#include "llvm/CodeGen/MachineLoopInfo.h"
Dan Gohman21d90032008-11-25 00:52:40 +000035#include "llvm/CodeGen/MachineRegisterInfo.h"
Dan Gohman2836c282009-01-16 01:33:36 +000036#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
Dan Gohmana70dca12009-10-09 23:27:56 +000037#include "llvm/Analysis/AliasAnalysis.h"
Dan Gohmanbed353d2009-02-10 23:29:38 +000038#include "llvm/Target/TargetLowering.h"
Dan Gohman79ce2762009-01-15 19:20:50 +000039#include "llvm/Target/TargetMachine.h"
Dan Gohman21d90032008-11-25 00:52:40 +000040#include "llvm/Target/TargetInstrInfo.h"
41#include "llvm/Target/TargetRegisterInfo.h"
David Goodwin0dad89f2009-09-30 00:10:16 +000042#include "llvm/Target/TargetSubtarget.h"
David Goodwine10deca2009-10-26 22:31:16 +000043#include "llvm/Support/CommandLine.h"
Dale Johannesene7e7d0d2007-07-13 17:13:54 +000044#include "llvm/Support/Debug.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000045#include "llvm/Support/ErrorHandling.h"
David Goodwin3a5f0d42009-08-11 01:44:26 +000046#include "llvm/Support/raw_ostream.h"
David Goodwin2e7be612009-10-26 16:59:04 +000047#include "llvm/ADT/BitVector.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000048#include "llvm/ADT/Statistic.h"
David Goodwin88a589c2009-08-25 17:03:05 +000049#include <set>
Dale Johannesene7e7d0d2007-07-13 17:13:54 +000050using namespace llvm;
51
Dan Gohman2836c282009-01-16 01:33:36 +000052STATISTIC(NumNoops, "Number of noops inserted");
Dan Gohman343f0c02008-11-19 23:18:57 +000053STATISTIC(NumStalls, "Number of pipeline stalls");
David Goodwin2e7be612009-10-26 16:59:04 +000054STATISTIC(NumFixedAnti, "Number of fixed anti-dependencies");
Dan Gohman343f0c02008-11-19 23:18:57 +000055
David Goodwin471850a2009-10-01 21:46:35 +000056// Post-RA scheduling is enabled with
57// TargetSubtarget.enablePostRAScheduler(). This flag can be used to
58// override the target.
59static cl::opt<bool>
60EnablePostRAScheduler("post-RA-scheduler",
61 cl::desc("Enable scheduling after register allocation"),
David Goodwin9843a932009-10-01 22:19:57 +000062 cl::init(false), cl::Hidden);
David Goodwin2e7be612009-10-26 16:59:04 +000063static cl::opt<std::string>
Dan Gohman21d90032008-11-25 00:52:40 +000064EnableAntiDepBreaking("break-anti-dependencies",
David Goodwin2e7be612009-10-26 16:59:04 +000065 cl::desc("Break post-RA scheduling anti-dependencies: "
66 "\"critical\", \"all\", or \"none\""),
67 cl::init("none"), cl::Hidden);
Dan Gohman2836c282009-01-16 01:33:36 +000068static cl::opt<bool>
69EnablePostRAHazardAvoidance("avoid-hazards",
David Goodwind94a4e52009-08-10 15:55:25 +000070 cl::desc("Enable exact hazard avoidance"),
David Goodwin5e411782009-09-03 22:15:25 +000071 cl::init(true), cl::Hidden);
Dan Gohman2836c282009-01-16 01:33:36 +000072
David Goodwin1f152282009-09-01 18:34:03 +000073// If DebugDiv > 0 then only schedule MBB with (ID % DebugDiv) == DebugMod
74static cl::opt<int>
75DebugDiv("postra-sched-debugdiv",
76 cl::desc("Debug control MBBs that are scheduled"),
77 cl::init(0), cl::Hidden);
78static cl::opt<int>
79DebugMod("postra-sched-debugmod",
80 cl::desc("Debug control MBBs that are scheduled"),
81 cl::init(0), cl::Hidden);
82
Jim Grosbach5468e092010-05-14 21:18:04 +000083static cl::opt<bool>
84EnablePostRADbgValue("post-RA-dbg-value",
85 cl::desc("Enable processing of dbg_value in post-RA"),
86 cl::init(false), cl::Hidden);
87
88
David Goodwinada0ef82009-10-26 19:41:00 +000089AntiDepBreaker::~AntiDepBreaker() { }
90
Dale Johannesene7e7d0d2007-07-13 17:13:54 +000091namespace {
Nick Lewycky6726b6d2009-10-25 06:33:48 +000092 class PostRAScheduler : public MachineFunctionPass {
Dan Gohmana70dca12009-10-09 23:27:56 +000093 AliasAnalysis *AA;
Evan Chengfa163542009-10-16 21:06:15 +000094 CodeGenOpt::Level OptLevel;
Dan Gohmana70dca12009-10-09 23:27:56 +000095
Dale Johannesene7e7d0d2007-07-13 17:13:54 +000096 public:
97 static char ID;
Evan Chengfa163542009-10-16 21:06:15 +000098 PostRAScheduler(CodeGenOpt::Level ol) :
99 MachineFunctionPass(&ID), OptLevel(ol) {}
Dan Gohman21d90032008-11-25 00:52:40 +0000100
Dan Gohman3f237442008-12-16 03:25:46 +0000101 void getAnalysisUsage(AnalysisUsage &AU) const {
Dan Gohman845012e2009-07-31 23:37:33 +0000102 AU.setPreservesCFG();
Dan Gohmana70dca12009-10-09 23:27:56 +0000103 AU.addRequired<AliasAnalysis>();
Dan Gohman3f237442008-12-16 03:25:46 +0000104 AU.addRequired<MachineDominatorTree>();
105 AU.addPreserved<MachineDominatorTree>();
106 AU.addRequired<MachineLoopInfo>();
107 AU.addPreserved<MachineLoopInfo>();
108 MachineFunctionPass::getAnalysisUsage(AU);
109 }
110
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000111 const char *getPassName() const {
Dan Gohman21d90032008-11-25 00:52:40 +0000112 return "Post RA top-down list latency scheduler";
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000113 }
114
115 bool runOnMachineFunction(MachineFunction &Fn);
116 };
Dan Gohman343f0c02008-11-19 23:18:57 +0000117 char PostRAScheduler::ID = 0;
118
Nick Lewycky6726b6d2009-10-25 06:33:48 +0000119 class SchedulePostRATDList : public ScheduleDAGInstrs {
Dan Gohman343f0c02008-11-19 23:18:57 +0000120 /// AvailableQueue - The priority queue to use for the available SUnits.
Dan Gohmanc1ae8c92009-10-21 01:44:44 +0000121 ///
Dan Gohman343f0c02008-11-19 23:18:57 +0000122 LatencyPriorityQueue AvailableQueue;
123
124 /// PendingQueue - This contains all of the instructions whose operands have
125 /// been issued, but their results are not ready yet (due to the latency of
126 /// the operation). Once the operands becomes available, the instruction is
127 /// added to the AvailableQueue.
128 std::vector<SUnit*> PendingQueue;
129
Dan Gohman21d90032008-11-25 00:52:40 +0000130 /// Topo - A topological ordering for SUnits.
131 ScheduleDAGTopologicalSort Topo;
Dan Gohman343f0c02008-11-19 23:18:57 +0000132
Dan Gohman2836c282009-01-16 01:33:36 +0000133 /// HazardRec - The hazard recognizer to use.
134 ScheduleHazardRecognizer *HazardRec;
135
David Goodwin2e7be612009-10-26 16:59:04 +0000136 /// AntiDepBreak - Anti-dependence breaking object, or NULL if none
137 AntiDepBreaker *AntiDepBreak;
138
Dan Gohmana70dca12009-10-09 23:27:56 +0000139 /// AA - AliasAnalysis for making memory reference queries.
140 AliasAnalysis *AA;
141
Dan Gohmanc1ae8c92009-10-21 01:44:44 +0000142 /// KillIndices - The index of the most recent kill (proceding bottom-up),
143 /// or ~0u if the register is not live.
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000144 unsigned KillIndices[TargetRegisterInfo::FirstVirtualRegister];
145
Dan Gohman21d90032008-11-25 00:52:40 +0000146 public:
Dan Gohman79ce2762009-01-15 19:20:50 +0000147 SchedulePostRATDList(MachineFunction &MF,
Dan Gohman3f237442008-12-16 03:25:46 +0000148 const MachineLoopInfo &MLI,
Dan Gohman2836c282009-01-16 01:33:36 +0000149 const MachineDominatorTree &MDT,
Dan Gohmana70dca12009-10-09 23:27:56 +0000150 ScheduleHazardRecognizer *HR,
David Goodwin2e7be612009-10-26 16:59:04 +0000151 AntiDepBreaker *ADB,
152 AliasAnalysis *aa)
Dan Gohman79ce2762009-01-15 19:20:50 +0000153 : ScheduleDAGInstrs(MF, MLI, MDT), Topo(SUnits),
David Goodwin2e7be612009-10-26 16:59:04 +0000154 HazardRec(HR), AntiDepBreak(ADB), AA(aa) {}
Dan Gohman2836c282009-01-16 01:33:36 +0000155
156 ~SchedulePostRATDList() {
Dan Gohman2836c282009-01-16 01:33:36 +0000157 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000158
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000159 /// StartBlock - Initialize register live-range state for scheduling in
160 /// this block.
161 ///
162 void StartBlock(MachineBasicBlock *BB);
163
164 /// Schedule - Schedule the instruction range using list scheduling.
165 ///
Dan Gohman343f0c02008-11-19 23:18:57 +0000166 void Schedule();
David Goodwin88a589c2009-08-25 17:03:05 +0000167
Dan Gohmanc1ae8c92009-10-21 01:44:44 +0000168 /// Observe - Update liveness information to account for the current
169 /// instruction, which will not be scheduled.
170 ///
171 void Observe(MachineInstr *MI, unsigned Count);
172
173 /// FinishBlock - Clean up register live-range state.
174 ///
175 void FinishBlock();
176
David Goodwin2e7be612009-10-26 16:59:04 +0000177 /// FixupKills - Fix register kill flags that have been made
178 /// invalid due to scheduling
179 ///
180 void FixupKills(MachineBasicBlock *MBB);
181
Dan Gohman343f0c02008-11-19 23:18:57 +0000182 private:
David Goodwin557bbe62009-11-20 19:32:48 +0000183 void ReleaseSucc(SUnit *SU, SDep *SuccEdge);
184 void ReleaseSuccessors(SUnit *SU);
185 void ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle);
186 void ListScheduleTopDown();
David Goodwin5e411782009-09-03 22:15:25 +0000187 void StartBlockForKills(MachineBasicBlock *BB);
David Goodwin8f909342009-09-23 16:35:25 +0000188
189 // ToggleKillFlag - Toggle a register operand kill flag. Other
190 // adjustments may be made to the instruction if necessary. Return
191 // true if the operand has been deleted, false if not.
192 bool ToggleKillFlag(MachineInstr *MI, MachineOperand &MO);
Dan Gohman343f0c02008-11-19 23:18:57 +0000193 };
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000194}
195
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000196/// isSchedulingBoundary - Test if the given instruction should be
197/// considered a scheduling boundary. This primarily includes labels
198/// and terminators.
199///
200static bool isSchedulingBoundary(const MachineInstr *MI,
201 const MachineFunction &MF) {
202 // Terminators and labels can't be scheduled around.
203 if (MI->getDesc().isTerminator() || MI->isLabel())
204 return true;
205
Dan Gohmanbed353d2009-02-10 23:29:38 +0000206 // Don't attempt to schedule around any instruction that modifies
207 // a stack-oriented pointer, as it's unlikely to be profitable. This
208 // saves compile time, because it doesn't require every single
209 // stack slot reference to depend on the instruction that does the
210 // modification.
211 const TargetLowering &TLI = *MF.getTarget().getTargetLowering();
212 if (MI->modifiesRegister(TLI.getStackPointerRegisterToSaveRestore()))
213 return true;
214
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000215 return false;
216}
217
Dan Gohman343f0c02008-11-19 23:18:57 +0000218bool PostRAScheduler::runOnMachineFunction(MachineFunction &Fn) {
Dan Gohman5bf7c2a2009-10-10 00:15:38 +0000219 AA = &getAnalysis<AliasAnalysis>();
220
David Goodwin471850a2009-10-01 21:46:35 +0000221 // Check for explicit enable/disable of post-ra scheduling.
David Goodwin4c3715c2009-10-22 23:19:17 +0000222 TargetSubtarget::AntiDepBreakMode AntiDepMode = TargetSubtarget::ANTIDEP_NONE;
David Goodwin87d21b92009-11-13 19:52:48 +0000223 SmallVector<TargetRegisterClass*, 4> CriticalPathRCs;
David Goodwin471850a2009-10-01 21:46:35 +0000224 if (EnablePostRAScheduler.getPosition() > 0) {
225 if (!EnablePostRAScheduler)
Evan Chengc83da2f92009-10-16 06:10:34 +0000226 return false;
David Goodwin471850a2009-10-01 21:46:35 +0000227 } else {
Evan Chengc83da2f92009-10-16 06:10:34 +0000228 // Check that post-RA scheduling is enabled for this target.
David Goodwin471850a2009-10-01 21:46:35 +0000229 const TargetSubtarget &ST = Fn.getTarget().getSubtarget<TargetSubtarget>();
David Goodwin87d21b92009-11-13 19:52:48 +0000230 if (!ST.enablePostRAScheduler(OptLevel, AntiDepMode, CriticalPathRCs))
Evan Chengc83da2f92009-10-16 06:10:34 +0000231 return false;
David Goodwin471850a2009-10-01 21:46:35 +0000232 }
David Goodwin0dad89f2009-09-30 00:10:16 +0000233
David Goodwin4c3715c2009-10-22 23:19:17 +0000234 // Check for antidep breaking override...
235 if (EnableAntiDepBreaking.getPosition() > 0) {
David Goodwin2e7be612009-10-26 16:59:04 +0000236 AntiDepMode = (EnableAntiDepBreaking == "all") ? TargetSubtarget::ANTIDEP_ALL :
237 (EnableAntiDepBreaking == "critical") ? TargetSubtarget::ANTIDEP_CRITICAL :
238 TargetSubtarget::ANTIDEP_NONE;
David Goodwin4c3715c2009-10-22 23:19:17 +0000239 }
240
David Greenee1b21292010-01-05 01:26:01 +0000241 DEBUG(dbgs() << "PostRAScheduler\n");
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000242
Dan Gohman3f237442008-12-16 03:25:46 +0000243 const MachineLoopInfo &MLI = getAnalysis<MachineLoopInfo>();
244 const MachineDominatorTree &MDT = getAnalysis<MachineDominatorTree>();
David Goodwind94a4e52009-08-10 15:55:25 +0000245 const InstrItineraryData &InstrItins = Fn.getTarget().getInstrItineraryData();
Dan Gohman2836c282009-01-16 01:33:36 +0000246 ScheduleHazardRecognizer *HR = EnablePostRAHazardAvoidance ?
David Goodwind94a4e52009-08-10 15:55:25 +0000247 (ScheduleHazardRecognizer *)new ExactHazardRecognizer(InstrItins) :
248 (ScheduleHazardRecognizer *)new SimpleHazardRecognizer();
David Goodwin2e7be612009-10-26 16:59:04 +0000249 AntiDepBreaker *ADB =
David Goodwin34877712009-10-26 19:32:42 +0000250 ((AntiDepMode == TargetSubtarget::ANTIDEP_ALL) ?
David Goodwin87d21b92009-11-13 19:52:48 +0000251 (AntiDepBreaker *)new AggressiveAntiDepBreaker(Fn, CriticalPathRCs) :
David Goodwin34877712009-10-26 19:32:42 +0000252 ((AntiDepMode == TargetSubtarget::ANTIDEP_CRITICAL) ?
253 (AntiDepBreaker *)new CriticalAntiDepBreaker(Fn) : NULL));
Dan Gohman3f237442008-12-16 03:25:46 +0000254
David Goodwin2e7be612009-10-26 16:59:04 +0000255 SchedulePostRATDList Scheduler(Fn, MLI, MDT, HR, ADB, AA);
Dan Gohman79ce2762009-01-15 19:20:50 +0000256
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000257 // Loop over all of the basic blocks
258 for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end();
Dan Gohman343f0c02008-11-19 23:18:57 +0000259 MBB != MBBe; ++MBB) {
David Goodwin1f152282009-09-01 18:34:03 +0000260#ifndef NDEBUG
261 // If DebugDiv > 0 then only schedule MBB with (ID % DebugDiv) == DebugMod
262 if (DebugDiv > 0) {
263 static int bbcnt = 0;
264 if (bbcnt++ % DebugDiv != DebugMod)
265 continue;
David Greenee1b21292010-01-05 01:26:01 +0000266 dbgs() << "*** DEBUG scheduling " << Fn.getFunction()->getNameStr() <<
Dan Gohman0ba90f32009-10-31 20:19:03 +0000267 ":BB#" << MBB->getNumber() << " ***\n";
David Goodwin1f152282009-09-01 18:34:03 +0000268 }
269#endif
270
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000271 // Initialize register live-range state for scheduling in this block.
272 Scheduler.StartBlock(MBB);
273
Bob Wilson8295d4c2010-04-17 00:49:11 +0000274 // FIXME: Temporary workaround for <rdar://problem/7759363>: The post-RA
275 // scheduler has some sort of problem with DebugValue instructions that
276 // causes an assertion in LeaksContext.h to fail occasionally. Just
277 // remove all those instructions for now.
Jim Grosbach5468e092010-05-14 21:18:04 +0000278 if (!EnablePostRADbgValue) {
279 DEBUG(dbgs() << "*** Maintaining DbgValues in PostRAScheduler\n");
280 for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end();
281 I != E; ) {
282 MachineInstr *MI = &*I++;
283 if (MI->isDebugValue())
284 MI->eraseFromParent();
285 }
Bob Wilson8295d4c2010-04-17 00:49:11 +0000286 }
287
Dan Gohmanf7119392009-01-16 22:10:20 +0000288 // Schedule each sequence of instructions not interrupted by a label
289 // or anything else that effectively needs to shut down scheduling.
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000290 MachineBasicBlock::iterator Current = MBB->end();
Dan Gohman47ac0f02009-02-11 04:27:20 +0000291 unsigned Count = MBB->size(), CurrentCount = Count;
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000292 for (MachineBasicBlock::iterator I = Current; I != MBB->begin(); ) {
293 MachineInstr *MI = prior(I);
294 if (isSchedulingBoundary(MI, Fn)) {
Dan Gohman1274ced2009-03-10 18:10:43 +0000295 Scheduler.Run(MBB, I, Current, CurrentCount);
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000296 Scheduler.EmitSchedule();
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000297 Current = MI;
Dan Gohman47ac0f02009-02-11 04:27:20 +0000298 CurrentCount = Count - 1;
Dan Gohman1274ced2009-03-10 18:10:43 +0000299 Scheduler.Observe(MI, CurrentCount);
Dan Gohmanf7119392009-01-16 22:10:20 +0000300 }
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000301 I = MI;
Dan Gohman47ac0f02009-02-11 04:27:20 +0000302 --Count;
Dan Gohman43f07fb2009-02-03 18:57:45 +0000303 }
Dan Gohman47ac0f02009-02-11 04:27:20 +0000304 assert(Count == 0 && "Instruction count mismatch!");
Duncan Sands9e8bd0b2009-03-11 09:04:34 +0000305 assert((MBB->begin() == Current || CurrentCount != 0) &&
Dan Gohman1274ced2009-03-10 18:10:43 +0000306 "Instruction count mismatch!");
307 Scheduler.Run(MBB, MBB->begin(), Current, CurrentCount);
Dan Gohmanaf1d8ca2010-05-01 00:01:06 +0000308 Scheduler.EmitSchedule();
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000309
310 // Clean up register live-range state.
311 Scheduler.FinishBlock();
David Goodwin88a589c2009-08-25 17:03:05 +0000312
David Goodwin5e411782009-09-03 22:15:25 +0000313 // Update register kills
David Goodwin88a589c2009-08-25 17:03:05 +0000314 Scheduler.FixupKills(MBB);
Dan Gohman343f0c02008-11-19 23:18:57 +0000315 }
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000316
David Goodwin2e7be612009-10-26 16:59:04 +0000317 delete HR;
318 delete ADB;
319
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000320 return true;
321}
322
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000323/// StartBlock - Initialize register live-range state for scheduling in
324/// this block.
Dan Gohman21d90032008-11-25 00:52:40 +0000325///
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000326void SchedulePostRATDList::StartBlock(MachineBasicBlock *BB) {
327 // Call the superclass.
328 ScheduleDAGInstrs::StartBlock(BB);
Dan Gohman21d90032008-11-25 00:52:40 +0000329
David Goodwin2e7be612009-10-26 16:59:04 +0000330 // Reset the hazard recognizer and anti-dep breaker.
David Goodwind94a4e52009-08-10 15:55:25 +0000331 HazardRec->Reset();
David Goodwin2e7be612009-10-26 16:59:04 +0000332 if (AntiDepBreak != NULL)
333 AntiDepBreak->StartBlock(BB);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000334}
335
336/// Schedule - Schedule the instruction range using list scheduling.
337///
338void SchedulePostRATDList::Schedule() {
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000339 // Build the scheduling graph.
Dan Gohmana70dca12009-10-09 23:27:56 +0000340 BuildSchedGraph(AA);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000341
David Goodwin2e7be612009-10-26 16:59:04 +0000342 if (AntiDepBreak != NULL) {
David Goodwin557bbe62009-11-20 19:32:48 +0000343 unsigned Broken =
344 AntiDepBreak->BreakAntiDependencies(SUnits, Begin, InsertPos,
345 InsertPosIndex);
David Goodwin4de099d2009-11-03 20:57:50 +0000346
David Goodwin557bbe62009-11-20 19:32:48 +0000347 if (Broken != 0) {
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000348 // We made changes. Update the dependency graph.
349 // Theoretically we could update the graph in place:
350 // When a live range is changed to use a different register, remove
351 // the def's anti-dependence *and* output-dependence edges due to
352 // that register, and add new anti-dependence and output-dependence
353 // edges based on the next live range of the register.
David Goodwin557bbe62009-11-20 19:32:48 +0000354 SUnits.clear();
355 Sequence.clear();
356 EntrySU = SUnit();
357 ExitSU = SUnit();
358 BuildSchedGraph(AA);
359
David Goodwin2e7be612009-10-26 16:59:04 +0000360 NumFixedAnti += Broken;
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000361 }
362 }
363
David Greenee1b21292010-01-05 01:26:01 +0000364 DEBUG(dbgs() << "********** List Scheduling **********\n");
David Goodwind94a4e52009-08-10 15:55:25 +0000365 DEBUG(for (unsigned su = 0, e = SUnits.size(); su != e; ++su)
366 SUnits[su].dumpAll(this));
367
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000368 AvailableQueue.initNodes(SUnits);
David Goodwin557bbe62009-11-20 19:32:48 +0000369 ListScheduleTopDown();
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000370 AvailableQueue.releaseState();
371}
372
373/// Observe - Update liveness information to account for the current
374/// instruction, which will not be scheduled.
375///
Dan Gohman47ac0f02009-02-11 04:27:20 +0000376void SchedulePostRATDList::Observe(MachineInstr *MI, unsigned Count) {
David Goodwin2e7be612009-10-26 16:59:04 +0000377 if (AntiDepBreak != NULL)
378 AntiDepBreak->Observe(MI, Count, InsertPosIndex);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000379}
380
381/// FinishBlock - Clean up register live-range state.
382///
383void SchedulePostRATDList::FinishBlock() {
David Goodwin2e7be612009-10-26 16:59:04 +0000384 if (AntiDepBreak != NULL)
385 AntiDepBreak->FinishBlock();
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000386
387 // Call the superclass.
388 ScheduleDAGInstrs::FinishBlock();
389}
390
David Goodwin5e411782009-09-03 22:15:25 +0000391/// StartBlockForKills - Initialize register live-range state for updating kills
392///
393void SchedulePostRATDList::StartBlockForKills(MachineBasicBlock *BB) {
394 // Initialize the indices to indicate that no registers are live.
David Goodwin990d2852009-12-09 17:18:22 +0000395 for (unsigned i = 0; i < TRI->getNumRegs(); ++i)
396 KillIndices[i] = ~0u;
David Goodwin5e411782009-09-03 22:15:25 +0000397
398 // Determine the live-out physregs for this block.
399 if (!BB->empty() && BB->back().getDesc().isReturn()) {
400 // In a return block, examine the function live-out regs.
401 for (MachineRegisterInfo::liveout_iterator I = MRI.liveout_begin(),
402 E = MRI.liveout_end(); I != E; ++I) {
403 unsigned Reg = *I;
404 KillIndices[Reg] = BB->size();
405 // Repeat, for all subregs.
406 for (const unsigned *Subreg = TRI->getSubRegisters(Reg);
407 *Subreg; ++Subreg) {
408 KillIndices[*Subreg] = BB->size();
409 }
410 }
411 }
412 else {
413 // In a non-return block, examine the live-in regs of all successors.
414 for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
415 SE = BB->succ_end(); SI != SE; ++SI) {
416 for (MachineBasicBlock::livein_iterator I = (*SI)->livein_begin(),
417 E = (*SI)->livein_end(); I != E; ++I) {
418 unsigned Reg = *I;
419 KillIndices[Reg] = BB->size();
420 // Repeat, for all subregs.
421 for (const unsigned *Subreg = TRI->getSubRegisters(Reg);
422 *Subreg; ++Subreg) {
423 KillIndices[*Subreg] = BB->size();
424 }
425 }
426 }
427 }
428}
429
David Goodwin8f909342009-09-23 16:35:25 +0000430bool SchedulePostRATDList::ToggleKillFlag(MachineInstr *MI,
431 MachineOperand &MO) {
432 // Setting kill flag...
433 if (!MO.isKill()) {
434 MO.setIsKill(true);
435 return false;
436 }
437
438 // If MO itself is live, clear the kill flag...
439 if (KillIndices[MO.getReg()] != ~0u) {
440 MO.setIsKill(false);
441 return false;
442 }
443
444 // If any subreg of MO is live, then create an imp-def for that
445 // subreg and keep MO marked as killed.
Benjamin Kramer8bff4af2009-10-02 15:59:52 +0000446 MO.setIsKill(false);
David Goodwin8f909342009-09-23 16:35:25 +0000447 bool AllDead = true;
448 const unsigned SuperReg = MO.getReg();
449 for (const unsigned *Subreg = TRI->getSubRegisters(SuperReg);
450 *Subreg; ++Subreg) {
451 if (KillIndices[*Subreg] != ~0u) {
452 MI->addOperand(MachineOperand::CreateReg(*Subreg,
453 true /*IsDef*/,
454 true /*IsImp*/,
455 false /*IsKill*/,
456 false /*IsDead*/));
457 AllDead = false;
458 }
459 }
460
Dan Gohmanc1ae8c92009-10-21 01:44:44 +0000461 if(AllDead)
Benjamin Kramer8bff4af2009-10-02 15:59:52 +0000462 MO.setIsKill(true);
David Goodwin8f909342009-09-23 16:35:25 +0000463 return false;
464}
465
David Goodwin88a589c2009-08-25 17:03:05 +0000466/// FixupKills - Fix the register kill flags, they may have been made
467/// incorrect by instruction reordering.
468///
469void SchedulePostRATDList::FixupKills(MachineBasicBlock *MBB) {
David Greenee1b21292010-01-05 01:26:01 +0000470 DEBUG(dbgs() << "Fixup kills for BB#" << MBB->getNumber() << '\n');
David Goodwin88a589c2009-08-25 17:03:05 +0000471
472 std::set<unsigned> killedRegs;
473 BitVector ReservedRegs = TRI->getReservedRegs(MF);
David Goodwin5e411782009-09-03 22:15:25 +0000474
475 StartBlockForKills(MBB);
David Goodwin7886cd82009-08-29 00:11:13 +0000476
477 // Examine block from end to start...
David Goodwin88a589c2009-08-25 17:03:05 +0000478 unsigned Count = MBB->size();
479 for (MachineBasicBlock::iterator I = MBB->end(), E = MBB->begin();
480 I != E; --Count) {
481 MachineInstr *MI = --I;
Dale Johannesenb0812f12010-03-05 00:02:59 +0000482 if (MI->isDebugValue())
483 continue;
David Goodwin88a589c2009-08-25 17:03:05 +0000484
David Goodwin7886cd82009-08-29 00:11:13 +0000485 // Update liveness. Registers that are defed but not used in this
486 // instruction are now dead. Mark register and all subregs as they
487 // are completely defined.
488 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
489 MachineOperand &MO = MI->getOperand(i);
490 if (!MO.isReg()) continue;
491 unsigned Reg = MO.getReg();
492 if (Reg == 0) continue;
493 if (!MO.isDef()) continue;
494 // Ignore two-addr defs.
495 if (MI->isRegTiedToUseOperand(i)) continue;
496
David Goodwin7886cd82009-08-29 00:11:13 +0000497 KillIndices[Reg] = ~0u;
498
499 // Repeat for all subregs.
500 for (const unsigned *Subreg = TRI->getSubRegisters(Reg);
501 *Subreg; ++Subreg) {
502 KillIndices[*Subreg] = ~0u;
503 }
504 }
David Goodwin88a589c2009-08-25 17:03:05 +0000505
David Goodwin8f909342009-09-23 16:35:25 +0000506 // Examine all used registers and set/clear kill flag. When a
507 // register is used multiple times we only set the kill flag on
508 // the first use.
David Goodwin88a589c2009-08-25 17:03:05 +0000509 killedRegs.clear();
510 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
511 MachineOperand &MO = MI->getOperand(i);
512 if (!MO.isReg() || !MO.isUse()) continue;
513 unsigned Reg = MO.getReg();
514 if ((Reg == 0) || ReservedRegs.test(Reg)) continue;
515
David Goodwin7886cd82009-08-29 00:11:13 +0000516 bool kill = false;
517 if (killedRegs.find(Reg) == killedRegs.end()) {
518 kill = true;
519 // A register is not killed if any subregs are live...
520 for (const unsigned *Subreg = TRI->getSubRegisters(Reg);
521 *Subreg; ++Subreg) {
522 if (KillIndices[*Subreg] != ~0u) {
523 kill = false;
524 break;
525 }
526 }
527
528 // If subreg is not live, then register is killed if it became
529 // live in this instruction
530 if (kill)
531 kill = (KillIndices[Reg] == ~0u);
532 }
533
David Goodwin88a589c2009-08-25 17:03:05 +0000534 if (MO.isKill() != kill) {
David Greenee1b21292010-01-05 01:26:01 +0000535 DEBUG(dbgs() << "Fixing " << MO << " in ");
Jakob Stoklund Olesen15d75d92009-12-03 01:49:56 +0000536 // Warning: ToggleKillFlag may invalidate MO.
537 ToggleKillFlag(MI, MO);
David Goodwin88a589c2009-08-25 17:03:05 +0000538 DEBUG(MI->dump());
539 }
David Goodwin7886cd82009-08-29 00:11:13 +0000540
David Goodwin88a589c2009-08-25 17:03:05 +0000541 killedRegs.insert(Reg);
542 }
David Goodwin7886cd82009-08-29 00:11:13 +0000543
David Goodwina3251db2009-08-31 20:47:02 +0000544 // Mark any used register (that is not using undef) and subregs as
545 // now live...
David Goodwin7886cd82009-08-29 00:11:13 +0000546 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
547 MachineOperand &MO = MI->getOperand(i);
David Goodwina3251db2009-08-31 20:47:02 +0000548 if (!MO.isReg() || !MO.isUse() || MO.isUndef()) continue;
David Goodwin7886cd82009-08-29 00:11:13 +0000549 unsigned Reg = MO.getReg();
550 if ((Reg == 0) || ReservedRegs.test(Reg)) continue;
551
David Goodwin7886cd82009-08-29 00:11:13 +0000552 KillIndices[Reg] = Count;
553
554 for (const unsigned *Subreg = TRI->getSubRegisters(Reg);
555 *Subreg; ++Subreg) {
556 KillIndices[*Subreg] = Count;
557 }
558 }
David Goodwin88a589c2009-08-25 17:03:05 +0000559 }
560}
561
Dan Gohman343f0c02008-11-19 23:18:57 +0000562//===----------------------------------------------------------------------===//
563// Top-Down Scheduling
564//===----------------------------------------------------------------------===//
565
566/// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to
567/// the PendingQueue if the count reaches zero. Also update its cycle bound.
David Goodwin557bbe62009-11-20 19:32:48 +0000568void SchedulePostRATDList::ReleaseSucc(SUnit *SU, SDep *SuccEdge) {
Dan Gohman54e4c362008-12-09 22:54:47 +0000569 SUnit *SuccSU = SuccEdge->getSUnit();
Reid Klecknerc277ab02009-09-30 20:15:38 +0000570
Dan Gohman343f0c02008-11-19 23:18:57 +0000571#ifndef NDEBUG
Reid Klecknerc277ab02009-09-30 20:15:38 +0000572 if (SuccSU->NumPredsLeft == 0) {
David Greenee1b21292010-01-05 01:26:01 +0000573 dbgs() << "*** Scheduling failed! ***\n";
Dan Gohman343f0c02008-11-19 23:18:57 +0000574 SuccSU->dump(this);
David Greenee1b21292010-01-05 01:26:01 +0000575 dbgs() << " has been released too many times!\n";
Torok Edwinc23197a2009-07-14 16:55:14 +0000576 llvm_unreachable(0);
Dan Gohman343f0c02008-11-19 23:18:57 +0000577 }
578#endif
Reid Klecknerc277ab02009-09-30 20:15:38 +0000579 --SuccSU->NumPredsLeft;
580
Dan Gohman343f0c02008-11-19 23:18:57 +0000581 // Compute how many cycles it will be before this actually becomes
582 // available. This is the max of the start time of all predecessors plus
583 // their latencies.
David Goodwin557bbe62009-11-20 19:32:48 +0000584 SuccSU->setDepthToAtLeast(SU->getDepth() + SuccEdge->getLatency());
Dan Gohman343f0c02008-11-19 23:18:57 +0000585
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000586 // If all the node's predecessors are scheduled, this node is ready
587 // to be scheduled. Ignore the special ExitSU node.
588 if (SuccSU->NumPredsLeft == 0 && SuccSU != &ExitSU)
Dan Gohman343f0c02008-11-19 23:18:57 +0000589 PendingQueue.push_back(SuccSU);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000590}
591
592/// ReleaseSuccessors - Call ReleaseSucc on each of SU's successors.
David Goodwin557bbe62009-11-20 19:32:48 +0000593void SchedulePostRATDList::ReleaseSuccessors(SUnit *SU) {
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000594 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
David Goodwin4de099d2009-11-03 20:57:50 +0000595 I != E; ++I) {
David Goodwin557bbe62009-11-20 19:32:48 +0000596 ReleaseSucc(SU, &*I);
David Goodwin4de099d2009-11-03 20:57:50 +0000597 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000598}
599
600/// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending
601/// count of its successors. If a successor pending count is zero, add it to
602/// the Available queue.
David Goodwin557bbe62009-11-20 19:32:48 +0000603void SchedulePostRATDList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) {
David Greenee1b21292010-01-05 01:26:01 +0000604 DEBUG(dbgs() << "*** Scheduling [" << CurCycle << "]: ");
Dan Gohman343f0c02008-11-19 23:18:57 +0000605 DEBUG(SU->dump(this));
606
607 Sequence.push_back(SU);
David Goodwin557bbe62009-11-20 19:32:48 +0000608 assert(CurCycle >= SU->getDepth() &&
David Goodwin4de099d2009-11-03 20:57:50 +0000609 "Node scheduled above its depth!");
David Goodwin557bbe62009-11-20 19:32:48 +0000610 SU->setDepthToAtLeast(CurCycle);
Dan Gohman343f0c02008-11-19 23:18:57 +0000611
David Goodwin557bbe62009-11-20 19:32:48 +0000612 ReleaseSuccessors(SU);
Dan Gohman343f0c02008-11-19 23:18:57 +0000613 SU->isScheduled = true;
614 AvailableQueue.ScheduledNode(SU);
615}
616
617/// ListScheduleTopDown - The main loop of list scheduling for top-down
618/// schedulers.
David Goodwin557bbe62009-11-20 19:32:48 +0000619void SchedulePostRATDList::ListScheduleTopDown() {
Dan Gohman343f0c02008-11-19 23:18:57 +0000620 unsigned CurCycle = 0;
David Goodwin4de099d2009-11-03 20:57:50 +0000621
622 // We're scheduling top-down but we're visiting the regions in
623 // bottom-up order, so we don't know the hazards at the start of a
624 // region. So assume no hazards (this should usually be ok as most
625 // blocks are a single region).
626 HazardRec->Reset();
627
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000628 // Release any successors of the special Entry node.
David Goodwin557bbe62009-11-20 19:32:48 +0000629 ReleaseSuccessors(&EntrySU);
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000630
David Goodwin557bbe62009-11-20 19:32:48 +0000631 // Add all leaves to Available queue.
Dan Gohman343f0c02008-11-19 23:18:57 +0000632 for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
633 // It is available if it has no predecessors.
David Goodwin4de099d2009-11-03 20:57:50 +0000634 bool available = SUnits[i].Preds.empty();
David Goodwin4de099d2009-11-03 20:57:50 +0000635 if (available) {
Dan Gohman343f0c02008-11-19 23:18:57 +0000636 AvailableQueue.push(&SUnits[i]);
637 SUnits[i].isAvailable = true;
638 }
639 }
Dan Gohman9e64bbb2009-02-10 23:27:53 +0000640
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000641 // In any cycle where we can't schedule any instructions, we must
642 // stall or emit a noop, depending on the target.
Benjamin Kramerbe441c02009-09-06 12:10:17 +0000643 bool CycleHasInsts = false;
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000644
Dan Gohman343f0c02008-11-19 23:18:57 +0000645 // While Available queue is not empty, grab the node with the highest
646 // priority. If it is not ready put it back. Schedule the node.
Dan Gohman2836c282009-01-16 01:33:36 +0000647 std::vector<SUnit*> NotReady;
Dan Gohman343f0c02008-11-19 23:18:57 +0000648 Sequence.reserve(SUnits.size());
649 while (!AvailableQueue.empty() || !PendingQueue.empty()) {
650 // Check to see if any of the pending instructions are ready to issue. If
651 // so, add them to the available queue.
Dan Gohman3f237442008-12-16 03:25:46 +0000652 unsigned MinDepth = ~0u;
Dan Gohman343f0c02008-11-19 23:18:57 +0000653 for (unsigned i = 0, e = PendingQueue.size(); i != e; ++i) {
David Goodwin557bbe62009-11-20 19:32:48 +0000654 if (PendingQueue[i]->getDepth() <= CurCycle) {
Dan Gohman343f0c02008-11-19 23:18:57 +0000655 AvailableQueue.push(PendingQueue[i]);
656 PendingQueue[i]->isAvailable = true;
657 PendingQueue[i] = PendingQueue.back();
658 PendingQueue.pop_back();
659 --i; --e;
David Goodwin557bbe62009-11-20 19:32:48 +0000660 } else if (PendingQueue[i]->getDepth() < MinDepth)
661 MinDepth = PendingQueue[i]->getDepth();
Dan Gohman343f0c02008-11-19 23:18:57 +0000662 }
David Goodwinc93d8372009-08-11 17:35:23 +0000663
David Greenee1b21292010-01-05 01:26:01 +0000664 DEBUG(dbgs() << "\n*** Examining Available\n";
David Goodwin7cd01182009-08-11 17:56:42 +0000665 LatencyPriorityQueue q = AvailableQueue;
666 while (!q.empty()) {
667 SUnit *su = q.pop();
David Greenee1b21292010-01-05 01:26:01 +0000668 dbgs() << "Height " << su->getHeight() << ": ";
David Goodwin7cd01182009-08-11 17:56:42 +0000669 su->dump(this);
670 });
David Goodwinc93d8372009-08-11 17:35:23 +0000671
Dan Gohman2836c282009-01-16 01:33:36 +0000672 SUnit *FoundSUnit = 0;
Dan Gohman2836c282009-01-16 01:33:36 +0000673 bool HasNoopHazards = false;
674 while (!AvailableQueue.empty()) {
675 SUnit *CurSUnit = AvailableQueue.pop();
676
677 ScheduleHazardRecognizer::HazardType HT =
678 HazardRec->getHazardType(CurSUnit);
679 if (HT == ScheduleHazardRecognizer::NoHazard) {
680 FoundSUnit = CurSUnit;
681 break;
682 }
683
684 // Remember if this is a noop hazard.
685 HasNoopHazards |= HT == ScheduleHazardRecognizer::NoopHazard;
686
687 NotReady.push_back(CurSUnit);
688 }
689
690 // Add the nodes that aren't ready back onto the available list.
691 if (!NotReady.empty()) {
692 AvailableQueue.push_all(NotReady);
693 NotReady.clear();
694 }
695
David Goodwin4de099d2009-11-03 20:57:50 +0000696 // If we found a node to schedule...
Dan Gohman343f0c02008-11-19 23:18:57 +0000697 if (FoundSUnit) {
David Goodwin4de099d2009-11-03 20:57:50 +0000698 // ... schedule the node...
David Goodwin557bbe62009-11-20 19:32:48 +0000699 ScheduleNodeTopDown(FoundSUnit, CurCycle);
Dan Gohman2836c282009-01-16 01:33:36 +0000700 HazardRec->EmitInstruction(FoundSUnit);
Benjamin Kramerbe441c02009-09-06 12:10:17 +0000701 CycleHasInsts = true;
Dan Gohman343f0c02008-11-19 23:18:57 +0000702
David Goodwind94a4e52009-08-10 15:55:25 +0000703 // If we are using the target-specific hazards, then don't
704 // advance the cycle time just because we schedule a node. If
705 // the target allows it we can schedule multiple nodes in the
706 // same cycle.
707 if (!EnablePostRAHazardAvoidance) {
708 if (FoundSUnit->Latency) // Don't increment CurCycle for pseudo-ops!
709 ++CurCycle;
710 }
Dan Gohman2836c282009-01-16 01:33:36 +0000711 } else {
Benjamin Kramerbe441c02009-09-06 12:10:17 +0000712 if (CycleHasInsts) {
David Greenee1b21292010-01-05 01:26:01 +0000713 DEBUG(dbgs() << "*** Finished cycle " << CurCycle << '\n');
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000714 HazardRec->AdvanceCycle();
715 } else if (!HasNoopHazards) {
716 // Otherwise, we have a pipeline stall, but no other problem,
717 // just advance the current cycle and try again.
David Greenee1b21292010-01-05 01:26:01 +0000718 DEBUG(dbgs() << "*** Stall in cycle " << CurCycle << '\n');
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000719 HazardRec->AdvanceCycle();
David Goodwin557bbe62009-11-20 19:32:48 +0000720 ++NumStalls;
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000721 } else {
722 // Otherwise, we have no instructions to issue and we have instructions
723 // that will fault if we don't do this right. This is the case for
724 // processors without pipeline interlocks and other cases.
David Greenee1b21292010-01-05 01:26:01 +0000725 DEBUG(dbgs() << "*** Emitting noop in cycle " << CurCycle << '\n');
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000726 HazardRec->EmitNoop();
727 Sequence.push_back(0); // NULL here means noop
David Goodwin557bbe62009-11-20 19:32:48 +0000728 ++NumNoops;
David Goodwin2ffb0ce2009-08-12 21:47:46 +0000729 }
730
Dan Gohman2836c282009-01-16 01:33:36 +0000731 ++CurCycle;
Benjamin Kramerbe441c02009-09-06 12:10:17 +0000732 CycleHasInsts = false;
Dan Gohman343f0c02008-11-19 23:18:57 +0000733 }
734 }
735
736#ifndef NDEBUG
Dan Gohmana1e6d362008-11-20 01:26:25 +0000737 VerifySchedule(/*isBottomUp=*/false);
Dan Gohman343f0c02008-11-19 23:18:57 +0000738#endif
739}
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000740
741//===----------------------------------------------------------------------===//
742// Public Constructor Functions
743//===----------------------------------------------------------------------===//
744
Evan Chengfa163542009-10-16 21:06:15 +0000745FunctionPass *llvm::createPostRAScheduler(CodeGenOpt::Level OptLevel) {
746 return new PostRAScheduler(OptLevel);
Dale Johannesene7e7d0d2007-07-13 17:13:54 +0000747}