OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ | 5 #ifndef VM_INTERMEDIATE_LANGUAGE_H_ |
6 #define VM_INTERMEDIATE_LANGUAGE_H_ | 6 #define VM_INTERMEDIATE_LANGUAGE_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 M(CatchEntry, CatchEntryComp) \ | 96 M(CatchEntry, CatchEntryComp) \ |
97 M(BinarySmiOp, BinarySmiOpComp) \ | 97 M(BinarySmiOp, BinarySmiOpComp) \ |
98 M(BinaryMintOp, BinaryMintOpComp) \ | 98 M(BinaryMintOp, BinaryMintOpComp) \ |
99 M(BinaryDoubleOp, BinaryDoubleOpComp) \ | 99 M(BinaryDoubleOp, BinaryDoubleOpComp) \ |
100 M(UnarySmiOp, UnarySmiOpComp) \ | 100 M(UnarySmiOp, UnarySmiOpComp) \ |
101 M(NumberNegate, NumberNegateComp) \ | 101 M(NumberNegate, NumberNegateComp) \ |
102 M(CheckStackOverflow, CheckStackOverflowComp) \ | 102 M(CheckStackOverflow, CheckStackOverflowComp) \ |
103 M(DoubleToDouble, DoubleToDoubleComp) \ | 103 M(DoubleToDouble, DoubleToDoubleComp) \ |
104 M(SmiToDouble, SmiToDoubleComp) \ | 104 M(SmiToDouble, SmiToDoubleComp) \ |
105 M(CheckClass, CheckClassComp) \ | 105 M(CheckClass, CheckClassComp) \ |
106 M(CheckSmi, CheckSmiComp) \ | |
106 M(Materialize, MaterializeComp) | 107 M(Materialize, MaterializeComp) |
107 | 108 |
108 | 109 |
109 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; | 110 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; |
110 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) | 111 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) |
111 FOR_EACH_VALUE(FORWARD_DECLARATION) | 112 FOR_EACH_VALUE(FORWARD_DECLARATION) |
112 #undef FORWARD_DECLARATION | 113 #undef FORWARD_DECLARATION |
113 | 114 |
114 // Forward declarations. | 115 // Forward declarations. |
115 class BindInstr; | 116 class BindInstr; |
(...skipping 29 matching lines...) Expand all Loading... | |
145 virtual Value* InputAt(intptr_t i) const = 0; | 146 virtual Value* InputAt(intptr_t i) const = 0; |
146 virtual void SetInputAt(intptr_t i, Value* value) = 0; | 147 virtual void SetInputAt(intptr_t i, Value* value) = 0; |
147 | 148 |
148 // Call computations override this function and return the | 149 // Call computations override this function and return the |
149 // number of pushed arguments. | 150 // number of pushed arguments. |
150 virtual intptr_t ArgumentCount() const = 0; | 151 virtual intptr_t ArgumentCount() const = 0; |
151 | 152 |
152 // Returns true, if this computation can deoptimize. | 153 // Returns true, if this computation can deoptimize. |
153 virtual bool CanDeoptimize() const = 0; | 154 virtual bool CanDeoptimize() const = 0; |
154 | 155 |
155 // Optimize this computation. Returns a replacement for the instruction | 156 // Returns a replacement for the instruction that wraps this computation. |
156 // that wraps this computation or NULL if nothing to replace. | 157 // By default return its input parameter (no replacement). |
srdjan
2012/08/22 15:56:51
'its input parameter' is not that clear to me. I t
Florian Schneider
2012/08/23 07:53:15
I changed the comment. The old behaviour was that
| |
157 virtual Definition* TryReplace(BindInstr* instr) { return NULL; } | 158 // Returns NULL if instr can be eliminated. |
159 virtual Definition* TryReplace(BindInstr* instr) const; | |
158 | 160 |
159 // Compares two computations. Returns true, if: | 161 // Compares two computations. Returns true, if: |
160 // 1. They are of the same kind. | 162 // 1. They are of the same kind. |
161 // 2. All input operands match. | 163 // 2. All input operands match. |
162 // 3. All other attributes match. | 164 // 3. All other attributes match. |
163 bool Equals(Computation* other) const; | 165 bool Equals(Computation* other) const; |
164 | 166 |
165 // Returns a hash code for use with hash maps. | 167 // Returns a hash code for use with hash maps. |
166 virtual intptr_t Hashcode() const; | 168 virtual intptr_t Hashcode() const; |
167 | 169 |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 : ComparisonComp(kind, left, right) { | 767 : ComparisonComp(kind, left, right) { |
766 ASSERT((kind == Token::kEQ_STRICT) || (kind == Token::kNE_STRICT)); | 768 ASSERT((kind == Token::kEQ_STRICT) || (kind == Token::kNE_STRICT)); |
767 } | 769 } |
768 | 770 |
769 DECLARE_COMPUTATION(StrictCompare) | 771 DECLARE_COMPUTATION(StrictCompare) |
770 | 772 |
771 virtual void PrintOperandsTo(BufferFormatter* f) const; | 773 virtual void PrintOperandsTo(BufferFormatter* f) const; |
772 | 774 |
773 virtual bool CanDeoptimize() const { return false; } | 775 virtual bool CanDeoptimize() const { return false; } |
774 | 776 |
775 virtual Definition* TryReplace(BindInstr* instr); | 777 virtual Definition* TryReplace(BindInstr* instr) const; |
778 | |
776 virtual intptr_t ResultCid() const { return kBoolCid; } | 779 virtual intptr_t ResultCid() const { return kBoolCid; } |
777 | 780 |
778 private: | 781 private: |
779 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp); | 782 DISALLOW_COPY_AND_ASSIGN(StrictCompareComp); |
780 }; | 783 }; |
781 | 784 |
782 | 785 |
783 class EqualityCompareComp : public ComparisonComp { | 786 class EqualityCompareComp : public ComparisonComp { |
784 public: | 787 public: |
785 EqualityCompareComp(intptr_t token_pos, | 788 EqualityCompareComp(intptr_t token_pos, |
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1883 | 1886 |
1884 virtual bool AttributesEqual(Computation* other) const; | 1887 virtual bool AttributesEqual(Computation* other) const; |
1885 | 1888 |
1886 virtual bool HasSideEffect() const { return false; } | 1889 virtual bool HasSideEffect() const { return false; } |
1887 | 1890 |
1888 Value* value() const { return inputs_[0]; } | 1891 Value* value() const { return inputs_[0]; } |
1889 | 1892 |
1890 intptr_t deopt_id() const { return original_->deopt_id(); } | 1893 intptr_t deopt_id() const { return original_->deopt_id(); } |
1891 intptr_t try_index() const { return original_->try_index(); } | 1894 intptr_t try_index() const { return original_->try_index(); } |
1892 | 1895 |
1896 virtual void PrintOperandsTo(BufferFormatter* f) const; | |
1897 | |
1893 private: | 1898 private: |
1894 InstanceCallComp* original_; | 1899 InstanceCallComp* original_; |
1895 | 1900 |
1896 DISALLOW_COPY_AND_ASSIGN(CheckClassComp); | 1901 DISALLOW_COPY_AND_ASSIGN(CheckClassComp); |
1897 }; | 1902 }; |
1898 | 1903 |
1899 | 1904 |
1905 class CheckSmiComp : public TemplateComputation<1> { | |
1906 public: | |
1907 CheckSmiComp(Value* value, InstanceCallComp* original) | |
1908 : original_(original) { | |
1909 ASSERT(value != NULL); | |
1910 inputs_[0] = value; | |
1911 } | |
1912 | |
1913 DECLARE_COMPUTATION(CheckSmi) | |
1914 | |
1915 virtual bool CanDeoptimize() const { return true; } | |
1916 | |
1917 virtual bool AttributesEqual(Computation* other) const { return true; } | |
1918 | |
1919 virtual bool HasSideEffect() const { return false; } | |
1920 | |
1921 virtual Definition* TryReplace(BindInstr* instr) const; | |
1922 | |
1923 Value* value() const { return inputs_[0]; } | |
1924 | |
1925 intptr_t deopt_id() const { return original_->deopt_id(); } | |
1926 intptr_t try_index() const { return original_->try_index(); } | |
1927 | |
1928 private: | |
1929 InstanceCallComp* original_; | |
1930 | |
1931 DISALLOW_COPY_AND_ASSIGN(CheckSmiComp); | |
1932 }; | |
1933 | |
1934 | |
1900 #undef DECLARE_COMPUTATION | 1935 #undef DECLARE_COMPUTATION |
1901 | 1936 |
1902 | 1937 |
1903 // Implementation of type testers and cast functins. | 1938 // Implementation of type testers and cast functins. |
1904 #define DEFINE_COMPUTATION_PREDICATE(ShortName, ClassName) \ | 1939 #define DEFINE_COMPUTATION_PREDICATE(ShortName, ClassName) \ |
1905 bool Computation::Is##ShortName() const { \ | 1940 bool Computation::Is##ShortName() const { \ |
1906 return computation_kind() == k##ShortName; \ | 1941 return computation_kind() == k##ShortName; \ |
1907 } \ | 1942 } \ |
1908 const ClassName* Computation::As##ShortName() const { \ | 1943 const ClassName* Computation::As##ShortName() const { \ |
1909 if (!Is##ShortName()) return NULL; \ | 1944 if (!Is##ShortName()) return NULL; \ |
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3056 | 3091 |
3057 Location* LocationSlotAt(intptr_t ix) const { | 3092 Location* LocationSlotAt(intptr_t ix) const { |
3058 ASSERT((ix >= 0) && (ix < values_.length())); | 3093 ASSERT((ix >= 0) && (ix < values_.length())); |
3059 return &locations_[ix]; | 3094 return &locations_[ix]; |
3060 } | 3095 } |
3061 | 3096 |
3062 intptr_t fixed_parameter_count() const { | 3097 intptr_t fixed_parameter_count() const { |
3063 return fixed_parameter_count_; | 3098 return fixed_parameter_count_; |
3064 } | 3099 } |
3065 | 3100 |
3101 Environment* Copy() const; | |
3102 | |
3066 void PrintTo(BufferFormatter* f) const; | 3103 void PrintTo(BufferFormatter* f) const; |
3067 | 3104 |
3068 private: | 3105 private: |
3106 Environment(intptr_t length, intptr_t fixed_parameter_count) | |
3107 : values_(length), | |
3108 locations_(NULL), | |
3109 fixed_parameter_count_(fixed_parameter_count) { } | |
3110 | |
3069 GrowableArray<Value*> values_; | 3111 GrowableArray<Value*> values_; |
3070 Location* locations_; | 3112 Location* locations_; |
3071 const intptr_t fixed_parameter_count_; | 3113 const intptr_t fixed_parameter_count_; |
3072 | 3114 |
3073 DISALLOW_COPY_AND_ASSIGN(Environment); | 3115 DISALLOW_COPY_AND_ASSIGN(Environment); |
3074 }; | 3116 }; |
3075 | 3117 |
3076 | 3118 |
3077 // Visitor base class to visit each instruction and computation in a flow | 3119 // Visitor base class to visit each instruction and computation in a flow |
3078 // graph as defined by a reversed list of basic blocks. | 3120 // graph as defined by a reversed list of basic blocks. |
(...skipping 30 matching lines...) Expand all Loading... | |
3109 ForwardInstructionIterator* current_iterator_; | 3151 ForwardInstructionIterator* current_iterator_; |
3110 | 3152 |
3111 private: | 3153 private: |
3112 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 3154 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
3113 }; | 3155 }; |
3114 | 3156 |
3115 | 3157 |
3116 } // namespace dart | 3158 } // namespace dart |
3117 | 3159 |
3118 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 3160 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
OLD | NEW |