aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/compiler/all-nodes.h
blob: 36f02e958256853e619c9ebdec0c48d4ed90d873 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_COMPILER_ALL_NODES_H_
#define V8_COMPILER_ALL_NODES_H_

#include "src/compiler/node.h"
#include "src/zone-containers.h"

namespace v8 {
namespace internal {
namespace compiler {

// A helper utility that traverses the graph and gathers all nodes reachable
// from end.
class AllNodes {
 public:
  // Constructor. Traverses the graph and builds the {reachable} sets. When
  // {only_inputs} is true, find the nodes reachable through input edges;
  // these are all live nodes.
  AllNodes(Zone* local_zone, const Graph* graph, bool only_inputs = true);

  bool IsLive(Node* node) {
    CHECK(only_inputs_);
    return IsReachable(node);
  }

  bool IsReachable(Node* node) {
    if (!node) return false;
    size_t id = node->id();
    return id < is_reachable_.size() && is_reachable_[id];
  }

  NodeVector reachable;  // Nodes reachable from end.

 private:
  BoolVector is_reachable_;
  const bool only_inputs_;
};

}  // namespace compiler
}  // namespace internal
}  // namespace v8

#endif  // V8_COMPILER_ALL_NODES_H_