Perform block ordering in-place.

R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/295543002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21353 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
bmeurer@chromium.org 2014-05-19 07:24:24 +00:00
parent ecadc63b60
commit f1f1ee9798
2 changed files with 46 additions and 35 deletions

View File

@ -79,7 +79,8 @@ HBasicBlock::HBasicBlock(HGraph* graph)
is_inline_return_target_(false), is_inline_return_target_(false),
is_reachable_(true), is_reachable_(true),
dominates_loop_successors_(false), dominates_loop_successors_(false),
is_osr_entry_(false) { } is_osr_entry_(false),
is_ordered_(false) { }
Isolate* HBasicBlock::isolate() const { Isolate* HBasicBlock::isolate() const {
@ -3330,21 +3331,19 @@ class PostorderProcessor : public ZoneObject {
HBasicBlock* loop_header() { return loop_header_; } HBasicBlock* loop_header() { return loop_header_; }
static PostorderProcessor* CreateEntryProcessor(Zone* zone, static PostorderProcessor* CreateEntryProcessor(Zone* zone,
HBasicBlock* block, HBasicBlock* block) {
BitVector* visited) {
PostorderProcessor* result = new(zone) PostorderProcessor(NULL); PostorderProcessor* result = new(zone) PostorderProcessor(NULL);
return result->SetupSuccessors(zone, block, NULL, visited); return result->SetupSuccessors(zone, block, NULL);
} }
PostorderProcessor* PerformStep(Zone* zone, PostorderProcessor* PerformStep(Zone* zone,
BitVector* visited,
ZoneList<HBasicBlock*>* order) { ZoneList<HBasicBlock*>* order) {
PostorderProcessor* next = PostorderProcessor* next =
PerformNonBacktrackingStep(zone, visited, order); PerformNonBacktrackingStep(zone, order);
if (next != NULL) { if (next != NULL) {
return next; return next;
} else { } else {
return Backtrack(zone, visited, order); return Backtrack(zone, order);
} }
} }
@ -3364,9 +3363,8 @@ class PostorderProcessor : public ZoneObject {
// Each "Setup..." method is like a constructor for a cycle state. // Each "Setup..." method is like a constructor for a cycle state.
PostorderProcessor* SetupSuccessors(Zone* zone, PostorderProcessor* SetupSuccessors(Zone* zone,
HBasicBlock* block, HBasicBlock* block,
HBasicBlock* loop_header, HBasicBlock* loop_header) {
BitVector* visited) { if (block == NULL || block->IsOrdered() ||
if (block == NULL || visited->Contains(block->block_id()) ||
block->parent_loop_header() != loop_header) { block->parent_loop_header() != loop_header) {
kind_ = NONE; kind_ = NONE;
block_ = NULL; block_ = NULL;
@ -3376,7 +3374,7 @@ class PostorderProcessor : public ZoneObject {
} else { } else {
block_ = block; block_ = block;
loop_ = NULL; loop_ = NULL;
visited->Add(block->block_id()); block->MarkAsOrdered();
if (block->IsLoopHeader()) { if (block->IsLoopHeader()) {
kind_ = SUCCESSORS_OF_LOOP_HEADER; kind_ = SUCCESSORS_OF_LOOP_HEADER;
@ -3439,7 +3437,6 @@ class PostorderProcessor : public ZoneObject {
// This method is the basic block to walk up the stack. // This method is the basic block to walk up the stack.
PostorderProcessor* Pop(Zone* zone, PostorderProcessor* Pop(Zone* zone,
BitVector* visited,
ZoneList<HBasicBlock*>* order) { ZoneList<HBasicBlock*>* order) {
switch (kind_) { switch (kind_) {
case SUCCESSORS: case SUCCESSORS:
@ -3466,16 +3463,15 @@ class PostorderProcessor : public ZoneObject {
// Walks up the stack. // Walks up the stack.
PostorderProcessor* Backtrack(Zone* zone, PostorderProcessor* Backtrack(Zone* zone,
BitVector* visited,
ZoneList<HBasicBlock*>* order) { ZoneList<HBasicBlock*>* order) {
PostorderProcessor* parent = Pop(zone, visited, order); PostorderProcessor* parent = Pop(zone, order);
while (parent != NULL) { while (parent != NULL) {
PostorderProcessor* next = PostorderProcessor* next =
parent->PerformNonBacktrackingStep(zone, visited, order); parent->PerformNonBacktrackingStep(zone, order);
if (next != NULL) { if (next != NULL) {
return next; return next;
} else { } else {
parent = parent->Pop(zone, visited, order); parent = parent->Pop(zone, order);
} }
} }
return NULL; return NULL;
@ -3483,7 +3479,6 @@ class PostorderProcessor : public ZoneObject {
PostorderProcessor* PerformNonBacktrackingStep( PostorderProcessor* PerformNonBacktrackingStep(
Zone* zone, Zone* zone,
BitVector* visited,
ZoneList<HBasicBlock*>* order) { ZoneList<HBasicBlock*>* order) {
HBasicBlock* next_block; HBasicBlock* next_block;
switch (kind_) { switch (kind_) {
@ -3491,16 +3486,14 @@ class PostorderProcessor : public ZoneObject {
next_block = AdvanceSuccessors(); next_block = AdvanceSuccessors();
if (next_block != NULL) { if (next_block != NULL) {
PostorderProcessor* result = Push(zone); PostorderProcessor* result = Push(zone);
return result->SetupSuccessors(zone, next_block, return result->SetupSuccessors(zone, next_block, loop_header_);
loop_header_, visited);
} }
break; break;
case SUCCESSORS_OF_LOOP_HEADER: case SUCCESSORS_OF_LOOP_HEADER:
next_block = AdvanceSuccessors(); next_block = AdvanceSuccessors();
if (next_block != NULL) { if (next_block != NULL) {
PostorderProcessor* result = Push(zone); PostorderProcessor* result = Push(zone);
return result->SetupSuccessors(zone, next_block, return result->SetupSuccessors(zone, next_block, block());
block(), visited);
} }
break; break;
case LOOP_MEMBERS: case LOOP_MEMBERS:
@ -3515,8 +3508,7 @@ class PostorderProcessor : public ZoneObject {
next_block = AdvanceSuccessors(); next_block = AdvanceSuccessors();
if (next_block != NULL) { if (next_block != NULL) {
PostorderProcessor* result = Push(zone); PostorderProcessor* result = Push(zone);
return result->SetupSuccessors(zone, next_block, return result->SetupSuccessors(zone, next_block, loop_header_);
loop_header_, visited);
} }
break; break;
case NONE: case NONE:
@ -3571,21 +3563,36 @@ class PostorderProcessor : public ZoneObject {
void HGraph::OrderBlocks() { void HGraph::OrderBlocks() {
CompilationPhase phase("H_Block ordering", info()); CompilationPhase phase("H_Block ordering", info());
BitVector visited(blocks_.length(), zone());
ZoneList<HBasicBlock*> reverse_result(8, zone()); #ifdef DEBUG
HBasicBlock* start = blocks_[0]; // Initially the blocks must not be ordered.
PostorderProcessor* postorder = for (int i = 0; i < blocks_.length(); ++i) {
PostorderProcessor::CreateEntryProcessor(zone(), start, &visited); ASSERT(!blocks_[i]->IsOrdered());
while (postorder != NULL) {
postorder = postorder->PerformStep(zone(), &visited, &reverse_result);
} }
#endif
PostorderProcessor* postorder =
PostorderProcessor::CreateEntryProcessor(zone(), blocks_[0]);
blocks_.Rewind(0); blocks_.Rewind(0);
int index = 0; while (postorder) {
for (int i = reverse_result.length() - 1; i >= 0; --i) { postorder = postorder->PerformStep(zone(), &blocks_);
HBasicBlock* b = reverse_result[i]; }
blocks_.Add(b, zone());
b->set_block_id(index++); #ifdef DEBUG
// Now all blocks must be marked as ordered.
for (int i = 0; i < blocks_.length(); ++i) {
ASSERT(blocks_[i]->IsOrdered());
}
#endif
// Reverse block list and assign block IDs.
for (int i = 0, j = blocks_.length(); --j >= i; ++i) {
HBasicBlock* bi = blocks_[i];
HBasicBlock* bj = blocks_[j];
bi->set_block_id(j);
bj->set_block_id(i);
blocks_[i] = bj;
blocks_[j] = bi;
} }
} }

View File

@ -151,6 +151,9 @@ class HBasicBlock V8_FINAL : public ZoneObject {
dominates_loop_successors_ = true; dominates_loop_successors_ = true;
} }
bool IsOrdered() const { return is_ordered_; }
void MarkAsOrdered() { is_ordered_ = true; }
void MarkSuccEdgeUnreachable(int succ); void MarkSuccEdgeUnreachable(int succ);
inline Zone* zone() const; inline Zone* zone() const;
@ -207,6 +210,7 @@ class HBasicBlock V8_FINAL : public ZoneObject {
bool is_reachable_ : 1; bool is_reachable_ : 1;
bool dominates_loop_successors_ : 1; bool dominates_loop_successors_ : 1;
bool is_osr_entry_ : 1; bool is_osr_entry_ : 1;
bool is_ordered_ : 1;
}; };