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

Side by Side Diff: vm/intermediate_language.h

Issue 10692107: Add forward iterator to iterate instructions inside a basic block. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « vm/il_printer.cc ('k') | vm/intermediate_language.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 // condition should be handled in the graph builder 1762 // condition should be handled in the graph builder
1763 successor_ = instr; 1763 successor_ = instr;
1764 } 1764 }
1765 1765
1766 Instruction* previous() const { return previous_; } 1766 Instruction* previous() const { return previous_; }
1767 void set_previous(Instruction* instr) { 1767 void set_previous(Instruction* instr) {
1768 ASSERT(!IsBlockEntry()); 1768 ASSERT(!IsBlockEntry());
1769 previous_ = instr; 1769 previous_ = instr;
1770 } 1770 }
1771 1771
1772 // Remove instruction from the graph and return the instruction following the
1773 // removed instruction.
1774 Instruction* RemoveFromGraph();
1775
1776 // 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
1777 // a block) successors. Branch instruction with >1 successors override this 1773 // a block) successors. Branch instruction with >1 successors override this
1778 // function. 1774 // function.
1779 virtual intptr_t SuccessorCount() const; 1775 virtual intptr_t SuccessorCount() const;
1780 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; 1776 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const;
1781 1777
1782 // Discover basic-block structure by performing a recursive depth first 1778 // Discover basic-block structure by performing a recursive depth first
1783 // traversal of the instruction graph reachable from this instruction. As 1779 // traversal of the instruction graph reachable from this instruction. As
1784 // a side effect, the block entry instructions in the graph are assigned 1780 // a side effect, the block entry instructions in the graph are assigned
1785 // numbers in both preorder and postorder. The array 'preorder' maps 1781 // numbers in both preorder and postorder. The array 'preorder' maps
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 intptr_t block_id_; 1925 intptr_t block_id_;
1930 BlockEntryInstr* dominator_; // Immediate dominator, NULL for graph entry. 1926 BlockEntryInstr* dominator_; // Immediate dominator, NULL for graph entry.
1931 // TODO(fschneider): Optimize the case of one child to save space. 1927 // TODO(fschneider): Optimize the case of one child to save space.
1932 GrowableArray<BlockEntryInstr*> dominated_blocks_; 1928 GrowableArray<BlockEntryInstr*> dominated_blocks_;
1933 Instruction* last_instruction_; 1929 Instruction* last_instruction_;
1934 1930
1935 DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr); 1931 DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr);
1936 }; 1932 };
1937 1933
1938 1934
1935 class ForwardInstructionIterator : public ValueObject {
1936 public:
1937 explicit ForwardInstructionIterator(BlockEntryInstr* block_entry)
1938 : block_entry_(block_entry), current_(block_entry) {
1939 Advance();
1940 }
1941
1942 void Advance() {
1943 if (!Done()) current_ = current_->successor();
1944 }
1945
1946 bool Done() const {
1947 return current_ == block_entry_->last_instruction()->successor();
1948 }
1949
1950 void RemoveCurrentFromGraph() {
1951 ASSERT(!current_->IsBlockEntry());
1952 ASSERT(!current_->IsBranch());
1953 ASSERT(!current_->IsThrow());
1954 ASSERT(!current_->IsReturn());
1955 ASSERT(!current_->IsReThrow());
1956 ASSERT(current_->previous() != NULL);
1957 Instruction* next = current_->successor();
1958 Instruction* prev = current_->previous();
1959 prev->set_successor(next);
1960 ASSERT(next != NULL);
1961 if (current_ != block_entry_->last_instruction()) {
1962 ASSERT(!next->IsBlockEntry());
1963 next->set_previous(prev);
1964 } else {
1965 ASSERT(current_->IsBind());
1966 // Removing the last instruction of a block.
1967 // Update last_instruction of the current basic block.
1968 block_entry_->set_last_instruction(prev);
1969 }
1970 // Reset successor and previous instruction to indicate
1971 // that the instruction is removed from the graph.
1972 current_->set_successor(NULL);
1973 current_->set_previous(NULL);
1974 current_ = prev;
1975 }
1976
1977 Instruction* Current() const { return current_; }
1978
1979 private:
1980 BlockEntryInstr* block_entry_;
1981 Instruction* current_;
1982 };
1983
1984
1939 class GraphEntryInstr : public BlockEntryInstr { 1985 class GraphEntryInstr : public BlockEntryInstr {
1940 public: 1986 public:
1941 explicit GraphEntryInstr(TargetEntryInstr* normal_entry) 1987 explicit GraphEntryInstr(TargetEntryInstr* normal_entry)
1942 : BlockEntryInstr(), 1988 : BlockEntryInstr(),
1943 normal_entry_(normal_entry), 1989 normal_entry_(normal_entry),
1944 catch_entries_(), 1990 catch_entries_(),
1945 start_env_(NULL) { } 1991 start_env_(NULL) { }
1946 1992
1947 DECLARE_INSTRUCTION(GraphEntry) 1993 DECLARE_INSTRUCTION(GraphEntry)
1948 1994
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
2389 const GrowableArray<BlockEntryInstr*>& block_order_; 2435 const GrowableArray<BlockEntryInstr*>& block_order_;
2390 2436
2391 private: 2437 private:
2392 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 2438 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
2393 }; 2439 };
2394 2440
2395 2441
2396 } // namespace dart 2442 } // namespace dart
2397 2443
2398 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 2444 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW
« no previous file with comments | « vm/il_printer.cc ('k') | vm/intermediate_language.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698