| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 size_t const arity = p.arity() - 2; | 56 size_t const arity = p.arity() - 2; |
| 57 NodeProperties::ReplaceValueInput(node, target, 0); | 57 NodeProperties::ReplaceValueInput(node, target, 0); |
| 58 NodeProperties::ReplaceValueInput(node, target, 1); | 58 NodeProperties::ReplaceValueInput(node, target, 1); |
| 59 // TODO(bmeurer): We might need to propagate the tail call mode to | 59 // TODO(bmeurer): We might need to propagate the tail call mode to |
| 60 // the JSCreateArray operator, because an Array call in tail call | 60 // the JSCreateArray operator, because an Array call in tail call |
| 61 // position must always properly consume the parent stack frame. | 61 // position must always properly consume the parent stack frame. |
| 62 NodeProperties::ChangeOp(node, javascript()->CreateArray(arity, site)); | 62 NodeProperties::ChangeOp(node, javascript()->CreateArray(arity, site)); |
| 63 return Changed(node); | 63 return Changed(node); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // ES6 section 19.3.1.1 Boolean ( value ) |
| 67 Reduction JSCallReducer::ReduceBooleanConstructor(Node* node) { |
| 68 DCHECK_EQ(IrOpcode::kJSCall, node->opcode()); |
| 69 CallParameters const& p = CallParametersOf(node->op()); |
| 70 |
| 71 // Replace the {node} with a proper {JSToBoolean} operator. |
| 72 DCHECK_LE(2u, p.arity()); |
| 73 Node* value = (p.arity() == 2) ? jsgraph()->UndefinedConstant() |
| 74 : NodeProperties::GetValueInput(node, 2); |
| 75 Node* context = NodeProperties::GetContextInput(node); |
| 76 value = graph()->NewNode(javascript()->ToBoolean(ToBooleanHint::kAny), value, |
| 77 context); |
| 78 ReplaceWithValue(node, value); |
| 79 return Replace(value); |
| 80 } |
| 66 | 81 |
| 67 // ES6 section 20.1.1 The Number Constructor | 82 // ES6 section 20.1.1 The Number Constructor |
| 68 Reduction JSCallReducer::ReduceNumberConstructor(Node* node) { | 83 Reduction JSCallReducer::ReduceNumberConstructor(Node* node) { |
| 69 DCHECK_EQ(IrOpcode::kJSCall, node->opcode()); | 84 DCHECK_EQ(IrOpcode::kJSCall, node->opcode()); |
| 70 CallParameters const& p = CallParametersOf(node->op()); | 85 CallParameters const& p = CallParametersOf(node->op()); |
| 71 | 86 |
| 72 // Turn the {node} into a {JSToNumber} call. | 87 // Turn the {node} into a {JSToNumber} call. |
| 73 DCHECK_LE(2u, p.arity()); | 88 DCHECK_LE(2u, p.arity()); |
| 74 Node* value = (p.arity() == 2) ? jsgraph()->ZeroConstant() | 89 Node* value = (p.arity() == 2) ? jsgraph()->ZeroConstant() |
| 75 : NodeProperties::GetValueInput(node, 2); | 90 : NodeProperties::GetValueInput(node, 2); |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 Reduction const reduction = ReduceJSCall(node); | 566 Reduction const reduction = ReduceJSCall(node); |
| 552 return reduction.Changed() ? reduction : Changed(node); | 567 return reduction.Changed() ? reduction : Changed(node); |
| 553 } | 568 } |
| 554 } | 569 } |
| 555 | 570 |
| 556 // Don't inline cross native context. | 571 // Don't inline cross native context. |
| 557 if (function->native_context() != *native_context()) return NoChange(); | 572 if (function->native_context() != *native_context()) return NoChange(); |
| 558 | 573 |
| 559 // Check for known builtin functions. | 574 // Check for known builtin functions. |
| 560 switch (builtin_index) { | 575 switch (builtin_index) { |
| 576 case Builtins::kBooleanConstructor: |
| 577 return ReduceBooleanConstructor(node); |
| 561 case Builtins::kFunctionPrototypeApply: | 578 case Builtins::kFunctionPrototypeApply: |
| 562 return ReduceFunctionPrototypeApply(node); | 579 return ReduceFunctionPrototypeApply(node); |
| 563 case Builtins::kFunctionPrototypeCall: | 580 case Builtins::kFunctionPrototypeCall: |
| 564 return ReduceFunctionPrototypeCall(node); | 581 return ReduceFunctionPrototypeCall(node); |
| 565 case Builtins::kFunctionPrototypeHasInstance: | 582 case Builtins::kFunctionPrototypeHasInstance: |
| 566 return ReduceFunctionPrototypeHasInstance(node); | 583 return ReduceFunctionPrototypeHasInstance(node); |
| 567 case Builtins::kNumberConstructor: | 584 case Builtins::kNumberConstructor: |
| 568 return ReduceNumberConstructor(node); | 585 return ReduceNumberConstructor(node); |
| 569 case Builtins::kObjectPrototypeGetProto: | 586 case Builtins::kObjectPrototypeGetProto: |
| 570 return ReduceObjectPrototypeGetProto(node); | 587 return ReduceObjectPrototypeGetProto(node); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 return jsgraph()->javascript(); | 856 return jsgraph()->javascript(); |
| 840 } | 857 } |
| 841 | 858 |
| 842 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { | 859 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { |
| 843 return jsgraph()->simplified(); | 860 return jsgraph()->simplified(); |
| 844 } | 861 } |
| 845 | 862 |
| 846 } // namespace compiler | 863 } // namespace compiler |
| 847 } // namespace internal | 864 } // namespace internal |
| 848 } // namespace v8 | 865 } // namespace v8 |
| OLD | NEW |