OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 kDontSelfOptimize, | 174 kDontSelfOptimize, |
175 kDontSoftInline, | 175 kDontSoftInline, |
176 kDontCache | 176 kDontCache |
177 }; | 177 }; |
178 | 178 |
179 | 179 |
180 class AstProperties V8_FINAL BASE_EMBEDDED { | 180 class AstProperties V8_FINAL BASE_EMBEDDED { |
181 public: | 181 public: |
182 class Flags : public EnumSet<AstPropertiesFlag, int> {}; | 182 class Flags : public EnumSet<AstPropertiesFlag, int> {}; |
183 | 183 |
184 AstProperties() : node_count_(0) { } | 184 AstProperties() |
185 : node_count_(0), | |
186 minimum_feedback_slots_(0), | |
187 maximum_feedback_slots_(0) { } | |
185 | 188 |
186 Flags* flags() { return &flags_; } | 189 Flags* flags() { return &flags_; } |
187 int node_count() { return node_count_; } | 190 int node_count() { return node_count_; } |
188 void add_node_count(int count) { node_count_ += count; } | 191 void add_node_count(int count) { node_count_ += count; } |
189 | 192 |
193 int minimum_feedback_slots() { return minimum_feedback_slots_; } | |
194 int maximum_feedback_slots() { return maximum_feedback_slots_; } | |
195 void increase_feedback_slots(int minimum, int maximum) { | |
196 minimum_feedback_slots_ += minimum; | |
197 maximum_feedback_slots_ += maximum; | |
Benedikt Meurer
2014/01/24 11:29:54
Can we have an ASSERT here to make sure that mini
mvstanton
2014/01/30 15:13:41
Changed the approach totally...
| |
198 } | |
199 | |
190 private: | 200 private: |
191 Flags flags_; | 201 Flags flags_; |
192 int node_count_; | 202 int node_count_; |
203 int minimum_feedback_slots_; | |
204 int maximum_feedback_slots_; | |
193 }; | 205 }; |
194 | 206 |
195 | 207 |
196 class AstNode: public ZoneObject { | 208 class AstNode: public ZoneObject { |
197 public: | 209 public: |
198 #define DECLARE_TYPE_ENUM(type) k##type, | 210 #define DECLARE_TYPE_ENUM(type) k##type, |
199 enum NodeType { | 211 enum NodeType { |
200 AST_NODE_LIST(DECLARE_TYPE_ENUM) | 212 AST_NODE_LIST(DECLARE_TYPE_ENUM) |
201 kInvalid = -1 | 213 kInvalid = -1 |
202 }; | 214 }; |
203 #undef DECLARE_TYPE_ENUM | 215 #undef DECLARE_TYPE_ENUM |
204 | 216 |
205 void* operator new(size_t size, Zone* zone) { | 217 void* operator new(size_t size, Zone* zone) { |
206 return zone->New(static_cast<int>(size)); | 218 return zone->New(static_cast<int>(size)); |
207 } | 219 } |
208 | 220 |
209 explicit AstNode(int position): position_(position) {} | 221 explicit AstNode(int position): position_(position) {} |
210 virtual ~AstNode() {} | 222 virtual ~AstNode() {} |
211 | 223 |
212 virtual void Accept(AstVisitor* v) = 0; | 224 virtual void Accept(AstVisitor* v) = 0; |
213 virtual NodeType node_type() const = 0; | 225 virtual NodeType node_type() const = 0; |
214 int position() const { return position_; } | 226 int position() const { return position_; } |
215 | 227 |
228 static int MinimumFeedbackSlots() { return 0; } | |
229 static int MaximumFeedbackSlots() { return 0; } | |
230 | |
231 virtual int ConsumeFeedbackSlots(Isolate* isolate, int current_slot) { | |
232 return current_slot; | |
233 } | |
234 | |
216 // Type testing & conversion functions overridden by concrete subclasses. | 235 // Type testing & conversion functions overridden by concrete subclasses. |
217 #define DECLARE_NODE_FUNCTIONS(type) \ | 236 #define DECLARE_NODE_FUNCTIONS(type) \ |
218 bool Is##type() { return node_type() == AstNode::k##type; } \ | 237 bool Is##type() { return node_type() == AstNode::k##type; } \ |
219 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; } | 238 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; } |
220 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 239 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
221 #undef DECLARE_NODE_FUNCTIONS | 240 #undef DECLARE_NODE_FUNCTIONS |
222 | 241 |
223 virtual TargetCollector* AsTargetCollector() { return NULL; } | 242 virtual TargetCollector* AsTargetCollector() { return NULL; } |
224 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 243 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
225 virtual IterationStatement* AsIterationStatement() { return NULL; } | 244 virtual IterationStatement* AsIterationStatement() { return NULL; } |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
915 | 934 |
916 | 935 |
917 class ForInStatement V8_FINAL : public ForEachStatement { | 936 class ForInStatement V8_FINAL : public ForEachStatement { |
918 public: | 937 public: |
919 DECLARE_NODE_TYPE(ForInStatement) | 938 DECLARE_NODE_TYPE(ForInStatement) |
920 | 939 |
921 Expression* enumerable() const { | 940 Expression* enumerable() const { |
922 return subject(); | 941 return subject(); |
923 } | 942 } |
924 | 943 |
925 TypeFeedbackId ForInFeedbackId() const { return reuse(PrepareId()); } | 944 // Type feedback information. |
945 static int MinimumFeedbackSlots() { return 1; } | |
946 static int MaximumFeedbackSlots() { return 1; } | |
947 | |
948 virtual int ConsumeFeedbackSlots(Isolate* isolate, int current_slot) { | |
949 first_feedback_slot_ = current_slot; | |
950 return current_slot + 1; | |
951 } | |
952 int ForInFeedbackSlot() { return first_feedback_slot_; } | |
953 | |
926 enum ForInType { FAST_FOR_IN, SLOW_FOR_IN }; | 954 enum ForInType { FAST_FOR_IN, SLOW_FOR_IN }; |
927 ForInType for_in_type() const { return for_in_type_; } | 955 ForInType for_in_type() const { return for_in_type_; } |
928 void set_for_in_type(ForInType type) { for_in_type_ = type; } | 956 void set_for_in_type(ForInType type) { for_in_type_ = type; } |
929 | 957 |
930 BailoutId BodyId() const { return body_id_; } | 958 BailoutId BodyId() const { return body_id_; } |
931 BailoutId PrepareId() const { return prepare_id_; } | 959 BailoutId PrepareId() const { return prepare_id_; } |
932 virtual BailoutId ContinueId() const V8_OVERRIDE { return EntryId(); } | 960 virtual BailoutId ContinueId() const V8_OVERRIDE { return EntryId(); } |
933 virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; } | 961 virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; } |
934 | 962 |
935 protected: | 963 protected: |
936 ForInStatement(Zone* zone, ZoneStringList* labels, int pos) | 964 ForInStatement(Zone* zone, ZoneStringList* labels, int pos) |
937 : ForEachStatement(zone, labels, pos), | 965 : ForEachStatement(zone, labels, pos), |
938 for_in_type_(SLOW_FOR_IN), | 966 for_in_type_(SLOW_FOR_IN), |
967 first_feedback_slot_(0), | |
Benedikt Meurer
2014/01/24 11:29:54
Initialize to -1 as below. Extra points if you add
| |
939 body_id_(GetNextId(zone)), | 968 body_id_(GetNextId(zone)), |
940 prepare_id_(GetNextId(zone)) { | 969 prepare_id_(GetNextId(zone)) { |
941 } | 970 } |
942 | 971 |
943 ForInType for_in_type_; | 972 ForInType for_in_type_; |
973 int first_feedback_slot_; | |
944 const BailoutId body_id_; | 974 const BailoutId body_id_; |
945 const BailoutId prepare_id_; | 975 const BailoutId prepare_id_; |
946 }; | 976 }; |
947 | 977 |
948 | 978 |
949 class ForOfStatement V8_FINAL : public ForEachStatement { | 979 class ForOfStatement V8_FINAL : public ForEachStatement { |
950 public: | 980 public: |
951 DECLARE_NODE_TYPE(ForOfStatement) | 981 DECLARE_NODE_TYPE(ForOfStatement) |
952 | 982 |
953 void Initialize(Expression* each, | 983 void Initialize(Expression* each, |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1733 }; | 1763 }; |
1734 | 1764 |
1735 | 1765 |
1736 class Call V8_FINAL : public Expression { | 1766 class Call V8_FINAL : public Expression { |
1737 public: | 1767 public: |
1738 DECLARE_NODE_TYPE(Call) | 1768 DECLARE_NODE_TYPE(Call) |
1739 | 1769 |
1740 Expression* expression() const { return expression_; } | 1770 Expression* expression() const { return expression_; } |
1741 ZoneList<Expression*>* arguments() const { return arguments_; } | 1771 ZoneList<Expression*>* arguments() const { return arguments_; } |
1742 | 1772 |
1773 static int MinimumFeedbackSlots() { return 0; } | |
1774 static int MaximumFeedbackSlots() { return 1; } | |
1775 virtual int ConsumeFeedbackSlots(Isolate* isolate, int current_slot); | |
1776 int CallFeedbackSlot() { return first_feedback_slot_; } | |
1777 | |
1743 // Type feedback information. | 1778 // Type feedback information. |
1744 TypeFeedbackId CallFeedbackId() const { return reuse(id()); } | 1779 TypeFeedbackId CallFeedbackId() const { return reuse(id()); } |
1745 void RecordTypeFeedback(TypeFeedbackOracle* oracle); | 1780 void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
1746 virtual SmallMapList* GetReceiverTypes() V8_OVERRIDE { | 1781 virtual SmallMapList* GetReceiverTypes() V8_OVERRIDE { |
1747 return &receiver_types_; | 1782 return &receiver_types_; |
1748 } | 1783 } |
1749 virtual bool IsMonomorphic() V8_OVERRIDE { return is_monomorphic_; } | 1784 virtual bool IsMonomorphic() V8_OVERRIDE { return is_monomorphic_; } |
1750 bool KeyedArrayCallIsHoley() { return keyed_array_call_is_holey_; } | 1785 bool KeyedArrayCallIsHoley() { return keyed_array_call_is_holey_; } |
1751 CheckType check_type() const { return check_type_; } | 1786 CheckType check_type() const { return check_type_; } |
1752 | 1787 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1804 Call(Zone* zone, | 1839 Call(Zone* zone, |
1805 Expression* expression, | 1840 Expression* expression, |
1806 ZoneList<Expression*>* arguments, | 1841 ZoneList<Expression*>* arguments, |
1807 int pos) | 1842 int pos) |
1808 : Expression(zone, pos), | 1843 : Expression(zone, pos), |
1809 expression_(expression), | 1844 expression_(expression), |
1810 arguments_(arguments), | 1845 arguments_(arguments), |
1811 is_monomorphic_(false), | 1846 is_monomorphic_(false), |
1812 keyed_array_call_is_holey_(true), | 1847 keyed_array_call_is_holey_(true), |
1813 check_type_(RECEIVER_MAP_CHECK), | 1848 check_type_(RECEIVER_MAP_CHECK), |
1849 first_feedback_slot_(-1), | |
Benedikt Meurer
2014/01/24 11:29:54
Remember the extra points...? ;-)
| |
1814 return_id_(GetNextId(zone)) { } | 1850 return_id_(GetNextId(zone)) { } |
1815 | 1851 |
1816 private: | 1852 private: |
1817 Expression* expression_; | 1853 Expression* expression_; |
1818 ZoneList<Expression*>* arguments_; | 1854 ZoneList<Expression*>* arguments_; |
1819 | 1855 |
1820 bool is_monomorphic_; | 1856 bool is_monomorphic_; |
1821 bool keyed_array_call_is_holey_; | 1857 bool keyed_array_call_is_holey_; |
1822 CheckType check_type_; | 1858 CheckType check_type_; |
1823 SmallMapList receiver_types_; | 1859 SmallMapList receiver_types_; |
1824 Handle<JSFunction> target_; | 1860 Handle<JSFunction> target_; |
1825 Handle<JSObject> holder_; | 1861 Handle<JSObject> holder_; |
1826 Handle<Cell> cell_; | 1862 Handle<Cell> cell_; |
1863 int first_feedback_slot_; | |
1827 | 1864 |
1828 const BailoutId return_id_; | 1865 const BailoutId return_id_; |
1829 }; | 1866 }; |
1830 | 1867 |
1831 | 1868 |
1832 class CallNew V8_FINAL : public Expression { | 1869 class CallNew V8_FINAL : public Expression { |
1833 public: | 1870 public: |
1834 DECLARE_NODE_TYPE(CallNew) | 1871 DECLARE_NODE_TYPE(CallNew) |
1835 | 1872 |
1836 Expression* expression() const { return expression_; } | 1873 Expression* expression() const { return expression_; } |
1837 ZoneList<Expression*>* arguments() const { return arguments_; } | 1874 ZoneList<Expression*>* arguments() const { return arguments_; } |
1838 | 1875 |
1839 // Type feedback information. | 1876 // Type feedback information. |
1877 static int MinimumFeedbackSlots() { return 1; } | |
1878 static int MaximumFeedbackSlots() { return 1; } | |
1879 | |
1880 virtual int ConsumeFeedbackSlots(Isolate* isolate, int current_slot) { | |
1881 first_feedback_slot_ = current_slot; | |
1882 return current_slot + 1; | |
1883 } | |
1884 int CallNewFeedbackSlot() { return first_feedback_slot_; } | |
1885 | |
1840 TypeFeedbackId CallNewFeedbackId() const { return reuse(id()); } | 1886 TypeFeedbackId CallNewFeedbackId() const { return reuse(id()); } |
1841 void RecordTypeFeedback(TypeFeedbackOracle* oracle); | 1887 void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
1842 virtual bool IsMonomorphic() V8_OVERRIDE { return is_monomorphic_; } | 1888 virtual bool IsMonomorphic() V8_OVERRIDE { return is_monomorphic_; } |
1843 Handle<JSFunction> target() const { return target_; } | 1889 Handle<JSFunction> target() const { return target_; } |
1844 ElementsKind elements_kind() const { return elements_kind_; } | 1890 ElementsKind elements_kind() const { return elements_kind_; } |
1845 Handle<AllocationSite> allocation_site() const { | 1891 Handle<AllocationSite> allocation_site() const { |
1846 return allocation_site_; | 1892 return allocation_site_; |
1847 } | 1893 } |
1848 | 1894 |
1895 static int feedback_slots() { return 1; } | |
1896 | |
1849 BailoutId ReturnId() const { return return_id_; } | 1897 BailoutId ReturnId() const { return return_id_; } |
1850 | 1898 |
1851 protected: | 1899 protected: |
1852 CallNew(Zone* zone, | 1900 CallNew(Zone* zone, |
1853 Expression* expression, | 1901 Expression* expression, |
1854 ZoneList<Expression*>* arguments, | 1902 ZoneList<Expression*>* arguments, |
1855 int pos) | 1903 int pos) |
1856 : Expression(zone, pos), | 1904 : Expression(zone, pos), |
1857 expression_(expression), | 1905 expression_(expression), |
1858 arguments_(arguments), | 1906 arguments_(arguments), |
1859 is_monomorphic_(false), | 1907 is_monomorphic_(false), |
1860 elements_kind_(GetInitialFastElementsKind()), | 1908 elements_kind_(GetInitialFastElementsKind()), |
1909 first_feedback_slot_(0), | |
Benedikt Meurer
2014/01/24 11:29:54
See above.
| |
1861 return_id_(GetNextId(zone)) { } | 1910 return_id_(GetNextId(zone)) { } |
1862 | 1911 |
1863 private: | 1912 private: |
1864 Expression* expression_; | 1913 Expression* expression_; |
1865 ZoneList<Expression*>* arguments_; | 1914 ZoneList<Expression*>* arguments_; |
1866 | 1915 |
1867 bool is_monomorphic_; | 1916 bool is_monomorphic_; |
1868 Handle<JSFunction> target_; | 1917 Handle<JSFunction> target_; |
1869 ElementsKind elements_kind_; | 1918 ElementsKind elements_kind_; |
1870 Handle<AllocationSite> allocation_site_; | 1919 Handle<AllocationSite> allocation_site_; |
1920 Handle<Cell> allocation_info_cell_; | |
1921 int first_feedback_slot_; | |
1871 | 1922 |
1872 const BailoutId return_id_; | 1923 const BailoutId return_id_; |
1873 }; | 1924 }; |
1874 | 1925 |
1875 | 1926 |
1876 // The CallRuntime class does not represent any official JavaScript | 1927 // The CallRuntime class does not represent any official JavaScript |
1877 // language construct. Instead it is used to call a C or JS function | 1928 // language construct. Instead it is used to call a C or JS function |
1878 // with a set of arguments. This is used from the builtins that are | 1929 // with a set of arguments. This is used from the builtins that are |
1879 // implemented in JavaScript (see "v8natives.js"). | 1930 // implemented in JavaScript (see "v8natives.js"). |
1880 class CallRuntime V8_FINAL : public Expression { | 1931 class CallRuntime V8_FINAL : public Expression { |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2346 } | 2397 } |
2347 void set_parenthesized() { | 2398 void set_parenthesized() { |
2348 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized); | 2399 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized); |
2349 } | 2400 } |
2350 | 2401 |
2351 bool is_generator() { | 2402 bool is_generator() { |
2352 return IsGenerator::decode(bitfield_) == kIsGenerator; | 2403 return IsGenerator::decode(bitfield_) == kIsGenerator; |
2353 } | 2404 } |
2354 | 2405 |
2355 int ast_node_count() { return ast_properties_.node_count(); } | 2406 int ast_node_count() { return ast_properties_.node_count(); } |
2407 | |
2408 int minimum_feedback_slots() { | |
2409 return ast_properties_.minimum_feedback_slots(); | |
2410 } | |
2411 | |
2412 int maximum_feedback_slots() { | |
2413 return ast_properties_.maximum_feedback_slots(); | |
2414 } | |
2415 | |
2356 AstProperties::Flags* flags() { return ast_properties_.flags(); } | 2416 AstProperties::Flags* flags() { return ast_properties_.flags(); } |
2357 void set_ast_properties(AstProperties* ast_properties) { | 2417 void set_ast_properties(AstProperties* ast_properties) { |
2358 ast_properties_ = *ast_properties; | 2418 ast_properties_ = *ast_properties; |
2359 } | 2419 } |
2360 | 2420 |
2361 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } | 2421 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } |
2362 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } | 2422 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } |
2363 void set_dont_optimize_reason(BailoutReason reason) { | 2423 void set_dont_optimize_reason(BailoutReason reason) { |
2364 dont_optimize_reason_ = reason; | 2424 dont_optimize_reason_ = reason; |
2365 } | 2425 } |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2889 private: | 2949 private: |
2890 template<class> friend class AstNodeFactory; | 2950 template<class> friend class AstNodeFactory; |
2891 | 2951 |
2892 // Node visitors. | 2952 // Node visitors. |
2893 #define DEF_VISIT(type) \ | 2953 #define DEF_VISIT(type) \ |
2894 void Visit##type(type* node); | 2954 void Visit##type(type* node); |
2895 AST_NODE_LIST(DEF_VISIT) | 2955 AST_NODE_LIST(DEF_VISIT) |
2896 #undef DEF_VISIT | 2956 #undef DEF_VISIT |
2897 | 2957 |
2898 void increase_node_count() { properties_.add_node_count(1); } | 2958 void increase_node_count() { properties_.add_node_count(1); } |
2959 void increase_feedback_slots(int count_fixed, int count_optional) { | |
2960 properties_.increase_feedback_slots(count_fixed, count_optional); | |
2961 } | |
2899 void add_flag(AstPropertiesFlag flag) { properties_.flags()->Add(flag); } | 2962 void add_flag(AstPropertiesFlag flag) { properties_.flags()->Add(flag); } |
2900 void set_dont_optimize_reason(BailoutReason reason) { | 2963 void set_dont_optimize_reason(BailoutReason reason) { |
2901 dont_optimize_reason_ = reason; | 2964 dont_optimize_reason_ = reason; |
2902 } | 2965 } |
2903 | 2966 |
2904 AstProperties properties_; | 2967 AstProperties properties_; |
2905 BailoutReason dont_optimize_reason_; | 2968 BailoutReason dont_optimize_reason_; |
2906 }; | 2969 }; |
2907 | 2970 |
2908 | 2971 |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3321 | 3384 |
3322 private: | 3385 private: |
3323 Zone* zone_; | 3386 Zone* zone_; |
3324 Visitor visitor_; | 3387 Visitor visitor_; |
3325 }; | 3388 }; |
3326 | 3389 |
3327 | 3390 |
3328 } } // namespace v8::internal | 3391 } } // namespace v8::internal |
3329 | 3392 |
3330 #endif // V8_AST_H_ | 3393 #endif // V8_AST_H_ |
OLD | NEW |