Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: src/interpreter/bytecode-generator.cc

Issue 1721723002: [interpreter] Clean super property handling. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/interpreter/bytecode-generator.h ('k') | src/interpreter/bytecode-register-allocator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecode-generator.cc
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc
index 57efc54011356a4fbc2b03beb16b46c176bd1ebd..c0ae3e619e1fe8fd2310a8c20c1e4cc34ffa9813 100644
--- a/src/interpreter/bytecode-generator.cc
+++ b/src/interpreter/bytecode-generator.cc
@@ -417,11 +417,6 @@ class BytecodeGenerator::RegisterAllocationScope {
return allocator_.NextConsecutiveRegister();
}
- template <size_t N>
- void PrepareAndInitializeConsecutiveAllocations(Register (&registers)[N]) {
- return allocator_.PrepareAndInitializeConsecutiveAllocations(registers, N);
- }
-
bool RegisterIsAllocatedInThisScope(Register reg) const {
return allocator_.RegisterIsAllocatedInThisScope(reg);
}
@@ -547,26 +542,6 @@ class BytecodeGenerator::RegisterResultScope final
Register result_register_;
};
-// Class for holding arguments for runtime calls relating to super
-// properties.
-class BytecodeGenerator::SuperPropertyArguments final {
- public:
- SuperPropertyArguments() {}
-
- Register (&registers())[4] { return args_; }
- Register receiver() const { return args_[0]; }
- Register home_object() const { return args_[1]; }
- Register name_or_key() const { return args_[2]; }
- Register store_value() const { return args_[3]; }
- Register language_mode() const { return args_[3]; }
- size_t count() const { return arraysize(args_); }
-
- private:
- Register args_[4];
-
- DISALLOW_COPY_AND_ASSIGN(SuperPropertyArguments);
-};
-
BytecodeGenerator::BytecodeGenerator(Isolate* isolate, Zone* zone)
: isolate_(isolate),
zone_(zone),
@@ -1074,26 +1049,36 @@ void BytecodeGenerator::VisitForInAssignment(Expression* expr,
}
case NAMED_SUPER_PROPERTY: {
RegisterAllocationScope register_scope(this);
- SuperPropertyArguments super_args;
- Register value = register_allocator()->NewRegister();
+ register_allocator()->PrepareForConsecutiveAllocations(4);
+ Register receiver = register_allocator()->NextConsecutiveRegister();
+ Register home_object = register_allocator()->NextConsecutiveRegister();
+ Register name = register_allocator()->NextConsecutiveRegister();
+ Register value = register_allocator()->NextConsecutiveRegister();
builder()->StoreAccumulatorInRegister(value);
- PrepareNamedSuperPropertyArguments(
- property->obj()->AsSuperPropertyReference(),
- property->key()->AsLiteral()->AsPropertyName(), &super_args);
- builder()->LoadAccumulatorWithRegister(value);
- BuildNamedSuperPropertyStore(&super_args);
+ SuperPropertyReference* super_property =
+ property->obj()->AsSuperPropertyReference();
+ VisitForRegisterValue(super_property->this_var(), receiver);
+ VisitForRegisterValue(super_property->home_object(), home_object);
+ builder()
+ ->LoadLiteral(property->key()->AsLiteral()->AsPropertyName())
+ .StoreAccumulatorInRegister(name);
+ BuildNamedSuperPropertyStore(receiver);
rmcilroy 2016/02/22 20:45:10 Could you pass the other registers as arguments to
break;
}
case KEYED_SUPER_PROPERTY: {
RegisterAllocationScope register_scope(this);
- SuperPropertyArguments super_args;
- Register value = register_allocator()->NewRegister();
+ register_allocator()->PrepareForConsecutiveAllocations(4);
+ Register receiver = register_allocator()->NextConsecutiveRegister();
+ Register home_object = register_allocator()->NextConsecutiveRegister();
+ Register key = register_allocator()->NextConsecutiveRegister();
+ Register value = register_allocator()->NextConsecutiveRegister();
builder()->StoreAccumulatorInRegister(value);
- PrepareKeyedSuperPropertyArguments(
- property->obj()->AsSuperPropertyReference(), property->key(),
- &super_args);
- builder()->LoadAccumulatorWithRegister(value);
- BuildKeyedSuperPropertyStore(&super_args);
+ SuperPropertyReference* super_property =
+ property->obj()->AsSuperPropertyReference();
+ VisitForRegisterValue(super_property->this_var(), receiver);
+ VisitForRegisterValue(super_property->home_object(), home_object);
+ VisitForRegisterValue(property->key(), key);
+ BuildKeyedSuperPropertyStore(receiver);
rmcilroy 2016/02/22 20:45:10 Ditto (and for the others).
break;
}
}
@@ -1834,65 +1819,26 @@ Register BytecodeGenerator::VisitVariableLoadForRegisterValue(
return register_scope.ResultRegister();
}
-void BytecodeGenerator::PrepareNamedSuperPropertyArguments(
- SuperPropertyReference* super_property, Handle<Name> name,
- SuperPropertyArguments* super_args) {
- register_allocator()->PrepareAndInitializeConsecutiveAllocations(
- super_args->registers());
-
- VisitForAccumulatorValue(super_property->this_var());
- builder()->StoreAccumulatorInRegister(super_args->receiver());
- VisitForAccumulatorValue(super_property->home_object());
- builder()->StoreAccumulatorInRegister(super_args->home_object());
- builder()->LoadLiteral(name).StoreAccumulatorInRegister(
- super_args->name_or_key());
+void BytecodeGenerator::BuildNamedSuperPropertyLoad(Register receiver) {
+ builder()->CallRuntime(Runtime::kLoadFromSuper, receiver, 3);
}
-void BytecodeGenerator::PrepareKeyedSuperPropertyArguments(
- SuperPropertyReference* super_property, Expression* key,
- SuperPropertyArguments* super_args) {
- register_allocator()->PrepareAndInitializeConsecutiveAllocations(
- super_args->registers());
-
- VisitForAccumulatorValue(super_property->this_var());
- builder()->StoreAccumulatorInRegister(super_args->receiver());
- VisitForAccumulatorValue(super_property->home_object());
- builder()->StoreAccumulatorInRegister(super_args->home_object());
- VisitForAccumulatorValue(key);
- builder()->StoreAccumulatorInRegister(super_args->name_or_key());
+void BytecodeGenerator::BuildKeyedSuperPropertyLoad(Register receiver) {
+ builder()->CallRuntime(Runtime::kLoadKeyedFromSuper, receiver, 3);
}
-void BytecodeGenerator::BuildNamedSuperPropertyLoad(
- SuperPropertyArguments* super_args) {
- // TODO(oth): Abstraction not suitable for 3 args, will over-allocate regs.
- builder()->CallRuntime(Runtime::kLoadFromSuper, super_args->receiver(), 3);
-}
-
-void BytecodeGenerator::BuildKeyedSuperPropertyLoad(
- SuperPropertyArguments* super_args) {
- // TODO(oth): Abstraction not suitable for 3 args, will over-allocate regs.
- builder()->CallRuntime(Runtime::kLoadKeyedFromSuper, super_args->receiver(),
- 3);
-}
-
-void BytecodeGenerator::BuildNamedSuperPropertyStore(
- SuperPropertyArguments* super_args) {
- builder()->StoreAccumulatorInRegister(super_args->store_value());
+void BytecodeGenerator::BuildNamedSuperPropertyStore(Register receiver) {
Runtime::FunctionId function_id = is_strict(language_mode())
? Runtime::kStoreToSuper_Strict
: Runtime::kStoreToSuper_Sloppy;
- builder()->CallRuntime(function_id, super_args->receiver(),
- super_args->count());
+ builder()->CallRuntime(function_id, receiver, 4);
}
-void BytecodeGenerator::BuildKeyedSuperPropertyStore(
- SuperPropertyArguments* super_args) {
- builder()->StoreAccumulatorInRegister(super_args->store_value());
+void BytecodeGenerator::BuildKeyedSuperPropertyStore(Register receiver) {
Runtime::FunctionId function_id = is_strict(language_mode())
? Runtime::kStoreKeyedToSuper_Strict
: Runtime::kStoreKeyedToSuper_Sloppy;
- builder()->CallRuntime(function_id, super_args->receiver(),
- super_args->count());
+ builder()->CallRuntime(function_id, receiver, 4);
}
void BytecodeGenerator::BuildThrowReferenceError(Handle<String> name) {
@@ -2103,8 +2049,7 @@ void BytecodeGenerator::VisitVariableAssignment(Variable* variable,
void BytecodeGenerator::VisitAssignment(Assignment* expr) {
DCHECK(expr->target()->IsValidReferenceExpressionOrThis());
- Register object, key;
- SuperPropertyArguments super_args;
+ Register object, key, home_object, value;
Handle<String> name;
// Left-hand side can only be a property, a global or a variable slot.
@@ -2135,15 +2080,32 @@ void BytecodeGenerator::VisitAssignment(Assignment* expr) {
break;
}
case NAMED_SUPER_PROPERTY: {
- PrepareNamedSuperPropertyArguments(
- property->obj()->AsSuperPropertyReference(),
- property->key()->AsLiteral()->AsPropertyName(), &super_args);
+ register_allocator()->PrepareForConsecutiveAllocations(4);
+ object = register_allocator()->NextConsecutiveRegister();
+ home_object = register_allocator()->NextConsecutiveRegister();
+ key = register_allocator()->NextConsecutiveRegister();
+ value = register_allocator()->NextConsecutiveRegister();
+ SuperPropertyReference* super_property =
+ property->obj()->AsSuperPropertyReference();
+ VisitForRegisterValue(super_property->this_var(), object);
+ VisitForRegisterValue(super_property->home_object(), home_object);
+ builder()
+ ->LoadLiteral(property->key()->AsLiteral()->AsPropertyName())
+ .StoreAccumulatorInRegister(key);
break;
}
case KEYED_SUPER_PROPERTY: {
- PrepareKeyedSuperPropertyArguments(
- property->obj()->AsSuperPropertyReference(), property->key(),
- &super_args);
+ register_allocator()->PrepareForConsecutiveAllocations(4);
+ object = register_allocator()->NextConsecutiveRegister();
+ home_object = register_allocator()->NextConsecutiveRegister();
+ key = register_allocator()->NextConsecutiveRegister();
+ value = register_allocator()->NextConsecutiveRegister();
+ builder()->StoreAccumulatorInRegister(value);
+ SuperPropertyReference* super_property =
+ property->obj()->AsSuperPropertyReference();
+ VisitForRegisterValue(super_property->this_var(), object);
+ VisitForRegisterValue(super_property->home_object(), home_object);
+ VisitForRegisterValue(property->key(), key);
break;
}
}
@@ -2179,13 +2141,13 @@ void BytecodeGenerator::VisitAssignment(Assignment* expr) {
}
case NAMED_SUPER_PROPERTY: {
old_value = register_allocator()->NewRegister();
- BuildNamedSuperPropertyLoad(&super_args);
+ BuildNamedSuperPropertyLoad(object);
builder()->StoreAccumulatorInRegister(old_value);
break;
}
case KEYED_SUPER_PROPERTY: {
old_value = register_allocator()->NewRegister();
- BuildKeyedSuperPropertyLoad(&super_args);
+ BuildKeyedSuperPropertyLoad(object);
builder()->StoreAccumulatorInRegister(old_value);
break;
}
@@ -2215,11 +2177,13 @@ void BytecodeGenerator::VisitAssignment(Assignment* expr) {
language_mode());
break;
case NAMED_SUPER_PROPERTY: {
- BuildNamedSuperPropertyStore(&super_args);
+ builder()->StoreAccumulatorInRegister(value);
+ BuildNamedSuperPropertyStore(object);
break;
}
case KEYED_SUPER_PROPERTY: {
- BuildKeyedSuperPropertyStore(&super_args);
+ builder()->StoreAccumulatorInRegister(value);
+ BuildKeyedSuperPropertyStore(object);
break;
}
}
@@ -2277,27 +2241,43 @@ void BytecodeGenerator::VisitPropertyLoadForAccumulator(Register obj,
void BytecodeGenerator::VisitNamedSuperPropertyLoad(Property* property,
Register opt_receiver_out) {
RegisterAllocationScope register_scope(this);
- SuperPropertyArguments super_args;
- PrepareNamedSuperPropertyArguments(
- property->obj()->AsSuperPropertyReference(),
- property->key()->AsLiteral()->AsPropertyName(), &super_args);
+ register_allocator()->PrepareForConsecutiveAllocations(3);
+
+ Register receiver, home_object, name;
+ receiver = register_allocator()->NextConsecutiveRegister();
+ home_object = register_allocator()->NextConsecutiveRegister();
+ name = register_allocator()->NextConsecutiveRegister();
+ SuperPropertyReference* super_property =
+ property->obj()->AsSuperPropertyReference();
+ VisitForRegisterValue(super_property->this_var(), receiver);
+ VisitForRegisterValue(super_property->home_object(), home_object);
+ builder()
+ ->LoadLiteral(property->key()->AsLiteral()->AsPropertyName())
+ .StoreAccumulatorInRegister(name);
+ BuildNamedSuperPropertyLoad(receiver);
if (opt_receiver_out.is_valid()) {
- builder()->MoveRegister(super_args.receiver(), opt_receiver_out);
+ builder()->MoveRegister(receiver, opt_receiver_out);
}
- BuildNamedSuperPropertyLoad(&super_args);
}
void BytecodeGenerator::VisitKeyedSuperPropertyLoad(Property* property,
Register opt_receiver_out) {
RegisterAllocationScope register_scope(this);
- SuperPropertyArguments super_args;
- PrepareKeyedSuperPropertyArguments(
- property->obj()->AsSuperPropertyReference(), property->key(),
- &super_args);
+ Register receiver, home_object, key;
+ register_allocator()->PrepareForConsecutiveAllocations(3);
+ receiver = register_allocator()->NextConsecutiveRegister();
+ home_object = register_allocator()->NextConsecutiveRegister();
+ key = register_allocator()->NextConsecutiveRegister();
+ SuperPropertyReference* super_property =
+ property->obj()->AsSuperPropertyReference();
+ VisitForRegisterValue(super_property->this_var(), receiver);
+ VisitForRegisterValue(super_property->home_object(), home_object);
+ VisitForRegisterValue(property->key(), key);
+ BuildKeyedSuperPropertyLoad(receiver);
+
if (opt_receiver_out.is_valid()) {
- builder()->MoveRegister(super_args.receiver(), opt_receiver_out);
+ builder()->MoveRegister(receiver, opt_receiver_out);
}
- BuildKeyedSuperPropertyLoad(&super_args);
}
void BytecodeGenerator::VisitProperty(Property* expr) {
@@ -2661,8 +2641,7 @@ void BytecodeGenerator::VisitCountOperation(CountOperation* expr) {
bool is_postfix = expr->is_postfix();
// Evaluate LHS expression and get old value.
- Register object, key, old_value;
- SuperPropertyArguments super_args;
+ Register object, home_object, key, old_value, value;
Handle<String> name;
switch (assign_type) {
case VARIABLE: {
@@ -2690,17 +2669,34 @@ void BytecodeGenerator::VisitCountOperation(CountOperation* expr) {
break;
}
case NAMED_SUPER_PROPERTY: {
- PrepareNamedSuperPropertyArguments(
- property->obj()->AsSuperPropertyReference(),
- property->key()->AsLiteral()->AsPropertyName(), &super_args);
- BuildNamedSuperPropertyLoad(&super_args);
+ register_allocator()->PrepareForConsecutiveAllocations(4);
+ object = register_allocator()->NextConsecutiveRegister();
+ home_object = register_allocator()->NextConsecutiveRegister();
+ key = register_allocator()->NextConsecutiveRegister();
+ value = register_allocator()->NextConsecutiveRegister();
+ SuperPropertyReference* super_property =
+ property->obj()->AsSuperPropertyReference();
+ VisitForRegisterValue(super_property->this_var(), object);
+ VisitForRegisterValue(super_property->home_object(), home_object);
+ builder()
+ ->LoadLiteral(property->key()->AsLiteral()->AsPropertyName())
+ .StoreAccumulatorInRegister(key);
+ BuildNamedSuperPropertyLoad(object);
break;
}
case KEYED_SUPER_PROPERTY: {
- PrepareKeyedSuperPropertyArguments(
- property->obj()->AsSuperPropertyReference(), property->key(),
- &super_args);
- BuildKeyedSuperPropertyLoad(&super_args);
+ register_allocator()->PrepareForConsecutiveAllocations(4);
+ object = register_allocator()->NextConsecutiveRegister();
+ home_object = register_allocator()->NextConsecutiveRegister();
+ key = register_allocator()->NextConsecutiveRegister();
+ value = register_allocator()->NextConsecutiveRegister();
+ builder()->StoreAccumulatorInRegister(value);
+ SuperPropertyReference* super_property =
+ property->obj()->AsSuperPropertyReference();
+ VisitForRegisterValue(super_property->this_var(), object);
+ VisitForRegisterValue(super_property->home_object(), home_object);
+ VisitForRegisterValue(property->key(), key);
+ BuildKeyedSuperPropertyLoad(object);
break;
}
}
@@ -2738,11 +2734,13 @@ void BytecodeGenerator::VisitCountOperation(CountOperation* expr) {
break;
}
case NAMED_SUPER_PROPERTY: {
- BuildNamedSuperPropertyStore(&super_args);
+ builder()->StoreAccumulatorInRegister(value);
+ BuildNamedSuperPropertyStore(object);
break;
}
case KEYED_SUPER_PROPERTY: {
- BuildKeyedSuperPropertyStore(&super_args);
+ builder()->StoreAccumulatorInRegister(value);
+ BuildKeyedSuperPropertyStore(object);
break;
}
}
@@ -3098,6 +3096,14 @@ Register BytecodeGenerator::VisitForRegisterValue(Expression* expr) {
return register_scope.ResultRegister();
}
+// Visits the expression |expr| and stores the expression result in
+// |destination|.
+void BytecodeGenerator::VisitForRegisterValue(Expression* expr,
+ Register destination) {
+ AccumulatorResultScope register_scope(this);
+ Visit(expr);
+ builder()->StoreAccumulatorInRegister(destination);
+}
void BytecodeGenerator::VisitInScope(Statement* stmt, Scope* scope) {
ContextScope context_scope(this, scope);
« no previous file with comments | « src/interpreter/bytecode-generator.h ('k') | src/interpreter/bytecode-register-allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698