| 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 17 matching lines...) Expand all Loading... |
| 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 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 void PrintMnemonicTo(StringStream* stream); | 751 void PrintMnemonicTo(StringStream* stream); |
| 751 | 752 |
| 752 HInstruction* next_; | 753 HInstruction* next_; |
| 753 HInstruction* previous_; | 754 HInstruction* previous_; |
| 754 int position_; | 755 int position_; |
| 755 | 756 |
| 756 friend class HBasicBlock; | 757 friend class HBasicBlock; |
| 757 }; | 758 }; |
| 758 | 759 |
| 759 | 760 |
| 760 class HControlInstruction: public HInstruction { | |
| 761 public: | |
| 762 HControlInstruction(HBasicBlock* first, HBasicBlock* second) | |
| 763 : first_successor_(first), second_successor_(second) { | |
| 764 } | |
| 765 | |
| 766 HBasicBlock* FirstSuccessor() const { return first_successor_; } | |
| 767 HBasicBlock* SecondSuccessor() const { return second_successor_; } | |
| 768 | |
| 769 virtual void PrintDataTo(StringStream* stream); | |
| 770 | |
| 771 DECLARE_ABSTRACT_INSTRUCTION(ControlInstruction) | |
| 772 | |
| 773 private: | |
| 774 HBasicBlock* first_successor_; | |
| 775 HBasicBlock* second_successor_; | |
| 776 }; | |
| 777 | |
| 778 | |
| 779 template<int NumElements> | |
| 780 class HOperandContainer { | |
| 781 public: | |
| 782 HOperandContainer() : elems_() { } | |
| 783 | |
| 784 int length() { return NumElements; } | |
| 785 HValue*& operator[](int i) { | |
| 786 ASSERT(i < length()); | |
| 787 return elems_[i]; | |
| 788 } | |
| 789 | |
| 790 private: | |
| 791 HValue* elems_[NumElements]; | |
| 792 }; | |
| 793 | |
| 794 | |
| 795 template<> | |
| 796 class HOperandContainer<0> { | |
| 797 public: | |
| 798 int length() { return 0; } | |
| 799 HValue*& operator[](int i) { | |
| 800 UNREACHABLE(); | |
| 801 static HValue* t = 0; | |
| 802 return t; | |
| 803 } | |
| 804 }; | |
| 805 | |
| 806 | |
| 807 template<int V> | 761 template<int V> |
| 808 class HTemplateInstruction : public HInstruction { | 762 class HTemplateInstruction : public HInstruction { |
| 809 public: | 763 public: |
| 810 int OperandCount() { return V; } | 764 int OperandCount() { return V; } |
| 811 HValue* OperandAt(int i) { return inputs_[i]; } | 765 HValue* OperandAt(int i) { return inputs_[i]; } |
| 812 | 766 |
| 813 protected: | 767 protected: |
| 814 void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } | 768 void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } |
| 815 | 769 |
| 816 private: | 770 private: |
| 817 HOperandContainer<V> inputs_; | 771 EmbeddedContainer<HValue*, V> inputs_; |
| 818 }; | 772 }; |
| 819 | 773 |
| 820 | 774 |
| 821 template<int V> | 775 class HControlInstruction: public HInstruction { |
| 822 class HTemplateControlInstruction : public HControlInstruction { | |
| 823 public: | 776 public: |
| 824 HTemplateControlInstruction<V>(HBasicBlock* first, HBasicBlock* second) | 777 virtual HBasicBlock* SuccessorAt(int i) = 0; |
| 825 : HControlInstruction(first, second) { } | 778 virtual int SuccessorCount() = 0; |
| 779 |
| 780 virtual void PrintDataTo(StringStream* stream); |
| 781 |
| 782 HBasicBlock* FirstSuccessor() { |
| 783 return SuccessorCount() > 0 ? SuccessorAt(0) : NULL; |
| 784 } |
| 785 HBasicBlock* SecondSuccessor() { |
| 786 return SuccessorCount() > 1 ? SuccessorAt(1) : NULL; |
| 787 } |
| 788 |
| 789 DECLARE_ABSTRACT_INSTRUCTION(ControlInstruction) |
| 790 }; |
| 791 |
| 792 |
| 793 class HSuccessorIterator BASE_EMBEDDED { |
| 794 public: |
| 795 explicit HSuccessorIterator(HControlInstruction* instr) |
| 796 : instr_(instr), current_(0) { } |
| 797 |
| 798 bool Done() { return current_ >= instr_->SuccessorCount(); } |
| 799 HBasicBlock* Current() { return instr_->SuccessorAt(current_); } |
| 800 void Advance() { current_++; } |
| 801 |
| 802 private: |
| 803 HControlInstruction* instr_; |
| 804 int current_; |
| 805 }; |
| 806 |
| 807 |
| 808 template<int S, int V> |
| 809 class HTemplateControlInstruction: public HControlInstruction { |
| 810 public: |
| 811 int SuccessorCount() { return S; } |
| 812 HBasicBlock* SuccessorAt(int i) { return successors_[i]; } |
| 813 |
| 826 int OperandCount() { return V; } | 814 int OperandCount() { return V; } |
| 827 HValue* OperandAt(int i) { return inputs_[i]; } | 815 HValue* OperandAt(int i) { return inputs_[i]; } |
| 828 | 816 |
| 829 protected: | 817 protected: |
| 818 void SetSuccessorAt(int i, HBasicBlock* block) { successors_[i] = block; } |
| 830 void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } | 819 void InternalSetOperandAt(int i, HValue* value) { inputs_[i] = value; } |
| 831 | 820 |
| 832 private: | 821 private: |
| 833 HOperandContainer<V> inputs_; | 822 EmbeddedContainer<HBasicBlock*, S> successors_; |
| 823 EmbeddedContainer<HValue*, V> inputs_; |
| 834 }; | 824 }; |
| 835 | 825 |
| 836 | 826 |
| 837 class HBlockEntry: public HTemplateInstruction<0> { | 827 class HBlockEntry: public HTemplateInstruction<0> { |
| 838 public: | 828 public: |
| 839 virtual Representation RequiredInputRepresentation(int index) const { | 829 virtual Representation RequiredInputRepresentation(int index) const { |
| 840 return Representation::None(); | 830 return Representation::None(); |
| 841 } | 831 } |
| 842 | 832 |
| 843 DECLARE_CONCRETE_INSTRUCTION(BlockEntry) | 833 DECLARE_CONCRETE_INSTRUCTION(BlockEntry) |
| 844 }; | 834 }; |
| 845 | 835 |
| 846 | 836 |
| 847 // We insert soft-deoptimize when we hit code with unknown typefeedback, | 837 // We insert soft-deoptimize when we hit code with unknown typefeedback, |
| 848 // so that we get a chance of re-optimizing with useful typefeedback. | 838 // so that we get a chance of re-optimizing with useful typefeedback. |
| 849 // HSoftDeoptimize does not end a basic block as opposed to HDeoptimize. | 839 // HSoftDeoptimize does not end a basic block as opposed to HDeoptimize. |
| 850 class HSoftDeoptimize: public HTemplateInstruction<0> { | 840 class HSoftDeoptimize: public HTemplateInstruction<0> { |
| 851 public: | 841 public: |
| 852 virtual Representation RequiredInputRepresentation(int index) const { | 842 virtual Representation RequiredInputRepresentation(int index) const { |
| 853 return Representation::None(); | 843 return Representation::None(); |
| 854 } | 844 } |
| 855 | 845 |
| 856 DECLARE_CONCRETE_INSTRUCTION(SoftDeoptimize) | 846 DECLARE_CONCRETE_INSTRUCTION(SoftDeoptimize) |
| 857 }; | 847 }; |
| 858 | 848 |
| 859 | 849 |
| 860 class HDeoptimize: public HControlInstruction { | 850 class HDeoptimize: public HControlInstruction { |
| 861 public: | 851 public: |
| 862 explicit HDeoptimize(int environment_length) | 852 explicit HDeoptimize(int environment_length) : values_(environment_length) { } |
| 863 : HControlInstruction(NULL, NULL), | |
| 864 values_(environment_length) { } | |
| 865 | 853 |
| 866 virtual Representation RequiredInputRepresentation(int index) const { | 854 virtual Representation RequiredInputRepresentation(int index) const { |
| 867 return Representation::None(); | 855 return Representation::None(); |
| 868 } | 856 } |
| 869 | 857 |
| 870 virtual int OperandCount() { return values_.length(); } | 858 virtual int OperandCount() { return values_.length(); } |
| 871 virtual HValue* OperandAt(int index) { return values_[index]; } | 859 virtual HValue* OperandAt(int index) { return values_[index]; } |
| 872 virtual void PrintDataTo(StringStream* stream); | 860 virtual void PrintDataTo(StringStream* stream); |
| 873 | 861 |
| 862 virtual int SuccessorCount() { return 0; } |
| 863 virtual HBasicBlock* SuccessorAt(int i) { |
| 864 UNREACHABLE(); |
| 865 return NULL; |
| 866 } |
| 867 |
| 874 void AddEnvironmentValue(HValue* value) { | 868 void AddEnvironmentValue(HValue* value) { |
| 875 values_.Add(NULL); | 869 values_.Add(NULL); |
| 876 SetOperandAt(values_.length() - 1, value); | 870 SetOperandAt(values_.length() - 1, value); |
| 877 } | 871 } |
| 878 | 872 |
| 879 DECLARE_CONCRETE_INSTRUCTION(Deoptimize) | 873 DECLARE_CONCRETE_INSTRUCTION(Deoptimize) |
| 880 | 874 |
| 881 enum UseEnvironment { | 875 enum UseEnvironment { |
| 882 kNoUses, | 876 kNoUses, |
| 883 kUseAll | 877 kUseAll |
| 884 }; | 878 }; |
| 885 | 879 |
| 886 protected: | 880 protected: |
| 887 virtual void InternalSetOperandAt(int index, HValue* value) { | 881 virtual void InternalSetOperandAt(int index, HValue* value) { |
| 888 values_[index] = value; | 882 values_[index] = value; |
| 889 } | 883 } |
| 890 | 884 |
| 891 private: | 885 private: |
| 892 ZoneList<HValue*> values_; | 886 ZoneList<HValue*> values_; |
| 893 }; | 887 }; |
| 894 | 888 |
| 895 | 889 |
| 896 class HGoto: public HTemplateControlInstruction<0> { | 890 class HGoto: public HTemplateControlInstruction<1, 0> { |
| 897 public: | 891 public: |
| 898 explicit HGoto(HBasicBlock* target) | 892 explicit HGoto(HBasicBlock* target) |
| 899 : HTemplateControlInstruction<0>(target, NULL), | 893 : include_stack_check_(false) { |
| 900 include_stack_check_(false) { } | 894 SetSuccessorAt(0, target); |
| 895 } |
| 901 | 896 |
| 902 void set_include_stack_check(bool include_stack_check) { | 897 void set_include_stack_check(bool include_stack_check) { |
| 903 include_stack_check_ = include_stack_check; | 898 include_stack_check_ = include_stack_check; |
| 904 } | 899 } |
| 905 bool include_stack_check() const { return include_stack_check_; } | 900 bool include_stack_check() const { return include_stack_check_; } |
| 906 | 901 |
| 907 virtual Representation RequiredInputRepresentation(int index) const { | 902 virtual Representation RequiredInputRepresentation(int index) const { |
| 908 return Representation::None(); | 903 return Representation::None(); |
| 909 } | 904 } |
| 910 | 905 |
| 911 DECLARE_CONCRETE_INSTRUCTION(Goto) | 906 DECLARE_CONCRETE_INSTRUCTION(Goto) |
| 912 | 907 |
| 913 private: | 908 private: |
| 914 bool include_stack_check_; | 909 bool include_stack_check_; |
| 915 }; | 910 }; |
| 916 | 911 |
| 917 | 912 |
| 918 class HUnaryControlInstruction: public HTemplateControlInstruction<1> { | 913 class HUnaryControlInstruction: public HTemplateControlInstruction<2, 1> { |
| 919 public: | 914 public: |
| 920 explicit HUnaryControlInstruction(HValue* value, | 915 HUnaryControlInstruction(HValue* value, |
| 921 HBasicBlock* true_target, | 916 HBasicBlock* true_target, |
| 922 HBasicBlock* false_target) | 917 HBasicBlock* false_target) { |
| 923 : HTemplateControlInstruction<1>(true_target, false_target) { | |
| 924 SetOperandAt(0, value); | 918 SetOperandAt(0, value); |
| 919 SetSuccessorAt(0, true_target); |
| 920 SetSuccessorAt(1, false_target); |
| 925 } | 921 } |
| 926 | 922 |
| 927 virtual void PrintDataTo(StringStream* stream); | 923 virtual void PrintDataTo(StringStream* stream); |
| 928 | 924 |
| 929 HValue* value() { return OperandAt(0); } | 925 HValue* value() { return OperandAt(0); } |
| 930 }; | 926 }; |
| 931 | 927 |
| 932 | 928 |
| 933 class HTest: public HUnaryControlInstruction { | 929 class HTest: public HUnaryControlInstruction { |
| 934 public: | 930 public: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 return Representation::Tagged(); | 962 return Representation::Tagged(); |
| 967 } | 963 } |
| 968 | 964 |
| 969 DECLARE_CONCRETE_INSTRUCTION(CompareMap) | 965 DECLARE_CONCRETE_INSTRUCTION(CompareMap) |
| 970 | 966 |
| 971 private: | 967 private: |
| 972 Handle<Map> map_; | 968 Handle<Map> map_; |
| 973 }; | 969 }; |
| 974 | 970 |
| 975 | 971 |
| 976 class HReturn: public HUnaryControlInstruction { | 972 class HReturn: public HTemplateControlInstruction<0, 1> { |
| 977 public: | 973 public: |
| 978 explicit HReturn(HValue* value) | 974 explicit HReturn(HValue* value) { |
| 979 : HUnaryControlInstruction(value, NULL, NULL) { | 975 SetOperandAt(0, value); |
| 980 } | 976 } |
| 981 | 977 |
| 982 virtual Representation RequiredInputRepresentation(int index) const { | 978 virtual Representation RequiredInputRepresentation(int index) const { |
| 983 return Representation::Tagged(); | 979 return Representation::Tagged(); |
| 984 } | 980 } |
| 985 | 981 |
| 982 virtual void PrintDataTo(StringStream* stream); |
| 983 |
| 984 HValue* value() { return OperandAt(0); } |
| 985 |
| 986 DECLARE_CONCRETE_INSTRUCTION(Return) | 986 DECLARE_CONCRETE_INSTRUCTION(Return) |
| 987 }; | 987 }; |
| 988 | 988 |
| 989 | 989 |
| 990 class HAbnormalExit: public HTemplateControlInstruction<0> { | 990 class HAbnormalExit: public HTemplateControlInstruction<0, 0> { |
| 991 public: | 991 public: |
| 992 HAbnormalExit() : HTemplateControlInstruction<0>(NULL, NULL) { } | |
| 993 | |
| 994 virtual Representation RequiredInputRepresentation(int index) const { | 992 virtual Representation RequiredInputRepresentation(int index) const { |
| 995 return Representation::None(); | 993 return Representation::None(); |
| 996 } | 994 } |
| 997 | 995 |
| 998 DECLARE_CONCRETE_INSTRUCTION(AbnormalExit) | 996 DECLARE_CONCRETE_INSTRUCTION(AbnormalExit) |
| 999 }; | 997 }; |
| 1000 | 998 |
| 1001 | 999 |
| 1002 class HUnaryOperation: public HTemplateInstruction<1> { | 1000 class HUnaryOperation: public HTemplateInstruction<1> { |
| 1003 public: | 1001 public: |
| (...skipping 3034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4038 | 4036 |
| 4039 DECLARE_CONCRETE_INSTRUCTION(In) | 4037 DECLARE_CONCRETE_INSTRUCTION(In) |
| 4040 }; | 4038 }; |
| 4041 | 4039 |
| 4042 #undef DECLARE_INSTRUCTION | 4040 #undef DECLARE_INSTRUCTION |
| 4043 #undef DECLARE_CONCRETE_INSTRUCTION | 4041 #undef DECLARE_CONCRETE_INSTRUCTION |
| 4044 | 4042 |
| 4045 } } // namespace v8::internal | 4043 } } // namespace v8::internal |
| 4046 | 4044 |
| 4047 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ | 4045 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ |
| OLD | NEW |