[sparkplug] Add a flag making sparkplug depend on short builtin calls

In case we find that Sparkplug benefits require short builtin calls, add
a --sparkplug-needs-short-builtins flag to make the former depend on the
latter.

Change-Id: I5b23abbd9ad6e0d11d7033497d5755f08c2ab876
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2988753
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75392}
This commit is contained in:
Leszek Swirski 2021-06-25 16:49:06 +02:00 committed by V8 LUCI CQ
parent ee307c747f
commit 35f774c74b
6 changed files with 22 additions and 13 deletions

View File

@ -41,7 +41,7 @@ bool BaselineBatchCompiler::EnqueueFunction(Handle<JSFunction> function) {
// Early return if the function is compiled with baseline already or it is not
// suitable for baseline compilation.
if (shared->HasBaselineData()) return true;
if (!CanCompileWithBaseline(isolate_, shared)) return false;
if (!CanCompileWithBaseline(isolate_, *shared)) return false;
// Immediately compile the function if batch compilation is disabled.
if (!is_enabled()) {

View File

@ -23,22 +23,29 @@
namespace v8 {
namespace internal {
bool CanCompileWithBaseline(Isolate* isolate,
Handle<SharedFunctionInfo> shared) {
bool CanCompileWithBaseline(Isolate* isolate, SharedFunctionInfo shared) {
DisallowGarbageCollection no_gc;
// Check that baseline compiler is enabled.
if (!FLAG_sparkplug) return false;
// Check that short builtin calls are enabled if needed.
if (FLAG_sparkplug_needs_short_builtins &&
!isolate->is_short_builtin_calls_enabled()) {
return false;
}
// Check if we actually have bytecode.
if (!shared->HasBytecodeArray()) return false;
if (!shared.HasBytecodeArray()) return false;
// Do not optimize when debugger needs to hook into every call.
if (isolate->debug()->needs_check_on_function_call()) return false;
// Functions with breakpoints have to stay interpreted.
if (shared->HasBreakInfo()) return false;
if (shared.HasBreakInfo()) return false;
// Do not baseline compile if function doesn't pass sparkplug_filter.
if (!shared->PassesFilter(FLAG_sparkplug_filter)) return false;
if (!shared.PassesFilter(FLAG_sparkplug_filter)) return false;
return true;
}
@ -89,8 +96,7 @@ void EmitReturnBaseline(MacroAssembler* masm) {
namespace v8 {
namespace internal {
bool CanCompileWithBaseline(Isolate* isolate,
Handle<SharedFunctionInfo> shared) {
bool CanCompileWithBaseline(Isolate* isolate, SharedFunctionInfo shared) {
return false;
}

View File

@ -14,8 +14,7 @@ class Code;
class SharedFunctionInfo;
class MacroAssembler;
bool CanCompileWithBaseline(Isolate* isolate,
Handle<SharedFunctionInfo> shared);
bool CanCompileWithBaseline(Isolate* isolate, SharedFunctionInfo shared);
MaybeHandle<Code> GenerateBaselineCode(Isolate* isolate,
Handle<SharedFunctionInfo> shared);

View File

@ -1311,7 +1311,7 @@ void CompileAllWithBaseline(Isolate* isolate,
Handle<SharedFunctionInfo> shared_info = finalize_data.function_handle();
IsCompiledScope is_compiled_scope(*shared_info, isolate);
if (!is_compiled_scope.is_compiled()) continue;
if (!CanCompileWithBaseline(isolate, shared_info)) continue;
if (!CanCompileWithBaseline(isolate, *shared_info)) continue;
Compiler::CompileSharedWithBaseline(
isolate, shared_info, Compiler::CLEAR_EXCEPTION, &is_compiled_scope);
}
@ -1941,7 +1941,7 @@ bool Compiler::CompileSharedWithBaseline(Isolate* isolate,
if (shared->HasBaselineData()) return true;
// Check if we actually can compile with baseline.
if (!CanCompileWithBaseline(isolate, shared)) return false;
if (!CanCompileWithBaseline(isolate, *shared)) return false;
StackLimitCheck check(isolate);
if (check.JsHasOverflowed(kStackSpaceRequiredForCompilation * KB)) {

View File

@ -668,6 +668,9 @@ DEFINE_BOOL(baseline_batch_compilation, true, "batch compile Sparkplug code")
DEFINE_BOOL(baseline_batch_compilation, false, "batch compile Sparkplug code")
#endif
DEFINE_STRING(sparkplug_filter, "*", "filter for Sparkplug baseline compiler")
DEFINE_BOOL(sparkplug_needs_short_builtins, false,
"only enable Sparkplug baseline compiler when "
"--short-builtin-calls are also enabled")
DEFINE_INT(baseline_batch_compilation_threshold, 4 * KB,
"the estimated instruction size of a batch to trigger compilation")
DEFINE_BOOL(trace_baseline, false, "trace baseline compilation")

View File

@ -345,7 +345,8 @@ RUNTIME_FUNCTION(Runtime_BytecodeBudgetInterruptFromBytecode) {
// a non zero invocation count so we can inline functions.
function->feedback_vector().set_invocation_count(1);
}
if (FLAG_sparkplug && !function->ActiveTierIsBaseline()) {
if (CanCompileWithBaseline(isolate, function->shared()) &&
!function->ActiveTierIsBaseline()) {
if (V8_LIKELY(FLAG_baseline_batch_compilation)) {
isolate->baseline_batch_compiler()->EnqueueFunction(function);
} else {