Skip to content

Commit

Permalink
JIT: Add simple late layout pass (dotnet#107483)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanasifkhalid authored and jtschuster committed Sep 17, 2024
1 parent ac2353f commit a329fbc
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5236,11 +5236,12 @@ 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;
lvaTrackedFixed = true;
const unsigned numBlocksBeforeLSRA = fgBBcount;

// Now that lowering is completed we can proceed to perform register allocation
//
auto linearScanPhase = [this]() {
auto linearScanPhase = [this] {
m_pLinearScan->doLinearScan();
};
DoPhase(this, PHASE_LINEAR_SCAN, linearScanPhase);
Expand All @@ -5250,8 +5251,25 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl

if (opts.OptimizationEnabled())
{
// LSRA and stack level setting can modify the flowgraph.
// Now that it won't change, run post-layout optimizations.
// LSRA may introduce new blocks. If it does, rerun layout.
if ((fgBBcount != numBlocksBeforeLSRA) && JitConfig.JitDoReversePostOrderLayout())
{
auto lateLayoutPhase = [this] {
fgDoReversePostOrderLayout();
fgMoveColdBlocks();
return PhaseStatus::MODIFIED_EVERYTHING;
};

DoPhase(this, PHASE_OPTIMIZE_LAYOUT, lateLayoutPhase);

if (fgFirstColdBlock != nullptr)
{
fgFirstColdBlock = nullptr;
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);
}

Expand Down

0 comments on commit a329fbc

Please sign in to comment.