From 6d34169426e409e2c52c5fb3c24fb0a79c0cd49c Mon Sep 17 00:00:00 2001 From: Mircea Trofin Date: Thu, 29 Feb 2024 15:56:09 -0800 Subject: [PATCH] [pgo][nfc] Model `Count` as a `std::optional` in `PGOUseEdge` Similar to PR #83364. --- .../Instrumentation/PGOInstrumentation.cpp | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 0c042e73ba083..55728709cde55 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -961,21 +961,16 @@ namespace { struct PGOUseEdge : public PGOEdge { using PGOEdge::PGOEdge; - bool CountValid = false; - uint64_t CountValue = 0; + std::optional Count; // Set edge count value - void setEdgeCount(uint64_t Value) { - CountValue = Value; - CountValid = true; - } + void setEdgeCount(uint64_t Value) { Count = Value; } // Return the information string for this object. std::string infoString() const { - if (!CountValid) + if (!Count) return PGOEdge::infoString(); - return (Twine(PGOEdge::infoString()) + " Count=" + Twine(CountValue)) - .str(); + return (Twine(PGOEdge::infoString()) + " Count=" + Twine(*Count)).str(); } }; @@ -1022,7 +1017,8 @@ static uint64_t sumEdgeCount(const ArrayRef Edges) { for (const auto &E : Edges) { if (E->Removed) continue; - Total += E->CountValue; + if (E->Count) + Total += *E->Count; } return Total; } @@ -1221,7 +1217,7 @@ bool PGOUseFunc::setInstrumentedCounts( if (DestInfo.Count && DestInfo.InEdges.size() == 1) setEdgeCount(E.get(), *DestInfo.Count); } - if (E->CountValid) + if (E->Count) continue; // E's count should have been set from profile. If not, this meenas E skips // the instrumentation. We set the count to 0. @@ -1234,7 +1230,7 @@ bool PGOUseFunc::setInstrumentedCounts( // unknown edge in Edges vector. void PGOUseFunc::setEdgeCount(DirectEdges &Edges, uint64_t Value) { for (auto &E : Edges) { - if (E->CountValid) + if (E->Count) continue; E->setEdgeCount(Value); @@ -1574,7 +1570,7 @@ void PGOUseFunc::setBranchWeights() { if (DestBB == nullptr) continue; unsigned SuccNum = GetSuccessorNumber(SrcBB, DestBB); - uint64_t EdgeCount = E->CountValue; + uint64_t EdgeCount = *E->Count; if (EdgeCount > MaxCount) MaxCount = EdgeCount; EdgeCounts[SuccNum] = EdgeCount;