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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: vm/intermediate_language.h
===================================================================
--- vm/intermediate_language.h (revision 9430)
+++ vm/intermediate_language.h (working copy)
@@ -1775,10 +1775,6 @@
previous_ = instr;
}
- // Remove instruction from the graph and return the instruction following the
- // removed instruction.
- Instruction* RemoveFromGraph();
-
// Normal instructions can have 0 (inside a block) or 1 (last instruction in
// a block) successors. Branch instruction with >1 successors override this
// function.
@@ -1942,6 +1938,56 @@
};
+class ForwardInstructionIterator : public ValueObject {
+ public:
+ explicit ForwardInstructionIterator(BlockEntryInstr* block_entry)
+ : block_entry_(block_entry), current_(block_entry) {
+ Advance();
+ }
+
+ void Advance() {
+ if (!Done()) current_ = current_->successor();
+ }
+
+ bool Done() const {
+ return current_ == block_entry_->last_instruction()->successor();
+ }
+
+ void RemoveCurrentFromGraph() {
Kevin Millikin (Google) 2012/07/06 11:58:42 I'd put this function in the .cc file.
+ ASSERT(!current_->IsBlockEntry());
+ ASSERT(!current_->IsBranch());
+ ASSERT(!current_->IsThrow());
+ ASSERT(!current_->IsReturn());
+ ASSERT(!current_->IsReThrow());
+ ASSERT(current_->previous() != NULL);
+ Instruction* next = current_->successor();
+ Instruction* prev = current_->previous();
+ prev->set_successor(next);
+ ASSERT(next != NULL);
+ if (current_ != block_entry_->last_instruction()) {
+ ASSERT(!next->IsBlockEntry());
+ next->set_previous(prev);
+ } else {
+ ASSERT(current_->IsBind());
+ // Removing the last instruction of a block.
+ // Update last_instruction of the current basic block.
+ block_entry_->set_last_instruction(prev);
+ }
+ // Reset successor and previous instruction to indicate
+ // that the instruction is removed from the graph.
+ current_->set_successor(NULL);
+ current_->set_previous(NULL);
+ current_ = prev;
+ }
+
+ Instruction* Current() const { return current_; }
+
+ private:
+ BlockEntryInstr* block_entry_;
+ Instruction* current_;
+};
+
+
class GraphEntryInstr : public BlockEntryInstr {
public:
explicit GraphEntryInstr(TargetEntryInstr* normal_entry)
« vm/il_printer.cc ('K') | « vm/il_printer.cc ('k') | vm/intermediate_language.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698