Skip to content

Commit ae24c92

Browse files
Reuse DFS tree from LSRA through layout
1 parent 58af570 commit ae24c92

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/coreclr/jit/fgopt.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4663,10 +4663,6 @@ void Compiler::fgDoReversePostOrderLayout()
46634663
}
46644664
#endif // DEBUG
46654665

4666-
// Compute DFS of all blocks in the method, using profile data to determine the order successors are visited in.
4667-
//
4668-
m_dfsTree = fgComputeDfs</* useProfile */ true>();
4669-
46704666
// If LSRA didn't create any new blocks, we can reuse its loop-aware RPO traversal,
46714667
// which is cached in Compiler::fgBBs.
46724668
// If the cache isn't available, we need to recompute the loop-aware RPO.
@@ -4675,15 +4671,21 @@ void Compiler::fgDoReversePostOrderLayout()
46754671

46764672
if (rpoSequence == nullptr)
46774673
{
4678-
rpoSequence = new (this, CMK_BasicBlock) BasicBlock*[m_dfsTree->GetPostOrderCount()];
4674+
assert(m_dfsTree == nullptr);
4675+
m_dfsTree = fgComputeDfs</* useProfile */ true>();
46794676
FlowGraphNaturalLoops* const loops = FlowGraphNaturalLoops::Find(m_dfsTree);
4680-
unsigned index = 0;
4681-
auto addToSequence = [rpoSequence, &index](BasicBlock* block) {
4677+
rpoSequence = new (this, CMK_BasicBlock) BasicBlock*[m_dfsTree->GetPostOrderCount()];
4678+
unsigned index = 0;
4679+
auto addToSequence = [rpoSequence, &index](BasicBlock* block) {
46824680
rpoSequence[index++] = block;
46834681
};
46844682

46854683
fgVisitBlocksInLoopAwareRPO(m_dfsTree, loops, addToSequence);
46864684
}
4685+
else
4686+
{
4687+
assert(m_dfsTree != nullptr);
4688+
}
46874689

46884690
// Fast path: We don't have any EH regions, so just reorder the blocks
46894691
//

src/coreclr/jit/lsra.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -947,13 +947,16 @@ void LinearScan::setBlockSequence()
947947
bbVisitedSet = BitVecOps::MakeEmpty(traits);
948948

949949
assert((blockSequence == nullptr) && (bbSeqCount == 0));
950-
FlowGraphDfsTree* const dfsTree = compiler->fgComputeDfs</* useProfile */ true>();
950+
951+
compiler->m_dfsTree = compiler->fgComputeDfs</* useProfile */ true>();
952+
FlowGraphDfsTree* const dfsTree = compiler->m_dfsTree;
951953
blockSequence = new (compiler, CMK_LSRA) BasicBlock*[compiler->fgBBcount];
952954

953955
if (compiler->opts.OptimizationEnabled() && dfsTree->HasCycle())
954956
{
955-
// Ensure loop bodies are compact in the visitation order
956-
FlowGraphNaturalLoops* const loops = FlowGraphNaturalLoops::Find(dfsTree);
957+
// Ensure loop bodies are compact in the visitation order.
958+
compiler->m_loops = FlowGraphNaturalLoops::Find(dfsTree);
959+
FlowGraphNaturalLoops* const loops = compiler->m_loops;
957960
unsigned index = 0;
958961

959962
auto addToSequence = [this, &index](BasicBlock* block) {
@@ -1319,6 +1322,7 @@ PhaseStatus LinearScan::doLinearScan()
13191322
{
13201323
assert(compiler->fgBBcount > bbSeqCount);
13211324
compiler->fgBBs = nullptr;
1325+
compiler->fgInvalidateDfsTree();
13221326
}
13231327

13241328
return PhaseStatus::MODIFIED_EVERYTHING;

0 commit comments

Comments
 (0)