| Dale Johannesen | 4dc35db | 2007-07-13 17:31:29 +0000 | [diff] [blame] | 1 | //===----- SchedulePostRAList.cpp - list scheduler ------------------------===// | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 2 | // | 
|  | 3 | //                     The LLVM Compiler Infrastructure | 
|  | 4 | // | 
| Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source | 
|  | 6 | // License. See LICENSE.TXT for details. | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 7 | // | 
|  | 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 |  | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/Passes.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 22 | #include "AggressiveAntiDepBreaker.h" | 
|  | 23 | #include "AntiDepBreaker.h" | 
|  | 24 | #include "CriticalAntiDepBreaker.h" | 
|  | 25 | #include "llvm/ADT/BitVector.h" | 
|  | 26 | #include "llvm/ADT/Statistic.h" | 
|  | 27 | #include "llvm/Analysis/AliasAnalysis.h" | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/LatencyPriorityQueue.h" | 
| Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineDominators.h" | 
| David Goodwin | be3039e | 2009-10-01 19:45:32 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineFrameInfo.h" | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineFunctionPass.h" | 
| Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineLoopInfo.h" | 
| Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/MachineRegisterInfo.h" | 
| Andrew Trick | 05ff466 | 2012-06-06 20:29:31 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/RegisterClassInfo.h" | 
| Andrew Trick | 9a0c583 | 2012-03-07 23:01:06 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/ScheduleDAGInstrs.h" | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/ScheduleHazardRecognizer.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/SchedulerRegistry.h" | 
| David Goodwin | e056d10 | 2009-10-26 22:31:16 +0000 | [diff] [blame] | 38 | #include "llvm/Support/CommandLine.h" | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 39 | #include "llvm/Support/Debug.h" | 
| Torok Edwin | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 40 | #include "llvm/Support/ErrorHandling.h" | 
| David Goodwin | f20236a | 2009-08-11 01:44:26 +0000 | [diff] [blame] | 41 | #include "llvm/Support/raw_ostream.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 42 | #include "llvm/Target/TargetInstrInfo.h" | 
|  | 43 | #include "llvm/Target/TargetLowering.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 44 | #include "llvm/Target/TargetRegisterInfo.h" | 
|  | 45 | #include "llvm/Target/TargetSubtargetInfo.h" | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 46 | using namespace llvm; | 
|  | 47 |  | 
| Chandler Carruth | 1b9dde0 | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 48 | #define DEBUG_TYPE "post-RA-sched" | 
|  | 49 |  | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 50 | STATISTIC(NumNoops, "Number of noops inserted"); | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 51 | STATISTIC(NumStalls, "Number of pipeline stalls"); | 
| David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 52 | STATISTIC(NumFixedAnti, "Number of fixed anti-dependencies"); | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 53 |  | 
| David Goodwin | 9a051a5 | 2009-10-01 21:46:35 +0000 | [diff] [blame] | 54 | // Post-RA scheduling is enabled with | 
| Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 55 | // TargetSubtargetInfo.enablePostRAScheduler(). This flag can be used to | 
| David Goodwin | 9a051a5 | 2009-10-01 21:46:35 +0000 | [diff] [blame] | 56 | // override the target. | 
|  | 57 | static cl::opt<bool> | 
|  | 58 | EnablePostRAScheduler("post-RA-scheduler", | 
|  | 59 | cl::desc("Enable scheduling after register allocation"), | 
| David Goodwin | 1cc6dd9 | 2009-10-01 22:19:57 +0000 | [diff] [blame] | 60 | cl::init(false), cl::Hidden); | 
| David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 61 | static cl::opt<std::string> | 
| Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 62 | EnableAntiDepBreaking("break-anti-dependencies", | 
| David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 63 | cl::desc("Break post-RA scheduling anti-dependencies: " | 
|  | 64 | "\"critical\", \"all\", or \"none\""), | 
|  | 65 | cl::init("none"), cl::Hidden); | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 66 |  | 
| David Goodwin | 7f65169 | 2009-09-01 18:34:03 +0000 | [diff] [blame] | 67 | // If DebugDiv > 0 then only schedule MBB with (ID % DebugDiv) == DebugMod | 
|  | 68 | static cl::opt<int> | 
|  | 69 | DebugDiv("postra-sched-debugdiv", | 
|  | 70 | cl::desc("Debug control MBBs that are scheduled"), | 
|  | 71 | cl::init(0), cl::Hidden); | 
|  | 72 | static cl::opt<int> | 
|  | 73 | DebugMod("postra-sched-debugmod", | 
|  | 74 | cl::desc("Debug control MBBs that are scheduled"), | 
|  | 75 | cl::init(0), cl::Hidden); | 
|  | 76 |  | 
| David Goodwin | 661ea98 | 2009-10-26 19:41:00 +0000 | [diff] [blame] | 77 | AntiDepBreaker::~AntiDepBreaker() { } | 
|  | 78 |  | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 79 | namespace { | 
| Nick Lewycky | 02d5f77 | 2009-10-25 06:33:48 +0000 | [diff] [blame] | 80 | class PostRAScheduler : public MachineFunctionPass { | 
| Evan Cheng | 2d51c7c | 2010-06-18 23:09:54 +0000 | [diff] [blame] | 81 | const TargetInstrInfo *TII; | 
| Jakob Stoklund Olesen | 4f5f84c | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 82 | RegisterClassInfo RegClassInfo; | 
| Dan Gohman | 87b02d5 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 83 |  | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 84 | public: | 
|  | 85 | static char ID; | 
| Andrew Trick | df7e376 | 2012-02-08 21:22:53 +0000 | [diff] [blame] | 86 | PostRAScheduler() : MachineFunctionPass(ID) {} | 
| Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 87 |  | 
| Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 88 | void getAnalysisUsage(AnalysisUsage &AU) const override { | 
| Dan Gohman | 0402315 | 2009-07-31 23:37:33 +0000 | [diff] [blame] | 89 | AU.setPreservesCFG(); | 
| Dan Gohman | 87b02d5 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 90 | AU.addRequired<AliasAnalysis>(); | 
| Andrew Trick | df7e376 | 2012-02-08 21:22:53 +0000 | [diff] [blame] | 91 | AU.addRequired<TargetPassConfig>(); | 
| Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 92 | AU.addRequired<MachineDominatorTree>(); | 
|  | 93 | AU.addPreserved<MachineDominatorTree>(); | 
|  | 94 | AU.addRequired<MachineLoopInfo>(); | 
|  | 95 | AU.addPreserved<MachineLoopInfo>(); | 
|  | 96 | MachineFunctionPass::getAnalysisUsage(AU); | 
|  | 97 | } | 
|  | 98 |  | 
| Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 99 | bool runOnMachineFunction(MachineFunction &Fn) override; | 
| NAKAMURA Takumi | f51a34e | 2014-10-29 15:23:11 +0000 | [diff] [blame] | 100 |  | 
| Sanjay Patel | a2f658d | 2014-07-15 22:39:58 +0000 | [diff] [blame] | 101 | bool enablePostRAScheduler( | 
|  | 102 | const TargetSubtargetInfo &ST, CodeGenOpt::Level OptLevel, | 
|  | 103 | TargetSubtargetInfo::AntiDepBreakMode &Mode, | 
|  | 104 | TargetSubtargetInfo::RegClassVector &CriticalPathRCs) const; | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 105 | }; | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 106 | char PostRAScheduler::ID = 0; | 
|  | 107 |  | 
| Nick Lewycky | 02d5f77 | 2009-10-25 06:33:48 +0000 | [diff] [blame] | 108 | class SchedulePostRATDList : public ScheduleDAGInstrs { | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 109 | /// AvailableQueue - The priority queue to use for the available SUnits. | 
| Dan Gohman | 682a2d1 | 2009-10-21 01:44:44 +0000 | [diff] [blame] | 110 | /// | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 111 | LatencyPriorityQueue AvailableQueue; | 
| Jim Grosbach | d772bde | 2010-05-14 21:19:48 +0000 | [diff] [blame] | 112 |  | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 113 | /// PendingQueue - This contains all of the instructions whose operands have | 
|  | 114 | /// been issued, but their results are not ready yet (due to the latency of | 
|  | 115 | /// the operation).  Once the operands becomes available, the instruction is | 
|  | 116 | /// added to the AvailableQueue. | 
|  | 117 | std::vector<SUnit*> PendingQueue; | 
|  | 118 |  | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 119 | /// HazardRec - The hazard recognizer to use. | 
|  | 120 | ScheduleHazardRecognizer *HazardRec; | 
|  | 121 |  | 
| David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 122 | /// AntiDepBreak - Anti-dependence breaking object, or NULL if none | 
|  | 123 | AntiDepBreaker *AntiDepBreak; | 
|  | 124 |  | 
| Dan Gohman | 87b02d5 | 2009-10-09 23:27:56 +0000 | [diff] [blame] | 125 | /// AA - AliasAnalysis for making memory reference queries. | 
|  | 126 | AliasAnalysis *AA; | 
|  | 127 |  | 
| Andrew Trick | 60cf03e | 2012-03-07 05:21:52 +0000 | [diff] [blame] | 128 | /// The schedule. Null SUnit*'s represent noop instructions. | 
|  | 129 | std::vector<SUnit*> Sequence; | 
|  | 130 |  | 
| Andrew Trick | a53e101 | 2013-08-23 17:48:33 +0000 | [diff] [blame] | 131 | /// The index in BB of RegionEnd. | 
|  | 132 | /// | 
|  | 133 | /// This is the instruction number from the top of the current block, not | 
|  | 134 | /// the SlotIndex. It is only used by the AntiDepBreaker. | 
|  | 135 | unsigned EndIndex; | 
|  | 136 |  | 
| Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 137 | public: | 
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 138 | SchedulePostRATDList( | 
| Alexey Samsonov | ea0aee6 | 2014-08-20 20:57:26 +0000 | [diff] [blame] | 139 | MachineFunction &MF, MachineLoopInfo &MLI, AliasAnalysis *AA, | 
|  | 140 | const RegisterClassInfo &, | 
|  | 141 | TargetSubtargetInfo::AntiDepBreakMode AntiDepMode, | 
|  | 142 | SmallVectorImpl<const TargetRegisterClass *> &CriticalPathRCs); | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 143 |  | 
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 144 | ~SchedulePostRATDList(); | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 145 |  | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 146 | /// startBlock - Initialize register live-range state for scheduling in | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 147 | /// this block. | 
|  | 148 | /// | 
| Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 149 | void startBlock(MachineBasicBlock *BB) override; | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 150 |  | 
| Andrew Trick | a53e101 | 2013-08-23 17:48:33 +0000 | [diff] [blame] | 151 | // Set the index of RegionEnd within the current BB. | 
|  | 152 | void setEndIndex(unsigned EndIdx) { EndIndex = EndIdx; } | 
|  | 153 |  | 
| Andrew Trick | 60cf03e | 2012-03-07 05:21:52 +0000 | [diff] [blame] | 154 | /// Initialize the scheduler state for the next scheduling region. | 
| Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 155 | void enterRegion(MachineBasicBlock *bb, | 
|  | 156 | MachineBasicBlock::iterator begin, | 
|  | 157 | MachineBasicBlock::iterator end, | 
|  | 158 | unsigned regioninstrs) override; | 
| Andrew Trick | 60cf03e | 2012-03-07 05:21:52 +0000 | [diff] [blame] | 159 |  | 
|  | 160 | /// Notify that the scheduler has finished scheduling the current region. | 
| Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 161 | void exitRegion() override; | 
| Andrew Trick | 60cf03e | 2012-03-07 05:21:52 +0000 | [diff] [blame] | 162 |  | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 163 | /// Schedule - Schedule the instruction range using list scheduling. | 
|  | 164 | /// | 
| Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 165 | void schedule() override; | 
| Jim Grosbach | d772bde | 2010-05-14 21:19:48 +0000 | [diff] [blame] | 166 |  | 
| Andrew Trick | e932bb7 | 2012-03-07 05:21:44 +0000 | [diff] [blame] | 167 | void EmitSchedule(); | 
|  | 168 |  | 
| Dan Gohman | 682a2d1 | 2009-10-21 01:44:44 +0000 | [diff] [blame] | 169 | /// Observe - Update liveness information to account for the current | 
|  | 170 | /// instruction, which will not be scheduled. | 
|  | 171 | /// | 
|  | 172 | void Observe(MachineInstr *MI, unsigned Count); | 
|  | 173 |  | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 174 | /// finishBlock - Clean up register live-range state. | 
| Dan Gohman | 682a2d1 | 2009-10-21 01:44:44 +0000 | [diff] [blame] | 175 | /// | 
| Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 176 | void finishBlock() override; | 
| Dan Gohman | 682a2d1 | 2009-10-21 01:44:44 +0000 | [diff] [blame] | 177 |  | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 178 | private: | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 179 | void ReleaseSucc(SUnit *SU, SDep *SuccEdge); | 
|  | 180 | void ReleaseSuccessors(SUnit *SU); | 
|  | 181 | void ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle); | 
|  | 182 | void ListScheduleTopDown(); | 
| Jim Grosbach | d772bde | 2010-05-14 21:19:48 +0000 | [diff] [blame] | 183 |  | 
| Andrew Trick | edee68c | 2012-03-07 05:21:40 +0000 | [diff] [blame] | 184 | void dumpSchedule() const; | 
| Hal Finkel | 4fd3b1d | 2013-12-11 22:33:43 +0000 | [diff] [blame] | 185 | void emitNoop(unsigned CurCycle); | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 186 | }; | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 187 | } | 
|  | 188 |  | 
| Andrew Trick | 1fa5bcb | 2012-02-08 21:23:13 +0000 | [diff] [blame] | 189 | char &llvm::PostRASchedulerID = PostRAScheduler::ID; | 
|  | 190 |  | 
|  | 191 | INITIALIZE_PASS(PostRAScheduler, "post-RA-sched", | 
|  | 192 | "Post RA top-down list latency scheduler", false, false) | 
|  | 193 |  | 
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 194 | SchedulePostRATDList::SchedulePostRATDList( | 
| Alexey Samsonov | ea0aee6 | 2014-08-20 20:57:26 +0000 | [diff] [blame] | 195 | MachineFunction &MF, MachineLoopInfo &MLI, AliasAnalysis *AA, | 
|  | 196 | const RegisterClassInfo &RCI, | 
|  | 197 | TargetSubtargetInfo::AntiDepBreakMode AntiDepMode, | 
|  | 198 | SmallVectorImpl<const TargetRegisterClass *> &CriticalPathRCs) | 
|  | 199 | : ScheduleDAGInstrs(MF, &MLI, /*IsPostRA=*/true), AA(AA), EndIndex(0) { | 
| Andrew Trick | 6b104f8 | 2013-12-28 21:56:55 +0000 | [diff] [blame] | 200 |  | 
| Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 201 | const InstrItineraryData *InstrItins = | 
| Eric Christopher | b66367a | 2014-10-14 07:17:23 +0000 | [diff] [blame] | 202 | MF.getSubtarget().getInstrItineraryData(); | 
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 203 | HazardRec = | 
| Eric Christopher | b66367a | 2014-10-14 07:17:23 +0000 | [diff] [blame] | 204 | MF.getSubtarget().getInstrInfo()->CreateTargetPostRAHazardRecognizer( | 
| Eric Christopher | d913448 | 2014-08-04 21:25:23 +0000 | [diff] [blame] | 205 | InstrItins, this); | 
| Preston Gurd | 9a09147 | 2012-04-23 21:39:35 +0000 | [diff] [blame] | 206 |  | 
|  | 207 | assert((AntiDepMode == TargetSubtargetInfo::ANTIDEP_NONE || | 
|  | 208 | MRI.tracksLiveness()) && | 
|  | 209 | "Live-ins must be accurate for anti-dependency breaking"); | 
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 210 | AntiDepBreak = | 
| Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 211 | ((AntiDepMode == TargetSubtargetInfo::ANTIDEP_ALL) ? | 
| Jakob Stoklund Olesen | 4f5f84c | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 212 | (AntiDepBreaker *)new AggressiveAntiDepBreaker(MF, RCI, CriticalPathRCs) : | 
| Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 213 | ((AntiDepMode == TargetSubtargetInfo::ANTIDEP_CRITICAL) ? | 
| Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 214 | (AntiDepBreaker *)new CriticalAntiDepBreaker(MF, RCI) : nullptr)); | 
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 215 | } | 
|  | 216 |  | 
|  | 217 | SchedulePostRATDList::~SchedulePostRATDList() { | 
|  | 218 | delete HazardRec; | 
|  | 219 | delete AntiDepBreak; | 
|  | 220 | } | 
|  | 221 |  | 
| Andrew Trick | 60cf03e | 2012-03-07 05:21:52 +0000 | [diff] [blame] | 222 | /// Initialize state associated with the next scheduling region. | 
|  | 223 | void SchedulePostRATDList::enterRegion(MachineBasicBlock *bb, | 
|  | 224 | MachineBasicBlock::iterator begin, | 
|  | 225 | MachineBasicBlock::iterator end, | 
| Andrew Trick | a53e101 | 2013-08-23 17:48:33 +0000 | [diff] [blame] | 226 | unsigned regioninstrs) { | 
|  | 227 | ScheduleDAGInstrs::enterRegion(bb, begin, end, regioninstrs); | 
| Andrew Trick | 60cf03e | 2012-03-07 05:21:52 +0000 | [diff] [blame] | 228 | Sequence.clear(); | 
|  | 229 | } | 
|  | 230 |  | 
|  | 231 | /// Print the schedule before exiting the region. | 
|  | 232 | void SchedulePostRATDList::exitRegion() { | 
|  | 233 | DEBUG({ | 
|  | 234 | dbgs() << "*** Final schedule ***\n"; | 
|  | 235 | dumpSchedule(); | 
|  | 236 | dbgs() << '\n'; | 
|  | 237 | }); | 
|  | 238 | ScheduleDAGInstrs::exitRegion(); | 
|  | 239 | } | 
|  | 240 |  | 
| Manman Ren | 19f49ac | 2012-09-11 22:23:19 +0000 | [diff] [blame] | 241 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | 
| Andrew Trick | edee68c | 2012-03-07 05:21:40 +0000 | [diff] [blame] | 242 | /// dumpSchedule - dump the scheduled Sequence. | 
|  | 243 | void SchedulePostRATDList::dumpSchedule() const { | 
|  | 244 | for (unsigned i = 0, e = Sequence.size(); i != e; i++) { | 
|  | 245 | if (SUnit *SU = Sequence[i]) | 
|  | 246 | SU->dump(this); | 
|  | 247 | else | 
|  | 248 | dbgs() << "**** NOOP ****\n"; | 
|  | 249 | } | 
|  | 250 | } | 
| Manman Ren | 742534c | 2012-09-06 19:06:06 +0000 | [diff] [blame] | 251 | #endif | 
| Andrew Trick | edee68c | 2012-03-07 05:21:40 +0000 | [diff] [blame] | 252 |  | 
| Sanjay Patel | a2f658d | 2014-07-15 22:39:58 +0000 | [diff] [blame] | 253 | bool PostRAScheduler::enablePostRAScheduler( | 
|  | 254 | const TargetSubtargetInfo &ST, | 
|  | 255 | CodeGenOpt::Level OptLevel, | 
|  | 256 | TargetSubtargetInfo::AntiDepBreakMode &Mode, | 
|  | 257 | TargetSubtargetInfo::RegClassVector &CriticalPathRCs) const { | 
|  | 258 | Mode = ST.getAntiDepBreakMode(); | 
|  | 259 | ST.getCriticalPathRCs(CriticalPathRCs); | 
|  | 260 | return ST.enablePostMachineScheduler() && | 
|  | 261 | OptLevel >= ST.getOptLevelToEnablePostRAScheduler(); | 
|  | 262 | } | 
|  | 263 |  | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 264 | bool PostRAScheduler::runOnMachineFunction(MachineFunction &Fn) { | 
| Paul Robinson | 7c99ec5 | 2014-03-31 17:43:35 +0000 | [diff] [blame] | 265 | if (skipOptnoneFunction(*Fn.getFunction())) | 
|  | 266 | return false; | 
|  | 267 |  | 
| Eric Christopher | fc6de42 | 2014-08-05 02:39:49 +0000 | [diff] [blame] | 268 | TII = Fn.getSubtarget().getInstrInfo(); | 
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 269 | MachineLoopInfo &MLI = getAnalysis<MachineLoopInfo>(); | 
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 270 | AliasAnalysis *AA = &getAnalysis<AliasAnalysis>(); | 
| Andrew Trick | df7e376 | 2012-02-08 21:22:53 +0000 | [diff] [blame] | 271 | TargetPassConfig *PassConfig = &getAnalysis<TargetPassConfig>(); | 
|  | 272 |  | 
| Jakob Stoklund Olesen | 4f5f84c | 2011-06-16 21:56:21 +0000 | [diff] [blame] | 273 | RegClassInfo.runOnMachineFunction(Fn); | 
| Dan Gohman | 26e9b89 | 2009-10-10 00:15:38 +0000 | [diff] [blame] | 274 |  | 
| David Goodwin | 9a051a5 | 2009-10-01 21:46:35 +0000 | [diff] [blame] | 275 | // Check for explicit enable/disable of post-ra scheduling. | 
| Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 276 | TargetSubtargetInfo::AntiDepBreakMode AntiDepMode = | 
|  | 277 | TargetSubtargetInfo::ANTIDEP_NONE; | 
| Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 278 | SmallVector<const TargetRegisterClass*, 4> CriticalPathRCs; | 
| David Goodwin | 9a051a5 | 2009-10-01 21:46:35 +0000 | [diff] [blame] | 279 | if (EnablePostRAScheduler.getPosition() > 0) { | 
|  | 280 | if (!EnablePostRAScheduler) | 
| Evan Cheng | 8b61476 | 2009-10-16 06:10:34 +0000 | [diff] [blame] | 281 | return false; | 
| David Goodwin | 9a051a5 | 2009-10-01 21:46:35 +0000 | [diff] [blame] | 282 | } else { | 
| Evan Cheng | 8b61476 | 2009-10-16 06:10:34 +0000 | [diff] [blame] | 283 | // Check that post-RA scheduling is enabled for this target. | 
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 284 | // This may upgrade the AntiDepMode. | 
| Eric Christopher | 3d4276f | 2015-01-27 07:31:29 +0000 | [diff] [blame] | 285 | if (!enablePostRAScheduler(Fn.getSubtarget(), PassConfig->getOptLevel(), | 
| Sanjay Patel | a2f658d | 2014-07-15 22:39:58 +0000 | [diff] [blame] | 286 | AntiDepMode, CriticalPathRCs)) | 
| Evan Cheng | 8b61476 | 2009-10-16 06:10:34 +0000 | [diff] [blame] | 287 | return false; | 
| David Goodwin | 9a051a5 | 2009-10-01 21:46:35 +0000 | [diff] [blame] | 288 | } | 
| David Goodwin | 17199b5 | 2009-09-30 00:10:16 +0000 | [diff] [blame] | 289 |  | 
| David Goodwin | 02ad4cb | 2009-10-22 23:19:17 +0000 | [diff] [blame] | 290 | // Check for antidep breaking override... | 
|  | 291 | if (EnableAntiDepBreaking.getPosition() > 0) { | 
| Evan Cheng | 0d639a2 | 2011-07-01 21:01:15 +0000 | [diff] [blame] | 292 | AntiDepMode = (EnableAntiDepBreaking == "all") | 
|  | 293 | ? TargetSubtargetInfo::ANTIDEP_ALL | 
|  | 294 | : ((EnableAntiDepBreaking == "critical") | 
|  | 295 | ? TargetSubtargetInfo::ANTIDEP_CRITICAL | 
|  | 296 | : TargetSubtargetInfo::ANTIDEP_NONE); | 
| David Goodwin | 02ad4cb | 2009-10-22 23:19:17 +0000 | [diff] [blame] | 297 | } | 
|  | 298 |  | 
| David Greene | aa8ce38 | 2010-01-05 01:26:01 +0000 | [diff] [blame] | 299 | DEBUG(dbgs() << "PostRAScheduler\n"); | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 300 |  | 
| Alexey Samsonov | ea0aee6 | 2014-08-20 20:57:26 +0000 | [diff] [blame] | 301 | SchedulePostRATDList Scheduler(Fn, MLI, AA, RegClassInfo, AntiDepMode, | 
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 302 | CriticalPathRCs); | 
| Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 303 |  | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 304 | // Loop over all of the basic blocks | 
|  | 305 | for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end(); | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 306 | MBB != MBBe; ++MBB) { | 
| David Goodwin | 7f65169 | 2009-09-01 18:34:03 +0000 | [diff] [blame] | 307 | #ifndef NDEBUG | 
|  | 308 | // If DebugDiv > 0 then only schedule MBB with (ID % DebugDiv) == DebugMod | 
|  | 309 | if (DebugDiv > 0) { | 
|  | 310 | static int bbcnt = 0; | 
|  | 311 | if (bbcnt++ % DebugDiv != DebugMod) | 
|  | 312 | continue; | 
| Craig Topper | a538d83 | 2012-08-22 06:07:19 +0000 | [diff] [blame] | 313 | dbgs() << "*** DEBUG scheduling " << Fn.getName() | 
| Benjamin Kramer | 1f97a5a | 2011-11-15 16:27:03 +0000 | [diff] [blame] | 314 | << ":BB#" << MBB->getNumber() << " ***\n"; | 
| David Goodwin | 7f65169 | 2009-09-01 18:34:03 +0000 | [diff] [blame] | 315 | } | 
|  | 316 | #endif | 
|  | 317 |  | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 318 | // Initialize register live-range state for scheduling in this block. | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 319 | Scheduler.startBlock(MBB); | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 320 |  | 
| Dan Gohman | 5f8a259 | 2009-01-16 22:10:20 +0000 | [diff] [blame] | 321 | // Schedule each sequence of instructions not interrupted by a label | 
|  | 322 | // or anything else that effectively needs to shut down scheduling. | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 323 | MachineBasicBlock::iterator Current = MBB->end(); | 
| Dan Gohman | dfaf646 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 324 | unsigned Count = MBB->size(), CurrentCount = Count; | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 325 | for (MachineBasicBlock::iterator I = Current; I != MBB->begin(); ) { | 
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 326 | MachineInstr *MI = std::prev(I); | 
| Andrew Trick | a53e101 | 2013-08-23 17:48:33 +0000 | [diff] [blame] | 327 | --Count; | 
| Jakob Stoklund Olesen | a793a59 | 2012-02-23 17:54:21 +0000 | [diff] [blame] | 328 | // Calls are not scheduling boundaries before register allocation, but | 
|  | 329 | // post-ra we don't gain anything by scheduling across calls since we | 
|  | 330 | // don't need to worry about register pressure. | 
|  | 331 | if (MI->isCall() || TII->isSchedulingBoundary(MI, MBB, Fn)) { | 
| Andrew Trick | a53e101 | 2013-08-23 17:48:33 +0000 | [diff] [blame] | 332 | Scheduler.enterRegion(MBB, I, Current, CurrentCount - Count); | 
|  | 333 | Scheduler.setEndIndex(CurrentCount); | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 334 | Scheduler.schedule(); | 
| Andrew Trick | 60cf03e | 2012-03-07 05:21:52 +0000 | [diff] [blame] | 335 | Scheduler.exitRegion(); | 
| Dan Gohman | 25c1653 | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 336 | Scheduler.EmitSchedule(); | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 337 | Current = MI; | 
| Andrew Trick | a53e101 | 2013-08-23 17:48:33 +0000 | [diff] [blame] | 338 | CurrentCount = Count; | 
| Dan Gohman | 64613ac | 2009-03-10 18:10:43 +0000 | [diff] [blame] | 339 | Scheduler.Observe(MI, CurrentCount); | 
| Dan Gohman | 5f8a259 | 2009-01-16 22:10:20 +0000 | [diff] [blame] | 340 | } | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 341 | I = MI; | 
| Evan Cheng | 7fae11b | 2011-12-14 02:11:42 +0000 | [diff] [blame] | 342 | if (MI->isBundle()) | 
|  | 343 | Count -= MI->getBundleSize(); | 
| Dan Gohman | d564353 | 2009-02-03 18:57:45 +0000 | [diff] [blame] | 344 | } | 
| Dan Gohman | dfaf646 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 345 | assert(Count == 0 && "Instruction count mismatch!"); | 
| Duncan Sands | be69d60 | 2009-03-11 09:04:34 +0000 | [diff] [blame] | 346 | assert((MBB->begin() == Current || CurrentCount != 0) && | 
| Dan Gohman | 64613ac | 2009-03-10 18:10:43 +0000 | [diff] [blame] | 347 | "Instruction count mismatch!"); | 
| Andrew Trick | 60cf03e | 2012-03-07 05:21:52 +0000 | [diff] [blame] | 348 | Scheduler.enterRegion(MBB, MBB->begin(), Current, CurrentCount); | 
| Andrew Trick | a53e101 | 2013-08-23 17:48:33 +0000 | [diff] [blame] | 349 | Scheduler.setEndIndex(CurrentCount); | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 350 | Scheduler.schedule(); | 
| Andrew Trick | 60cf03e | 2012-03-07 05:21:52 +0000 | [diff] [blame] | 351 | Scheduler.exitRegion(); | 
| Dan Gohman | 25c1653 | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 352 | Scheduler.EmitSchedule(); | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 353 |  | 
|  | 354 | // Clean up register live-range state. | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 355 | Scheduler.finishBlock(); | 
| David Goodwin | ae6bc82 | 2009-08-25 17:03:05 +0000 | [diff] [blame] | 356 |  | 
| David Goodwin | 6c08cfc | 2009-09-03 22:15:25 +0000 | [diff] [blame] | 357 | // Update register kills | 
| Andrew Trick | 6b104f8 | 2013-12-28 21:56:55 +0000 | [diff] [blame] | 358 | Scheduler.fixupKills(MBB); | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 359 | } | 
| Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 360 |  | 
|  | 361 | return true; | 
|  | 362 | } | 
| Jim Grosbach | d772bde | 2010-05-14 21:19:48 +0000 | [diff] [blame] | 363 |  | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 364 | /// StartBlock - Initialize register live-range state for scheduling in | 
|  | 365 | /// this block. | 
| Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 366 | /// | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 367 | void SchedulePostRATDList::startBlock(MachineBasicBlock *BB) { | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 368 | // Call the superclass. | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 369 | ScheduleDAGInstrs::startBlock(BB); | 
| Dan Gohman | ad2134d | 2008-11-25 00:52:40 +0000 | [diff] [blame] | 370 |  | 
| David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 371 | // Reset the hazard recognizer and anti-dep breaker. | 
| David Goodwin | 6021b4d | 2009-08-10 15:55:25 +0000 | [diff] [blame] | 372 | HazardRec->Reset(); | 
| Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 373 | if (AntiDepBreak) | 
| David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 374 | AntiDepBreak->StartBlock(BB); | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 375 | } | 
|  | 376 |  | 
|  | 377 | /// Schedule - Schedule the instruction range using list scheduling. | 
|  | 378 | /// | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 379 | void SchedulePostRATDList::schedule() { | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 380 | // Build the scheduling graph. | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 381 | buildSchedGraph(AA); | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 382 |  | 
| Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 383 | if (AntiDepBreak) { | 
| Jim Grosbach | d772bde | 2010-05-14 21:19:48 +0000 | [diff] [blame] | 384 | unsigned Broken = | 
| Andrew Trick | 8c207e4 | 2012-03-09 04:29:02 +0000 | [diff] [blame] | 385 | AntiDepBreak->BreakAntiDependencies(SUnits, RegionBegin, RegionEnd, | 
|  | 386 | EndIndex, DbgValues); | 
| Jim Grosbach | d772bde | 2010-05-14 21:19:48 +0000 | [diff] [blame] | 387 |  | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 388 | if (Broken != 0) { | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 389 | // We made changes. Update the dependency graph. | 
|  | 390 | // Theoretically we could update the graph in place: | 
|  | 391 | // When a live range is changed to use a different register, remove | 
|  | 392 | // the def's anti-dependence *and* output-dependence edges due to | 
|  | 393 | // that register, and add new anti-dependence and output-dependence | 
|  | 394 | // edges based on the next live range of the register. | 
| Andrew Trick | 60cf03e | 2012-03-07 05:21:52 +0000 | [diff] [blame] | 395 | ScheduleDAG::clearDAG(); | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 396 | buildSchedGraph(AA); | 
| Jim Grosbach | d772bde | 2010-05-14 21:19:48 +0000 | [diff] [blame] | 397 |  | 
| David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 398 | NumFixedAnti += Broken; | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 399 | } | 
|  | 400 | } | 
|  | 401 |  | 
| David Greene | aa8ce38 | 2010-01-05 01:26:01 +0000 | [diff] [blame] | 402 | DEBUG(dbgs() << "********** List Scheduling **********\n"); | 
| David Goodwin | 6021b4d | 2009-08-10 15:55:25 +0000 | [diff] [blame] | 403 | DEBUG(for (unsigned su = 0, e = SUnits.size(); su != e; ++su) | 
|  | 404 | SUnits[su].dumpAll(this)); | 
|  | 405 |  | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 406 | AvailableQueue.initNodes(SUnits); | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 407 | ListScheduleTopDown(); | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 408 | AvailableQueue.releaseState(); | 
|  | 409 | } | 
|  | 410 |  | 
|  | 411 | /// Observe - Update liveness information to account for the current | 
|  | 412 | /// instruction, which will not be scheduled. | 
|  | 413 | /// | 
| Dan Gohman | dfaf646 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 414 | void SchedulePostRATDList::Observe(MachineInstr *MI, unsigned Count) { | 
| Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 415 | if (AntiDepBreak) | 
| Andrew Trick | a316faa | 2012-03-07 23:00:52 +0000 | [diff] [blame] | 416 | AntiDepBreak->Observe(MI, Count, EndIndex); | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 417 | } | 
|  | 418 |  | 
|  | 419 | /// FinishBlock - Clean up register live-range state. | 
|  | 420 | /// | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 421 | void SchedulePostRATDList::finishBlock() { | 
| Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 422 | if (AntiDepBreak) | 
| David Goodwin | 8370485 | 2009-10-26 16:59:04 +0000 | [diff] [blame] | 423 | AntiDepBreak->FinishBlock(); | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 424 |  | 
|  | 425 | // Call the superclass. | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 426 | ScheduleDAGInstrs::finishBlock(); | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 427 | } | 
|  | 428 |  | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 429 | //===----------------------------------------------------------------------===// | 
|  | 430 | //  Top-Down Scheduling | 
|  | 431 | //===----------------------------------------------------------------------===// | 
|  | 432 |  | 
|  | 433 | /// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to | 
| Andrew Trick | f1ff84c | 2012-11-12 19:28:57 +0000 | [diff] [blame] | 434 | /// the PendingQueue if the count reaches zero. | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 435 | void SchedulePostRATDList::ReleaseSucc(SUnit *SU, SDep *SuccEdge) { | 
| Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 436 | SUnit *SuccSU = SuccEdge->getSUnit(); | 
| Reid Kleckner | 8ff5c19 | 2009-09-30 20:15:38 +0000 | [diff] [blame] | 437 |  | 
| Andrew Trick | 4b1f9e3 | 2012-11-13 02:35:06 +0000 | [diff] [blame] | 438 | if (SuccEdge->isWeak()) { | 
| Andrew Trick | f1ff84c | 2012-11-12 19:28:57 +0000 | [diff] [blame] | 439 | --SuccSU->WeakPredsLeft; | 
|  | 440 | return; | 
|  | 441 | } | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 442 | #ifndef NDEBUG | 
| Reid Kleckner | 8ff5c19 | 2009-09-30 20:15:38 +0000 | [diff] [blame] | 443 | if (SuccSU->NumPredsLeft == 0) { | 
| David Greene | aa8ce38 | 2010-01-05 01:26:01 +0000 | [diff] [blame] | 444 | dbgs() << "*** Scheduling failed! ***\n"; | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 445 | SuccSU->dump(this); | 
| David Greene | aa8ce38 | 2010-01-05 01:26:01 +0000 | [diff] [blame] | 446 | dbgs() << " has been released too many times!\n"; | 
| Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 447 | llvm_unreachable(nullptr); | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 448 | } | 
|  | 449 | #endif | 
| Reid Kleckner | 8ff5c19 | 2009-09-30 20:15:38 +0000 | [diff] [blame] | 450 | --SuccSU->NumPredsLeft; | 
|  | 451 |  | 
| Andrew Trick | 84f9ad9 | 2011-05-06 18:14:32 +0000 | [diff] [blame] | 452 | // Standard scheduler algorithms will recompute the depth of the successor | 
| Andrew Trick | aab77fe | 2011-05-06 17:09:08 +0000 | [diff] [blame] | 453 | // here as such: | 
|  | 454 | //   SuccSU->setDepthToAtLeast(SU->getDepth() + SuccEdge->getLatency()); | 
|  | 455 | // | 
|  | 456 | // However, we lazily compute node depth instead. Note that | 
|  | 457 | // ScheduleNodeTopDown has already updated the depth of this node which causes | 
|  | 458 | // all descendents to be marked dirty. Setting the successor depth explicitly | 
|  | 459 | // here would cause depth to be recomputed for all its ancestors. If the | 
|  | 460 | // successor is not yet ready (because of a transitively redundant edge) then | 
|  | 461 | // this causes depth computation to be quadratic in the size of the DAG. | 
| Jim Grosbach | d772bde | 2010-05-14 21:19:48 +0000 | [diff] [blame] | 462 |  | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 463 | // If all the node's predecessors are scheduled, this node is ready | 
|  | 464 | // to be scheduled. Ignore the special ExitSU node. | 
|  | 465 | if (SuccSU->NumPredsLeft == 0 && SuccSU != &ExitSU) | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 466 | PendingQueue.push_back(SuccSU); | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 467 | } | 
|  | 468 |  | 
|  | 469 | /// ReleaseSuccessors - Call ReleaseSucc on each of SU's successors. | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 470 | void SchedulePostRATDList::ReleaseSuccessors(SUnit *SU) { | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 471 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); | 
| David Goodwin | 8501dbbe | 2009-11-03 20:57:50 +0000 | [diff] [blame] | 472 | I != E; ++I) { | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 473 | ReleaseSucc(SU, &*I); | 
| David Goodwin | 8501dbbe | 2009-11-03 20:57:50 +0000 | [diff] [blame] | 474 | } | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 475 | } | 
|  | 476 |  | 
|  | 477 | /// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending | 
|  | 478 | /// count of its successors. If a successor pending count is zero, add it to | 
|  | 479 | /// the Available queue. | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 480 | void SchedulePostRATDList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) { | 
| David Greene | aa8ce38 | 2010-01-05 01:26:01 +0000 | [diff] [blame] | 481 | DEBUG(dbgs() << "*** Scheduling [" << CurCycle << "]: "); | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 482 | DEBUG(SU->dump(this)); | 
| Jim Grosbach | d772bde | 2010-05-14 21:19:48 +0000 | [diff] [blame] | 483 |  | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 484 | Sequence.push_back(SU); | 
| Jim Grosbach | d772bde | 2010-05-14 21:19:48 +0000 | [diff] [blame] | 485 | assert(CurCycle >= SU->getDepth() && | 
| David Goodwin | 8501dbbe | 2009-11-03 20:57:50 +0000 | [diff] [blame] | 486 | "Node scheduled above its depth!"); | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 487 | SU->setDepthToAtLeast(CurCycle); | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 488 |  | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 489 | ReleaseSuccessors(SU); | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 490 | SU->isScheduled = true; | 
| Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 491 | AvailableQueue.scheduledNode(SU); | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 492 | } | 
|  | 493 |  | 
| Hal Finkel | 4fd3b1d | 2013-12-11 22:33:43 +0000 | [diff] [blame] | 494 | /// emitNoop - Add a noop to the current instruction sequence. | 
|  | 495 | void SchedulePostRATDList::emitNoop(unsigned CurCycle) { | 
|  | 496 | DEBUG(dbgs() << "*** Emitting noop in cycle " << CurCycle << '\n'); | 
|  | 497 | HazardRec->EmitNoop(); | 
| Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 498 | Sequence.push_back(nullptr);   // NULL here means noop | 
| Hal Finkel | 4fd3b1d | 2013-12-11 22:33:43 +0000 | [diff] [blame] | 499 | ++NumNoops; | 
|  | 500 | } | 
|  | 501 |  | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 502 | /// ListScheduleTopDown - The main loop of list scheduling for top-down | 
|  | 503 | /// schedulers. | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 504 | void SchedulePostRATDList::ListScheduleTopDown() { | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 505 | unsigned CurCycle = 0; | 
| Jim Grosbach | d772bde | 2010-05-14 21:19:48 +0000 | [diff] [blame] | 506 |  | 
| David Goodwin | 8501dbbe | 2009-11-03 20:57:50 +0000 | [diff] [blame] | 507 | // We're scheduling top-down but we're visiting the regions in | 
|  | 508 | // bottom-up order, so we don't know the hazards at the start of a | 
|  | 509 | // region. So assume no hazards (this should usually be ok as most | 
|  | 510 | // blocks are a single region). | 
|  | 511 | HazardRec->Reset(); | 
|  | 512 |  | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 513 | // Release any successors of the special Entry node. | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 514 | ReleaseSuccessors(&EntrySU); | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 515 |  | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 516 | // Add all leaves to Available queue. | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 517 | for (unsigned i = 0, e = SUnits.size(); i != e; ++i) { | 
|  | 518 | // It is available if it has no predecessors. | 
| Andrew Trick | f1ff84c | 2012-11-12 19:28:57 +0000 | [diff] [blame] | 519 | if (!SUnits[i].NumPredsLeft && !SUnits[i].isAvailable) { | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 520 | AvailableQueue.push(&SUnits[i]); | 
|  | 521 | SUnits[i].isAvailable = true; | 
|  | 522 | } | 
|  | 523 | } | 
| Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 524 |  | 
| David Goodwin | 1f8c7a7 | 2009-08-12 21:47:46 +0000 | [diff] [blame] | 525 | // In any cycle where we can't schedule any instructions, we must | 
|  | 526 | // stall or emit a noop, depending on the target. | 
| Benjamin Kramer | e3c9d23 | 2009-09-06 12:10:17 +0000 | [diff] [blame] | 527 | bool CycleHasInsts = false; | 
| David Goodwin | 1f8c7a7 | 2009-08-12 21:47:46 +0000 | [diff] [blame] | 528 |  | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 529 | // While Available queue is not empty, grab the node with the highest | 
|  | 530 | // priority. If it is not ready put it back.  Schedule the node. | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 531 | std::vector<SUnit*> NotReady; | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 532 | Sequence.reserve(SUnits.size()); | 
|  | 533 | while (!AvailableQueue.empty() || !PendingQueue.empty()) { | 
|  | 534 | // Check to see if any of the pending instructions are ready to issue.  If | 
|  | 535 | // so, add them to the available queue. | 
| Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 536 | unsigned MinDepth = ~0u; | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 537 | for (unsigned i = 0, e = PendingQueue.size(); i != e; ++i) { | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 538 | if (PendingQueue[i]->getDepth() <= CurCycle) { | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 539 | AvailableQueue.push(PendingQueue[i]); | 
|  | 540 | PendingQueue[i]->isAvailable = true; | 
|  | 541 | PendingQueue[i] = PendingQueue.back(); | 
|  | 542 | PendingQueue.pop_back(); | 
|  | 543 | --i; --e; | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 544 | } else if (PendingQueue[i]->getDepth() < MinDepth) | 
|  | 545 | MinDepth = PendingQueue[i]->getDepth(); | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 546 | } | 
| David Goodwin | ebd694b | 2009-08-11 17:35:23 +0000 | [diff] [blame] | 547 |  | 
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 548 | DEBUG(dbgs() << "\n*** Examining Available\n"; AvailableQueue.dump(this)); | 
| David Goodwin | ebd694b | 2009-08-11 17:35:23 +0000 | [diff] [blame] | 549 |  | 
| Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 550 | SUnit *FoundSUnit = nullptr, *NotPreferredSUnit = nullptr; | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 551 | bool HasNoopHazards = false; | 
|  | 552 | while (!AvailableQueue.empty()) { | 
|  | 553 | SUnit *CurSUnit = AvailableQueue.pop(); | 
|  | 554 |  | 
|  | 555 | ScheduleHazardRecognizer::HazardType HT = | 
| Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 556 | HazardRec->getHazardType(CurSUnit, 0/*no stalls*/); | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 557 | if (HT == ScheduleHazardRecognizer::NoHazard) { | 
| Hal Finkel | 4fd3b1d | 2013-12-11 22:33:43 +0000 | [diff] [blame] | 558 | if (HazardRec->ShouldPreferAnother(CurSUnit)) { | 
|  | 559 | if (!NotPreferredSUnit) { | 
| NAKAMURA Takumi | f51a34e | 2014-10-29 15:23:11 +0000 | [diff] [blame] | 560 | // If this is the first non-preferred node for this cycle, then | 
|  | 561 | // record it and continue searching for a preferred node. If this | 
|  | 562 | // is not the first non-preferred node, then treat it as though | 
|  | 563 | // there had been a hazard. | 
| Hal Finkel | 4fd3b1d | 2013-12-11 22:33:43 +0000 | [diff] [blame] | 564 | NotPreferredSUnit = CurSUnit; | 
|  | 565 | continue; | 
|  | 566 | } | 
|  | 567 | } else { | 
|  | 568 | FoundSUnit = CurSUnit; | 
|  | 569 | break; | 
|  | 570 | } | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 571 | } | 
|  | 572 |  | 
|  | 573 | // Remember if this is a noop hazard. | 
|  | 574 | HasNoopHazards |= HT == ScheduleHazardRecognizer::NoopHazard; | 
|  | 575 |  | 
|  | 576 | NotReady.push_back(CurSUnit); | 
|  | 577 | } | 
|  | 578 |  | 
| Hal Finkel | 4fd3b1d | 2013-12-11 22:33:43 +0000 | [diff] [blame] | 579 | // If we have a non-preferred node, push it back onto the available list. | 
|  | 580 | // If we did not find a preferred node, then schedule this first | 
|  | 581 | // non-preferred node. | 
|  | 582 | if (NotPreferredSUnit) { | 
|  | 583 | if (!FoundSUnit) { | 
|  | 584 | DEBUG(dbgs() << "*** Will schedule a non-preferred instruction...\n"); | 
|  | 585 | FoundSUnit = NotPreferredSUnit; | 
|  | 586 | } else { | 
|  | 587 | AvailableQueue.push(NotPreferredSUnit); | 
|  | 588 | } | 
|  | 589 |  | 
| Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 590 | NotPreferredSUnit = nullptr; | 
| Hal Finkel | 4fd3b1d | 2013-12-11 22:33:43 +0000 | [diff] [blame] | 591 | } | 
|  | 592 |  | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 593 | // Add the nodes that aren't ready back onto the available list. | 
|  | 594 | if (!NotReady.empty()) { | 
|  | 595 | AvailableQueue.push_all(NotReady); | 
|  | 596 | NotReady.clear(); | 
|  | 597 | } | 
|  | 598 |  | 
| David Goodwin | 8501dbbe | 2009-11-03 20:57:50 +0000 | [diff] [blame] | 599 | // If we found a node to schedule... | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 600 | if (FoundSUnit) { | 
| Hal Finkel | 4fd3b1d | 2013-12-11 22:33:43 +0000 | [diff] [blame] | 601 | // If we need to emit noops prior to this instruction, then do so. | 
|  | 602 | unsigned NumPreNoops = HazardRec->PreEmitNoops(FoundSUnit); | 
|  | 603 | for (unsigned i = 0; i != NumPreNoops; ++i) | 
|  | 604 | emitNoop(CurCycle); | 
|  | 605 |  | 
| David Goodwin | 8501dbbe | 2009-11-03 20:57:50 +0000 | [diff] [blame] | 606 | // ... schedule the node... | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 607 | ScheduleNodeTopDown(FoundSUnit, CurCycle); | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 608 | HazardRec->EmitInstruction(FoundSUnit); | 
| Benjamin Kramer | e3c9d23 | 2009-09-06 12:10:17 +0000 | [diff] [blame] | 609 | CycleHasInsts = true; | 
| Andrew Trick | 18c9b37 | 2011-06-01 03:27:56 +0000 | [diff] [blame] | 610 | if (HazardRec->atIssueLimit()) { | 
|  | 611 | DEBUG(dbgs() << "*** Max instructions per cycle " << CurCycle << '\n'); | 
|  | 612 | HazardRec->AdvanceCycle(); | 
|  | 613 | ++CurCycle; | 
|  | 614 | CycleHasInsts = false; | 
|  | 615 | } | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 616 | } else { | 
| Benjamin Kramer | e3c9d23 | 2009-09-06 12:10:17 +0000 | [diff] [blame] | 617 | if (CycleHasInsts) { | 
| David Greene | aa8ce38 | 2010-01-05 01:26:01 +0000 | [diff] [blame] | 618 | DEBUG(dbgs() << "*** Finished cycle " << CurCycle << '\n'); | 
| David Goodwin | 1f8c7a7 | 2009-08-12 21:47:46 +0000 | [diff] [blame] | 619 | HazardRec->AdvanceCycle(); | 
|  | 620 | } else if (!HasNoopHazards) { | 
|  | 621 | // Otherwise, we have a pipeline stall, but no other problem, | 
|  | 622 | // just advance the current cycle and try again. | 
| David Greene | aa8ce38 | 2010-01-05 01:26:01 +0000 | [diff] [blame] | 623 | DEBUG(dbgs() << "*** Stall in cycle " << CurCycle << '\n'); | 
| David Goodwin | 1f8c7a7 | 2009-08-12 21:47:46 +0000 | [diff] [blame] | 624 | HazardRec->AdvanceCycle(); | 
| David Goodwin | 80a03cc | 2009-11-20 19:32:48 +0000 | [diff] [blame] | 625 | ++NumStalls; | 
| David Goodwin | 1f8c7a7 | 2009-08-12 21:47:46 +0000 | [diff] [blame] | 626 | } else { | 
|  | 627 | // Otherwise, we have no instructions to issue and we have instructions | 
|  | 628 | // that will fault if we don't do this right.  This is the case for | 
|  | 629 | // processors without pipeline interlocks and other cases. | 
| Hal Finkel | 4fd3b1d | 2013-12-11 22:33:43 +0000 | [diff] [blame] | 630 | emitNoop(CurCycle); | 
| David Goodwin | 1f8c7a7 | 2009-08-12 21:47:46 +0000 | [diff] [blame] | 631 | } | 
|  | 632 |  | 
| Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 633 | ++CurCycle; | 
| Benjamin Kramer | e3c9d23 | 2009-09-06 12:10:17 +0000 | [diff] [blame] | 634 | CycleHasInsts = false; | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 635 | } | 
|  | 636 | } | 
|  | 637 |  | 
|  | 638 | #ifndef NDEBUG | 
| Andrew Trick | 46a5866 | 2012-03-07 05:21:36 +0000 | [diff] [blame] | 639 | unsigned ScheduledNodes = VerifyScheduledDAG(/*isBottomUp=*/false); | 
|  | 640 | unsigned Noops = 0; | 
|  | 641 | for (unsigned i = 0, e = Sequence.size(); i != e; ++i) | 
|  | 642 | if (!Sequence[i]) | 
|  | 643 | ++Noops; | 
|  | 644 | assert(Sequence.size() - Noops == ScheduledNodes && | 
|  | 645 | "The number of nodes scheduled doesn't match the expected number!"); | 
|  | 646 | #endif // NDEBUG | 
| Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 647 | } | 
| Andrew Trick | e932bb7 | 2012-03-07 05:21:44 +0000 | [diff] [blame] | 648 |  | 
|  | 649 | // EmitSchedule - Emit the machine code in scheduled order. | 
|  | 650 | void SchedulePostRATDList::EmitSchedule() { | 
| Andrew Trick | 8c207e4 | 2012-03-09 04:29:02 +0000 | [diff] [blame] | 651 | RegionBegin = RegionEnd; | 
| Andrew Trick | e932bb7 | 2012-03-07 05:21:44 +0000 | [diff] [blame] | 652 |  | 
|  | 653 | // If first instruction was a DBG_VALUE then put it back. | 
|  | 654 | if (FirstDbgValue) | 
| Andrew Trick | 8c207e4 | 2012-03-09 04:29:02 +0000 | [diff] [blame] | 655 | BB->splice(RegionEnd, BB, FirstDbgValue); | 
| Andrew Trick | e932bb7 | 2012-03-07 05:21:44 +0000 | [diff] [blame] | 656 |  | 
|  | 657 | // Then re-insert them according to the given schedule. | 
|  | 658 | for (unsigned i = 0, e = Sequence.size(); i != e; i++) { | 
|  | 659 | if (SUnit *SU = Sequence[i]) | 
| Andrew Trick | 8c207e4 | 2012-03-09 04:29:02 +0000 | [diff] [blame] | 660 | BB->splice(RegionEnd, BB, SU->getInstr()); | 
| Andrew Trick | e932bb7 | 2012-03-07 05:21:44 +0000 | [diff] [blame] | 661 | else | 
|  | 662 | // Null SUnit* is a noop. | 
| Andrew Trick | 8c207e4 | 2012-03-09 04:29:02 +0000 | [diff] [blame] | 663 | TII->insertNoop(*BB, RegionEnd); | 
| Andrew Trick | e932bb7 | 2012-03-07 05:21:44 +0000 | [diff] [blame] | 664 |  | 
|  | 665 | // Update the Begin iterator, as the first instruction in the block | 
|  | 666 | // may have been scheduled later. | 
|  | 667 | if (i == 0) | 
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 668 | RegionBegin = std::prev(RegionEnd); | 
| Andrew Trick | e932bb7 | 2012-03-07 05:21:44 +0000 | [diff] [blame] | 669 | } | 
|  | 670 |  | 
|  | 671 | // Reinsert any remaining debug_values. | 
|  | 672 | for (std::vector<std::pair<MachineInstr *, MachineInstr *> >::iterator | 
|  | 673 | DI = DbgValues.end(), DE = DbgValues.begin(); DI != DE; --DI) { | 
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 674 | std::pair<MachineInstr *, MachineInstr *> P = *std::prev(DI); | 
| Andrew Trick | e932bb7 | 2012-03-07 05:21:44 +0000 | [diff] [blame] | 675 | MachineInstr *DbgValue = P.first; | 
|  | 676 | MachineBasicBlock::iterator OrigPrivMI = P.second; | 
|  | 677 | BB->splice(++OrigPrivMI, BB, DbgValue); | 
|  | 678 | } | 
|  | 679 | DbgValues.clear(); | 
| Craig Topper | c0196b1 | 2014-04-14 00:51:57 +0000 | [diff] [blame] | 680 | FirstDbgValue = nullptr; | 
| Andrew Trick | e932bb7 | 2012-03-07 05:21:44 +0000 | [diff] [blame] | 681 | } |