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/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 Loading... | |
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 static Node* ReuseContextIfPossible(JSGraph* jsgraph, | |
410 Handle<JSFunction> function, | |
411 Node* maybe_the_right_one) { | |
412 // TODO(titzer): total hack to share function context constants. | |
413 // Remove this when the JSGraph canonicalizes heap constants. | |
414 HeapObjectMatcher<Context> context(maybe_the_right_one); | |
415 if (context.HasValue() && | |
416 *(context.Value().handle()) == function->context()) { | |
417 return maybe_the_right_one; | |
418 } | |
419 return jsgraph->HeapConstant(Handle<Context>(function->context())); | |
420 } | |
421 | |
422 | |
408 void JSGenericLowering::LowerJSCallFunction(Node* node) { | 423 void JSGenericLowering::LowerJSCallFunction(Node* node) { |
409 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); | 424 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); |
410 CallFunctionStub stub(isolate(), static_cast<int>(p.arity() - 2), p.flags()); | 425 int argument_count = static_cast<int>(p.arity() - 2); |
426 HeapObjectMatcher<JSFunction> func(node->InputAt(0)); | |
427 if (func.HasValue()) { | |
Michael Starzinger
2014/10/31 12:28:06
suggestion: How would you feel about moving this o
| |
428 // Call to a constant JSFunction. Skip CallFunctionStub if arity matches. | |
429 Handle<JSFunction> function = func.Value().handle(); | |
430 if (argument_count == function->shared()->formal_parameter_count()) { | |
431 int index = NodeProperties::FirstContextIndex(node); | |
432 Node* context = | |
433 ReuseContextIfPossible(jsgraph(), function, node->InputAt(index)); | |
434 node->ReplaceInput(index, context); | |
435 CallDescriptor* desc = linkage()->GetJSCallDescriptor( | |
436 1 + argument_count, jsgraph()->zone(), FlagsForNode(node)); | |
437 PatchOperator(node, common()->Call(desc)); | |
438 return; | |
439 } | |
440 } | |
441 // Call to computed function; use CallFunctionStub; | |
442 CallFunctionStub stub(isolate(), argument_count, p.flags()); | |
411 CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor(); | 443 CallInterfaceDescriptor d = stub.GetCallInterfaceDescriptor(); |
412 CallDescriptor* desc = linkage()->GetStubCallDescriptor( | 444 CallDescriptor* desc = linkage()->GetStubCallDescriptor( |
413 d, static_cast<int>(p.arity() - 1), FlagsForNode(node)); | 445 d, static_cast<int>(p.arity() - 1), FlagsForNode(node)); |
414 Node* stub_code = CodeConstant(stub.GetCode()); | 446 Node* stub_code = CodeConstant(stub.GetCode()); |
415 PatchInsertInput(node, 0, stub_code); | 447 PatchInsertInput(node, 0, stub_code); |
416 PatchOperator(node, common()->Call(desc)); | 448 PatchOperator(node, common()->Call(desc)); |
417 } | 449 } |
418 | 450 |
419 | 451 |
420 void JSGenericLowering::LowerJSCallRuntime(Node* node) { | 452 void JSGenericLowering::LowerJSCallRuntime(Node* node) { |
421 const CallRuntimeParameters& p = CallRuntimeParametersOf(node->op()); | 453 const CallRuntimeParameters& p = CallRuntimeParametersOf(node->op()); |
422 ReplaceWithRuntimeCall(node, p.id(), static_cast<int>(p.arity())); | 454 ReplaceWithRuntimeCall(node, p.id(), static_cast<int>(p.arity())); |
423 } | 455 } |
424 | 456 |
425 } // namespace compiler | 457 } // namespace compiler |
426 } // namespace internal | 458 } // namespace internal |
427 } // namespace v8 | 459 } // namespace v8 |
OLD | NEW |