Commit e38cb757 authored by Mythri A's avatar Mythri A Committed by Commit Bot

[turboprop] Enable tierup to TurboFan with FLAG_turboprop

FLAG_turboprop was used to test the turboprop compiler without any
further tierup to TurboFan. This cl changes:
- FLAG_turboprop to also tier up to TurboFan.
- Introduces FLAG_turboprop_as_toptier to continue running the
  configuration without tierup.
- Removes FLAG_turboprop_as_midtier which is same as FLAG_turboprop.

Bug: v8:9684
Change-Id: I487bda13d226434837770ecc43b3ced7c31ccf19
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2622214
Commit-Queue: Mythri Alle <mythria@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72101}
parent 8327ce71
...@@ -1048,8 +1048,8 @@ Handle<Code> ContinuationForConcurrentOptimization( ...@@ -1048,8 +1048,8 @@ Handle<Code> ContinuationForConcurrentOptimization(
// Tiering up to Turbofan and cached optimized code exists. Continue // Tiering up to Turbofan and cached optimized code exists. Continue
// execution there until TF optimization has finished. // execution there until TF optimization has finished.
return cached_code; return cached_code;
} else if (FLAG_turboprop_as_midtier && } else if (FLAG_turboprop && function->HasAvailableOptimizedCode()) {
function->HasAvailableOptimizedCode()) { DCHECK(!FLAG_turboprop_as_toptier);
DCHECK(function->NextTier() == CodeKind::TURBOFAN); DCHECK(function->NextTier() == CodeKind::TURBOFAN);
// It is possible that we have marked a closure for TurboFan optimization // It is possible that we have marked a closure for TurboFan optimization
// but the marker is processed by another closure that doesn't have // but the marker is processed by another closure that doesn't have
......
...@@ -178,7 +178,6 @@ void RuntimeProfiler::MaybeOptimizeFrame(JSFunction function, ...@@ -178,7 +178,6 @@ void RuntimeProfiler::MaybeOptimizeFrame(JSFunction function,
// Note: We currently do not trigger OSR compilation from NCI or TP code. // Note: We currently do not trigger OSR compilation from NCI or TP code.
// TODO(jgruber,v8:8888): But we should. // TODO(jgruber,v8:8888): But we should.
if (frame->is_interpreted()) { if (frame->is_interpreted()) {
DCHECK_EQ(code_kind, CodeKind::INTERPRETED_FUNCTION);
if (FLAG_always_osr) { if (FLAG_always_osr) {
AttemptOnStackReplacement(InterpretedFrame::cast(frame), AttemptOnStackReplacement(InterpretedFrame::cast(frame),
AbstractCode::kMaxLoopNestingMarker); AbstractCode::kMaxLoopNestingMarker);
...@@ -308,8 +307,11 @@ void RuntimeProfiler::MarkCandidatesForOptimization(JavaScriptFrame* frame) { ...@@ -308,8 +307,11 @@ void RuntimeProfiler::MarkCandidatesForOptimization(JavaScriptFrame* frame) {
MarkCandidatesForOptimizationScope scope(this); MarkCandidatesForOptimizationScope scope(this);
JSFunction function = frame->function(); JSFunction function = frame->function();
CodeKind code_kind = frame->is_interpreted() ? CodeKind::INTERPRETED_FUNCTION CodeKind code_kind = function.GetActiveTier();
: function.code().kind(); // For recursive functions it could happen that we have some frames
// still executing mid-tier code even after the function had higher tier code.
// In such cases, ignore any interrupts from the mid-tier code.
if (!CodeKindCanTierUp(code_kind)) return;
DCHECK(function.shared().is_compiled()); DCHECK(function.shared().is_compiled());
DCHECK(function.shared().IsInterpreted()); DCHECK(function.shared().IsInterpreted());
......
...@@ -554,9 +554,10 @@ DEFINE_BOOL(turboprop, false, "enable experimental turboprop mid-tier compiler") ...@@ -554,9 +554,10 @@ DEFINE_BOOL(turboprop, false, "enable experimental turboprop mid-tier compiler")
DEFINE_IMPLICATION(turboprop, turbo_direct_heap_access) DEFINE_IMPLICATION(turboprop, turbo_direct_heap_access)
DEFINE_BOOL(turboprop_mid_tier_reg_alloc, true, DEFINE_BOOL(turboprop_mid_tier_reg_alloc, true,
"enable mid-tier register allocator for turboprop") "enable mid-tier register allocator for turboprop")
DEFINE_BOOL(turboprop_as_midtier, false, DEFINE_BOOL(
"enable experimental turboprop mid-tier compiler") turboprop_as_toptier, false,
DEFINE_IMPLICATION(turboprop_as_midtier, turboprop) "enable experimental turboprop compiler without further tierup to turbofan")
DEFINE_IMPLICATION(turboprop_as_toptier, turboprop)
DEFINE_VALUE_IMPLICATION(turboprop, interrupt_budget, 15 * KB) DEFINE_VALUE_IMPLICATION(turboprop, interrupt_budget, 15 * KB)
DEFINE_VALUE_IMPLICATION(turboprop, reuse_opt_code_count, 2) DEFINE_VALUE_IMPLICATION(turboprop, reuse_opt_code_count, 2)
DEFINE_UINT_READONLY(max_minimorphic_map_checks, 4, DEFINE_UINT_READONLY(max_minimorphic_map_checks, 4,
......
...@@ -86,7 +86,7 @@ inline constexpr bool CodeKindCanOSR(CodeKind kind) { ...@@ -86,7 +86,7 @@ inline constexpr bool CodeKindCanOSR(CodeKind kind) {
inline constexpr bool CodeKindIsOptimizedAndCanTierUp(CodeKind kind) { inline constexpr bool CodeKindIsOptimizedAndCanTierUp(CodeKind kind) {
return kind == CodeKind::NATIVE_CONTEXT_INDEPENDENT || return kind == CodeKind::NATIVE_CONTEXT_INDEPENDENT ||
(FLAG_turboprop_as_midtier && kind == CodeKind::TURBOPROP); (!FLAG_turboprop_as_toptier && kind == CodeKind::TURBOPROP);
} }
inline constexpr bool CodeKindCanTierUp(CodeKind kind) { inline constexpr bool CodeKindCanTierUp(CodeKind kind) {
...@@ -105,8 +105,8 @@ inline constexpr bool CodeKindIsStoredInOptimizedCodeCache(CodeKind kind) { ...@@ -105,8 +105,8 @@ inline constexpr bool CodeKindIsStoredInOptimizedCodeCache(CodeKind kind) {
inline OptimizationTier GetTierForCodeKind(CodeKind kind) { inline OptimizationTier GetTierForCodeKind(CodeKind kind) {
if (kind == CodeKind::TURBOFAN) return OptimizationTier::kTopTier; if (kind == CodeKind::TURBOFAN) return OptimizationTier::kTopTier;
if (kind == CodeKind::TURBOPROP) { if (kind == CodeKind::TURBOPROP) {
return FLAG_turboprop_as_midtier ? OptimizationTier::kMidTier return FLAG_turboprop_as_toptier ? OptimizationTier::kTopTier
: OptimizationTier::kTopTier; : OptimizationTier::kMidTier;
} }
if (kind == CodeKind::NATIVE_CONTEXT_INDEPENDENT) { if (kind == CodeKind::NATIVE_CONTEXT_INDEPENDENT) {
return FLAG_turbo_nci_as_midtier ? OptimizationTier::kMidTier return FLAG_turbo_nci_as_midtier ? OptimizationTier::kMidTier
...@@ -116,12 +116,8 @@ inline OptimizationTier GetTierForCodeKind(CodeKind kind) { ...@@ -116,12 +116,8 @@ inline OptimizationTier GetTierForCodeKind(CodeKind kind) {
} }
inline CodeKind CodeKindForTopTier() { inline CodeKind CodeKindForTopTier() {
// TODO(turboprop, mythria): We should make FLAG_turboprop mean turboprop is if (V8_UNLIKELY(FLAG_turboprop_as_toptier)) {
// mid-tier compiler and replace FLAG_turboprop_as_midtier with return CodeKind::TURBOPROP;
// FLAG_turboprop_as_top_tier to tier up to only Turboprop once
// FLAG_turboprop_as_midtier is stable and major regressions are addressed.
if (V8_UNLIKELY(FLAG_turboprop)) {
return FLAG_turboprop_as_midtier ? CodeKind::TURBOFAN : CodeKind::TURBOPROP;
} }
return CodeKind::TURBOFAN; return CodeKind::TURBOFAN;
} }
......
...@@ -52,14 +52,12 @@ CodeKinds JSFunction::GetAvailableCodeKinds() const { ...@@ -52,14 +52,12 @@ CodeKinds JSFunction::GetAvailableCodeKinds() const {
} }
} }
if ((result & kOptimizedJSFunctionCodeKindsMask) == 0) { // Check the optimized code cache.
// Check the optimized code cache. if (has_feedback_vector() && feedback_vector().has_optimized_code() &&
if (has_feedback_vector() && feedback_vector().has_optimized_code() && !feedback_vector().optimized_code().marked_for_deoptimization()) {
!feedback_vector().optimized_code().marked_for_deoptimization()) { Code code = feedback_vector().optimized_code();
Code code = feedback_vector().optimized_code(); DCHECK(CodeKindIsOptimizedJSFunction(code.kind()));
DCHECK(CodeKindIsOptimizedJSFunction(code.kind())); result |= CodeKindToCodeKindFlag(code.kind());
result |= CodeKindToCodeKindFlag(code.kind());
}
} }
DCHECK_EQ((result & ~kJSFunctionCodeKindsMask), 0); DCHECK_EQ((result & ~kJSFunctionCodeKindsMask), 0);
...@@ -107,9 +105,8 @@ bool HighestTierOf(CodeKinds kinds, CodeKind* highest_tier) { ...@@ -107,9 +105,8 @@ bool HighestTierOf(CodeKinds kinds, CodeKind* highest_tier) {
} // namespace } // namespace
bool JSFunction::ActiveTierIsIgnition() const { bool JSFunction::ActiveTierIsIgnition() const {
CodeKind highest_tier; if (!shared().HasBytecodeArray()) return false;
if (!HighestTierOf(GetAvailableCodeKinds(), &highest_tier)) return false; bool result = (GetActiveTier() == CodeKind::INTERPRETED_FUNCTION);
bool result = (highest_tier == CodeKind::INTERPRETED_FUNCTION);
DCHECK_IMPLIES(result, DCHECK_IMPLIES(result,
code().is_interpreter_trampoline_builtin() || code().is_interpreter_trampoline_builtin() ||
(CodeKindIsOptimizedJSFunction(code().kind()) && (CodeKindIsOptimizedJSFunction(code().kind()) &&
...@@ -119,30 +116,37 @@ bool JSFunction::ActiveTierIsIgnition() const { ...@@ -119,30 +116,37 @@ bool JSFunction::ActiveTierIsIgnition() const {
return result; return result;
} }
bool JSFunction::ActiveTierIsTurbofan() const { CodeKind JSFunction::GetActiveTier() const {
CodeKind highest_tier; CodeKind highest_tier;
if (!HighestTierOf(GetAvailableCodeKinds(), &highest_tier)) return false; DCHECK(shared().is_compiled());
return highest_tier == CodeKind::TURBOFAN; HighestTierOf(GetAvailableCodeKinds(), &highest_tier);
DCHECK(highest_tier == CodeKind::TURBOFAN ||
highest_tier == CodeKind::TURBOPROP ||
highest_tier == CodeKind::NATIVE_CONTEXT_INDEPENDENT ||
highest_tier == CodeKind::INTERPRETED_FUNCTION);
return highest_tier;
}
bool JSFunction::ActiveTierIsTurbofan() const {
if (!shared().HasBytecodeArray()) return false;
return GetActiveTier() == CodeKind::TURBOFAN;
} }
bool JSFunction::ActiveTierIsNCI() const { bool JSFunction::ActiveTierIsNCI() const {
CodeKind highest_tier; if (!shared().HasBytecodeArray()) return false;
if (!HighestTierOf(GetAvailableCodeKinds(), &highest_tier)) return false; return GetActiveTier() == CodeKind::NATIVE_CONTEXT_INDEPENDENT;
return highest_tier == CodeKind::NATIVE_CONTEXT_INDEPENDENT;
} }
bool JSFunction::ActiveTierIsToptierTurboprop() const { bool JSFunction::ActiveTierIsToptierTurboprop() const {
CodeKind highest_tier; if (!FLAG_turboprop_as_toptier) return false;
if (!FLAG_turboprop) return false; if (!shared().HasBytecodeArray()) return false;
if (!HighestTierOf(GetAvailableCodeKinds(), &highest_tier)) return false; return GetActiveTier() == CodeKind::TURBOPROP && FLAG_turboprop_as_toptier;
return highest_tier == CodeKind::TURBOPROP && !FLAG_turboprop_as_midtier;
} }
bool JSFunction::ActiveTierIsMidtierTurboprop() const { bool JSFunction::ActiveTierIsMidtierTurboprop() const {
CodeKind highest_tier; if (!FLAG_turboprop) return false;
if (!FLAG_turboprop_as_midtier) return false; if (!shared().HasBytecodeArray()) return false;
if (!HighestTierOf(GetAvailableCodeKinds(), &highest_tier)) return false; return GetActiveTier() == CodeKind::TURBOPROP && !FLAG_turboprop_as_toptier;
return highest_tier == CodeKind::TURBOPROP && FLAG_turboprop_as_midtier;
} }
CodeKind JSFunction::NextTier() const { CodeKind JSFunction::NextTier() const {
......
...@@ -114,6 +114,7 @@ class JSFunction : public JSFunctionOrBoundFunction { ...@@ -114,6 +114,7 @@ class JSFunction : public JSFunctionOrBoundFunction {
bool HasAvailableCodeKind(CodeKind kind) const; bool HasAvailableCodeKind(CodeKind kind) const;
CodeKind GetActiveTier() const;
V8_EXPORT_PRIVATE bool ActiveTierIsIgnition() const; V8_EXPORT_PRIVATE bool ActiveTierIsIgnition() const;
bool ActiveTierIsTurbofan() const; bool ActiveTierIsTurbofan() const;
bool ActiveTierIsNCI() const; bool ActiveTierIsNCI() const;
......
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