Commit 9841a432 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Simplify {TurbofanWasmCompilationUnit}.

R=clemensh@chromium.org
BUG=v8:7921

Change-Id: I5d6417c7b661066cecaf2eb7125d7399f3d9cf21
Reviewed-on: https://chromium-review.googlesource.com/1135141
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54431}
parent f3a8aef2
......@@ -302,7 +302,6 @@ class OptimizedCompilationJob : public CompilationJob {
OptimizedCompilationInfo* compilation_info() const {
return compilation_info_;
}
virtual size_t AllocatedMemory() const { return 0; }
protected:
// Overridden by the actual implementation.
......
......@@ -1000,8 +1000,6 @@ class PipelineWasmCompilationJob final : public OptimizedCompilationJob {
Status FinalizeJobImpl(Isolate* isolate) final;
private:
size_t AllocatedMemory() const override;
ZoneStats zone_stats_;
std::unique_ptr<PipelineStatistics> pipeline_statistics_;
PipelineData data_;
......@@ -1091,10 +1089,6 @@ PipelineWasmCompilationJob::ExecuteJobImpl() {
return SUCCEEDED;
}
size_t PipelineWasmCompilationJob::AllocatedMemory() const {
return pipeline_.data_->zone_stats()->GetCurrentAllocatedBytes();
}
PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::FinalizeJobImpl(
Isolate* isolate) {
UNREACHABLE(); // Finalize should always be skipped for WasmCompilationJob.
......
......@@ -36,6 +36,7 @@
#include "src/heap/factory.h"
#include "src/isolate-inl.h"
#include "src/log-inl.h"
#include "src/optimized-compilation-info.h"
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/function-body-decoder.h"
#include "src/wasm/function-compiler.h"
......@@ -5087,7 +5088,7 @@ TurbofanWasmCompilationUnit::TurbofanWasmCompilationUnit(
TurbofanWasmCompilationUnit::~TurbofanWasmCompilationUnit() = default;
SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
double* decode_ms, NodeOriginTable* node_origins) {
double* decode_ms, MachineGraph* mcgraph, NodeOriginTable* node_origins) {
base::ElapsedTimer decode_timer;
if (FLAG_trace_wasm_decode_time) {
decode_timer.Start();
......@@ -5095,8 +5096,8 @@ SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
// Create a TF graph during decoding.
SourcePositionTable* source_position_table =
new (mcgraph_->zone()) SourcePositionTable(mcgraph_->graph());
WasmGraphBuilder builder(wasm_unit_->env_, mcgraph_->zone(), mcgraph_,
new (mcgraph->zone()) SourcePositionTable(mcgraph->graph());
WasmGraphBuilder builder(wasm_unit_->env_, mcgraph->zone(), mcgraph,
wasm_unit_->func_body_.sig, source_position_table);
graph_construction_result_ =
wasm::BuildTFGraph(wasm_unit_->isolate_->allocator(), &builder,
......@@ -5114,8 +5115,8 @@ SourcePositionTable* TurbofanWasmCompilationUnit::BuildGraphForWasmFunction(
if (builder.has_simd() &&
(!CpuFeatures::SupportsWasmSimd128() || wasm_unit_->lower_simd_)) {
SimdScalarLowering(
mcgraph_,
CreateMachineSignature(mcgraph_->zone(), wasm_unit_->func_body_.sig))
mcgraph,
CreateMachineSignature(mcgraph->zone(), wasm_unit_->func_body_.sig))
.LowerGraph();
}
......@@ -5159,7 +5160,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() {
// Scope for the {graph_zone}.
{
Zone graph_zone(wasm_unit_->isolate_->allocator(), ZONE_NAME);
mcgraph_ = new (&graph_zone)
MachineGraph* mcgraph = new (&graph_zone)
MachineGraph(new (&graph_zone) Graph(&graph_zone),
new (&graph_zone) CommonOperatorBuilder(&graph_zone),
new (&graph_zone) MachineOperatorBuilder(
......@@ -5167,20 +5168,19 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() {
InstructionSelector::SupportedMachineOperatorFlags(),
InstructionSelector::AlignmentRequirements()));
compilation_zone_.reset(
new Zone(wasm_unit_->isolate_->allocator(), ZONE_NAME));
Zone compilation_zone(wasm_unit_->isolate_->allocator(), ZONE_NAME);
info_.reset(new OptimizedCompilationInfo(
GetDebugName(compilation_zone_.get(), wasm_unit_->func_name_,
OptimizedCompilationInfo info(
GetDebugName(&compilation_zone, wasm_unit_->func_name_,
wasm_unit_->func_index_),
compilation_zone_.get(), Code::WASM_FUNCTION));
&compilation_zone, Code::WASM_FUNCTION);
NodeOriginTable* node_origins = info_->trace_turbo_json_enabled()
NodeOriginTable* node_origins = info.trace_turbo_json_enabled()
? new (&graph_zone)
NodeOriginTable(mcgraph_->graph())
NodeOriginTable(mcgraph->graph())
: nullptr;
SourcePositionTable* source_positions =
BuildGraphForWasmFunction(&decode_ms, node_origins);
BuildGraphForWasmFunction(&decode_ms, mcgraph, node_origins);
if (graph_construction_result_.failed()) {
ok_ = false;
......@@ -5193,29 +5193,30 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() {
base::ElapsedTimer pipeline_timer;
if (FLAG_trace_wasm_decode_time) {
node_count = mcgraph_->graph()->NodeCount();
node_count = mcgraph->graph()->NodeCount();
pipeline_timer.Start();
}
// Run the compiler pipeline to generate machine code.
auto call_descriptor = GetWasmCallDescriptor(compilation_zone_.get(),
wasm_unit_->func_body_.sig);
if (mcgraph_->machine()->Is32()) {
auto call_descriptor =
GetWasmCallDescriptor(&compilation_zone, wasm_unit_->func_body_.sig);
if (mcgraph->machine()->Is32()) {
call_descriptor =
GetI32WasmCallDescriptor(compilation_zone_.get(), call_descriptor);
GetI32WasmCallDescriptor(&compilation_zone, call_descriptor);
}
job_.reset(Pipeline::NewWasmCompilationJob(
info_.get(), wasm_unit_->isolate_->wasm_engine(), wasm_unit_->isolate_,
mcgraph_, call_descriptor, source_positions, node_origins,
&wasm_compilation_data_, wasm_unit_->func_body_,
const_cast<wasm::WasmModule*>(wasm_unit_->env_->module),
wasm_unit_->native_module_, wasm_unit_->func_index_,
wasm_unit_->env_->module->origin));
ok_ = job_->ExecuteJob() == CompilationJob::SUCCEEDED;
std::unique_ptr<OptimizedCompilationJob> job(
Pipeline::NewWasmCompilationJob(
&info, wasm_unit_->isolate_->wasm_engine(), wasm_unit_->isolate_,
mcgraph, call_descriptor, source_positions, node_origins,
&wasm_compilation_data_, wasm_unit_->func_body_,
const_cast<wasm::WasmModule*>(wasm_unit_->env_->module),
wasm_unit_->native_module_, wasm_unit_->func_index_,
wasm_unit_->env_->module->origin));
ok_ = job->ExecuteJob() == CompilationJob::SUCCEEDED;
// TODO(bradnelson): Improve histogram handling of size_t.
wasm_unit_->counters_->wasm_compile_function_peak_memory_bytes()->AddSample(
static_cast<int>(mcgraph_->graph()->zone()->allocation_size()));
static_cast<int>(mcgraph->graph()->zone()->allocation_size()));
if (FLAG_trace_wasm_decode_time) {
double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF();
......@@ -5226,13 +5227,12 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() {
wasm_unit_->func_body_.start),
decode_ms, node_count, pipeline_ms);
}
// The graph zone is about to get out of scope. Avoid invalid references.
mcgraph_ = nullptr;
if (ok_) wasm_code_ = info.wasm_code();
}
// Record the memory cost this unit places on the system until
// it is finalized.
wasm_unit_->memory_cost_ = job_->AllocatedMemory();
wasm_unit_->memory_cost_ = sizeof(TurbofanWasmCompilationUnit);
}
wasm::WasmCode* TurbofanWasmCompilationUnit::FinishCompilation(
......@@ -5256,9 +5256,8 @@ wasm::WasmCode* TurbofanWasmCompilationUnit::FinishCompilation(
return nullptr;
}
wasm::WasmCode* code = job_->compilation_info()->wasm_code();
wasm_unit_->native_module()->PublishCode(code);
return code;
wasm_unit_->native_module()->PublishCode(wasm_code_);
return wasm_code_;
}
namespace {
......
......@@ -9,7 +9,6 @@
// Clients of this interface shouldn't depend on lots of compiler internals.
// Do not include anything from src/compiler here!
#include "src/optimized-compilation-info.h"
#include "src/runtime/runtime.h"
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/function-body-decoder.h"
......@@ -22,7 +21,6 @@
namespace v8 {
namespace internal {
struct AssemblerOptions;
class OptimizedCompilationJob;
namespace compiler {
// Forward declarations for some compiler data structures.
......@@ -84,6 +82,7 @@ class TurbofanWasmCompilationUnit {
~TurbofanWasmCompilationUnit();
SourcePositionTable* BuildGraphForWasmFunction(double* decode_ms,
MachineGraph* mcgraph,
NodeOriginTable* node_origins);
void ExecuteCompilation();
......@@ -94,15 +93,7 @@ class TurbofanWasmCompilationUnit {
wasm::WasmCompilationUnit* const wasm_unit_;
WasmCompilationData wasm_compilation_data_;
bool ok_ = true;
// The graph zone is deallocated at the end of {ExecuteCompilation} by virtue
// of it being zone allocated.
MachineGraph* mcgraph_ = nullptr;
// The compilation_zone_, info_, and job_ fields need to survive past
// {ExecuteCompilation}, onto {FinishCompilation} (which happens on the main
// thread).
std::unique_ptr<Zone> compilation_zone_;
std::unique_ptr<OptimizedCompilationInfo> info_;
std::unique_ptr<OptimizedCompilationJob> job_;
wasm::WasmCode* wasm_code_ = nullptr;
wasm::Result<wasm::DecodeStruct*> graph_construction_result_;
DISALLOW_COPY_AND_ASSIGN(TurbofanWasmCompilationUnit);
......
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