Commit 15165208 authored by Kim-Anh Tran's avatar Kim-Anh Tran Committed by Commit Bot

[wasm] Introduce Tier enum to replace the current is_liftoff flag

Bug: v8:7310
Change-Id: I87bdb640a3c006a268974b34808f184307badeb2
Reviewed-on: https://chromium-review.googlesource.com/934243
Commit-Queue: Kim-Anh Tran <kimanh@google.com>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51644}
parent 923ba7da
......@@ -5370,7 +5370,7 @@ WasmCodeWrapper WasmCompilationUnit::FinishTurbofanCompilation(
func_index_,
tf_.job_->compilation_info()->wasm_code_desc()->safepoint_table_offset,
tf_.job_->compilation_info()->wasm_code_desc()->handler_table_offset,
std::move(protected_instructions_), false);
std::move(protected_instructions_), wasm::WasmCode::kTurbofan);
if (!code) {
return WasmCodeWrapper(code);
}
......@@ -5460,10 +5460,10 @@ WasmCodeWrapper WasmCompilationUnit::FinishLiftoffCompilation(
// TODO(herhut) Consider lifting it to FinishCompilation.
native_module_->compiled_module()->source_positions()->set(
func_index_, *source_positions);
wasm::WasmCode* code =
native_module_->AddCode(desc, liftoff_.asm_.GetTotalFrameSlotCount(),
func_index_, liftoff_.safepoint_table_offset_,
0, std::move(protected_instructions_), true);
wasm::WasmCode* code = native_module_->AddCode(
desc, liftoff_.asm_.GetTotalFrameSlotCount(), func_index_,
liftoff_.safepoint_table_offset_, 0, std::move(protected_instructions_),
wasm::WasmCode::kLiftoff);
PROFILE(isolate_,
CodeCreateEvent(CodeEventListener::FUNCTION_TAG, code, func_name_));
ret = WasmCodeWrapper(code);
......
......@@ -320,7 +320,7 @@ WasmCode* NativeModule::AddOwnedCode(
uint32_t stack_slots, size_t safepoint_table_offset,
size_t handler_table_offset,
std::shared_ptr<ProtectedInstructions> protected_instructions,
bool is_liftoff) {
WasmCode::Tier tier) {
// both allocation and insertion in owned_code_ happen in the same critical
// section, thus ensuring owned_code_'s elements are rarely if ever moved.
base::LockGuard<base::Mutex> lock(&allocation_mutex_);
......@@ -332,7 +332,7 @@ WasmCode* NativeModule::AddOwnedCode(
{executable_buffer, orig_instructions.size()}, std::move(reloc_info),
reloc_size, this, index, kind, constant_pool_offset, stack_slots,
safepoint_table_offset, handler_table_offset,
std::move(protected_instructions), is_liftoff));
std::move(protected_instructions), tier));
WasmCode* ret = code.get();
// TODO(mtrofin): We allocate in increasing address order, and
......@@ -397,7 +397,7 @@ WasmCode* NativeModule::AddAnonymousCode(Handle<Code> code,
Nothing<uint32_t>(), kind, code->constant_pool_offset(),
(code->has_safepoint_info() ? code->stack_slots() : 0),
(code->has_safepoint_info() ? code->safepoint_table_offset() : 0),
code->handler_table_offset(), protected_instructions, false);
code->handler_table_offset(), protected_instructions, WasmCode::kOther);
if (ret == nullptr) return nullptr;
intptr_t delta = ret->instructions().start() - code->instruction_start();
int mask = RelocInfo::kApplyMask | RelocInfo::kCodeTargetMask |
......@@ -427,7 +427,7 @@ WasmCode* NativeModule::AddCode(
const CodeDesc& desc, uint32_t frame_slots, uint32_t index,
size_t safepoint_table_offset, size_t handler_table_offset,
std::unique_ptr<ProtectedInstructions> protected_instructions,
bool is_liftoff) {
WasmCode::Tier tier) {
std::unique_ptr<byte[]> reloc_info;
if (desc.reloc_size) {
reloc_info.reset(new byte[desc.reloc_size]);
......@@ -440,7 +440,7 @@ WasmCode* NativeModule::AddCode(
std::move(reloc_info), static_cast<size_t>(desc.reloc_size), Just(index),
WasmCode::kFunction, desc.instr_size - desc.constant_pool_size,
frame_slots, safepoint_table_offset, handler_table_offset,
std::move(protected_instructions), is_liftoff);
std::move(protected_instructions), tier);
if (ret == nullptr) return nullptr;
code_table_[index] = ret;
......@@ -488,7 +488,8 @@ Address NativeModule::CreateTrampolineTo(Handle<Code> code) {
masm.GetCode(nullptr, &code_desc);
WasmCode* wasm_code = AddOwnedCode(
{code_desc.buffer, static_cast<size_t>(code_desc.instr_size)}, nullptr, 0,
Nothing<uint32_t>(), WasmCode::kTrampoline, 0, 0, 0, 0, {}, false);
Nothing<uint32_t>(), WasmCode::kTrampoline, 0, 0, 0, 0, {},
WasmCode::kOther);
if (wasm_code == nullptr) return nullptr;
Address ret = wasm_code->instructions().start();
trampolines_.emplace(std::make_pair(dest, ret));
......@@ -692,7 +693,7 @@ WasmCode* NativeModule::CloneCode(const WasmCode* original_code) {
original_code->kind(), original_code->constant_pool_offset_,
original_code->stack_slots(), original_code->safepoint_table_offset_,
original_code->handler_table_offset_,
original_code->protected_instructions_, original_code->is_liftoff());
original_code->protected_instructions_, original_code->tier());
if (ret == nullptr) return nullptr;
if (!ret->IsAnonymous()) {
code_table_[ret->index()] = ret;
......
......@@ -97,6 +97,11 @@ class V8_EXPORT_PRIVATE WasmCode final {
kTrampoline
};
// kOther is used if we have WasmCode that is neither
// liftoff- nor turbofan-compiled, i.e. if Kind is
// not a kFunction.
enum Tier : int8_t { kLiftoff, kTurbofan, kOther };
Vector<byte> instructions() const { return instructions_; }
Vector<const byte> reloc_info() const {
return {reloc_info_.get(), reloc_size_};
......@@ -108,12 +113,13 @@ class V8_EXPORT_PRIVATE WasmCode final {
bool IsAnonymous() const { return index_.IsNothing(); }
Kind kind() const { return kind_; }
NativeModule* owner() const { return owner_; }
Tier tier() const { return tier_; }
Address constant_pool() const;
size_t constant_pool_offset() const { return constant_pool_offset_; }
size_t safepoint_table_offset() const { return safepoint_table_offset_; }
size_t handler_table_offset() const { return handler_table_offset_; }
uint32_t stack_slots() const { return stack_slots_; }
bool is_liftoff() const { return is_liftoff_; }
bool is_liftoff() const { return tier_ == kLiftoff; }
size_t trap_handler_index() const;
void set_trap_handler_index(size_t);
......@@ -145,7 +151,7 @@ class V8_EXPORT_PRIVATE WasmCode final {
size_t constant_pool_offset, uint32_t stack_slots,
size_t safepoint_table_offset, size_t handler_table_offset,
std::shared_ptr<ProtectedInstructions> protected_instructions,
bool is_liftoff)
Tier tier)
: instructions_(instructions),
reloc_info_(std::move(reloc_info)),
reloc_size_(reloc_size),
......@@ -157,7 +163,7 @@ class V8_EXPORT_PRIVATE WasmCode final {
safepoint_table_offset_(safepoint_table_offset),
handler_table_offset_(handler_table_offset),
protected_instructions_(std::move(protected_instructions)),
is_liftoff_(is_liftoff) {}
tier_(tier) {}
WasmCode(const WasmCode&) = delete;
WasmCode& operator=(const WasmCode&) = delete;
......@@ -177,7 +183,7 @@ class V8_EXPORT_PRIVATE WasmCode final {
size_t handler_table_offset_ = 0;
intptr_t trap_handler_index_ = -1;
std::shared_ptr<ProtectedInstructions> protected_instructions_;
bool is_liftoff_;
Tier tier_;
};
// Return a textual description of the kind.
......@@ -196,7 +202,8 @@ class V8_EXPORT_PRIVATE NativeModule final {
WasmCode* AddCode(const CodeDesc& desc, uint32_t frame_count, uint32_t index,
size_t safepoint_table_offset, size_t handler_table_offset,
std::unique_ptr<ProtectedInstructions>, bool is_liftoff);
std::unique_ptr<ProtectedInstructions>,
WasmCode::Tier tier);
// A way to copy over JS-allocated code. This is because we compile
// certain wrappers using a different pipeline.
......@@ -289,7 +296,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
uint32_t stack_slots, size_t safepoint_table_offset,
size_t handler_table_offset,
std::shared_ptr<ProtectedInstructions>,
bool is_liftoff);
WasmCode::Tier tier);
WasmCode* CloneCode(const WasmCode*);
bool CloneTrampolinesAndStubs(const NativeModule* other);
WasmCode* Lookup(Address);
......
......@@ -221,16 +221,16 @@ void NativeModuleSerializer::BufferHeader() {
}
size_t NativeModuleSerializer::GetCodeHeaderSize() {
return sizeof(size_t) + // size of this section
sizeof(size_t) + // offset of constant pool
sizeof(size_t) + // offset of safepoint table
sizeof(size_t) + // offset of handler table
sizeof(uint32_t) + // stack slots
sizeof(size_t) + // code size
sizeof(size_t) + // reloc size
sizeof(uint32_t) + // source positions size
sizeof(size_t) + // protected instructions size
sizeof(bool); // is_liftoff
return sizeof(size_t) + // size of this section
sizeof(size_t) + // offset of constant pool
sizeof(size_t) + // offset of safepoint table
sizeof(size_t) + // offset of handler table
sizeof(uint32_t) + // stack slots
sizeof(size_t) + // code size
sizeof(size_t) + // reloc size
sizeof(uint32_t) + // source positions size
sizeof(size_t) + // protected instructions size
sizeof(WasmCode::Tier); // tier
}
size_t NativeModuleSerializer::MeasureCode(const WasmCode* code) const {
......@@ -350,7 +350,7 @@ void NativeModuleSerializer::BufferCodeInAllocatedScratch(
writer.Write(code->reloc_info().size());
writer.Write(source_positions_size);
writer.Write(code->protected_instructions().size());
writer.Write(code->is_liftoff());
writer.Write(code->tier());
// next is the code, which we have to reloc.
Address serialized_code_start = writer.current_buffer().start();
// write the code and everything else
......@@ -545,7 +545,8 @@ bool NativeModuleDeserializer::ReadCode() {
size_t reloc_size = reader.Read<size_t>();
uint32_t source_position_size = reader.Read<uint32_t>();
size_t protected_instructions_size = reader.Read<size_t>();
bool is_liftoff = reader.Read<bool>();
WasmCode::Tier tier = reader.Read<WasmCode::Tier>();
std::shared_ptr<ProtectedInstructions> protected_instructions(
new ProtectedInstructions(protected_instructions_size));
DCHECK_EQ(protected_instructions_size, protected_instructions->size());
......@@ -560,7 +561,7 @@ bool NativeModuleDeserializer::ReadCode() {
code_buffer, std::move(reloc_info), reloc_size, Just(index_),
WasmCode::kFunction, constant_pool_offset, stack_slot_count,
safepoint_table_offset, handler_table_offset, protected_instructions,
is_liftoff);
tier);
if (ret == nullptr) return false;
native_module_->code_table_[index_] = ret;
......
......@@ -187,7 +187,7 @@ class WasmCodeManagerTest : public TestWithIsolate {
std::unique_ptr<byte[]> exec_buff(new byte[size]);
desc.buffer = exec_buff.get();
desc.instr_size = static_cast<int>(size);
return native_module->AddCode(desc, 0, index, 0, 0, {}, false);
return native_module->AddCode(desc, 0, index, 0, 0, {}, WasmCode::kOther);
}
size_t page() const { return AllocatePageSize(); }
......
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