| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 | 64 |
| 65 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; | 65 #define FORWARD_DECLARATION(ShortName, ClassName) class ClassName; |
| 66 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) | 66 FOR_EACH_COMPUTATION(FORWARD_DECLARATION) |
| 67 #undef FORWARD_DECLARATION | 67 #undef FORWARD_DECLARATION |
| 68 | 68 |
| 69 class Computation : public ZoneAllocated { | 69 class Computation : public ZoneAllocated { |
| 70 public: | 70 public: |
| 71 static const int kNoCid = -1; | 71 static const int kNoCid = -1; |
| 72 | 72 |
| 73 Computation() : cid_(GetNextCid()) { } | 73 Computation() : cid_(-1), ic_data_(NULL) { |
| 74 Isolate* isolate = Isolate::Current(); |
| 75 cid_ = GetNextCid(isolate); |
| 76 ic_data_ = GetICDataForCid(cid_, isolate); |
| 77 } |
| 74 | 78 |
| 75 // Unique computation/instruction id, used for deoptimization. | 79 // Unique computation/instruction id, used for deoptimization. |
| 76 intptr_t cid() const { return cid_; } | 80 intptr_t cid() const { return cid_; } |
| 77 | 81 |
| 82 const ICData* ic_data() const { return ic_data_; } |
| 83 |
| 78 // Visiting support. | 84 // Visiting support. |
| 79 virtual void Accept(FlowGraphVisitor* visitor) = 0; | 85 virtual void Accept(FlowGraphVisitor* visitor) = 0; |
| 80 | 86 |
| 81 virtual intptr_t InputCount() const = 0; | 87 virtual intptr_t InputCount() const = 0; |
| 82 | 88 |
| 83 private: | 89 private: |
| 84 friend class Instruction; | 90 friend class Instruction; |
| 85 static intptr_t GetNextCid() { | 91 static intptr_t GetNextCid(Isolate* isolate) { |
| 86 Isolate* isolate = Isolate::Current(); | |
| 87 intptr_t tmp = isolate->computation_id(); | 92 intptr_t tmp = isolate->computation_id(); |
| 88 isolate->set_computation_id(tmp + 1); | 93 isolate->set_computation_id(tmp + 1); |
| 89 return tmp; | 94 return tmp; |
| 90 } | 95 } |
| 96 static ICData* GetICDataForCid(intptr_t cid, Isolate* isolate) { |
| 97 if (isolate->ic_data_array() == Array::null()) { |
| 98 return NULL; |
| 99 } else { |
| 100 const Array& array_handle = Array::Handle(isolate->ic_data_array()); |
| 101 ICData& ic_data_handle = ICData::ZoneHandle(); |
| 102 if (cid < array_handle.Length()) { |
| 103 ic_data_handle ^= array_handle.At(cid); |
| 104 } |
| 105 return &ic_data_handle; |
| 106 } |
| 107 } |
| 91 | 108 |
| 92 const intptr_t cid_; | 109 intptr_t cid_; |
| 110 ICData* ic_data_; |
| 93 | 111 |
| 94 DISALLOW_COPY_AND_ASSIGN(Computation); | 112 DISALLOW_COPY_AND_ASSIGN(Computation); |
| 95 }; | 113 }; |
| 96 | 114 |
| 97 | 115 |
| 98 // An embedded container with N elements of type T. Used (with partial | 116 // An embedded container with N elements of type T. Used (with partial |
| 99 // specialization for N=0) because embedded arrays cannot have size 0. | 117 // specialization for N=0) because embedded arrays cannot have size 0. |
| 100 template<typename T, intptr_t N> | 118 template<typename T, intptr_t N> |
| 101 class EmbeddedArray { | 119 class EmbeddedArray { |
| 102 public: | 120 public: |
| (...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1131 // Functions required in all concrete instruction classes. | 1149 // Functions required in all concrete instruction classes. |
| 1132 #define DECLARE_INSTRUCTION(type) \ | 1150 #define DECLARE_INSTRUCTION(type) \ |
| 1133 virtual Instruction* Accept(FlowGraphVisitor* visitor); \ | 1151 virtual Instruction* Accept(FlowGraphVisitor* visitor); \ |
| 1134 virtual bool Is##type() const { return true; } \ | 1152 virtual bool Is##type() const { return true; } \ |
| 1135 virtual type##Instr* As##type() { return this; } \ | 1153 virtual type##Instr* As##type() { return this; } \ |
| 1136 virtual intptr_t InputCount() const; \ | 1154 virtual intptr_t InputCount() const; \ |
| 1137 | 1155 |
| 1138 | 1156 |
| 1139 class Instruction : public ZoneAllocated { | 1157 class Instruction : public ZoneAllocated { |
| 1140 public: | 1158 public: |
| 1141 Instruction() : cid_(Computation::GetNextCid()) { } | 1159 Instruction() : cid_(-1), ic_data_(NULL) { |
| 1160 Isolate* isolate = Isolate::Current(); |
| 1161 cid_ = Computation::GetNextCid(isolate); |
| 1162 ic_data_ = Computation::GetICDataForCid(cid_, isolate); |
| 1163 } |
| 1142 | 1164 |
| 1143 // Unique computation/instruction id, used for deoptimization, e.g. for | 1165 // Unique computation/instruction id, used for deoptimization, e.g. for |
| 1144 // ReturnInstr, ThrowInstr and ReThrowInstr. | 1166 // ReturnInstr, ThrowInstr and ReThrowInstr. |
| 1145 intptr_t cid() const { return cid_; } | 1167 intptr_t cid() const { return cid_; } |
| 1146 | 1168 |
| 1169 const ICData* ic_data() const { return ic_data_; } |
| 1170 |
| 1147 virtual bool IsBlockEntry() const { return false; } | 1171 virtual bool IsBlockEntry() const { return false; } |
| 1148 BlockEntryInstr* AsBlockEntry() { | 1172 BlockEntryInstr* AsBlockEntry() { |
| 1149 return IsBlockEntry() ? reinterpret_cast<BlockEntryInstr*>(this) : NULL; | 1173 return IsBlockEntry() ? reinterpret_cast<BlockEntryInstr*>(this) : NULL; |
| 1150 } | 1174 } |
| 1151 virtual bool IsDefinition() const { return false; } | 1175 virtual bool IsDefinition() const { return false; } |
| 1152 Definition* AsDefinition() { | 1176 Definition* AsDefinition() { |
| 1153 return IsDefinition() ? reinterpret_cast<Definition*>(this) : NULL; | 1177 return IsDefinition() ? reinterpret_cast<Definition*>(this) : NULL; |
| 1154 } | 1178 } |
| 1155 | 1179 |
| 1156 virtual intptr_t InputCount() const = 0; | 1180 virtual intptr_t InputCount() const = 0; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1181 UNREACHABLE(); | 1205 UNREACHABLE(); |
| 1182 } | 1206 } |
| 1183 | 1207 |
| 1184 #define INSTRUCTION_TYPE_CHECK(type) \ | 1208 #define INSTRUCTION_TYPE_CHECK(type) \ |
| 1185 virtual bool Is##type() const { return false; } \ | 1209 virtual bool Is##type() const { return false; } \ |
| 1186 virtual type##Instr* As##type() { return NULL; } | 1210 virtual type##Instr* As##type() { return NULL; } |
| 1187 FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) | 1211 FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1188 #undef INSTRUCTION_TYPE_CHECK | 1212 #undef INSTRUCTION_TYPE_CHECK |
| 1189 | 1213 |
| 1190 private: | 1214 private: |
| 1191 const intptr_t cid_; | 1215 intptr_t cid_; |
| 1216 ICData* ic_data_; |
| 1192 DISALLOW_COPY_AND_ASSIGN(Instruction); | 1217 DISALLOW_COPY_AND_ASSIGN(Instruction); |
| 1193 }; | 1218 }; |
| 1194 | 1219 |
| 1195 | 1220 |
| 1196 // Basic block entries are administrative nodes. Joins are the only nodes | 1221 // Basic block entries are administrative nodes. Joins are the only nodes |
| 1197 // with multiple predecessors. Targets are the other basic block entries. | 1222 // with multiple predecessors. Targets are the other basic block entries. |
| 1198 // The types enforce edge-split form---joins are forbidden as the successors | 1223 // The types enforce edge-split form---joins are forbidden as the successors |
| 1199 // of branches. | 1224 // of branches. |
| 1200 class BlockEntryInstr : public Instruction { | 1225 class BlockEntryInstr : public Instruction { |
| 1201 public: | 1226 public: |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1635 const GrowableArray<BlockEntryInstr*>& block_order_; | 1660 const GrowableArray<BlockEntryInstr*>& block_order_; |
| 1636 | 1661 |
| 1637 private: | 1662 private: |
| 1638 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 1663 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 1639 }; | 1664 }; |
| 1640 | 1665 |
| 1641 | 1666 |
| 1642 } // namespace dart | 1667 } // namespace dart |
| 1643 | 1668 |
| 1644 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 1669 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |