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

[wasm] Remove WasmEngine* from compilation units

The wasm engine is the same for all units, thus we should store (or
get) it in the compilation task, and not store it duplicated in each
compilation unit.

R=mstarzinger@chromium.org

Bug: v8:8916, v8:8343
Change-Id: Id4b062b5b8a52228b4d6051a67e025088a61d466
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1559863
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60754}
parent 04156067
...@@ -6115,9 +6115,10 @@ TurbofanWasmCompilationUnit::TurbofanWasmCompilationUnit( ...@@ -6115,9 +6115,10 @@ TurbofanWasmCompilationUnit::TurbofanWasmCompilationUnit(
TurbofanWasmCompilationUnit::~TurbofanWasmCompilationUnit() = default; TurbofanWasmCompilationUnit::~TurbofanWasmCompilationUnit() = default;
bool TurbofanWasmCompilationUnit::BuildGraphForWasmFunction( bool TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
wasm::CompilationEnv* env, const wasm::FunctionBody& func_body, AccountingAllocator* allocator, wasm::CompilationEnv* env,
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();
...@@ -6126,9 +6127,9 @@ bool TurbofanWasmCompilationUnit::BuildGraphForWasmFunction( ...@@ -6126,9 +6127,9 @@ bool TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
// Create a TF graph during decoding. // Create a TF graph during decoding.
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_unit_->wasm_engine_->allocator(), env->enabled_features, env->module, wasm::BuildTFGraph(allocator, env->enabled_features, env->module,
&builder, detected, func_body, node_origins); &builder, 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: "
...@@ -6149,8 +6150,7 @@ bool TurbofanWasmCompilationUnit::BuildGraphForWasmFunction( ...@@ -6149,8 +6150,7 @@ bool TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
if (wasm_unit_->func_index_ >= FLAG_trace_wasm_ast_start && if (wasm_unit_->func_index_ >= FLAG_trace_wasm_ast_start &&
wasm_unit_->func_index_ < FLAG_trace_wasm_ast_end) { wasm_unit_->func_index_ < FLAG_trace_wasm_ast_end) {
PrintRawWasmCode(wasm_unit_->wasm_engine_->allocator(), func_body, PrintRawWasmCode(allocator, func_body, env->module, wasm::kPrintLocals);
env->module, wasm::kPrintLocals);
} }
if (FLAG_trace_wasm_decode_time) { if (FLAG_trace_wasm_decode_time) {
*decode_ms = decode_timer.Elapsed().InMillisecondsF(); *decode_ms = decode_timer.Elapsed().InMillisecondsF();
...@@ -6174,14 +6174,15 @@ Vector<const char> GetDebugName(Zone* zone, int index) { ...@@ -6174,14 +6174,15 @@ Vector<const char> GetDebugName(Zone* zone, int index) {
} // namespace } // namespace
wasm::WasmCompilationResult TurbofanWasmCompilationUnit::ExecuteCompilation( wasm::WasmCompilationResult TurbofanWasmCompilationUnit::ExecuteCompilation(
wasm::CompilationEnv* env, const wasm::FunctionBody& func_body, wasm::WasmEngine* wasm_engine, wasm::CompilationEnv* env,
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;
size_t node_count = 0; size_t node_count = 0;
Zone zone(wasm_unit_->wasm_engine_->allocator(), ZONE_NAME); Zone zone(wasm_engine->allocator(), ZONE_NAME);
MachineGraph* mcgraph = new (&zone) MachineGraph( MachineGraph* mcgraph = new (&zone) MachineGraph(
new (&zone) Graph(&zone), new (&zone) CommonOperatorBuilder(&zone), new (&zone) Graph(&zone), new (&zone) CommonOperatorBuilder(&zone),
new (&zone) MachineOperatorBuilder( new (&zone) MachineOperatorBuilder(
...@@ -6206,8 +6207,9 @@ wasm::WasmCompilationResult TurbofanWasmCompilationUnit::ExecuteCompilation( ...@@ -6206,8 +6207,9 @@ wasm::WasmCompilationResult 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(wasm_engine->allocator(), env, func_body,
node_origins, source_positions)) { detected, &decode_ms, mcgraph, node_origins,
source_positions)) {
return wasm::WasmCompilationResult{}; return wasm::WasmCompilationResult{};
} }
...@@ -6228,9 +6230,8 @@ wasm::WasmCompilationResult TurbofanWasmCompilationUnit::ExecuteCompilation( ...@@ -6228,9 +6230,8 @@ wasm::WasmCompilationResult TurbofanWasmCompilationUnit::ExecuteCompilation(
} }
Pipeline::GenerateCodeForWasmFunction( Pipeline::GenerateCodeForWasmFunction(
&info, wasm_unit_->wasm_engine_, mcgraph, call_descriptor, &info, wasm_engine, mcgraph, call_descriptor, source_positions,
source_positions, node_origins, func_body, env->module, node_origins, func_body, env->module, wasm_unit_->func_index_);
wasm_unit_->func_index_);
if (FLAG_trace_wasm_decode_time) { if (FLAG_trace_wasm_decode_time) {
double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF(); double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF();
...@@ -6249,18 +6250,19 @@ wasm::WasmCompilationResult TurbofanWasmCompilationUnit::ExecuteCompilation( ...@@ -6249,18 +6250,19 @@ wasm::WasmCompilationResult TurbofanWasmCompilationUnit::ExecuteCompilation(
} }
wasm::WasmCompilationResult InterpreterCompilationUnit::ExecuteCompilation( wasm::WasmCompilationResult InterpreterCompilationUnit::ExecuteCompilation(
wasm::CompilationEnv* env, const wasm::FunctionBody& func_body, wasm::WasmEngine* wasm_engine, wasm::CompilationEnv* env,
Counters* counters, wasm::WasmFeatures* detected) { const wasm::FunctionBody& func_body, Counters* counters,
Zone zone(wasm_unit_->wasm_engine_->allocator(), ZONE_NAME); wasm::WasmFeatures* detected) {
Zone zone(wasm_engine->allocator(), ZONE_NAME);
const wasm::WasmModule* module = env ? env->module : nullptr; const wasm::WasmModule* module = env ? env->module : nullptr;
wasm::WasmFullDecoder<wasm::Decoder::kValidate, wasm::EmptyInterface> decoder( wasm::WasmFullDecoder<wasm::Decoder::kValidate, wasm::EmptyInterface> decoder(
&zone, module, env->enabled_features, detected, func_body); &zone, module, env->enabled_features, detected, func_body);
decoder.Decode(); decoder.Decode();
if (decoder.failed()) return wasm::WasmCompilationResult{}; if (decoder.failed()) return wasm::WasmCompilationResult{};
wasm::WasmCompilationResult result = CompileWasmInterpreterEntry( wasm::WasmCompilationResult result =
wasm_unit_->wasm_engine_, env->enabled_features, wasm_unit_->func_index_, CompileWasmInterpreterEntry(wasm_engine, env->enabled_features,
func_body.sig); wasm_unit_->func_index_, func_body.sig);
DCHECK(result.succeeded()); DCHECK(result.succeeded());
DCHECK_EQ(wasm::ExecutionTier::kInterpreter, result.result_tier); DCHECK_EQ(wasm::ExecutionTier::kInterpreter, result.result_tier);
......
...@@ -50,14 +50,16 @@ class TurbofanWasmCompilationUnit { ...@@ -50,14 +50,16 @@ class TurbofanWasmCompilationUnit {
explicit TurbofanWasmCompilationUnit(wasm::WasmCompilationUnit* wasm_unit); explicit TurbofanWasmCompilationUnit(wasm::WasmCompilationUnit* wasm_unit);
~TurbofanWasmCompilationUnit(); ~TurbofanWasmCompilationUnit();
bool BuildGraphForWasmFunction(wasm::CompilationEnv* env, bool BuildGraphForWasmFunction(AccountingAllocator* allocator,
wasm::CompilationEnv* env,
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);
wasm::WasmCompilationResult ExecuteCompilation(wasm::CompilationEnv*, wasm::WasmCompilationResult ExecuteCompilation(wasm::WasmEngine*,
wasm::CompilationEnv*,
const wasm::FunctionBody&, const wasm::FunctionBody&,
Counters*, Counters*,
wasm::WasmFeatures* detected); wasm::WasmFeatures* detected);
...@@ -73,7 +75,8 @@ class InterpreterCompilationUnit final { ...@@ -73,7 +75,8 @@ class InterpreterCompilationUnit final {
explicit InterpreterCompilationUnit(wasm::WasmCompilationUnit* wasm_unit) explicit InterpreterCompilationUnit(wasm::WasmCompilationUnit* wasm_unit)
: wasm_unit_(wasm_unit) {} : wasm_unit_(wasm_unit) {}
wasm::WasmCompilationResult ExecuteCompilation(wasm::CompilationEnv*, wasm::WasmCompilationResult ExecuteCompilation(wasm::WasmEngine*,
wasm::CompilationEnv*,
const wasm::FunctionBody&, const wasm::FunctionBody&,
Counters*, Counters*,
wasm::WasmFeatures* detected); wasm::WasmFeatures* detected);
......
...@@ -2033,8 +2033,8 @@ class LiftoffCompiler { ...@@ -2033,8 +2033,8 @@ class LiftoffCompiler {
} // namespace } // namespace
WasmCompilationResult LiftoffCompilationUnit::ExecuteCompilation( WasmCompilationResult LiftoffCompilationUnit::ExecuteCompilation(
CompilationEnv* env, const FunctionBody& func_body, Counters* counters, AccountingAllocator* allocator, CompilationEnv* env,
WasmFeatures* detected) { const FunctionBody& func_body, Counters* counters, WasmFeatures* detected) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"),
"ExecuteLiftoffCompilation"); "ExecuteLiftoffCompilation");
base::ElapsedTimer compile_timer; base::ElapsedTimer compile_timer;
...@@ -2042,7 +2042,7 @@ WasmCompilationResult LiftoffCompilationUnit::ExecuteCompilation( ...@@ -2042,7 +2042,7 @@ WasmCompilationResult LiftoffCompilationUnit::ExecuteCompilation(
compile_timer.Start(); compile_timer.Start();
} }
Zone zone(wasm_unit_->wasm_engine_->allocator(), "LiftoffCompilationZone"); Zone zone(allocator, "LiftoffCompilationZone");
const WasmModule* module = env ? env->module : nullptr; const WasmModule* module = env ? env->module : nullptr;
auto call_descriptor = compiler::GetWasmCallDescriptor(&zone, func_body.sig); auto call_descriptor = compiler::GetWasmCallDescriptor(&zone, func_body.sig);
base::Optional<TimedHistogramScope> liftoff_compile_time_scope( base::Optional<TimedHistogramScope> liftoff_compile_time_scope(
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class AccountingAllocator;
class Counters; class Counters;
namespace wasm { namespace wasm {
...@@ -22,16 +23,14 @@ struct WasmFeatures; ...@@ -22,16 +23,14 @@ struct WasmFeatures;
class LiftoffCompilationUnit final { class LiftoffCompilationUnit final {
public: public:
explicit LiftoffCompilationUnit(WasmCompilationUnit* wasm_unit) LiftoffCompilationUnit() = default;
: wasm_unit_(wasm_unit) {}
WasmCompilationResult ExecuteCompilation(CompilationEnv*, const FunctionBody&, WasmCompilationResult ExecuteCompilation(AccountingAllocator*,
CompilationEnv*, const FunctionBody&,
Counters*, Counters*,
WasmFeatures* detected_features); WasmFeatures* detected_features);
private: private:
WasmCompilationUnit* const wasm_unit_;
DISALLOW_COPY_AND_ASSIGN(LiftoffCompilationUnit); DISALLOW_COPY_AND_ASSIGN(LiftoffCompilationUnit);
}; };
......
...@@ -115,9 +115,8 @@ ExecutionTier WasmCompilationUnit::GetDefaultExecutionTier( ...@@ -115,9 +115,8 @@ ExecutionTier WasmCompilationUnit::GetDefaultExecutionTier(
return ExecutionTier::kTurbofan; return ExecutionTier::kTurbofan;
} }
WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine, int index, WasmCompilationUnit::WasmCompilationUnit(int index, ExecutionTier tier)
ExecutionTier tier) : func_index_(index), tier_(tier) {
: wasm_engine_(wasm_engine), func_index_(index), tier_(tier) {
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::kTurbofan; tier = ExecutionTier::kTurbofan;
...@@ -130,7 +129,7 @@ WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine, int index, ...@@ -130,7 +129,7 @@ WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine, int index,
WasmCompilationUnit::~WasmCompilationUnit() = default; WasmCompilationUnit::~WasmCompilationUnit() = default;
WasmCompilationResult WasmCompilationUnit::ExecuteCompilation( WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
CompilationEnv* env, WasmEngine* wasm_engine, CompilationEnv* env,
const std::shared_ptr<WireBytesStorage>& wire_bytes_storage, const std::shared_ptr<WireBytesStorage>& wire_bytes_storage,
Counters* counters, WasmFeatures* detected) { Counters* counters, WasmFeatures* detected) {
auto* func = &env->module->functions[func_index_]; auto* func = &env->module->functions[func_index_];
...@@ -156,8 +155,8 @@ WasmCompilationResult WasmCompilationUnit::ExecuteCompilation( ...@@ -156,8 +155,8 @@ WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
WasmCompilationResult result; WasmCompilationResult result;
if (liftoff_unit_) { if (liftoff_unit_) {
result = result = liftoff_unit_->ExecuteCompilation(wasm_engine->allocator(), env,
liftoff_unit_->ExecuteCompilation(env, func_body, counters, detected); func_body, counters, detected);
if (!result.succeeded()) { if (!result.succeeded()) {
// If Liftoff failed, fall back to turbofan. // If Liftoff failed, fall back to turbofan.
// TODO(wasm): We could actually stop or remove the tiering unit for this // TODO(wasm): We could actually stop or remove the tiering unit for this
...@@ -167,12 +166,12 @@ WasmCompilationResult WasmCompilationUnit::ExecuteCompilation( ...@@ -167,12 +166,12 @@ WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
} }
} }
if (turbofan_unit_) { if (turbofan_unit_) {
result = result = turbofan_unit_->ExecuteCompilation(wasm_engine, env, func_body,
turbofan_unit_->ExecuteCompilation(env, func_body, counters, detected); counters, detected);
} }
if (interpreter_unit_) { if (interpreter_unit_) {
result = interpreter_unit_->ExecuteCompilation(env, func_body, counters, result = interpreter_unit_->ExecuteCompilation(wasm_engine, env, func_body,
detected); counters, detected);
} }
result.func_index = func_index_; result.func_index = func_index_;
result.requested_tier = tier_; result.requested_tier = tier_;
...@@ -196,7 +195,7 @@ void WasmCompilationUnit::SwitchTier(ExecutionTier new_tier) { ...@@ -196,7 +195,7 @@ void WasmCompilationUnit::SwitchTier(ExecutionTier new_tier) {
DCHECK(!turbofan_unit_); DCHECK(!turbofan_unit_);
DCHECK(!liftoff_unit_); DCHECK(!liftoff_unit_);
DCHECK(!interpreter_unit_); DCHECK(!interpreter_unit_);
liftoff_unit_.reset(new LiftoffCompilationUnit(this)); liftoff_unit_.reset(new LiftoffCompilationUnit());
return; return;
case ExecutionTier::kTurbofan: case ExecutionTier::kTurbofan:
DCHECK(!turbofan_unit_); DCHECK(!turbofan_unit_);
...@@ -227,10 +226,11 @@ void WasmCompilationUnit::CompileWasmFunction(Isolate* isolate, ...@@ -227,10 +226,11 @@ 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(), function->func_index, tier); WasmCompilationUnit unit(function->func_index, tier);
CompilationEnv env = native_module->CreateCompilationEnv(); CompilationEnv env = native_module->CreateCompilationEnv();
WasmCompilationResult result = unit.ExecuteCompilation( WasmCompilationResult result = unit.ExecuteCompilation(
&env, native_module->compilation_state()->GetWireBytesStorage(), isolate->wasm_engine(), &env,
native_module->compilation_state()->GetWireBytesStorage(),
isolate->counters(), detected); isolate->counters(), detected);
if (result.succeeded()) { if (result.succeeded()) {
WasmCodeRefScope code_ref_scope; WasmCodeRefScope code_ref_scope;
......
...@@ -70,13 +70,13 @@ class V8_EXPORT_PRIVATE WasmCompilationUnit final { ...@@ -70,13 +70,13 @@ class V8_EXPORT_PRIVATE WasmCompilationUnit final {
public: public:
static ExecutionTier GetDefaultExecutionTier(const WasmModule*); static ExecutionTier GetDefaultExecutionTier(const WasmModule*);
WasmCompilationUnit(WasmEngine*, int index, ExecutionTier); WasmCompilationUnit(int index, ExecutionTier);
~WasmCompilationUnit(); ~WasmCompilationUnit();
WasmCompilationResult ExecuteCompilation( WasmCompilationResult ExecuteCompilation(
CompilationEnv*, const std::shared_ptr<WireBytesStorage>&, Counters*, WasmEngine*, CompilationEnv*, const std::shared_ptr<WireBytesStorage>&,
WasmFeatures* detected); Counters*, WasmFeatures* detected);
ExecutionTier tier() const { return tier_; } ExecutionTier tier() const { return tier_; }
...@@ -89,7 +89,6 @@ class V8_EXPORT_PRIVATE WasmCompilationUnit final { ...@@ -89,7 +89,6 @@ class V8_EXPORT_PRIVATE WasmCompilationUnit final {
friend class compiler::TurbofanWasmCompilationUnit; friend class compiler::TurbofanWasmCompilationUnit;
friend class compiler::InterpreterCompilationUnit; friend class compiler::InterpreterCompilationUnit;
WasmEngine* const wasm_engine_;
const int func_index_; const int func_index_;
ExecutionTier tier_; ExecutionTier tier_;
......
...@@ -553,10 +553,8 @@ ExecutionTierPair GetRequestedExecutionTiers( ...@@ -553,10 +553,8 @@ ExecutionTierPair GetRequestedExecutionTiers(
// {CompilationStateImpl} when {Commit} is called. // {CompilationStateImpl} when {Commit} is called.
class CompilationUnitBuilder { class CompilationUnitBuilder {
public: public:
explicit CompilationUnitBuilder(NativeModule* native_module, explicit CompilationUnitBuilder(NativeModule* native_module)
WasmEngine* wasm_engine)
: native_module_(native_module), : native_module_(native_module),
wasm_engine_(wasm_engine),
default_tier_(WasmCompilationUnit::GetDefaultExecutionTier( default_tier_(WasmCompilationUnit::GetDefaultExecutionTier(
native_module->module())) {} native_module->module())) {}
...@@ -586,8 +584,7 @@ class CompilationUnitBuilder { ...@@ -586,8 +584,7 @@ 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_, func_index, return base::make_unique<WasmCompilationUnit>(func_index, tier);
tier);
} }
CompilationStateImpl* compilation_state() const { CompilationStateImpl* compilation_state() const {
...@@ -595,7 +592,6 @@ class CompilationUnitBuilder { ...@@ -595,7 +592,6 @@ class CompilationUnitBuilder {
} }
NativeModule* const native_module_; NativeModule* const native_module_;
WasmEngine* const wasm_engine_;
const ExecutionTier default_tier_; 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_;
...@@ -633,18 +629,17 @@ void CompileLazy(Isolate* isolate, NativeModule* native_module, ...@@ -633,18 +629,17 @@ void CompileLazy(Isolate* isolate, NativeModule* native_module,
native_module->module(), compilation_state->compile_mode(), native_module->module(), compilation_state->compile_mode(),
native_module->enabled_features(), func_index); native_module->enabled_features(), func_index);
WasmCompilationUnit baseline_unit(isolate->wasm_engine(), func_index, WasmCompilationUnit baseline_unit(func_index, tiers.baseline_tier);
tiers.baseline_tier);
CompilationEnv env = native_module->CreateCompilationEnv(); CompilationEnv env = native_module->CreateCompilationEnv();
WasmCompilationResult result = baseline_unit.ExecuteCompilation( WasmCompilationResult result = baseline_unit.ExecuteCompilation(
&env, compilation_state->GetWireBytesStorage(), isolate->counters(), isolate->wasm_engine(), &env, compilation_state->GetWireBytesStorage(),
compilation_state->detected_features()); isolate->counters(), compilation_state->detected_features());
WasmCodeRefScope code_ref_scope; WasmCodeRefScope code_ref_scope;
WasmCode* code = native_module->AddCompiledCode(std::move(result)); WasmCode* code = native_module->AddCompiledCode(std::move(result));
if (tiers.baseline_tier < tiers.top_tier) { if (tiers.baseline_tier < tiers.top_tier) {
auto tiering_unit = base::make_unique<WasmCompilationUnit>( auto tiering_unit =
isolate->wasm_engine(), func_index, tiers.top_tier); base::make_unique<WasmCompilationUnit>(func_index, tiers.top_tier);
compilation_state->AddTopTierCompilationUnit(std::move(tiering_unit)); compilation_state->AddTopTierCompilationUnit(std::move(tiering_unit));
} }
...@@ -678,7 +673,8 @@ void RecordStats(const Code code, Counters* counters) { ...@@ -678,7 +673,8 @@ void RecordStats(const Code code, Counters* counters) {
// Run by the main thread to take part in compilation. Only used for synchronous // Run by the main thread to take part in compilation. Only used for synchronous
// compilation. // compilation.
bool FetchAndExecuteCompilationUnit(CompilationEnv* env, bool FetchAndExecuteCompilationUnit(WasmEngine* wasm_engine,
CompilationEnv* env,
NativeModule* native_module, NativeModule* native_module,
CompilationStateImpl* compilation_state, CompilationStateImpl* compilation_state,
WasmFeatures* detected, WasmFeatures* detected,
...@@ -694,7 +690,8 @@ bool FetchAndExecuteCompilationUnit(CompilationEnv* env, ...@@ -694,7 +690,8 @@ bool FetchAndExecuteCompilationUnit(CompilationEnv* env,
if (unit == nullptr) return false; if (unit == nullptr) return false;
WasmCompilationResult result = unit->ExecuteCompilation( WasmCompilationResult result = unit->ExecuteCompilation(
env, compilation_state->GetWireBytesStorage(), counters, detected); wasm_engine, env, compilation_state->GetWireBytesStorage(), counters,
detected);
if (result.succeeded()) { if (result.succeeded()) {
WasmCodeRefScope code_ref_scope; WasmCodeRefScope code_ref_scope;
...@@ -758,8 +755,7 @@ void ValidateSequentially(Counters* counters, AccountingAllocator* allocator, ...@@ -758,8 +755,7 @@ void ValidateSequentially(Counters* counters, AccountingAllocator* allocator,
// TODO(wasm): This function should not depend on an isolate. Internally, it is // TODO(wasm): This function should not depend on an isolate. Internally, it is
// used for the ErrorThrower only. // used for the ErrorThrower only.
bool InitializeCompilationUnits(Isolate* isolate, NativeModule* native_module, bool InitializeCompilationUnits(Isolate* isolate, NativeModule* native_module) {
WasmEngine* wasm_engine) {
// Set number of functions that must be compiled to consider the module fully // Set number of functions that must be compiled to consider the module fully
// compiled. // compiled.
auto wasm_module = native_module->module(); auto wasm_module = native_module->module();
...@@ -775,7 +771,7 @@ bool InitializeCompilationUnits(Isolate* isolate, NativeModule* native_module, ...@@ -775,7 +771,7 @@ bool InitializeCompilationUnits(Isolate* isolate, NativeModule* native_module,
ErrorThrower thrower(isolate, "WebAssembly.compile()"); ErrorThrower thrower(isolate, "WebAssembly.compile()");
ModuleWireBytes wire_bytes(native_module->wire_bytes()); ModuleWireBytes wire_bytes(native_module->wire_bytes());
const WasmModule* module = native_module->module(); const WasmModule* module = native_module->module();
CompilationUnitBuilder builder(native_module, wasm_engine); CompilationUnitBuilder builder(native_module);
uint32_t start = module->num_imported_functions; uint32_t start = module->num_imported_functions;
uint32_t end = start + module->num_declared_functions; uint32_t end = start + module->num_declared_functions;
for (uint32_t func_index = start; func_index < end; func_index++) { for (uint32_t func_index = start; func_index < end; func_index++) {
...@@ -834,8 +830,7 @@ void CompileNativeModule(Isolate* isolate, ErrorThrower* thrower, ...@@ -834,8 +830,7 @@ void CompileNativeModule(Isolate* isolate, ErrorThrower* thrower,
DCHECK_GE(kMaxInt, native_module->module()->num_declared_functions); DCHECK_GE(kMaxInt, native_module->module()->num_declared_functions);
// Initialize the compilation units and kick off background compile tasks. // Initialize the compilation units and kick off background compile tasks.
if (!InitializeCompilationUnits(isolate, native_module, if (!InitializeCompilationUnits(isolate, native_module)) {
isolate->wasm_engine())) {
// TODO(frgossen): Add test coverage for this path. // TODO(frgossen): Add test coverage for this path.
DCHECK(native_module->enabled_features().compilation_hints); DCHECK(native_module->enabled_features().compilation_hints);
compilation_state->SetError(); compilation_state->SetError();
...@@ -854,8 +849,9 @@ void CompileNativeModule(Isolate* isolate, ErrorThrower* thrower, ...@@ -854,8 +849,9 @@ void CompileNativeModule(Isolate* isolate, ErrorThrower* thrower,
// deterministic compilation; in that case, the single background task will // deterministic compilation; in that case, the single background task will
// execute all compilation. // execute all compilation.
if (NeedsDeterministicCompile()) continue; if (NeedsDeterministicCompile()) continue;
FetchAndExecuteCompilationUnit(&env, native_module, compilation_state, FetchAndExecuteCompilationUnit(isolate->wasm_engine(), &env, native_module,
&detected_features, isolate->counters()); compilation_state, &detected_features,
isolate->counters());
} }
// Publish features from the foreground and background tasks. // Publish features from the foreground and background tasks.
...@@ -897,6 +893,7 @@ class BackgroundCompileTask : public CancelableTask { ...@@ -897,6 +893,7 @@ class BackgroundCompileTask : public CancelableTask {
base::Optional<CompilationEnv> env; base::Optional<CompilationEnv> env;
std::shared_ptr<WireBytesStorage> wire_bytes; std::shared_ptr<WireBytesStorage> wire_bytes;
std::shared_ptr<const WasmModule> module; std::shared_ptr<const WasmModule> module;
WasmEngine* wasm_engine = nullptr;
std::unique_ptr<WasmCompilationUnit> unit; std::unique_ptr<WasmCompilationUnit> unit;
WasmFeatures detected_features = kNoWasmFeatures; WasmFeatures detected_features = kNoWasmFeatures;
...@@ -908,6 +905,7 @@ class BackgroundCompileTask : public CancelableTask { ...@@ -908,6 +905,7 @@ class BackgroundCompileTask : public CancelableTask {
env.emplace(compile_scope.native_module()->CreateCompilationEnv()); env.emplace(compile_scope.native_module()->CreateCompilationEnv());
wire_bytes = compile_scope.compilation_state()->GetWireBytesStorage(); wire_bytes = compile_scope.compilation_state()->GetWireBytesStorage();
module = compile_scope.native_module()->shared_module(); module = compile_scope.native_module()->shared_module();
wasm_engine = compile_scope.native_module()->engine();
unit = unit =
compile_scope.compilation_state()->GetNextCompilationUnit(task_id_); compile_scope.compilation_state()->GetNextCompilationUnit(task_id_);
if (unit == nullptr) { if (unit == nullptr) {
...@@ -934,8 +932,9 @@ class BackgroundCompileTask : public CancelableTask { ...@@ -934,8 +932,9 @@ class BackgroundCompileTask : public CancelableTask {
bool compilation_failed = false; bool compilation_failed = false;
while (true) { while (true) {
// (asynchronous): Execute the compilation. // (asynchronous): Execute the compilation.
WasmCompilationResult result = unit->ExecuteCompilation( WasmCompilationResult result =
&env.value(), wire_bytes, async_counters_.get(), &detected_features); unit->ExecuteCompilation(wasm_engine, &env.value(), wire_bytes,
async_counters_.get(), &detected_features);
results_to_publish.emplace_back(std::move(result)); results_to_publish.emplace_back(std::move(result));
// (synchronized): Publish the compilation result and get the next unit. // (synchronized): Publish the compilation result and get the next unit.
...@@ -978,8 +977,8 @@ class BackgroundCompileTask : public CancelableTask { ...@@ -978,8 +977,8 @@ class BackgroundCompileTask : public CancelableTask {
} }
private: private:
std::shared_ptr<BackgroundCompileToken> token_; const std::shared_ptr<BackgroundCompileToken> token_;
std::shared_ptr<Counters> async_counters_; const std::shared_ptr<Counters> async_counters_;
const int task_id_; const int task_id_;
}; };
...@@ -1488,8 +1487,8 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep { ...@@ -1488,8 +1487,8 @@ class AsyncCompileJob::PrepareAndStartCompile : public CompileStep {
// Add compilation units and kick off compilation. // Add compilation units and kick off compilation.
auto isolate = job->isolate(); auto isolate = job->isolate();
bool success = InitializeCompilationUnits( bool success =
isolate, job->native_module_.get(), isolate->wasm_engine()); InitializeCompilationUnits(isolate, job->native_module_.get());
if (!success) { if (!success) {
// TODO(frgossen): Add test coverage for this path. // TODO(frgossen): Add test coverage for this path.
DCHECK(job->native_module_->enabled_features().compilation_hints); DCHECK(job->native_module_->enabled_features().compilation_hints);
...@@ -1676,8 +1675,8 @@ bool AsyncStreamingProcessor::ProcessCodeSectionHeader( ...@@ -1676,8 +1675,8 @@ bool AsyncStreamingProcessor::ProcessCodeSectionHeader(
// Set outstanding_finishers_ to 2, because both the AsyncCompileJob and the // Set outstanding_finishers_ to 2, because both the AsyncCompileJob and the
// AsyncStreamingProcessor have to finish. // AsyncStreamingProcessor have to finish.
job_->outstanding_finishers_.store(2); job_->outstanding_finishers_.store(2);
compilation_unit_builder_.reset(new CompilationUnitBuilder( compilation_unit_builder_.reset(
job_->native_module_.get(), job_->isolate()->wasm_engine())); new CompilationUnitBuilder(job_->native_module_.get()));
return true; return true;
} }
......
...@@ -510,11 +510,11 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) { ...@@ -510,11 +510,11 @@ 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(), function_->func_index, WasmCompilationUnit unit(function_->func_index, builder_->execution_tier());
builder_->execution_tier());
WasmFeatures unused_detected_features; WasmFeatures unused_detected_features;
WasmCompilationResult result = unit.ExecuteCompilation( WasmCompilationResult result = unit.ExecuteCompilation(
&env, native_module->compilation_state()->GetWireBytesStorage(), isolate()->wasm_engine(), &env,
native_module->compilation_state()->GetWireBytesStorage(),
isolate()->counters(), &unused_detected_features); isolate()->counters(), &unused_detected_features);
WasmCode* code = native_module->AddCompiledCode(std::move(result)); WasmCode* code = native_module->AddCompiledCode(std::move(result));
DCHECK_NOT_NULL(code); DCHECK_NOT_NULL(code);
......
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