Commit e4d28751 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[compiler] Optimize TranslationArray building and representation

Several small optimisations for TranslationArray:

  a) Store opcodes and register codes as unsigned values (no need to
     shift in the sign bit when encoding/decoding). Note that skips over
     register codes will decode them as if they were signed -- this is
     ok since we don't use the skipped value.

  b) Use the static knowledge that opcodes and register codes need 7
     bits to avoid the VLQEncode loop when building (still use a
     VLQDecode when decoding since decode time matters less).

  c) Add a special opcode for "optimized out", instead of using a
     literal, since this will be a common case.

Change-Id: I9758e5b889ecc3f1a3fa4d840867f2a3d481e75f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3812040
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Nico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82227}
parent 81597be2
......@@ -85,7 +85,6 @@ CodeGenerator::CodeGenerator(
ools_(nullptr),
osr_helper_(std::move(osr_helper)),
osr_pc_offset_(-1),
optimized_out_literal_id_(-1),
source_position_table_builder_(
codegen_zone, SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS),
#if V8_ENABLE_WEBASSEMBLY
......@@ -1029,11 +1028,7 @@ void CodeGenerator::TranslateStateValueDescriptor(
AddTranslationForOperand(iter->instruction(), op, desc->type());
} else {
DCHECK(desc->IsOptimizedOut());
if (optimized_out_literal_id_ == -1) {
optimized_out_literal_id_ = DefineDeoptimizationLiteral(
DeoptimizationLiteral(isolate()->factory()->optimized_out()));
}
translations_.StoreLiteral(optimized_out_literal_id_);
translations_.StoreOptimizedOut();
}
}
......
......@@ -468,7 +468,6 @@ class V8_EXPORT_PRIVATE CodeGenerator final : public GapResolver::Assembler {
OutOfLineCode* ools_;
base::Optional<OsrHelper> osr_helper_;
int osr_pc_offset_;
int optimized_out_literal_id_;
SourcePositionTableBuilder source_position_table_builder_;
#if V8_ENABLE_WEBASSEMBLY
ZoneVector<trap_handler::ProtectedInstructionData> protected_instructions_;
......
......@@ -36,8 +36,8 @@ void TranslationArrayPrintSingleFrame(
TranslationArrayIterator iterator(translation_array, translation_index);
disasm::NameConverter converter;
TranslationOpcode opcode = TranslationOpcodeFromInt(iterator.Next());
DCHECK(TranslationOpcode::BEGIN == opcode);
TranslationOpcode opcode = TranslationOpcodeFromInt(iterator.NextUnsigned());
DCHECK_EQ(TranslationOpcode::BEGIN, opcode);
int frame_count = iterator.Next();
int jsframe_count = iterator.Next();
int update_feedback_count = iterator.Next();
......@@ -46,7 +46,7 @@ void TranslationArrayPrintSingleFrame(
<< ", update_feedback_count=" << update_feedback_count << "}\n";
while (iterator.HasNext()) {
opcode = TranslationOpcodeFromInt(iterator.Next());
opcode = TranslationOpcodeFromInt(iterator.NextUnsigned());
if (opcode == TranslationOpcode::BEGIN) break;
os << std::setw(31) << " " << TranslationOpcodeToString(opcode) << " ";
......@@ -126,28 +126,28 @@ void TranslationArrayPrintSingleFrame(
case TranslationOpcode::REGISTER: {
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
int reg_code = iterator.Next();
int reg_code = iterator.NextUnsigned();
os << "{input=" << converter.NameOfCPURegister(reg_code) << "}";
break;
}
case TranslationOpcode::INT32_REGISTER: {
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
int reg_code = iterator.Next();
int reg_code = iterator.NextUnsigned();
os << "{input=" << converter.NameOfCPURegister(reg_code) << " (int32)}";
break;
}
case TranslationOpcode::INT64_REGISTER: {
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
int reg_code = iterator.Next();
int reg_code = iterator.NextUnsigned();
os << "{input=" << converter.NameOfCPURegister(reg_code) << " (int64)}";
break;
}
case TranslationOpcode::UINT32_REGISTER: {
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
int reg_code = iterator.Next();
int reg_code = iterator.NextUnsigned();
os << "{input=" << converter.NameOfCPURegister(reg_code)
<< " (uint32)}";
break;
......@@ -155,21 +155,21 @@ void TranslationArrayPrintSingleFrame(
case TranslationOpcode::BOOL_REGISTER: {
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
int reg_code = iterator.Next();
int reg_code = iterator.NextUnsigned();
os << "{input=" << converter.NameOfCPURegister(reg_code) << " (bool)}";
break;
}
case TranslationOpcode::FLOAT_REGISTER: {
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
int reg_code = iterator.Next();
int reg_code = iterator.NextUnsigned();
os << "{input=" << FloatRegister::from_code(reg_code) << "}";
break;
}
case TranslationOpcode::DOUBLE_REGISTER: {
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
int reg_code = iterator.Next();
int reg_code = iterator.NextUnsigned();
os << "{input=" << DoubleRegister::from_code(reg_code) << "}";
break;
}
......@@ -217,6 +217,12 @@ void TranslationArrayPrintSingleFrame(
break;
}
case TranslationOpcode::OPTIMIZED_OUT: {
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 0);
os << "{optimized_out}}";
break;
}
case TranslationOpcode::LITERAL: {
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
int literal_index = iterator.Next();
......@@ -728,7 +734,7 @@ void TranslatedFrame::Handlify() {
TranslatedFrame TranslatedState::CreateNextTranslatedFrame(
TranslationArrayIterator* iterator,
DeoptimizationLiteralArray literal_array, Address fp, FILE* trace_file) {
TranslationOpcode opcode = TranslationOpcodeFromInt(iterator->Next());
TranslationOpcode opcode = TranslationOpcodeFromInt(iterator->NextUnsigned());
switch (opcode) {
case TranslationOpcode::INTERPRETED_FRAME: {
BytecodeOffset bytecode_offset = BytecodeOffset(iterator->Next());
......@@ -874,6 +880,7 @@ TranslatedFrame TranslatedState::CreateNextTranslatedFrame(
case TranslationOpcode::FLOAT_STACK_SLOT:
case TranslationOpcode::DOUBLE_STACK_SLOT:
case TranslationOpcode::LITERAL:
case TranslationOpcode::OPTIMIZED_OUT:
break;
}
UNREACHABLE();
......@@ -967,7 +974,7 @@ int TranslatedState::CreateNextTranslatedValue(
TranslatedFrame& frame = frames_[frame_index];
int value_index = static_cast<int>(frame.values_.size());
TranslationOpcode opcode = TranslationOpcodeFromInt(iterator->Next());
TranslationOpcode opcode = TranslationOpcodeFromInt(iterator->NextUnsigned());
switch (opcode) {
case TranslationOpcode::BEGIN:
case TranslationOpcode::INTERPRETED_FRAME:
......@@ -1027,7 +1034,7 @@ int TranslatedState::CreateNextTranslatedValue(
}
case TranslationOpcode::REGISTER: {
int input_reg = iterator->Next();
int input_reg = iterator->NextUnsigned();
if (registers == nullptr) {
TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
frame.Add(translated_value);
......@@ -1047,7 +1054,7 @@ int TranslatedState::CreateNextTranslatedValue(
}
case TranslationOpcode::INT32_REGISTER: {
int input_reg = iterator->Next();
int input_reg = iterator->NextUnsigned();
if (registers == nullptr) {
TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
frame.Add(translated_value);
......@@ -1065,7 +1072,7 @@ int TranslatedState::CreateNextTranslatedValue(
}
case TranslationOpcode::INT64_REGISTER: {
int input_reg = iterator->Next();
int input_reg = iterator->NextUnsigned();
if (registers == nullptr) {
TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
frame.Add(translated_value);
......@@ -1083,7 +1090,7 @@ int TranslatedState::CreateNextTranslatedValue(
}
case TranslationOpcode::UINT32_REGISTER: {
int input_reg = iterator->Next();
int input_reg = iterator->NextUnsigned();
if (registers == nullptr) {
TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
frame.Add(translated_value);
......@@ -1101,7 +1108,7 @@ int TranslatedState::CreateNextTranslatedValue(
}
case TranslationOpcode::BOOL_REGISTER: {
int input_reg = iterator->Next();
int input_reg = iterator->NextUnsigned();
if (registers == nullptr) {
TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
frame.Add(translated_value);
......@@ -1119,7 +1126,7 @@ int TranslatedState::CreateNextTranslatedValue(
}
case TranslationOpcode::FLOAT_REGISTER: {
int input_reg = iterator->Next();
int input_reg = iterator->NextUnsigned();
if (registers == nullptr) {
TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
frame.Add(translated_value);
......@@ -1136,7 +1143,7 @@ int TranslatedState::CreateNextTranslatedValue(
}
case TranslationOpcode::DOUBLE_REGISTER: {
int input_reg = iterator->Next();
int input_reg = iterator->NextUnsigned();
if (registers == nullptr) {
TranslatedValue translated_value = TranslatedValue::NewInvalid(this);
frame.Add(translated_value);
......@@ -1266,6 +1273,17 @@ int TranslatedState::CreateNextTranslatedValue(
frame.Add(translated_value);
return translated_value.GetChildrenCount();
}
case TranslationOpcode::OPTIMIZED_OUT: {
if (trace_file != nullptr) {
PrintF(trace_file, "(optimized out)");
}
TranslatedValue translated_value = TranslatedValue::NewTagged(
this, ReadOnlyRoots(isolate_).optimized_out());
frame.Add(translated_value);
return translated_value.GetChildrenCount();
}
}
FATAL("We should never get here - unexpected deopt info.");
......@@ -1312,8 +1330,8 @@ void TranslatedState::Init(Isolate* isolate, Address input_frame_pointer,
isolate_ = isolate;
// Read out the 'header' translation.
TranslationOpcode opcode = TranslationOpcodeFromInt(iterator->Next());
CHECK(opcode == TranslationOpcode::BEGIN);
TranslationOpcode opcode = TranslationOpcodeFromInt(iterator->NextUnsigned());
CHECK_EQ(opcode, TranslationOpcode::BEGIN);
int count = iterator->Next();
frames_.reserve(count);
......@@ -1375,7 +1393,8 @@ void TranslatedState::Init(Isolate* isolate, Address input_frame_pointer,
}
CHECK(!iterator->HasNext() ||
TranslationOpcodeFromInt(iterator->Next()) == TranslationOpcode::BEGIN);
TranslationOpcodeFromInt(iterator->NextUnsigned()) ==
TranslationOpcode::BEGIN);
}
void TranslatedState::Prepare(Address stack_frame_pointer) {
......@@ -2146,7 +2165,7 @@ void TranslatedState::ReadUpdateFeedback(
TranslationArrayIterator* iterator,
DeoptimizationLiteralArray literal_array, FILE* trace_file) {
CHECK_EQ(TranslationOpcode::UPDATE_FEEDBACK,
TranslationOpcodeFromInt(iterator->Next()));
TranslationOpcodeFromInt(iterator->NextUnsigned()));
feedback_vector_ = FeedbackVector::cast(literal_array.get(iterator->Next()));
feedback_slot_ = FeedbackSlot(iterator->Next());
if (trace_file != nullptr) {
......
......@@ -56,6 +56,17 @@ int32_t TranslationArrayIterator::Next() {
}
}
uint32_t TranslationArrayIterator::NextUnsigned() {
if (V8_UNLIKELY(FLAG_turbo_compress_translation_arrays)) {
return uncompressed_contents_[index_++];
} else {
uint32_t value =
base::VLQDecodeUnsigned(buffer_.GetDataStartAddress(), &index_);
DCHECK_LE(index_, buffer_.length());
return value;
}
}
bool TranslationArrayIterator::HasNext() const {
if (V8_UNLIKELY(FLAG_turbo_compress_translation_arrays)) {
return index_ < static_cast<int>(uncompressed_contents_.size());
......@@ -72,6 +83,42 @@ void TranslationArrayBuilder::Add(int32_t value) {
}
}
void TranslationArrayBuilder::AddOpcode(TranslationOpcode opcode) {
static_assert(kNumTranslationOpcodes - 1 <= base::kDataMask);
if (V8_UNLIKELY(FLAG_turbo_compress_translation_arrays)) {
contents_for_compression_.push_back(static_cast<byte>(opcode));
} else {
contents_.push_back(static_cast<byte>(opcode));
}
}
void TranslationArrayBuilder::AddRegister(Register reg) {
static_assert(Register::kNumRegisters - 1 <= base::kDataMask);
if (V8_UNLIKELY(FLAG_turbo_compress_translation_arrays)) {
contents_for_compression_.push_back(static_cast<byte>(reg.code()));
} else {
contents_.push_back(static_cast<byte>(reg.code()));
}
}
void TranslationArrayBuilder::AddFloatRegister(FloatRegister reg) {
static_assert(FloatRegister::kNumRegisters - 1 <= base::kDataMask);
if (V8_UNLIKELY(FLAG_turbo_compress_translation_arrays)) {
contents_for_compression_.push_back(static_cast<byte>(reg.code()));
} else {
contents_.push_back(static_cast<byte>(reg.code()));
}
}
void TranslationArrayBuilder::AddDoubleRegister(DoubleRegister reg) {
static_assert(DoubleRegister::kNumRegisters - 1 <= base::kDataMask);
if (V8_UNLIKELY(FLAG_turbo_compress_translation_arrays)) {
contents_for_compression_.push_back(static_cast<byte>(reg.code()));
} else {
contents_.push_back(static_cast<byte>(reg.code()));
}
}
Handle<TranslationArray> TranslationArrayBuilder::ToTranslationArray(
Factory* factory) {
if (V8_UNLIKELY(FLAG_turbo_compress_translation_arrays)) {
......@@ -109,7 +156,7 @@ Handle<TranslationArray> TranslationArrayBuilder::ToTranslationArray(
void TranslationArrayBuilder::BeginBuiltinContinuationFrame(
BytecodeOffset bytecode_offset, int literal_id, unsigned height) {
auto opcode = TranslationOpcode::BUILTIN_CONTINUATION_FRAME;
Add(opcode);
AddOpcode(opcode);
Add(bytecode_offset.ToInt());
Add(literal_id);
Add(height);
......@@ -121,7 +168,7 @@ void TranslationArrayBuilder::BeginJSToWasmBuiltinContinuationFrame(
BytecodeOffset bytecode_offset, int literal_id, unsigned height,
base::Optional<wasm::ValueKind> return_kind) {
auto opcode = TranslationOpcode::JS_TO_WASM_BUILTIN_CONTINUATION_FRAME;
Add(opcode);
AddOpcode(opcode);
Add(bytecode_offset.ToInt());
Add(literal_id);
Add(height);
......@@ -133,7 +180,7 @@ void TranslationArrayBuilder::BeginJSToWasmBuiltinContinuationFrame(
void TranslationArrayBuilder::BeginJavaScriptBuiltinContinuationFrame(
BytecodeOffset bytecode_offset, int literal_id, unsigned height) {
auto opcode = TranslationOpcode::JAVA_SCRIPT_BUILTIN_CONTINUATION_FRAME;
Add(opcode);
AddOpcode(opcode);
Add(bytecode_offset.ToInt());
Add(literal_id);
Add(height);
......@@ -144,7 +191,7 @@ void TranslationArrayBuilder::BeginJavaScriptBuiltinContinuationWithCatchFrame(
BytecodeOffset bytecode_offset, int literal_id, unsigned height) {
auto opcode =
TranslationOpcode::JAVA_SCRIPT_BUILTIN_CONTINUATION_WITH_CATCH_FRAME;
Add(opcode);
AddOpcode(opcode);
Add(bytecode_offset.ToInt());
Add(literal_id);
Add(height);
......@@ -154,7 +201,7 @@ void TranslationArrayBuilder::BeginJavaScriptBuiltinContinuationWithCatchFrame(
void TranslationArrayBuilder::BeginConstructStubFrame(
BytecodeOffset bytecode_offset, int literal_id, unsigned height) {
auto opcode = TranslationOpcode::CONSTRUCT_STUB_FRAME;
Add(opcode);
AddOpcode(opcode);
Add(bytecode_offset.ToInt());
Add(literal_id);
Add(height);
......@@ -164,7 +211,7 @@ void TranslationArrayBuilder::BeginConstructStubFrame(
void TranslationArrayBuilder::BeginInlinedExtraArguments(int literal_id,
unsigned height) {
auto opcode = TranslationOpcode::INLINED_EXTRA_ARGUMENTS;
Add(opcode);
AddOpcode(opcode);
Add(literal_id);
Add(height);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 2);
......@@ -174,7 +221,7 @@ void TranslationArrayBuilder::BeginInterpretedFrame(
BytecodeOffset bytecode_offset, int literal_id, unsigned height,
int return_value_offset, int return_value_count) {
auto opcode = TranslationOpcode::INTERPRETED_FRAME;
Add(opcode);
AddOpcode(opcode);
Add(bytecode_offset.ToInt());
Add(literal_id);
Add(height);
......@@ -185,136 +232,142 @@ void TranslationArrayBuilder::BeginInterpretedFrame(
void TranslationArrayBuilder::ArgumentsElements(CreateArgumentsType type) {
auto opcode = TranslationOpcode::ARGUMENTS_ELEMENTS;
Add(opcode);
AddOpcode(opcode);
Add(static_cast<uint8_t>(type));
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::ArgumentsLength() {
auto opcode = TranslationOpcode::ARGUMENTS_LENGTH;
Add(opcode);
AddOpcode(opcode);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 0);
}
void TranslationArrayBuilder::BeginCapturedObject(int length) {
auto opcode = TranslationOpcode::CAPTURED_OBJECT;
Add(opcode);
AddOpcode(opcode);
Add(length);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::DuplicateObject(int object_index) {
auto opcode = TranslationOpcode::DUPLICATED_OBJECT;
Add(opcode);
AddOpcode(opcode);
Add(object_index);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreRegister(Register reg) {
auto opcode = TranslationOpcode::REGISTER;
Add(opcode);
Add(reg.code());
AddOpcode(opcode);
AddRegister(reg);
}
void TranslationArrayBuilder::StoreInt32Register(Register reg) {
auto opcode = TranslationOpcode::INT32_REGISTER;
Add(opcode);
Add(reg.code());
AddOpcode(opcode);
AddRegister(reg);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreInt64Register(Register reg) {
auto opcode = TranslationOpcode::INT64_REGISTER;
Add(opcode);
Add(reg.code());
AddOpcode(opcode);
AddRegister(reg);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreUint32Register(Register reg) {
auto opcode = TranslationOpcode::UINT32_REGISTER;
Add(opcode);
Add(reg.code());
AddOpcode(opcode);
AddRegister(reg);
}
void TranslationArrayBuilder::StoreBoolRegister(Register reg) {
auto opcode = TranslationOpcode::BOOL_REGISTER;
Add(opcode);
Add(reg.code());
AddOpcode(opcode);
AddRegister(reg);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreFloatRegister(FloatRegister reg) {
auto opcode = TranslationOpcode::FLOAT_REGISTER;
Add(opcode);
Add(reg.code());
AddOpcode(opcode);
AddFloatRegister(reg);
}
void TranslationArrayBuilder::StoreDoubleRegister(DoubleRegister reg) {
auto opcode = TranslationOpcode::DOUBLE_REGISTER;
Add(opcode);
Add(reg.code());
AddOpcode(opcode);
AddDoubleRegister(reg);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreStackSlot(int index) {
auto opcode = TranslationOpcode::STACK_SLOT;
Add(opcode);
AddOpcode(opcode);
Add(index);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreInt32StackSlot(int index) {
auto opcode = TranslationOpcode::INT32_STACK_SLOT;
Add(opcode);
AddOpcode(opcode);
Add(index);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreInt64StackSlot(int index) {
auto opcode = TranslationOpcode::INT64_STACK_SLOT;
Add(opcode);
AddOpcode(opcode);
Add(index);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreUint32StackSlot(int index) {
auto opcode = TranslationOpcode::UINT32_STACK_SLOT;
Add(opcode);
AddOpcode(opcode);
Add(index);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreBoolStackSlot(int index) {
auto opcode = TranslationOpcode::BOOL_STACK_SLOT;
Add(opcode);
AddOpcode(opcode);
Add(index);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreFloatStackSlot(int index) {
auto opcode = TranslationOpcode::FLOAT_STACK_SLOT;
Add(opcode);
AddOpcode(opcode);
Add(index);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreDoubleStackSlot(int index) {
auto opcode = TranslationOpcode::DOUBLE_STACK_SLOT;
Add(opcode);
AddOpcode(opcode);
Add(index);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreLiteral(int literal_id) {
auto opcode = TranslationOpcode::LITERAL;
Add(opcode);
AddOpcode(opcode);
Add(literal_id);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 1);
}
void TranslationArrayBuilder::StoreOptimizedOut() {
auto opcode = TranslationOpcode::OPTIMIZED_OUT;
AddOpcode(opcode);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 0);
}
void TranslationArrayBuilder::AddUpdateFeedback(int vector_literal, int slot) {
auto opcode = TranslationOpcode::UPDATE_FEEDBACK;
Add(opcode);
AddOpcode(opcode);
Add(vector_literal);
Add(slot);
DCHECK_EQ(TranslationOpcodeOperandCount(opcode), 2);
......
......@@ -32,6 +32,8 @@ class TranslationArrayIterator {
int32_t Next();
uint32_t NextUnsigned();
bool HasNext() const;
void Skip(int n) {
......@@ -55,7 +57,7 @@ class TranslationArrayBuilder {
int update_feedback_count) {
int start_index = Size();
auto opcode = TranslationOpcode::BEGIN;
Add(opcode);
AddOpcode(opcode);
Add(frame_count);
Add(jsframe_count);
Add(update_feedback_count);
......@@ -100,11 +102,15 @@ class TranslationArrayBuilder {
void StoreFloatStackSlot(int index);
void StoreDoubleStackSlot(int index);
void StoreLiteral(int literal_id);
void StoreOptimizedOut();
void StoreJSFrameFunction();
private:
void Add(int32_t value);
void Add(TranslationOpcode opcode) { Add(static_cast<int32_t>(opcode)); }
void AddOpcode(TranslationOpcode opcode);
void AddRegister(Register reg);
void AddFloatRegister(FloatRegister reg);
void AddDoubleRegister(DoubleRegister reg);
int Size() const {
return V8_UNLIKELY(FLAG_turbo_compress_translation_arrays)
......
......@@ -34,6 +34,7 @@ namespace internal {
V(JAVA_SCRIPT_BUILTIN_CONTINUATION_FRAME, 3) \
V(JAVA_SCRIPT_BUILTIN_CONTINUATION_WITH_CATCH_FRAME, 3) \
IF_WASM(V, JS_TO_WASM_BUILTIN_CONTINUATION_FRAME, 4) \
V(OPTIMIZED_OUT, 0) \
V(LITERAL, 1) \
V(REGISTER, 1) \
V(STACK_SLOT, 1) \
......@@ -47,7 +48,12 @@ enum class TranslationOpcode {
#undef CASE
};
constexpr TranslationOpcode TranslationOpcodeFromInt(int i) {
#define PLUS_ONE(...) +1
static constexpr int kNumTranslationOpcodes =
0 TRANSLATION_OPCODE_LIST(PLUS_ONE);
#undef PLUS_ONE
constexpr TranslationOpcode TranslationOpcodeFromInt(uint32_t i) {
return static_cast<TranslationOpcode>(i);
}
......
......@@ -2233,7 +2233,7 @@ void OptimizedFrame::GetFunctions(
TranslationArrayIterator it(data.TranslationByteArray(),
data.TranslationIndex(deopt_index).value());
TranslationOpcode opcode = TranslationOpcodeFromInt(it.Next());
TranslationOpcode opcode = TranslationOpcodeFromInt(it.NextUnsigned());
DCHECK_EQ(TranslationOpcode::BEGIN, opcode);
it.Next(); // Skip frame count.
int jsframe_count = it.Next();
......@@ -2242,7 +2242,7 @@ void OptimizedFrame::GetFunctions(
// We insert the frames in reverse order because the frames
// in the deoptimization translation are ordered bottom-to-top.
while (jsframe_count != 0) {
opcode = TranslationOpcodeFromInt(it.Next());
opcode = TranslationOpcodeFromInt(it.NextUnsigned());
if (opcode == TranslationOpcode::INTERPRETED_FRAME ||
opcode == TranslationOpcode::JAVA_SCRIPT_BUILTIN_CONTINUATION_FRAME ||
opcode == TranslationOpcode::
......
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