OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef V8_COMPILER_ALL_NODES_H_ | 5 #ifndef V8_COMPILER_ALL_NODES_H_ |
6 #define V8_COMPILER_ALL_NODES_H_ | 6 #define V8_COMPILER_ALL_NODES_H_ |
7 | 7 |
8 #include "src/compiler/node.h" | 8 #include "src/compiler/node.h" |
9 #include "src/zone-containers.h" | 9 #include "src/zone-containers.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 namespace compiler { | 13 namespace compiler { |
14 | 14 |
15 // A helper utility that traverses the graph and gathers all nodes reachable | 15 // A helper utility that traverses the graph and gathers all nodes reachable |
16 // from end. | 16 // from end. |
17 class AllNodes { | 17 class AllNodes { |
18 public: | 18 public: |
19 // Constructor. Traverses the graph and builds the {reachable} sets. When | 19 // Constructor. Traverses the graph and builds the {reachable} set of nodes |
20 // {only_inputs} is true, find the nodes reachable through input edges; | 20 // reachable from {end}. When {only_inputs} is true, find the nodes |
21 // these are all live nodes. | 21 // reachable through input edges; these are all live nodes. |
| 22 AllNodes(Zone* local_zone, Node* end, const Graph* graph, |
| 23 bool only_inputs = true); |
| 24 // Constructor. Traverses the graph and builds the {reachable} set of nodes |
| 25 // reachable from the End node. |
22 AllNodes(Zone* local_zone, const Graph* graph, bool only_inputs = true); | 26 AllNodes(Zone* local_zone, const Graph* graph, bool only_inputs = true); |
23 | 27 |
24 bool IsLive(Node* node) { | 28 bool IsLive(Node* node) { |
25 CHECK(only_inputs_); | 29 CHECK(only_inputs_); |
26 return IsReachable(node); | 30 return IsReachable(node); |
27 } | 31 } |
28 | 32 |
29 bool IsReachable(Node* node) { | 33 bool IsReachable(Node* node) { |
30 if (!node) return false; | 34 if (!node) return false; |
31 size_t id = node->id(); | 35 size_t id = node->id(); |
32 return id < is_reachable_.size() && is_reachable_[id]; | 36 return id < is_reachable_.size() && is_reachable_[id]; |
33 } | 37 } |
34 | 38 |
35 NodeVector reachable; // Nodes reachable from end. | 39 NodeVector reachable; // Nodes reachable from end. |
36 | 40 |
37 private: | 41 private: |
| 42 void Mark(Zone* local_zone, Node* end, const Graph* graph); |
| 43 |
38 BoolVector is_reachable_; | 44 BoolVector is_reachable_; |
39 const bool only_inputs_; | 45 const bool only_inputs_; |
40 }; | 46 }; |
41 | 47 |
42 } // namespace compiler | 48 } // namespace compiler |
43 } // namespace internal | 49 } // namespace internal |
44 } // namespace v8 | 50 } // namespace v8 |
45 | 51 |
46 #endif // V8_COMPILER_ALL_NODES_H_ | 52 #endif // V8_COMPILER_ALL_NODES_H_ |
OLD | NEW |