| 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 1670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1681 | 1681 |
| 1682 // Instructions. | 1682 // Instructions. |
| 1683 | 1683 |
| 1684 // M is a single argument macro. It is applied to each concrete instruction | 1684 // M is a single argument macro. It is applied to each concrete instruction |
| 1685 // type name. The concrete instruction classes are the name with Instr | 1685 // type name. The concrete instruction classes are the name with Instr |
| 1686 // concatenated. | 1686 // concatenated. |
| 1687 #define FOR_EACH_INSTRUCTION(M) \ | 1687 #define FOR_EACH_INSTRUCTION(M) \ |
| 1688 M(GraphEntry) \ | 1688 M(GraphEntry) \ |
| 1689 M(JoinEntry) \ | 1689 M(JoinEntry) \ |
| 1690 M(TargetEntry) \ | 1690 M(TargetEntry) \ |
| 1691 M(Phi) \ |
| 1691 M(Bind) \ | 1692 M(Bind) \ |
| 1692 M(Phi) \ | 1693 M(Parameter) \ |
| 1694 M(ParallelMove) \ |
| 1693 M(Return) \ | 1695 M(Return) \ |
| 1694 M(Throw) \ | 1696 M(Throw) \ |
| 1695 M(ReThrow) \ | 1697 M(ReThrow) \ |
| 1698 M(Goto) \ |
| 1696 M(Branch) \ | 1699 M(Branch) \ |
| 1697 M(ParallelMove) \ | |
| 1698 M(Parameter) | |
| 1699 | 1700 |
| 1700 | 1701 |
| 1701 // Forward declarations for Instruction classes. | 1702 // Forward declarations for Instruction classes. |
| 1702 class BlockEntryInstr; | 1703 class BlockEntryInstr; |
| 1703 class FlowGraphBuilder; | 1704 class FlowGraphBuilder; |
| 1704 class Environment; | 1705 class Environment; |
| 1705 | 1706 |
| 1706 #define FORWARD_DECLARATION(type) class type##Instr; | 1707 #define FORWARD_DECLARATION(type) class type##Instr; |
| 1707 FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) | 1708 FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1708 #undef FORWARD_DECLARATION | 1709 #undef FORWARD_DECLARATION |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1760 ASSERT(!IsBlockEntry()); | 1761 ASSERT(!IsBlockEntry()); |
| 1761 previous_ = instr; | 1762 previous_ = instr; |
| 1762 } | 1763 } |
| 1763 | 1764 |
| 1764 Instruction* next() const { return next_; } | 1765 Instruction* next() const { return next_; } |
| 1765 void set_next(Instruction* instr) { | 1766 void set_next(Instruction* instr) { |
| 1766 ASSERT(!IsGraphEntry()); | 1767 ASSERT(!IsGraphEntry()); |
| 1767 ASSERT(!IsReturn()); | 1768 ASSERT(!IsReturn()); |
| 1768 ASSERT(!IsBranch()); | 1769 ASSERT(!IsBranch()); |
| 1769 ASSERT(!IsPhi()); | 1770 ASSERT(!IsPhi()); |
| 1771 ASSERT(instr == NULL || !instr->IsBlockEntry()); |
| 1770 // TODO(fschneider): Also add Throw and ReThrow to the list of instructions | 1772 // TODO(fschneider): Also add Throw and ReThrow to the list of instructions |
| 1771 // that do not have a successor. Currently, the graph builder will continue | 1773 // that do not have a successor. Currently, the graph builder will continue |
| 1772 // to append instruction in case of a Throw inside an expression. This | 1774 // to append instruction in case of a Throw inside an expression. This |
| 1773 // condition should be handled in the graph builder | 1775 // condition should be handled in the graph builder |
| 1774 next_ = instr; | 1776 next_ = instr; |
| 1775 } | 1777 } |
| 1776 | 1778 |
| 1777 // Normal instructions can have 0 (inside a block) or 1 (last instruction in | 1779 // Normal instructions can have 0 (inside a block) or 1 (last instruction in |
| 1778 // a block) successors. Branch instruction with >1 successors override this | 1780 // a block) successors. Branch instruction with >1 successors override this |
| 1779 // function. | 1781 // function. |
| 1780 virtual intptr_t SuccessorCount() const; | 1782 virtual intptr_t SuccessorCount() const; |
| 1781 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; | 1783 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; |
| 1782 | 1784 |
| 1785 void Goto(JoinEntryInstr* entry); |
| 1786 |
| 1783 // Discover basic-block structure by performing a recursive depth first | 1787 // Discover basic-block structure by performing a recursive depth first |
| 1784 // traversal of the instruction graph reachable from this instruction. As | 1788 // traversal of the instruction graph reachable from this instruction. As |
| 1785 // a side effect, the block entry instructions in the graph are assigned | 1789 // a side effect, the block entry instructions in the graph are assigned |
| 1786 // numbers in both preorder and postorder. The array 'preorder' maps | 1790 // numbers in both preorder and postorder. The array 'preorder' maps |
| 1787 // preorder block numbers to the block entry instruction with that number | 1791 // preorder block numbers to the block entry instruction with that number |
| 1788 // and analogously for the array 'postorder'. The depth first spanning | 1792 // and analogously for the array 'postorder'. The depth first spanning |
| 1789 // tree is recorded in the array 'parent', which maps preorder block | 1793 // tree is recorded in the array 'parent', which maps preorder block |
| 1790 // numbers to the preorder number of the block's spanning-tree parent. | 1794 // numbers to the preorder number of the block's spanning-tree parent. |
| 1791 // The array 'assigned_vars' maps preorder block numbers to the set of | 1795 // The array 'assigned_vars' maps preorder block numbers to the set of |
| 1792 // assigned frame-allocated local variables in the block. As a side | 1796 // assigned frame-allocated local variables in the block. As a side |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1851 ICData* ic_data_; | 1855 ICData* ic_data_; |
| 1852 Instruction* previous_; | 1856 Instruction* previous_; |
| 1853 Instruction* next_; | 1857 Instruction* next_; |
| 1854 Environment* env_; | 1858 Environment* env_; |
| 1855 DISALLOW_COPY_AND_ASSIGN(Instruction); | 1859 DISALLOW_COPY_AND_ASSIGN(Instruction); |
| 1856 }; | 1860 }; |
| 1857 | 1861 |
| 1858 | 1862 |
| 1859 class InstructionWithInputs : public Instruction { | 1863 class InstructionWithInputs : public Instruction { |
| 1860 public: | 1864 public: |
| 1861 InstructionWithInputs() : locs_(NULL) { | 1865 InstructionWithInputs() : locs_(NULL) { } |
| 1862 } | |
| 1863 | 1866 |
| 1864 virtual LocationSummary* locs() { | 1867 virtual LocationSummary* locs() { |
| 1865 if (locs_ == NULL) { | 1868 if (locs_ == NULL) { |
| 1866 locs_ = MakeLocationSummary(); | 1869 locs_ = MakeLocationSummary(); |
| 1867 } | 1870 } |
| 1868 return locs_; | 1871 return locs_; |
| 1869 } | 1872 } |
| 1870 | 1873 |
| 1871 virtual LocationSummary* MakeLocationSummary() const = 0; | 1874 virtual LocationSummary* MakeLocationSummary() const = 0; |
| 1872 | 1875 |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2285 private: | 2288 private: |
| 2286 const intptr_t token_pos_; | 2289 const intptr_t token_pos_; |
| 2287 const intptr_t try_index_; | 2290 const intptr_t try_index_; |
| 2288 Value* exception_; | 2291 Value* exception_; |
| 2289 Value* stack_trace_; | 2292 Value* stack_trace_; |
| 2290 | 2293 |
| 2291 DISALLOW_COPY_AND_ASSIGN(ReThrowInstr); | 2294 DISALLOW_COPY_AND_ASSIGN(ReThrowInstr); |
| 2292 }; | 2295 }; |
| 2293 | 2296 |
| 2294 | 2297 |
| 2298 class GotoInstr : public InstructionWithInputs { |
| 2299 public: |
| 2300 explicit GotoInstr(JoinEntryInstr* entry) : successor_(entry) { } |
| 2301 |
| 2302 DECLARE_INSTRUCTION(Goto) |
| 2303 |
| 2304 JoinEntryInstr* successor() const { return successor_; } |
| 2305 void set_successor(JoinEntryInstr* successor) { successor_ = successor; } |
| 2306 virtual intptr_t SuccessorCount() const; |
| 2307 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; |
| 2308 |
| 2309 virtual LocationSummary* MakeLocationSummary() const; |
| 2310 |
| 2311 virtual void EmitNativeCode(FlowGraphCompiler* compiler); |
| 2312 |
| 2313 private: |
| 2314 JoinEntryInstr* successor_; |
| 2315 }; |
| 2316 |
| 2317 |
| 2295 class BranchInstr : public InstructionWithInputs { | 2318 class BranchInstr : public InstructionWithInputs { |
| 2296 public: | 2319 public: |
| 2297 explicit BranchInstr(Value* value) | 2320 explicit BranchInstr(Value* value) |
| 2298 : InstructionWithInputs(), | 2321 : InstructionWithInputs(), |
| 2299 value_(value), | 2322 value_(value), |
| 2300 true_successor_(NULL), | 2323 true_successor_(NULL), |
| 2301 false_successor_(NULL), | 2324 false_successor_(NULL), |
| 2302 fused_with_comparison_(NULL), | 2325 fused_with_comparison_(NULL), |
| 2303 is_negated_(false) { } | 2326 is_negated_(false) { } |
| 2304 | 2327 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2490 const GrowableArray<BlockEntryInstr*>& block_order_; | 2513 const GrowableArray<BlockEntryInstr*>& block_order_; |
| 2491 | 2514 |
| 2492 private: | 2515 private: |
| 2493 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 2516 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 2494 }; | 2517 }; |
| 2495 | 2518 |
| 2496 | 2519 |
| 2497 } // namespace dart | 2520 } // namespace dart |
| 2498 | 2521 |
| 2499 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 2522 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |