| 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 <functional> | 5 #include <functional> |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 #include "src/compiler/graph.h" | 8 #include "src/compiler/graph.h" |
| 9 #include "src/compiler/graph-reducer.h" | 9 #include "src/compiler/graph-reducer.h" |
| 10 #include "src/compiler/node.h" | 10 #include "src/compiler/node.h" |
| 11 #include "src/compiler/node-properties.h" | 11 #include "src/compiler/node-properties.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 namespace compiler { | 15 namespace compiler { |
| 16 | 16 |
| 17 bool Reducer::Finish() { return true; } | |
| 18 | |
| 19 | |
| 20 enum class GraphReducer::State : uint8_t { | 17 enum class GraphReducer::State : uint8_t { |
| 21 kUnvisited, | 18 kUnvisited, |
| 22 kRevisit, | 19 kRevisit, |
| 23 kOnStack, | 20 kOnStack, |
| 24 kVisited | 21 kVisited |
| 25 }; | 22 }; |
| 26 | 23 |
| 27 | 24 |
| 28 GraphReducer::GraphReducer(Zone* zone, Graph* graph, Node* dead_value, | 25 GraphReducer::GraphReducer(Zone* zone, Graph* graph, Node* dead_value, |
| 29 Node* dead_control) | 26 Node* dead_control) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 60 } |
| 64 } else { | 61 } else { |
| 65 break; | 62 break; |
| 66 } | 63 } |
| 67 } | 64 } |
| 68 DCHECK(revisit_.empty()); | 65 DCHECK(revisit_.empty()); |
| 69 DCHECK(stack_.empty()); | 66 DCHECK(stack_.empty()); |
| 70 } | 67 } |
| 71 | 68 |
| 72 | 69 |
| 73 void GraphReducer::ReduceGraph() { | 70 void GraphReducer::ReduceGraph() { ReduceNode(graph()->end()); } |
| 74 for (;;) { | |
| 75 ReduceNode(graph()->end()); | |
| 76 // TODO(turbofan): Remove this once the dead node trimming is in the | |
| 77 // GraphReducer. | |
| 78 bool done = true; | |
| 79 for (Reducer* const reducer : reducers_) { | |
| 80 if (!reducer->Finish()) { | |
| 81 done = false; | |
| 82 break; | |
| 83 } | |
| 84 } | |
| 85 if (done) break; | |
| 86 // Reset all marks on the graph in preparation to re-reduce the graph. | |
| 87 state_.Reset(graph()); | |
| 88 } | |
| 89 } | |
| 90 | 71 |
| 91 | 72 |
| 92 Reduction GraphReducer::Reduce(Node* const node) { | 73 Reduction GraphReducer::Reduce(Node* const node) { |
| 93 auto skip = reducers_.end(); | 74 auto skip = reducers_.end(); |
| 94 for (auto i = reducers_.begin(); i != reducers_.end();) { | 75 for (auto i = reducers_.begin(); i != reducers_.end();) { |
| 95 if (i != skip) { | 76 if (i != skip) { |
| 96 Reduction reduction = (*i)->Reduce(node); | 77 Reduction reduction = (*i)->Reduce(node); |
| 97 if (!reduction.Changed()) { | 78 if (!reduction.Changed()) { |
| 98 // No change from this reducer. | 79 // No change from this reducer. |
| 99 } else if (reduction.replacement() == node) { | 80 } else if (reduction.replacement() == node) { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 void GraphReducer::Revisit(Node* node) { | 256 void GraphReducer::Revisit(Node* node) { |
| 276 if (state_.Get(node) == State::kVisited) { | 257 if (state_.Get(node) == State::kVisited) { |
| 277 state_.Set(node, State::kRevisit); | 258 state_.Set(node, State::kRevisit); |
| 278 revisit_.push(node); | 259 revisit_.push(node); |
| 279 } | 260 } |
| 280 } | 261 } |
| 281 | 262 |
| 282 } // namespace compiler | 263 } // namespace compiler |
| 283 } // namespace internal | 264 } // namespace internal |
| 284 } // namespace v8 | 265 } // namespace v8 |
| OLD | NEW |