Commit 7927d646 authored by Pierre Langlois's avatar Pierre Langlois Committed by Commit Bot

[turbofan][wasm] Fix --trace-turbo with compiling a WASM function.

The --trace-turbo flag would cause a crash when compiling a WASM_FUNCTION. It
was caused by assuming the OptimizedCompilationInfo had a SharedFunctionInfo
attached if the code isn't a stub and wasm functions are not considered as such.

In order to test this, we've added a new flag to specify were to dump JSON
files: --trace-turbo-path. This is used to make sure we do not leave lots of
files behind in the top-level directory. It should be useful as standalone
feature too.


Change-Id: Ia9442638d28100bea45a8683fb233803cc5393f2
Reviewed-on: https://chromium-review.googlesource.com/1030555
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53153}
parent 7bed2581
......@@ -30,6 +30,7 @@ namespace internal {
namespace compiler {
std::unique_ptr<char[]> GetVisualizerLogFileName(OptimizedCompilationInfo* info,
const char* optional_base_dir,
const char* phase,
const char* suffix) {
EmbeddedVector<char, 256> filename(0);
......@@ -62,16 +63,26 @@ std::unique_ptr<char[]> GetVisualizerLogFileName(OptimizedCompilationInfo* info,
std::replace(filename.start(), filename.start() + filename.length(), ' ',
'_');
EmbeddedVector<char, 256> base_dir;
if (optional_base_dir != nullptr) {
SNPrintF(base_dir, "%s%c", optional_base_dir,
base::OS::DirectorySeparator());
} else {
base_dir[0] = '\0';
}
EmbeddedVector<char, 256> full_filename;
if (phase == nullptr && !source_available) {
SNPrintF(full_filename, "%s.%s", filename.start(), suffix);
SNPrintF(full_filename, "%s%s.%s", base_dir.start(), filename.start(),
suffix);
} else if (phase != nullptr && !source_available) {
SNPrintF(full_filename, "%s-%s.%s", filename.start(), phase, suffix);
SNPrintF(full_filename, "%s%s-%s.%s", base_dir.start(), filename.start(),
phase, suffix);
} else if (phase == nullptr && source_available) {
SNPrintF(full_filename, "%s_%s.%s", filename.start(), source_file.start(),
suffix);
SNPrintF(full_filename, "%s%s_%s.%s", base_dir.start(), filename.start(),
source_file.start(), suffix);
} else {
SNPrintF(full_filename, "%s_%s-%s.%s", filename.start(),
SNPrintF(full_filename, "%s%s_%s-%s.%s", base_dir.start(), filename.start(),
source_file.start(), phase, suffix);
}
......
......@@ -25,6 +25,7 @@ class Schedule;
class SourcePositionTable;
std::unique_ptr<char[]> GetVisualizerLogFileName(OptimizedCompilationInfo* info,
const char* optional_base_dir,
const char* phase,
const char* suffix);
......
......@@ -623,7 +623,9 @@ struct TurboCfgFile : public std::ofstream {
struct TurboJsonFile : public std::ofstream {
TurboJsonFile(OptimizedCompilationInfo* info, std::ios_base::openmode mode)
: std::ofstream(GetVisualizerLogFileName(info, nullptr, "json").get(),
: std::ofstream(GetVisualizerLogFileName(info, FLAG_trace_turbo_path,
nullptr, "json")
.get(),
mode) {}
};
......@@ -714,7 +716,8 @@ PipelineStatistics* CreatePipelineStatistics(Handle<Script> script,
if (FLAG_trace_turbo) {
TurboJsonFile json_of(info, std::ios_base::trunc);
std::unique_ptr<char[]> function_name = info->GetDebugName();
int pos = info->IsStub() ? 0 : info->shared_info()->StartPosition();
int pos =
info->has_shared_info() ? info->shared_info()->StartPosition() : 0;
json_of << "{\"function\":\"" << function_name.get()
<< "\", \"sourcePosition\":" << pos << ", \"source\":\"";
if (!script.is_null() && !script->source()->IsUndefined(isolate)) {
......
......@@ -3290,7 +3290,9 @@ int Shell::Main(int argc, char* argv[]) {
} else {
v8::V8::InitializeExternalStartupData(argv[0]);
}
SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg");
if (i::FLAG_trace_turbo_cfg_file == nullptr) {
SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg");
}
SetFlagsFromString("--redirect-code-traces-to=code.asm");
int result = 0;
Isolate::CreateParams create_params;
......
......@@ -390,6 +390,8 @@ DEFINE_BOOL(turbo_preprocess_ranges, true,
"run pre-register allocation heuristics")
DEFINE_STRING(turbo_filter, "*", "optimization filter for TurboFan compiler")
DEFINE_BOOL(trace_turbo, false, "trace generated TurboFan IR")
DEFINE_STRING(trace_turbo_path, nullptr,
"directory to dump generated TurboFan IR to")
DEFINE_BOOL(trace_turbo_graph, false, "trace generated TurboFan graphs")
DEFINE_BOOL(trace_turbo_scheduled, false, "trace TurboFan IR with schedule")
DEFINE_IMPLICATION(trace_turbo_scheduled, trace_turbo_graph)
......
......@@ -120,10 +120,11 @@
'tools/dumpcpp': [PASS, NO_VARIANTS, ['arch == android_arm or arch == android_arm64 or arch == android_ia32', SKIP]],
##############################################################################
# This test generates a file in the test directory, so we cannot run several
# variants of the test simultaneously. Additionally the test should not be
# affected by variants.
# These tests generate files in the test directory, so we cannot run several
# variants of them simultaneously. Additionally they should not be affected by
# variants.
'd8/enable-tracing': [PASS, NO_VARIANTS],
'tools/compiler-trace-flags': [PASS, NO_VARIANTS],
##############################################################################
# Long running test that reproduces memory leak and should be run manually.
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --trace-turbo --trace-turbo-graph
// Flags: --trace-turbo-cfg-file=test/mjsunit/tools/turbo.cfg
// Flags: --trace-turbo-path=test/mjsunit/tools
load('test/mjsunit/wasm/wasm-constants.js');
load('test/mjsunit/wasm/wasm-module-builder.js');
// The idea behind this test is to make sure we do not crash when using the
// --trace-turbo flag given different sort of inputs, JS or WASM.
(function testOptimizedJS() {
function add(a, b) {
return a + b;
}
add(21, 21);
%OptimizeFunctionOnNextCall(add);
add(20, 22);
})();
(function testWASM() {
let builder = new WasmModuleBuilder();
builder.addFunction("add", kSig_i_ii)
.addBody([kExprGetLocal, 0,
kExprGetLocal, 1,
kExprI32Add])
.exportFunc();
let instance = builder.instantiate();
instance.exports.add(21, 21);
})();
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