Reviewers: titzer,
Description:
Turn throws into basic block terminators.
[email protected]
TEST=cctest/test-run-jsexceptions/Throw
Please review this at https://codereview.chromium.org/896783002/
Base URL: https://chromium.googlesource.com/v8/v8.git@local_trycatch-1
Affected files (+19, -9 lines):
M src/compiler/ast-graph-builder.cc
M src/compiler/instruction-selector.cc
M src/compiler/scheduler.cc
M test/cctest/compiler/test-run-jsexceptions.cc
Index: src/compiler/ast-graph-builder.cc
diff --git a/src/compiler/ast-graph-builder.cc
b/src/compiler/ast-graph-builder.cc
index
98d80e8a9d2ce17dc065a0574c4f8c9de629fde9..3a9fcd9d83447d60e13359652f62fdbf40228f4c
100644
--- a/src/compiler/ast-graph-builder.cc
+++ b/src/compiler/ast-graph-builder.cc
@@ -551,8 +551,7 @@ void
AstGraphBuilder::ControlScope::PerformCommand(Command command,
environment()->Drop(current->stack_delta());
current = current->next_;
}
- // TODO(mstarzinger): Unconditionally kill environment once throw is
control.
- if (command != CMD_THROW) builder()->set_environment(env);
+ builder()->set_environment(env);
DCHECK(current != NULL); // Always handled (unless stack is malformed).
}
@@ -2678,11 +2677,9 @@ Node* AstGraphBuilder::BuildReturn(Node*
return_value) {
Node* AstGraphBuilder::BuildThrow(Node* exception_value) {
- const Operator* op = javascript()->CallRuntime(Runtime::kThrow, 1);
- Node* control = NewNode(op, exception_value);
- // TODO(mstarzinger): Thread through the correct bailout id to this
point.
- // PrepareFrameState(value, expr->id(),
ast_context()->GetStateCombine());
- PrepareFrameState(control, BailoutId::None());
+ NewNode(javascript()->CallRuntime(Runtime::kReThrow, 1),
exception_value);
+ Node* control = NewNode(common()->Throw(), exception_value);
+ UpdateControlDependencyToLeaveFunction(control);
return control;
}
Index: src/compiler/instruction-selector.cc
diff --git a/src/compiler/instruction-selector.cc
b/src/compiler/instruction-selector.cc
index
fe9c287bc73740ee2381664640b110d41644f745..05d1b212f9cfcf58acae6136b592dd7603fea772
100644
--- a/src/compiler/instruction-selector.cc
+++ b/src/compiler/instruction-selector.cc
@@ -521,7 +521,8 @@ void InstructionSelector::VisitControl(BasicBlock*
block) {
return VisitReturn(value);
}
case BasicBlock::kThrow:
- return VisitThrow(input);
+ DCHECK_EQ(IrOpcode::kThrow, input->opcode());
+ return VisitThrow(input->InputAt(0));
case BasicBlock::kNone: {
// TODO(titzer): exit block doesn't have control.
DCHECK(input == NULL);
@@ -1049,7 +1050,7 @@ void InstructionSelector::VisitReturn(Node* value) {
void InstructionSelector::VisitThrow(Node* value) {
- UNIMPLEMENTED(); // TODO(titzer)
+ Emit(kArchNop, NULL); // TODO(titzer)
}
Index: src/compiler/scheduler.cc
diff --git a/src/compiler/scheduler.cc b/src/compiler/scheduler.cc
index
6281371abacc6b737045d38ac1f5de4ef32c4bcb..e0d659822c857a6bac8cd602b31cc2c77bebf195
100644
--- a/src/compiler/scheduler.cc
+++ b/src/compiler/scheduler.cc
@@ -336,6 +336,10 @@ class CFGBuilder : public ZoneObject {
scheduler_->UpdatePlacement(node, Scheduler::kFixed);
ConnectReturn(node);
break;
+ case IrOpcode::kThrow:
+ scheduler_->UpdatePlacement(node, Scheduler::kFixed);
+ ConnectThrow(node);
+ break;
default:
break;
}
@@ -447,6 +451,13 @@ class CFGBuilder : public ZoneObject {
schedule_->AddReturn(return_block, ret);
}
+ void ConnectThrow(Node* thr) {
+ Node* throw_block_node = NodeProperties::GetControlInput(thr);
+ BasicBlock* throw_block = schedule_->block(throw_block_node);
+ TraceConnect(thr, throw_block, NULL);
+ schedule_->AddThrow(throw_block, thr);
+ }
+
void TraceConnect(Node* node, BasicBlock* block, BasicBlock* succ) {
DCHECK(block);
if (succ == NULL) {
Index: test/cctest/compiler/test-run-jsexceptions.cc
diff --git a/test/cctest/compiler/test-run-jsexceptions.cc
b/test/cctest/compiler/test-run-jsexceptions.cc
index
43ce91b56b6928a5b0de65fc0dd66472a7e51edf..74990daac9ff0fcc9391fff3819f7e4eda9e8eb9
100644
--- a/test/cctest/compiler/test-run-jsexceptions.cc
+++ b/test/cctest/compiler/test-run-jsexceptions.cc
@@ -10,6 +10,7 @@ using namespace v8::internal;
using namespace v8::internal::compiler;
TEST(Throw) {
+ i::FLAG_turbo_exceptions = true;
FunctionTester T("(function(a,b) { if (a) { throw b; } else { return b;
}})");
T.CheckThrows(T.true_value(), T.NewObject("new Error"));
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.