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 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 HBasicBlock* split_edge = | 745 HBasicBlock* split_edge = |
746 builder_->CreateBasicBlock(env->Copy()); | 746 builder_->CreateBasicBlock(env->Copy()); |
747 if (did_or_) { | 747 if (did_or_) { |
748 compare->SetSuccessorAt(0, split_edge); | 748 compare->SetSuccessorAt(0, split_edge); |
749 compare->SetSuccessorAt(1, first_false_block_); | 749 compare->SetSuccessorAt(1, first_false_block_); |
750 } else { | 750 } else { |
751 compare->SetSuccessorAt(0, first_true_block_); | 751 compare->SetSuccessorAt(0, first_true_block_); |
752 compare->SetSuccessorAt(1, split_edge); | 752 compare->SetSuccessorAt(1, split_edge); |
753 } | 753 } |
754 split_edge->GotoNoSimulate(split_edge_merge_block_); | 754 split_edge->GotoNoSimulate(split_edge_merge_block_); |
755 ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope()); | |
756 } else { | 755 } else { |
757 compare->SetSuccessorAt(0, first_true_block_); | 756 compare->SetSuccessorAt(0, first_true_block_); |
758 compare->SetSuccessorAt(1, first_false_block_); | 757 compare->SetSuccessorAt(1, first_false_block_); |
759 } | 758 } |
760 builder_->current_block()->Finish(compare); | 759 builder_->current_block()->Finish(compare); |
761 needs_compare_ = false; | 760 needs_compare_ = false; |
762 } | 761 } |
763 | 762 |
764 | 763 |
765 void HGraphBuilder::IfBuilder::Or() { | 764 void HGraphBuilder::IfBuilder::Or() { |
766 ASSERT(!did_and_); | 765 ASSERT(!did_and_); |
767 did_or_ = true; | 766 did_or_ = true; |
768 HEnvironment* env = first_false_block_->last_environment(); | 767 HEnvironment* env = first_false_block_->last_environment(); |
769 if (split_edge_merge_block_ == NULL) { | 768 if (split_edge_merge_block_ == NULL) { |
770 split_edge_merge_block_ = | 769 split_edge_merge_block_ = |
771 builder_->CreateBasicBlock(env->Copy()); | 770 builder_->CreateBasicBlock(env->Copy()); |
772 first_true_block_->GotoNoSimulate(split_edge_merge_block_); | 771 first_true_block_->GotoNoSimulate(split_edge_merge_block_); |
773 ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope()); | |
774 first_true_block_ = split_edge_merge_block_; | 772 first_true_block_ = split_edge_merge_block_; |
775 } | 773 } |
776 builder_->set_current_block(first_false_block_); | 774 builder_->set_current_block(first_false_block_); |
777 first_false_block_ = builder_->CreateBasicBlock(env->Copy()); | 775 first_false_block_ = builder_->CreateBasicBlock(env->Copy()); |
778 } | 776 } |
779 | 777 |
780 | 778 |
781 void HGraphBuilder::IfBuilder::And() { | 779 void HGraphBuilder::IfBuilder::And() { |
782 ASSERT(!did_or_); | 780 ASSERT(!did_or_); |
783 did_and_ = true; | 781 did_and_ = true; |
784 HEnvironment* env = first_false_block_->last_environment(); | 782 HEnvironment* env = first_false_block_->last_environment(); |
785 if (split_edge_merge_block_ == NULL) { | 783 if (split_edge_merge_block_ == NULL) { |
786 split_edge_merge_block_ = builder_->CreateBasicBlock(env->Copy()); | 784 split_edge_merge_block_ = builder_->CreateBasicBlock(env->Copy()); |
787 first_false_block_->GotoNoSimulate(split_edge_merge_block_); | 785 first_false_block_->GotoNoSimulate(split_edge_merge_block_); |
788 ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope()); | |
789 first_false_block_ = split_edge_merge_block_; | 786 first_false_block_ = split_edge_merge_block_; |
790 } | 787 } |
791 builder_->set_current_block(first_true_block_); | 788 builder_->set_current_block(first_true_block_); |
792 first_true_block_ = builder_->CreateBasicBlock(env->Copy()); | 789 first_true_block_ = builder_->CreateBasicBlock(env->Copy()); |
793 } | 790 } |
794 | 791 |
795 | 792 |
796 void HGraphBuilder::IfBuilder::CaptureContinuation( | 793 void HGraphBuilder::IfBuilder::CaptureContinuation( |
797 HIfContinuation* continuation) { | 794 HIfContinuation* continuation) { |
798 ASSERT(!finished_); | 795 ASSERT(!finished_); |
(...skipping 11 matching lines...) Expand all Loading... |
810 | 807 |
811 | 808 |
812 void HGraphBuilder::IfBuilder::Then() { | 809 void HGraphBuilder::IfBuilder::Then() { |
813 ASSERT(!captured_); | 810 ASSERT(!captured_); |
814 ASSERT(!finished_); | 811 ASSERT(!finished_); |
815 did_then_ = true; | 812 did_then_ = true; |
816 if (needs_compare_) { | 813 if (needs_compare_) { |
817 // Handle if's without any expressions, they jump directly to the "else" | 814 // Handle if's without any expressions, they jump directly to the "else" |
818 // branch. | 815 // branch. |
819 builder_->current_block()->GotoNoSimulate(first_false_block_); | 816 builder_->current_block()->GotoNoSimulate(first_false_block_); |
820 ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope()); | |
821 first_true_block_ = NULL; | 817 first_true_block_ = NULL; |
822 } | 818 } |
823 builder_->set_current_block(first_true_block_); | 819 builder_->set_current_block(first_true_block_); |
824 } | 820 } |
825 | 821 |
826 | 822 |
827 void HGraphBuilder::IfBuilder::Else() { | 823 void HGraphBuilder::IfBuilder::Else() { |
828 ASSERT(did_then_); | 824 ASSERT(did_then_); |
829 ASSERT(!captured_); | 825 ASSERT(!captured_); |
830 ASSERT(!finished_); | 826 ASSERT(!finished_); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 } else { | 869 } else { |
874 HEnvironment* merge_env = last_true_block_->last_environment()->Copy(); | 870 HEnvironment* merge_env = last_true_block_->last_environment()->Copy(); |
875 merge_block_ = builder_->CreateBasicBlock(merge_env); | 871 merge_block_ = builder_->CreateBasicBlock(merge_env); |
876 ASSERT(!finished_); | 872 ASSERT(!finished_); |
877 if (!did_else_) Else(); | 873 if (!did_else_) Else(); |
878 ASSERT(!last_true_block_->IsFinished()); | 874 ASSERT(!last_true_block_->IsFinished()); |
879 HBasicBlock* last_false_block = builder_->current_block(); | 875 HBasicBlock* last_false_block = builder_->current_block(); |
880 ASSERT(!last_false_block->IsFinished()); | 876 ASSERT(!last_false_block->IsFinished()); |
881 last_true_block_->GotoNoSimulate(merge_block_); | 877 last_true_block_->GotoNoSimulate(merge_block_); |
882 last_false_block->GotoNoSimulate(merge_block_); | 878 last_false_block->GotoNoSimulate(merge_block_); |
883 ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope()); | |
884 builder_->set_current_block(merge_block_); | 879 builder_->set_current_block(merge_block_); |
885 } | 880 } |
886 } | 881 } |
887 finished_ = true; | 882 finished_ = true; |
888 } | 883 } |
889 | 884 |
890 | 885 |
891 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder, | 886 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder, |
892 HValue* context, | 887 HValue* context, |
893 LoopBuilder::Direction direction) | 888 LoopBuilder::Direction direction) |
(...skipping 12 matching lines...) Expand all Loading... |
906 HValue* terminating, | 901 HValue* terminating, |
907 Token::Value token, | 902 Token::Value token, |
908 Representation input_representation) { | 903 Representation input_representation) { |
909 HEnvironment* env = builder_->environment(); | 904 HEnvironment* env = builder_->environment(); |
910 phi_ = new(zone()) HPhi(env->values()->length(), zone()); | 905 phi_ = new(zone()) HPhi(env->values()->length(), zone()); |
911 header_block_->AddPhi(phi_); | 906 header_block_->AddPhi(phi_); |
912 phi_->AddInput(initial); | 907 phi_->AddInput(initial); |
913 phi_->AssumeRepresentation(Representation::Integer32()); | 908 phi_->AssumeRepresentation(Representation::Integer32()); |
914 env->Push(initial); | 909 env->Push(initial); |
915 builder_->current_block()->GotoNoSimulate(header_block_); | 910 builder_->current_block()->GotoNoSimulate(header_block_); |
916 ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope()); | |
917 | 911 |
918 HEnvironment* body_env = env->Copy(); | 912 HEnvironment* body_env = env->Copy(); |
919 HEnvironment* exit_env = env->Copy(); | 913 HEnvironment* exit_env = env->Copy(); |
920 body_block_ = builder_->CreateBasicBlock(body_env); | 914 body_block_ = builder_->CreateBasicBlock(body_env); |
921 exit_block_ = builder_->CreateBasicBlock(exit_env); | 915 exit_block_ = builder_->CreateBasicBlock(exit_env); |
922 // Remove the phi from the expression stack | 916 // Remove the phi from the expression stack |
923 body_env->Pop(); | 917 body_env->Pop(); |
924 | 918 |
925 builder_->set_current_block(header_block_); | 919 builder_->set_current_block(header_block_); |
926 HCompareIDAndBranch* compare = | 920 HCompareIDAndBranch* compare = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 increment_ = HSub::New(zone(), context_, phi_, one); | 955 increment_ = HSub::New(zone(), context_, phi_, one); |
962 } | 956 } |
963 increment_->ClearFlag(HValue::kCanOverflow); | 957 increment_->ClearFlag(HValue::kCanOverflow); |
964 increment_->AssumeRepresentation(Representation::Integer32()); | 958 increment_->AssumeRepresentation(Representation::Integer32()); |
965 builder_->AddInstruction(increment_); | 959 builder_->AddInstruction(increment_); |
966 } | 960 } |
967 | 961 |
968 // Push the new increment value on the expression stack to merge into the phi. | 962 // Push the new increment value on the expression stack to merge into the phi. |
969 builder_->environment()->Push(increment_); | 963 builder_->environment()->Push(increment_); |
970 builder_->current_block()->GotoNoSimulate(header_block_); | 964 builder_->current_block()->GotoNoSimulate(header_block_); |
971 ASSERT(builder_->SafeToAddPhiInNoSideEffectsScope()); | |
972 header_block_->loop_information()->RegisterBackEdge(body_block_); | 965 header_block_->loop_information()->RegisterBackEdge(body_block_); |
973 | 966 |
974 builder_->set_current_block(exit_block_); | 967 builder_->set_current_block(exit_block_); |
975 // Pop the phi from the expression stack | 968 // Pop the phi from the expression stack |
976 builder_->environment()->Pop(); | 969 builder_->environment()->Pop(); |
977 finished_ = true; | 970 finished_ = true; |
978 } | 971 } |
979 | 972 |
980 | 973 |
981 HGraph* HGraphBuilder::CreateGraph() { | 974 HGraph* HGraphBuilder::CreateGraph() { |
(...skipping 7246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8228 Push(access); | 8221 Push(access); |
8229 } | 8222 } |
8230 | 8223 |
8231 *has_side_effects |= access->HasObservableSideEffects(); | 8224 *has_side_effects |= access->HasObservableSideEffects(); |
8232 // The caller will use has_side_effects and add correct Simulate. | 8225 // The caller will use has_side_effects and add correct Simulate. |
8233 access->SetFlag(HValue::kHasNoObservableSideEffects); | 8226 access->SetFlag(HValue::kHasNoObservableSideEffects); |
8234 if (position != -1) { | 8227 if (position != -1) { |
8235 access->set_position(position); | 8228 access->set_position(position); |
8236 } | 8229 } |
8237 if_jsarray->GotoNoSimulate(join); | 8230 if_jsarray->GotoNoSimulate(join); |
8238 ASSERT(SafeToAddPhiInNoSideEffectsScope()); | |
8239 | 8231 |
8240 set_current_block(if_fastobject); | 8232 set_current_block(if_fastobject); |
8241 length = AddInstruction(new(zone()) HFixedArrayBaseLength(elements)); | 8233 length = AddInstruction(new(zone()) HFixedArrayBaseLength(elements)); |
8242 checked_key = AddBoundsCheck(key, length, ALLOW_SMI_KEY); | 8234 checked_key = AddBoundsCheck(key, length, ALLOW_SMI_KEY); |
8243 access = AddInstruction(BuildFastElementAccess( | 8235 access = AddInstruction(BuildFastElementAccess( |
8244 elements, checked_key, val, elements_kind_branch, | 8236 elements, checked_key, val, elements_kind_branch, |
8245 elements_kind, is_store, STANDARD_STORE)); | 8237 elements_kind, is_store, STANDARD_STORE)); |
8246 } else if (elements_kind == DICTIONARY_ELEMENTS) { | 8238 } else if (elements_kind == DICTIONARY_ELEMENTS) { |
8247 if (is_store) { | 8239 if (is_store) { |
8248 access = AddInstruction(BuildStoreKeyedGeneric(object, key, val)); | 8240 access = AddInstruction(BuildStoreKeyedGeneric(object, key, val)); |
8249 } else { | 8241 } else { |
8250 access = AddInstruction(BuildLoadKeyedGeneric(object, key)); | 8242 access = AddInstruction(BuildLoadKeyedGeneric(object, key)); |
8251 } | 8243 } |
8252 } else { // External array elements. | 8244 } else { // External array elements. |
8253 access = AddInstruction(BuildExternalArrayElementAccess( | 8245 access = AddInstruction(BuildExternalArrayElementAccess( |
8254 external_elements, checked_key, val, | 8246 external_elements, checked_key, val, |
8255 elements_kind_branch, elements_kind, is_store)); | 8247 elements_kind_branch, elements_kind, is_store)); |
8256 } | 8248 } |
8257 *has_side_effects |= access->HasObservableSideEffects(); | 8249 *has_side_effects |= access->HasObservableSideEffects(); |
8258 // The caller will use has_side_effects and add correct Simulate. | 8250 // The caller will use has_side_effects and add correct Simulate. |
8259 access->SetFlag(HValue::kHasNoObservableSideEffects); | 8251 access->SetFlag(HValue::kHasNoObservableSideEffects); |
8260 if (position != RelocInfo::kNoPosition) access->set_position(position); | 8252 if (position != RelocInfo::kNoPosition) access->set_position(position); |
8261 if (!is_store) { | 8253 if (!is_store) { |
8262 Push(access); | 8254 Push(access); |
8263 } | 8255 } |
8264 current_block()->GotoNoSimulate(join); | 8256 current_block()->GotoNoSimulate(join); |
8265 ASSERT(SafeToAddPhiInNoSideEffectsScope()); | |
8266 set_current_block(if_false); | 8257 set_current_block(if_false); |
8267 } | 8258 } |
8268 } | 8259 } |
8269 | 8260 |
8270 // Deopt if none of the cases matched. | 8261 // Deopt if none of the cases matched. |
8271 current_block()->FinishExitWithDeoptimization(HDeoptimize::kNoUses); | 8262 current_block()->FinishExitWithDeoptimization(HDeoptimize::kNoUses); |
8272 set_current_block(join); | 8263 set_current_block(join); |
8273 return is_store ? NULL : Pop(); | 8264 return is_store ? NULL : Pop(); |
8274 } | 8265 } |
8275 | 8266 |
(...skipping 4151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12427 } | 12418 } |
12428 } | 12419 } |
12429 | 12420 |
12430 #ifdef DEBUG | 12421 #ifdef DEBUG |
12431 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 12422 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
12432 if (allocator_ != NULL) allocator_->Verify(); | 12423 if (allocator_ != NULL) allocator_->Verify(); |
12433 #endif | 12424 #endif |
12434 } | 12425 } |
12435 | 12426 |
12436 } } // namespace v8::internal | 12427 } } // namespace v8::internal |
OLD | NEW |