| 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 #include "src/compiler/verifier.h" | 12 #include "src/compiler/verifier.h" |
| 13 | 13 |
| 14 namespace v8 { | 14 namespace v8 { |
| 15 namespace internal { | 15 namespace internal { |
| 16 namespace compiler { | 16 namespace compiler { |
| 17 | 17 |
| 18 enum class GraphReducer::State : uint8_t { | 18 enum class GraphReducer::State : uint8_t { |
| 19 kUnvisited, | 19 kUnvisited, |
| 20 kRevisit, | 20 kRevisit, |
| 21 kOnStack, | 21 kOnStack, |
| 22 kVisited | 22 kVisited |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 | 25 |
| 26 void Reducer::Finalize() {} |
| 27 |
| 28 |
| 26 GraphReducer::GraphReducer(Zone* zone, Graph* graph, Node* dead) | 29 GraphReducer::GraphReducer(Zone* zone, Graph* graph, Node* dead) |
| 27 : graph_(graph), | 30 : graph_(graph), |
| 28 dead_(dead), | 31 dead_(dead), |
| 29 state_(graph, 4), | 32 state_(graph, 4), |
| 30 reducers_(zone), | 33 reducers_(zone), |
| 31 revisit_(zone), | 34 revisit_(zone), |
| 32 stack_(zone) {} | 35 stack_(zone) {} |
| 33 | 36 |
| 34 | 37 |
| 35 GraphReducer::~GraphReducer() {} | 38 GraphReducer::~GraphReducer() {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 51 ReduceTop(); | 54 ReduceTop(); |
| 52 } else if (!revisit_.empty()) { | 55 } else if (!revisit_.empty()) { |
| 53 // If the stack becomes empty, revisit any nodes in the revisit queue. | 56 // If the stack becomes empty, revisit any nodes in the revisit queue. |
| 54 Node* const node = revisit_.top(); | 57 Node* const node = revisit_.top(); |
| 55 revisit_.pop(); | 58 revisit_.pop(); |
| 56 if (state_.Get(node) == State::kRevisit) { | 59 if (state_.Get(node) == State::kRevisit) { |
| 57 // state can change while in queue. | 60 // state can change while in queue. |
| 58 Push(node); | 61 Push(node); |
| 59 } | 62 } |
| 60 } else { | 63 } else { |
| 61 break; | 64 // Run all finalizers. |
| 65 for (Reducer* const reducer : reducers_) reducer->Finalize(); |
| 66 |
| 67 // Check if we have new nodes to revisit. |
| 68 if (revisit_.empty()) break; |
| 62 } | 69 } |
| 63 } | 70 } |
| 64 DCHECK(revisit_.empty()); | 71 DCHECK(revisit_.empty()); |
| 65 DCHECK(stack_.empty()); | 72 DCHECK(stack_.empty()); |
| 66 } | 73 } |
| 67 | 74 |
| 68 | 75 |
| 69 void GraphReducer::ReduceGraph() { ReduceNode(graph()->end()); } | 76 void GraphReducer::ReduceGraph() { ReduceNode(graph()->end()); } |
| 70 | 77 |
| 71 | 78 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 void GraphReducer::Revisit(Node* node) { | 261 void GraphReducer::Revisit(Node* node) { |
| 255 if (state_.Get(node) == State::kVisited) { | 262 if (state_.Get(node) == State::kVisited) { |
| 256 state_.Set(node, State::kRevisit); | 263 state_.Set(node, State::kRevisit); |
| 257 revisit_.push(node); | 264 revisit_.push(node); |
| 258 } | 265 } |
| 259 } | 266 } |
| 260 | 267 |
| 261 } // namespace compiler | 268 } // namespace compiler |
| 262 } // namespace internal | 269 } // namespace internal |
| 263 } // namespace v8 | 270 } // namespace v8 |
| OLD | NEW |