[sparkplug] Add --sparkplug-filter

Allow filtering what functions compile with Sparkplug.

Bug: v8:11420
Change-Id: Ib70c4405687ec527109f2adbf87b58a51aae9870
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2700671
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72823}
This commit is contained in:
Leszek Swirski 2021-02-17 17:16:59 +01:00 committed by Commit Bot
parent 564361d878
commit c7bad60657
2 changed files with 36 additions and 23 deletions

View File

@ -636,23 +636,8 @@ void UpdateSharedFunctionFlagsAfterCompilation(FunctionLiteral* literal,
shared_info.SetScopeInfo(*literal->scope()->scope_info());
}
bool CompileSharedWithBaseline(Isolate* isolate,
Handle<SharedFunctionInfo> shared,
Compiler::ClearExceptionFlag flag,
IsCompiledScope* is_compiled_scope) {
DCHECK(FLAG_sparkplug);
DCHECK(is_compiled_scope->is_compiled());
if (shared->HasBaselineData()) return true;
StackLimitCheck check(isolate);
if (check.JsHasOverflowed(kStackSpaceRequiredForCompilation * KB)) {
if (flag == Compiler::KEEP_EXCEPTION) {
isolate->StackOverflow();
}
return false;
}
bool CanCompileWithBaseline(Isolate* isolate,
Handle<SharedFunctionInfo> shared) {
// Check if we actually have bytecode.
if (!shared->HasBytecodeArray()) return false;
@ -662,6 +647,36 @@ bool CompileSharedWithBaseline(Isolate* isolate,
// Functions with breakpoints have to stay interpreted.
if (shared->HasBreakInfo()) return false;
// Do not baseline compile if sparkplug is disabled or function doesn't pass
// sparkplug_filter.
if (!FLAG_sparkplug || !shared->PassesFilter(FLAG_sparkplug_filter)) {
return false;
}
return true;
}
bool CompileSharedWithBaseline(Isolate* isolate,
Handle<SharedFunctionInfo> shared,
Compiler::ClearExceptionFlag flag,
IsCompiledScope* is_compiled_scope) {
// We shouldn't be passing uncompiled functions into this function.
DCHECK(is_compiled_scope->is_compiled());
// Early return for already baseline-compiled functions.
if (shared->HasBaselineData()) return true;
// Check if we actually can compile with baseline.
if (!CanCompileWithBaseline(isolate, shared)) return false;
StackLimitCheck check(isolate);
if (check.JsHasOverflowed(kStackSpaceRequiredForCompilation * KB)) {
if (flag == Compiler::KEEP_EXCEPTION) {
isolate->StackOverflow();
}
return false;
}
CompilerTracer::TraceStartBaselineCompile(isolate, shared);
Handle<Code> code;
base::TimeDelta time_taken;
@ -1934,10 +1949,7 @@ bool Compiler::Compile(Isolate* isolate, Handle<JSFunction> function,
JSFunction::InitializeFeedbackCell(function, is_compiled_scope, true);
// If --always-sparkplug is enabled, make sure we have baseline code.
// TODO(v8:11429): Extract out the rest of the if into a "can baseline
// compile" predicate, or similar.
if (FLAG_always_sparkplug && !function->shared().HasAsmWasmData() &&
!function->shared().HasDebugInfo()) {
if (FLAG_always_sparkplug && CanCompileWithBaseline(isolate, shared_info)) {
DCHECK(shared_info->HasBaselineData());
}

View File

@ -582,8 +582,9 @@ DEFINE_INT(ticks_scale_factor_for_top_tier, 10,
"scale factor for profiler ticks when tiering up from midtier")
// Flags for Sparkplug
DEFINE_BOOL(sparkplug, false, "enable experimental sparkplug baseline compiler")
DEFINE_BOOL(always_sparkplug, false, "directly tier up to sparkplug")
DEFINE_BOOL(sparkplug, false, "enable experimental Sparkplug baseline compiler")
DEFINE_STRING(sparkplug_filter, "*", "filter for Sparkplug baseline compiler")
DEFINE_BOOL(always_sparkplug, false, "directly tier up to Sparkplug code")
DEFINE_BOOL(trace_baseline, false, "trace baseline compilation")
DEFINE_NEG_IMPLICATION(sparkplug, write_protect_code_memory)
DEFINE_IMPLICATION(always_sparkplug, sparkplug)