From 35f774c74b71f01b486fdbe2071dc5b36dc2b894 Mon Sep 17 00:00:00 2001 From: Leszek Swirski Date: Fri, 25 Jun 2021 16:49:06 +0200 Subject: [PATCH] [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 Auto-Submit: Leszek Swirski Reviewed-by: Toon Verwaest Cr-Commit-Position: refs/heads/master@{#75392} --- src/baseline/baseline-batch-compiler.cc | 2 +- src/baseline/baseline.cc | 20 +++++++++++++------- src/baseline/baseline.h | 3 +-- src/codegen/compiler.cc | 4 ++-- src/flags/flag-definitions.h | 3 +++ src/runtime/runtime-internal.cc | 3 ++- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/baseline/baseline-batch-compiler.cc b/src/baseline/baseline-batch-compiler.cc index abca4721e1..6a25df7264 100644 --- a/src/baseline/baseline-batch-compiler.cc +++ b/src/baseline/baseline-batch-compiler.cc @@ -41,7 +41,7 @@ bool BaselineBatchCompiler::EnqueueFunction(Handle 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()) { diff --git a/src/baseline/baseline.cc b/src/baseline/baseline.cc index 2f6e0243f2..396f63285a 100644 --- a/src/baseline/baseline.cc +++ b/src/baseline/baseline.cc @@ -23,22 +23,29 @@ namespace v8 { namespace internal { -bool CanCompileWithBaseline(Isolate* isolate, - Handle 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 shared) { +bool CanCompileWithBaseline(Isolate* isolate, SharedFunctionInfo shared) { return false; } diff --git a/src/baseline/baseline.h b/src/baseline/baseline.h index 73f4f76cc4..10a6e25e4f 100644 --- a/src/baseline/baseline.h +++ b/src/baseline/baseline.h @@ -14,8 +14,7 @@ class Code; class SharedFunctionInfo; class MacroAssembler; -bool CanCompileWithBaseline(Isolate* isolate, - Handle shared); +bool CanCompileWithBaseline(Isolate* isolate, SharedFunctionInfo shared); MaybeHandle GenerateBaselineCode(Isolate* isolate, Handle shared); diff --git a/src/codegen/compiler.cc b/src/codegen/compiler.cc index cb156f1d03..171f508ad2 100644 --- a/src/codegen/compiler.cc +++ b/src/codegen/compiler.cc @@ -1311,7 +1311,7 @@ void CompileAllWithBaseline(Isolate* isolate, Handle 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)) { diff --git a/src/flags/flag-definitions.h b/src/flags/flag-definitions.h index 353a40cbae..01ce303974 100644 --- a/src/flags/flag-definitions.h +++ b/src/flags/flag-definitions.h @@ -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") diff --git a/src/runtime/runtime-internal.cc b/src/runtime/runtime-internal.cc index 8df330d51d..49f4b91475 100644 --- a/src/runtime/runtime-internal.cc +++ b/src/runtime/runtime-internal.cc @@ -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 {