Commit 1dd0988a authored by Seth Brenith's avatar Seth Brenith Committed by Commit Bot

[interpreter] Rename AccumulatorUse so it can be expanded for short star

In https://chromium-review.googlesource.com/c/v8/v8/+/2641180 , we are
discussing renaming AccumulatorUse. To avoid polluting that change with
a large mechanical find&replace, I've created a separate change for the
renaming.

Change-Id: Ibc7e438f9e719571c9237e7e08ba86562a3c679f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2684923Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#72679}
parent 34ea1904
......@@ -327,7 +327,7 @@ class OperandHelper<OperandType::kRegOutTriple> {
} // namespace
template <Bytecode bytecode, AccumulatorUse accumulator_use,
template <Bytecode bytecode, ImplicitRegisterUse implicit_register_use,
OperandType... operand_types>
class BytecodeNodeBuilder {
public:
......@@ -336,7 +336,7 @@ class BytecodeNodeBuilder {
Operands... operands) {
static_assert(sizeof...(Operands) <= Bytecodes::kMaxOperands,
"too many operands for bytecode");
builder->PrepareToOutputBytecode<bytecode, accumulator_use>();
builder->PrepareToOutputBytecode<bytecode, implicit_register_use>();
// The "OperandHelper<operand_types>::Convert(builder, operands)..." will
// expand both the OperandType... and Operands... parameter packs e.g. for:
// BytecodeNodeBuilder<OperandType::kReg, OperandType::kImm>::Make<
......@@ -344,7 +344,8 @@ class BytecodeNodeBuilder {
// the code will expand into:
// OperandHelper<OperandType::kReg>::Convert(builder, reg),
// OperandHelper<OperandType::kImm>::Convert(builder, immediate),
return BytecodeNode::Create<bytecode, accumulator_use, operand_types...>(
return BytecodeNode::Create<bytecode, implicit_register_use,
operand_types...>(
builder->CurrentSourcePosition(bytecode),
OperandHelper<operand_types>::Convert(builder, operands)...);
}
......@@ -1598,10 +1599,10 @@ bool BytecodeArrayBuilder::RegisterListIsValid(RegisterList reg_list) const {
}
}
template <Bytecode bytecode, AccumulatorUse accumulator_use>
template <Bytecode bytecode, ImplicitRegisterUse implicit_register_use>
void BytecodeArrayBuilder::PrepareToOutputBytecode() {
if (register_optimizer_)
register_optimizer_->PrepareForBytecode<bytecode, accumulator_use>();
register_optimizer_->PrepareForBytecode<bytecode, implicit_register_use>();
}
uint32_t BytecodeArrayBuilder::GetInputRegisterOperand(Register reg) {
......
......@@ -567,7 +567,7 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final {
private:
friend class BytecodeRegisterAllocator;
template <Bytecode bytecode, AccumulatorUse accumulator_use,
template <Bytecode bytecode, ImplicitRegisterUse implicit_register_use,
OperandType... operand_types>
friend class BytecodeNodeBuilder;
......@@ -613,7 +613,7 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final {
// during bytecode generation.
BytecodeArrayBuilder& Illegal();
template <Bytecode bytecode, AccumulatorUse accumulator_use>
template <Bytecode bytecode, ImplicitRegisterUse implicit_register_use>
void PrepareToOutputBytecode();
BytecodeArrayWriter* bytecode_array_writer() {
......
......@@ -253,7 +253,8 @@ void BytecodeArrayWriter::MaybeElideLastBytecode(Bytecode next_bytecode,
// and the next bytecode clobbers this load without reading the accumulator,
// then the previous bytecode can be elided as it has no effect.
if (Bytecodes::IsAccumulatorLoadWithoutEffects(last_bytecode_) &&
Bytecodes::GetAccumulatorUse(next_bytecode) == AccumulatorUse::kWrite &&
Bytecodes::GetImplicitRegisterUse(next_bytecode) ==
ImplicitRegisterUse::kWriteAccumulator &&
(!last_bytecode_had_source_info_ || !has_source_info)) {
DCHECK_GT(bytecodes()->size(), last_bytecode_offset_);
bytecodes()->resize(last_bytecode_offset_);
......
......@@ -127,7 +127,7 @@ class V8_EXPORT_PRIVATE BytecodeNode final {
bool operator!=(const BytecodeNode& other) const { return !(*this == other); }
private:
template <Bytecode bytecode, AccumulatorUse accumulator_use,
template <Bytecode bytecode, ImplicitRegisterUse implicit_register_use,
OperandType... operand_types>
friend class BytecodeNodeBuilder;
......@@ -148,12 +148,12 @@ class V8_EXPORT_PRIVATE BytecodeNode final {
operands_[4] = operand4;
}
template <Bytecode bytecode, AccumulatorUse accum_use>
template <Bytecode bytecode, ImplicitRegisterUse accum_use>
V8_INLINE static BytecodeNode Create(BytecodeSourceInfo source_info) {
return BytecodeNode(bytecode, 0, OperandScale::kSingle, source_info);
}
template <Bytecode bytecode, AccumulatorUse accum_use,
template <Bytecode bytecode, ImplicitRegisterUse accum_use,
OperandType operand0_type>
V8_INLINE static BytecodeNode Create(BytecodeSourceInfo source_info,
uint32_t operand0) {
......@@ -163,7 +163,7 @@ class V8_EXPORT_PRIVATE BytecodeNode final {
return BytecodeNode(bytecode, 1, scale, source_info, operand0);
}
template <Bytecode bytecode, AccumulatorUse accum_use,
template <Bytecode bytecode, ImplicitRegisterUse accum_use,
OperandType operand0_type, OperandType operand1_type>
V8_INLINE static BytecodeNode Create(BytecodeSourceInfo source_info,
uint32_t operand0, uint32_t operand1) {
......@@ -175,7 +175,7 @@ class V8_EXPORT_PRIVATE BytecodeNode final {
return BytecodeNode(bytecode, 2, scale, source_info, operand0, operand1);
}
template <Bytecode bytecode, AccumulatorUse accum_use,
template <Bytecode bytecode, ImplicitRegisterUse accum_use,
OperandType operand0_type, OperandType operand1_type,
OperandType operand2_type>
V8_INLINE static BytecodeNode Create(BytecodeSourceInfo source_info,
......@@ -192,7 +192,7 @@ class V8_EXPORT_PRIVATE BytecodeNode final {
operand2);
}
template <Bytecode bytecode, AccumulatorUse accum_use,
template <Bytecode bytecode, ImplicitRegisterUse accum_use,
OperandType operand0_type, OperandType operand1_type,
OperandType operand2_type, OperandType operand3_type>
V8_INLINE static BytecodeNode Create(BytecodeSourceInfo source_info,
......@@ -211,7 +211,7 @@ class V8_EXPORT_PRIVATE BytecodeNode final {
operand2, operand3);
}
template <Bytecode bytecode, AccumulatorUse accum_use,
template <Bytecode bytecode, ImplicitRegisterUse accum_use,
OperandType operand0_type, OperandType operand1_type,
OperandType operand2_type, OperandType operand3_type,
OperandType operand4_type>
......
......@@ -12,15 +12,16 @@ namespace interpreter {
namespace {
const char* AccumulatorUseToString(AccumulatorUse accumulator_use) {
switch (accumulator_use) {
case AccumulatorUse::kNone:
const char* ImplicitRegisterUseToString(
ImplicitRegisterUse implicit_register_use) {
switch (implicit_register_use) {
case ImplicitRegisterUse::kNone:
return "None";
case AccumulatorUse::kRead:
case ImplicitRegisterUse::kReadAccumulator:
return "Read";
case AccumulatorUse::kWrite:
case ImplicitRegisterUse::kWriteAccumulator:
return "Write";
case AccumulatorUse::kReadWrite:
case ImplicitRegisterUse::kReadWriteAccumulator:
return "ReadWrite";
}
UNREACHABLE();
......@@ -64,8 +65,8 @@ const char* OperandSizeToString(OperandSize operand_size) {
} // namespace
std::ostream& operator<<(std::ostream& os, const AccumulatorUse& use) {
return os << AccumulatorUseToString(use);
std::ostream& operator<<(std::ostream& os, const ImplicitRegisterUse& use) {
return os << ImplicitRegisterUseToString(use);
}
std::ostream& operator<<(std::ostream& os, const OperandSize& operand_size) {
......
......@@ -109,27 +109,27 @@ enum class OperandType : uint8_t {
#undef COUNT_OPERAND_TYPES
};
enum class AccumulatorUse : uint8_t {
enum class ImplicitRegisterUse : uint8_t {
kNone = 0,
kRead = 1 << 0,
kWrite = 1 << 1,
kReadWrite = kRead | kWrite
kReadAccumulator = 1 << 0,
kWriteAccumulator = 1 << 1,
kReadWriteAccumulator = kReadAccumulator | kWriteAccumulator
};
constexpr inline AccumulatorUse operator&(AccumulatorUse lhs,
AccumulatorUse rhs) {
return static_cast<AccumulatorUse>(static_cast<int>(lhs) &
static_cast<int>(rhs));
constexpr inline ImplicitRegisterUse operator&(ImplicitRegisterUse lhs,
ImplicitRegisterUse rhs) {
return static_cast<ImplicitRegisterUse>(static_cast<int>(lhs) &
static_cast<int>(rhs));
}
constexpr inline AccumulatorUse operator|(AccumulatorUse lhs,
AccumulatorUse rhs) {
return static_cast<AccumulatorUse>(static_cast<int>(lhs) |
static_cast<int>(rhs));
constexpr inline ImplicitRegisterUse operator|(ImplicitRegisterUse lhs,
ImplicitRegisterUse rhs) {
return static_cast<ImplicitRegisterUse>(static_cast<int>(lhs) |
static_cast<int>(rhs));
}
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
const AccumulatorUse& use);
const ImplicitRegisterUse& use);
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
const OperandScale& operand_scale);
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
......@@ -170,14 +170,20 @@ class BytecodeOperands : public AllStatic {
return static_cast<int>(operand_scale) >> 1;
}
// Returns true if |accumulator_use| reads the accumulator.
static constexpr bool ReadsAccumulator(AccumulatorUse accumulator_use) {
return (accumulator_use & AccumulatorUse::kRead) == AccumulatorUse::kRead;
// Returns true if |implicit_register_use| reads the
// accumulator.
static constexpr bool ReadsAccumulator(
ImplicitRegisterUse implicit_register_use) {
return (implicit_register_use & ImplicitRegisterUse::kReadAccumulator) ==
ImplicitRegisterUse::kReadAccumulator;
}
// Returns true if |accumulator_use| writes the accumulator.
static constexpr bool WritesAccumulator(AccumulatorUse accumulator_use) {
return (accumulator_use & AccumulatorUse::kWrite) == AccumulatorUse::kWrite;
// Returns true if |implicit_register_use| writes the
// accumulator.
static constexpr bool WritesAccumulator(
ImplicitRegisterUse implicit_register_use) {
return (implicit_register_use & ImplicitRegisterUse::kWriteAccumulator) ==
ImplicitRegisterUse::kWriteAccumulator;
}
// Returns true if |operand_type| is a scalable signed byte.
......
......@@ -65,7 +65,7 @@ class V8_EXPORT_PRIVATE BytecodeRegisterOptimizer final
bool EnsureAllRegistersAreFlushed() const;
// Prepares for |bytecode|.
template <Bytecode bytecode, AccumulatorUse accumulator_use>
template <Bytecode bytecode, ImplicitRegisterUse implicit_register_use>
V8_INLINE void PrepareForBytecode() {
if (Bytecodes::IsJump(bytecode) || Bytecodes::IsSwitch(bytecode) ||
bytecode == Bytecode::kDebugger ||
......@@ -85,13 +85,13 @@ class V8_EXPORT_PRIVATE BytecodeRegisterOptimizer final
// Materialize the accumulator if it is read by the bytecode. The
// accumulator is special and no other register can be materialized
// in it's place.
if (BytecodeOperands::ReadsAccumulator(accumulator_use)) {
if (BytecodeOperands::ReadsAccumulator(implicit_register_use)) {
Materialize(accumulator_info_);
}
// Materialize an equivalent to the accumulator if it will be
// clobbered when the bytecode is dispatched.
if (BytecodeOperands::WritesAccumulator(accumulator_use)) {
if (BytecodeOperands::WritesAccumulator(implicit_register_use)) {
PrepareOutputRegister(accumulator_);
}
}
......
......@@ -76,7 +76,7 @@ struct SumHelper<value, values...> {
static const int kValue = value + SumHelper<values...>::kValue;
};
template <AccumulatorUse accumulator_use, OperandType... operands>
template <ImplicitRegisterUse implicit_register_use, OperandType... operands>
struct BytecodeTraits {
static const OperandType kOperandTypes[];
static const OperandTypeInfo kOperandTypeInfos[];
......@@ -89,33 +89,33 @@ struct BytecodeTraits {
1, OperandScaler<operands, OperandScale::kDouble>::kSize...>::kValue;
static const int kQuadrupleScaleSize = SumHelper<
1, OperandScaler<operands, OperandScale::kQuadruple>::kSize...>::kValue;
static const AccumulatorUse kAccumulatorUse = accumulator_use;
static const ImplicitRegisterUse kImplicitRegisterUse = implicit_register_use;
static const int kOperandCount = sizeof...(operands);
};
template <AccumulatorUse accumulator_use, OperandType... operands>
template <ImplicitRegisterUse implicit_register_use, OperandType... operands>
STATIC_CONST_MEMBER_DEFINITION const OperandType
BytecodeTraits<accumulator_use, operands...>::kOperandTypes[] = {
BytecodeTraits<implicit_register_use, operands...>::kOperandTypes[] = {
operands...};
template <AccumulatorUse accumulator_use, OperandType... operands>
template <ImplicitRegisterUse implicit_register_use, OperandType... operands>
STATIC_CONST_MEMBER_DEFINITION const OperandTypeInfo
BytecodeTraits<accumulator_use, operands...>::kOperandTypeInfos[] = {
BytecodeTraits<implicit_register_use, operands...>::kOperandTypeInfos[] = {
OperandTraits<operands>::kOperandTypeInfo...};
template <AccumulatorUse accumulator_use, OperandType... operands>
STATIC_CONST_MEMBER_DEFINITION const OperandSize
BytecodeTraits<accumulator_use, operands...>::kSingleScaleOperandSizes[] = {
OperandScaler<operands, OperandScale::kSingle>::kOperandSize...};
template <AccumulatorUse accumulator_use, OperandType... operands>
STATIC_CONST_MEMBER_DEFINITION const OperandSize
BytecodeTraits<accumulator_use, operands...>::kDoubleScaleOperandSizes[] = {
OperandScaler<operands, OperandScale::kDouble>::kOperandSize...};
template <AccumulatorUse accumulator_use, OperandType... operands>
template <ImplicitRegisterUse implicit_register_use, OperandType... operands>
STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits<
implicit_register_use, operands...>::kSingleScaleOperandSizes[] = {
OperandScaler<operands, OperandScale::kSingle>::kOperandSize...};
template <ImplicitRegisterUse implicit_register_use, OperandType... operands>
STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits<
implicit_register_use, operands...>::kDoubleScaleOperandSizes[] = {
OperandScaler<operands, OperandScale::kDouble>::kOperandSize...};
template <ImplicitRegisterUse implicit_register_use, OperandType... operands>
STATIC_CONST_MEMBER_DEFINITION const OperandSize BytecodeTraits<
accumulator_use, operands...>::kQuadrupleScaleOperandSizes[] = {
implicit_register_use, operands...>::kQuadrupleScaleOperandSizes[] = {
OperandScaler<operands, OperandScale::kQuadruple>::kOperandSize...};
template <AccumulatorUse accumulator_use>
struct BytecodeTraits<accumulator_use> {
template <ImplicitRegisterUse implicit_register_use>
struct BytecodeTraits<implicit_register_use> {
static const OperandType kOperandTypes[];
static const OperandTypeInfo kOperandTypeInfos[];
static const OperandSize kSingleScaleOperandSizes[];
......@@ -124,28 +124,29 @@ struct BytecodeTraits<accumulator_use> {
static const int kSingleScaleSize = 1;
static const int kDoubleScaleSize = 1;
static const int kQuadrupleScaleSize = 1;
static const AccumulatorUse kAccumulatorUse = accumulator_use;
static const ImplicitRegisterUse kImplicitRegisterUse = implicit_register_use;
static const int kOperandCount = 0;
};
template <AccumulatorUse accumulator_use>
template <ImplicitRegisterUse implicit_register_use>
STATIC_CONST_MEMBER_DEFINITION const OperandType
BytecodeTraits<accumulator_use>::kOperandTypes[] = {OperandType::kNone};
template <AccumulatorUse accumulator_use>
BytecodeTraits<implicit_register_use>::kOperandTypes[] = {
OperandType::kNone};
template <ImplicitRegisterUse implicit_register_use>
STATIC_CONST_MEMBER_DEFINITION const OperandTypeInfo
BytecodeTraits<accumulator_use>::kOperandTypeInfos[] = {
BytecodeTraits<implicit_register_use>::kOperandTypeInfos[] = {
OperandTypeInfo::kNone};
template <AccumulatorUse accumulator_use>
template <ImplicitRegisterUse implicit_register_use>
STATIC_CONST_MEMBER_DEFINITION const OperandSize
BytecodeTraits<accumulator_use>::kSingleScaleOperandSizes[] = {
BytecodeTraits<implicit_register_use>::kSingleScaleOperandSizes[] = {
OperandSize::kNone};
template <AccumulatorUse accumulator_use>
template <ImplicitRegisterUse implicit_register_use>
STATIC_CONST_MEMBER_DEFINITION const OperandSize
BytecodeTraits<accumulator_use>::kDoubleScaleOperandSizes[] = {
BytecodeTraits<implicit_register_use>::kDoubleScaleOperandSizes[] = {
OperandSize::kNone};
template <AccumulatorUse accumulator_use>
template <ImplicitRegisterUse implicit_register_use>
STATIC_CONST_MEMBER_DEFINITION const OperandSize
BytecodeTraits<accumulator_use>::kQuadrupleScaleOperandSizes[] = {
BytecodeTraits<implicit_register_use>::kQuadrupleScaleOperandSizes[] = {
OperandSize::kNone};
} // namespace interpreter
......
......@@ -32,8 +32,8 @@ const int Bytecodes::kOperandCount[] = {
#undef ENTRY
};
const AccumulatorUse Bytecodes::kAccumulatorUse[] = {
#define ENTRY(Name, ...) BytecodeTraits<__VA_ARGS__>::kAccumulatorUse,
const ImplicitRegisterUse Bytecodes::kImplicitRegisterUse[] = {
#define ENTRY(Name, ...) BytecodeTraits<__VA_ARGS__>::kImplicitRegisterUse,
BYTECODE_LIST(ENTRY)
#undef ENTRY
};
......
This diff is collapsed.
......@@ -42,7 +42,7 @@ InterpreterAssembler::InterpreterAssembler(CodeAssemblerState* state,
TVARIABLE_CONSTRUCTOR(
accumulator_,
Parameter<Object>(InterpreterDispatchDescriptor::kAccumulator)),
accumulator_use_(AccumulatorUse::kNone),
implicit_register_use_(ImplicitRegisterUse::kNone),
made_call_(false),
reloaded_frame_ptr_(false),
bytecode_array_valid_(true) {
......@@ -64,7 +64,8 @@ InterpreterAssembler::~InterpreterAssembler() {
// If the following check fails the handler does not use the
// accumulator in the way described in the bytecode definitions in
// bytecodes.h.
DCHECK_EQ(accumulator_use_, Bytecodes::GetAccumulatorUse(bytecode_));
DCHECK_EQ(implicit_register_use_,
Bytecodes::GetImplicitRegisterUse(bytecode_));
UnregisterCallGenerationCallbacks();
}
......@@ -154,13 +155,15 @@ TNode<Object> InterpreterAssembler::GetAccumulatorUnchecked() {
TNode<Object> InterpreterAssembler::GetAccumulator() {
DCHECK(Bytecodes::ReadsAccumulator(bytecode_));
accumulator_use_ = accumulator_use_ | AccumulatorUse::kRead;
implicit_register_use_ =
implicit_register_use_ | ImplicitRegisterUse::kReadAccumulator;
return TaggedPoisonOnSpeculation(GetAccumulatorUnchecked());
}
void InterpreterAssembler::SetAccumulator(TNode<Object> value) {
DCHECK(Bytecodes::WritesAccumulator(bytecode_));
accumulator_use_ = accumulator_use_ | AccumulatorUse::kWrite;
implicit_register_use_ =
implicit_register_use_ | ImplicitRegisterUse::kWriteAccumulator;
accumulator_ = value;
}
......@@ -754,7 +757,8 @@ void InterpreterAssembler::CallJSAndDispatch(
args_count, args.base_reg_location(),
function);
// TailCallStubThenDispatch updates accumulator with result.
accumulator_use_ = accumulator_use_ | AccumulatorUse::kWrite;
implicit_register_use_ =
implicit_register_use_ | ImplicitRegisterUse::kWriteAccumulator;
}
template <class... TArgs>
......@@ -780,7 +784,8 @@ void InterpreterAssembler::CallJSAndDispatch(TNode<Object> function,
context, function, arg_count, args...);
}
// TailCallStubThenDispatch updates accumulator with result.
accumulator_use_ = accumulator_use_ | AccumulatorUse::kWrite;
implicit_register_use_ =
implicit_register_use_ | ImplicitRegisterUse::kWriteAccumulator;
}
// Instantiate CallJSAndDispatch() for argument counts used by interpreter
......@@ -817,7 +822,8 @@ void InterpreterAssembler::CallJSWithSpreadAndDispatch(
args_count, args.base_reg_location(),
function);
// TailCallStubThenDispatch updates accumulator with result.
accumulator_use_ = accumulator_use_ | AccumulatorUse::kWrite;
implicit_register_use_ =
implicit_register_use_ | ImplicitRegisterUse::kWriteAccumulator;
}
TNode<Object> InterpreterAssembler::Construct(
......@@ -1158,10 +1164,10 @@ TNode<WordT> InterpreterAssembler::StarDispatchLookahead(
void InterpreterAssembler::InlineStar() {
Bytecode previous_bytecode = bytecode_;
AccumulatorUse previous_acc_use = accumulator_use_;
ImplicitRegisterUse previous_acc_use = implicit_register_use_;
bytecode_ = Bytecode::kStar;
accumulator_use_ = AccumulatorUse::kNone;
implicit_register_use_ = ImplicitRegisterUse::kNone;
#ifdef V8_TRACE_IGNITION
TraceBytecode(Runtime::kInterpreterTraceBytecodeEntry);
......@@ -1169,11 +1175,12 @@ void InterpreterAssembler::InlineStar() {
StoreRegister(GetAccumulator(),
BytecodeOperandReg(0, LoadSensitivity::kSafe));
DCHECK_EQ(accumulator_use_, Bytecodes::GetAccumulatorUse(bytecode_));
DCHECK_EQ(implicit_register_use_,
Bytecodes::GetImplicitRegisterUse(bytecode_));
Advance();
bytecode_ = previous_bytecode;
accumulator_use_ = previous_acc_use;
implicit_register_use_ = previous_acc_use;
}
void InterpreterAssembler::Dispatch() {
......
......@@ -398,7 +398,7 @@ class V8_EXPORT_PRIVATE InterpreterAssembler : public CodeStubAssembler {
CodeStubAssembler::TVariable<IntPtrT> bytecode_offset_;
CodeStubAssembler::TVariable<ExternalReference> dispatch_table_;
CodeStubAssembler::TVariable<Object> accumulator_;
AccumulatorUse accumulator_use_;
ImplicitRegisterUse implicit_register_use_;
bool made_call_;
bool reloaded_frame_ptr_;
bool bytecode_array_valid_;
......
......@@ -81,7 +81,8 @@ TEST_F(BytecodeRegisterOptimizerTest, TemporaryMaterializedForJump) {
Register temp = NewTemporary();
optimizer()->DoStar(temp);
CHECK_EQ(write_count(), 0u);
optimizer()->PrepareForBytecode<Bytecode::kJump, AccumulatorUse::kNone>();
optimizer()
->PrepareForBytecode<Bytecode::kJump, ImplicitRegisterUse::kNone>();
CHECK_EQ(write_count(), 1u);
CHECK_EQ(output()->at(0).bytecode, Bytecode::kStar);
CHECK_EQ(output()->at(0).output.index(), temp.index());
......@@ -98,19 +99,25 @@ TEST_F(BytecodeRegisterOptimizerTest, TemporaryNotEmitted) {
optimizer()->DoStar(temp);
ReleaseTemporaries(temp);
CHECK_EQ(write_count(), 0u);
optimizer()->PrepareForBytecode<Bytecode::kReturn, AccumulatorUse::kRead>();
optimizer()
->PrepareForBytecode<Bytecode::kReturn,
ImplicitRegisterUse::kReadAccumulator>();
CHECK_EQ(output()->at(0).bytecode, Bytecode::kLdar);
CHECK_EQ(output()->at(0).input.index(), parameter.index());
}
TEST_F(BytecodeRegisterOptimizerTest, ReleasedRegisterUsed) {
Initialize(3, 1);
optimizer()->PrepareForBytecode<Bytecode::kLdaSmi, AccumulatorUse::kWrite>();
optimizer()
->PrepareForBytecode<Bytecode::kLdaSmi,
ImplicitRegisterUse::kWriteAccumulator>();
Register temp0 = NewTemporary();
Register temp1 = NewTemporary();
optimizer()->DoStar(temp1);
CHECK_EQ(write_count(), 0u);
optimizer()->PrepareForBytecode<Bytecode::kLdaSmi, AccumulatorUse::kWrite>();
optimizer()
->PrepareForBytecode<Bytecode::kLdaSmi,
ImplicitRegisterUse::kWriteAccumulator>();
CHECK_EQ(write_count(), 1u);
CHECK_EQ(output()->at(0).bytecode, Bytecode::kStar);
CHECK_EQ(output()->at(0).output.index(), temp1.index());
......@@ -120,7 +127,9 @@ TEST_F(BytecodeRegisterOptimizerTest, ReleasedRegisterUsed) {
CHECK_EQ(write_count(), 1u);
optimizer()->DoLdar(temp0);
CHECK_EQ(write_count(), 1u);
optimizer()->PrepareForBytecode<Bytecode::kReturn, AccumulatorUse::kRead>();
optimizer()
->PrepareForBytecode<Bytecode::kReturn,
ImplicitRegisterUse::kReadAccumulator>();
CHECK_EQ(write_count(), 2u);
CHECK_EQ(output()->at(1).bytecode, Bytecode::kLdar);
CHECK_EQ(output()->at(1).input.index(), temp1.index());
......@@ -128,7 +137,9 @@ TEST_F(BytecodeRegisterOptimizerTest, ReleasedRegisterUsed) {
TEST_F(BytecodeRegisterOptimizerTest, ReleasedRegisterNotFlushed) {
Initialize(3, 1);
optimizer()->PrepareForBytecode<Bytecode::kLdaSmi, AccumulatorUse::kWrite>();
optimizer()
->PrepareForBytecode<Bytecode::kLdaSmi,
ImplicitRegisterUse::kWriteAccumulator>();
Register temp0 = NewTemporary();
Register temp1 = NewTemporary();
optimizer()->DoStar(temp0);
......@@ -154,7 +165,9 @@ TEST_F(BytecodeRegisterOptimizerTest, StoresToLocalsImmediate) {
CHECK_EQ(output()->at(0).input.index(), parameter.index());
CHECK_EQ(output()->at(0).output.index(), local.index());
optimizer()->PrepareForBytecode<Bytecode::kReturn, AccumulatorUse::kRead>();
optimizer()
->PrepareForBytecode<Bytecode::kReturn,
ImplicitRegisterUse::kReadAccumulator>();
CHECK_EQ(write_count(), 2u);
CHECK_EQ(output()->at(1).bytecode, Bytecode::kLdar);
CHECK_EQ(output()->at(1).input.index(), local.index());
......@@ -183,13 +196,16 @@ TEST_F(BytecodeRegisterOptimizerTest, RangeOfTemporariesMaterializedForInput) {
Register parameter = Register::FromParameterIndex(1, 3);
Register temp0 = NewTemporary();
Register temp1 = NewTemporary();
optimizer()->PrepareForBytecode<Bytecode::kLdaSmi, AccumulatorUse::kWrite>();
optimizer()
->PrepareForBytecode<Bytecode::kLdaSmi,
ImplicitRegisterUse::kWriteAccumulator>();
optimizer()->DoStar(temp0);
optimizer()->DoMov(parameter, temp1);
CHECK_EQ(write_count(), 0u);
optimizer()
->PrepareForBytecode<Bytecode::kCallJSRuntime, AccumulatorUse::kWrite>();
->PrepareForBytecode<Bytecode::kCallJSRuntime,
ImplicitRegisterUse::kWriteAccumulator>();
RegisterList reg_list = optimizer()->GetInputRegisterList(
BytecodeUtils::NewRegisterList(temp0.index(), 2));
CHECK_EQ(temp0.index(), reg_list.first_register().index());
......
......@@ -333,30 +333,33 @@ TEST(OperandScale, PrefixesRequired) {
Bytecode::kExtraWide);
}
TEST(AccumulatorUse, LogicalOperators) {
CHECK_EQ(AccumulatorUse::kNone | AccumulatorUse::kRead,
AccumulatorUse::kRead);
CHECK_EQ(AccumulatorUse::kRead | AccumulatorUse::kWrite,
AccumulatorUse::kReadWrite);
CHECK_EQ(AccumulatorUse::kRead & AccumulatorUse::kReadWrite,
AccumulatorUse::kRead);
CHECK_EQ(AccumulatorUse::kRead & AccumulatorUse::kWrite,
AccumulatorUse::kNone);
TEST(ImplicitRegisterUse, LogicalOperators) {
CHECK_EQ(ImplicitRegisterUse::kNone | ImplicitRegisterUse::kReadAccumulator,
ImplicitRegisterUse::kReadAccumulator);
CHECK_EQ(ImplicitRegisterUse::kReadAccumulator |
ImplicitRegisterUse::kWriteAccumulator,
ImplicitRegisterUse::kReadWriteAccumulator);
CHECK_EQ(ImplicitRegisterUse::kReadAccumulator &
ImplicitRegisterUse::kReadWriteAccumulator,
ImplicitRegisterUse::kReadAccumulator);
CHECK_EQ(ImplicitRegisterUse::kReadAccumulator &
ImplicitRegisterUse::kWriteAccumulator,
ImplicitRegisterUse::kNone);
}
TEST(AccumulatorUse, SampleBytecodes) {
TEST(ImplicitRegisterUse, SampleBytecodes) {
CHECK(Bytecodes::ReadsAccumulator(Bytecode::kStar));
CHECK(!Bytecodes::WritesAccumulator(Bytecode::kStar));
CHECK_EQ(Bytecodes::GetAccumulatorUse(Bytecode::kStar),
AccumulatorUse::kRead);
CHECK_EQ(Bytecodes::GetImplicitRegisterUse(Bytecode::kStar),
ImplicitRegisterUse::kReadAccumulator);
CHECK(!Bytecodes::ReadsAccumulator(Bytecode::kLdar));
CHECK(Bytecodes::WritesAccumulator(Bytecode::kLdar));
CHECK_EQ(Bytecodes::GetAccumulatorUse(Bytecode::kLdar),
AccumulatorUse::kWrite);
CHECK_EQ(Bytecodes::GetImplicitRegisterUse(Bytecode::kLdar),
ImplicitRegisterUse::kWriteAccumulator);
CHECK(Bytecodes::ReadsAccumulator(Bytecode::kAdd));
CHECK(Bytecodes::WritesAccumulator(Bytecode::kAdd));
CHECK_EQ(Bytecodes::GetAccumulatorUse(Bytecode::kAdd),
AccumulatorUse::kReadWrite);
CHECK_EQ(Bytecodes::GetImplicitRegisterUse(Bytecode::kAdd),
ImplicitRegisterUse::kReadWriteAccumulator);
}
} // namespace interpreter
......
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