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

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

Issue 1588903002: [Interpreter] Fixes VisitObjectLiteral to reserve consecutive registers in innerscope. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased the patch. Created 4 years, 11 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 | « no previous file | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | test/mjsunit/mjsunit.status » ('J')
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 959e15514976132c32a0292e367ba17ea3b23d5e..6603feb8cfe580b139f494153eb63a103d670b2c 100644
--- a/src/interpreter/bytecode-generator.cc
+++ b/src/interpreter/bytecode-generator.cc
@@ -964,10 +964,12 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
builder()->CreateObjectLiteral(expr->constant_properties(),
expr->literal_index(),
expr->ComputeFlags(true));
- Register literal;
+
+ // Allocate in the outer scope since this register is returned.
rmcilroy 2016/01/15 17:15:09 /s/since.../since this register is used to return
mythria 2016/01/18 11:34:05 Thanks, Done.
+ Register literal = register_allocator()->outer()->NewRegister();
+ builder()->StoreAccumulatorInRegister(literal);
// Store computed values into the literal.
- bool literal_in_accumulator = true;
int property_index = 0;
AccessorTable accessor_table(zone());
for (; property_index < expr->properties()->length(); property_index++) {
@@ -975,12 +977,6 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
if (property->is_computed_name()) break;
if (property->IsCompileTimeValue()) continue;
- if (literal_in_accumulator) {
- literal = register_allocator()->NewRegister();
- builder()->StoreAccumulatorInRegister(literal);
- literal_in_accumulator = false;
- }
-
RegisterAllocationScope inner_register_scope(this);
Literal* literal_key = property->key()->AsLiteral();
switch (property->kind()) {
@@ -1002,14 +998,16 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
VisitForEffect(property->value());
}
} else {
- register_allocator()->PrepareForConsecutiveAllocations(3);
+ register_allocator()->PrepareForConsecutiveAllocations(4);
+ Register literal_argument =
+ register_allocator()->NextConsecutiveRegister();
Register key = register_allocator()->NextConsecutiveRegister();
Register value = register_allocator()->NextConsecutiveRegister();
Register language = register_allocator()->NextConsecutiveRegister();
- // TODO(oth): This is problematic - can't assume contiguous here.
- // literal is allocated in outer register scope, whereas key, value,
- // language are in another.
- DCHECK(Register::AreContiguous(literal, key, value, language));
+ DCHECK(
+ Register::AreContiguous(literal_argument, key, value, language));
rmcilroy 2016/01/15 17:15:09 This DCHECK's probably not necessary anymore.
mythria 2016/01/18 11:34:05 Done.
+
+ builder()->MoveRegister(literal, literal_argument);
VisitForAccumulatorValue(property->key());
builder()->StoreAccumulatorInRegister(key);
VisitForAccumulatorValue(property->value());
@@ -1018,20 +1016,24 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
builder()
->LoadLiteral(Smi::FromInt(SLOPPY))
.StoreAccumulatorInRegister(language)
- .CallRuntime(Runtime::kSetProperty, literal, 4);
+ .CallRuntime(Runtime::kSetProperty, literal_argument, 4);
VisitSetHomeObject(value, literal, property);
}
}
break;
}
case ObjectLiteral::Property::PROTOTYPE: {
- register_allocator()->PrepareForConsecutiveAllocations(1);
DCHECK(property->emit_store());
+ register_allocator()->PrepareForConsecutiveAllocations(2);
+ Register literal_argument =
+ register_allocator()->NextConsecutiveRegister();
Register value = register_allocator()->NextConsecutiveRegister();
- DCHECK(Register::AreContiguous(literal, value));
+ DCHECK(Register::AreContiguous(literal_argument, value));
rmcilroy 2016/01/15 17:15:09 ditto
mythria 2016/01/18 11:34:05 Done.
+
+ builder()->MoveRegister(literal, literal_argument);
VisitForAccumulatorValue(property->value());
builder()->StoreAccumulatorInRegister(value).CallRuntime(
- Runtime::kInternalSetPrototype, literal, 2);
+ Runtime::kInternalSetPrototype, literal_argument, 2);
break;
}
case ObjectLiteral::Property::GETTER:
@@ -1052,12 +1054,16 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
for (AccessorTable::Iterator it = accessor_table.begin();
it != accessor_table.end(); ++it) {
RegisterAllocationScope inner_register_scope(this);
- register_allocator()->PrepareForConsecutiveAllocations(4);
+ register_allocator()->PrepareForConsecutiveAllocations(5);
+ Register literal_argument = register_allocator()->NextConsecutiveRegister();
Register name = register_allocator()->NextConsecutiveRegister();
Register getter = register_allocator()->NextConsecutiveRegister();
Register setter = register_allocator()->NextConsecutiveRegister();
Register attr = register_allocator()->NextConsecutiveRegister();
- DCHECK(Register::AreContiguous(literal, name, getter, setter, attr));
+ DCHECK(
+ Register::AreContiguous(literal_argument, name, getter, setter, attr));
rmcilroy 2016/01/15 17:15:09 ditto
mythria 2016/01/18 11:34:05 Done.
+
+ builder()->MoveRegister(literal, literal_argument);
VisitForAccumulatorValue(it->first);
builder()->StoreAccumulatorInRegister(name);
VisitObjectLiteralAccessor(literal, it->second->getter, getter);
@@ -1065,7 +1071,8 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
builder()
->LoadLiteral(Smi::FromInt(NONE))
.StoreAccumulatorInRegister(attr)
- .CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, literal, 5);
+ .CallRuntime(Runtime::kDefineAccessorPropertyUnchecked,
+ literal_argument, 5);
}
// Object literals have two parts. The "static" part on the left contains no
@@ -1078,30 +1085,32 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
// compile them into a series of "SetOwnProperty" runtime calls. This will
// preserve insertion order.
for (; property_index < expr->properties()->length(); property_index++) {
- if (literal_in_accumulator) {
- literal = register_allocator()->NewRegister();
- builder()->StoreAccumulatorInRegister(literal);
- literal_in_accumulator = false;
- }
-
ObjectLiteral::Property* property = expr->properties()->at(property_index);
RegisterAllocationScope inner_register_scope(this);
+
if (property->kind() == ObjectLiteral::Property::PROTOTYPE) {
DCHECK(property->emit_store());
- Register value = register_allocator()->NewRegister();
- DCHECK(Register::AreContiguous(literal, value));
+ register_allocator()->PrepareForConsecutiveAllocations(2);
+ Register literal_argument =
+ register_allocator()->NextConsecutiveRegister();
+ Register value = register_allocator()->NextConsecutiveRegister();
+ DCHECK(Register::AreContiguous(literal_argument, value));
rmcilroy 2016/01/15 17:15:09 ditto
mythria 2016/01/18 11:34:05 Done.
+
+ builder()->MoveRegister(literal, literal_argument);
VisitForAccumulatorValue(property->value());
builder()->StoreAccumulatorInRegister(value).CallRuntime(
- Runtime::kInternalSetPrototype, literal, 2);
+ Runtime::kInternalSetPrototype, literal_argument, 2);
continue;
}
- register_allocator()->PrepareForConsecutiveAllocations(3);
+ register_allocator()->PrepareForConsecutiveAllocations(4);
+ Register literal_argument = register_allocator()->NextConsecutiveRegister();
Register key = register_allocator()->NextConsecutiveRegister();
Register value = register_allocator()->NextConsecutiveRegister();
Register attr = register_allocator()->NextConsecutiveRegister();
- DCHECK(Register::AreContiguous(literal, key, value, attr));
+ DCHECK(Register::AreContiguous(literal_argument, key, value, attr));
+ builder()->MoveRegister(literal, literal_argument);
VisitForAccumulatorValue(property->key());
builder()->CastAccumulatorToName().StoreAccumulatorInRegister(key);
VisitForAccumulatorValue(property->value());
@@ -1125,20 +1134,15 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
function_id = Runtime::kDefineSetterPropertyUnchecked;
break;
}
- builder()->CallRuntime(function_id, literal, 4);
+ builder()->CallRuntime(function_id, literal_argument, 4);
}
// Transform literals that contain functions to fast properties.
if (expr->has_function()) {
- DCHECK(!literal_in_accumulator);
builder()->CallRuntime(Runtime::kToFastProperties, literal, 1);
}
- if (!literal_in_accumulator) {
- // Restore literal array into accumulator.
- builder()->LoadAccumulatorWithRegister(literal);
- }
- execution_result()->SetResultInAccumulator();
+ execution_result()->SetResultInRegister(literal);
}
« no previous file with comments | « no previous file | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | test/mjsunit/mjsunit.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698