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

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

Issue 1416623003: [Interpreter] Add support for for count operations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 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 <stack> 7 #include <stack>
8 8
9 #include "src/compiler.h" 9 #include "src/compiler.h"
10 #include "src/interpreter/control-flow-builders.h" 10 #include "src/interpreter/control-flow-builders.h"
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 case Token::Value::BIT_NOT: 1142 case Token::Value::BIT_NOT:
1143 case Token::Value::DELETE: 1143 case Token::Value::DELETE:
1144 UNIMPLEMENTED(); 1144 UNIMPLEMENTED();
1145 default: 1145 default:
1146 UNREACHABLE(); 1146 UNREACHABLE();
1147 } 1147 }
1148 } 1148 }
1149 1149
1150 1150
1151 void BytecodeGenerator::VisitCountOperation(CountOperation* expr) { 1151 void BytecodeGenerator::VisitCountOperation(CountOperation* expr) {
1152 UNIMPLEMENTED(); 1152 DCHECK(expr->expression()->IsValidReferenceExpressionOrThis());
1153
1154 // Left-hand side can only be a property, a global or a variable slot.
1155 Property* property = expr->expression()->AsProperty();
1156 LhsKind assign_type = Property::GetAssignType(property);
1157
1158 // TODO(rmcilroy): Set is_postfix to false if visiting for effect.
1159 bool is_postfix = expr->is_postfix();
1160
1161 // Evaluate LHS expression and get old value.
1162 TemporaryRegisterScope temporary_register_scope(builder());
1163 Register obj, key, old_value;
1164 switch (assign_type) {
1165 case VARIABLE: {
1166 VariableProxy* proxy = expr->expression()->AsVariableProxy();
1167 VisitVariableLoad(proxy->var(), proxy->VariableFeedbackSlot());
1168 break;
1169 }
1170 case NAMED_PROPERTY: {
1171 obj = temporary_register_scope.NewRegister();
1172 key = temporary_register_scope.NewRegister();
1173 FeedbackVectorSlot slot = property->PropertyFeedbackSlot();
1174 Visit(property->obj());
1175 builder()
1176 ->StoreAccumulatorInRegister(obj)
1177 .LoadLiteral(property->key()->AsLiteral()->AsPropertyName())
1178 .StoreAccumulatorInRegister(key)
1179 .LoadNamedProperty(obj, feedback_index(slot), language_mode());
1180 break;
1181 }
1182 case KEYED_PROPERTY: {
1183 obj = temporary_register_scope.NewRegister();
1184 key = temporary_register_scope.NewRegister();
1185 FeedbackVectorSlot slot = property->PropertyFeedbackSlot();
1186 Visit(property->obj());
1187 builder()->StoreAccumulatorInRegister(obj);
1188 Visit(property->key());
1189 builder()->StoreAccumulatorInRegister(key).LoadKeyedProperty(
1190 obj, feedback_index(slot), language_mode());
1191 break;
1192 }
1193 case NAMED_SUPER_PROPERTY:
1194 case KEYED_SUPER_PROPERTY:
1195 UNIMPLEMENTED();
1196 }
1197
1198 // Convert old value into a number.
1199 if (!is_strong(language_mode())) {
1200 builder()->CastAccumulatorToNumber();
1201 }
1202
1203 // Save result for postfix expressions.
1204 if (is_postfix) {
1205 old_value = temporary_register_scope.NewRegister();
1206 builder()->StoreAccumulatorInRegister(old_value);
1207 }
1208
1209 // Perform +1/-1 operation.
1210 builder()->CountOperation(expr->binary_op(), language_mode_strength());
1211
1212 // Store the value.
1213 FeedbackVectorSlot feedback_slot = expr->CountSlot();
1214 switch (assign_type) {
1215 case VARIABLE: {
1216 Variable* variable = expr->expression()->AsVariableProxy()->var();
1217 VisitVariableAssignment(variable, feedback_slot);
1218 break;
1219 }
1220 case NAMED_PROPERTY: {
1221 builder()->StoreNamedProperty(obj, key, feedback_index(feedback_slot),
1222 language_mode());
1223 break;
1224 }
1225 case KEYED_PROPERTY: {
1226 builder()->StoreKeyedProperty(obj, key, feedback_index(feedback_slot),
1227 language_mode());
1228 break;
1229 }
1230 case NAMED_SUPER_PROPERTY:
1231 case KEYED_SUPER_PROPERTY:
1232 UNIMPLEMENTED();
1233 }
1234
1235 // Restore old value for postfix expressions.
1236 if (is_postfix) builder()->LoadAccumulatorWithRegister(old_value);
1153 } 1237 }
1154 1238
1155 1239
1156 void BytecodeGenerator::VisitBinaryOperation(BinaryOperation* binop) { 1240 void BytecodeGenerator::VisitBinaryOperation(BinaryOperation* binop) {
1157 switch (binop->op()) { 1241 switch (binop->op()) {
1158 case Token::COMMA: 1242 case Token::COMMA:
1159 VisitCommaExpression(binop); 1243 VisitCommaExpression(binop);
1160 break; 1244 break;
1161 case Token::OR: 1245 case Token::OR:
1162 VisitLogicalOrExpression(binop); 1246 VisitLogicalOrExpression(binop);
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 } 1498 }
1415 1499
1416 1500
1417 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 1501 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
1418 return info()->feedback_vector()->GetIndex(slot); 1502 return info()->feedback_vector()->GetIndex(slot);
1419 } 1503 }
1420 1504
1421 } // namespace interpreter 1505 } // namespace interpreter
1422 } // namespace internal 1506 } // namespace internal
1423 } // namespace v8 1507 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698