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

Side by Side Diff: src/hydrogen.cc

Issue 700963002: Replace C++ bitfields with our own BitFields (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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
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 <sstream> 7 #include <sstream>
8 8
9 #include "src/v8.h" 9 #include "src/v8.h"
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 predecessors_(2, graph->zone()), 75 predecessors_(2, graph->zone()),
76 dominator_(NULL), 76 dominator_(NULL),
77 dominated_blocks_(4, graph->zone()), 77 dominated_blocks_(4, graph->zone()),
78 last_environment_(NULL), 78 last_environment_(NULL),
79 argument_count_(-1), 79 argument_count_(-1),
80 first_instruction_index_(-1), 80 first_instruction_index_(-1),
81 last_instruction_index_(-1), 81 last_instruction_index_(-1),
82 deleted_phis_(4, graph->zone()), 82 deleted_phis_(4, graph->zone()),
83 parent_loop_header_(NULL), 83 parent_loop_header_(NULL),
84 inlined_entry_block_(NULL), 84 inlined_entry_block_(NULL),
85 is_inline_return_target_(false), 85 bit_field_(IsInlineReturnTargetField::encode(false) |
86 is_reachable_(true), 86 IsReachableField::encode(true) |
87 dominates_loop_successors_(false), 87 DominatesLoopSuccessorsField::encode(false) |
88 is_osr_entry_(false), 88 IsOsrEntryField::encode(false) |
89 is_ordered_(false) { } 89 IsOrderedField::encode(false)) {}
90 90
91 91
92 Isolate* HBasicBlock::isolate() const { 92 Isolate* HBasicBlock::isolate() const {
93 return graph_->isolate(); 93 return graph_->isolate();
94 } 94 }
95 95
96 96
97 void HBasicBlock::MarkUnreachable() { 97 void HBasicBlock::MarkUnreachable() {
98 is_reachable_ = false; 98 bit_field_ = IsReachableField::update(bit_field_, false);
99 } 99 }
100 100
101 101
102 void HBasicBlock::AttachLoopInformation() { 102 void HBasicBlock::AttachLoopInformation() {
103 DCHECK(!IsLoopHeader()); 103 DCHECK(!IsLoopHeader());
104 loop_information_ = new(zone()) HLoopInformation(this, zone()); 104 loop_information_ = new(zone()) HLoopInformation(this, zone());
105 } 105 }
106 106
107 107
108 void HBasicBlock::DetachLoopInformation() { 108 void HBasicBlock::DetachLoopInformation() {
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 if (IsConstant1(constant)) return true; 741 if (IsConstant1(constant)) return true;
742 if (IsConstantMinus1(constant)) return true; 742 if (IsConstantMinus1(constant)) return true;
743 if (IsConstantTrue(constant)) return true; 743 if (IsConstantTrue(constant)) return true;
744 if (IsConstantFalse(constant)) return true; 744 if (IsConstantFalse(constant)) return true;
745 if (IsConstantHole(constant)) return true; 745 if (IsConstantHole(constant)) return true;
746 if (IsConstantNull(constant)) return true; 746 if (IsConstantNull(constant)) return true;
747 return false; 747 return false;
748 } 748 }
749 749
750 750
751 HGraphBuilder::IfBuilder::IfBuilder() : builder_(NULL), needs_compare_(true) {} 751 HGraphBuilder::IfBuilder::IfBuilder()
752 : builder_(NULL), bit_field_(NeedsCompareField::encode(true)) {}
752 753
753 754
754 HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder) 755 HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder)
755 : needs_compare_(true) { 756 : bit_field_(NeedsCompareField::encode(true)) {
756 Initialize(builder); 757 Initialize(builder);
757 } 758 }
758 759
759 760
760 HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder, 761 HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder,
761 HIfContinuation* continuation) 762 HIfContinuation* continuation)
762 : needs_compare_(false), first_true_block_(NULL), first_false_block_(NULL) { 763 : bit_field_(NeedsCompareField::encode(false)),
764 first_true_block_(NULL),
765 first_false_block_(NULL) {
763 InitializeDontCreateBlocks(builder); 766 InitializeDontCreateBlocks(builder);
764 continuation->Continue(&first_true_block_, &first_false_block_); 767 continuation->Continue(&first_true_block_, &first_false_block_);
765 } 768 }
766 769
767 770
768 void HGraphBuilder::IfBuilder::InitializeDontCreateBlocks( 771 void HGraphBuilder::IfBuilder::InitializeDontCreateBlocks(
769 HGraphBuilder* builder) { 772 HGraphBuilder* builder) {
770 builder_ = builder; 773 builder_ = builder;
771 finished_ = false; 774 bool needs_compare = NeedsCompareField::decode(bit_field_);
772 did_then_ = false; 775 bit_field_ = FinishedField::encode(false) | DidThenField::encode(false) |
773 did_else_ = false; 776 DidElseField::encode(false) | DidElseIfField::encode(false) |
774 did_else_if_ = false; 777 DidAndField::encode(false) | DidOrField::encode(false) |
775 did_and_ = false; 778 CapturedField::encode(false) |
776 did_or_ = false; 779 NeedsCompareField::encode(needs_compare) |
777 captured_ = false; 780 PendingMergeBlockField::encode(false);
778 pending_merge_block_ = false;
779 split_edge_merge_block_ = NULL; 781 split_edge_merge_block_ = NULL;
780 merge_at_join_blocks_ = NULL; 782 merge_at_join_blocks_ = NULL;
781 normal_merge_at_join_block_count_ = 0; 783 normal_merge_at_join_block_count_ = 0;
782 deopt_merge_at_join_block_count_ = 0; 784 deopt_merge_at_join_block_count_ = 0;
783 } 785 }
784 786
785 787
786 void HGraphBuilder::IfBuilder::Initialize(HGraphBuilder* builder) { 788 void HGraphBuilder::IfBuilder::Initialize(HGraphBuilder* builder) {
787 InitializeDontCreateBlocks(builder); 789 InitializeDontCreateBlocks(builder);
788 HEnvironment* env = builder->environment(); 790 HEnvironment* env = builder->environment();
789 first_true_block_ = builder->CreateBasicBlock(env->Copy()); 791 first_true_block_ = builder->CreateBasicBlock(env->Copy());
790 first_false_block_ = builder->CreateBasicBlock(env->Copy()); 792 first_false_block_ = builder->CreateBasicBlock(env->Copy());
791 } 793 }
792 794
793 795
794 HControlInstruction* HGraphBuilder::IfBuilder::AddCompare( 796 HControlInstruction* HGraphBuilder::IfBuilder::AddCompare(
795 HControlInstruction* compare) { 797 HControlInstruction* compare) {
796 DCHECK(did_then_ == did_else_); 798 DCHECK(did_then() == did_else());
797 if (did_else_) { 799 if (did_else()) {
798 // Handle if-then-elseif 800 // Handle if-then-elseif
799 did_else_if_ = true; 801 set_did_else_if(true);
800 did_else_ = false; 802 set_did_else(false);
801 did_then_ = false; 803 set_did_then(false);
802 did_and_ = false; 804 set_did_and(false);
803 did_or_ = false; 805 set_did_or(false);
804 pending_merge_block_ = false; 806 set_pending_merge_block(false);
805 split_edge_merge_block_ = NULL; 807 split_edge_merge_block_ = NULL;
806 HEnvironment* env = builder()->environment(); 808 HEnvironment* env = builder()->environment();
807 first_true_block_ = builder()->CreateBasicBlock(env->Copy()); 809 first_true_block_ = builder()->CreateBasicBlock(env->Copy());
808 first_false_block_ = builder()->CreateBasicBlock(env->Copy()); 810 first_false_block_ = builder()->CreateBasicBlock(env->Copy());
809 } 811 }
810 if (split_edge_merge_block_ != NULL) { 812 if (split_edge_merge_block_ != NULL) {
811 HEnvironment* env = first_false_block_->last_environment(); 813 HEnvironment* env = first_false_block_->last_environment();
812 HBasicBlock* split_edge = builder()->CreateBasicBlock(env->Copy()); 814 HBasicBlock* split_edge = builder()->CreateBasicBlock(env->Copy());
813 if (did_or_) { 815 if (did_or()) {
814 compare->SetSuccessorAt(0, split_edge); 816 compare->SetSuccessorAt(0, split_edge);
815 compare->SetSuccessorAt(1, first_false_block_); 817 compare->SetSuccessorAt(1, first_false_block_);
816 } else { 818 } else {
817 compare->SetSuccessorAt(0, first_true_block_); 819 compare->SetSuccessorAt(0, first_true_block_);
818 compare->SetSuccessorAt(1, split_edge); 820 compare->SetSuccessorAt(1, split_edge);
819 } 821 }
820 builder()->GotoNoSimulate(split_edge, split_edge_merge_block_); 822 builder()->GotoNoSimulate(split_edge, split_edge_merge_block_);
821 } else { 823 } else {
822 compare->SetSuccessorAt(0, first_true_block_); 824 compare->SetSuccessorAt(0, first_true_block_);
823 compare->SetSuccessorAt(1, first_false_block_); 825 compare->SetSuccessorAt(1, first_false_block_);
824 } 826 }
825 builder()->FinishCurrentBlock(compare); 827 builder()->FinishCurrentBlock(compare);
826 needs_compare_ = false; 828 set_needs_compare(false);
827 return compare; 829 return compare;
828 } 830 }
829 831
830 832
831 void HGraphBuilder::IfBuilder::Or() { 833 void HGraphBuilder::IfBuilder::Or() {
832 DCHECK(!needs_compare_); 834 DCHECK(!needs_compare());
833 DCHECK(!did_and_); 835 DCHECK(!did_and());
834 did_or_ = true; 836 set_did_or(true);
835 HEnvironment* env = first_false_block_->last_environment(); 837 HEnvironment* env = first_false_block_->last_environment();
836 if (split_edge_merge_block_ == NULL) { 838 if (split_edge_merge_block_ == NULL) {
837 split_edge_merge_block_ = builder()->CreateBasicBlock(env->Copy()); 839 split_edge_merge_block_ = builder()->CreateBasicBlock(env->Copy());
838 builder()->GotoNoSimulate(first_true_block_, split_edge_merge_block_); 840 builder()->GotoNoSimulate(first_true_block_, split_edge_merge_block_);
839 first_true_block_ = split_edge_merge_block_; 841 first_true_block_ = split_edge_merge_block_;
840 } 842 }
841 builder()->set_current_block(first_false_block_); 843 builder()->set_current_block(first_false_block_);
842 first_false_block_ = builder()->CreateBasicBlock(env->Copy()); 844 first_false_block_ = builder()->CreateBasicBlock(env->Copy());
843 } 845 }
844 846
845 847
846 void HGraphBuilder::IfBuilder::And() { 848 void HGraphBuilder::IfBuilder::And() {
847 DCHECK(!needs_compare_); 849 DCHECK(!needs_compare());
848 DCHECK(!did_or_); 850 DCHECK(!did_or());
849 did_and_ = true; 851 set_did_and(true);
850 HEnvironment* env = first_false_block_->last_environment(); 852 HEnvironment* env = first_false_block_->last_environment();
851 if (split_edge_merge_block_ == NULL) { 853 if (split_edge_merge_block_ == NULL) {
852 split_edge_merge_block_ = builder()->CreateBasicBlock(env->Copy()); 854 split_edge_merge_block_ = builder()->CreateBasicBlock(env->Copy());
853 builder()->GotoNoSimulate(first_false_block_, split_edge_merge_block_); 855 builder()->GotoNoSimulate(first_false_block_, split_edge_merge_block_);
854 first_false_block_ = split_edge_merge_block_; 856 first_false_block_ = split_edge_merge_block_;
855 } 857 }
856 builder()->set_current_block(first_true_block_); 858 builder()->set_current_block(first_true_block_);
857 first_true_block_ = builder()->CreateBasicBlock(env->Copy()); 859 first_true_block_ = builder()->CreateBasicBlock(env->Copy());
858 } 860 }
859 861
860 862
861 void HGraphBuilder::IfBuilder::CaptureContinuation( 863 void HGraphBuilder::IfBuilder::CaptureContinuation(
862 HIfContinuation* continuation) { 864 HIfContinuation* continuation) {
863 DCHECK(!did_else_if_); 865 DCHECK(!did_else_if());
864 DCHECK(!finished_); 866 DCHECK(!finished());
865 DCHECK(!captured_); 867 DCHECK(!captured());
866 868
867 HBasicBlock* true_block = NULL; 869 HBasicBlock* true_block = NULL;
868 HBasicBlock* false_block = NULL; 870 HBasicBlock* false_block = NULL;
869 Finish(&true_block, &false_block); 871 Finish(&true_block, &false_block);
870 DCHECK(true_block != NULL); 872 DCHECK(true_block != NULL);
871 DCHECK(false_block != NULL); 873 DCHECK(false_block != NULL);
872 continuation->Capture(true_block, false_block); 874 continuation->Capture(true_block, false_block);
873 captured_ = true; 875 set_captured();
874 builder()->set_current_block(NULL); 876 builder()->set_current_block(NULL);
875 End(); 877 End();
876 } 878 }
877 879
878 880
879 void HGraphBuilder::IfBuilder::JoinContinuation(HIfContinuation* continuation) { 881 void HGraphBuilder::IfBuilder::JoinContinuation(HIfContinuation* continuation) {
880 DCHECK(!did_else_if_); 882 DCHECK(!did_else_if());
881 DCHECK(!finished_); 883 DCHECK(!finished());
882 DCHECK(!captured_); 884 DCHECK(!captured());
883 HBasicBlock* true_block = NULL; 885 HBasicBlock* true_block = NULL;
884 HBasicBlock* false_block = NULL; 886 HBasicBlock* false_block = NULL;
885 Finish(&true_block, &false_block); 887 Finish(&true_block, &false_block);
886 merge_at_join_blocks_ = NULL; 888 merge_at_join_blocks_ = NULL;
887 if (true_block != NULL && !true_block->IsFinished()) { 889 if (true_block != NULL && !true_block->IsFinished()) {
888 DCHECK(continuation->IsTrueReachable()); 890 DCHECK(continuation->IsTrueReachable());
889 builder()->GotoNoSimulate(true_block, continuation->true_branch()); 891 builder()->GotoNoSimulate(true_block, continuation->true_branch());
890 } 892 }
891 if (false_block != NULL && !false_block->IsFinished()) { 893 if (false_block != NULL && !false_block->IsFinished()) {
892 DCHECK(continuation->IsFalseReachable()); 894 DCHECK(continuation->IsFalseReachable());
893 builder()->GotoNoSimulate(false_block, continuation->false_branch()); 895 builder()->GotoNoSimulate(false_block, continuation->false_branch());
894 } 896 }
895 captured_ = true; 897 set_captured();
896 End(); 898 End();
897 } 899 }
898 900
899 901
900 void HGraphBuilder::IfBuilder::Then() { 902 void HGraphBuilder::IfBuilder::Then() {
901 DCHECK(!captured_); 903 DCHECK(!captured());
902 DCHECK(!finished_); 904 DCHECK(!finished());
903 did_then_ = true; 905 set_did_then(true);
904 if (needs_compare_) { 906 if (needs_compare()) {
905 // Handle if's without any expressions, they jump directly to the "else" 907 // Handle if's without any expressions, they jump directly to the "else"
906 // branch. However, we must pretend that the "then" branch is reachable, 908 // branch. However, we must pretend that the "then" branch is reachable,
907 // so that the graph builder visits it and sees any live range extending 909 // so that the graph builder visits it and sees any live range extending
908 // constructs within it. 910 // constructs within it.
909 HConstant* constant_false = builder()->graph()->GetConstantFalse(); 911 HConstant* constant_false = builder()->graph()->GetConstantFalse();
910 ToBooleanStub::Types boolean_type = ToBooleanStub::Types(); 912 ToBooleanStub::Types boolean_type = ToBooleanStub::Types();
911 boolean_type.Add(ToBooleanStub::BOOLEAN); 913 boolean_type.Add(ToBooleanStub::BOOLEAN);
912 HBranch* branch = builder()->New<HBranch>( 914 HBranch* branch = builder()->New<HBranch>(
913 constant_false, boolean_type, first_true_block_, first_false_block_); 915 constant_false, boolean_type, first_true_block_, first_false_block_);
914 builder()->FinishCurrentBlock(branch); 916 builder()->FinishCurrentBlock(branch);
915 } 917 }
916 builder()->set_current_block(first_true_block_); 918 builder()->set_current_block(first_true_block_);
917 pending_merge_block_ = true; 919 set_pending_merge_block(true);
918 } 920 }
919 921
920 922
921 void HGraphBuilder::IfBuilder::Else() { 923 void HGraphBuilder::IfBuilder::Else() {
922 DCHECK(did_then_); 924 DCHECK(did_then());
923 DCHECK(!captured_); 925 DCHECK(!captured());
924 DCHECK(!finished_); 926 DCHECK(!finished());
925 AddMergeAtJoinBlock(false); 927 AddMergeAtJoinBlock(false);
926 builder()->set_current_block(first_false_block_); 928 builder()->set_current_block(first_false_block_);
927 pending_merge_block_ = true; 929 set_pending_merge_block(true);
928 did_else_ = true; 930 set_did_else(true);
929 } 931 }
930 932
931 933
932 void HGraphBuilder::IfBuilder::Deopt(const char* reason) { 934 void HGraphBuilder::IfBuilder::Deopt(const char* reason) {
933 DCHECK(did_then_); 935 DCHECK(did_then());
934 builder()->Add<HDeoptimize>(reason, Deoptimizer::EAGER); 936 builder()->Add<HDeoptimize>(reason, Deoptimizer::EAGER);
935 AddMergeAtJoinBlock(true); 937 AddMergeAtJoinBlock(true);
936 } 938 }
937 939
938 940
939 void HGraphBuilder::IfBuilder::Return(HValue* value) { 941 void HGraphBuilder::IfBuilder::Return(HValue* value) {
940 HValue* parameter_count = builder()->graph()->GetConstantMinus1(); 942 HValue* parameter_count = builder()->graph()->GetConstantMinus1();
941 builder()->FinishExitCurrentBlock( 943 builder()->FinishExitCurrentBlock(
942 builder()->New<HReturn>(value, parameter_count)); 944 builder()->New<HReturn>(value, parameter_count));
943 AddMergeAtJoinBlock(false); 945 AddMergeAtJoinBlock(false);
944 } 946 }
945 947
946 948
947 void HGraphBuilder::IfBuilder::AddMergeAtJoinBlock(bool deopt) { 949 void HGraphBuilder::IfBuilder::AddMergeAtJoinBlock(bool deopt) {
948 if (!pending_merge_block_) return; 950 if (!pending_merge_block()) return;
949 HBasicBlock* block = builder()->current_block(); 951 HBasicBlock* block = builder()->current_block();
950 DCHECK(block == NULL || !block->IsFinished()); 952 DCHECK(block == NULL || !block->IsFinished());
951 MergeAtJoinBlock* record = new (builder()->zone()) 953 MergeAtJoinBlock* record = new (builder()->zone())
952 MergeAtJoinBlock(block, deopt, merge_at_join_blocks_); 954 MergeAtJoinBlock(block, deopt, merge_at_join_blocks_);
953 merge_at_join_blocks_ = record; 955 merge_at_join_blocks_ = record;
954 if (block != NULL) { 956 if (block != NULL) {
955 DCHECK(block->end() == NULL); 957 DCHECK(block->end() == NULL);
956 if (deopt) { 958 if (deopt) {
957 normal_merge_at_join_block_count_++; 959 normal_merge_at_join_block_count_++;
958 } else { 960 } else {
959 deopt_merge_at_join_block_count_++; 961 deopt_merge_at_join_block_count_++;
960 } 962 }
961 } 963 }
962 builder()->set_current_block(NULL); 964 builder()->set_current_block(NULL);
963 pending_merge_block_ = false; 965 set_pending_merge_block(false);
964 } 966 }
965 967
966 968
967 void HGraphBuilder::IfBuilder::Finish() { 969 void HGraphBuilder::IfBuilder::Finish() {
968 DCHECK(!finished_); 970 DCHECK(!finished());
969 if (!did_then_) { 971 if (!did_then()) {
970 Then(); 972 Then();
971 } 973 }
972 AddMergeAtJoinBlock(false); 974 AddMergeAtJoinBlock(false);
973 if (!did_else_) { 975 if (!did_else()) {
974 Else(); 976 Else();
975 AddMergeAtJoinBlock(false); 977 AddMergeAtJoinBlock(false);
976 } 978 }
977 finished_ = true; 979 set_finished();
978 } 980 }
979 981
980 982
981 void HGraphBuilder::IfBuilder::Finish(HBasicBlock** then_continuation, 983 void HGraphBuilder::IfBuilder::Finish(HBasicBlock** then_continuation,
982 HBasicBlock** else_continuation) { 984 HBasicBlock** else_continuation) {
983 Finish(); 985 Finish();
984 986
985 MergeAtJoinBlock* else_record = merge_at_join_blocks_; 987 MergeAtJoinBlock* else_record = merge_at_join_blocks_;
986 if (else_continuation != NULL) { 988 if (else_continuation != NULL) {
987 *else_continuation = else_record->block_; 989 *else_continuation = else_record->block_;
988 } 990 }
989 MergeAtJoinBlock* then_record = else_record->next_; 991 MergeAtJoinBlock* then_record = else_record->next_;
990 if (then_continuation != NULL) { 992 if (then_continuation != NULL) {
991 *then_continuation = then_record->block_; 993 *then_continuation = then_record->block_;
992 } 994 }
993 DCHECK(then_record->next_ == NULL); 995 DCHECK(then_record->next_ == NULL);
994 } 996 }
995 997
996 998
997 void HGraphBuilder::IfBuilder::End() { 999 void HGraphBuilder::IfBuilder::End() {
998 if (captured_) return; 1000 if (captured()) return;
999 Finish(); 1001 Finish();
1000 1002
1001 int total_merged_blocks = normal_merge_at_join_block_count_ + 1003 int total_merged_blocks = normal_merge_at_join_block_count_ +
1002 deopt_merge_at_join_block_count_; 1004 deopt_merge_at_join_block_count_;
1003 DCHECK(total_merged_blocks >= 1); 1005 DCHECK(total_merged_blocks >= 1);
1004 HBasicBlock* merge_block = 1006 HBasicBlock* merge_block =
1005 total_merged_blocks == 1 ? NULL : builder()->graph()->CreateBasicBlock(); 1007 total_merged_blocks == 1 ? NULL : builder()->graph()->CreateBasicBlock();
1006 1008
1007 // Merge non-deopt blocks first to ensure environment has right size for 1009 // Merge non-deopt blocks first to ensure environment has right size for
1008 // padding. 1010 // padding.
(...skipping 11663 matching lines...) Expand 10 before | Expand all | Expand 10 after
12672 if (ShouldProduceTraceOutput()) { 12674 if (ShouldProduceTraceOutput()) {
12673 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 12675 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
12674 } 12676 }
12675 12677
12676 #ifdef DEBUG 12678 #ifdef DEBUG
12677 graph_->Verify(false); // No full verify. 12679 graph_->Verify(false); // No full verify.
12678 #endif 12680 #endif
12679 } 12681 }
12680 12682
12681 } } // namespace v8::internal 12683 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698