OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/hydrogen.h" | 5 #include "src/hydrogen.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "src/allocation-site-scopes.h" | 9 #include "src/allocation-site-scopes.h" |
10 #include "src/ast-numbering.h" | 10 #include "src/ast-numbering.h" |
(...skipping 3628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3639 start_environment_ = | 3639 start_environment_ = |
3640 new (zone_) HEnvironment(zone_, descriptor.GetRegisterParameterCount()); | 3640 new (zone_) HEnvironment(zone_, descriptor.GetRegisterParameterCount()); |
3641 } else { | 3641 } else { |
3642 if (info->is_tracking_positions()) { | 3642 if (info->is_tracking_positions()) { |
3643 info->TraceInlinedFunction(info->shared_info(), SourcePosition::Unknown(), | 3643 info->TraceInlinedFunction(info->shared_info(), SourcePosition::Unknown(), |
3644 InlinedFunctionInfo::kNoParentId); | 3644 InlinedFunctionInfo::kNoParentId); |
3645 } | 3645 } |
3646 start_environment_ = | 3646 start_environment_ = |
3647 new(zone_) HEnvironment(NULL, info->scope(), info->closure(), zone_); | 3647 new(zone_) HEnvironment(NULL, info->scope(), info->closure(), zone_); |
3648 } | 3648 } |
3649 start_environment_->set_ast_id(BailoutId::FunctionEntry()); | 3649 start_environment_->set_ast_id(BailoutId::Prologue()); |
3650 entry_block_ = CreateBasicBlock(); | 3650 entry_block_ = CreateBasicBlock(); |
3651 entry_block_->SetInitialEnvironment(start_environment_); | 3651 entry_block_->SetInitialEnvironment(start_environment_); |
3652 } | 3652 } |
3653 | 3653 |
3654 | 3654 |
3655 HBasicBlock* HGraph::CreateBasicBlock() { | 3655 HBasicBlock* HGraph::CreateBasicBlock() { |
3656 HBasicBlock* result = new(zone()) HBasicBlock(this); | 3656 HBasicBlock* result = new(zone()) HBasicBlock(this); |
3657 blocks_.Add(result, zone()); | 3657 blocks_.Add(result, zone()); |
3658 return result; | 3658 return result; |
3659 } | 3659 } |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4401 } | 4401 } |
4402 } | 4402 } |
4403 | 4403 |
4404 | 4404 |
4405 bool HOptimizedGraphBuilder::BuildGraph() { | 4405 bool HOptimizedGraphBuilder::BuildGraph() { |
4406 if (IsSubclassConstructor(current_info()->literal()->kind())) { | 4406 if (IsSubclassConstructor(current_info()->literal()->kind())) { |
4407 Bailout(kSuperReference); | 4407 Bailout(kSuperReference); |
4408 return false; | 4408 return false; |
4409 } | 4409 } |
4410 | 4410 |
4411 int slots = current_info()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | |
4412 if (current_info()->scope()->is_script_scope() && slots > 0) { | |
4413 Bailout(kScriptContext); | |
4414 return false; | |
4415 } | |
4416 | |
4417 Scope* scope = current_info()->scope(); | 4411 Scope* scope = current_info()->scope(); |
4418 SetUpScope(scope); | 4412 SetUpScope(scope); |
4419 | 4413 |
4420 // Add an edge to the body entry. This is warty: the graph's start | 4414 // Add an edge to the body entry. This is warty: the graph's start |
4421 // environment will be used by the Lithium translation as the initial | 4415 // environment will be used by the Lithium translation as the initial |
4422 // environment on graph entry, but it has now been mutated by the | 4416 // environment on graph entry, but it has now been mutated by the |
4423 // Hydrogen translation of the instructions in the start block. This | 4417 // Hydrogen translation of the instructions in the start block. This |
4424 // environment uses values which have not been defined yet. These | 4418 // environment uses values which have not been defined yet. These |
4425 // Hydrogen instructions will then be replayed by the Lithium | 4419 // Hydrogen instructions will then be replayed by the Lithium |
4426 // translation, so they cannot have an environment effect. The edge to | 4420 // translation, so they cannot have an environment effect. The edge to |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4610 | 4604 |
4611 | 4605 |
4612 template <class Instruction> | 4606 template <class Instruction> |
4613 HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) { | 4607 HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) { |
4614 PushArgumentsFromEnvironment(call->argument_count()); | 4608 PushArgumentsFromEnvironment(call->argument_count()); |
4615 return call; | 4609 return call; |
4616 } | 4610 } |
4617 | 4611 |
4618 | 4612 |
4619 void HOptimizedGraphBuilder::SetUpScope(Scope* scope) { | 4613 void HOptimizedGraphBuilder::SetUpScope(Scope* scope) { |
| 4614 HEnvironment* prolog_env = environment(); |
| 4615 int parameter_count = environment()->parameter_count(); |
| 4616 ZoneList<HValue*> parameters(parameter_count, zone()); |
| 4617 for (int i = 0; i < parameter_count; ++i) { |
| 4618 HInstruction* parameter = Add<HParameter>(static_cast<unsigned>(i)); |
| 4619 parameters.Add(parameter, zone()); |
| 4620 environment()->Bind(i, parameter); |
| 4621 } |
| 4622 |
| 4623 HConstant* undefined_constant = graph()->GetConstantUndefined(); |
| 4624 // Initialize specials and locals to undefined. |
| 4625 for (int i = parameter_count + 1; i < environment()->length(); ++i) { |
| 4626 environment()->Bind(i, undefined_constant); |
| 4627 } |
| 4628 Add<HPrologue>(); |
| 4629 |
| 4630 HEnvironment* initial_env = environment()->CopyWithoutHistory(); |
| 4631 HBasicBlock* body_entry = CreateBasicBlock(initial_env); |
| 4632 GotoNoSimulate(body_entry); |
| 4633 set_current_block(body_entry); |
| 4634 |
| 4635 // Initialize context of prolog environment to undefined. |
| 4636 prolog_env->BindContext(undefined_constant); |
| 4637 |
4620 // First special is HContext. | 4638 // First special is HContext. |
4621 HInstruction* context = Add<HContext>(); | 4639 HInstruction* context = Add<HContext>(); |
4622 environment()->BindContext(context); | 4640 environment()->BindContext(context); |
4623 | 4641 |
4624 // Create an arguments object containing the initial parameters. Set the | 4642 // Create an arguments object containing the initial parameters. Set the |
4625 // initial values of parameters including "this" having parameter index 0. | 4643 // initial values of parameters including "this" having parameter index 0. |
4626 DCHECK_EQ(scope->num_parameters() + 1, environment()->parameter_count()); | 4644 DCHECK_EQ(scope->num_parameters() + 1, parameter_count); |
4627 HArgumentsObject* arguments_object = | 4645 HArgumentsObject* arguments_object = New<HArgumentsObject>(parameter_count); |
4628 New<HArgumentsObject>(environment()->parameter_count()); | 4646 for (int i = 0; i < parameter_count; ++i) { |
4629 for (int i = 0; i < environment()->parameter_count(); ++i) { | 4647 HValue* parameter = parameters.at(i); |
4630 HInstruction* parameter = Add<HParameter>(i); | |
4631 arguments_object->AddArgument(parameter, zone()); | 4648 arguments_object->AddArgument(parameter, zone()); |
4632 environment()->Bind(i, parameter); | |
4633 } | 4649 } |
| 4650 |
4634 AddInstruction(arguments_object); | 4651 AddInstruction(arguments_object); |
4635 graph()->SetArgumentsObject(arguments_object); | 4652 graph()->SetArgumentsObject(arguments_object); |
4636 | 4653 |
4637 HConstant* undefined_constant = graph()->GetConstantUndefined(); | |
4638 // Initialize specials and locals to undefined. | |
4639 for (int i = environment()->parameter_count() + 1; | |
4640 i < environment()->length(); | |
4641 ++i) { | |
4642 environment()->Bind(i, undefined_constant); | |
4643 } | |
4644 | |
4645 // Handle the arguments and arguments shadow variables specially (they do | 4654 // Handle the arguments and arguments shadow variables specially (they do |
4646 // not have declarations). | 4655 // not have declarations). |
4647 if (scope->arguments() != NULL) { | 4656 if (scope->arguments() != NULL) { |
4648 environment()->Bind(scope->arguments(), | 4657 environment()->Bind(scope->arguments(), graph()->GetArgumentsObject()); |
4649 graph()->GetArgumentsObject()); | |
4650 } | 4658 } |
4651 | 4659 |
4652 int rest_index; | 4660 int rest_index; |
4653 Variable* rest = scope->rest_parameter(&rest_index); | 4661 Variable* rest = scope->rest_parameter(&rest_index); |
4654 if (rest) { | 4662 if (rest) { |
4655 return Bailout(kRestParameter); | 4663 return Bailout(kRestParameter); |
4656 } | 4664 } |
4657 | 4665 |
4658 if (scope->this_function_var() != nullptr || | 4666 if (scope->this_function_var() != nullptr || |
4659 scope->new_target_var() != nullptr) { | 4667 scope->new_target_var() != nullptr) { |
4660 return Bailout(kSuperReference); | 4668 return Bailout(kSuperReference); |
4661 } | 4669 } |
| 4670 |
| 4671 // Trace the call. |
| 4672 if (FLAG_trace && top_info()->IsOptimizing()) { |
| 4673 Add<HCallRuntime>(Runtime::FunctionForId(Runtime::kTraceEnter), 0); |
| 4674 } |
4662 } | 4675 } |
4663 | 4676 |
4664 | 4677 |
4665 void HOptimizedGraphBuilder::VisitStatements(ZoneList<Statement*>* statements) { | 4678 void HOptimizedGraphBuilder::VisitStatements(ZoneList<Statement*>* statements) { |
4666 for (int i = 0; i < statements->length(); i++) { | 4679 for (int i = 0; i < statements->length(); i++) { |
4667 Statement* stmt = statements->at(i); | 4680 Statement* stmt = statements->at(i); |
4668 CHECK_ALIVE(Visit(stmt)); | 4681 CHECK_ALIVE(Visit(stmt)); |
4669 if (stmt->IsJump()) break; | 4682 if (stmt->IsJump()) break; |
4670 } | 4683 } |
4671 } | 4684 } |
(...skipping 8317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12989 } | 13002 } |
12990 | 13003 |
12991 | 13004 |
12992 void HEnvironment::Drop(int count) { | 13005 void HEnvironment::Drop(int count) { |
12993 for (int i = 0; i < count; ++i) { | 13006 for (int i = 0; i < count; ++i) { |
12994 Pop(); | 13007 Pop(); |
12995 } | 13008 } |
12996 } | 13009 } |
12997 | 13010 |
12998 | 13011 |
| 13012 void HEnvironment::Print() const { |
| 13013 OFStream os(stdout); |
| 13014 os << *this << "\n"; |
| 13015 } |
| 13016 |
| 13017 |
12999 HEnvironment* HEnvironment::Copy() const { | 13018 HEnvironment* HEnvironment::Copy() const { |
13000 return new(zone()) HEnvironment(this, zone()); | 13019 return new(zone()) HEnvironment(this, zone()); |
13001 } | 13020 } |
13002 | 13021 |
13003 | 13022 |
13004 HEnvironment* HEnvironment::CopyWithoutHistory() const { | 13023 HEnvironment* HEnvironment::CopyWithoutHistory() const { |
13005 HEnvironment* result = Copy(); | 13024 HEnvironment* result = Copy(); |
13006 result->ClearHistory(); | 13025 result->ClearHistory(); |
13007 return result; | 13026 return result; |
13008 } | 13027 } |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13435 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 13454 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
13436 } | 13455 } |
13437 | 13456 |
13438 #ifdef DEBUG | 13457 #ifdef DEBUG |
13439 graph_->Verify(false); // No full verify. | 13458 graph_->Verify(false); // No full verify. |
13440 #endif | 13459 #endif |
13441 } | 13460 } |
13442 | 13461 |
13443 } // namespace internal | 13462 } // namespace internal |
13444 } // namespace v8 | 13463 } // namespace v8 |
OLD | NEW |