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: Consolidate layout passes into one phase #112004

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0a70d2a
Reorder block list only once after 3-opt
amanasifkhalid Jan 29, 2025
25389c9
Fix block insertion
amanasifkhalid Jan 30, 2025
df25317
Run 3-opt once for all regions
amanasifkhalid Jan 30, 2025
46539d5
Remove some EH checks
amanasifkhalid Jan 30, 2025
84600ec
Remove unused layout methods
amanasifkhalid Jan 30, 2025
289134a
Relax EH invariants; better stress mode
amanasifkhalid Jan 30, 2025
94d4f84
Place cold blocks in RPO
amanasifkhalid Jan 30, 2025
38b3700
Merge from main
amanasifkhalid Feb 5, 2025
a2774e0
Clean up 3-opt driver a bit
amanasifkhalid Feb 5, 2025
1262dd6
Clean up 3-opt driver a bit
amanasifkhalid Feb 6, 2025
918c557
Merge from main
amanasifkhalid Feb 6, 2025
1404f80
Cold code motion working
amanasifkhalid Feb 6, 2025
26359c4
Move try regions
amanasifkhalid Feb 7, 2025
f062f0b
Ensure method entry is considered hot by 3-opt
amanasifkhalid Feb 7, 2025
ce79655
Always invalidate DFS tree after layout
amanasifkhalid Feb 7, 2025
2520f7a
Revert "Always invalidate DFS tree after layout"
amanasifkhalid Feb 7, 2025
e54dbb5
Fix DFS tree invalidation logic
amanasifkhalid Feb 7, 2025
2f5f342
Merge from main
amanasifkhalid Feb 20, 2025
f08a756
Style; use bbPreorderNum for ordinal
amanasifkhalid Feb 20, 2025
447b2dd
Cleanup
amanasifkhalid Feb 20, 2025
6f7ec57
Fix call-finally motion
amanasifkhalid Feb 20, 2025
5d32277
fgFindEHRegionEnds -> fgFindTryRegionEnds
amanasifkhalid Feb 20, 2025
52536be
Style
amanasifkhalid Feb 21, 2025
60303ad
Recompute try region ends only when necessary
amanasifkhalid Feb 21, 2025
2497d6b
Merge branch 'main' into one-layout-phase
amanasifkhalid Feb 21, 2025
c3b78a3
Merge branch 'main' into one-layout-phase
amanasifkhalid Feb 21, 2025
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
Prev Previous commit
Next Next commit
Relax EH invariants; better stress mode
amanasifkhalid committed Jan 30, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 289134afdd96ab7b54d4ec0eb85e592106c7e913
31 changes: 20 additions & 11 deletions src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
@@ -4691,15 +4691,7 @@ void Compiler::ThreeOptLayout::ConsiderEdge(FlowEdge* edge)
BasicBlock* const dstBlk = edge->getDestinationBlock();

// Ignore cross-region branches
if (!BasicBlock::sameTryRegion(srcBlk, dstBlk))
{
return;
}

// Don't waste time reordering within handler regions.
// Note that if a finally region is sufficiently hot,
// we should have cloned it into the main method body already.
if (srcBlk->hasHndIndex() || dstBlk->hasHndIndex())
if (!BasicBlock::sameEHRegion(srcBlk, dstBlk))
{
return;
}
@@ -4829,6 +4821,12 @@ bool Compiler::ThreeOptLayout::Run()
continue;
}

// Don't reorder filter regions.
if (block->hasHndIndex() && compiler->ehGetDsc(block->getHndIndex())->HasFilter())
{
continue;
}

// Don't break up call-finally pairs.
if (block->isBBCallFinallyPair() || next->isBBCallFinallyPairTail())
{
@@ -5123,9 +5121,20 @@ PhaseStatus Compiler::fgSearchImprovedLayout()
}
};

fgVisitBlocksInLoopAwareRPO(m_dfsTree, m_loops, addToSequence);
bool modified = false;
// Stress 3-opt by giving it the post-order traversal as its initial layout,
// but keep the method entry block at the beginning.
if (compStressCompile(STRESS_THREE_OPT_LAYOUT, 10))
{
numHotBlocks = m_dfsTree->GetPostOrderCount();
memcpy(initialLayout, m_dfsTree->GetPostOrder(), sizeof(BasicBlock*) * numHotBlocks);
std::swap(initialLayout[0], initialLayout[numHotBlocks - 1]);
}
else
{
fgVisitBlocksInLoopAwareRPO(m_dfsTree, m_loops, addToSequence);
}

bool modified = false;
if (numHotBlocks > 0)
{
ThreeOptLayout layoutRunner(this, initialLayout, numHotBlocks);