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#include "src/compiler/graph-trimmer.h" 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci#include "src/compiler/graph.h" 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_cinamespace v8 { 101cb0ef41Sopenharmony_cinamespace internal { 111cb0ef41Sopenharmony_cinamespace compiler { 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciGraphTrimmer::GraphTrimmer(Zone* zone, Graph* graph) 141cb0ef41Sopenharmony_ci : graph_(graph), is_live_(graph, 2), live_(zone) { 151cb0ef41Sopenharmony_ci live_.reserve(graph->NodeCount()); 161cb0ef41Sopenharmony_ci} 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ciGraphTrimmer::~GraphTrimmer() = default; 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_civoid GraphTrimmer::TrimGraph() { 231cb0ef41Sopenharmony_ci // Mark end node as live. 241cb0ef41Sopenharmony_ci MarkAsLive(graph()->end()); 251cb0ef41Sopenharmony_ci // Compute transitive closure of live nodes. 261cb0ef41Sopenharmony_ci for (size_t i = 0; i < live_.size(); ++i) { 271cb0ef41Sopenharmony_ci Node* const live = live_[i]; 281cb0ef41Sopenharmony_ci for (Node* const input : live->inputs()) MarkAsLive(input); 291cb0ef41Sopenharmony_ci } 301cb0ef41Sopenharmony_ci // Remove dead->live edges. 311cb0ef41Sopenharmony_ci for (Node* const live : live_) { 321cb0ef41Sopenharmony_ci DCHECK(IsLive(live)); 331cb0ef41Sopenharmony_ci for (Edge edge : live->use_edges()) { 341cb0ef41Sopenharmony_ci Node* const user = edge.from(); 351cb0ef41Sopenharmony_ci if (!IsLive(user)) { 361cb0ef41Sopenharmony_ci if (FLAG_trace_turbo_trimming) { 371cb0ef41Sopenharmony_ci StdoutStream{} << "DeadLink: " << *user << "(" << edge.index() 381cb0ef41Sopenharmony_ci << ") -> " << *live << std::endl; 391cb0ef41Sopenharmony_ci } 401cb0ef41Sopenharmony_ci edge.UpdateTo(nullptr); 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci } 431cb0ef41Sopenharmony_ci } 441cb0ef41Sopenharmony_ci} 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci} // namespace compiler 471cb0ef41Sopenharmony_ci} // namespace internal 481cb0ef41Sopenharmony_ci} // namespace v8 49