OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 3069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3080 ASSERT(unoptimized_code->kind() == Code::FUNCTION); | 3080 ASSERT(unoptimized_code->kind() == Code::FUNCTION); |
3081 Handle<TypeFeedbackInfo> type_info( | 3081 Handle<TypeFeedbackInfo> type_info( |
3082 TypeFeedbackInfo::cast(unoptimized_code->type_feedback_info())); | 3082 TypeFeedbackInfo::cast(unoptimized_code->type_feedback_info())); |
3083 int checksum = type_info->own_type_change_checksum(); | 3083 int checksum = type_info->own_type_change_checksum(); |
3084 int composite_checksum = graph()->update_type_change_checksum(checksum); | 3084 int composite_checksum = graph()->update_type_change_checksum(checksum); |
3085 graph()->set_use_optimistic_licm( | 3085 graph()->set_use_optimistic_licm( |
3086 !type_info->matches_inlined_type_change_checksum(composite_checksum)); | 3086 !type_info->matches_inlined_type_change_checksum(composite_checksum)); |
3087 type_info->set_inlined_type_change_checksum(composite_checksum); | 3087 type_info->set_inlined_type_change_checksum(composite_checksum); |
3088 | 3088 |
3089 // Perform any necessary OSR-specific cleanups or changes to the graph. | 3089 // Perform any necessary OSR-specific cleanups or changes to the graph. |
3090 osr_->FinishGraph(); | 3090 osr()->FinishGraph(); |
3091 | 3091 |
3092 return true; | 3092 return true; |
3093 } | 3093 } |
3094 | 3094 |
3095 | 3095 |
3096 bool HGraph::Optimize(BailoutReason* bailout_reason) { | 3096 bool HGraph::Optimize(BailoutReason* bailout_reason) { |
3097 OrderBlocks(); | 3097 OrderBlocks(); |
3098 AssignDominators(); | 3098 AssignDominators(); |
3099 | 3099 |
3100 // We need to create a HConstant "zero" now so that GVN will fold every | 3100 // We need to create a HConstant "zero" now so that GVN will fold every |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3663 loop_entry->loop_information()->set_stack_check(stack_check); | 3663 loop_entry->loop_information()->set_stack_check(stack_check); |
3664 CHECK_BAILOUT(Visit(stmt->body())); | 3664 CHECK_BAILOUT(Visit(stmt->body())); |
3665 } | 3665 } |
3666 | 3666 |
3667 | 3667 |
3668 void HOptimizedGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { | 3668 void HOptimizedGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { |
3669 ASSERT(!HasStackOverflow()); | 3669 ASSERT(!HasStackOverflow()); |
3670 ASSERT(current_block() != NULL); | 3670 ASSERT(current_block() != NULL); |
3671 ASSERT(current_block()->HasPredecessor()); | 3671 ASSERT(current_block()->HasPredecessor()); |
3672 ASSERT(current_block() != NULL); | 3672 ASSERT(current_block() != NULL); |
3673 HBasicBlock* loop_entry = osr_->BuildPossibleOsrLoopEntry(stmt); | 3673 HBasicBlock* loop_entry = BuildLoopEntry(stmt); |
3674 | 3674 |
3675 BreakAndContinueInfo break_info(stmt); | 3675 BreakAndContinueInfo break_info(stmt); |
3676 CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry, &break_info)); | 3676 CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry, &break_info)); |
3677 HBasicBlock* body_exit = | 3677 HBasicBlock* body_exit = |
3678 JoinContinue(stmt, current_block(), break_info.continue_block()); | 3678 JoinContinue(stmt, current_block(), break_info.continue_block()); |
3679 HBasicBlock* loop_successor = NULL; | 3679 HBasicBlock* loop_successor = NULL; |
3680 if (body_exit != NULL && !stmt->cond()->ToBooleanIsTrue()) { | 3680 if (body_exit != NULL && !stmt->cond()->ToBooleanIsTrue()) { |
3681 set_current_block(body_exit); | 3681 set_current_block(body_exit); |
3682 // The block for a true condition, the actual predecessor block of the | 3682 // The block for a true condition, the actual predecessor block of the |
3683 // back edge. | 3683 // back edge. |
(...skipping 18 matching lines...) Expand all Loading... | |
3702 break_info.break_block()); | 3702 break_info.break_block()); |
3703 set_current_block(loop_exit); | 3703 set_current_block(loop_exit); |
3704 } | 3704 } |
3705 | 3705 |
3706 | 3706 |
3707 void HOptimizedGraphBuilder::VisitWhileStatement(WhileStatement* stmt) { | 3707 void HOptimizedGraphBuilder::VisitWhileStatement(WhileStatement* stmt) { |
3708 ASSERT(!HasStackOverflow()); | 3708 ASSERT(!HasStackOverflow()); |
3709 ASSERT(current_block() != NULL); | 3709 ASSERT(current_block() != NULL); |
3710 ASSERT(current_block()->HasPredecessor()); | 3710 ASSERT(current_block()->HasPredecessor()); |
3711 ASSERT(current_block() != NULL); | 3711 ASSERT(current_block() != NULL); |
3712 HBasicBlock* loop_entry = osr_->BuildPossibleOsrLoopEntry(stmt); | 3712 HBasicBlock* loop_entry = BuildLoopEntry(stmt); |
3713 | 3713 |
3714 // If the condition is constant true, do not generate a branch. | 3714 // If the condition is constant true, do not generate a branch. |
3715 HBasicBlock* loop_successor = NULL; | 3715 HBasicBlock* loop_successor = NULL; |
3716 if (!stmt->cond()->ToBooleanIsTrue()) { | 3716 if (!stmt->cond()->ToBooleanIsTrue()) { |
3717 HBasicBlock* body_entry = graph()->CreateBasicBlock(); | 3717 HBasicBlock* body_entry = graph()->CreateBasicBlock(); |
3718 loop_successor = graph()->CreateBasicBlock(); | 3718 loop_successor = graph()->CreateBasicBlock(); |
3719 CHECK_BAILOUT(VisitForControl(stmt->cond(), body_entry, loop_successor)); | 3719 CHECK_BAILOUT(VisitForControl(stmt->cond(), body_entry, loop_successor)); |
3720 if (body_entry->HasPredecessor()) { | 3720 if (body_entry->HasPredecessor()) { |
3721 body_entry->SetJoinId(stmt->BodyId()); | 3721 body_entry->SetJoinId(stmt->BodyId()); |
3722 set_current_block(body_entry); | 3722 set_current_block(body_entry); |
(...skipping 21 matching lines...) Expand all Loading... | |
3744 | 3744 |
3745 | 3745 |
3746 void HOptimizedGraphBuilder::VisitForStatement(ForStatement* stmt) { | 3746 void HOptimizedGraphBuilder::VisitForStatement(ForStatement* stmt) { |
3747 ASSERT(!HasStackOverflow()); | 3747 ASSERT(!HasStackOverflow()); |
3748 ASSERT(current_block() != NULL); | 3748 ASSERT(current_block() != NULL); |
3749 ASSERT(current_block()->HasPredecessor()); | 3749 ASSERT(current_block()->HasPredecessor()); |
3750 if (stmt->init() != NULL) { | 3750 if (stmt->init() != NULL) { |
3751 CHECK_ALIVE(Visit(stmt->init())); | 3751 CHECK_ALIVE(Visit(stmt->init())); |
3752 } | 3752 } |
3753 ASSERT(current_block() != NULL); | 3753 ASSERT(current_block() != NULL); |
3754 HBasicBlock* loop_entry = osr_->BuildPossibleOsrLoopEntry(stmt); | 3754 HBasicBlock* loop_entry = BuildLoopEntry(stmt); |
3755 | 3755 |
3756 HBasicBlock* loop_successor = NULL; | 3756 HBasicBlock* loop_successor = NULL; |
3757 if (stmt->cond() != NULL) { | 3757 if (stmt->cond() != NULL) { |
3758 HBasicBlock* body_entry = graph()->CreateBasicBlock(); | 3758 HBasicBlock* body_entry = graph()->CreateBasicBlock(); |
3759 loop_successor = graph()->CreateBasicBlock(); | 3759 loop_successor = graph()->CreateBasicBlock(); |
3760 CHECK_BAILOUT(VisitForControl(stmt->cond(), body_entry, loop_successor)); | 3760 CHECK_BAILOUT(VisitForControl(stmt->cond(), body_entry, loop_successor)); |
3761 if (body_entry->HasPredecessor()) { | 3761 if (body_entry->HasPredecessor()) { |
3762 body_entry->SetJoinId(stmt->BodyId()); | 3762 body_entry->SetJoinId(stmt->BodyId()); |
3763 set_current_block(body_entry); | 3763 set_current_block(body_entry); |
3764 } | 3764 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3827 Push(map); | 3827 Push(map); |
3828 Push(array); | 3828 Push(array); |
3829 Push(enum_length); | 3829 Push(enum_length); |
3830 Push(start_index); | 3830 Push(start_index); |
3831 | 3831 |
3832 HInstruction* index_cache = Add<HForInCacheArray>( | 3832 HInstruction* index_cache = Add<HForInCacheArray>( |
3833 enumerable, map, DescriptorArray::kEnumCacheBridgeIndicesCacheIndex); | 3833 enumerable, map, DescriptorArray::kEnumCacheBridgeIndicesCacheIndex); |
3834 HForInCacheArray::cast(array)->set_index_cache( | 3834 HForInCacheArray::cast(array)->set_index_cache( |
3835 HForInCacheArray::cast(index_cache)); | 3835 HForInCacheArray::cast(index_cache)); |
3836 | 3836 |
3837 HBasicBlock* loop_entry = osr_->BuildPossibleOsrLoopEntry(stmt); | 3837 HBasicBlock* loop_entry = BuildLoopEntry(stmt); |
3838 | 3838 |
3839 HValue* index = environment()->ExpressionStackAt(0); | 3839 HValue* index = environment()->ExpressionStackAt(0); |
3840 HValue* limit = environment()->ExpressionStackAt(1); | 3840 HValue* limit = environment()->ExpressionStackAt(1); |
3841 | 3841 |
3842 // Check that we still have more keys. | 3842 // Check that we still have more keys. |
3843 HCompareNumericAndBranch* compare_index = | 3843 HCompareNumericAndBranch* compare_index = |
3844 New<HCompareNumericAndBranch>(index, limit, Token::LT); | 3844 New<HCompareNumericAndBranch>(index, limit, Token::LT); |
3845 compare_index->set_observed_input_representation( | 3845 compare_index->set_observed_input_representation( |
3846 Representation::Smi(), Representation::Smi()); | 3846 Representation::Smi(), Representation::Smi()); |
3847 | 3847 |
(...skipping 4766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8614 for (int i = 0; i < globals_.length(); ++i) array->set(i, *globals_.at(i)); | 8614 for (int i = 0; i < globals_.length(); ++i) array->set(i, *globals_.at(i)); |
8615 int flags = DeclareGlobalsEvalFlag::encode(current_info()->is_eval()) | | 8615 int flags = DeclareGlobalsEvalFlag::encode(current_info()->is_eval()) | |
8616 DeclareGlobalsNativeFlag::encode(current_info()->is_native()) | | 8616 DeclareGlobalsNativeFlag::encode(current_info()->is_native()) | |
8617 DeclareGlobalsLanguageMode::encode(current_info()->language_mode()); | 8617 DeclareGlobalsLanguageMode::encode(current_info()->language_mode()); |
8618 Add<HDeclareGlobals>(array, flags); | 8618 Add<HDeclareGlobals>(array, flags); |
8619 globals_.Clear(); | 8619 globals_.Clear(); |
8620 } | 8620 } |
8621 } | 8621 } |
8622 | 8622 |
8623 | 8623 |
8624 // Build a new loop header block and set it as the current block. | |
8625 HBasicBlock *HOptimizedGraphBuilder::BuildLoopEntry() { | |
Michael Starzinger
2013/09/27 13:26:22
nit: Asterisk sticks to the left.
mvstanton
2013/09/27 13:31:43
Done.
| |
8626 HBasicBlock* loop_entry = CreateLoopHeaderBlock(); | |
8627 current_block()->Goto(loop_entry); | |
8628 set_current_block(loop_entry); | |
8629 return loop_entry; | |
8630 } | |
8631 | |
8632 | |
8633 HBasicBlock* HOptimizedGraphBuilder::BuildLoopEntry( | |
Michael Starzinger
2013/09/27 13:26:22
nit: See comment in hydrogen.h about placement of
mvstanton
2013/09/27 13:31:43
Done.
| |
8634 IterationStatement* statement) { | |
8635 HBasicBlock* loop_entry = osr()->HasOsrEntryAt(statement) | |
8636 ? osr()->BuildOsrLoopEntry(statement) | |
8637 : BuildLoopEntry(); | |
8638 return loop_entry; | |
8639 } | |
8640 | |
8641 | |
8624 void HOptimizedGraphBuilder::VisitVariableDeclaration( | 8642 void HOptimizedGraphBuilder::VisitVariableDeclaration( |
8625 VariableDeclaration* declaration) { | 8643 VariableDeclaration* declaration) { |
8626 VariableProxy* proxy = declaration->proxy(); | 8644 VariableProxy* proxy = declaration->proxy(); |
8627 VariableMode mode = declaration->mode(); | 8645 VariableMode mode = declaration->mode(); |
8628 Variable* variable = proxy->var(); | 8646 Variable* variable = proxy->var(); |
8629 bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET; | 8647 bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET; |
8630 switch (variable->location()) { | 8648 switch (variable->location()) { |
8631 case Variable::UNALLOCATED: | 8649 case Variable::UNALLOCATED: |
8632 globals_.Add(variable->name(), zone()); | 8650 globals_.Add(variable->name(), zone()); |
8633 globals_.Add(variable->binding_needs_init() | 8651 globals_.Add(variable->binding_needs_init() |
(...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9847 if (ShouldProduceTraceOutput()) { | 9865 if (ShouldProduceTraceOutput()) { |
9848 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 9866 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
9849 } | 9867 } |
9850 | 9868 |
9851 #ifdef DEBUG | 9869 #ifdef DEBUG |
9852 graph_->Verify(false); // No full verify. | 9870 graph_->Verify(false); // No full verify. |
9853 #endif | 9871 #endif |
9854 } | 9872 } |
9855 | 9873 |
9856 } } // namespace v8::internal | 9874 } } // namespace v8::internal |
OLD | NEW |