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

Side by Side Diff: src/interpreter/bytecode-generator.cc

Issue 1546643002: [Interpreter] Updates load/store global and named property to accept variable name. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 12 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/interpreter/bytecode-generator.h" 5 #include "src/interpreter/bytecode-generator.h"
6 6
7 #include "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/compiler.h" 8 #include "src/compiler.h"
9 #include "src/interpreter/control-flow-builders.h" 9 #include "src/interpreter/control-flow-builders.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 case VARIABLE: { 837 case VARIABLE: {
838 Variable* variable = expr->AsVariableProxy()->var(); 838 Variable* variable = expr->AsVariableProxy()->var();
839 VisitVariableAssignment(variable, slot); 839 VisitVariableAssignment(variable, slot);
840 break; 840 break;
841 } 841 }
842 case NAMED_PROPERTY: { 842 case NAMED_PROPERTY: {
843 TemporaryRegisterScope temporary_register_scope(builder()); 843 TemporaryRegisterScope temporary_register_scope(builder());
844 Register value = temporary_register_scope.NewRegister(); 844 Register value = temporary_register_scope.NewRegister();
845 builder()->StoreAccumulatorInRegister(value); 845 builder()->StoreAccumulatorInRegister(value);
846 Register object = VisitForRegisterValue(property->obj()); 846 Register object = VisitForRegisterValue(property->obj());
847 size_t name_index = builder()->GetConstantPoolEntry( 847 Handle<String> name = property->key()->AsLiteral()->AsPropertyName();
848 property->key()->AsLiteral()->AsPropertyName()); 848 builder()->StoreNamedProperty(object, name, feedback_index(slot),
849 builder()->StoreNamedProperty(object, name_index, feedback_index(slot),
850 language_mode()); 849 language_mode());
851 break; 850 break;
852 } 851 }
853 case KEYED_PROPERTY: { 852 case KEYED_PROPERTY: {
854 TemporaryRegisterScope temporary_register_scope(builder()); 853 TemporaryRegisterScope temporary_register_scope(builder());
855 Register value = temporary_register_scope.NewRegister(); 854 Register value = temporary_register_scope.NewRegister();
856 builder()->StoreAccumulatorInRegister(value); 855 builder()->StoreAccumulatorInRegister(value);
857 Register object = VisitForRegisterValue(property->obj()); 856 Register object = VisitForRegisterValue(property->obj());
858 Register key = VisitForRegisterValue(property->key()); 857 Register key = VisitForRegisterValue(property->key());
859 builder()->LoadAccumulatorWithRegister(value); 858 builder()->LoadAccumulatorWithRegister(value);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 case ObjectLiteral::Property::CONSTANT: 1056 case ObjectLiteral::Property::CONSTANT:
1058 UNREACHABLE(); 1057 UNREACHABLE();
1059 case ObjectLiteral::Property::MATERIALIZED_LITERAL: 1058 case ObjectLiteral::Property::MATERIALIZED_LITERAL:
1060 DCHECK(!CompileTimeValue::IsCompileTimeValue(property->value())); 1059 DCHECK(!CompileTimeValue::IsCompileTimeValue(property->value()));
1061 // Fall through. 1060 // Fall through.
1062 case ObjectLiteral::Property::COMPUTED: { 1061 case ObjectLiteral::Property::COMPUTED: {
1063 // It is safe to use [[Put]] here because the boilerplate already 1062 // It is safe to use [[Put]] here because the boilerplate already
1064 // contains computed properties with an uninitialized value. 1063 // contains computed properties with an uninitialized value.
1065 if (literal_key->value()->IsInternalizedString()) { 1064 if (literal_key->value()->IsInternalizedString()) {
1066 if (property->emit_store()) { 1065 if (property->emit_store()) {
1067 size_t name_index =
1068 builder()->GetConstantPoolEntry(literal_key->AsPropertyName());
1069 VisitForAccumulatorValue(property->value()); 1066 VisitForAccumulatorValue(property->value());
1070 builder()->StoreNamedProperty(literal, name_index, 1067 builder()->StoreNamedProperty(
1071 feedback_index(property->GetSlot(0)), 1068 literal, literal_key->AsPropertyName(),
1072 language_mode()); 1069 feedback_index(property->GetSlot(0)), language_mode());
1073 } else { 1070 } else {
1074 VisitForEffect(property->value()); 1071 VisitForEffect(property->value());
1075 } 1072 }
1076 } else { 1073 } else {
1077 inner_temporary_register_scope.PrepareForConsecutiveAllocations(3); 1074 inner_temporary_register_scope.PrepareForConsecutiveAllocations(3);
1078 Register key = 1075 Register key =
1079 inner_temporary_register_scope.NextConsecutiveRegister(); 1076 inner_temporary_register_scope.NextConsecutiveRegister();
1080 Register value = 1077 Register value =
1081 inner_temporary_register_scope.NextConsecutiveRegister(); 1078 inner_temporary_register_scope.NextConsecutiveRegister();
1082 Register language = 1079 Register language =
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 case VariableLocation::PARAMETER: { 1281 case VariableLocation::PARAMETER: {
1285 // The parameter indices are shifted by 1 (receiver is variable 1282 // The parameter indices are shifted by 1 (receiver is variable
1286 // index -1 but is parameter index 0 in BytecodeArrayBuilder). 1283 // index -1 but is parameter index 0 in BytecodeArrayBuilder).
1287 Register source = builder()->Parameter(variable->index() + 1); 1284 Register source = builder()->Parameter(variable->index() + 1);
1288 source = assignment_hazard_helper()->GetRegisterForLoad(source); 1285 source = assignment_hazard_helper()->GetRegisterForLoad(source);
1289 execution_result()->SetResultInRegister(source); 1286 execution_result()->SetResultInRegister(source);
1290 break; 1287 break;
1291 } 1288 }
1292 case VariableLocation::GLOBAL: 1289 case VariableLocation::GLOBAL:
1293 case VariableLocation::UNALLOCATED: { 1290 case VariableLocation::UNALLOCATED: {
1294 size_t name_index = builder()->GetConstantPoolEntry(variable->name()); 1291 builder()->LoadGlobal(variable->name(), feedback_index(slot),
1295 builder()->LoadGlobal(name_index, feedback_index(slot), language_mode(), 1292 language_mode(), typeof_mode);
1296 typeof_mode);
1297 execution_result()->SetResultInAccumulator(); 1293 execution_result()->SetResultInAccumulator();
1298 break; 1294 break;
1299 } 1295 }
1300 case VariableLocation::CONTEXT: { 1296 case VariableLocation::CONTEXT: {
1301 int depth = execution_context()->ContextChainDepth(variable->scope()); 1297 int depth = execution_context()->ContextChainDepth(variable->scope());
1302 ContextScope* context = execution_context()->Previous(depth); 1298 ContextScope* context = execution_context()->Previous(depth);
1303 Register context_reg; 1299 Register context_reg;
1304 if (context) { 1300 if (context) {
1305 context_reg = context->reg(); 1301 context_reg = context->reg();
1306 } else { 1302 } else {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 // index -1 but is parameter index 0 in BytecodeArrayBuilder). 1361 // index -1 but is parameter index 0 in BytecodeArrayBuilder).
1366 Register destination(builder()->Parameter(variable->index() + 1)); 1362 Register destination(builder()->Parameter(variable->index() + 1));
1367 destination = 1363 destination =
1368 assignment_hazard_helper()->GetRegisterForStore(destination); 1364 assignment_hazard_helper()->GetRegisterForStore(destination);
1369 1365
1370 builder()->StoreAccumulatorInRegister(destination); 1366 builder()->StoreAccumulatorInRegister(destination);
1371 break; 1367 break;
1372 } 1368 }
1373 case VariableLocation::GLOBAL: 1369 case VariableLocation::GLOBAL:
1374 case VariableLocation::UNALLOCATED: { 1370 case VariableLocation::UNALLOCATED: {
1375 size_t name_index = builder()->GetConstantPoolEntry(variable->name()); 1371 builder()->StoreGlobal(variable->name(), feedback_index(slot),
1376 builder()->StoreGlobal(name_index, feedback_index(slot), language_mode()); 1372 language_mode());
1377 break; 1373 break;
1378 } 1374 }
1379 case VariableLocation::CONTEXT: { 1375 case VariableLocation::CONTEXT: {
1380 // TODO(rmcilroy): support const mode initialization. 1376 // TODO(rmcilroy): support const mode initialization.
1381 int depth = execution_context()->ContextChainDepth(variable->scope()); 1377 int depth = execution_context()->ContextChainDepth(variable->scope());
1382 ContextScope* context = execution_context()->Previous(depth); 1378 ContextScope* context = execution_context()->Previous(depth);
1383 Register context_reg; 1379 Register context_reg;
1384 if (context) { 1380 if (context) {
1385 context_reg = context->reg(); 1381 context_reg = context->reg();
1386 } else { 1382 } else {
(...skipping 22 matching lines...) Expand all
1409 builder()->StoreLookupSlot(variable->name(), language_mode()); 1405 builder()->StoreLookupSlot(variable->name(), language_mode());
1410 break; 1406 break;
1411 } 1407 }
1412 } 1408 }
1413 } 1409 }
1414 1410
1415 1411
1416 void BytecodeGenerator::VisitAssignment(Assignment* expr) { 1412 void BytecodeGenerator::VisitAssignment(Assignment* expr) {
1417 DCHECK(expr->target()->IsValidReferenceExpression()); 1413 DCHECK(expr->target()->IsValidReferenceExpression());
1418 Register object, key; 1414 Register object, key;
1419 size_t name_index = kMaxUInt32; 1415 Handle<String> name;
1420 1416
1421 // Left-hand side can only be a property, a global or a variable slot. 1417 // Left-hand side can only be a property, a global or a variable slot.
1422 Property* property = expr->target()->AsProperty(); 1418 Property* property = expr->target()->AsProperty();
1423 LhsKind assign_type = Property::GetAssignType(property); 1419 LhsKind assign_type = Property::GetAssignType(property);
1424 1420
1425 // Evaluate LHS expression. 1421 // Evaluate LHS expression.
1426 switch (assign_type) { 1422 switch (assign_type) {
1427 case VARIABLE: 1423 case VARIABLE:
1428 // Nothing to do to evaluate variable assignment LHS. 1424 // Nothing to do to evaluate variable assignment LHS.
1429 break; 1425 break;
1430 case NAMED_PROPERTY: { 1426 case NAMED_PROPERTY: {
1431 object = VisitForRegisterValue(property->obj()); 1427 object = VisitForRegisterValue(property->obj());
1432 name_index = builder()->GetConstantPoolEntry( 1428 name = property->key()->AsLiteral()->AsPropertyName();
1433 property->key()->AsLiteral()->AsPropertyName());
1434 break; 1429 break;
1435 } 1430 }
1436 case KEYED_PROPERTY: { 1431 case KEYED_PROPERTY: {
1437 object = VisitForRegisterValue(property->obj()); 1432 object = VisitForRegisterValue(property->obj());
1438 if (expr->is_compound()) { 1433 if (expr->is_compound()) {
1439 // Use VisitForAccumulator and store to register so that the key is 1434 // Use VisitForAccumulator and store to register so that the key is
1440 // still in the accumulator for loading the old value below. 1435 // still in the accumulator for loading the old value below.
1441 key = execution_result()->NewRegister(); 1436 key = execution_result()->NewRegister();
1442 VisitForAccumulatorValue(property->key()); 1437 VisitForAccumulatorValue(property->key());
1443 builder()->StoreAccumulatorInRegister(key); 1438 builder()->StoreAccumulatorInRegister(key);
(...skipping 15 matching lines...) Expand all
1459 case VARIABLE: { 1454 case VARIABLE: {
1460 VariableProxy* proxy = expr->target()->AsVariableProxy(); 1455 VariableProxy* proxy = expr->target()->AsVariableProxy();
1461 old_value = VisitVariableLoadForRegisterValue( 1456 old_value = VisitVariableLoadForRegisterValue(
1462 proxy->var(), proxy->VariableFeedbackSlot()); 1457 proxy->var(), proxy->VariableFeedbackSlot());
1463 break; 1458 break;
1464 } 1459 }
1465 case NAMED_PROPERTY: { 1460 case NAMED_PROPERTY: {
1466 FeedbackVectorSlot slot = property->PropertyFeedbackSlot(); 1461 FeedbackVectorSlot slot = property->PropertyFeedbackSlot();
1467 old_value = execution_result()->NewRegister(); 1462 old_value = execution_result()->NewRegister();
1468 builder() 1463 builder()
1469 ->LoadNamedProperty(object, name_index, feedback_index(slot), 1464 ->LoadNamedProperty(object, name, feedback_index(slot),
1470 language_mode()) 1465 language_mode())
1471 .StoreAccumulatorInRegister(old_value); 1466 .StoreAccumulatorInRegister(old_value);
1472 break; 1467 break;
1473 } 1468 }
1474 case KEYED_PROPERTY: { 1469 case KEYED_PROPERTY: {
1475 // Key is already in accumulator at this point due to evaluating the 1470 // Key is already in accumulator at this point due to evaluating the
1476 // LHS above. 1471 // LHS above.
1477 FeedbackVectorSlot slot = property->PropertyFeedbackSlot(); 1472 FeedbackVectorSlot slot = property->PropertyFeedbackSlot();
1478 old_value = execution_result()->NewRegister(); 1473 old_value = execution_result()->NewRegister();
1479 builder() 1474 builder()
(...skipping 17 matching lines...) Expand all
1497 FeedbackVectorSlot slot = expr->AssignmentSlot(); 1492 FeedbackVectorSlot slot = expr->AssignmentSlot();
1498 switch (assign_type) { 1493 switch (assign_type) {
1499 case VARIABLE: { 1494 case VARIABLE: {
1500 // TODO(oth): The VisitVariableAssignment() call is hard to reason about. 1495 // TODO(oth): The VisitVariableAssignment() call is hard to reason about.
1501 // Is the value in the accumulator safe? Yes, but scary. 1496 // Is the value in the accumulator safe? Yes, but scary.
1502 Variable* variable = expr->target()->AsVariableProxy()->var(); 1497 Variable* variable = expr->target()->AsVariableProxy()->var();
1503 VisitVariableAssignment(variable, slot); 1498 VisitVariableAssignment(variable, slot);
1504 break; 1499 break;
1505 } 1500 }
1506 case NAMED_PROPERTY: 1501 case NAMED_PROPERTY:
1507 builder()->StoreNamedProperty(object, name_index, feedback_index(slot), 1502 builder()->StoreNamedProperty(object, name, feedback_index(slot),
1508 language_mode()); 1503 language_mode());
1509 break; 1504 break;
1510 case KEYED_PROPERTY: 1505 case KEYED_PROPERTY:
1511 builder()->StoreKeyedProperty(object, key, feedback_index(slot), 1506 builder()->StoreKeyedProperty(object, key, feedback_index(slot),
1512 language_mode()); 1507 language_mode());
1513 break; 1508 break;
1514 case NAMED_SUPER_PROPERTY: 1509 case NAMED_SUPER_PROPERTY:
1515 case KEYED_SUPER_PROPERTY: 1510 case KEYED_SUPER_PROPERTY:
1516 UNIMPLEMENTED(); 1511 UNIMPLEMENTED();
1517 } 1512 }
(...skipping 10 matching lines...) Expand all
1528 } 1523 }
1529 1524
1530 1525
1531 void BytecodeGenerator::VisitPropertyLoad(Register obj, Property* expr) { 1526 void BytecodeGenerator::VisitPropertyLoad(Register obj, Property* expr) {
1532 LhsKind property_kind = Property::GetAssignType(expr); 1527 LhsKind property_kind = Property::GetAssignType(expr);
1533 FeedbackVectorSlot slot = expr->PropertyFeedbackSlot(); 1528 FeedbackVectorSlot slot = expr->PropertyFeedbackSlot();
1534 switch (property_kind) { 1529 switch (property_kind) {
1535 case VARIABLE: 1530 case VARIABLE:
1536 UNREACHABLE(); 1531 UNREACHABLE();
1537 case NAMED_PROPERTY: { 1532 case NAMED_PROPERTY: {
1538 size_t name_index = builder()->GetConstantPoolEntry( 1533 builder()->LoadNamedProperty(obj,
1539 expr->key()->AsLiteral()->AsPropertyName()); 1534 expr->key()->AsLiteral()->AsPropertyName(),
1540 builder()->LoadNamedProperty(obj, name_index, feedback_index(slot), 1535 feedback_index(slot), language_mode());
1541 language_mode());
1542 break; 1536 break;
1543 } 1537 }
1544 case KEYED_PROPERTY: { 1538 case KEYED_PROPERTY: {
1545 VisitForAccumulatorValue(expr->key()); 1539 VisitForAccumulatorValue(expr->key());
1546 builder()->LoadKeyedProperty(obj, feedback_index(slot), language_mode()); 1540 builder()->LoadKeyedProperty(obj, feedback_index(slot), language_mode());
1547 break; 1541 break;
1548 } 1542 }
1549 case NAMED_SUPER_PROPERTY: 1543 case NAMED_SUPER_PROPERTY:
1550 case KEYED_SUPER_PROPERTY: 1544 case KEYED_SUPER_PROPERTY:
1551 UNIMPLEMENTED(); 1545 UNIMPLEMENTED();
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 1811
1818 // Left-hand side can only be a property, a global or a variable slot. 1812 // Left-hand side can only be a property, a global or a variable slot.
1819 Property* property = expr->expression()->AsProperty(); 1813 Property* property = expr->expression()->AsProperty();
1820 LhsKind assign_type = Property::GetAssignType(property); 1814 LhsKind assign_type = Property::GetAssignType(property);
1821 1815
1822 // TODO(rmcilroy): Set is_postfix to false if visiting for effect. 1816 // TODO(rmcilroy): Set is_postfix to false if visiting for effect.
1823 bool is_postfix = expr->is_postfix(); 1817 bool is_postfix = expr->is_postfix();
1824 1818
1825 // Evaluate LHS expression and get old value. 1819 // Evaluate LHS expression and get old value.
1826 Register obj, key, old_value; 1820 Register obj, key, old_value;
1827 size_t name_index = kMaxUInt32; 1821 Handle<String> name;
1828 switch (assign_type) { 1822 switch (assign_type) {
1829 case VARIABLE: { 1823 case VARIABLE: {
1830 VariableProxy* proxy = expr->expression()->AsVariableProxy(); 1824 VariableProxy* proxy = expr->expression()->AsVariableProxy();
1831 VisitVariableLoadForAccumulatorValue(proxy->var(), 1825 VisitVariableLoadForAccumulatorValue(proxy->var(),
1832 proxy->VariableFeedbackSlot()); 1826 proxy->VariableFeedbackSlot());
1833 break; 1827 break;
1834 } 1828 }
1835 case NAMED_PROPERTY: { 1829 case NAMED_PROPERTY: {
1836 FeedbackVectorSlot slot = property->PropertyFeedbackSlot(); 1830 FeedbackVectorSlot slot = property->PropertyFeedbackSlot();
1837 obj = VisitForRegisterValue(property->obj()); 1831 obj = VisitForRegisterValue(property->obj());
1838 name_index = builder()->GetConstantPoolEntry( 1832 name = property->key()->AsLiteral()->AsPropertyName();
1839 property->key()->AsLiteral()->AsPropertyName()); 1833 builder()->LoadNamedProperty(obj, name, feedback_index(slot),
1840 builder()->LoadNamedProperty(obj, name_index, feedback_index(slot),
1841 language_mode()); 1834 language_mode());
1842 break; 1835 break;
1843 } 1836 }
1844 case KEYED_PROPERTY: { 1837 case KEYED_PROPERTY: {
1845 FeedbackVectorSlot slot = property->PropertyFeedbackSlot(); 1838 FeedbackVectorSlot slot = property->PropertyFeedbackSlot();
1846 obj = VisitForRegisterValue(property->obj()); 1839 obj = VisitForRegisterValue(property->obj());
1847 // Use visit for accumulator here since we need the key in the accumulator 1840 // Use visit for accumulator here since we need the key in the accumulator
1848 // for the LoadKeyedProperty. 1841 // for the LoadKeyedProperty.
1849 key = execution_result()->NewRegister(); 1842 key = execution_result()->NewRegister();
1850 VisitForAccumulatorValue(property->key()); 1843 VisitForAccumulatorValue(property->key());
(...skipping 22 matching lines...) Expand all
1873 1866
1874 // Store the value. 1867 // Store the value.
1875 FeedbackVectorSlot feedback_slot = expr->CountSlot(); 1868 FeedbackVectorSlot feedback_slot = expr->CountSlot();
1876 switch (assign_type) { 1869 switch (assign_type) {
1877 case VARIABLE: { 1870 case VARIABLE: {
1878 Variable* variable = expr->expression()->AsVariableProxy()->var(); 1871 Variable* variable = expr->expression()->AsVariableProxy()->var();
1879 VisitVariableAssignment(variable, feedback_slot); 1872 VisitVariableAssignment(variable, feedback_slot);
1880 break; 1873 break;
1881 } 1874 }
1882 case NAMED_PROPERTY: { 1875 case NAMED_PROPERTY: {
1883 builder()->StoreNamedProperty( 1876 builder()->StoreNamedProperty(obj, name, feedback_index(feedback_slot),
1884 obj, name_index, feedback_index(feedback_slot), language_mode()); 1877 language_mode());
1885 break; 1878 break;
1886 } 1879 }
1887 case KEYED_PROPERTY: { 1880 case KEYED_PROPERTY: {
1888 builder()->StoreKeyedProperty(obj, key, feedback_index(feedback_slot), 1881 builder()->StoreKeyedProperty(obj, key, feedback_index(feedback_slot),
1889 language_mode()); 1882 language_mode());
1890 break; 1883 break;
1891 } 1884 }
1892 case NAMED_SUPER_PROPERTY: 1885 case NAMED_SUPER_PROPERTY:
1893 case KEYED_SUPER_PROPERTY: 1886 case KEYED_SUPER_PROPERTY:
1894 UNIMPLEMENTED(); 1887 UNIMPLEMENTED();
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
2223 } 2216 }
2224 2217
2225 2218
2226 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 2219 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
2227 return info()->feedback_vector()->GetIndex(slot); 2220 return info()->feedback_vector()->GetIndex(slot);
2228 } 2221 }
2229 2222
2230 } // namespace interpreter 2223 } // namespace interpreter
2231 } // namespace internal 2224 } // namespace internal
2232 } // namespace v8 2225 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-array-builder.cc ('k') | test/cctest/interpreter/test-bytecode-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698