Commit c68df411 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Interpreter] Allocate context registers as temporary registers.

Rather than trying to pre-calculate the number of contexts required during
scope analysis, instead just allocate context registers in the register
allocator. This reduces frame size a bit due to reusing of registers when
the context isn't pushed.

 BUG=v8:6322, chromium:716265

Change-Id: I145e38fcb3797a3b86c91e90ea9326a6e55b9b89
Reviewed-on: https://chromium-review.googlesource.com/514087Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45522}
parent a07218a5
......@@ -1409,19 +1409,6 @@ int Scope::ContextChainLengthUntilOutermostSloppyEval() const {
return result;
}
int Scope::MaxNestedContextChainLength() {
int max_context_chain_length = 0;
for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
if (scope->is_function_scope()) continue;
max_context_chain_length = std::max(scope->MaxNestedContextChainLength(),
max_context_chain_length);
}
if (NeedsContext()) {
max_context_chain_length += 1;
}
return max_context_chain_length;
}
DeclarationScope* Scope::GetDeclarationScope() {
Scope* scope = this;
while (!scope->is_declaration_scope()) {
......
......@@ -407,10 +407,6 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
// sloppy eval call. One if this->calls_sloppy_eval().
int ContextChainLengthUntilOutermostSloppyEval() const;
// The maximum number of nested contexts required for this scope and any inner
// scopes.
int MaxNestedContextChainLength();
// Find the first function, script, eval or (declaration) block scope. This is
// the scope where var declarations will be hoisted to in the implementation.
DeclarationScope* GetDeclarationScope();
......
......@@ -38,8 +38,8 @@ class RegisterTransferWriter final
};
BytecodeArrayBuilder::BytecodeArrayBuilder(
Isolate* isolate, Zone* zone, int parameter_count, int context_count,
int locals_count, FunctionLiteral* literal,
Isolate* isolate, Zone* zone, int parameter_count, int locals_count,
FunctionLiteral* literal,
SourcePositionTableBuilder::RecordingMode source_position_mode)
: zone_(zone),
literal_(literal),
......@@ -49,13 +49,11 @@ BytecodeArrayBuilder::BytecodeArrayBuilder(
return_seen_in_block_(false),
parameter_count_(parameter_count),
local_register_count_(locals_count),
context_register_count_(context_count),
register_allocator_(fixed_register_count()),
bytecode_array_writer_(zone, &constant_array_builder_,
source_position_mode),
register_optimizer_(nullptr) {
DCHECK_GE(parameter_count_, 0);
DCHECK_GE(context_register_count_, 0);
DCHECK_GE(local_register_count_, 0);
if (FLAG_ignition_reo) {
......@@ -67,16 +65,6 @@ BytecodeArrayBuilder::BytecodeArrayBuilder(
return_position_ = literal ? literal->return_position() : kNoSourcePosition;
}
Register BytecodeArrayBuilder::first_context_register() const {
DCHECK_GT(context_register_count_, 0);
return Register(local_register_count_);
}
Register BytecodeArrayBuilder::last_context_register() const {
DCHECK_GT(context_register_count_, 0);
return Register(local_register_count_ + context_register_count_ - 1);
}
Register BytecodeArrayBuilder::Parameter(int parameter_index) const {
DCHECK_GE(parameter_index, 0);
// The parameter indices are shifted by 1 (receiver is the
......
......@@ -35,8 +35,8 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final
: public NON_EXPORTED_BASE(ZoneObject) {
public:
BytecodeArrayBuilder(
Isolate* isolate, Zone* zone, int parameter_count, int context_count,
int locals_count, FunctionLiteral* literal = nullptr,
Isolate* isolate, Zone* zone, int parameter_count, int locals_count,
FunctionLiteral* literal = nullptr,
SourcePositionTableBuilder::RecordingMode source_position_mode =
SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS);
......@@ -54,17 +54,8 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final
return local_register_count_;
}
// Get number of contexts required for bytecode array.
int context_count() const {
DCHECK_GE(context_register_count_, 0);
return context_register_count_;
}
Register first_context_register() const;
Register last_context_register() const;
// Returns the number of fixed (non-temporary) registers.
int fixed_register_count() const { return context_count() + locals_count(); }
int fixed_register_count() const { return locals_count(); }
// Returns the number of fixed and temporary registers.
int total_register_count() const {
......@@ -558,7 +549,6 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final
bool return_seen_in_block_;
int parameter_count_;
int local_register_count_;
int context_register_count_;
int return_position_;
BytecodeRegisterAllocator register_allocator_;
BytecodeArrayWriter bytecode_array_writer_;
......
......@@ -38,15 +38,9 @@ class BytecodeGenerator::ContextScope BASE_EMBEDDED {
if (outer_) {
depth_ = outer_->depth_ + 1;
int outer_reg_index =
builder()->first_context_register().index() + outer_->depth_;
// TODO(ignition): ensure overwriting of non-context registers with
// a Context can never occurs, and re-enable DCHECK.
// DCHECK_LE(outer_reg_index, builder()->last_context_register().index());
// Push the outer context into a new context register.
Register outer_context_reg(outer_reg_index);
Register outer_context_reg =
generator_->register_allocator()->NewRegister();
outer_->set_register(outer_context_reg);
generator_->builder()->PushContext(outer_context_reg);
}
......@@ -766,7 +760,6 @@ BytecodeGenerator::BytecodeGenerator(CompilationInfo* info)
: zone_(info->zone()),
builder_(new (zone()) BytecodeArrayBuilder(
info->isolate(), info->zone(), info->num_parameters_including_this(),
info->scope()->MaxNestedContextChainLength(),
info->scope()->num_stack_slots(), info->literal(),
info->SourcePositionRecordingMode())),
info_(info),
......
......@@ -9,23 +9,23 @@ wrap: yes
snippet: "
try { return 1; } catch(e) { return 2; }
"
frame size: 3
frame size: 2
parameter count: 1
bytecode array length: 30
bytecodes: [
/* 30 E> */ B(StackCheck),
B(Mov), R(context), R(1),
B(Mov), R(context), R(0),
/* 40 S> */ B(LdaSmi), I8(1),
/* 75 S> */ B(Return),
B(Jump), U8(21),
B(Star), R(2),
B(Ldar), R(closure),
B(CreateCatchContext), R(2), U8(0), U8(1),
B(Star), R(1),
B(Ldar), R(closure),
B(CreateCatchContext), R(1), U8(0), U8(1),
B(Star), R(0),
B(LdaTheHole),
B(SetPendingMessage),
B(Ldar), R(1),
B(PushContext), R(0),
B(Ldar), R(0),
B(PushContext), R(1),
/* 63 S> */ B(LdaSmi), I8(2),
/* 75 S> */ B(Return),
B(LdaUndefined),
......@@ -45,39 +45,39 @@ snippet: "
try { a = 1 } catch(e1) {};
try { a = 2 } catch(e2) { a = 3 }
"
frame size: 4
frame size: 3
parameter count: 1
bytecode array length: 61
bytecodes: [
/* 30 E> */ B(StackCheck),
B(Mov), R(context), R(2),
B(Mov), R(context), R(1),
/* 47 S> */ B(LdaSmi), I8(1),
B(Star), R(0),
B(Jump), U8(20),
B(Star), R(3),
B(Ldar), R(closure),
/* 49 E> */ B(CreateCatchContext), R(3), U8(0), U8(1),
B(Star), R(2),
B(Ldar), R(closure),
/* 49 E> */ B(CreateCatchContext), R(2), U8(0), U8(1),
B(Star), R(1),
B(LdaTheHole),
B(SetPendingMessage),
B(Ldar), R(2),
B(PushContext), R(1),
B(PopContext), R(1),
B(Mov), R(context), R(2),
B(Ldar), R(1),
B(PushContext), R(2),
B(PopContext), R(2),
B(Mov), R(context), R(1),
/* 75 S> */ B(LdaSmi), I8(2),
B(Star), R(0),
B(Jump), U8(24),
B(Star), R(3),
B(Ldar), R(closure),
/* 77 E> */ B(CreateCatchContext), R(3), U8(2), U8(3),
B(Star), R(2),
B(Ldar), R(closure),
/* 77 E> */ B(CreateCatchContext), R(2), U8(2), U8(3),
B(Star), R(1),
B(LdaTheHole),
B(SetPendingMessage),
B(Ldar), R(2),
B(PushContext), R(1),
B(Ldar), R(1),
B(PushContext), R(2),
/* 95 S> */ B(LdaSmi), I8(3),
B(Star), R(0),
B(PopContext), R(1),
B(PopContext), R(2),
B(LdaUndefined),
/* 103 S> */ B(Return),
]
......
......@@ -9,16 +9,16 @@ wrap: yes
snippet: "
with ({x:42}) { return x; }
"
frame size: 2
frame size: 1
parameter count: 1
bytecode array length: 20
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 34 S> */ B(CreateObjectLiteral), U8(0), U8(3), U8(1), R(1),
B(Ldar), R(1),
B(ToObject), R(1),
/* 34 S> */ B(CreateObjectLiteral), U8(0), U8(3), U8(1), R(0),
B(Ldar), R(0),
B(ToObject), R(0),
B(Ldar), R(closure),
B(CreateWithContext), R(1), U8(1),
B(CreateWithContext), R(0), U8(1),
B(PushContext), R(0),
/* 50 S> */ B(LdaLookupSlot), U8(2),
/* 62 S> */ B(Return),
......
This diff is collapsed.
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