Commit 95bec7e7 authored by oth's avatar oth Committed by Commit bot

[interpreter] Reduce move operations for wide register support.

Introduces the concept of transfer direction to register operands. This
enables the register translator to emit exactly the moves that a
bytecode having it's register operands translated needs.

BUG=v8:4280,v8:4675
LOG=N

Review URL: https://codereview.chromium.org/1633153002

Cr-Commit-Position: refs/heads/master@{#33544}
parent f22a5663
......@@ -305,31 +305,18 @@ Node* InterpreterAssembler::BytecodeOperandIdx(int operand_index) {
Node* InterpreterAssembler::BytecodeOperandReg(int operand_index) {
switch (interpreter::Bytecodes::GetOperandType(bytecode_, operand_index)) {
case interpreter::OperandType::kMaybeReg8:
case interpreter::OperandType::kReg8:
case interpreter::OperandType::kRegPair8:
case interpreter::OperandType::kRegTriple8:
DCHECK_EQ(
interpreter::OperandSize::kByte,
interpreter::Bytecodes::GetOperandSize(bytecode_, operand_index));
interpreter::OperandType operand_type =
interpreter::Bytecodes::GetOperandType(bytecode_, operand_index);
if (interpreter::Bytecodes::IsRegisterOperandType(operand_type)) {
interpreter::OperandSize operand_size =
interpreter::Bytecodes::SizeOfOperand(operand_type);
if (operand_size == interpreter::OperandSize::kByte) {
return BytecodeOperandSignExtended(operand_index);
case interpreter::OperandType::kMaybeReg16:
case interpreter::OperandType::kReg16:
case interpreter::OperandType::kRegPair16:
case interpreter::OperandType::kRegTriple16:
DCHECK_EQ(
interpreter::OperandSize::kShort,
interpreter::Bytecodes::GetOperandSize(bytecode_, operand_index));
} else if (operand_size == interpreter::OperandSize::kShort) {
return BytecodeOperandShortSignExtended(operand_index);
case interpreter::OperandType::kNone:
case interpreter::OperandType::kIdx8:
case interpreter::OperandType::kIdx16:
case interpreter::OperandType::kImm8:
case interpreter::OperandType::kRegCount8:
case interpreter::OperandType::kRegCount16:
UNREACHABLE();
}
}
UNREACHABLE();
return nullptr;
}
......
......@@ -401,25 +401,6 @@ void BytecodeArrayBuilder::MoveRegisterUntranslated(Register from,
Output(Bytecode::kMovWide, from.ToRawOperand(), to.ToRawOperand());
}
bool BytecodeArrayBuilder::RegisterOperandIsMovable(Bytecode bytecode,
int operand_index) {
// By design, we only support moving individual registers. There
// should be wide variants of such bytecodes instead to avoid the
// need for a large translation window.
OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index);
if (operand_type != OperandType::kReg8 &&
operand_type != OperandType::kReg16) {
return false;
} else if (operand_index + 1 == Bytecodes::NumberOfOperands(bytecode)) {
return true;
} else {
OperandType next_operand_type =
Bytecodes::GetOperandType(bytecode, operand_index + 1);
return (next_operand_type != OperandType::kRegCount8 &&
next_operand_type != OperandType::kRegCount16);
}
}
BytecodeArrayBuilder& BytecodeArrayBuilder::LoadGlobal(
const Handle<String> name, int feedback_slot, LanguageMode language_mode,
TypeofMode typeof_mode) {
......@@ -1413,8 +1394,11 @@ bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index,
}
// Fall-through to kReg8 case.
case OperandType::kReg8:
case OperandType::kRegOut8:
return RegisterIsValid(Register::FromRawOperand(operand_value),
operand_type);
case OperandType::kRegOutPair8:
case OperandType::kRegOutPair16:
case OperandType::kRegPair8:
case OperandType::kRegPair16: {
Register reg0 = Register::FromRawOperand(operand_value);
......@@ -1422,8 +1406,8 @@ bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index,
return RegisterIsValid(reg0, operand_type) &&
RegisterIsValid(reg1, operand_type);
}
case OperandType::kRegTriple8:
case OperandType::kRegTriple16: {
case OperandType::kRegOutTriple8:
case OperandType::kRegOutTriple16: {
Register reg0 = Register::FromRawOperand(operand_value);
Register reg1 = Register(reg0.index() + 1);
Register reg2 = Register(reg0.index() + 2);
......@@ -1436,7 +1420,8 @@ bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index,
return true;
}
// Fall-through to kReg16 case.
case OperandType::kReg16: {
case OperandType::kReg16:
case OperandType::kRegOut16: {
Register reg = Register::FromRawOperand(operand_value);
return RegisterIsValid(reg, operand_type);
}
......
......@@ -281,9 +281,8 @@ class BytecodeArrayBuilder final : private RegisterMover {
static bool FitsInReg16Operand(Register value);
static bool FitsInReg16OperandUntranslated(Register value);
// RegisterMover interface methods.
// RegisterMover interface.
void MoveRegisterUntranslated(Register from, Register to) override;
bool RegisterOperandIsMovable(Bytecode bytecode, int operand_index) override;
static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand);
static Bytecode GetJumpWithConstantWideOperand(Bytecode jump_smi8_operand);
......
......@@ -87,11 +87,7 @@ int BytecodeArrayIterator::GetIndexOperand(int operand_index) const {
Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const {
OperandType operand_type =
Bytecodes::GetOperandType(current_bytecode(), operand_index);
DCHECK(operand_type == OperandType::kReg8 ||
operand_type == OperandType::kRegPair8 ||
operand_type == OperandType::kRegTriple8 ||
operand_type == OperandType::kMaybeReg8 ||
operand_type == OperandType::kReg16);
DCHECK(Bytecodes::IsRegisterOperandType(operand_type));
uint32_t operand = GetRawOperand(operand_index, operand_type);
switch (Bytecodes::GetOperandSize(current_bytecode(), operand_index)) {
case OperandSize::kByte:
......
......@@ -262,6 +262,58 @@ bool Bytecodes::IsJumpOrReturn(Bytecode bytecode) {
return bytecode == Bytecode::kReturn || IsJump(bytecode);
}
// static
bool Bytecodes::IsRegisterOperandType(OperandType operand_type) {
switch (operand_type) {
#define CASE(Name, _) \
case OperandType::k##Name: \
return true;
REGISTER_OPERAND_TYPE_LIST(CASE)
#undef CASE
#define CASE(Name, _) \
case OperandType::k##Name: \
break;
NON_REGISTER_OPERAND_TYPE_LIST(CASE)
#undef CASE
}
return false;
}
// static
bool Bytecodes::IsRegisterInputOperandType(OperandType operand_type) {
switch (operand_type) {
#define CASE(Name, _) \
case OperandType::k##Name: \
return true;
REGISTER_INPUT_OPERAND_TYPE_LIST(CASE)
#undef CASE
#define CASE(Name, _) \
case OperandType::k##Name: \
break;
NON_REGISTER_OPERAND_TYPE_LIST(CASE)
REGISTER_OUTPUT_OPERAND_TYPE_LIST(CASE)
#undef CASE
}
return false;
}
// static
bool Bytecodes::IsRegisterOutputOperandType(OperandType operand_type) {
switch (operand_type) {
#define CASE(Name, _) \
case OperandType::k##Name: \
return true;
REGISTER_OUTPUT_OPERAND_TYPE_LIST(CASE)
#undef CASE
#define CASE(Name, _) \
case OperandType::k##Name: \
break;
NON_REGISTER_OPERAND_TYPE_LIST(CASE)
REGISTER_INPUT_OPERAND_TYPE_LIST(CASE)
#undef CASE
}
return false;
}
namespace {
static Register DecodeRegister(const uint8_t* operand_start,
......@@ -300,6 +352,7 @@ std::ostream& Bytecodes::Decode(std::ostream& os, const uint8_t* bytecode_start,
os << bytecode << " ";
int number_of_operands = NumberOfOperands(bytecode);
int range = 0;
for (int i = 0; i < number_of_operands; i++) {
OperandType op_type = GetOperandType(bytecode, i);
const uint8_t* operand_start =
......@@ -323,7 +376,9 @@ std::ostream& Bytecodes::Decode(std::ostream& os, const uint8_t* bytecode_start,
case interpreter::OperandType::kMaybeReg8:
case interpreter::OperandType::kMaybeReg16:
case interpreter::OperandType::kReg8:
case interpreter::OperandType::kReg16: {
case interpreter::OperandType::kReg16:
case interpreter::OperandType::kRegOut8:
case interpreter::OperandType::kRegOut16: {
Register reg = DecodeRegister(operand_start, op_type);
if (reg.is_current_context()) {
os << "<context>";
......@@ -343,12 +398,15 @@ std::ostream& Bytecodes::Decode(std::ostream& os, const uint8_t* bytecode_start,
}
break;
}
case interpreter::OperandType::kRegOutTriple8:
case interpreter::OperandType::kRegOutTriple16:
range += 1;
case interpreter::OperandType::kRegOutPair8:
case interpreter::OperandType::kRegOutPair16:
case interpreter::OperandType::kRegPair8:
case interpreter::OperandType::kRegTriple8:
case interpreter::OperandType::kRegPair16:
case interpreter::OperandType::kRegTriple16: {
case interpreter::OperandType::kRegPair16: {
range += 1;
Register reg = DecodeRegister(operand_start, op_type);
int range = op_type == interpreter::OperandType::kRegPair8 ? 1 : 2;
if (reg.is_parameter()) {
int parameter_index = reg.ToParameterIndex(parameter_count);
DCHECK_GT(parameter_index, 0);
......@@ -456,7 +514,6 @@ bool Register::is_new_target() const {
return index() == kNewTargetRegisterIndex;
}
int Register::MaxParameterIndex() { return kMaxParameterIndex; }
int Register::MaxRegisterIndex() { return kMaxRegisterIndex; }
......
......@@ -18,17 +18,25 @@ namespace interpreter {
#define INVALID_OPERAND_TYPE_LIST(V) \
V(None, OperandSize::kNone)
#define REGISTER_OPERAND_TYPE_LIST(V) \
/* Byte operands. */ \
V(MaybeReg8, OperandSize::kByte) \
V(Reg8, OperandSize::kByte) \
V(RegPair8, OperandSize::kByte) \
V(RegTriple8, OperandSize::kByte) \
/* Short operands. */ \
V(MaybeReg16, OperandSize::kShort) \
V(Reg16, OperandSize::kShort) \
V(RegPair16, OperandSize::kShort) \
V(RegTriple16, OperandSize::kShort)
#define REGISTER_INPUT_OPERAND_TYPE_LIST(V) \
/* Byte operands. */ \
V(MaybeReg8, OperandSize::kByte) \
V(Reg8, OperandSize::kByte) \
V(RegPair8, OperandSize::kByte) \
/* Short operands. */ \
V(MaybeReg16, OperandSize::kShort) \
V(Reg16, OperandSize::kShort) \
V(RegPair16, OperandSize::kShort)
#define REGISTER_OUTPUT_OPERAND_TYPE_LIST(V) \
/* Byte operands. */ \
V(RegOut8, OperandSize::kByte) \
V(RegOutPair8, OperandSize::kByte) \
V(RegOutTriple8, OperandSize::kByte) \
/* Short operands. */ \
V(RegOut16, OperandSize::kShort) \
V(RegOutPair16, OperandSize::kShort) \
V(RegOutTriple16, OperandSize::kShort)
#define SCALAR_OPERAND_TYPE_LIST(V) \
/* Byte operands. */ \
......@@ -39,12 +47,19 @@ namespace interpreter {
V(Idx16, OperandSize::kShort) \
V(RegCount16, OperandSize::kShort)
// The list of operand types used by bytecodes.
#define OPERAND_TYPE_LIST(V) \
INVALID_OPERAND_TYPE_LIST(V) \
REGISTER_OPERAND_TYPE_LIST(V) \
#define REGISTER_OPERAND_TYPE_LIST(V) \
REGISTER_INPUT_OPERAND_TYPE_LIST(V) \
REGISTER_OUTPUT_OPERAND_TYPE_LIST(V)
#define NON_REGISTER_OPERAND_TYPE_LIST(V) \
INVALID_OPERAND_TYPE_LIST(V) \
SCALAR_OPERAND_TYPE_LIST(V)
// The list of operand types used by bytecodes.
#define OPERAND_TYPE_LIST(V) \
NON_REGISTER_OPERAND_TYPE_LIST(V) \
REGISTER_OPERAND_TYPE_LIST(V)
// The list of bytecodes which are interpreted by the interpreter.
#define BYTECODE_LIST(V) \
\
......@@ -93,11 +108,11 @@ namespace interpreter {
\
/* Register-accumulator transfers */ \
V(Ldar, OperandType::kReg8) \
V(Star, OperandType::kReg8) \
V(Star, OperandType::kRegOut8) \
\
/* Register-register transfers */ \
V(Mov, OperandType::kReg8, OperandType::kReg8) \
V(MovWide, OperandType::kReg16, OperandType::kReg16) \
V(Mov, OperandType::kReg8, OperandType::kRegOut8) \
V(MovWide, OperandType::kReg16, OperandType::kRegOut16) \
\
/* LoadIC operations */ \
V(LoadICSloppy, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \
......@@ -159,9 +174,9 @@ namespace interpreter {
V(CallRuntimeWide, OperandType::kIdx16, OperandType::kMaybeReg16, \
OperandType::kRegCount8) \
V(CallRuntimeForPair, OperandType::kIdx16, OperandType::kMaybeReg8, \
OperandType::kRegCount8, OperandType::kRegPair8) \
OperandType::kRegCount8, OperandType::kRegOutPair8) \
V(CallRuntimeForPairWide, OperandType::kIdx16, OperandType::kMaybeReg16, \
OperandType::kRegCount8, OperandType::kRegPair16) \
OperandType::kRegCount8, OperandType::kRegOutPair16) \
V(CallJSRuntime, OperandType::kIdx16, OperandType::kReg8, \
OperandType::kRegCount8) \
V(CallJSRuntimeWide, OperandType::kIdx16, OperandType::kReg16, \
......@@ -235,8 +250,8 @@ namespace interpreter {
V(JumpIfUndefinedConstantWide, OperandType::kIdx16) \
\
/* Complex flow control For..in */ \
V(ForInPrepare, OperandType::kRegTriple8) \
V(ForInPrepareWide, OperandType::kRegTriple16) \
V(ForInPrepare, OperandType::kRegOutTriple8) \
V(ForInPrepareWide, OperandType::kRegOutTriple16) \
V(ForInDone, OperandType::kReg8, OperandType::kReg8) \
V(ForInNext, OperandType::kReg8, OperandType::kReg8, OperandType::kRegPair8) \
V(ForInNextWide, OperandType::kReg16, OperandType::kReg16, \
......@@ -248,7 +263,6 @@ namespace interpreter {
V(ReThrow, OperandType::kNone) \
V(Return, OperandType::kNone)
// Enumeration of the size classes of operand types used by bytecodes.
enum class OperandSize : uint8_t {
kNone = 0,
......@@ -382,10 +396,10 @@ class Bytecodes {
// Returns the number of register operands expected by |bytecode|.
static int NumberOfRegisterOperands(Bytecode bytecode);
// Return the i-th operand of |bytecode|.
// Returns the i-th operand of |bytecode|.
static OperandType GetOperandType(Bytecode bytecode, int i);
// Return the size of the i-th operand of |bytecode|.
// Returns the size of the i-th operand of |bytecode|.
static OperandSize GetOperandSize(Bytecode bytecode, int i);
// Returns the offset of the i-th operand of |bytecode| relative to the start
......@@ -430,13 +444,22 @@ class Bytecodes {
// constant pool entry (OperandType::kIdx16).
static bool IsJumpConstantWide(Bytecode bytecode);
// Return true if the bytecode is a jump or conditional jump taking
// Returns true if the bytecode is a jump or conditional jump taking
// any kind of operand.
static bool IsJump(Bytecode bytecode);
// Return true if the bytecode is a conditional jump, a jump, or a return.
// Returns true if the bytecode is a conditional jump, a jump, or a return.
static bool IsJumpOrReturn(Bytecode bytecode);
// Returns true if |operand_type| is any type of register operand.
static bool IsRegisterOperandType(OperandType operand_type);
// Returns true if |operand_type| represents a register used as an input.
static bool IsRegisterInputOperandType(OperandType operand_type);
// Returns true if |operand_type| represents a register used as an output.
static bool IsRegisterOutputOperandType(OperandType operand_type);
// Decode a single bytecode and operands to |os|.
static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start,
int number_of_parameters);
......
......@@ -11,7 +11,10 @@ namespace internal {
namespace interpreter {
RegisterTranslator::RegisterTranslator(RegisterMover* mover)
: mover_(mover), emitting_moves_(false), window_registers_count_(0) {}
: mover_(mover),
emitting_moves_(false),
window_registers_count_(0),
output_moves_count_(0) {}
void RegisterTranslator::TranslateInputRegisters(Bytecode bytecode,
uint32_t* raw_operands,
......@@ -29,6 +32,7 @@ void RegisterTranslator::TranslateInputRegisters(Bytecode bytecode,
Register out_reg = TranslateAndMove(bytecode, i, in_reg);
raw_operands[i] = out_reg.ToRawOperand();
}
window_registers_count_ = 0;
emitting_moves_ = false;
} else {
// When the register translator is translating registers, it will
......@@ -42,49 +46,70 @@ void RegisterTranslator::TranslateInputRegisters(Bytecode bytecode,
Register RegisterTranslator::TranslateAndMove(Bytecode bytecode,
int operand_index, Register reg) {
if (FitsInReg8Operand(reg)) {
return reg;
}
OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index);
OperandSize operand_size = Bytecodes::SizeOfOperand(operand_type);
if (operand_size == OperandSize::kShort) {
CHECK(FitsInReg16Operand(reg));
return Translate(reg);
}
CHECK((operand_type == OperandType::kReg8 ||
operand_type == OperandType::kRegOut8) &&
RegisterIsMovableToWindow(bytecode, operand_index));
Register translated_reg = Translate(reg);
Register addressable_reg = MakeAddressable(translated_reg, operand_type);
if (addressable_reg != translated_reg) {
CHECK(operand_type == OperandType::kReg8 &&
mover()->RegisterOperandIsMovable(bytecode, operand_index));
mover()->MoveRegisterUntranslated(translated_reg, addressable_reg);
Register window_reg(kTranslationWindowStart + window_registers_count_);
window_registers_count_ += 1;
if (Bytecodes::IsRegisterInputOperandType(operand_type)) {
DCHECK(!Bytecodes::IsRegisterOutputOperandType(operand_type));
mover()->MoveRegisterUntranslated(translated_reg, window_reg);
} else if (Bytecodes::IsRegisterOutputOperandType(operand_type)) {
DCHECK_LT(output_moves_count_, kTranslationWindowLength);
output_moves_[output_moves_count_] =
std::make_pair(window_reg, translated_reg);
output_moves_count_ += 1;
} else {
UNREACHABLE();
}
return window_reg;
}
// static
bool RegisterTranslator::RegisterIsMovableToWindow(Bytecode bytecode,
int operand_index) {
// By design, we only support moving individual registers. There
// should be wide variants of such bytecodes instead to avoid the
// need for a large translation window.
OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index);
if (operand_type != OperandType::kReg8 &&
operand_type != OperandType::kRegOut8) {
return false;
} else if (operand_index + 1 == Bytecodes::NumberOfOperands(bytecode)) {
return true;
} else {
OperandType next_operand_type =
Bytecodes::GetOperandType(bytecode, operand_index + 1);
return (next_operand_type != OperandType::kRegCount8 &&
next_operand_type != OperandType::kRegCount16);
}
return addressable_reg;
}
void RegisterTranslator::TranslateOutputRegisters() {
if (!emitting_moves_) {
emitting_moves_ = true;
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);
while (output_moves_count_ > 0) {
output_moves_count_ -= 1;
mover()->MoveRegisterUntranslated(
output_moves_[output_moves_count_].first,
output_moves_[output_moves_count_].second);
}
emitting_moves_ = false;
}
}
Register RegisterTranslator::MakeAddressable(Register reg,
OperandType reg_type) {
DCHECK(!InTranslationWindow(reg));
OperandSize reg_size = Bytecodes::SizeOfOperand(reg_type);
if (reg_size == OperandSize::kByte && !FitsInReg8Operand(reg)) {
// TODO(oth): Moves into and out from translation window could be
// decoupled if there were metadata to say whether the register
// operand was an input, output, or input-and-output for a given
// bytecode.
Register destination(kTranslationWindowStart + window_registers_count_);
window_registers_[window_registers_count_] = reg;
window_registers_count_ += 1;
DCHECK_LE(window_registers_count_, kTranslationWindowLength);
return destination;
} else {
return reg;
}
}
// static
Register RegisterTranslator::Translate(Register reg) {
if (reg.index() >= kTranslationWindowStart) {
......
......@@ -77,7 +77,8 @@ class RegisterTranslator final {
kTranslationWindowLimit - kTranslationWindowLength + 1;
Register TranslateAndMove(Bytecode bytecode, int operand_index, Register reg);
Register MakeAddressable(Register reg, OperandType reg_type);
static bool RegisterIsMovableToWindow(Bytecode bytecode, int operand_index);
static Register Translate(Register reg);
RegisterMover* mover() const { return mover_; }
......@@ -90,9 +91,12 @@ class RegisterTranslator final {
// translation.
bool emitting_moves_;
// State for restoring registers after bytecode.
Register window_registers_[kTranslationWindowLength];
// Number of window registers in use.
int window_registers_count_;
// State for restoring register moves emitted by TranslateOutputRegisters.
std::pair<Register, Register> output_moves_[kTranslationWindowLength];
int output_moves_count_;
};
// Interface for RegisterTranslator helper class that will emit
......@@ -106,11 +110,6 @@ class RegisterMover {
// of this method must be aware that register moves with bad
// register values are a security hole.
virtual void MoveRegisterUntranslated(Register from, Register to) = 0;
// Returns true if the register operand can be moved into the
// translation window.
virtual bool RegisterOperandIsMovable(Bytecode bytecode,
int operand_index) = 0;
};
} // namespace interpreter
......
This diff is collapsed.
......@@ -350,8 +350,10 @@ TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
break;
case interpreter::OperandType::kMaybeReg8:
case interpreter::OperandType::kReg8:
case interpreter::OperandType::kRegOut8:
case interpreter::OperandType::kRegOutPair8:
case interpreter::OperandType::kRegOutTriple8:
case interpreter::OperandType::kRegPair8:
case interpreter::OperandType::kRegTriple8:
EXPECT_THAT(m.BytecodeOperandReg(i),
m.IsBytecodeOperandSignExtended(offset));
break;
......@@ -365,8 +367,10 @@ TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
break;
case interpreter::OperandType::kMaybeReg16:
case interpreter::OperandType::kReg16:
case interpreter::OperandType::kRegOut16:
case interpreter::OperandType::kRegOutPair16:
case interpreter::OperandType::kRegOutTriple16:
case interpreter::OperandType::kRegPair16:
case interpreter::OperandType::kRegTriple16:
EXPECT_THAT(m.BytecodeOperandReg(i),
m.IsBytecodeOperandShortSignExtended(offset));
break;
......
......@@ -43,7 +43,6 @@ TEST(OperandConversion, Registers) {
}
}
TEST(OperandConversion, Parameters) {
int parameter_counts[] = {7, 13, 99};
......@@ -59,7 +58,6 @@ TEST(OperandConversion, Parameters) {
}
}
TEST(OperandConversion, RegistersParametersNoOverlap) {
int register_count = Register::MaxRegisterIndex() + 1;
int parameter_count = Register::MaxParameterIndex() + 1;
......@@ -118,6 +116,46 @@ TEST(Bytecodes, RegisterOperandBitmaps) {
CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kForInNext), 7);
}
TEST(Bytecodes, RegisterOperands) {
CHECK(Bytecodes::IsRegisterOperandType(OperandType::kReg8));
CHECK(Bytecodes::IsRegisterInputOperandType(OperandType::kReg8));
CHECK(!Bytecodes::IsRegisterOutputOperandType(OperandType::kReg8));
CHECK(!Bytecodes::IsRegisterInputOperandType(OperandType::kRegOut8));
CHECK(Bytecodes::IsRegisterOutputOperandType(OperandType::kRegOut8));
#define IS_REGISTER_OPERAND_TYPE(Name, _) \
CHECK(Bytecodes::IsRegisterOperandType(OperandType::k##Name));
REGISTER_OPERAND_TYPE_LIST(IS_REGISTER_OPERAND_TYPE)
#undef IS_REGISTER_OPERAND_TYPE
#define IS_NOT_REGISTER_OPERAND_TYPE(Name, _) \
CHECK(!Bytecodes::IsRegisterOperandType(OperandType::k##Name));
NON_REGISTER_OPERAND_TYPE_LIST(IS_NOT_REGISTER_OPERAND_TYPE)
#undef IS_NOT_REGISTER_OPERAND_TYPE
#define IS_REGISTER_INPUT_OPERAND_TYPE(Name, _) \
CHECK(Bytecodes::IsRegisterInputOperandType(OperandType::k##Name));
REGISTER_INPUT_OPERAND_TYPE_LIST(IS_REGISTER_INPUT_OPERAND_TYPE)
#undef IS_REGISTER_INPUT_OPERAND_TYPE
#define IS_NOT_REGISTER_INPUT_OPERAND_TYPE(Name, _) \
CHECK(!Bytecodes::IsRegisterInputOperandType(OperandType::k##Name));
NON_REGISTER_OPERAND_TYPE_LIST(IS_NOT_REGISTER_INPUT_OPERAND_TYPE);
REGISTER_OUTPUT_OPERAND_TYPE_LIST(IS_NOT_REGISTER_INPUT_OPERAND_TYPE)
#undef IS_NOT_REGISTER_INPUT_OPERAND_TYPE
#define IS_REGISTER_OUTPUT_OPERAND_TYPE(Name, _) \
CHECK(Bytecodes::IsRegisterOutputOperandType(OperandType::k##Name));
REGISTER_OUTPUT_OPERAND_TYPE_LIST(IS_REGISTER_OUTPUT_OPERAND_TYPE)
#undef IS_REGISTER_OUTPUT_OPERAND_TYPE
#define IS_NOT_REGISTER_OUTPUT_OPERAND_TYPE(Name, _) \
CHECK(!Bytecodes::IsRegisterOutputOperandType(OperandType::k##Name));
NON_REGISTER_OPERAND_TYPE_LIST(IS_NOT_REGISTER_OUTPUT_OPERAND_TYPE)
REGISTER_INPUT_OPERAND_TYPE_LIST(IS_NOT_REGISTER_OUTPUT_OPERAND_TYPE)
#undef IS_NOT_REGISTER_INPUT_OPERAND_TYPE
}
} // namespace interpreter
} // namespace internal
} // namespace v8
......@@ -27,10 +27,14 @@ class RegisterTranslatorTest : public TestWithIsolateAndZone,
~RegisterTranslatorTest() override {}
bool PopMoveAndMatch(Register from, Register to) {
CHECK(from.is_valid() && to.is_valid());
const std::pair<Register, Register> top = moves_.top();
moves_.pop();
return top.first == from && top.second == to;
if (!moves_.empty()) {
CHECK(from.is_valid() && to.is_valid());
const std::pair<Register, Register> top = moves_.top();
moves_.pop();
return top.first == from && top.second == to;
} else {
return false;
}
}
int move_count() const { return move_count_; }
......@@ -49,23 +53,6 @@ class RegisterTranslatorTest : public TestWithIsolateAndZone,
move_count_++;
}
bool RegisterOperandIsMovable(Bytecode bytecode, int operand_index) override {
OperandType operand_type =
Bytecodes::GetOperandType(bytecode, operand_index);
if (operand_type == OperandType::kReg8 ||
operand_type == OperandType::kReg16) {
if (operand_index == Bytecodes::NumberOfOperands(bytecode) - 1) {
return true;
}
OperandType next_operand_type =
Bytecodes::GetOperandType(bytecode, operand_index + 1);
return (next_operand_type != OperandType::kRegCount8 &&
next_operand_type != OperandType::kRegCount16);
} else {
return false;
}
}
RegisterTranslator translator_;
std::stack<std::pair<Register, Register>> moves_;
int move_count_;
......@@ -74,7 +61,8 @@ class RegisterTranslatorTest : public TestWithIsolateAndZone,
};
const char* const RegisterTranslatorTest::kBadOperandRegex =
".*OperandType::kReg8 && mover\\(\\)->RegisterOperandIsMovable.*";
".*OperandType::kReg8 \\|\\| .*OperandType::kRegOut8\\) && "
"RegisterIsMovableToWindow.*";
TEST_F(RegisterTranslatorTest, TestFrameSizeAdjustmentsForTranslationWindow) {
EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(0, 0));
......@@ -157,7 +145,7 @@ TEST_F(RegisterTranslatorTest, NoTranslationRequired) {
Register param_reg = Register::FromParameterIndex(129, 130);
operands[0] = param_reg.ToRawOperand();
translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1);
translator()->TranslateInputRegisters(Bytecode::kAdd, operands, 1);
translator()->TranslateOutputRegisters();
EXPECT_EQ(0, move_count());
}
......@@ -172,6 +160,14 @@ TEST_F(RegisterTranslatorTest, TranslationRequired) {
EXPECT_EQ(1, move_count());
EXPECT_TRUE(PopMoveAndMatch(local_reg_translated, window_reg));
translator()->TranslateOutputRegisters();
EXPECT_EQ(1, move_count());
EXPECT_FALSE(PopMoveAndMatch(window_reg, local_reg_translated));
operands[0] = local_reg.ToRawOperand();
translator()->TranslateInputRegisters(Bytecode::kStar, operands, 1);
EXPECT_EQ(1, move_count());
EXPECT_FALSE(PopMoveAndMatch(local_reg_translated, window_reg));
translator()->TranslateOutputRegisters();
EXPECT_EQ(2, move_count());
EXPECT_TRUE(PopMoveAndMatch(window_reg, local_reg_translated));
......@@ -181,6 +177,14 @@ TEST_F(RegisterTranslatorTest, TranslationRequired) {
EXPECT_EQ(3, move_count());
EXPECT_TRUE(PopMoveAndMatch(param_reg, window_reg));
translator()->TranslateOutputRegisters();
EXPECT_EQ(3, move_count());
EXPECT_FALSE(PopMoveAndMatch(window_reg, param_reg));
operands[0] = {param_reg.ToRawOperand()};
translator()->TranslateInputRegisters(Bytecode::kStar, operands, 1);
EXPECT_EQ(3, move_count());
EXPECT_FALSE(PopMoveAndMatch(local_reg_translated, window_reg));
translator()->TranslateOutputRegisters();
EXPECT_EQ(4, move_count());
EXPECT_TRUE(PopMoveAndMatch(window_reg, param_reg));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment