From 807cdd492be737ed252ad63c64fb291184dd3e2d Mon Sep 17 00:00:00 2001 From: "mvstanton@chromium.org" Date: Fri, 27 Sep 2013 13:38:04 +0000 Subject: [PATCH] Refactoring such that loop builders only call into the HOsrBuilder if compiling for OSR. BUG= R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/25039003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16990 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/hydrogen-osr.cc | 17 +++-------------- src/hydrogen-osr.h | 6 +++--- src/hydrogen.cc | 28 +++++++++++++++++++++++----- src/hydrogen.h | 8 ++++++++ 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/hydrogen-osr.cc b/src/hydrogen-osr.cc index e95967e05d..3492debfce 100644 --- a/src/hydrogen-osr.cc +++ b/src/hydrogen-osr.cc @@ -37,19 +37,8 @@ bool HOsrBuilder::HasOsrEntryAt(IterationStatement* statement) { } -// Build a new loop header block and set it as the current block. -HBasicBlock *HOsrBuilder::BuildLoopEntry() { - HBasicBlock* loop_entry = builder_->CreateLoopHeaderBlock(); - builder_->current_block()->Goto(loop_entry); - builder_->set_current_block(loop_entry); - return loop_entry; -} - - -HBasicBlock* HOsrBuilder::BuildPossibleOsrLoopEntry( - IterationStatement* statement) { - // Check if there is an OSR here first. - if (!HasOsrEntryAt(statement)) return BuildLoopEntry(); +HBasicBlock* HOsrBuilder::BuildOsrLoopEntry(IterationStatement* statement) { + ASSERT(HasOsrEntryAt(statement)); Zone* zone = builder_->zone(); HGraph* graph = builder_->graph(); @@ -113,7 +102,7 @@ HBasicBlock* HOsrBuilder::BuildPossibleOsrLoopEntry( builder_->set_current_block(loop_predecessor); // Create the final loop entry - osr_loop_entry_ = BuildLoopEntry(); + osr_loop_entry_ = builder_->BuildLoopEntry(); return osr_loop_entry_; } diff --git a/src/hydrogen-osr.h b/src/hydrogen-osr.h index 5014a75bda..ae72ce650c 100644 --- a/src/hydrogen-osr.h +++ b/src/hydrogen-osr.h @@ -45,9 +45,10 @@ class HOsrBuilder : public ZoneObject { osr_entry_(NULL), osr_loop_entry_(NULL), osr_values_(NULL) { } + // Creates the loop entry block for the given statement, setting up OSR // entries as necessary, and sets the current block to the new block. - HBasicBlock* BuildPossibleOsrLoopEntry(IterationStatement* statement); + HBasicBlock* BuildOsrLoopEntry(IterationStatement* statement); // Process the hydrogen graph after it has been completed, performing // any OSR-specific cleanups or changes. @@ -61,10 +62,9 @@ class HOsrBuilder : public ZoneObject { return unoptimized_frame_slots_; } - private: - HBasicBlock* BuildLoopEntry(); bool HasOsrEntryAt(IterationStatement* statement); + private: int unoptimized_frame_slots_; HOptimizedGraphBuilder* builder_; HBasicBlock* osr_entry_; diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 57ea17313b..5d89e38d11 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -2246,6 +2246,24 @@ HBasicBlock* HOptimizedGraphBuilder::CreateLoop(IterationStatement* statement, } +// Build a new loop header block and set it as the current block. +HBasicBlock* HOptimizedGraphBuilder::BuildLoopEntry() { + HBasicBlock* loop_entry = CreateLoopHeaderBlock(); + current_block()->Goto(loop_entry); + set_current_block(loop_entry); + return loop_entry; +} + + +HBasicBlock* HOptimizedGraphBuilder::BuildLoopEntry( + IterationStatement* statement) { + HBasicBlock* loop_entry = osr()->HasOsrEntryAt(statement) + ? osr()->BuildOsrLoopEntry(statement) + : BuildLoopEntry(); + return loop_entry; +} + + void HBasicBlock::FinishExit(HControlInstruction* instruction) { Finish(instruction); ClearEnvironment(); @@ -3087,7 +3105,7 @@ bool HOptimizedGraphBuilder::BuildGraph() { type_info->set_inlined_type_change_checksum(composite_checksum); // Perform any necessary OSR-specific cleanups or changes to the graph. - osr_->FinishGraph(); + osr()->FinishGraph(); return true; } @@ -3670,7 +3688,7 @@ void HOptimizedGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { ASSERT(current_block() != NULL); ASSERT(current_block()->HasPredecessor()); ASSERT(current_block() != NULL); - HBasicBlock* loop_entry = osr_->BuildPossibleOsrLoopEntry(stmt); + HBasicBlock* loop_entry = BuildLoopEntry(stmt); BreakAndContinueInfo break_info(stmt); CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry, &break_info)); @@ -3709,7 +3727,7 @@ void HOptimizedGraphBuilder::VisitWhileStatement(WhileStatement* stmt) { ASSERT(current_block() != NULL); ASSERT(current_block()->HasPredecessor()); ASSERT(current_block() != NULL); - HBasicBlock* loop_entry = osr_->BuildPossibleOsrLoopEntry(stmt); + HBasicBlock* loop_entry = BuildLoopEntry(stmt); // If the condition is constant true, do not generate a branch. HBasicBlock* loop_successor = NULL; @@ -3751,7 +3769,7 @@ void HOptimizedGraphBuilder::VisitForStatement(ForStatement* stmt) { CHECK_ALIVE(Visit(stmt->init())); } ASSERT(current_block() != NULL); - HBasicBlock* loop_entry = osr_->BuildPossibleOsrLoopEntry(stmt); + HBasicBlock* loop_entry = BuildLoopEntry(stmt); HBasicBlock* loop_successor = NULL; if (stmt->cond() != NULL) { @@ -3834,7 +3852,7 @@ void HOptimizedGraphBuilder::VisitForInStatement(ForInStatement* stmt) { HForInCacheArray::cast(array)->set_index_cache( HForInCacheArray::cast(index_cache)); - HBasicBlock* loop_entry = osr_->BuildPossibleOsrLoopEntry(stmt); + HBasicBlock* loop_entry = BuildLoopEntry(stmt); HValue* index = environment()->ExpressionStackAt(0); HValue* limit = environment()->ExpressionStackAt(1); diff --git a/src/hydrogen.h b/src/hydrogen.h index be23fa84c3..9b998c92b9 100644 --- a/src/hydrogen.h +++ b/src/hydrogen.h @@ -1781,6 +1781,8 @@ class HOptimizedGraphBuilder V8_FINAL HValue* context() { return environment()->context(); } + HOsrBuilder* osr() const { return osr_; } + void Bailout(BailoutReason reason); HBasicBlock* CreateJoin(HBasicBlock* first, @@ -1886,6 +1888,12 @@ class HOptimizedGraphBuilder V8_FINAL HBasicBlock* loop_successor, HBasicBlock* break_block); + // Build a loop entry + HBasicBlock* BuildLoopEntry(); + + // Builds a loop entry respectful of OSR requirements + HBasicBlock* BuildLoopEntry(IterationStatement* statement); + HBasicBlock* JoinContinue(IterationStatement* statement, HBasicBlock* exit_block, HBasicBlock* continue_block);