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

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

Issue 10453098: Move Throw and ReThrow to the location based code generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Move Branch as well, introduce base class for instruction with inputs Created 8 years, 6 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
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_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 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 #undef INSTRUCTION_TYPE_CHECK 1424 #undef INSTRUCTION_TYPE_CHECK
1425 1425
1426 // Static type of the instruction. 1426 // Static type of the instruction.
1427 virtual RawAbstractType* StaticType() const { 1427 virtual RawAbstractType* StaticType() const {
1428 UNREACHABLE(); 1428 UNREACHABLE();
1429 return AbstractType::null(); 1429 return AbstractType::null();
1430 } 1430 }
1431 1431
1432 // Returns structure describing location constraints required 1432 // Returns structure describing location constraints required
1433 // to emit native code for this instruction. 1433 // to emit native code for this instruction.
1434 virtual LocationSummary* locs() const { 1434 virtual LocationSummary* locs() {
1435 // TODO(vegorov): This should be pure virtual method. 1435 // TODO(vegorov): This should be pure virtual method.
1436 // However we are temporary using NULL for instructions that 1436 // However we are temporary using NULL for instructions that
1437 // were not converted to the location based code generation yet. 1437 // were not converted to the location based code generation yet.
1438 return NULL; 1438 return NULL;
1439 } 1439 }
1440 1440
1441 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { 1441 virtual void EmitNativeCode(FlowGraphCompiler* compiler) {
1442 UNIMPLEMENTED(); 1442 UNIMPLEMENTED();
1443 } 1443 }
1444 1444
1445 private: 1445 private:
1446 intptr_t cid_; 1446 intptr_t cid_;
1447 ICData* ic_data_; 1447 ICData* ic_data_;
1448 DISALLOW_COPY_AND_ASSIGN(Instruction); 1448 DISALLOW_COPY_AND_ASSIGN(Instruction);
1449 }; 1449 };
1450 1450
1451 1451
1452 class InstructionWithInputs : public Instruction {
1453 public:
1454 InstructionWithInputs() : locs_(NULL) {
1455 }
1456
1457 virtual LocationSummary* locs() {
1458 if (locs_ == NULL) {
1459 locs_ = MakeLocationSummary();
1460 }
1461 return locs_;
1462 }
1463
1464 virtual LocationSummary* MakeLocationSummary() const = 0;
1465
1466 private:
1467 LocationSummary* locs_;
srdjan 2012/05/31 16:00:53 Add DISALLOW_COPY_AND_ASSIGN. Generally I am not
1468 };
1469
1470
1452 // Basic block entries are administrative nodes. There is a distinguished 1471 // Basic block entries are administrative nodes. There is a distinguished
1453 // graph entry with no predecessor. Joins are the only nodes with multiple 1472 // graph entry with no predecessor. Joins are the only nodes with multiple
1454 // predecessors. Targets are all other basic block entries. The types 1473 // predecessors. Targets are all other basic block entries. The types
1455 // enforce edge-split form---joins are forbidden as the successors of 1474 // enforce edge-split form---joins are forbidden as the successors of
1456 // branches. 1475 // branches.
1457 class BlockEntryInstr : public Instruction { 1476 class BlockEntryInstr : public Instruction {
1458 public: 1477 public:
1459 virtual bool IsBlockEntry() const { return true; } 1478 virtual bool IsBlockEntry() const { return true; }
1460 1479
1461 virtual intptr_t PredecessorCount() const = 0; 1480 virtual intptr_t PredecessorCount() const = 0;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 return successor_; 1663 return successor_;
1645 } 1664 }
1646 1665
1647 virtual void SetSuccessor(Instruction* instr) { 1666 virtual void SetSuccessor(Instruction* instr) {
1648 ASSERT(successor_ == NULL); 1667 ASSERT(successor_ == NULL);
1649 successor_ = instr; 1668 successor_ = instr;
1650 } 1669 }
1651 1670
1652 virtual void RecordAssignedVars(BitVector* assigned_vars); 1671 virtual void RecordAssignedVars(BitVector* assigned_vars);
1653 1672
1654 virtual LocationSummary* locs() const { 1673 virtual LocationSummary* locs() {
1655 return computation()->locs(); 1674 return computation()->locs();
1656 } 1675 }
1657 1676
1658 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { 1677 virtual void EmitNativeCode(FlowGraphCompiler* compiler) {
1659 computation()->EmitNativeCode(compiler); 1678 computation()->EmitNativeCode(compiler);
1660 } 1679 }
1661 1680
1662 private: 1681 private:
1663 Computation* computation_; 1682 Computation* computation_;
1664 Instruction* successor_; 1683 Instruction* successor_;
(...skipping 30 matching lines...) Expand all
1695 successor_ = instr; 1714 successor_ = instr;
1696 } 1715 }
1697 1716
1698 // Static type of the underlying computation. 1717 // Static type of the underlying computation.
1699 virtual RawAbstractType* StaticType() const { 1718 virtual RawAbstractType* StaticType() const {
1700 return computation()->StaticType(); 1719 return computation()->StaticType();
1701 } 1720 }
1702 1721
1703 virtual void RecordAssignedVars(BitVector* assigned_vars); 1722 virtual void RecordAssignedVars(BitVector* assigned_vars);
1704 1723
1705 virtual LocationSummary* locs() const { 1724 virtual LocationSummary* locs() {
1706 return computation()->locs(); 1725 return computation()->locs();
1707 } 1726 }
1708 1727
1709 virtual void EmitNativeCode(FlowGraphCompiler* compiler); 1728 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
1710 1729
1711 private: 1730 private:
1712 intptr_t temp_index_; 1731 intptr_t temp_index_;
1713 Computation* computation_; 1732 Computation* computation_;
1714 Instruction* successor_; 1733 Instruction* successor_;
1715 1734
(...skipping 17 matching lines...) Expand all
1733 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } 1752 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); }
1734 1753
1735 private: 1754 private:
1736 const intptr_t token_index_; 1755 const intptr_t token_index_;
1737 Value* value_; 1756 Value* value_;
1738 1757
1739 DISALLOW_COPY_AND_ASSIGN(ReturnInstr); 1758 DISALLOW_COPY_AND_ASSIGN(ReturnInstr);
1740 }; 1759 };
1741 1760
1742 1761
1743 class ThrowInstr : public Instruction { 1762 class ThrowInstr : public InstructionWithInputs {
1744 public: 1763 public:
1745 ThrowInstr(intptr_t token_index, 1764 ThrowInstr(intptr_t token_index,
1746 intptr_t try_index, 1765 intptr_t try_index,
1747 Value* exception) 1766 Value* exception)
1748 : token_index_(token_index), 1767 : token_index_(token_index),
1749 try_index_(try_index), 1768 try_index_(try_index),
1750 exception_(exception), 1769 exception_(exception),
1751 successor_(NULL) { 1770 successor_(NULL) {
1752 ASSERT(exception_ != NULL); 1771 ASSERT(exception_ != NULL);
1753 } 1772 }
1754 1773
1755 DECLARE_INSTRUCTION(Throw) 1774 DECLARE_INSTRUCTION(Throw)
1756 1775
1757 intptr_t token_index() const { return token_index_; } 1776 intptr_t token_index() const { return token_index_; }
1758 intptr_t try_index() const { return try_index_; } 1777 intptr_t try_index() const { return try_index_; }
1759 Value* exception() const { return exception_; } 1778 Value* exception() const { return exception_; }
1760 1779
1761 // Parser can generate a throw within an expression tree. We never 1780 // Parser can generate a throw within an expression tree. We never
1762 // add successor instructions to the graph. 1781 // add successor instructions to the graph.
1763 virtual Instruction* StraightLineSuccessor() const { return NULL; } 1782 virtual Instruction* StraightLineSuccessor() const { return NULL; }
1764 virtual void SetSuccessor(Instruction* instr) { 1783 virtual void SetSuccessor(Instruction* instr) {
1765 ASSERT(successor_ == NULL); 1784 ASSERT(successor_ == NULL);
1766 } 1785 }
1767 1786
1787 virtual LocationSummary* MakeLocationSummary() const;
1788
1789 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
1790
1768 private: 1791 private:
1769 const intptr_t token_index_; 1792 const intptr_t token_index_;
1770 const intptr_t try_index_; 1793 const intptr_t try_index_;
1771 Value* exception_; 1794 Value* exception_;
1772 Instruction* successor_; 1795 Instruction* successor_;
1773 1796
1774 DISALLOW_COPY_AND_ASSIGN(ThrowInstr); 1797 DISALLOW_COPY_AND_ASSIGN(ThrowInstr);
1775 }; 1798 };
1776 1799
1777 1800
1778 class ReThrowInstr : public Instruction { 1801 class ReThrowInstr : public InstructionWithInputs {
1779 public: 1802 public:
1780 ReThrowInstr(intptr_t token_index, 1803 ReThrowInstr(intptr_t token_index,
1781 intptr_t try_index, 1804 intptr_t try_index,
1782 Value* exception, 1805 Value* exception,
1783 Value* stack_trace) 1806 Value* stack_trace)
1784 : token_index_(token_index), 1807 : token_index_(token_index),
1785 try_index_(try_index), 1808 try_index_(try_index),
1786 exception_(exception), 1809 exception_(exception),
1787 stack_trace_(stack_trace), 1810 stack_trace_(stack_trace),
1788 successor_(NULL) { 1811 successor_(NULL) {
(...skipping 10 matching lines...) Expand all
1799 1822
1800 // Parser can generate a rethrow within an expression tree. We 1823 // Parser can generate a rethrow within an expression tree. We
1801 // never add successor instructions to the graph. 1824 // never add successor instructions to the graph.
1802 virtual Instruction* StraightLineSuccessor() const { 1825 virtual Instruction* StraightLineSuccessor() const {
1803 return NULL; 1826 return NULL;
1804 } 1827 }
1805 virtual void SetSuccessor(Instruction* instr) { 1828 virtual void SetSuccessor(Instruction* instr) {
1806 ASSERT(successor_ == NULL); 1829 ASSERT(successor_ == NULL);
1807 } 1830 }
1808 1831
1832 virtual LocationSummary* MakeLocationSummary() const;
1833
1834 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
1835
1809 private: 1836 private:
1810 const intptr_t token_index_; 1837 const intptr_t token_index_;
1811 const intptr_t try_index_; 1838 const intptr_t try_index_;
1812 Value* exception_; 1839 Value* exception_;
1813 Value* stack_trace_; 1840 Value* stack_trace_;
1814 Instruction* successor_; 1841 Instruction* successor_;
1815 1842
1816 DISALLOW_COPY_AND_ASSIGN(ReThrowInstr); 1843 DISALLOW_COPY_AND_ASSIGN(ReThrowInstr);
1817 }; 1844 };
1818 1845
1819 1846
1820 class BranchInstr : public Instruction { 1847 class BranchInstr : public InstructionWithInputs {
1821 public: 1848 public:
1822 explicit BranchInstr(Value* value) 1849 explicit BranchInstr(Value* value)
1823 : value_(value), 1850 : value_(value),
1824 true_successor_(NULL), 1851 true_successor_(NULL),
1825 false_successor_(NULL) { } 1852 false_successor_(NULL) { }
1826 1853
1827 DECLARE_INSTRUCTION(Branch) 1854 DECLARE_INSTRUCTION(Branch)
1828 1855
1829 Value* value() const { return value_; } 1856 Value* value() const { return value_; }
1830 TargetEntryInstr* true_successor() const { return true_successor_; } 1857 TargetEntryInstr* true_successor() const { return true_successor_; }
1831 TargetEntryInstr* false_successor() const { return false_successor_; } 1858 TargetEntryInstr* false_successor() const { return false_successor_; }
1832 1859
1833 TargetEntryInstr** true_successor_address() { return &true_successor_; } 1860 TargetEntryInstr** true_successor_address() { return &true_successor_; }
1834 TargetEntryInstr** false_successor_address() { return &false_successor_; } 1861 TargetEntryInstr** false_successor_address() { return &false_successor_; }
1835 1862
1836 virtual Instruction* StraightLineSuccessor() const { return NULL; } 1863 virtual Instruction* StraightLineSuccessor() const { return NULL; }
1837 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); } 1864 virtual void SetSuccessor(Instruction* instr) { UNREACHABLE(); }
1838 1865
1839 virtual void DiscoverBlocks( 1866 virtual void DiscoverBlocks(
1840 BlockEntryInstr* current_block, 1867 BlockEntryInstr* current_block,
1841 GrowableArray<BlockEntryInstr*>* preorder, 1868 GrowableArray<BlockEntryInstr*>* preorder,
1842 GrowableArray<BlockEntryInstr*>* postorder, 1869 GrowableArray<BlockEntryInstr*>* postorder,
1843 GrowableArray<intptr_t>* parent, 1870 GrowableArray<intptr_t>* parent,
1844 GrowableArray<BitVector*>* assigned_vars, 1871 GrowableArray<BitVector*>* assigned_vars,
1845 intptr_t variable_count); 1872 intptr_t variable_count);
1846 1873
1874 virtual LocationSummary* MakeLocationSummary() const;
1875
1876 virtual void EmitNativeCode(FlowGraphCompiler* compiler);
1877
1847 private: 1878 private:
1848 Value* value_; 1879 Value* value_;
1849 TargetEntryInstr* true_successor_; 1880 TargetEntryInstr* true_successor_;
1850 TargetEntryInstr* false_successor_; 1881 TargetEntryInstr* false_successor_;
1851 1882
1852 DISALLOW_COPY_AND_ASSIGN(BranchInstr); 1883 DISALLOW_COPY_AND_ASSIGN(BranchInstr);
1853 }; 1884 };
1854 1885
1855 #undef DECLARE_INSTRUCTION 1886 #undef DECLARE_INSTRUCTION
1856 1887
(...skipping 21 matching lines...) Expand all
1878 FOR_EACH_COMPUTATION(DECLARE_VISIT_COMPUTATION) 1909 FOR_EACH_COMPUTATION(DECLARE_VISIT_COMPUTATION)
1879 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) 1910 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
1880 1911
1881 #undef DECLARE_VISIT_COMPUTATION 1912 #undef DECLARE_VISIT_COMPUTATION
1882 #undef DECLARE_VISIT_INSTRUCTION 1913 #undef DECLARE_VISIT_INSTRUCTION
1883 1914
1884 protected: 1915 protected:
1885 // Map a block number in a forward iteration into the block number in the 1916 // Map a block number in a forward iteration into the block number in the
1886 // corresponding reverse iteration. Used to obtain an index into 1917 // corresponding reverse iteration. Used to obtain an index into
1887 // block_order for reverse iterations. 1918 // block_order for reverse iterations.
1888 intptr_t reverse_index(intptr_t index) { 1919 intptr_t reverse_index(intptr_t index) const {
1889 return block_order_.length() - index - 1; 1920 return block_order_.length() - index - 1;
1890 } 1921 }
1891 1922
1892 const GrowableArray<BlockEntryInstr*>& block_order_; 1923 const GrowableArray<BlockEntryInstr*>& block_order_;
1893 1924
1894 private: 1925 private:
1895 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 1926 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
1896 }; 1927 };
1897 1928
1898 1929
1899 } // namespace dart 1930 } // namespace dart
1900 1931
1901 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 1932 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698