blob: 8040897fd33be5507ad84bc261304456806aa6dc [file] [log] [blame]
Ben Murdoch014dc512016-03-22 12:00:34 +00001// Copyright 2014 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#include "src/compiler/all-nodes.h"
6
7#include "src/compiler/graph.h"
8
9namespace v8 {
10namespace internal {
11namespace compiler {
12
Ben Murdochf91f0612016-11-29 16:50:11 +000013AllNodes::AllNodes(Zone* local_zone, const Graph* graph, bool only_inputs)
14 : reachable(local_zone),
15 is_reachable_(graph->NodeCount(), false, local_zone),
16 only_inputs_(only_inputs) {
Ben Murdoch014dc512016-03-22 12:00:34 +000017 Node* end = graph->end();
Ben Murdochf91f0612016-11-29 16:50:11 +000018 is_reachable_[end->id()] = true;
19 reachable.push_back(end);
20 // Find all nodes reachable from end.
21 for (size_t i = 0; i < reachable.size(); i++) {
22 for (Node* input : reachable[i]->inputs()) {
23 if (input == nullptr || input->id() >= graph->NodeCount()) {
Ben Murdoch014dc512016-03-22 12:00:34 +000024 continue;
25 }
Ben Murdochf91f0612016-11-29 16:50:11 +000026 if (!is_reachable_[input->id()]) {
27 is_reachable_[input->id()] = true;
28 reachable.push_back(input);
Ben Murdoch014dc512016-03-22 12:00:34 +000029 }
Ben Murdochf91f0612016-11-29 16:50:11 +000030 }
31 if (!only_inputs) {
32 for (Node* use : reachable[i]->uses()) {
33 if (use == nullptr || use->id() >= graph->NodeCount()) {
34 continue;
35 }
36 if (!is_reachable_[use->id()]) {
37 is_reachable_[use->id()] = true;
38 reachable.push_back(use);
39 }
Ben Murdoch014dc512016-03-22 12:00:34 +000040 }
41 }
42 }
43}
44
45} // namespace compiler
46} // namespace internal
47} // namespace v8