Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit de510bd

Browse files
authored
Merge pull request #6201 from AndyAyersMS/LowerCallsiteWeight
Inliner: updates to ModelPolicy
2 parents d4fc9b7 + ff2700a commit de510bd

File tree

2 files changed

+74
-3
lines changed

2 files changed

+74
-3
lines changed

src/jit/inlinepolicy.cpp

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,60 @@ ModelPolicy::ModelPolicy(Compiler* compiler, bool isPrejitRoot)
19131913
// Empty
19141914
}
19151915

1916+
//------------------------------------------------------------------------
1917+
// NoteInt: handle an observed integer value
1918+
//
1919+
// Arguments:
1920+
// obs - the current obsevation
1921+
// value - the value being observed
1922+
//
1923+
// Notes:
1924+
// The ILSize threshold used here should be large enough that
1925+
// it does not generally influence inlining decisions -- it only
1926+
// helps to make them faster.
1927+
//
1928+
// The value is determined as follows. We figure out the maximum
1929+
// possible code size estimate that will lead to an inline. This is
1930+
// found by determining the maximum possible inline benefit and
1931+
// working backwards.
1932+
//
1933+
// In the current ModelPolicy, the maximum benefit is -28.1, which
1934+
// comes from a CallSiteWeight of 3 and a per call benefit of
1935+
// -9.37. This implies that any candidate with code size larger
1936+
// than (28.1/0.2) will not pass the threshold. So maximum code
1937+
// size estimate (in bytes) for any inlinee is 140.55, and hence
1938+
// maximum estimate is 1405.
1939+
//
1940+
// Since we are trying to short circuit early in the evaluation
1941+
// process we don't have the code size estimate in hand. We need to
1942+
// estimate the possible code size estimate based on something we
1943+
// know cheaply and early -- the ILSize. So we use quantile
1944+
// regression to project how ILSize predicts the model code size
1945+
// estimate. Note that ILSize does not currently directly enter
1946+
// into the model.
1947+
//
1948+
// The median value for the model code size estimate based on
1949+
// ILSize is given by -107 + 12.6 * ILSize for the V9 data. This
1950+
// means an ILSize of 120 is likely to lead to a size estimate of
1951+
// at least 1405 at least 50% of the time. So we choose this as the
1952+
// early rejection threshold.
1953+
1954+
void ModelPolicy::NoteInt(InlineObservation obs, int value)
1955+
{
1956+
// Let underlying policy do its thing.
1957+
DiscretionaryPolicy::NoteInt(obs, value);
1958+
1959+
// Fail fast for inlinees that are too large to ever inline.
1960+
// The value of 120 is model-dependent; see notes above.
1961+
if (!m_IsForceInline &&
1962+
(obs == InlineObservation::CALLEE_IL_CODE_SIZE) &&
1963+
(value >= 120))
1964+
{
1965+
// Callee too big, not a candidate
1966+
SetNever(InlineObservation::CALLEE_TOO_MUCH_IL);
1967+
}
1968+
}
1969+
19161970
//------------------------------------------------------------------------
19171971
// DetermineProfitability: determine if this inline is profitable
19181972
//
@@ -1980,10 +2034,24 @@ void ModelPolicy::DetermineProfitability(CORINFO_METHOD_INFO* methodInfo)
19802034
// frequency, somehow.
19812035
double callSiteWeight = 1.0;
19822036

1983-
if ((m_CallsiteFrequency == InlineCallsiteFrequency::LOOP) ||
1984-
(m_CallsiteFrequency == InlineCallsiteFrequency::HOT))
2037+
switch (m_CallsiteFrequency)
19852038
{
1986-
callSiteWeight = 8.0;
2039+
case InlineCallsiteFrequency::RARE:
2040+
callSiteWeight = 0.1;
2041+
break;
2042+
case InlineCallsiteFrequency::BORING:
2043+
callSiteWeight = 1.0;
2044+
break;
2045+
case InlineCallsiteFrequency::WARM:
2046+
callSiteWeight = 1.5;
2047+
break;
2048+
case InlineCallsiteFrequency::LOOP:
2049+
case InlineCallsiteFrequency::HOT:
2050+
callSiteWeight = 3.0;
2051+
break;
2052+
default:
2053+
assert(false);
2054+
break;
19872055
}
19882056

19892057
// Determine the estimated number of instructions saved per

src/jit/inlinepolicy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ class ModelPolicy : public DiscretionaryPolicy
297297
// Construct a ModelPolicy
298298
ModelPolicy(Compiler* compiler, bool isPrejitRoot);
299299

300+
// Policy observations
301+
void NoteInt(InlineObservation obs, int value) override;
302+
300303
// Policy determinations
301304
void DetermineProfitability(CORINFO_METHOD_INFO* methodInfo) override;
302305

0 commit comments

Comments
 (0)