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 2228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2239 loop_entry->PostProcessLoopHeader(statement); | 2239 loop_entry->PostProcessLoopHeader(statement); |
2240 if (break_block != NULL) { | 2240 if (break_block != NULL) { |
2241 if (loop_successor != NULL) loop_successor->Goto(break_block); | 2241 if (loop_successor != NULL) loop_successor->Goto(break_block); |
2242 break_block->SetJoinId(statement->ExitId()); | 2242 break_block->SetJoinId(statement->ExitId()); |
2243 return break_block; | 2243 return break_block; |
2244 } | 2244 } |
2245 return loop_successor; | 2245 return loop_successor; |
2246 } | 2246 } |
2247 | 2247 |
2248 | 2248 |
| 2249 // Build a new loop header block and set it as the current block. |
| 2250 HBasicBlock* HOptimizedGraphBuilder::BuildLoopEntry() { |
| 2251 HBasicBlock* loop_entry = CreateLoopHeaderBlock(); |
| 2252 current_block()->Goto(loop_entry); |
| 2253 set_current_block(loop_entry); |
| 2254 return loop_entry; |
| 2255 } |
| 2256 |
| 2257 |
| 2258 HBasicBlock* HOptimizedGraphBuilder::BuildLoopEntry( |
| 2259 IterationStatement* statement) { |
| 2260 HBasicBlock* loop_entry = osr()->HasOsrEntryAt(statement) |
| 2261 ? osr()->BuildOsrLoopEntry(statement) |
| 2262 : BuildLoopEntry(); |
| 2263 return loop_entry; |
| 2264 } |
| 2265 |
| 2266 |
2249 void HBasicBlock::FinishExit(HControlInstruction* instruction) { | 2267 void HBasicBlock::FinishExit(HControlInstruction* instruction) { |
2250 Finish(instruction); | 2268 Finish(instruction); |
2251 ClearEnvironment(); | 2269 ClearEnvironment(); |
2252 } | 2270 } |
2253 | 2271 |
2254 | 2272 |
2255 HGraph::HGraph(CompilationInfo* info) | 2273 HGraph::HGraph(CompilationInfo* info) |
2256 : isolate_(info->isolate()), | 2274 : isolate_(info->isolate()), |
2257 next_block_id_(0), | 2275 next_block_id_(0), |
2258 entry_block_(NULL), | 2276 entry_block_(NULL), |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3080 ASSERT(unoptimized_code->kind() == Code::FUNCTION); | 3098 ASSERT(unoptimized_code->kind() == Code::FUNCTION); |
3081 Handle<TypeFeedbackInfo> type_info( | 3099 Handle<TypeFeedbackInfo> type_info( |
3082 TypeFeedbackInfo::cast(unoptimized_code->type_feedback_info())); | 3100 TypeFeedbackInfo::cast(unoptimized_code->type_feedback_info())); |
3083 int checksum = type_info->own_type_change_checksum(); | 3101 int checksum = type_info->own_type_change_checksum(); |
3084 int composite_checksum = graph()->update_type_change_checksum(checksum); | 3102 int composite_checksum = graph()->update_type_change_checksum(checksum); |
3085 graph()->set_use_optimistic_licm( | 3103 graph()->set_use_optimistic_licm( |
3086 !type_info->matches_inlined_type_change_checksum(composite_checksum)); | 3104 !type_info->matches_inlined_type_change_checksum(composite_checksum)); |
3087 type_info->set_inlined_type_change_checksum(composite_checksum); | 3105 type_info->set_inlined_type_change_checksum(composite_checksum); |
3088 | 3106 |
3089 // Perform any necessary OSR-specific cleanups or changes to the graph. | 3107 // Perform any necessary OSR-specific cleanups or changes to the graph. |
3090 osr_->FinishGraph(); | 3108 osr()->FinishGraph(); |
3091 | 3109 |
3092 return true; | 3110 return true; |
3093 } | 3111 } |
3094 | 3112 |
3095 | 3113 |
3096 bool HGraph::Optimize(BailoutReason* bailout_reason) { | 3114 bool HGraph::Optimize(BailoutReason* bailout_reason) { |
3097 OrderBlocks(); | 3115 OrderBlocks(); |
3098 AssignDominators(); | 3116 AssignDominators(); |
3099 | 3117 |
3100 // We need to create a HConstant "zero" now so that GVN will fold every | 3118 // 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); | 3681 loop_entry->loop_information()->set_stack_check(stack_check); |
3664 CHECK_BAILOUT(Visit(stmt->body())); | 3682 CHECK_BAILOUT(Visit(stmt->body())); |
3665 } | 3683 } |
3666 | 3684 |
3667 | 3685 |
3668 void HOptimizedGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { | 3686 void HOptimizedGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { |
3669 ASSERT(!HasStackOverflow()); | 3687 ASSERT(!HasStackOverflow()); |
3670 ASSERT(current_block() != NULL); | 3688 ASSERT(current_block() != NULL); |
3671 ASSERT(current_block()->HasPredecessor()); | 3689 ASSERT(current_block()->HasPredecessor()); |
3672 ASSERT(current_block() != NULL); | 3690 ASSERT(current_block() != NULL); |
3673 HBasicBlock* loop_entry = osr_->BuildPossibleOsrLoopEntry(stmt); | 3691 HBasicBlock* loop_entry = BuildLoopEntry(stmt); |
3674 | 3692 |
3675 BreakAndContinueInfo break_info(stmt); | 3693 BreakAndContinueInfo break_info(stmt); |
3676 CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry, &break_info)); | 3694 CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry, &break_info)); |
3677 HBasicBlock* body_exit = | 3695 HBasicBlock* body_exit = |
3678 JoinContinue(stmt, current_block(), break_info.continue_block()); | 3696 JoinContinue(stmt, current_block(), break_info.continue_block()); |
3679 HBasicBlock* loop_successor = NULL; | 3697 HBasicBlock* loop_successor = NULL; |
3680 if (body_exit != NULL && !stmt->cond()->ToBooleanIsTrue()) { | 3698 if (body_exit != NULL && !stmt->cond()->ToBooleanIsTrue()) { |
3681 set_current_block(body_exit); | 3699 set_current_block(body_exit); |
3682 // The block for a true condition, the actual predecessor block of the | 3700 // The block for a true condition, the actual predecessor block of the |
3683 // back edge. | 3701 // back edge. |
(...skipping 18 matching lines...) Expand all Loading... |
3702 break_info.break_block()); | 3720 break_info.break_block()); |
3703 set_current_block(loop_exit); | 3721 set_current_block(loop_exit); |
3704 } | 3722 } |
3705 | 3723 |
3706 | 3724 |
3707 void HOptimizedGraphBuilder::VisitWhileStatement(WhileStatement* stmt) { | 3725 void HOptimizedGraphBuilder::VisitWhileStatement(WhileStatement* stmt) { |
3708 ASSERT(!HasStackOverflow()); | 3726 ASSERT(!HasStackOverflow()); |
3709 ASSERT(current_block() != NULL); | 3727 ASSERT(current_block() != NULL); |
3710 ASSERT(current_block()->HasPredecessor()); | 3728 ASSERT(current_block()->HasPredecessor()); |
3711 ASSERT(current_block() != NULL); | 3729 ASSERT(current_block() != NULL); |
3712 HBasicBlock* loop_entry = osr_->BuildPossibleOsrLoopEntry(stmt); | 3730 HBasicBlock* loop_entry = BuildLoopEntry(stmt); |
3713 | 3731 |
3714 // If the condition is constant true, do not generate a branch. | 3732 // If the condition is constant true, do not generate a branch. |
3715 HBasicBlock* loop_successor = NULL; | 3733 HBasicBlock* loop_successor = NULL; |
3716 if (!stmt->cond()->ToBooleanIsTrue()) { | 3734 if (!stmt->cond()->ToBooleanIsTrue()) { |
3717 HBasicBlock* body_entry = graph()->CreateBasicBlock(); | 3735 HBasicBlock* body_entry = graph()->CreateBasicBlock(); |
3718 loop_successor = graph()->CreateBasicBlock(); | 3736 loop_successor = graph()->CreateBasicBlock(); |
3719 CHECK_BAILOUT(VisitForControl(stmt->cond(), body_entry, loop_successor)); | 3737 CHECK_BAILOUT(VisitForControl(stmt->cond(), body_entry, loop_successor)); |
3720 if (body_entry->HasPredecessor()) { | 3738 if (body_entry->HasPredecessor()) { |
3721 body_entry->SetJoinId(stmt->BodyId()); | 3739 body_entry->SetJoinId(stmt->BodyId()); |
3722 set_current_block(body_entry); | 3740 set_current_block(body_entry); |
(...skipping 21 matching lines...) Expand all Loading... |
3744 | 3762 |
3745 | 3763 |
3746 void HOptimizedGraphBuilder::VisitForStatement(ForStatement* stmt) { | 3764 void HOptimizedGraphBuilder::VisitForStatement(ForStatement* stmt) { |
3747 ASSERT(!HasStackOverflow()); | 3765 ASSERT(!HasStackOverflow()); |
3748 ASSERT(current_block() != NULL); | 3766 ASSERT(current_block() != NULL); |
3749 ASSERT(current_block()->HasPredecessor()); | 3767 ASSERT(current_block()->HasPredecessor()); |
3750 if (stmt->init() != NULL) { | 3768 if (stmt->init() != NULL) { |
3751 CHECK_ALIVE(Visit(stmt->init())); | 3769 CHECK_ALIVE(Visit(stmt->init())); |
3752 } | 3770 } |
3753 ASSERT(current_block() != NULL); | 3771 ASSERT(current_block() != NULL); |
3754 HBasicBlock* loop_entry = osr_->BuildPossibleOsrLoopEntry(stmt); | 3772 HBasicBlock* loop_entry = BuildLoopEntry(stmt); |
3755 | 3773 |
3756 HBasicBlock* loop_successor = NULL; | 3774 HBasicBlock* loop_successor = NULL; |
3757 if (stmt->cond() != NULL) { | 3775 if (stmt->cond() != NULL) { |
3758 HBasicBlock* body_entry = graph()->CreateBasicBlock(); | 3776 HBasicBlock* body_entry = graph()->CreateBasicBlock(); |
3759 loop_successor = graph()->CreateBasicBlock(); | 3777 loop_successor = graph()->CreateBasicBlock(); |
3760 CHECK_BAILOUT(VisitForControl(stmt->cond(), body_entry, loop_successor)); | 3778 CHECK_BAILOUT(VisitForControl(stmt->cond(), body_entry, loop_successor)); |
3761 if (body_entry->HasPredecessor()) { | 3779 if (body_entry->HasPredecessor()) { |
3762 body_entry->SetJoinId(stmt->BodyId()); | 3780 body_entry->SetJoinId(stmt->BodyId()); |
3763 set_current_block(body_entry); | 3781 set_current_block(body_entry); |
3764 } | 3782 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3827 Push(map); | 3845 Push(map); |
3828 Push(array); | 3846 Push(array); |
3829 Push(enum_length); | 3847 Push(enum_length); |
3830 Push(start_index); | 3848 Push(start_index); |
3831 | 3849 |
3832 HInstruction* index_cache = Add<HForInCacheArray>( | 3850 HInstruction* index_cache = Add<HForInCacheArray>( |
3833 enumerable, map, DescriptorArray::kEnumCacheBridgeIndicesCacheIndex); | 3851 enumerable, map, DescriptorArray::kEnumCacheBridgeIndicesCacheIndex); |
3834 HForInCacheArray::cast(array)->set_index_cache( | 3852 HForInCacheArray::cast(array)->set_index_cache( |
3835 HForInCacheArray::cast(index_cache)); | 3853 HForInCacheArray::cast(index_cache)); |
3836 | 3854 |
3837 HBasicBlock* loop_entry = osr_->BuildPossibleOsrLoopEntry(stmt); | 3855 HBasicBlock* loop_entry = BuildLoopEntry(stmt); |
3838 | 3856 |
3839 HValue* index = environment()->ExpressionStackAt(0); | 3857 HValue* index = environment()->ExpressionStackAt(0); |
3840 HValue* limit = environment()->ExpressionStackAt(1); | 3858 HValue* limit = environment()->ExpressionStackAt(1); |
3841 | 3859 |
3842 // Check that we still have more keys. | 3860 // Check that we still have more keys. |
3843 HCompareNumericAndBranch* compare_index = | 3861 HCompareNumericAndBranch* compare_index = |
3844 New<HCompareNumericAndBranch>(index, limit, Token::LT); | 3862 New<HCompareNumericAndBranch>(index, limit, Token::LT); |
3845 compare_index->set_observed_input_representation( | 3863 compare_index->set_observed_input_representation( |
3846 Representation::Smi(), Representation::Smi()); | 3864 Representation::Smi(), Representation::Smi()); |
3847 | 3865 |
(...skipping 5999 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 |