11cb0ef41Sopenharmony_ci// Copyright 2015 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#ifndef V8_COMPILER_ALL_NODES_H_ 61cb0ef41Sopenharmony_ci#define V8_COMPILER_ALL_NODES_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/compiler/node.h" 91cb0ef41Sopenharmony_ci#include "src/zone/zone-containers.h" 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cinamespace v8 { 121cb0ef41Sopenharmony_cinamespace internal { 131cb0ef41Sopenharmony_cinamespace compiler { 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci// A helper utility that traverses the graph and gathers all nodes reachable 161cb0ef41Sopenharmony_ci// from end. 171cb0ef41Sopenharmony_ciclass AllNodes { 181cb0ef41Sopenharmony_ci public: 191cb0ef41Sopenharmony_ci // Constructor. Traverses the graph and builds the {reachable} set of nodes 201cb0ef41Sopenharmony_ci // reachable from {end}. When {only_inputs} is true, find the nodes 211cb0ef41Sopenharmony_ci // reachable through input edges; these are all live nodes. 221cb0ef41Sopenharmony_ci AllNodes(Zone* local_zone, Node* end, const Graph* graph, 231cb0ef41Sopenharmony_ci bool only_inputs = true); 241cb0ef41Sopenharmony_ci // Constructor. Traverses the graph and builds the {reachable} set of nodes 251cb0ef41Sopenharmony_ci // reachable from the End node. 261cb0ef41Sopenharmony_ci AllNodes(Zone* local_zone, const Graph* graph, bool only_inputs = true); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci bool IsLive(const Node* node) const { 291cb0ef41Sopenharmony_ci CHECK(only_inputs_); 301cb0ef41Sopenharmony_ci return IsReachable(node); 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci bool IsReachable(const Node* node) const { 341cb0ef41Sopenharmony_ci if (!node) return false; 351cb0ef41Sopenharmony_ci size_t id = node->id(); 361cb0ef41Sopenharmony_ci return id < is_reachable_.size() && is_reachable_[id]; 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci NodeVector reachable; // Nodes reachable from end. 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci private: 421cb0ef41Sopenharmony_ci void Mark(Zone* local_zone, Node* end, const Graph* graph); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci BoolVector is_reachable_; 451cb0ef41Sopenharmony_ci const bool only_inputs_; 461cb0ef41Sopenharmony_ci}; 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci} // namespace compiler 491cb0ef41Sopenharmony_ci} // namespace internal 501cb0ef41Sopenharmony_ci} // namespace v8 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci#endif // V8_COMPILER_ALL_NODES_H_ 53