OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/js-inlining.h" | 5 #include "src/compiler/js-inlining.h" |
6 | 6 |
7 #include "src/ast.h" | 7 #include "src/ast.h" |
8 #include "src/ast-numbering.h" | 8 #include "src/ast-numbering.h" |
9 #include "src/compiler/access-builder.h" | |
10 #include "src/compiler/all-nodes.h" | 9 #include "src/compiler/all-nodes.h" |
11 #include "src/compiler/ast-graph-builder.h" | 10 #include "src/compiler/ast-graph-builder.h" |
12 #include "src/compiler/common-operator.h" | 11 #include "src/compiler/common-operator.h" |
13 #include "src/compiler/graph-visualizer.h" | |
14 #include "src/compiler/js-operator.h" | 12 #include "src/compiler/js-operator.h" |
15 #include "src/compiler/node-matchers.h" | 13 #include "src/compiler/node-matchers.h" |
16 #include "src/compiler/node-properties.h" | 14 #include "src/compiler/node-properties.h" |
17 #include "src/compiler/operator-properties.h" | 15 #include "src/compiler/operator-properties.h" |
18 #include "src/compiler/simplified-operator.h" | |
19 #include "src/compiler/typer.h" | |
20 #include "src/full-codegen.h" | 16 #include "src/full-codegen.h" |
21 #include "src/parser.h" | 17 #include "src/parser.h" |
22 #include "src/rewriter.h" | 18 #include "src/rewriter.h" |
23 #include "src/scopes.h" | 19 #include "src/scopes.h" |
24 | 20 |
25 namespace v8 { | 21 namespace v8 { |
26 namespace internal { | 22 namespace internal { |
27 namespace compiler { | 23 namespace compiler { |
28 | 24 |
29 | 25 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 size_t total_parameters() { return start_->op()->ValueOutputCount(); } | 92 size_t total_parameters() { return start_->op()->ValueOutputCount(); } |
97 | 93 |
98 // Counts only formal parameters. | 94 // Counts only formal parameters. |
99 size_t formal_parameters() { | 95 size_t formal_parameters() { |
100 DCHECK_GE(total_parameters(), 3u); | 96 DCHECK_GE(total_parameters(), 3u); |
101 return total_parameters() - 3; | 97 return total_parameters() - 3; |
102 } | 98 } |
103 | 99 |
104 // Inline this graph at {call}, use {jsgraph} and its zone to create | 100 // Inline this graph at {call}, use {jsgraph} and its zone to create |
105 // any new nodes. | 101 // any new nodes. |
106 Reduction InlineAtCall(JSGraph* jsgraph, Node* call); | 102 Reduction InlineAtCall(JSGraph* jsgraph, Node* call, Node* context); |
107 | 103 |
108 // Ensure that only a single return reaches the end node. | 104 // Ensure that only a single return reaches the end node. |
109 static void UnifyReturn(JSGraph* jsgraph); | 105 static void UnifyReturn(JSGraph* jsgraph); |
110 | 106 |
111 private: | 107 private: |
112 Node* start_; | 108 Node* start_; |
113 Node* end_; | 109 Node* end_; |
114 }; | 110 }; |
115 | 111 |
116 | 112 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 private: | 205 private: |
210 Operator const sentinel_op_; | 206 Operator const sentinel_op_; |
211 Node* const sentinel_; | 207 Node* const sentinel_; |
212 NodeVector copies_; | 208 NodeVector copies_; |
213 Graph* const source_graph_; | 209 Graph* const source_graph_; |
214 Graph* const target_graph_; | 210 Graph* const target_graph_; |
215 Zone* const temp_zone_; | 211 Zone* const temp_zone_; |
216 }; | 212 }; |
217 | 213 |
218 | 214 |
219 Reduction Inlinee::InlineAtCall(JSGraph* jsgraph, Node* call) { | 215 Reduction Inlinee::InlineAtCall(JSGraph* jsgraph, Node* call, Node* context) { |
220 // The scheduler is smart enough to place our code; we just ensure {control} | 216 // The scheduler is smart enough to place our code; we just ensure {control} |
221 // becomes the control input of the start of the inlinee. | 217 // becomes the control input of the start of the inlinee, and {effect} becomes |
| 218 // the effect input of the start of the inlinee. |
222 Node* control = NodeProperties::GetControlInput(call); | 219 Node* control = NodeProperties::GetControlInput(call); |
223 | 220 Node* effect = NodeProperties::GetEffectInput(call); |
224 // The inlinee uses the context from the JSFunction object. This will | |
225 // also be the effect dependency for the inlinee as it produces an effect. | |
226 SimplifiedOperatorBuilder simplified(jsgraph->zone()); | |
227 Node* context = jsgraph->graph()->NewNode( | |
228 simplified.LoadField(AccessBuilder::ForJSFunctionContext()), | |
229 NodeProperties::GetValueInput(call, 0), | |
230 NodeProperties::GetEffectInput(call), control); | |
231 | 221 |
232 // Context is last argument. | 222 // Context is last argument. |
233 int inlinee_context_index = static_cast<int>(total_parameters()) - 1; | 223 int inlinee_context_index = static_cast<int>(total_parameters()) - 1; |
234 // {inliner_inputs} counts JSFunction, Receiver, arguments, but not | 224 // {inliner_inputs} counts JSFunction, Receiver, arguments, but not |
235 // context, effect, control. | 225 // context, effect, control. |
236 int inliner_inputs = call->op()->ValueInputCount(); | 226 int inliner_inputs = call->op()->ValueInputCount(); |
237 // Iterate over all uses of the start node. | 227 // Iterate over all uses of the start node. |
238 for (Edge edge : start_->use_edges()) { | 228 for (Edge edge : start_->use_edges()) { |
239 Node* use = edge.from(); | 229 Node* use = edge.from(); |
240 switch (use->opcode()) { | 230 switch (use->opcode()) { |
(...skipping 11 matching lines...) Expand all Loading... |
252 // Call has fewer arguments than required, fill with undefined. | 242 // Call has fewer arguments than required, fill with undefined. |
253 NodeProperties::ReplaceWithValue(use, jsgraph->UndefinedConstant()); | 243 NodeProperties::ReplaceWithValue(use, jsgraph->UndefinedConstant()); |
254 } else { | 244 } else { |
255 // We got too many arguments, discard for now. | 245 // We got too many arguments, discard for now. |
256 // TODO(sigurds): Fix to treat arguments array correctly. | 246 // TODO(sigurds): Fix to treat arguments array correctly. |
257 } | 247 } |
258 break; | 248 break; |
259 } | 249 } |
260 default: | 250 default: |
261 if (NodeProperties::IsEffectEdge(edge)) { | 251 if (NodeProperties::IsEffectEdge(edge)) { |
262 edge.UpdateTo(context); | 252 edge.UpdateTo(effect); |
263 } else if (NodeProperties::IsControlEdge(edge)) { | 253 } else if (NodeProperties::IsControlEdge(edge)) { |
264 edge.UpdateTo(control); | 254 edge.UpdateTo(control); |
265 } else { | 255 } else { |
266 UNREACHABLE(); | 256 UNREACHABLE(); |
267 } | 257 } |
268 break; | 258 break; |
269 } | 259 } |
270 } | 260 } |
271 | 261 |
272 for (Edge edge : call->use_edges()) { | 262 NodeProperties::ReplaceWithValue(call, value_output(), effect_output(), |
273 if (NodeProperties::IsControlEdge(edge)) { | 263 control_output()); |
274 // TODO(turbofan): Handle kIfException uses. | |
275 DCHECK_EQ(IrOpcode::kIfSuccess, edge.from()->opcode()); | |
276 edge.from()->ReplaceUses(control_output()); | |
277 edge.UpdateTo(nullptr); | |
278 } else if (NodeProperties::IsEffectEdge(edge)) { | |
279 edge.UpdateTo(effect_output()); | |
280 } else { | |
281 edge.UpdateTo(value_output()); | |
282 } | |
283 } | |
284 | 264 |
285 return Reducer::Replace(value_output()); | 265 return Reducer::Replace(value_output()); |
286 } | 266 } |
287 | 267 |
288 } // namespace | 268 } // namespace |
289 | 269 |
290 | 270 |
291 void JSInliner::AddClosureToFrameState(Node* frame_state, | 271 void JSInliner::AddClosureToFrameState(Node* frame_state, |
292 Handle<JSFunction> jsfunction) { | 272 Handle<JSFunction> jsfunction) { |
293 FrameStateCallInfo call_info = OpParameter<FrameStateCallInfo>(frame_state); | 273 FrameStateCallInfo call_info = OpParameter<FrameStateCallInfo>(frame_state); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 360 |
381 for (Node* node : visitor.copies()) { | 361 for (Node* node : visitor.copies()) { |
382 if (node && node->opcode() == IrOpcode::kFrameState) { | 362 if (node && node->opcode() == IrOpcode::kFrameState) { |
383 DCHECK_EQ(1, OperatorProperties::GetFrameStateInputCount(node->op())); | 363 DCHECK_EQ(1, OperatorProperties::GetFrameStateInputCount(node->op())); |
384 AddClosureToFrameState(node, function); | 364 AddClosureToFrameState(node, function); |
385 NodeProperties::ReplaceFrameStateInput(node, 0, outer_frame_state); | 365 NodeProperties::ReplaceFrameStateInput(node, 0, outer_frame_state); |
386 } | 366 } |
387 } | 367 } |
388 } | 368 } |
389 | 369 |
390 return inlinee.InlineAtCall(jsgraph_, node); | 370 // The inlinee uses the context from the JSFunction object. |
| 371 // TODO(turbofan): We might want to load the context from the JSFunction at |
| 372 // runtime in case we only know the SharedFunctionInfo once we have dynamic |
| 373 // type feedback in the compiler. |
| 374 Node* context = jsgraph_->HeapConstant(handle(function->context())); |
| 375 |
| 376 return inlinee.InlineAtCall(jsgraph_, node, context); |
391 } | 377 } |
392 | 378 |
393 } // namespace compiler | 379 } // namespace compiler |
394 } // namespace internal | 380 } // namespace internal |
395 } // namespace v8 | 381 } // namespace v8 |
OLD | NEW |