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

[wasm-hints] Enable Wasm Compilation Hints

Wasm Compilation hints are now used when
{--experimental-wasm-compilation-hints} is set to create compilation
units as suggested. Hints regarding the compilation strategy, e.g. lazy
compilation, are ignored for now.

Bug: v8:9003

Change-Id: Id275537db375e425e872b0a05b587931c829c865
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1524202
Commit-Queue: Frederik Gossen <frgossen@google.com>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60352}
parent 73c62c84
......@@ -115,7 +115,7 @@ class BackgroundCompileScope {
// owning NativeModule, i.e. which functions are left to be compiled.
// It contains a task manager to allow parallel and asynchronous background
// compilation of functions.
// It's public interface {CompilationState} lives in compilation-environment.h.
// Its public interface {CompilationState} lives in compilation-environment.h.
class CompilationStateImpl {
public:
CompilationStateImpl(const std::shared_ptr<NativeModule>& native_module,
......@@ -349,6 +349,21 @@ void CompileLazy(Isolate* isolate, NativeModule* native_module,
namespace {
ExecutionTier apply_hint_to_execution_tier(WasmCompilationHintTier hint,
ExecutionTier default_tier) {
switch (hint) {
case WasmCompilationHintTier::kDefault:
return default_tier;
case WasmCompilationHintTier::kInterpreter:
return ExecutionTier::kInterpreter;
case WasmCompilationHintTier::kBaseline:
return ExecutionTier::kBaseline;
case WasmCompilationHintTier::kOptimized:
return ExecutionTier::kOptimized;
}
UNREACHABLE();
}
// The {CompilationUnitBuilder} builds compilation units and stores them in an
// internal buffer. The buffer is moved into the working queue of the
// {CompilationStateImpl} when {Commit} is called.
......@@ -363,15 +378,45 @@ class CompilationUnitBuilder {
void AddUnit(uint32_t func_index) {
switch (compilation_state()->compile_mode()) {
case CompileMode::kTiering:
tiering_units_.emplace_back(
CreateUnit(func_index, ExecutionTier::kOptimized));
baseline_units_.emplace_back(
CreateUnit(func_index, ExecutionTier::kBaseline));
return;
case CompileMode::kRegular:
baseline_units_.emplace_back(CreateUnit(func_index, default_tier_));
return;
case CompileMode::kTiering:
// Default tiering behaviour.
ExecutionTier first_tier = ExecutionTier::kBaseline;
ExecutionTier second_tier = ExecutionTier::kOptimized;
// Check if compilation hints override default tiering behaviour.
if (native_module_->enabled_features().compilation_hints) {
// Find compilation hint.
CHECK_LE(native_module_->num_imported_functions(), func_index);
uint32_t hint_index =
func_index - native_module_->num_imported_functions();
const std::vector<WasmCompilationHint>& compilation_hints =
native_module_->module()->compilation_hints;
if (hint_index < compilation_hints.size()) {
WasmCompilationHint hint = compilation_hints[hint_index];
// Apply compilation hint.
first_tier =
apply_hint_to_execution_tier(hint.first_tier, first_tier);
second_tier =
apply_hint_to_execution_tier(hint.second_tier, second_tier);
}
}
// Create compilation units and suppress duplicate compilation.
baseline_units_.emplace_back(
CreateUnit(func_index, std::move(first_tier)));
static_assert(ExecutionTier::kInterpreter < ExecutionTier::kBaseline &&
ExecutionTier::kBaseline < ExecutionTier::kOptimized,
"Assume an order on execution tiers");
if (first_tier < second_tier) {
tiering_units_.emplace_back(
CreateUnit(func_index, std::move(second_tier)));
}
return;
}
UNREACHABLE();
}
......@@ -1516,21 +1561,26 @@ void CompilationStateImpl::AddCompilationUnits(
{
base::MutexGuard guard(&mutex_);
if (compile_mode_ == CompileMode::kTiering) {
DCHECK_EQ(baseline_units.size(), tiering_units.size());
DCHECK_EQ(tiering_units.back()->tier(), ExecutionTier::kOptimized);
tiering_compilation_units_.insert(
tiering_compilation_units_.end(),
std::make_move_iterator(tiering_units.begin()),
std::make_move_iterator(tiering_units.end()));
} else {
DCHECK(tiering_compilation_units_.empty());
}
DCHECK_LE(tiering_units.size(), baseline_units.size());
DCHECK_IMPLIES(compile_mode_ == CompileMode::kTiering &&
!native_module_->enabled_features().compilation_hints,
tiering_units.size() == baseline_units.size());
DCHECK_IMPLIES(compile_mode_ == CompileMode::kTiering &&
!native_module_->enabled_features().compilation_hints,
tiering_units.back()->tier() == ExecutionTier::kOptimized);
DCHECK_IMPLIES(compile_mode_ == CompileMode::kRegular,
tiering_compilation_units_.empty());
baseline_compilation_units_.insert(
baseline_compilation_units_.end(),
std::make_move_iterator(baseline_units.begin()),
std::make_move_iterator(baseline_units.end()));
if (!tiering_units.empty()) {
tiering_compilation_units_.insert(
tiering_compilation_units_.end(),
std::make_move_iterator(tiering_units.begin()),
std::make_move_iterator(tiering_units.end()));
}
}
RestartBackgroundTasks();
......
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