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: Remove some fgRenumberBlocks calls #110026

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
18 changes: 9 additions & 9 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4761,13 +4761,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
};
DoPhase(this, PHASE_POST_MORPH, postMorphPhase);

// If we needed to create any new BasicBlocks then renumber the blocks
//
if (fgBBcount > preMorphBBCount)
{
fgRenumberBlocks();
}

// GS security checks for unsafe buffers
//
DoPhase(this, PHASE_GS_COOKIE, &Compiler::gsPhase);
Expand Down Expand Up @@ -4928,6 +4921,15 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl

if (doLoopHoisting)
{
if (doBranchOpt)
{
// bbNum quirk: RBO uses the current BB epoch size to determine if loop hoisting created blocks.
// Ensure the BB epoch is up to date before running loop hoisting to avoid false positives.
// TODO-bbNum: Either replace this check with a breadcrumb like 'fgModified',
// or relax jump threading's prerequisites.
EnsureBasicBlockEpoch();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, we should be able to get rid of RBO's dependency on block epoch altogether. Let me do that first.

}

// Hoist invariant code out of loops
//
DoPhase(this, PHASE_HOIST_LOOP_CODE, &Compiler::optHoistLoopCode);
Expand Down Expand Up @@ -5888,8 +5890,6 @@ void Compiler::RecomputeFlowGraphAnnotations()
// Recompute reachability sets, dominators, and loops.
optResetLoopInfo();

fgRenumberBlocks();
fgInvalidateDfsTree();
fgDfsBlocksAndRemove();
optFindLoops();

Expand Down
8 changes: 0 additions & 8 deletions src/coreclr/jit/fginline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,14 +913,6 @@ PhaseStatus Compiler::fgInline()

#endif // DEBUG

if (madeChanges)
{
// Optional quirk to keep this as zero diff. Some downstream phases are bbNum sensitive
// but rely on the ambient bbNums.
//
fgRenumberBlocks();
}

if (fgPgoConsistent)
{
Metrics.ProfileConsistentAfterInline++;
Expand Down
14 changes: 1 addition & 13 deletions src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,25 +752,13 @@ PhaseStatus Compiler::fgPostImportationCleanup()
}
}

// Did we alter any flow or EH?
//
const bool madeFlowChanges = (addedBlocks > 0) || (delCnt > 0) || (removedBlks > 0);

// Renumber the basic blocks if so.
//
if (madeFlowChanges)
{
JITDUMP("\nRenumbering the basic blocks for fgPostImportationCleanup\n");
fgRenumberBlocks();
}

#ifdef DEBUG
fgVerifyHandlerTab();
#endif // DEBUG

// Did we make any changes?
//
const bool madeChanges = madeFlowChanges || addedTemps;
const bool madeChanges = (addedBlocks > 0) || (delCnt > 0) || (removedBlks > 0) || addedTemps;

// Note that we have now run post importation cleanup,
// so we can enable more stringent checking.
Expand Down
7 changes: 1 addition & 6 deletions src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,8 @@ PhaseStatus Compiler::fgInsertGCPolls()
block = curBasicBlock;
}

// If we split a block to create a GC Poll, call fgUpdateChangedFlowGraph.
// We should never split blocks unless we're optimizing.
if (createdPollBlocks)
{
noway_assert(opts.OptimizationEnabled());
fgRenumberBlocks();
}
assert(!createdPollBlocks || opts.OptimizationEnabled());

return result;
}
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/jit/gschecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ PhaseStatus Compiler::gsPhase()
gsCopyShadowParams();
}

// If we needed to create any new BasicBlocks then renumber the blocks
if (fgBBcount > prevBBCount)
{
fgRenumberBlocks();
}

madeChanges = true;
}
else
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/jit/helperexpansion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,11 +1225,6 @@ PhaseStatus Compiler::fgExpandHelper(bool skipRarelyRunBlocks)
if (result == PhaseStatus::MODIFIED_EVERYTHING)
{
fgInvalidateDfsTree();

if (opts.OptimizationEnabled())
{
fgRenumberBlocks();
}
}

return result;
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/jiteh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2123,8 +2123,8 @@ void Compiler::fgNormalizeEH()
if (modified)
{
JITDUMP("Added at least one basic block in fgNormalizeEH.\n");
fgRenumberBlocks();
// fgRenumberBlocks() will dump all the blocks and the handler table, so we don't need to do it here.
JITDUMPEXEC(fgDispBasicBlocks());
JITDUMPEXEC(fgDispHandlerTab());
INDEBUG(fgVerifyHandlerTab());
}
else
Expand Down
11 changes: 3 additions & 8 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ DataFlow::DataFlow(Compiler* pCompiler)
PhaseStatus Compiler::optSetBlockWeights()
{
noway_assert(opts.OptimizationEnabled());
bool madeChanges = false;

assert(m_dfsTree != nullptr);
if (m_domTree == nullptr)
Expand All @@ -53,11 +54,11 @@ PhaseStatus Compiler::optSetBlockWeights()

if (m_dfsTree->HasCycle())
{
madeChanges = fgRenumberBlocks();
optMarkLoopHeads();
optFindAndScaleGeneralLoopBlocks();
}

bool madeChanges = false;
bool firstBBDominatesAllReturns = true;
const bool usingProfileWeights = fgIsUsingProfileWeights();

Expand Down Expand Up @@ -1335,13 +1336,11 @@ PhaseStatus Compiler::optUnrollLoops()
m_loops = FlowGraphNaturalLoops::Find(m_dfsTree);
}

fgRenumberBlocks();

DBEXEC(verbose, fgDispBasicBlocks());
}

#ifdef DEBUG
fgDebugCheckBBlist(true);
fgDebugCheckBBlist();
#endif // DEBUG

return anyIRchange ? PhaseStatus::MODIFIED_EVERYTHING : PhaseStatus::MODIFIED_NOTHING;
Expand Down Expand Up @@ -2687,8 +2686,6 @@ PhaseStatus Compiler::optFindLoopsPhase()
}
#endif

fgRenumberBlocks();

assert(m_dfsTree != nullptr);
optFindLoops();

Expand All @@ -2713,8 +2710,6 @@ void Compiler::optFindLoops()
m_loops = FlowGraphNaturalLoops::Find(m_dfsTree);
}

fgRenumberBlocks();

// Starting now we require all loops to be in canonical form.
optLoopsCanonical = true;

Expand Down
Loading