Skip to content

JIT: Compute fgCalledCount after synthesis #112041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5398,9 +5398,9 @@ class Compiler
// - Rationalization links all nodes into linear form which is kept until
// the end of compilation. The first and last nodes are stored in the block.
NodeThreading fgNodeThreading = NodeThreading::None;
weight_t fgCalledCount = BB_ZERO_WEIGHT; // count of the number of times this method was called
// This is derived from the profile data
// or is BB_UNITY_WEIGHT when we don't have profile data
weight_t fgCalledCount = BB_UNITY_WEIGHT; // count of the number of times this method was called
// This is derived from the profile data
// or is BB_UNITY_WEIGHT when we don't have profile data

bool fgFuncletsCreated = false; // true if the funclet creation phase has been run

Expand Down
10 changes: 0 additions & 10 deletions src/coreclr/jit/fgprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4222,19 +4222,9 @@ PhaseStatus Compiler::fgComputeBlockWeights()

if (fgIsUsingProfileWeights())
{
// Compute fgCalledCount by subtracting any non-entry flow into fgFirstBB from its weight
fgCalledCount = fgFirstBB->bbWeight;
for (FlowEdge* const predEdge : fgFirstBB->PredEdges())
{
fgCalledCount = max(BB_ZERO_WEIGHT, fgCalledCount - predEdge->getLikelyWeight());
}

JITDUMP("We are using the profile weights and fgCalledCount is " FMT_WT "\n", fgCalledCount);
return PhaseStatus::MODIFIED_NOTHING;
}

JITDUMP(" -- no profile data, so using default called count\n");
fgCalledCount = BB_UNITY_WEIGHT;
return fgComputeMissingBlockWeights() ? PhaseStatus::MODIFIED_EVERYTHING : PhaseStatus::MODIFIED_NOTHING;
}

Expand Down
14 changes: 14 additions & 0 deletions src/coreclr/jit/fgprofilesynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ void ProfileSynthesis::Run(ProfileSynthesisOption option)
m_comp->Metrics.ProfileInconsistentInitially++;
}

// Derive the method's call count from the entry block's weight
//
if (m_comp->fgIsUsingProfileWeights() && !m_comp->compIsForInlining())
{
weight_t entryWeight = m_entryBlock->bbWeight;
for (FlowEdge* const predEdge : m_entryBlock->PredEdges())
{
entryWeight -= predEdge->getLikelyWeight();
}

m_comp->fgCalledCount = max(BB_ZERO_WEIGHT, entryWeight);
JITDUMP("fgCalledCount is " FMT_WT "\n", m_comp->fgCalledCount);
}

#ifdef DEBUG
// We want to assert that the profile is consistent.
// However, we need to defer asserting since invalid IL can
Expand Down
Loading