Commit 8b14d187 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Remove TurbofanWasmCompilationUnit::ok_ field

This field is redundant in that {ok_ == true} equals
{wasm_code_ != nullptr}. Thus remove it, and simplify some logic.

R=ahaas@chromium.org
CC=gdeepti@chromium.org

Bug: v8:8238
Change-Id: I3e3cfcc3a06c945d836c1a8a388bec54e1af12ea
Reviewed-on: https://chromium-review.googlesource.com/c/1290791Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56803}
parent 845ac4b6
...@@ -5209,114 +5209,107 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation( ...@@ -5209,114 +5209,107 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation(
double decode_ms = 0; double decode_ms = 0;
size_t node_count = 0; size_t node_count = 0;
// Scope for the {graph_zone}. Zone graph_zone(wasm_unit_->wasm_engine_->allocator(), ZONE_NAME);
{ MachineGraph* mcgraph = new (&graph_zone)
Zone graph_zone(wasm_unit_->wasm_engine_->allocator(), ZONE_NAME); MachineGraph(new (&graph_zone) Graph(&graph_zone),
MachineGraph* mcgraph = new (&graph_zone) new (&graph_zone) CommonOperatorBuilder(&graph_zone),
MachineGraph(new (&graph_zone) Graph(&graph_zone), new (&graph_zone) MachineOperatorBuilder(
new (&graph_zone) CommonOperatorBuilder(&graph_zone), &graph_zone, MachineType::PointerRepresentation(),
new (&graph_zone) MachineOperatorBuilder( InstructionSelector::SupportedMachineOperatorFlags(),
&graph_zone, MachineType::PointerRepresentation(), InstructionSelector::AlignmentRequirements()));
InstructionSelector::SupportedMachineOperatorFlags(),
InstructionSelector::AlignmentRequirements()));
Zone compilation_zone(wasm_unit_->wasm_engine_->allocator(), ZONE_NAME);
OptimizedCompilationInfo info(
GetDebugName(&compilation_zone, wasm_unit_->func_index_),
&compilation_zone, Code::WASM_FUNCTION);
if (wasm_unit_->env_->runtime_exception_support) {
info.SetWasmRuntimeExceptionSupport();
}
if (info.trace_turbo_json_enabled()) { Zone compilation_zone(wasm_unit_->wasm_engine_->allocator(), ZONE_NAME);
TurboCfgFile tcf;
tcf << AsC1VCompilation(&info);
}
NodeOriginTable* node_origins = info.trace_turbo_json_enabled() OptimizedCompilationInfo info(
? new (&graph_zone) GetDebugName(&compilation_zone, wasm_unit_->func_index_),
NodeOriginTable(mcgraph->graph()) &compilation_zone, Code::WASM_FUNCTION);
: nullptr; if (wasm_unit_->env_->runtime_exception_support) {
SourcePositionTable* source_positions = info.SetWasmRuntimeExceptionSupport();
BuildGraphForWasmFunction(detected, &decode_ms, mcgraph, node_origins); }
if (graph_construction_result_.failed()) { if (info.trace_turbo_json_enabled()) {
ok_ = false; TurboCfgFile tcf;
return; tcf << AsC1VCompilation(&info);
} }
if (node_origins) { NodeOriginTable* node_origins = info.trace_turbo_json_enabled()
node_origins->AddDecorator(); ? new (&graph_zone)
} NodeOriginTable(mcgraph->graph())
: nullptr;
SourcePositionTable* source_positions =
BuildGraphForWasmFunction(detected, &decode_ms, mcgraph, node_origins);
base::ElapsedTimer pipeline_timer; if (graph_construction_result_.failed()) return;
if (FLAG_trace_wasm_decode_time) {
node_count = mcgraph->graph()->NodeCount();
pipeline_timer.Start();
}
// Run the compiler pipeline to generate machine code. if (node_origins) {
auto call_descriptor = node_origins->AddDecorator();
GetWasmCallDescriptor(&compilation_zone, wasm_unit_->func_body_.sig); }
if (mcgraph->machine()->Is32()) {
call_descriptor =
GetI32WasmCallDescriptor(&compilation_zone, call_descriptor);
}
std::unique_ptr<OptimizedCompilationJob> job( base::ElapsedTimer pipeline_timer;
Pipeline::NewWasmCompilationJob( if (FLAG_trace_wasm_decode_time) {
&info, wasm_unit_->wasm_engine_, mcgraph, call_descriptor, node_count = mcgraph->graph()->NodeCount();
source_positions, node_origins, wasm_unit_->func_body_, pipeline_timer.Start();
const_cast<wasm::WasmModule*>(wasm_unit_->env_->module), }
wasm_unit_->native_module_, wasm_unit_->func_index_,
wasm_unit_->env_->module->origin)); // Run the compiler pipeline to generate machine code.
ok_ = job->ExecuteJob() == CompilationJob::SUCCEEDED; auto call_descriptor =
// TODO(bradnelson): Improve histogram handling of size_t. GetWasmCallDescriptor(&compilation_zone, wasm_unit_->func_body_.sig);
wasm_unit_->counters_->wasm_compile_function_peak_memory_bytes()->AddSample( if (mcgraph->machine()->Is32()) {
static_cast<int>(mcgraph->graph()->zone()->allocation_size())); call_descriptor =
GetI32WasmCallDescriptor(&compilation_zone, call_descriptor);
if (FLAG_trace_wasm_decode_time) { }
double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF();
PrintF( std::unique_ptr<OptimizedCompilationJob> job(Pipeline::NewWasmCompilationJob(
"wasm-compilation phase 1 ok: %u bytes, %0.3f ms decode, %zu nodes, " &info, wasm_unit_->wasm_engine_, mcgraph, call_descriptor,
"%0.3f ms pipeline\n", source_positions, node_origins, wasm_unit_->func_body_,
static_cast<unsigned>(wasm_unit_->func_body_.end - const_cast<wasm::WasmModule*>(wasm_unit_->env_->module),
wasm_unit_->func_body_.start), wasm_unit_->native_module_, wasm_unit_->func_index_,
decode_ms, node_count, pipeline_ms); wasm_unit_->env_->module->origin));
} bool succeeded = job->ExecuteJob() == CompilationJob::SUCCEEDED;
if (ok_) wasm_code_ = info.wasm_code(); // 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()));
if (FLAG_trace_wasm_decode_time) {
double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF();
PrintF(
"wasm-compilation phase 1 ok: %u bytes, %0.3f ms decode, %zu nodes, "
"%0.3f ms pipeline\n",
static_cast<unsigned>(wasm_unit_->func_body_.end -
wasm_unit_->func_body_.start),
decode_ms, node_count, pipeline_ms);
}
if (succeeded) {
wasm_code_ = info.wasm_code();
wasm_unit_->native_module()->PublishCode(wasm_code_);
} }
if (ok_) wasm_unit_->native_module()->PublishCode(wasm_code_);
} }
wasm::WasmCode* TurbofanWasmCompilationUnit::FinishCompilation( wasm::WasmCode* TurbofanWasmCompilationUnit::FinishCompilation(
wasm::ErrorThrower* thrower) { wasm::ErrorThrower* thrower) {
if (!ok_) { DCHECK_IMPLIES(graph_construction_result_.failed(), wasm_code_ == nullptr);
if (graph_construction_result_.failed()) { if (wasm_code_ != nullptr) return wasm_code_;
// Add the function as another context for the exception. This is
// user-visible, so use official format.
EmbeddedVector<char, 128> message;
wasm::ModuleWireBytes wire_bytes(
wasm_unit_->native_module()->wire_bytes());
wasm::WireBytesRef name_ref =
wasm_unit_->native_module()->module()->LookupFunctionName(
wire_bytes, wasm_unit_->func_index_);
if (name_ref.is_set()) {
wasm::WasmName name = wire_bytes.GetNameOrNull(name_ref);
SNPrintF(message, "Compiling wasm function \"%.*s\" failed",
name.length(), name.start());
} else {
SNPrintF(message,
"Compiling wasm function \"wasm-function[%d]\" failed",
wasm_unit_->func_index_);
}
thrower->CompileFailed(message.start(), graph_construction_result_);
}
return nullptr; if (graph_construction_result_.failed()) {
// Add the function as another context for the exception. This is
// user-visible, so use official format.
EmbeddedVector<char, 128> message;
wasm::ModuleWireBytes wire_bytes(wasm_unit_->native_module()->wire_bytes());
wasm::WireBytesRef name_ref =
wasm_unit_->native_module()->module()->LookupFunctionName(
wire_bytes, wasm_unit_->func_index_);
if (name_ref.is_set()) {
wasm::WasmName name = wire_bytes.GetNameOrNull(name_ref);
SNPrintF(message, "Compiling wasm function \"%.*s\" failed",
name.length(), name.start());
} else {
SNPrintF(message, "Compiling wasm function \"wasm-function[%d]\" failed",
wasm_unit_->func_index_);
}
thrower->CompileFailed(message.start(), graph_construction_result_);
} }
return wasm_code_;
return nullptr;
} }
namespace { namespace {
......
...@@ -61,7 +61,6 @@ class TurbofanWasmCompilationUnit { ...@@ -61,7 +61,6 @@ class TurbofanWasmCompilationUnit {
private: private:
wasm::WasmCompilationUnit* const wasm_unit_; wasm::WasmCompilationUnit* const wasm_unit_;
bool ok_ = true;
wasm::WasmCode* wasm_code_ = nullptr; wasm::WasmCode* wasm_code_ = nullptr;
wasm::Result<wasm::DecodeStruct*> graph_construction_result_; wasm::Result<wasm::DecodeStruct*> graph_construction_result_;
......
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