@@ -31,6 +31,8 @@ struct PerFunctionStats {
31
31
unsigned TotalVarWithLoc = 0 ;
32
32
// / Number of constants with location across all inlined instances.
33
33
unsigned ConstantMembers = 0 ;
34
+ // / Number of arificial variables, parameters or members across all instances.
35
+ unsigned NumArtificial = 0 ;
34
36
// / List of all Variables and parameters in this function.
35
37
StringSet<> VarsInFunction;
36
38
// / Compile units also cover a PC range, but have this flag set to false.
@@ -196,12 +198,13 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
196
198
bool HasLoc = false ;
197
199
bool HasSrcLoc = false ;
198
200
bool HasType = false ;
199
- bool IsArtificial = false ;
200
201
uint64_t BytesCovered = 0 ;
201
202
uint64_t BytesEntryValuesCovered = 0 ;
202
203
auto &FnStats = FnStatMap[FnPrefix];
203
204
bool IsParam = Die.getTag () == dwarf::DW_TAG_formal_parameter;
204
205
bool IsVariable = Die.getTag () == dwarf::DW_TAG_variable;
206
+ bool IsConstantMember = Die.getTag () == dwarf::DW_TAG_member &&
207
+ Die.find (dwarf::DW_AT_const_value);
205
208
206
209
if (Die.getTag () == dwarf::DW_TAG_call_site ||
207
210
Die.getTag () == dwarf::DW_TAG_GNU_call_site) {
@@ -215,7 +218,7 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
215
218
return ;
216
219
}
217
220
218
- if (!IsParam && !IsVariable && Die. getTag () != dwarf::DW_TAG_member ) {
221
+ if (!IsParam && !IsVariable && !IsConstantMember ) {
219
222
// Not a variable or constant member.
220
223
return ;
221
224
}
@@ -231,9 +234,6 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
231
234
if (Die.findRecursively (dwarf::DW_AT_type))
232
235
HasType = true ;
233
236
234
- if (Die.find (dwarf::DW_AT_artificial))
235
- IsArtificial = true ;
236
-
237
237
auto IsEntryValue = [&](ArrayRef<uint8_t > D) -> bool {
238
238
DWARFUnit *U = Die.getDwarfUnit ();
239
239
DataExtractor Data (toStringRef (D),
@@ -252,10 +252,6 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
252
252
HasLoc = true ;
253
253
BytesCovered = BytesInScope;
254
254
} else {
255
- if (Die.getTag () == dwarf::DW_TAG_member) {
256
- // Non-const member.
257
- return ;
258
- }
259
255
// Handle variables and function arguments.
260
256
Expected<std::vector<DWARFLocationExpression>> Loc =
261
257
Die.getLocations (dwarf::DW_AT_location);
@@ -307,7 +303,6 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
307
303
FnStats.VarsInFunction .insert (VarID);
308
304
309
305
if (BytesInScope) {
310
- FnStats.TotalVarWithLoc += (unsigned )HasLoc;
311
306
// Turns out we have a lot of ranges that extend past the lexical scope.
312
307
GlobalStats.ScopeBytesCovered += std::min (BytesInScope, BytesCovered);
313
308
GlobalStats.ScopeBytes += BytesInScope;
@@ -323,29 +318,36 @@ static void collectStatsForDie(DWARFDie Die, std::string FnPrefix,
323
318
GlobalStats.VarScopeEntryValueBytesCovered += BytesEntryValuesCovered;
324
319
}
325
320
assert (GlobalStats.ScopeBytesCovered <= GlobalStats.ScopeBytes );
326
- } else if (Die.getTag () == dwarf::DW_TAG_member) {
321
+ }
322
+
323
+ if (IsConstantMember) {
327
324
FnStats.ConstantMembers ++;
328
- } else {
329
- FnStats.TotalVarWithLoc += (unsigned )HasLoc;
325
+ return ;
330
326
}
331
- if (!IsArtificial) {
332
- if (IsParam) {
333
- FnStats.NumParams ++;
334
- if (HasType)
335
- FnStats.NumParamTypes ++;
336
- if (HasSrcLoc)
337
- FnStats.NumParamSourceLocations ++;
338
- if (HasLoc)
339
- FnStats.NumParamLocations ++;
340
- } else if (IsVariable) {
341
- FnStats.NumVars ++;
342
- if (HasType)
343
- FnStats.NumVarTypes ++;
344
- if (HasSrcLoc)
345
- FnStats.NumVarSourceLocations ++;
346
- if (HasLoc)
347
- FnStats.NumVarLocations ++;
348
- }
327
+
328
+ FnStats.TotalVarWithLoc += (unsigned )HasLoc;
329
+
330
+ if (Die.find (dwarf::DW_AT_artificial)) {
331
+ FnStats.NumArtificial ++;
332
+ return ;
333
+ }
334
+
335
+ if (IsParam) {
336
+ FnStats.NumParams ++;
337
+ if (HasType)
338
+ FnStats.NumParamTypes ++;
339
+ if (HasSrcLoc)
340
+ FnStats.NumParamSourceLocations ++;
341
+ if (HasLoc)
342
+ FnStats.NumParamLocations ++;
343
+ } else if (IsVariable) {
344
+ FnStats.NumVars ++;
345
+ if (HasType)
346
+ FnStats.NumVarTypes ++;
347
+ if (HasSrcLoc)
348
+ FnStats.NumVarSourceLocations ++;
349
+ if (HasLoc)
350
+ FnStats.NumVarLocations ++;
349
351
}
350
352
}
351
353
@@ -527,7 +529,7 @@ bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
527
529
(Stats.NumFnInlined + Stats.NumFnOutOfLine );
528
530
// Count variables in global scope.
529
531
if (!Stats.IsFunction )
530
- TotalVars + = Stats.VarsInFunction . size () ;
532
+ TotalVars = Stats.NumVars + Stats. ConstantMembers + Stats. NumArtificial ;
531
533
unsigned Constants = Stats.ConstantMembers ;
532
534
VarParamWithLoc += Stats.TotalVarWithLoc + Constants;
533
535
VarParamTotal += TotalVars;
0 commit comments