Line data Source code
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
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_COMPILER_ALL_NODES_H_
6 : #define V8_COMPILER_ALL_NODES_H_
7 :
8 : #include "src/compiler/node.h"
9 : #include "src/zone/zone-containers.h"
10 :
11 : namespace v8 {
12 : namespace internal {
13 : namespace compiler {
14 :
15 : // A helper utility that traverses the graph and gathers all nodes reachable
16 : // from end.
17 535146 : class AllNodes {
18 : public:
19 : // Constructor. Traverses the graph and builds the {reachable} set of nodes
20 : // reachable from {end}. When {only_inputs} is true, find the 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.
26 : AllNodes(Zone* local_zone, const Graph* graph, bool only_inputs = true);
27 :
28 16534390 : bool IsLive(const Node* node) const {
29 16534390 : CHECK(only_inputs_);
30 16534390 : return IsReachable(node);
31 : }
32 :
33 16534390 : bool IsReachable(const Node* node) const {
34 16534390 : if (!node) return false;
35 16534390 : size_t id = node->id();
36 33068780 : return id < is_reachable_.size() && is_reachable_[id];
37 : }
38 :
39 : NodeVector reachable; // Nodes reachable from end.
40 :
41 : private:
42 : void Mark(Zone* local_zone, Node* end, const Graph* graph);
43 :
44 : BoolVector is_reachable_;
45 : const bool only_inputs_;
46 : };
47 :
48 : } // namespace compiler
49 : } // namespace internal
50 : } // namespace v8
51 :
52 : #endif // V8_COMPILER_ALL_NODES_H_
|