Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/compiler/js-typed-lowering.cc

Issue 2259883002: [turbofan] Inline calls to CPP builtins (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@builtin-descriptors
Patch Set: Comments and API builtins Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/js-typed-lowering.h" 5 #include "src/compiler/js-typed-lowering.h"
6 6
7 #include "src/builtins/builtins-utils.h"
7 #include "src/code-factory.h" 8 #include "src/code-factory.h"
8 #include "src/compilation-dependencies.h" 9 #include "src/compilation-dependencies.h"
9 #include "src/compiler/access-builder.h" 10 #include "src/compiler/access-builder.h"
10 #include "src/compiler/js-graph.h" 11 #include "src/compiler/js-graph.h"
11 #include "src/compiler/linkage.h" 12 #include "src/compiler/linkage.h"
12 #include "src/compiler/node-matchers.h" 13 #include "src/compiler/node-matchers.h"
13 #include "src/compiler/node-properties.h" 14 #include "src/compiler/node-properties.h"
14 #include "src/compiler/operator-properties.h" 15 #include "src/compiler/operator-properties.h"
15 #include "src/type-cache.h" 16 #include "src/type-cache.h"
16 #include "src/types.h" 17 #include "src/types.h"
(...skipping 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 } else if (!receiver_type->Maybe(Type::NullOrUndefined())) { 1576 } else if (!receiver_type->Maybe(Type::NullOrUndefined())) {
1576 convert_mode = ConvertReceiverMode::kNotNullOrUndefined; 1577 convert_mode = ConvertReceiverMode::kNotNullOrUndefined;
1577 } 1578 }
1578 1579
1579 // Check if {target} is a known JSFunction. 1580 // Check if {target} is a known JSFunction.
1580 if (target_type->IsConstant() && 1581 if (target_type->IsConstant() &&
1581 target_type->AsConstant()->Value()->IsJSFunction()) { 1582 target_type->AsConstant()->Value()->IsJSFunction()) {
1582 Handle<JSFunction> function = 1583 Handle<JSFunction> function =
1583 Handle<JSFunction>::cast(target_type->AsConstant()->Value()); 1584 Handle<JSFunction>::cast(target_type->AsConstant()->Value());
1584 Handle<SharedFunctionInfo> shared(function->shared(), isolate()); 1585 Handle<SharedFunctionInfo> shared(function->shared(), isolate());
1586 Handle<Code> code(shared->code());
1587 auto builtin_name = static_cast<Builtins::Name>(code->builtin_index());
1585 1588
1586 // Class constructors are callable, but [[Call]] will raise an exception. 1589 // Class constructors are callable, but [[Call]] will raise an exception.
1587 // See ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList ). 1590 // See ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList ).
1588 if (IsClassConstructor(shared->kind())) return NoChange(); 1591 if (IsClassConstructor(shared->kind())) return NoChange();
1589 1592
1590 // Load the context from the {target}. 1593 // Load the context from the {target}.
1591 Node* context = effect = graph()->NewNode( 1594 Node* context = effect = graph()->NewNode(
1592 simplified()->LoadField(AccessBuilder::ForJSFunctionContext()), target, 1595 simplified()->LoadField(AccessBuilder::ForJSFunctionContext()), target,
1593 effect, control); 1596 effect, control);
1594 NodeProperties::ReplaceContextInput(node, context); 1597 NodeProperties::ReplaceContextInput(node, context);
(...skipping 11 matching lines...) Expand all
1606 NodeProperties::ReplaceEffectInput(node, effect); 1609 NodeProperties::ReplaceEffectInput(node, effect);
1607 1610
1608 // Compute flags for the call. 1611 // Compute flags for the call.
1609 CallDescriptor::Flags flags = CallDescriptor::kNeedsFrameState; 1612 CallDescriptor::Flags flags = CallDescriptor::kNeedsFrameState;
1610 if (p.tail_call_mode() == TailCallMode::kAllow) { 1613 if (p.tail_call_mode() == TailCallMode::kAllow) {
1611 flags |= CallDescriptor::kSupportsTailCalls; 1614 flags |= CallDescriptor::kSupportsTailCalls;
1612 } 1615 }
1613 1616
1614 Node* new_target = jsgraph()->UndefinedConstant(); 1617 Node* new_target = jsgraph()->UndefinedConstant();
1615 Node* argument_count = jsgraph()->Int32Constant(arity); 1618 Node* argument_count = jsgraph()->Int32Constant(arity);
1616 if (shared->internal_formal_parameter_count() == arity || 1619 if (code->kind() == Code::BUILTIN &&
1617 shared->internal_formal_parameter_count() == 1620 isolate()->builtins()->IsCppBuiltin(builtin_name)) {
1618 SharedFunctionInfo::kDontAdaptArgumentsSentinel) { 1621 // Patch {node} to a direct CEntryStub call.
1622 //
1623 // ----------- A r g u m e n t s -----------
1624 // -- 0: CEntryStub
1625 // --- Stack args ---
1626 // -- 1: receiver
1627 // -- [2, 2 + n[: the n actual arguments passed to the builtin
1628 // -- 2 + n: argc, including the receiver and implicit args (Smi)
1629 // -- 2 + n + 1: target
1630 // -- 2 + n + 2: new_target
1631 // --- Register args ---
1632 // -- 2 + n + 3: the C entry point
1633 // -- 2 + n + 4: argc (Int32)
1634 // -----------------------------------
1635
1636 // The logic contained here is mirrored in Builtins::Generate_Adaptor.
1637 // Keep these in sync.
1638
1639 // API and CPP builtins are implemented in C++, and we can inline both.
1640 // CPP builtins create a builtin exit frame, API builtins don't.
1641 const auto builtin = isolate()->builtins()->DescriptorFor(builtin_name);
1642 const bool create_builtin_exit_frame = (builtin->kind == Builtins::CPP);
1643
1644 Node* stub = jsgraph()->CEntryStubConstant(
1645 1, kDontSaveFPRegs, kArgvOnStack, create_builtin_exit_frame);
1646 node->ReplaceInput(0, stub);
1647
1648 const int argc = arity + BuiltinArguments::kNumExtraArgsWithReceiver;
1649 Node* argc_node = jsgraph()->Int32Constant(argc);
1650
1651 Zone* zone = graph()->zone();
1652 node->InsertInput(zone, arity + 2, argc_node);
1653 node->InsertInput(zone, arity + 3, target);
1654 node->InsertInput(zone, arity + 4, new_target);
1655
1656 ExternalReference entry(ExternalReference(builtin->entry, isolate()));
1657 Node* entry_node = jsgraph()->ExternalConstant(entry);
1658
1659 node->InsertInput(zone, arity + 5, entry_node);
1660 node->InsertInput(zone, arity + 6, argc_node);
1661
1662 const int return_count = 1;
1663 CallDescriptor::Flags flags = CallDescriptor::kNeedsFrameState;
1664 Operator::Properties properties = node->op()->properties();
1665 CallDescriptor* desc = Linkage::GetCEntryStubCallDescriptor(
1666 graph()->zone(), return_count, argc, builtin->debug_name, properties,
1667 flags);
1668
1669 NodeProperties::ChangeOp(node, common()->Call(desc));
1670 } else if (shared->internal_formal_parameter_count() == arity ||
1671 shared->internal_formal_parameter_count() ==
1672 SharedFunctionInfo::kDontAdaptArgumentsSentinel) {
1619 // Patch {node} to a direct call. 1673 // Patch {node} to a direct call.
1620 node->InsertInput(graph()->zone(), arity + 2, new_target); 1674 node->InsertInput(graph()->zone(), arity + 2, new_target);
1621 node->InsertInput(graph()->zone(), arity + 3, argument_count); 1675 node->InsertInput(graph()->zone(), arity + 3, argument_count);
1622 NodeProperties::ChangeOp(node, 1676 NodeProperties::ChangeOp(node,
1623 common()->Call(Linkage::GetJSCallDescriptor( 1677 common()->Call(Linkage::GetJSCallDescriptor(
1624 graph()->zone(), false, 1 + arity, flags))); 1678 graph()->zone(), false, 1 + arity, flags)));
1625 } else { 1679 } else {
1626 // Patch {node} to an indirect call via the ArgumentsAdaptorTrampoline. 1680 // Patch {node} to an indirect call via the ArgumentsAdaptorTrampoline.
1627 Callable callable = CodeFactory::ArgumentAdaptor(isolate()); 1681 Callable callable = CodeFactory::ArgumentAdaptor(isolate());
1628 node->InsertInput(graph()->zone(), 0, 1682 node->InsertInput(graph()->zone(), 0,
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 } 2173 }
2120 2174
2121 2175
2122 CompilationDependencies* JSTypedLowering::dependencies() const { 2176 CompilationDependencies* JSTypedLowering::dependencies() const {
2123 return dependencies_; 2177 return dependencies_;
2124 } 2178 }
2125 2179
2126 } // namespace compiler 2180 } // namespace compiler
2127 } // namespace internal 2181 } // namespace internal
2128 } // namespace v8 2182 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698