diff options
author | Rong Xu <xur@google.com> | 2019-04-11 20:54:17 +0000 |
---|---|---|
committer | Rong Xu <xur@google.com> | 2019-04-11 20:54:17 +0000 |
commit | 959ef1685979e96a745ac20f1b34ccd080656cb2 (patch) | |
tree | 9cc1228f6ddb12ed122ab2201db9b46c1e2a65ca /llvm/lib/Transforms | |
parent | a318a7f6651e931bd947ec9ee0b8b91ca2107aea (diff) | |
download | bcm5719-llvm-959ef1685979e96a745ac20f1b34ccd080656cb2.tar.gz bcm5719-llvm-959ef1685979e96a745ac20f1b34ccd080656cb2.zip |
[PGO] Better handling of profile hash mismatch
We currently assume profile hash conflicts will be caught by an upfront
check and we assert for the cases that escape the check. The assumption
is not always true as there are chances of conflict. This patch prints
a warning and skips annotating the function for the escaped cases,.
Differential Revision: https://reviews.llvm.org/D60154
llvm-svn: 358225
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 99377b8a6cd..b1c7687e19f 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -1006,8 +1006,8 @@ private: // Is to use the context sensitive profile. bool IsCS; - // Find the Instrumented BB and set the value. - void setInstrumentedCounts(const std::vector<uint64_t> &CountFromProfile); + // Find the Instrumented BB and set the value. Return false on error. + bool setInstrumentedCounts(const std::vector<uint64_t> &CountFromProfile); // Set the edge counter value for the unknown edge -- there should be only // one unknown edge. @@ -1036,10 +1036,14 @@ private: } // end anonymous namespace // Visit all the edges and assign the count value for the instrumented -// edges and the BB. -void PGOUseFunc::setInstrumentedCounts( +// edges and the BB. Return false on error. +bool PGOUseFunc::setInstrumentedCounts( const std::vector<uint64_t> &CountFromProfile) { - assert(FuncInfo.getNumCounters() == CountFromProfile.size()); + // The number of counters here should match the number of counters + // in profile. Return if they mismatch. + if (FuncInfo.getNumCounters() != CountFromProfile.size()) { + return false; + } // Use a worklist as we will update the vector during the iteration. std::vector<PGOUseEdge *> WorkList; for (auto &E : FuncInfo.MST.AllEdges) @@ -1071,6 +1075,7 @@ void PGOUseFunc::setInstrumentedCounts( } ProfileCountSize = CountFromProfile.size(); CountPosition = I; + return true; } // Set the count value for the unknown edge. There should be one and only one @@ -1146,7 +1151,16 @@ bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader, bool &AllZeros) getBBInfo(nullptr).UnknownCountOutEdge = 2; getBBInfo(nullptr).UnknownCountInEdge = 2; - setInstrumentedCounts(CountFromProfile); + if (!setInstrumentedCounts(CountFromProfile)) { + LLVM_DEBUG( + dbgs() << "Inconsistent number of counts, skipping this function"); + Ctx.diagnose(DiagnosticInfoPGOProfile( + M->getName().data(), + Twine("Inconsistent number of counts in ") + F.getName().str() + + Twine(": the profile may be stale or there is a function name collision."), + DS_Warning)); + return false; + } ProgramMaxCount = PGOReader->getMaximumFunctionCount(IsCS); return true; } |