| 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/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
| 9 #include "src/compiler/simplified-operator.h" | 9 #include "src/compiler/simplified-operator.h" |
| 10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 --arity; | 182 --arity; |
| 183 } | 183 } |
| 184 NodeProperties::ChangeOp( | 184 NodeProperties::ChangeOp( |
| 185 node, javascript()->CallFunction(arity, p.frequency(), VectorSlotPair(), | 185 node, javascript()->CallFunction(arity, p.frequency(), VectorSlotPair(), |
| 186 convert_mode, p.tail_call_mode())); | 186 convert_mode, p.tail_call_mode())); |
| 187 // Try to further reduce the JSCallFunction {node}. | 187 // Try to further reduce the JSCallFunction {node}. |
| 188 Reduction const reduction = ReduceJSCallFunction(node); | 188 Reduction const reduction = ReduceJSCallFunction(node); |
| 189 return reduction.Changed() ? reduction : Changed(node); | 189 return reduction.Changed() ? reduction : Changed(node); |
| 190 } | 190 } |
| 191 | 191 |
| 192 // ES6 section 19.2.3.6 Function.prototype [ @@hasInstance ] (V) |
| 193 Reduction JSCallReducer::ReduceFunctionPrototypeHasInstance(Node* node) { |
| 194 DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode()); |
| 195 Node* receiver = NodeProperties::GetValueInput(node, 1); |
| 196 Node* object = (node->op()->ValueInputCount() >= 3) |
| 197 ? NodeProperties::GetValueInput(node, 2) |
| 198 : jsgraph()->UndefinedConstant(); |
| 199 Node* context = NodeProperties::GetContextInput(node); |
| 200 Node* frame_state = NodeProperties::GetFrameStateInput(node); |
| 201 Node* effect = NodeProperties::GetEffectInput(node); |
| 202 Node* control = NodeProperties::GetControlInput(node); |
| 203 |
| 204 // TODO(turbofan): If JSOrdinaryToInstance raises an exception, the |
| 205 // stack trace doesn't contain the @@hasInstance call; we have the |
| 206 // corresponding bug in the baseline case. Some massaging of the frame |
| 207 // state would be necessary here. |
| 208 |
| 209 // Morph this {node} into a JSOrdinaryHasInstance node. |
| 210 node->ReplaceInput(0, receiver); |
| 211 node->ReplaceInput(1, object); |
| 212 node->ReplaceInput(2, context); |
| 213 node->ReplaceInput(3, frame_state); |
| 214 node->ReplaceInput(4, effect); |
| 215 node->ReplaceInput(5, control); |
| 216 node->TrimInputCount(6); |
| 217 NodeProperties::ChangeOp(node, javascript()->OrdinaryHasInstance()); |
| 218 return Changed(node); |
| 219 } |
| 220 |
| 192 namespace { | 221 namespace { |
| 193 | 222 |
| 194 // TODO(turbofan): Shall we move this to the NodeProperties? Or some (untyped) | 223 // TODO(turbofan): Shall we move this to the NodeProperties? Or some (untyped) |
| 195 // alias analyzer? | 224 // alias analyzer? |
| 196 bool IsSame(Node* a, Node* b) { | 225 bool IsSame(Node* a, Node* b) { |
| 197 if (a == b) { | 226 if (a == b) { |
| 198 return true; | 227 return true; |
| 199 } else if (a->opcode() == IrOpcode::kCheckHeapObject) { | 228 } else if (a->opcode() == IrOpcode::kCheckHeapObject) { |
| 200 return IsSame(a->InputAt(0), b); | 229 return IsSame(a->InputAt(0), b); |
| 201 } else if (b->opcode() == IrOpcode::kCheckHeapObject) { | 230 } else if (b->opcode() == IrOpcode::kCheckHeapObject) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 Runtime::kThrowConstructorNonCallableError, 1)); | 302 Runtime::kThrowConstructorNonCallableError, 1)); |
| 274 return Changed(node); | 303 return Changed(node); |
| 275 } | 304 } |
| 276 | 305 |
| 277 // Check for known builtin functions. | 306 // Check for known builtin functions. |
| 278 switch (shared->code()->builtin_index()) { | 307 switch (shared->code()->builtin_index()) { |
| 279 case Builtins::kFunctionPrototypeApply: | 308 case Builtins::kFunctionPrototypeApply: |
| 280 return ReduceFunctionPrototypeApply(node); | 309 return ReduceFunctionPrototypeApply(node); |
| 281 case Builtins::kFunctionPrototypeCall: | 310 case Builtins::kFunctionPrototypeCall: |
| 282 return ReduceFunctionPrototypeCall(node); | 311 return ReduceFunctionPrototypeCall(node); |
| 312 case Builtins::kFunctionPrototypeHasInstance: |
| 313 return ReduceFunctionPrototypeHasInstance(node); |
| 283 case Builtins::kNumberConstructor: | 314 case Builtins::kNumberConstructor: |
| 284 return ReduceNumberConstructor(node); | 315 return ReduceNumberConstructor(node); |
| 285 case Builtins::kObjectPrototypeGetProto: | 316 case Builtins::kObjectPrototypeGetProto: |
| 286 return ReduceObjectPrototypeGetProto(node); | 317 return ReduceObjectPrototypeGetProto(node); |
| 287 default: | 318 default: |
| 288 break; | 319 break; |
| 289 } | 320 } |
| 290 | 321 |
| 291 // Check for the Array constructor. | 322 // Check for the Array constructor. |
| 292 if (*function == function->native_context()->array_function()) { | 323 if (*function == function->native_context()->array_function()) { |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 return jsgraph()->javascript(); | 547 return jsgraph()->javascript(); |
| 517 } | 548 } |
| 518 | 549 |
| 519 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { | 550 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { |
| 520 return jsgraph()->simplified(); | 551 return jsgraph()->simplified(); |
| 521 } | 552 } |
| 522 | 553 |
| 523 } // namespace compiler | 554 } // namespace compiler |
| 524 } // namespace internal | 555 } // namespace internal |
| 525 } // namespace v8 | 556 } // namespace v8 |
| OLD | NEW |