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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353491 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/tools/llvm-dwarfdump/X86/statistics.ll b/test/tools/llvm-dwarfdump/X86/statistics.ll
index 0ddae7e..73c56da 100644
--- a/test/tools/llvm-dwarfdump/X86/statistics.ll
+++ b/test/tools/llvm-dwarfdump/X86/statistics.ll
@@ -1,6 +1,6 @@
; RUN: llc -O0 %s -o - -filetype=obj \
; RUN: | llvm-dwarfdump -statistics - | FileCheck %s
-; CHECK: "version":1
+; CHECK: "version":2
; int GlobalConst = 42;
; int Global;
diff --git a/test/tools/llvm-dwarfdump/X86/stats-inlining-multi-cu.ll b/test/tools/llvm-dwarfdump/X86/stats-inlining-multi-cu.ll
index f8656e6..e6e193c 100644
--- a/test/tools/llvm-dwarfdump/X86/stats-inlining-multi-cu.ll
+++ b/test/tools/llvm-dwarfdump/X86/stats-inlining-multi-cu.ll
@@ -4,7 +4,7 @@
; Test that abstract origins in multiple CUs are uniqued.
; CHECK: "source functions":4,
-; CHECK-SAME: "inlined functions":5,
+; CHECK-SAME: "inlined functions":2,
; CHECK-SAME: "unique source variables":4
; CHECK-SAME: "source variables":6
; CHECK-SAME: "variables with location":6
diff --git a/test/tools/llvm-dwarfdump/X86/stats-inlining-single-cu.ll b/test/tools/llvm-dwarfdump/X86/stats-inlining-single-cu.ll
index 14ef709..5a4c354 100644
--- a/test/tools/llvm-dwarfdump/X86/stats-inlining-single-cu.ll
+++ b/test/tools/llvm-dwarfdump/X86/stats-inlining-single-cu.ll
@@ -5,7 +5,7 @@
; The results for both tests should be identical.
; CHECK: "source functions":4,
-; CHECK-SAME: "inlined functions":5,
+; CHECK-SAME: "inlined functions":2,
; CHECK-SAME: "unique source variables":4
; CHECK-SAME: "source variables":6
; CHECK-SAME: "variables with location":6
diff --git a/tools/llvm-dwarfdump/Statistics.cpp b/tools/llvm-dwarfdump/Statistics.cpp
index 5fe7e8b..a01a501 100644
--- a/tools/llvm-dwarfdump/Statistics.cpp
+++ b/tools/llvm-dwarfdump/Statistics.cpp
@@ -23,6 +23,9 @@
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 @@
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,21 +169,6 @@
if (Die.find(dwarf::DW_AT_declaration))
return;
- // Count the function.
- if (!IsBlock) {
- StringRef Name = Die.getName(DINameKind::LinkageName);
- if (Name.empty())
- Name = Die.getName(DINameKind::ShortName);
- FnPrefix = Name;
- // Skip over abstract origins.
- if (Die.find(dwarf::DW_AT_inline))
- return;
- // We've seen an (inlined) instance of this function.
- auto &FnStats = FnStatMap[Name];
- FnStats.NumFnInlined++;
- FnStats.IsFunction = true;
- }
-
// PC Ranges.
auto RangesOrError = Die.getAddressRanges();
if (!RangesOrError) {
@@ -192,6 +182,24 @@
BytesInThisScope += Range.HighPC - Range.LowPC;
ScopeLowPC = getLowPC(Die);
+ // Count the function.
+ if (!IsBlock) {
+ StringRef Name = Die.getName(DINameKind::LinkageName);
+ if (Name.empty())
+ Name = Die.getName(DINameKind::ShortName);
+ FnPrefix = Name;
+ // Skip over abstract origins.
+ if (Die.find(dwarf::DW_AT_inline))
+ return;
+ // We've seen an (inlined) instance of this function.
+ auto &FnStats = FnStatMap[Name];
+ if (IsInlinedFunction)
+ FnStats.NumFnInlined++;
+ FnStats.IsFunction = true;
+ if (BytesInThisScope && !IsInlinedFunction)
+ FnStats.HasPCAddresses = true;
+ }
+
if (BytesInThisScope) {
BytesInScope = BytesInThisScope;
if (IsFunction)
@@ -258,7 +266,7 @@
/// 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 @@
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");