Commit e0059db5 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[turbofan] Add --trace-turbo-filter

This adds a filter option for --trace-turbo, --trace-turbo-graph
and --trace-turbo-scheduled. The filter is a pattern that matches
function names in this way:
   "*"      all; the default
   "-"      all but the top-level function
   "-name"  all but the function "name"
   ""       only the top-level function
   "name"   only the function "name"
   "name*"  only functions starting with "name"
   "~"      none; the tilde is not an identifier

Bug: v8:7761
Change-Id: I7e8e726023f2c72754b0dd691d790af20b022fd3
Reviewed-on: https://chromium-review.googlesource.com/1059774Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53201}
parent 42027031
...@@ -709,7 +709,9 @@ void CodeGenerator::AssembleSourcePosition(SourcePosition source_position) { ...@@ -709,7 +709,9 @@ void CodeGenerator::AssembleSourcePosition(SourcePosition source_position) {
if (info->IsStub()) return; if (info->IsStub()) return;
std::ostringstream buffer; std::ostringstream buffer;
buffer << "-- "; buffer << "-- ";
if (FLAG_trace_turbo || FLAG_trace_turbo_graph || // Turbolizer only needs the source position, as it can reconstruct
// the inlining stack from other information.
if (info->trace_turbo_json_enabled() ||
tasm()->isolate()->concurrent_recompilation_enabled()) { tasm()->isolate()->concurrent_recompilation_enabled()) {
buffer << source_position; buffer << source_position;
} else { } else {
......
...@@ -631,7 +631,7 @@ struct TurboJsonFile : public std::ofstream { ...@@ -631,7 +631,7 @@ struct TurboJsonFile : public std::ofstream {
void TraceSchedule(OptimizedCompilationInfo* info, Isolate* isolate, void TraceSchedule(OptimizedCompilationInfo* info, Isolate* isolate,
Schedule* schedule) { Schedule* schedule) {
if (FLAG_trace_turbo) { if (info->trace_turbo_json_enabled()) {
AllowHandleDereference allow_deref; AllowHandleDereference allow_deref;
TurboJsonFile json_of(info, std::ios_base::app); TurboJsonFile json_of(info, std::ios_base::app);
json_of << "{\"name\":\"Schedule\",\"type\":\"schedule\",\"data\":\""; json_of << "{\"name\":\"Schedule\",\"type\":\"schedule\",\"data\":\"";
...@@ -643,7 +643,7 @@ void TraceSchedule(OptimizedCompilationInfo* info, Isolate* isolate, ...@@ -643,7 +643,7 @@ void TraceSchedule(OptimizedCompilationInfo* info, Isolate* isolate,
} }
json_of << "\"},\n"; json_of << "\"},\n";
} }
if (FLAG_trace_turbo_graph || FLAG_trace_turbo_scheduler) { if (info->trace_turbo_graph_enabled() || FLAG_trace_turbo_scheduler) {
AllowHandleDereference allow_deref; AllowHandleDereference allow_deref;
CodeTracer::Scope tracing_scope(isolate->GetCodeTracer()); CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
OFStream os(tracing_scope.file()); OFStream os(tracing_scope.file());
...@@ -713,7 +713,7 @@ PipelineStatistics* CreatePipelineStatistics(Handle<Script> script, ...@@ -713,7 +713,7 @@ PipelineStatistics* CreatePipelineStatistics(Handle<Script> script,
pipeline_statistics->BeginPhaseKind("initializing"); pipeline_statistics->BeginPhaseKind("initializing");
} }
if (FLAG_trace_turbo) { if (info->trace_turbo_json_enabled()) {
TurboJsonFile json_of(info, std::ios_base::trunc); TurboJsonFile json_of(info, std::ios_base::trunc);
std::unique_ptr<char[]> function_name = info->GetDebugName(); std::unique_ptr<char[]> function_name = info->GetDebugName();
int pos = int pos =
...@@ -934,7 +934,7 @@ PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::PrepareJobImpl( ...@@ -934,7 +934,7 @@ PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::PrepareJobImpl(
PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::Status
PipelineWasmCompilationJob::ExecuteJobImpl() { PipelineWasmCompilationJob::ExecuteJobImpl() {
if (FLAG_trace_turbo) { if (compilation_info()->trace_turbo_json_enabled()) {
TurboJsonFile json_of(compilation_info(), std::ios_base::trunc); TurboJsonFile json_of(compilation_info(), std::ios_base::trunc);
json_of << "{\"function\":\"" << compilation_info()->GetDebugName().get() json_of << "{\"function\":\"" << compilation_info()->GetDebugName().get()
<< "\", \"source\":\"\",\n\"phases\":["; << "\", \"source\":\"\",\n\"phases\":[";
...@@ -1753,14 +1753,14 @@ struct PrintGraphPhase { ...@@ -1753,14 +1753,14 @@ struct PrintGraphPhase {
OptimizedCompilationInfo* info = data->info(); OptimizedCompilationInfo* info = data->info();
Graph* graph = data->graph(); Graph* graph = data->graph();
if (FLAG_trace_turbo) { // Print JSON. if (info->trace_turbo_json_enabled()) { // Print JSON.
AllowHandleDereference allow_deref; AllowHandleDereference allow_deref;
TurboJsonFile json_of(info, std::ios_base::app); TurboJsonFile json_of(info, std::ios_base::app);
json_of << "{\"name\":\"" << phase << "\",\"type\":\"graph\",\"data\":" json_of << "{\"name\":\"" << phase << "\",\"type\":\"graph\",\"data\":"
<< AsJSON(*graph, data->source_positions()) << "},\n"; << AsJSON(*graph, data->source_positions()) << "},\n";
} }
if (FLAG_trace_turbo_scheduled) { // Scheduled textual output. if (info->trace_turbo_scheduled_enabled()) {
AccountingAllocator allocator; AccountingAllocator allocator;
Schedule* schedule = data->schedule(); Schedule* schedule = data->schedule();
if (schedule == nullptr) { if (schedule == nullptr) {
...@@ -1773,7 +1773,7 @@ struct PrintGraphPhase { ...@@ -1773,7 +1773,7 @@ struct PrintGraphPhase {
OFStream os(tracing_scope.file()); OFStream os(tracing_scope.file());
os << "-- Graph after " << phase << " -- " << std::endl; os << "-- Graph after " << phase << " -- " << std::endl;
os << AsScheduledGraph(schedule); os << AsScheduledGraph(schedule);
} else if (FLAG_trace_turbo_graph) { // Simple textual RPO. } else if (info->trace_turbo_graph_enabled()) { // Simple textual RPO.
AllowHandleDereference allow_deref; AllowHandleDereference allow_deref;
CodeTracer::Scope tracing_scope(data->isolate()->GetCodeTracer()); CodeTracer::Scope tracing_scope(data->isolate()->GetCodeTracer());
OFStream os(tracing_scope.file()); OFStream os(tracing_scope.file());
...@@ -1808,7 +1808,8 @@ struct VerifyGraphPhase { ...@@ -1808,7 +1808,8 @@ struct VerifyGraphPhase {
}; };
void PipelineImpl::RunPrintAndVerify(const char* phase, bool untyped) { void PipelineImpl::RunPrintAndVerify(const char* phase, bool untyped) {
if (FLAG_trace_turbo || FLAG_trace_turbo_graph) { if (info()->trace_turbo_json_enabled() ||
info()->trace_turbo_graph_enabled()) {
Run<PrintGraphPhase>(phase); Run<PrintGraphPhase>(phase);
} }
if (FLAG_turbo_verify) { if (FLAG_turbo_verify) {
...@@ -1821,14 +1822,15 @@ bool PipelineImpl::CreateGraph() { ...@@ -1821,14 +1822,15 @@ bool PipelineImpl::CreateGraph() {
data->BeginPhaseKind("graph creation"); data->BeginPhaseKind("graph creation");
if (FLAG_trace_turbo || FLAG_trace_turbo_graph) { if (info()->trace_turbo_json_enabled() ||
info()->trace_turbo_graph_enabled()) {
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
OFStream os(tracing_scope.file()); OFStream os(tracing_scope.file());
os << "---------------------------------------------------\n" os << "---------------------------------------------------\n"
<< "Begin compiling method " << info()->GetDebugName().get() << "Begin compiling method " << info()->GetDebugName().get()
<< " using Turbofan" << std::endl; << " using Turbofan" << std::endl;
} }
if (FLAG_trace_turbo) { if (info()->trace_turbo_json_enabled()) {
TurboCfgFile tcf(isolate()); TurboCfgFile tcf(isolate());
tcf << AsC1VCompilation(info()); tcf << AsC1VCompilation(info());
} }
...@@ -1998,12 +2000,12 @@ Handle<Code> Pipeline::GenerateCodeForCodeStub( ...@@ -1998,12 +2000,12 @@ Handle<Code> Pipeline::GenerateCodeForCodeStub(
PipelineImpl pipeline(&data); PipelineImpl pipeline(&data);
DCHECK_NOT_NULL(data.schedule()); DCHECK_NOT_NULL(data.schedule());
if (FLAG_trace_turbo || FLAG_trace_turbo_graph) { if (info.trace_turbo_json_enabled() || info.trace_turbo_graph_enabled()) {
CodeTracer::Scope tracing_scope(isolate->GetCodeTracer()); CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
OFStream os(tracing_scope.file()); OFStream os(tracing_scope.file());
os << "---------------------------------------------------\n" os << "---------------------------------------------------\n"
<< "Begin compiling " << debug_name << " using Turbofan" << std::endl; << "Begin compiling " << debug_name << " using Turbofan" << std::endl;
if (FLAG_trace_turbo) { if (info.trace_turbo_json_enabled()) {
TurboJsonFile json_of(&info, std::ios_base::trunc); TurboJsonFile json_of(&info, std::ios_base::trunc);
json_of << "{\"function\":\"" << info.GetDebugName().get() json_of << "{\"function\":\"" << info.GetDebugName().get()
<< "\", \"source\":\"\",\n\"phases\":["; << "\", \"source\":\"\",\n\"phases\":[";
...@@ -2067,7 +2069,7 @@ Handle<Code> Pipeline::GenerateCodeForTesting( ...@@ -2067,7 +2069,7 @@ Handle<Code> Pipeline::GenerateCodeForTesting(
PipelineImpl pipeline(&data); PipelineImpl pipeline(&data);
if (FLAG_trace_turbo) { if (info->trace_turbo_json_enabled()) {
TurboJsonFile json_of(info, std::ios_base::trunc); TurboJsonFile json_of(info, std::ios_base::trunc);
json_of << "{\"function\":\"" << info->GetDebugName().get() json_of << "{\"function\":\"" << info->GetDebugName().get()
<< "\", \"source\":\"\",\n\"phases\":["; << "\", \"source\":\"\",\n\"phases\":[";
...@@ -2182,14 +2184,14 @@ bool PipelineImpl::SelectInstructions(Linkage* linkage) { ...@@ -2182,14 +2184,14 @@ bool PipelineImpl::SelectInstructions(Linkage* linkage) {
return false; return false;
} }
if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { if (info()->trace_turbo_json_enabled() && !data->MayHaveUnverifiableGraph()) {
AllowHandleDereference allow_deref; AllowHandleDereference allow_deref;
TurboCfgFile tcf(isolate()); TurboCfgFile tcf(isolate());
tcf << AsC1V("CodeGen", data->schedule(), data->source_positions(), tcf << AsC1V("CodeGen", data->schedule(), data->source_positions(),
data->sequence()); data->sequence());
} }
if (FLAG_trace_turbo) { if (info()->trace_turbo_json_enabled()) {
std::ostringstream source_position_output; std::ostringstream source_position_output;
// Output source position information before the graph is deleted. // Output source position information before the graph is deleted.
data_->source_positions()->Print(source_position_output); data_->source_positions()->Print(source_position_output);
...@@ -2265,7 +2267,7 @@ Handle<Code> PipelineImpl::FinalizeCode() { ...@@ -2265,7 +2267,7 @@ Handle<Code> PipelineImpl::FinalizeCode() {
info()->SetCode(code); info()->SetCode(code);
PrintCode(code, info()); PrintCode(code, info());
if (FLAG_trace_turbo) { if (info()->trace_turbo_json_enabled()) {
TurboJsonFile json_of(info(), std::ios_base::app); TurboJsonFile json_of(info(), std::ios_base::app);
json_of << "{\"name\":\"disassembly\",\"type\":\"disassembly\",\"data\":\""; json_of << "{\"name\":\"disassembly\",\"type\":\"disassembly\",\"data\":\"";
#if ENABLE_DISASSEMBLER #if ENABLE_DISASSEMBLER
...@@ -2281,7 +2283,8 @@ Handle<Code> PipelineImpl::FinalizeCode() { ...@@ -2281,7 +2283,8 @@ Handle<Code> PipelineImpl::FinalizeCode() {
json_of << data->source_position_output(); json_of << data->source_position_output();
json_of << "}"; json_of << "}";
} }
if (FLAG_trace_turbo || FLAG_trace_turbo_graph) { if (info()->trace_turbo_json_enabled() ||
info()->trace_turbo_graph_enabled()) {
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
OFStream os(tracing_scope.file()); OFStream os(tracing_scope.file());
os << "---------------------------------------------------\n" os << "---------------------------------------------------\n"
...@@ -2327,7 +2330,7 @@ void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config, ...@@ -2327,7 +2330,7 @@ void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config,
Run<MeetRegisterConstraintsPhase>(); Run<MeetRegisterConstraintsPhase>();
Run<ResolvePhisPhase>(); Run<ResolvePhisPhase>();
Run<BuildLiveRangesPhase>(); Run<BuildLiveRangesPhase>();
if (FLAG_trace_turbo_graph) { if (info()->trace_turbo_graph_enabled()) {
AllowHandleDereference allow_deref; AllowHandleDereference allow_deref;
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
OFStream os(tracing_scope.file()); OFStream os(tracing_scope.file());
...@@ -2371,7 +2374,7 @@ void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config, ...@@ -2371,7 +2374,7 @@ void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config,
Run<LocateSpillSlotsPhase>(); Run<LocateSpillSlotsPhase>();
if (FLAG_trace_turbo_graph) { if (info()->trace_turbo_graph_enabled()) {
AllowHandleDereference allow_deref; AllowHandleDereference allow_deref;
CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
OFStream os(tracing_scope.file()); OFStream os(tracing_scope.file());
...@@ -2384,8 +2387,8 @@ void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config, ...@@ -2384,8 +2387,8 @@ void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config,
verifier->VerifyGapMoves(); verifier->VerifyGapMoves();
} }
if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { if (info()->trace_turbo_json_enabled() && !data->MayHaveUnverifiableGraph()) {
TurboCfgFile tcf(data->isolate()); TurboCfgFile tcf(isolate());
tcf << AsC1VRegisterAllocationData("CodeGen", tcf << AsC1VRegisterAllocationData("CodeGen",
data->register_allocation_data()); data->register_allocation_data());
} }
......
...@@ -4717,7 +4717,17 @@ Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::WasmModule* module, ...@@ -4717,7 +4717,17 @@ Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::WasmModule* module,
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Run the compilation pipeline. // Run the compilation pipeline.
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
if (FLAG_trace_turbo_graph) { // Simple textual RPO. #ifdef DEBUG
EmbeddedVector<char, 32> func_name;
static unsigned id = 0;
func_name.Truncate(SNPrintF(func_name, "js-to-wasm#%d", id++));
#else
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.
OFStream os(stdout); OFStream os(stdout);
os << "-- Graph after change lowering -- " << std::endl; os << "-- Graph after change lowering -- " << std::endl;
os << AsRPO(graph); os << AsRPO(graph);
...@@ -4729,15 +4739,6 @@ Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::WasmModule* module, ...@@ -4729,15 +4739,6 @@ Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::WasmModule* module,
CallDescriptor* incoming = Linkage::GetJSCallDescriptor( CallDescriptor* incoming = Linkage::GetJSCallDescriptor(
&zone, false, params + 1, CallDescriptor::kNoFlags); &zone, false, params + 1, CallDescriptor::kNoFlags);
#ifdef DEBUG
EmbeddedVector<char, 32> func_name;
static unsigned id = 0;
func_name.Truncate(SNPrintF(func_name, "js-to-wasm#%d", id++));
#else
Vector<const char> func_name = CStrVector("js-to-wasm");
#endif
OptimizedCompilationInfo info(func_name, &zone, Code::JS_TO_WASM_FUNCTION);
Handle<Code> code = Handle<Code> code =
Pipeline::GenerateCodeForTesting(&info, isolate, incoming, &graph); Pipeline::GenerateCodeForTesting(&info, isolate, incoming, &graph);
#ifdef ENABLE_DISASSEMBLER #ifdef ENABLE_DISASSEMBLER
...@@ -4820,7 +4821,17 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, ...@@ -4820,7 +4821,17 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target,
builder.set_effect_ptr(&effect); builder.set_effect_ptr(&effect);
builder.BuildWasmToJSWrapper(target, index); builder.BuildWasmToJSWrapper(target, index);
if (FLAG_trace_turbo_graph) { // Simple textual RPO. #ifdef DEBUG
EmbeddedVector<char, 32> func_name;
static unsigned id = 0;
func_name.Truncate(SNPrintF(func_name, "wasm-to-js#%d", id++));
#else
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.
OFStream os(stdout); OFStream os(stdout);
os << "-- Graph after change lowering -- " << std::endl; os << "-- Graph after change lowering -- " << std::endl;
os << AsRPO(graph); os << AsRPO(graph);
...@@ -4832,15 +4843,6 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, ...@@ -4832,15 +4843,6 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target,
incoming = GetI32WasmCallDescriptor(&zone, incoming); incoming = GetI32WasmCallDescriptor(&zone, incoming);
} }
#ifdef DEBUG
EmbeddedVector<char, 32> func_name;
static unsigned id = 0;
func_name.Truncate(SNPrintF(func_name, "wasm-to-js#%d", id++));
#else
Vector<const char> func_name = CStrVector("wasm-to-js");
#endif
OptimizedCompilationInfo info(func_name, &zone, Code::WASM_TO_JS_FUNCTION);
Handle<Code> code = Pipeline::GenerateCodeForTesting( Handle<Code> code = Pipeline::GenerateCodeForTesting(
&info, isolate, incoming, &graph, nullptr, source_position_table); &info, isolate, incoming, &graph, nullptr, source_position_table);
ValidateImportWrapperReferencesImmovables(code); ValidateImportWrapperReferencesImmovables(code);
...@@ -4885,12 +4887,6 @@ Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index, ...@@ -4885,12 +4887,6 @@ Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index,
Handle<Code> code = Handle<Code>::null(); Handle<Code> code = Handle<Code>::null();
{ {
if (FLAG_trace_turbo_graph) { // Simple textual RPO.
OFStream os(stdout);
os << "-- Wasm interpreter entry graph -- " << std::endl;
os << AsRPO(graph);
}
// Schedule and compile to machine code. // Schedule and compile to machine code.
CallDescriptor* incoming = GetWasmCallDescriptor(&zone, sig); CallDescriptor* incoming = GetWasmCallDescriptor(&zone, sig);
if (machine.Is32()) { if (machine.Is32()) {
...@@ -4906,6 +4902,13 @@ Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index, ...@@ -4906,6 +4902,13 @@ Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index,
OptimizedCompilationInfo info(func_name, &zone, OptimizedCompilationInfo info(func_name, &zone,
Code::WASM_INTERPRETER_ENTRY); Code::WASM_INTERPRETER_ENTRY);
if (info.trace_turbo_graph_enabled()) { // Simple textual RPO.
OFStream os(stdout);
os << "-- Wasm interpreter entry graph -- " << std::endl;
os << AsRPO(graph);
}
code = Pipeline::GenerateCodeForTesting(&info, isolate, incoming, &graph, code = Pipeline::GenerateCodeForTesting(&info, isolate, incoming, &graph,
nullptr); nullptr);
#ifdef ENABLE_DISASSEMBLER #ifdef ENABLE_DISASSEMBLER
...@@ -4943,12 +4946,6 @@ Handle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) { ...@@ -4943,12 +4946,6 @@ Handle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) {
builder.set_effect_ptr(&effect); builder.set_effect_ptr(&effect);
builder.BuildCWasmEntry(); builder.BuildCWasmEntry();
if (FLAG_trace_turbo_graph) { // Simple textual RPO.
OFStream os(stdout);
os << "-- C Wasm entry graph -- " << std::endl;
os << AsRPO(graph);
}
// Schedule and compile to machine code. // Schedule and compile to machine code.
CallDescriptor* incoming = Linkage::GetJSCallDescriptor( CallDescriptor* incoming = Linkage::GetJSCallDescriptor(
&zone, false, CWasmEntryParameters::kNumParameters + 1, &zone, false, CWasmEntryParameters::kNumParameters + 1,
...@@ -4972,6 +4969,13 @@ Handle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) { ...@@ -4972,6 +4969,13 @@ Handle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) {
Vector<const char> debug_name_vec(debug_name, name_len); Vector<const char> debug_name_vec(debug_name, name_len);
OptimizedCompilationInfo info(debug_name_vec, &zone, Code::C_WASM_ENTRY); OptimizedCompilationInfo info(debug_name_vec, &zone, Code::C_WASM_ENTRY);
if (info.trace_turbo_graph_enabled()) { // Simple textual RPO.
OFStream os(stdout);
os << "-- C Wasm entry graph -- " << std::endl;
os << AsRPO(graph);
}
Handle<Code> code = Handle<Code> code =
Pipeline::GenerateCodeForTesting(&info, isolate, incoming, &graph); Pipeline::GenerateCodeForTesting(&info, isolate, incoming, &graph);
#ifdef ENABLE_DISASSEMBLER #ifdef ENABLE_DISASSEMBLER
......
...@@ -400,6 +400,8 @@ DEFINE_STRING(turbo_filter, "*", "optimization filter for TurboFan compiler") ...@@ -400,6 +400,8 @@ DEFINE_STRING(turbo_filter, "*", "optimization filter for TurboFan compiler")
DEFINE_BOOL(trace_turbo, false, "trace generated TurboFan IR") DEFINE_BOOL(trace_turbo, false, "trace generated TurboFan IR")
DEFINE_STRING(trace_turbo_path, nullptr, DEFINE_STRING(trace_turbo_path, nullptr,
"directory to dump generated TurboFan IR to") "directory to dump generated TurboFan IR to")
DEFINE_STRING(trace_turbo_filter, "*",
"filter for tracing turbofan compilation")
DEFINE_BOOL(trace_turbo_graph, false, "trace generated TurboFan graphs") DEFINE_BOOL(trace_turbo_graph, false, "trace generated TurboFan graphs")
DEFINE_BOOL(trace_turbo_scheduled, false, "trace TurboFan IR with schedule") DEFINE_BOOL(trace_turbo_scheduled, false, "trace TurboFan IR with schedule")
DEFINE_IMPLICATION(trace_turbo_scheduled, trace_turbo_graph) DEFINE_IMPLICATION(trace_turbo_scheduled, trace_turbo_graph)
......
...@@ -13699,40 +13699,10 @@ SharedFunctionInfo::SideEffectState SharedFunctionInfo::GetSideEffectState( ...@@ -13699,40 +13699,10 @@ SharedFunctionInfo::SideEffectState SharedFunctionInfo::GetSideEffectState(
return static_cast<SideEffectState>(info->side_effect_state()); return static_cast<SideEffectState>(info->side_effect_state());
} }
// The filter is a pattern that matches function names in this way:
// "*" all; the default
// "-" all but the top-level function
// "-name" all but the function "name"
// "" only the top-level function
// "name" only the function "name"
// "name*" only functions starting with "name"
// "~" none; the tilde is not an identifier
bool SharedFunctionInfo::PassesFilter(const char* raw_filter) { bool SharedFunctionInfo::PassesFilter(const char* raw_filter) {
if (*raw_filter == '*') return true;
String* name = DebugName();
Vector<const char> filter = CStrVector(raw_filter); Vector<const char> filter = CStrVector(raw_filter);
if (filter.length() == 0) return name->length() == 0; std::unique_ptr<char[]> cstrname(DebugName()->ToCString());
if (filter[0] == '-') { return v8::internal::PassesFilter(CStrVector(cstrname.get()), filter);
// Negative filter.
if (filter.length() == 1) {
return (name->length() != 0);
} else if (name->IsUtf8EqualTo(filter.SubVector(1, filter.length()))) {
return false;
}
if (filter[filter.length() - 1] == '*' &&
name->IsUtf8EqualTo(filter.SubVector(1, filter.length() - 1), true)) {
return false;
}
return true;
} else if (name->IsUtf8EqualTo(filter)) {
return true;
}
if (filter[filter.length() - 1] == '*' &&
name->IsUtf8EqualTo(filter.SubVector(0, filter.length() - 1), true)) {
return true;
}
return false;
} }
bool SharedFunctionInfo::HasSourceCode() const { bool SharedFunctionInfo::HasSourceCode() const {
......
...@@ -42,6 +42,8 @@ OptimizedCompilationInfo::OptimizedCompilationInfo( ...@@ -42,6 +42,8 @@ OptimizedCompilationInfo::OptimizedCompilationInfo(
if (isolate->NeedsSourcePositionsForProfiling()) { if (isolate->NeedsSourcePositionsForProfiling()) {
MarkAsSourcePositionsEnabled(); MarkAsSourcePositionsEnabled();
} }
SetTracingFlags(shared->PassesFilter(FLAG_trace_turbo_filter));
} }
OptimizedCompilationInfo::OptimizedCompilationInfo( OptimizedCompilationInfo::OptimizedCompilationInfo(
...@@ -58,6 +60,8 @@ OptimizedCompilationInfo::OptimizedCompilationInfo( ...@@ -58,6 +60,8 @@ OptimizedCompilationInfo::OptimizedCompilationInfo(
} }
#endif #endif
#endif #endif
SetTracingFlags(
PassesFilter(debug_name, CStrVector(FLAG_trace_turbo_filter)));
} }
OptimizedCompilationInfo::OptimizedCompilationInfo( OptimizedCompilationInfo::OptimizedCompilationInfo(
...@@ -167,5 +171,12 @@ int OptimizedCompilationInfo::AddInlinedFunction( ...@@ -167,5 +171,12 @@ int OptimizedCompilationInfo::AddInlinedFunction(
return id; return id;
} }
void OptimizedCompilationInfo::SetTracingFlags(bool passes_filter) {
if (!passes_filter) return;
if (FLAG_trace_turbo) SetFlag(kTraceTurboJson);
if (FLAG_trace_turbo_graph) SetFlag(kTraceTurboGraph);
if (FLAG_trace_turbo_scheduled) SetFlag(kTraceTurboScheduled);
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -52,6 +52,9 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final { ...@@ -52,6 +52,9 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
kPoisonRegisterArguments = 1 << 11, kPoisonRegisterArguments = 1 << 11,
kAllocationFoldingEnabled = 1 << 12, kAllocationFoldingEnabled = 1 << 12,
kAnalyzeEnvironmentLiveness = 1 << 13, kAnalyzeEnvironmentLiveness = 1 << 13,
kTraceTurboJson = 1 << 14,
kTraceTurboGraph = 1 << 15,
kTraceTurboScheduled = 1 << 16,
}; };
// TODO(mtrofin): investigate if this might be generalized outside wasm, with // TODO(mtrofin): investigate if this might be generalized outside wasm, with
...@@ -170,6 +173,14 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final { ...@@ -170,6 +173,14 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
return GetFlag(kAnalyzeEnvironmentLiveness); return GetFlag(kAnalyzeEnvironmentLiveness);
} }
bool trace_turbo_json_enabled() const { return GetFlag(kTraceTurboJson); }
bool trace_turbo_graph_enabled() const { return GetFlag(kTraceTurboGraph); }
bool trace_turbo_scheduled_enabled() const {
return GetFlag(kTraceTurboScheduled);
}
// Code getters and setters. // Code getters and setters.
void SetCode(Handle<Code> code) { code_ = code; } void SetCode(Handle<Code> code) { code_ = code; }
...@@ -267,6 +278,8 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final { ...@@ -267,6 +278,8 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
void SetFlag(Flag flag) { flags_ |= flag; } void SetFlag(Flag flag) { flags_ |= flag; }
bool GetFlag(Flag flag) const { return (flags_ & flag) != 0; } bool GetFlag(Flag flag) const { return (flags_ & flag) != 0; }
void SetTracingFlags(bool passes_filter);
// Compilation flags. // Compilation flags.
unsigned flags_; unsigned flags_;
PoisoningMitigationLevel poisoning_level_ = PoisoningMitigationLevel poisoning_level_ =
......
...@@ -442,6 +442,53 @@ bool DoubleToBoolean(double d) { ...@@ -442,6 +442,53 @@ bool DoubleToBoolean(double d) {
return true; return true;
} }
// The filter is a pattern that matches function names in this way:
// "*" all; the default
// "-" all but the top-level function
// "-name" all but the function "name"
// "" only the top-level function
// "name" only the function "name"
// "name*" only functions starting with "name"
// "~" none; the tilde is not an identifier
bool PassesFilter(Vector<const char> name, Vector<const char> filter) {
if (filter.size() == 0) return name.size() == 0;
auto filter_it = filter.begin();
bool positive_filter = true;
if (*filter_it == '-') {
++filter_it;
positive_filter = false;
}
if (filter_it == filter.end()) return name.size() != 0;
if (*filter_it == '*') return positive_filter;
if (*filter_it == '~') return !positive_filter;
bool prefix_match = filter[filter.size() - 1] == '*';
size_t min_match_length = filter.size();
if (!positive_filter) min_match_length--; // Subtract 1 for leading '-'.
if (prefix_match) min_match_length--; // Subtract 1 for trailing '*'.
if (name.size() < min_match_length) return !positive_filter;
// TODO(sigurds): Use the new version of std::mismatch here, once we
// can assume C++14.
auto res = std::mismatch(filter_it, filter.end(), name.begin());
if (res.first == filter.end()) {
if (res.second == name.end()) {
// The strings match, so {name} passes if we have a {positive_filter}.
return positive_filter;
}
// {name} is longer than the filter, so {name} passes if we don't have a
// {positive_filter}.
return !positive_filter;
}
if (*res.first == '*') {
// We matched up to the wildcard, so {name} passes if we have a
// {positive_filter}.
return positive_filter;
}
// We don't match, so {name} passes if we don't have a {positive_filter}.
return !positive_filter;
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -1818,6 +1818,9 @@ class ThreadedListZoneEntry final : public ZoneObject { ...@@ -1818,6 +1818,9 @@ class ThreadedListZoneEntry final : public ZoneObject {
DISALLOW_COPY_AND_ASSIGN(ThreadedListZoneEntry); DISALLOW_COPY_AND_ASSIGN(ThreadedListZoneEntry);
}; };
V8_EXPORT_PRIVATE bool PassesFilter(Vector<const char> name,
Vector<const char> filter);
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -109,5 +109,28 @@ TYPED_TEST(UtilsTest, SaturateAdd) { ...@@ -109,5 +109,28 @@ TYPED_TEST(UtilsTest, SaturateAdd) {
} }
} }
TYPED_TEST(UtilsTest, PassesFilterTest) {
EXPECT_TRUE(PassesFilter(CStrVector("abcdefg"), CStrVector("abcdefg")));
EXPECT_TRUE(PassesFilter(CStrVector("abcdefg"), CStrVector("abcdefg*")));
EXPECT_TRUE(PassesFilter(CStrVector("abcdefg"), CStrVector("abc*")));
EXPECT_TRUE(PassesFilter(CStrVector("abcdefg"), CStrVector("*")));
EXPECT_TRUE(PassesFilter(CStrVector("abcdefg"), CStrVector("-~")));
EXPECT_TRUE(PassesFilter(CStrVector("abcdefg"), CStrVector("-abcdefgh")));
EXPECT_TRUE(PassesFilter(CStrVector("abdefg"), CStrVector("-")));
EXPECT_FALSE(PassesFilter(CStrVector("abcdefg"), CStrVector("-abcdefg")));
EXPECT_FALSE(PassesFilter(CStrVector("abcdefg"), CStrVector("-abcdefg*")));
EXPECT_FALSE(PassesFilter(CStrVector("abcdefg"), CStrVector("-abc*")));
EXPECT_FALSE(PassesFilter(CStrVector("abcdefg"), CStrVector("-*")));
EXPECT_FALSE(PassesFilter(CStrVector("abcdefg"), CStrVector("~")));
EXPECT_FALSE(PassesFilter(CStrVector("abcdefg"), CStrVector("")));
EXPECT_FALSE(PassesFilter(CStrVector("abcdefg"), CStrVector("abcdefgh")));
EXPECT_TRUE(PassesFilter(CStrVector(""), CStrVector("")));
EXPECT_TRUE(PassesFilter(CStrVector(""), CStrVector("*")));
EXPECT_FALSE(PassesFilter(CStrVector(""), CStrVector("-")));
EXPECT_FALSE(PassesFilter(CStrVector(""), CStrVector("-*")));
EXPECT_FALSE(PassesFilter(CStrVector(""), CStrVector("a")));
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
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