JIT: Continue profile consistency checks until after finally cloning (#109792)

Part of #107749. The next few opt phases alter flow substantially, such that we need to propagate new weight throughout the flowgraph. That will probably justify running profile synthesis after, in a later PR.
This commit is contained in:
Aman Khalid 2024-11-19 22:01:44 +00:00 коммит произвёл GitHub
Родитель 7eecb045f7
Коммит 1e3544ec04
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 29 добавлений и 14 удалений

Просмотреть файл

@ -4609,11 +4609,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
// Record "start" values for post-inlining cycles and elapsed time.
RecordStateAtEndOfInlining();
// Drop back to just checking profile likelihoods.
//
activePhaseChecks &= ~PhaseChecks::CHECK_PROFILE;
activePhaseChecks |= PhaseChecks::CHECK_LIKELIHOODS;
if (opts.OptimizationEnabled())
{
// Build post-order and remove dead blocks
@ -4658,6 +4653,11 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
//
DoPhase(this, PHASE_CLONE_FINALLY, &Compiler::fgCloneFinally);
// Drop back to just checking profile likelihoods.
//
activePhaseChecks &= ~PhaseChecks::CHECK_PROFILE;
activePhaseChecks |= PhaseChecks::CHECK_LIKELIHOODS;
// Do some flow-related optimizations
//
if (opts.OptimizationEnabled())

Просмотреть файл

@ -1038,8 +1038,27 @@ PhaseStatus Compiler::fgCloneFinally()
const unsigned finallyTryIndex = firstBlock->bbTryIndex;
BasicBlock* insertAfter = nullptr;
BlockToBlockMap blockMap(getAllocator());
unsigned cloneBBCount = 0;
weight_t const originalWeight = firstBlock->hasProfileWeight() ? firstBlock->bbWeight : BB_ZERO_WEIGHT;
unsigned cloneBBCount = 0;
weight_t originalWeight;
// When distributing weight between the original and cloned regions,
// ensure only weight from region entries is considered.
// Flow from loop backedges within the region should not influence the weight distribution ratio.
if (firstBlock->hasProfileWeight())
{
originalWeight = firstBlock->bbWeight;
for (BasicBlock* const predBlock : firstBlock->PredBlocks())
{
if (!predBlock->KindIs(BBJ_CALLFINALLY))
{
originalWeight = max(0.0, originalWeight - predBlock->bbWeight);
}
}
}
else
{
originalWeight = BB_ZERO_WEIGHT;
}
for (BasicBlock* block = firstBlock; block != nextBlock; block = block->Next())
{

Просмотреть файл

@ -1401,15 +1401,8 @@ void Compiler::fgAddSyncMethodEnterExit()
// Create a block for the start of the try region, where the monitor enter call
// will go.
BasicBlock* const tryBegBB = fgSplitBlockAtEnd(fgFirstBB);
BasicBlock* const tryNextBB = tryBegBB->Next();
BasicBlock* const tryLastBB = fgLastBB;
// If we have profile data the new block will inherit the next block's weight
if (tryNextBB->hasProfileWeight())
{
tryBegBB->inheritWeight(tryNextBB);
}
// Create a block for the fault.
// It gets an artificial ref count.

Просмотреть файл

@ -673,6 +673,9 @@ unsigned int ObjectAllocator::MorphAllocObjNodeIntoStackAlloc(
if (predBlock->hasProfileWeight())
{
block->setBBProfileWeight(predBlock->bbWeight);
JITDUMP("Profile weight into " FMT_BB " needs to be propagated to successors. Profile %s inconsistent.\n",
block->bbNum, comp->fgPgoConsistent ? "is now" : "was already");
comp->fgPgoConsistent = false;
}
// Just lop off the JTRUE, the rest can clean up later