Commit 185922de authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Distinguish requested tier and executed tier

During execution, the tier can be switch from Liftoff to TurboFan. We
already handle this in some locations by getting the tier before
execution, so that we later know which was the requested tier for that
unit.
In the case of the --wasm-tier-mask-for-testing flag, this accounting
was not right because the tier was already switched in the constructor.
This CL changes the compilation units to store both the requested and
the executed tier explicitly, so we know which counter to decrement
when the unit finishes.

R=ahaas@chromium.org

Bug: chromium:925671
Change-Id: I673463135e9b3ab17e40cfdfd5d3a526ad5a9b79
Reviewed-on: https://chromium-review.googlesource.com/c/1442639Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59168}
parent a7f59888
......@@ -124,7 +124,7 @@ ExecutionTier WasmCompilationUnit::GetDefaultExecutionTier(
WasmCompilationUnit::WasmCompilationUnit(WasmEngine* wasm_engine, int index,
ExecutionTier tier)
: wasm_engine_(wasm_engine), func_index_(index), tier_(tier) {
: wasm_engine_(wasm_engine), func_index_(index), requested_tier_(tier) {
if (V8_UNLIKELY(FLAG_wasm_tier_mask_for_testing) && index < 32 &&
(FLAG_wasm_tier_mask_for_testing & (1 << index))) {
tier = ExecutionTier::kOptimized;
......@@ -154,11 +154,11 @@ WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
if (FLAG_trace_wasm_compiler) {
PrintF("Compiling wasm function %d with %s\n\n", func_index_,
GetExecutionTierAsString(tier_));
GetExecutionTierAsString(executed_tier_));
}
WasmCompilationResult result;
switch (tier_) {
switch (executed_tier_) {
case ExecutionTier::kBaseline:
result =
liftoff_unit_->ExecuteCompilation(env, func_body, counters, detected);
......@@ -193,10 +193,8 @@ WasmCode* WasmCompilationUnit::Publish(WasmCompilationResult result,
return nullptr;
}
// The {tier} argument specifies the requested tier, which can differ from the
// actually executed tier stored in {unit->tier()}.
DCHECK(result.succeeded());
WasmCode::Tier code_tier = tier_ == ExecutionTier::kBaseline
WasmCode::Tier code_tier = executed_tier_ == ExecutionTier::kBaseline
? WasmCode::kLiftoff
: WasmCode::kTurbofan;
DCHECK_EQ(result.code_desc.buffer, result.instr_buffer.get());
......@@ -214,7 +212,7 @@ void WasmCompilationUnit::SwitchTier(ExecutionTier new_tier) {
// This method is being called in the constructor, where neither
// {liftoff_unit_} nor {turbofan_unit_} are set, or to switch tier from
// kLiftoff to kTurbofan, in which case {liftoff_unit_} is already set.
tier_ = new_tier;
executed_tier_ = new_tier;
switch (new_tier) {
case ExecutionTier::kBaseline:
DCHECK(!turbofan_unit_);
......
......@@ -88,7 +88,8 @@ class WasmCompilationUnit final {
WasmCode* Publish(WasmCompilationResult, NativeModule*);
ExecutionTier tier() const { return tier_; }
ExecutionTier requested_tier() const { return requested_tier_; }
ExecutionTier executed_tier() const { return executed_tier_; }
static void CompileWasmFunction(Isolate*, NativeModule*,
WasmFeatures* detected, const WasmFunction*,
......@@ -100,7 +101,8 @@ class WasmCompilationUnit final {
WasmEngine* const wasm_engine_;
const int func_index_;
ExecutionTier tier_;
ExecutionTier requested_tier_;
ExecutionTier executed_tier_;
// LiftoffCompilationUnit, set if {tier_ == kLiftoff}.
std::unique_ptr<LiftoffCompilationUnit> liftoff_unit_;
......
......@@ -496,14 +496,11 @@ bool FetchAndExecuteCompilationUnit(CompilationEnv* env,
compilation_state->GetNextCompilationUnit();
if (unit == nullptr) return false;
// Get the tier before starting compilation, as compilation can switch tiers
// if baseline bails out.
ExecutionTier tier = unit->tier();
WasmCompilationResult result = unit->ExecuteCompilation(
env, compilation_state->GetWireBytesStorage(), counters, detected);
WasmCode* code = unit->Publish(std::move(result), native_module);
compilation_state->OnFinishedUnit(tier, code);
compilation_state->OnFinishedUnit(unit->requested_tier(), code);
return true;
}
......@@ -806,9 +803,6 @@ class BackgroundCompileTask : public CancelableTask {
// Step 2: Execute the compilation.
// Get the tier before starting compilation, as compilation can switch
// tiers if baseline bails out.
ExecutionTier tier = unit->tier();
WasmCompilationResult result = unit->ExecuteCompilation(
&env.value(), wire_bytes, async_counters_.get(), &detected_features);
......@@ -825,7 +819,8 @@ class BackgroundCompileTask : public CancelableTask {
token_->CancelLocked();
return;
}
compile_scope.compilation_state()->OnFinishedUnit(tier, code);
compile_scope.compilation_state()->OnFinishedUnit(
unit->requested_tier(), code);
if (deadline < MonotonicallyIncreasingTimeInMs()) {
compile_scope.compilation_state()->ReportDetectedFeatures(
detected_features);
......@@ -1644,7 +1639,8 @@ void CompilationStateImpl::AddCompilationUnits(
if (compile_mode_ == CompileMode::kTiering) {
DCHECK_EQ(baseline_units.size(), tiering_units.size());
DCHECK_EQ(tiering_units.back()->tier(), ExecutionTier::kOptimized);
DCHECK_EQ(tiering_units.back()->requested_tier(),
ExecutionTier::kOptimized);
tiering_compilation_units_.insert(
tiering_compilation_units_.end(),
std::make_move_iterator(tiering_units.begin()),
......
......@@ -5,12 +5,14 @@
#ifndef V8_WASM_WASM_TIER_H_
#define V8_WASM_WASM_TIER_H_
#include <cstdint>
namespace v8 {
namespace internal {
namespace wasm {
// All the tiers of WASM execution.
enum class ExecutionTier {
enum class ExecutionTier : int8_t {
kInterpreter, // interpreter (used to provide debugging services).
kBaseline, // Liftoff.
kOptimized // TurboFan.
......
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --wasm-tier-mask-for-testing=1
load('test/mjsunit/wasm/wasm-constants.js');
load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
builder.addFunction('f0', kSig_v_v).addBody([]);
builder.addFunction('f1', kSig_v_v).addBody([]);
builder.instantiate();
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