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

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

Issue 694773002: Skip the CallFunctionStub when the callee function can be statically determined. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments. 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 unified diff | Download patch | Annotate | Revision Log
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/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/graph-inl.h" 8 #include "src/compiler/graph-inl.h"
9 #include "src/compiler/js-generic-lowering.h" 9 #include "src/compiler/js-generic-lowering.h"
10 #include "src/compiler/machine-operator.h" 10 #include "src/compiler/machine-operator.h"
11 #include "src/compiler/node-aux-data-inl.h" 11 #include "src/compiler/node-aux-data-inl.h"
12 #include "src/compiler/node-matchers.h"
12 #include "src/compiler/node-properties-inl.h" 13 #include "src/compiler/node-properties-inl.h"
13 #include "src/unique.h" 14 #include "src/unique.h"
14 15
15 namespace v8 { 16 namespace v8 {
16 namespace internal { 17 namespace internal {
17 namespace compiler { 18 namespace compiler {
18 19
19 JSGenericLowering::JSGenericLowering(CompilationInfo* info, JSGraph* jsgraph) 20 JSGenericLowering::JSGenericLowering(CompilationInfo* info, JSGraph* jsgraph)
20 : info_(info), 21 : info_(info),
21 jsgraph_(jsgraph), 22 jsgraph_(jsgraph),
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 Node* stub_code = CodeConstant(stub.GetCode()); 399 Node* stub_code = CodeConstant(stub.GetCode());
399 Node* construct = NodeProperties::GetValueInput(node, 0); 400 Node* construct = NodeProperties::GetValueInput(node, 0);
400 PatchInsertInput(node, 0, stub_code); 401 PatchInsertInput(node, 0, stub_code);
401 PatchInsertInput(node, 1, Int32Constant(arity - 1)); 402 PatchInsertInput(node, 1, Int32Constant(arity - 1));
402 PatchInsertInput(node, 2, construct); 403 PatchInsertInput(node, 2, construct);
403 PatchInsertInput(node, 3, jsgraph()->UndefinedConstant()); 404 PatchInsertInput(node, 3, jsgraph()->UndefinedConstant());
404 PatchOperator(node, common()->Call(desc)); 405 PatchOperator(node, common()->Call(desc));
405 } 406 }
406 407
407 408
409 bool JSGenericLowering::TryLowerDirectJSCall(Node* node) {
410 // Lower to a direct call to a constant JSFunction if the arity matches.
411 const CallFunctionParameters& p = CallFunctionParametersOf(node->op());
412 int arg_count = static_cast<int>(p.arity() - 2);
413 HeapObjectMatcher<JSFunction> func(node->InputAt(0));
414 if (!func.HasValue()) return false;
415
416 Handle<JSFunction> function = func.Value().handle();
417 if (arg_count != function->shared()->formal_parameter_count()) return false;
418
419 int index = NodeProperties::FirstContextIndex(node);
420
421 // TODO(titzer): total hack to share function context constants.
422 // Remove this when the JSGraph canonicalizes heap constants.
423 Node* context = node->InputAt(index);
424 HeapObjectMatcher<Context> context_const(context);
425 if (!context_const.HasValue() ||
426 *(context_const.Value().handle()) != function->context()) {
427 context = jsgraph()->HeapConstant(Handle<Context>(function->context()));
428 }
429 node->ReplaceInput(index, context);
430 CallDescriptor* desc = linkage()->GetJSCallDescriptor(
431 1 + arg_count, jsgraph()->zone(), FlagsForNode(node));
432 PatchOperator(node, common()->Call(desc));
433 return true;
434 }
435
436
408 void JSGenericLowering::LowerJSCallFunction(Node* node) { 437 void JSGenericLowering::LowerJSCallFunction(Node* node) {
409 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); 438 if (!TryLowerDirectJSCall(node)) {
410 CallFunctionStub stub(isolate(), static_cast<int>(p.arity() - 2), p.flags()); 439 // Call to computed function; use CallFunctionStub;
411 CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor(); 440 const CallFunctionParameters& p = CallFunctionParametersOf(node->op());
412 CallDescriptor* desc = linkage()->GetStubCallDescriptor( 441 int arg_count = static_cast<int>(p.arity() - 2);
413 d, static_cast<int>(p.arity() - 1), FlagsForNode(node)); 442 CallFunctionStub stub(isolate(), arg_count, p.flags());
414 Node* stub_code = CodeConstant(stub.GetCode()); 443 CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor();
415 PatchInsertInput(node, 0, stub_code); 444 CallDescriptor* desc = linkage()->GetStubCallDescriptor(
416 PatchOperator(node, common()->Call(desc)); 445 d, static_cast<int>(p.arity() - 1), FlagsForNode(node));
446 Node* stub_code = CodeConstant(stub.GetCode());
447 PatchInsertInput(node, 0, stub_code);
448 PatchOperator(node, common()->Call(desc));
449 }
417 } 450 }
418 451
419 452
420 void JSGenericLowering::LowerJSCallRuntime(Node* node) { 453 void JSGenericLowering::LowerJSCallRuntime(Node* node) {
421 const CallRuntimeParameters& p = CallRuntimeParametersOf(node->op()); 454 const CallRuntimeParameters& p = CallRuntimeParametersOf(node->op());
422 ReplaceWithRuntimeCall(node, p.id(), static_cast<int>(p.arity())); 455 ReplaceWithRuntimeCall(node, p.id(), static_cast<int>(p.arity()));
423 } 456 }
424 457
425 } // namespace compiler 458 } // namespace compiler
426 } // namespace internal 459 } // namespace internal
427 } // namespace v8 460 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698