Skip to content

Commit eb76787

Browse files
authored
JIT: Enable edge based profiles for all scenarios (#80481)
Enable edge based profiles for OSR, partial compilation, and optimized plus instrumented cases. For OSR this requires deferring flow graph modifications until after we have built the initial probe list, so that the initial list reflects the entirety of the method. This set of candidate edge probes is thus the same no matter how the method is compiled. A given compile may schematize a subset of these probes and materialize a subset of what gets schematized; this is tolerated by the PGO mechanism provided that the initial instrumented jitting produces a schema which is a superset of the schema produced by any subsequent instrumented rejitting. This is normally the case. Partial compilation may still need some work to ensure full schematization but it is currently off by default. Will address this subsequently. For optimized compiles we give the EfficientEdgeCountInstrumentor the same kind of probe relocation abilities that we have in the BlockCountInstrumentor. In particular we need to move probes that might appear in return blocks that follow implicit tail call blocks, since those return blocks must remain empty. The details on how we do this are a bit different but the idea is the same: we create duplicate copies of any probe that was going to appear in the return block and instead instrument each pred. If the pred reached the return via a critical edge, we split the edge and put the probe there. This analysis relies on cheap preds, so to ensure we can use them we move all the critial edge splitting so it happens before we need the cheap pred lists. The ability to do block profiling is retained but will no longer be used without special config settings. There were also a few bug fixes in the spanning tree visitor. It must visit a superset of the blocks we end up importing and was missing visits in some cases. This should improve jit time and code quality for instrumented code. Fixes #47942. Fixes #66101. Contributes to #74873.
1 parent 8a5b42f commit eb76787

File tree

3 files changed

+676
-263
lines changed

3 files changed

+676
-263
lines changed

src/coreclr/jit/compiler.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -4389,6 +4389,13 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
43894389
DoPhase(this, PHASE_IBCPREP, &Compiler::fgPrepareToInstrumentMethod);
43904390
}
43914391

4392+
// If we are doing OSR, update flow to initially reach the appropriate IL offset.
4393+
//
4394+
if (opts.IsOSR())
4395+
{
4396+
fgFixEntryFlowForOSR();
4397+
}
4398+
43924399
// Enable the post-phase checks that use internal logic to decide when checking makes sense.
43934400
//
43944401
activePhaseChecks = PhaseChecks::CHECK_EH | PhaseChecks::CHECK_LOOPS | PhaseChecks::CHECK_UNIQUE |
@@ -4398,17 +4405,17 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
43984405
//
43994406
DoPhase(this, PHASE_IMPORTATION, &Compiler::fgImport);
44004407

4401-
// Expand any patchpoints
4402-
//
4403-
DoPhase(this, PHASE_PATCHPOINTS, &Compiler::fgTransformPatchpoints);
4404-
44054408
// If instrumenting, add block and class probes.
44064409
//
44074410
if (compileFlags->IsSet(JitFlags::JIT_FLAG_BBINSTR))
44084411
{
44094412
DoPhase(this, PHASE_IBCINSTR, &Compiler::fgInstrumentMethod);
44104413
}
44114414

4415+
// Expand any patchpoints
4416+
//
4417+
DoPhase(this, PHASE_PATCHPOINTS, &Compiler::fgTransformPatchpoints);
4418+
44124419
// Transform indirect calls that require control flow expansion.
44134420
//
44144421
DoPhase(this, PHASE_INDXCALL, &Compiler::fgTransformIndirectCalls);
@@ -6594,13 +6601,6 @@ int Compiler::compCompileHelper(CORINFO_MODULE_HANDLE classPtr,
65946601
{
65956602
// We are jitting the root method, or inlining.
65966603
fgFindBasicBlocks();
6597-
6598-
// If we are doing OSR, update flow to initially reach the appropriate IL offset.
6599-
//
6600-
if (opts.IsOSR())
6601-
{
6602-
fgFixEntryFlowForOSR();
6603-
}
66046604
}
66056605

66066606
// If we're inlining and the candidate is bad, bail out.

src/coreclr/jit/fgbasic.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -3621,6 +3621,11 @@ void Compiler::fgFixEntryFlowForOSR()
36213621
fgFirstBB->bbJumpDest = osrEntry;
36223622
fgAddRefPred(osrEntry, fgFirstBB);
36233623

3624+
// Give the method entry (which will be a scratch BB)
3625+
// the same weight as the OSR Entry.
3626+
//
3627+
fgFirstBB->inheritWeight(fgOSREntryBB);
3628+
36243629
JITDUMP("OSR: redirecting flow at entry from entry " FMT_BB " to OSR entry " FMT_BB " for the importer\n",
36253630
fgFirstBB->bbNum, osrEntry->bbNum);
36263631
}

0 commit comments

Comments
 (0)