Chromium Code Reviews| 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 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1715 virtual const char* DebugName() const { return #type; } \ | 1715 virtual const char* DebugName() const { return #type; } \ |
| 1716 virtual void PrintTo(BufferFormatter* f) const; \ | 1716 virtual void PrintTo(BufferFormatter* f) const; \ |
| 1717 virtual void PrintToVisualizer(BufferFormatter* f) const; | 1717 virtual void PrintToVisualizer(BufferFormatter* f) const; |
| 1718 | 1718 |
| 1719 | 1719 |
| 1720 class Instruction : public ZoneAllocated { | 1720 class Instruction : public ZoneAllocated { |
| 1721 public: | 1721 public: |
| 1722 Instruction() | 1722 Instruction() |
| 1723 : cid_(-1), | 1723 : cid_(-1), |
| 1724 ic_data_(NULL), | 1724 ic_data_(NULL), |
| 1725 successor_(NULL), | |
| 1726 previous_(NULL), | 1725 previous_(NULL), |
| 1726 next_(NULL), | |
| 1727 env_(NULL) { | 1727 env_(NULL) { |
| 1728 Isolate* isolate = Isolate::Current(); | 1728 Isolate* isolate = Isolate::Current(); |
| 1729 cid_ = Computation::GetNextCid(isolate); | 1729 cid_ = Computation::GetNextCid(isolate); |
| 1730 ic_data_ = Computation::GetICDataForCid(cid_, isolate); | 1730 ic_data_ = Computation::GetICDataForCid(cid_, isolate); |
| 1731 } | 1731 } |
| 1732 | 1732 |
| 1733 // Unique computation/instruction id, used for deoptimization, e.g. for | 1733 // Unique computation/instruction id, used for deoptimization, e.g. for |
| 1734 // ReturnInstr, ThrowInstr and ReThrowInstr. | 1734 // ReturnInstr, ThrowInstr and ReThrowInstr. |
| 1735 intptr_t cid() const { return cid_; } | 1735 intptr_t cid() const { return cid_; } |
| 1736 | 1736 |
| 1737 const ICData* ic_data() const { return ic_data_; } | 1737 const ICData* ic_data() const { return ic_data_; } |
| 1738 | 1738 |
| 1739 virtual bool IsBlockEntry() const { return false; } | 1739 virtual bool IsBlockEntry() const { return false; } |
| 1740 BlockEntryInstr* AsBlockEntry() { | 1740 BlockEntryInstr* AsBlockEntry() { |
| 1741 return IsBlockEntry() ? reinterpret_cast<BlockEntryInstr*>(this) : NULL; | 1741 return IsBlockEntry() ? reinterpret_cast<BlockEntryInstr*>(this) : NULL; |
| 1742 } | 1742 } |
| 1743 virtual bool IsDefinition() const { return false; } | 1743 virtual bool IsDefinition() const { return false; } |
| 1744 virtual Definition* AsDefinition() { return NULL; } | 1744 virtual Definition* AsDefinition() { return NULL; } |
| 1745 | 1745 |
| 1746 virtual intptr_t InputCount() const = 0; | 1746 virtual intptr_t InputCount() const = 0; |
| 1747 virtual Value* InputAt(intptr_t i) const = 0; | 1747 virtual Value* InputAt(intptr_t i) const = 0; |
| 1748 virtual void SetInputAt(intptr_t i, Value* value) = 0; | 1748 virtual void SetInputAt(intptr_t i, Value* value) = 0; |
| 1749 | 1749 |
| 1750 // Visiting support. | 1750 // Visiting support. |
| 1751 virtual Instruction* Accept(FlowGraphVisitor* visitor) = 0; | 1751 virtual Instruction* Accept(FlowGraphVisitor* visitor) = 0; |
| 1752 | 1752 |
| 1753 Instruction* successor() const { return successor_; } | 1753 Instruction* previous() const { return previous_; } |
| 1754 void set_successor(Instruction* instr) { | 1754 void set_previous(Instruction* instr) { |
| 1755 ASSERT(!IsBlockEntry()); | |
| 1756 previous_ = instr; | |
| 1757 } | |
| 1758 | |
| 1759 Instruction* next() const { return next_; } | |
| 1760 void set_next(Instruction* instr) { | |
| 1755 ASSERT(!IsGraphEntry()); | 1761 ASSERT(!IsGraphEntry()); |
| 1756 ASSERT(!IsReturn()); | 1762 ASSERT(!IsReturn()); |
| 1757 ASSERT(!IsBranch()); | 1763 ASSERT(!IsBranch()); |
| 1758 ASSERT(!IsPhi()); | 1764 ASSERT(!IsPhi()); |
|
srdjan
2012/07/09 17:08:25
Why not make this virtual and make this UNREACHABL
| |
| 1759 // TODO(fschneider): Also add Throw and ReThrow to the list of instructions | 1765 // TODO(fschneider): Also add Throw and ReThrow to the list of instructions |
| 1760 // that do not have a successor. Currently, the graph builder will continue | 1766 // that do not have a successor. Currently, the graph builder will continue |
| 1761 // to append instruction in case of a Throw inside an expression. This | 1767 // to append instruction in case of a Throw inside an expression. This |
| 1762 // condition should be handled in the graph builder | 1768 // condition should be handled in the graph builder |
| 1763 successor_ = instr; | 1769 next_ = instr; |
| 1764 } | |
| 1765 | |
| 1766 Instruction* previous() const { return previous_; } | |
| 1767 void set_previous(Instruction* instr) { | |
| 1768 ASSERT(!IsBlockEntry()); | |
| 1769 previous_ = instr; | |
| 1770 } | 1770 } |
| 1771 | 1771 |
| 1772 // Normal instructions can have 0 (inside a block) or 1 (last instruction in | 1772 // Normal instructions can have 0 (inside a block) or 1 (last instruction in |
| 1773 // a block) successors. Branch instruction with >1 successors override this | 1773 // a block) successors. Branch instruction with >1 successors override this |
| 1774 // function. | 1774 // function. |
| 1775 virtual intptr_t SuccessorCount() const; | 1775 virtual intptr_t SuccessorCount() const; |
| 1776 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; | 1776 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; |
| 1777 | 1777 |
| 1778 // Discover basic-block structure by performing a recursive depth first | 1778 // Discover basic-block structure by performing a recursive depth first |
| 1779 // traversal of the instruction graph reachable from this instruction. As | 1779 // traversal of the instruction graph reachable from this instruction. As |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1831 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { | 1831 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { |
| 1832 UNIMPLEMENTED(); | 1832 UNIMPLEMENTED(); |
| 1833 } | 1833 } |
| 1834 | 1834 |
| 1835 Environment* env() const { return env_; } | 1835 Environment* env() const { return env_; } |
| 1836 void set_env(Environment* env) { env_ = env; } | 1836 void set_env(Environment* env) { env_ = env; } |
| 1837 | 1837 |
| 1838 private: | 1838 private: |
| 1839 intptr_t cid_; | 1839 intptr_t cid_; |
| 1840 ICData* ic_data_; | 1840 ICData* ic_data_; |
| 1841 Instruction* successor_; | |
| 1842 Instruction* previous_; | 1841 Instruction* previous_; |
| 1842 Instruction* next_; | |
| 1843 Environment* env_; | 1843 Environment* env_; |
| 1844 DISALLOW_COPY_AND_ASSIGN(Instruction); | 1844 DISALLOW_COPY_AND_ASSIGN(Instruction); |
| 1845 }; | 1845 }; |
| 1846 | 1846 |
| 1847 | 1847 |
| 1848 class InstructionWithInputs : public Instruction { | 1848 class InstructionWithInputs : public Instruction { |
| 1849 public: | 1849 public: |
| 1850 InstructionWithInputs() : locs_(NULL) { | 1850 InstructionWithInputs() : locs_(NULL) { |
| 1851 } | 1851 } |
| 1852 | 1852 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1933 | 1933 |
| 1934 | 1934 |
| 1935 class ForwardInstructionIterator : public ValueObject { | 1935 class ForwardInstructionIterator : public ValueObject { |
| 1936 public: | 1936 public: |
| 1937 explicit ForwardInstructionIterator(BlockEntryInstr* block_entry) | 1937 explicit ForwardInstructionIterator(BlockEntryInstr* block_entry) |
| 1938 : block_entry_(block_entry), current_(block_entry) { | 1938 : block_entry_(block_entry), current_(block_entry) { |
| 1939 Advance(); | 1939 Advance(); |
| 1940 } | 1940 } |
| 1941 | 1941 |
| 1942 void Advance() { | 1942 void Advance() { |
| 1943 if (!Done()) current_ = current_->successor(); | 1943 if (!Done()) current_ = current_->next(); |
| 1944 } | 1944 } |
| 1945 | 1945 |
| 1946 bool Done() const { | 1946 bool Done() const { |
| 1947 return current_ == block_entry_->last_instruction()->successor(); | 1947 return current_ == block_entry_->last_instruction()->next(); |
| 1948 } | 1948 } |
| 1949 | 1949 |
| 1950 void RemoveCurrentFromGraph() { | 1950 void RemoveCurrentFromGraph() { |
| 1951 ASSERT(!current_->IsBlockEntry()); | 1951 ASSERT(!current_->IsBlockEntry()); |
| 1952 ASSERT(!current_->IsBranch()); | 1952 ASSERT(!current_->IsBranch()); |
| 1953 ASSERT(!current_->IsThrow()); | 1953 ASSERT(!current_->IsThrow()); |
| 1954 ASSERT(!current_->IsReturn()); | 1954 ASSERT(!current_->IsReturn()); |
| 1955 ASSERT(!current_->IsReThrow()); | 1955 ASSERT(!current_->IsReThrow()); |
| 1956 ASSERT(current_->previous() != NULL); | 1956 ASSERT(current_->previous() != NULL); |
| 1957 Instruction* next = current_->successor(); | |
| 1958 Instruction* prev = current_->previous(); | 1957 Instruction* prev = current_->previous(); |
| 1959 prev->set_successor(next); | 1958 Instruction* next = current_->next(); |
| 1959 prev->set_next(next); | |
| 1960 ASSERT(next != NULL); | 1960 ASSERT(next != NULL); |
| 1961 if (current_ != block_entry_->last_instruction()) { | 1961 if (current_ != block_entry_->last_instruction()) { |
| 1962 ASSERT(!next->IsBlockEntry()); | 1962 ASSERT(!next->IsBlockEntry()); |
| 1963 next->set_previous(prev); | 1963 next->set_previous(prev); |
| 1964 } else { | 1964 } else { |
| 1965 ASSERT(current_->IsBind()); | 1965 ASSERT(current_->IsBind()); |
| 1966 // Removing the last instruction of a block. | 1966 // Removing the last instruction of a block. |
| 1967 // Update last_instruction of the current basic block. | 1967 // Update last_instruction of the current basic block. |
| 1968 block_entry_->set_last_instruction(prev); | 1968 block_entry_->set_last_instruction(prev); |
| 1969 } | 1969 } |
| 1970 // Reset successor and previous instruction to indicate | 1970 // Reset successor and previous instruction to indicate |
| 1971 // that the instruction is removed from the graph. | 1971 // that the instruction is removed from the graph. |
| 1972 current_->set_successor(NULL); | |
| 1973 current_->set_previous(NULL); | 1972 current_->set_previous(NULL); |
| 1973 current_->set_next(NULL); | |
| 1974 current_ = prev; | 1974 current_ = prev; |
| 1975 } | 1975 } |
| 1976 | 1976 |
| 1977 Instruction* Current() const { return current_; } | 1977 Instruction* Current() const { return current_; } |
| 1978 | 1978 |
| 1979 private: | 1979 private: |
| 1980 BlockEntryInstr* block_entry_; | 1980 BlockEntryInstr* block_entry_; |
| 1981 Instruction* current_; | 1981 Instruction* current_; |
| 1982 }; | 1982 }; |
| 1983 | 1983 |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2435 const GrowableArray<BlockEntryInstr*>& block_order_; | 2435 const GrowableArray<BlockEntryInstr*>& block_order_; |
| 2436 | 2436 |
| 2437 private: | 2437 private: |
| 2438 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 2438 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 2439 }; | 2439 }; |
| 2440 | 2440 |
| 2441 | 2441 |
| 2442 } // namespace dart | 2442 } // namespace dart |
| 2443 | 2443 |
| 2444 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 2444 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |