Skip to content

Commit 40d1c89

Browse files
authoredFeb 28, 2024
JIT: Use successor edges instead of block targets for remaining block kinds (#98993)
Part of #93020. Replaces BasicBlock::bbTarget/bbFalseTarget/bbTrueTarget with FlowEdge* members.
1 parent fc8bb88 commit 40d1c89

29 files changed

+1032
-919
lines changed
 

‎src/coreclr/jit/block.cpp

+32-32
Original file line numberDiff line numberDiff line change
@@ -676,11 +676,11 @@ void BasicBlock::dspKind() const
676676
break;
677677

678678
case BBJ_EHFILTERRET:
679-
printf(" -> %s (fltret)", dspBlockNum(bbTarget));
679+
printf(" -> %s (fltret)", dspBlockNum(GetTarget()));
680680
break;
681681

682682
case BBJ_EHCATCHRET:
683-
printf(" -> %s (cret)", dspBlockNum(bbTarget));
683+
printf(" -> %s (cret)", dspBlockNum(GetTarget()));
684684
break;
685685

686686
case BBJ_THROW:
@@ -694,28 +694,28 @@ void BasicBlock::dspKind() const
694694
case BBJ_ALWAYS:
695695
if (HasFlag(BBF_KEEP_BBJ_ALWAYS))
696696
{
697-
printf(" -> %s (ALWAYS)", dspBlockNum(bbTarget));
697+
printf(" -> %s (ALWAYS)", dspBlockNum(GetTarget()));
698698
}
699699
else
700700
{
701-
printf(" -> %s (always)", dspBlockNum(bbTarget));
701+
printf(" -> %s (always)", dspBlockNum(GetTarget()));
702702
}
703703
break;
704704

705705
case BBJ_LEAVE:
706-
printf(" -> %s (leave)", dspBlockNum(bbTarget));
706+
printf(" -> %s (leave)", dspBlockNum(GetTarget()));
707707
break;
708708

709709
case BBJ_CALLFINALLY:
710-
printf(" -> %s (callf)", dspBlockNum(bbTarget));
710+
printf(" -> %s (callf)", dspBlockNum(GetTarget()));
711711
break;
712712

713713
case BBJ_CALLFINALLYRET:
714-
printf(" -> %s (callfr)", dspBlockNum(bbTarget));
714+
printf(" -> %s (callfr)", dspBlockNum(GetTarget()));
715715
break;
716716

717717
case BBJ_COND:
718-
printf(" -> %s,%s (cond)", dspBlockNum(bbTrueTarget), dspBlockNum(bbFalseTarget));
718+
printf(" -> %s,%s (cond)", dspBlockNum(GetTrueTarget()), dspBlockNum(GetFalseTarget()));
719719
break;
720720

721721
case BBJ_SWITCH:
@@ -857,22 +857,27 @@ void BasicBlock::TransferTarget(BasicBlock* from)
857857
SetEhf(from->GetEhfTargets());
858858
from->bbEhfTargets = nullptr; // Make sure nobody uses the descriptor after this.
859859
break;
860+
861+
// TransferTarget may be called after setting the source block of `from`'s
862+
// successor edges to this block.
863+
// This means calling GetTarget/GetTrueTarget/GetFalseTarget would trigger asserts.
864+
// Avoid this by accessing the edges directly.
860865
case BBJ_COND:
861-
SetCond(from->GetTrueTarget(), from->GetFalseTarget());
866+
SetCond(from->bbTrueEdge, from->bbFalseEdge);
862867
break;
863868
case BBJ_ALWAYS:
864-
SetKindAndTarget(from->GetKind(), from->GetTarget());
869+
SetKindAndTargetEdge(BBJ_ALWAYS, from->bbTargetEdge);
865870
CopyFlags(from, BBF_NONE_QUIRK);
866871
break;
867872
case BBJ_CALLFINALLY:
868873
case BBJ_CALLFINALLYRET:
869874
case BBJ_EHCATCHRET:
870875
case BBJ_EHFILTERRET:
871876
case BBJ_LEAVE:
872-
SetKindAndTarget(from->GetKind(), from->GetTarget());
877+
SetKindAndTargetEdge(from->GetKind(), from->bbTargetEdge);
873878
break;
874879
default:
875-
SetKindAndTarget(from->GetKind()); // Clear the target
880+
SetKindAndTargetEdge(from->GetKind()); // Clear the target
876881
break;
877882
}
878883
assert(KindIs(from->GetKind()));
@@ -985,7 +990,7 @@ BasicBlock* BasicBlock::GetUniquePred(Compiler* compiler) const
985990
//
986991
BasicBlock* BasicBlock::GetUniqueSucc() const
987992
{
988-
return KindIs(BBJ_ALWAYS) ? bbTarget : nullptr;
993+
return KindIs(BBJ_ALWAYS) ? GetTarget() : nullptr;
989994
}
990995

991996
// Static vars.
@@ -1145,7 +1150,7 @@ unsigned BasicBlock::NumSucc() const
11451150
return 1;
11461151

11471152
case BBJ_COND:
1148-
if (bbTrueTarget == bbFalseTarget)
1153+
if (bbTrueEdge == bbFalseEdge)
11491154
{
11501155
return 1;
11511156
}
@@ -1199,18 +1204,18 @@ BasicBlock* BasicBlock::GetSucc(unsigned i) const
11991204
case BBJ_EHCATCHRET:
12001205
case BBJ_EHFILTERRET:
12011206
case BBJ_LEAVE:
1202-
return bbTarget;
1207+
return GetTarget();
12031208

12041209
case BBJ_COND:
12051210
if (i == 0)
12061211
{
1207-
return bbFalseTarget;
1212+
return GetFalseTarget();
12081213
}
12091214
else
12101215
{
12111216
assert(i == 1);
1212-
assert(bbFalseTarget != bbTrueTarget);
1213-
return bbTrueTarget;
1217+
assert(bbTrueEdge != bbFalseEdge);
1218+
return GetTrueTarget();
12141219
}
12151220

12161221
case BBJ_EHFINALLYRET:
@@ -1270,7 +1275,7 @@ unsigned BasicBlock::NumSucc(Compiler* comp)
12701275
return 1;
12711276

12721277
case BBJ_COND:
1273-
if (bbTrueTarget == bbFalseTarget)
1278+
if (bbTrueEdge == bbFalseEdge)
12741279
{
12751280
return 1;
12761281
}
@@ -1309,8 +1314,8 @@ BasicBlock* BasicBlock::GetSucc(unsigned i, Compiler* comp)
13091314
{
13101315
case BBJ_EHFILTERRET:
13111316
// Handler is the (sole) normal successor of the filter.
1312-
assert(comp->fgFirstBlockOfHandler(this) == bbTarget);
1313-
return bbTarget;
1317+
assert(comp->fgFirstBlockOfHandler(this) == GetTarget());
1318+
return GetTarget();
13141319

13151320
case BBJ_EHFINALLYRET:
13161321
assert(bbEhfTargets != nullptr);
@@ -1322,18 +1327,18 @@ BasicBlock* BasicBlock::GetSucc(unsigned i, Compiler* comp)
13221327
case BBJ_ALWAYS:
13231328
case BBJ_EHCATCHRET:
13241329
case BBJ_LEAVE:
1325-
return bbTarget;
1330+
return GetTarget();
13261331

13271332
case BBJ_COND:
13281333
if (i == 0)
13291334
{
1330-
return bbFalseTarget;
1335+
return GetFalseTarget();
13311336
}
13321337
else
13331338
{
13341339
assert(i == 1);
1335-
assert(bbFalseTarget != bbTrueTarget);
1336-
return bbTrueTarget;
1340+
assert(bbTrueEdge != bbFalseEdge);
1341+
return GetTrueTarget();
13371342
}
13381343

13391344
case BBJ_SWITCH:
@@ -1585,15 +1590,10 @@ BasicBlock* BasicBlock::New(Compiler* compiler)
15851590
return block;
15861591
}
15871592

1588-
BasicBlock* BasicBlock::New(Compiler* compiler, BBKinds kind, BasicBlock* target /* = nullptr */)
1593+
BasicBlock* BasicBlock::New(Compiler* compiler, BBKinds kind)
15891594
{
15901595
BasicBlock* block = BasicBlock::New(compiler);
1591-
1592-
// In some cases, we don't know a block's jump target during initialization, so don't check the jump kind/target
1593-
// yet.
1594-
// The checks will be done any time the jump kind/target is read or written to after initialization.
1595-
block->bbKind = kind;
1596-
block->bbTarget = target;
1596+
block->bbKind = kind;
15971597

15981598
if (block->KindIs(BBJ_THROW))
15991599
{

0 commit comments

Comments
 (0)