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: Add an "init BB" invariant #110404

Merged
merged 12 commits into from
Dec 13, 2024
14 changes: 5 additions & 9 deletions src/coreclr/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ void CodeGen::genCodeForBBlist()

genMarkLabelsForCodegen();

assert(!compiler->fgFirstBBScratch ||
compiler->fgFirstBB == compiler->fgFirstBBScratch); // compiler->fgFirstBBScratch
// has to be first.

/* Initialize structures used in the block list iteration */
genInitialize();

Expand Down Expand Up @@ -367,9 +363,9 @@ void CodeGen::genCodeForBBlist()
siBeginBlock(block);

// BBF_INTERNAL blocks don't correspond to any single IL instruction.
if (compiler->opts.compDbgInfo && block->HasFlag(BBF_INTERNAL) &&
!compiler->fgBBisScratch(block)) // If the block is the distinguished first scratch block, then no need to
// emit a NO_MAPPING entry, immediately after the prolog.
// Add a NoMapping entry unless this is right after the prolog where it
// is unnecessary.
if (compiler->opts.compDbgInfo && block->HasFlag(BBF_INTERNAL) && !block->IsFirst())
{
genIPmappingAdd(IPmappingDscKind::NoMapping, DebugInfo(), true);
}
Expand All @@ -396,9 +392,9 @@ void CodeGen::genCodeForBBlist()
}
#endif

// Emit poisoning into scratch BB that comes right after prolog.
// Emit poisoning into the init BB that comes right after prolog.
// We cannot emit this code in the prolog as it might make the prolog too large.
if (compiler->compShouldPoisonFrame() && compiler->fgBBisScratch(block))
if (compiler->compShouldPoisonFrame() && block->IsFirst())
{
genPoisonFrame(newLiveRegSet);
}
Expand Down
31 changes: 3 additions & 28 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3743,20 +3743,6 @@ void Compiler::compInitDebuggingInfo()
compInitScopeLists();
}

