diff options
author | Rong Xu <xur@google.com> | 2018-11-07 23:51:20 +0000 |
---|---|---|
committer | Rong Xu <xur@google.com> | 2018-11-07 23:51:20 +0000 |
commit | fb4bcc452c0cfba85b7e5b177727eb8c8f966c58 (patch) | |
tree | 4c56e5c3546d58ff9a5f34f3a5beecd577a5a6d1 /llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | |
parent | 892bbd3f88b9f44efeb4fa9156e569c188d600f3 (diff) | |
download | bcm5719-llvm-fb4bcc452c0cfba85b7e5b177727eb8c8f966c58.tar.gz bcm5719-llvm-fb4bcc452c0cfba85b7e5b177727eb8c8f966c58.zip |
[PGO] Exit early if all count values are zero
If all the edge counts for a function are zero, skip count population and
annotation, as nothing will happen. This can save some compile time.
Differential Revision: https://reviews.llvm.org/D54212
llvm-svn: 346370
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 4790c9e5cfe..876ae23dfd2 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -859,7 +859,7 @@ public: FreqAttr(FFA_Normal) {} // Read counts for the instrumented BB from profile. - bool readCounters(IndexedInstrProfReader *PGOReader); + bool readCounters(IndexedInstrProfReader *PGOReader, bool &AllZeros); // Populate the counts for all BBs. void populateCounters(); @@ -904,6 +904,7 @@ public: FuncInfo.dumpInfo(Str); } + uint64_t getProgramMaxCount() const { return ProgramMaxCount; } private: Function &F; Module *M; @@ -1013,7 +1014,7 @@ void PGOUseFunc::setEdgeCount(DirectEdges &Edges, uint64_t Value) { // Read the profile from ProfileFileName and assign the value to the // instrumented BB and the edges. This function also updates ProgramMaxCount. // Return true if the profile are successfully read, and false on errors. -bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader) { +bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader, bool &AllZeros) { auto &Ctx = M->getContext(); Expected<InstrProfRecord> Result = PGOReader->getInstrProfRecord(FuncInfo.FuncName, FuncInfo.FunctionHash); @@ -1053,6 +1054,7 @@ bool PGOUseFunc::readCounters(IndexedInstrProfReader *PGOReader) { LLVM_DEBUG(dbgs() << " " << I << ": " << CountFromProfile[I] << "\n"); ValueSum += CountFromProfile[I]; } + AllZeros = (ValueSum == 0); LLVM_DEBUG(dbgs() << "SUM = " << ValueSum << "\n"); @@ -1477,8 +1479,15 @@ static bool annotateAllFunctions( // later in getInstrBB() to avoid invalidating it. SplitIndirectBrCriticalEdges(F, BPI, BFI); PGOUseFunc Func(F, &M, ComdatMembers, BPI, BFI); - if (!Func.readCounters(PGOReader.get())) + bool AllZeros = false; + if (!Func.readCounters(PGOReader.get(), AllZeros)) continue; + if (AllZeros) { + F.setEntryCount(ProfileCount(0, Function::PCT_Real)); + if (Func.getProgramMaxCount() != 0) + ColdFunctions.push_back(&F); + continue; + } Func.populateCounters(); Func.setBranchWeights(); Func.annotateValueSites(); |