Line data Source code
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 :
13 4786093 : GraphTrimmer::GraphTrimmer(Zone* zone, Graph* graph)
14 4786093 : : graph_(graph), is_live_(graph, 2), live_(zone) {
15 4786379 : live_.reserve(graph->NodeCount());
16 4788712 : }
17 :
18 :
19 : GraphTrimmer::~GraphTrimmer() = default;
20 :
21 :
22 4786091 : void GraphTrimmer::TrimGraph() {
23 : // Mark end node as live.
24 : MarkAsLive(graph()->end());
25 : // Compute transitive closure of live nodes.
26 641692175 : for (size_t i = 0; i < live_.size(); ++i) {
27 318444170 : Node* const live = live_[i];
28 1070954326 : for (Node* const input : live->inputs()) MarkAsLive(input);
29 : }
30 : // Remove dead->live edges.
31 323271010 : for (Node* const live : live_) {
32 : DCHECK(IsLive(live));
33 1908975836 : for (Edge edge : live->use_edges()) {
34 : Node* const user = edge.from();
35 795250365 : if (!IsLive(user)) {
36 42724751 : if (FLAG_trace_turbo_trimming) {
37 0 : StdoutStream{} << "DeadLink: " << *user << "(" << edge.index()
38 0 : << ") -> " << *live << std::endl;
39 : }
40 42724751 : edge.UpdateTo(nullptr);
41 : }
42 : }
43 : }
44 4788762 : }
45 :
46 : } // namespace compiler
47 : } // namespace internal
48 121996 : } // namespace v8
|