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

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: Address comments 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
« no previous file with comments | « src/compiler/js-graph.cc ('k') | src/compiler/linkage.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 const int builtin_index = shared->code()->builtin_index();
1587 const bool is_builtin = (builtin_index != -1);
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 (is_builtin && Builtins::HasCppImplementation(builtin_index)) {
1617 shared->internal_formal_parameter_count() == 1620 // Patch {node} to a direct CEntryStub call.
1618 SharedFunctionInfo::kDontAdaptArgumentsSentinel) { 1621 //
1622 // ----------- A r g u m e n t s -----------
1623 // -- 0: CEntryStub
1624 // --- Stack args ---
1625 // -- 1: receiver
1626 // -- [2, 2 + n[: the n actual arguments passed to the builtin
1627 // -- 2 + n: argc, including the receiver and implicit args (Smi)
1628 // -- 2 + n + 1: target
1629 // -- 2 + n + 2: new_target
1630 // --- Register args ---
1631 // -- 2 + n + 3: the C entry point
1632 // -- 2 + n + 4: argc (Int32)
1633 // -----------------------------------
1634
1635 // The logic contained here is mirrored in Builtins::Generate_Adaptor.
1636 // Keep these in sync.
1637
1638 // API and CPP builtins are implemented in C++, and we can inline both.
1639 // CPP builtins create a builtin exit frame, API builtins don't.
1640 const bool create_builtin_exit_frame = Builtins::IsCpp(builtin_index);
1641
1642 Node* stub = jsgraph()->CEntryStubConstant(
1643 1, kDontSaveFPRegs, kArgvOnStack, create_builtin_exit_frame);
1644 node->ReplaceInput(0, stub);
1645
1646 const int argc = arity + BuiltinArguments::kNumExtraArgsWithReceiver;
1647 Node* argc_node = jsgraph()->Int32Constant(argc);
1648
1649 Zone* zone = graph()->zone();
1650 node->InsertInput(zone, arity + 2, argc_node);
1651 node->InsertInput(zone, arity + 3, target);
1652 node->InsertInput(zone, arity + 4, new_target);
1653
1654 Address entry = Builtins::CppEntryOf(builtin_index);
1655 ExternalReference entry_ref(ExternalReference(entry, isolate()));
1656 Node* entry_node = jsgraph()->ExternalConstant(entry_ref);
1657
1658 node->InsertInput(zone, arity + 5, entry_node);
1659 node->InsertInput(zone, arity + 6, argc_node);
1660
1661 const int return_count = 1;
1662 Operator::Properties properties = node->op()->properties();
1663 const char* debug_name = Builtins::name(builtin_index);
1664 CallDescriptor* desc = Linkage::GetCEntryStubCallDescriptor(
1665 graph()->zone(), return_count, argc, debug_name, properties, flags);
1666
1667 NodeProperties::ChangeOp(node, common()->Call(desc));
1668 } else if (shared->internal_formal_parameter_count() == arity ||
1669 shared->internal_formal_parameter_count() ==
1670 SharedFunctionInfo::kDontAdaptArgumentsSentinel) {
1619 // Patch {node} to a direct call. 1671 // Patch {node} to a direct call.
1620 node->InsertInput(graph()->zone(), arity + 2, new_target); 1672 node->InsertInput(graph()->zone(), arity + 2, new_target);
1621 node->InsertInput(graph()->zone(), arity + 3, argument_count); 1673 node->InsertInput(graph()->zone(), arity + 3, argument_count);
1622 NodeProperties::ChangeOp(node, 1674 NodeProperties::ChangeOp(node,
1623 common()->Call(Linkage::GetJSCallDescriptor( 1675 common()->Call(Linkage::GetJSCallDescriptor(
1624 graph()->zone(), false, 1 + arity, flags))); 1676 graph()->zone(), false, 1 + arity, flags)));
1625 } else { 1677 } else {
1626 // Patch {node} to an indirect call via the ArgumentsAdaptorTrampoline. 1678 // Patch {node} to an indirect call via the ArgumentsAdaptorTrampoline.
1627 Callable callable = CodeFactory::ArgumentAdaptor(isolate()); 1679 Callable callable = CodeFactory::ArgumentAdaptor(isolate());
1628 node->InsertInput(graph()->zone(), 0, 1680 node->InsertInput(graph()->zone(), 0,
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 } 2171 }
2120 2172
2121 2173
2122 CompilationDependencies* JSTypedLowering::dependencies() const { 2174 CompilationDependencies* JSTypedLowering::dependencies() const {
2123 return dependencies_; 2175 return dependencies_;
2124 } 2176 }
2125 2177
2126 } // namespace compiler 2178 } // namespace compiler
2127 } // namespace internal 2179 } // namespace internal
2128 } // namespace v8 2180 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-graph.cc ('k') | src/compiler/linkage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698