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

Unified Diff: src/hydrogen.cc

Issue 10910161: Partial ia32 implementation of optimized try/catch (by Kevin Millikin) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed build. Created 8 years, 3 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 | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 75344bb513a0d13365ba32bff60330cd2a521301..578a0c4fd83ab52a6d8823d468fecb306ca02b72 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -3941,7 +3941,7 @@ void HGraphBuilder::VisitBlock(Block* stmt) {
if (stmt->scope() != NULL) {
return Bailout("ScopedBlock");
}
- BreakAndContinueInfo break_info(stmt);
+ BreakAndContinueInfo break_info(stmt, 0);
{ BreakAndContinueScope push(&break_info, this);
CHECK_BAILOUT(VisitStatements(stmt->statements()));
}
@@ -4008,20 +4008,41 @@ void HGraphBuilder::VisitIfStatement(IfStatement* stmt) {
}
-HBasicBlock* HGraphBuilder::BreakAndContinueScope::Get(
- BreakableStatement* stmt,
- BreakType type,
- int* drop_extra) {
- *drop_extra = 0;
+void HGraphBuilder::BreakAndContinueScope::UnwindReturn() {
BreakAndContinueScope* current = this;
- while (current != NULL && current->info()->target() != stmt) {
- *drop_extra += current->info()->drop_extra();
+ while (current != NULL) {
+ TryCatchStatement* try_catch =
+ current->info()->statement()->AsTryCatchStatement();
+ if (try_catch != NULL) {
+ HLeaveTry* leave = new(owner()->zone()) HLeaveTry;
+ owner()->AddInstruction(leave);
+ owner()->environment()->RemoveExceptionHandler();
+ owner()->AddSimulate(try_catch->TryExitId());
+ }
+ current = current->next();
+ }
+}
+
+
+void HGraphBuilder::BreakAndContinueScope::Unwind(BreakableStatement* target,
+ BreakType type) {
+ BreakAndContinueScope* current = this;
+ while (current != NULL && current->info()->statement() != target) {
+ TryCatchStatement* try_catch =
+ current->info()->statement()->AsTryCatchStatement();
+ if (try_catch != NULL) {
+ HLeaveTry* leave = new(owner()->zone()) HLeaveTry;
+ owner()->AddInstruction(leave);
+ owner()->environment()->RemoveExceptionHandler();
+ owner()->AddSimulate(try_catch->TryExitId());
+ }
+ owner()->Drop(current->info()->drop_extra());
current = current->next();
}
ASSERT(current != NULL); // Always found (unless stack is malformed).
if (type == BREAK) {
- *drop_extra += current->info()->drop_extra();
+ owner()->Drop(current->info()->drop_extra());
}
HBasicBlock* block = NULL;
@@ -4042,8 +4063,8 @@ HBasicBlock* HGraphBuilder::BreakAndContinueScope::Get(
}
break;
}
-
- return block;
+ owner()->current_block()->Goto(block);
+ owner()->set_current_block(NULL);
}
@@ -4051,13 +4072,7 @@ void HGraphBuilder::VisitContinueStatement(ContinueStatement* stmt) {
ASSERT(!HasStackOverflow());
ASSERT(current_block() != NULL);
ASSERT(current_block()->HasPredecessor());
- int drop_extra = 0;
- HBasicBlock* continue_block = break_scope()->Get(stmt->target(),
- CONTINUE,
- &drop_extra);
- Drop(drop_extra);
- current_block()->Goto(continue_block);
- set_current_block(NULL);
+ break_scope()->Unwind(stmt->target(), CONTINUE);
}
@@ -4065,13 +4080,7 @@ void HGraphBuilder::VisitBreakStatement(BreakStatement* stmt) {
ASSERT(!HasStackOverflow());
ASSERT(current_block() != NULL);
ASSERT(current_block()->HasPredecessor());
- int drop_extra = 0;
- HBasicBlock* break_block = break_scope()->Get(stmt->target(),
- BREAK,
- &drop_extra);
- Drop(drop_extra);
- current_block()->Goto(break_block);
- set_current_block(NULL);
+ break_scope()->Unwind(stmt->target(), BREAK);
}
@@ -4085,6 +4094,7 @@ void HGraphBuilder::VisitReturnStatement(ReturnStatement* stmt) {
// Not an inlined return, so an actual one.
CHECK_ALIVE(VisitForValue(stmt->expression()));
HValue* result = environment()->Pop();
+ break_scope()->UnwindReturn();
current_block()->FinishExit(new(zone()) HReturn(result));
} else if (state->inlining_kind() == CONSTRUCT_CALL_RETURN) {
// Return from an inlined construct call. In a test context the return value
@@ -4277,7 +4287,7 @@ void HGraphBuilder::VisitSwitchStatement(SwitchStatement* stmt) {
HBasicBlock* curr_test_block = first_test_block;
HBasicBlock* fall_through_block = NULL;
- BreakAndContinueInfo break_info(stmt);
+ BreakAndContinueInfo break_info(stmt, 0);
{ BreakAndContinueScope push(&break_info, this);
for (int i = 0; i < clause_count; ++i) {
CaseClause* clause = clauses->at(i);
@@ -4421,7 +4431,7 @@ void HGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) {
set_current_block(loop_entry);
if (osr_entry) graph()->set_osr_loop_entry(loop_entry);
- BreakAndContinueInfo break_info(stmt);
+ BreakAndContinueInfo break_info(stmt, 0);
CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry, &break_info));
HBasicBlock* body_exit =
JoinContinue(stmt, current_block(), break_info.continue_block());
@@ -4482,7 +4492,7 @@ void HGraphBuilder::VisitWhileStatement(WhileStatement* stmt) {
}
}
- BreakAndContinueInfo break_info(stmt);
+ BreakAndContinueInfo break_info(stmt, 0);
if (current_block() != NULL) {
CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry, &break_info));
}
@@ -4527,7 +4537,7 @@ void HGraphBuilder::VisitForStatement(ForStatement* stmt) {
}
}
- BreakAndContinueInfo break_info(stmt);
+ BreakAndContinueInfo break_info(stmt, 0);
if (current_block() != NULL) {
CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry, &break_info));
}
@@ -4672,7 +4682,24 @@ void HGraphBuilder::VisitTryCatchStatement(TryCatchStatement* stmt) {
ASSERT(!HasStackOverflow());
ASSERT(current_block() != NULL);
ASSERT(current_block()->HasPredecessor());
- return Bailout("TryCatchStatement");
+ if (!FLAG_crankshaft_try_support) {
+ Bailout("try statement support disabled");
+ return;
+ }
+ HEnterTry* enter = new(zone()) HEnterTry(stmt->index());
+ AddInstruction(enter);
+ environment()->AddExceptionHandler();
+ AddSimulate(stmt->TryEntryId());
+ BreakAndContinueInfo try_info(stmt, 0);
+ { BreakAndContinueScope push(&try_info, this);
+ CHECK_BAILOUT(Visit(stmt->try_block()));
+ }
+ if (current_block() != NULL) {
+ HLeaveTry* leave = new(zone()) HLeaveTry;
+ AddInstruction(leave);
+ environment()->RemoveExceptionHandler();
+ AddSimulate(stmt->TryExitId());
+ }
}
@@ -9390,6 +9417,7 @@ HEnvironment::HEnvironment(HEnvironment* outer,
parameter_count_(0),
specials_count_(1),
local_count_(0),
+ handler_count_(0),
outer_(outer),
pop_count_(0),
push_count_(0),
@@ -9406,6 +9434,7 @@ HEnvironment::HEnvironment(const HEnvironment* other, Zone* zone)
parameter_count_(0),
specials_count_(1),
local_count_(0),
+ handler_count_(0),
outer_(NULL),
pop_count_(0),
push_count_(0),
@@ -9426,6 +9455,7 @@ HEnvironment::HEnvironment(HEnvironment* outer,
frame_type_(frame_type),
parameter_count_(arguments),
local_count_(0),
+ handler_count_(0),
outer_(outer),
pop_count_(0),
push_count_(0),
@@ -9454,6 +9484,7 @@ void HEnvironment::Initialize(const HEnvironment* other) {
frame_type_ = other->frame_type_;
parameter_count_ = other->parameter_count_;
local_count_ = other->local_count_;
+ handler_count_ = other->handler_count_;
if (other->outer_ != NULL) outer_ = other->outer_->Copy(); // Deep copy.
pop_count_ = other->pop_count_;
push_count_ = other->push_count_;
@@ -9464,6 +9495,7 @@ void HEnvironment::Initialize(const HEnvironment* other) {
void HEnvironment::AddIncomingEdge(HBasicBlock* block, HEnvironment* other) {
ASSERT(!block->IsLoopHeader());
ASSERT(values_.length() == other->values_.length());
+ ASSERT(handler_count_ == other->handler_count_);
int length = values_.length();
for (int i = 0; i < length; ++i) {
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698