Skip to content

Commit

Permalink
JIT: defer creating throw helper blocks (#93371)
Browse files Browse the repository at this point in the history
Don't create any throw helper blocks until just before the late flow graph optimizations. 
This removes some of the flow graph updates from morph, with the aim of making it easier
to show that an RPO traversal in morph is safe.

Unfortunately it's hard to get these blocks in the exact same places
they were before, so there are some diffs.
  • Loading branch information
AndyAyersMS authored Oct 18, 2023
1 parent 93fc05c commit c5f3009
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 265 deletions.
4 changes: 4 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5038,6 +5038,10 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
// Insert GC Polls
DoPhase(this, PHASE_INSERT_GC_POLLS, &Compiler::fgInsertGCPolls);

// Create any throw helper blocks that might be needed
//
DoPhase(this, PHASE_CREATE_THROW_HELPERS, &Compiler::fgCreateThrowHelperBlocks);

if (opts.OptimizationEnabled())
{
// Optimize boolean conditions
Expand Down
9 changes: 3 additions & 6 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6119,12 +6119,11 @@ class Compiler
static unsigned acdHelper(SpecialCodeKind codeKind);

AddCodeDsc* fgAddCodeList;
bool fgAddCodeModf;
bool fgRngChkThrowAdded;
AddCodeDsc* fgExcptnTargetCache[SCK_COUNT];

BasicBlock* fgRngChkTarget(BasicBlock* block, SpecialCodeKind kind);

BasicBlock* fgAddCodeRef(BasicBlock* srcBlk, unsigned refData, SpecialCodeKind kind);
void fgAddCodeRef(BasicBlock* srcBlk, SpecialCodeKind kind);
PhaseStatus fgCreateThrowHelperBlocks();

public:
AddCodeDsc* fgFindExcptnTarget(SpecialCodeKind kind, unsigned refData);
Expand All @@ -6137,8 +6136,6 @@ class Compiler
}

private:
bool fgIsCodeAdded();

bool fgIsThrowHlpBlk(BasicBlock* block);

#if !FEATURE_FIXED_OUT_ARGS
Expand Down
12 changes: 1 addition & 11 deletions src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3069,7 +3069,7 @@ inline Compiler::fgWalkResult Compiler::fgWalkTree(GenTree** pTree,

inline bool Compiler::fgIsThrowHlpBlk(BasicBlock* block)
{
if (!fgIsCodeAdded())
if (!fgRngChkThrowAdded)
{
return false;
}
Expand Down Expand Up @@ -3157,16 +3157,6 @@ inline unsigned Compiler::fgThrowHlpBlkStkLevel(BasicBlock* block)

#endif // !FEATURE_FIXED_OUT_ARGS

/*****************************************************************************
*
* Return true if we've added any new basic blocks.
*/

inline bool Compiler::fgIsCodeAdded()
{
return fgAddCodeModf;
}

/*****************************************************************************
Is the offset too big?
*/
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compphases.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ CompPhaseNameMacro(PHASE_EXPAND_RTLOOKUPS, "Expand runtime lookups",
CompPhaseNameMacro(PHASE_EXPAND_STATIC_INIT, "Expand static init", false, -1, true)
CompPhaseNameMacro(PHASE_EXPAND_TLS, "Expand TLS access", false, -1, true)
CompPhaseNameMacro(PHASE_INSERT_GC_POLLS, "Insert GC Polls", false, -1, true)
CompPhaseNameMacro(PHASE_CREATE_THROW_HELPERS, "Create throw helper blocks", false, -1, true)
CompPhaseNameMacro(PHASE_DETERMINE_FIRST_COLD_BLOCK, "Determine first cold block", false, -1, true)
CompPhaseNameMacro(PHASE_RATIONALIZE, "Rationalize IR", false, -1, false)
CompPhaseNameMacro(PHASE_SIMPLE_LOWERING, "Do 'simple' lowering", false, -1, false)
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ void Compiler::fgInit()
// as the code that raises an exception when an array range check fails.

fgAddCodeList = nullptr;
fgAddCodeModf = false;

for (int i = 0; i < SCK_COUNT; i++)
{
Expand All @@ -109,6 +108,9 @@ void Compiler::fgInit()
/* This global flag is set whenever we remove a statement */
fgStmtRemoved = false;

// This global flag is set when we create throw helper blocks
fgRngChkThrowAdded = false;

/* Keep track of whether or not EH statements have been optimized */
fgOptimizedFinally = false;

Expand Down
Loading

0 comments on commit c5f3009

Please sign in to comment.