Skip to content

Commit b6d294d

Browse files
JIT: Unify block successor iteration logic (#117743)
Follow-up to #117423. * Collapse `BBSuccList` and `BBSuccEdgeList` into one templatized type, where the template specifies the iterator kind * Remove `BasicBlock::NumSucc(Compiler*)` et al * Have `BasicBlock::NumSucc()` et al deal only with unique successors, now that they're always available * For the occasional case where we have a switch block, and we want to iterate its cases with duplicates, we don't rely on the general successor iteration pattern, anyway * (unrelated) Remove `BasicBlock::bbFallsThrough`
1 parent 3e239f8 commit b6d294d

File tree

14 files changed

+82
-436
lines changed

14 files changed

+82
-436
lines changed

src/coreclr/jit/block.cpp

Lines changed: 7 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,10 @@ unsigned BasicBlock::dspPreds() const
580580
//------------------------------------------------------------------------
581581
// dspSuccs: Display the basic block successors.
582582
//
583-
// Arguments:
584-
// compiler - compiler instance; passed to NumSucc(Compiler*) -- see that function for implications.
585-
//
586-
void BasicBlock::dspSuccs(Compiler* compiler)
583+
void BasicBlock::dspSuccs() const
587584
{
588585
bool first = true;
589-
for (const BasicBlock* const succ : Succs(compiler))
586+
for (const BasicBlock* const succ : Succs())
590587
{
591588
printf("%s" FMT_BB, first ? "" : ",", succ->bbNum);
592589
first = false;
@@ -734,10 +731,7 @@ void BasicBlock::dspKind() const
734731
}
735732
}
736733

737-
void BasicBlock::dspBlockHeader(Compiler* compiler,
738-
bool showKind /*= true*/,
739-
bool showFlags /*= false*/,
740-
bool showPreds /*= true*/)
734+
void BasicBlock::dspBlockHeader(bool showKind /*= true*/, bool showFlags /*= false*/, bool showPreds /*= true*/) const
741735
{
742736
printf("%s ", dspToString());
743737
dspBlockILRange();
@@ -750,7 +744,7 @@ void BasicBlock::dspBlockHeader(Compiler* compiler,
750744
printf(", preds={");
751745
dspPreds();
752746
printf("} succs={");
753-
dspSuccs(compiler);
747+
dspSuccs();
754748
printf("}");
755749
}
756750
if (showFlags)
@@ -1066,41 +1060,6 @@ Statement* BasicBlock::FirstNonPhiDefOrCatchArgStore() const
10661060
return stmt;
10671061
}
10681062

1069-
//------------------------------------------------------------------------
1070-
// bbFallsThrough: Check if inserting a BasicBlock after this one will alter
1071-
// the flowgraph.
1072-
//
1073-
// Returns:
1074-
// True if so.
1075-
//
1076-
bool BasicBlock::bbFallsThrough() const
1077-
{
1078-
switch (bbKind)
1079-
{
1080-
case BBJ_THROW:
1081-
case BBJ_EHFINALLYRET:
1082-
case BBJ_EHFAULTRET:
1083-
case BBJ_EHFILTERRET:
1084-
case BBJ_EHCATCHRET:
1085-
case BBJ_RETURN:
1086-
case BBJ_ALWAYS:
1087-
case BBJ_CALLFINALLYRET:
1088-
case BBJ_LEAVE:
1089-
case BBJ_SWITCH:
1090-
return false;
1091-
1092-
case BBJ_COND:
1093-
return true;
1094-
1095-
case BBJ_CALLFINALLY:
1096-
return !HasFlag(BBF_RETLESS_CALL);
1097-
1098-
default:
1099-
assert(!"Unknown bbKind in bbFallsThrough()");
1100-
return true;
1101-
}
1102-
}
1103-
11041063
//------------------------------------------------------------------------
11051064
// NumSucc: Returns the count of block successors. See the declaration comment for details.
11061065
//
@@ -1155,15 +1114,15 @@ unsigned BasicBlock::NumSucc() const
11551114
return bbEhfTargets->GetSuccCount();
11561115

11571116
case BBJ_SWITCH:
1158-
return bbSwtTargets->GetCaseCount();
1117+
return bbSwtTargets->GetSuccCount();
11591118

11601119
default:
11611120
unreached();
11621121
}
11631122
}
11641123

11651124
//------------------------------------------------------------------------
1166-
// GetSucc: Returns the requested successor edge. See the declaration comment for details.
1125+
// GetSuccEdge: Returns the requested successor edge. See the declaration comment for details.
11671126
//
11681127
// Arguments:
11691128
// i - index of successor to return. 0 <= i <= NumSucc().
@@ -1200,7 +1159,7 @@ FlowEdge* BasicBlock::GetSuccEdge(unsigned i) const
12001159
return bbEhfTargets->GetSucc(i);
12011160

12021161
case BBJ_SWITCH:
1203-
return bbSwtTargets->GetCase(i);
1162+
return bbSwtTargets->GetSucc(i);
12041163

12051164
default:
12061165
unreached();
@@ -1221,137 +1180,6 @@ BasicBlock* BasicBlock::GetSucc(unsigned i) const
12211180
return GetSuccEdge(i)->getDestinationBlock();
12221181
}
12231182

1224-
//------------------------------------------------------------------------
1225-
// NumSucc: Returns the count of block successors. See the declaration comment for details.
1226-
//
1227-
// Arguments:
1228-
// comp - Compiler instance
1229-
//
1230-
// Return Value:
1231-
// Count of block successors.
1232-
//
1233-
unsigned BasicBlock::NumSucc(Compiler* comp)
1234-
{
1235-
assert(comp != nullptr);
1236-
1237-
switch (bbKind)
1238-
{
1239-
case BBJ_THROW:
1240-
case BBJ_RETURN:
1241-
case BBJ_EHFAULTRET:
1242-
return 0;
1243-
1244-
case BBJ_EHFINALLYRET:
1245-
// We may call this method before we realize we have invalid IL. Tolerate.
1246-
//
1247-
if (!hasHndIndex())
1248-
{
1249-
return 0;
1250-
}
1251-
1252-
// We may call this before we've computed the BBJ_EHFINALLYRET successors in the importer. Tolerate.
1253-
//
1254-
if (bbEhfTargets == nullptr)
1255-
{
1256-
return 0;
1257-
}
1258-
1259-
return bbEhfTargets->GetSuccCount();
1260-
1261-
case BBJ_CALLFINALLY:
1262-
case BBJ_CALLFINALLYRET:
1263-
case BBJ_ALWAYS:
1264-
case BBJ_EHCATCHRET:
1265-
case BBJ_EHFILTERRET:
1266-
case BBJ_LEAVE:
1267-
return 1;
1268-
1269-
case BBJ_COND:
1270-
if (bbTrueEdge == bbFalseEdge)
1271-
{
1272-
return 1;
1273-
}
1274-
else
1275-
{
1276-
return 2;
1277-
}
1278-
1279-
case BBJ_SWITCH:
1280-
return bbSwtTargets->GetSuccCount();
1281-
1282-
default:
1283-
unreached();
1284-
}
1285-
}
1286-
1287-
//------------------------------------------------------------------------
1288-
// GetSucc: Returns the requested successor edge. See the declaration comment for details.
1289-
//
1290-
// Arguments:
1291-
// i - index of successor to return. 0 <= i <= NumSucc(comp).
1292-
// comp - Compiler instance
1293-
//
1294-
// Return Value:
1295-
// Requested successor edge
1296-
//
1297-
FlowEdge* BasicBlock::GetSuccEdge(unsigned i, Compiler* comp)
1298-
{
1299-
assert(comp != nullptr);
1300-
1301-
assert(i < NumSucc(comp)); // Index bounds check.
1302-
switch (bbKind)
1303-
{
1304-
case BBJ_EHFILTERRET:
1305-
// Handler is the (sole) normal successor of the filter.
1306-
assert(comp->fgFirstBlockOfHandler(this) == GetTarget());
1307-
return GetTargetEdge();
1308-
1309-
case BBJ_EHFINALLYRET:
1310-
assert(bbEhfTargets != nullptr);
1311-
return bbEhfTargets->GetSucc(i);
1312-
1313-
case BBJ_CALLFINALLY:
1314-
case BBJ_CALLFINALLYRET:
1315-
case BBJ_ALWAYS:
1316-
case BBJ_EHCATCHRET:
1317-
case BBJ_LEAVE:
1318-
return GetTargetEdge();
1319-
1320-
case BBJ_COND:
1321-
if (i == 0)
1322-
{
1323-
return GetFalseEdge();
1324-
}
1325-
else
1326-
{
1327-
assert(i == 1);
1328-
assert(bbTrueEdge != bbFalseEdge);
1329-
return GetTrueEdge();
1330-
}
1331-
1332-
case BBJ_SWITCH:
1333-
return bbSwtTargets->GetSucc(i);
1334-
1335-
default:
1336-
unreached();
1337-
}
1338-
}
1339-
1340-
//------------------------------------------------------------------------
1341-
// GetSucc: Returns the requested block successor. See the declaration comment for details.
1342-
//
1343-
// Arguments:
1344-
// i - index of successor to return. 0 <= i <= NumSucc(comp).
1345-
// comp - Compiler instance
1346-
//
1347-
// Return Value:
1348-
// Requested successor block
1349-
//
1350-
BasicBlock* BasicBlock::GetSucc(unsigned i, Compiler* comp)
1351-
{
1352-
return GetSuccEdge(i, comp)->getDestinationBlock();
1353-
}
1354-
13551183
void BasicBlock::InitVarSets(Compiler* comp)
13561184
{
13571185
VarSetOps::AssignNoCopy(comp, bbVarUse, VarSetOps::MakeEmpty(comp));

0 commit comments

Comments
 (0)