| 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/diamond.h" | |
| 6 #include "src/compiler/js-builtin-reducer.h" | 5 #include "src/compiler/js-builtin-reducer.h" |
| 7 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/node-matchers.h" | 7 #include "src/compiler/node-matchers.h" |
| 9 #include "src/compiler/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
| 10 #include "src/compiler/simplified-operator.h" | 9 #include "src/compiler/simplified-operator.h" |
| 11 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
| 12 #include "src/types.h" | 11 #include "src/types.h" |
| 13 | 12 |
| 14 namespace v8 { | 13 namespace v8 { |
| 15 namespace internal { | 14 namespace internal { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 83 |
| 85 private: | 84 private: |
| 86 Node* node_; | 85 Node* node_; |
| 87 }; | 86 }; |
| 88 | 87 |
| 89 | 88 |
| 90 JSBuiltinReducer::JSBuiltinReducer(Editor* editor, JSGraph* jsgraph) | 89 JSBuiltinReducer::JSBuiltinReducer(Editor* editor, JSGraph* jsgraph) |
| 91 : AdvancedReducer(editor), jsgraph_(jsgraph) {} | 90 : AdvancedReducer(editor), jsgraph_(jsgraph) {} |
| 92 | 91 |
| 93 | 92 |
| 94 // ES6 section 19.2.3.3 Function.prototype.call (thisArg, ...args) | |
| 95 Reduction JSBuiltinReducer::ReduceFunctionCall(Node* node) { | |
| 96 DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode()); | |
| 97 CallFunctionParameters const& p = CallFunctionParametersOf(node->op()); | |
| 98 Handle<JSFunction> apply = Handle<JSFunction>::cast( | |
| 99 HeapObjectMatcher(NodeProperties::GetValueInput(node, 0)).Value()); | |
| 100 // Change context of {node} to the Function.prototype.call context, | |
| 101 // to ensure any exception is thrown in the correct context. | |
| 102 NodeProperties::ReplaceContextInput( | |
| 103 node, jsgraph()->HeapConstant(handle(apply->context(), isolate()))); | |
| 104 // Remove the target from {node} and use the receiver as target instead, and | |
| 105 // the thisArg becomes the new target. If thisArg was not provided, insert | |
| 106 // undefined instead. | |
| 107 size_t arity = p.arity(); | |
| 108 DCHECK_LE(2u, arity); | |
| 109 ConvertReceiverMode convert_mode; | |
| 110 if (arity == 2) { | |
| 111 // The thisArg was not provided, use undefined as receiver. | |
| 112 convert_mode = ConvertReceiverMode::kNullOrUndefined; | |
| 113 node->ReplaceInput(0, node->InputAt(1)); | |
| 114 node->ReplaceInput(1, jsgraph()->UndefinedConstant()); | |
| 115 } else { | |
| 116 // Just remove the target, which is the first value input. | |
| 117 convert_mode = ConvertReceiverMode::kAny; | |
| 118 node->RemoveInput(0); | |
| 119 --arity; | |
| 120 } | |
| 121 // TODO(turbofan): Migrate the call count to the new operator? | |
| 122 NodeProperties::ChangeOp(node, javascript()->CallFunction( | |
| 123 arity, p.language_mode(), VectorSlotPair(), | |
| 124 convert_mode, p.tail_call_mode())); | |
| 125 return Changed(node); | |
| 126 } | |
| 127 | |
| 128 | |
| 129 // ECMA-262, section 15.8.2.11. | 93 // ECMA-262, section 15.8.2.11. |
| 130 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { | 94 Reduction JSBuiltinReducer::ReduceMathMax(Node* node) { |
| 131 JSCallReduction r(node); | 95 JSCallReduction r(node); |
| 132 if (r.InputsMatchZero()) { | 96 if (r.InputsMatchZero()) { |
| 133 // Math.max() -> -Infinity | 97 // Math.max() -> -Infinity |
| 134 return Replace(jsgraph()->Constant(-V8_INFINITY)); | 98 return Replace(jsgraph()->Constant(-V8_INFINITY)); |
| 135 } | 99 } |
| 136 if (r.InputsMatchOne(Type::Number())) { | 100 if (r.InputsMatchOne(Type::Number())) { |
| 137 // Math.max(a:number) -> a | 101 // Math.max(a:number) -> a |
| 138 return Replace(r.left()); | 102 return Replace(r.left()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 142 } |
| 179 | 143 |
| 180 | 144 |
| 181 Reduction JSBuiltinReducer::Reduce(Node* node) { | 145 Reduction JSBuiltinReducer::Reduce(Node* node) { |
| 182 Reduction reduction = NoChange(); | 146 Reduction reduction = NoChange(); |
| 183 JSCallReduction r(node); | 147 JSCallReduction r(node); |
| 184 | 148 |
| 185 // Dispatch according to the BuiltinFunctionId if present. | 149 // Dispatch according to the BuiltinFunctionId if present. |
| 186 if (!r.HasBuiltinFunctionId()) return NoChange(); | 150 if (!r.HasBuiltinFunctionId()) return NoChange(); |
| 187 switch (r.GetBuiltinFunctionId()) { | 151 switch (r.GetBuiltinFunctionId()) { |
| 188 case kFunctionCall: | |
| 189 return ReduceFunctionCall(node); | |
| 190 case kMathMax: | 152 case kMathMax: |
| 191 reduction = ReduceMathMax(node); | 153 reduction = ReduceMathMax(node); |
| 192 break; | 154 break; |
| 193 case kMathImul: | 155 case kMathImul: |
| 194 reduction = ReduceMathImul(node); | 156 reduction = ReduceMathImul(node); |
| 195 break; | 157 break; |
| 196 case kMathFround: | 158 case kMathFround: |
| 197 reduction = ReduceMathFround(node); | 159 reduction = ReduceMathFround(node); |
| 198 break; | 160 break; |
| 199 default: | 161 default: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 221 | 183 |
| 222 MachineOperatorBuilder* JSBuiltinReducer::machine() const { | 184 MachineOperatorBuilder* JSBuiltinReducer::machine() const { |
| 223 return jsgraph()->machine(); | 185 return jsgraph()->machine(); |
| 224 } | 186 } |
| 225 | 187 |
| 226 | 188 |
| 227 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { | 189 SimplifiedOperatorBuilder* JSBuiltinReducer::simplified() const { |
| 228 return jsgraph()->simplified(); | 190 return jsgraph()->simplified(); |
| 229 } | 191 } |
| 230 | 192 |
| 231 | |
| 232 JSOperatorBuilder* JSBuiltinReducer::javascript() const { | |
| 233 return jsgraph()->javascript(); | |
| 234 } | |
| 235 | |
| 236 } // namespace compiler | 193 } // namespace compiler |
| 237 } // namespace internal | 194 } // namespace internal |
| 238 } // namespace v8 | 195 } // namespace v8 |
| OLD | NEW |