| Index: src/compiler/wasm-compiler.cc
|
| diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc
|
| index e147123817af7de8f8fac0a5542389712112ce6d..56fb1bc6a60f1f4f11faf045d89ca46f07b463fd 100644
|
| --- a/src/compiler/wasm-compiler.cc
|
| +++ b/src/compiler/wasm-compiler.cc
|
| @@ -29,6 +29,9 @@
|
|
|
| #include "src/code-factory.h"
|
| #include "src/code-stubs.h"
|
| +#include "src/factory.h"
|
| +#include "src/log-inl.h"
|
| +#include "src/profiler/cpu-profiler.h"
|
|
|
| #include "src/wasm/ast-decoder.h"
|
| #include "src/wasm/wasm-module.h"
|
| @@ -1862,6 +1865,28 @@ Node* WasmGraphBuilder::String(const char* string) {
|
| Graph* WasmGraphBuilder::graph() { return jsgraph()->graph(); }
|
|
|
|
|
| +static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
|
| + CompilationInfo* info,
|
| + const char* message, uint32_t index,
|
| + const char* func_name) {
|
| + Isolate* isolate = info->isolate();
|
| + if (isolate->logger()->is_logging_code_events() ||
|
| + isolate->cpu_profiler()->is_profiling()) {
|
| + ScopedVector<char> buffer(128);
|
| + SNPrintF(buffer, "%s#%d:%s", message, index, func_name);
|
| + Handle<String> name_str =
|
| + isolate->factory()->NewStringFromAsciiChecked(buffer.start());
|
| + Handle<String> script_str =
|
| + isolate->factory()->NewStringFromAsciiChecked("(WASM)");
|
| + Handle<Code> code = info->code();
|
| + Handle<SharedFunctionInfo> shared =
|
| + isolate->factory()->NewSharedFunctionInfo(name_str, code, false);
|
| + PROFILE(isolate,
|
| + CodeCreateEvent(tag, *code, *shared, info, *script_str, 0, 0));
|
| + }
|
| +}
|
| +
|
| +
|
| Handle<JSFunction> CompileJSToWasmWrapper(
|
| Isolate* isolate, wasm::ModuleEnv* module, Handle<String> name,
|
| Handle<Code> wasm_code, Handle<JSObject> module_object, uint32_t index) {
|
| @@ -1933,21 +1958,8 @@ Handle<JSFunction> CompileJSToWasmWrapper(
|
| CompilationInfo info("js-to-wasm", isolate, &zone, flags);
|
| Handle<Code> code =
|
| Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr);
|
| -
|
| -#ifdef ENABLE_DISASSEMBLER
|
| - // Disassemble the wrapper code for debugging.
|
| - if (!code.is_null() && FLAG_print_opt_code) {
|
| - Vector<char> buffer;
|
| - const char* name = "";
|
| - if (func->name_offset > 0) {
|
| - const byte* ptr = module->module->module_start + func->name_offset;
|
| - name = reinterpret_cast<const char*>(ptr);
|
| - }
|
| - SNPrintF(buffer, "JS->WASM function wrapper #%d:%s", index, name);
|
| - OFStream os(stdout);
|
| - code->Disassemble(buffer.start(), os);
|
| - }
|
| -#endif
|
| + RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "js-to-wasm", index,
|
| + module->module->GetName(func->name_offset));
|
| // Set the JSFunction's machine code.
|
| function->set_code(*code);
|
| }
|
| @@ -2008,20 +2020,8 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module,
|
| CompilationInfo info("wasm-to-js", isolate, &zone, flags);
|
| code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr);
|
|
|
| -#ifdef ENABLE_DISASSEMBLER
|
| - // Disassemble the wrapper code for debugging.
|
| - if (!code.is_null() && FLAG_print_opt_code) {
|
| - Vector<char> buffer;
|
| - const char* name = "";
|
| - if (func->name_offset > 0) {
|
| - const byte* ptr = module->module->module_start + func->name_offset;
|
| - name = reinterpret_cast<const char*>(ptr);
|
| - }
|
| - SNPrintF(buffer, "WASM->JS function wrapper #%d:%s", index, name);
|
| - OFStream os(stdout);
|
| - code->Disassemble(buffer.start(), os);
|
| - }
|
| -#endif
|
| + RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", index,
|
| + module->module->GetName(func->name_offset));
|
| }
|
| return code;
|
| }
|
| @@ -2072,7 +2072,7 @@ Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate,
|
| os << "Compilation failed: " << result << std::endl;
|
| }
|
| // Add the function as another context for the exception
|
| - Vector<char> buffer;
|
| + ScopedVector<char> buffer(128);
|
| SNPrintF(buffer, "Compiling WASM function #%d:%s failed:", index,
|
| module_env->module->GetName(function.name_offset));
|
| thrower.Failed(buffer.start(), result);
|
| @@ -2083,24 +2083,29 @@ Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate,
|
| CallDescriptor* descriptor = const_cast<CallDescriptor*>(
|
| module_env->GetWasmCallDescriptor(&zone, function.sig));
|
| Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION);
|
| - CompilationInfo info("wasm", isolate, &zone, flags);
|
| + // add flags here if a meaningful name is helpful for debugging.
|
| + bool debugging =
|
| + FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph;
|
| + const char* func_name = "wasm";
|
| + Vector<char> buffer;
|
| + if (debugging) {
|
| + buffer = Vector<char>::New(128);
|
| + SNPrintF(buffer, "WASM_function_#%d:%s", index,
|
| + module_env->module->GetName(function.name_offset));
|
| + func_name = buffer.start();
|
| + }
|
| + CompilationInfo info(func_name, isolate, &zone, flags);
|
| Handle<Code> code =
|
| Pipeline::GenerateCodeForTesting(&info, descriptor, &graph);
|
| -
|
| -#ifdef ENABLE_DISASSEMBLER
|
| - // Disassemble the code for debugging.
|
| - if (!code.is_null() && FLAG_print_opt_code) {
|
| - Vector<char> buffer;
|
| - const char* name = "";
|
| - if (function.name_offset > 0) {
|
| - const byte* ptr = module_env->module->module_start + function.name_offset;
|
| - name = reinterpret_cast<const char*>(ptr);
|
| - }
|
| - SNPrintF(buffer, "WASM function #%d:%s", index, name);
|
| - OFStream os(stdout);
|
| - code->Disassemble(buffer.start(), os);
|
| + if (debugging) {
|
| + buffer.Dispose();
|
| }
|
| -#endif
|
| + if (!code.is_null()) {
|
| + RecordFunctionCompilation(
|
| + Logger::FUNCTION_TAG, &info, "WASM_function", index,
|
| + module_env->module->GetName(function.name_offset));
|
| + }
|
| +
|
| return code;
|
| }
|
|
|
|
|