Commit 7cd978df authored by jgruber's avatar jgruber Committed by Commit Bot

[interpreter] AllStatic, OperandScaleCount, ReusesExistingHandler

* Mark BytecodeOperands and Bytecodes AllStatic.
* Add BytecodeOperands::kOperandScaleCount.
* Add Bytecodes::ReusesExistingHandler in preparation for adding another
  callsite from deserialization.

Bug: v8:6624
Change-Id: Ic8b5d444df5525ef6d14de6931b38afd926b251e
Reviewed-on: https://chromium-review.googlesource.com/738092Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48957}
parent f2f0049d
......@@ -134,11 +134,17 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
const OperandType& operand_type);
class BytecodeOperands {
class BytecodeOperands : public AllStatic {
public:
// The total number of bytecodes used.
// The total number of bytecode operand types used.
static const int kOperandTypeCount = static_cast<int>(OperandType::kLast) + 1;
// The total number of bytecode operand scales used.
#define OPERAND_SCALE_COUNT(...) +1
static const int kOperandScaleCount =
0 OPERAND_SCALE_LIST(OPERAND_SCALE_COUNT);
#undef OPERAND_SCALE_COUNT
// Returns true if |accumulator_use| reads the accumulator.
static constexpr bool ReadsAccumulator(AccumulatorUse accumulator_use) {
return accumulator_use == AccumulatorUse::kRead ||
......
......@@ -443,7 +443,7 @@ enum class Bytecode : uint8_t {
#undef COUNT_BYTECODE
};
class V8_EXPORT_PRIVATE Bytecodes final {
class V8_EXPORT_PRIVATE Bytecodes final : public AllStatic {
public:
// The maximum number of operands a bytecode may have.
static const int kMaxOperands = 5;
......@@ -832,6 +832,26 @@ class V8_EXPORT_PRIVATE Bytecodes final {
UNREACHABLE();
}
// Returns true, iff the given bytecode reuses an existing handler. If so,
// the bytecode of the reused handler is written into {reused}.
static bool ReusesExistingHandler(Bytecode bytecode, Bytecode* reused) {
switch (bytecode) {
case Bytecode::kLdaImmutableContextSlot:
STATIC_ASSERT(static_cast<int>(Bytecode::kLdaContextSlot) <
static_cast<int>(Bytecode::kLdaImmutableContextSlot));
*reused = Bytecode::kLdaContextSlot;
return true;
case Bytecode::kLdaImmutableCurrentContextSlot:
STATIC_ASSERT(
static_cast<int>(Bytecode::kLdaCurrentContextSlot) <
static_cast<int>(Bytecode::kLdaImmutableCurrentContextSlot));
*reused = Bytecode::kLdaCurrentContextSlot;
return true;
default:
return false;
}
}
// Returns the size of |operand_type| for |operand_scale|.
static OperandSize SizeOfOperand(OperandType operand_type,
OperandScale operand_scale) {
......
......@@ -75,7 +75,7 @@ class Interpreter {
bool IsDispatchTableInitialized();
static const int kNumberOfWideVariants = 3;
static const int kNumberOfWideVariants = BytecodeOperands::kOperandScaleCount;
static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1);
static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1;
......
......@@ -64,25 +64,16 @@ void SetupInterpreter::InstallBytecodeHandlers(Interpreter* interpreter) {
bool SetupInterpreter::ReuseExistingHandler(Address* dispatch_table,
Bytecode bytecode,
OperandScale operand_scale) {
size_t index = Interpreter::GetDispatchTableIndex(bytecode, operand_scale);
switch (bytecode) {
case Bytecode::kLdaImmutableContextSlot:
STATIC_ASSERT(static_cast<int>(Bytecode::kLdaContextSlot) <
static_cast<int>(Bytecode::kLdaImmutableContextSlot));
dispatch_table[index] = dispatch_table[Interpreter::GetDispatchTableIndex(
Bytecode::kLdaContextSlot, operand_scale)];
return true;
case Bytecode::kLdaImmutableCurrentContextSlot:
STATIC_ASSERT(
static_cast<int>(Bytecode::kLdaCurrentContextSlot) <
static_cast<int>(Bytecode::kLdaImmutableCurrentContextSlot));
dispatch_table[index] = dispatch_table[Interpreter::GetDispatchTableIndex(
Bytecode::kLdaCurrentContextSlot, operand_scale)];
return true;
default:
return false;
Bytecode reused_bytecode;
if (!Bytecodes::ReusesExistingHandler(bytecode, &reused_bytecode)) {
return false;
}
return false;
size_t index = Interpreter::GetDispatchTableIndex(bytecode, operand_scale);
dispatch_table[index] = dispatch_table[Interpreter::GetDispatchTableIndex(
reused_bytecode, operand_scale)];
return true;
}
// static
......
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