Skip to content

Commit

Permalink
JIT: Add FlowEdge destination block member (#98243)
Browse files Browse the repository at this point in the history
Part of #93020. Per conversation in #98054, I'm going to try to replace BasicBlock's block successor pointers (bbTarget, bbFalseTarget, etc) with FlowEdge pointers to simplify access to successor edges. To do this, each edge is going to need access to its destination block, so that access to successor blocks is still simple. As a first step, add a destination block member to FlowEdge.
  • Loading branch information
amanasifkhalid authored Feb 10, 2024
1 parent 8af0b00 commit 35bff27
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/coreclr/jit/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ FlowEdge* Compiler::BlockPredsWithEH(BasicBlock* blk)
{
if (bbInExnFlowRegions(tryIndex, bb) && !bb->isBBCallFinallyPairTail())
{
res = new (this, CMK_FlowEdge) FlowEdge(bb, res);
res = new (this, CMK_FlowEdge) FlowEdge(bb, blk, res);

#if MEASURE_BLOCK_SIZE
genFlowNodeCnt += 1;
Expand All @@ -164,7 +164,7 @@ FlowEdge* Compiler::BlockPredsWithEH(BasicBlock* blk)
for (BasicBlock* filterBlk = enclosingDsc->ebdFilter; filterBlk != enclosingDsc->ebdHndBeg;
filterBlk = filterBlk->Next())
{
res = new (this, CMK_FlowEdge) FlowEdge(filterBlk, res);
res = new (this, CMK_FlowEdge) FlowEdge(filterBlk, blk, res);

assert(filterBlk->VisitEHEnclosedHandlerSecondPassSuccs(this, [blk](BasicBlock* succ) {
return succ == blk ? BasicBlockVisit::Abort : BasicBlockVisit::Continue;
Expand Down Expand Up @@ -239,7 +239,7 @@ FlowEdge* Compiler::BlockDominancePreds(BasicBlock* blk)
for (BasicBlock* filterBlk = enclosingDsc->ebdFilter; filterBlk != enclosingDsc->ebdHndBeg;
filterBlk = filterBlk->Next())
{
res = new (this, CMK_FlowEdge) FlowEdge(filterBlk, res);
res = new (this, CMK_FlowEdge) FlowEdge(filterBlk, blk, res);

assert(filterBlk->VisitEHEnclosedHandlerSecondPassSuccs(this, [blk](BasicBlock* succ) {
return succ == blk ? BasicBlockVisit::Abort : BasicBlockVisit::Continue;
Expand Down
22 changes: 20 additions & 2 deletions src/coreclr/jit/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,9 @@ struct FlowEdge
// The source of the control flow
BasicBlock* m_sourceBlock;

// The destination of the control flow
BasicBlock* m_destBlock;

// Edge weights
weight_t m_edgeWeightMin;
weight_t m_edgeWeightMax;
Expand All @@ -2074,9 +2077,10 @@ struct FlowEdge
bool m_likelihoodSet;

public:
FlowEdge(BasicBlock* block, FlowEdge* rest)
FlowEdge(BasicBlock* sourceBlock, BasicBlock* destBlock, FlowEdge* rest)
: m_nextPredEdge(rest)
, m_sourceBlock(block)
, m_sourceBlock(sourceBlock)
, m_destBlock(destBlock)
, m_edgeWeightMin(0)
, m_edgeWeightMax(0)
, m_likelihood(0)
Expand All @@ -2102,14 +2106,28 @@ struct FlowEdge

BasicBlock* getSourceBlock() const
{
assert(m_sourceBlock != nullptr);
return m_sourceBlock;
}

void setSourceBlock(BasicBlock* newBlock)
{
assert(newBlock != nullptr);
m_sourceBlock = newBlock;
}

BasicBlock* getDestinationBlock() const
{
assert(m_destBlock != nullptr);
return m_destBlock;
}

void setDestinationBlock(BasicBlock* newBlock)
{
assert(newBlock != nullptr);
m_destBlock = newBlock;
}

weight_t edgeWeightMin() const
{
return m_edgeWeightMin;
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/fgdiagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,10 @@ unsigned BBPredsChecker::CheckBBPreds(BasicBlock* block, unsigned curTraversalSt
}

assert(CheckJump(blockPred, block));

// Make sure the pred edge's destination block is correct
//
assert(pred->getDestinationBlock() == block);
}

// Make sure preds are in increasing BBnum order
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/fgflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ FlowEdge* Compiler::fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, FlowE

// Create new edge in the list in the correct ordered location.
//
flow = new (this, CMK_FlowEdge) FlowEdge(blockPred, *listp);
flow = new (this, CMK_FlowEdge) FlowEdge(blockPred, block, *listp);
flow->incrementDupCount();
*listp = flow;

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void Compiler::optScaleLoopBlocks(BasicBlock* begBlk, BasicBlock* endBlk)
// Is this a back edge?
if (predBlock->bbNum >= begBlk->bbNum)
{
backedgeList = new (this, CMK_FlowEdge) FlowEdge(predBlock, backedgeList);
backedgeList = new (this, CMK_FlowEdge) FlowEdge(predBlock, begBlk, backedgeList);

#if MEASURE_BLOCK_SIZE
genFlowNodeCnt += 1;
Expand Down

0 comments on commit 35bff27

Please sign in to comment.