1 // 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 9 namespace v8 { 10 namespace internal { 11 namespace compiler { 12 GraphTrimmer(Zone * zone,Graph * graph)13GraphTrimmer::GraphTrimmer(Zone* zone, Graph* graph) 14 : graph_(graph), is_live_(graph, 2), live_(zone) { 15 live_.reserve(graph->NodeCount()); 16 } 17 18 ~GraphTrimmer()19GraphTrimmer::~GraphTrimmer() {} 20 21 TrimGraph()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) { 27 for (Node* const input : live_[i]->inputs()) MarkAsLive(input); 28 } 29 // Remove dead->live edges. 30 for (Node* const live : live_) { 31 DCHECK(IsLive(live)); 32 for (Edge edge : live->use_edges()) { 33 Node* const user = edge.from(); 34 if (!IsLive(user)) { 35 if (FLAG_trace_turbo_reduction) { 36 OFStream os(stdout); 37 os << "DeadLink: " << *user << "(" << edge.index() << ") -> " << *live 38 << std::endl; 39 } 40 edge.UpdateTo(nullptr); 41 } 42 } 43 } 44 } 45 46 } // namespace compiler 47 } // namespace internal 48 } // namespace v8 49