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

Commit 82ec59e

Browse files
committed
Inliner refactoring: consolidate logging, reporting and dumping
With this change the responsibility for dumping, logging, and reporting inline decisions is moved into the JitInlineResult class instead of being distributed throughout the code base. This insures all the relevant inline information is handled in a consistent manner. The JitInlineResult is updated to hold a compiler instance and now requires a context string describing the what the jit is doing as it evaluates an inline candidate. There are 4 distinct contexts in use currently.
1 parent 6b039c4 commit 82ec59e

File tree

5 files changed

+197
-289
lines changed

5 files changed

+197
-289
lines changed

src/jit/compiler.cpp

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,7 +4282,6 @@ int Compiler::compCompile(CORINFO_METHOD_HANDLE methodHnd,
42824282
{
42834283
if (compIsForInlining())
42844284
{
4285-
JITLOG((LL_INFO1000000, INLINER_FAILED "Inlinee marked as skipped.\n"));
42864285
compInlineResult->setNever("Inlinee marked as skipped");
42874286
}
42884287
return CORJIT_SKIPPED;
@@ -4891,7 +4890,7 @@ int Compiler::compCompileHelper (CORINFO_MODULE_HANDLE clas
48914890
if (opts.eeFlags & CORJIT_FLG_PREJIT)
48924891
{
48934892
// Cache inlining hint during NGen to avoid touching bodies of non-inlineable methods at runtime
4894-
JitInlineResult trialResult(info.compCompHnd, nullptr, methodHnd);
4893+
JitInlineResult trialResult(this, nullptr, methodHnd, "prejit1");
48954894
impCanInlineIL(methodHnd, methodInfo, forceInline, &trialResult);
48964895
if (trialResult.isFailure())
48974896
{
@@ -4937,7 +4936,7 @@ int Compiler::compCompileHelper (CORINFO_MODULE_HANDLE clas
49374936
assert(compNativeSizeEstimate != NATIVE_SIZE_INVALID);
49384937

49394938
int callsiteNativeSizeEstimate = impEstimateCallsiteNativeSize(methodInfo);
4940-
JitInlineResult trialResult(info.compCompHnd, nullptr, methodHnd);
4939+
JitInlineResult trialResult(this, nullptr, methodHnd, "prejit2");
49414940

49424941
impCanInlineNative(callsiteNativeSizeEstimate,
49434942
compNativeSizeEstimate,
@@ -5000,7 +4999,6 @@ int Compiler::compCompileHelper (CORINFO_MODULE_HANDLE clas
50004999
(fgBBcount > 5) &&
50015000
!forceInline)
50025001
{
5003-
JITLOG((LL_INFO1000000, INLINER_FAILED "Too many basic blocks in the inlinee.\n"));
50045002
compInlineResult->setNever("Too many basic blocks in the inlinee");
50055003
goto _Next;
50065004
}
@@ -9750,3 +9748,48 @@ HelperCallProperties Compiler::s_helperCallProperties;
97509748

97519749
/*****************************************************************************/
97529750
/*****************************************************************************/
9751+
9752+
//------------------------------------------------------------------------
9753+
// report: Dump, log, and report information about an inline decision.
9754+
//
9755+
// Notes:
9756+
//
9757+
// Called (automatically via the JitInlineResult dtor) when the inliner
9758+
// is done evaluating a candidate.
9759+
//
9760+
// Dumps state of the inline candidate, and if a decision was reached
9761+
// sends it to the log and reports the decision back to the EE.
9762+
//
9763+
// All this can be suppressed if desired by calling setReported() before
9764+
// the JitInlineResult goes out of scope.
9765+
9766+
void JitInlineResult::report()
9767+
{
9768+
// User may have suppressed reporting via setReported(). If so, do nothing.
9769+
if (inlReported)
9770+
{
9771+
return;
9772+
}
9773+
9774+
inlReported = true;
9775+
9776+
#ifdef DEBUG
9777+
9778+
const char* format = "INLINER: during '%s' result '%s' reason '%s' for '%s' calling '%s'\n";
9779+
const char* caller = (inlInliner == nullptr) ? "n/a" : inlCompiler->eeGetMethodFullName(inlInliner);
9780+
const char* callee = (inlInlinee == nullptr) ? "n/a" : inlCompiler->eeGetMethodFullName(inlInlinee);
9781+
9782+
JITDUMP(format, inlContext, resultString(), inlReason, caller, callee);
9783+
9784+
#endif // DEBUG
9785+
9786+
if (isDecided())
9787+
{
9788+
JITLOG_THIS(inlCompiler, (LL_INFO100000, format, inlContext, resultString(), inlReason, caller, callee));
9789+
COMP_HANDLE comp = inlCompiler->info.compCompHnd;
9790+
comp->reportInliningDecision(inlInliner, inlInlinee, result(), inlReason);
9791+
}
9792+
}
9793+
9794+
9795+

src/jit/compiler.h

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -878,14 +878,16 @@ class JitInlineResult
878878
public:
879879

880880
// Construct a new JitInlineResult.
881-
JitInlineResult(COMP_HANDLE compiler,
881+
JitInlineResult(Compiler* compiler,
882882
CORINFO_METHOD_HANDLE inliner,
883-
CORINFO_METHOD_HANDLE inlinee)
884-
: inlComp(compiler)
883+
CORINFO_METHOD_HANDLE inlinee,
884+
const char* context)
885+
: inlCompiler(compiler)
885886
, inlDecision(InlineDecision::UNDECIDED)
886887
, inlInliner(inliner)
887888
, inlInlinee(inlinee)
888889
, inlReason(nullptr)
890+
, inlContext(context)
889891
, inlReported(false)
890892
{
891893
// empty
@@ -910,6 +912,26 @@ class JitInlineResult
910912
}
911913
}
912914

915+
// Translate into string for dumping
916+
const char* resultString() const
917+
{
918+
switch (inlDecision) {
919+
case InlineDecision::SUCCESS:
920+
return "success";
921+
case InlineDecision::FAILURE:
922+
return "failed this call site";
923+
case InlineDecision::NEVER:
924+
return "failed this callee";
925+
case InlineDecision::CANDIDATE:
926+
return "candidate";
927+
case InlineDecision::UNDECIDED:
928+
return "undecided";
929+
default:
930+
assert(!"Unexpected: interim inline result");
931+
unreached();
932+
}
933+
}
934+
913935
// True if this definitely a failed inline candidate
914936
bool isFailure() const
915937
{
@@ -1012,7 +1034,7 @@ class JitInlineResult
10121034
setCommon(InlineDecision::NEVER, reason);
10131035
}
10141036

1015-
// Report decision, if necessary.
1037+
// Report/log/dump decision as appropriate
10161038
~JitInlineResult()
10171039
{
10181040
report();
@@ -1021,7 +1043,7 @@ class JitInlineResult
10211043
const char * reason() const { return inlReason; }
10221044

10231045
// setReported indicates that this particular result doesn't need
1024-
// to be reported back to the runtime, either becaus the runtime
1046+
// to be reported back to the runtime, either because the runtime
10251047
// already knows, or we weren't actually inlining yet.
10261048
void setReported() { inlReported = true; }
10271049

@@ -1038,21 +1060,15 @@ class JitInlineResult
10381060
inlDecision = decision;
10391061
inlReason = reason;
10401062
}
1041-
1042-
void report()
1043-
{
1044-
if (!inlReported && isDecided())
1045-
{
1046-
inlComp->reportInliningDecision(inlInliner, inlInlinee, result(), inlReason);
1047-
}
1048-
inlReported = true;
1049-
}
1050-
1051-
COMP_HANDLE inlComp;
1063+
1064+
void report();
1065+
1066+
Compiler* inlCompiler;
10521067
InlineDecision inlDecision;
10531068
CORINFO_METHOD_HANDLE inlInliner;
10541069
CORINFO_METHOD_HANDLE inlInlinee;
10551070
const char* inlReason;
1071+
const char* inlContext;
10561072
bool inlReported;
10571073
};
10581074

src/jit/flowgraph.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22053,9 +22053,6 @@ void Compiler::fgInvokeInlineeCompiler(GenTreeCall* call,
2205322053
if (!(info.compCompHnd->initClass(NULL /* field */, fncHandle /* method */,
2205422054
inlineCandidateInfo->exactContextHnd /* context */) & CORINFO_INITCLASS_INITIALIZED))
2205522055
{
22056-
JITLOG((LL_INFO100000, INLINER_FAILED "Could not complete class init side effect: "
22057-
"%s called by %s\n",
22058-
eeGetMethodFullName(fncHandle), info.compFullName));
2205922056
inlineResult->setNever("Failed class init side-effect");
2206022057
return;
2206122058
}

0 commit comments

Comments
 (0)