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.h" | 9 #include "src/compiler.h" |
10 #include "src/compiler/all-nodes.h" | 10 #include "src/compiler/all-nodes.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 | 128 |
129 Reduction JSInliner::InlineCall(Node* call, Node* context, Node* frame_state, | 129 Reduction JSInliner::InlineCall(Node* call, Node* context, Node* frame_state, |
130 Node* start, Node* end) { | 130 Node* start, Node* end) { |
131 // The scheduler is smart enough to place our code; we just ensure {control} | 131 // The scheduler is smart enough to place our code; we just ensure {control} |
132 // becomes the control input of the start of the inlinee, and {effect} becomes | 132 // becomes the control input of the start of the inlinee, and {effect} becomes |
133 // the effect input of the start of the inlinee. | 133 // the effect input of the start of the inlinee. |
134 Node* control = NodeProperties::GetControlInput(call); | 134 Node* control = NodeProperties::GetControlInput(call); |
135 Node* effect = NodeProperties::GetEffectInput(call); | 135 Node* effect = NodeProperties::GetEffectInput(call); |
136 | 136 |
137 // Context is last argument. | 137 int const inlinee_arity_index = |
| 138 static_cast<int>(start->op()->ValueOutputCount()) - 2; |
| 139 // Context is last parameter. |
138 int const inlinee_context_index = | 140 int const inlinee_context_index = |
139 static_cast<int>(start->op()->ValueOutputCount()) - 1; | 141 static_cast<int>(start->op()->ValueOutputCount()) - 1; |
140 | 142 |
141 // {inliner_inputs} counts JSFunction, Receiver, arguments, but not | 143 // {inliner_inputs} counts JSFunction, Receiver, arguments, but not |
142 // context, effect, control. | 144 // context, effect, control. |
143 int inliner_inputs = call->op()->ValueInputCount(); | 145 int inliner_inputs = call->op()->ValueInputCount(); |
144 // Iterate over all uses of the start node. | 146 // Iterate over all uses of the start node. |
145 for (Edge edge : start->use_edges()) { | 147 for (Edge edge : start->use_edges()) { |
146 Node* use = edge.from(); | 148 Node* use = edge.from(); |
147 switch (use->opcode()) { | 149 switch (use->opcode()) { |
148 case IrOpcode::kParameter: { | 150 case IrOpcode::kParameter: { |
149 int index = 1 + ParameterIndexOf(use->op()); | 151 int index = 1 + ParameterIndexOf(use->op()); |
150 DCHECK_LE(index, inlinee_context_index); | 152 DCHECK_LE(index, inlinee_context_index); |
151 if (index < inliner_inputs && index < inlinee_context_index) { | 153 if (index < inliner_inputs && index < inlinee_arity_index) { |
152 // There is an input from the call, and the index is a value | 154 // There is an input from the call, and the index is a value |
153 // projection but not the context, so rewire the input. | 155 // projection but not the context, so rewire the input. |
154 Replace(use, call->InputAt(index)); | 156 Replace(use, call->InputAt(index)); |
| 157 } else if (index == inlinee_arity_index) { |
| 158 // The projection is requesting the number of arguments. |
| 159 Replace(use, jsgraph_->Int32Constant(inliner_inputs - 2)); |
155 } else if (index == inlinee_context_index) { | 160 } else if (index == inlinee_context_index) { |
156 // The projection is requesting the inlinee function context. | 161 // The projection is requesting the inlinee function context. |
157 Replace(use, context); | 162 Replace(use, context); |
158 } else { | 163 } else { |
159 // Call has fewer arguments than required, fill with undefined. | 164 // Call has fewer arguments than required, fill with undefined. |
160 Replace(use, jsgraph_->UndefinedConstant()); | 165 Replace(use, jsgraph_->UndefinedConstant()); |
161 } | 166 } |
162 break; | 167 break; |
163 } | 168 } |
164 default: | 169 default: |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 JSCallFunctionAccessor call(node); | 272 JSCallFunctionAccessor call(node); |
268 | 273 |
269 if (!function->shared()->IsInlineable()) { | 274 if (!function->shared()->IsInlineable()) { |
270 // Function must be inlineable. | 275 // Function must be inlineable. |
271 TRACE("Not inlining %s into %s because callee is not inlineable\n", | 276 TRACE("Not inlining %s into %s because callee is not inlineable\n", |
272 function->shared()->DebugName()->ToCString().get(), | 277 function->shared()->DebugName()->ToCString().get(), |
273 info_->shared_info()->DebugName()->ToCString().get()); | 278 info_->shared_info()->DebugName()->ToCString().get()); |
274 return NoChange(); | 279 return NoChange(); |
275 } | 280 } |
276 | 281 |
| 282 // Class constructors are callable, but [[Call]] will raise an exception. |
| 283 // See ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList ). |
| 284 if (IsClassConstructor(function->shared()->kind())) { |
| 285 TRACE("Not inlining %s into %s because callee is classConstructor\n", |
| 286 function->shared()->DebugName()->ToCString().get(), |
| 287 info_->shared_info()->DebugName()->ToCString().get()); |
| 288 return NoChange(); |
| 289 } |
| 290 |
277 if (function->shared()->HasDebugInfo()) { | 291 if (function->shared()->HasDebugInfo()) { |
278 // Function contains break points. | 292 // Function contains break points. |
279 TRACE("Not inlining %s into %s because callee may contain break points\n", | 293 TRACE("Not inlining %s into %s because callee may contain break points\n", |
280 function->shared()->DebugName()->ToCString().get(), | 294 function->shared()->DebugName()->ToCString().get(), |
281 info_->shared_info()->DebugName()->ToCString().get()); | 295 info_->shared_info()->DebugName()->ToCString().get()); |
282 return NoChange(); | 296 return NoChange(); |
283 } | 297 } |
284 | 298 |
285 // Disallow cross native-context inlining for now. This means that all parts | 299 // Disallow cross native-context inlining for now. This means that all parts |
286 // of the resulting code will operate on the same global object. | 300 // of the resulting code will operate on the same global object. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); | 448 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); |
435 Node* effect = NodeProperties::GetEffectInput(node); | 449 Node* effect = NodeProperties::GetEffectInput(node); |
436 Node* convert = jsgraph_->graph()->NewNode( | 450 Node* convert = jsgraph_->graph()->NewNode( |
437 jsgraph_->javascript()->ConvertReceiver(p.convert_mode()), | 451 jsgraph_->javascript()->ConvertReceiver(p.convert_mode()), |
438 call.receiver(), context, call.frame_state_before(), effect, start); | 452 call.receiver(), context, call.frame_state_before(), effect, start); |
439 NodeProperties::ReplaceValueInput(node, convert, 1); | 453 NodeProperties::ReplaceValueInput(node, convert, 1); |
440 NodeProperties::ReplaceEffectInput(node, convert); | 454 NodeProperties::ReplaceEffectInput(node, convert); |
441 } | 455 } |
442 | 456 |
443 // Insert argument adaptor frame if required. The callees formal parameter | 457 // Insert argument adaptor frame if required. The callees formal parameter |
444 // count (i.e. value outputs of start node minus target, receiver & context) | 458 // count (i.e. value outputs of start node minus target, receiver, num args |
445 // have to match the number of arguments passed to the call. | 459 // and context) have to match the number of arguments passed to the call. |
446 DCHECK_EQ(static_cast<int>(parameter_count), | 460 DCHECK_EQ(static_cast<int>(parameter_count), |
447 start->op()->ValueOutputCount() - 3); | 461 start->op()->ValueOutputCount() - 4); |
448 if (call.formal_arguments() != parameter_count) { | 462 if (call.formal_arguments() != parameter_count) { |
449 frame_state = CreateArgumentsAdaptorFrameState(&call, info.shared_info()); | 463 frame_state = CreateArgumentsAdaptorFrameState(&call, info.shared_info()); |
450 } | 464 } |
451 | 465 |
452 return InlineCall(node, context, frame_state, start, end); | 466 return InlineCall(node, context, frame_state, start, end); |
453 } | 467 } |
454 | 468 |
455 } // namespace compiler | 469 } // namespace compiler |
456 } // namespace internal | 470 } // namespace internal |
457 } // namespace v8 | 471 } // namespace v8 |
OLD | NEW |