Commit bd502b2b authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Do not store the NativeModule in compilation units

Instead, pass it as a parameter to the compilation.
This makes compilation units slimmer with the end goal of them being
just the function index and execution tier.
It also makes ownership handling of the NativeModule easier.

R=titzer@chromium.org

Bug: v8:8343, v8:7921
Change-Id: I0522c894569c71d8b7245f5ed5612ab2a249e1ad
Reviewed-on: https://chromium-review.googlesource.com/c/1406668Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58776}
parent f5729f1c
...@@ -5717,9 +5717,10 @@ TurbofanWasmCompilationUnit::TurbofanWasmCompilationUnit( ...@@ -5717,9 +5717,10 @@ TurbofanWasmCompilationUnit::TurbofanWasmCompilationUnit(
TurbofanWasmCompilationUnit::~TurbofanWasmCompilationUnit() = default; TurbofanWasmCompilationUnit::~TurbofanWasmCompilationUnit() = default;
bool TurbofanWasmCompilationUnit::BuildGraphForWasmFunction( bool TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
wasm::CompilationEnv* env, const wasm::FunctionBody& func_body, wasm::CompilationEnv* env, wasm::NativeModule* native_module,
wasm::WasmFeatures* detected, double* decode_ms, MachineGraph* mcgraph, const wasm::FunctionBody& func_body, wasm::WasmFeatures* detected,
NodeOriginTable* node_origins, SourcePositionTable* source_positions) { double* decode_ms, MachineGraph* mcgraph, NodeOriginTable* node_origins,
SourcePositionTable* source_positions) {
base::ElapsedTimer decode_timer; base::ElapsedTimer decode_timer;
if (FLAG_trace_wasm_decode_time) { if (FLAG_trace_wasm_decode_time) {
decode_timer.Start(); decode_timer.Start();
...@@ -5729,15 +5730,14 @@ bool TurbofanWasmCompilationUnit::BuildGraphForWasmFunction( ...@@ -5729,15 +5730,14 @@ bool TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
WasmGraphBuilder builder(env, mcgraph->zone(), mcgraph, func_body.sig, WasmGraphBuilder builder(env, mcgraph->zone(), mcgraph, func_body.sig,
source_positions); source_positions);
wasm::VoidResult graph_construction_result = wasm::BuildTFGraph( wasm::VoidResult graph_construction_result = wasm::BuildTFGraph(
wasm_unit_->wasm_engine_->allocator(), wasm_unit_->wasm_engine_->allocator(), native_module->enabled_features(),
wasm_unit_->native_module_->enabled_features(), env->module, &builder, env->module, &builder, detected, func_body, node_origins);
detected, func_body, node_origins);
if (graph_construction_result.failed()) { if (graph_construction_result.failed()) {
if (FLAG_trace_wasm_compiler) { if (FLAG_trace_wasm_compiler) {
StdoutStream{} << "Compilation failed: " StdoutStream{} << "Compilation failed: "
<< graph_construction_result.error_msg() << std::endl; << graph_construction_result.error_msg() << std::endl;
} }
wasm_unit_->native_module()->compilation_state()->SetError( native_module->compilation_state()->SetError(
wasm_unit_->func_index_, std::move(graph_construction_result)); wasm_unit_->func_index_, std::move(graph_construction_result));
return false; return false;
} }
...@@ -5778,8 +5778,9 @@ Vector<const char> GetDebugName(Zone* zone, int index) { ...@@ -5778,8 +5778,9 @@ Vector<const char> GetDebugName(Zone* zone, int index) {
} // namespace } // namespace
void TurbofanWasmCompilationUnit::ExecuteCompilation( void TurbofanWasmCompilationUnit::ExecuteCompilation(
wasm::CompilationEnv* env, const wasm::FunctionBody& func_body, wasm::CompilationEnv* env, wasm::NativeModule* native_module,
Counters* counters, wasm::WasmFeatures* detected) { const wasm::FunctionBody& func_body, Counters* counters,
wasm::WasmFeatures* detected) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"),
"ExecuteTurbofanCompilation"); "ExecuteTurbofanCompilation");
double decode_ms = 0; double decode_ms = 0;
...@@ -5810,8 +5811,9 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation( ...@@ -5810,8 +5811,9 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation(
: nullptr; : nullptr;
SourcePositionTable* source_positions = SourcePositionTable* source_positions =
new (mcgraph->zone()) SourcePositionTable(mcgraph->graph()); new (mcgraph->zone()) SourcePositionTable(mcgraph->graph());
if (!BuildGraphForWasmFunction(env, func_body, detected, &decode_ms, mcgraph, if (!BuildGraphForWasmFunction(env, native_module, func_body, detected,
node_origins, source_positions)) { &decode_ms, mcgraph, node_origins,
source_positions)) {
// Compilation failed. // Compilation failed.
return; return;
} }
...@@ -5834,7 +5836,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation( ...@@ -5834,7 +5836,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation(
if (wasm::WasmCode* wasm_code = Pipeline::GenerateCodeForWasmFunction( if (wasm::WasmCode* wasm_code = Pipeline::GenerateCodeForWasmFunction(
&info, wasm_unit_->wasm_engine_, mcgraph, call_descriptor, &info, wasm_unit_->wasm_engine_, mcgraph, call_descriptor,
source_positions, node_origins, func_body, wasm_unit_->native_module_, source_positions, node_origins, func_body, native_module,
wasm_unit_->func_index_)) { wasm_unit_->func_index_)) {
wasm_unit_->SetResult(wasm_code, counters); wasm_unit_->SetResult(wasm_code, counters);
} }
......
...@@ -51,14 +51,16 @@ class TurbofanWasmCompilationUnit { ...@@ -51,14 +51,16 @@ class TurbofanWasmCompilationUnit {
~TurbofanWasmCompilationUnit(); ~TurbofanWasmCompilationUnit();
bool BuildGraphForWasmFunction(wasm::CompilationEnv* env, bool BuildGraphForWasmFunction(wasm::CompilationEnv* env,
wasm::NativeModule* native_module,
const wasm::FunctionBody& func_body, const wasm::FunctionBody& func_body,
wasm::WasmFeatures* detected, wasm::WasmFeatures* detected,
double* decode_ms, MachineGraph* mcgraph, double* decode_ms, MachineGraph* mcgraph,
NodeOriginTable* node_origins, NodeOriginTable* node_origins,
SourcePositionTable* source_positions); SourcePositionTable* source_positions);
void ExecuteCompilation(wasm::CompilationEnv*, const wasm::FunctionBody&, void ExecuteCompilation(wasm::CompilationEnv*, wasm::NativeModule*,
Counters*, wasm::WasmFeatures* detected); const wasm::FunctionBody&, Counters*,
wasm::WasmFeatures* detected);
private: private:
wasm::WasmCompilationUnit* const wasm_unit_; wasm::WasmCompilationUnit* const wasm_unit_;
......
...@@ -1947,6 +1947,7 @@ class LiftoffCompiler { ...@@ -1947,6 +1947,7 @@ class LiftoffCompiler {
} // namespace } // namespace
bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env, bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env,
NativeModule* native_module,
const FunctionBody& func_body, const FunctionBody& func_body,
Counters* counters, Counters* counters,
WasmFeatures* detected) { WasmFeatures* detected) {
...@@ -1963,8 +1964,8 @@ bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env, ...@@ -1963,8 +1964,8 @@ bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env,
base::Optional<TimedHistogramScope> liftoff_compile_time_scope( base::Optional<TimedHistogramScope> liftoff_compile_time_scope(
base::in_place, counters->liftoff_compile_time()); base::in_place, counters->liftoff_compile_time());
WasmFullDecoder<Decoder::kValidate, LiftoffCompiler> decoder( WasmFullDecoder<Decoder::kValidate, LiftoffCompiler> decoder(
&zone, module, wasm_unit_->native_module_->enabled_features(), detected, &zone, module, native_module->enabled_features(), detected, func_body,
func_body, call_descriptor, env, &zone); call_descriptor, env, &zone);
decoder.Decode(); decoder.Decode();
liftoff_compile_time_scope.reset(); liftoff_compile_time_scope.reset();
LiftoffCompiler* compiler = &decoder.interface(); LiftoffCompiler* compiler = &decoder.interface();
...@@ -1993,7 +1994,7 @@ bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env, ...@@ -1993,7 +1994,7 @@ bool LiftoffCompilationUnit::ExecuteCompilation(CompilationEnv* env,
uint32_t frame_slot_count = compiler->GetTotalFrameSlotCount(); uint32_t frame_slot_count = compiler->GetTotalFrameSlotCount();
int safepoint_table_offset = compiler->GetSafepointTableOffset(); int safepoint_table_offset = compiler->GetSafepointTableOffset();
WasmCode* code = wasm_unit_->native_module_->AddCode( WasmCode* code = native_module->AddCode(
wasm_unit_->func_index_, desc, frame_slot_count, safepoint_table_offset, wasm_unit_->func_index_, desc, frame_slot_count, safepoint_table_offset,
0, std::move(protected_instructions), std::move(source_positions), 0, std::move(protected_instructions), std::move(source_positions),
WasmCode::kFunction, WasmCode::kLiftoff); WasmCode::kFunction, WasmCode::kLiftoff);
......
...@@ -16,6 +16,7 @@ namespace wasm { ...@@ -16,6 +16,7 @@ namespace wasm {
struct CompilationEnv; struct CompilationEnv;
struct FunctionBody; struct FunctionBody;
class NativeModule;
class WasmCompilationUnit; class WasmCompilationUnit;
struct WasmFeatures; struct WasmFeatures;
...@@ -24,8 +25,8 @@ class LiftoffCompilationUnit final { ...@@ -24,8 +25,8 @@ class LiftoffCompilationUnit final {
explicit LiftoffCompilationUnit(WasmCompilationUnit* wasm_unit) explicit LiftoffCompilationUnit(WasmCompilationUnit* wasm_unit)
: wasm_unit_(wasm_unit) {} : wasm_unit_(wasm_unit) {}
bool ExecuteCompilation(CompilationEnv*, const FunctionBody&, Counters*, bool ExecuteCompilation(CompilationEnv*, NativeModule*, const FunctionBody&,
WasmFeatures* detected); Counters*, WasmFeatures* detected);
private: private:
WasmCompilationUnit* const wasm_unit_; WasmCompilationUnit* const wasm_unit_;
......
...@@ -31,24 +31,16 @@ const char* GetExecutionTierAsString(ExecutionTier tier) { ...@@ -31,24 +31,16 @@ const char* GetExecutionTierAsString(ExecutionTier tier) {
} // namespace } // namespace
// static // static
ExecutionTier WasmCompilationUnit::GetDefaultExecutionTier() { ExecutionTier WasmCompilationUnit::GetDefaultExecutionTier(
return FLAG_liftoff ? ExecutionTier::kBaseline : ExecutionTier::kOptimized; const WasmModule* module) {
return FLAG_liftoff && module->origin == kWasmOrigin
? ExecutionTier::kBaseline
: ExecutionTier::kOptimized;
} }
WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine, WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine, int index,
NativeModule* native_module, int index,
ExecutionTier tier) ExecutionTier tier)
: wasm_engine_(wasm_engine), : wasm_engine_(wasm_engine), func_index_(index), tier_(tier) {
func_index_(index),
native_module_(native_module),
tier_(tier) {
const WasmModule* module = native_module->module();
DCHECK_GE(index, module->num_imported_functions);
DCHECK_LT(index, module->functions.size());
// Always disable Liftoff for asm.js, for two reasons:
// 1) asm-specific opcodes are not implemented, and
// 2) tier-up does not work with lazy compilation.
if (module->origin == kAsmJsOrigin) tier = ExecutionTier::kOptimized;
if (V8_UNLIKELY(FLAG_wasm_tier_mask_for_testing) && index < 32 && if (V8_UNLIKELY(FLAG_wasm_tier_mask_for_testing) && index < 32 &&
(FLAG_wasm_tier_mask_for_testing & (1 << index))) { (FLAG_wasm_tier_mask_for_testing & (1 << index))) {
tier = ExecutionTier::kOptimized; tier = ExecutionTier::kOptimized;
...@@ -61,20 +53,18 @@ WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine, ...@@ -61,20 +53,18 @@ WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine,
WasmCompilationUnit::~WasmCompilationUnit() = default; WasmCompilationUnit::~WasmCompilationUnit() = default;
void WasmCompilationUnit::ExecuteCompilation( void WasmCompilationUnit::ExecuteCompilation(
CompilationEnv* env, std::shared_ptr<WireBytesStorage> wire_bytes_storage, CompilationEnv* env, NativeModule* native_module,
Counters* counters, WasmFeatures* detected) { std::shared_ptr<WireBytesStorage> wire_bytes_storage, Counters* counters,
const WasmModule* module = native_module_->module(); WasmFeatures* detected) {
DCHECK_EQ(module, env->module);
auto* func = &env->module->functions[func_index_]; auto* func = &env->module->functions[func_index_];
Vector<const uint8_t> code = wire_bytes_storage->GetCode(func->code); Vector<const uint8_t> code = wire_bytes_storage->GetCode(func->code);
wasm::FunctionBody func_body{func->sig, func->code.offset(), code.start(), wasm::FunctionBody func_body{func->sig, func->code.offset(), code.start(),
code.end()}; code.end()};
auto size_histogram = auto size_histogram = SELECT_WASM_COUNTER(counters, env->module->origin, wasm,
SELECT_WASM_COUNTER(counters, module->origin, wasm, function_size_bytes); function_size_bytes);
size_histogram->AddSample(static_cast<int>(func_body.end - func_body.start)); size_histogram->AddSample(static_cast<int>(func_body.end - func_body.start));
auto timed_histogram = SELECT_WASM_COUNTER(counters, module->origin, auto timed_histogram = SELECT_WASM_COUNTER(counters, env->module->origin,
wasm_compile, function_time); wasm_compile, function_time);
TimedHistogramScope wasm_compile_function_time_scope(timed_histogram); TimedHistogramScope wasm_compile_function_time_scope(timed_histogram);
...@@ -85,8 +75,8 @@ void WasmCompilationUnit::ExecuteCompilation( ...@@ -85,8 +75,8 @@ void WasmCompilationUnit::ExecuteCompilation(
switch (tier_) { switch (tier_) {
case ExecutionTier::kBaseline: case ExecutionTier::kBaseline:
if (liftoff_unit_->ExecuteCompilation(env, func_body, counters, if (liftoff_unit_->ExecuteCompilation(env, native_module, func_body,
detected)) { counters, detected)) {
break; break;
} }
// Otherwise, fall back to turbofan. // Otherwise, fall back to turbofan.
...@@ -95,7 +85,8 @@ void WasmCompilationUnit::ExecuteCompilation( ...@@ -95,7 +85,8 @@ void WasmCompilationUnit::ExecuteCompilation(
// function to avoid compiling it twice with TurboFan. // function to avoid compiling it twice with TurboFan.
V8_FALLTHROUGH; V8_FALLTHROUGH;
case ExecutionTier::kOptimized: case ExecutionTier::kOptimized:
turbofan_unit_->ExecuteCompilation(env, func_body, counters, detected); turbofan_unit_->ExecuteCompilation(env, native_module, func_body,
counters, detected);
break; break;
case ExecutionTier::kInterpreter: case ExecutionTier::kInterpreter:
UNREACHABLE(); // TODO(titzer): compile interpreter entry stub. UNREACHABLE(); // TODO(titzer): compile interpreter entry stub.
...@@ -135,18 +126,18 @@ void WasmCompilationUnit::CompileWasmFunction(Isolate* isolate, ...@@ -135,18 +126,18 @@ void WasmCompilationUnit::CompileWasmFunction(Isolate* isolate,
wire_bytes.start() + function->code.offset(), wire_bytes.start() + function->code.offset(),
wire_bytes.start() + function->code.end_offset()}; wire_bytes.start() + function->code.end_offset()};
WasmCompilationUnit unit(isolate->wasm_engine(), native_module, WasmCompilationUnit unit(isolate->wasm_engine(), function->func_index, tier);
function->func_index, tier);
CompilationEnv env = native_module->CreateCompilationEnv(); CompilationEnv env = native_module->CreateCompilationEnv();
unit.ExecuteCompilation( unit.ExecuteCompilation(
&env, native_module->compilation_state()->GetWireBytesStorage(), &env, native_module,
native_module->compilation_state()->GetWireBytesStorage(),
isolate->counters(), detected); isolate->counters(), detected);
} }
void WasmCompilationUnit::SetResult(WasmCode* code, Counters* counters) { void WasmCompilationUnit::SetResult(WasmCode* code, Counters* counters) {
DCHECK_NULL(result_); DCHECK_NULL(result_);
result_ = code; result_ = code;
native_module()->PublishCode(code); code->native_module()->PublishCode(code);
counters->wasm_generated_code_size()->Increment( counters->wasm_generated_code_size()->Increment(
static_cast<int>(code->instructions().size())); static_cast<int>(code->instructions().size()));
......
...@@ -30,29 +30,27 @@ struct WasmFunction; ...@@ -30,29 +30,27 @@ struct WasmFunction;
class WasmCompilationUnit final { class WasmCompilationUnit final {
public: public:
static ExecutionTier GetDefaultExecutionTier(); static ExecutionTier GetDefaultExecutionTier(const WasmModule*);
// If constructing from a background thread, pass in a Counters*, and ensure // If constructing from a background thread, pass in a Counters*, and ensure
// that the Counters live at least as long as this compilation unit (which // that the Counters live at least as long as this compilation unit (which
// typically means to hold a std::shared_ptr<Counters>). // typically means to hold a std::shared_ptr<Counters>).
// If used exclusively from a foreground thread, Isolate::counters() may be // If used exclusively from a foreground thread, Isolate::counters() may be
// used by callers to pass Counters. // used by callers to pass Counters.
WasmCompilationUnit(WasmEngine*, NativeModule*, int index, WasmCompilationUnit(WasmEngine*, int index, ExecutionTier);
ExecutionTier = GetDefaultExecutionTier());
~WasmCompilationUnit(); ~WasmCompilationUnit();
void ExecuteCompilation(CompilationEnv*, std::shared_ptr<WireBytesStorage>, void ExecuteCompilation(CompilationEnv*, NativeModule*,
Counters*, WasmFeatures* detected); std::shared_ptr<WireBytesStorage>, Counters*,
WasmFeatures* detected);
NativeModule* native_module() const { return native_module_; }
ExecutionTier tier() const { return tier_; } ExecutionTier tier() const { return tier_; }
WasmCode* result() const { return result_; } WasmCode* result() const { return result_; }
static void CompileWasmFunction(Isolate* isolate, NativeModule* native_module, static void CompileWasmFunction(Isolate*, NativeModule*,
WasmFeatures* detected, WasmFeatures* detected, const WasmFunction*,
const WasmFunction* function, ExecutionTier);
ExecutionTier = GetDefaultExecutionTier());
private: private:
friend class LiftoffCompilationUnit; friend class LiftoffCompilationUnit;
...@@ -60,7 +58,6 @@ class WasmCompilationUnit final { ...@@ -60,7 +58,6 @@ class WasmCompilationUnit final {
WasmEngine* const wasm_engine_; WasmEngine* const wasm_engine_;
const int func_index_; const int func_index_;
NativeModule* const native_module_;
ExecutionTier tier_; ExecutionTier tier_;
WasmCode* result_ = nullptr; WasmCode* result_ = nullptr;
......
...@@ -550,10 +550,13 @@ WasmCode* LazyCompileFunction(Isolate* isolate, NativeModule* native_module, ...@@ -550,10 +550,13 @@ WasmCode* LazyCompileFunction(Isolate* isolate, NativeModule* native_module,
module_start + func->code.offset(), module_start + func->code.offset(),
module_start + func->code.end_offset()}; module_start + func->code.end_offset()};
WasmCompilationUnit unit(isolate->wasm_engine(), native_module, func_index); WasmCompilationUnit unit(
isolate->wasm_engine(), func_index,
WasmCompilationUnit::GetDefaultExecutionTier(native_module->module()));
CompilationEnv env = native_module->CreateCompilationEnv(); CompilationEnv env = native_module->CreateCompilationEnv();
unit.ExecuteCompilation( unit.ExecuteCompilation(
&env, native_module->compilation_state()->GetWireBytesStorage(), &env, native_module,
native_module->compilation_state()->GetWireBytesStorage(),
isolate->counters(), isolate->counters(),
Impl(native_module->compilation_state())->detected_features()); Impl(native_module->compilation_state())->detected_features());
...@@ -607,7 +610,10 @@ class CompilationUnitBuilder { ...@@ -607,7 +610,10 @@ class CompilationUnitBuilder {
public: public:
explicit CompilationUnitBuilder(NativeModule* native_module, explicit CompilationUnitBuilder(NativeModule* native_module,
WasmEngine* wasm_engine) WasmEngine* wasm_engine)
: native_module_(native_module), wasm_engine_(wasm_engine) {} : native_module_(native_module),
wasm_engine_(wasm_engine),
default_tier_(WasmCompilationUnit::GetDefaultExecutionTier(
native_module->module())) {}
void AddUnit(uint32_t func_index) { void AddUnit(uint32_t func_index) {
switch (compilation_state()->compile_mode()) { switch (compilation_state()->compile_mode()) {
...@@ -618,8 +624,7 @@ class CompilationUnitBuilder { ...@@ -618,8 +624,7 @@ class CompilationUnitBuilder {
CreateUnit(func_index, ExecutionTier::kBaseline)); CreateUnit(func_index, ExecutionTier::kBaseline));
return; return;
case CompileMode::kRegular: case CompileMode::kRegular:
baseline_units_.emplace_back(CreateUnit( baseline_units_.emplace_back(CreateUnit(func_index, default_tier_));
func_index, WasmCompilationUnit::GetDefaultExecutionTier()));
return; return;
} }
UNREACHABLE(); UNREACHABLE();
...@@ -640,8 +645,8 @@ class CompilationUnitBuilder { ...@@ -640,8 +645,8 @@ class CompilationUnitBuilder {
private: private:
std::unique_ptr<WasmCompilationUnit> CreateUnit(uint32_t func_index, std::unique_ptr<WasmCompilationUnit> CreateUnit(uint32_t func_index,
ExecutionTier tier) { ExecutionTier tier) {
return base::make_unique<WasmCompilationUnit>(wasm_engine_, native_module_, return base::make_unique<WasmCompilationUnit>(wasm_engine_, func_index,
func_index, tier); tier);
} }
CompilationStateImpl* compilation_state() const { CompilationStateImpl* compilation_state() const {
...@@ -650,6 +655,7 @@ class CompilationUnitBuilder { ...@@ -650,6 +655,7 @@ class CompilationUnitBuilder {
NativeModule* const native_module_; NativeModule* const native_module_;
WasmEngine* const wasm_engine_; WasmEngine* const wasm_engine_;
const ExecutionTier default_tier_;
std::vector<std::unique_ptr<WasmCompilationUnit>> baseline_units_; std::vector<std::unique_ptr<WasmCompilationUnit>> baseline_units_;
std::vector<std::unique_ptr<WasmCompilationUnit>> tiering_units_; std::vector<std::unique_ptr<WasmCompilationUnit>> tiering_units_;
}; };
...@@ -685,6 +691,7 @@ double MonotonicallyIncreasingTimeInMs() { ...@@ -685,6 +691,7 @@ double MonotonicallyIncreasingTimeInMs() {
// within the result_mutex_ lock when no finishing task is running, i.e. when // within the result_mutex_ lock when no finishing task is running, i.e. when
// the finisher_is_running_ flag is not set. // the finisher_is_running_ flag is not set.
bool FetchAndExecuteCompilationUnit(CompilationEnv* env, bool FetchAndExecuteCompilationUnit(CompilationEnv* env,
NativeModule* native_module,
CompilationStateImpl* compilation_state, CompilationStateImpl* compilation_state,
WasmFeatures* detected, WasmFeatures* detected,
Counters* counters) { Counters* counters) {
...@@ -697,7 +704,8 @@ bool FetchAndExecuteCompilationUnit(CompilationEnv* env, ...@@ -697,7 +704,8 @@ bool FetchAndExecuteCompilationUnit(CompilationEnv* env,
// Get the tier before starting compilation, as compilation can switch tiers // Get the tier before starting compilation, as compilation can switch tiers
// if baseline bails out. // if baseline bails out.
ExecutionTier tier = unit->tier(); ExecutionTier tier = unit->tier();
unit->ExecuteCompilation(env, compilation_state->GetSharedWireBytesStorage(), unit->ExecuteCompilation(env, native_module,
compilation_state->GetSharedWireBytesStorage(),
counters, detected); counters, detected);
compilation_state->OnFinishedUnit(tier, unit->result()); compilation_state->OnFinishedUnit(tier, unit->result());
...@@ -770,7 +778,7 @@ void CompileInParallel(Isolate* isolate, NativeModule* native_module) { ...@@ -770,7 +778,7 @@ void CompileInParallel(Isolate* isolate, NativeModule* native_module) {
// a time and execute the parallel phase of the compilation unit. // a time and execute the parallel phase of the compilation unit.
WasmFeatures detected_features; WasmFeatures detected_features;
CompilationEnv env = native_module->CreateCompilationEnv(); CompilationEnv env = native_module->CreateCompilationEnv();
while (FetchAndExecuteCompilationUnit(&env, compilation_state, while (FetchAndExecuteCompilationUnit(&env, native_module, compilation_state,
&detected_features, &detected_features,
isolate->counters()) && isolate->counters()) &&
!compilation_state->baseline_compilation_finished()) { !compilation_state->baseline_compilation_finished()) {
...@@ -812,12 +820,14 @@ void CompileSequentially(Isolate* isolate, NativeModule* native_module, ...@@ -812,12 +820,14 @@ void CompileSequentially(Isolate* isolate, NativeModule* native_module,
const WasmModule* module = native_module->module(); const WasmModule* module = native_module->module();
WasmFeatures detected = kNoWasmFeatures; WasmFeatures detected = kNoWasmFeatures;
auto* comp_state = Impl(native_module->compilation_state()); auto* comp_state = Impl(native_module->compilation_state());
ExecutionTier tier =
WasmCompilationUnit::GetDefaultExecutionTier(native_module->module());
for (const WasmFunction& func : module->functions) { for (const WasmFunction& func : module->functions) {
if (func.imported) continue; // Imports are compiled at instantiation time. if (func.imported) continue; // Imports are compiled at instantiation time.
// Compile the function. // Compile the function.
WasmCompilationUnit::CompileWasmFunction(isolate, native_module, &detected, WasmCompilationUnit::CompileWasmFunction(isolate, native_module, &detected,
&func); &func, tier);
if (comp_state->failed()) { if (comp_state->failed()) {
thrower->CompileFailed(comp_state->GetCompileError()); thrower->CompileFailed(comp_state->GetCompileError());
break; break;
...@@ -975,8 +985,9 @@ class BackgroundCompileTask : public CancelableTask { ...@@ -975,8 +985,9 @@ class BackgroundCompileTask : public CancelableTask {
auto* compilation_state = Impl(native_module_->compilation_state()); auto* compilation_state = Impl(native_module_->compilation_state());
WasmFeatures detected_features = kNoWasmFeatures; WasmFeatures detected_features = kNoWasmFeatures;
while (!compilation_state->failed()) { while (!compilation_state->failed()) {
if (!FetchAndExecuteCompilationUnit(&env, compilation_state, if (!FetchAndExecuteCompilationUnit(&env, native_module_,
&detected_features, counters_)) { compilation_state, &detected_features,
counters_)) {
break; break;
} }
} }
......
...@@ -419,11 +419,12 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) { ...@@ -419,11 +419,12 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
func_wire_bytes.start(), func_wire_bytes.end()}; func_wire_bytes.start(), func_wire_bytes.end()};
NativeModule* native_module = NativeModule* native_module =
builder_->instance_object()->module_object()->native_module(); builder_->instance_object()->module_object()->native_module();
WasmCompilationUnit unit(isolate()->wasm_engine(), native_module, WasmCompilationUnit unit(isolate()->wasm_engine(), function_->func_index,
function_->func_index, tier); tier);
WasmFeatures unused_detected_features; WasmFeatures unused_detected_features;
unit.ExecuteCompilation( unit.ExecuteCompilation(
&env, native_module->compilation_state()->GetWireBytesStorage(), &env, native_module,
native_module->compilation_state()->GetWireBytesStorage(),
isolate()->counters(), &unused_detected_features); isolate()->counters(), &unused_detected_features);
WasmCode* result = unit.result(); WasmCode* result = unit.result();
DCHECK_NOT_NULL(result); DCHECK_NOT_NULL(result);
......
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