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.
GlobalStats.ScopeBytesFromFirstDefinition += BytesInScope;
assert(GlobalStats.ScopeBytesCovered <=
GlobalStats.ScopeBytesFromFirstDefinition);
- } else {
+ } else if (Die.getTag() == dwarf::DW_TAG_member) {
FnStats.ConstantMembers++;
+ } else {
+ FnStats.TotalVarWithLoc += (unsigned)HasLoc;
}
}
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);
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)
/// 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;
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");