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