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

Unified Diff: src/interpreter/register-translator.cc

Issue 1613163002: [interpreter] Wide register support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added tests, fixed off-by-one error in register indicies. Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: src/interpreter/register-translator.cc
diff --git a/src/interpreter/register-translator.cc b/src/interpreter/register-translator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..625aaedee2d05d6ca90b81c42e545cdfb1fe0e63
--- /dev/null
+++ b/src/interpreter/register-translator.cc
@@ -0,0 +1,275 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/interpreter/register-translator.h"
+
+#include "src/interpreter/bytecode-array-builder.h"
+
+namespace v8 {
+namespace internal {
+namespace interpreter {
+
+RegisterTranslator::RegisterTranslator(RegisterMover* mover)
+ : mover_(mover), window_registers_count_(0), register_operands_count_(0) {}
+
+
+Register RegisterTranslator::Translate(Bytecode bytecode, Register reg) {
+ if (register_operands_count_ == 0) {
+ bytecode_ = bytecode;
+ }
+ DCHECK_EQ(bytecode, bytecode_);
rmcilroy 2016/01/22 17:50:57 I'm not sure what the point of passing bytecode to
+ DCHECK_LT(register_operands_count_,
+ static_cast<int>(arraysize(register_operands_)));
+ OperandType operand_type =
+ GetRegisterOperandType(bytecode, register_operands_count_);
+ Register translated_reg = Translate(reg);
+ Register addressable = MakeAddressable(translated_reg, operand_type);
+ register_operands_[register_operands_count_] = addressable.ToRawOperand();
rmcilroy 2016/01/22 17:50:57 Do we need to keep the register_operands_ in vecto
+ register_operands_count_ += 1;
+ if (addressable != translated_reg) {
+ Move(translated_reg, addressable, operand_type);
+ }
+ return addressable;
+}
+
+
+Register RegisterTranslator::MakeAddressable(Register translated_reg,
+ OperandType translated_reg_type) {
+ DCHECK(!InTranslationWindow(translated_reg));
+ OperandSize translated_reg_size =
+ Bytecodes::SizeOfOperand(translated_reg_type);
+ if (translated_reg_size == OperandSize::kByte &&
+ !FitsInReg8Operand(translated_reg)) {
+ // TODO(oth): Moves into and out from translation window could be
+ // decoupled if there were metadata to say whether the register was
+ // an input, output, or both.
+ Register destination(kTranslationWindowStart + window_registers_count_);
+ window_registers_[window_registers_count_] = translated_reg;
+ window_registers_count_ += 1;
+ DCHECK_LE(window_registers_count_, kTranslationWindowLength);
+ return destination;
+ } else {
+ return translated_reg;
+ }
+}
+
+
+void RegisterTranslator::Move(Register from, Register to,
+ OperandType to_operand_type) {
+ bool expect_movable = true;
+ if (to_operand_type != OperandType::kReg8) {
+ // Only tests should visit this path.
rmcilroy 2016/01/22 17:50:57 What test kick this path? It seems non-obvious tha
+ from = to = Register::IllegalRegister();
+ expect_movable = false;
+ }
+
+ bool movable = mover()->MoveRegisterUntranslated(from, to);
+ CHECK_EQ(expect_movable, movable);
+}
+
+
+void RegisterTranslator::CompleteTranslations() {
+ while (window_registers_count_ > 0) {
+ window_registers_count_ -= 1;
+ Register source(kTranslationWindowStart + window_registers_count_);
+ Register destination = window_registers_[window_registers_count_];
+ mover()->MoveRegisterUntranslated(source, destination);
+ }
+ register_operands_count_ = 0;
+ bytecode_ = static_cast<Bytecode>(-1);
+}
+
+
+bool RegisterTranslator::RegisterOperandsValid(Bytecode bytecode,
+ const uint32_t* const operands,
+ int operands_count) const {
+ if (bytecode != bytecode_ && bytecode == Bytecode::kMovWide) {
+ // Checking move emitted by register translator for bytecode_.
+ DCHECK_EQ(operands_count, 2);
+ Register from = Register::FromRawOperand(operands[0]);
+ Register to = Register::FromRawOperand(operands[1]);
+ return MoveIsValid(from, to);
+ } else if (register_operands_count_ == 0) {
+ DCHECK_EQ(Bytecodes::NumberOfRegisterOperands(bytecode), 0);
+ return true;
+ }
+
+ int reg_count = 0;
+ for (int i = 0; i < operands_count; i++) {
+ OperandType operand_type = Bytecodes::GetOperandType(bytecode, i);
+ bool next_operand_is_reg_count = false;
+ if (i != operands_count - 1) {
+ OperandType next_operand_type =
+ Bytecodes::GetOperandType(bytecode, i + 1);
+ next_operand_is_reg_count =
+ next_operand_type == OperandType::kRegCount8 ||
+ next_operand_type == OperandType::kRegCount16;
rmcilroy 2016/01/22 17:50:57 You don't seem to use next_operand_is_reg_count ?
+ }
+
+ Register reg;
+ int length = 0;
+ switch (operand_type) {
+ case OperandType::kNone:
+ UNREACHABLE();
+ return false;
+ case OperandType::kIdx8:
+ case OperandType::kIdx16:
+ case OperandType::kImm8:
+ case OperandType::kRegCount8:
+ case OperandType::kRegCount16:
+ break;
+ case OperandType::kMaybeReg8:
+ case OperandType::kMaybeReg16: {
+ DCHECK(next_operand_is_reg_count);
+ reg = Register::FromRawOperand(operands[i]);
+ length = static_cast<int>(operands[i + 1]);
+ break;
+ }
+ case OperandType::kRegPair8:
+ case OperandType::kRegPair16: {
+ reg = Register::FromRawOperand(operands[i]);
+ length = 2;
+ break;
+ }
+ case OperandType::kRegTriple8:
+ case OperandType::kRegTriple16: {
+ reg = Register::FromRawOperand(operands[i]);
+ length = 3;
+ break;
+ }
+ case OperandType::kReg8:
+ case OperandType::kReg16: {
+ reg = Register::FromRawOperand(operands[i]);
+ if (next_operand_is_reg_count) {
+ length = static_cast<int>(operands[i + 1]);
+ } else {
+ length = 1;
+ }
+ break;
+ }
+ }
+ if (reg.is_valid()) {
+ if (reg.ToRawOperand() != register_operands_[reg_count]) {
+ return false;
+ } else if (reg.index() < kTranslationWindowStart &&
+ reg.index() + length > kTranslationWindowStart) {
+ return false;
+ }
+ reg_count++;
+ }
+ }
+ return reg_count == Bytecodes::NumberOfRegisterOperands(bytecode) &&
+ reg_count == register_operands_count_;
+}
+
+
+bool RegisterTranslator::MoveIsValid(Register from, Register to) const {
+ // Checking a move bytecode ahead of emitting actual bytecode. The move
+ // is ensuring all register operands are reachable.
+ if (InTranslationWindow(to)) {
+ // Moving register into translation window.
+ DCHECK(!FitsInReg8Operand(from));
+ DCHECK(from.index() > kTranslationWindowLimit || !from.is_byte_operand());
+ DCHECK_GT(window_registers_count_, 0);
+ DCHECK_LE(window_registers_count_,
+ static_cast<int>(arraysize(window_registers_)));
+ Register last_window_register =
+ window_registers_[window_registers_count_ - 1];
+ return from == last_window_register;
+ } else if (InTranslationWindow(from)) {
+ // Moving register out of translation window.
+ DCHECK(!FitsInReg8Operand(to));
+ DCHECK(to.index() > kTranslationWindowLimit || !to.is_byte_operand());
+ DCHECK_GE(window_registers_count_, 0);
+ DCHECK_LT(window_registers_count_,
+ static_cast<int>(arraysize(window_registers_)));
+ Register last_window_register = window_registers_[window_registers_count_];
+ return to == last_window_register;
+ } else {
+ UNREACHABLE();
+ return false;
+ }
+}
+
+
+// static
+Register RegisterTranslator::Translate(Register reg) {
+ if (reg.index() >= kTranslationWindowStart) {
+ return Register(reg.index() + kTranslationWindowLength);
rmcilroy 2016/01/22 17:50:57 I wonder whether we should have a TranslatedRegist
+ } else {
+ return reg;
+ }
+}
+
+
+// static
+OperandType RegisterTranslator::GetRegisterOperandType(Bytecode bytecode,
+ int register_operand) {
+ int operand_count = Bytecodes::NumberOfOperands(bytecode);
+ for (int operand = 0; operand < operand_count; ++operand) {
rmcilroy 2016/01/22 17:50:56 Would it be possible to calculate this statically
+ OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand);
+ switch (operand_type) {
+#define REGISTER_OPERAND_CASE(op, _) case OperandType::k##op:
+ REGISTER_OPERAND_TYPE_LIST(REGISTER_OPERAND_CASE)
+#undef REGISTER_OPERAND_CASE
+ if (register_operand-- == 0) {
+ return operand_type;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ UNREACHABLE();
+ return OperandType::kNone;
+}
+
+
+// static
+bool RegisterTranslator::InTranslationWindow(Register reg) {
+ return (reg.index() >= kTranslationWindowStart &&
+ reg.index() <= kTranslationWindowLimit);
+}
+
+
+// static
+int RegisterTranslator::DistanceToTranslationWindow(Register reg) {
+ return kTranslationWindowStart - reg.index();
+}
+
+
+// static
+bool RegisterTranslator::FitsInReg8Operand(Register reg) {
+ return reg.is_byte_operand() && reg.index() < kTranslationWindowStart;
+}
+
+
+// static
+bool RegisterTranslator::FitsInReg16Operand(Register reg) {
+ int max_index = Register::MaxRegisterIndex() - kTranslationWindowLength + 1;
+ return reg.is_short_operand() && reg.index() < max_index;
+}
+
+
+// static
+int RegisterTranslator::RegisterCountAdjustment(int register_count,
+ int parameter_count) {
+ if (register_count > kTranslationWindowStart) {
+ return kTranslationWindowLength;
+ } else if (parameter_count > 0) {
+ Register param0 = Register::FromParameterIndex(0, parameter_count);
+ DCHECK_LT(param0.index(), 0);
+ if (param0.index() < kMinInt8) {
+ // TODO(oth): Translation window does not relocate when number of
+ // registers is small, but number of parameters is large enough to
+ // require translation. The frame may be 128 registers too large.
+ return kTranslationWindowLimit + 1 - register_count;
+ }
+ }
+ return 0;
+}
+
+} // namespace interpreter
+} // namespace internal
+} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698