Commit 3e1b3502 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Remove {LiftoffCompilationUnit}

{LiftoffCompilationUnit} does not store any data, and has a single
method only. Thus remove it, and replace it by a static function.
This saves one field per compilation unit. We can probably also remove
{TurbofanWasmCompilationUnit} and {InterpreterCompilationUnit} in a
similar way, which I will do in follow-up CLs.

R=mstarzinger@chromium.org

Change-Id: I5e1a7d4245fd8bce4862cc83c96f9dac8e0c635e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1587386Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61080}
parent 3a2424d0
......@@ -2032,9 +2032,11 @@ class LiftoffCompiler {
} // namespace
WasmCompilationResult LiftoffCompilationUnit::ExecuteCompilation(
AccountingAllocator* allocator, CompilationEnv* env,
const FunctionBody& func_body, Counters* counters, WasmFeatures* detected) {
WasmCompilationResult ExecuteLiftoffCompilation(AccountingAllocator* allocator,
CompilationEnv* env,
const FunctionBody& func_body,
Counters* counters,
WasmFeatures* detected) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"),
"ExecuteLiftoffCompilation");
base::ElapsedTimer compile_timer;
......
......@@ -5,7 +5,6 @@
#ifndef V8_WASM_BASELINE_LIFTOFF_COMPILER_H_
#define V8_WASM_BASELINE_LIFTOFF_COMPILER_H_
#include "src/base/macros.h"
#include "src/wasm/function-compiler.h"
namespace v8 {
......@@ -18,21 +17,11 @@ namespace wasm {
struct CompilationEnv;
struct FunctionBody;
class NativeModule;
struct WasmFeatures;
class LiftoffCompilationUnit final {
public:
LiftoffCompilationUnit() = default;
WasmCompilationResult ExecuteCompilation(AccountingAllocator*,
CompilationEnv*, const FunctionBody&,
Counters*,
WasmFeatures* detected_features);
private:
DISALLOW_COPY_AND_ASSIGN(LiftoffCompilationUnit);
};
WasmCompilationResult ExecuteLiftoffCompilation(
AccountingAllocator*, CompilationEnv*, const FunctionBody&, Counters*,
WasmFeatures* detected_features);
} // namespace wasm
} // namespace internal
......
......@@ -114,15 +114,11 @@ ExecutionTier WasmCompilationUnit::GetDefaultExecutionTier(
WasmCompilationUnit::WasmCompilationUnit(int index, ExecutionTier tier)
: func_index_(index), tier_(tier) {
if (V8_UNLIKELY(FLAG_wasm_tier_mask_for_testing) && index < 32 &&
(FLAG_wasm_tier_mask_for_testing & (1 << index))) {
tier = ExecutionTier::kTurbofan;
}
SwitchTier(tier);
}
// Declared here such that {LiftoffCompilationUnit} and
// {TurbofanWasmCompilationUnit} can be opaque in the header file.
// Declared here such that {TurbofanWasmCompilationUnit} can be opaque in the
// header file.
WasmCompilationUnit::~WasmCompilationUnit() = default;
WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
......@@ -141,35 +137,46 @@ WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
wasm_compile, function_time);
TimedHistogramScope wasm_compile_function_time_scope(timed_histogram);
// Exactly one compiler-specific unit must be set.
DCHECK_EQ(1, !!liftoff_unit_ + !!turbofan_unit_ + !!interpreter_unit_);
if (FLAG_trace_wasm_compiler) {
const char* tier =
liftoff_unit_ ? "liftoff" : turbofan_unit_ ? "turbofan" : "interpreter";
PrintF("Compiling wasm function %d with %s\n\n", func_index_, tier);
PrintF("Compiling wasm function %d with %s\n\n", func_index_,
ExecutionTierToString(tier_));
}
WasmCompilationResult result;
if (liftoff_unit_) {
result = liftoff_unit_->ExecuteCompilation(wasm_engine->allocator(), env,
func_body, counters, detected);
if (!result.succeeded()) {
switch (tier_) {
case ExecutionTier::kNone:
UNREACHABLE();
case ExecutionTier::kLiftoff:
// The --wasm-tier-mask-for-testing flag can force functions to be
// compiled with TurboFan, see documentation.
if (V8_LIKELY(FLAG_wasm_tier_mask_for_testing == 0) ||
func_index_ >= 32 ||
((FLAG_wasm_tier_mask_for_testing & (1 << func_index_)) == 0)) {
result = ExecuteLiftoffCompilation(wasm_engine->allocator(), env,
func_body, counters, detected);
if (result.succeeded()) break;
}
// If Liftoff failed, fall back to turbofan.
// TODO(wasm): We could actually stop or remove the tiering unit for this
// function to avoid compiling it twice with TurboFan.
SwitchTier(ExecutionTier::kTurbofan);
DCHECK_NOT_NULL(turbofan_unit_);
}
}
if (turbofan_unit_) {
result = turbofan_unit_->ExecuteCompilation(wasm_engine, env, func_body,
counters, detected);
}
if (interpreter_unit_) {
result = interpreter_unit_->ExecuteCompilation(wasm_engine, env, func_body,
counters, detected);
V8_FALLTHROUGH;
case ExecutionTier::kTurbofan:
result = turbofan_unit_->ExecuteCompilation(wasm_engine, env, func_body,
counters, detected);
break;
case ExecutionTier::kInterpreter:
result = interpreter_unit_->ExecuteCompilation(
wasm_engine, env, func_body, counters, detected);
break;
}
result.func_index = func_index_;
result.requested_tier = tier_;
......@@ -184,25 +191,20 @@ WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
void WasmCompilationUnit::SwitchTier(ExecutionTier new_tier) {
// This method is being called in the constructor, where neither
// {liftoff_unit_} nor {turbofan_unit_} nor {interpreter_unit_} are set, or to
// switch tier from kLiftoff to kTurbofan, in which case {liftoff_unit_} is
// already set.
// {turbofan_unit_} nor {interpreter_unit_} are set, or to switch tier from
// kLiftoff to kTurbofan.
switch (new_tier) {
case ExecutionTier::kLiftoff:
DCHECK(!turbofan_unit_);
DCHECK(!liftoff_unit_);
DCHECK(!interpreter_unit_);
liftoff_unit_.reset(new LiftoffCompilationUnit());
return;
case ExecutionTier::kTurbofan:
DCHECK(!turbofan_unit_);
DCHECK(!interpreter_unit_);
liftoff_unit_.reset();
turbofan_unit_.reset(new compiler::TurbofanWasmCompilationUnit(this));
return;
case ExecutionTier::kInterpreter:
DCHECK(!turbofan_unit_);
DCHECK(!liftoff_unit_);
DCHECK(!interpreter_unit_);
interpreter_unit_.reset(new compiler::InterpreterCompilationUnit(this));
return;
......
......@@ -27,7 +27,6 @@ class TurbofanWasmCompilationUnit;
namespace wasm {
class LiftoffCompilationUnit;
class NativeModule;
class WasmCode;
class WasmCompilationUnit;
......@@ -85,15 +84,12 @@ class V8_EXPORT_PRIVATE WasmCompilationUnit final {
ExecutionTier);
private:
friend class LiftoffCompilationUnit;
friend class compiler::TurbofanWasmCompilationUnit;
friend class compiler::InterpreterCompilationUnit;
const int func_index_;
ExecutionTier tier_;
// LiftoffCompilationUnit, set if {tier_ == kLiftoff}.
std::unique_ptr<LiftoffCompilationUnit> liftoff_unit_;
// TurbofanWasmCompilationUnit, set if {tier_ == kTurbofan}.
std::unique_ptr<compiler::TurbofanWasmCompilationUnit> turbofan_unit_;
// InterpreterCompilationUnit, set if {tier_ == kInterpreter}.
......
......@@ -35,20 +35,7 @@ void TraceMemoryOperation(ExecutionTier tier, const MemoryTracingInfo* info,
default:
SNPrintF(value, "???");
}
const char* eng = "?";
switch (tier) {
case ExecutionTier::kTurbofan:
eng = "turbofan";
break;
case ExecutionTier::kLiftoff:
eng = "liftoff";
break;
case ExecutionTier::kInterpreter:
eng = "interpreter";
break;
case ExecutionTier::kNone:
UNREACHABLE();
}
const char* eng = ExecutionTierToString(tier);
printf("%-11s func:%6d+0x%-6x%s %08x val: %s\n", eng, func_index, position,
info->is_store ? " store to" : "load from", info->address,
value.start());
......
......@@ -19,6 +19,19 @@ enum class ExecutionTier : int8_t {
kTurbofan,
};
inline const char* ExecutionTierToString(ExecutionTier tier) {
switch (tier) {
case ExecutionTier::kTurbofan:
return "turbofan";
case ExecutionTier::kLiftoff:
return "liftoff";
case ExecutionTier::kInterpreter:
return "interpreter";
case ExecutionTier::kNone:
return "none";
}
}
} // namespace wasm
} // namespace internal
} // namespace v8
......
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