| 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 372 |
| 373 | 373 |
| 374 BytecodeArrayBuilder& BytecodeArrayBuilder::MoveRegister(Register from, | 374 BytecodeArrayBuilder& BytecodeArrayBuilder::MoveRegister(Register from, |
| 375 Register to) { | 375 Register to) { |
| 376 DCHECK(from != to); | 376 DCHECK(from != to); |
| 377 Output(Bytecode::kMov, from.ToOperand(), to.ToOperand()); | 377 Output(Bytecode::kMov, from.ToOperand(), to.ToOperand()); |
| 378 return *this; | 378 return *this; |
| 379 } | 379 } |
| 380 | 380 |
| 381 | 381 |
| 382 BytecodeArrayBuilder& BytecodeArrayBuilder::ExchangeRegisters(Register reg0, |
| 383 Register reg1) { |
| 384 DCHECK(reg0 != reg1); |
| 385 if (FitsInReg8Operand(reg0)) { |
| 386 Output(Bytecode::kExchange, reg0.ToOperand(), reg1.ToWideOperand()); |
| 387 } else if (FitsInReg8Operand(reg1)) { |
| 388 Output(Bytecode::kExchange, reg1.ToOperand(), reg0.ToWideOperand()); |
| 389 } else { |
| 390 Output(Bytecode::kExchangeWide, reg0.ToWideOperand(), reg1.ToWideOperand()); |
| 391 } |
| 392 return *this; |
| 393 } |
| 394 |
| 395 |
| 382 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadGlobal( | 396 BytecodeArrayBuilder& BytecodeArrayBuilder::LoadGlobal( |
| 383 const Handle<String> name, int feedback_slot, LanguageMode language_mode, | 397 const Handle<String> name, int feedback_slot, LanguageMode language_mode, |
| 384 TypeofMode typeof_mode) { | 398 TypeofMode typeof_mode) { |
| 385 // TODO(rmcilroy): Potentially store language and typeof information in an | 399 // TODO(rmcilroy): Potentially store language and typeof information in an |
| 386 // operand rather than having extra bytecodes. | 400 // operand rather than having extra bytecodes. |
| 387 Bytecode bytecode = BytecodeForLoadGlobal(language_mode, typeof_mode); | 401 Bytecode bytecode = BytecodeForLoadGlobal(language_mode, typeof_mode); |
| 388 size_t name_index = GetConstantPoolEntry(name); | 402 size_t name_index = GetConstantPoolEntry(name); |
| 389 if (FitsInIdx8Operand(name_index) && FitsInIdx8Operand(feedback_slot)) { | 403 if (FitsInIdx8Operand(name_index) && FitsInIdx8Operand(feedback_slot)) { |
| 390 Output(bytecode, static_cast<uint8_t>(name_index), | 404 Output(bytecode, static_cast<uint8_t>(name_index), |
| 391 static_cast<uint8_t>(feedback_slot)); | 405 static_cast<uint8_t>(feedback_slot)); |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 return true; | 1170 return true; |
| 1157 } else if (reg.is_parameter()) { | 1171 } else if (reg.is_parameter()) { |
| 1158 int parameter_index = reg.ToParameterIndex(parameter_count_); | 1172 int parameter_index = reg.ToParameterIndex(parameter_count_); |
| 1159 return parameter_index >= 0 && parameter_index < parameter_count_; | 1173 return parameter_index >= 0 && parameter_index < parameter_count_; |
| 1160 } else if (reg.index() < fixed_register_count()) { | 1174 } else if (reg.index() < fixed_register_count()) { |
| 1161 return true; | 1175 return true; |
| 1162 } else { | 1176 } else { |
| 1163 return TemporaryRegisterIsLive(reg); | 1177 return TemporaryRegisterIsLive(reg); |
| 1164 } | 1178 } |
| 1165 } | 1179 } |
| 1180 case OperandType::kReg16: { |
| 1181 if (bytecode != Bytecode::kExchange && |
| 1182 bytecode != Bytecode::kExchangeWide) { |
| 1183 return false; |
| 1184 } |
| 1185 Register reg = |
| 1186 Register::FromWideOperand(static_cast<uint16_t>(operand_value)); |
| 1187 if (reg.is_function_context() || reg.is_function_closure() || |
| 1188 reg.is_new_target()) { |
| 1189 return false; |
| 1190 } else if (reg.is_parameter()) { |
| 1191 return false; |
| 1192 } else if (reg.index() < fixed_register_count()) { |
| 1193 return true; |
| 1194 } else { |
| 1195 return TemporaryRegisterIsLive(reg); |
| 1196 } |
| 1197 } |
| 1166 } | 1198 } |
| 1167 UNREACHABLE(); | 1199 UNREACHABLE(); |
| 1168 return false; | 1200 return false; |
| 1169 } | 1201 } |
| 1170 | 1202 |
| 1171 | 1203 |
| 1172 bool BytecodeArrayBuilder::LastBytecodeInSameBlock() const { | 1204 bool BytecodeArrayBuilder::LastBytecodeInSameBlock() const { |
| 1173 return last_bytecode_start_ < bytecodes()->size() && | 1205 return last_bytecode_start_ < bytecodes()->size() && |
| 1174 last_bytecode_start_ >= last_block_end_; | 1206 last_bytecode_start_ >= last_block_end_; |
| 1175 } | 1207 } |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1461 | 1493 |
| 1462 | 1494 |
| 1463 // static | 1495 // static |
| 1464 bool BytecodeArrayBuilder::FitsInIdx8Operand(size_t value) { | 1496 bool BytecodeArrayBuilder::FitsInIdx8Operand(size_t value) { |
| 1465 return value <= static_cast<size_t>(kMaxUInt8); | 1497 return value <= static_cast<size_t>(kMaxUInt8); |
| 1466 } | 1498 } |
| 1467 | 1499 |
| 1468 | 1500 |
| 1469 // static | 1501 // static |
| 1470 bool BytecodeArrayBuilder::FitsInImm8Operand(int value) { | 1502 bool BytecodeArrayBuilder::FitsInImm8Operand(int value) { |
| 1471 return kMinInt8 <= value && value < kMaxInt8; | 1503 return kMinInt8 <= value && value <= kMaxInt8; |
| 1472 } | 1504 } |
| 1473 | 1505 |
| 1474 | 1506 |
| 1475 // static | 1507 // static |
| 1476 bool BytecodeArrayBuilder::FitsInIdx16Operand(int value) { | 1508 bool BytecodeArrayBuilder::FitsInIdx16Operand(int value) { |
| 1477 return kMinUInt16 <= value && value <= kMaxUInt16; | 1509 return kMinUInt16 <= value && value <= kMaxUInt16; |
| 1478 } | 1510 } |
| 1479 | 1511 |
| 1480 | 1512 |
| 1481 // static | 1513 // static |
| 1482 bool BytecodeArrayBuilder::FitsInIdx16Operand(size_t value) { | 1514 bool BytecodeArrayBuilder::FitsInIdx16Operand(size_t value) { |
| 1483 return value <= static_cast<size_t>(kMaxUInt16); | 1515 return value <= static_cast<size_t>(kMaxUInt16); |
| 1484 } | 1516 } |
| 1485 | 1517 |
| 1486 | 1518 |
| 1519 // static |
| 1520 bool BytecodeArrayBuilder::FitsInReg8Operand(Register value) { |
| 1521 return kMinInt8 <= value.index() && value.index() <= kMaxInt8; |
| 1522 } |
| 1523 |
| 1524 |
| 1525 // static |
| 1526 bool BytecodeArrayBuilder::FitsInReg16Operand(Register value) { |
| 1527 return kMinInt16 <= value.index() && value.index() <= kMaxInt16; |
| 1528 } |
| 1529 |
| 1530 |
| 1487 TemporaryRegisterScope::TemporaryRegisterScope(BytecodeArrayBuilder* builder) | 1531 TemporaryRegisterScope::TemporaryRegisterScope(BytecodeArrayBuilder* builder) |
| 1488 : builder_(builder), | 1532 : builder_(builder), |
| 1489 allocated_(builder->zone()), | 1533 allocated_(builder->zone()), |
| 1490 next_consecutive_register_(-1), | 1534 next_consecutive_register_(-1), |
| 1491 next_consecutive_count_(-1) {} | 1535 next_consecutive_count_(-1) {} |
| 1492 | 1536 |
| 1493 | 1537 |
| 1494 TemporaryRegisterScope::~TemporaryRegisterScope() { | 1538 TemporaryRegisterScope::~TemporaryRegisterScope() { |
| 1495 for (auto i = allocated_.rbegin(); i != allocated_.rend(); i++) { | 1539 for (auto i = allocated_.rbegin(); i != allocated_.rend(); i++) { |
| 1496 builder_->ReturnTemporaryRegister(*i); | 1540 builder_->ReturnTemporaryRegister(*i); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 DCHECK_GT(next_consecutive_count_, 0); | 1587 DCHECK_GT(next_consecutive_count_, 0); |
| 1544 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); | 1588 builder_->BorrowConsecutiveTemporaryRegister(next_consecutive_register_); |
| 1545 allocated_.push_back(next_consecutive_register_); | 1589 allocated_.push_back(next_consecutive_register_); |
| 1546 next_consecutive_count_--; | 1590 next_consecutive_count_--; |
| 1547 return Register(next_consecutive_register_++); | 1591 return Register(next_consecutive_register_++); |
| 1548 } | 1592 } |
| 1549 | 1593 |
| 1550 } // namespace interpreter | 1594 } // namespace interpreter |
| 1551 } // namespace internal | 1595 } // namespace internal |
| 1552 } // namespace v8 | 1596 } // namespace v8 |
| OLD | NEW |