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 {live} sets. | 19 // Constructor. Traverses the graph and builds the {reachable} sets. When |
20 AllNodes(Zone* local_zone, const Graph* graph); | 20 // {only_inputs} is true, find the nodes reachable through input edges; |
| 21 // these are all live nodes. |
| 22 AllNodes(Zone* local_zone, const Graph* graph, bool only_inputs = true); |
21 | 23 |
22 bool IsLive(Node* node) { | 24 bool IsLive(Node* node) { |
| 25 CHECK(only_inputs_); |
| 26 return IsReachable(node); |
| 27 } |
| 28 |
| 29 bool IsReachable(Node* node) { |
23 if (!node) return false; | 30 if (!node) return false; |
24 size_t id = node->id(); | 31 size_t id = node->id(); |
25 return id < is_live.size() && is_live[id]; | 32 return id < is_reachable_.size() && is_reachable_[id]; |
26 } | 33 } |
27 | 34 |
28 NodeVector live; // Nodes reachable from end. | 35 NodeVector reachable; // Nodes reachable from end. |
29 | 36 |
30 private: | 37 private: |
31 BoolVector is_live; | 38 BoolVector is_reachable_; |
| 39 const bool only_inputs_; |
32 }; | 40 }; |
33 | 41 |
34 } // namespace compiler | 42 } // namespace compiler |
35 } // namespace internal | 43 } // namespace internal |
36 } // namespace v8 | 44 } // namespace v8 |
37 | 45 |
38 #endif // V8_COMPILER_ALL_NODES_H_ | 46 #endif // V8_COMPILER_ALL_NODES_H_ |
OLD | NEW |