all-nodes.h 1.5 KB
Newer Older
1 2 3 4 5 6 7 8
// 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"
9
#include "src/zone/zone-containers.h"
10 11 12 13 14 15 16 17 18

namespace v8 {
namespace internal {
namespace compiler {

// A helper utility that traverses the graph and gathers all nodes reachable
// from end.
class AllNodes {
 public:
19 20 21 22 23 24 25
  // Constructor. Traverses the graph and builds the {reachable} set of nodes
  // reachable from {end}. When {only_inputs} is true, find the nodes
  // reachable through input edges; these are all live nodes.
  AllNodes(Zone* local_zone, Node* end, const Graph* graph,
           bool only_inputs = true);
  // Constructor. Traverses the graph and builds the {reachable} set of nodes
  // reachable from the End node.
26
  AllNodes(Zone* local_zone, const Graph* graph, bool only_inputs = true);
27

28
  bool IsLive(const Node* node) const {
29 30 31 32
    CHECK(only_inputs_);
    return IsReachable(node);
  }

33
  bool IsReachable(const Node* node) const {
34 35
    if (!node) return false;
    size_t id = node->id();
36
    return id < is_reachable_.size() && is_reachable_[id];
37 38
  }

39
  NodeVector reachable;  // Nodes reachable from end.
40 41

 private:
42 43
  void Mark(Zone* local_zone, Node* end, const Graph* graph);

44 45
  BoolVector is_reachable_;
  const bool only_inputs_;
46
};
47 48 49 50

}  // namespace compiler
}  // namespace internal
}  // namespace v8
51 52

#endif  // V8_COMPILER_ALL_NODES_H_