Skip to content
Merged
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
16 changes: 0 additions & 16 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3247,14 +3247,6 @@ void Compiler::fgFindBasicBlocks()
BADCODE("Handler Clause is invalid");
}

#if HANDLER_ENTRY_MUST_BE_IN_HOT_SECTION
// This will change the block weight from 0 to 1
// and clear the rarely run flag
hndBegBB->makeBlockHot();
#else
hndBegBB->bbSetRunRarely(); // handler entry points are rarely executed
#endif

if (hndEndOff < info.compILCodeSize)
{
hndEndBB = fgLookupBB(hndEndOff);
Expand All @@ -3266,14 +3258,6 @@ void Compiler::fgFindBasicBlocks()
filtBB->bbCatchTyp = BBCT_FILTER;
hndBegBB->bbCatchTyp = BBCT_FILTER_HANDLER;

#if HANDLER_ENTRY_MUST_BE_IN_HOT_SECTION
// This will change the block weight from 0 to 1
// and clear the rarely run flag
filtBB->makeBlockHot();
#else
filtBB->bbSetRunRarely(); // filter entry points are rarely executed
#endif

// Mark all BBs that belong to the filter with the XTnum of the corresponding handler
for (block = filtBB; /**/; block = block->bbNext)
{
Expand Down
35 changes: 35 additions & 0 deletions src/coreclr/jit/fgprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3584,6 +3584,27 @@ weight_t Compiler::fgComputeMissingBlockWeights()
}
}

// Handler entries are assumed to run rarely, except for
// finally blocks: These are executed regardless of if
// an exception is thrown, and thus should inherit weight.
if (bbIsHandlerBeg(bDst))
{
bSrc = bDst->bbPreds->getBlock();

// To minimize asmdiffs for now, modify weights only if splitting.
if (fgFirstColdBlock != nullptr)
{
if (bSrc->bbJumpKind == BBJ_CALLFINALLY)
{
newWeight = bSrc->bbWeight;
}
else
{
newWeight = BB_ZERO_WEIGHT;
}
}
}

if ((newWeight != BB_MAX_WEIGHT) && (bDst->bbWeight != newWeight))
{
changed = true;
Expand All @@ -3599,6 +3620,20 @@ weight_t Compiler::fgComputeMissingBlockWeights()
}
}
}
else if (!bDst->hasProfileWeight() && bbIsHandlerBeg(bDst) && !bDst->isRunRarely())
{
// Assume handler/filter entries are rarely executed.
// To avoid unnecessary loop iterations, set weight
// only if bDst->bbWeight is not already zero.

// To minimize asmdiffs for now, modify weights only if splitting.
if (fgFirstColdBlock != nullptr)
{
changed = true;
modified = true;
bDst->bbSetRunRarely();
}
}

// Sum up the weights of all of the return blocks and throw blocks
// This is used when we have a back-edge into block 1
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class GlobalJitOptions

#define CSE_INTO_HANDLERS 0
#define DUMP_FLOWGRAPHS DEBUG // Support for creating Xml Flowgraph reports in *.fgx files
#define HANDLER_ENTRY_MUST_BE_IN_HOT_SECTION 1 // if 1 we must have all handler entry points in the Hot code section
#define HANDLER_ENTRY_MUST_BE_IN_HOT_SECTION 0 // if 1 we must have all handler entry points in the Hot code section

/*****************************************************************************/

Expand Down