[wasm] Remove {TurbofanWasmCompilationUnit}

{TurbofanWasmCompilationUnit} does not store any data except for a
pointer back to the {WasmCompilationUnit}, and has a single method only.
Thus remove it, and replace it by a static function.
This saves one field per compilation unit.

R=mstarzinger@chromium.org

Change-Id: I2bcb9246c65e6971aa747488ea631886ca3bc037
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1587388
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61084}
This commit is contained in:
Clemens Hammacher 2019-04-29 13:38:21 +02:00 committed by Commit Bot
parent ea2de39ff1
commit 884a45a72d
4 changed files with 31 additions and 83 deletions

View File

@ -6121,18 +6121,13 @@ MaybeHandle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) {
return code;
}
TurbofanWasmCompilationUnit::TurbofanWasmCompilationUnit(
wasm::WasmCompilationUnit* wasm_unit)
: wasm_unit_(wasm_unit) {}
// Clears unique_ptrs, but (part of) the type is forward declared in the header.
TurbofanWasmCompilationUnit::~TurbofanWasmCompilationUnit() = default;
bool TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
AccountingAllocator* allocator, wasm::CompilationEnv* env,
const wasm::FunctionBody& func_body, wasm::WasmFeatures* detected,
double* decode_ms, MachineGraph* mcgraph, NodeOriginTable* node_origins,
SourcePositionTable* source_positions) {
bool BuildGraphForWasmFunction(AccountingAllocator* allocator,
wasm::CompilationEnv* env,
const wasm::FunctionBody& func_body,
int func_index, wasm::WasmFeatures* detected,
double* decode_ms, MachineGraph* mcgraph,
NodeOriginTable* node_origins,
SourcePositionTable* source_positions) {
base::ElapsedTimer decode_timer;
if (FLAG_trace_wasm_decode_time) {
decode_timer.Start();
@ -6162,8 +6157,8 @@ bool TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
.LowerGraph();
}
if (wasm_unit_->func_index_ >= FLAG_trace_wasm_ast_start &&
wasm_unit_->func_index_ < FLAG_trace_wasm_ast_end) {
if (func_index >= FLAG_trace_wasm_ast_start &&
func_index < FLAG_trace_wasm_ast_end) {
PrintRawWasmCode(allocator, func_body, env->module, wasm::kPrintLocals);
}
if (FLAG_trace_wasm_decode_time) {
@ -6187,9 +6182,9 @@ Vector<const char> GetDebugName(Zone* zone, int index) {
}
} // namespace
wasm::WasmCompilationResult TurbofanWasmCompilationUnit::ExecuteCompilation(
wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation(
wasm::WasmEngine* wasm_engine, wasm::CompilationEnv* env,
const wasm::FunctionBody& func_body, Counters* counters,
const wasm::FunctionBody& func_body, int func_index, Counters* counters,
wasm::WasmFeatures* detected) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"),
"ExecuteTurbofanCompilation");
@ -6204,8 +6199,8 @@ wasm::WasmCompilationResult TurbofanWasmCompilationUnit::ExecuteCompilation(
InstructionSelector::SupportedMachineOperatorFlags(),
InstructionSelector::AlignmentRequirements()));
OptimizedCompilationInfo info(GetDebugName(&zone, wasm_unit_->func_index_),
&zone, Code::WASM_FUNCTION);
OptimizedCompilationInfo info(GetDebugName(&zone, func_index), &zone,
Code::WASM_FUNCTION);
if (env->runtime_exception_support) {
info.SetWasmRuntimeExceptionSupport();
}
@ -6222,8 +6217,8 @@ wasm::WasmCompilationResult TurbofanWasmCompilationUnit::ExecuteCompilation(
SourcePositionTable* source_positions =
new (mcgraph->zone()) SourcePositionTable(mcgraph->graph());
if (!BuildGraphForWasmFunction(wasm_engine->allocator(), env, func_body,
detected, &decode_ms, mcgraph, node_origins,
source_positions)) {
func_index, detected, &decode_ms, mcgraph,
node_origins, source_positions)) {
return wasm::WasmCompilationResult{};
}
@ -6245,7 +6240,7 @@ wasm::WasmCompilationResult TurbofanWasmCompilationUnit::ExecuteCompilation(
Pipeline::GenerateCodeForWasmFunction(
&info, wasm_engine, mcgraph, call_descriptor, source_positions,
node_origins, func_body, env->module, wasm_unit_->func_index_);
node_origins, func_body, env->module, func_index);
if (FLAG_trace_wasm_decode_time) {
double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF();

View File

@ -45,30 +45,17 @@ struct WasmFeatures;
namespace compiler {
class TurbofanWasmCompilationUnit {
public:
explicit TurbofanWasmCompilationUnit(wasm::WasmCompilationUnit* wasm_unit);
~TurbofanWasmCompilationUnit();
bool BuildGraphForWasmFunction(AccountingAllocator* allocator,
wasm::CompilationEnv* env,
const wasm::FunctionBody& func_body,
int func_index, wasm::WasmFeatures* detected,
double* decode_ms, MachineGraph* mcgraph,
NodeOriginTable* node_origins,
SourcePositionTable* source_positions);
bool BuildGraphForWasmFunction(AccountingAllocator* allocator,
wasm::CompilationEnv* env,
const wasm::FunctionBody& func_body,
wasm::WasmFeatures* detected,
double* decode_ms, MachineGraph* mcgraph,
NodeOriginTable* node_origins,
SourcePositionTable* source_positions);
wasm::WasmCompilationResult ExecuteCompilation(wasm::WasmEngine*,
wasm::CompilationEnv*,
const wasm::FunctionBody&,
Counters*,
wasm::WasmFeatures* detected);
private:
wasm::WasmCompilationUnit* const wasm_unit_;
DISALLOW_COPY_AND_ASSIGN(TurbofanWasmCompilationUnit);
};
wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation(
wasm::WasmEngine*, wasm::CompilationEnv*, const wasm::FunctionBody&,
int func_index, Counters*, wasm::WasmFeatures* detected);
wasm::WasmCompilationResult ExecuteInterpreterEntryCompilation(
wasm::WasmEngine*, wasm::CompilationEnv*, const wasm::FunctionBody&,

View File

@ -112,15 +112,6 @@ ExecutionTier WasmCompilationUnit::GetDefaultExecutionTier(
return FLAG_liftoff ? ExecutionTier::kLiftoff : ExecutionTier::kTurbofan;
}
WasmCompilationUnit::WasmCompilationUnit(int index, ExecutionTier tier)
: func_index_(index), tier_(tier) {
SwitchTier(tier);
}
// Declared here such that {TurbofanWasmCompilationUnit} can be opaque in the
// header file.
WasmCompilationUnit::~WasmCompilationUnit() = default;
WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
WasmEngine* wasm_engine, CompilationEnv* env,
const std::shared_ptr<WireBytesStorage>& wire_bytes_storage,
@ -162,13 +153,11 @@ WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
// 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_);
V8_FALLTHROUGH;
case ExecutionTier::kTurbofan:
result = turbofan_unit_->ExecuteCompilation(wasm_engine, env, func_body,
counters, detected);
result = compiler::ExecuteTurbofanWasmCompilation(
wasm_engine, env, func_body, func_index_, counters, detected);
break;
case ExecutionTier::kInterpreter:
@ -189,15 +178,6 @@ WasmCompilationResult WasmCompilationUnit::ExecuteCompilation(
return result;
}
void WasmCompilationUnit::SwitchTier(ExecutionTier new_tier) {
// This method is being called in the constructor, where {turbofan_unit_} is
// not set, or to switch tier from kLiftoff to kTurbofan.
DCHECK(!turbofan_unit_);
if (new_tier == ExecutionTier::kTurbofan) {
turbofan_unit_.reset(new compiler::TurbofanWasmCompilationUnit(this));
}
}
// static
void WasmCompilationUnit::CompileWasmFunction(Isolate* isolate,
NativeModule* native_module,

View File

@ -19,16 +19,10 @@ namespace internal {
class AssemblerBuffer;
class Counters;
namespace compiler {
class Pipeline;
class TurbofanWasmCompilationUnit;
} // namespace compiler
namespace wasm {
class NativeModule;
class WasmCode;
class WasmCompilationUnit;
class WasmEngine;
struct WasmFunction;
@ -68,9 +62,8 @@ class V8_EXPORT_PRIVATE WasmCompilationUnit final {
public:
static ExecutionTier GetDefaultExecutionTier(const WasmModule*);
WasmCompilationUnit(int index, ExecutionTier);
~WasmCompilationUnit();
WasmCompilationUnit(int index, ExecutionTier tier)
: func_index_(index), tier_(tier) {}
WasmCompilationResult ExecuteCompilation(
WasmEngine*, CompilationEnv*, const std::shared_ptr<WireBytesStorage>&,
@ -83,15 +76,8 @@ class V8_EXPORT_PRIVATE WasmCompilationUnit final {
ExecutionTier);
private:
friend class compiler::TurbofanWasmCompilationUnit;
const int func_index_;
ExecutionTier tier_;
// TurbofanWasmCompilationUnit, set if {tier_ == kTurbofan}.
std::unique_ptr<compiler::TurbofanWasmCompilationUnit> turbofan_unit_;
void SwitchTier(ExecutionTier new_tier);
const ExecutionTier tier_;
DISALLOW_COPY_AND_ASSIGN(WasmCompilationUnit);
};