Skip to content

Commit 6d34169

Browse files
committed
[pgo][nfc] Model Count as a std::optional in PGOUseEdge
Similar to PR llvm#83364.
1 parent 1a2960b commit 6d34169

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -961,21 +961,16 @@ namespace {
961961
struct PGOUseEdge : public PGOEdge {
962962
using PGOEdge::PGOEdge;
963963

964-
bool CountValid = false;
965-
uint64_t CountValue = 0;
964+
std::optional<uint64_t> Count;
966965

967966
// Set edge count value
968-
void setEdgeCount(uint64_t Value) {
969-
CountValue = Value;
970-
CountValid = true;
971-
}
967+
void setEdgeCount(uint64_t Value) { Count = Value; }
972968

973969
// Return the information string for this object.
974970
std::string infoString() const {
975-
if (!CountValid)
971+
if (!Count)
976972
return PGOEdge::infoString();
977-
return (Twine(PGOEdge::infoString()) + " Count=" + Twine(CountValue))
978-
.str();
973+
return (Twine(PGOEdge::infoString()) + " Count=" + Twine(*Count)).str();
979974
}
980975
};
981976

@@ -1022,7 +1017,8 @@ static uint64_t sumEdgeCount(const ArrayRef<PGOUseEdge *> Edges) {
10221017
for (const auto &E : Edges) {
10231018
if (E->Removed)
10241019
continue;
1025-
Total += E->CountValue;
1020+
if (E->Count)
1021+
Total += *E->Count;
10261022
}
10271023
return Total;
10281024
}
@@ -1221,7 +1217,7 @@ bool PGOUseFunc::setInstrumentedCounts(
12211217
if (DestInfo.Count && DestInfo.InEdges.size() == 1)
12221218
setEdgeCount(E.get(), *DestInfo.Count);
12231219
}
1224-
if (E->CountValid)
1220+
if (E->Count)
12251221
continue;
12261222
// E's count should have been set from profile. If not, this meenas E skips
12271223
// the instrumentation. We set the count to 0.
@@ -1234,7 +1230,7 @@ bool PGOUseFunc::setInstrumentedCounts(
12341230
// unknown edge in Edges vector.
12351231
void PGOUseFunc::setEdgeCount(DirectEdges &Edges, uint64_t Value) {
12361232
for (auto &E : Edges) {
1237-
if (E->CountValid)
1233+
if (E->Count)
12381234
continue;
12391235
E->setEdgeCount(Value);
12401236

@@ -1574,7 +1570,7 @@ void PGOUseFunc::setBranchWeights() {
15741570
if (DestBB == nullptr)
15751571
continue;
15761572
unsigned SuccNum = GetSuccessorNumber(SrcBB, DestBB);
1577-
uint64_t EdgeCount = E->CountValue;
1573+
uint64_t EdgeCount = *E->Count;
15781574
if (EdgeCount > MaxCount)
15791575
MaxCount = EdgeCount;
15801576
EdgeCounts[SuccNum] = EdgeCount;

0 commit comments

Comments
 (0)