Remove most uses of HSubgraph as an argument.

In a lot of cases where we were passing a subgraph (a pair of basic blocks),
we actually only needed a basic block.

Review URL: http://codereview.chromium.org/6570006

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6913 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 65443b38
...@@ -482,23 +482,19 @@ HConstant* HGraph::GetConstantFalse() { ...@@ -482,23 +482,19 @@ HConstant* HGraph::GetConstantFalse() {
} }
void HSubgraph::AppendJoin(HSubgraph* then_graph, void HSubgraph::AppendJoin(HBasicBlock* first,
HSubgraph* else_graph, HBasicBlock* second,
AstNode* node) { int join_id) {
if (then_graph->exit_block() != NULL && if (first == NULL) {
else_graph->exit_block() != NULL) { exit_block_ = second;
// We need to merge, create new merge block. } else if (second == NULL) {
exit_block_ = first;
} else {
HBasicBlock* join_block = graph_->CreateBasicBlock(); HBasicBlock* join_block = graph_->CreateBasicBlock();
then_graph->exit_block()->Goto(join_block); first->Goto(join_block);
else_graph->exit_block()->Goto(join_block); second->Goto(join_block);
join_block->SetJoinId(node->id()); join_block->SetJoinId(join_id);
exit_block_ = join_block; exit_block_ = join_block;
} else if (then_graph->exit_block() != NULL) {
exit_block_ = then_graph->exit_block_;
} else if (else_graph->exit_block() != NULL) {
exit_block_ = else_graph->exit_block_;
} else {
exit_block_ = NULL;
} }
} }
...@@ -524,80 +520,81 @@ HBasicBlock* HSubgraph::JoinBlocks(HBasicBlock* a, HBasicBlock* b, int id) { ...@@ -524,80 +520,81 @@ HBasicBlock* HSubgraph::JoinBlocks(HBasicBlock* a, HBasicBlock* b, int id) {
} }
void HSubgraph::AppendEndless(HSubgraph* body, void HSubgraph::AppendEndless(IterationStatement* statement,
IterationStatement* statement, HBasicBlock* body_entry,
HBasicBlock* body_exit,
HBasicBlock* break_block) { HBasicBlock* break_block) {
if (exit_block() != NULL) { if (exit_block() != NULL) {
exit_block()->Goto(body->entry_block(), false); exit_block()->Goto(body_entry, false);
} }
if (body->exit_block() != NULL) { if (body_exit != NULL) {
body->exit_block()->Goto(body->entry_block(), true); body_exit->Goto(body_entry, true);
} }
if (break_block != NULL) break_block->SetJoinId(statement->ExitId()); if (break_block != NULL) break_block->SetJoinId(statement->ExitId());
exit_block_ = break_block; exit_block_ = break_block;
body->entry_block()->PostProcessLoopHeader(statement); body_entry->PostProcessLoopHeader(statement);
} }
void HSubgraph::AppendDoWhile(HSubgraph* body, void HSubgraph::AppendDoWhile(IterationStatement* statement,
IterationStatement* statement, HBasicBlock* body_entry,
HSubgraph* go_back, HBasicBlock* go_back,
HSubgraph* exit, HBasicBlock* exit_block,
HBasicBlock* break_block) { HBasicBlock* break_block) {
if (exit_block() != NULL) { if (this->exit_block() != NULL) {
exit_block()->Goto(body->entry_block(), false); this->exit_block()->Goto(body_entry, false);
} }
if (go_back->exit_block() != NULL) { if (go_back != NULL) {
go_back->exit_block()->Goto(body->entry_block(), true); go_back->Goto(body_entry, true);
} }
if (break_block != NULL) break_block->SetJoinId(statement->ExitId()); if (break_block != NULL) break_block->SetJoinId(statement->ExitId());
exit_block_ = exit_block_ =
JoinBlocks(exit->exit_block(), break_block, statement->ExitId()); JoinBlocks(exit_block, break_block, statement->ExitId());
body->entry_block()->PostProcessLoopHeader(statement); body_entry->PostProcessLoopHeader(statement);
} }
void HSubgraph::AppendWhile(HSubgraph* condition, void HSubgraph::AppendWhile(IterationStatement* statement,
HSubgraph* body, HBasicBlock* condition_entry,
IterationStatement* statement, HBasicBlock* exit_block,
HSubgraph* continue_subgraph, HBasicBlock* body_exit,
HSubgraph* exit, HBasicBlock* break_block,
HBasicBlock* break_block) { HBasicBlock* loop_entry,
if (exit_block() != NULL) { HBasicBlock* loop_exit) {
exit_block()->Goto(condition->entry_block(), false); if (this->exit_block() != NULL) {
this->exit_block()->Goto(condition_entry, false);
} }
if (break_block != NULL) break_block->SetJoinId(statement->ExitId()); if (break_block != NULL) break_block->SetJoinId(statement->ExitId());
exit_block_ = exit_block_ =
JoinBlocks(exit->exit_block(), break_block, statement->ExitId()); JoinBlocks(exit_block, break_block, statement->ExitId());
if (continue_subgraph != NULL) { if (loop_entry != NULL) {
if (body->exit_block() != NULL) { if (body_exit != NULL) {
body->exit_block()->Goto(continue_subgraph->entry_block(), true); body_exit->Goto(loop_entry, true);
} }
continue_subgraph->entry_block()->SetJoinId(statement->EntryId()); loop_entry->SetJoinId(statement->EntryId());
exit_block_ = JoinBlocks(exit_block_, exit_block_ = JoinBlocks(exit_block_, loop_exit, statement->ExitId());
continue_subgraph->exit_block(),
statement->ExitId());
} else { } else {
if (body->exit_block() != NULL) { if (body_exit != NULL) {
body->exit_block()->Goto(condition->entry_block(), true); body_exit->Goto(condition_entry, true);
} }
} }
condition->entry_block()->PostProcessLoopHeader(statement); condition_entry->PostProcessLoopHeader(statement);
} }
void HSubgraph::Append(HSubgraph* next, void HSubgraph::Append(BreakableStatement* stmt,
BreakableStatement* stmt, HBasicBlock* entry_block,
HBasicBlock* exit_block,
HBasicBlock* break_block) { HBasicBlock* break_block) {
exit_block_->Goto(next->entry_block()); exit_block_->Goto(entry_block);
exit_block_ = next->exit_block_; exit_block_ = exit_block;
if (stmt != NULL) { if (stmt != NULL) {
next->entry_block()->SetJoinId(stmt->EntryId()); entry_block->SetJoinId(stmt->EntryId());
if (break_block != NULL) break_block->SetJoinId(stmt->EntryId()); if (break_block != NULL) break_block->SetJoinId(stmt->EntryId());
exit_block_ = JoinBlocks(exit_block(), break_block, stmt->ExitId()); exit_block_ = JoinBlocks(exit_block, break_block, stmt->ExitId());
} }
} }
...@@ -2170,7 +2167,10 @@ HGraph* HGraphBuilder::CreateGraph(CompilationInfo* info) { ...@@ -2170,7 +2167,10 @@ HGraph* HGraphBuilder::CreateGraph(CompilationInfo* info) {
HSubgraph* body = CreateGotoSubgraph(environment()); HSubgraph* body = CreateGotoSubgraph(environment());
AddToSubgraph(body, stmts); AddToSubgraph(body, stmts);
if (HasStackOverflow()) return NULL; if (HasStackOverflow()) return NULL;
current_subgraph_->Append(body, NULL, NULL); current_subgraph_->Append(NULL,
body->entry_block(),
body->exit_block(),
NULL);
body->entry_block()->SetJoinId(info->function()->id()); body->entry_block()->SetJoinId(info->function()->id());
if (graph()->exit_block() != NULL) { if (graph()->exit_block() != NULL) {
...@@ -2379,7 +2379,10 @@ void HGraphBuilder::VisitBlock(Block* stmt) { ...@@ -2379,7 +2379,10 @@ void HGraphBuilder::VisitBlock(Block* stmt) {
{ BreakAndContinueScope push(&break_info, this); { BreakAndContinueScope push(&break_info, this);
ADD_TO_SUBGRAPH(block_graph, stmt->statements()); ADD_TO_SUBGRAPH(block_graph, stmt->statements());
} }
subgraph()->Append(block_graph, stmt, break_info.break_block()); subgraph()->Append(stmt,
block_graph->entry_block(),
block_graph->exit_block(),
break_info.break_block());
} else { } else {
VisitStatements(stmt->statements()); VisitStatements(stmt->statements());
} }
...@@ -2415,7 +2418,9 @@ void HGraphBuilder::VisitIfStatement(IfStatement* stmt) { ...@@ -2415,7 +2418,9 @@ void HGraphBuilder::VisitIfStatement(IfStatement* stmt) {
else_graph->entry_block()->SetJoinId(stmt->ElseId()); else_graph->entry_block()->SetJoinId(stmt->ElseId());
ADD_TO_SUBGRAPH(else_graph, stmt->else_statement()); ADD_TO_SUBGRAPH(else_graph, stmt->else_statement());
current_subgraph_->AppendJoin(then_graph, else_graph, stmt); current_subgraph_->AppendJoin(then_graph->exit_block(),
else_graph->exit_block(),
stmt->id());
} }
} }
...@@ -2724,7 +2729,10 @@ void HGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { ...@@ -2724,7 +2729,10 @@ void HGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) {
body_graph->ResolveContinue(stmt, break_info.continue_block()); body_graph->ResolveContinue(stmt, break_info.continue_block());
if (body_graph->exit_block() == NULL || stmt->cond()->ToBooleanIsTrue()) { if (body_graph->exit_block() == NULL || stmt->cond()->ToBooleanIsTrue()) {
subgraph()->AppendEndless(body_graph, stmt, break_info.break_block()); subgraph()->AppendEndless(stmt,
body_graph->entry_block(),
body_graph->exit_block(),
break_info.break_block());
} else { } else {
HSubgraph* go_back = CreateEmptySubgraph(); HSubgraph* go_back = CreateEmptySubgraph();
HSubgraph* exit = CreateEmptySubgraph(); HSubgraph* exit = CreateEmptySubgraph();
...@@ -2736,17 +2744,15 @@ void HGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { ...@@ -2736,17 +2744,15 @@ void HGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) {
go_back->entry_block()->SetJoinId(stmt->BackEdgeId()); go_back->entry_block()->SetJoinId(stmt->BackEdgeId());
exit->entry_block()->SetJoinId(stmt->ExitId()); exit->entry_block()->SetJoinId(stmt->ExitId());
} }
subgraph()->AppendDoWhile(body_graph, stmt, go_back, exit, subgraph()->AppendDoWhile(stmt,
body_graph->entry_block(),
go_back->exit_block(),
exit->exit_block(),
break_info.break_block()); break_info.break_block());
} }
} }
bool HGraphBuilder::ShouldPeel(HSubgraph* cond, HSubgraph* body) {
return FLAG_use_peeling;
}
void HGraphBuilder::VisitWhileStatement(WhileStatement* stmt) { void HGraphBuilder::VisitWhileStatement(WhileStatement* stmt) {
ASSERT(current_block() != NULL); ASSERT(current_block() != NULL);
subgraph()->PreProcessOsrEntry(stmt); subgraph()->PreProcessOsrEntry(stmt);
...@@ -2779,32 +2785,45 @@ void HGraphBuilder::VisitWhileStatement(WhileStatement* stmt) { ...@@ -2779,32 +2785,45 @@ void HGraphBuilder::VisitWhileStatement(WhileStatement* stmt) {
body_graph->ResolveContinue(stmt, break_info.continue_block()); body_graph->ResolveContinue(stmt, break_info.continue_block());
if (cond_graph != NULL) { if (cond_graph != NULL) {
AppendPeeledWhile(stmt, cond_graph, body_graph, exit_graph, AppendPeeledWhile(stmt,
cond_graph->entry_block(),
exit_graph->exit_block(),
body_graph->exit_block(),
break_info.break_block()); break_info.break_block());
} else { } else {
// TODO(fschneider): Implement peeling for endless loops as well. // TODO(fschneider): Implement peeling for endless loops as well.
subgraph()->AppendEndless(body_graph, stmt, break_info.break_block()); subgraph()->AppendEndless(stmt,
body_graph->entry_block(),
body_graph->exit_block(),
break_info.break_block());
} }
} }
void HGraphBuilder::AppendPeeledWhile(IterationStatement* stmt, void HGraphBuilder::AppendPeeledWhile(IterationStatement* stmt,
HSubgraph* cond_graph, HBasicBlock* condition_entry,
HSubgraph* body_graph, HBasicBlock* exit_block,
HSubgraph* exit_graph, HBasicBlock* body_exit,
HBasicBlock* break_block) { HBasicBlock* break_block) {
HSubgraph* loop = NULL; HBasicBlock* loop_entry = NULL;
if (body_graph->exit_block() != NULL && stmt != peeled_statement_ && HBasicBlock* loop_exit = NULL;
ShouldPeel(cond_graph, body_graph)) { if (FLAG_use_peeling && body_exit != NULL && stmt != peeled_statement_) {
// Save the last peeled iteration statement to prevent infinite recursion. // Save the last peeled iteration statement to prevent infinite recursion.
IterationStatement* outer_peeled_statement = peeled_statement_; IterationStatement* outer_peeled_statement = peeled_statement_;
peeled_statement_ = stmt; peeled_statement_ = stmt;
loop = CreateGotoSubgraph(body_graph->exit_block()->last_environment()); HSubgraph* loop = CreateGotoSubgraph(body_exit->last_environment());
ADD_TO_SUBGRAPH(loop, stmt); ADD_TO_SUBGRAPH(loop, stmt);
peeled_statement_ = outer_peeled_statement; peeled_statement_ = outer_peeled_statement;
loop_entry = loop->entry_block();
loop_exit = loop->exit_block();
} }
subgraph()->AppendWhile(cond_graph, body_graph, stmt, loop, exit_graph, subgraph()->AppendWhile(stmt,
break_block); condition_entry,
exit_block,
body_exit,
break_block,
loop_entry,
loop_exit);
} }
...@@ -2847,15 +2866,24 @@ void HGraphBuilder::VisitForStatement(ForStatement* stmt) { ...@@ -2847,15 +2866,24 @@ void HGraphBuilder::VisitForStatement(ForStatement* stmt) {
next_graph = next_graph =
CreateGotoSubgraph(body_graph->exit_block()->last_environment()); CreateGotoSubgraph(body_graph->exit_block()->last_environment());
ADD_TO_SUBGRAPH(next_graph, stmt->next()); ADD_TO_SUBGRAPH(next_graph, stmt->next());
body_graph->Append(next_graph, NULL, NULL); body_graph->Append(NULL,
next_graph->entry_block(),
next_graph->exit_block(),
NULL);
next_graph->entry_block()->SetJoinId(stmt->ContinueId()); next_graph->entry_block()->SetJoinId(stmt->ContinueId());
} }
if (cond_graph != NULL) { if (cond_graph != NULL) {
AppendPeeledWhile(stmt, cond_graph, body_graph, exit_graph, AppendPeeledWhile(stmt,
cond_graph->entry_block(),
exit_graph->exit_block(),
body_graph->exit_block(),
break_info.break_block()); break_info.break_block());
} else { } else {
subgraph()->AppendEndless(body_graph, stmt, break_info.break_block()); subgraph()->AppendEndless(stmt,
body_graph->entry_block(),
body_graph->exit_block(),
break_info.break_block());
} }
} }
...@@ -2909,7 +2937,9 @@ void HGraphBuilder::VisitConditional(Conditional* expr) { ...@@ -2909,7 +2937,9 @@ void HGraphBuilder::VisitConditional(Conditional* expr) {
else_graph->entry_block()->SetJoinId(expr->ElseId()); else_graph->entry_block()->SetJoinId(expr->ElseId());
ADD_TO_SUBGRAPH(else_graph, expr->else_expression()); ADD_TO_SUBGRAPH(else_graph, expr->else_expression());
current_subgraph_->AppendJoin(then_graph, else_graph, expr); current_subgraph_->AppendJoin(then_graph->exit_block(),
else_graph->exit_block(),
expr->id());
ast_context()->ReturnValue(Pop()); ast_context()->ReturnValue(Pop());
} }
...@@ -4700,7 +4730,9 @@ void HGraphBuilder::VisitUnaryOperation(UnaryOperation* expr) { ...@@ -4700,7 +4730,9 @@ void HGraphBuilder::VisitUnaryOperation(UnaryOperation* expr) {
false_graph->exit_block()->last_environment()->Push( false_graph->exit_block()->last_environment()->Push(
graph_->GetConstantFalse()); graph_->GetConstantFalse());
current_subgraph_->AppendJoin(true_graph, false_graph, expr); current_subgraph_->AppendJoin(true_graph->exit_block(),
false_graph->exit_block(),
expr->id());
ast_context()->ReturnValue(Pop()); ast_context()->ReturnValue(Pop());
} else { } else {
ASSERT(ast_context()->IsEffect()); ASSERT(ast_context()->IsEffect());
......
...@@ -208,23 +208,26 @@ class HSubgraph: public ZoneObject { ...@@ -208,23 +208,26 @@ class HSubgraph: public ZoneObject {
void PreProcessOsrEntry(IterationStatement* statement); void PreProcessOsrEntry(IterationStatement* statement);
void AppendJoin(HSubgraph* then_graph, HSubgraph* else_graph, AstNode* node); void AppendJoin(HBasicBlock* first, HBasicBlock* second, int join_id);
void AppendWhile(HSubgraph* condition, void AppendWhile(IterationStatement* statement,
HSubgraph* body, HBasicBlock* condition_entry,
IterationStatement* statement, HBasicBlock* exit_block,
HSubgraph* continue_subgraph, HBasicBlock* body_exit,
HSubgraph* exit, HBasicBlock* break_block,
HBasicBlock* break_block); HBasicBlock* loop_entry,
void AppendDoWhile(HSubgraph* body, HBasicBlock* loop_exit);
IterationStatement* statement, void AppendDoWhile(IterationStatement* statement,
HSubgraph* go_back, HBasicBlock* body_entry,
HSubgraph* exit, HBasicBlock* go_back,
HBasicBlock* exit_block,
HBasicBlock* break_block); HBasicBlock* break_block);
void AppendEndless(HSubgraph* body, void AppendEndless(IterationStatement* statement,
IterationStatement* statement, HBasicBlock* body_entry,
HBasicBlock* body_exit,
HBasicBlock* break_block); HBasicBlock* break_block);
void Append(HSubgraph* next, void Append(BreakableStatement* stmt,
BreakableStatement* stmt, HBasicBlock* entry_block,
HBasicBlock* exit_block,
HBasicBlock* break_block); HBasicBlock* break_block);
void ResolveContinue(IterationStatement* statement, void ResolveContinue(IterationStatement* statement,
HBasicBlock* continue_block); HBasicBlock* continue_block);
...@@ -696,9 +699,9 @@ class HGraphBuilder: public AstVisitor { ...@@ -696,9 +699,9 @@ class HGraphBuilder: public AstVisitor {
void Bailout(const char* reason); void Bailout(const char* reason);
void AppendPeeledWhile(IterationStatement* stmt, void AppendPeeledWhile(IterationStatement* stmt,
HSubgraph* cond_graph, HBasicBlock* condition_entry,
HSubgraph* body_graph, HBasicBlock* exit_block,
HSubgraph* exit_graph, HBasicBlock* body_exit,
HBasicBlock* break_block); HBasicBlock* break_block);
void AddToSubgraph(HSubgraph* graph, ZoneList<Statement*>* stmts); void AddToSubgraph(HSubgraph* graph, ZoneList<Statement*>* stmts);
...@@ -741,8 +744,6 @@ class HGraphBuilder: public AstVisitor { ...@@ -741,8 +744,6 @@ class HGraphBuilder: public AstVisitor {
AST_NODE_LIST(DECLARE_VISIT) AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT #undef DECLARE_VISIT
bool ShouldPeel(HSubgraph* cond, HSubgraph* body);
HBasicBlock* CreateBasicBlock(HEnvironment* env); HBasicBlock* CreateBasicBlock(HEnvironment* env);
HSubgraph* CreateEmptySubgraph(); HSubgraph* CreateEmptySubgraph();
HSubgraph* CreateGotoSubgraph(HEnvironment* env); HSubgraph* CreateGotoSubgraph(HEnvironment* env);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment