Skip to content

Commit

Permalink
JIT: reset max bbnum after failed inline attempt (#80958)
Browse files Browse the repository at this point in the history
And if we renumber blocks in the inlinee's portion of the flow graph,
start renumbering from the max bbnum before the inline attempt, rather
than the current maximum.

More prep work in anticipation of moving pred list building to happen
before (or the root) and during (for inlinees) inlining.
  • Loading branch information
AndyAyersMS committed Jan 22, 2023
1 parent 1aa6b03 commit d5d96f4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4325,6 +4325,7 @@ class Compiler
unsigned fgBBcountAtCodegen; // # of BBs in the method at the start of codegen
jitstd::vector<BasicBlock*>* fgBBOrder; // ordered vector of BBs
#endif
unsigned fgBBNumMin; // The min bbNum that has been assigned to basic blocks
unsigned fgBBNumMax; // The max bbNum that has been assigned to basic blocks
unsigned fgDomBBcount; // # of BBs for which we have dominator and reachability information
BasicBlock** fgBBInvPostOrder; // The flow graph stored in an array sorted in topological order, needed to compute
Expand Down
42 changes: 13 additions & 29 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void Compiler::fgInit()
fgBBOrder = nullptr;
#endif // DEBUG

fgBBNumMin = compIsForInlining() ? impInlineRoot()->fgBBNumMax + 1 : 1;
fgBBNumMax = 0;
fgEdgeCount = 0;
fgDomBBcount = 0;
Expand Down Expand Up @@ -5352,50 +5353,33 @@ bool Compiler::fgRenumberBlocks()
}
#endif // DEBUG

bool renumbered = false;
bool newMaxBBNum = false;
BasicBlock* block;

unsigned numStart = 1 + (compIsForInlining() ? impInlineInfo->InlinerCompiler->fgBBNumMax : 0);
unsigned num;
bool renumbered = false;
bool newMaxBBNum = false;
unsigned num = fgBBNumMin;

for (block = fgFirstBB, num = numStart; block != nullptr; block = block->bbNext, num++)
for (BasicBlock* block : Blocks())
{
noway_assert((block->bbFlags & BBF_REMOVED) == 0);

if (block->bbNum != num)
{
renumbered = true;
#ifdef DEBUG
if (verbose)
{
printf("Renumber " FMT_BB " to " FMT_BB "\n", block->bbNum, num);
}
#endif // DEBUG
JITDUMP("Renumber " FMT_BB " to " FMT_BB "\n", block->bbNum, num);
renumbered = true;
block->bbNum = num;
}

if (block->bbNext == nullptr)
{
fgLastBB = block;
fgBBcount = num - numStart + 1;
if (compIsForInlining())
fgBBcount = num - fgBBNumMin + 1;
if (fgBBNumMax != num)
{
if (impInlineInfo->InlinerCompiler->fgBBNumMax != num)
{
impInlineInfo->InlinerCompiler->fgBBNumMax = num;
newMaxBBNum = true;
}
}
else
{
if (fgBBNumMax != num)
{
fgBBNumMax = num;
newMaxBBNum = true;
}
fgBBNumMax = num;
newMaxBBNum = true;
}
}

num++;
}

// If we renumbered, then we may need to reorder some pred lists.
Expand Down
17 changes: 13 additions & 4 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5492,7 +5492,8 @@ void Compiler::fgMorphCallInlineHelper(GenTreeCall* call, InlineResult* result,
// Calling inlinee's compiler to inline the method.
//

unsigned startVars = lvaCount;
unsigned const startVars = lvaCount;
unsigned const startBBNumMax = fgBBNumMax;

#ifdef DEBUG
if (verbose)
Expand All @@ -5518,16 +5519,24 @@ void Compiler::fgMorphCallInlineHelper(GenTreeCall* call, InlineResult* result,

if (result->IsFailure())
{
// Undo some changes made in anticipation of inlining...

// Undo some changes made during the inlining attempt.
// Zero out the used locals
memset((void*)(lvaTable + startVars), 0, (lvaCount - startVars) * sizeof(*lvaTable));
for (unsigned i = startVars; i < lvaCount; i++)
{
new (&lvaTable[i], jitstd::placement_t()) LclVarDsc(); // call the constructor.
}

lvaCount = startVars;
// Reset local var count and max bb num
lvaCount = startVars;
fgBBNumMax = startBBNumMax;

#ifdef DEBUG
for (BasicBlock* block : Blocks())
{
assert(block->bbNum <= fgBBNumMax);
}
#endif
}
}

Expand Down

0 comments on commit d5d96f4

Please sign in to comment.