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

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

Issue 8394061: Store IC data instead of array of classes in AST node, so that we can easier access targets and f... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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/compiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/assert.h" 9 #include "vm/assert.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
11 #include "vm/ic_data.h"
11 #include "vm/scopes.h" 12 #include "vm/scopes.h"
12 #include "vm/object.h" 13 #include "vm/object.h"
13 #include "vm/native_entry.h" 14 #include "vm/native_entry.h"
14 #include "vm/token.h" 15 #include "vm/token.h"
15 16
16 namespace dart { 17 namespace dart {
17 18
18 #define NODE_LIST(V) \ 19 #define NODE_LIST(V) \
19 V(ReturnNode, "return") \ 20 V(ReturnNode, "return") \
20 V(LiteralNode, "literal") \ 21 V(LiteralNode, "literal") \
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 virtual type* As##type() { return this; } 94 virtual type* As##type() { return this; }
94 95
95 96
96 class AstNode : public ZoneAllocated { 97 class AstNode : public ZoneAllocated {
97 public: 98 public:
98 static const int kInvalidId = -1; 99 static const int kInvalidId = -1;
99 100
100 explicit AstNode(intptr_t token_index) 101 explicit AstNode(intptr_t token_index)
101 : token_index_(token_index), 102 : token_index_(token_index),
102 id_(GetNextId()), 103 id_(GetNextId()),
103 collected_classes_(NULL), 104 ic_data_(Array::ZoneHandle()),
104 info_(NULL) { 105 info_(NULL) {
105 ASSERT(token_index >= 0); 106 ASSERT(token_index >= 0);
106 } 107 }
107 108
108 intptr_t token_index() const { return token_index_; } 109 intptr_t token_index() const { return token_index_; }
109 110
110 virtual const ZoneGrowableArray<const Class*>* CollectedClassesAtId( 111 virtual void SetIcDataArrayAtId(intptr_t node_id, const Array& value) {
111 intptr_t node_id) const {
112 ASSERT(id() == node_id); 112 ASSERT(id() == node_id);
113 return collected_classes_; 113 set_ic_data_array(value);
114 } 114 }
115 115
116 virtual void SetCollectedClassesAtId( 116 virtual const ICData& ICDataAtId(intptr_t node_id) const {
117 intptr_t node_id,
118 const ZoneGrowableArray<const Class*>* value) {
119 ASSERT(id() == node_id); 117 ASSERT(id() == node_id);
120 collected_classes_ = value; 118 return ic_data();
121 } 119 }
122 120
123 virtual bool HasId(intptr_t value) const { return id_ == value; } 121 virtual bool HasId(intptr_t value) const { return id_ == value; }
124 122
125 intptr_t id() const { return id_; } 123 intptr_t id() const { return id_; }
126 124
127 void set_info(CodeGenInfo* info) { info_ = info; } 125 void set_info(CodeGenInfo* info) { info_ = info; }
128 CodeGenInfo* info() const { return info_; } 126 CodeGenInfo* info() const { return info_; }
129 127
130 #define AST_TYPE_CHECK(type, name) \ 128 #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 166 // 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 167 // constant or not. Returns NULL if the expression is not a compile time
170 // constant. Otherwise, the return value is an approximation of the 168 // constant. Otherwise, the return value is an approximation of the
171 // actual value of the const expression. The type of the returned value 169 // actual value of the const expression. The type of the returned value
172 // corresponds to the type of the const expression and is either 170 // corresponds to the type of the const expression and is either
173 // Number, Integer, String, Bool, or anything else (not a subtype of 171 // Number, Integer, String, Bool, or anything else (not a subtype of
174 // the former). 172 // the former).
175 virtual const Instance* EvalConstExpr() const { return NULL; } 173 virtual const Instance* EvalConstExpr() const { return NULL; }
176 174
177 protected: 175 protected:
178 void set_collected_classes(const ZoneGrowableArray<const Class*>* value) { 176 void set_ic_data_array(const Array& value) {
179 collected_classes_ = value; 177 ic_data_.set_data(value);
180 } 178 }
181 179
182 const ZoneGrowableArray<const Class*>* collected_classes() const { 180 const ICData& ic_data() const { return ic_data_; }
183 return collected_classes_;
184 }
185 181
186 static intptr_t GetNextId() { 182 static intptr_t GetNextId() {
187 Isolate* isolate = Isolate::Current(); 183 Isolate* isolate = Isolate::Current();
188 intptr_t tmp = isolate->ast_node_id(); 184 intptr_t tmp = isolate->ast_node_id();
189 isolate->set_ast_node_id(tmp + 1); 185 isolate->set_ast_node_id(tmp + 1);
190 return tmp; 186 return tmp;
191 } 187 }
192 188
193 private: 189 private:
194 const intptr_t token_index_; 190 const intptr_t token_index_;
195 // 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.
196 const intptr_t id_; 192 const intptr_t id_;
197 // Possible classes of the node, collected using inline caches. 193 // IC data collected for this node.
198 // Inline caches contain all encountered receiver classes for that node. 194 ICData ic_data_;
199 const ZoneGrowableArray<const Class*>* collected_classes_;
200 // Used by optimizing compiler. 195 // Used by optimizing compiler.
201 CodeGenInfo* info_; 196 CodeGenInfo* info_;
202 DISALLOW_COPY_AND_ASSIGN(AstNode); 197 DISALLOW_COPY_AND_ASSIGN(AstNode);
203 }; 198 };
204 199
205 200
206 class SequenceNode : public AstNode { 201 class SequenceNode : public AstNode {
207 public: 202 public:
208 SequenceNode(intptr_t token_index, LocalScope* scope) 203 SequenceNode(intptr_t token_index, LocalScope* scope)
209 : AstNode(token_index), 204 : AstNode(token_index),
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 bool prefix, 633 bool prefix,
639 AstNode* receiver, 634 AstNode* receiver,
640 const String& field_name) 635 const String& field_name)
641 : AstNode(token_index), 636 : AstNode(token_index),
642 kind_(kind), 637 kind_(kind),
643 prefix_(prefix), 638 prefix_(prefix),
644 receiver_(receiver), 639 receiver_(receiver),
645 field_name_(field_name), 640 field_name_(field_name),
646 operator_id_(AstNode::GetNextId()), 641 operator_id_(AstNode::GetNextId()),
647 setter_id_(AstNode::GetNextId()), 642 setter_id_(AstNode::GetNextId()),
648 operator_collected_classes_(NULL), 643 operator_ic_data_(Array::ZoneHandle()),
649 setter_collected_classes_(NULL) { 644 setter_ic_data_(Array::ZoneHandle()) {
650 ASSERT(receiver_ != NULL); 645 ASSERT(receiver_ != NULL);
651 ASSERT(field_name_.IsZoneHandle()); 646 ASSERT(field_name_.IsZoneHandle());
652 ASSERT(kind_ == Token::kINCR || kind_ == Token::kDECR); 647 ASSERT(kind_ == Token::kINCR || kind_ == Token::kDECR);
653 } 648 }
654 649
655 Token::Kind kind() const { return kind_; } 650 Token::Kind kind() const { return kind_; }
656 bool prefix() const { return prefix_; } 651 bool prefix() const { return prefix_; }
657 AstNode* receiver() const { return receiver_; } 652 AstNode* receiver() const { return receiver_; }
658 const String& field_name() const { return field_name_; } 653 const String& field_name() const { return field_name_; }
659 654
660 intptr_t getter_id() const { return id(); } 655 intptr_t getter_id() const { return id(); }
661 intptr_t operator_id() const { return operator_id_; } 656 intptr_t operator_id() const { return operator_id_; }
662 intptr_t setter_id() const { return setter_id_; } 657 intptr_t setter_id() const { return setter_id_; }
663 658
664 virtual bool HasId(intptr_t value) const { 659 virtual bool HasId(intptr_t value) const {
665 return (getter_id() == value) || 660 return (getter_id() == value) ||
666 (operator_id() == value) || 661 (operator_id() == value) ||
667 (setter_id() == value); 662 (setter_id() == value);
668 } 663 }
669 664
670 virtual const ZoneGrowableArray<const Class*>* CollectedClassesAtId( 665 virtual void SetIcDataArrayAtId(intptr_t node_id, const Array& value) {
671 intptr_t node_id) const {
672 ASSERT(HasId(node_id)); 666 ASSERT(HasId(node_id));
673 if (node_id == getter_id()) { 667 if (node_id == getter_id()) {
674 return collected_classes(); 668 set_ic_data_array(value);
675 } else if (node_id == operator_id()) { 669 } else if (node_id == operator_id()) {
676 return operator_collected_classes_; 670 operator_ic_data_.set_data(value);
677 } else { 671 } else {
678 ASSERT(node_id == setter_id()); 672 ASSERT(node_id == setter_id());
679 return setter_collected_classes_; 673 setter_ic_data_.set_data(value);
680 } 674 }
681 } 675 }
682 676
683 virtual void SetCollectedClassesAtId( 677 virtual const ICData& ICDataAtId(intptr_t node_id) const {
684 intptr_t node_id,
685 const ZoneGrowableArray<const Class*>* value) {
686 ASSERT(HasId(node_id)); 678 ASSERT(HasId(node_id));
687 if (node_id == getter_id()) { 679 if (node_id == getter_id()) {
688 set_collected_classes(value); 680 return ic_data();
689 } else if (node_id == operator_id()) { 681 } else if (node_id == operator_id()) {
690 operator_collected_classes_ = value; 682 return operator_ic_data_;
691 } else { 683 } else {
692 ASSERT(node_id == setter_id()); 684 ASSERT(node_id == setter_id());
693 setter_collected_classes_ = value; 685 return setter_ic_data_;
694 } 686 }
695 } 687 }
696 688
697 virtual void VisitChildren(AstNodeVisitor* visitor) const { 689 virtual void VisitChildren(AstNodeVisitor* visitor) const {
698 receiver()->Visit(visitor); 690 receiver()->Visit(visitor);
699 } 691 }
700 692
701 virtual const char* Name() const; 693 virtual const char* Name() const;
702 694
703 DECLARE_COMMON_NODE_FUNCTIONS(IncrOpInstanceFieldNode); 695 DECLARE_COMMON_NODE_FUNCTIONS(IncrOpInstanceFieldNode);
704 696
705 private: 697 private:
706 const Token::Kind kind_; 698 const Token::Kind kind_;
707 const bool prefix_; 699 const bool prefix_;
708 AstNode* receiver_; 700 AstNode* receiver_;
709 const String& field_name_; 701 const String& field_name_;
710 const intptr_t operator_id_; 702 const intptr_t operator_id_;
711 const intptr_t setter_id_; 703 const intptr_t setter_id_;
712 const ZoneGrowableArray<const Class*>* operator_collected_classes_; 704 ICData operator_ic_data_;
713 const ZoneGrowableArray<const Class*>* setter_collected_classes_; 705 ICData setter_ic_data_;
714 706
715 DISALLOW_IMPLICIT_CONSTRUCTORS(IncrOpInstanceFieldNode); 707 DISALLOW_IMPLICIT_CONSTRUCTORS(IncrOpInstanceFieldNode);
716 }; 708 };
717 709
718 710
719 class IncrOpStaticFieldNode : public AstNode { 711 class IncrOpStaticFieldNode : public AstNode {
720 public: 712 public:
721 // Access the static field via a call to static getter. 713 // Access the static field via a call to static getter.
722 IncrOpStaticFieldNode(intptr_t token_index, 714 IncrOpStaticFieldNode(intptr_t token_index,
723 Token::Kind kind, 715 Token::Kind kind,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 bool prefix, 772 bool prefix,
781 AstNode* array, 773 AstNode* array,
782 AstNode* index) 774 AstNode* index)
783 : AstNode(token_index), 775 : AstNode(token_index),
784 kind_(kind), 776 kind_(kind),
785 prefix_(prefix), 777 prefix_(prefix),
786 array_(array), 778 array_(array),
787 index_(index), 779 index_(index),
788 operator_id_(AstNode::GetNextId()), 780 operator_id_(AstNode::GetNextId()),
789 store_id_(AstNode::GetNextId()), 781 store_id_(AstNode::GetNextId()),
790 operator_collected_classes_(NULL), 782 operator_ic_data_(Array::ZoneHandle()),
791 store_collected_classes_(NULL) { 783 store_ic_data_(Array::ZoneHandle()) {
792 ASSERT(kind_ == Token::kINCR || kind_ == Token::kDECR); 784 ASSERT(kind_ == Token::kINCR || kind_ == Token::kDECR);
793 ASSERT(array_ != NULL); 785 ASSERT(array_ != NULL);
794 ASSERT(index_ != NULL); 786 ASSERT(index_ != NULL);
795 } 787 }
796 788
797 Token::Kind kind() const { return kind_; } 789 Token::Kind kind() const { return kind_; }
798 bool prefix() const { return prefix_; } 790 bool prefix() const { return prefix_; }
799 AstNode* array() const { return array_; } 791 AstNode* array() const { return array_; }
800 AstNode* index() const { return index_; } 792 AstNode* index() const { return index_; }
801 793
802 intptr_t load_id() const { return id(); } 794 intptr_t load_id() const { return id(); }
803 intptr_t operator_id() const { return operator_id_; } 795 intptr_t operator_id() const { return operator_id_; }
804 intptr_t store_id() const { return store_id_; } 796 intptr_t store_id() const { return store_id_; }
805 797
806 virtual bool HasId(intptr_t value) const { 798 virtual bool HasId(intptr_t value) const {
807 return (load_id() == value) || 799 return (load_id() == value) ||
808 (operator_id() == value) || 800 (operator_id() == value) ||
809 (store_id() == value); 801 (store_id() == value);
810 } 802 }
811 803
812 virtual const ZoneGrowableArray<const Class*>* CollectedClassesAtId( 804 virtual const ICData& ICDataAtId(intptr_t node_id) const {
813 intptr_t node_id) const {
814 ASSERT(HasId(node_id)); 805 ASSERT(HasId(node_id));
815 if (node_id == load_id()) { 806 if (node_id == load_id()) {
816 return collected_classes(); 807 return ic_data();
817 } else if (node_id == operator_id()) { 808 } else if (node_id == operator_id()) {
818 return operator_collected_classes_; 809 return operator_ic_data_;
819 } else { 810 } else {
820 ASSERT(node_id == store_id()); 811 ASSERT(node_id == store_id());
821 return store_collected_classes_; 812 return store_ic_data_;
822 } 813 }
823 } 814 }
824 815
825 virtual void SetCollectedClassesAtId( 816 virtual void SetIcDataArrayAtId(intptr_t node_id, const Array& value) {
826 intptr_t node_id,
827 const ZoneGrowableArray<const Class*>* value) {
828 ASSERT(HasId(node_id)); 817 ASSERT(HasId(node_id));
829 if (node_id == load_id()) { 818 if (node_id == load_id()) {
830 set_collected_classes(value); 819 set_ic_data_array(value);
831 } else if (node_id == operator_id()) { 820 } else if (node_id == operator_id()) {
832 operator_collected_classes_ = value; 821 operator_ic_data_.set_data(value);
833 } else { 822 } else {
834 ASSERT(node_id == store_id()); 823 ASSERT(node_id == store_id());
835 store_collected_classes_ = value; 824 store_ic_data_.set_data(value);
836 } 825 }
837 } 826 }
838 827
839 virtual void VisitChildren(AstNodeVisitor* visitor) const { 828 virtual void VisitChildren(AstNodeVisitor* visitor) const {
840 array()->Visit(visitor); 829 array()->Visit(visitor);
841 index()->Visit(visitor); 830 index()->Visit(visitor);
842 } 831 }
843 832
844 virtual const char* Name() const; 833 virtual const char* Name() const;
845 834
846 DECLARE_COMMON_NODE_FUNCTIONS(IncrOpIndexedNode); 835 DECLARE_COMMON_NODE_FUNCTIONS(IncrOpIndexedNode);
847 836
848 private: 837 private:
849 const Token::Kind kind_; 838 const Token::Kind kind_;
850 const bool prefix_; 839 const bool prefix_;
851 AstNode* array_; 840 AstNode* array_;
852 AstNode* index_; 841 AstNode* index_;
853 const intptr_t operator_id_; 842 const intptr_t operator_id_;
854 const intptr_t store_id_; 843 const intptr_t store_id_;
855 const ZoneGrowableArray<const Class*>* operator_collected_classes_; 844 ICData operator_ic_data_;
856 const ZoneGrowableArray<const Class*>* store_collected_classes_; 845 ICData store_ic_data_;
857 }; 846 };
858 847
859 848
860 class ConditionalExprNode : public AstNode { 849 class ConditionalExprNode : public AstNode {
861 public: 850 public:
862 ConditionalExprNode(intptr_t token_index, 851 ConditionalExprNode(intptr_t token_index,
863 AstNode* condition, 852 AstNode* condition,
864 AstNode* true_expr, 853 AstNode* true_expr,
865 AstNode* false_expr) 854 AstNode* false_expr)
866 : AstNode(token_index), 855 : AstNode(token_index),
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 const LocalVariable& context_var_; 1864 const LocalVariable& context_var_;
1876 1865
1877 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); 1866 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode);
1878 }; 1867 };
1879 1868
1880 } // namespace dart 1869 } // namespace dart
1881 1870
1882 #undef DECLARE_COMMON_NODE_FUNCTIONS 1871 #undef DECLARE_COMMON_NODE_FUNCTIONS
1883 1872
1884 #endif // VM_AST_H_ 1873 #endif // VM_AST_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698