Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cef4c29

Browse files
committed
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
1 parent ddeb2f2 commit cef4c29

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

llvm/test/tools/llvm-dwarfdump/X86/statistics.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; RUN: llc -O0 %s -o - -filetype=obj \
22
; RUN: | llvm-dwarfdump -statistics - | FileCheck %s
3-
; CHECK: "version":1
3+
; CHECK: "version":2
44

55
; int GlobalConst = 42;
66
; int Global;

llvm/test/tools/llvm-dwarfdump/X86/stats-inlining-multi-cu.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
; Test that abstract origins in multiple CUs are uniqued.
55

66
; CHECK: "source functions":4,
7-
; CHECK-SAME: "inlined functions":5,
7+
; CHECK-SAME: "inlined functions":2,
88
; CHECK-SAME: "unique source variables":4
99
; CHECK-SAME: "source variables":6
1010
; CHECK-SAME: "variables with location":6

llvm/test/tools/llvm-dwarfdump/X86/stats-inlining-single-cu.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
; The results for both tests should be identical.
66

77
; CHECK: "source functions":4,
8-
; CHECK-SAME: "inlined functions":5,
8+
; CHECK-SAME: "inlined functions":2,
99
; CHECK-SAME: "unique source variables":4
1010
; CHECK-SAME: "source variables":6
1111
; CHECK-SAME: "variables with location":6

llvm/tools/llvm-dwarfdump/Statistics.cpp

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ struct PerFunctionStats {
2323
StringSet<> VarsInFunction;
2424
/// Compile units also cover a PC range, but have this flag set to false.
2525
bool IsFunction = false;
26+
/// Verify function definition has PC addresses (for detecting when
27+
/// a function has been inlined everywhere).
28+
bool HasPCAddresses = false;
2629
};
2730

2831
/// Holds accumulated global statistics about DIEs.
@@ -136,8 +139,10 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
136139
GlobalStats.ScopeBytesFromFirstDefinition += BytesInScope;
137140
assert(GlobalStats.ScopeBytesCovered <=
138141
GlobalStats.ScopeBytesFromFirstDefinition);
139-
} else {
142+
} else if (Die.getTag() == dwarf::DW_TAG_member) {
140143
FnStats.ConstantMembers++;
144+
} else {
145+
FnStats.TotalVarWithLoc += (unsigned)HasLoc;
141146
}
142147
}
143148

@@ -164,6 +169,19 @@ static void collectStatsRecursive(DWARFDie Die, std::string FnPrefix,
164169
if (Die.find(dwarf::DW_AT_declaration))
165170
return;
166171

172+
// PC Ranges.
173+
auto RangesOrError = Die.getAddressRanges();
174+
if (!RangesOrError) {
175+
llvm::consumeError(RangesOrError.takeError());
176+
return;
177+
}
178+
179+
auto Ranges = RangesOrError.get();
180+
uint64_t BytesInThisScope = 0;
181+
for (auto Range : Ranges)
182+
BytesInThisScope += Range.HighPC - Range.LowPC;
183+
ScopeLowPC = getLowPC(Die);
184+
167185
// Count the function.
168186
if (!IsBlock) {
169187
StringRef Name = Die.getName(DINameKind::LinkageName);
@@ -175,23 +193,13 @@ static void collectStatsRecursive(DWARFDie Die, std::string FnPrefix,
175193
return;
176194
// We've seen an (inlined) instance of this function.
177195
auto &FnStats = FnStatMap[Name];
178-
FnStats.NumFnInlined++;
196+
if (IsInlinedFunction)
197+
FnStats.NumFnInlined++;
179198
FnStats.IsFunction = true;
199+
if (BytesInThisScope && !IsInlinedFunction)
200+
FnStats.HasPCAddresses = true;
180201
}
181202

182-
// PC Ranges.
183-
auto RangesOrError = Die.getAddressRanges();
184-
if (!RangesOrError) {
185-
llvm::consumeError(RangesOrError.takeError());
186-
return;
187-
}
188-
189-
auto Ranges = RangesOrError.get();
190-
uint64_t BytesInThisScope = 0;
191-
for (auto Range : Ranges)
192-
BytesInThisScope += Range.HighPC - Range.LowPC;
193-
ScopeLowPC = getLowPC(Die);
194-
195203
if (BytesInThisScope) {
196204
BytesInScope = BytesInThisScope;
197205
if (IsFunction)
@@ -258,7 +266,7 @@ bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
258266
/// The version number should be increased every time the algorithm is changed
259267
/// (including bug fixes). New metrics may be added without increasing the
260268
/// version.
261-
unsigned Version = 1;
269+
unsigned Version = 2;
262270
unsigned VarTotal = 0;
263271
unsigned VarUnique = 0;
264272
unsigned VarWithLoc = 0;
@@ -267,9 +275,12 @@ bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
267275
for (auto &Entry : Statistics) {
268276
PerFunctionStats &Stats = Entry.getValue();
269277
unsigned TotalVars = Stats.VarsInFunction.size() * Stats.NumFnInlined;
278+
// Count variables in concrete out-of-line functions and in global scope.
279+
if (Stats.HasPCAddresses || !Stats.IsFunction)
280+
TotalVars += Stats.VarsInFunction.size();
270281
unsigned Constants = Stats.ConstantMembers;
271282
VarWithLoc += Stats.TotalVarWithLoc + Constants;
272-
VarTotal += TotalVars + Constants;
283+
VarTotal += TotalVars;
273284
VarUnique += Stats.VarsInFunction.size();
274285
LLVM_DEBUG(for (auto &V : Stats.VarsInFunction) llvm::dbgs()
275286
<< Entry.getKey() << ": " << V.getKey() << "\n");

0 commit comments

Comments
 (0)