Commit 231c8ac0 authored by adamk's avatar adamk Committed by Commit bot

[full-codegen] Eliminate unnecessary hole checks for stores

Loads already used source position elimination to avoid unnecessary hole checks,
but for reasons unknown stores did not. This CL corrects that, making full-codegen's
hole elimination equivalent to ignition's.

Also introduced a HoleCheckMode enum class to avoid more bool flags and updated
VariableProxy and BytecodeGenerator appropriately.

Review-Url: https://codereview.chromium.org/2441543005
Cr-Commit-Position: refs/heads/master@{#40522}
parent 8e742617
......@@ -165,9 +165,10 @@ VariableProxy::VariableProxy(Variable* var, int start_position,
end_position_(end_position),
raw_name_(var->raw_name()),
next_unresolved_(nullptr) {
bit_field_ |=
IsThisField::encode(var->is_this()) | IsAssignedField::encode(false) |
IsResolvedField::encode(false) | NeedsHoleCheckField::encode(false);
bit_field_ |= IsThisField::encode(var->is_this()) |
IsAssignedField::encode(false) |
IsResolvedField::encode(false) |
HoleCheckModeField::encode(HoleCheckMode::kElided);
BindTo(var);
}
......@@ -181,7 +182,7 @@ VariableProxy::VariableProxy(const AstRawString* name,
bit_field_ |= IsThisField::encode(variable_kind == THIS_VARIABLE) |
IsAssignedField::encode(false) |
IsResolvedField::encode(false) |
NeedsHoleCheckField::encode(false);
HoleCheckModeField::encode(HoleCheckMode::kElided);
}
VariableProxy::VariableProxy(const VariableProxy* copy_from)
......
......@@ -1671,11 +1671,12 @@ class VariableProxy final : public Expression {
bit_field_ = IsNewTargetField::update(bit_field_, true);
}
bool needs_hole_check() const {
return NeedsHoleCheckField::decode(bit_field_);
HoleCheckMode hole_check_mode() const {
return HoleCheckModeField::decode(bit_field_);
}
void set_needs_hole_check() {
bit_field_ = NeedsHoleCheckField::update(bit_field_, true);
bit_field_ =
HoleCheckModeField::update(bit_field_, HoleCheckMode::kRequired);
}
int end_position() const { return end_position_; }
......@@ -1713,8 +1714,8 @@ class VariableProxy final : public Expression {
class IsAssignedField : public BitField<bool, IsThisField::kNext, 1> {};
class IsResolvedField : public BitField<bool, IsAssignedField::kNext, 1> {};
class IsNewTargetField : public BitField<bool, IsResolvedField::kNext, 1> {};
class NeedsHoleCheckField
: public BitField<bool, IsNewTargetField::kNext, 1> {};
class HoleCheckModeField
: public BitField<HoleCheckMode, IsNewTargetField::kNext, 1> {};
// Position is stored in the AstNode superclass, but VariableProxy needs to
// know its end position too (for error messages). It cannot be inferred from
......
......@@ -1287,7 +1287,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy,
DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode);
Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable"
: "[ Stack variable");
if (proxy->needs_hole_check()) {
if (proxy->hole_check_mode() == HoleCheckMode::kRequired) {
// Throw a reference error when using an uninitialized let/const
// binding in harmony mode.
Label done;
......@@ -1730,12 +1730,14 @@ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
// Store the value.
switch (assign_type) {
case VARIABLE:
EmitVariableAssignment(expr->target()->AsVariableProxy()->var(),
expr->op(), expr->AssignmentSlot());
case VARIABLE: {
VariableProxy* proxy = expr->target()->AsVariableProxy();
EmitVariableAssignment(proxy->var(), expr->op(), expr->AssignmentSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER);
context()->Plug(r0);
break;
}
case NAMED_PROPERTY:
EmitNamedPropertyAssignment(expr);
break;
......@@ -2017,9 +2019,10 @@ void FullCodeGenerator::EmitAssignment(Expression* expr,
switch (assign_type) {
case VARIABLE: {
Variable* var = expr->AsVariableProxy()->var();
VariableProxy* proxy = expr->AsVariableProxy();
EffectContext context(this);
EmitVariableAssignment(var, Token::ASSIGN, slot);
EmitVariableAssignment(proxy->var(), Token::ASSIGN, slot,
proxy->hole_check_mode());
break;
}
case NAMED_PROPERTY: {
......@@ -2094,9 +2097,9 @@ void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot(
}
}
void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
FeedbackVectorSlot slot) {
FeedbackVectorSlot slot,
HoleCheckMode hole_check_mode) {
if (var->IsUnallocated()) {
// Global var, const, or let.
__ LoadGlobalObject(StoreDescriptor::ReceiverRegister());
......@@ -2107,7 +2110,7 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
DCHECK(var->IsStackAllocated() || var->IsContextSlot());
MemOperand location = VarOperand(var, r1);
// Perform an initialization check for lexically declared variables.
if (var->binding_needs_init()) {
if (hole_check_mode == HoleCheckMode::kRequired) {
Label assign;
__ ldr(r3, location);
__ CompareRoot(r3, Heap::kTheHoleValueRootIndex);
......@@ -3188,11 +3191,12 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
// Store the value returned in r0.
switch (assign_type) {
case VARIABLE:
case VARIABLE: {
VariableProxy* proxy = expr->expression()->AsVariableProxy();
if (expr->is_postfix()) {
{ EffectContext context(this);
EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
Token::ASSIGN, expr->CountSlot());
EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(),
BailoutState::TOS_REGISTER);
context.Plug(r0);
......@@ -3203,13 +3207,14 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
context()->PlugTOS();
}
} else {
EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
Token::ASSIGN, expr->CountSlot());
EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(),
BailoutState::TOS_REGISTER);
context()->Plug(r0);
}
break;
}
case NAMED_PROPERTY: {
PopOperand(StoreDescriptor::ReceiverRegister());
CallStoreIC(expr->CountSlot(), prop->key()->AsLiteral()->value());
......
......@@ -1275,7 +1275,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy,
Comment cmnt(masm_, var->IsContextSlot()
? "Context variable"
: "Stack variable");
if (proxy->needs_hole_check()) {
if (proxy->hole_check_mode() == HoleCheckMode::kRequired) {
// Throw a reference error when using an uninitialized let/const
// binding in harmony mode.
Label done;
......@@ -1710,12 +1710,14 @@ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
// Store the value.
switch (assign_type) {
case VARIABLE:
EmitVariableAssignment(expr->target()->AsVariableProxy()->var(),
expr->op(), expr->AssignmentSlot());
case VARIABLE: {
VariableProxy* proxy = expr->target()->AsVariableProxy();
EmitVariableAssignment(proxy->var(), expr->op(), expr->AssignmentSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER);
context()->Plug(x0);
break;
}
case NAMED_PROPERTY:
EmitNamedPropertyAssignment(expr);
break;
......@@ -1908,9 +1910,10 @@ void FullCodeGenerator::EmitAssignment(Expression* expr,
switch (assign_type) {
case VARIABLE: {
Variable* var = expr->AsVariableProxy()->var();
VariableProxy* proxy = expr->AsVariableProxy();
EffectContext context(this);
EmitVariableAssignment(var, Token::ASSIGN, slot);
EmitVariableAssignment(proxy->var(), Token::ASSIGN, slot,
proxy->hole_check_mode());
break;
}
case NAMED_PROPERTY: {
......@@ -1987,9 +1990,9 @@ void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot(
}
}
void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
FeedbackVectorSlot slot) {
FeedbackVectorSlot slot,
HoleCheckMode hole_check_mode) {
ASM_LOCATION("FullCodeGenerator::EmitVariableAssignment");
if (var->IsUnallocated()) {
// Global var, const, or let.
......@@ -3106,11 +3109,12 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
// Store the value returned in x0.
switch (assign_type) {
case VARIABLE:
case VARIABLE: {
VariableProxy* proxy = expr->expression()->AsVariableProxy();
if (expr->is_postfix()) {
{ EffectContext context(this);
EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
Token::ASSIGN, expr->CountSlot());
EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(),
BailoutState::TOS_REGISTER);
context.Plug(x0);
......@@ -3121,13 +3125,14 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
context()->PlugTOS();
}
} else {
EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
Token::ASSIGN, expr->CountSlot());
EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(),
BailoutState::TOS_REGISTER);
context()->Plug(x0);
}
break;
}
case NAMED_PROPERTY: {
PopOperand(StoreDescriptor::ReceiverRegister());
CallStoreIC(expr->CountSlot(), prop->key()->AsLiteral()->value());
......
......@@ -1582,7 +1582,7 @@ void FullCodeGenerator::VisitClassLiteral(ClassLiteral* lit) {
if (lit->class_variable_proxy() != nullptr) {
EmitVariableAssignment(lit->class_variable_proxy()->var(), Token::INIT,
lit->ProxySlot());
lit->ProxySlot(), HoleCheckMode::kElided);
}
context()->Plug(result_register());
......
......@@ -572,7 +572,8 @@ class FullCodeGenerator final : public AstVisitor<FullCodeGenerator> {
// Complete a variable assignment. The right-hand-side value is expected
// in the accumulator.
void EmitVariableAssignment(Variable* var, Token::Value op,
FeedbackVectorSlot slot);
FeedbackVectorSlot slot,
HoleCheckMode hole_check_mode);
// Helper functions to EmitVariableAssignment
void EmitStoreToStackLocalOrContextSlot(Variable* var,
......
......@@ -1210,7 +1210,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy,
Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable"
: "[ Stack variable");
if (proxy->needs_hole_check()) {
if (proxy->hole_check_mode() == HoleCheckMode::kRequired) {
// Throw a reference error when using an uninitialized let/const
// binding in harmony mode.
Label done;
......@@ -1643,12 +1643,14 @@ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
// Store the value.
switch (assign_type) {
case VARIABLE:
EmitVariableAssignment(expr->target()->AsVariableProxy()->var(),
expr->op(), expr->AssignmentSlot());
case VARIABLE: {
VariableProxy* proxy = expr->target()->AsVariableProxy();
EmitVariableAssignment(proxy->var(), expr->op(), expr->AssignmentSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER);
context()->Plug(eax);
break;
}
case NAMED_PROPERTY:
EmitNamedPropertyAssignment(expr);
break;
......@@ -1927,9 +1929,10 @@ void FullCodeGenerator::EmitAssignment(Expression* expr,
switch (assign_type) {
case VARIABLE: {
Variable* var = expr->AsVariableProxy()->var();
VariableProxy* proxy = expr->AsVariableProxy();
EffectContext context(this);
EmitVariableAssignment(var, Token::ASSIGN, slot);
EmitVariableAssignment(proxy->var(), Token::ASSIGN, slot,
proxy->hole_check_mode());
break;
}
case NAMED_PROPERTY: {
......@@ -2002,9 +2005,9 @@ void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot(
}
}
void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
FeedbackVectorSlot slot) {
FeedbackVectorSlot slot,
HoleCheckMode hole_check_mode) {
if (var->IsUnallocated()) {
// Global var, const, or let.
__ mov(StoreDescriptor::ReceiverRegister(), NativeContextOperand());
......@@ -2018,7 +2021,7 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
DCHECK(var->IsStackAllocated() || var->IsContextSlot());
MemOperand location = VarOperand(var, ecx);
// Perform an initialization check for lexically declared variables.
if (var->binding_needs_init()) {
if (hole_check_mode == HoleCheckMode::kRequired) {
Label assign;
__ mov(edx, location);
__ cmp(edx, isolate()->factory()->the_hole_value());
......@@ -3084,12 +3087,13 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
// Store the value returned in eax.
switch (assign_type) {
case VARIABLE:
case VARIABLE: {
VariableProxy* proxy = expr->expression()->AsVariableProxy();
if (expr->is_postfix()) {
// Perform the assignment as if via '='.
{ EffectContext context(this);
EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
Token::ASSIGN, expr->CountSlot());
EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(),
BailoutState::TOS_REGISTER);
context.Plug(eax);
......@@ -3101,13 +3105,14 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
}
} else {
// Perform the assignment as if via '='.
EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
Token::ASSIGN, expr->CountSlot());
EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(),
BailoutState::TOS_REGISTER);
context()->Plug(eax);
}
break;
}
case NAMED_PROPERTY: {
PopOperand(StoreDescriptor::ReceiverRegister());
CallStoreIC(expr->CountSlot(), prop->key()->AsLiteral()->value());
......
......@@ -1287,7 +1287,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy,
DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode);
Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable"
: "[ Stack variable");
if (proxy->needs_hole_check()) {
if (proxy->hole_check_mode() == HoleCheckMode::kRequired) {
// Throw a reference error when using an uninitialized let/const
// binding in harmony mode.
Label done;
......@@ -1731,12 +1731,14 @@ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
// Store the value.
switch (assign_type) {
case VARIABLE:
EmitVariableAssignment(expr->target()->AsVariableProxy()->var(),
expr->op(), expr->AssignmentSlot());
case VARIABLE: {
VariableProxy* proxy = expr->target()->AsVariableProxy();
EmitVariableAssignment(proxy->var(), expr->op(), expr->AssignmentSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER);
context()->Plug(v0);
break;
}
case NAMED_PROPERTY:
EmitNamedPropertyAssignment(expr);
break;
......@@ -2025,9 +2027,10 @@ void FullCodeGenerator::EmitAssignment(Expression* expr,
switch (assign_type) {
case VARIABLE: {
Variable* var = expr->AsVariableProxy()->var();
VariableProxy* proxy = expr->AsVariableProxy();
EffectContext context(this);
EmitVariableAssignment(var, Token::ASSIGN, slot);
EmitVariableAssignment(proxy->var(), Token::ASSIGN, slot,
proxy->hole_check_mode());
break;
}
case NAMED_PROPERTY: {
......@@ -2102,9 +2105,9 @@ void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot(
}
}
void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
FeedbackVectorSlot slot) {
FeedbackVectorSlot slot,
HoleCheckMode hole_check_mode) {
if (var->IsUnallocated()) {
// Global var, const, or let.
__ mov(StoreDescriptor::ValueRegister(), result_register());
......@@ -2116,7 +2119,7 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
DCHECK(var->IsStackAllocated() || var->IsContextSlot());
MemOperand location = VarOperand(var, a1);
// Perform an initialization check for lexically declared variables.
if (var->binding_needs_init()) {
if (hole_check_mode == HoleCheckMode::kRequired) {
Label assign;
__ lw(a3, location);
__ LoadRoot(t0, Heap::kTheHoleValueRootIndex);
......@@ -3195,11 +3198,12 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
// Store the value returned in v0.
switch (assign_type) {
case VARIABLE:
case VARIABLE: {
VariableProxy* proxy = expr->expression()->AsVariableProxy();
if (expr->is_postfix()) {
{ EffectContext context(this);
EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
Token::ASSIGN, expr->CountSlot());
EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(),
BailoutState::TOS_REGISTER);
context.Plug(v0);
......@@ -3210,13 +3214,14 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
context()->PlugTOS();
}
} else {
EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
Token::ASSIGN, expr->CountSlot());
EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(),
BailoutState::TOS_REGISTER);
context()->Plug(v0);
}
break;
}
case NAMED_PROPERTY: {
__ mov(StoreDescriptor::ValueRegister(), result_register());
PopOperand(StoreDescriptor::ReceiverRegister());
......
......@@ -1288,7 +1288,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy,
DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode);
Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable"
: "[ Stack variable");
if (proxy->needs_hole_check()) {
if (proxy->hole_check_mode() == HoleCheckMode::kRequired) {
// Throw a reference error when using an uninitialized let/const
// binding in harmony mode.
Label done;
......@@ -1732,12 +1732,14 @@ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
// Store the value.
switch (assign_type) {
case VARIABLE:
EmitVariableAssignment(expr->target()->AsVariableProxy()->var(),
expr->op(), expr->AssignmentSlot());
case VARIABLE: {
VariableProxy* proxy = expr->target()->AsVariableProxy();
EmitVariableAssignment(proxy->var(), expr->op(), expr->AssignmentSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER);
context()->Plug(v0);
break;
}
case NAMED_PROPERTY:
EmitNamedPropertyAssignment(expr);
break;
......@@ -2025,9 +2027,10 @@ void FullCodeGenerator::EmitAssignment(Expression* expr,
switch (assign_type) {
case VARIABLE: {
Variable* var = expr->AsVariableProxy()->var();
VariableProxy* proxy = expr->AsVariableProxy();
EffectContext context(this);
EmitVariableAssignment(var, Token::ASSIGN, slot);
EmitVariableAssignment(proxy->var(), Token::ASSIGN, slot,
proxy->hole_check_mode());
break;
}
case NAMED_PROPERTY: {
......@@ -2102,9 +2105,9 @@ void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot(
}
}
void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
FeedbackVectorSlot slot) {
FeedbackVectorSlot slot,
HoleCheckMode hole_check_mode) {
if (var->IsUnallocated()) {
// Global var, const, or let.
__ mov(StoreDescriptor::ValueRegister(), result_register());
......@@ -2116,7 +2119,7 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
DCHECK(var->IsStackAllocated() || var->IsContextSlot());
MemOperand location = VarOperand(var, a1);
// Perform an initialization check for lexically declared variables.
if (var->binding_needs_init()) {
if (hole_check_mode == HoleCheckMode::kRequired) {
Label assign;
__ ld(a3, location);
__ LoadRoot(a4, Heap::kTheHoleValueRootIndex);
......@@ -3195,11 +3198,12 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
// Store the value returned in v0.
switch (assign_type) {
case VARIABLE:
case VARIABLE: {
VariableProxy* proxy = expr->expression()->AsVariableProxy();
if (expr->is_postfix()) {
{ EffectContext context(this);
EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
Token::ASSIGN, expr->CountSlot());
EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(),
BailoutState::TOS_REGISTER);
context.Plug(v0);
......@@ -3210,13 +3214,14 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
context()->PlugTOS();
}
} else {
EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
Token::ASSIGN, expr->CountSlot());
EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(),
BailoutState::TOS_REGISTER);
context()->Plug(v0);
}
break;
}
case NAMED_PROPERTY: {
__ mov(StoreDescriptor::ValueRegister(), result_register());
PopOperand(StoreDescriptor::ReceiverRegister());
......
......@@ -1239,7 +1239,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy,
DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode);
Comment cmnt(masm_, var->IsContextSlot() ? "[ Context slot"
: "[ Stack slot");
if (proxy->needs_hole_check()) {
if (proxy->hole_check_mode() == HoleCheckMode::kRequired) {
// Throw a reference error when using an uninitialized let/const
// binding in harmony mode.
DCHECK(IsLexicalVariableMode(var->mode()));
......@@ -1670,12 +1670,14 @@ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
// Store the value.
switch (assign_type) {
case VARIABLE:
EmitVariableAssignment(expr->target()->AsVariableProxy()->var(),
expr->op(), expr->AssignmentSlot());
case VARIABLE: {
VariableProxy* proxy = expr->target()->AsVariableProxy();
EmitVariableAssignment(proxy->var(), expr->op(), expr->AssignmentSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER);
context()->Plug(rax);
break;
}
case NAMED_PROPERTY:
EmitNamedPropertyAssignment(expr);
break;
......@@ -1919,9 +1921,10 @@ void FullCodeGenerator::EmitAssignment(Expression* expr,
switch (assign_type) {
case VARIABLE: {
Variable* var = expr->AsVariableProxy()->var();
VariableProxy* proxy = expr->AsVariableProxy();
EffectContext context(this);
EmitVariableAssignment(var, Token::ASSIGN, slot);
EmitVariableAssignment(proxy->var(), Token::ASSIGN, slot,
proxy->hole_check_mode());
break;
}
case NAMED_PROPERTY: {
......@@ -1994,9 +1997,9 @@ void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot(
}
}
void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
FeedbackVectorSlot slot) {
FeedbackVectorSlot slot,
HoleCheckMode hole_check_mode) {
if (var->IsUnallocated()) {
// Global var, const, or let.
__ LoadGlobalObject(StoreDescriptor::ReceiverRegister());
......@@ -2007,7 +2010,7 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op,
DCHECK(var->IsStackAllocated() || var->IsContextSlot());
MemOperand location = VarOperand(var, rcx);
// Perform an initialization check for lexically declared variables.
if (var->binding_needs_init()) {
if (hole_check_mode == HoleCheckMode::kRequired) {
Label assign;
__ movp(rdx, location);
__ CompareRoot(rdx, Heap::kTheHoleValueRootIndex);
......@@ -3073,12 +3076,13 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
// Store the value returned in rax.
switch (assign_type) {
case VARIABLE:
case VARIABLE: {
VariableProxy* proxy = expr->expression()->AsVariableProxy();
if (expr->is_postfix()) {
// Perform the assignment as if via '='.
{ EffectContext context(this);
EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
Token::ASSIGN, expr->CountSlot());
EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(),
BailoutState::TOS_REGISTER);
context.Plug(rax);
......@@ -3090,13 +3094,14 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
}
} else {
// Perform the assignment as if via '='.
EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(),
Token::ASSIGN, expr->CountSlot());
EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(),
proxy->hole_check_mode());
PrepareForBailoutForId(expr->AssignmentId(),
BailoutState::TOS_REGISTER);
context()->Plug(rax);
}
break;
}
case NAMED_PROPERTY: {
PopOperand(StoreDescriptor::ReceiverRegister());
CallStoreIC(expr->CountSlot(), prop->key()->AsLiteral()->value());
......
......@@ -1049,6 +1049,8 @@ enum VariableLocation : uint8_t {
// immediately initialized upon creation (kCreatedInitialized).
enum InitializationFlag : uint8_t { kNeedsInitialization, kCreatedInitialized };
enum class HoleCheckMode { kRequired, kElided };
enum MaybeAssignedFlag : uint8_t { kNotAssigned, kMaybeAssigned };
// Serialized in PreparseData, so numeric values should not be changed.
......
......@@ -830,7 +830,8 @@ void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) {
if (variable->IsExport() && variable->binding_needs_init()) {
builder()->LoadTheHole();
BuildVariableAssignment(variable, Token::INIT,
FeedbackVectorSlot::Invalid(), false);
FeedbackVectorSlot::Invalid(),
HoleCheckMode::kElided);
}
// Nothing to do for imports.
break;
......@@ -850,7 +851,8 @@ void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) {
case VariableLocation::LOCAL: {
VisitForAccumulatorValue(decl->fun());
BuildVariableAssignment(variable, Token::INIT,
FeedbackVectorSlot::Invalid(), false);
FeedbackVectorSlot::Invalid(),
HoleCheckMode::kElided);
break;
}
case VariableLocation::CONTEXT: {
......@@ -875,7 +877,8 @@ void BytecodeGenerator::VisitFunctionDeclaration(FunctionDeclaration* decl) {
DCHECK(variable->IsExport());
VisitForAccumulatorValue(decl->fun());
BuildVariableAssignment(variable, Token::INIT,
FeedbackVectorSlot::Invalid(), false);
FeedbackVectorSlot::Invalid(),
HoleCheckMode::kElided);
break;
}
}
......@@ -895,7 +898,7 @@ void BytecodeGenerator::VisitModuleNamespaceImports() {
Variable* var = scope()->LookupLocal(entry->local_name);
DCHECK_NOT_NULL(var);
BuildVariableAssignment(var, Token::INIT, FeedbackVectorSlot::Invalid(),
false);
HoleCheckMode::kElided);
}
}
......@@ -1150,7 +1153,7 @@ void BytecodeGenerator::VisitForInAssignment(Expression* expr,
case VARIABLE: {
VariableProxy* proxy = expr->AsVariableProxy();
BuildVariableAssignment(proxy->var(), Token::ASSIGN, slot,
proxy->needs_hole_check());
proxy->hole_check_mode());
break;
}
case NAMED_PROPERTY: {
......@@ -1401,7 +1404,8 @@ void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) {
FeedbackVectorSlot slot = expr->NeedsProxySlot()
? expr->ProxySlot()
: FeedbackVectorSlot::Invalid();
BuildVariableAssignment(proxy->var(), Token::INIT, slot, false);
BuildVariableAssignment(proxy->var(), Token::INIT, slot,
HoleCheckMode::kElided);
}
}
......@@ -1776,12 +1780,12 @@ void BytecodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) {
void BytecodeGenerator::VisitVariableProxy(VariableProxy* proxy) {
builder()->SetExpressionPosition(proxy);
BuildVariableLoad(proxy->var(), proxy->VariableFeedbackSlot(),
proxy->needs_hole_check());
proxy->hole_check_mode());
}
void BytecodeGenerator::BuildVariableLoad(Variable* variable,
FeedbackVectorSlot slot,
bool needs_hole_check,
HoleCheckMode hole_check_mode,
TypeofMode typeof_mode) {
switch (variable->location()) {
case VariableLocation::LOCAL: {
......@@ -1790,7 +1794,9 @@ void BytecodeGenerator::BuildVariableLoad(Variable* variable,
// VisitForRegisterScope, in order to avoid register aliasing if
// subsequent expressions assign to the same variable.
builder()->LoadAccumulatorWithRegister(source);
if (needs_hole_check) BuildThrowIfHole(variable->name());
if (hole_check_mode == HoleCheckMode::kRequired) {
BuildThrowIfHole(variable->name());
}
break;
}
case VariableLocation::PARAMETER: {
......@@ -1801,7 +1807,9 @@ void BytecodeGenerator::BuildVariableLoad(Variable* variable,
// VisitForRegisterScope, in order to avoid register aliasing if
// subsequent expressions assign to the same variable.
builder()->LoadAccumulatorWithRegister(source);
if (needs_hole_check) BuildThrowIfHole(variable->name());
if (hole_check_mode == HoleCheckMode::kRequired) {
BuildThrowIfHole(variable->name());
}
break;
}
case VariableLocation::UNALLOCATED: {
......@@ -1820,7 +1828,9 @@ void BytecodeGenerator::BuildVariableLoad(Variable* variable,
}
builder()->LoadContextSlot(context_reg, variable->index(), depth);
if (needs_hole_check) BuildThrowIfHole(variable->name());
if (hole_check_mode == HoleCheckMode::kRequired) {
BuildThrowIfHole(variable->name());
}
break;
}
case VariableLocation::LOOKUP: {
......@@ -1831,7 +1841,9 @@ void BytecodeGenerator::BuildVariableLoad(Variable* variable,
execution_context()->ContextChainDepth(local_variable->scope());
builder()->LoadLookupContextSlot(variable->name(), typeof_mode,
local_variable->index(), depth);
if (needs_hole_check) BuildThrowIfHole(variable->name());
if (hole_check_mode == HoleCheckMode::kRequired) {
BuildThrowIfHole(variable->name());
}
break;
}
case DYNAMIC_GLOBAL: {
......@@ -1866,17 +1878,19 @@ void BytecodeGenerator::BuildVariableLoad(Variable* variable,
.StoreAccumulatorInRegister(args[1])
.CallRuntime(Runtime::kLoadModuleImport, args);
}
if (needs_hole_check) BuildThrowIfHole(variable->name());
if (hole_check_mode == HoleCheckMode::kRequired) {
BuildThrowIfHole(variable->name());
}
break;
}
}
}
void BytecodeGenerator::BuildVariableLoadForAccumulatorValue(
Variable* variable, FeedbackVectorSlot slot, bool needs_hole_check,
Variable* variable, FeedbackVectorSlot slot, HoleCheckMode hole_check_mode,
TypeofMode typeof_mode) {
ValueResultScope accumulator_result(this);
BuildVariableLoad(variable, slot, needs_hole_check, typeof_mode);
BuildVariableLoad(variable, slot, hole_check_mode, typeof_mode);
}
void BytecodeGenerator::BuildReturn() {
......@@ -1948,7 +1962,7 @@ void BytecodeGenerator::BuildHoleCheckForVariableAssignment(Variable* variable,
void BytecodeGenerator::BuildVariableAssignment(Variable* variable,
Token::Value op,
FeedbackVectorSlot slot,
bool needs_hole_check) {
HoleCheckMode hole_check_mode) {
VariableMode mode = variable->mode();
RegisterAllocationScope assignment_register_scope(this);
BytecodeLabel end_label;
......@@ -1962,7 +1976,7 @@ void BytecodeGenerator::BuildVariableAssignment(Variable* variable,
destination = Register(variable->index());
}
if (needs_hole_check) {
if (hole_check_mode == HoleCheckMode::kRequired) {
// Load destination to check for hole.
Register value_temp = register_allocator()->NewRegister();
builder()
......@@ -1997,7 +2011,7 @@ void BytecodeGenerator::BuildVariableAssignment(Variable* variable,
context_reg = execution_context()->reg();
}
if (needs_hole_check) {
if (hole_check_mode == HoleCheckMode::kRequired) {
// Load destination to check for hole.
Register value_temp = register_allocator()->NewRegister();
builder()
......@@ -2043,7 +2057,7 @@ void BytecodeGenerator::BuildVariableAssignment(Variable* variable,
->StoreAccumulatorInRegister(args[1])
.LoadLiteral(it->second->export_name->string())
.StoreAccumulatorInRegister(args[0]);
if (needs_hole_check) {
if (hole_check_mode == HoleCheckMode::kRequired) {
builder()->CallRuntime(Runtime::kLoadModuleExport, args[0]);
BuildHoleCheckForVariableAssignment(variable, op);
}
......@@ -2112,7 +2126,7 @@ void BytecodeGenerator::VisitAssignment(Assignment* expr) {
case VARIABLE: {
VariableProxy* proxy = expr->target()->AsVariableProxy();
BuildVariableLoad(proxy->var(), proxy->VariableFeedbackSlot(),
proxy->needs_hole_check());
proxy->hole_check_mode());
builder()->StoreAccumulatorInRegister(old_value);
break;
}
......@@ -2165,7 +2179,7 @@ void BytecodeGenerator::VisitAssignment(Assignment* expr) {
// Is the value in the accumulator safe? Yes, but scary.
VariableProxy* proxy = expr->target()->AsVariableProxy();
BuildVariableAssignment(proxy->var(), expr->op(), slot,
proxy->needs_hole_check());
proxy->hole_check_mode());
break;
}
case NAMED_PROPERTY:
......@@ -2393,7 +2407,7 @@ void BytecodeGenerator::VisitCall(Call* expr) {
VariableProxy* proxy = callee_expr->AsVariableProxy();
BuildVariableLoadForAccumulatorValue(proxy->var(),
proxy->VariableFeedbackSlot(),
proxy->needs_hole_check());
proxy->hole_check_mode());
builder()->StoreAccumulatorInRegister(callee);
break;
}
......@@ -2551,7 +2565,7 @@ void BytecodeGenerator::VisitTypeOf(UnaryOperation* expr) {
// perform a non-contextual load in case the operand is a variable proxy.
VariableProxy* proxy = expr->expression()->AsVariableProxy();
BuildVariableLoadForAccumulatorValue(
proxy->var(), proxy->VariableFeedbackSlot(), proxy->needs_hole_check(),
proxy->var(), proxy->VariableFeedbackSlot(), proxy->hole_check_mode(),
INSIDE_TYPEOF);
} else {
VisitForAccumulatorValue(expr->expression());
......@@ -2678,7 +2692,7 @@ void BytecodeGenerator::VisitCountOperation(CountOperation* expr) {
VariableProxy* proxy = expr->expression()->AsVariableProxy();
BuildVariableLoadForAccumulatorValue(proxy->var(),
proxy->VariableFeedbackSlot(),
proxy->needs_hole_check());
proxy->hole_check_mode());
break;
}
case NAMED_PROPERTY: {
......@@ -2743,7 +2757,7 @@ void BytecodeGenerator::VisitCountOperation(CountOperation* expr) {
case VARIABLE: {
VariableProxy* proxy = expr->expression()->AsVariableProxy();
BuildVariableAssignment(proxy->var(), expr->op(), feedback_slot,
proxy->needs_hole_check());
proxy->hole_check_mode());
break;
}
case NAMED_PROPERTY: {
......@@ -3036,7 +3050,8 @@ void BytecodeGenerator::VisitArgumentsObject(Variable* variable) {
: CreateArgumentsType::kMappedArguments;
builder()->CreateArguments(type);
BuildVariableAssignment(variable, Token::ASSIGN,
FeedbackVectorSlot::Invalid(), false);
FeedbackVectorSlot::Invalid(),
HoleCheckMode::kElided);
}
void BytecodeGenerator::VisitRestArgumentsArray(Variable* rest) {
......@@ -3047,7 +3062,7 @@ void BytecodeGenerator::VisitRestArgumentsArray(Variable* rest) {
builder()->CreateArguments(CreateArgumentsType::kRestParameter);
DCHECK(rest->IsContextSlot() || rest->IsStackAllocated());
BuildVariableAssignment(rest, Token::ASSIGN, FeedbackVectorSlot::Invalid(),
false);
HoleCheckMode::kElided);
}
void BytecodeGenerator::VisitThisFunctionVariable(Variable* variable) {
......@@ -3056,7 +3071,7 @@ void BytecodeGenerator::VisitThisFunctionVariable(Variable* variable) {
// Store the closure we were called with in the given variable.
builder()->LoadAccumulatorWithRegister(Register::function_closure());
BuildVariableAssignment(variable, Token::INIT, FeedbackVectorSlot::Invalid(),
false);
HoleCheckMode::kElided);
}
void BytecodeGenerator::VisitNewTargetVariable(Variable* variable) {
......@@ -3065,7 +3080,7 @@ void BytecodeGenerator::VisitNewTargetVariable(Variable* variable) {
// Store the new target we were called with in the given variable.
builder()->LoadAccumulatorWithRegister(Register::new_target());
BuildVariableAssignment(variable, Token::INIT, FeedbackVectorSlot::Invalid(),
false);
HoleCheckMode::kElided);
// TODO(mstarzinger): The <new.target> register is not set by the deoptimizer
// and we need to make sure {BytecodeRegisterOptimizer} flushes its state
......
......@@ -95,13 +95,15 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
void VisitPropertyLoadForAccumulator(Register obj, Property* expr);
void BuildVariableLoad(Variable* variable, FeedbackVectorSlot slot,
bool needs_hole_check,
HoleCheckMode hole_check_mode,
TypeofMode typeof_mode = NOT_INSIDE_TYPEOF);
void BuildVariableLoadForAccumulatorValue(
Variable* variable, FeedbackVectorSlot slot, bool needs_hole_check,
Variable* variable, FeedbackVectorSlot slot,
HoleCheckMode hole_check_mode,
TypeofMode typeof_mode = NOT_INSIDE_TYPEOF);
void BuildVariableAssignment(Variable* variable, Token::Value op,
FeedbackVectorSlot slot, bool needs_hole_check);
FeedbackVectorSlot slot,
HoleCheckMode hole_check_mode);
void BuildReturn();
void BuildReThrow();
......
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