Skip to content

Commit

Permalink
JIT: Use BitVec with bbPostorderNum key to track visited blocks d…
Browse files Browse the repository at this point in the history
…uring value numbering (#108943)
  • Loading branch information
amanasifkhalid authored Oct 21, 2024
1 parent 4e4054b commit f87687a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5792,7 +5792,7 @@ class Compiler
// Utility functions for fgValueNumber.

// Value number a block or blocks in a loop
void fgValueNumberBlocks(BasicBlock* block, BlockSet& visitedBlocks);
void fgValueNumberBlocks(BasicBlock* block, BitVec& visitedBlocks, BitVecTraits* traits);

// Perform value-numbering for the trees in "blk".
void fgValueNumberBlock(BasicBlock* blk);
Expand Down
19 changes: 10 additions & 9 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10888,14 +10888,14 @@ PhaseStatus Compiler::fgValueNumber()
// Visiting that in reverse will ensure we visit a block's predecessors
// before itself whenever possible.
//
EnsureBasicBlockEpoch();
BlockSet visitedBlocks(BlockSetOps::MakeEmpty(this));
BitVecTraits traits = m_dfsTree->PostOrderTraits();
BitVec visitedBlocks(BitVecOps::MakeEmpty(&traits));
BasicBlock** postOrder = m_dfsTree->GetPostOrder();
unsigned postOrderCount = m_dfsTree->GetPostOrderCount();
for (unsigned i = postOrderCount; i != 0; i--)
{
BasicBlock* const block = postOrder[i - 1];
fgValueNumberBlocks(block, visitedBlocks);
fgValueNumberBlocks(block, visitedBlocks, &traits);
}

#ifdef DEBUG
Expand All @@ -10912,8 +10912,9 @@ PhaseStatus Compiler::fgValueNumber()
// fgValueNumberBlocks: Run value numbering for a block or blocks in a loop
//
// Arguments:
// block -- block to value number (may already have been numbered)
// visitedBlocks -- blocks that have already had VNs assigned
// block - block to value number (may already have been numbered)
// visitedBlocks - blocks that have already had VNs assigned
// traits - pointer to BitVecTraits describing visitedBlocks
//
// Notes:
//
Expand All @@ -10922,11 +10923,11 @@ PhaseStatus Compiler::fgValueNumber()
// header, we switch to visiting the loop blocks in RPO, and once we finish
// that visitation, we try and refine loop header PHIs.
//
void Compiler::fgValueNumberBlocks(BasicBlock* block, BlockSet& visitedBlocks)
void Compiler::fgValueNumberBlocks(BasicBlock* block, BitVec& visitedBlocks, BitVecTraits* traits)
{
// Because we're not following the strict RPO, we may have already visisted this block.
//
if (BlockSetOps::IsMember(this, visitedBlocks, block->bbNum))
if (BitVecOps::IsMember(traits, visitedBlocks, block->bbPostorderNum))
{
return;
}
Expand Down Expand Up @@ -10961,7 +10962,7 @@ void Compiler::fgValueNumberBlocks(BasicBlock* block, BlockSet& visitedBlocks)

// Mark block as visited
//
BlockSetOps::AddElemD(this, visitedBlocks, block->bbNum);
BitVecOps::AddElemD(traits, visitedBlocks, block->bbPostorderNum);

// Is block the head of a loop?
//
Expand All @@ -10971,7 +10972,7 @@ void Compiler::fgValueNumberBlocks(BasicBlock* block, BlockSet& visitedBlocks)
// Yes. Visit all other loop blocks using the within-loop RPO.
//
loop->VisitLoopBlocksReversePostOrder([&](BasicBlock* block) {
fgValueNumberBlocks(block, visitedBlocks);
fgValueNumberBlocks(block, visitedBlocks, traits);
return BasicBlockVisit::Continue;
});

Expand Down

0 comments on commit f87687a

Please sign in to comment.