Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: src/hydrogen.cc

Issue 367343002: Hydrogenized KeyedLoadGeneric stub: when probing the KeyedLookupCache fails, call the runtime, don'… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: check for valid builder Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/hydrogen.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 8
9 #include "src/v8.h" 9 #include "src/v8.h"
10 10
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 if (IsConstant1(constant)) return true; 738 if (IsConstant1(constant)) return true;
739 if (IsConstantMinus1(constant)) return true; 739 if (IsConstantMinus1(constant)) return true;
740 if (IsConstantTrue(constant)) return true; 740 if (IsConstantTrue(constant)) return true;
741 if (IsConstantFalse(constant)) return true; 741 if (IsConstantFalse(constant)) return true;
742 if (IsConstantHole(constant)) return true; 742 if (IsConstantHole(constant)) return true;
743 if (IsConstantNull(constant)) return true; 743 if (IsConstantNull(constant)) return true;
744 return false; 744 return false;
745 } 745 }
746 746
747 747
748 HGraphBuilder::IfBuilder::IfBuilder() : builder_(NULL), needs_compare_(true) {}
749
750
748 HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder) 751 HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder)
749 : builder_(builder), 752 : needs_compare_(true) {
750 finished_(false), 753 Initialize(builder);
751 did_then_(false), 754 }
752 did_else_(false), 755
753 did_else_if_(false), 756
754 did_and_(false), 757 HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder,
755 did_or_(false), 758 HIfContinuation* continuation)
756 captured_(false), 759 : needs_compare_(false), first_true_block_(NULL), first_false_block_(NULL) {
757 needs_compare_(true), 760 InitializeDontCreateBlocks(builder);
758 pending_merge_block_(false), 761 continuation->Continue(&first_true_block_, &first_false_block_);
759 split_edge_merge_block_(NULL), 762 }
760 merge_at_join_blocks_(NULL), 763
761 normal_merge_at_join_block_count_(0), 764
762 deopt_merge_at_join_block_count_(0) { 765 void HGraphBuilder::IfBuilder::InitializeDontCreateBlocks(
766 HGraphBuilder* builder) {
767 builder_ = builder;
768 finished_ = false;
769 did_then_ = false;
770 did_else_ = false;
771 did_else_if_ = false;
772 did_and_ = false;
773 did_or_ = false;
774 captured_ = false;
775 pending_merge_block_ = false;
776 split_edge_merge_block_ = NULL;
777 merge_at_join_blocks_ = NULL;
778 normal_merge_at_join_block_count_ = 0;
779 deopt_merge_at_join_block_count_ = 0;
780 }
781
782
783 void HGraphBuilder::IfBuilder::Initialize(HGraphBuilder* builder) {
784 InitializeDontCreateBlocks(builder);
763 HEnvironment* env = builder->environment(); 785 HEnvironment* env = builder->environment();
764 first_true_block_ = builder->CreateBasicBlock(env->Copy()); 786 first_true_block_ = builder->CreateBasicBlock(env->Copy());
765 first_false_block_ = builder->CreateBasicBlock(env->Copy()); 787 first_false_block_ = builder->CreateBasicBlock(env->Copy());
766 } 788 }
767 789
768 790
769 HGraphBuilder::IfBuilder::IfBuilder(
770 HGraphBuilder* builder,
771 HIfContinuation* continuation)
772 : builder_(builder),
773 finished_(false),
774 did_then_(false),
775 did_else_(false),
776 did_else_if_(false),
777 did_and_(false),
778 did_or_(false),
779 captured_(false),
780 needs_compare_(false),
781 pending_merge_block_(false),
782 first_true_block_(NULL),
783 first_false_block_(NULL),
784 split_edge_merge_block_(NULL),
785 merge_at_join_blocks_(NULL),
786 normal_merge_at_join_block_count_(0),
787 deopt_merge_at_join_block_count_(0) {
788 continuation->Continue(&first_true_block_,
789 &first_false_block_);
790 }
791
792
793 HControlInstruction* HGraphBuilder::IfBuilder::AddCompare( 791 HControlInstruction* HGraphBuilder::IfBuilder::AddCompare(
794 HControlInstruction* compare) { 792 HControlInstruction* compare) {
795 ASSERT(did_then_ == did_else_); 793 ASSERT(did_then_ == did_else_);
796 if (did_else_) { 794 if (did_else_) {
797 // Handle if-then-elseif 795 // Handle if-then-elseif
798 did_else_if_ = true; 796 did_else_if_ = true;
799 did_else_ = false; 797 did_else_ = false;
800 did_then_ = false; 798 did_then_ = false;
801 did_and_ = false; 799 did_and_ = false;
802 did_or_ = false; 800 did_or_ = false;
803 pending_merge_block_ = false; 801 pending_merge_block_ = false;
804 split_edge_merge_block_ = NULL; 802 split_edge_merge_block_ = NULL;
805 HEnvironment* env = builder_->environment(); 803 HEnvironment* env = builder()->environment();
806 first_true_block_ = builder_->CreateBasicBlock(env->Copy()); 804 first_true_block_ = builder()->CreateBasicBlock(env->Copy());
807 first_false_block_ = builder_->CreateBasicBlock(env->Copy()); 805 first_false_block_ = builder()->CreateBasicBlock(env->Copy());
808 } 806 }
809 if (split_edge_merge_block_ != NULL) { 807 if (split_edge_merge_block_ != NULL) {
810 HEnvironment* env = first_false_block_->last_environment(); 808 HEnvironment* env = first_false_block_->last_environment();
811 HBasicBlock* split_edge = 809 HBasicBlock* split_edge = builder()->CreateBasicBlock(env->Copy());
812 builder_->CreateBasicBlock(env->Copy());
813 if (did_or_) { 810 if (did_or_) {
814 compare->SetSuccessorAt(0, split_edge); 811 compare->SetSuccessorAt(0, split_edge);
815 compare->SetSuccessorAt(1, first_false_block_); 812 compare->SetSuccessorAt(1, first_false_block_);
816 } else { 813 } else {
817 compare->SetSuccessorAt(0, first_true_block_); 814 compare->SetSuccessorAt(0, first_true_block_);
818 compare->SetSuccessorAt(1, split_edge); 815 compare->SetSuccessorAt(1, split_edge);
819 } 816 }
820 builder_->GotoNoSimulate(split_edge, split_edge_merge_block_); 817 builder()->GotoNoSimulate(split_edge, split_edge_merge_block_);
821 } else { 818 } else {
822 compare->SetSuccessorAt(0, first_true_block_); 819 compare->SetSuccessorAt(0, first_true_block_);
823 compare->SetSuccessorAt(1, first_false_block_); 820 compare->SetSuccessorAt(1, first_false_block_);
824 } 821 }
825 builder_->FinishCurrentBlock(compare); 822 builder()->FinishCurrentBlock(compare);
826 needs_compare_ = false; 823 needs_compare_ = false;
827 return compare; 824 return compare;
828 } 825 }
829 826
830 827
831 void HGraphBuilder::IfBuilder::Or() { 828 void HGraphBuilder::IfBuilder::Or() {
832 ASSERT(!needs_compare_); 829 ASSERT(!needs_compare_);
833 ASSERT(!did_and_); 830 ASSERT(!did_and_);
834 did_or_ = true; 831 did_or_ = true;
835 HEnvironment* env = first_false_block_->last_environment(); 832 HEnvironment* env = first_false_block_->last_environment();
836 if (split_edge_merge_block_ == NULL) { 833 if (split_edge_merge_block_ == NULL) {
837 split_edge_merge_block_ = 834 split_edge_merge_block_ = builder()->CreateBasicBlock(env->Copy());
838 builder_->CreateBasicBlock(env->Copy()); 835 builder()->GotoNoSimulate(first_true_block_, split_edge_merge_block_);
839 builder_->GotoNoSimulate(first_true_block_, split_edge_merge_block_);
840 first_true_block_ = split_edge_merge_block_; 836 first_true_block_ = split_edge_merge_block_;
841 } 837 }
842 builder_->set_current_block(first_false_block_); 838 builder()->set_current_block(first_false_block_);
843 first_false_block_ = builder_->CreateBasicBlock(env->Copy()); 839 first_false_block_ = builder()->CreateBasicBlock(env->Copy());
844 } 840 }
845 841
846 842
847 void HGraphBuilder::IfBuilder::And() { 843 void HGraphBuilder::IfBuilder::And() {
848 ASSERT(!needs_compare_); 844 ASSERT(!needs_compare_);
849 ASSERT(!did_or_); 845 ASSERT(!did_or_);
850 did_and_ = true; 846 did_and_ = true;
851 HEnvironment* env = first_false_block_->last_environment(); 847 HEnvironment* env = first_false_block_->last_environment();
852 if (split_edge_merge_block_ == NULL) { 848 if (split_edge_merge_block_ == NULL) {
853 split_edge_merge_block_ = builder_->CreateBasicBlock(env->Copy()); 849 split_edge_merge_block_ = builder()->CreateBasicBlock(env->Copy());
854 builder_->GotoNoSimulate(first_false_block_, split_edge_merge_block_); 850 builder()->GotoNoSimulate(first_false_block_, split_edge_merge_block_);
855 first_false_block_ = split_edge_merge_block_; 851 first_false_block_ = split_edge_merge_block_;
856 } 852 }
857 builder_->set_current_block(first_true_block_); 853 builder()->set_current_block(first_true_block_);
858 first_true_block_ = builder_->CreateBasicBlock(env->Copy()); 854 first_true_block_ = builder()->CreateBasicBlock(env->Copy());
859 } 855 }
860 856
861 857
862 void HGraphBuilder::IfBuilder::CaptureContinuation( 858 void HGraphBuilder::IfBuilder::CaptureContinuation(
863 HIfContinuation* continuation) { 859 HIfContinuation* continuation) {
864 ASSERT(!did_else_if_); 860 ASSERT(!did_else_if_);
865 ASSERT(!finished_); 861 ASSERT(!finished_);
866 ASSERT(!captured_); 862 ASSERT(!captured_);
867 863
868 HBasicBlock* true_block = NULL; 864 HBasicBlock* true_block = NULL;
869 HBasicBlock* false_block = NULL; 865 HBasicBlock* false_block = NULL;
870 Finish(&true_block, &false_block); 866 Finish(&true_block, &false_block);
871 ASSERT(true_block != NULL); 867 ASSERT(true_block != NULL);
872 ASSERT(false_block != NULL); 868 ASSERT(false_block != NULL);
873 continuation->Capture(true_block, false_block); 869 continuation->Capture(true_block, false_block);
874 captured_ = true; 870 captured_ = true;
875 builder_->set_current_block(NULL); 871 builder()->set_current_block(NULL);
876 End(); 872 End();
877 } 873 }
878 874
879 875
880 void HGraphBuilder::IfBuilder::JoinContinuation(HIfContinuation* continuation) { 876 void HGraphBuilder::IfBuilder::JoinContinuation(HIfContinuation* continuation) {
881 ASSERT(!did_else_if_); 877 ASSERT(!did_else_if_);
882 ASSERT(!finished_); 878 ASSERT(!finished_);
883 ASSERT(!captured_); 879 ASSERT(!captured_);
884 HBasicBlock* true_block = NULL; 880 HBasicBlock* true_block = NULL;
885 HBasicBlock* false_block = NULL; 881 HBasicBlock* false_block = NULL;
886 Finish(&true_block, &false_block); 882 Finish(&true_block, &false_block);
887 merge_at_join_blocks_ = NULL; 883 merge_at_join_blocks_ = NULL;
888 if (true_block != NULL && !true_block->IsFinished()) { 884 if (true_block != NULL && !true_block->IsFinished()) {
889 ASSERT(continuation->IsTrueReachable()); 885 ASSERT(continuation->IsTrueReachable());
890 builder_->GotoNoSimulate(true_block, continuation->true_branch()); 886 builder()->GotoNoSimulate(true_block, continuation->true_branch());
891 } 887 }
892 if (false_block != NULL && !false_block->IsFinished()) { 888 if (false_block != NULL && !false_block->IsFinished()) {
893 ASSERT(continuation->IsFalseReachable()); 889 ASSERT(continuation->IsFalseReachable());
894 builder_->GotoNoSimulate(false_block, continuation->false_branch()); 890 builder()->GotoNoSimulate(false_block, continuation->false_branch());
895 } 891 }
896 captured_ = true; 892 captured_ = true;
897 End(); 893 End();
898 } 894 }
899 895
900 896
901 void HGraphBuilder::IfBuilder::Then() { 897 void HGraphBuilder::IfBuilder::Then() {
902 ASSERT(!captured_); 898 ASSERT(!captured_);
903 ASSERT(!finished_); 899 ASSERT(!finished_);
904 did_then_ = true; 900 did_then_ = true;
905 if (needs_compare_) { 901 if (needs_compare_) {
906 // Handle if's without any expressions, they jump directly to the "else" 902 // Handle if's without any expressions, they jump directly to the "else"
907 // branch. However, we must pretend that the "then" branch is reachable, 903 // branch. However, we must pretend that the "then" branch is reachable,
908 // so that the graph builder visits it and sees any live range extending 904 // so that the graph builder visits it and sees any live range extending
909 // constructs within it. 905 // constructs within it.
910 HConstant* constant_false = builder_->graph()->GetConstantFalse(); 906 HConstant* constant_false = builder()->graph()->GetConstantFalse();
911 ToBooleanStub::Types boolean_type = ToBooleanStub::Types(); 907 ToBooleanStub::Types boolean_type = ToBooleanStub::Types();
912 boolean_type.Add(ToBooleanStub::BOOLEAN); 908 boolean_type.Add(ToBooleanStub::BOOLEAN);
913 HBranch* branch = builder()->New<HBranch>( 909 HBranch* branch = builder()->New<HBranch>(
914 constant_false, boolean_type, first_true_block_, first_false_block_); 910 constant_false, boolean_type, first_true_block_, first_false_block_);
915 builder_->FinishCurrentBlock(branch); 911 builder()->FinishCurrentBlock(branch);
916 } 912 }
917 builder_->set_current_block(first_true_block_); 913 builder()->set_current_block(first_true_block_);
918 pending_merge_block_ = true; 914 pending_merge_block_ = true;
919 } 915 }
920 916
921 917
922 void HGraphBuilder::IfBuilder::Else() { 918 void HGraphBuilder::IfBuilder::Else() {
923 ASSERT(did_then_); 919 ASSERT(did_then_);
924 ASSERT(!captured_); 920 ASSERT(!captured_);
925 ASSERT(!finished_); 921 ASSERT(!finished_);
926 AddMergeAtJoinBlock(false); 922 AddMergeAtJoinBlock(false);
927 builder_->set_current_block(first_false_block_); 923 builder()->set_current_block(first_false_block_);
928 pending_merge_block_ = true; 924 pending_merge_block_ = true;
929 did_else_ = true; 925 did_else_ = true;
930 } 926 }
931 927
932 928
933 void HGraphBuilder::IfBuilder::Deopt(const char* reason) { 929 void HGraphBuilder::IfBuilder::Deopt(const char* reason) {
934 ASSERT(did_then_); 930 ASSERT(did_then_);
935 builder_->Add<HDeoptimize>(reason, Deoptimizer::EAGER); 931 builder()->Add<HDeoptimize>(reason, Deoptimizer::EAGER);
936 AddMergeAtJoinBlock(true); 932 AddMergeAtJoinBlock(true);
937 } 933 }
938 934
939 935
940 void HGraphBuilder::IfBuilder::Return(HValue* value) { 936 void HGraphBuilder::IfBuilder::Return(HValue* value) {
941 HValue* parameter_count = builder_->graph()->GetConstantMinus1(); 937 HValue* parameter_count = builder()->graph()->GetConstantMinus1();
942 builder_->FinishExitCurrentBlock( 938 builder()->FinishExitCurrentBlock(
943 builder_->New<HReturn>(value, parameter_count)); 939 builder()->New<HReturn>(value, parameter_count));
944 AddMergeAtJoinBlock(false); 940 AddMergeAtJoinBlock(false);
945 } 941 }
946 942
947 943
948 void HGraphBuilder::IfBuilder::AddMergeAtJoinBlock(bool deopt) { 944 void HGraphBuilder::IfBuilder::AddMergeAtJoinBlock(bool deopt) {
949 if (!pending_merge_block_) return; 945 if (!pending_merge_block_) return;
950 HBasicBlock* block = builder_->current_block(); 946 HBasicBlock* block = builder()->current_block();
951 ASSERT(block == NULL || !block->IsFinished()); 947 ASSERT(block == NULL || !block->IsFinished());
952 MergeAtJoinBlock* record = 948 MergeAtJoinBlock* record = new (builder()->zone())
953 new(builder_->zone()) MergeAtJoinBlock(block, deopt, 949 MergeAtJoinBlock(block, deopt, merge_at_join_blocks_);
954 merge_at_join_blocks_);
955 merge_at_join_blocks_ = record; 950 merge_at_join_blocks_ = record;
956 if (block != NULL) { 951 if (block != NULL) {
957 ASSERT(block->end() == NULL); 952 ASSERT(block->end() == NULL);
958 if (deopt) { 953 if (deopt) {
959 normal_merge_at_join_block_count_++; 954 normal_merge_at_join_block_count_++;
960 } else { 955 } else {
961 deopt_merge_at_join_block_count_++; 956 deopt_merge_at_join_block_count_++;
962 } 957 }
963 } 958 }
964 builder_->set_current_block(NULL); 959 builder()->set_current_block(NULL);
965 pending_merge_block_ = false; 960 pending_merge_block_ = false;
966 } 961 }
967 962
968 963
969 void HGraphBuilder::IfBuilder::Finish() { 964 void HGraphBuilder::IfBuilder::Finish() {
970 ASSERT(!finished_); 965 ASSERT(!finished_);
971 if (!did_then_) { 966 if (!did_then_) {
972 Then(); 967 Then();
973 } 968 }
974 AddMergeAtJoinBlock(false); 969 AddMergeAtJoinBlock(false);
(...skipping 21 matching lines...) Expand all
996 } 991 }
997 992
998 993
999 void HGraphBuilder::IfBuilder::End() { 994 void HGraphBuilder::IfBuilder::End() {
1000 if (captured_) return; 995 if (captured_) return;
1001 Finish(); 996 Finish();
1002 997
1003 int total_merged_blocks = normal_merge_at_join_block_count_ + 998 int total_merged_blocks = normal_merge_at_join_block_count_ +
1004 deopt_merge_at_join_block_count_; 999 deopt_merge_at_join_block_count_;
1005 ASSERT(total_merged_blocks >= 1); 1000 ASSERT(total_merged_blocks >= 1);
1006 HBasicBlock* merge_block = total_merged_blocks == 1 1001 HBasicBlock* merge_block =
1007 ? NULL : builder_->graph()->CreateBasicBlock(); 1002 total_merged_blocks == 1 ? NULL : builder()->graph()->CreateBasicBlock();
1008 1003
1009 // Merge non-deopt blocks first to ensure environment has right size for 1004 // Merge non-deopt blocks first to ensure environment has right size for
1010 // padding. 1005 // padding.
1011 MergeAtJoinBlock* current = merge_at_join_blocks_; 1006 MergeAtJoinBlock* current = merge_at_join_blocks_;
1012 while (current != NULL) { 1007 while (current != NULL) {
1013 if (!current->deopt_ && current->block_ != NULL) { 1008 if (!current->deopt_ && current->block_ != NULL) {
1014 // If there is only one block that makes it through to the end of the 1009 // If there is only one block that makes it through to the end of the
1015 // if, then just set it as the current block and continue rather then 1010 // if, then just set it as the current block and continue rather then
1016 // creating an unnecessary merge block. 1011 // creating an unnecessary merge block.
1017 if (total_merged_blocks == 1) { 1012 if (total_merged_blocks == 1) {
1018 builder_->set_current_block(current->block_); 1013 builder()->set_current_block(current->block_);
1019 return; 1014 return;
1020 } 1015 }
1021 builder_->GotoNoSimulate(current->block_, merge_block); 1016 builder()->GotoNoSimulate(current->block_, merge_block);
1022 } 1017 }
1023 current = current->next_; 1018 current = current->next_;
1024 } 1019 }
1025 1020
1026 // Merge deopt blocks, padding when necessary. 1021 // Merge deopt blocks, padding when necessary.
1027 current = merge_at_join_blocks_; 1022 current = merge_at_join_blocks_;
1028 while (current != NULL) { 1023 while (current != NULL) {
1029 if (current->deopt_ && current->block_ != NULL) { 1024 if (current->deopt_ && current->block_ != NULL) {
1030 current->block_->FinishExit( 1025 current->block_->FinishExit(HAbnormalExit::New(builder()->zone(), NULL),
1031 HAbnormalExit::New(builder_->zone(), NULL), 1026 HSourcePosition::Unknown());
1032 HSourcePosition::Unknown());
1033 } 1027 }
1034 current = current->next_; 1028 current = current->next_;
1035 } 1029 }
1036 builder_->set_current_block(merge_block); 1030 builder()->set_current_block(merge_block);
1037 } 1031 }
1038 1032
1039 1033
1040 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder) { 1034 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder) {
1041 Initialize(builder, NULL, kWhileTrue, NULL); 1035 Initialize(builder, NULL, kWhileTrue, NULL);
1042 } 1036 }
1043 1037
1044 1038
1045 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder, HValue* context, 1039 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder, HValue* context,
1046 LoopBuilder::Direction direction) { 1040 LoopBuilder::Direction direction) {
(...skipping 11381 matching lines...) Expand 10 before | Expand all | Expand 10 after
12428 if (ShouldProduceTraceOutput()) { 12422 if (ShouldProduceTraceOutput()) {
12429 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 12423 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
12430 } 12424 }
12431 12425
12432 #ifdef DEBUG 12426 #ifdef DEBUG
12433 graph_->Verify(false); // No full verify. 12427 graph_->Verify(false); // No full verify.
12434 #endif 12428 #endif
12435 } 12429 }
12436 12430
12437 } } // namespace v8::internal 12431 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698