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 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1768 // condition should be handled in the graph builder | 1768 // condition should be handled in the graph builder |
| 1769 successor_ = instr; | 1769 successor_ = instr; |
| 1770 } | 1770 } |
| 1771 | 1771 |
| 1772 Instruction* previous() const { return previous_; } | 1772 Instruction* previous() const { return previous_; } |
| 1773 void set_previous(Instruction* instr) { | 1773 void set_previous(Instruction* instr) { |
| 1774 ASSERT(!IsBlockEntry()); | 1774 ASSERT(!IsBlockEntry()); |
| 1775 previous_ = instr; | 1775 previous_ = instr; |
| 1776 } | 1776 } |
| 1777 | 1777 |
| 1778 // Remove instruction from the graph and return the instruction following the | |
| 1779 // removed instruction. | |
| 1780 Instruction* RemoveFromGraph(); | |
| 1781 | |
| 1782 // Normal instructions can have 0 (inside a block) or 1 (last instruction in | 1778 // Normal instructions can have 0 (inside a block) or 1 (last instruction in |
| 1783 // a block) successors. Branch instruction with >1 successors override this | 1779 // a block) successors. Branch instruction with >1 successors override this |
| 1784 // function. | 1780 // function. |
| 1785 virtual intptr_t SuccessorCount() const; | 1781 virtual intptr_t SuccessorCount() const; |
| 1786 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; | 1782 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; |
| 1787 | 1783 |
| 1788 // Discover basic-block structure by performing a recursive depth first | 1784 // Discover basic-block structure by performing a recursive depth first |
| 1789 // traversal of the instruction graph reachable from this instruction. As | 1785 // traversal of the instruction graph reachable from this instruction. As |
| 1790 // a side effect, the block entry instructions in the graph are assigned | 1786 // a side effect, the block entry instructions in the graph are assigned |
| 1791 // numbers in both preorder and postorder. The array 'preorder' maps | 1787 // numbers in both preorder and postorder. The array 'preorder' maps |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1935 intptr_t block_id_; | 1931 intptr_t block_id_; |
| 1936 BlockEntryInstr* dominator_; // Immediate dominator, NULL for graph entry. | 1932 BlockEntryInstr* dominator_; // Immediate dominator, NULL for graph entry. |
| 1937 // TODO(fschneider): Optimize the case of one child to save space. | 1933 // TODO(fschneider): Optimize the case of one child to save space. |
| 1938 GrowableArray<BlockEntryInstr*> dominated_blocks_; | 1934 GrowableArray<BlockEntryInstr*> dominated_blocks_; |
| 1939 Instruction* last_instruction_; | 1935 Instruction* last_instruction_; |
| 1940 | 1936 |
| 1941 DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr); | 1937 DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr); |
| 1942 }; | 1938 }; |
| 1943 | 1939 |
| 1944 | 1940 |
| 1941 class ForwardInstructionIterator : public ValueObject { | |
| 1942 public: | |
| 1943 explicit ForwardInstructionIterator(BlockEntryInstr* block_entry) | |
| 1944 : block_entry_(block_entry), current_(block_entry) { | |
| 1945 Advance(); | |
| 1946 } | |
| 1947 | |
| 1948 void Advance() { | |
| 1949 if (!Done()) current_ = current_->successor(); | |
| 1950 } | |
| 1951 | |
| 1952 bool Done() const { | |
| 1953 return current_ == block_entry_->last_instruction()->successor(); | |
| 1954 } | |
| 1955 | |
| 1956 void RemoveCurrentFromGraph() { | |
|
Kevin Millikin (Google)
2012/07/06 11:58:42
I'd put this function in the .cc file.
| |
| 1957 ASSERT(!current_->IsBlockEntry()); | |
| 1958 ASSERT(!current_->IsBranch()); | |
| 1959 ASSERT(!current_->IsThrow()); | |
| 1960 ASSERT(!current_->IsReturn()); | |
| 1961 ASSERT(!current_->IsReThrow()); | |
| 1962 ASSERT(current_->previous() != NULL); | |
| 1963 Instruction* next = current_->successor(); | |
| 1964 Instruction* prev = current_->previous(); | |
| 1965 prev->set_successor(next); | |
| 1966 ASSERT(next != NULL); | |
| 1967 if (current_ != block_entry_->last_instruction()) { | |
| 1968 ASSERT(!next->IsBlockEntry()); | |
| 1969 next->set_previous(prev); | |
| 1970 } else { | |
| 1971 ASSERT(current_->IsBind()); | |
| 1972 // Removing the last instruction of a block. | |
| 1973 // Update last_instruction of the current basic block. | |
| 1974 block_entry_->set_last_instruction(prev); | |
| 1975 } | |
| 1976 // Reset successor and previous instruction to indicate | |
| 1977 // that the instruction is removed from the graph. | |
| 1978 current_->set_successor(NULL); | |
| 1979 current_->set_previous(NULL); | |
| 1980 current_ = prev; | |
| 1981 } | |
| 1982 | |
| 1983 Instruction* Current() const { return current_; } | |
| 1984 | |
| 1985 private: | |
| 1986 BlockEntryInstr* block_entry_; | |
| 1987 Instruction* current_; | |
| 1988 }; | |
| 1989 | |
| 1990 | |
| 1945 class GraphEntryInstr : public BlockEntryInstr { | 1991 class GraphEntryInstr : public BlockEntryInstr { |
| 1946 public: | 1992 public: |
| 1947 explicit GraphEntryInstr(TargetEntryInstr* normal_entry) | 1993 explicit GraphEntryInstr(TargetEntryInstr* normal_entry) |
| 1948 : BlockEntryInstr(), | 1994 : BlockEntryInstr(), |
| 1949 normal_entry_(normal_entry), | 1995 normal_entry_(normal_entry), |
| 1950 catch_entries_(), | 1996 catch_entries_(), |
| 1951 start_env_(NULL) { } | 1997 start_env_(NULL) { } |
| 1952 | 1998 |
| 1953 DECLARE_INSTRUCTION(GraphEntry) | 1999 DECLARE_INSTRUCTION(GraphEntry) |
| 1954 | 2000 |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2396 const GrowableArray<BlockEntryInstr*>& block_order_; | 2442 const GrowableArray<BlockEntryInstr*>& block_order_; |
| 2397 | 2443 |
| 2398 private: | 2444 private: |
| 2399 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); | 2445 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); |
| 2400 }; | 2446 }; |
| 2401 | 2447 |
| 2402 | 2448 |
| 2403 } // namespace dart | 2449 } // namespace dart |
| 2404 | 2450 |
| 2405 #endif // VM_INTERMEDIATE_LANGUAGE_H_ | 2451 #endif // VM_INTERMEDIATE_LANGUAGE_H_ |
| OLD | NEW |