| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 3532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3543 FunctionState::FunctionState(HOptimizedGraphBuilder* owner, | 3543 FunctionState::FunctionState(HOptimizedGraphBuilder* owner, |
| 3544 CompilationInfo* info, | 3544 CompilationInfo* info, |
| 3545 InliningKind inlining_kind) | 3545 InliningKind inlining_kind) |
| 3546 : owner_(owner), | 3546 : owner_(owner), |
| 3547 compilation_info_(info), | 3547 compilation_info_(info), |
| 3548 call_context_(NULL), | 3548 call_context_(NULL), |
| 3549 inlining_kind_(inlining_kind), | 3549 inlining_kind_(inlining_kind), |
| 3550 function_return_(NULL), | 3550 function_return_(NULL), |
| 3551 test_context_(NULL), | 3551 test_context_(NULL), |
| 3552 entry_(NULL), | 3552 entry_(NULL), |
| 3553 arguments_object_(NULL), |
| 3553 arguments_elements_(NULL), | 3554 arguments_elements_(NULL), |
| 3554 outer_(owner->function_state()) { | 3555 outer_(owner->function_state()) { |
| 3555 if (outer_ != NULL) { | 3556 if (outer_ != NULL) { |
| 3556 // State for an inline function. | 3557 // State for an inline function. |
| 3557 if (owner->ast_context()->IsTest()) { | 3558 if (owner->ast_context()->IsTest()) { |
| 3558 HBasicBlock* if_true = owner->graph()->CreateBasicBlock(); | 3559 HBasicBlock* if_true = owner->graph()->CreateBasicBlock(); |
| 3559 HBasicBlock* if_false = owner->graph()->CreateBasicBlock(); | 3560 HBasicBlock* if_false = owner->graph()->CreateBasicBlock(); |
| 3560 if_true->MarkAsInlineReturnTarget(owner->current_block()); | 3561 if_true->MarkAsInlineReturnTarget(owner->current_block()); |
| 3561 if_false->MarkAsInlineReturnTarget(owner->current_block()); | 3562 if_false->MarkAsInlineReturnTarget(owner->current_block()); |
| 3562 TestContext* outer_test_context = TestContext::cast(owner->ast_context()); | 3563 TestContext* outer_test_context = TestContext::cast(owner->ast_context()); |
| (...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4694 return call; | 4695 return call; |
| 4695 } | 4696 } |
| 4696 | 4697 |
| 4697 | 4698 |
| 4698 void HOptimizedGraphBuilder::SetUpScope(Scope* scope) { | 4699 void HOptimizedGraphBuilder::SetUpScope(Scope* scope) { |
| 4699 HConstant* undefined_constant = new(zone()) HConstant( | 4700 HConstant* undefined_constant = new(zone()) HConstant( |
| 4700 isolate()->factory()->undefined_value(), Representation::Tagged()); | 4701 isolate()->factory()->undefined_value(), Representation::Tagged()); |
| 4701 AddInstruction(undefined_constant); | 4702 AddInstruction(undefined_constant); |
| 4702 graph()->set_undefined_constant(undefined_constant); | 4703 graph()->set_undefined_constant(undefined_constant); |
| 4703 | 4704 |
| 4704 HArgumentsObject* object = new(zone()) HArgumentsObject; | 4705 // Create an arguments object containing the initial parameters. Set the |
| 4705 AddInstruction(object); | 4706 // initial values of parameters including "this" having parameter index 0. |
| 4706 graph()->SetArgumentsObject(object); | |
| 4707 | |
| 4708 // Set the initial values of parameters including "this". "This" has | |
| 4709 // parameter index 0. | |
| 4710 ASSERT_EQ(scope->num_parameters() + 1, environment()->parameter_count()); | 4707 ASSERT_EQ(scope->num_parameters() + 1, environment()->parameter_count()); |
| 4711 | 4708 HArgumentsObject* arguments_object = |
| 4709 new(zone()) HArgumentsObject(environment()->parameter_count(), zone()); |
| 4712 for (int i = 0; i < environment()->parameter_count(); ++i) { | 4710 for (int i = 0; i < environment()->parameter_count(); ++i) { |
| 4713 HInstruction* parameter = AddInstruction(new(zone()) HParameter(i)); | 4711 HInstruction* parameter = AddInstruction(new(zone()) HParameter(i)); |
| 4712 arguments_object->AddArgument(parameter, zone()); |
| 4714 environment()->Bind(i, parameter); | 4713 environment()->Bind(i, parameter); |
| 4715 } | 4714 } |
| 4715 AddInstruction(arguments_object); |
| 4716 graph()->SetArgumentsObject(arguments_object); |
| 4716 | 4717 |
| 4717 // First special is HContext. | 4718 // First special is HContext. |
| 4718 HInstruction* context = AddInstruction(new(zone()) HContext); | 4719 HInstruction* context = AddInstruction(new(zone()) HContext); |
| 4719 environment()->BindContext(context); | 4720 environment()->BindContext(context); |
| 4720 | 4721 |
| 4721 // Initialize specials and locals to undefined. | 4722 // Initialize specials and locals to undefined. |
| 4722 for (int i = environment()->parameter_count() + 1; | 4723 for (int i = environment()->parameter_count() + 1; |
| 4723 i < environment()->length(); | 4724 i < environment()->length(); |
| 4724 ++i) { | 4725 ++i) { |
| 4725 environment()->Bind(i, undefined_constant); | 4726 environment()->Bind(i, undefined_constant); |
| (...skipping 2697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7423 void HOptimizedGraphBuilder::EnsureArgumentsArePushedForAccess() { | 7424 void HOptimizedGraphBuilder::EnsureArgumentsArePushedForAccess() { |
| 7424 // Outermost function already has arguments on the stack. | 7425 // Outermost function already has arguments on the stack. |
| 7425 if (function_state()->outer() == NULL) return; | 7426 if (function_state()->outer() == NULL) return; |
| 7426 | 7427 |
| 7427 if (function_state()->arguments_pushed()) return; | 7428 if (function_state()->arguments_pushed()) return; |
| 7428 | 7429 |
| 7429 // Push arguments when entering inlined function. | 7430 // Push arguments when entering inlined function. |
| 7430 HEnterInlined* entry = function_state()->entry(); | 7431 HEnterInlined* entry = function_state()->entry(); |
| 7431 entry->set_arguments_pushed(); | 7432 entry->set_arguments_pushed(); |
| 7432 | 7433 |
| 7433 ZoneList<HValue*>* arguments_values = entry->arguments_values(); | 7434 HArgumentsObject* arguments = entry->arguments_object(); |
| 7435 const ZoneList<HValue*>* arguments_values = arguments->arguments_values(); |
| 7434 | 7436 |
| 7435 HInstruction* insert_after = entry; | 7437 HInstruction* insert_after = entry; |
| 7436 for (int i = 0; i < arguments_values->length(); i++) { | 7438 for (int i = 0; i < arguments_values->length(); i++) { |
| 7437 HValue* argument = arguments_values->at(i); | 7439 HValue* argument = arguments_values->at(i); |
| 7438 HInstruction* push_argument = new(zone()) HPushArgument(argument); | 7440 HInstruction* push_argument = new(zone()) HPushArgument(argument); |
| 7439 push_argument->InsertAfter(insert_after); | 7441 push_argument->InsertAfter(insert_after); |
| 7440 insert_after = push_argument; | 7442 insert_after = push_argument; |
| 7441 } | 7443 } |
| 7442 | 7444 |
| 7443 HArgumentsElements* arguments_elements = | 7445 HArgumentsElements* arguments_elements = |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8024 // can remove the unsightly ifdefs in this function. | 8026 // can remove the unsightly ifdefs in this function. |
| 8025 HConstant* context = | 8027 HConstant* context = |
| 8026 new(zone()) HConstant(Handle<Context>(target->context()), | 8028 new(zone()) HConstant(Handle<Context>(target->context()), |
| 8027 Representation::Tagged()); | 8029 Representation::Tagged()); |
| 8028 AddInstruction(context); | 8030 AddInstruction(context); |
| 8029 inner_env->BindContext(context); | 8031 inner_env->BindContext(context); |
| 8030 #endif | 8032 #endif |
| 8031 | 8033 |
| 8032 AddSimulate(return_id); | 8034 AddSimulate(return_id); |
| 8033 current_block()->UpdateEnvironment(inner_env); | 8035 current_block()->UpdateEnvironment(inner_env); |
| 8034 ZoneList<HValue*>* arguments_values = NULL; | 8036 HArgumentsObject* arguments_object = NULL; |
| 8035 | 8037 |
| 8036 // If the function uses arguments copy current arguments values | 8038 // If the function uses arguments object create and bind one, also copy |
| 8037 // to use them for materialization. | 8039 // current arguments values to use them for materialization. |
| 8038 if (function->scope()->arguments() != NULL) { | 8040 if (function->scope()->arguments() != NULL) { |
| 8041 ASSERT(function->scope()->arguments()->IsStackAllocated()); |
| 8039 HEnvironment* arguments_env = inner_env->arguments_environment(); | 8042 HEnvironment* arguments_env = inner_env->arguments_environment(); |
| 8040 int arguments_count = arguments_env->parameter_count(); | 8043 int arguments_count = arguments_env->parameter_count(); |
| 8041 arguments_values = new(zone()) ZoneList<HValue*>(arguments_count, zone()); | 8044 arguments_object = new(zone()) HArgumentsObject(arguments_count, zone()); |
| 8045 inner_env->Bind(function->scope()->arguments(), arguments_object); |
| 8042 for (int i = 0; i < arguments_count; i++) { | 8046 for (int i = 0; i < arguments_count; i++) { |
| 8043 arguments_values->Add(arguments_env->Lookup(i), zone()); | 8047 arguments_object->AddArgument(arguments_env->Lookup(i), zone()); |
| 8044 } | 8048 } |
| 8049 AddInstruction(arguments_object); |
| 8045 } | 8050 } |
| 8046 | 8051 |
| 8047 HEnterInlined* enter_inlined = | 8052 HEnterInlined* enter_inlined = |
| 8048 new(zone()) HEnterInlined(target, | 8053 new(zone()) HEnterInlined(target, |
| 8049 arguments_count, | 8054 arguments_count, |
| 8050 function, | 8055 function, |
| 8051 function_state()->inlining_kind(), | 8056 function_state()->inlining_kind(), |
| 8052 function->scope()->arguments(), | 8057 function->scope()->arguments(), |
| 8053 arguments_values, | 8058 arguments_object, |
| 8054 undefined_receiver, | 8059 undefined_receiver, |
| 8055 zone()); | 8060 zone()); |
| 8056 function_state()->set_entry(enter_inlined); | 8061 function_state()->set_entry(enter_inlined); |
| 8057 AddInstruction(enter_inlined); | 8062 AddInstruction(enter_inlined); |
| 8058 | 8063 |
| 8059 // If the function uses arguments object create and bind one. | |
| 8060 if (function->scope()->arguments() != NULL) { | |
| 8061 ASSERT(function->scope()->arguments()->IsStackAllocated()); | |
| 8062 inner_env->Bind(function->scope()->arguments(), | |
| 8063 graph()->GetArgumentsObject()); | |
| 8064 } | |
| 8065 | |
| 8066 | |
| 8067 VisitDeclarations(target_info.scope()->declarations()); | 8064 VisitDeclarations(target_info.scope()->declarations()); |
| 8068 VisitStatements(function->body()); | 8065 VisitStatements(function->body()); |
| 8069 if (HasStackOverflow()) { | 8066 if (HasStackOverflow()) { |
| 8070 // Bail out if the inline function did, as we cannot residualize a call | 8067 // Bail out if the inline function did, as we cannot residualize a call |
| 8071 // instead. | 8068 // instead. |
| 8072 TraceInline(target, caller, "inline graph construction failed"); | 8069 TraceInline(target, caller, "inline graph construction failed"); |
| 8073 target_shared->DisableOptimization("inlining bailed out"); | 8070 target_shared->DisableOptimization("inlining bailed out"); |
| 8074 inline_bailout_ = true; | 8071 inline_bailout_ = true; |
| 8075 delete target_state; | 8072 delete target_state; |
| 8076 return true; | 8073 return true; |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8487 new(zone()) HApplyArguments(function, | 8484 new(zone()) HApplyArguments(function, |
| 8488 wrapped_receiver, | 8485 wrapped_receiver, |
| 8489 length, | 8486 length, |
| 8490 elements); | 8487 elements); |
| 8491 result->set_position(expr->position()); | 8488 result->set_position(expr->position()); |
| 8492 ast_context()->ReturnInstruction(result, expr->id()); | 8489 ast_context()->ReturnInstruction(result, expr->id()); |
| 8493 return true; | 8490 return true; |
| 8494 } else { | 8491 } else { |
| 8495 // We are inside inlined function and we know exactly what is inside | 8492 // We are inside inlined function and we know exactly what is inside |
| 8496 // arguments object. But we need to be able to materialize at deopt. | 8493 // arguments object. But we need to be able to materialize at deopt. |
| 8497 // TODO(mstarzinger): For now we just ensure arguments are pushed | |
| 8498 // right after HEnterInlined, but we could be smarter about this. | |
| 8499 EnsureArgumentsArePushedForAccess(); | |
| 8500 ASSERT_EQ(environment()->arguments_environment()->parameter_count(), | 8494 ASSERT_EQ(environment()->arguments_environment()->parameter_count(), |
| 8501 function_state()->entry()->arguments_values()->length()); | 8495 function_state()->entry()->arguments_object()->arguments_count()); |
| 8502 HEnterInlined* entry = function_state()->entry(); | 8496 HArgumentsObject* args = function_state()->entry()->arguments_object(); |
| 8503 ZoneList<HValue*>* arguments_values = entry->arguments_values(); | 8497 const ZoneList<HValue*>* arguments_values = args->arguments_values(); |
| 8504 int arguments_count = arguments_values->length(); | 8498 int arguments_count = arguments_values->length(); |
| 8505 PushAndAdd(new(zone()) HWrapReceiver(receiver, function)); | 8499 PushAndAdd(new(zone()) HWrapReceiver(receiver, function)); |
| 8506 for (int i = 1; i < arguments_count; i++) { | 8500 for (int i = 1; i < arguments_count; i++) { |
| 8507 Push(arguments_values->at(i)); | 8501 Push(arguments_values->at(i)); |
| 8508 } | 8502 } |
| 8509 | 8503 |
| 8510 Handle<JSFunction> known_function; | 8504 Handle<JSFunction> known_function; |
| 8511 if (function->IsConstant()) { | 8505 if (function->IsConstant()) { |
| 8512 HConstant* constant_function = HConstant::cast(function); | 8506 HConstant* constant_function = HConstant::cast(function); |
| 8513 known_function = Handle<JSFunction>::cast(constant_function->handle()); | 8507 known_function = Handle<JSFunction>::cast(constant_function->handle()); |
| (...skipping 2484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10998 | 10992 |
| 10999 HEnvironment::HEnvironment(HEnvironment* outer, | 10993 HEnvironment::HEnvironment(HEnvironment* outer, |
| 11000 Handle<JSFunction> closure, | 10994 Handle<JSFunction> closure, |
| 11001 FrameType frame_type, | 10995 FrameType frame_type, |
| 11002 int arguments, | 10996 int arguments, |
| 11003 Zone* zone) | 10997 Zone* zone) |
| 11004 : closure_(closure), | 10998 : closure_(closure), |
| 11005 values_(arguments, zone), | 10999 values_(arguments, zone), |
| 11006 frame_type_(frame_type), | 11000 frame_type_(frame_type), |
| 11007 parameter_count_(arguments), | 11001 parameter_count_(arguments), |
| 11002 specials_count_(0), |
| 11008 local_count_(0), | 11003 local_count_(0), |
| 11009 outer_(outer), | 11004 outer_(outer), |
| 11010 entry_(NULL), | 11005 entry_(NULL), |
| 11011 pop_count_(0), | 11006 pop_count_(0), |
| 11012 push_count_(0), | 11007 push_count_(0), |
| 11013 ast_id_(BailoutId::None()), | 11008 ast_id_(BailoutId::None()), |
| 11014 zone_(zone) { | 11009 zone_(zone) { |
| 11015 } | 11010 } |
| 11016 | 11011 |
| 11017 | 11012 |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11613 } | 11608 } |
| 11614 } | 11609 } |
| 11615 | 11610 |
| 11616 #ifdef DEBUG | 11611 #ifdef DEBUG |
| 11617 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 11612 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 11618 if (allocator_ != NULL) allocator_->Verify(); | 11613 if (allocator_ != NULL) allocator_->Verify(); |
| 11619 #endif | 11614 #endif |
| 11620 } | 11615 } |
| 11621 | 11616 |
| 11622 } } // namespace v8::internal | 11617 } } // namespace v8::internal |
| OLD | NEW |