Commit d650d368 authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

Reland "Reland "[wasm] Refactor compilation tier computations""

This is a reland of commit b3a27f22.
Conditions needed to be switched to still ensure eager compilation
of tiered-down modules (otherwise an existing test would fail).
I opened https://crbug.com/v8/13224 to switch to lazy compilation
for tier-down.

Original change's description:
> Reland "[wasm] Refactor compilation tier computations"
>
> This is a reland of commit e50472d6.
> In {ApplyCompilationHintToInitialProgress} we would reset the baseline
> tier to {kNone} if the compilation strategy is {kDefault}, which is
> wrong. We would not generate code but also not install the lazy stub,
> so whenever we start executing the code before top-tier is ready we
> would crash.
>
> Original change's description:
> > [wasm] Refactor compilation tier computations
> >
> > The way we initialized the "compilation progress" was pretty convoluted,
> > with multiple levels of functions being called for initializing every
> > single slot.
> >
> > This CL refactors this to compute one default value for the whole
> > module, and only modifies those slots that need special handling (e.g.
> > because of compilation hints, or lazy/eager compilation after
> > deserialization).
> >
> > We also rename "liftoff_functions" to "eager_functions" in the
> > deserialization path; the idea is that those functions should get
> > eagerly compiled because we expect them to be needed during execution.
> > Usually they would be Liftoff-compiled, but it's more consistent to use
> > the existing logic to choose the baseline tier. In the default
> > configuration, this will still use Liftoff, but if Liftoff is disabled
> > we will use TurboFan instead.
> >
> > R=jkummerow@chromium.org, ahaas@chromium.org
> >
> > Bug: v8:12425
> > Change-Id: Ie58840b19efd0b1e98f1b02d5f1d4369410ed8e1
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3829606
> > Commit-Queue: Clemens Backes <clemensb@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> > Cr-Commit-Position: refs/heads/main@{#82521}
>
> Bug: v8:12425
> Change-Id: Ie41e63148bf6bd0e38fc07a3a514f1094d9d26cf
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3838409
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Commit-Queue: Clemens Backes <clemensb@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#82585}

Bug: v8:12425, v8:13224
Change-Id: I7da418a393cd470cfbe368f12b30a045b1bf9dcd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3850841Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82688}
parent 2b477ebd
...@@ -167,9 +167,8 @@ class V8_EXPORT_PRIVATE CompilationState { ...@@ -167,9 +167,8 @@ class V8_EXPORT_PRIVATE CompilationState {
void AddCallback(std::unique_ptr<CompilationEventCallback> callback); void AddCallback(std::unique_ptr<CompilationEventCallback> callback);
void InitializeAfterDeserialization( void InitializeAfterDeserialization(base::Vector<const int> lazy_functions,
base::Vector<const int> lazy_functions, base::Vector<const int> eager_functions);
base::Vector<const int> liftoff_functions);
// Set a higher priority for the compilation job. // Set a higher priority for the compilation job.
void SetHighPriority(); void SetHighPriority();
......
...@@ -16,18 +16,7 @@ ...@@ -16,18 +16,7 @@
#include "src/wasm/wasm-debug.h" #include "src/wasm/wasm-debug.h"
#include "src/wasm/wasm-engine.h" #include "src/wasm/wasm-engine.h"
namespace v8 { namespace v8::internal::wasm {
namespace internal {
namespace wasm {
// static
ExecutionTier WasmCompilationUnit::GetBaselineExecutionTier(
const WasmModule* module) {
// Liftoff does not support the special asm.js opcodes, thus always compile
// asm.js modules with TurboFan.
if (is_asmjs_module(module)) return ExecutionTier::kTurbofan;
return FLAG_liftoff ? ExecutionTier::kLiftoff : ExecutionTier::kTurbofan;
}
WasmCompilationResult WasmCompilationUnit::ExecuteCompilation( WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
CompilationEnv* env, const WireBytesStorage* wire_bytes_storage, CompilationEnv* env, const WireBytesStorage* wire_bytes_storage,
...@@ -275,6 +264,4 @@ Handle<CodeT> JSToWasmWrapperCompilationUnit::CompileSpecificJSToWasmWrapper( ...@@ -275,6 +264,4 @@ Handle<CodeT> JSToWasmWrapperCompilationUnit::CompileSpecificJSToWasmWrapper(
return unit.Finalize(); return unit.Finalize();
} }
} // namespace wasm } // namespace v8::internal::wasm
} // namespace internal
} // namespace v8
...@@ -62,8 +62,6 @@ struct WasmCompilationResult { ...@@ -62,8 +62,6 @@ struct WasmCompilationResult {
class V8_EXPORT_PRIVATE WasmCompilationUnit final { class V8_EXPORT_PRIVATE WasmCompilationUnit final {
public: public:
static ExecutionTier GetBaselineExecutionTier(const WasmModule*);
WasmCompilationUnit(int index, ExecutionTier tier, ForDebugging for_debugging) WasmCompilationUnit(int index, ExecutionTier tier, ForDebugging for_debugging)
: func_index_(index), tier_(tier), for_debugging_(for_debugging) {} : func_index_(index), tier_(tier), for_debugging_(for_debugging) {}
......
This diff is collapsed.
...@@ -28,7 +28,7 @@ namespace wasm { ...@@ -28,7 +28,7 @@ namespace wasm {
namespace { namespace {
constexpr uint8_t kLazyFunction = 2; constexpr uint8_t kLazyFunction = 2;
constexpr uint8_t kLiftoffFunction = 3; constexpr uint8_t kEagerFunction = 3;
constexpr uint8_t kTurboFanFunction = 4; constexpr uint8_t kTurboFanFunction = 4;
// TODO(bbudge) Try to unify the various implementations of readers and writers // TODO(bbudge) Try to unify the various implementations of readers and writers
...@@ -340,17 +340,17 @@ void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) { ...@@ -340,17 +340,17 @@ void NativeModuleSerializer::WriteCode(const WasmCode* code, Writer* writer) {
// non-relocatable constants. // non-relocatable constants.
if (code->tier() != ExecutionTier::kTurbofan) { if (code->tier() != ExecutionTier::kTurbofan) {
// We check if the function has been executed already. If so, we serialize // We check if the function has been executed already. If so, we serialize
// it as {kLiftoffFunction} so that upon deserialization the function will // it as {kEagerFunction} so that upon deserialization the function will
// get compiled with Liftoff eagerly. If the function has not been executed // get eagerly compiled with Liftoff (if enabled). If the function has not
// yet, we serialize it as {kLazyFunction}, and the function will not get // been executed yet, we serialize it as {kLazyFunction}, and the function
// compiled upon deserialization. // will not get compiled upon deserialization.
NativeModule* native_module = code->native_module(); NativeModule* native_module = code->native_module();
uint32_t budget = uint32_t budget =
native_module->tiering_budget_array()[declared_function_index( native_module->tiering_budget_array()[declared_function_index(
native_module->module(), code->index())]; native_module->module(), code->index())];
writer->Write(budget == static_cast<uint32_t>(FLAG_wasm_tiering_budget) writer->Write(budget == static_cast<uint32_t>(FLAG_wasm_tiering_budget)
? kLazyFunction ? kLazyFunction
: kLiftoffFunction); : kEagerFunction);
return; return;
} }
...@@ -552,8 +552,8 @@ class V8_EXPORT_PRIVATE NativeModuleDeserializer { ...@@ -552,8 +552,8 @@ class V8_EXPORT_PRIVATE NativeModuleDeserializer {
return base::VectorOf(lazy_functions_); return base::VectorOf(lazy_functions_);
} }
base::Vector<const int> liftoff_functions() { base::Vector<const int> eager_functions() {
return base::VectorOf(liftoff_functions_); return base::VectorOf(eager_functions_);
} }
private: private:
...@@ -574,7 +574,7 @@ class V8_EXPORT_PRIVATE NativeModuleDeserializer { ...@@ -574,7 +574,7 @@ class V8_EXPORT_PRIVATE NativeModuleDeserializer {
base::Vector<byte> current_code_space_; base::Vector<byte> current_code_space_;
NativeModule::JumpTablesRef current_jump_tables_; NativeModule::JumpTablesRef current_jump_tables_;
std::vector<int> lazy_functions_; std::vector<int> lazy_functions_;
std::vector<int> liftoff_functions_; std::vector<int> eager_functions_;
}; };
class DeserializeCodeTask : public JobTask { class DeserializeCodeTask : public JobTask {
...@@ -714,8 +714,8 @@ DeserializationUnit NativeModuleDeserializer::ReadCode(int fn_index, ...@@ -714,8 +714,8 @@ DeserializationUnit NativeModuleDeserializer::ReadCode(int fn_index,
lazy_functions_.push_back(fn_index); lazy_functions_.push_back(fn_index);
return {}; return {};
} }
if (code_kind == kLiftoffFunction) { if (code_kind == kEagerFunction) {
liftoff_functions_.push_back(fn_index); eager_functions_.push_back(fn_index);
return {}; return {};
} }
...@@ -896,7 +896,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule( ...@@ -896,7 +896,7 @@ MaybeHandle<WasmModuleObject> DeserializeNativeModule(
return {}; return {};
} }
shared_native_module->compilation_state()->InitializeAfterDeserialization( shared_native_module->compilation_state()->InitializeAfterDeserialization(
deserializer.lazy_functions(), deserializer.liftoff_functions()); deserializer.lazy_functions(), deserializer.eager_functions());
wasm_engine->UpdateNativeModuleCache(error, &shared_native_module, isolate); wasm_engine->UpdateNativeModuleCache(error, &shared_native_module, isolate);
} }
......
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