[PATCH] D54212: [PGO] early exit if all count values are zero
Rong Xu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 7 08:53:47 PST 2018
xur created this revision.
xur added a reviewer: davidxl.
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.
https://reviews.llvm.org/D54212
Files:
lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Index: lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===================================================================
--- lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -859,7 +859,7 @@
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 @@
FuncInfo.dumpInfo(Str);
}
+ uint64_t getProgramMaxCount() const { return ProgramMaxCount; }
private:
Function &F;
Module *M;
@@ -1013,7 +1014,7 @@
// 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 @@
LLVM_DEBUG(dbgs() << " " << I << ": " << CountFromProfile[I] << "\n");
ValueSum += CountFromProfile[I];
}
+ AllZeros = (ValueSum == 0);
LLVM_DEBUG(dbgs() << "SUM = " << ValueSum << "\n");
@@ -1477,8 +1479,14 @@
// 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) {
+ if (Func.getProgramMaxCount() != 0)
+ ColdFunctions.push_back(&F);
+ continue;
+ }
Func.populateCounters();
Func.setBranchWeights();
Func.annotateValueSites();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54212.172965.patch
Type: text/x-patch
Size: 2045 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181107/236f1fcc/attachment.bin>
More information about the llvm-commits
mailing list