| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 void set_ic_data(ICData* value) { ic_data_ = value; } | 131 void set_ic_data(ICData* value) { ic_data_ = value; } |
| 132 bool HasICData() const { | 132 bool HasICData() const { |
| 133 return (ic_data() != NULL) && !ic_data()->IsNull(); | 133 return (ic_data() != NULL) && !ic_data()->IsNull(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Visiting support. | 136 // Visiting support. |
| 137 virtual void Accept(FlowGraphVisitor* visitor) = 0; | 137 virtual void Accept(FlowGraphVisitor* visitor) = 0; |
| 138 | 138 |
| 139 virtual intptr_t InputCount() const = 0; | 139 virtual intptr_t InputCount() const = 0; |
| 140 virtual Value* InputAt(intptr_t i) const = 0; | 140 virtual Value* InputAt(intptr_t i) const = 0; |
| 141 virtual void SetInputAt(intptr_t i, Value* value) = 0; |
| 141 | 142 |
| 142 // Static type of the computation. | 143 // Static type of the computation. |
| 143 virtual RawAbstractType* StaticType() const = 0; | 144 virtual RawAbstractType* StaticType() const = 0; |
| 144 | 145 |
| 145 // Mutate assigned_vars to add the local variable index for all | 146 // Mutate assigned_vars to add the local variable index for all |
| 146 // frame-allocated locals assigned to by the computation. | 147 // frame-allocated locals assigned to by the computation. |
| 147 virtual void RecordAssignedVars(BitVector* assigned_vars); | 148 virtual void RecordAssignedVars(BitVector* assigned_vars); |
| 148 | 149 |
| 149 virtual const char* DebugName() const = 0; | 150 virtual const char* DebugName() const = 0; |
| 150 | 151 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 return sentinel; | 278 return sentinel; |
| 278 } | 279 } |
| 279 }; | 280 }; |
| 280 | 281 |
| 281 | 282 |
| 282 template<intptr_t N> | 283 template<intptr_t N> |
| 283 class TemplateComputation : public Computation { | 284 class TemplateComputation : public Computation { |
| 284 public: | 285 public: |
| 285 virtual intptr_t InputCount() const { return N; } | 286 virtual intptr_t InputCount() const { return N; } |
| 286 virtual Value* InputAt(intptr_t i) const { return inputs_[i]; } | 287 virtual Value* InputAt(intptr_t i) const { return inputs_[i]; } |
| 288 virtual void SetInputAt(intptr_t i, Value* value) { inputs_[i] = value; } |
| 287 | 289 |
| 288 protected: | 290 protected: |
| 289 EmbeddedArray<Value*, N> inputs_; | 291 EmbeddedArray<Value*, N> inputs_; |
| 290 }; | 292 }; |
| 291 | 293 |
| 292 | 294 |
| 293 class Value : public TemplateComputation<0> { | 295 class Value : public TemplateComputation<0> { |
| 294 public: | 296 public: |
| 295 Value() { } | 297 Value() { } |
| 296 | 298 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 473 |
| 472 const Array& argument_names() const { return ast_node_.arguments()->names(); } | 474 const Array& argument_names() const { return ast_node_.arguments()->names(); } |
| 473 intptr_t token_index() const { return ast_node_.token_index(); } | 475 intptr_t token_index() const { return ast_node_.token_index(); } |
| 474 intptr_t try_index() const { return try_index_; } | 476 intptr_t try_index() const { return try_index_; } |
| 475 | 477 |
| 476 intptr_t ArgumentCount() const { return arguments_->length(); } | 478 intptr_t ArgumentCount() const { return arguments_->length(); } |
| 477 Value* ArgumentAt(intptr_t index) const { return (*arguments_)[index]; } | 479 Value* ArgumentAt(intptr_t index) const { return (*arguments_)[index]; } |
| 478 | 480 |
| 479 virtual intptr_t InputCount() const; | 481 virtual intptr_t InputCount() const; |
| 480 virtual Value* InputAt(intptr_t i) const { return ArgumentAt(i); } | 482 virtual Value* InputAt(intptr_t i) const { return ArgumentAt(i); } |
| 483 virtual void SetInputAt(intptr_t i, Value* value) { |
| 484 (*arguments_)[i] = value; |
| 485 } |
| 481 | 486 |
| 482 virtual void PrintOperandsTo(BufferFormatter* f) const; | 487 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 483 | 488 |
| 484 private: | 489 private: |
| 485 const ClosureCallNode& ast_node_; | 490 const ClosureCallNode& ast_node_; |
| 486 const intptr_t try_index_; | 491 const intptr_t try_index_; |
| 487 ZoneGrowableArray<Value*>* arguments_; | 492 ZoneGrowableArray<Value*>* arguments_; |
| 488 | 493 |
| 489 DISALLOW_COPY_AND_ASSIGN(ClosureCallComp); | 494 DISALLOW_COPY_AND_ASSIGN(ClosureCallComp); |
| 490 }; | 495 }; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 521 intptr_t try_index() const { return try_index_; } | 526 intptr_t try_index() const { return try_index_; } |
| 522 const String& function_name() const { return function_name_; } | 527 const String& function_name() const { return function_name_; } |
| 523 Token::Kind token_kind() const { return token_kind_; } | 528 Token::Kind token_kind() const { return token_kind_; } |
| 524 intptr_t ArgumentCount() const { return arguments_->length(); } | 529 intptr_t ArgumentCount() const { return arguments_->length(); } |
| 525 Value* ArgumentAt(intptr_t index) const { return (*arguments_)[index]; } | 530 Value* ArgumentAt(intptr_t index) const { return (*arguments_)[index]; } |
| 526 const Array& argument_names() const { return argument_names_; } | 531 const Array& argument_names() const { return argument_names_; } |
| 527 intptr_t checked_argument_count() const { return checked_argument_count_; } | 532 intptr_t checked_argument_count() const { return checked_argument_count_; } |
| 528 | 533 |
| 529 virtual intptr_t InputCount() const; | 534 virtual intptr_t InputCount() const; |
| 530 virtual Value* InputAt(intptr_t i) const { return ArgumentAt(i); } | 535 virtual Value* InputAt(intptr_t i) const { return ArgumentAt(i); } |
| 536 virtual void SetInputAt(intptr_t i, Value* value) { |
| 537 (*arguments_)[i] = value; |
| 538 } |
| 531 | 539 |
| 532 virtual void PrintOperandsTo(BufferFormatter* f) const; | 540 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 533 | 541 |
| 534 bool VerifyComputation(); | 542 bool VerifyComputation(); |
| 535 | 543 |
| 536 private: | 544 private: |
| 537 const intptr_t token_index_; | 545 const intptr_t token_index_; |
| 538 const intptr_t try_index_; | 546 const intptr_t try_index_; |
| 539 const String& function_name_; | 547 const String& function_name_; |
| 540 const Token::Kind token_kind_; // Binary op, unary op, kGET or kILLEGAL. | 548 const Token::Kind token_kind_; // Binary op, unary op, kGET or kILLEGAL. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 558 } | 566 } |
| 559 | 567 |
| 560 InstanceCallComp* instance_call() const { return instance_call_; } | 568 InstanceCallComp* instance_call() const { return instance_call_; } |
| 561 const ZoneGrowableArray<intptr_t>& class_ids() const { return class_ids_; } | 569 const ZoneGrowableArray<intptr_t>& class_ids() const { return class_ids_; } |
| 562 const ZoneGrowableArray<Function*>& targets() const { return targets_; } | 570 const ZoneGrowableArray<Function*>& targets() const { return targets_; } |
| 563 | 571 |
| 564 virtual intptr_t InputCount() const { return instance_call()->InputCount(); } | 572 virtual intptr_t InputCount() const { return instance_call()->InputCount(); } |
| 565 virtual Value* InputAt(intptr_t i) const { | 573 virtual Value* InputAt(intptr_t i) const { |
| 566 return instance_call()->ArgumentAt(i); | 574 return instance_call()->ArgumentAt(i); |
| 567 } | 575 } |
| 576 virtual void SetInputAt(intptr_t index, Value* value) { |
| 577 instance_call()->SetInputAt(index, value); |
| 578 } |
| 568 | 579 |
| 569 virtual void PrintOperandsTo(BufferFormatter* f) const { | 580 virtual void PrintOperandsTo(BufferFormatter* f) const { |
| 570 instance_call()->PrintOperandsTo(f); | 581 instance_call()->PrintOperandsTo(f); |
| 571 } | 582 } |
| 572 | 583 |
| 573 DECLARE_COMPUTATION(PolymorphicInstanceCall) | 584 DECLARE_COMPUTATION(PolymorphicInstanceCall) |
| 574 | 585 |
| 575 private: | 586 private: |
| 576 InstanceCallComp* instance_call_; | 587 InstanceCallComp* instance_call_; |
| 577 const ZoneGrowableArray<intptr_t>& class_ids_; | 588 const ZoneGrowableArray<intptr_t>& class_ids_; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 intptr_t try_index() const { return try_index_; } | 758 intptr_t try_index() const { return try_index_; } |
| 748 | 759 |
| 749 intptr_t ArgumentCount() const { return arguments_->length(); } | 760 intptr_t ArgumentCount() const { return arguments_->length(); } |
| 750 Value* ArgumentAt(intptr_t index) const { return (*arguments_)[index]; } | 761 Value* ArgumentAt(intptr_t index) const { return (*arguments_)[index]; } |
| 751 | 762 |
| 752 MethodRecognizer::Kind recognized() const { return recognized_; } | 763 MethodRecognizer::Kind recognized() const { return recognized_; } |
| 753 void set_recognized(MethodRecognizer::Kind kind) { recognized_ = kind; } | 764 void set_recognized(MethodRecognizer::Kind kind) { recognized_ = kind; } |
| 754 | 765 |
| 755 virtual intptr_t InputCount() const; | 766 virtual intptr_t InputCount() const; |
| 756 virtual Value* InputAt(intptr_t i) const { return ArgumentAt(i); } | 767 virtual Value* InputAt(intptr_t i) const { return ArgumentAt(i); } |
| 768 virtual void SetInputAt(intptr_t i, Value* value) { |
| 769 (*arguments_)[i] = value; |
| 770 } |
| 757 | 771 |
| 758 virtual void PrintOperandsTo(BufferFormatter* f) const; | 772 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 759 | 773 |
| 760 private: | 774 private: |
| 761 const intptr_t token_index_; | 775 const intptr_t token_index_; |
| 762 const intptr_t try_index_; | 776 const intptr_t try_index_; |
| 763 const Function& function_; | 777 const Function& function_; |
| 764 const Array& argument_names_; | 778 const Array& argument_names_; |
| 765 ZoneGrowableArray<Value*>* arguments_; | 779 ZoneGrowableArray<Value*>* arguments_; |
| 766 MethodRecognizer::Kind recognized_; | 780 MethodRecognizer::Kind recognized_; |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 | 1192 |
| 1179 DECLARE_COMPUTATION(AllocateObject) | 1193 DECLARE_COMPUTATION(AllocateObject) |
| 1180 | 1194 |
| 1181 const Function& constructor() const { return ast_node_.constructor(); } | 1195 const Function& constructor() const { return ast_node_.constructor(); } |
| 1182 intptr_t token_index() const { return ast_node_.token_index(); } | 1196 intptr_t token_index() const { return ast_node_.token_index(); } |
| 1183 intptr_t try_index() const { return try_index_; } | 1197 intptr_t try_index() const { return try_index_; } |
| 1184 const ZoneGrowableArray<Value*>& arguments() const { return *arguments_; } | 1198 const ZoneGrowableArray<Value*>& arguments() const { return *arguments_; } |
| 1185 | 1199 |
| 1186 virtual intptr_t InputCount() const; | 1200 virtual intptr_t InputCount() const; |
| 1187 virtual Value* InputAt(intptr_t i) const { return arguments()[i]; } | 1201 virtual Value* InputAt(intptr_t i) const { return arguments()[i]; } |
| 1202 virtual void SetInputAt(intptr_t i, Value* value) { |
| 1203 (*arguments_)[i] = value; |
| 1204 } |
| 1188 | 1205 |
| 1189 virtual void PrintOperandsTo(BufferFormatter* f) const; | 1206 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 1190 | 1207 |
| 1191 private: | 1208 private: |
| 1192 const ConstructorCallNode& ast_node_; | 1209 const ConstructorCallNode& ast_node_; |
| 1193 const intptr_t try_index_; | 1210 const intptr_t try_index_; |
| 1194 ZoneGrowableArray<Value*>* const arguments_; | 1211 ZoneGrowableArray<Value*>* const arguments_; |
| 1195 DISALLOW_COPY_AND_ASSIGN(AllocateObjectComp); | 1212 DISALLOW_COPY_AND_ASSIGN(AllocateObjectComp); |
| 1196 }; | 1213 }; |
| 1197 | 1214 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1208 | 1225 |
| 1209 DECLARE_COMPUTATION(AllocateObjectWithBoundsCheck) | 1226 DECLARE_COMPUTATION(AllocateObjectWithBoundsCheck) |
| 1210 | 1227 |
| 1211 const Function& constructor() const { return ast_node_.constructor(); } | 1228 const Function& constructor() const { return ast_node_.constructor(); } |
| 1212 intptr_t token_index() const { return ast_node_.token_index(); } | 1229 intptr_t token_index() const { return ast_node_.token_index(); } |
| 1213 intptr_t try_index() const { return try_index_; } | 1230 intptr_t try_index() const { return try_index_; } |
| 1214 const ZoneGrowableArray<Value*>& arguments() const { return *arguments_; } | 1231 const ZoneGrowableArray<Value*>& arguments() const { return *arguments_; } |
| 1215 | 1232 |
| 1216 virtual intptr_t InputCount() const; | 1233 virtual intptr_t InputCount() const; |
| 1217 virtual Value* InputAt(intptr_t i) const { return arguments()[i]; } | 1234 virtual Value* InputAt(intptr_t i) const { return arguments()[i]; } |
| 1235 virtual void SetInputAt(intptr_t i, Value* value) { |
| 1236 (*arguments_)[i] = value; |
| 1237 } |
| 1218 | 1238 |
| 1219 virtual void PrintOperandsTo(BufferFormatter* f) const; | 1239 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 1220 | 1240 |
| 1221 private: | 1241 private: |
| 1222 const ConstructorCallNode& ast_node_; | 1242 const ConstructorCallNode& ast_node_; |
| 1223 const intptr_t try_index_; | 1243 const intptr_t try_index_; |
| 1224 ZoneGrowableArray<Value*>* const arguments_; | 1244 ZoneGrowableArray<Value*>* const arguments_; |
| 1225 DISALLOW_COPY_AND_ASSIGN(AllocateObjectWithBoundsCheckComp); | 1245 DISALLOW_COPY_AND_ASSIGN(AllocateObjectWithBoundsCheckComp); |
| 1226 }; | 1246 }; |
| 1227 | 1247 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1247 DECLARE_COMPUTATION(CreateArray) | 1267 DECLARE_COMPUTATION(CreateArray) |
| 1248 | 1268 |
| 1249 intptr_t token_index() const { return token_index_; } | 1269 intptr_t token_index() const { return token_index_; } |
| 1250 intptr_t try_index() const { return try_index_; } | 1270 intptr_t try_index() const { return try_index_; } |
| 1251 intptr_t ElementCount() const { return elements_->length(); } | 1271 intptr_t ElementCount() const { return elements_->length(); } |
| 1252 Value* ElementAt(intptr_t i) const { return (*elements_)[i]; } | 1272 Value* ElementAt(intptr_t i) const { return (*elements_)[i]; } |
| 1253 Value* element_type() const { return inputs_[0]; } | 1273 Value* element_type() const { return inputs_[0]; } |
| 1254 | 1274 |
| 1255 virtual intptr_t InputCount() const; | 1275 virtual intptr_t InputCount() const; |
| 1256 virtual Value* InputAt(intptr_t i) const; | 1276 virtual Value* InputAt(intptr_t i) const; |
| 1277 virtual void SetInputAt(intptr_t i, Value* value); |
| 1257 | 1278 |
| 1258 virtual void PrintOperandsTo(BufferFormatter* f) const; | 1279 virtual void PrintOperandsTo(BufferFormatter* f) const; |
| 1259 | 1280 |
| 1260 private: | 1281 private: |
| 1261 const intptr_t token_index_; | 1282 const intptr_t token_index_; |
| 1262 const intptr_t try_index_; | 1283 const intptr_t try_index_; |
| 1263 ZoneGrowableArray<Value*>* const elements_; | 1284 ZoneGrowableArray<Value*>* const elements_; |
| 1264 | 1285 |
| 1265 DISALLOW_COPY_AND_ASSIGN(CreateArrayComp); | 1286 DISALLOW_COPY_AND_ASSIGN(CreateArrayComp); |
| 1266 }; | 1287 }; |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1748 #undef FORWARD_DECLARATION | 1769 #undef FORWARD_DECLARATION |
| 1749 | 1770 |
| 1750 | 1771 |
| 1751 // Functions required in all concrete instruction classes. | 1772 // Functions required in all concrete instruction classes. |
| 1752 #define DECLARE_INSTRUCTION(type) \ | 1773 #define DECLARE_INSTRUCTION(type) \ |
| 1753 virtual Instruction* Accept(FlowGraphVisitor* visitor); \ | 1774 virtual Instruction* Accept(FlowGraphVisitor* visitor); \ |
| 1754 virtual bool Is##type() const { return true; } \ | 1775 virtual bool Is##type() const { return true; } \ |
| 1755 virtual type##Instr* As##type() { return this; } \ | 1776 virtual type##Instr* As##type() { return this; } \ |
| 1756 virtual intptr_t InputCount() const; \ | 1777 virtual intptr_t InputCount() const; \ |
| 1757 virtual Value* InputAt(intptr_t i) const; \ | 1778 virtual Value* InputAt(intptr_t i) const; \ |
| 1779 virtual void SetInputAt(intptr_t i, Value* value); \ |
| 1758 virtual const char* DebugName() const { return #type; } \ | 1780 virtual const char* DebugName() const { return #type; } \ |
| 1759 virtual void PrintTo(BufferFormatter* f) const; \ | 1781 virtual void PrintTo(BufferFormatter* f) const; \ |
| 1760 virtual void PrintToVisualizer(BufferFormatter* f) const; | 1782 virtual void PrintToVisualizer(BufferFormatter* f) const; |
| 1761 | 1783 |
| 1762 | 1784 |
| 1763 class Instruction : public ZoneAllocated { | 1785 class Instruction : public ZoneAllocated { |
| 1764 public: | 1786 public: |
| 1765 Instruction() : cid_(-1), ic_data_(NULL) { | 1787 Instruction() : cid_(-1), ic_data_(NULL) { |
| 1766 Isolate* isolate = Isolate::Current(); | 1788 Isolate* isolate = Isolate::Current(); |
| 1767 cid_ = Computation::GetNextCid(isolate); | 1789 cid_ = Computation::GetNextCid(isolate); |
| 1768 ic_data_ = Computation::GetICDataForCid(cid_, isolate); | 1790 ic_data_ = Computation::GetICDataForCid(cid_, isolate); |
| 1769 } | 1791 } |
| 1770 | 1792 |
| 1771 // Unique computation/instruction id, used for deoptimization, e.g. for | 1793 // Unique computation/instruction id, used for deoptimization, e.g. for |
| 1772 // ReturnInstr, ThrowInstr and ReThrowInstr. | 1794 // ReturnInstr, ThrowInstr and ReThrowInstr. |
| 1773 intptr_t cid() const { return cid_; } | 1795 intptr_t cid() const { return cid_; } |
| 1774 | 1796 |
| 1775 const ICData* ic_data() const { return ic_data_; } | 1797 const ICData* ic_data() const { return ic_data_; } |
| 1776 | 1798 |
| 1777 virtual bool IsBlockEntry() const { return false; } | 1799 virtual bool IsBlockEntry() const { return false; } |
| 1778 BlockEntryInstr* AsBlockEntry() { | 1800 BlockEntryInstr* AsBlockEntry() { |
| 1779 return IsBlockEntry() ? reinterpret_cast<BlockEntryInstr*>(this) : NULL; | 1801 return IsBlockEntry() ? reinterpret_cast<BlockEntryInstr*>(this) : NULL; |
| 1780 } | 1802 } |
| 1781 virtual bool IsDefinition() const { return false; } | 1803 virtual bool IsDefinition() const { return false; } |
| 1782 virtual Definition* AsDefinition() { return NULL; } | 1804 virtual Definition* AsDefinition() { return NULL; } |
| 1783 | 1805 |
| 1784 virtual intptr_t InputCount() const = 0; | 1806 virtual intptr_t InputCount() const = 0; |
| 1785 virtual Value* InputAt(intptr_t i) const = 0; | 1807 virtual Value* InputAt(intptr_t i) const = 0; |
| 1808 virtual void SetInputAt(intptr_t i, Value* value) = 0; |
| 1786 | 1809 |
| 1787 // Visiting support. | 1810 // Visiting support. |
| 1788 virtual Instruction* Accept(FlowGraphVisitor* visitor) = 0; | 1811 virtual Instruction* Accept(FlowGraphVisitor* visitor) = 0; |
| 1789 | 1812 |
| 1790 virtual Instruction* StraightLineSuccessor() const = 0; | 1813 virtual Instruction* StraightLineSuccessor() const = 0; |
| 1791 virtual void SetSuccessor(Instruction* instr) = 0; | 1814 virtual void SetSuccessor(Instruction* instr) = 0; |
| 1792 | 1815 |
| 1793 // Normal instructions can have 0 (inside a block) or 1 (last instruction in | 1816 // Normal instructions can have 0 (inside a block) or 1 (last instruction in |
| 1794 // a block) successors. Branch instruction with >1 successors override this | 1817 // a block) successors. Branch instruction with >1 successors override this |
| 1795 // function. | 1818 // function. |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1946 GrowableArray<BlockEntryInstr*> dominated_blocks_; | 1969 GrowableArray<BlockEntryInstr*> dominated_blocks_; |
| 1947 Instruction* last_instruction_; | 1970 Instruction* last_instruction_; |
| 1948 | 1971 |
| 1949 DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr); | 1972 DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr); |
| 1950 }; | 1973 }; |
| 1951 | 1974 |
| 1952 | 1975 |
| 1953 class GraphEntryInstr : public BlockEntryInstr { | 1976 class GraphEntryInstr : public BlockEntryInstr { |
| 1954 public: | 1977 public: |
| 1955 explicit GraphEntryInstr(TargetEntryInstr* normal_entry) | 1978 explicit GraphEntryInstr(TargetEntryInstr* normal_entry) |
| 1956 : BlockEntryInstr(), normal_entry_(normal_entry), catch_entries_() { } | 1979 : BlockEntryInstr(), |
| 1980 normal_entry_(normal_entry), |
| 1981 catch_entries_(), |
| 1982 start_env_(NULL) { } |
| 1957 | 1983 |
| 1958 DECLARE_INSTRUCTION(GraphEntry) | 1984 DECLARE_INSTRUCTION(GraphEntry) |
| 1959 | 1985 |
| 1960 virtual intptr_t PredecessorCount() const { return 0; } | 1986 virtual intptr_t PredecessorCount() const { return 0; } |
| 1961 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const { | 1987 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const { |
| 1962 UNREACHABLE(); | 1988 UNREACHABLE(); |
| 1963 return NULL; | 1989 return NULL; |
| 1964 } | 1990 } |
| 1965 virtual void AddPredecessor(BlockEntryInstr* predecessor) { UNREACHABLE(); } | 1991 virtual void AddPredecessor(BlockEntryInstr* predecessor) { UNREACHABLE(); } |
| 1966 | 1992 |
| 1967 virtual Instruction* StraightLineSuccessor() const { return NULL; } | 1993 virtual Instruction* StraightLineSuccessor() const { return NULL; } |
| 1968 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } | 1994 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } |
| 1969 | 1995 |
| 1970 virtual intptr_t SuccessorCount() const; | 1996 virtual intptr_t SuccessorCount() const; |
| 1971 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; | 1997 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; |
| 1972 | 1998 |
| 1973 virtual void DiscoverBlocks( | 1999 virtual void DiscoverBlocks( |
| 1974 BlockEntryInstr* current_block, | 2000 BlockEntryInstr* current_block, |
| 1975 GrowableArray<BlockEntryInstr*>* preorder, | 2001 GrowableArray<BlockEntryInstr*>* preorder, |
| 1976 GrowableArray<BlockEntryInstr*>* postorder, | 2002 GrowableArray<BlockEntryInstr*>* postorder, |
| 1977 GrowableArray<intptr_t>* parent, | 2003 GrowableArray<intptr_t>* parent, |
| 1978 GrowableArray<BitVector*>* assigned_vars, | 2004 GrowableArray<BitVector*>* assigned_vars, |
| 1979 intptr_t variable_count); | 2005 intptr_t variable_count); |
| 1980 | 2006 |
| 1981 void AddCatchEntry(TargetEntryInstr* entry) { catch_entries_.Add(entry); } | 2007 void AddCatchEntry(TargetEntryInstr* entry) { catch_entries_.Add(entry); } |
| 1982 | 2008 |
| 1983 virtual void PrepareEntry(FlowGraphCompiler* compiler); | 2009 virtual void PrepareEntry(FlowGraphCompiler* compiler); |
| 1984 | 2010 |
| 2011 ZoneGrowableArray<Value*>* start_env() const { return start_env_; } |
| 2012 void set_start_env(ZoneGrowableArray<Value*>* env) { start_env_ = env; } |
| 2013 |
| 1985 private: | 2014 private: |
| 1986 TargetEntryInstr* normal_entry_; | 2015 TargetEntryInstr* normal_entry_; |
| 1987 GrowableArray<TargetEntryInstr*> catch_entries_; | 2016 GrowableArray<TargetEntryInstr*> catch_entries_; |
| 2017 ZoneGrowableArray<Value*>* start_env_; |
| 1988 | 2018 |
| 1989 DISALLOW_COPY_AND_ASSIGN(GraphEntryInstr); | 2019 DISALLOW_COPY_AND_ASSIGN(GraphEntryInstr); |
| 1990 }; | 2020 }; |
| 1991 | 2021 |
| 1992 | 2022 |
| 1993 class JoinEntryInstr : public BlockEntryInstr { | 2023 class JoinEntryInstr : public BlockEntryInstr { |
| 1994 public: | 2024 public: |
| 1995 JoinEntryInstr() | 2025 JoinEntryInstr() |
| 1996 : BlockEntryInstr(), | 2026 : BlockEntryInstr(), |
| 1997 predecessors_(2), // Two is the assumed to be the common case. | 2027 predecessors_(2), // Two is the assumed to be the common case. |
| 1998 successor_(NULL), | 2028 successor_(NULL), |
| 1999 phis_(NULL), | 2029 phis_(NULL), |
| 2000 phi_count_(0) { } | 2030 phi_count_(0) { } |
| 2001 | 2031 |
| 2002 DECLARE_INSTRUCTION(JoinEntry) | 2032 DECLARE_INSTRUCTION(JoinEntry) |
| 2003 | 2033 |
| 2004 virtual intptr_t PredecessorCount() const { return predecessors_.length(); } | 2034 virtual intptr_t PredecessorCount() const { return predecessors_.length(); } |
| 2005 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const { | 2035 virtual BlockEntryInstr* PredecessorAt(intptr_t index) const { |
| 2006 return predecessors_[index]; | 2036 return predecessors_[index]; |
| 2007 } | 2037 } |
| 2008 virtual void AddPredecessor(BlockEntryInstr* predecessor) { | 2038 virtual void AddPredecessor(BlockEntryInstr* predecessor) { |
| 2009 predecessors_.Add(predecessor); | 2039 predecessors_.Add(predecessor); |
| 2010 } | 2040 } |
| 2011 | 2041 |
| 2012 virtual Instruction* StraightLineSuccessor() const { | 2042 virtual Instruction* StraightLineSuccessor() const { |
| 2013 return successor_; | 2043 return successor_; |
| 2014 } | 2044 } |
| 2015 virtual void SetSuccessor(Instruction* instr) { | 2045 virtual void SetSuccessor(Instruction* instr) { |
| 2016 ASSERT(successor_ == NULL); | |
| 2017 successor_ = instr; | 2046 successor_ = instr; |
| 2018 } | 2047 } |
| 2019 | 2048 |
| 2020 ZoneGrowableArray<PhiInstr*>* phis() const { return phis_; } | 2049 ZoneGrowableArray<PhiInstr*>* phis() const { return phis_; } |
| 2021 | 2050 |
| 2022 virtual void PrepareEntry(FlowGraphCompiler* compiler); | 2051 virtual void PrepareEntry(FlowGraphCompiler* compiler); |
| 2023 | 2052 |
| 2024 void InsertPhi(intptr_t var_index, intptr_t var_count); | 2053 void InsertPhi(intptr_t var_index, intptr_t var_count); |
| 2025 | 2054 |
| 2026 intptr_t phi_count() const { return phi_count_; } | 2055 intptr_t phi_count() const { return phi_count_; } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2061 } | 2090 } |
| 2062 virtual void AddPredecessor(BlockEntryInstr* predecessor) { | 2091 virtual void AddPredecessor(BlockEntryInstr* predecessor) { |
| 2063 ASSERT(predecessor_ == NULL); | 2092 ASSERT(predecessor_ == NULL); |
| 2064 predecessor_ = predecessor; | 2093 predecessor_ = predecessor; |
| 2065 } | 2094 } |
| 2066 | 2095 |
| 2067 virtual Instruction* StraightLineSuccessor() const { | 2096 virtual Instruction* StraightLineSuccessor() const { |
| 2068 return successor_; | 2097 return successor_; |
| 2069 } | 2098 } |
| 2070 virtual void SetSuccessor(Instruction* instr) { | 2099 virtual void SetSuccessor(Instruction* instr) { |
| 2071 ASSERT(successor_ == NULL); | |
| 2072 successor_ = instr; | 2100 successor_ = instr; |
| 2073 } | 2101 } |
| 2074 | 2102 |
| 2075 bool HasTryIndex() const { | 2103 bool HasTryIndex() const { |
| 2076 return try_index_ != CatchClauseNode::kInvalidTryIndex; | 2104 return try_index_ != CatchClauseNode::kInvalidTryIndex; |
| 2077 } | 2105 } |
| 2078 | 2106 |
| 2079 intptr_t try_index() const { | 2107 intptr_t try_index() const { |
| 2080 ASSERT(HasTryIndex()); | 2108 ASSERT(HasTryIndex()); |
| 2081 return try_index_; | 2109 return try_index_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2103 DECLARE_INSTRUCTION(Do) | 2131 DECLARE_INSTRUCTION(Do) |
| 2104 | 2132 |
| 2105 Computation* computation() const { return computation_; } | 2133 Computation* computation() const { return computation_; } |
| 2106 virtual void replace_computation(Computation* value) { computation_ = value; } | 2134 virtual void replace_computation(Computation* value) { computation_ = value; } |
| 2107 | 2135 |
| 2108 virtual Instruction* StraightLineSuccessor() const { | 2136 virtual Instruction* StraightLineSuccessor() const { |
| 2109 return successor_; | 2137 return successor_; |
| 2110 } | 2138 } |
| 2111 | 2139 |
| 2112 virtual void SetSuccessor(Instruction* instr) { | 2140 virtual void SetSuccessor(Instruction* instr) { |
| 2113 ASSERT(successor_ == NULL); | |
| 2114 successor_ = instr; | 2141 successor_ = instr; |
| 2115 } | 2142 } |
| 2116 | 2143 |
| 2117 virtual void RecordAssignedVars(BitVector* assigned_vars); | 2144 virtual void RecordAssignedVars(BitVector* assigned_vars); |
| 2118 | 2145 |
| 2119 virtual LocationSummary* locs() { | 2146 virtual LocationSummary* locs() { |
| 2120 return computation()->locs(); | 2147 return computation()->locs(); |
| 2121 } | 2148 } |
| 2122 | 2149 |
| 2123 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { | 2150 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { |
| 2124 computation()->EmitNativeCode(compiler); | 2151 computation()->EmitNativeCode(compiler); |
| 2125 } | 2152 } |
| 2126 | 2153 |
| 2127 private: | 2154 private: |
| 2128 Computation* computation_; | 2155 Computation* computation_; |
| 2129 Instruction* successor_; | 2156 Instruction* successor_; |
| 2130 | 2157 |
| 2131 DISALLOW_COPY_AND_ASSIGN(DoInstr); | 2158 DISALLOW_COPY_AND_ASSIGN(DoInstr); |
| 2132 }; | 2159 }; |
| 2133 | 2160 |
| 2134 | 2161 |
| 2135 // Abstract super-class of all instructions that define a value (Bind, Phi). | 2162 // Abstract super-class of all instructions that define a value (Bind, Phi). |
| 2136 class Definition : public Instruction { | 2163 class Definition : public Instruction { |
| 2137 public: | 2164 public: |
| 2138 Definition() : temp_index_(-1) { } | 2165 Definition() : temp_index_(-1), ssa_temp_index_(-1) { } |
| 2139 | 2166 |
| 2140 virtual bool IsDefinition() const { return true; } | 2167 virtual bool IsDefinition() const { return true; } |
| 2141 virtual Definition* AsDefinition() { return this; } | 2168 virtual Definition* AsDefinition() { return this; } |
| 2142 | 2169 |
| 2143 intptr_t temp_index() const { return temp_index_; } | 2170 intptr_t temp_index() const { return temp_index_; } |
| 2144 void set_temp_index(intptr_t index) { temp_index_ = index; } | 2171 void set_temp_index(intptr_t index) { temp_index_ = index; } |
| 2145 | 2172 |
| 2173 intptr_t ssa_temp_index() const { return ssa_temp_index_; } |
| 2174 void set_ssa_temp_index(intptr_t index) { ssa_temp_index_ = index; } |
| 2175 |
| 2146 private: | 2176 private: |
| 2147 intptr_t temp_index_; | 2177 intptr_t temp_index_; |
| 2178 intptr_t ssa_temp_index_; |
| 2148 | 2179 |
| 2149 DISALLOW_COPY_AND_ASSIGN(Definition); | 2180 DISALLOW_COPY_AND_ASSIGN(Definition); |
| 2150 }; | 2181 }; |
| 2151 | 2182 |
| 2152 | 2183 |
| 2153 class BindInstr : public Definition { | 2184 class BindInstr : public Definition { |
| 2154 public: | 2185 public: |
| 2155 explicit BindInstr(Computation* computation) | 2186 explicit BindInstr(Computation* computation) |
| 2156 : computation_(computation), successor_(NULL) { | 2187 : computation_(computation), successor_(NULL) { |
| 2157 ASSERT(computation != NULL); | 2188 ASSERT(computation != NULL); |
| 2158 computation->set_instr(this); | 2189 computation->set_instr(this); |
| 2159 } | 2190 } |
| 2160 | 2191 |
| 2161 DECLARE_INSTRUCTION(Bind) | 2192 DECLARE_INSTRUCTION(Bind) |
| 2162 | 2193 |
| 2163 Computation* computation() const { return computation_; } | 2194 Computation* computation() const { return computation_; } |
| 2164 virtual void replace_computation(Computation* value) { computation_ = value; } | 2195 virtual void replace_computation(Computation* value) { computation_ = value; } |
| 2165 | 2196 |
| 2166 virtual Instruction* StraightLineSuccessor() const { | 2197 virtual Instruction* StraightLineSuccessor() const { |
| 2167 return successor_; | 2198 return successor_; |
| 2168 } | 2199 } |
| 2169 | 2200 |
| 2170 virtual void SetSuccessor(Instruction* instr) { | 2201 virtual void SetSuccessor(Instruction* instr) { |
| 2171 ASSERT(successor_ == NULL); | |
| 2172 successor_ = instr; | 2202 successor_ = instr; |
| 2173 } | 2203 } |
| 2174 | 2204 |
| 2175 // Static type of the underlying computation. | 2205 // Static type of the underlying computation. |
| 2176 virtual RawAbstractType* StaticType() const { | 2206 virtual RawAbstractType* StaticType() const { |
| 2177 return computation()->StaticType(); | 2207 return computation()->StaticType(); |
| 2178 } | 2208 } |
| 2179 | 2209 |
| 2180 virtual void RecordAssignedVars(BitVector* assigned_vars); | 2210 virtual void RecordAssignedVars(BitVector* assigned_vars); |
| 2181 | 2211 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2196 class PhiInstr: public Definition { | 2226 class PhiInstr: public Definition { |
| 2197 public: | 2227 public: |
| 2198 explicit PhiInstr(intptr_t num_inputs) : inputs_(num_inputs) { | 2228 explicit PhiInstr(intptr_t num_inputs) : inputs_(num_inputs) { |
| 2199 for (intptr_t i = 0; i < num_inputs; ++i) { | 2229 for (intptr_t i = 0; i < num_inputs; ++i) { |
| 2200 inputs_.Add(NULL); | 2230 inputs_.Add(NULL); |
| 2201 } | 2231 } |
| 2202 } | 2232 } |
| 2203 | 2233 |
| 2204 DECLARE_INSTRUCTION(Phi) | 2234 DECLARE_INSTRUCTION(Phi) |
| 2205 | 2235 |
| 2206 void SetInputAt(intptr_t i, Value* value) { | |
| 2207 inputs_[i] = value; | |
| 2208 } | |
| 2209 | |
| 2210 virtual Instruction* StraightLineSuccessor() const { return NULL; } | 2236 virtual Instruction* StraightLineSuccessor() const { return NULL; } |
| 2211 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } | 2237 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } |
| 2212 | 2238 |
| 2213 private: | 2239 private: |
| 2214 GrowableArray<Value*> inputs_; | 2240 GrowableArray<Value*> inputs_; |
| 2215 | 2241 |
| 2216 DISALLOW_COPY_AND_ASSIGN(PhiInstr); | 2242 DISALLOW_COPY_AND_ASSIGN(PhiInstr); |
| 2217 }; | 2243 }; |
| 2218 | 2244 |
| 2219 | 2245 |
| 2220 | |
| 2221 | |
| 2222 class ReturnInstr : public InstructionWithInputs { | 2246 class ReturnInstr : public InstructionWithInputs { |
| 2223 public: | 2247 public: |
| 2224 ReturnInstr(intptr_t token_index, Value* value) | 2248 ReturnInstr(intptr_t token_index, Value* value) |
| 2225 : InstructionWithInputs(), token_index_(token_index), value_(value) { | 2249 : InstructionWithInputs(), token_index_(token_index), value_(value) { |
| 2226 ASSERT(value_ != NULL); | 2250 ASSERT(value_ != NULL); |
| 2227 } | 2251 } |
| 2228 | 2252 |
| 2229 DECLARE_INSTRUCTION(Return) | 2253 DECLARE_INSTRUCTION(Return) |
| 2230 | 2254 |
| 2231 Value* value() const { return value_; } | 2255 Value* value() const { return value_; } |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2420 const GrowableArray<BlockEntryInstr*>& block_order_; | 2444 const GrowableArray<BlockEntryInstr*>& block_order_; |
| 2421 | 2445 |
| 2422 private: | 2446 private: |
| 2423 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 2447 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 2424 }; | 2448 }; |
| 2425 | 2449 |
| 2426 | 2450 |
| 2427 } // namespace dart | 2451 } // namespace dart |
| 2428 | 2452 |
| 2429 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 2453 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |