| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 46   Node* target() { | 46   Node* target() { | 
| 47     // Both, {JSCallFunction} and {JSCallConstruct}, have same layout here. | 47     // Both, {JSCallFunction} and {JSCallConstruct}, have same layout here. | 
| 48     return call_->InputAt(0); | 48     return call_->InputAt(0); | 
| 49   } | 49   } | 
| 50 | 50 | 
| 51   Node* receiver() { | 51   Node* receiver() { | 
| 52     DCHECK_EQ(IrOpcode::kJSCallFunction, call_->opcode()); | 52     DCHECK_EQ(IrOpcode::kJSCallFunction, call_->opcode()); | 
| 53     return call_->InputAt(1); | 53     return call_->InputAt(1); | 
| 54   } | 54   } | 
| 55 | 55 | 
| 56   Node* original_constructor() { | 56   Node* new_target() { | 
| 57     DCHECK_EQ(IrOpcode::kJSCallConstruct, call_->opcode()); | 57     DCHECK_EQ(IrOpcode::kJSCallConstruct, call_->opcode()); | 
| 58     return call_->InputAt(formal_arguments() + 1); | 58     return call_->InputAt(formal_arguments() + 1); | 
| 59   } | 59   } | 
| 60 | 60 | 
| 61   Node* frame_state_before() { | 61   Node* frame_state_before() { | 
| 62     DCHECK_EQ(IrOpcode::kJSCallFunction, call_->opcode()); | 62     DCHECK_EQ(IrOpcode::kJSCallFunction, call_->opcode()); | 
| 63     return NodeProperties::GetFrameStateInput(call_, 1); | 63     return NodeProperties::GetFrameStateInput(call_, 1); | 
| 64   } | 64   } | 
| 65 | 65 | 
| 66   Node* frame_state_after() { | 66   Node* frame_state_after() { | 
| 67     // Both, {JSCallFunction} and {JSCallConstruct}, have frame state after. | 67     // Both, {JSCallFunction} and {JSCallConstruct}, have frame state after. | 
| 68     return NodeProperties::GetFrameStateInput(call_, 0); | 68     return NodeProperties::GetFrameStateInput(call_, 0); | 
| 69   } | 69   } | 
| 70 | 70 | 
| 71   int formal_arguments() { | 71   int formal_arguments() { | 
| 72     // Both, {JSCallFunction} and {JSCallConstruct}, have two extra inputs: | 72     // Both, {JSCallFunction} and {JSCallConstruct}, have two extra inputs: | 
| 73     //  - JSCallConstruct: Includes target function and original constructor. | 73     //  - JSCallConstruct: Includes target function and new target. | 
| 74     //  - JSCallFunction: Includes target function and receiver. | 74     //  - JSCallFunction: Includes target function and receiver. | 
| 75     return call_->op()->ValueInputCount() - 2; | 75     return call_->op()->ValueInputCount() - 2; | 
| 76   } | 76   } | 
| 77 | 77 | 
| 78  private: | 78  private: | 
| 79   Node* call_; | 79   Node* call_; | 
| 80 }; | 80 }; | 
| 81 | 81 | 
| 82 | 82 | 
| 83 class CopyVisitor { | 83 class CopyVisitor { | 
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 445   Node* end = visitor.GetCopy(graph.end()); | 445   Node* end = visitor.GetCopy(graph.end()); | 
| 446   Node* frame_state = call.frame_state_after(); | 446   Node* frame_state = call.frame_state_after(); | 
| 447 | 447 | 
| 448   // Insert nodes around the call that model the behavior required for a | 448   // Insert nodes around the call that model the behavior required for a | 
| 449   // constructor dispatch and turn the constructor call into a regular call. | 449   // constructor dispatch and turn the constructor call into a regular call. | 
| 450   // This models the behavior usually accomplished by our {JSConstructStub}. | 450   // This models the behavior usually accomplished by our {JSConstructStub}. | 
| 451   // Note that the context has to be the callers context (input to call node). | 451   // Note that the context has to be the callers context (input to call node). | 
| 452   if (node->opcode() == IrOpcode::kJSCallConstruct) { | 452   if (node->opcode() == IrOpcode::kJSCallConstruct) { | 
| 453     Node* effect = NodeProperties::GetEffectInput(node); | 453     Node* effect = NodeProperties::GetEffectInput(node); | 
| 454     Node* context = NodeProperties::GetContextInput(node); | 454     Node* context = NodeProperties::GetContextInput(node); | 
| 455     Node* create = jsgraph_->graph()->NewNode( | 455     Node* create = jsgraph_->graph()->NewNode(jsgraph_->javascript()->Create(), | 
| 456         jsgraph_->javascript()->Create(), call.target(), | 456                                               call.target(), call.new_target(), | 
| 457         call.original_constructor(), context, effect); | 457                                               context, effect); | 
| 458     NodeProperties::ReplaceEffectInput(node, create); | 458     NodeProperties::ReplaceEffectInput(node, create); | 
| 459     // TODO(4544): For now Runtime_GetOriginalConstructor depends on the actual | 459     // TODO(4544): For now Runtime_GetNewTarget depends on the actual target to | 
| 460     // constructor to coincide with the original constructor. Fix this! | 460     // coincide with the new target. Fix this! | 
| 461     CHECK_EQ(call.target(), call.original_constructor()); | 461     CHECK_EQ(call.target(), call.new_target()); | 
| 462     // TODO(4544): For derived constructors we should not allocate an implicit | 462     // TODO(4544): For derived constructors we should not allocate an implicit | 
| 463     // receiver and also the return value should not be checked afterwards. | 463     // receiver and also the return value should not be checked afterwards. | 
| 464     CHECK(!IsClassConstructor(function->shared()->kind())); | 464     CHECK(!IsClassConstructor(function->shared()->kind())); | 
| 465     // Swizzle the inputs of the {JSCallConstruct} node to look like inputs to | 465     // Swizzle the inputs of the {JSCallConstruct} node to look like inputs to | 
| 466     // any {JSCallFunction} node so that the rest of the inlining machinery | 466     // any {JSCallFunction} node so that the rest of the inlining machinery | 
| 467     // behaves as if we were dealing with a regular function invocation. | 467     // behaves as if we were dealing with a regular function invocation. | 
| 468     node->RemoveInput(call.formal_arguments() + 1);  // Drop new.target. | 468     node->RemoveInput(call.formal_arguments() + 1);  // Drop new.target. | 
| 469     node->InsertInput(jsgraph_->graph()->zone(), 1, create); | 469     node->InsertInput(jsgraph_->graph()->zone(), 1, create); | 
| 470     // Insert a check of the return value to determine whether the return value | 470     // Insert a check of the return value to determine whether the return value | 
| 471     // or the implicit receiver should be selected as a result of the call. | 471     // or the implicit receiver should be selected as a result of the call. | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 517         node, frame_state, call.formal_arguments(), | 517         node, frame_state, call.formal_arguments(), | 
| 518         FrameStateType::kArgumentsAdaptor, info.shared_info()); | 518         FrameStateType::kArgumentsAdaptor, info.shared_info()); | 
| 519   } | 519   } | 
| 520 | 520 | 
| 521   return InlineCall(node, context, frame_state, start, end); | 521   return InlineCall(node, context, frame_state, start, end); | 
| 522 } | 522 } | 
| 523 | 523 | 
| 524 }  // namespace compiler | 524 }  // namespace compiler | 
| 525 }  // namespace internal | 525 }  // namespace internal | 
| 526 }  // namespace v8 | 526 }  // namespace v8 | 
| OLD | NEW | 
|---|