Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 752 HInstruction* next_; | 752 HInstruction* next_; |
| 753 HInstruction* previous_; | 753 HInstruction* previous_; |
| 754 int position_; | 754 int position_; |
| 755 | 755 |
| 756 friend class HBasicBlock; | 756 friend class HBasicBlock; |
| 757 }; | 757 }; |
| 758 | 758 |
| 759 | 759 |
| 760 class HControlInstruction: public HInstruction { | 760 class HControlInstruction: public HInstruction { |
| 761 public: | 761 public: |
| 762 HControlInstruction(HBasicBlock* first, HBasicBlock* second) | 762 virtual HBasicBlock* SuccessorAt(int i) = 0; |
| 763 : first_successor_(first), second_successor_(second) { | 763 virtual int SuccessorCount() = 0; |
| 764 } | |
| 765 | |
| 766 HBasicBlock* FirstSuccessor() const { return first_successor_; } | |
| 767 HBasicBlock* SecondSuccessor() const { return second_successor_; } | |
| 768 | 764 |
| 769 virtual void PrintDataTo(StringStream* stream); | 765 virtual void PrintDataTo(StringStream* stream); |
| 770 | 766 |
| 767 HBasicBlock* FirstSuccessor() { | |
| 768 return SuccessorCount() > 0 ? SuccessorAt(0) : NULL; | |
| 769 } | |
| 770 HBasicBlock* SecondSuccessor() { | |
| 771 return SuccessorCount() > 1 ? SuccessorAt(1) : NULL; | |
| 772 } | |
| 773 | |
| 771 DECLARE_ABSTRACT_INSTRUCTION(ControlInstruction) | 774 DECLARE_ABSTRACT_INSTRUCTION(ControlInstruction) |
| 772 | |
| 773 private: | |
| 774 HBasicBlock* first_successor_; | |
| 775 HBasicBlock* second_successor_; | |
| 776 }; | 775 }; |
| 777 | 776 |
| 778 | 777 |
| 779 template<int NumElements> | 778 class HSuccessorIterator BASE_EMBEDDED { |
| 780 class HOperandContainer { | |
| 781 public: | 779 public: |
| 782 HOperandContainer() : elems_() { } | 780 explicit HSuccessorIterator(HControlInstruction* instr) |
| 781 : instr_(instr), next_(0) { } | |
| 782 | |
| 783 bool HasNext() { return next_ < instr_->SuccessorCount(); } | |
| 784 HBasicBlock* Next() { return instr_->SuccessorAt(next_); } | |
| 785 void Advance() { next_++; } | |
| 786 | |
| 787 private: | |
| 788 HControlInstruction* instr_; | |
| 789 int next_; | |
| 790 }; | |
| 791 | |
| 792 | |
| 793 template<typename T, int NumElements> | |
|
Kevin Millikin (Chromium)
2011/05/25 15:50:28
We have more or less this class "OperandContainer"
| |
| 794 class Container { | |
| 795 public: | |
| 796 Container() : elems_() { } | |
| 783 | 797 |
| 784 int length() { return NumElements; } | 798 int length() { return NumElements; } |
| 785 HValue*& operator[](int i) { | 799 T& operator[](int i) { |
| 786 ASSERT(i < length()); | 800 ASSERT(i < length()); |
| 787 return elems_[i]; | 801 return elems_[i]; |
| 788 } | 802 } |
| 789 | 803 |
| 790 private: | 804 private: |
| 791 HValue* elems_[NumElements]; | 805 T elems_[NumElements]; |
| 792 }; | 806 }; |
| 793 | 807 |
| 794 | 808 |
| 795 template<> | 809 template<typename T> |
| 796 class HOperandContainer<0> { | 810 class Container<T, 0> { |
| 797 public: | 811 public: |
| 798 int length() { return 0; } | 812 int length() { return 0; } |
| 799 HValue*& operator[](int i) { | 813 T& operator[](int i) { |
| 800 UNREACHABLE(); | 814 UNREACHABLE(); |
| 801 static HValue* t = 0; | 815 static T t = 0; |
| 802 return t; | 816 return t; |
| 803 } | 817 } |
| 804 }; | 818 }; |
| 805 | 819 |
| 806 | 820 |
| 807 template<int V> | 821 template<int V> |
| 808 class HTemplateInstruction : public HInstruction { | 822 class HTemplateInstruction : public HInstruction { |
| 809 public: | 823 public: |
| 810 int OperandCount() { return V; } | 824 int OperandCount() { return V; } |
| 811 HValue* OperandAt(int i) { return inputs_[i]; } | 825 HValue* OperandAt(int i) { return inputs_[i]; } |
| 812 | 826 |
| 813 protected: | 827 protected: |
| 814 void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } | 828 void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } |
| 815 | 829 |
| 816 private: | 830 private: |
| 817 HOperandContainer<V> inputs_; | 831 Container<HValue*, V> inputs_; |
| 818 }; | 832 }; |
| 819 | 833 |
| 820 | 834 |
| 821 template<int V> | 835 template<int S, int V> |
| 822 class HTemplateControlInstruction : public HControlInstruction { | 836 class HTemplateControlInstruction : public HControlInstruction { |
| 823 public: | 837 public: |
| 824 HTemplateControlInstruction<V>(HBasicBlock* first, HBasicBlock* second) | |
| 825 : HControlInstruction(first, second) { } | |
| 826 int OperandCount() { return V; } | 838 int OperandCount() { return V; } |
| 827 HValue* OperandAt(int i) { return inputs_[i]; } | 839 HValue* OperandAt(int i) { return inputs_[i]; } |
| 828 | 840 |
| 841 int SuccessorCount() { return S; } | |
| 842 HBasicBlock* SuccessorAt(int i) { return successors_[i]; } | |
| 843 | |
| 829 protected: | 844 protected: |
| 830 void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } | 845 void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } |
| 846 void SetSuccessorAt(int i, HBasicBlock* block) { successors_[i] = block; } | |
| 831 | 847 |
| 832 private: | 848 private: |
| 833 HOperandContainer<V> inputs_; | 849 Container<HBasicBlock*, S> successors_; |
| 850 Container<HValue*, V> inputs_; | |
| 834 }; | 851 }; |
| 835 | 852 |
| 836 | 853 |
| 837 class HBlockEntry: public HTemplateInstruction<0> { | 854 class HBlockEntry: public HTemplateInstruction<0> { |
| 838 public: | 855 public: |
| 839 virtual Representation RequiredInputRepresentation(int index) const { | 856 virtual Representation RequiredInputRepresentation(int index) const { |
| 840 return Representation::None(); | 857 return Representation::None(); |
| 841 } | 858 } |
| 842 | 859 |
| 843 DECLARE_CONCRETE_INSTRUCTION(BlockEntry) | 860 DECLARE_CONCRETE_INSTRUCTION(BlockEntry) |
| 844 }; | 861 }; |
| 845 | 862 |
| 846 | 863 |
| 847 class HDeoptimize: public HControlInstruction { | 864 class HDeoptimize: public HControlInstruction { |
| 848 public: | 865 public: |
| 849 explicit HDeoptimize(int environment_length) | 866 explicit HDeoptimize(int environment_length) : values_(environment_length) { } |
| 850 : HControlInstruction(NULL, NULL), | |
| 851 values_(environment_length) { } | |
| 852 | 867 |
| 853 virtual Representation RequiredInputRepresentation(int index) const { | 868 virtual Representation RequiredInputRepresentation(int index) const { |
| 854 return Representation::None(); | 869 return Representation::None(); |
| 855 } | 870 } |
| 856 | 871 |
| 857 virtual int OperandCount() { return values_.length(); } | 872 virtual int OperandCount() { return values_.length(); } |
| 858 virtual HValue* OperandAt(int index) { return values_[index]; } | 873 virtual HValue* OperandAt(int index) { return values_[index]; } |
| 859 | 874 |
| 875 virtual int SuccessorCount() { return 0; } | |
| 876 virtual HBasicBlock* SuccessorAt(int i) { | |
| 877 UNREACHABLE(); | |
| 878 return NULL; | |
| 879 } | |
| 880 | |
| 860 void AddEnvironmentValue(HValue* value) { | 881 void AddEnvironmentValue(HValue* value) { |
| 861 values_.Add(NULL); | 882 values_.Add(NULL); |
| 862 SetOperandAt(values_.length() - 1, value); | 883 SetOperandAt(values_.length() - 1, value); |
| 863 } | 884 } |
| 864 | 885 |
| 865 DECLARE_CONCRETE_INSTRUCTION(Deoptimize) | 886 DECLARE_CONCRETE_INSTRUCTION(Deoptimize) |
| 866 | 887 |
| 867 enum UseEnvironment { | 888 enum UseEnvironment { |
| 868 kNoUses, | 889 kNoUses, |
| 869 kUseAll | 890 kUseAll |
| 870 }; | 891 }; |
| 871 | 892 |
| 872 protected: | 893 protected: |
| 873 virtual void InternalSetOperandAt(int index, HValue* value) { | 894 virtual void InternalSetOperandAt(int index, HValue* value) { |
| 874 values_[index] = value; | 895 values_[index] = value; |
| 875 } | 896 } |
| 876 | 897 |
| 877 private: | 898 private: |
| 878 ZoneList<HValue*> values_; | 899 ZoneList<HValue*> values_; |
| 879 }; | 900 }; |
| 880 | 901 |
| 881 | 902 |
| 882 class HGoto: public HTemplateControlInstruction<0> { | 903 class HGoto: public HTemplateControlInstruction<1, 0> { |
| 883 public: | 904 public: |
| 884 explicit HGoto(HBasicBlock* target) | 905 explicit HGoto(HBasicBlock* target) |
| 885 : HTemplateControlInstruction<0>(target, NULL), | 906 : include_stack_check_(false) { |
| 886 include_stack_check_(false) { } | 907 SetSuccessorAt(0, target); |
| 908 } | |
| 887 | 909 |
| 888 void set_include_stack_check(bool include_stack_check) { | 910 void set_include_stack_check(bool include_stack_check) { |
| 889 include_stack_check_ = include_stack_check; | 911 include_stack_check_ = include_stack_check; |
| 890 } | 912 } |
| 891 bool include_stack_check() const { return include_stack_check_; } | 913 bool include_stack_check() const { return include_stack_check_; } |
| 892 | 914 |
| 893 virtual Representation RequiredInputRepresentation(int index) const { | 915 virtual Representation RequiredInputRepresentation(int index) const { |
| 894 return Representation::None(); | 916 return Representation::None(); |
| 895 } | 917 } |
| 896 | 918 |
| 897 DECLARE_CONCRETE_INSTRUCTION(Goto) | 919 DECLARE_CONCRETE_INSTRUCTION(Goto) |
| 898 | 920 |
| 899 private: | 921 private: |
| 900 bool include_stack_check_; | 922 bool include_stack_check_; |
| 901 }; | 923 }; |
| 902 | 924 |
| 903 | 925 |
| 904 class HUnaryControlInstruction: public HTemplateControlInstruction<1> { | 926 class HUnaryControlInstruction: public HTemplateControlInstruction<2, 1> { |
| 905 public: | 927 public: |
| 906 explicit HUnaryControlInstruction(HValue* value, | 928 explicit HUnaryControlInstruction(HValue* value, |
| 907 HBasicBlock* true_target, | 929 HBasicBlock* true_target, |
| 908 HBasicBlock* false_target) | 930 HBasicBlock* false_target) { |
| 909 : HTemplateControlInstruction<1>(true_target, false_target) { | |
| 910 SetOperandAt(0, value); | 931 SetOperandAt(0, value); |
| 932 SetSuccessorAt(0, true_target); | |
| 933 SetSuccessorAt(1, false_target); | |
| 911 } | 934 } |
| 912 | 935 |
| 913 virtual void PrintDataTo(StringStream* stream); | 936 virtual void PrintDataTo(StringStream* stream); |
| 914 | 937 |
| 915 HValue* value() { return OperandAt(0); } | 938 HValue* value() { return OperandAt(0); } |
| 916 }; | 939 }; |
| 917 | 940 |
| 918 | 941 |
| 919 class HTest: public HUnaryControlInstruction { | 942 class HTest: public HUnaryControlInstruction { |
| 920 public: | 943 public: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 return Representation::Tagged(); | 975 return Representation::Tagged(); |
| 953 } | 976 } |
| 954 | 977 |
| 955 DECLARE_CONCRETE_INSTRUCTION(CompareMap) | 978 DECLARE_CONCRETE_INSTRUCTION(CompareMap) |
| 956 | 979 |
| 957 private: | 980 private: |
| 958 Handle<Map> map_; | 981 Handle<Map> map_; |
| 959 }; | 982 }; |
| 960 | 983 |
| 961 | 984 |
| 962 class HReturn: public HUnaryControlInstruction { | 985 class HReturn: public HTemplateControlInstruction<0, 1> { |
| 963 public: | 986 public: |
| 964 explicit HReturn(HValue* value) | 987 explicit HReturn(HValue* value) { |
| 965 : HUnaryControlInstruction(value, NULL, NULL) { | 988 SetOperandAt(0, value); |
| 966 } | 989 } |
| 967 | 990 |
| 968 virtual Representation RequiredInputRepresentation(int index) const { | 991 virtual Representation RequiredInputRepresentation(int index) const { |
| 969 return Representation::Tagged(); | 992 return Representation::Tagged(); |
| 970 } | 993 } |
| 971 | 994 |
| 995 HValue* value() { return OperandAt(0); } | |
| 996 | |
| 972 DECLARE_CONCRETE_INSTRUCTION(Return) | 997 DECLARE_CONCRETE_INSTRUCTION(Return) |
| 973 }; | 998 }; |
| 974 | 999 |
| 975 | 1000 |
| 976 class HAbnormalExit: public HTemplateControlInstruction<0> { | 1001 class HAbnormalExit: public HTemplateControlInstruction<0, 0> { |
| 977 public: | 1002 public: |
| 978 HAbnormalExit() : HTemplateControlInstruction<0>(NULL, NULL) { } | |
| 979 | |
| 980 virtual Representation RequiredInputRepresentation(int index) const { | 1003 virtual Representation RequiredInputRepresentation(int index) const { |
| 981 return Representation::None(); | 1004 return Representation::None(); |
| 982 } | 1005 } |
| 983 | 1006 |
| 984 DECLARE_CONCRETE_INSTRUCTION(AbnormalExit) | 1007 DECLARE_CONCRETE_INSTRUCTION(AbnormalExit) |
| 985 }; | 1008 }; |
| 986 | 1009 |
| 987 | 1010 |
| 988 class HUnaryOperation: public HTemplateInstruction<1> { | 1011 class HUnaryOperation: public HTemplateInstruction<1> { |
| 989 public: | 1012 public: |
| (...skipping 2972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3962 | 3985 |
| 3963 DECLARE_CONCRETE_INSTRUCTION(In) | 3986 DECLARE_CONCRETE_INSTRUCTION(In) |
| 3964 }; | 3987 }; |
| 3965 | 3988 |
| 3966 #undef DECLARE_INSTRUCTION | 3989 #undef DECLARE_INSTRUCTION |
| 3967 #undef DECLARE_CONCRETE_INSTRUCTION | 3990 #undef DECLARE_CONCRETE_INSTRUCTION |
| 3968 | 3991 |
| 3969 } } // namespace v8::internal | 3992 } } // namespace v8::internal |
| 3970 | 3993 |
| 3971 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ | 3994 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ |
| OLD | NEW |