OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/graph-reducer.h" | 5 #include "src/compiler/graph-reducer.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 | 8 |
9 #include "src/compiler/graph-inl.h" | 9 #include "src/compiler/graph-inl.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 namespace compiler { | 13 namespace compiler { |
14 | 14 |
15 GraphReducer::GraphReducer(Graph* graph) | 15 GraphReducer::GraphReducer(Graph* graph) |
16 : graph_(graph), reducers_(Reducers::allocator_type(graph->zone())) {} | 16 : graph_(graph), reducers_(graph->zone()) {} |
17 | 17 |
18 | 18 |
19 static bool NodeIdIsLessThan(const Node* node, NodeId id) { | 19 static bool NodeIdIsLessThan(const Node* node, NodeId id) { |
20 return node->id() < id; | 20 return node->id() < id; |
21 } | 21 } |
22 | 22 |
23 | 23 |
24 void GraphReducer::ReduceNode(Node* node) { | 24 void GraphReducer::ReduceNode(Node* node) { |
25 Reducers::iterator skip = reducers_.end(); | 25 ZoneVector<Reducer*>::iterator skip = reducers_.end(); |
26 static const unsigned kMaxAttempts = 16; | 26 static const unsigned kMaxAttempts = 16; |
27 bool reduce = true; | 27 bool reduce = true; |
28 for (unsigned attempts = 0; attempts <= kMaxAttempts; ++attempts) { | 28 for (unsigned attempts = 0; attempts <= kMaxAttempts; ++attempts) { |
29 if (!reduce) return; | 29 if (!reduce) return; |
30 reduce = false; // Assume we don't need to rerun any reducers. | 30 reduce = false; // Assume we don't need to rerun any reducers. |
31 int before = graph_->NodeCount(); | 31 int before = graph_->NodeCount(); |
32 for (Reducers::iterator i = reducers_.begin(); i != reducers_.end(); ++i) { | 32 for (ZoneVector<Reducer*>::iterator i = reducers_.begin(); |
| 33 i != reducers_.end(); ++i) { |
33 if (i == skip) continue; // Skip this reducer. | 34 if (i == skip) continue; // Skip this reducer. |
34 Reduction reduction = (*i)->Reduce(node); | 35 Reduction reduction = (*i)->Reduce(node); |
35 Node* replacement = reduction.replacement(); | 36 Node* replacement = reduction.replacement(); |
36 if (replacement == NULL) { | 37 if (replacement == NULL) { |
37 // No change from this reducer. | 38 // No change from this reducer. |
38 } else if (replacement == node) { | 39 } else if (replacement == node) { |
39 // {replacement == node} represents an in-place reduction. | 40 // {replacement == node} represents an in-place reduction. |
40 // Rerun all the reducers except the current one for this node, | 41 // Rerun all the reducers except the current one for this node, |
41 // as now there may be more opportunities for reduction. | 42 // as now there may be more opportunities for reduction. |
42 reduce = true; | 43 reduce = true; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 GraphReducerVisitor visitor(this); | 86 GraphReducerVisitor visitor(this); |
86 // Perform a post-order reduction of all nodes starting from the end. | 87 // Perform a post-order reduction of all nodes starting from the end. |
87 graph()->VisitNodeInputsFromEnd(&visitor); | 88 graph()->VisitNodeInputsFromEnd(&visitor); |
88 } | 89 } |
89 | 90 |
90 | 91 |
91 // TODO(titzer): partial graph reductions. | 92 // TODO(titzer): partial graph reductions. |
92 } | 93 } |
93 } | 94 } |
94 } // namespace v8::internal::compiler | 95 } // namespace v8::internal::compiler |
OLD | NEW |