Commit 5b91f448 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by V8 LUCI CQ

[wasm][turbofan] Use function name if available

If a name is defined for a wasm function, we retrieve it from the module
and use it for tracing.

Change-Id: I42da12d2476af573017daaa3f216cca8a95efbbb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3344646Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78409}
parent d0e2117a
...@@ -8093,8 +8093,23 @@ bool BuildGraphForWasmFunction(wasm::CompilationEnv* env, ...@@ -8093,8 +8093,23 @@ bool BuildGraphForWasmFunction(wasm::CompilationEnv* env,
return true; return true;
} }
base::Vector<const char> GetDebugName(Zone* zone, int index) { base::Vector<const char> GetDebugName(Zone* zone,
// TODO(herhut): Use name from module if available. const wasm::WasmModule* module,
const wasm::WireBytesStorage* wire_bytes,
int index) {
base::Optional<wasm::ModuleWireBytes> module_bytes =
wire_bytes->GetModuleBytes();
if (module_bytes.has_value() &&
(FLAG_trace_turbo || FLAG_trace_turbo_scheduled ||
FLAG_trace_turbo_graph || FLAG_print_wasm_code)) {
wasm::WireBytesRef name = module->lazily_generated_names.LookupFunctionName(
module_bytes.value(), index);
int name_len = name.length();
char* index_name = zone->NewArray<char>(name_len);
memcpy(index_name, module_bytes->start() + name.offset(), name.length());
return base::Vector<const char>(index_name, name_len);
}
constexpr int kBufferLength = 24; constexpr int kBufferLength = 24;
base::EmbeddedVector<char, kBufferLength> name_vector; base::EmbeddedVector<char, kBufferLength> name_vector;
...@@ -8109,7 +8124,7 @@ base::Vector<const char> GetDebugName(Zone* zone, int index) { ...@@ -8109,7 +8124,7 @@ base::Vector<const char> GetDebugName(Zone* zone, int index) {
} // namespace } // namespace
wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation( wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation(
wasm::CompilationEnv* env, const wasm::WireBytesStorage* wire_bytes_storage, wasm::CompilationEnv* env, const wasm::WireBytesStorage* wire_byte_storage,
const wasm::FunctionBody& func_body, int func_index, Counters* counters, const wasm::FunctionBody& func_body, int func_index, Counters* counters,
wasm::WasmFeatures* detected) { wasm::WasmFeatures* detected) {
TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"), TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed"),
...@@ -8123,8 +8138,9 @@ wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation( ...@@ -8123,8 +8138,9 @@ wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation(
InstructionSelector::SupportedMachineOperatorFlags(), InstructionSelector::SupportedMachineOperatorFlags(),
InstructionSelector::AlignmentRequirements())); InstructionSelector::AlignmentRequirements()));
OptimizedCompilationInfo info(GetDebugName(&zone, func_index), &zone, OptimizedCompilationInfo info(
CodeKind::WASM_FUNCTION); GetDebugName(&zone, env->module, wire_byte_storage, func_index), &zone,
CodeKind::WASM_FUNCTION);
if (env->runtime_exception_support) { if (env->runtime_exception_support) {
info.set_wasm_runtime_exception_support(); info.set_wasm_runtime_exception_support();
} }
...@@ -8166,10 +8182,9 @@ wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation( ...@@ -8166,10 +8182,9 @@ wasm::WasmCompilationResult ExecuteTurbofanWasmCompilation(
return wasm::WasmCompilationResult{}; return wasm::WasmCompilationResult{};
} }
Pipeline::GenerateCodeForWasmFunction(&info, env, wire_bytes_storage, mcgraph, Pipeline::GenerateCodeForWasmFunction(
call_descriptor, source_positions, &info, env, wire_byte_storage, mcgraph, call_descriptor, source_positions,
node_origins, func_body, env->module, node_origins, func_body, env->module, func_index, &loop_infos);
func_index, &loop_infos);
if (counters) { if (counters) {
int zone_bytes = int zone_bytes =
......
...@@ -103,6 +103,9 @@ class WireBytesStorage { ...@@ -103,6 +103,9 @@ class WireBytesStorage {
public: public:
virtual ~WireBytesStorage() = default; virtual ~WireBytesStorage() = default;
virtual base::Vector<const uint8_t> GetCode(WireBytesRef) const = 0; virtual base::Vector<const uint8_t> GetCode(WireBytesRef) const = 0;
// Returns the ModuleWireBytes corresponding to the underlying module if
// available. Not supported if the wire bytes are owned by a StreamingDecoder.
virtual base::Optional<ModuleWireBytes> GetModuleBytes() const = 0;
}; };
// Callbacks will receive either {kFailedCompilation} or both // Callbacks will receive either {kFailedCompilation} or both
......
...@@ -77,6 +77,8 @@ class V8_EXPORT_PRIVATE AsyncStreamingDecoder : public StreamingDecoder { ...@@ -77,6 +77,8 @@ class V8_EXPORT_PRIVATE AsyncStreamingDecoder : public StreamingDecoder {
offset_in_code_buffer + ref.length()); offset_in_code_buffer + ref.length());
} }
base::Optional<ModuleWireBytes> GetModuleBytes() const final { return {}; }
uint32_t module_offset() const { return module_offset_; } uint32_t module_offset() const { return module_offset_; }
base::Vector<uint8_t> bytes() const { return bytes_.as_vector(); } base::Vector<uint8_t> bytes() const { return bytes_.as_vector(); }
base::Vector<uint8_t> payload() const { return bytes() + payload_offset_; } base::Vector<uint8_t> payload() const { return bytes() + payload_offset_; }
......
...@@ -1653,6 +1653,11 @@ class NativeModuleWireBytesStorage final : public WireBytesStorage { ...@@ -1653,6 +1653,11 @@ class NativeModuleWireBytesStorage final : public WireBytesStorage {
.SubVector(ref.offset(), ref.end_offset()); .SubVector(ref.offset(), ref.end_offset());
} }
base::Optional<ModuleWireBytes> GetModuleBytes() const final {
return base::Optional<ModuleWireBytes>(
std::atomic_load(&wire_bytes_)->as_vector());
}
private: private:
const std::shared_ptr<base::OwnedVector<const uint8_t>> wire_bytes_; const std::shared_ptr<base::OwnedVector<const uint8_t>> wire_bytes_;
}; };
......
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