Skip to content
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

JIT: add concept of edge likelihood #81738

Merged
merged 1 commit into from
Feb 9, 2023
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
41 changes: 40 additions & 1 deletion src/coreclr/jit/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -1800,12 +1800,25 @@ struct FlowEdge
weight_t m_edgeWeightMin;
weight_t m_edgeWeightMax;

// Likelihood that m_sourceBlock transfers control along this edge.
// Values in range [0..1]
weight_t m_likelihood;

// The count of duplicate "edges" (used for switch stmts or degenerate branches)
unsigned m_dupCount;

#ifdef DEBUG
bool m_likelihoodSet;
#endif

public:
FlowEdge(BasicBlock* block, FlowEdge* rest)
: m_nextPredEdge(rest), m_sourceBlock(block), m_edgeWeightMin(0), m_edgeWeightMax(0), m_dupCount(0)
: m_nextPredEdge(rest)
, m_sourceBlock(block)
, m_edgeWeightMin(0)
, m_edgeWeightMax(0)
, m_likelihood(0)
, m_dupCount(0) DEBUGARG(m_likelihoodSet(false))
{
}

Expand Down Expand Up @@ -1852,6 +1865,32 @@ struct FlowEdge
bool setEdgeWeightMaxChecked(weight_t newWeight, BasicBlock* bDst, weight_t slop, bool* wbUsedSlop);
void setEdgeWeights(weight_t newMinWeight, weight_t newMaxWeight, BasicBlock* bDst);

weight_t getLikelihood() const
{
return m_likelihood;
}

void setLikelihood(weight_t likelihood)
{
assert(likelihood >= 0.0);
assert(likelihood <= 1.0);
INDEBUG(m_likelihoodSet = true);
m_likelihood = likelihood;
}

#ifdef DEBUG
bool hasLikelihood() const
{
return m_likelihoodSet;
}
#endif

weight_t getLikelyWeight() const
{
assert(m_likelihoodSet);
return m_likelihood * m_sourceBlock->bbWeight;
}

unsigned getDupCount() const
{
return m_dupCount;
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4385,6 +4385,7 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
// Note: the importer is sensitive to block weights, so this has
// to happen before importation.
//
activePhaseChecks |= PhaseChecks::CHECK_PROFILE;
DoPhase(this, PHASE_INCPROFILE, &Compiler::fgIncorporateProfileData);

// If we're going to instrument code, we may need to prepare before
Expand All @@ -4404,8 +4405,8 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl

// Enable the post-phase checks that use internal logic to decide when checking makes sense.
//
activePhaseChecks |= PhaseChecks::CHECK_EH | PhaseChecks::CHECK_LOOPS | PhaseChecks::CHECK_UNIQUE |
PhaseChecks::CHECK_PROFILE | PhaseChecks::CHECK_LINKED_LOCALS;
activePhaseChecks |=
PhaseChecks::CHECK_EH | PhaseChecks::CHECK_LOOPS | PhaseChecks::CHECK_UNIQUE | PhaseChecks::CHECK_LINKED_LOCALS;

// Import: convert the instrs in each basic block to a tree based intermediate representation
//
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ void Compiler::fgReplaceSwitchJumpTarget(BasicBlock* blockSwitch, BasicBlock* ne
//
FlowEdge* const newEdge = fgAddRefPred(newTarget, blockSwitch);

// Now set the correct value of newEdge's lDupCount
// Now set the correct value of newEdge's DupCount
// and replace any other jumps in jumpTab[] that go to oldTarget.
//
i++;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgdiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3635,7 +3635,7 @@ void Compiler::fgDebugCheckBlockLinks()
{
// Create a set with all the successors. Don't use BlockSet, so we don't need to worry
// about the BlockSet epoch.
BitVecTraits bitVecTraits(fgBBNumMax + 1, this);
BitVecTraits bitVecTraits(impInlineRoot()->fgBBNumMax + 1, this);
BitVec succBlocks(BitVecOps::MakeEmpty(&bitVecTraits));
for (BasicBlock* const bTarget : block->SwitchTargets())
{
Expand Down
Loading