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

Unified Diff: src/compiler/js-generic-lowering.cc

Issue 696223002: Now with more checkings! Skip the CallFunctionStub when the callee function can be statically deter… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/js-generic-lowering.h ('k') | src/compiler/linkage.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/js-generic-lowering.cc
diff --git a/src/compiler/js-generic-lowering.cc b/src/compiler/js-generic-lowering.cc
index 11979ec6edc9ea800980354a4ca70521fe7bddaa..6434c1062cba0c8e57eb56798b7e56d6d6d04b53 100644
--- a/src/compiler/js-generic-lowering.cc
+++ b/src/compiler/js-generic-lowering.cc
@@ -9,6 +9,7 @@
#include "src/compiler/js-generic-lowering.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node-aux-data-inl.h"
+#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties-inl.h"
#include "src/unique.h"
@@ -405,15 +406,56 @@ void JSGenericLowering::LowerJSCallConstruct(Node* node) {
}
-void JSGenericLowering::LowerJSCallFunction(Node* node) {
+bool JSGenericLowering::TryLowerDirectJSCall(Node* node) {
+ // Lower to a direct call to a constant JSFunction if legal.
const CallFunctionParameters& p = CallFunctionParametersOf(node->op());
- CallFunctionStub stub(isolate(), static_cast<int>(p.arity() - 2), p.flags());
- CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor();
- CallDescriptor* desc = linkage()->GetStubCallDescriptor(
- d, static_cast<int>(p.arity() - 1), FlagsForNode(node));
- Node* stub_code = CodeConstant(stub.GetCode());
- PatchInsertInput(node, 0, stub_code);
+ int arg_count = static_cast<int>(p.arity() - 2);
+
+ // Check the function is a constant and is really a JSFunction.
+ HeapObjectMatcher<Object> function_const(node->InputAt(0));
+ if (!function_const.HasValue()) return false; // not a constant.
+ Handle<Object> func = function_const.Value().handle();
+ if (!func->IsJSFunction()) return false; // not a function.
+ Handle<JSFunction> function = Handle<JSFunction>::cast(func);
+ if (arg_count != function->shared()->formal_parameter_count()) return false;
+
+ // Check the receiver doesn't need to be wrapped.
+ Node* receiver = node->InputAt(1);
+ if (!NodeProperties::IsTyped(receiver)) return false;
+ Type* ok_receiver = Type::Union(Type::Undefined(), Type::Receiver(), zone());
+ if (!NodeProperties::GetBounds(receiver).upper->Is(ok_receiver)) return false;
+
+ int index = NodeProperties::FirstContextIndex(node);
+
+ // TODO(titzer): total hack to share function context constants.
+ // Remove this when the JSGraph canonicalizes heap constants.
+ Node* context = node->InputAt(index);
+ HeapObjectMatcher<Context> context_const(context);
+ if (!context_const.HasValue() ||
+ *(context_const.Value().handle()) != function->context()) {
+ context = jsgraph()->HeapConstant(Handle<Context>(function->context()));
+ }
+ node->ReplaceInput(index, context);
+ CallDescriptor* desc = linkage()->GetJSCallDescriptor(
+ 1 + arg_count, jsgraph()->zone(), FlagsForNode(node));
PatchOperator(node, common()->Call(desc));
+ return true;
+}
+
+
+void JSGenericLowering::LowerJSCallFunction(Node* node) {
+ if (!TryLowerDirectJSCall(node)) {
Michael Starzinger 2014/11/03 09:57:41 nit: How would you feel about an early return here
+ // Call to computed function; use CallFunctionStub;
+ const CallFunctionParameters& p = CallFunctionParametersOf(node->op());
+ int arg_count = static_cast<int>(p.arity() - 2);
+ CallFunctionStub stub(isolate(), arg_count, p.flags());
+ CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor();
+ CallDescriptor* desc = linkage()->GetStubCallDescriptor(
+ d, static_cast<int>(p.arity() - 1), FlagsForNode(node));
+ Node* stub_code = CodeConstant(stub.GetCode());
+ PatchInsertInput(node, 0, stub_code);
+ PatchOperator(node, common()->Call(desc));
+ }
}
« no previous file with comments | « src/compiler/js-generic-lowering.h ('k') | src/compiler/linkage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698