blob: 75071c68b3b5cf1163822edad9aa5f7ca9babaa5 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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#include "src/compiler/graph-trimmer.h"
6
7#include "src/compiler/graph.h"
8
9namespace v8 {
10namespace internal {
11namespace compiler {
12
13GraphTrimmer::GraphTrimmer(Zone* zone, Graph* graph)
14 : graph_(graph), is_live_(graph, 2), live_(zone) {
15 live_.reserve(graph->NodeCount());
16}
17
18
19GraphTrimmer::~GraphTrimmer() {}
20
21
22void GraphTrimmer::TrimGraph() {
23 // Mark end node as live.
24 MarkAsLive(graph()->end());
25 // Compute transitive closure of live nodes.
26 for (size_t i = 0; i < live_.size(); ++i) {
Ben Murdoch097c5b22016-05-18 11:27:45 +010027 Node* const live = live_[i];
28 for (Node* const input : live->inputs()) MarkAsLive(input);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000029 }
30 // Remove dead->live edges.
31 for (Node* const live : live_) {
32 DCHECK(IsLive(live));
33 for (Edge edge : live->use_edges()) {
34 Node* const user = edge.from();
35 if (!IsLive(user)) {
36 if (FLAG_trace_turbo_reduction) {
37 OFStream os(stdout);
38 os << "DeadLink: " << *user << "(" << edge.index() << ") -> " << *live
39 << std::endl;
40 }
41 edge.UpdateTo(nullptr);
42 }
43 }
44 }
45}
46
47} // namespace compiler
48} // namespace internal
49} // namespace v8