Commit e9d76f88 authored by Patrick Thier's avatar Patrick Thier Committed by V8 LUCI CQ

[sparkplug] Improve OSR for batch compilation

- Remove possibility to pass frame to %BaselineOsr (was unused and adds
overhead to the normal path)
- Arm back edges for OSR of all functions compiled in a batch
- Refactoring

Bug: v8:11790
Change-Id: Ifb1016935296a172914f99e8b2a1742f618a2be0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2982609Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Patrick Thier <pthier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75384}
parent 81841073
......@@ -2410,7 +2410,6 @@ v8_header_set("v8_internal_headers") {
"src/baseline/baseline-assembler.h",
"src/baseline/baseline-batch-compiler.h",
"src/baseline/baseline-compiler.h",
"src/baseline/baseline-osr-inl.h",
"src/baseline/baseline.h",
"src/baseline/bytecode-offset-iterator.h",
"src/builtins/accessors.h",
......
......@@ -6,7 +6,6 @@ include_rules = [
"-src/baseline",
"+src/baseline/baseline.h",
"+src/baseline/baseline-batch-compiler.h",
"+src/baseline/baseline-osr-inl.h",
"+src/baseline/bytecode-offset-iterator.h",
"-src/bigint",
"+src/bigint/bigint.h",
......
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#ifndef V8_BASELINE_BASELINE_OSR_INL_H_
#define V8_BASELINE_BASELINE_OSR_INL_H_
#include "src/baseline/baseline-batch-compiler.h"
#include "src/execution/frames.h"
#include "src/execution/isolate-inl.h"
namespace v8 {
namespace internal {
enum CompilationMode { kCompileImmediate, kCompileBatch };
inline void OSRInterpreterFrameToBaseline(Isolate* isolate,
Handle<JSFunction> function,
UnoptimizedFrame* frame,
CompilationMode compilation_mode) {
IsCompiledScope is_compiled_scope(
function->shared().is_compiled_scope(isolate));
bool is_compiled = false;
switch (compilation_mode) {
case kCompileBatch:
is_compiled =
isolate->baseline_batch_compiler()->EnqueueFunction(function);
break;
case kCompileImmediate:
is_compiled = Compiler::CompileBaseline(
isolate, function, Compiler::CLEAR_EXCEPTION, &is_compiled_scope);
break;
}
if (is_compiled) {
if (V8_LIKELY(FLAG_use_osr)) {
DCHECK_NOT_NULL(frame);
if (FLAG_trace_osr) {
CodeTracer::Scope scope(isolate->GetCodeTracer());
PrintF(scope.file(),
"[OSR - Entry at OSR bytecode offset %d into baseline code]\n",
frame->GetBytecodeOffset());
}
frame->GetBytecodeArray().set_osr_loop_nesting_level(
AbstractCode::kMaxLoopNestingMarker);
}
}
}
} // namespace internal
} // namespace v8
#endif // V8_BASELINE_BASELINE_OSR_INL_H_
......@@ -1967,6 +1967,20 @@ bool Compiler::CompileSharedWithBaseline(Isolate* isolate,
Handle<BaselineData> baseline_data =
isolate->factory()->NewBaselineData(code, function_data);
shared->set_baseline_data(*baseline_data);
if (V8_LIKELY(FLAG_use_osr)) {
// Arm back edges for OSR
shared->GetBytecodeArray(isolate).set_osr_loop_nesting_level(
AbstractCode::kMaxLoopNestingMarker);
if (FLAG_trace_osr) {
JavaScriptFrameIterator it(isolate);
DCHECK(it.frame()->is_unoptimized());
UnoptimizedFrame* frame = UnoptimizedFrame::cast(it.frame());
CodeTracer::Scope scope(isolate->GetCodeTracer());
PrintF(scope.file(),
"[OSR - Entry at OSR bytecode offset %d into baseline code]\n",
frame->GetBytecodeOffset());
}
}
}
double time_taken_ms = time_taken.InMillisecondsF();
......
......@@ -7,7 +7,7 @@
#include "src/api/api.h"
#include "src/ast/ast-traversal-visitor.h"
#include "src/ast/prettyprinter.h"
#include "src/baseline/baseline-osr-inl.h"
#include "src/baseline/baseline-batch-compiler.h"
#include "src/baseline/baseline.h"
#include "src/builtins/builtins.h"
#include "src/common/message-template.h"
......@@ -346,16 +346,13 @@ RUNTIME_FUNCTION(Runtime_BytecodeBudgetInterruptFromBytecode) {
function->feedback_vector().set_invocation_count(1);
}
if (FLAG_sparkplug && !function->ActiveTierIsBaseline()) {
CompilationMode compilation_mode =
FLAG_baseline_batch_compilation ? kCompileBatch : kCompileImmediate;
if (V8_LIKELY(FLAG_use_osr)) {
JavaScriptFrameIterator it(isolate);
DCHECK(it.frame()->is_unoptimized());
UnoptimizedFrame* frame = UnoptimizedFrame::cast(it.frame());
OSRInterpreterFrameToBaseline(isolate, function, frame, compilation_mode);
if (V8_LIKELY(FLAG_baseline_batch_compilation)) {
isolate->baseline_batch_compiler()->EnqueueFunction(function);
} else {
OSRInterpreterFrameToBaseline(isolate, function, nullptr,
compilation_mode);
IsCompiledScope is_compiled_scope(
function->shared().is_compiled_scope(isolate));
Compiler::CompileBaseline(isolate, function, Compiler::CLEAR_EXCEPTION,
&is_compiled_scope);
}
}
if (should_mark_for_optimization) {
......
......@@ -5,7 +5,6 @@
#include "src/api/api-inl.h"
#include "src/base/numbers/double.h"
#include "src/base/platform/mutex.h"
#include "src/baseline/baseline-osr-inl.h"
#include "src/codegen/assembler-inl.h"
#include "src/codegen/compiler.h"
#include "src/codegen/pending-optimization-table.h"
......@@ -488,21 +487,11 @@ RUNTIME_FUNCTION(Runtime_OptimizeOsr) {
RUNTIME_FUNCTION(Runtime_BaselineOsr) {
HandleScope scope(isolate);
DCHECK(args.length() == 0 || args.length() == 1);
Handle<JSFunction> function;
// The optional parameter determines the frame being targeted.
int stack_depth = 0;
if (args.length() == 1) {
if (!args[0].IsSmi()) return CrashUnlessFuzzing(isolate);
stack_depth = args.smi_at(0);
}
DCHECK_EQ(0, args.length());
// Find the JavaScript function on the top of the stack.
JavaScriptFrameIterator it(isolate);
while (!it.done() && stack_depth--) it.Advance();
if (!it.done()) function = handle(it.frame()->function(), isolate);
Handle<JSFunction> function = handle(it.frame()->function(), isolate);
if (function.is_null()) return CrashUnlessFuzzing(isolate);
if (!FLAG_sparkplug || !FLAG_use_osr) {
return ReadOnlyRoots(isolate).undefined_value();
......@@ -511,8 +500,10 @@ RUNTIME_FUNCTION(Runtime_BaselineOsr) {
return ReadOnlyRoots(isolate).undefined_value();
}
UnoptimizedFrame* frame = UnoptimizedFrame::cast(it.frame());
OSRInterpreterFrameToBaseline(isolate, function, frame, kCompileImmediate);
IsCompiledScope is_compiled_scope(
function->shared().is_compiled_scope(isolate));
Compiler::CompileBaseline(isolate, function, Compiler::CLEAR_EXCEPTION,
&is_compiled_scope);
return ReadOnlyRoots(isolate).undefined_value();
}
......
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