diff options
| author | Caroline Tice <cmtice@google.com> | 2019-02-08 00:51:33 +0000 |
|---|---|---|
| committer | Caroline Tice <cmtice@google.com> | 2019-02-08 00:51:33 +0000 |
| commit | cef4c294170d24b56ffc557071a58525efede076 (patch) | |
| tree | 02f1e731cd1537c52dc98dbd8290e12ca4afea71 /llvm/tools/llvm-dwarfdump/Statistics.cpp | |
| parent | ddeb2f2a160595159b1e330385aaf51f5b2f3e51 (diff) | |
| download | bcm5719-llvm-cef4c294170d24b56ffc557071a58525efede076.tar.gz bcm5719-llvm-cef4c294170d24b56ffc557071a58525efede076.zip | |
lvm-dwarfdump: Stop counting out-of-line subprogram in the "inlined functions" statistic.
DW_TAG_subprogram DIEs should not be counted in the inlined function statistic. This also addresses the source variables count, as that uses the inlined function count in its calculations.
Differential revision: https://reviews.llvm.org/D57849
llvm-svn: 353491
Diffstat (limited to 'llvm/tools/llvm-dwarfdump/Statistics.cpp')
| -rw-r--r-- | llvm/tools/llvm-dwarfdump/Statistics.cpp | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/llvm/tools/llvm-dwarfdump/Statistics.cpp b/llvm/tools/llvm-dwarfdump/Statistics.cpp index 5fe7e8b4615..a01a5017c59 100644 --- a/llvm/tools/llvm-dwarfdump/Statistics.cpp +++ b/llvm/tools/llvm-dwarfdump/Statistics.cpp @@ -23,6 +23,9 @@ struct PerFunctionStats { StringSet<> VarsInFunction; /// Compile units also cover a PC range, but have this flag set to false. bool IsFunction = false; + /// Verify function definition has PC addresses (for detecting when + /// a function has been inlined everywhere). + bool HasPCAddresses = false; }; /// Holds accumulated global statistics about DIEs. @@ -136,8 +139,10 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix, GlobalStats.ScopeBytesFromFirstDefinition += BytesInScope; assert(GlobalStats.ScopeBytesCovered <= GlobalStats.ScopeBytesFromFirstDefinition); - } else { + } else if (Die.getTag() == dwarf::DW_TAG_member) { FnStats.ConstantMembers++; + } else { + FnStats.TotalVarWithLoc += (unsigned)HasLoc; } } @@ -164,6 +169,19 @@ static void collectStatsRecursive(DWARFDie Die, std::string FnPrefix, if (Die.find(dwarf::DW_AT_declaration)) return; + // PC Ranges. + auto RangesOrError = Die.getAddressRanges(); + if (!RangesOrError) { + llvm::consumeError(RangesOrError.takeError()); + return; + } + + auto Ranges = RangesOrError.get(); + uint64_t BytesInThisScope = 0; + for (auto Range : Ranges) + BytesInThisScope += Range.HighPC - Range.LowPC; + ScopeLowPC = getLowPC(Die); + // Count the function. if (!IsBlock) { StringRef Name = Die.getName(DINameKind::LinkageName); @@ -175,23 +193,13 @@ static void collectStatsRecursive(DWARFDie Die, std::string FnPrefix, return; // We've seen an (inlined) instance of this function. auto &FnStats = FnStatMap[Name]; - FnStats.NumFnInlined++; + if (IsInlinedFunction) + FnStats.NumFnInlined++; FnStats.IsFunction = true; + if (BytesInThisScope && !IsInlinedFunction) + FnStats.HasPCAddresses = true; } - // PC Ranges. - auto RangesOrError = Die.getAddressRanges(); - if (!RangesOrError) { - llvm::consumeError(RangesOrError.takeError()); - return; - } - - auto Ranges = RangesOrError.get(); - uint64_t BytesInThisScope = 0; - for (auto Range : Ranges) - BytesInThisScope += Range.HighPC - Range.LowPC; - ScopeLowPC = getLowPC(Die); - if (BytesInThisScope) { BytesInScope = BytesInThisScope; if (IsFunction) @@ -258,7 +266,7 @@ bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx, /// The version number should be increased every time the algorithm is changed /// (including bug fixes). New metrics may be added without increasing the /// version. - unsigned Version = 1; + unsigned Version = 2; unsigned VarTotal = 0; unsigned VarUnique = 0; unsigned VarWithLoc = 0; @@ -267,9 +275,12 @@ bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx, for (auto &Entry : Statistics) { PerFunctionStats &Stats = Entry.getValue(); unsigned TotalVars = Stats.VarsInFunction.size() * Stats.NumFnInlined; + // Count variables in concrete out-of-line functions and in global scope. + if (Stats.HasPCAddresses || !Stats.IsFunction) + TotalVars += Stats.VarsInFunction.size(); unsigned Constants = Stats.ConstantMembers; VarWithLoc += Stats.TotalVarWithLoc + Constants; - VarTotal += TotalVars + Constants; + VarTotal += TotalVars; VarUnique += Stats.VarsInFunction.size(); LLVM_DEBUG(for (auto &V : Stats.VarsInFunction) llvm::dbgs() << Entry.getKey() << ": " << V.getKey() << "\n"); |

