Skip to content

Commit 35bff27

Browse files
JIT: Add FlowEdge destination block member (#98243)
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.
1 parent 8af0b00 commit 35bff27

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

src/coreclr/jit/block.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ FlowEdge* Compiler::BlockPredsWithEH(BasicBlock* blk)
142142
{
143143
if (bbInExnFlowRegions(tryIndex, bb) && !bb->isBBCallFinallyPairTail())
144144
{
145-
res = new (this, CMK_FlowEdge) FlowEdge(bb, res);
145+
res = new (this, CMK_FlowEdge) FlowEdge(bb, blk, res);
146146

147147
#if MEASURE_BLOCK_SIZE
148148
genFlowNodeCnt += 1;
@@ -164,7 +164,7 @@ FlowEdge* Compiler::BlockPredsWithEH(BasicBlock* blk)
164164
for (BasicBlock* filterBlk = enclosingDsc->ebdFilter; filterBlk != enclosingDsc->ebdHndBeg;
165165
filterBlk = filterBlk->Next())
166166
{
167-
res = new (this, CMK_FlowEdge) FlowEdge(filterBlk, res);
167+
res = new (this, CMK_FlowEdge) FlowEdge(filterBlk, blk, res);
168168

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

244244
assert(filterBlk->VisitEHEnclosedHandlerSecondPassSuccs(this, [blk](BasicBlock* succ) {
245245
return succ == blk ? BasicBlockVisit::Abort : BasicBlockVisit::Continue;

src/coreclr/jit/block.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,9 @@ struct FlowEdge
20592059
// The source of the control flow
20602060
BasicBlock* m_sourceBlock;
20612061

2062+
// The destination of the control flow
2063+
BasicBlock* m_destBlock;
2064+
20622065
// Edge weights
20632066
weight_t m_edgeWeightMin;
20642067
weight_t m_edgeWeightMax;
@@ -2074,9 +2077,10 @@ struct FlowEdge
20742077
bool m_likelihoodSet;
20752078

20762079
public:
2077-
FlowEdge(BasicBlock* block, FlowEdge* rest)
2080+
FlowEdge(BasicBlock* sourceBlock, BasicBlock* destBlock, FlowEdge* rest)
20782081
: m_nextPredEdge(rest)
2079-
, m_sourceBlock(block)
2082+
, m_sourceBlock(sourceBlock)
2083+
, m_destBlock(destBlock)
20802084
, m_edgeWeightMin(0)
20812085
, m_edgeWeightMax(0)
20822086
, m_likelihood(0)
@@ -2102,14 +2106,28 @@ struct FlowEdge
21022106

21032107
BasicBlock* getSourceBlock() const
21042108
{
2109+
assert(m_sourceBlock != nullptr);
21052110
return m_sourceBlock;
21062111
}
21072112

21082113
void setSourceBlock(BasicBlock* newBlock)
21092114
{
2115+
assert(newBlock != nullptr);
21102116
m_sourceBlock = newBlock;
21112117
}
21122118

2119+
BasicBlock* getDestinationBlock() const
2120+
{
2121+
assert(m_destBlock != nullptr);
2122+
return m_destBlock;
2123+
}
2124+
2125+
void setDestinationBlock(BasicBlock* newBlock)
2126+
{
2127+
assert(newBlock != nullptr);
2128+
m_destBlock = newBlock;
2129+
}
2130+
21132131
weight_t edgeWeightMin() const
21142132
{
21152133
return m_edgeWeightMin;

src/coreclr/jit/fgdiagnostic.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,10 @@ unsigned BBPredsChecker::CheckBBPreds(BasicBlock* block, unsigned curTraversalSt
26832683
}
26842684

26852685
assert(CheckJump(blockPred, block));
2686+
2687+
// Make sure the pred edge's destination block is correct
2688+
//
2689+
assert(pred->getDestinationBlock() == block);
26862690
}
26872691

26882692
// Make sure preds are in increasing BBnum order

src/coreclr/jit/fgflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ FlowEdge* Compiler::fgAddRefPred(BasicBlock* block, BasicBlock* blockPred, FlowE
204204

205205
// Create new edge in the list in the correct ordered location.
206206
//
207-
flow = new (this, CMK_FlowEdge) FlowEdge(blockPred, *listp);
207+
flow = new (this, CMK_FlowEdge) FlowEdge(blockPred, block, *listp);
208208
flow->incrementDupCount();
209209
*listp = flow;
210210

src/coreclr/jit/optimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void Compiler::optScaleLoopBlocks(BasicBlock* begBlk, BasicBlock* endBlk)
196196
// Is this a back edge?
197197
if (predBlock->bbNum >= begBlk->bbNum)
198198
{
199-
backedgeList = new (this, CMK_FlowEdge) FlowEdge(predBlock, backedgeList);
199+
backedgeList = new (this, CMK_FlowEdge) FlowEdge(predBlock, begBlk, backedgeList);
200200

201201
#if MEASURE_BLOCK_SIZE
202202
genFlowNodeCnt += 1;

0 commit comments

Comments
 (0)