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 10021074 : GraphTrimmer::GraphTrimmer(Zone* zone, Graph* graph)
14 5010488 : : graph_(graph), is_live_(graph, 2), live_(zone) {
15 5010586 : live_.reserve(graph->NodeCount());
16 5010851 : }
17 :
18 :
19 : GraphTrimmer::~GraphTrimmer() = default;
20 :
21 :
22 5010727 : void GraphTrimmer::TrimGraph() {
23 : // Mark end node as live.
24 5010727 : MarkAsLive(graph()->end());
25 : // Compute transitive closure of live nodes.
26 607452975 : for (size_t i = 0; i < live_.size(); ++i) {
27 607453758 : Node* const live = live_[i];
28 1286859248 : for (Node* const input : live->inputs()) MarkAsLive(input);
29 : }
30 : // Remove dead->live edges.
31 607458263 : for (Node* const live : live_) {
32 : DCHECK(IsLive(live));
33 2062535789 : for (Edge edge : live->use_edges()) {
34 : Node* const user = edge.from();
35 730044494 : if (!IsLive(user)) {
36 45635459 : if (FLAG_trace_turbo_trimming) {
37 0 : StdoutStream{} << "DeadLink: " << *user << "(" << edge.index()
38 0 : << ") -> " << *live << std::endl;
39 : }
40 45635459 : edge.UpdateTo(nullptr);
41 : }
42 : }
43 : }
44 5010863 : }
45 :
46 : } // namespace compiler
47 : } // namespace internal
48 183867 : } // namespace v8
|