diff options
author | Diego Novillo <dnovillo@google.com> | 2015-11-20 21:46:38 +0000 |
---|---|---|
committer | Diego Novillo <dnovillo@google.com> | 2015-11-20 21:46:38 +0000 |
commit | 5fb49e5c5f43ff57909a9dc96b353135d9e1401e (patch) | |
tree | 4f55868f395acf0f0140ada360c16f875aa50b52 /llvm/lib/Transforms/IPO/SampleProfile.cpp | |
parent | dc67f9b7e8ab9e3ff3f3d8f35aa9cd7b5e58a1ad (diff) | |
download | llvm-5fb49e5c5f43ff57909a9dc96b353135d9e1401e.zip llvm-5fb49e5c5f43ff57909a9dc96b353135d9e1401e.tar.gz llvm-5fb49e5c5f43ff57909a9dc96b353135d9e1401e.tar.bz2 |
SamplePGO - Do not count never-executed inlined functions when computing coverage.
If a function was originally inlined but not actually hot at runtime,
its samples will not be counted inside the parent function. This throws
off the coverage calculation because it expects to find more used
records than it should.
Fixed by ignoring functions that will not be inlined into the parent.
Currently, this is inlined functions with 0 samples. In subsequent
patches, I'll change this to mean "cold" functions.
llvm-svn: 253716
Diffstat (limited to 'llvm/lib/Transforms/IPO/SampleProfile.cpp')
-rw-r--r-- | llvm/lib/Transforms/IPO/SampleProfile.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp index df8c8a0..816fc93 100644 --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -225,20 +225,39 @@ bool SampleCoverageTracker::markSamplesUsed(const FunctionSamples *Samples, unsigned SampleCoverageTracker::countUsedSamples(const FunctionSamples *Samples) const { auto I = SampleCoverage.find(Samples); + + // The size of the coverage map for Samples represents the number of records + // that were marked used at least once. unsigned Count = (I != SampleCoverage.end()) ? I->second.size() : 0; - for (const auto &I : Samples->getCallsiteSamples()) - Count += countUsedSamples(&I.second); + + // If there are inlined callsites in this function, count the samples found + // in the respective bodies. However, do not bother counting callees with 0 + // total samples, these are callees that were never invoked at runtime. + for (const auto &I : Samples->getCallsiteSamples()) { + const FunctionSamples *CalleeSamples = &I.second; + if (CalleeSamples->getTotalSamples() > 0) + Count += countUsedSamples(&I.second); + } + return Count; } /// Return the number of sample records in the body of this profile. /// -/// The count includes all the samples in inlined callees. +/// The count includes all the samples in inlined callees. However, callsites +/// with 0 samples indicate inlined function calls that were never actually +/// invoked at runtime. Ignore these callsites for coverage purposes. unsigned SampleCoverageTracker::countBodySamples(const FunctionSamples *Samples) const { unsigned Count = Samples->getBodySamples().size(); - for (const auto &I : Samples->getCallsiteSamples()) - Count += countBodySamples(&I.second); + + // Count all the callsites with non-zero samples. + for (const auto &I : Samples->getCallsiteSamples()) { + const FunctionSamples *CalleeSamples = &I.second; + if (CalleeSamples->getTotalSamples() > 0) + Count += countBodySamples(&I.second); + } + return Count; } |