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

Unified Diff: runtime/vm/intermediate_language.cc

Issue 9732022: Do not use recursion for depth-first traversal of straight line code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/intermediate_language.cc
diff --git a/runtime/vm/intermediate_language.cc b/runtime/vm/intermediate_language.cc
index 8fc6e01d85f6dea53704d9eefbc56e93885e7111..0721fc595f540d9caa02cd79bea22119dcf035a5 100644
--- a/runtime/vm/intermediate_language.cc
+++ b/runtime/vm/intermediate_language.cc
@@ -119,9 +119,17 @@ void JoinEntryInstr::DiscoverBlocks(
// number, so they should stay in lockstep.
ASSERT(preorder->length() == parent->length());
- // 5. Recursively visit the successor.
+ // 5. Iterate straight-line successors until a branch instruction or
+ // another basic block entry instruction, and visit that instruction.
ASSERT(successor_ != NULL);
- successor_->DiscoverBlocks(this, preorder, postorder, parent);
+ Instruction* next = successor_;
+ while ((next != NULL) && !next->IsBlockEntry() && !next->IsBranch()) {
+ set_last_instruction(next);
+ next = next->StraightLineSuccessor();
+ }
+ if (next != NULL) {
+ next->DiscoverBlocks(this, preorder, postorder, parent);
+ }
// 6. Assign postorder number and add the block entry to the list.
set_postorder_number(postorder->length());
@@ -152,9 +160,19 @@ void TargetEntryInstr::DiscoverBlocks(
// they should stay in lockstep.
ASSERT(preorder->length() == parent->length());
- // 5. Recursively visit the successor.
+ // 5. Iterate straight-line successors until a branch instruction or
+ // another basic block entry instruction, and visit that instruction.
ASSERT(successor_ != NULL);
- successor_->DiscoverBlocks(this, preorder, postorder, parent);
+ Instruction* next = successor_;
+ while ((next != NULL) &&
+ !next->IsBlockEntry() &&
+ !next->IsBranch()) {
+ set_last_instruction(next);
+ next = next->StraightLineSuccessor();
+ }
+ if (next != NULL) {
+ next->DiscoverBlocks(this, preorder, postorder, parent);
+ }
// 6. Assign postorder number and add the block entry to the list.
set_postorder_number(postorder->length());
@@ -162,77 +180,6 @@ void TargetEntryInstr::DiscoverBlocks(
}
-void PickTempInstr::DiscoverBlocks(
- BlockEntryInstr* current_block,
- GrowableArray<BlockEntryInstr*>* preorder,
- GrowableArray<BlockEntryInstr*>* postorder,
- GrowableArray<BlockEntryInstr*>* parent) {
- current_block->set_last_instruction(this);
- ASSERT(successor_ != NULL);
- successor_->DiscoverBlocks(current_block, preorder, postorder, parent);
-}
-
-
-void TuckTempInstr::DiscoverBlocks(
- BlockEntryInstr* current_block,
- GrowableArray<BlockEntryInstr*>* preorder,
- GrowableArray<BlockEntryInstr*>* postorder,
- GrowableArray<BlockEntryInstr*>* parent) {
- current_block->set_last_instruction(this);
- ASSERT(successor_ != NULL);
- successor_->DiscoverBlocks(current_block, preorder, postorder, parent);
-}
-
-
-void DoInstr::DiscoverBlocks(
- BlockEntryInstr* current_block,
- GrowableArray<BlockEntryInstr*>* preorder,
- GrowableArray<BlockEntryInstr*>* postorder,
- GrowableArray<BlockEntryInstr*>* parent) {
- current_block->set_last_instruction(this);
- ASSERT(successor_ != NULL);
- successor_->DiscoverBlocks(current_block, preorder, postorder, parent);
-}
-
-
-void BindInstr::DiscoverBlocks(
- BlockEntryInstr* current_block,
- GrowableArray<BlockEntryInstr*>* preorder,
- GrowableArray<BlockEntryInstr*>* postorder,
- GrowableArray<BlockEntryInstr*>* parent) {
- current_block->set_last_instruction(this);
- ASSERT(successor_ != NULL);
- successor_->DiscoverBlocks(current_block, preorder, postorder, parent);
-}
-
-
-void ReturnInstr::DiscoverBlocks(
- BlockEntryInstr* current_block,
- GrowableArray<BlockEntryInstr*>* preorder,
- GrowableArray<BlockEntryInstr*>* postorder,
- GrowableArray<BlockEntryInstr*>* parent) {
- current_block->set_last_instruction(this);
-}
-
-
-void ThrowInstr::DiscoverBlocks(
- BlockEntryInstr* current_block,
- GrowableArray<BlockEntryInstr*>* preorder,
- GrowableArray<BlockEntryInstr*>* postorder,
- GrowableArray<BlockEntryInstr*>* parent) {
- current_block->set_last_instruction(this);
-}
-
-
-void ReThrowInstr::DiscoverBlocks(
- BlockEntryInstr* current_block,
- GrowableArray<BlockEntryInstr*>* preorder,
- GrowableArray<BlockEntryInstr*>* postorder,
- GrowableArray<BlockEntryInstr*>* parent) {
- current_block->set_last_instruction(this);
-}
-
-
void BranchInstr::DiscoverBlocks(
BlockEntryInstr* current_block,
GrowableArray<BlockEntryInstr*>* preorder,
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698