Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(820)

Side by Side Diff: runtime/vm/ast.h

Issue 9395016: First part of new ICData infrastructure: use a wrapper object instead of an array. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/code_generator.cc » ('j') | runtime/vm/code_generator_ia32.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_AST_H_ 5 #ifndef VM_AST_H_
6 #define VM_AST_H_ 6 #define VM_AST_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
11 #include "vm/ic_data.h"
12 #include "vm/scopes.h" 11 #include "vm/scopes.h"
13 #include "vm/object.h" 12 #include "vm/object.h"
14 #include "vm/native_entry.h" 13 #include "vm/native_entry.h"
15 #include "vm/token.h" 14 #include "vm/token.h"
16 15
17 namespace dart { 16 namespace dart {
18 17
19 #define NODE_LIST(V) \ 18 #define NODE_LIST(V) \
20 V(ReturnNode, "return") \ 19 V(ReturnNode, "return") \
21 V(LiteralNode, "literal") \ 20 V(LiteralNode, "literal") \
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 virtual type* As##type() { return this; } 95 virtual type* As##type() { return this; }
97 96
98 97
99 class AstNode : public ZoneAllocated { 98 class AstNode : public ZoneAllocated {
100 public: 99 public:
101 static const int kNoId = -1; 100 static const int kNoId = -1;
102 101
103 explicit AstNode(intptr_t token_index) 102 explicit AstNode(intptr_t token_index)
104 : token_index_(token_index), 103 : token_index_(token_index),
105 id_(GetNextId()), 104 id_(GetNextId()),
106 ic_data_(Array::ZoneHandle()), 105 ic_data_(ICData::ZoneHandle()),
107 info_(NULL) { 106 info_(NULL) {
108 ASSERT(token_index >= 0); 107 ASSERT(token_index >= 0);
109 } 108 }
110 109
111 intptr_t token_index() const { return token_index_; } 110 intptr_t token_index() const { return token_index_; }
112 111
113 virtual void SetIcDataArrayAtId(intptr_t node_id, const Array& value) { 112 virtual void SetIcDataAtId(intptr_t node_id, const ICData& value) {
114 ASSERT(id() == node_id); 113 ASSERT(id() == node_id);
115 set_ic_data_array(value); 114 set_ic_data(value);
116 } 115 }
117 116
118 virtual const ICData& ICDataAtId(intptr_t node_id) const { 117 virtual const ICData& ICDataAtId(intptr_t node_id) const {
119 ASSERT(id() == node_id); 118 ASSERT(id() == node_id);
120 return ic_data(); 119 return ic_data_;
121 } 120 }
122 121
123 virtual bool HasId(intptr_t value) const { return id_ == value; } 122 virtual bool HasId(intptr_t value) const { return id_ == value; }
124 123
125 intptr_t id() const { return id_; } 124 intptr_t id() const { return id_; }
126 125
127 void set_info(CodeGenInfo* info) { info_ = info; } 126 void set_info(CodeGenInfo* info) { info_ = info; }
128 CodeGenInfo* info() const { return info_; } 127 CodeGenInfo* info() const { return info_; }
129 128
130 #define AST_TYPE_CHECK(type, name) \ 129 #define AST_TYPE_CHECK(type, name) \
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // Analyzes an expression to determine whether it is a compile time 167 // Analyzes an expression to determine whether it is a compile time
169 // constant or not. Returns NULL if the expression is not a compile time 168 // constant or not. Returns NULL if the expression is not a compile time
170 // constant. Otherwise, the return value is an approximation of the 169 // constant. Otherwise, the return value is an approximation of the
171 // actual value of the const expression. The type of the returned value 170 // actual value of the const expression. The type of the returned value
172 // corresponds to the type of the const expression and is either 171 // corresponds to the type of the const expression and is either
173 // Number, Integer, String, Bool, or anything else (not a subtype of 172 // Number, Integer, String, Bool, or anything else (not a subtype of
174 // the former). 173 // the former).
175 virtual const Instance* EvalConstExpr() const { return NULL; } 174 virtual const Instance* EvalConstExpr() const { return NULL; }
176 175
177 protected: 176 protected:
178 void set_ic_data_array(const Array& value) { 177 const ICData& ic_data() const { return ic_data_; }
179 ic_data_.set_data(value); 178 void set_ic_data(const ICData& value) {
179 ic_data_ = value.raw();
180 } 180 }
181 181
182 const ICData& ic_data() const { return ic_data_; }
183
184 static intptr_t GetNextId() { 182 static intptr_t GetNextId() {
185 Isolate* isolate = Isolate::Current(); 183 Isolate* isolate = Isolate::Current();
186 intptr_t tmp = isolate->ast_node_id(); 184 intptr_t tmp = isolate->ast_node_id();
187 isolate->set_ast_node_id(tmp + 1); 185 isolate->set_ast_node_id(tmp + 1);
188 return tmp; 186 return tmp;
189 } 187 }
190 188
191 private: 189 private:
192 const intptr_t token_index_; 190 const intptr_t token_index_;
193 // Unique id per function compiled, used to match AST node to a PC. 191 // Unique id per function compiled, used to match AST node to a PC.
194 const intptr_t id_; 192 const intptr_t id_;
195 // IC data collected for this node. 193 // IC data collected for this node.
196 ICData ic_data_; 194 ICData& ic_data_;
197 // Used by optimizing compiler. 195 // Used by optimizing compiler.
198 CodeGenInfo* info_; 196 CodeGenInfo* info_;
199 DISALLOW_COPY_AND_ASSIGN(AstNode); 197 DISALLOW_COPY_AND_ASSIGN(AstNode);
200 }; 198 };
201 199
202 200
203 class SequenceNode : public AstNode { 201 class SequenceNode : public AstNode {
204 public: 202 public:
205 SequenceNode(intptr_t token_index, LocalScope* scope) 203 SequenceNode(intptr_t token_index, LocalScope* scope)
206 : AstNode(token_index), 204 : AstNode(token_index),
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 bool prefix, 684 bool prefix,
687 AstNode* receiver, 685 AstNode* receiver,
688 const String& field_name) 686 const String& field_name)
689 : AstNode(token_index), 687 : AstNode(token_index),
690 kind_(kind), 688 kind_(kind),
691 prefix_(prefix), 689 prefix_(prefix),
692 receiver_(receiver), 690 receiver_(receiver),
693 field_name_(field_name), 691 field_name_(field_name),
694 operator_id_(AstNode::GetNextId()), 692 operator_id_(AstNode::GetNextId()),
695 setter_id_(AstNode::GetNextId()), 693 setter_id_(AstNode::GetNextId()),
696 operator_ic_data_(Array::ZoneHandle()), 694 operator_ic_data_(ICData::ZoneHandle()),
697 setter_ic_data_(Array::ZoneHandle()) { 695 setter_ic_data_(ICData::ZoneHandle()) {
698 ASSERT(receiver_ != NULL); 696 ASSERT(receiver_ != NULL);
699 ASSERT(field_name_.IsZoneHandle()); 697 ASSERT(field_name_.IsZoneHandle());
700 ASSERT(kind_ == Token::kINCR || kind_ == Token::kDECR); 698 ASSERT(kind_ == Token::kINCR || kind_ == Token::kDECR);
701 } 699 }
702 700
703 Token::Kind kind() const { return kind_; } 701 Token::Kind kind() const { return kind_; }
704 bool prefix() const { return prefix_; } 702 bool prefix() const { return prefix_; }
705 AstNode* receiver() const { return receiver_; } 703 AstNode* receiver() const { return receiver_; }
706 const String& field_name() const { return field_name_; } 704 const String& field_name() const { return field_name_; }
707 705
708 intptr_t getter_id() const { return id(); } 706 intptr_t getter_id() const { return id(); }
709 intptr_t operator_id() const { return operator_id_; } 707 intptr_t operator_id() const { return operator_id_; }
710 intptr_t setter_id() const { return setter_id_; } 708 intptr_t setter_id() const { return setter_id_; }
711 709
712 virtual bool HasId(intptr_t value) const { 710 virtual bool HasId(intptr_t value) const {
713 return (getter_id() == value) || 711 return (getter_id() == value) ||
714 (operator_id() == value) || 712 (operator_id() == value) ||
715 (setter_id() == value); 713 (setter_id() == value);
716 } 714 }
717 715
718 virtual void SetIcDataArrayAtId(intptr_t node_id, const Array& value) { 716 virtual void SetIcDataAtId(intptr_t node_id, const ICData& value) {
719 ASSERT(HasId(node_id)); 717 ASSERT(HasId(node_id));
720 if (node_id == getter_id()) { 718 if (node_id == getter_id()) {
721 set_ic_data_array(value); 719 set_ic_data(value);
722 } else if (node_id == operator_id()) { 720 } else if (node_id == operator_id()) {
723 operator_ic_data_.set_data(value); 721 operator_ic_data_ = value.raw();
724 } else { 722 } else {
725 ASSERT(node_id == setter_id()); 723 ASSERT(node_id == setter_id());
726 setter_ic_data_.set_data(value); 724 setter_ic_data_ = value.raw();
727 } 725 }
728 } 726 }
729 727
730 virtual const ICData& ICDataAtId(intptr_t node_id) const { 728 virtual const ICData& ICDataAtId(intptr_t node_id) const {
731 ASSERT(HasId(node_id)); 729 ASSERT(HasId(node_id));
732 if (node_id == getter_id()) { 730 if (node_id == getter_id()) {
733 return ic_data(); 731 return ic_data();
734 } else if (node_id == operator_id()) { 732 } else if (node_id == operator_id()) {
735 return operator_ic_data_; 733 return operator_ic_data_;
736 } else { 734 } else {
(...skipping 10 matching lines...) Expand all
747 745
748 DECLARE_COMMON_NODE_FUNCTIONS(IncrOpInstanceFieldNode); 746 DECLARE_COMMON_NODE_FUNCTIONS(IncrOpInstanceFieldNode);
749 747
750 private: 748 private:
751 const Token::Kind kind_; 749 const Token::Kind kind_;
752 const bool prefix_; 750 const bool prefix_;
753 AstNode* receiver_; 751 AstNode* receiver_;
754 const String& field_name_; 752 const String& field_name_;
755 const intptr_t operator_id_; 753 const intptr_t operator_id_;
756 const intptr_t setter_id_; 754 const intptr_t setter_id_;
757 ICData operator_ic_data_; 755 ICData& operator_ic_data_;
758 ICData setter_ic_data_; 756 ICData& setter_ic_data_;
759 757
760 DISALLOW_IMPLICIT_CONSTRUCTORS(IncrOpInstanceFieldNode); 758 DISALLOW_IMPLICIT_CONSTRUCTORS(IncrOpInstanceFieldNode);
761 }; 759 };
762 760
763 761
764 class IncrOpStaticFieldNode : public AstNode { 762 class IncrOpStaticFieldNode : public AstNode {
765 public: 763 public:
766 // Access the static field via a call to static getter. 764 // Access the static field via a call to static getter.
767 IncrOpStaticFieldNode(intptr_t token_index, 765 IncrOpStaticFieldNode(intptr_t token_index,
768 Token::Kind kind, 766 Token::Kind kind,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 bool prefix, 823 bool prefix,
826 AstNode* array, 824 AstNode* array,
827 AstNode* index) 825 AstNode* index)
828 : AstNode(token_index), 826 : AstNode(token_index),
829 kind_(kind), 827 kind_(kind),
830 prefix_(prefix), 828 prefix_(prefix),
831 array_(array), 829 array_(array),
832 index_(index), 830 index_(index),
833 operator_id_(AstNode::GetNextId()), 831 operator_id_(AstNode::GetNextId()),
834 store_id_(AstNode::GetNextId()), 832 store_id_(AstNode::GetNextId()),
835 operator_ic_data_(Array::ZoneHandle()), 833 operator_ic_data_(ICData::ZoneHandle()),
836 store_ic_data_(Array::ZoneHandle()) { 834 store_ic_data_(ICData::ZoneHandle()) {
837 ASSERT(kind_ == Token::kINCR || kind_ == Token::kDECR); 835 ASSERT(kind_ == Token::kINCR || kind_ == Token::kDECR);
838 ASSERT(array_ != NULL); 836 ASSERT(array_ != NULL);
839 ASSERT(index_ != NULL); 837 ASSERT(index_ != NULL);
840 } 838 }
841 839
842 Token::Kind kind() const { return kind_; } 840 Token::Kind kind() const { return kind_; }
843 bool prefix() const { return prefix_; } 841 bool prefix() const { return prefix_; }
844 AstNode* array() const { return array_; } 842 AstNode* array() const { return array_; }
845 AstNode* index() const { return index_; } 843 AstNode* index() const { return index_; }
846 844
(...skipping 12 matching lines...) Expand all
859 if (node_id == load_id()) { 857 if (node_id == load_id()) {
860 return ic_data(); 858 return ic_data();
861 } else if (node_id == operator_id()) { 859 } else if (node_id == operator_id()) {
862 return operator_ic_data_; 860 return operator_ic_data_;
863 } else { 861 } else {
864 ASSERT(node_id == store_id()); 862 ASSERT(node_id == store_id());
865 return store_ic_data_; 863 return store_ic_data_;
866 } 864 }
867 } 865 }
868 866
869 virtual void SetIcDataArrayAtId(intptr_t node_id, const Array& value) { 867 virtual void SetIcDataArrayAtId(intptr_t node_id, const ICData& value) {
870 ASSERT(HasId(node_id)); 868 ASSERT(HasId(node_id));
871 if (node_id == load_id()) { 869 if (node_id == load_id()) {
872 set_ic_data_array(value); 870 set_ic_data(value);
873 } else if (node_id == operator_id()) { 871 } else if (node_id == operator_id()) {
874 operator_ic_data_.set_data(value); 872 operator_ic_data_ = value.raw();
875 } else { 873 } else {
876 ASSERT(node_id == store_id()); 874 ASSERT(node_id == store_id());
877 store_ic_data_.set_data(value); 875 store_ic_data_ = value.raw();
878 } 876 }
879 } 877 }
880 878
881 virtual void VisitChildren(AstNodeVisitor* visitor) const { 879 virtual void VisitChildren(AstNodeVisitor* visitor) const {
882 array()->Visit(visitor); 880 array()->Visit(visitor);
883 index()->Visit(visitor); 881 index()->Visit(visitor);
884 } 882 }
885 883
886 virtual const char* Name() const; 884 virtual const char* Name() const;
887 885
888 DECLARE_COMMON_NODE_FUNCTIONS(IncrOpIndexedNode); 886 DECLARE_COMMON_NODE_FUNCTIONS(IncrOpIndexedNode);
889 887
890 private: 888 private:
891 const Token::Kind kind_; 889 const Token::Kind kind_;
892 const bool prefix_; 890 const bool prefix_;
893 AstNode* array_; 891 AstNode* array_;
894 AstNode* index_; 892 AstNode* index_;
895 const intptr_t operator_id_; 893 const intptr_t operator_id_;
896 const intptr_t store_id_; 894 const intptr_t store_id_;
897 ICData operator_ic_data_; 895 ICData& operator_ic_data_;
898 ICData store_ic_data_; 896 ICData& store_ic_data_;
899 }; 897 };
900 898
901 899
902 class ConditionalExprNode : public AstNode { 900 class ConditionalExprNode : public AstNode {
903 public: 901 public:
904 ConditionalExprNode(intptr_t token_index, 902 ConditionalExprNode(intptr_t token_index,
905 AstNode* condition, 903 AstNode* condition,
906 AstNode* true_expr, 904 AstNode* true_expr,
907 AstNode* false_expr) 905 AstNode* false_expr)
908 : AstNode(token_index), 906 : AstNode(token_index),
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 const LocalVariable& context_var_; 1914 const LocalVariable& context_var_;
1917 1915
1918 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); 1916 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode);
1919 }; 1917 };
1920 1918
1921 } // namespace dart 1919 } // namespace dart
1922 1920
1923 #undef DECLARE_COMMON_NODE_FUNCTIONS 1921 #undef DECLARE_COMMON_NODE_FUNCTIONS
1924 1922
1925 #endif // VM_AST_H_ 1923 #endif // VM_AST_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/code_generator.cc » ('j') | runtime/vm/code_generator_ia32.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698