| 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/all-nodes.h" | 5 #include "src/compiler/all-nodes.h" |
| 6 | 6 |
| 7 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
| 8 | 8 |
| 9 namespace v8 { | 9 namespace v8 { |
| 10 namespace internal { | 10 namespace internal { |
| 11 namespace compiler { | 11 namespace compiler { |
| 12 | 12 |
| 13 AllNodes::AllNodes(Zone* local_zone, const Graph* graph) | 13 AllNodes::AllNodes(Zone* local_zone, const Graph* graph, bool only_inputs) |
| 14 : live(local_zone), is_live(graph->NodeCount(), false, local_zone) { | 14 : reachable(local_zone), |
| 15 is_reachable_(graph->NodeCount(), false, local_zone), |
| 16 only_inputs_(only_inputs) { |
| 15 Node* end = graph->end(); | 17 Node* end = graph->end(); |
| 16 is_live[end->id()] = true; | 18 is_reachable_[end->id()] = true; |
| 17 live.push_back(end); | 19 reachable.push_back(end); |
| 18 // Find all live nodes reachable from end. | 20 // Find all nodes reachable from end. |
| 19 for (size_t i = 0; i < live.size(); i++) { | 21 for (size_t i = 0; i < reachable.size(); i++) { |
| 20 for (Node* const input : live[i]->inputs()) { | 22 for (Node* input : reachable[i]->inputs()) { |
| 21 if (input == nullptr) { | 23 if (input == nullptr || input->id() >= graph->NodeCount()) { |
| 22 // TODO(titzer): print a warning. | |
| 23 continue; | 24 continue; |
| 24 } | 25 } |
| 25 if (input->id() >= graph->NodeCount()) { | 26 if (!is_reachable_[input->id()]) { |
| 26 // TODO(titzer): print a warning. | 27 is_reachable_[input->id()] = true; |
| 27 continue; | 28 reachable.push_back(input); |
| 28 } | 29 } |
| 29 if (!is_live[input->id()]) { | 30 } |
| 30 is_live[input->id()] = true; | 31 if (!only_inputs) { |
| 31 live.push_back(input); | 32 for (Node* use : reachable[i]->uses()) { |
| 33 if (use == nullptr || use->id() >= graph->NodeCount()) { |
| 34 continue; |
| 35 } |
| 36 if (!is_reachable_[use->id()]) { |
| 37 is_reachable_[use->id()] = true; |
| 38 reachable.push_back(use); |
| 39 } |
| 32 } | 40 } |
| 33 } | 41 } |
| 34 } | 42 } |
| 35 } | 43 } |
| 36 | 44 |
| 37 } // namespace compiler | 45 } // namespace compiler |
| 38 } // namespace internal | 46 } // namespace internal |
| 39 } // namespace v8 | 47 } // namespace v8 |
| OLD | NEW |