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

Commit 06ee8cd

Browse files
committed
Inliner: Update data collection by targeting a single inline
The inliner currently will record detailed data about the last successful inline performed (given a build with DEBUG or INLINE_DATA defined). However, for purposes of inline profitability analysis we might be more interested in the data from an earlier inline. This change creates a mechanism where the replay log can flag one inline per method as the target of data collection. The inliner checks for this attribute during replay and captures that inline's data.
1 parent 60ae03f commit 06ee8cd

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

src/jit/inline.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,8 +955,23 @@ void InlineStrategy::NoteOutcome(InlineContext* context)
955955

956956
#if defined(DEBUG) || defined(INLINE_DATA)
957957

958-
m_LastContext = context;
959-
m_LastSuccessfulPolicy = context->m_Policy;
958+
// Keep track of the inline targeted for data collection or,
959+
// if we don't have one (yet), the last successful inline.
960+
bool updateLast =
961+
(m_LastSuccessfulPolicy == nullptr) ||
962+
!m_LastSuccessfulPolicy->IsDataCollectionTarget();
963+
964+
if (updateLast)
965+
{
966+
m_LastContext = context;
967+
m_LastSuccessfulPolicy = context->m_Policy;
968+
}
969+
else
970+
{
971+
// We only expect one inline to be a data collection
972+
// target.
973+
assert(!context->m_Policy->IsDataCollectionTarget());
974+
}
960975

961976
#endif // defined(DEBUG) || defined(INLINE_DATA)
962977

src/jit/inline.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ class InlinePolicy
256256
virtual void DumpData(FILE* file) const { }
257257
// Detailed data name dump
258258
virtual void DumpSchema(FILE* file) const { }
259+
// True if this is the inline targeted by data collection
260+
bool IsDataCollectionTarget() { return m_IsDataCollectionTarget; }
259261

260262
#endif // defined(DEBUG) || defined(INLINE_DATA)
261263

@@ -265,6 +267,10 @@ class InlinePolicy
265267
: m_Decision(InlineDecision::UNDECIDED)
266268
, m_Observation(InlineObservation::CALLEE_UNUSED_INITIAL)
267269
, m_IsPrejitRoot(isPrejitRoot)
270+
#if defined(DEBUG) || defined(INLINE_DATA)
271+
, m_IsDataCollectionTarget(false)
272+
#endif // defined(DEBUG) || defined(INLINE_DATA)
273+
268274
{
269275
// empty
270276
}
@@ -280,6 +286,12 @@ class InlinePolicy
280286
InlineDecision m_Decision;
281287
InlineObservation m_Observation;
282288
bool m_IsPrejitRoot;
289+
290+
#if defined(DEBUG) || defined(INLINE_DATA)
291+
292+
bool m_IsDataCollectionTarget;
293+
294+
#endif // defined(DEBUG) || defined(INLINE_DATA)
283295
};
284296

285297
// InlineResult summarizes what is known about the viability of a

src/jit/inlinepolicy.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ void ModelPolicy::DetermineProfitability(CORINFO_METHOD_INFO* methodInfo)
20382038
// positive be better and negative worse.
20392039
double perCallBenefit = -((double) m_PerCallInstructionEstimate / (double) m_ModelCodeSizeEstimate);
20402040

2041-
// Now estimate the local call frequency.
2041+
// Now estimate the local call frequency.
20422042
//
20432043
// Todo: use IBC data, or a better local profile estimate, or
20442044
// try and incorporate this into the model. For instance if we
@@ -2072,8 +2072,8 @@ void ModelPolicy::DetermineProfitability(CORINFO_METHOD_INFO* methodInfo)
20722072
// is our benefit figure of merit.
20732073
double benefit = callSiteWeight * perCallBenefit;
20742074

2075-
// Compare this to the threshold, and inline if greater.
2076-
//
2075+
// Compare this to the threshold, and inline if greater.
2076+
//
20772077
// The threshold is interpretable as a size/speed tradeoff:
20782078
// the value of 0.2 below indicates we'll allow inlines that
20792079
// grow code by as many as 5 bytes to save 1 instruction
@@ -2583,6 +2583,22 @@ bool ReplayPolicy::FindInline(unsigned token, unsigned hash, unsigned offset)
25832583

25842584
// We're good!
25852585
foundInline = true;
2586+
2587+
// Check for a data collection marker. This does not affect
2588+
// matching...
2589+
2590+
// Get next line
2591+
if (fgets(buffer, sizeof(buffer), s_ReplayFile) != nullptr)
2592+
{
2593+
unsigned collectData = 0;
2594+
count = sscanf(buffer, " <CollectData>%u</CollectData> ", &collectData);
2595+
2596+
if (count == 1)
2597+
{
2598+
m_IsDataCollectionTarget = (collectData == 1);
2599+
}
2600+
}
2601+
25862602
break;
25872603
}
25882604

0 commit comments

Comments
 (0)