1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-11 18:20:26 +09:00

JIT: Remove hasLikelihood checks; make FlowEdge::m_likelihoodSet debug-only (#99925)

Part of #93020. Now that edge likelihoods are expected to be set throughout all phases, when transferring the likelihood of an existing edge to a new edge, we should assume the former edge's likelihood should already be set. By removing all non-debug conditional logic that uses hasLikelihood, we can make m_likelihoodSet available only in Debug builds again.
This commit is contained in:
Aman Khalid 2024-03-20 20:09:33 +00:00 committed by GitHub
parent 682d1c7dad
commit 21bfbd5763
Signed by: github
GPG key ID: B5690EEEBB952194
6 changed files with 31 additions and 30 deletions

View file

@ -80,6 +80,7 @@ void FlowEdge::setLikelihood(weight_t likelihood)
assert(likelihood >= 0.0); assert(likelihood >= 0.0);
assert(likelihood <= 1.0); assert(likelihood <= 1.0);
#ifdef DEBUG
if (m_likelihoodSet) if (m_likelihoodSet)
{ {
JITDUMP("setting likelihood of " FMT_BB " -> " FMT_BB " from " FMT_WT " to " FMT_WT "\n", m_sourceBlock->bbNum, JITDUMP("setting likelihood of " FMT_BB " -> " FMT_BB " from " FMT_WT " to " FMT_WT "\n", m_sourceBlock->bbNum,
@ -92,7 +93,9 @@ void FlowEdge::setLikelihood(weight_t likelihood)
} }
m_likelihoodSet = true; m_likelihoodSet = true;
m_likelihood = likelihood; #endif // DEBUG
m_likelihood = likelihood;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------

View file

@ -594,7 +594,7 @@ private:
unsigned m_dupCount; unsigned m_dupCount;
// True if likelihood has been set // True if likelihood has been set
bool m_likelihoodSet; INDEBUG(bool m_likelihoodSet);
public: public:
FlowEdge(BasicBlock* sourceBlock, BasicBlock* destBlock, FlowEdge* rest) FlowEdge(BasicBlock* sourceBlock, BasicBlock* destBlock, FlowEdge* rest)
@ -605,7 +605,9 @@ public:
, m_edgeWeightMax(0) , m_edgeWeightMax(0)
, m_likelihood(0) , m_likelihood(0)
, m_dupCount(0) , m_dupCount(0)
#ifdef DEBUG
, m_likelihoodSet(false) , m_likelihoodSet(false)
#endif // DEBUG
{ {
} }
@ -668,6 +670,7 @@ public:
weight_t getLikelihood() const weight_t getLikelihood() const
{ {
assert(m_likelihoodSet);
return m_likelihood; return m_likelihood;
} }
@ -676,14 +679,16 @@ public:
void clearLikelihood() void clearLikelihood()
{ {
m_likelihood = 0.0; m_likelihood = 0.0;
m_likelihoodSet = false; INDEBUG(m_likelihoodSet = false);
} }
#ifdef DEBUG
bool hasLikelihood() const bool hasLikelihood() const
{ {
return m_likelihoodSet; return m_likelihoodSet;
} }
#endif // DEBUG
weight_t getLikelyWeight() const; weight_t getLikelyWeight() const;

View file

@ -730,10 +730,7 @@ void Compiler::fgReplaceJumpTarget(BasicBlock* block, BasicBlock* oldTarget, Bas
assert(newEdge->getSourceBlock() == block); assert(newEdge->getSourceBlock() == block);
assert(newEdge->getDestinationBlock() == newTarget); assert(newEdge->getDestinationBlock() == newTarget);
if (newEdge->hasLikelihood() && oldEdge->hasLikelihood()) newEdge->addLikelihood(oldEdge->getLikelihood());
{
newEdge->addLikelihood(oldEdge->getLikelihood());
}
} }
assert(changed); assert(changed);

View file

@ -185,9 +185,9 @@ FlowEdge* Compiler::fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, FlowE
{ {
block->bbLastPred = flow; block->bbLastPred = flow;
} }
else if ((oldEdge != nullptr) && oldEdge->hasLikelihood()) else if (oldEdge != nullptr)
{ {
// Copy likelihood from old edge, if any. // Copy likelihood from old edge.
// //
flow->setLikelihood(oldEdge->getLikelihood()); flow->setLikelihood(oldEdge->getLikelihood());
} }

View file

@ -1837,23 +1837,21 @@ bool Compiler::fgOptimizeSwitchBranches(BasicBlock* block)
// Update edge likelihoods // Update edge likelihoods
// Note old edge may still be "in use" so we decrease its likelihood. // Note old edge may still be "in use" so we decrease its likelihood.
// //
if (oldEdge->hasLikelihood())
// We want to move this much likelihood from old->new
//
const weight_t likelihoodFraction = oldEdge->getLikelihood() / (oldEdge->getDupCount() + 1);
if (newEdge->getDupCount() == 1)
{ {
// We want to move this much likelihood from old->new newEdge->setLikelihood(likelihoodFraction);
//
const weight_t likelihoodFraction = oldEdge->getLikelihood() / (oldEdge->getDupCount() + 1);
if (newEdge->getDupCount() == 1)
{
newEdge->setLikelihood(likelihoodFraction);
}
else
{
newEdge->addLikelihood(likelihoodFraction);
}
oldEdge->addLikelihood(-likelihoodFraction);
} }
else
{
newEdge->addLikelihood(likelihoodFraction);
}
oldEdge->addLikelihood(-likelihoodFraction);
// we optimized a Switch label - goto REPEAT_SWITCH to follow this new jump // we optimized a Switch label - goto REPEAT_SWITCH to follow this new jump
modified = true; modified = true;

View file

@ -603,8 +603,7 @@ private:
assert(prevCheckBlock->KindIs(BBJ_ALWAYS)); assert(prevCheckBlock->KindIs(BBJ_ALWAYS));
assert(prevCheckBlock->JumpsToNext()); assert(prevCheckBlock->JumpsToNext());
FlowEdge* const prevCheckThenEdge = prevCheckBlock->GetTargetEdge(); FlowEdge* const prevCheckThenEdge = prevCheckBlock->GetTargetEdge();
assert(prevCheckThenEdge->hasLikelihood()); weight_t checkLikelihood = max(0.0, 1.0 - prevCheckThenEdge->getLikelihood());
weight_t checkLikelihood = max(0.0, 1.0 - prevCheckThenEdge->getLikelihood());
JITDUMP("Level %u Check block " FMT_BB " success likelihood " FMT_WT "\n", checkIdx, checkBlock->bbNum, JITDUMP("Level %u Check block " FMT_BB " success likelihood " FMT_WT "\n", checkIdx, checkBlock->bbNum,
checkLikelihood); checkLikelihood);
@ -1086,9 +1085,8 @@ private:
// just use that to figure out the "else" likelihood. // just use that to figure out the "else" likelihood.
// //
assert(checkBlock->KindIs(BBJ_ALWAYS)); assert(checkBlock->KindIs(BBJ_ALWAYS));
FlowEdge* const checkThenEdge = checkBlock->GetTargetEdge(); FlowEdge* const checkThenEdge = checkBlock->GetTargetEdge();
assert(checkThenEdge->hasLikelihood()); weight_t elseLikelihood = max(0.0, 1.0 - checkThenEdge->getLikelihood());
weight_t elseLikelihood = max(0.0, 1.0 - checkThenEdge->getLikelihood());
// CheckBlock flows into elseBlock unless we deal with the case // CheckBlock flows into elseBlock unless we deal with the case
// where we know the last check is always true (in case of "exact" GDV) // where we know the last check is always true (in case of "exact" GDV)