Skip to content

Commit

Permalink
JIT: have inliner use fgSplitBlockAfterStatement (#80928)
Browse files Browse the repository at this point in the history
In anticipation of moving pred list building before inlining,
use the common block split utility instead of custom code. This does a
better job of propagating IL offsets, and automatically handles
pred list maintenance.

Contributes to #80193.
  • Loading branch information
AndyAyersMS committed Jan 20, 2023
1 parent 31e4f40 commit 861a886
Showing 1 changed file with 1 addition and 72 deletions.
73 changes: 1 addition & 72 deletions src/coreclr/jit/fginline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1164,78 +1164,7 @@ void Compiler::fgInsertInlineeBlocks(InlineInfo* pInlineInfo)
//
// ======= Inserting inlinee's basic blocks ===============
//

bottomBlock = fgNewBBafter(topBlock->bbJumpKind, topBlock, true);
bottomBlock->bbRefs = 1;
bottomBlock->bbJumpDest = topBlock->bbJumpDest;
bottomBlock->inheritWeight(topBlock);

topBlock->bbJumpKind = BBJ_NONE;

// Update block flags
{
const BasicBlockFlags originalFlags = topBlock->bbFlags;
noway_assert((originalFlags & BBF_SPLIT_NONEXIST) == 0);
topBlock->bbFlags &= ~(BBF_SPLIT_LOST);
bottomBlock->bbFlags |= originalFlags & BBF_SPLIT_GAINED;
}

// Split statements between topBlock and bottomBlock.
// First figure out bottomBlock_Begin
Statement* bottomBlock_Begin;
bottomBlock_Begin = stmtAfter->GetNextStmt();

if (topBlock->bbStmtList == nullptr)
{
// topBlock is empty before the split.
// In this case, both topBlock and bottomBlock should be empty
noway_assert(bottomBlock_Begin == nullptr);
topBlock->bbStmtList = nullptr;
bottomBlock->bbStmtList = nullptr;
}
else if (topBlock->bbStmtList == bottomBlock_Begin)
{
noway_assert(bottomBlock_Begin != nullptr);

// topBlock contains at least one statement before the split.
// And the split is before the first statement.
// In this case, topBlock should be empty, and everything else should be moved to the bottomBlock.
bottomBlock->bbStmtList = topBlock->bbStmtList;
topBlock->bbStmtList = nullptr;
}
else if (bottomBlock_Begin == nullptr)
{
noway_assert(topBlock->bbStmtList != nullptr);

// topBlock contains at least one statement before the split.
// And the split is at the end of the topBlock.
// In this case, everything should be kept in the topBlock, and the bottomBlock should be empty

bottomBlock->bbStmtList = nullptr;
}
else
{
noway_assert(topBlock->bbStmtList != nullptr);
noway_assert(bottomBlock_Begin != nullptr);

// This is the normal case where both blocks should contain at least one statement.
Statement* topBlock_Begin = topBlock->firstStmt();
noway_assert(topBlock_Begin != nullptr);
Statement* topBlock_End = bottomBlock_Begin->GetPrevStmt();
noway_assert(topBlock_End != nullptr);
Statement* bottomBlock_End = topBlock->lastStmt();
noway_assert(bottomBlock_End != nullptr);

// Break the linkage between 2 blocks.
topBlock_End->SetNextStmt(nullptr);

// Fix up all the pointers.
topBlock->bbStmtList = topBlock_Begin;
topBlock->bbStmtList->SetPrevStmt(topBlock_End);

bottomBlock->bbStmtList = bottomBlock_Begin;
bottomBlock->bbStmtList->SetPrevStmt(bottomBlock_End);
}
bottomBlock = fgSplitBlockAfterStatement(topBlock, stmtAfter);

//
// Set the try and handler index and fix the jump types of inlinee's blocks.
Expand Down

0 comments on commit 861a886

Please sign in to comment.