llvm.org GIT mirror llvm / 5e84368
Reapply 53476 and 53480, with a fix so that it properly updates the BB member to the current basic block after emitting instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53567 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
8 changed file(s) with 83 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
264264
265265 /// Run - perform scheduling.
266266 ///
267 MachineBasicBlock *Run();
267 void Run();
268268
269269 /// isPassiveNode - Return true if the node is a non-scheduled leaf.
270270 ///
335335 ///
336336 void EmitNoop();
337337
338 void EmitSchedule();
338 MachineBasicBlock *EmitSchedule();
339339
340340 void dumpSchedule() const;
341341
2929 class FunctionLoweringInfo;
3030 class HazardRecognizer;
3131 class CollectorMetadata;
32 class ScheduleDAG;
3233
3334 /// SelectionDAGISel - This is the common base class used for SelectionDAG-based
3435 /// pattern-matching instruction selectors.
190191
191192 void ComputeLiveOutVRegInfo(SelectionDAG &DAG);
192193
193 /// Pick a safe ordering and emit instructions for each target node in the
194 /// Pick a safe ordering for instructions for each target node in the
194195 /// graph.
195 void ScheduleAndEmitDAG(SelectionDAG &DAG);
196 ScheduleDAG *Schedule(SelectionDAG &DAG);
196197
197198 /// SwitchCases - Vector of CaseBlock structures used to communicate
198199 /// SwitchInst code generation information.
131131 ///
132132 struct NamedRegionTimer : public TimeRegion {
133133 explicit NamedRegionTimer(const std::string &Name);
134 explicit NamedRegionTimer(const std::string &Name,
135 const std::string &GroupName);
134136 };
135137
136138
10811081 }
10821082
10831083 /// EmitSchedule - Emit the machine code in scheduled order.
1084 void ScheduleDAG::EmitSchedule() {
1084 MachineBasicBlock *ScheduleDAG::EmitSchedule() {
10851085 bool isEntryBB = &MF->front() == BB;
10861086
10871087 if (isEntryBB && !SchedLiveInCopies) {
11171117
11181118 if (isEntryBB && SchedLiveInCopies)
11191119 EmitLiveInCopies(MF->begin());
1120
1121 return BB;
11201122 }
11211123
11221124 /// dump - dump the schedule.
11321134
11331135 /// Run - perform scheduling.
11341136 ///
1135 MachineBasicBlock *ScheduleDAG::Run() {
1137 void ScheduleDAG::Run() {
11361138 Schedule();
1137 return BB;
1139
1140 DOUT << "*** Final schedule ***\n";
1141 DEBUG(dumpSchedule());
1142 DOUT << "\n";
11381143 }
11391144
11401145 /// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
9898 ListScheduleTopDown();
9999
100100 AvailableQueue->releaseState();
101
102 DOUT << "*** Final schedule ***\n";
103 DEBUG(dumpSchedule());
104 DOUT << "\n";
105
106 // Emit in scheduled order
107 EmitSchedule();
108101 }
109102
110103 //===----------------------------------------------------------------------===//
203203
204204 if (!Fast)
205205 CommuteNodesToReducePressure();
206
207 DOUT << "*** Final schedule ***\n";
208 DEBUG(dumpSchedule());
209 DOUT << "\n";
210
211 // Emit in scheduled order
212 EmitSchedule();
213206 }
214207
215208 /// CommuteNodesToReducePressure - If a node is two-address and commutable, and
52835283 void SelectionDAGISel::CodeGenAndEmitDAG(SelectionDAG &DAG) {
52845284 DOUT << "Lowered selection DAG:\n";
52855285 DEBUG(DAG.dump());
5286 std::string GroupName = "Instruction Selection and Scheduling";
52865287
52875288 // Run the DAG combiner in pre-legalize mode.
52885289 if (TimePassesIsEnabled) {
5289 NamedRegionTimer T("DAG Combining 1");
5290 NamedRegionTimer T("DAG Combining 1", GroupName);
52905291 DAG.Combine(false, *AA);
52915292 } else {
52925293 DAG.Combine(false, *AA);
53035304 }
53045305
53055306 if (TimePassesIsEnabled) {
5306 NamedRegionTimer T("DAG Legalization");
5307 NamedRegionTimer T("DAG Legalization", GroupName);
53075308 DAG.Legalize();
53085309 } else {
53095310 DAG.Legalize();
53145315
53155316 // Run the DAG combiner in post-legalize mode.
53165317 if (TimePassesIsEnabled) {
5317 NamedRegionTimer T("DAG Combining 2");
5318 NamedRegionTimer T("DAG Combining 2", GroupName);
53185319 DAG.Combine(true, *AA);
53195320 } else {
53205321 DAG.Combine(true, *AA);
53315332 // Third, instruction select all of the operations to machine code, adding the
53325333 // code to the MachineBasicBlock.
53335334 if (TimePassesIsEnabled) {
5334 NamedRegionTimer T("Instruction Selection");
5335 NamedRegionTimer T("Instruction Selection", GroupName);
53355336 InstructionSelect(DAG);
53365337 } else {
53375338 InstructionSelect(DAG);
53385339 }
53395340
5341 // Schedule machine code.
5342 ScheduleDAG *Scheduler;
5343 if (TimePassesIsEnabled) {
5344 NamedRegionTimer T("Instruction Scheduling", GroupName);
5345 Scheduler = Schedule(DAG);
5346 } else {
5347 Scheduler = Schedule(DAG);
5348 }
5349
53405350 // Emit machine code to BB. This can change 'BB' to the last block being
53415351 // inserted into.
53425352 if (TimePassesIsEnabled) {
5343 NamedRegionTimer T("Instruction Scheduling");
5344 ScheduleAndEmitDAG(DAG);
5353 NamedRegionTimer T("Instruction Creation", GroupName);
5354 BB = Scheduler->EmitSchedule();
53455355 } else {
5346 ScheduleAndEmitDAG(DAG);
5356 BB = Scheduler->EmitSchedule();
5357 }
5358
5359 // Free the scheduler state.
5360 if (TimePassesIsEnabled) {
5361 NamedRegionTimer T("Instruction Scheduling Cleanup", GroupName);
5362 delete Scheduler;
5363 } else {
5364 delete Scheduler;
53475365 }
53485366
53495367 // Perform target specific isel post processing.
53505368 if (TimePassesIsEnabled) {
5351 NamedRegionTimer T("Instruction Selection Post Processing");
5369 NamedRegionTimer T("Instruction Selection Post Processing", GroupName);
53525370 InstructionSelectPostProcessing(DAG);
53535371 } else {
53545372 InstructionSelectPostProcessing(DAG);
55965614 }
55975615
55985616
5599 //===----------------------------------------------------------------------===//
5600 /// ScheduleAndEmitDAG - Pick a safe ordering and emit instructions for each
5617 /// Schedule - Pick a safe ordering for instructions for each
56015618 /// target node in the graph.
5602 void SelectionDAGISel::ScheduleAndEmitDAG(SelectionDAG &DAG) {
5619 ///
5620 ScheduleDAG *SelectionDAGISel::Schedule(SelectionDAG &DAG) {
56035621 if (ViewSchedDAGs) DAG.viewGraph();
56045622
56055623 RegisterScheduler::FunctionPassCtor Ctor = RegisterScheduler::getDefault();
56095627 RegisterScheduler::setDefault(Ctor);
56105628 }
56115629
5612 ScheduleDAG *SL = Ctor(this, &DAG, BB, FastISel);
5613 BB = SL->Run();
5614
5615 if (ViewSUnitDAGs) SL->viewGraph();
5616
5617 delete SL;
5630 ScheduleDAG *Scheduler = Ctor(this, &DAG, BB, FastISel);
5631 Scheduler->Run();
5632
5633 if (ViewSUnitDAGs) Scheduler->viewGraph();
5634 return Scheduler;
56185635 }
56195636
56205637
181181 // NamedRegionTimer Implementation
182182 //===----------------------------------------------------------------------===//
183183
184 static ManagedStatic > NamedTimers;
184 namespace {
185
186 typedef std::map Name2Timer;
187 typedef std::map > Name2Pair;
188
189 }
190
191 static ManagedStatic NamedTimers;
192
193 static ManagedStatic NamedGroupedTimers;
185194
186195 static Timer &getNamedRegionTimer(const std::string &Name) {
187 std::map::iterator I = NamedTimers->find(Name);
196 Name2Timer::iterator I = NamedTimers->find(Name);
188197 if (I != NamedTimers->end())
189198 return I->second;
190199
191200 return NamedTimers->insert(I, std::make_pair(Name, Timer(Name)))->second;
192201 }
193202
203 static Timer &getNamedRegionTimer(const std::string &Name,
204 const std::string &GroupName) {
205
206 Name2Pair::iterator I = NamedGroupedTimers->find(GroupName);
207 if (I == NamedGroupedTimers->end()) {
208 TimerGroup TG(GroupName);
209 std::pair Pair(TG, Name2Timer());
210 I = NamedGroupedTimers->insert(I, std::make_pair(GroupName, Pair));
211 }
212
213 Name2Timer::iterator J = I->second.second.find(Name);
214 if (J == I->second.second.end())
215 J = I->second.second.insert(J,
216 std::make_pair(Name,
217 Timer(Name,
218 I->second.first)));
219
220 return J->second;
221 }
222
194223 NamedRegionTimer::NamedRegionTimer(const std::string &Name)
195224 : TimeRegion(getNamedRegionTimer(Name)) {}
196225
226 NamedRegionTimer::NamedRegionTimer(const std::string &Name,
227 const std::string &GroupName)
228 : TimeRegion(getNamedRegionTimer(Name, GroupName)) {}
197229
198230 //===----------------------------------------------------------------------===//
199231 // TimerGroup Implementation