| 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/code-factory.h" | 5 #include "src/code-factory.h" |
| 6 #include "src/code-stubs.h" | 6 #include "src/code-stubs.h" |
| 7 #include "src/compiler/common-operator.h" | 7 #include "src/compiler/common-operator.h" |
| 8 #include "src/compiler/js-generic-lowering.h" | 8 #include "src/compiler/js-generic-lowering.h" |
| 9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
| 10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 ReplaceWithRuntimeCall(node, Runtime::kNewRestParameter); | 386 ReplaceWithRuntimeCall(node, Runtime::kNewRestParameter); |
| 387 break; | 387 break; |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 | 390 |
| 391 | 391 |
| 392 void JSGenericLowering::LowerJSCreateArray(Node* node) { | 392 void JSGenericLowering::LowerJSCreateArray(Node* node) { |
| 393 CreateArrayParameters const& p = CreateArrayParametersOf(node->op()); | 393 CreateArrayParameters const& p = CreateArrayParametersOf(node->op()); |
| 394 int const arity = static_cast<int>(p.arity()); | 394 int const arity = static_cast<int>(p.arity()); |
| 395 Handle<AllocationSite> const site = p.site(); | 395 Handle<AllocationSite> const site = p.site(); |
| 396 | 396 Node* new_target = node->InputAt(1); |
| 397 // TODO(turbofan): We embed the AllocationSite from the Operator at this | 397 Node* type_info = site.is_null() ? jsgraph()->UndefinedConstant() |
| 398 // point, which we should not do once we want to both consume the feedback | 398 : jsgraph()->HeapConstant(site); |
| 399 // but at the same time shared the optimized code across native contexts, | 399 node->RemoveInput(1); |
| 400 // as the AllocationSite is associated with a single native context (it's | 400 node->InsertInput(zone(), 1 + arity, new_target); |
| 401 // stored in the type feedback vector after all). Once we go for cross | 401 node->InsertInput(zone(), 2 + arity, type_info); |
| 402 // context code generation, we should somehow find a way to get to the | 402 ReplaceWithRuntimeCall(node, Runtime::kNewArray, arity + 3); |
| 403 // allocation site for the actual native context at runtime. | |
| 404 if (!site.is_null()) { | |
| 405 // Reduce {node} to the appropriate ArrayConstructorStub backend. | |
| 406 // Note that these stubs "behave" like JSFunctions, which means they | |
| 407 // expect a receiver on the stack, which they remove. We just push | |
| 408 // undefined for the receiver. | |
| 409 ElementsKind elements_kind = site->GetElementsKind(); | |
| 410 AllocationSiteOverrideMode override_mode = | |
| 411 (AllocationSite::GetMode(elements_kind) == TRACK_ALLOCATION_SITE) | |
| 412 ? DISABLE_ALLOCATION_SITES | |
| 413 : DONT_OVERRIDE; | |
| 414 if (arity == 0) { | |
| 415 ArrayNoArgumentConstructorStub stub(isolate(), elements_kind, | |
| 416 override_mode); | |
| 417 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | |
| 418 isolate(), graph()->zone(), stub.GetCallInterfaceDescriptor(), 1, | |
| 419 CallDescriptor::kNeedsFrameState); | |
| 420 node->ReplaceInput(0, jsgraph()->HeapConstant(stub.GetCode())); | |
| 421 node->InsertInput(graph()->zone(), 2, jsgraph()->HeapConstant(site)); | |
| 422 node->InsertInput(graph()->zone(), 3, jsgraph()->Int32Constant(0)); | |
| 423 node->InsertInput(graph()->zone(), 4, jsgraph()->UndefinedConstant()); | |
| 424 NodeProperties::ChangeOp(node, common()->Call(desc)); | |
| 425 } else if (arity == 1) { | |
| 426 // TODO(bmeurer): Optimize for the 0 length non-holey case? | |
| 427 ArraySingleArgumentConstructorStub stub( | |
| 428 isolate(), GetHoleyElementsKind(elements_kind), override_mode); | |
| 429 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | |
| 430 isolate(), graph()->zone(), stub.GetCallInterfaceDescriptor(), 2, | |
| 431 CallDescriptor::kNeedsFrameState); | |
| 432 node->ReplaceInput(0, jsgraph()->HeapConstant(stub.GetCode())); | |
| 433 node->InsertInput(graph()->zone(), 2, jsgraph()->HeapConstant(site)); | |
| 434 node->InsertInput(graph()->zone(), 3, jsgraph()->Int32Constant(1)); | |
| 435 node->InsertInput(graph()->zone(), 4, jsgraph()->UndefinedConstant()); | |
| 436 NodeProperties::ChangeOp(node, common()->Call(desc)); | |
| 437 } else { | |
| 438 ArrayNArgumentsConstructorStub stub(isolate()); | |
| 439 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | |
| 440 isolate(), graph()->zone(), stub.GetCallInterfaceDescriptor(), | |
| 441 arity + 1, CallDescriptor::kNeedsFrameState); | |
| 442 node->ReplaceInput(0, jsgraph()->HeapConstant(stub.GetCode())); | |
| 443 node->InsertInput(graph()->zone(), 2, jsgraph()->HeapConstant(site)); | |
| 444 node->InsertInput(graph()->zone(), 3, jsgraph()->Int32Constant(arity)); | |
| 445 node->InsertInput(graph()->zone(), 4, jsgraph()->UndefinedConstant()); | |
| 446 NodeProperties::ChangeOp(node, common()->Call(desc)); | |
| 447 } | |
| 448 } else { | |
| 449 Node* new_target = node->InputAt(1); | |
| 450 Node* type_info = site.is_null() ? jsgraph()->UndefinedConstant() | |
| 451 : jsgraph()->HeapConstant(site); | |
| 452 node->RemoveInput(1); | |
| 453 node->InsertInput(zone(), 1 + arity, new_target); | |
| 454 node->InsertInput(zone(), 2 + arity, type_info); | |
| 455 ReplaceWithRuntimeCall(node, Runtime::kNewArray, arity + 3); | |
| 456 } | |
| 457 } | 403 } |
| 458 | 404 |
| 459 | 405 |
| 460 void JSGenericLowering::LowerJSCreateClosure(Node* node) { | 406 void JSGenericLowering::LowerJSCreateClosure(Node* node) { |
| 461 CreateClosureParameters const& p = CreateClosureParametersOf(node->op()); | 407 CreateClosureParameters const& p = CreateClosureParametersOf(node->op()); |
| 462 CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); | 408 CallDescriptor::Flags flags = AdjustFrameStatesForCall(node); |
| 463 Handle<SharedFunctionInfo> const shared_info = p.shared_info(); | 409 Handle<SharedFunctionInfo> const shared_info = p.shared_info(); |
| 464 node->InsertInput(zone(), 0, jsgraph()->HeapConstant(shared_info)); | 410 node->InsertInput(zone(), 0, jsgraph()->HeapConstant(shared_info)); |
| 465 | 411 |
| 466 // Use the FastNewClosureStub only for functions allocated in new space. | 412 // Use the FastNewClosureStub only for functions allocated in new space. |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 } | 670 } |
| 725 | 671 |
| 726 | 672 |
| 727 MachineOperatorBuilder* JSGenericLowering::machine() const { | 673 MachineOperatorBuilder* JSGenericLowering::machine() const { |
| 728 return jsgraph()->machine(); | 674 return jsgraph()->machine(); |
| 729 } | 675 } |
| 730 | 676 |
| 731 } // namespace compiler | 677 } // namespace compiler |
| 732 } // namespace internal | 678 } // namespace internal |
| 733 } // namespace v8 | 679 } // namespace v8 |
| OLD | NEW |