OLD | NEW |
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-array-builder.h" | 5 #include "src/interpreter/bytecode-array-builder.h" |
6 | 6 |
7 namespace v8 { | 7 namespace v8 { |
8 namespace internal { | 8 namespace internal { |
9 namespace interpreter { | 9 namespace interpreter { |
10 | 10 |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 LoadLiteral(Handle<Object>(smi, isolate_)); | 217 LoadLiteral(Handle<Object>(smi, isolate_)); |
218 } | 218 } |
219 return *this; | 219 return *this; |
220 } | 220 } |
221 | 221 |
222 | 222 |
223 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLiteral(Handle<Object> object) { | 223 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadLiteral(Handle<Object> object) { |
224 size_t entry = GetConstantPoolEntry(object); | 224 size_t entry = GetConstantPoolEntry(object); |
225 if (FitsInIdx8Operand(entry)) { | 225 if (FitsInIdx8Operand(entry)) { |
226 Output(Bytecode::kLdaConstant, static_cast<uint8_t>(entry)); | 226 Output(Bytecode::kLdaConstant, static_cast<uint8_t>(entry)); |
| 227 } else if (FitsInIdx16Operand(entry)) { |
| 228 Output(Bytecode::kLdaConstantWide, static_cast<uint16_t>(entry)); |
227 } else { | 229 } else { |
228 UNIMPLEMENTED(); | 230 UNIMPLEMENTED(); |
229 } | 231 } |
230 return *this; | 232 return *this; |
231 } | 233 } |
232 | 234 |
233 | 235 |
234 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadUndefined() { | 236 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadUndefined() { |
235 Output(Bytecode::kLdaUndefined); | 237 Output(Bytecode::kLdaUndefined); |
236 return *this; | 238 return *this; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 return *this; | 280 return *this; |
279 } | 281 } |
280 | 282 |
281 | 283 |
282 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadGlobal( | 284 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadGlobal( |
283 size_t name_index, int feedback_slot, LanguageMode language_mode) { | 285 size_t name_index, int feedback_slot, LanguageMode language_mode) { |
284 Bytecode bytecode = BytecodeForLoadGlobal(language_mode); | 286 Bytecode bytecode = BytecodeForLoadGlobal(language_mode); |
285 if (FitsInIdx8Operand(name_index) && FitsInIdx8Operand(feedback_slot)) { | 287 if (FitsInIdx8Operand(name_index) && FitsInIdx8Operand(feedback_slot)) { |
286 Output(bytecode, static_cast<uint8_t>(name_index), | 288 Output(bytecode, static_cast<uint8_t>(name_index), |
287 static_cast<uint8_t>(feedback_slot)); | 289 static_cast<uint8_t>(feedback_slot)); |
| 290 } else if (FitsInIdx16Operand(name_index) && |
| 291 FitsInIdx16Operand(feedback_slot)) { |
| 292 Output(BytecodeForWideOperands(bytecode), static_cast<uint16_t>(name_index), |
| 293 static_cast<uint16_t>(feedback_slot)); |
288 } else { | 294 } else { |
289 UNIMPLEMENTED(); | 295 UNIMPLEMENTED(); |
290 } | 296 } |
291 return *this; | 297 return *this; |
292 } | 298 } |
293 | 299 |
294 | 300 |
295 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreGlobal( | 301 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreGlobal( |
296 size_t name_index, int feedback_slot, LanguageMode language_mode) { | 302 size_t name_index, int feedback_slot, LanguageMode language_mode) { |
297 Bytecode bytecode = BytecodeForStoreGlobal(language_mode); | 303 Bytecode bytecode = BytecodeForStoreGlobal(language_mode); |
298 if (FitsInIdx8Operand(name_index) && FitsInIdx8Operand(feedback_slot)) { | 304 if (FitsInIdx8Operand(name_index) && FitsInIdx8Operand(feedback_slot)) { |
299 Output(bytecode, static_cast<uint8_t>(name_index), | 305 Output(bytecode, static_cast<uint8_t>(name_index), |
300 static_cast<uint8_t>(feedback_slot)); | 306 static_cast<uint8_t>(feedback_slot)); |
| 307 } else if (FitsInIdx16Operand(name_index) && |
| 308 FitsInIdx16Operand(feedback_slot)) { |
| 309 Output(BytecodeForWideOperands(bytecode), static_cast<uint16_t>(name_index), |
| 310 static_cast<uint16_t>(feedback_slot)); |
301 } else { | 311 } else { |
302 UNIMPLEMENTED(); | 312 UNIMPLEMENTED(); |
303 } | 313 } |
304 return *this; | 314 return *this; |
305 } | 315 } |
306 | 316 |
307 | 317 |
308 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadContextSlot(Register context, | 318 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadContextSlot(Register context, |
309 int slot_index) { | 319 int slot_index) { |
310 DCHECK(slot_index >= 0); | 320 DCHECK(slot_index >= 0); |
(...skipping 20 matching lines...) Expand all Loading... |
331 } | 341 } |
332 | 342 |
333 | 343 |
334 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadNamedProperty( | 344 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadNamedProperty( |
335 Register object, size_t name_index, int feedback_slot, | 345 Register object, size_t name_index, int feedback_slot, |
336 LanguageMode language_mode) { | 346 LanguageMode language_mode) { |
337 Bytecode bytecode = BytecodeForLoadIC(language_mode); | 347 Bytecode bytecode = BytecodeForLoadIC(language_mode); |
338 if (FitsInIdx8Operand(name_index) && FitsInIdx8Operand(feedback_slot)) { | 348 if (FitsInIdx8Operand(name_index) && FitsInIdx8Operand(feedback_slot)) { |
339 Output(bytecode, object.ToOperand(), static_cast<uint8_t>(name_index), | 349 Output(bytecode, object.ToOperand(), static_cast<uint8_t>(name_index), |
340 static_cast<uint8_t>(feedback_slot)); | 350 static_cast<uint8_t>(feedback_slot)); |
| 351 } else if (FitsInIdx16Operand(name_index) && |
| 352 FitsInIdx16Operand(feedback_slot)) { |
| 353 Output(BytecodeForWideOperands(bytecode), object.ToOperand(), |
| 354 static_cast<uint16_t>(name_index), |
| 355 static_cast<uint16_t>(feedback_slot)); |
341 } else { | 356 } else { |
342 UNIMPLEMENTED(); | 357 UNIMPLEMENTED(); |
343 } | 358 } |
344 return *this; | 359 return *this; |
345 } | 360 } |
346 | 361 |
347 | 362 |
348 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadKeyedProperty( | 363 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadKeyedProperty( |
349 Register object, int feedback_slot, LanguageMode language_mode) { | 364 Register object, int feedback_slot, LanguageMode language_mode) { |
350 Bytecode bytecode = BytecodeForKeyedLoadIC(language_mode); | 365 Bytecode bytecode = BytecodeForKeyedLoadIC(language_mode); |
351 if (FitsInIdx8Operand(feedback_slot)) { | 366 if (FitsInIdx8Operand(feedback_slot)) { |
352 Output(bytecode, object.ToOperand(), static_cast<uint8_t>(feedback_slot)); | 367 Output(bytecode, object.ToOperand(), static_cast<uint8_t>(feedback_slot)); |
| 368 } else if (FitsInIdx16Operand(feedback_slot)) { |
| 369 Output(BytecodeForWideOperands(bytecode), object.ToOperand(), |
| 370 static_cast<uint16_t>(feedback_slot)); |
353 } else { | 371 } else { |
354 UNIMPLEMENTED(); | 372 UNIMPLEMENTED(); |
355 } | 373 } |
356 return *this; | 374 return *this; |
357 } | 375 } |
358 | 376 |
359 | 377 |
360 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreNamedProperty( | 378 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreNamedProperty( |
361 Register object, size_t name_index, int feedback_slot, | 379 Register object, size_t name_index, int feedback_slot, |
362 LanguageMode language_mode) { | 380 LanguageMode language_mode) { |
363 Bytecode bytecode = BytecodeForStoreIC(language_mode); | 381 Bytecode bytecode = BytecodeForStoreIC(language_mode); |
364 if (FitsInIdx8Operand(name_index) && FitsInIdx8Operand(feedback_slot)) { | 382 if (FitsInIdx8Operand(name_index) && FitsInIdx8Operand(feedback_slot)) { |
365 Output(bytecode, object.ToOperand(), static_cast<uint8_t>(name_index), | 383 Output(bytecode, object.ToOperand(), static_cast<uint8_t>(name_index), |
366 static_cast<uint8_t>(feedback_slot)); | 384 static_cast<uint8_t>(feedback_slot)); |
| 385 } else if (FitsInIdx16Operand(name_index) && |
| 386 FitsInIdx16Operand(feedback_slot)) { |
| 387 Output(BytecodeForWideOperands(bytecode), object.ToOperand(), |
| 388 static_cast<uint16_t>(name_index), |
| 389 static_cast<uint16_t>(feedback_slot)); |
367 } else { | 390 } else { |
368 UNIMPLEMENTED(); | 391 UNIMPLEMENTED(); |
369 } | 392 } |
370 return *this; | 393 return *this; |
371 } | 394 } |
372 | 395 |
373 | 396 |
374 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreKeyedProperty( | 397 BytecodeArrayBuilder& BytecodeArrayBuilder::StoreKeyedProperty( |
375 Register object, Register key, int feedback_slot, | 398 Register object, Register key, int feedback_slot, |
376 LanguageMode language_mode) { | 399 LanguageMode language_mode) { |
377 Bytecode bytecode = BytecodeForKeyedStoreIC(language_mode); | 400 Bytecode bytecode = BytecodeForKeyedStoreIC(language_mode); |
378 if (FitsInIdx8Operand(feedback_slot)) { | 401 if (FitsInIdx8Operand(feedback_slot)) { |
379 Output(bytecode, object.ToOperand(), key.ToOperand(), | 402 Output(bytecode, object.ToOperand(), key.ToOperand(), |
380 static_cast<uint8_t>(feedback_slot)); | 403 static_cast<uint8_t>(feedback_slot)); |
| 404 } else if (FitsInIdx16Operand(feedback_slot)) { |
| 405 Output(BytecodeForWideOperands(bytecode), object.ToOperand(), |
| 406 key.ToOperand(), static_cast<uint16_t>(feedback_slot)); |
381 } else { | 407 } else { |
382 UNIMPLEMENTED(); | 408 UNIMPLEMENTED(); |
383 } | 409 } |
384 return *this; | 410 return *this; |
385 } | 411 } |
386 | 412 |
387 | 413 |
388 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateClosure( | 414 BytecodeArrayBuilder& BytecodeArrayBuilder::CreateClosure( |
389 PretenureFlag tenured) { | 415 PretenureFlag tenured) { |
390 DCHECK(FitsInImm8Operand(tenured)); | 416 DCHECK(FitsInImm8Operand(tenured)); |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 case Token::Value::IN: | 971 case Token::Value::IN: |
946 return Bytecode::kTestIn; | 972 return Bytecode::kTestIn; |
947 default: | 973 default: |
948 UNREACHABLE(); | 974 UNREACHABLE(); |
949 return static_cast<Bytecode>(-1); | 975 return static_cast<Bytecode>(-1); |
950 } | 976 } |
951 } | 977 } |
952 | 978 |
953 | 979 |
954 // static | 980 // static |
| 981 Bytecode BytecodeArrayBuilder::BytecodeForWideOperands(Bytecode bytecode) { |
| 982 switch (bytecode) { |
| 983 case Bytecode::kLoadICSloppy: |
| 984 return Bytecode::kLoadICSloppyWide; |
| 985 case Bytecode::kLoadICStrict: |
| 986 return Bytecode::kLoadICStrictWide; |
| 987 case Bytecode::kKeyedLoadICSloppy: |
| 988 return Bytecode::kKeyedLoadICSloppyWide; |
| 989 case Bytecode::kKeyedLoadICStrict: |
| 990 return Bytecode::kKeyedLoadICStrictWide; |
| 991 case Bytecode::kStoreICSloppy: |
| 992 return Bytecode::kStoreICSloppyWide; |
| 993 case Bytecode::kStoreICStrict: |
| 994 return Bytecode::kStoreICStrictWide; |
| 995 case Bytecode::kKeyedStoreICSloppy: |
| 996 return Bytecode::kKeyedStoreICSloppyWide; |
| 997 case Bytecode::kKeyedStoreICStrict: |
| 998 return Bytecode::kKeyedStoreICStrictWide; |
| 999 case Bytecode::kLdaGlobalSloppy: |
| 1000 return Bytecode::kLdaGlobalSloppyWide; |
| 1001 case Bytecode::kLdaGlobalStrict: |
| 1002 return Bytecode::kLdaGlobalStrictWide; |
| 1003 case Bytecode::kStaGlobalSloppy: |
| 1004 return Bytecode::kStaGlobalSloppyWide; |
| 1005 case Bytecode::kStaGlobalStrict: |
| 1006 return Bytecode::kStaGlobalStrictWide; |
| 1007 default: |
| 1008 UNREACHABLE(); |
| 1009 return static_cast<Bytecode>(-1); |
| 1010 } |
| 1011 } |
| 1012 |
| 1013 |
| 1014 // static |
955 Bytecode BytecodeArrayBuilder::BytecodeForLoadIC(LanguageMode language_mode) { | 1015 Bytecode BytecodeArrayBuilder::BytecodeForLoadIC(LanguageMode language_mode) { |
956 switch (language_mode) { | 1016 switch (language_mode) { |
957 case SLOPPY: | 1017 case SLOPPY: |
958 return Bytecode::kLoadICSloppy; | 1018 return Bytecode::kLoadICSloppy; |
959 case STRICT: | 1019 case STRICT: |
960 return Bytecode::kLoadICStrict; | 1020 return Bytecode::kLoadICStrict; |
961 case STRONG: | 1021 case STRONG: |
962 UNIMPLEMENTED(); | 1022 UNIMPLEMENTED(); |
963 default: | 1023 default: |
964 UNREACHABLE(); | 1024 UNREACHABLE(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 return kMinInt8 <= value && value < kMaxInt8; | 1159 return kMinInt8 <= value && value < kMaxInt8; |
1100 } | 1160 } |
1101 | 1161 |
1102 | 1162 |
1103 // static | 1163 // static |
1104 bool BytecodeArrayBuilder::FitsInIdx16Operand(int value) { | 1164 bool BytecodeArrayBuilder::FitsInIdx16Operand(int value) { |
1105 return kMinUInt16 <= value && value <= kMaxUInt16; | 1165 return kMinUInt16 <= value && value <= kMaxUInt16; |
1106 } | 1166 } |
1107 | 1167 |
1108 | 1168 |
| 1169 // static |
| 1170 bool BytecodeArrayBuilder::FitsInIdx16Operand(size_t value) { |
| 1171 return value <= static_cast<size_t>(kMaxUInt16); |
| 1172 } |
| 1173 |
| 1174 |
1109 TemporaryRegisterScope::TemporaryRegisterScope(BytecodeArrayBuilder* builder) | 1175 TemporaryRegisterScope::TemporaryRegisterScope(BytecodeArrayBuilder* builder) |
1110 : builder_(builder), | 1176 : builder_(builder), |
1111 allocated_(builder->zone()), | 1177 allocated_(builder->zone()), |
1112 next_consecutive_register_(-1), | 1178 next_consecutive_register_(-1), |
1113 next_consecutive_count_(-1) {} | 1179 next_consecutive_count_(-1) {} |
1114 | 1180 |
1115 | 1181 |
1116 TemporaryRegisterScope::~TemporaryRegisterScope() { | 1182 TemporaryRegisterScope::~TemporaryRegisterScope() { |
1117 for (auto i = allocated_.rbegin(); i != allocated_.rend(); i++) { | 1183 for (auto i = allocated_.rbegin(); i != allocated_.rend(); i++) { |
1118 builder_->ReturnTemporaryRegister(*i); | 1184 builder_->ReturnTemporaryRegister(*i); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 DCHECK_GT(next_consecutive_count_, 0); | 1217 DCHECK_GT(next_consecutive_count_, 0); |
1152 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); | 1218 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); |
1153 allocated_.push_back(next_consecutive_register_); | 1219 allocated_.push_back(next_consecutive_register_); |
1154 next_consecutive_count_--; | 1220 next_consecutive_count_--; |
1155 return Register(next_consecutive_register_++); | 1221 return Register(next_consecutive_register_++); |
1156 } | 1222 } |
1157 | 1223 |
1158 } // namespace interpreter | 1224 } // namespace interpreter |
1159 } // namespace internal | 1225 } // namespace internal |
1160 } // namespace v8 | 1226 } // namespace v8 |
OLD | NEW |