Commit d5fe9621 authored by Jakob Linke's avatar Jakob Linke Committed by V8 LUCI CQ

[maglev] Add the function-context-specialization option

.. and just the option for now, there's no logic behind this yet.

--maglev-function-context-specialization enables FCS globally, and the
MaglevCompilationInfo stores for each compilation job whether FCS is
enabled.

Bug: v8:7700
Change-Id: I4c32fe93fca70ae3644588902e282910a9673b74
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3905382Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Jakob Linke <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83351}
parent 13f06689
......@@ -2677,31 +2677,6 @@ bool Compiler::CompileBaseline(Isolate* isolate, Handle<JSFunction> function,
return true;
}
// static
bool Compiler::CompileMaglev(Isolate* isolate, Handle<JSFunction> function,
ConcurrencyMode mode,
IsCompiledScope* is_compiled_scope) {
#ifdef V8_ENABLE_MAGLEV
// Bytecode must be available for maglev compilation.
DCHECK(is_compiled_scope->is_compiled());
// TODO(v8:7700): Support concurrent compilation.
DCHECK(IsSynchronous(mode));
// Maglev code needs a feedback vector.
JSFunction::EnsureFeedbackVector(isolate, function, is_compiled_scope);
MaybeHandle<CodeT> maybe_code = Maglev::Compile(isolate, function);
Handle<CodeT> code;
if (!maybe_code.ToHandle(&code)) return false;
DCHECK_EQ(code->kind(), CodeKind::MAGLEV);
function->set_code(*code);
return true;
#else
return false;
#endif // V8_ENABLE_MAGLEV
}
// static
MaybeHandle<SharedFunctionInfo> Compiler::CompileToplevel(
ParseInfo* parse_info, Handle<Script> script, Isolate* isolate,
......@@ -4021,9 +3996,9 @@ void Compiler::FinalizeMaglevCompilationJob(maglev::MaglevCompilationJob* job,
// Note the finalized Code object has already been installed on the
// function by MaglevCompilationJob::FinalizeJobImpl.
const bool kIsContextSpecializing = false;
OptimizedCodeCache::Insert(isolate, *function, BytecodeOffset::None(),
function->code(), kIsContextSpecializing);
function->code(),
job->specialize_to_function_context());
// Reset ticks just after installation since ticks accumulated in lower
// tiers use a different (lower) budget than ticks collected in Maglev
......
......@@ -89,10 +89,6 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
ClearExceptionFlag flag,
IsCompiledScope* is_compiled_scope);
static bool CompileMaglev(Isolate* isolate, Handle<JSFunction> function,
ConcurrencyMode mode,
IsCompiledScope* is_compiled_scope);
static void CompileOptimized(Isolate* isolate, Handle<JSFunction> function,
ConcurrencyMode mode, CodeKind code_kind);
......
......@@ -476,6 +476,10 @@ DEFINE_BOOL(print_maglev_code, false, "print maglev code")
DEFINE_BOOL(trace_maglev_graph_building, false, "trace maglev graph building")
DEFINE_BOOL(trace_maglev_regalloc, false, "trace maglev register allocation")
// TODO(v8:7700): Remove once stable.
DEFINE_BOOL(maglev_function_context_specialization, false,
"enable function context specialization in maglev")
#if ENABLE_SPARKPLUG
DEFINE_WEAK_IMPLICATION(future, sparkplug)
DEFINE_WEAK_IMPLICATION(future, flush_baseline_code)
......
......@@ -58,7 +58,11 @@ MaglevCompilationInfo::MaglevCompilationInfo(Isolate* isolate,
#define V(Name) , Name##_(v8_flags.Name)
MAGLEV_COMPILATION_FLAG_LIST(V)
#undef V
{
,
specialize_to_function_context_(
v8_flags.maglev_function_context_specialization &&
function->raw_feedback_cell().map() ==
ReadOnlyRoots(isolate).one_closure_cell_map()) {
DCHECK(v8_flags.maglev);
MaglevCompilationHandleScope compilation(isolate, this);
......
......@@ -34,6 +34,8 @@ class Graph;
class MaglevCompilationUnit;
class MaglevGraphLabeller;
// A list of v8_flag values copied into the MaglevCompilationInfo for
// guaranteed {immutable,threadsafe} access.
#define MAGLEV_COMPILATION_FLAG_LIST(V) \
V(code_comments) \
V(maglev) \
......@@ -88,6 +90,10 @@ class MaglevCompilationInfo final {
MAGLEV_COMPILATION_FLAG_LIST(V)
#undef V
bool specialize_to_function_context() const {
return specialize_to_function_context_;
}
// Must be called from within a MaglevCompilationHandleScope. Transfers owned
// handles (e.g. shared_, function_) to the new scope.
void ReopenHandlesInNewHandleScope(Isolate* isolate);
......@@ -123,6 +129,12 @@ class MaglevCompilationInfo final {
MAGLEV_COMPILATION_FLAG_LIST(V)
#undef V
// If enabled, the generated code can rely on the function context to be a
// constant (known at compile-time). This opens new optimization
// opportunities, but prevents code sharing between different function
// contexts.
const bool specialize_to_function_context_;
// 1) PersistentHandles created via PersistentHandlesScope inside of
// CompilationHandleScope.
// 2) Owned by MaglevCompilationInfo.
......
......@@ -119,6 +119,10 @@ Handle<JSFunction> MaglevCompilationJob::function() const {
return info_->toplevel_compilation_unit()->function().object();
}
bool MaglevCompilationJob::specialize_to_function_context() const {
return info_->specialize_to_function_context();
}
// The JobTask is posted to V8::GetCurrentPlatform(). It's responsible for
// processing the incoming queue on a worker thread.
class MaglevConcurrentDispatcher::JobTask final : public v8::JobTask {
......
......@@ -56,6 +56,8 @@ class MaglevCompilationJob final : public OptimizedCompilationJob {
Handle<JSFunction> function() const;
bool specialize_to_function_context() const;
base::TimeDelta time_taken_to_prepare() { return time_taken_to_prepare_; }
base::TimeDelta time_taken_to_execute() { return time_taken_to_execute_; }
base::TimeDelta time_taken_to_finalize() { return time_taken_to_finalize_; }
......
......@@ -17,6 +17,8 @@ class JSFunction;
class Maglev : public AllStatic {
public:
// TODO(v8:7700): This entry point is only used for testing. Consider
// removing it once BenchMaglev runtime functions are no longer useful.
static MaybeHandle<CodeT> Compile(Isolate* isolate,
Handle<JSFunction> function);
};
......
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