Commit 5ccd2558 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[interpreter] Remove {ContextScope::should_pop_context}.

This removes the need for certain context scopes to skip popping the
context register. For the {incoming_context} the flag was already
obsolete, because its destructor would only run once the basic block
ended with a return. For {local_function_context} the same holds now
by moving handling of implicit returns into the body visitor.

R=rmcilroy@chromium.org

Change-Id: Icceaab1b30d7223b2b2f87a092a6580be7d7d675
Reviewed-on: https://chromium-review.googlesource.com/513963Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45511}
parent dd161a28
......@@ -28,14 +28,12 @@ namespace interpreter {
// popping of the current {context_register} during visitation.
class BytecodeGenerator::ContextScope BASE_EMBEDDED {
public:
ContextScope(BytecodeGenerator* generator, Scope* scope,
bool should_pop_context = true)
ContextScope(BytecodeGenerator* generator, Scope* scope)
: generator_(generator),
scope_(scope),
outer_(generator_->execution_context()),
register_(Register::current_context()),
depth_(0),
should_pop_context_(should_pop_context) {
depth_(0) {
DCHECK(scope->NeedsContext() || outer_ == nullptr);
if (outer_) {
depth_ = outer_->depth_ + 1;
......@@ -56,7 +54,7 @@ class BytecodeGenerator::ContextScope BASE_EMBEDDED {
}
~ContextScope() {
if (outer_ && should_pop_context_) {
if (outer_) {
DCHECK_EQ(register_.index(), Register::current_context().index());
generator_->builder()->PopContext(outer_->reg());
outer_->set_register(register_);
......@@ -95,7 +93,6 @@ class BytecodeGenerator::ContextScope BASE_EMBEDDED {
ContextScope* outer_;
Register register_;
int depth_;
bool should_pop_context_;
};
// Scoped class for tracking control statements entered by the
......@@ -858,7 +855,7 @@ void BytecodeGenerator::GenerateBytecode(uintptr_t stack_limit) {
InitializeAstVisitor(stack_limit);
// Initialize the incoming context.
ContextScope incoming_context(this, closure_scope(), false);
ContextScope incoming_context(this, closure_scope());
// Initialize control scope.
ControlScopeForTopLevel control(this);
......@@ -872,19 +869,14 @@ void BytecodeGenerator::GenerateBytecode(uintptr_t stack_limit) {
if (closure_scope()->NeedsContext()) {
// Push a new inner context scope for the function.
BuildNewLocalActivationContext();
ContextScope local_function_context(this, closure_scope(), false);
ContextScope local_function_context(this, closure_scope());
BuildLocalActivationContextInitialization();
GenerateBytecodeBody();
} else {
GenerateBytecodeBody();
}
// Emit an implicit return instruction in case control flow can fall off the
// end of the function without an explicit return being present on all paths.
if (builder()->RequiresImplicitReturn()) {
builder()->LoadUndefined();
BuildReturn();
}
// Check that we are not falling off the end.
DCHECK(!builder()->RequiresImplicitReturn());
}
......@@ -932,6 +924,13 @@ void BytecodeGenerator::GenerateBytecodeBody() {
// Visit statements in the function body.
VisitStatements(info()->literal()->body());
// Emit an implicit return instruction in case control flow can fall off the
// end of the function without an explicit return being present on all paths.
if (builder()->RequiresImplicitReturn()) {
builder()->LoadUndefined();
BuildReturn();
}
}
void BytecodeGenerator::VisitIterationHeader(IterationStatement* stmt,
......
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