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: make bbID available in release, use it for pred list ordering #93636

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 9 additions & 12 deletions src/coreclr/jit/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,27 +220,27 @@ bool BasicBlock::IsFirstColdBlock(Compiler* compiler) const
// checkPredListOrder: see if pred list is properly ordered
//
// Returns:
// false if pred list is not in increasing bbNum order.
// false if pred list is not in increasing bbID order.
//
bool BasicBlock::checkPredListOrder()
{
unsigned lastBBNum = 0;
unsigned lastBBID = 0;
for (BasicBlock* const predBlock : PredBlocks())
{
const unsigned bbNum = predBlock->bbNum;
if (bbNum <= lastBBNum)
const unsigned bbID = predBlock->bbID;
if (bbID <= lastBBID)
{
assert(bbNum != lastBBNum);
assert(bbID != lastBBID);
return false;
}
lastBBNum = bbNum;
lastBBID = bbID;
}
return true;
}

//------------------------------------------------------------------------
// ensurePredListOrder: ensure all pred list entries appear in increasing
// bbNum order.
// bbID order.
//
// Arguments:
// compiler - current compiler instance
Expand Down Expand Up @@ -305,7 +305,7 @@ void BasicBlock::reorderPredList(Compiler* compiler)
{
bool operator()(const FlowEdge* f1, const FlowEdge* f2)
{
return f1->getSourceBlock()->bbNum < f2->getSourceBlock()->bbNum;
return f1->getSourceBlock()->bbID < f2->getSourceBlock()->bbID;
}
};

Expand Down Expand Up @@ -1469,10 +1469,7 @@ BasicBlock* Compiler::bbNewBasicBlock(BBjumpKinds jumpKind)
// boundaries), or have been inserted by the JIT
block->bbCodeOffs = BAD_IL_OFFSET;
block->bbCodeOffsEnd = BAD_IL_OFFSET;

#ifdef DEBUG
block->bbID = compBasicBlockID++;
#endif
block->bbID = ++compBasicBlockID;

/* Give the block a number, set the ancestor count and weight */

Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -1259,9 +1259,10 @@ struct BasicBlock : private LIR::Range
// still in the BB list by whether they have the same stamp (with high probability).
unsigned bbTraversalStamp;

#endif // DEBUG

// bbID is a unique block identifier number that does not change: it does not get renumbered, like bbNum.
unsigned bbID;
#endif // DEBUG

unsigned bbStackDepthOnEntry() const;
void bbSetStack(StackEntry* stack);
Expand Down
7 changes: 4 additions & 3 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6795,11 +6795,12 @@ int Compiler::compCompileHelper(CORINFO_MODULE_HANDLE classPtr,
lvaTable = nullptr;

// Reset node and block ID counter
compGenTreeID = 0;
compStatementID = 0;
compBasicBlockID = 0;
compGenTreeID = 0;
compStatementID = 0;
#endif

compBasicBlockID = 0;

#ifdef TARGET_ARM64
info.compNeedsConsecutiveRegisters = false;
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10283,9 +10283,9 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#ifdef DEBUG
unsigned compGenTreeID;
unsigned compStatementID;
unsigned compBasicBlockID;
#endif
LONG compMethodID;
unsigned compBasicBlockID;
LONG compMethodID;

BasicBlock* compCurBB; // the current basic block in process
Statement* compCurStmt; // the current statement in process
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5718,10 +5718,6 @@ bool Compiler::fgRenumberBlocks()
//
if (renumbered)
{
for (BasicBlock* const block : Blocks())
{
block->ensurePredListOrder(this);
}
JITDUMP("\n*************** After renumbering the basic blocks\n");
JITDUMPEXEC(fgDispBasicBlocks());
JITDUMPEXEC(fgDispHandlerTab());
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/jit/fgflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ FlowEdge* Compiler::fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, FlowE

block->bbRefs++;

// Keep the predecessor list in lowest to highest bbNum order. This allows us to discover the loops in
// Keep the predecessor list in lowest to highest bbID order. This allows us to discover the loops in
// optFindNaturalLoops from innermost to outermost.
//
// If we are initializing preds, we rely on the fact that we are adding references in increasing
// order of blockPred->bbNum to avoid searching the list.
// order of blockPred->bbID to avoid searching the list.
//
// TODO-Throughput: Inserting an edge for a block in sorted order requires searching every existing edge.
// Thus, inserting all the edges for a block is quadratic in the number of edges. We need to either
Expand All @@ -123,15 +123,15 @@ FlowEdge* Compiler::fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, FlowE
if (initializingPreds)
{
// List is sorted order and we're adding references in
// increasing blockPred->bbNum order. The only possible
// increasing blockPred->bbID order. The only possible
// dup list entry is the last one.
//
FlowEdge* flowLast = block->bbLastPred;
if (flowLast != nullptr)
{
listp = flowLast->getNextPredEdgeRef();

assert(flowLast->getSourceBlock()->bbNum <= blockPred->bbNum);
assert(flowLast->getSourceBlock()->bbID <= blockPred->bbID);

if (flowLast->getSourceBlock() == blockPred)
{
Expand All @@ -143,7 +143,7 @@ FlowEdge* Compiler::fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, FlowE
{
// References are added randomly, so we have to search.
//
while ((*listp != nullptr) && ((*listp)->getSourceBlock()->bbNum < blockPred->bbNum))
while ((*listp != nullptr) && ((*listp)->getSourceBlock()->bbID < blockPred->bbID))
{
listp = (*listp)->getNextPredEdgeRef();
}
Expand Down
14 changes: 0 additions & 14 deletions src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2451,20 +2451,6 @@ void Compiler::fgCompactBlocks(BasicBlock* block, BasicBlock* bNext)
bNext->bbNum);

block->bbNum = bNext->bbNum;

// Because we may have reordered pred lists when we swapped in
// block for bNext above, we now need to re-reorder pred lists
// to reflect the bbNum update.
//
// This process of reordering and re-reordering could likely be avoided
// via a different update strategy. But because it's probably rare,
// and we avoid most of the work if pred lists are already in order,
// we'll just ensure everything is properly ordered.
//
for (BasicBlock* const checkBlock : Blocks())
{
checkBlock->ensurePredListOrder(this);
}
}

fgUpdateLoopsAfterCompacting(block, bNext);
Expand Down
Loading