Skip to content

Commit

Permalink
Templatize fgAddRefPred (#81865)
Browse files Browse the repository at this point in the history
The `initializingPreds` argument is only `true` in a few cases.
Convert it to a template argument to see if there is any measureable
throughput impact.
  • Loading branch information
BruceForstall committed Feb 14, 2023
1 parent 6823bc2 commit 327a244
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5319,11 +5319,9 @@ class Compiler

void fgReplacePred(BasicBlock* block, BasicBlock* oldPred, BasicBlock* newPred);

FlowEdge* fgAddRefPred(BasicBlock* block,
BasicBlock* blockPred,
FlowEdge* oldEdge = nullptr,
bool initializingPreds = false); // Only set to 'true' when we are computing preds in
// fgLinkBasicBlocks()
// initializingPreds is only 'true' when we are computing preds in fgLinkBasicBlocks()
template <bool initializingPreds = false>
FlowEdge* fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, FlowEdge* oldEdge = nullptr);

void fgFindBasicBlocks();

Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2742,7 +2742,7 @@ void Compiler::fgLinkBasicBlocks()
{
BasicBlock* const jumpDest = fgLookupBB(curBBdesc->bbJumpOffs);
curBBdesc->bbJumpDest = jumpDest;
fgAddRefPred(jumpDest, curBBdesc, oldEdge, initializingPreds);
fgAddRefPred<initializingPreds>(jumpDest, curBBdesc, oldEdge);

if (curBBdesc->bbJumpDest->bbNum <= curBBdesc->bbNum)
{
Expand All @@ -2766,7 +2766,7 @@ void Compiler::fgLinkBasicBlocks()
FALLTHROUGH;

case BBJ_NONE:
fgAddRefPred(curBBdesc->bbNext, curBBdesc, oldEdge, initializingPreds);
fgAddRefPred<initializingPreds>(curBBdesc->bbNext, curBBdesc, oldEdge);
break;

case BBJ_EHFILTERRET:
Expand All @@ -2792,7 +2792,7 @@ void Compiler::fgLinkBasicBlocks()
{
BasicBlock* jumpDest = fgLookupBB((unsigned)*(size_t*)jumpPtr);
*jumpPtr = jumpDest;
fgAddRefPred(jumpDest, curBBdesc, oldEdge, initializingPreds);
fgAddRefPred<initializingPreds>(jumpDest, curBBdesc, oldEdge);
if ((*jumpPtr)->bbNum <= curBBdesc->bbNum)
{
fgMarkBackwardJump(*jumpPtr, curBBdesc);
Expand Down
19 changes: 13 additions & 6 deletions src/coreclr/jit/fgflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ FlowEdge* Compiler::fgGetPredForBlock(BasicBlock* block, BasicBlock* blockPred,
// fgAddRefPred: Increment block->bbRefs by one and add "blockPred" to the predecessor list of "block".
//
// Arguments:
// initializingPreds -- Optional (default: false). Only set to "true" when the initial preds computation is
// happening.
//
// block -- A block to operate on.
// blockPred -- The predecessor block to add to the predecessor list.
// oldEdge -- Optional (default: nullptr). If non-nullptr, and a new edge is created (and the dup count
// of an existing edge is not just incremented), the edge weights are copied from this edge.
// initializingPreds -- Optional (default: false). Only set to "true" when the initial preds computation is
// happening.
//
// Return Value:
// The flow edge representing the predecessor.
Expand All @@ -94,10 +95,8 @@ FlowEdge* Compiler::fgGetPredForBlock(BasicBlock* block, BasicBlock* blockPred,
// -- fgModified is set if a new flow edge is created (but not if an existing flow edge dup count is incremented),
// indicating that the flow graph shape has changed.
//
FlowEdge* Compiler::fgAddRefPred(BasicBlock* block,
BasicBlock* blockPred,
FlowEdge* oldEdge /* = nullptr */,
bool initializingPreds /* = false */)
template <bool initializingPreds>
FlowEdge* Compiler::fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, FlowEdge* oldEdge /* = nullptr */)
{
assert(block != nullptr);
assert(blockPred != nullptr);
Expand Down Expand Up @@ -227,6 +226,14 @@ FlowEdge* Compiler::fgAddRefPred(BasicBlock* block,
return flow;
}

// Add explicit instantiations.
template FlowEdge* Compiler::fgAddRefPred<false>(BasicBlock* block,
BasicBlock* blockPred,
FlowEdge* oldEdge /* = nullptr */);
template FlowEdge* Compiler::fgAddRefPred<true>(BasicBlock* block,
BasicBlock* blockPred,
FlowEdge* oldEdge /* = nullptr */);

//------------------------------------------------------------------------
// fgRemoveRefPred: Decrements the reference count of a predecessor edge from "blockPred" to "block",
// removing the edge if it is no longer necessary.
Expand Down

0 comments on commit 327a244

Please sign in to comment.