Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 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-call-reducer.h" | 5 #include "src/compiler/js-call-reducer.h" |
| 6 | 6 |
| 7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
| 8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
| 9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
| 10 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 | 575 |
| 576 // Raise a TypeError if the {target} is a "classConstructor". | 576 // Raise a TypeError if the {target} is a "classConstructor". |
| 577 if (IsClassConstructor(shared->kind())) { | 577 if (IsClassConstructor(shared->kind())) { |
| 578 NodeProperties::ReplaceValueInputs(node, target); | 578 NodeProperties::ReplaceValueInputs(node, target); |
| 579 NodeProperties::ChangeOp( | 579 NodeProperties::ChangeOp( |
| 580 node, javascript()->CallRuntime( | 580 node, javascript()->CallRuntime( |
| 581 Runtime::kThrowConstructorNonCallableError, 1)); | 581 Runtime::kThrowConstructorNonCallableError, 1)); |
| 582 return Changed(node); | 582 return Changed(node); |
| 583 } | 583 } |
| 584 | 584 |
| 585 // For CSA/C++ builtin {target}s, we can ensure that the number | |
|
Benedikt Meurer
2017/04/26 16:17:57
As discussed a few weeks ago, I don't think we sho
danno
2017/04/28 06:58:10
Done.
| |
| 586 // of parameters we pass to the {target} matches exactly the | |
| 587 // number of formal parameters expected by the builtin, and thus | |
| 588 // avoid creating an ArgumentsAdaptorFrame. This is safe because | |
| 589 // all CSA/C++ builtins that care about variable arguments are | |
| 590 // declared with the kDontAdaptArgumentsSentinel marker. | |
| 591 int builtin_index = shared->code()->builtin_index(); | |
| 592 if (builtin_index != -1 && shared->native() && !shared->IsInterpreted()) { | |
| 593 // Check if we have an arguments mismatch for {target}. | |
| 594 int arity = static_cast<int>(p.arity() - 2); | |
| 595 int num_parameters = shared->internal_formal_parameter_count(); | |
| 596 if (num_parameters != arity && | |
| 597 num_parameters != SharedFunctionInfo::kDontAdaptArgumentsSentinel) { | |
| 598 // Fill up missing parameters with undefined. | |
| 599 while (arity < num_parameters) { | |
| 600 node->InsertInput(graph()->zone(), arity + 2, | |
| 601 jsgraph()->UndefinedConstant()); | |
| 602 arity++; | |
| 603 } | |
| 604 // Remove additional parameters. | |
| 605 while (arity > num_parameters) { | |
| 606 node->RemoveInput(arity + 1); | |
| 607 arity--; | |
| 608 } | |
| 609 NodeProperties::ChangeOp( | |
| 610 node, javascript()->Call(arity + 2, p.frequency(), p.feedback(), | |
| 611 p.convert_mode(), p.tail_call_mode())); | |
| 612 // Try to further reduce the JSCall {node}. | |
| 613 Reduction const reduction = ReduceJSCall(node); | |
| 614 return reduction.Changed() ? reduction : Changed(node); | |
| 615 } | |
| 616 } | |
| 617 | |
| 585 // Don't inline cross native context. | 618 // Don't inline cross native context. |
| 586 if (function->native_context() != *native_context()) return NoChange(); | 619 if (function->native_context() != *native_context()) return NoChange(); |
| 587 | 620 |
| 588 // Check for known builtin functions. | 621 // Check for known builtin functions. |
| 589 switch (shared->code()->builtin_index()) { | 622 switch (builtin_index) { |
| 590 case Builtins::kBooleanConstructor: | 623 case Builtins::kBooleanConstructor: |
| 591 return ReduceBooleanConstructor(node); | 624 return ReduceBooleanConstructor(node); |
| 592 case Builtins::kFunctionPrototypeApply: | 625 case Builtins::kFunctionPrototypeApply: |
| 593 return ReduceFunctionPrototypeApply(node); | 626 return ReduceFunctionPrototypeApply(node); |
| 594 case Builtins::kFunctionPrototypeCall: | 627 case Builtins::kFunctionPrototypeCall: |
| 595 return ReduceFunctionPrototypeCall(node); | 628 return ReduceFunctionPrototypeCall(node); |
| 596 case Builtins::kFunctionPrototypeHasInstance: | 629 case Builtins::kFunctionPrototypeHasInstance: |
| 597 return ReduceFunctionPrototypeHasInstance(node); | 630 return ReduceFunctionPrototypeHasInstance(node); |
| 598 case Builtins::kNumberConstructor: | 631 case Builtins::kNumberConstructor: |
| 599 return ReduceNumberConstructor(node); | 632 return ReduceNumberConstructor(node); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 return jsgraph()->javascript(); | 907 return jsgraph()->javascript(); |
| 875 } | 908 } |
| 876 | 909 |
| 877 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { | 910 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { |
| 878 return jsgraph()->simplified(); | 911 return jsgraph()->simplified(); |
| 879 } | 912 } |
| 880 | 913 |
| 881 } // namespace compiler | 914 } // namespace compiler |
| 882 } // namespace internal | 915 } // namespace internal |
| 883 } // namespace v8 | 916 } // namespace v8 |
| OLD | NEW |