Commit 2f52803e authored by Z Nguyen-Huu's avatar Z Nguyen-Huu Committed by Commit Bot

[wasm] Tier up in parallel

Add tier up to existing recompilation logic.
This is a part of Tier up to Turbofan on Debugger.disable

Bug: v8:10290
Change-Id: I44731df520201ac254f2d1bfbfb5c49d8bb50117
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2080658
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66573}
parent 0ecbda14
...@@ -556,6 +556,7 @@ class CompilationStateImpl { ...@@ -556,6 +556,7 @@ class CompilationStateImpl {
std::vector<uint8_t> compilation_progress_; std::vector<uint8_t> compilation_progress_;
int outstanding_recompilation_functions_ = 0; int outstanding_recompilation_functions_ = 0;
ExecutionTier recompilation_tier_;
// End of fields protected by {callbacks_mutex_}. // End of fields protected by {callbacks_mutex_}.
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
...@@ -772,8 +773,9 @@ class CompilationUnitBuilder { ...@@ -772,8 +773,9 @@ class CompilationUnitBuilder {
tiering_units_.emplace_back(func_index, tiers.top_tier); tiering_units_.emplace_back(func_index, tiers.top_tier);
} }
void AddBaselineUnit(int func_index) { void AddRecompilationUnit(int func_index, ExecutionTier tier) {
baseline_units_.emplace_back(func_index, ExecutionTier::kLiftoff); // For recompilation, just treat all units like baseline units.
baseline_units_.emplace_back(func_index, tier);
} }
bool Commit() { bool Commit() {
...@@ -1192,7 +1194,7 @@ void InitializeCompilationUnits(Isolate* isolate, NativeModule* native_module) { ...@@ -1192,7 +1194,7 @@ void InitializeCompilationUnits(Isolate* isolate, NativeModule* native_module) {
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++) {
if (prefer_liftoff) { if (prefer_liftoff) {
builder.AddBaselineUnit(func_index); builder.AddRecompilationUnit(func_index, ExecutionTier::kLiftoff);
continue; continue;
} }
CompileStrategy strategy = GetCompileStrategy( CompileStrategy strategy = GetCompileStrategy(
...@@ -1418,7 +1420,7 @@ void RecompileNativeModule(Isolate* isolate, NativeModule* native_module, ...@@ -1418,7 +1420,7 @@ void RecompileNativeModule(Isolate* isolate, NativeModule* native_module,
// Install a callback to notify us once background recompilation finished. // Install a callback to notify us once background recompilation finished.
auto recompilation_finished_semaphore = std::make_shared<base::Semaphore>(0); auto recompilation_finished_semaphore = std::make_shared<base::Semaphore>(0);
auto* compilation_state = Impl(native_module->compilation_state()); auto* compilation_state = Impl(native_module->compilation_state());
DCHECK_EQ(tier, ExecutionTier::kLiftoff); DCHECK(tier == ExecutionTier::kTurbofan || tier == ExecutionTier::kLiftoff);
// The callback captures a shared ptr to the semaphore. // The callback captures a shared ptr to the semaphore.
// Initialize the compilation units and kick off background compile tasks. // Initialize the compilation units and kick off background compile tasks.
compilation_state->InitializeRecompilation( compilation_state->InitializeRecompilation(
...@@ -1434,7 +1436,8 @@ void RecompileNativeModule(Isolate* isolate, NativeModule* native_module, ...@@ -1434,7 +1436,8 @@ void RecompileNativeModule(Isolate* isolate, NativeModule* native_module,
if (!NeedsDeterministicCompile()) { if (!NeedsDeterministicCompile()) {
while (ExecuteCompilationUnits( while (ExecuteCompilationUnits(
compilation_state->background_compile_token(), isolate->counters(), compilation_state->background_compile_token(), isolate->counters(),
kMainThreadTaskId, kBaselineOnly)) { kMainThreadTaskId,
tier == ExecutionTier::kLiftoff ? kBaselineOnly : kBaselineOrTopTier)) {
// Continue executing compilation units. // Continue executing compilation units.
} }
} }
...@@ -2541,8 +2544,7 @@ void CompilationStateImpl::InitializeRecompilation( ...@@ -2541,8 +2544,7 @@ void CompilationStateImpl::InitializeRecompilation(
has_correct_tier ? tier : ExecutionTier::kNone); has_correct_tier ? tier : ExecutionTier::kNone);
if (!has_correct_tier) { if (!has_correct_tier) {
outstanding_recompilation_functions_++; outstanding_recompilation_functions_++;
// TODO(duongn): Fix this for tier up. builder.AddRecompilationUnit(function_index, tier);
builder.AddBaselineUnit(function_index);
} }
} }
} }
...@@ -2553,6 +2555,7 @@ void CompilationStateImpl::InitializeRecompilation( ...@@ -2553,6 +2555,7 @@ void CompilationStateImpl::InitializeRecompilation(
recompilation_finished_callback(CompilationEvent::kFinishedRecompilation); recompilation_finished_callback(CompilationEvent::kFinishedRecompilation);
} else { } else {
callbacks_.emplace_back(std::move(recompilation_finished_callback)); callbacks_.emplace_back(std::move(recompilation_finished_callback));
recompilation_tier_ = tier;
} }
} }
...@@ -2706,9 +2709,9 @@ void CompilationStateImpl::OnFinishedUnits( ...@@ -2706,9 +2709,9 @@ void CompilationStateImpl::OnFinishedUnits(
// TODO(duongn): extend this logic for tier up. // TODO(duongn): extend this logic for tier up.
ExecutionTier recompilation_tier = ExecutionTier recompilation_tier =
ReachedRecompilationTierField::decode(function_progress); ReachedRecompilationTierField::decode(function_progress);
if (results[i].requested_tier == ExecutionTier::kLiftoff && if (results[i].requested_tier == recompilation_tier_ &&
recompilation_tier == ExecutionTier::kNone) { recompilation_tier == ExecutionTier::kNone) {
DCHECK(code->tier() >= ExecutionTier::kLiftoff); DCHECK(code->tier() >= recompilation_tier_);
outstanding_recompilation_functions_--; outstanding_recompilation_functions_--;
// Update function's recompilation progress. // Update function's recompilation progress.
compilation_progress_[slot_index] = compilation_progress_[slot_index] =
......
...@@ -1834,6 +1834,9 @@ void NativeModule::TierDown(Isolate* isolate) { ...@@ -1834,6 +1834,9 @@ void NativeModule::TierDown(Isolate* isolate) {
} }
void NativeModule::TierUp(Isolate* isolate) { void NativeModule::TierUp(Isolate* isolate) {
// Do not tier up asm.js.
if (module()->origin != kWasmOrigin) return;
// Set the flag. // Set the flag.
{ {
base::MutexGuard lock(&allocation_mutex_); base::MutexGuard lock(&allocation_mutex_);
...@@ -1841,13 +1844,8 @@ void NativeModule::TierUp(Isolate* isolate) { ...@@ -1841,13 +1844,8 @@ void NativeModule::TierUp(Isolate* isolate) {
} }
// Tier up all functions. // Tier up all functions.
// TODO(duongn): parallelize this eventually. isolate->wasm_engine()->RecompileAllFunctions(isolate, this,
for (uint32_t index = module_->num_imported_functions; ExecutionTier::kTurbofan);
index < num_functions(); index++) {
isolate->wasm_engine()->CompileFunction(isolate, this, index,
ExecutionTier::kTurbofan);
DCHECK(!compilation_state()->failed());
}
} }
void NativeModule::FreeCode(Vector<WasmCode* const> codes) { void NativeModule::FreeCode(Vector<WasmCode* const> codes) {
......
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