Skip to content

Commit

Permalink
JIT: Run new block layout only in backend (dotnet#107634)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanasifkhalid authored Oct 21, 2024
1 parent e195258 commit 1434eee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
14 changes: 10 additions & 4 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5235,8 +5235,7 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
m_pLowering->FinalizeOutgoingArgSpace();

// We can not add any new tracked variables after this point.
lvaTrackedFixed = true;
const unsigned numBlocksBeforeLSRA = fgBBcount;
lvaTrackedFixed = true;

// Now that lowering is completed we can proceed to perform register allocation
//
Expand All @@ -5250,8 +5249,10 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl

if (opts.OptimizationEnabled())
{
// LSRA may introduce new blocks. If it does, rerun layout.
if ((fgBBcount != numBlocksBeforeLSRA) && JitConfig.JitDoReversePostOrderLayout())
// We won't introduce new blocks from here on out,
// so run the new block layout.
//
if (JitConfig.JitDoReversePostOrderLayout())
{
auto lateLayoutPhase = [this] {
fgDoReversePostOrderLayout();
Expand All @@ -5272,7 +5273,12 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
DoPhase(this, PHASE_DETERMINE_FIRST_COLD_BLOCK, &Compiler::fgDetermineFirstColdBlock);

// Now that the flowgraph is finalized, run post-layout optimizations.
//
DoPhase(this, PHASE_OPTIMIZE_POST_LAYOUT, &Compiler::optOptimizePostLayout);

// Determine start of cold region if we are hot/cold splitting
//
DoPhase(this, PHASE_DETERMINE_FIRST_COLD_BLOCK, &Compiler::fgDetermineFirstColdBlock);
}

#if FEATURE_LOOP_ALIGN
Expand Down
18 changes: 4 additions & 14 deletions src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3341,22 +3341,12 @@ bool Compiler::fgReorderBlocks(bool useProfile)

if (useProfile)
{
// Don't run the new layout until we get to the backend,
// since LSRA can introduce new blocks, and lowering can churn the flowgraph.
//
if (JitConfig.JitDoReversePostOrderLayout())
{
fgDoReversePostOrderLayout();
fgMoveColdBlocks();

if (compHndBBtabCount != 0)
{
fgRebuildEHRegions();
}

// Renumber blocks to facilitate LSRA's order of block visitation
// TODO: Consider removing this, and using traversal order in lSRA
//
fgRenumberBlocks();

return true;
return (newRarelyRun || movedBlocks || optimizedSwitches);
}

// We will be reordering blocks, so ensure the false target of a BBJ_COND block is its next block
Expand Down

0 comments on commit 1434eee

Please sign in to comment.