if (opts.compDbgCode && (info.compVarScopesCount > 0))
{
/* Create a new empty basic block. fgExtendDbgLifetimes() may add
initialization of variables which are in scope right from the
start of the (real) first BB (and therefore artificially marked
as alive) into this block.
*/

fgEnsureFirstBBisScratch();

fgNewStmtAtEnd(fgFirstBB, gtNewNothingNode());

JITDUMP("Debuggable code - Add new %s to perform initialization of variables\n", fgFirstBB->dspToString());
}
/*-------------------------------------------------------------------------
*
* Read the stmt-offsets table and the line-number table
Expand Down Expand Up @@ -4523,6 +4509,9 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
activePhaseChecks |= PhaseChecks::CHECK_PROFILE;
DoPhase(this, PHASE_INCPROFILE, &Compiler::fgIncorporateProfileData);

activePhaseChecks |= PhaseChecks::CHECK_FG_INIT_BLOCK;
DoPhase(this, PHASE_CANONICALIZE_ENTRY_BB, &Compiler::fgCanonicalizeFirstBB);

// If we are doing OSR, update flow to initially reach the appropriate IL offset.
//
if (opts.IsOSR())
Expand Down Expand Up @@ -4691,10 +4680,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl

if (opts.OptimizationEnabled())
{
// Canonicalize entry to have unique entry BB to put IR in for the upcoming phases
//
DoPhase(this, PHASE_CANONICALIZE_ENTRY, &Compiler::fgCanonicalizeFirstBB);

// Build post-order and remove dead blocks
//
DoPhase(this, PHASE_DFS_BLOCKS2, &Compiler::fgDfsBlocksAndRemove);
Expand Down Expand Up @@ -4789,10 +4774,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
return fgHeadTailMerge(false);
});

// Canonicalize entry to give a unique dominator tree root
//
DoPhase(this, PHASE_CANONICALIZE_ENTRY, &Compiler::fgCanonicalizeFirstBB);

// Compute DFS tree and remove all unreachable blocks.
//
DoPhase(this, PHASE_DFS_BLOCKS3, &Compiler::fgDfsBlocksAndRemove);
Expand Down Expand Up @@ -5024,12 +5005,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl

assert(opts.optRepeat);

// We may have optimized away the canonical entry BB that SSA
// depends on above, so if we are going for another iteration then
// make sure we still have a canonical entry.
//
DoPhase(this, PHASE_CANONICALIZE_ENTRY, &Compiler::fgCanonicalizeFirstBB);

ResetOptAnnotations();
RecomputeFlowGraphAnnotations();

Expand Down
11 changes: 6 additions & 5 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,7 @@ enum class PhaseChecks : unsigned int
CHECK_LIKELIHOODS = 1 << 5, // profile data likelihood integrity
CHECK_PROFILE = 1 << 6, // profile data full integrity
CHECK_LINKED_LOCALS = 1 << 7, // check linked list of locals
CHECK_FG_INIT_BLOCK = 1 << 8, // flow graph has an init block
};

inline constexpr PhaseChecks operator ~(PhaseChecks a)
Expand Down Expand Up @@ -5175,7 +5176,6 @@ class Compiler
BasicBlock* fgEntryBB = nullptr; // For OSR, the original method's entry point
BasicBlock* fgOSREntryBB = nullptr; // For OSR, the logical entry point (~ patchpoint)
BasicBlock* fgFirstFuncletBB = nullptr; // First block of outlined funclets (to allow block insertion before the funclets)
BasicBlock* fgFirstBBScratch = nullptr; // Block inserted for initialization stuff. Is nullptr if no such block has been
// created.
jakobbotsch marked this conversation as resolved.
Show resolved Hide resolved
BasicBlockList* fgReturnBlocks = nullptr; // list of BBJ_RETURN blocks
unsigned fgEdgeCount = 0; // # of control flow edges between the BBs
Expand Down Expand Up @@ -5224,10 +5224,6 @@ class Compiler
return getAllocator(cmk).allocate<T>(fgBBNumMax + 1);
}

bool fgEnsureFirstBBisScratch();
bool fgFirstBBisScratch();
bool fgBBisScratch(BasicBlock* block);

void fgExtendEHRegionBefore(BasicBlock* block);
void fgExtendEHRegionAfter(BasicBlock* block);

Expand Down Expand Up @@ -5414,6 +5410,7 @@ class Compiler
};

PhaseStatus fgMorphBlocks();
BasicBlock* fgGetFirstILBlock();
void fgMorphBlock(BasicBlock* block, MorphUnreachableInfo* unreachableInfo = nullptr);
void fgMorphStmts(BasicBlock* block);

Expand Down Expand Up @@ -6133,6 +6130,7 @@ class Compiler
bool fgCheckRemoveStmt(BasicBlock* block, Statement* stmt);

PhaseStatus fgCanonicalizeFirstBB();
void fgCreateNewInitBB();

void fgSetEHRegionForNewPreheaderOrExit(BasicBlock* preheader);

Expand All @@ -6154,6 +6152,8 @@ class Compiler

bool fgCanCompactBlock(BasicBlock* block);

bool fgCanCompactInitBlock();

void fgCompactBlock(BasicBlock* block);

BasicBlock* fgConnectFallThrough(BasicBlock* bSrc, BasicBlock* bDst);
Expand Down Expand Up @@ -6330,6 +6330,7 @@ class Compiler
void fgDebugCheckBBNumIncreasing();
void fgDebugCheckBBlist(bool checkBBNum = false, bool checkBBRefs = true);
void fgDebugCheckBlockLinks();
void fgDebugCheckInitBB();
void fgDebugCheckLinks(bool morphTrees = false);
void fgDebugCheckStmtsList(BasicBlock* block, bool morphTrees);
void fgDebugCheckNodeLinks(BasicBlock* block, Statement* stmt);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/compphases.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ CompPhaseNameMacro(PHASE_OPTIMIZE_FLOW, "Optimize control flow",
CompPhaseNameMacro(PHASE_OPTIMIZE_LAYOUT, "Optimize layout", false, -1, false)
CompPhaseNameMacro(PHASE_OPTIMIZE_POST_LAYOUT, "Optimize post-layout", false, -1, false)
CompPhaseNameMacro(PHASE_COMPUTE_DOMINATORS, "Compute dominators", false, -1, false)
CompPhaseNameMacro(PHASE_CANONICALIZE_ENTRY, "Canonicalize entry", false, -1, false)
CompPhaseNameMacro(PHASE_CANONICALIZE_ENTRY_BB, "Canonicalize entry", false, -1, false)
CompPhaseNameMacro(PHASE_SET_BLOCK_WEIGHTS, "Set block weights", false, -1, false)
CompPhaseNameMacro(PHASE_ZERO_INITS, "Redundant zero Inits", false, -1, false)
CompPhaseNameMacro(PHASE_FIND_LOOPS, "Find loops", false, -1, false)
Expand Down
Loading
Loading