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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 } | 634 } |
635 | 635 |
636 | 636 |
637 HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder, BailoutId id) | 637 HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder, BailoutId id) |
638 : builder_(builder), | 638 : builder_(builder), |
639 finished_(false), | 639 finished_(false), |
640 id_(id) { | 640 id_(id) { |
641 HEnvironment* env = builder->environment(); | 641 HEnvironment* env = builder->environment(); |
642 HEnvironment* true_env = env->Copy(); | 642 HEnvironment* true_env = env->Copy(); |
643 HEnvironment* false_env = env->Copy(); | 643 HEnvironment* false_env = env->Copy(); |
644 HEnvironment* merge_env = env->Copy(); | 644 first_true_block_ = builder->CreateBasicBlock(true_env); |
645 true_block_ = builder->CreateBasicBlock(true_env); | 645 last_true_block_ = NULL; |
646 false_block_ = builder->CreateBasicBlock(false_env); | 646 first_false_block_ = builder->CreateBasicBlock(false_env); |
647 merge_block_ = builder->CreateBasicBlock(merge_env); | |
648 } | 647 } |
649 | 648 |
650 | 649 |
651 void HGraphBuilder::IfBuilder::BeginTrue(HValue* left, | 650 HInstruction* HGraphBuilder::IfBuilder::BeginTrue( |
652 HValue* right, | 651 HValue* left, |
653 Token::Value token) { | 652 HValue* right, |
| 653 Token::Value token, |
| 654 Representation input_representation) { |
654 HCompareIDAndBranch* compare = | 655 HCompareIDAndBranch* compare = |
655 new(zone()) HCompareIDAndBranch(left, right, token); | 656 new(zone()) HCompareIDAndBranch(left, right, token); |
656 compare->ChangeRepresentation(Representation::Integer32()); | 657 compare->set_observed_input_representation(input_representation, |
657 compare->SetSuccessorAt(0, true_block_); | 658 input_representation); |
658 compare->SetSuccessorAt(1, false_block_); | 659 compare->ChangeRepresentation(input_representation); |
| 660 compare->SetSuccessorAt(0, first_true_block_); |
| 661 compare->SetSuccessorAt(1, first_false_block_); |
659 builder_->current_block()->Finish(compare); | 662 builder_->current_block()->Finish(compare); |
660 builder_->set_current_block(true_block_); | 663 builder_->set_current_block(first_true_block_); |
| 664 return compare; |
661 } | 665 } |
662 | 666 |
663 | 667 |
664 void HGraphBuilder::IfBuilder::BeginFalse() { | 668 void HGraphBuilder::IfBuilder::BeginFalse() { |
665 builder_->current_block()->Goto(merge_block_); | 669 last_true_block_ = builder_->current_block(); |
666 builder_->set_current_block(false_block_); | 670 ASSERT(!last_true_block_->IsFinished()); |
| 671 builder_->set_current_block(first_false_block_); |
667 } | 672 } |
668 | 673 |
669 | 674 |
670 void HGraphBuilder::IfBuilder::End() { | 675 void HGraphBuilder::IfBuilder::End() { |
671 ASSERT(!finished_); | 676 ASSERT(!finished_); |
672 builder_->current_block()->Goto(merge_block_); | 677 ASSERT(!last_true_block_->IsFinished()); |
| 678 HBasicBlock* last_false_block = builder_->current_block(); |
| 679 ASSERT(!last_false_block->IsFinished()); |
| 680 HEnvironment* merge_env = |
| 681 last_true_block_->last_environment()->Copy(); |
| 682 merge_block_ = builder_->CreateBasicBlock(merge_env); |
| 683 last_true_block_->Goto(merge_block_); |
| 684 last_false_block->Goto(merge_block_); |
| 685 merge_block_->SetJoinId(id_); |
673 builder_->set_current_block(merge_block_); | 686 builder_->set_current_block(merge_block_); |
674 merge_block_->SetJoinId(id_); | |
675 finished_ = true; | 687 finished_ = true; |
676 } | 688 } |
677 | 689 |
678 | 690 |
679 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder, | 691 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder, |
680 HValue* context, | 692 HValue* context, |
681 LoopBuilder::Direction direction, | 693 LoopBuilder::Direction direction, |
682 BailoutId id) | 694 BailoutId id) |
683 : builder_(builder), | 695 : builder_(builder), |
684 context_(context), | 696 context_(context), |
685 direction_(direction), | 697 direction_(direction), |
686 id_(id), | 698 id_(id), |
687 finished_(false) { | 699 finished_(false) { |
688 HEnvironment* env = builder_->environment(); | |
689 HEnvironment* body_env = env->Copy(); | |
690 HEnvironment* exit_env = env->Copy(); | |
691 header_block_ = builder->CreateLoopHeaderBlock(); | 700 header_block_ = builder->CreateLoopHeaderBlock(); |
692 body_block_ = builder->CreateBasicBlock(body_env); | 701 body_block_ = NULL; |
693 exit_block_ = builder->CreateBasicBlock(exit_env); | 702 exit_block_ = NULL; |
694 } | 703 } |
695 | 704 |
696 | 705 |
697 HValue* HGraphBuilder::LoopBuilder::BeginBody(HValue* initial, | 706 HValue* HGraphBuilder::LoopBuilder::BeginBody( |
698 HValue* terminating, | 707 HValue* initial, |
699 Token::Value token) { | 708 HValue* terminating, |
700 phi_ = new(zone()) HPhi(0, zone()); | 709 Token::Value token, |
| 710 Representation input_representation) { |
| 711 HEnvironment* env = builder_->environment(); |
| 712 phi_ = new(zone()) HPhi(env->values()->length(), zone()); |
701 header_block_->AddPhi(phi_); | 713 header_block_->AddPhi(phi_); |
702 phi_->AddInput(initial); | 714 phi_->AddInput(initial); |
703 phi_->ChangeRepresentation(Representation::Integer32()); | 715 phi_->ChangeRepresentation(Representation::Integer32()); |
704 HEnvironment* env = builder_->environment(); | |
705 env->Push(initial); | 716 env->Push(initial); |
706 builder_->current_block()->Goto(header_block_); | 717 builder_->current_block()->Goto(header_block_); |
707 builder_->set_current_block(header_block_); | 718 |
| 719 HEnvironment* body_env = env->Copy(); |
| 720 HEnvironment* exit_env = env->Copy(); |
| 721 body_block_ = builder_->CreateBasicBlock(body_env); |
| 722 exit_block_ = builder_->CreateBasicBlock(exit_env); |
| 723 // Remove the phi from the expression stack |
| 724 body_env->Pop(); |
708 | 725 |
709 builder_->set_current_block(header_block_); | 726 builder_->set_current_block(header_block_); |
710 HCompareIDAndBranch* compare = | 727 HCompareIDAndBranch* compare = |
711 new(zone()) HCompareIDAndBranch(phi_, terminating, token); | 728 new(zone()) HCompareIDAndBranch(phi_, terminating, token); |
712 compare->ChangeRepresentation(Representation::Integer32()); | 729 compare->set_observed_input_representation(input_representation, |
| 730 input_representation); |
| 731 compare->ChangeRepresentation(input_representation); |
713 compare->SetSuccessorAt(0, body_block_); | 732 compare->SetSuccessorAt(0, body_block_); |
714 compare->SetSuccessorAt(1, exit_block_); | 733 compare->SetSuccessorAt(1, exit_block_); |
715 builder_->current_block()->Finish(compare); | 734 builder_->current_block()->Finish(compare); |
716 | 735 |
717 builder_->set_current_block(body_block_); | 736 builder_->set_current_block(body_block_); |
718 if (direction_ == kPreIncrement || direction_ == kPreDecrement) { | 737 if (direction_ == kPreIncrement || direction_ == kPreDecrement) { |
719 HValue* one = builder_->graph()->GetConstant1(); | 738 HValue* one = builder_->graph()->GetConstant1(); |
720 if (direction_ == kPreIncrement) { | 739 if (direction_ == kPreIncrement) { |
721 increment_ = HAdd::New(zone(), context_, phi_, one); | 740 increment_ = HAdd::New(zone(), context_, phi_, one); |
722 } else { | 741 } else { |
(...skipping 17 matching lines...) Expand all Loading... |
740 if (direction_ == kPostIncrement) { | 759 if (direction_ == kPostIncrement) { |
741 increment_ = HAdd::New(zone(), context_, phi_, one); | 760 increment_ = HAdd::New(zone(), context_, phi_, one); |
742 } else { | 761 } else { |
743 increment_ = HSub::New(zone(), context_, phi_, one); | 762 increment_ = HSub::New(zone(), context_, phi_, one); |
744 } | 763 } |
745 increment_->ClearFlag(HValue::kCanOverflow); | 764 increment_->ClearFlag(HValue::kCanOverflow); |
746 increment_->ChangeRepresentation(Representation::Integer32()); | 765 increment_->ChangeRepresentation(Representation::Integer32()); |
747 builder_->AddInstruction(increment_); | 766 builder_->AddInstruction(increment_); |
748 } | 767 } |
749 | 768 |
| 769 // Push the new increment value on the expression stack to merge into the phi. |
750 builder_->environment()->Push(increment_); | 770 builder_->environment()->Push(increment_); |
751 builder_->current_block()->Goto(header_block_); | 771 builder_->current_block()->Goto(header_block_); |
752 header_block_->loop_information()->RegisterBackEdge(body_block_); | 772 header_block_->loop_information()->RegisterBackEdge(body_block_); |
753 header_block_->SetJoinId(BailoutId::StubEntry()); | 773 header_block_->SetJoinId(id_); |
| 774 |
754 builder_->set_current_block(exit_block_); | 775 builder_->set_current_block(exit_block_); |
| 776 // Pop the phi from the expression stack |
| 777 builder_->environment()->Pop(); |
755 finished_ = true; | 778 finished_ = true; |
756 } | 779 } |
757 | 780 |
758 | 781 |
759 HGraph* HGraphBuilder::CreateGraph() { | 782 HGraph* HGraphBuilder::CreateGraph() { |
760 graph_ = new(zone()) HGraph(info_); | 783 graph_ = new(zone()) HGraph(info_); |
761 if (FLAG_hydrogen_stats) HStatistics::Instance()->Initialize(info_); | 784 if (FLAG_hydrogen_stats) HStatistics::Instance()->Initialize(info_); |
762 HPhase phase("H_Block building"); | 785 HPhase phase("H_Block building"); |
763 set_current_block(graph()->entry_block()); | 786 set_current_block(graph()->entry_block()); |
764 if (!BuildGraph()) return NULL; | 787 if (!BuildGraph()) return NULL; |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 values_(16, info->zone()), | 1166 values_(16, info->zone()), |
1144 phi_list_(NULL), | 1167 phi_list_(NULL), |
1145 uint32_instructions_(NULL), | 1168 uint32_instructions_(NULL), |
1146 info_(info), | 1169 info_(info), |
1147 zone_(info->zone()), | 1170 zone_(info->zone()), |
1148 is_recursive_(false), | 1171 is_recursive_(false), |
1149 use_optimistic_licm_(false), | 1172 use_optimistic_licm_(false), |
1150 has_soft_deoptimize_(false), | 1173 has_soft_deoptimize_(false), |
1151 type_change_checksum_(0) { | 1174 type_change_checksum_(0) { |
1152 if (info->IsStub()) { | 1175 if (info->IsStub()) { |
| 1176 HydrogenCodeStub* stub = info->code_stub(); |
| 1177 int param_count = |
| 1178 stub->GetInterfaceDescriptor(isolate_)->register_param_count_; |
1153 start_environment_ = | 1179 start_environment_ = |
1154 new(zone_) HEnvironment(zone_); | 1180 new(zone_) HEnvironment(zone_, param_count); |
1155 } else { | 1181 } else { |
1156 start_environment_ = | 1182 start_environment_ = |
1157 new(zone_) HEnvironment(NULL, info->scope(), info->closure(), zone_); | 1183 new(zone_) HEnvironment(NULL, info->scope(), info->closure(), zone_); |
1158 } | 1184 } |
1159 start_environment_->set_ast_id(BailoutId::FunctionEntry()); | 1185 start_environment_->set_ast_id(BailoutId::FunctionEntry()); |
1160 entry_block_ = CreateBasicBlock(); | 1186 entry_block_ = CreateBasicBlock(); |
1161 entry_block_->SetInitialEnvironment(start_environment_); | 1187 entry_block_->SetInitialEnvironment(start_environment_); |
1162 } | 1188 } |
1163 | 1189 |
1164 | 1190 |
(...skipping 8926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10091 outer_(outer), | 10117 outer_(outer), |
10092 entry_(NULL), | 10118 entry_(NULL), |
10093 pop_count_(0), | 10119 pop_count_(0), |
10094 push_count_(0), | 10120 push_count_(0), |
10095 ast_id_(BailoutId::None()), | 10121 ast_id_(BailoutId::None()), |
10096 zone_(zone) { | 10122 zone_(zone) { |
10097 Initialize(scope->num_parameters() + 1, scope->num_stack_slots(), 0); | 10123 Initialize(scope->num_parameters() + 1, scope->num_stack_slots(), 0); |
10098 } | 10124 } |
10099 | 10125 |
10100 | 10126 |
10101 HEnvironment::HEnvironment(Zone* zone) | 10127 HEnvironment::HEnvironment(Zone* zone, int parameter_count) |
10102 : values_(0, zone), | 10128 : values_(0, zone), |
10103 frame_type_(STUB), | 10129 frame_type_(STUB), |
10104 parameter_count_(0), | 10130 parameter_count_(parameter_count), |
10105 specials_count_(0), | 10131 specials_count_(1), |
10106 local_count_(0), | 10132 local_count_(0), |
10107 outer_(NULL), | 10133 outer_(NULL), |
10108 entry_(NULL), | 10134 entry_(NULL), |
10109 pop_count_(0), | 10135 pop_count_(0), |
10110 push_count_(0), | 10136 push_count_(0), |
10111 ast_id_(BailoutId::None()), | 10137 ast_id_(BailoutId::None()), |
10112 zone_(zone) { | 10138 zone_(zone) { |
10113 Initialize(0, 0, 0); | 10139 Initialize(parameter_count, 0, 0); |
10114 } | 10140 } |
10115 | 10141 |
10116 | 10142 |
10117 HEnvironment::HEnvironment(const HEnvironment* other, Zone* zone) | 10143 HEnvironment::HEnvironment(const HEnvironment* other, Zone* zone) |
10118 : values_(0, zone), | 10144 : values_(0, zone), |
10119 frame_type_(JS_FUNCTION), | 10145 frame_type_(JS_FUNCTION), |
10120 parameter_count_(0), | 10146 parameter_count_(0), |
10121 specials_count_(0), | 10147 specials_count_(0), |
10122 local_count_(0), | 10148 local_count_(0), |
10123 outer_(NULL), | 10149 outer_(NULL), |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10712 } | 10738 } |
10713 } | 10739 } |
10714 | 10740 |
10715 #ifdef DEBUG | 10741 #ifdef DEBUG |
10716 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 10742 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
10717 if (allocator_ != NULL) allocator_->Verify(); | 10743 if (allocator_ != NULL) allocator_->Verify(); |
10718 #endif | 10744 #endif |
10719 } | 10745 } |
10720 | 10746 |
10721 } } // namespace v8::internal | 10747 } } // namespace v8::internal |
OLD | NEW |