Skip to content

Commit 81bb11d

Browse files
authored
Clean up AggressiveOpt tier in vm (#90504)
1 parent e3368e8 commit 81bb11d

File tree

3 files changed

+39
-41
lines changed

3 files changed

+39
-41
lines changed

src/coreclr/vm/method.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3038,8 +3038,8 @@ bool MethodDesc::DetermineAndSetIsEligibleForTieredCompilation()
30383038
// Functional requirement - These methods have no IL that could be optimized
30393039
!IsWrapperStub() &&
30403040

3041-
// Policy - Generating optimized code is not disabled
3042-
!IsJitOptimizationDisabledForSpecificMethod())
3041+
// Functions with NoOptimization or AggressiveOptimization don't participate in tiering
3042+
!IsJitOptimizationLevelRequested())
30433043
{
30443044
m_wFlags3AndTokenRemainder |= enum_flag3_IsEligibleForTieredCompilation;
30453045
_ASSERTE(IsVersionable());
@@ -3065,6 +3065,17 @@ bool MethodDesc::IsJitOptimizationDisabledForSpecificMethod()
30653065
return (!IsNoMetadata() && IsMiNoOptimization(GetImplAttrs()));
30663066
}
30673067

3068+
bool MethodDesc::IsJitOptimizationLevelRequested()
3069+
{
3070+
if (IsNoMetadata())
3071+
{
3072+
return false;
3073+
}
3074+
3075+
const DWORD attrs = GetImplAttrs();
3076+
return IsMiNoOptimization(attrs) || IsMiAggressiveOptimization(attrs);
3077+
}
3078+
30683079
bool MethodDesc::IsJitOptimizationDisabledForAllMethodsInChunk()
30693080
{
30703081
WRAPPER_NO_CONTRACT;

src/coreclr/vm/method.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,7 @@ class MethodDesc
11241124
bool IsJitOptimizationDisabled();
11251125
bool IsJitOptimizationDisabledForAllMethodsInChunk();
11261126
bool IsJitOptimizationDisabledForSpecificMethod();
1127+
bool IsJitOptimizationLevelRequested();
11271128

11281129
private:
11291130
// This function is not intended to be called in most places, and is named as such to discourage calling it accidentally

src/coreclr/vm/tieredcompilation.cpp

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ NativeCodeVersion::OptimizationTier TieredCompilationManager::GetInitialOptimiza
9898
return NativeCodeVersion::OptimizationTierOptimized;
9999
}
100100

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

107103
if (!pMethodDesc->GetLoaderAllocator()->GetCallCountingManager()->IsCallCountingEnabled(NativeCodeVersion(pMethodDesc)))
108104
{
@@ -1075,50 +1071,40 @@ CORJIT_FLAGS TieredCompilationManager::GetJitFlags(PrepareCodeConfig *config)
10751071
return flags;
10761072
}
10771073

1078-
NativeCodeVersion::OptimizationTier newOptimizationTier;
1079-
if (!methodDesc->RequestedAggressiveOptimization())
1074+
_ASSERT(!methodDesc->RequestedAggressiveOptimization());
1075+
1076+
if (g_pConfig->TieredCompilation_QuickJit())
10801077
{
10811078
NativeCodeVersion::OptimizationTier currentTier = nativeCodeVersion.GetOptimizationTier();
1082-
1083-
if (g_pConfig->TieredCompilation_QuickJit())
1079+
if (currentTier == NativeCodeVersion::OptimizationTier::OptimizationTier0Instrumented)
10841080
{
1085-
if (currentTier == NativeCodeVersion::OptimizationTier::OptimizationTier0Instrumented)
1086-
{
1087-
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR);
1088-
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER0);
1089-
return flags;
1090-
}
1091-
1092-
if (currentTier == NativeCodeVersion::OptimizationTier::OptimizationTier1Instrumented)
1093-
{
1094-
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR);
1095-
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER1);
1096-
return flags;
1097-
}
1098-
1099-
_ASSERTE(!nativeCodeVersion.IsFinalTier());
1081+
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR);
11001082
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER0);
1101-
if (g_pConfig->TieredPGO() && g_pConfig->TieredPGO_InstrumentOnlyHotCode())
1102-
{
1103-
// If we plan to only instrument hot code we have to make an exception
1104-
// for cold methods with loops so if those self promote to OSR they need
1105-
// some profile to optimize, so here we allow JIT to enable instrumentation
1106-
// if current method has loops and is eligible for OSR.
1107-
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR_IF_LOOPS);
1108-
}
11091083
return flags;
11101084
}
11111085

1112-
newOptimizationTier = NativeCodeVersion::OptimizationTierOptimized;
1113-
}
1114-
else
1115-
{
1116-
newOptimizationTier = NativeCodeVersion::OptimizationTier1;
1117-
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER1);
1086+
if (currentTier == NativeCodeVersion::OptimizationTier::OptimizationTier1Instrumented)
1087+
{
1088+
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR);
1089+
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER1);
1090+
return flags;
1091+
}
1092+
1093+
_ASSERTE(!nativeCodeVersion.IsFinalTier());
1094+
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_TIER0);
1095+
if (g_pConfig->TieredPGO() && g_pConfig->TieredPGO_InstrumentOnlyHotCode())
1096+
{
1097+
// If we plan to only instrument hot code we have to make an exception
1098+
// for cold methods with loops so if those self promote to OSR they need
1099+
// some profile to optimize, so here we allow JIT to enable instrumentation
1100+
// if current method has loops and is eligible for OSR.
1101+
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_BBINSTR_IF_LOOPS);
1102+
}
1103+
return flags;
11181104
}
11191105

11201106
methodDesc->GetLoaderAllocator()->GetCallCountingManager()->DisableCallCounting(nativeCodeVersion);
1121-
nativeCodeVersion.SetOptimizationTier(newOptimizationTier);
1107+
nativeCodeVersion.SetOptimizationTier(NativeCodeVersion::OptimizationTierOptimized);
11221108
#ifdef FEATURE_INTERPRETER
11231109
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_MAKEFINALCODE);
11241110
#endif

0 commit comments

Comments
 (0)