Skip to content

Commit

Permalink
JIT: random partial compilation stress mode (#107561)
Browse files Browse the repository at this point in the history
When JitRandomPartialCompilation is nonzero, allow partial compilation patchpoints at
the start of randomly chosen patchpoint-eligible blocks.

Enable this stress mode in the jit-experimental pipeline.
  • Loading branch information
AndyAyersMS authored Sep 13, 2024
1 parent cf9c995 commit f722e5c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions eng/pipelines/common/templates/runtimes/run-test-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ jobs:
scenarios:
- jitosr_stress
- jitpartialcompilation_pgo
- jitpartialcompilation_pgo_stress_random
- jitoptrepeat
- jitoldlayout
${{ else }}:
Expand All @@ -548,6 +549,7 @@ jobs:
- jit_stress_splitting
- jitpartialcompilation
- jitpartialcompilation_pgo
- jitpartialcompilation_pgo_stress_random
- jitobjectstackallocation
- jitphysicalpromotion_only
- jitphysicalpromotion_full
Expand Down
31 changes: 25 additions & 6 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6238,17 +6238,36 @@ void Compiler::impImportBlockCode(BasicBlock* block)
//
// Note unlike OSR, it's ok to forgo these.
//
// Todo: stress mode...
//
if (opts.jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0) && (JitConfig.TC_PartialCompilation() > 0) &&
compCanHavePatchpoints() && !compTailPrefixSeen)
compCanHavePatchpoints() && !compTailPrefixSeen && (verCurrentState.esStackDepth == 0) &&
!block->HasFlag(BBF_PATCHPOINT) && !block->hasHndIndex())
{
// Is this block a good place for partial compilation?
//
if ((block != fgFirstBB) && block->isRunRarely() && (verCurrentState.esStackDepth == 0) &&
!block->HasFlag(BBF_PATCHPOINT) && !block->hasHndIndex())
bool addPartialCompilationPatchpoint = (block != fgFirstBB) && block->isRunRarely();

#ifdef DEBUG
// Stress mode
//
const char* reason = "rarely run";
const int randomPartialCompilation = JitConfig.JitRandomPartialCompilation();
if (randomPartialCompilation > 0)
{
// Reuse the random inliner's random state.
// Note m_inlineStrategy is always created, even if we're not inlining.
//
CLRRandom* const random = impInlineRoot()->m_inlineStrategy->GetRandom(randomPartialCompilation);
const int randomValue = (int)random->Next(100);

addPartialCompilationPatchpoint = (randomValue < randomPartialCompilation);
reason = "randomly chosen";
}
#endif

if (addPartialCompilationPatchpoint)
{
JITDUMP("\nBlock " FMT_BB " will be a partial compilation patchpoint -- not importing\n", block->bbNum);
JITDUMP("\nBlock " FMT_BB " (%s) will be a partial compilation patchpoint -- not importing\n", block->bbNum,
reason);
block->SetFlags(BBF_PARTIAL_COMPILATION_PATCHPOINT);
setMethodHasPartialCompilationPatchpoint();

Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/jitconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,9 @@ RELEASE_CONFIG_INTEGER(TC_OnStackReplacement_InitialCounter, W("TC_OnStackReplac
// Enable partial compilation for Tier0 methods
RELEASE_CONFIG_INTEGER(TC_PartialCompilation, W("TC_PartialCompilation"), 0)

// If partial compilation is enabled, use random heuristic for patchpoint placement
CONFIG_INTEGER(JitRandomPartialCompilation, W("JitRandomPartialCompilation"), 0)

// Patchpoint strategy:
// 0 - backedge sources
// 1 - backedge targets
Expand Down
2 changes: 2 additions & 0 deletions src/tests/Common/testenvironment.proj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
DOTNET_JitRandomGuardedDevirtualization;
DOTNET_JitRandomEdgeCounts;
DOTNET_JitRandomOnStackReplacement;
DOTNET_JitRandomPartialComplation;
DOTNET_JitRandomlyCollect64BitCounts;
DOTNET_JitStressModeNames;
DOTNET_JitGuardedDevirtualizationMaxTypeChecks;
Expand Down Expand Up @@ -225,6 +226,7 @@
<TestEnvironment Include="jit_stress_splitting" JitFakeProcedureSplitting="1" JitStressProcedureSplitting="1" />
<TestEnvironment Include="jitpartialcompilation" TC_PartialCompilation="1" TC_QuickJitForLoops="1" TieredCompilation="1" />
<TestEnvironment Include="jitpartialcompilation_pgo" TC_PartialCompilation="1" TC_QuickJitForLoops="1" TieredCompilation="1" TieredPGO="1" />
<TestEnvironment Include="jitpartialcompilation_pgo_stress_random" TC_PartialCompilation="1" TC_QuickJitForLoops="1" TieredCompilation="1" TieredPGO="1" JitRandomPartialCompilation="15" />
<TestEnvironment Include="jitobjectstackallocation" JitObjectStackAllocation="1" TieredCompilation="0" />
<TestEnvironment Include="jitphysicalpromotion_only" JitStressModeNames="STRESS_NO_OLD_PROMOTION" TieredCompilation="0" />
<TestEnvironment Include="jitphysicalpromotion_full" JitStressModeNames="STRESS_PHYSICAL_PROMOTION_COST STRESS_NO_OLD_PROMOTION" TieredCompilation="0" />
Expand Down

0 comments on commit f722e5c

Please sign in to comment.