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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 | 537 |
538 // Raise a TypeError if the {target} is a "classConstructor". | 538 // Raise a TypeError if the {target} is a "classConstructor". |
539 if (IsClassConstructor(shared->kind())) { | 539 if (IsClassConstructor(shared->kind())) { |
540 NodeProperties::ReplaceValueInputs(node, target); | 540 NodeProperties::ReplaceValueInputs(node, target); |
541 NodeProperties::ChangeOp( | 541 NodeProperties::ChangeOp( |
542 node, javascript()->CallRuntime( | 542 node, javascript()->CallRuntime( |
543 Runtime::kThrowConstructorNonCallableError, 1)); | 543 Runtime::kThrowConstructorNonCallableError, 1)); |
544 return Changed(node); | 544 return Changed(node); |
545 } | 545 } |
546 | 546 |
547 // For CSA/C++ builtin {target}s, we can ensure that the number | |
548 // of parameters we pass to the {target} matches exactly the | |
549 // number of formal parameters expected by the builtin, and thus | |
550 // avoid creating an ArgumentsAdaptorFrame. This is safe because | |
551 // all CSA/C++ builtins that care about variable arguments are | |
552 // declared with the kDontAdaptArgumentsSentinel marker. | |
553 int builtin_index = shared->code()->builtin_index(); | |
554 if (builtin_index != -1 && shared->native() && !shared->IsInterpreted()) { | |
555 // Check if we have an arguments mismatch for {target}. | |
556 int arity = static_cast<int>(p.arity() - 2); | |
557 int num_parameters = shared->internal_formal_parameter_count(); | |
558 if (num_parameters != arity && | |
559 num_parameters != SharedFunctionInfo::kDontAdaptArgumentsSentinel) { | |
560 // Fill up missing parameters with undefined. | |
561 while (arity < num_parameters) { | |
562 node->InsertInput(graph()->zone(), arity + 2, | |
563 jsgraph()->UndefinedConstant()); | |
564 arity++; | |
565 } | |
566 // Remove additional parameters. | |
567 while (arity > num_parameters) { | |
568 node->RemoveInput(arity + 1); | |
569 arity--; | |
570 } | |
571 NodeProperties::ChangeOp( | |
572 node, javascript()->Call(arity + 2, p.frequency(), p.feedback(), | |
573 p.convert_mode(), p.tail_call_mode())); | |
574 // Try to further reduce the JSCall {node}. | |
575 Reduction const reduction = ReduceJSCall(node); | |
576 return reduction.Changed() ? reduction : Changed(node); | |
577 } | |
578 } | |
579 | |
580 // Don't inline cross native context. | 547 // Don't inline cross native context. |
581 if (function->native_context() != *native_context()) return NoChange(); | 548 if (function->native_context() != *native_context()) return NoChange(); |
582 | 549 |
583 // Check for known builtin functions. | 550 // Check for known builtin functions. |
584 switch (builtin_index) { | 551 switch (shared->code()->builtin_index()) { |
585 case Builtins::kBooleanConstructor: | 552 case Builtins::kBooleanConstructor: |
586 return ReduceBooleanConstructor(node); | 553 return ReduceBooleanConstructor(node); |
587 case Builtins::kFunctionPrototypeApply: | 554 case Builtins::kFunctionPrototypeApply: |
588 return ReduceFunctionPrototypeApply(node); | 555 return ReduceFunctionPrototypeApply(node); |
589 case Builtins::kFunctionPrototypeCall: | 556 case Builtins::kFunctionPrototypeCall: |
590 return ReduceFunctionPrototypeCall(node); | 557 return ReduceFunctionPrototypeCall(node); |
591 case Builtins::kFunctionPrototypeHasInstance: | 558 case Builtins::kFunctionPrototypeHasInstance: |
592 return ReduceFunctionPrototypeHasInstance(node); | 559 return ReduceFunctionPrototypeHasInstance(node); |
593 case Builtins::kNumberConstructor: | 560 case Builtins::kNumberConstructor: |
594 return ReduceNumberConstructor(node); | 561 return ReduceNumberConstructor(node); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 return jsgraph()->javascript(); | 832 return jsgraph()->javascript(); |
866 } | 833 } |
867 | 834 |
868 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { | 835 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { |
869 return jsgraph()->simplified(); | 836 return jsgraph()->simplified(); |
870 } | 837 } |
871 | 838 |
872 } // namespace compiler | 839 } // namespace compiler |
873 } // namespace internal | 840 } // namespace internal |
874 } // namespace v8 | 841 } // namespace v8 |
OLD | NEW |