Commit 88401186 authored by Frederik Gossen's avatar Frederik Gossen Committed by Commit Bot

[wasm] Enabled Wasm Interpreter as First-class Tier

Enabled Wasm interpreter as first-class tier. Depending on the flag
{--wasm-interpret-all} the interpreter is the default and only tier
used to run Wasm modules.

Change-Id: I9ffa333f7138437e646dee2113f06c1676bac331
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1516292
Commit-Queue: Frederik Gossen <frgossen@google.com>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60190}
parent 71c66873
......@@ -667,6 +667,7 @@ DEFINE_DEBUG_BOOL(trace_wasm_lazy_compilation, false,
// wasm-interpret-all resets {asm-,}wasm-lazy-compilation.
DEFINE_NEG_IMPLICATION(wasm_interpret_all, asm_wasm_lazy_compilation)
DEFINE_NEG_IMPLICATION(wasm_interpret_all, wasm_lazy_compilation)
DEFINE_NEG_IMPLICATION(wasm_interpret_all, wasm_tier_up)
// Profiler flags.
DEFINE_INT(frame_count, 1, "number of stack frames inspected by the profiler")
......
......@@ -117,9 +117,14 @@ std::unique_ptr<WasmInstructionBuffer> WasmInstructionBuffer::New() {
// static
ExecutionTier WasmCompilationUnit::GetDefaultExecutionTier(
const WasmModule* module) {
return FLAG_liftoff && module->origin == kWasmOrigin
? ExecutionTier::kBaseline
: ExecutionTier::kOptimized;
if (module->origin == kWasmOrigin) {
if (FLAG_wasm_interpret_all) {
return ExecutionTier::kInterpreter;
} else if (FLAG_liftoff) {
return ExecutionTier::kBaseline;
}
}
return ExecutionTier::kOptimized;
}
WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine, int index,
......
......@@ -504,18 +504,6 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
// Set all breakpoints that were set on the shared module.
WasmModuleObject::SetBreakpointsOnNewInstance(module_object_, instance);
if (FLAG_wasm_interpret_all && module_->origin == kWasmOrigin) {
Handle<WasmDebugInfo> debug_info =
WasmInstanceObject::GetOrCreateDebugInfo(instance);
std::vector<int> func_indexes;
for (int func_index = num_imported_functions,
num_wasm_functions = static_cast<int>(module_->functions.size());
func_index < num_wasm_functions; ++func_index) {
func_indexes.push_back(func_index);
}
WasmDebugInfo::RedirectToInterpreter(debug_info, VectorOf(func_indexes));
}
//--------------------------------------------------------------------------
// Create a wrapper for the start function.
//--------------------------------------------------------------------------
......
......@@ -681,13 +681,14 @@ WasmCode* NativeModule::AddDeserializedCode(
size_t code_comments_offset, size_t unpadded_binary_size,
OwnedVector<trap_handler::ProtectedInstructionData> protected_instructions,
OwnedVector<const byte> reloc_info,
OwnedVector<const byte> source_position_table, WasmCode::Tier tier) {
OwnedVector<const byte> source_position_table, WasmCode::Kind kind,
WasmCode::Tier tier) {
WasmCode* code = AddOwnedCode(
index, instructions, stack_slots, tagged_parameter_slots,
safepoint_table_offset, handler_table_offset, constant_pool_offset,
code_comments_offset, unpadded_binary_size,
std::move(protected_instructions), std::move(reloc_info),
std::move(source_position_table), WasmCode::kFunction, tier);
std::move(source_position_table), kind, tier);
if (!code->protected_instructions_.is_empty()) {
code->RegisterTrapHandlerData();
......@@ -740,13 +741,15 @@ void NativeModule::InstallCode(WasmCode* code) {
DCHECK_LT(code->index(), num_functions());
DCHECK_LE(module_->num_imported_functions, code->index());
// Update code table, except for interpreter entries.
if (code->kind() != WasmCode::kInterpreterEntry) {
code_table_[code->index() - module_->num_imported_functions] = code;
// Update code table, except for interpreter entries that would overwrite
// existing code.
uint32_t slot_idx = code->index() - module_->num_imported_functions;
if (code->kind() != WasmCode::kInterpreterEntry ||
code_table_[slot_idx] == nullptr) {
code_table_[slot_idx] = code;
}
// Patch jump table.
uint32_t slot_idx = code->index() - module_->num_imported_functions;
JumpTableAssembler::PatchJumpTableSlot(jump_table_->instruction_start(),
slot_idx, code->instruction_start(),
WasmCode::kFlushICache);
......
......@@ -249,7 +249,8 @@ class V8_EXPORT_PRIVATE NativeModule final {
OwnedVector<trap_handler::ProtectedInstructionData>
protected_instructions,
OwnedVector<const byte> reloc_info,
OwnedVector<const byte> source_position_table, WasmCode::Tier tier);
OwnedVector<const byte> source_position_table, WasmCode::Kind kind,
WasmCode::Tier tier);
// Adds anonymous code for testing purposes.
WasmCode* AddCodeForTesting(Handle<Code> code);
......
......@@ -593,7 +593,6 @@ void WasmDebugInfo::RedirectToInterpreter(Handle<WasmDebugInfo> debug_info,
std::move(result.source_positions), wasm::WasmCode::kInterpreterEntry,
wasm::WasmCode::kOther);
DCHECK_NOT_NULL(wasm_code);
native_module->PublishInterpreterEntry(wasm_code, func_index);
Handle<Foreign> foreign_holder = isolate->factory()->NewForeign(
......
......@@ -188,19 +188,20 @@ constexpr size_t kHeaderSize =
sizeof(uint32_t); // imported functions (index of first wasm function)
constexpr size_t kCodeHeaderSize =
sizeof(size_t) + // size of code section
sizeof(size_t) + // offset of constant pool
sizeof(size_t) + // offset of safepoint table
sizeof(size_t) + // offset of handler table
sizeof(size_t) + // offset of code comments
sizeof(size_t) + // unpadded binary size
sizeof(uint32_t) + // stack slots
sizeof(uint32_t) + // tagged parameter slots
sizeof(size_t) + // code size
sizeof(size_t) + // reloc size
sizeof(size_t) + // source positions size
sizeof(size_t) + // protected instructions size
sizeof(WasmCode::Tier); // tier
sizeof(size_t) + // size of code section
sizeof(size_t) + // offset of constant pool
sizeof(size_t) + // offset of safepoint table
sizeof(size_t) + // offset of handler table
sizeof(size_t) + // offset of code comments
sizeof(size_t) + // unpadded binary size
sizeof(uint32_t) + // stack slots
sizeof(uint32_t) + // tagged parameter slots
sizeof(size_t) + // code size
sizeof(size_t) + // reloc size
sizeof(size_t) + // source positions size
sizeof(size_t) + // protected instructions size
sizeof(WasmCode::Kind) + // code kind
sizeof(WasmCode::Tier); // tier
// A List of all isolate-independent external references. This is used to create
// a tag from the Address of an external reference and vice versa.
......@@ -307,7 +308,8 @@ NativeModuleSerializer::NativeModuleSerializer(
size_t NativeModuleSerializer::MeasureCode(const WasmCode* code) const {
if (code == nullptr) return sizeof(size_t);
DCHECK_EQ(WasmCode::kFunction, code->kind());
DCHECK(code->kind() == WasmCode::kFunction ||
code->kind() == WasmCode::kInterpreterEntry);
return kCodeHeaderSize + code->instructions().size() +
code->reloc_info().size() + code->source_positions().size() +
code->protected_instructions().size() *
......@@ -335,7 +337,8 @@ void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) {
writer->Write(size_t{0});
return;
}
DCHECK_EQ(WasmCode::kFunction, code->kind());
DCHECK(code->kind() == WasmCode::kFunction ||
code->kind() == WasmCode::kInterpreterEntry);
// Write the size of the entire code section, followed by the code header.
writer->Write(MeasureCode(code));
writer->Write(code->constant_pool_offset());
......@@ -349,6 +352,7 @@ void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) {
writer->Write(code->reloc_info().size());
writer->Write(code->source_positions().size());
writer->Write(code->protected_instructions().size());
writer->Write(code->kind());
writer->Write(code->tier());
// Get a pointer to the destination buffer, to hold relocated code.
......@@ -511,6 +515,7 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
size_t reloc_size = reader->Read<size_t>();
size_t source_position_size = reader->Read<size_t>();
size_t protected_instructions_size = reader->Read<size_t>();
WasmCode::Kind kind = reader->Read<WasmCode::Kind>();
WasmCode::Tier tier = reader->Read<WasmCode::Tier>();
Vector<const byte> code_buffer = {reader->current_location(), code_size};
......@@ -530,7 +535,7 @@ bool NativeModuleDeserializer::ReadCode(uint32_t fn_index, Reader* reader) {
safepoint_table_offset, handler_table_offset, constant_pool_offset,
code_comment_offset, unpadded_binary_size,
std::move(protected_instructions), std::move(reloc_info),
std::move(source_pos), tier);
std::move(source_pos), kind, tier);
// Relocate the code.
int mask = RelocInfo::ModeMask(RelocInfo::WASM_CALL) |
......
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