Skip to content

Commit 5499e2f

Browse files
committed
[llvm-dwarfdump][Statistics] Distinguish parameters with same name or w/o a name
A few DW_TAG_formal_parameter's of the same function may have the same name (e.g. variadic (template) functions) or don't have a name at all (if the parameter isn't used inside the function body), but we still need to be able to distinguish between them to get correct number of 'total vars' and 'availability' metric. Reviewed by: aprantl Differential Revision: https://reviews.llvm.org/D73003
1 parent 57839e5 commit 5499e2f

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,26 @@
2020
; int squared = square(i);
2121
; return squared*i;
2222
; }
23+
;
24+
; int boo(int, int) {}
2325

2426
; Following variables/arguments/members should be counted:
2527
; - GlobalConst,
2628
; - Global,
2729
; - s, s.constant,
2830
; - square::i,
2931
; - cube::i, cube::squared
32+
; - boo::1, boo::2
3033
; Skipped entities:
3134
; - declaration of test::a,
3235
; - non-constant member S:fn,
3336
; - arguments of S:fn.
3437

35-
; CHECK: "unique source variables":7
38+
; CHECK: "unique source variables":9
3639
; +1 extra inline i.
37-
; CHECK: "source variables":8
40+
; CHECK: "source variables":10
3841
; -1 square::i
39-
; CHECK: "variables with location":7
42+
; CHECK: "variables with location":9
4043
; CHECK: "scope bytes total":[[BYTES:[0-9]+]]
4144
; Because of the dbg.value in the middle of the function, the pc range coverage
4245
; must be below 100%.
@@ -99,6 +102,18 @@ entry:
99102
ret i32 %mul, !dbg !44
100103
}
101104

105+
; Function Attrs: noinline optnone uwtable
106+
define dso_local i32 @_Z3booii(i32 %0, i32 %1) !dbg !52 {
107+
entry:
108+
%.addr = alloca i32, align 4
109+
%.addr1 = alloca i32, align 4
110+
store i32 %0, i32* %.addr, align 4
111+
call void @llvm.dbg.declare(metadata i32* %.addr, metadata !55, metadata !DIExpression()), !dbg !56
112+
store i32 %1, i32* %.addr1, align 4
113+
call void @llvm.dbg.declare(metadata i32* %.addr1, metadata !57, metadata !DIExpression()), !dbg !58
114+
ret i32 0, !dbg !58
115+
}
116+
102117
attributes #0 = { alwaysinline nounwind ssp uwtable }
103118
attributes #1 = { nounwind readnone speculatable }
104119
attributes #2 = { noinline nounwind optnone ssp uwtable }
@@ -159,3 +174,10 @@ attributes #2 = { noinline nounwind optnone ssp uwtable }
159174
!49 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !2, entity: !50, file: !3, line: 2)
160175
!50 = !DIGlobalVariable(name: "a", linkageName: "_ZN4test1aE", scope: !51, file: !3, line: 2, type: !8, isLocal: false, isDefinition: false)
161176
!51 = !DINamespace(name: "test", scope: !2)
177+
!52 = distinct !DISubprogram(name: "boo", linkageName: "_Z3booii", scope: !3, file: !3, line: 10, type: !53, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4)
178+
!53 = !DISubroutineType(types: !54)
179+
!54 = !{!8, !8, !8}
180+
!55 = !DILocalVariable(arg: 1, scope: !52, file: !3, line: 10, type: !8)
181+
!56 = !DILocation(line: 10, column: 12, scope: !52)
182+
!57 = !DILocalVariable(arg: 2, scope: !52, file: !3, line: 10, type: !8)
183+
!58 = !DILocation(line: 10, column: 17, scope: !52)

llvm/tools/llvm-dwarfdump/Statistics.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,14 @@ static void collectStatsRecursive(DWARFDie Die, std::string FnPrefix,
436436

437437
// Traverse children.
438438
unsigned LexicalBlockIndex = 0;
439+
unsigned FormalParameterIndex = 0;
439440
DWARFDie Child = Die.getFirstChild();
440441
while (Child) {
441442
std::string ChildVarPrefix = VarPrefix;
442443
if (Child.getTag() == dwarf::DW_TAG_lexical_block)
443444
ChildVarPrefix += toHex(LexicalBlockIndex++) + '.';
445+
if (Child.getTag() == dwarf::DW_TAG_formal_parameter)
446+
ChildVarPrefix += 'p' + toHex(FormalParameterIndex++) + '.';
444447

445448
collectStatsRecursive(Child, FnPrefix, ChildVarPrefix, BytesInScope,
446449
InlineDepth, FnStatMap, GlobalStats, LocStats);

0 commit comments

Comments
 (0)