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

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
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 1759 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 1778 // Remove instruction from the graph and return the instruction following the
1779 // removed instruction. 1779 // removed instruction.
1780 Instruction* RemoveFromGraph(); 1780 enum RemoveReturnValue {
1781 kReturnPrevious,
1782 kReturnNext
1783 };
1784 Instruction* RemoveFromGraph(RemoveReturnValue ret);
1781 1785
1782 // Normal instructions can have 0 (inside a block) or 1 (last instruction in 1786 // Normal instructions can have 0 (inside a block) or 1 (last instruction in
1783 // a block) successors. Branch instruction with >1 successors override this 1787 // a block) successors. Branch instruction with >1 successors override this
1784 // function. 1788 // function.
1785 virtual intptr_t SuccessorCount() const; 1789 virtual intptr_t SuccessorCount() const;
1786 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const; 1790 virtual BlockEntryInstr* SuccessorAt(intptr_t index) const;
1787 1791
1788 // Discover basic-block structure by performing a recursive depth first 1792 // Discover basic-block structure by performing a recursive depth first
1789 // traversal of the instruction graph reachable from this instruction. As 1793 // traversal of the instruction graph reachable from this instruction. As
1790 // a side effect, the block entry instructions in the graph are assigned 1794 // a side effect, the block entry instructions in the graph are assigned
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1935 intptr_t block_id_; 1939 intptr_t block_id_;
1936 BlockEntryInstr* dominator_; // Immediate dominator, NULL for graph entry. 1940 BlockEntryInstr* dominator_; // Immediate dominator, NULL for graph entry.
1937 // TODO(fschneider): Optimize the case of one child to save space. 1941 // TODO(fschneider): Optimize the case of one child to save space.
1938 GrowableArray<BlockEntryInstr*> dominated_blocks_; 1942 GrowableArray<BlockEntryInstr*> dominated_blocks_;
1939 Instruction* last_instruction_; 1943 Instruction* last_instruction_;
1940 1944
1941 DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr); 1945 DISALLOW_COPY_AND_ASSIGN(BlockEntryInstr);
1942 }; 1946 };
1943 1947
1944 1948
1949 class ForwardIterator : public ValueObject {
Kevin Millikin (Google) 2012/07/06 10:44:30 I think the class name is probably too generic. W
1950 public:
1951 explicit ForwardIterator(BlockEntryInstr* block_entry)
1952 : block_entry_(block_entry), current_(block_entry) {
1953 Advance();
1954 }
1955
1956 void Advance() {
1957 if (!Done()) current_ = current_->successor();
1958 }
1959
1960 bool Done() const {
1961 return current_ == block_entry_->last_instruction()->successor();
1962 }
1963
1964 void RemoveCurrentFromGraph() {
1965 current_ = current_->RemoveFromGraph(Instruction::kReturnPrevious);
1966 }
1967
1968 Instruction* Current() const { return current_; }
1969
1970 private:
1971 BlockEntryInstr* block_entry_;
1972 Instruction* current_;
1973 };
1974
1975
1945 class GraphEntryInstr : public BlockEntryInstr { 1976 class GraphEntryInstr : public BlockEntryInstr {
1946 public: 1977 public:
1947 explicit GraphEntryInstr(TargetEntryInstr* normal_entry) 1978 explicit GraphEntryInstr(TargetEntryInstr* normal_entry)
1948 : BlockEntryInstr(), 1979 : BlockEntryInstr(),
1949 normal_entry_(normal_entry), 1980 normal_entry_(normal_entry),
1950 catch_entries_(), 1981 catch_entries_(),
1951 start_env_(NULL) { } 1982 start_env_(NULL) { }
1952 1983
1953 DECLARE_INSTRUCTION(GraphEntry) 1984 DECLARE_INSTRUCTION(GraphEntry)
1954 1985
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
2396 const GrowableArray<BlockEntryInstr*>& block_order_; 2427 const GrowableArray<BlockEntryInstr*>& block_order_;
2397 2428
2398 private: 2429 private:
2399 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor); 2430 DISALLOW_COPY_AND_ASSIGN(FlowGraphVisitor);
2400 }; 2431 };
2401 2432
2402 2433
2403 } // namespace dart 2434 } // namespace dart
2404 2435
2405 #endif // VM_INTERMEDIATE_LANGUAGE_H_ 2436 #endif // VM_INTERMEDIATE_LANGUAGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698