Chromium Code Reviews

Side by Side Diff: src/hydrogen-instructions.h

Issue 7114004: Add support for hydrogen control instructions with >2 successor blocks. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « src/hydrogen.cc ('k') | src/hydrogen-instructions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 17 matching lines...)
28 #ifndef V8_HYDROGEN_INSTRUCTIONS_H_ 28 #ifndef V8_HYDROGEN_INSTRUCTIONS_H_
29 #define V8_HYDROGEN_INSTRUCTIONS_H_ 29 #define V8_HYDROGEN_INSTRUCTIONS_H_
30 30
31 #include "v8.h" 31 #include "v8.h"
32 32
33 #include "allocation.h" 33 #include "allocation.h"
34 #include "code-stubs.h" 34 #include "code-stubs.h"
35 #include "data-flow.h" 35 #include "data-flow.h"
36 #include "small-pointer-list.h" 36 #include "small-pointer-list.h"
37 #include "string-stream.h" 37 #include "string-stream.h"
38 #include "utils.h"
38 #include "zone.h" 39 #include "zone.h"
39 40
40 namespace v8 { 41 namespace v8 {
41 namespace internal { 42 namespace internal {
42 43
43 // Forward declarations. 44 // Forward declarations.
44 class HBasicBlock; 45 class HBasicBlock;
45 class HEnvironment; 46 class HEnvironment;
46 class HInstruction; 47 class HInstruction;
47 class HLoopInformation; 48 class HLoopInformation;
(...skipping 706 matching lines...)
754 void PrintMnemonicTo(StringStream* stream); 755 void PrintMnemonicTo(StringStream* stream);
755 756
756 HInstruction* next_; 757 HInstruction* next_;
757 HInstruction* previous_; 758 HInstruction* previous_;
758 int position_; 759 int position_;
759 760
760 friend class HBasicBlock; 761 friend class HBasicBlock;
761 }; 762 };
762 763
763 764
764 class HControlInstruction: public HInstruction {
765 public:
766 HControlInstruction(HBasicBlock* first, HBasicBlock* second)
767 : first_successor_(first), second_successor_(second) {
768 }
769
770 HBasicBlock* FirstSuccessor() const { return first_successor_; }
771 HBasicBlock* SecondSuccessor() const { return second_successor_; }
772
773 virtual void PrintDataTo(StringStream* stream);
774
775 DECLARE_ABSTRACT_INSTRUCTION(ControlInstruction)
776
777 private:
778 HBasicBlock* first_successor_;
779 HBasicBlock* second_successor_;
780 };
781
782
783 template<int NumElements>
784 class HOperandContainer {
785 public:
786 HOperandContainer() : elems_() { }
787
788 int length() { return NumElements; }
789 HValue*& operator[](int i) {
790 ASSERT(i < length());
791 return elems_[i];
792 }
793
794 private:
795 HValue* elems_[NumElements];
796 };
797
798
799 template<>
800 class HOperandContainer<0> {
801 public:
802 int length() { return 0; }
803 HValue*& operator[](int i) {
804 UNREACHABLE();
805 static HValue* t = 0;
806 return t;
807 }
808 };
809
810
811 template<int V> 765 template<int V>
812 class HTemplateInstruction : public HInstruction { 766 class HTemplateInstruction : public HInstruction {
813 public: 767 public:
814 int OperandCount() { return V; } 768 int OperandCount() { return V; }
815 HValue* OperandAt(int i) { return inputs_[i]; } 769 HValue* OperandAt(int i) { return inputs_[i]; }
816 770
817 protected: 771 protected:
818 void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } 772 void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; }
819 773
820 private: 774 private:
821 HOperandContainer<V> inputs_; 775 EmbeddedContainer<HValue*, V> inputs_;
822 }; 776 };
823 777
824 778
825 template<int V> 779 class HControlInstruction: public HInstruction {
826 class HTemplateControlInstruction : public HControlInstruction {
827 public: 780 public:
828 HTemplateControlInstruction<V>(HBasicBlock* first, HBasicBlock* second) 781 virtual HBasicBlock* SuccessorAt(int i) = 0;
829 : HControlInstruction(first, second) { } 782 virtual int SuccessorCount() = 0;
783
784 virtual void PrintDataTo(StringStream* stream);
785
786 HBasicBlock* FirstSuccessor() {
787 return SuccessorCount() > 0 ? SuccessorAt(0) : NULL;
788 }
789 HBasicBlock* SecondSuccessor() {
790 return SuccessorCount() > 1 ? SuccessorAt(1) : NULL;
791 }
792
793 DECLARE_ABSTRACT_INSTRUCTION(ControlInstruction)
794 };
795
796
797 class HSuccessorIterator BASE_EMBEDDED {
798 public:
799 explicit HSuccessorIterator(HControlInstruction* instr)
800 : instr_(instr), next_(0) { }
801
802 bool HasNext() { return next_ < instr_->SuccessorCount(); }
Kevin Millikin (Chromium) 2011/06/10 11:39:15 Most of the existing hydrogen/lithium iterators ha
fschneider 2011/06/10 12:09:36 Done.
803 HBasicBlock* Next() { return instr_->SuccessorAt(next_); }
804 void Advance() { next_++; }
805
806 private:
807 HControlInstruction* instr_;
808 int next_;
809 };
810
811
812 template<int S, int V>
813 class HTemplateControlInstruction: public HControlInstruction {
814 public:
815 int SuccessorCount() { return S; }
816 HBasicBlock* SuccessorAt(int i) { return successors_[i]; }
817
830 int OperandCount() { return V; } 818 int OperandCount() { return V; }
831 HValue* OperandAt(int i) { return inputs_[i]; } 819 HValue* OperandAt(int i) { return inputs_[i]; }
832 820
833 protected: 821 protected:
822 void SetSuccessorAt(int i, HBasicBlock* block) { successors_[i] = block; }
834 void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } 823 void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; }
835 824
836 private: 825 private:
837 HOperandContainer<V> inputs_; 826 EmbeddedContainer<HBasicBlock*, S> successors_;
827 EmbeddedContainer<HValue*, V> inputs_;
838 }; 828 };
839 829
840 830
841 class HBlockEntry: public HTemplateInstruction<0> { 831 class HBlockEntry: public HTemplateInstruction<0> {
842 public: 832 public:
843 virtual Representation RequiredInputRepresentation(int index) const { 833 virtual Representation RequiredInputRepresentation(int index) const {
844 return Representation::None(); 834 return Representation::None();
845 } 835 }
846 836
847 DECLARE_CONCRETE_INSTRUCTION(BlockEntry) 837 DECLARE_CONCRETE_INSTRUCTION(BlockEntry)
848 }; 838 };
849 839
850 840
851 // We insert soft-deoptimize when we hit code with unknown typefeedback, 841 // We insert soft-deoptimize when we hit code with unknown typefeedback,
852 // so that we get a chance of re-optimizing with useful typefeedback. 842 // so that we get a chance of re-optimizing with useful typefeedback.
853 // HSoftDeoptimize does not end a basic block as opposed to HDeoptimize. 843 // HSoftDeoptimize does not end a basic block as opposed to HDeoptimize.
854 class HSoftDeoptimize: public HTemplateInstruction<0> { 844 class HSoftDeoptimize: public HTemplateInstruction<0> {
855 public: 845 public:
856 virtual Representation RequiredInputRepresentation(int index) const { 846 virtual Representation RequiredInputRepresentation(int index) const {
857 return Representation::None(); 847 return Representation::None();
858 } 848 }
859 849
860 DECLARE_CONCRETE_INSTRUCTION(SoftDeoptimize) 850 DECLARE_CONCRETE_INSTRUCTION(SoftDeoptimize)
861 }; 851 };
862 852
863 853
864 class HDeoptimize: public HControlInstruction { 854 class HDeoptimize : public HControlInstruction {
Kevin Millikin (Chromium) 2011/06/10 11:39:15 The rest of this file, with only a coupld of excep
fschneider 2011/06/10 12:09:36 Done.
865 public: 855 public:
866 explicit HDeoptimize(int environment_length) 856 explicit HDeoptimize(int environment_length) : values_(environment_length) { }
867 : HControlInstruction(NULL, NULL),
868 values_(environment_length) { }
869 857
870 virtual Representation RequiredInputRepresentation(int index) const { 858 virtual Representation RequiredInputRepresentation(int index) const {
871 return Representation::None(); 859 return Representation::None();
872 } 860 }
873 861
874 virtual int OperandCount() { return values_.length(); } 862 virtual int OperandCount() { return values_.length(); }
875 virtual HValue* OperandAt(int index) { return values_[index]; } 863 virtual HValue* OperandAt(int index) { return values_[index]; }
876 virtual void PrintDataTo(StringStream* stream); 864 virtual void PrintDataTo(StringStream* stream);
877 865
866 virtual int SuccessorCount() { return 0; }
867 virtual HBasicBlock* SuccessorAt(int i) {
868 UNREACHABLE();
869 return NULL;
870 }
871
878 void AddEnvironmentValue(HValue* value) { 872 void AddEnvironmentValue(HValue* value) {
879 values_.Add(NULL); 873 values_.Add(NULL);
880 SetOperandAt(values_.length() - 1, value); 874 SetOperandAt(values_.length() - 1, value);
881 } 875 }
882 876
883 DECLARE_CONCRETE_INSTRUCTION(Deoptimize) 877 DECLARE_CONCRETE_INSTRUCTION(Deoptimize)
884 878
885 enum UseEnvironment { 879 enum UseEnvironment {
886 kNoUses, 880 kNoUses,
887 kUseAll 881 kUseAll
888 }; 882 };
889 883
890 protected: 884 protected:
891 virtual void InternalSetOperandAt(int index, HValue* value) { 885 virtual void InternalSetOperandAt(int index, HValue* value) {
892 values_[index] = value; 886 values_[index] = value;
893 } 887 }
894 888
895 private: 889 private:
896 ZoneList<HValue*> values_; 890 ZoneList<HValue*> values_;
897 }; 891 };
898 892
899 893
900 class HGoto: public HTemplateControlInstruction<0> { 894 class HGoto: public HTemplateControlInstruction<1, 0> {
901 public: 895 public:
902 explicit HGoto(HBasicBlock* target) 896 explicit HGoto(HBasicBlock* target)
903 : HTemplateControlInstruction<0>(target, NULL), 897 : include_stack_check_(false) {
904 include_stack_check_(false) { } 898 SetSuccessorAt(0, target);
899 }
905 900
906 void set_include_stack_check(bool include_stack_check) { 901 void set_include_stack_check(bool include_stack_check) {
907 include_stack_check_ = include_stack_check; 902 include_stack_check_ = include_stack_check;
908 } 903 }
909 bool include_stack_check() const { return include_stack_check_; } 904 bool include_stack_check() const { return include_stack_check_; }
910 905
911 virtual Representation RequiredInputRepresentation(int index) const { 906 virtual Representation RequiredInputRepresentation(int index) const {
912 return Representation::None(); 907 return Representation::None();
913 } 908 }
914 909
915 DECLARE_CONCRETE_INSTRUCTION(Goto) 910 DECLARE_CONCRETE_INSTRUCTION(Goto)
916 911
917 private: 912 private:
918 bool include_stack_check_; 913 bool include_stack_check_;
919 }; 914 };
920 915
921 916
922 class HUnaryControlInstruction: public HTemplateControlInstruction<1> { 917 class HUnaryControlInstruction: public HTemplateControlInstruction<2, 1> {
923 public: 918 public:
924 explicit HUnaryControlInstruction(HValue* value, 919 HUnaryControlInstruction(HValue* value,
925 HBasicBlock* true_target, 920 HBasicBlock* true_target,
926 HBasicBlock* false_target) 921 HBasicBlock* false_target) {
927 : HTemplateControlInstruction<1>(true_target, false_target) {
928 SetOperandAt(0, value); 922 SetOperandAt(0, value);
923 SetSuccessorAt(0, true_target);
924 SetSuccessorAt(1, false_target);
929 } 925 }
930 926
931 virtual void PrintDataTo(StringStream* stream); 927 virtual void PrintDataTo(StringStream* stream);
932 928
933 HValue* value() { return OperandAt(0); } 929 HValue* value() { return OperandAt(0); }
934 }; 930 };
935 931
936 932
937 class HTest: public HUnaryControlInstruction { 933 class HTest: public HUnaryControlInstruction {
938 public: 934 public:
(...skipping 31 matching lines...)
970 return Representation::Tagged(); 966 return Representation::Tagged();
971 } 967 }
972 968
973 DECLARE_CONCRETE_INSTRUCTION(CompareMap) 969 DECLARE_CONCRETE_INSTRUCTION(CompareMap)
974 970
975 private: 971 private:
976 Handle<Map> map_; 972 Handle<Map> map_;
977 }; 973 };
978 974
979 975
980 class HReturn: public HUnaryControlInstruction { 976 class HReturn: public HTemplateControlInstruction<0, 1> {
981 public: 977 public:
982 explicit HReturn(HValue* value) 978 explicit HReturn(HValue* value) {
983 : HUnaryControlInstruction(value, NULL, NULL) { 979 SetOperandAt(0, value);
984 } 980 }
985 981
986 virtual Representation RequiredInputRepresentation(int index) const { 982 virtual Representation RequiredInputRepresentation(int index) const {
987 return Representation::Tagged(); 983 return Representation::Tagged();
988 } 984 }
989 985
986 virtual void PrintDataTo(StringStream* stream);
987
988 HValue* value() { return OperandAt(0); }
989
990 DECLARE_CONCRETE_INSTRUCTION(Return) 990 DECLARE_CONCRETE_INSTRUCTION(Return)
991 }; 991 };
992 992
993 993
994 class HAbnormalExit: public HTemplateControlInstruction<0> { 994 class HAbnormalExit: public HTemplateControlInstruction<0, 0> {
995 public: 995 public:
996 HAbnormalExit() : HTemplateControlInstruction<0>(NULL, NULL) { }
997
998 virtual Representation RequiredInputRepresentation(int index) const { 996 virtual Representation RequiredInputRepresentation(int index) const {
999 return Representation::None(); 997 return Representation::None();
1000 } 998 }
1001 999
1002 DECLARE_CONCRETE_INSTRUCTION(AbnormalExit) 1000 DECLARE_CONCRETE_INSTRUCTION(AbnormalExit)
1003 }; 1001 };
1004 1002
1005 1003
1006 class HUnaryOperation: public HTemplateInstruction<1> { 1004 class HUnaryOperation: public HTemplateInstruction<1> {
1007 public: 1005 public:
(...skipping 3039 matching lines...)
4047 4045
4048 DECLARE_CONCRETE_INSTRUCTION(In) 4046 DECLARE_CONCRETE_INSTRUCTION(In)
4049 }; 4047 };
4050 4048
4051 #undef DECLARE_INSTRUCTION 4049 #undef DECLARE_INSTRUCTION
4052 #undef DECLARE_CONCRETE_INSTRUCTION 4050 #undef DECLARE_CONCRETE_INSTRUCTION
4053 4051
4054 } } // namespace v8::internal 4052 } } // namespace v8::internal
4055 4053
4056 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ 4054 #endif // V8_HYDROGEN_INSTRUCTIONS_H_
OLDNEW
« no previous file with comments | « src/hydrogen.cc ('k') | src/hydrogen-instructions.cc » ('j') | no next file with comments »

Powered by Google App Engine