Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: src/compiler/escape-analysis-reducer.cc

Issue 1457683003: [turbofan] Initial support for escape analysis. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/escape-analysis-reducer.h ('k') | src/compiler/pipeline.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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/escape-analysis-reducer.h"
6
7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/js-operator.h"
9
10 namespace v8 {
11 namespace internal {
12 namespace compiler {
13
14 EscapeAnalysisReducer::EscapeAnalysisReducer(
15 Editor* editor, JSGraph* jsgraph, EscapeStatusAnalysis* escape_status,
16 EscapeObjectAnalysis* escape_analysis, Zone* zone)
17 : AdvancedReducer(editor),
18 jsgraph_(jsgraph),
19 escape_status_(escape_status),
20 escape_analysis_(escape_analysis),
21 zone_(zone) {}
22
23
24 Reduction EscapeAnalysisReducer::Reduce(Node* node) {
25 switch (node->opcode()) {
26 case IrOpcode::kLoadField:
27 return ReduceLoadField(node);
28 case IrOpcode::kStoreField:
29 return ReduceStoreField(node);
30 case IrOpcode::kAllocate:
31 return ReduceAllocate(node);
32 case IrOpcode::kFinishRegion:
33 return ReduceFinishRegion(node);
34 case IrOpcode::kReferenceEqual:
35 return ReduceReferenceEqual(node);
36 case IrOpcode::kStateValues:
37 case IrOpcode::kFrameState:
38 return ReplaceWithDeoptDummy(node);
39 default:
40 break;
41 }
42 return NoChange();
43 }
44
45
46 Reduction EscapeAnalysisReducer::ReduceLoadField(Node* node) {
47 DCHECK_EQ(node->opcode(), IrOpcode::kLoadField);
48 if (Node* rep = escape_analysis()->GetReplacement(node, node->id())) {
49 if (FLAG_trace_turbo_escape) {
50 PrintF("Replaced #%d with #%d\n", node->id(), rep->id());
51 }
52 ReplaceWithValue(node, rep);
53 return Changed(rep);
54 }
55 return NoChange();
56 }
57
58
59 Reduction EscapeAnalysisReducer::ReduceStoreField(Node* node) {
60 DCHECK_EQ(node->opcode(), IrOpcode::kStoreField);
61 if (escape_status()->IsVirtual(NodeProperties::GetValueInput(node, 0))) {
62 if (FLAG_trace_turbo_escape) {
63 PrintF("Removed store field #%d from effect chain\n", node->id());
64 }
65 RelaxEffectsAndControls(node);
66 return Changed(node);
67 }
68 return NoChange();
69 }
70
71
72 Reduction EscapeAnalysisReducer::ReduceAllocate(Node* node) {
73 DCHECK_EQ(node->opcode(), IrOpcode::kAllocate);
74 if (escape_status()->IsVirtual(node)) {
75 RelaxEffectsAndControls(node);
76 if (FLAG_trace_turbo_escape) {
77 PrintF("Removed allocate #%d from effect chain\n", node->id());
78 }
79 return Changed(node);
80 }
81 return NoChange();
82 }
83
84
85 Reduction EscapeAnalysisReducer::ReduceFinishRegion(Node* node) {
86 DCHECK_EQ(node->opcode(), IrOpcode::kFinishRegion);
87 Node* effect = NodeProperties::GetEffectInput(node, 0);
88 if (effect->opcode() == IrOpcode::kBeginRegion) {
89 RelaxEffectsAndControls(effect);
90 RelaxEffectsAndControls(node);
91 if (FLAG_trace_turbo_escape) {
92 PrintF("Removed region #%d / #%d from effect chain,", effect->id(),
93 node->id());
94 PrintF("%d user(s) of #%d remain(s):", node->UseCount(), node->id());
95 for (Edge edge : node->use_edges()) {
96 PrintF(" #%d", edge.from()->id());
97 }
98 PrintF("\n");
99 }
100 return Changed(node);
101 }
102 return NoChange();
103 }
104
105
106 Reduction EscapeAnalysisReducer::ReduceReferenceEqual(Node* node) {
107 DCHECK_EQ(node->opcode(), IrOpcode::kReferenceEqual);
108 Node* left = NodeProperties::GetValueInput(node, 0);
109 Node* right = NodeProperties::GetValueInput(node, 1);
110 if (escape_status()->IsVirtual(left)) {
111 if (escape_status()->IsVirtual(right)) {
112 if (Node* rep = escape_analysis()->GetReplacement(node, left->id())) {
113 left = rep;
114 }
115 if (Node* rep = escape_analysis()->GetReplacement(node, right->id())) {
116 right = rep;
117 }
118 // TODO(sigurds): What to do if either is a PHI?
119 if (left == right) {
120 ReplaceWithValue(node, jsgraph()->TrueConstant());
121 if (FLAG_trace_turbo_escape) {
122 PrintF("Replaced ref eq #%d with true\n", node->id());
123 }
124 return Replace(node);
125 }
126 }
127 // Right-hand side is either not virtual, or a different node.
128 ReplaceWithValue(node, jsgraph()->FalseConstant());
129 if (FLAG_trace_turbo_escape) {
130 PrintF("Replaced ref eq #%d with false\n", node->id());
131 }
132 return Replace(node);
133 } else if (escape_status()->IsVirtual(right)) {
134 // Left-hand side is not a virtual object.
135 ReplaceWithValue(node, jsgraph()->FalseConstant());
136 if (FLAG_trace_turbo_escape) {
137 PrintF("Replaced ref eq #%d with false\n", node->id());
138 }
139 }
140 return NoChange();
141 }
142
143
144 // TODO(sigurds): This is a temporary solution until escape analysis
145 // supports deoptimization.
146 Reduction EscapeAnalysisReducer::ReplaceWithDeoptDummy(Node* node) {
147 DCHECK(node->opcode() == IrOpcode::kStateValues ||
148 node->opcode() == IrOpcode::kFrameState);
149 Reduction r = NoChange();
150 for (int i = 0; i < node->op()->ValueInputCount(); ++i) {
151 Node* input = NodeProperties::GetValueInput(node, i);
152 if (input->opcode() == IrOpcode::kFinishRegion ||
153 input->opcode() == IrOpcode::kAllocate ||
154 input->opcode() == IrOpcode::kPhi) {
155 if (escape_status()->IsVirtual(input)) {
156 NodeProperties::ReplaceValueInput(node, jsgraph()->UndefinedConstant(),
157 i);
158 if (FLAG_trace_turbo_escape) {
159 PrintF("Replaced state value (#%d) input with dummy\n", node->id());
160 }
161 r = Changed(node);
162 }
163 }
164 }
165 return r;
166 }
167
168
169 } // namespace compiler
170 } // namespace internal
171 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/escape-analysis-reducer.h ('k') | src/compiler/pipeline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698