OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/scheduler.h" | 5 #include "src/compiler/scheduler.h" |
6 | 6 |
7 #include "src/bit-vector.h" | 7 #include "src/bit-vector.h" |
8 #include "src/compiler/common-operator.h" | 8 #include "src/compiler/common-operator.h" |
9 #include "src/compiler/control-equivalence.h" | 9 #include "src/compiler/control-equivalence.h" |
10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" |
11 #include "src/compiler/graph-inl.h" | |
12 #include "src/compiler/node.h" | 11 #include "src/compiler/node.h" |
13 #include "src/compiler/node-marker.h" | 12 #include "src/compiler/node-marker.h" |
14 #include "src/compiler/node-properties.h" | 13 #include "src/compiler/node-properties.h" |
| 14 #include "src/zone-containers.h" |
15 | 15 |
16 namespace v8 { | 16 namespace v8 { |
17 namespace internal { | 17 namespace internal { |
18 namespace compiler { | 18 namespace compiler { |
19 | 19 |
20 static inline void Trace(const char* msg, ...) { | 20 static inline void Trace(const char* msg, ...) { |
21 if (FLAG_trace_turbo_scheduler) { | 21 if (FLAG_trace_turbo_scheduler) { |
22 va_list arguments; | 22 va_list arguments; |
23 va_start(arguments, msg); | 23 va_start(arguments, msg); |
24 base::OS::VPrint(msg, arguments); | 24 base::OS::VPrint(msg, arguments); |
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 | 1039 |
1040 // Build the block dominator tree resulting from the above seed. | 1040 // Build the block dominator tree resulting from the above seed. |
1041 PropagateImmediateDominators(schedule_->start()->rpo_next()); | 1041 PropagateImmediateDominators(schedule_->start()->rpo_next()); |
1042 } | 1042 } |
1043 | 1043 |
1044 | 1044 |
1045 // ----------------------------------------------------------------------------- | 1045 // ----------------------------------------------------------------------------- |
1046 // Phase 3: Prepare use counts for nodes. | 1046 // Phase 3: Prepare use counts for nodes. |
1047 | 1047 |
1048 | 1048 |
1049 class PrepareUsesVisitor : public NullNodeVisitor { | 1049 class PrepareUsesVisitor { |
1050 public: | 1050 public: |
1051 explicit PrepareUsesVisitor(Scheduler* scheduler) | 1051 explicit PrepareUsesVisitor(Scheduler* scheduler) |
1052 : scheduler_(scheduler), schedule_(scheduler->schedule_) {} | 1052 : scheduler_(scheduler), schedule_(scheduler->schedule_) {} |
1053 | 1053 |
1054 void Pre(Node* node) { | 1054 void Pre(Node* node) { |
1055 if (scheduler_->GetPlacement(node) == Scheduler::kFixed) { | 1055 if (scheduler_->GetPlacement(node) == Scheduler::kFixed) { |
1056 // Fixed nodes are always roots for schedule late. | 1056 // Fixed nodes are always roots for schedule late. |
1057 scheduler_->schedule_root_nodes_.push_back(node); | 1057 scheduler_->schedule_root_nodes_.push_back(node); |
1058 if (!schedule_->IsScheduled(node)) { | 1058 if (!schedule_->IsScheduled(node)) { |
1059 // Make sure root nodes are scheduled in their respective blocks. | 1059 // Make sure root nodes are scheduled in their respective blocks. |
(...skipping 22 matching lines...) Expand all Loading... |
1082 | 1082 |
1083 private: | 1083 private: |
1084 Scheduler* scheduler_; | 1084 Scheduler* scheduler_; |
1085 Schedule* schedule_; | 1085 Schedule* schedule_; |
1086 }; | 1086 }; |
1087 | 1087 |
1088 | 1088 |
1089 void Scheduler::PrepareUses() { | 1089 void Scheduler::PrepareUses() { |
1090 Trace("--- PREPARE USES -------------------------------------------\n"); | 1090 Trace("--- PREPARE USES -------------------------------------------\n"); |
1091 | 1091 |
1092 // Count the uses of every node, it will be used to ensure that all of a | 1092 // Count the uses of every node, which is used to ensure that all of a |
1093 // node's uses are scheduled before the node itself. | 1093 // node's uses are scheduled before the node itself. |
1094 PrepareUsesVisitor prepare_uses(this); | 1094 PrepareUsesVisitor prepare_uses(this); |
1095 graph_->VisitNodeInputsFromEnd(&prepare_uses); | 1095 |
| 1096 // TODO(turbofan): simplify the careful pre/post ordering here. |
| 1097 BoolVector visited(graph_->NodeCount(), false, zone_); |
| 1098 ZoneStack<Node::InputEdges::iterator> stack(zone_); |
| 1099 Node* node = graph_->end(); |
| 1100 prepare_uses.Pre(node); |
| 1101 visited[node->id()] = true; |
| 1102 stack.push(node->input_edges().begin()); |
| 1103 while (!stack.empty()) { |
| 1104 Edge edge = *stack.top(); |
| 1105 Node* node = edge.to(); |
| 1106 if (visited[node->id()]) { |
| 1107 prepare_uses.PostEdge(edge.from(), edge.index(), edge.to()); |
| 1108 if (++stack.top() == edge.from()->input_edges().end()) stack.pop(); |
| 1109 } else { |
| 1110 prepare_uses.Pre(node); |
| 1111 visited[node->id()] = true; |
| 1112 if (node->InputCount() > 0) stack.push(node->input_edges().begin()); |
| 1113 } |
| 1114 } |
1096 } | 1115 } |
1097 | 1116 |
1098 | 1117 |
1099 // ----------------------------------------------------------------------------- | 1118 // ----------------------------------------------------------------------------- |
1100 // Phase 4: Schedule nodes early. | 1119 // Phase 4: Schedule nodes early. |
1101 | 1120 |
1102 | 1121 |
1103 class ScheduleEarlyNodeVisitor { | 1122 class ScheduleEarlyNodeVisitor { |
1104 public: | 1123 public: |
1105 ScheduleEarlyNodeVisitor(Zone* zone, Scheduler* scheduler) | 1124 ScheduleEarlyNodeVisitor(Zone* zone, Scheduler* scheduler) |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1447 for (Node* const node : *nodes) { | 1466 for (Node* const node : *nodes) { |
1448 schedule_->SetBlockForNode(to, node); | 1467 schedule_->SetBlockForNode(to, node); |
1449 scheduled_nodes_[to->id().ToSize()].push_back(node); | 1468 scheduled_nodes_[to->id().ToSize()].push_back(node); |
1450 } | 1469 } |
1451 nodes->clear(); | 1470 nodes->clear(); |
1452 } | 1471 } |
1453 | 1472 |
1454 } // namespace compiler | 1473 } // namespace compiler |
1455 } // namespace internal | 1474 } // namespace internal |
1456 } // namespace v8 | 1475 } // namespace v8 |
OLD | NEW |