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