Commit 8cc3da3c authored by Stephan Herhut's avatar Stephan Herhut Committed by Commit Bot

[wasm] Do not use GenerateCodeForTesting in production

The wasm compiler used Pipeline::GenerateCodeForTesting to generate code
for various stubs. This change adds a dedicated entry point and moves
some common code there.

Bug: v8:8015
Change-Id: Ied628ba14c36e68826cb71d00506994184cc4763
Reviewed-on: https://chromium-review.googlesource.com/1196885
Commit-Queue: Stephan Herhut <herhut@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55599}
parent a4df9cbf
......@@ -2194,6 +2194,53 @@ MaybeHandle<Code> Pipeline::GenerateCodeForCodeStub(
return pipeline.GenerateCode(call_descriptor);
}
// static
MaybeHandle<Code> Pipeline::GenerateCodeForWasmStub(
Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph,
Code::Kind kind, const char* debug_name, const AssemblerOptions& options,
SourcePositionTable* source_positions) {
OptimizedCompilationInfo info(CStrVector(debug_name), graph->zone(), kind);
// Construct a pipeline for scheduling and code generation.
ZoneStats zone_stats(isolate->allocator());
// TODO(wasm): Refactor code generation to check for non-existing source
// table, then remove this conditional allocation.
if (!source_positions)
source_positions = new (graph->zone()) SourcePositionTable(graph);
NodeOriginTable* node_positions = new (graph->zone()) NodeOriginTable(graph);
PipelineData data(&zone_stats, &info, isolate, graph, nullptr,
source_positions, node_positions, nullptr, options);
std::unique_ptr<PipelineStatistics> pipeline_statistics;
if (FLAG_turbo_stats || FLAG_turbo_stats_nvp) {
pipeline_statistics.reset(new PipelineStatistics(
&info, isolate->GetTurboStatistics(), &zone_stats));
pipeline_statistics->BeginPhaseKind("wasm stub codegen");
}
PipelineImpl pipeline(&data);
if (info.trace_turbo_graph_enabled()) { // Simple textual RPO.
StdoutStream{} << "-- wasm stub " << Code::Kind2String(kind) << " graph -- "
<< std::endl
<< AsRPO(*graph);
}
if (info.trace_turbo_json_enabled()) {
TurboJsonFile json_of(&info, std::ios_base::trunc);
json_of << "{\"function\":\"" << info.GetDebugName().get()
<< "\", \"source\":\"\",\n\"phases\":[";
}
// TODO(rossberg): Should this really be untyped?
pipeline.RunPrintAndVerify("machine", true);
pipeline.ComputeScheduledGraph();
Handle<Code> code;
if (pipeline.GenerateCode(call_descriptor).ToHandle(&code) &&
pipeline.CommitDependencies(code)) {
return code;
}
return MaybeHandle<Code>();
}
// static
MaybeHandle<Code> Pipeline::GenerateCodeForTesting(
OptimizedCompilationInfo* info, Isolate* isolate) {
......
......@@ -54,6 +54,13 @@ class Pipeline : public AllStatic {
wasm::NativeModule* native_module, int function_index,
wasm::ModuleOrigin wasm_origin);
// Run the pipeline on a machine graph and generate code.
static MaybeHandle<Code> GenerateCodeForWasmStub(
Isolate* isolate, CallDescriptor* call_descriptor, Graph* graph,
Code::Kind kind, const char* debug_name,
const AssemblerOptions& assembler_options,
SourcePositionTable* source_positions = nullptr);
// Run the pipeline on a machine graph and generate code. The {schedule} must
// be valid, hence the given {graph} does not need to be schedulable.
static MaybeHandle<Code> GenerateCodeForCodeStub(
......
......@@ -4783,20 +4783,14 @@ MaybeHandle<Code> CompileJSToWasmWrapper(
Vector<const char> func_name = CStrVector("js-to-wasm");
#endif
OptimizedCompilationInfo info(func_name, &zone, Code::JS_TO_WASM_FUNCTION);
if (info.trace_turbo_graph_enabled()) { // Simple textual RPO.
StdoutStream{} << "-- Graph after change lowering -- " << std::endl
<< AsRPO(graph);
}
// Schedule and compile to machine code.
int params = static_cast<int>(sig->parameter_count());
CallDescriptor* incoming = Linkage::GetJSCallDescriptor(
&zone, false, params + 1, CallDescriptor::kNoFlags);
MaybeHandle<Code> maybe_code = Pipeline::GenerateCodeForTesting(
&info, isolate, incoming, &graph, WasmAssemblerOptions());
MaybeHandle<Code> maybe_code = Pipeline::GenerateCodeForWasmStub(
isolate, incoming, &graph, Code::JS_TO_WASM_FUNCTION, func_name.start(),
WasmAssemblerOptions());
Handle<Code> code;
if (!maybe_code.ToHandle(&code)) {
return maybe_code;
......@@ -4860,21 +4854,14 @@ MaybeHandle<Code> CompileWasmToJSWrapper(
Vector<const char> func_name = CStrVector("wasm-to-js");
#endif
OptimizedCompilationInfo info(func_name, &zone, Code::WASM_TO_JS_FUNCTION);
if (info.trace_turbo_graph_enabled()) { // Simple textual RPO.
StdoutStream{} << "-- Graph after change lowering -- " << std::endl
<< AsRPO(graph);
}
// Schedule and compile to machine code.
CallDescriptor* incoming = GetWasmCallDescriptor(&zone, sig);
if (machine.Is32()) {
incoming = GetI32WasmCallDescriptor(&zone, incoming);
}
MaybeHandle<Code> maybe_code = Pipeline::GenerateCodeForTesting(
&info, isolate, incoming, &graph, AssemblerOptions::Default(isolate),
nullptr, source_position_table);
MaybeHandle<Code> maybe_code = Pipeline::GenerateCodeForWasmStub(
isolate, incoming, &graph, Code::WASM_TO_JS_FUNCTION, func_name.start(),
AssemblerOptions::Default(isolate), source_position_table);
Handle<Code> code;
if (!maybe_code.ToHandle(&code)) {
return maybe_code;
......@@ -4932,16 +4919,9 @@ MaybeHandle<Code> CompileWasmInterpreterEntry(Isolate* isolate,
Vector<const char> func_name = CStrVector("wasm-interpreter-entry");
#endif
OptimizedCompilationInfo info(func_name, &zone, Code::WASM_INTERPRETER_ENTRY);
if (info.trace_turbo_graph_enabled()) { // Simple textual RPO.
StdoutStream{} << "-- Wasm interpreter entry graph -- " << std::endl
<< AsRPO(graph);
}
MaybeHandle<Code> maybe_code = Pipeline::GenerateCodeForTesting(
&info, isolate, incoming, &graph, AssemblerOptions::Default(isolate),
nullptr);
MaybeHandle<Code> maybe_code = Pipeline::GenerateCodeForWasmStub(
isolate, incoming, &graph, Code::WASM_INTERPRETER_ENTRY,
func_name.start(), AssemblerOptions::Default(isolate));
Handle<Code> code;
if (!maybe_code.ToHandle(&code)) {
return maybe_code;
......@@ -5001,16 +4981,10 @@ MaybeHandle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) {
append_name_char(wasm::ValueTypes::ShortNameOf(t));
}
debug_name[name_len] = '\0';
Vector<const char> debug_name_vec(debug_name, name_len);
OptimizedCompilationInfo info(debug_name_vec, &zone, Code::C_WASM_ENTRY);
if (info.trace_turbo_graph_enabled()) { // Simple textual RPO.
StdoutStream{} << "-- C Wasm entry graph -- " << std::endl << AsRPO(graph);
}
MaybeHandle<Code> maybe_code = Pipeline::GenerateCodeForTesting(
&info, isolate, incoming, &graph, AssemblerOptions::Default(isolate));
MaybeHandle<Code> maybe_code = Pipeline::GenerateCodeForWasmStub(
isolate, incoming, &graph, Code::C_WASM_ENTRY, debug_name,
AssemblerOptions::Default(isolate));
Handle<Code> code;
if (!maybe_code.ToHandle(&code)) {
return maybe_code;
......
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