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/ast.h" | 7 #include "src/ast/ast.h" |
8 #include "src/ast/ast-numbering.h" | 8 #include "src/ast/ast-numbering.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 } | 256 } |
257 const Operator* op_param = | 257 const Operator* op_param = |
258 jsgraph_->common()->StateValues(static_cast<int>(params.size())); | 258 jsgraph_->common()->StateValues(static_cast<int>(params.size())); |
259 Node* params_node = jsgraph_->graph()->NewNode( | 259 Node* params_node = jsgraph_->graph()->NewNode( |
260 op_param, static_cast<int>(params.size()), ¶ms.front()); | 260 op_param, static_cast<int>(params.size()), ¶ms.front()); |
261 return jsgraph_->graph()->NewNode(op, params_node, node0, node0, | 261 return jsgraph_->graph()->NewNode(op, params_node, node0, node0, |
262 jsgraph_->UndefinedConstant(), | 262 jsgraph_->UndefinedConstant(), |
263 node->InputAt(0), outer_frame_state); | 263 node->InputAt(0), outer_frame_state); |
264 } | 264 } |
265 | 265 |
266 Node* JSInliner::CreateTailCallerFrameState(Node* node, Node* frame_state) { | |
267 FrameStateInfo const& frame_info = OpParameter<FrameStateInfo>(frame_state); | |
268 Handle<SharedFunctionInfo> shared = | |
269 frame_info.shared_info().ToHandleChecked(); | |
270 | |
271 Node* function = frame_state->InputAt(kFrameStateFunctionInput); | |
272 | |
273 // If we are inlining a tail call drop caller's frame state and an | |
274 // arguments adaptor if it exists. | |
275 frame_state = NodeProperties::GetFrameStateInput(frame_state, 0); | |
276 if (frame_state->opcode() == IrOpcode::kFrameState) { | |
277 FrameStateInfo state_info = OpParameter<FrameStateInfo>(frame_state); | |
278 if (state_info.type() == FrameStateType::kArgumentsAdaptor) { | |
279 frame_state = NodeProperties::GetFrameStateInput(frame_state, 0); | |
280 } | |
281 } | |
282 | |
283 const FrameStateFunctionInfo* state_info = | |
284 jsgraph_->common()->CreateFrameStateFunctionInfo( | |
285 FrameStateType::kTailCallerFunction, 0, 0, shared); | |
286 | |
287 const Operator* op = jsgraph_->common()->FrameState( | |
288 BailoutId(-1), OutputFrameStateCombine::Ignore(), state_info); | |
289 const Operator* op0 = jsgraph_->common()->StateValues(0); | |
290 Node* node0 = jsgraph_->graph()->NewNode(op0); | |
291 return jsgraph_->graph()->NewNode(op, node0, node0, node0, | |
292 jsgraph_->UndefinedConstant(), function, | |
293 frame_state); | |
294 } | |
266 | 295 |
267 namespace { | 296 namespace { |
268 | 297 |
269 // TODO(mstarzinger,verwaest): Move this predicate onto SharedFunctionInfo? | 298 // TODO(mstarzinger,verwaest): Move this predicate onto SharedFunctionInfo? |
270 bool NeedsImplicitReceiver(Handle<SharedFunctionInfo> shared_info) { | 299 bool NeedsImplicitReceiver(Handle<SharedFunctionInfo> shared_info) { |
271 DisallowHeapAllocation no_gc; | 300 DisallowHeapAllocation no_gc; |
272 Isolate* const isolate = shared_info->GetIsolate(); | 301 Isolate* const isolate = shared_info->GetIsolate(); |
273 Code* const construct_stub = shared_info->construct_stub(); | 302 Code* const construct_stub = shared_info->construct_stub(); |
274 return construct_stub != *isolate->builtins()->JSBuiltinsConstructStub(); | 303 return construct_stub != *isolate->builtins()->JSBuiltinsConstructStub(); |
275 } | 304 } |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 node, frame_state, call.formal_arguments(), | 513 node, frame_state, call.formal_arguments(), |
485 FrameStateType::kConstructStub, info.shared_info()); | 514 FrameStateType::kConstructStub, info.shared_info()); |
486 } | 515 } |
487 | 516 |
488 // The inlinee specializes to the context from the JSFunction object. | 517 // The inlinee specializes to the context from the JSFunction object. |
489 // TODO(turbofan): We might want to load the context from the JSFunction at | 518 // TODO(turbofan): We might want to load the context from the JSFunction at |
490 // runtime in case we only know the SharedFunctionInfo once we have dynamic | 519 // runtime in case we only know the SharedFunctionInfo once we have dynamic |
491 // type feedback in the compiler. | 520 // type feedback in the compiler. |
492 Node* context = jsgraph_->Constant(handle(function->context())); | 521 Node* context = jsgraph_->Constant(handle(function->context())); |
493 | 522 |
523 if (node->opcode() == IrOpcode::kJSCallFunction) { | |
Michael Starzinger
2016/03/08 16:25:08
This definitely needs a comment explaining the rea
Igor Sheludko
2016/03/08 18:03:40
Done. Please review the comment.
| |
524 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); | |
525 if (p.tail_call_mode() == TailCallMode::kAllow) { | |
526 frame_state = CreateTailCallerFrameState(node, frame_state); | |
527 } | |
528 } | |
529 | |
494 // Insert a JSConvertReceiver node for sloppy callees. Note that the context | 530 // Insert a JSConvertReceiver node for sloppy callees. Note that the context |
495 // passed into this node has to be the callees context (loaded above). Note | 531 // passed into this node has to be the callees context (loaded above). Note |
496 // that the frame state passed to the JSConvertReceiver must be the frame | 532 // that the frame state passed to the JSConvertReceiver must be the frame |
497 // state _before_ the call; it is not necessary to fiddle with the receiver | 533 // state _before_ the call; it is not necessary to fiddle with the receiver |
498 // in that frame state tho, as the conversion of the receiver can be repeated | 534 // in that frame state tho, as the conversion of the receiver can be repeated |
499 // any number of times, it's not observable. | 535 // any number of times, it's not observable. |
500 if (node->opcode() == IrOpcode::kJSCallFunction && | 536 if (node->opcode() == IrOpcode::kJSCallFunction && |
501 is_sloppy(info.language_mode()) && !shared_info->native()) { | 537 is_sloppy(info.language_mode()) && !shared_info->native()) { |
502 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); | 538 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); |
503 Node* effect = NodeProperties::GetEffectInput(node); | 539 Node* effect = NodeProperties::GetEffectInput(node); |
(...skipping 14 matching lines...) Expand all Loading... | |
518 node, frame_state, call.formal_arguments(), | 554 node, frame_state, call.formal_arguments(), |
519 FrameStateType::kArgumentsAdaptor, shared_info); | 555 FrameStateType::kArgumentsAdaptor, shared_info); |
520 } | 556 } |
521 | 557 |
522 return InlineCall(node, new_target, context, frame_state, start, end); | 558 return InlineCall(node, new_target, context, frame_state, start, end); |
523 } | 559 } |
524 | 560 |
525 } // namespace compiler | 561 } // namespace compiler |
526 } // namespace internal | 562 } // namespace internal |
527 } // namespace v8 | 563 } // namespace v8 |
OLD | NEW |