OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/instruction-scheduler.h" | 5 #include "src/compiler/instruction-scheduler.h" |
6 | 6 |
7 #include "src/base/adapters.h" | 7 #include "src/base/adapters.h" |
8 #include "src/base/utils/random-number-generator.h" | 8 #include "src/base/utils/random-number-generator.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 namespace compiler { | 12 namespace compiler { |
13 | 13 |
14 // Compare the two nodes and return true if node1 is a better candidate than | 14 void InstructionScheduler::SchedulingQueueBase::AddNode( |
15 // node2 (i.e. node1 should be scheduled before node2). | 15 ScheduleGraphNode* node) { |
16 bool InstructionScheduler::CriticalPathFirstQueue::CompareNodes( | 16 // We keep the ready list sorted by total latency so that we can quickly find |
17 ScheduleGraphNode *node1, ScheduleGraphNode *node2) const { | 17 // the next best candidate to schedule. |
18 return node1->total_latency() > node2->total_latency(); | 18 auto it = nodes_.begin(); |
| 19 while ((it != nodes_.end()) && |
| 20 ((*it)->total_latency() > node->total_latency())) { |
| 21 ++it; |
| 22 } |
| 23 nodes_.insert(it, node); |
19 } | 24 } |
20 | 25 |
21 | 26 |
22 InstructionScheduler::ScheduleGraphNode* | 27 InstructionScheduler::ScheduleGraphNode* |
23 InstructionScheduler::CriticalPathFirstQueue::PopBestCandidate(int cycle) { | 28 InstructionScheduler::CriticalPathFirstQueue::PopBestCandidate(int cycle) { |
24 DCHECK(!IsEmpty()); | 29 DCHECK(!IsEmpty()); |
25 auto candidate = nodes_.end(); | 30 auto candidate = nodes_.end(); |
26 for (auto iterator = nodes_.begin(); iterator != nodes_.end(); ++iterator) { | 31 for (auto iterator = nodes_.begin(); iterator != nodes_.end(); ++iterator) { |
27 // We only consider instructions that have all their operands ready and | 32 // We only consider instructions that have all their operands ready. |
28 // we try to schedule the critical path first. | |
29 if (cycle >= (*iterator)->start_cycle()) { | 33 if (cycle >= (*iterator)->start_cycle()) { |
30 if ((candidate == nodes_.end()) || CompareNodes(*iterator, *candidate)) { | 34 candidate = iterator; |
31 candidate = iterator; | 35 break; |
32 } | |
33 } | 36 } |
34 } | 37 } |
35 | 38 |
36 if (candidate != nodes_.end()) { | 39 if (candidate != nodes_.end()) { |
37 ScheduleGraphNode *result = *candidate; | 40 ScheduleGraphNode *result = *candidate; |
38 nodes_.erase(candidate); | 41 nodes_.erase(candidate); |
39 return result; | 42 return result; |
40 } | 43 } |
41 | 44 |
42 return nullptr; | 45 return nullptr; |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 355 } |
353 } | 356 } |
354 | 357 |
355 node->set_total_latency(max_latency + node->latency()); | 358 node->set_total_latency(max_latency + node->latency()); |
356 } | 359 } |
357 } | 360 } |
358 | 361 |
359 } // namespace compiler | 362 } // namespace compiler |
360 } // namespace internal | 363 } // namespace internal |
361 } // namespace v8 | 364 } // namespace v8 |
OLD | NEW |