Commit 6fe12676 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

Simplify computation of environment stack delta.

R=titzer@chromium.org
TEST=cctest/test-run-jsexceptions/CatchCall

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

Cr-Commit-Position: refs/heads/master@{#26768}
parent 9e6181d5
...@@ -140,10 +140,10 @@ class AstGraphBuilder::ContextScope BASE_EMBEDDED { ...@@ -140,10 +140,10 @@ class AstGraphBuilder::ContextScope BASE_EMBEDDED {
// - TryFinallyStatement: Intercepts 'break', 'continue', 'throw' and 'return'. // - TryFinallyStatement: Intercepts 'break', 'continue', 'throw' and 'return'.
class AstGraphBuilder::ControlScope BASE_EMBEDDED { class AstGraphBuilder::ControlScope BASE_EMBEDDED {
public: public:
ControlScope(AstGraphBuilder* builder, int stack_delta) explicit ControlScope(AstGraphBuilder* builder)
: builder_(builder), : builder_(builder),
outer_(builder->execution_control()), outer_(builder->execution_control()),
stack_delta_(stack_delta) { stack_height_(builder->environment()->stack_height()) {
builder_->set_execution_control(this); // Push. builder_->set_execution_control(this); // Push.
} }
...@@ -190,12 +190,12 @@ class AstGraphBuilder::ControlScope BASE_EMBEDDED { ...@@ -190,12 +190,12 @@ class AstGraphBuilder::ControlScope BASE_EMBEDDED {
Environment* environment() { return builder_->environment(); } Environment* environment() { return builder_->environment(); }
AstGraphBuilder* builder() const { return builder_; } AstGraphBuilder* builder() const { return builder_; }
int stack_delta() const { return stack_delta_; } int stack_height() const { return stack_height_; }
private: private:
AstGraphBuilder* builder_; AstGraphBuilder* builder_;
ControlScope* outer_; ControlScope* outer_;
int stack_delta_; int stack_height_;
}; };
...@@ -271,7 +271,7 @@ class AstGraphBuilder::ControlScopeForBreakable : public ControlScope { ...@@ -271,7 +271,7 @@ class AstGraphBuilder::ControlScopeForBreakable : public ControlScope {
public: public:
ControlScopeForBreakable(AstGraphBuilder* owner, BreakableStatement* target, ControlScopeForBreakable(AstGraphBuilder* owner, BreakableStatement* target,
ControlBuilder* control) ControlBuilder* control)
: ControlScope(owner, 0), target_(target), control_(control) {} : ControlScope(owner), target_(target), control_(control) {}
protected: protected:
virtual bool Execute(Command cmd, Statement* target, Node* value) OVERRIDE { virtual bool Execute(Command cmd, Statement* target, Node* value) OVERRIDE {
...@@ -298,8 +298,8 @@ class AstGraphBuilder::ControlScopeForBreakable : public ControlScope { ...@@ -298,8 +298,8 @@ class AstGraphBuilder::ControlScopeForBreakable : public ControlScope {
class AstGraphBuilder::ControlScopeForIteration : public ControlScope { class AstGraphBuilder::ControlScopeForIteration : public ControlScope {
public: public:
ControlScopeForIteration(AstGraphBuilder* owner, IterationStatement* target, ControlScopeForIteration(AstGraphBuilder* owner, IterationStatement* target,
LoopBuilder* control, int stack_delta) LoopBuilder* control)
: ControlScope(owner, stack_delta), target_(target), control_(control) {} : ControlScope(owner), target_(target), control_(control) {}
protected: protected:
virtual bool Execute(Command cmd, Statement* target, Node* value) OVERRIDE { virtual bool Execute(Command cmd, Statement* target, Node* value) OVERRIDE {
...@@ -328,7 +328,7 @@ class AstGraphBuilder::ControlScopeForIteration : public ControlScope { ...@@ -328,7 +328,7 @@ class AstGraphBuilder::ControlScopeForIteration : public ControlScope {
class AstGraphBuilder::ControlScopeForCatch : public ControlScope { class AstGraphBuilder::ControlScopeForCatch : public ControlScope {
public: public:
ControlScopeForCatch(AstGraphBuilder* owner, TryCatchBuilder* control) ControlScopeForCatch(AstGraphBuilder* owner, TryCatchBuilder* control)
: ControlScope(owner, 0), control_(control) { : ControlScope(owner), control_(control) {
builder()->try_nesting_level_++; // Increment nesting. builder()->try_nesting_level_++; // Increment nesting.
} }
~ControlScopeForCatch() { ~ControlScopeForCatch() {
...@@ -359,7 +359,7 @@ class AstGraphBuilder::ControlScopeForFinally : public ControlScope { ...@@ -359,7 +359,7 @@ class AstGraphBuilder::ControlScopeForFinally : public ControlScope {
public: public:
ControlScopeForFinally(AstGraphBuilder* owner, DeferredCommands* commands, ControlScopeForFinally(AstGraphBuilder* owner, DeferredCommands* commands,
TryFinallyBuilder* control) TryFinallyBuilder* control)
: ControlScope(owner, 0), commands_(commands), control_(control) { : ControlScope(owner), commands_(commands), control_(control) {
builder()->try_nesting_level_++; // Increment nesting. builder()->try_nesting_level_++; // Increment nesting.
} }
~ControlScopeForFinally() { ~ControlScopeForFinally() {
...@@ -439,13 +439,13 @@ bool AstGraphBuilder::CreateGraph(bool constant_context) { ...@@ -439,13 +439,13 @@ bool AstGraphBuilder::CreateGraph(bool constant_context) {
int parameter_count = info()->num_parameters(); int parameter_count = info()->num_parameters();
graph()->SetStart(graph()->NewNode(common()->Start(parameter_count))); graph()->SetStart(graph()->NewNode(common()->Start(parameter_count)));
// Initialize control scope.
ControlScope control(this, 0);
// Initialize the top-level environment. // Initialize the top-level environment.
Environment env(this, scope, graph()->start()); Environment env(this, scope, graph()->start());
set_environment(&env); set_environment(&env);
// Initialize control scope.
ControlScope control(this);
if (info()->is_osr()) { if (info()->is_osr()) {
// Use OSR normal entry as the start of the top-level environment. // Use OSR normal entry as the start of the top-level environment.
// It will be replaced with {Dead} after typing and optimizations. // It will be replaced with {Dead} after typing and optimizations.
...@@ -709,8 +709,8 @@ void AstGraphBuilder::ControlScope::PerformCommand(Command command, ...@@ -709,8 +709,8 @@ void AstGraphBuilder::ControlScope::PerformCommand(Command command,
Environment* env = environment()->CopyAsUnreachable(); Environment* env = environment()->CopyAsUnreachable();
ControlScope* current = this; ControlScope* current = this;
while (current != NULL) { while (current != NULL) {
environment()->Trim(current->stack_height());
if (current->Execute(command, target, value)) break; if (current->Execute(command, target, value)) break;
environment()->Drop(current->stack_delta());
current = current->outer_; current = current->outer_;
} }
builder()->set_environment(env); builder()->set_environment(env);
...@@ -1019,7 +1019,7 @@ void AstGraphBuilder::VisitSwitchStatement(SwitchStatement* stmt) { ...@@ -1019,7 +1019,7 @@ void AstGraphBuilder::VisitSwitchStatement(SwitchStatement* stmt) {
void AstGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) { void AstGraphBuilder::VisitDoWhileStatement(DoWhileStatement* stmt) {
LoopBuilder while_loop(this); LoopBuilder while_loop(this);
while_loop.BeginLoop(GetVariablesAssignedInLoop(stmt), CheckOsrEntry(stmt)); while_loop.BeginLoop(GetVariablesAssignedInLoop(stmt), CheckOsrEntry(stmt));
VisitIterationBody(stmt, &while_loop, 0); VisitIterationBody(stmt, &while_loop);
while_loop.EndBody(); while_loop.EndBody();
VisitForTest(stmt->cond()); VisitForTest(stmt->cond());
Node* condition = environment()->Pop(); Node* condition = environment()->Pop();
...@@ -1034,7 +1034,7 @@ void AstGraphBuilder::VisitWhileStatement(WhileStatement* stmt) { ...@@ -1034,7 +1034,7 @@ void AstGraphBuilder::VisitWhileStatement(WhileStatement* stmt) {
VisitForTest(stmt->cond()); VisitForTest(stmt->cond());
Node* condition = environment()->Pop(); Node* condition = environment()->Pop();
while_loop.BreakUnless(condition); while_loop.BreakUnless(condition);
VisitIterationBody(stmt, &while_loop, 0); VisitIterationBody(stmt, &while_loop);
while_loop.EndBody(); while_loop.EndBody();
while_loop.EndLoop(); while_loop.EndLoop();
} }
...@@ -1051,7 +1051,7 @@ void AstGraphBuilder::VisitForStatement(ForStatement* stmt) { ...@@ -1051,7 +1051,7 @@ void AstGraphBuilder::VisitForStatement(ForStatement* stmt) {
} else { } else {
for_loop.BreakUnless(jsgraph()->TrueConstant()); for_loop.BreakUnless(jsgraph()->TrueConstant());
} }
VisitIterationBody(stmt, &for_loop, 0); VisitIterationBody(stmt, &for_loop);
for_loop.EndBody(); for_loop.EndBody();
VisitIfNotNull(stmt->next()); VisitIfNotNull(stmt->next());
for_loop.EndLoop(); for_loop.EndLoop();
...@@ -1190,7 +1190,7 @@ void AstGraphBuilder::VisitForInBody(ForInStatement* stmt) { ...@@ -1190,7 +1190,7 @@ void AstGraphBuilder::VisitForInBody(ForInStatement* stmt) {
value = environment()->Pop(); value = environment()->Pop();
// Bind value and do loop body. // Bind value and do loop body.
VisitForInAssignment(stmt->each(), value, stmt->AssignmentId()); VisitForInAssignment(stmt->each(), value, stmt->AssignmentId());
VisitIterationBody(stmt, &for_loop, 5); VisitIterationBody(stmt, &for_loop);
for_loop.EndBody(); for_loop.EndBody();
// Inc counter and continue. // Inc counter and continue.
Node* index_inc = Node* index_inc =
...@@ -1213,7 +1213,7 @@ void AstGraphBuilder::VisitForOfStatement(ForOfStatement* stmt) { ...@@ -1213,7 +1213,7 @@ void AstGraphBuilder::VisitForOfStatement(ForOfStatement* stmt) {
Node* condition = environment()->Pop(); Node* condition = environment()->Pop();
for_loop.BreakWhen(condition); for_loop.BreakWhen(condition);
VisitForEffect(stmt->assign_each()); VisitForEffect(stmt->assign_each());
VisitIterationBody(stmt, &for_loop, 0); VisitIterationBody(stmt, &for_loop);
for_loop.EndBody(); for_loop.EndBody();
for_loop.EndLoop(); for_loop.EndLoop();
} }
...@@ -2304,8 +2304,8 @@ void AstGraphBuilder::VisitIfNotNull(Statement* stmt) { ...@@ -2304,8 +2304,8 @@ void AstGraphBuilder::VisitIfNotNull(Statement* stmt) {
void AstGraphBuilder::VisitIterationBody(IterationStatement* stmt, void AstGraphBuilder::VisitIterationBody(IterationStatement* stmt,
LoopBuilder* loop, int stack_delta) { LoopBuilder* loop) {
ControlScopeForIteration scope(this, stmt, loop, stack_delta); ControlScopeForIteration scope(this, stmt, loop);
Visit(stmt->body()); Visit(stmt->body());
} }
...@@ -3022,10 +3022,8 @@ Node* AstGraphBuilder::MakeNode(const Operator* op, int value_input_count, ...@@ -3022,10 +3022,8 @@ Node* AstGraphBuilder::MakeNode(const Operator* op, int value_input_count,
if (!result->op()->HasProperty(Operator::kNoThrow) && inside_try_scope) { if (!result->op()->HasProperty(Operator::kNoThrow) && inside_try_scope) {
Node* on_exception = graph()->NewNode(common()->IfException(), result); Node* on_exception = graph()->NewNode(common()->IfException(), result);
environment_->UpdateControlDependency(on_exception); environment_->UpdateControlDependency(on_exception);
if (FLAG_turbo_exceptions) {
execution_control()->ThrowValue(jsgraph()->UndefinedConstant()); execution_control()->ThrowValue(jsgraph()->UndefinedConstant());
} }
}
// Add implicit success continuation for throwing nodes. // Add implicit success continuation for throwing nodes.
if (!result->op()->HasProperty(Operator::kNoThrow)) { if (!result->op()->HasProperty(Operator::kNoThrow)) {
Node* on_success = graph()->NewNode(common()->IfSuccess(), result); Node* on_success = graph()->NewNode(common()->IfSuccess(), result);
......
...@@ -290,7 +290,7 @@ class AstGraphBuilder : public AstVisitor { ...@@ -290,7 +290,7 @@ class AstGraphBuilder : public AstVisitor {
void VisitForValues(ZoneList<Expression*>* exprs); void VisitForValues(ZoneList<Expression*>* exprs);
// Common for all IterationStatement bodies. // Common for all IterationStatement bodies.
void VisitIterationBody(IterationStatement* stmt, LoopBuilder* loop, int); void VisitIterationBody(IterationStatement* stmt, LoopBuilder* loop);
// Dispatched from VisitCallRuntime. // Dispatched from VisitCallRuntime.
void VisitCallJSRuntime(CallRuntime* expr); void VisitCallJSRuntime(CallRuntime* expr);
...@@ -400,6 +400,11 @@ class AstGraphBuilder::Environment : public ZoneObject { ...@@ -400,6 +400,11 @@ class AstGraphBuilder::Environment : public ZoneObject {
DCHECK(depth >= 0 && depth <= stack_height()); DCHECK(depth >= 0 && depth <= stack_height());
values()->erase(values()->end() - depth, values()->end()); values()->erase(values()->end() - depth, values()->end());
} }
void Trim(int trim_to_height) {
int depth = stack_height() - trim_to_height;
DCHECK(depth >= 0 && depth <= stack_height());
values()->erase(values()->end() - depth, values()->end());
}
// Preserve a checkpoint of the environment for the IR graph. Any // Preserve a checkpoint of the environment for the IR graph. Any
// further mutation of the environment will not affect checkpoints. // further mutation of the environment will not affect checkpoints.
......
...@@ -125,7 +125,7 @@ TEST(CatchCall) { ...@@ -125,7 +125,7 @@ TEST(CatchCall) {
" var r = '-';" " var r = '-';"
" try {" " try {"
" r += 'A-';" " r += 'A-';"
" fun();" " return r + 'B-' + fun();"
" } catch (e) {" " } catch (e) {"
" r += e;" " r += e;"
" }" " }"
...@@ -137,6 +137,8 @@ TEST(CatchCall) { ...@@ -137,6 +137,8 @@ TEST(CatchCall) {
#if 0 // TODO(mstarzinger): Enable once we have exception handlers. #if 0 // TODO(mstarzinger): Enable once we have exception handlers.
T.CheckCall(T.Val("-A-T-"), T.NewFunction("thrower")); T.CheckCall(T.Val("-A-T-"), T.NewFunction("thrower"));
#endif #endif
CompileRun("function returner() { return 'R-'; }");
T.CheckCall(T.Val("-A-B-R-"), T.NewFunction("returner"));
} }
......
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