Commit 48fd454c authored by Stephan Herhut's avatar Stephan Herhut Committed by Commit Bot

[cleanup] Resurrect the c1 visualizer output

This had bit-rotten a little and did no longer work for compiling
webassembly code. Also, correct the output of live ranges so that it
can be parsed again.

Bug: v8:8238
Change-Id: I09c2d8bd604f3be12ead8b968f0b70287fad65f1
Reviewed-on: https://chromium-review.googlesource.com/c/1256864
Commit-Queue: Stephan Herhut <herhut@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56373}
parent c4ada3de
...@@ -46,6 +46,12 @@ TurboJsonFile::TurboJsonFile(OptimizedCompilationInfo* info, ...@@ -46,6 +46,12 @@ TurboJsonFile::TurboJsonFile(OptimizedCompilationInfo* info,
TurboJsonFile::~TurboJsonFile() { flush(); } TurboJsonFile::~TurboJsonFile() { flush(); }
TurboCfgFile::TurboCfgFile(Isolate* isolate)
: std::ofstream(Isolate::GetTurboCfgFileName(isolate).c_str(),
std::ios_base::app) {}
TurboCfgFile::~TurboCfgFile() { flush(); }
std::ostream& operator<<(std::ostream& out, std::ostream& operator<<(std::ostream& out,
const SourcePositionAsJSON& asJSON) { const SourcePositionAsJSON& asJSON) {
asJSON.sp.PrintJson(out); asJSON.sp.PrintJson(out);
...@@ -768,7 +774,12 @@ void GraphC1Visualizer::PrintLiveRange(const LiveRange* range, const char* type, ...@@ -768,7 +774,12 @@ void GraphC1Visualizer::PrintLiveRange(const LiveRange* range, const char* type,
} }
} }
os_ << " " << vreg; // The toplevel range is always suffixed with :0. Use that as parent.
os_ << " " << vreg << ":0";
// TODO(herhut) Find something useful to print for the hint field
os_ << " unknown";
for (const UseInterval* interval = range->first_interval(); for (const UseInterval* interval = range->first_interval();
interval != nullptr; interval = interval->next()) { interval != nullptr; interval = interval->next()) {
os_ << " [" << interval->start().value() << ", " os_ << " [" << interval->start().value() << ", "
......
...@@ -34,6 +34,11 @@ struct TurboJsonFile : public std::ofstream { ...@@ -34,6 +34,11 @@ struct TurboJsonFile : public std::ofstream {
~TurboJsonFile() override; ~TurboJsonFile() override;
}; };
struct TurboCfgFile : public std::ofstream {
explicit TurboCfgFile(Isolate* isolate = nullptr);
~TurboCfgFile() override;
};
struct SourcePositionAsJSON { struct SourcePositionAsJSON {
explicit SourcePositionAsJSON(const SourcePosition& sp) : sp(sp) {} explicit SourcePositionAsJSON(const SourcePosition& sp) : sp(sp) {}
const SourcePosition& sp; const SourcePosition& sp;
......
...@@ -147,8 +147,7 @@ class PipelineData { ...@@ -147,8 +147,7 @@ class PipelineData {
OptimizedCompilationInfo* info, MachineGraph* mcgraph, OptimizedCompilationInfo* info, MachineGraph* mcgraph,
PipelineStatistics* pipeline_statistics, PipelineStatistics* pipeline_statistics,
SourcePositionTable* source_positions, SourcePositionTable* source_positions,
NodeOriginTable* node_origins, NodeOriginTable* node_origins, int wasm_function_index,
int wasm_function_index,
const AssemblerOptions& assembler_options) const AssemblerOptions& assembler_options)
: isolate_(nullptr), : isolate_(nullptr),
wasm_engine_(wasm_engine), wasm_engine_(wasm_engine),
...@@ -156,6 +155,7 @@ class PipelineData { ...@@ -156,6 +155,7 @@ class PipelineData {
info_(info), info_(info),
debug_name_(info_->GetDebugName()), debug_name_(info_->GetDebugName()),
wasm_function_index_(wasm_function_index), wasm_function_index_(wasm_function_index),
may_have_unverifiable_graph_(false),
zone_stats_(zone_stats), zone_stats_(zone_stats),
pipeline_statistics_(pipeline_statistics), pipeline_statistics_(pipeline_statistics),
graph_zone_scope_(zone_stats_, ZONE_NAME), graph_zone_scope_(zone_stats_, ZONE_NAME),
...@@ -679,12 +679,6 @@ void PrintCode(Isolate* isolate, Handle<Code> code, ...@@ -679,12 +679,6 @@ void PrintCode(Isolate* isolate, Handle<Code> code,
#endif // ENABLE_DISASSEMBLER #endif // ENABLE_DISASSEMBLER
} }
struct TurboCfgFile : public std::ofstream {
explicit TurboCfgFile(Isolate* isolate)
: std::ofstream(isolate->GetTurboCfgFileName().c_str(),
std::ios_base::app) {}
};
void TraceSchedule(OptimizedCompilationInfo* info, PipelineData* data, void TraceSchedule(OptimizedCompilationInfo* info, PipelineData* data,
Schedule* schedule, const char* phase_name) { Schedule* schedule, const char* phase_name) {
if (info->trace_turbo_json_enabled()) { if (info->trace_turbo_json_enabled()) {
......
...@@ -5221,6 +5221,11 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation( ...@@ -5221,6 +5221,11 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation(
info.SetWasmRuntimeExceptionSupport(); info.SetWasmRuntimeExceptionSupport();
} }
if (info.trace_turbo_json_enabled()) {
TurboCfgFile tcf;
tcf << AsC1VCompilation(&info);
}
NodeOriginTable* node_origins = info.trace_turbo_json_enabled() NodeOriginTable* node_origins = info.trace_turbo_json_enabled()
? new (&graph_zone) ? new (&graph_zone)
NodeOriginTable(mcgraph->graph()) NodeOriginTable(mcgraph->graph())
......
...@@ -3428,6 +3428,12 @@ int Shell::Main(int argc, char* argv[]) { ...@@ -3428,6 +3428,12 @@ int Shell::Main(int argc, char* argv[]) {
g_platform.reset(new PredictablePlatform(std::move(g_platform))); g_platform.reset(new PredictablePlatform(std::move(g_platform)));
} }
if (i::FLAG_trace_turbo_cfg_file == nullptr) {
SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg");
}
if (i::FLAG_redirect_code_traces_to == nullptr) {
SetFlagsFromString("--redirect-code-traces-to=code.asm");
}
v8::V8::InitializePlatform(g_platform.get()); v8::V8::InitializePlatform(g_platform.get());
v8::V8::Initialize(); v8::V8::Initialize();
if (options.natives_blob || options.snapshot_blob) { if (options.natives_blob || options.snapshot_blob) {
...@@ -3436,12 +3442,6 @@ int Shell::Main(int argc, char* argv[]) { ...@@ -3436,12 +3442,6 @@ int Shell::Main(int argc, char* argv[]) {
} else { } else {
v8::V8::InitializeExternalStartupData(argv[0]); v8::V8::InitializeExternalStartupData(argv[0]);
} }
if (i::FLAG_trace_turbo_cfg_file == nullptr) {
SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg");
}
if (i::FLAG_redirect_code_traces_to == nullptr) {
SetFlagsFromString("--redirect-code-traces-to=code.asm");
}
int result = 0; int result = 0;
Isolate::CreateParams create_params; Isolate::CreateParams create_params;
ShellArrayBufferAllocator shell_array_buffer_allocator; ShellArrayBufferAllocator shell_array_buffer_allocator;
......
...@@ -3220,7 +3220,7 @@ bool Isolate::Init(StartupDeserializer* des) { ...@@ -3220,7 +3220,7 @@ bool Isolate::Init(StartupDeserializer* des) {
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
// Create an empty file. // Create an empty file.
std::ofstream(GetTurboCfgFileName().c_str(), std::ios_base::trunc); std::ofstream(GetTurboCfgFileName(this).c_str(), std::ios_base::trunc);
} }
CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, embedder_data_)), CHECK_EQ(static_cast<int>(OFFSET_OF(Isolate, embedder_data_)),
...@@ -4184,10 +4184,17 @@ void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) { ...@@ -4184,10 +4184,17 @@ void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) {
} }
} }
std::string Isolate::GetTurboCfgFileName() { // static
std::string Isolate::GetTurboCfgFileName(Isolate* isolate) {
if (FLAG_trace_turbo_cfg_file == nullptr) { if (FLAG_trace_turbo_cfg_file == nullptr) {
std::ostringstream os; std::ostringstream os;
os << "turbo-" << base::OS::GetCurrentProcessId() << "-" << id() << ".cfg"; os << "turbo-" << base::OS::GetCurrentProcessId() << "-";
if (isolate != nullptr) {
os << isolate->id();
} else {
os << "any";
}
os << ".cfg";
return os.str(); return os.str();
} else { } else {
return FLAG_trace_turbo_cfg_file; return FLAG_trace_turbo_cfg_file;
......
...@@ -1386,7 +1386,7 @@ class Isolate : private HiddenFactory { ...@@ -1386,7 +1386,7 @@ class Isolate : private HiddenFactory {
void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback); void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback);
void CountUsage(v8::Isolate::UseCounterFeature feature); void CountUsage(v8::Isolate::UseCounterFeature feature);
std::string GetTurboCfgFileName(); static std::string GetTurboCfgFileName(Isolate* isolate);
#if V8_SFI_HAS_UNIQUE_ID #if V8_SFI_HAS_UNIQUE_ID
int GetNextUniqueSharedFunctionInfoId() { return next_unique_sfi_id_++; } int GetNextUniqueSharedFunctionInfoId() { return next_unique_sfi_id_++; }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "src/v8.h" #include "src/v8.h"
#include <fstream>
#include "src/api.h" #include "src/api.h"
#include "src/base/atomicops.h" #include "src/base/atomicops.h"
#include "src/base/once.h" #include "src/base/once.h"
...@@ -72,6 +74,12 @@ void V8::InitializeOncePerProcessImpl() { ...@@ -72,6 +74,12 @@ void V8::InitializeOncePerProcessImpl() {
FLAG_max_semi_space_size = 1; FLAG_max_semi_space_size = 1;
} }
if (FLAG_trace_turbo) {
// Create an empty file shared by the process (e.g. the wasm engine).
std::ofstream(Isolate::GetTurboCfgFileName(nullptr).c_str(),
std::ios_base::trunc);
}
base::OS::Initialize(FLAG_hard_abort, FLAG_gc_fake_mmap); base::OS::Initialize(FLAG_hard_abort, FLAG_gc_fake_mmap);
if (FLAG_random_seed) SetRandomMmapSeed(FLAG_random_seed); if (FLAG_random_seed) SetRandomMmapSeed(FLAG_random_seed);
......
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