@@ -60,28 +60,26 @@ struct PerFunctionStats {
6060struct GlobalStats {
6161 // / Total number of PC range bytes covered by DW_AT_locations.
6262 unsigned ScopeBytesCovered = 0 ;
63- // / Total number of PC range bytes in each variable's enclosing scope,
64- // / starting from the first definition of the variable.
65- unsigned ScopeBytesFromFirstDefinition = 0 ;
63+ // / Total number of PC range bytes in each variable's enclosing scope.
64+ unsigned ScopeBytes = 0 ;
6665 // / Total number of PC range bytes covered by DW_AT_locations with
6766 // / the debug entry values (DW_OP_entry_value).
6867 unsigned ScopeEntryValueBytesCovered = 0 ;
6968 // / Total number of PC range bytes covered by DW_AT_locations of
7069 // / formal parameters.
7170 unsigned ParamScopeBytesCovered = 0 ;
72- // / Total number of PC range bytes in each variable's enclosing scope,
73- // / starting from the first definition of the variable (only for parameters).
74- unsigned ParamScopeBytesFromFirstDefinition = 0 ;
71+ // / Total number of PC range bytes in each variable's enclosing scope
72+ // / (only for parameters).
73+ unsigned ParamScopeBytes = 0 ;
7574 // / Total number of PC range bytes covered by DW_AT_locations with
7675 // / the debug entry values (DW_OP_entry_value) (only for parameters).
7776 unsigned ParamScopeEntryValueBytesCovered = 0 ;
7877 // / Total number of PC range bytes covered by DW_AT_locations (only for local
7978 // / variables).
8079 unsigned VarScopeBytesCovered = 0 ;
81- // / Total number of PC range bytes in each variable's enclosing scope,
82- // / starting from the first definition of the variable (only for local
83- // / variables).
84- unsigned VarScopeBytesFromFirstDefinition = 0 ;
80+ // / Total number of PC range bytes in each variable's enclosing scope
81+ // / (only for local variables).
82+ unsigned VarScopeBytes = 0 ;
8583 // / Total number of PC range bytes covered by DW_AT_locations with
8684 // / the debug entry values (DW_OP_entry_value) (only for local variables).
8785 unsigned VarScopeEntryValueBytesCovered = 0 ;
@@ -133,19 +131,6 @@ struct LocationStats {
133131 unsigned NumVar = 0 ;
134132};
135133
136- // / Extract the low pc from a Die.
137- static uint64_t getLowPC (DWARFDie Die) {
138- auto RangesOrError = Die.getAddressRanges ();
139- DWARFAddressRangesVector Ranges;
140- if (RangesOrError)
141- Ranges = RangesOrError.get ();
142- else
143- llvm::consumeError (RangesOrError.takeError ());
144- if (Ranges.size ())
145- return Ranges[0 ].LowPC ;
146- return dwarf::toAddress (Die.find (dwarf::DW_AT_low_pc), 0 );
147- }
148-
149134// / Collect debug location statistics for one DIE.
150135static void collectLocStats (uint64_t BytesCovered, uint64_t BytesInScope,
151136 std::vector<unsigned > &VarParamLocStats,
@@ -177,8 +162,8 @@ static void collectLocStats(uint64_t BytesCovered, uint64_t BytesInScope,
177162
178163// / Collect debug info quality metrics for one DIE.
179164static void collectStatsForDie (DWARFDie Die, std::string FnPrefix,
180- std::string VarPrefix, uint64_t ScopeLowPC ,
181- uint64_t BytesInScope, uint32_t InlineDepth,
165+ std::string VarPrefix, uint64_t BytesInScope ,
166+ uint32_t InlineDepth,
182167 StringMap<PerFunctionStats> &FnStatMap,
183168 GlobalStats &GlobalStats,
184169 LocationStats &LocStats) {
@@ -188,7 +173,6 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
188173 bool IsArtificial = false ;
189174 uint64_t BytesCovered = 0 ;
190175 uint64_t BytesEntryValuesCovered = 0 ;
191- uint64_t OffsetToFirstDefinition = 0 ;
192176 auto &FnStats = FnStatMap[FnPrefix];
193177 bool IsParam = Die.getTag () == dwarf::DW_TAG_formal_parameter;
194178 bool IsLocalVar = Die.getTag () == dwarf::DW_TAG_variable;
@@ -262,16 +246,6 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
262246 if (IsEntryValue (Entry.Expr ))
263247 BytesEntryValuesCovered += BytesEntryCovered;
264248 }
265- if (!Loc->empty ()) {
266- uint64_t FirstDef = Loc->front ().Range ->LowPC ;
267- // Ranges sometimes start before the lexical scope.
268- if (FirstDef >= ScopeLowPC)
269- OffsetToFirstDefinition = FirstDef - ScopeLowPC;
270- // Or even after it. Count that as a failure.
271- if (OffsetToFirstDefinition > BytesInScope)
272- OffsetToFirstDefinition = 0 ;
273- }
274- assert (BytesInScope);
275249 }
276250 }
277251 }
@@ -304,25 +278,21 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
304278 FnStats.VarsInFunction .insert (VarPrefix + VarName);
305279 if (BytesInScope) {
306280 FnStats.TotalVarWithLoc += (unsigned )HasLoc;
307- // Adjust for the fact the variables often start their lifetime in the
308- // middle of the scope.
309- BytesInScope -= OffsetToFirstDefinition;
310281 // Turns out we have a lot of ranges that extend past the lexical scope.
311282 GlobalStats.ScopeBytesCovered += std::min (BytesInScope, BytesCovered);
312- GlobalStats.ScopeBytesFromFirstDefinition += BytesInScope;
283+ GlobalStats.ScopeBytes += BytesInScope;
313284 GlobalStats.ScopeEntryValueBytesCovered += BytesEntryValuesCovered;
314285 if (IsParam) {
315286 GlobalStats.ParamScopeBytesCovered +=
316287 std::min (BytesInScope, BytesCovered);
317- GlobalStats.ParamScopeBytesFromFirstDefinition += BytesInScope;
288+ GlobalStats.ParamScopeBytes += BytesInScope;
318289 GlobalStats.ParamScopeEntryValueBytesCovered += BytesEntryValuesCovered;
319290 } else if (IsLocalVar) {
320291 GlobalStats.VarScopeBytesCovered += std::min (BytesInScope, BytesCovered);
321- GlobalStats.VarScopeBytesFromFirstDefinition += BytesInScope;
292+ GlobalStats.VarScopeBytes += BytesInScope;
322293 GlobalStats.VarScopeEntryValueBytesCovered += BytesEntryValuesCovered;
323294 }
324- assert (GlobalStats.ScopeBytesCovered <=
325- GlobalStats.ScopeBytesFromFirstDefinition );
295+ assert (GlobalStats.ScopeBytesCovered <= GlobalStats.ScopeBytes );
326296 } else if (Die.getTag () == dwarf::DW_TAG_member) {
327297 FnStats.ConstantMembers ++;
328298 } else {
@@ -351,8 +321,8 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
351321
352322// / Recursively collect debug info quality metrics.
353323static void collectStatsRecursive (DWARFDie Die, std::string FnPrefix,
354- std::string VarPrefix, uint64_t ScopeLowPC ,
355- uint64_t BytesInScope, uint32_t InlineDepth,
324+ std::string VarPrefix, uint64_t BytesInScope ,
325+ uint32_t InlineDepth,
356326 StringMap<PerFunctionStats> &FnStatMap,
357327 GlobalStats &GlobalStats,
358328 LocationStats &LocStats) {
@@ -387,7 +357,6 @@ static void collectStatsRecursive(DWARFDie Die, std::string FnPrefix,
387357 uint64_t BytesInThisScope = 0 ;
388358 for (auto Range : Ranges)
389359 BytesInThisScope += Range.HighPC - Range.LowPC ;
390- ScopeLowPC = getLowPC (Die);
391360
392361 // Count the function.
393362 if (!IsBlock) {
@@ -423,8 +392,8 @@ static void collectStatsRecursive(DWARFDie Die, std::string FnPrefix,
423392 }
424393 } else {
425394 // Not a scope, visit the Die itself. It could be a variable.
426- collectStatsForDie (Die, FnPrefix, VarPrefix, ScopeLowPC, BytesInScope ,
427- InlineDepth, FnStatMap, GlobalStats, LocStats);
395+ collectStatsForDie (Die, FnPrefix, VarPrefix, BytesInScope, InlineDepth ,
396+ FnStatMap, GlobalStats, LocStats);
428397 }
429398
430399 // Set InlineDepth correctly for child recursion
@@ -441,9 +410,8 @@ static void collectStatsRecursive(DWARFDie Die, std::string FnPrefix,
441410 if (Child.getTag () == dwarf::DW_TAG_lexical_block)
442411 ChildVarPrefix += toHex (LexicalBlockIndex++) + ' .' ;
443412
444- collectStatsRecursive (Child, FnPrefix, ChildVarPrefix, ScopeLowPC,
445- BytesInScope, InlineDepth, FnStatMap, GlobalStats,
446- LocStats);
413+ collectStatsRecursive (Child, FnPrefix, ChildVarPrefix, BytesInScope,
414+ InlineDepth, FnStatMap, GlobalStats, LocStats);
447415 Child = Child.getSibling ();
448416 }
449417}
@@ -496,13 +464,13 @@ bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
496464 StringMap<PerFunctionStats> Statistics;
497465 for (const auto &CU : static_cast <DWARFContext *>(&DICtx)->compile_units ())
498466 if (DWARFDie CUDie = CU->getNonSkeletonUnitDIE (false ))
499- collectStatsRecursive (CUDie, " /" , " g" , 0 , 0 , 0 , Statistics, GlobalStats,
467+ collectStatsRecursive (CUDie, " /" , " g" , 0 , 0 , Statistics, GlobalStats,
500468 LocStats);
501469
502470 // / The version number should be increased every time the algorithm is changed
503471 // / (including bug fixes). New metrics may be added without increasing the
504472 // / version.
505- unsigned Version = 3 ;
473+ unsigned Version = 4 ;
506474 unsigned VarParamTotal = 0 ;
507475 unsigned VarParamUnique = 0 ;
508476 unsigned VarParamWithLoc = 0 ;
@@ -562,19 +530,17 @@ bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
562530 printDatum (OS, " call site entries" , GlobalStats.CallSiteEntries );
563531 printDatum (OS, " call site DIEs" , GlobalStats.CallSiteDIEs );
564532 printDatum (OS, " call site parameter DIEs" , GlobalStats.CallSiteParamDIEs );
565- printDatum (OS, " scope bytes total" ,
566- GlobalStats.ScopeBytesFromFirstDefinition );
533+ printDatum (OS, " scope bytes total" , GlobalStats.ScopeBytes );
567534 printDatum (OS, " scope bytes covered" , GlobalStats.ScopeBytesCovered );
568535 printDatum (OS, " entry value scope bytes covered" ,
569536 GlobalStats.ScopeEntryValueBytesCovered );
570537 printDatum (OS, " formal params scope bytes total" ,
571- GlobalStats.ParamScopeBytesFromFirstDefinition );
538+ GlobalStats.ParamScopeBytes );
572539 printDatum (OS, " formal params scope bytes covered" ,
573540 GlobalStats.ParamScopeBytesCovered );
574541 printDatum (OS, " formal params entry value scope bytes covered" ,
575542 GlobalStats.ParamScopeEntryValueBytesCovered );
576- printDatum (OS, " vars scope bytes total" ,
577- GlobalStats.VarScopeBytesFromFirstDefinition );
543+ printDatum (OS, " vars scope bytes total" , GlobalStats.VarScopeBytes );
578544 printDatum (OS, " vars scope bytes covered" , GlobalStats.VarScopeBytesCovered );
579545 printDatum (OS, " vars entry value scope bytes covered" ,
580546 GlobalStats.VarScopeEntryValueBytesCovered );
@@ -609,7 +575,7 @@ bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
609575 << " %\n " ;
610576 llvm::dbgs () << " PC Ranges covered: "
611577 << (int )std::round ((GlobalStats.ScopeBytesCovered * 100.0 ) /
612- GlobalStats.ScopeBytesFromFirstDefinition )
578+ GlobalStats.ScopeBytes )
613579 << " %\n " );
614580 return true ;
615581}
0 commit comments