Skip to content

Clean up AggressiveOpt tier in vm #90504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/coreclr/vm/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3035,8 +3035,8 @@ bool MethodDesc::DetermineAndSetIsEligibleForTieredCompilation()
// Functional requirement - These methods have no IL that could be optimized
!IsWrapperStub() &&

// Policy - Generating optimized code is not disabled
!IsJitOptimizationDisabledForSpecificMethod())
// Functions with NoOptimization or AggressiveOptimization don't participate in tiering
!IsJitOptimizationLevelRequested())
{
m_wFlags3AndTokenRemainder |= enum_flag3_IsEligibleForTieredCompilation;
_ASSERTE(IsVersionable());
Expand All @@ -3062,6 +3062,17 @@ bool MethodDesc::IsJitOptimizationDisabledForSpecificMethod()
return (!IsNoMetadata() && IsMiNoOptimization(GetImplAttrs()));
}

bool MethodDesc::IsJitOptimizationLevelRequested()
{
if (IsNoMetadata())
{
return false;
}

const DWORD attrs = GetImplAttrs();
return IsMiNoOptimization(attrs) || IsMiAggressiveOptimization(attrs);
}

bool MethodDesc::IsJitOptimizationDisabledForAllMethodsInChunk()
{
WRAPPER_NO_CONTRACT;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ class MethodDesc
bool IsJitOptimizationDisabled();
bool IsJitOptimizationDisabledForAllMethodsInChunk();
bool IsJitOptimizationDisabledForSpecificMethod();
bool IsJitOptimizationLevelRequested();

private:
// This function is not intended to be called in most places, and is named as such to discourage calling it accidentally
Expand Down
64 changes: 25 additions & 39 deletions src/coreclr/vm/tieredcompilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ NativeCodeVersion::OptimizationTier TieredCompilationManager::GetInitialOptimiza
return NativeCodeVersion::OptimizationTierOptimized;
}

if (pMethodDesc->RequestedAggressiveOptimization())
{
// Methods flagged with MethodImplOptions.AggressiveOptimization start with and stay at tier 1
return NativeCodeVersion::OptimizationTier1;
}
_ASSERT(!pMethodDesc->RequestedAggressiveOptimization());

if (!pMethodDesc->GetLoaderAllocator()->GetCallCountingManager()->IsCallCountingEnabled(NativeCodeVersion(pMethodDesc)))
{
Expand Down Expand Up @@ -1075,50 +1071,40 @@ CORJIT_FLAGS TieredCompilationManager::GetJitFlags(PrepareCodeConfig *config)
return flags;
}

NativeCodeVersion::OptimizationTier newOptimizationTier;
if (!methodDesc->RequestedAggressiveOptimization())
_ASSERT(!methodDesc->RequestedAggressiveOptimization());

if (g_pConfig->TieredCompilation_QuickJit())
{
NativeCodeVersion::OptimizationTier currentTier = nativeCodeVersion.GetOptimizationTier();

if (g_pConfig->TieredCompilation_QuickJit())
if (currentTier == NativeCodeVersion::OptimizationTier::OptimizationTier0Instrumented)
{
if (currentTier == NativeCodeVersion::OptimizationTier::OptimizationTier0Instrumented)
{
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR);
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER0);
return flags;
}

if (currentTier == NativeCodeVersion::OptimizationTier::OptimizationTier1Instrumented)
{
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR);
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER1);
return flags;
}

_ASSERTE(!nativeCodeVersion.IsFinalTier());
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR);
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER0);
if (g_pConfig->TieredPGO() && g_pConfig->TieredPGO_InstrumentOnlyHotCode())
{
// If we plan to only instrument hot code we have to make an exception
// for cold methods with loops so if those self promote to OSR they need
// some profile to optimize, so here we allow JIT to enable instrumentation
// if current method has loops and is eligible for OSR.
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR_IF_LOOPS);
}
return flags;
}

newOptimizationTier = NativeCodeVersion::OptimizationTierOptimized;
}
else
{
newOptimizationTier = NativeCodeVersion::OptimizationTier1;
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER1);
if (currentTier == NativeCodeVersion::OptimizationTier::OptimizationTier1Instrumented)
{
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR);
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER1);
return flags;
}

_ASSERTE(!nativeCodeVersion.IsFinalTier());
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER0);
if (g_pConfig->TieredPGO() && g_pConfig->TieredPGO_InstrumentOnlyHotCode())
{
// If we plan to only instrument hot code we have to make an exception
// for cold methods with loops so if those self promote to OSR they need
// some profile to optimize, so here we allow JIT to enable instrumentation
// if current method has loops and is eligible for OSR.
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR_IF_LOOPS);
}
return flags;
}

methodDesc->GetLoaderAllocator()->GetCallCountingManager()->DisableCallCounting(nativeCodeVersion);
nativeCodeVersion.SetOptimizationTier(newOptimizationTier);
nativeCodeVersion.SetOptimizationTier(NativeCodeVersion::OptimizationTierOptimized);
#ifdef FEATURE_INTERPRETER
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_MAKEFINALCODE);
#endif
Expand Down