[llvm] 5499e2f - [llvm-dwarfdump][Statistics] Distinguish parameters with same name or w/o a name

Kristina Bessonova via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 10:56:33 PST 2020


Author: Kristina Bessonova
Date: 2020-01-28T20:52:20+02:00
New Revision: 5499e2f455caad5c7cf95aa459b8d246e14c6af9

URL: https://github.com/llvm/llvm-project/commit/5499e2f455caad5c7cf95aa459b8d246e14c6af9
DIFF: https://github.com/llvm/llvm-project/commit/5499e2f455caad5c7cf95aa459b8d246e14c6af9.diff

LOG: [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

Added: 
    

Modified: 
    llvm/test/tools/llvm-dwarfdump/X86/statistics.ll
    llvm/tools/llvm-dwarfdump/Statistics.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-dwarfdump/X86/statistics.ll b/llvm/test/tools/llvm-dwarfdump/X86/statistics.ll
index 4fa7f9363732..1830e27837dd 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/statistics.ll
+++ b/llvm/test/tools/llvm-dwarfdump/X86/statistics.ll
@@ -20,6 +20,8 @@
 ;   int squared = square(i);
 ;   return squared*i;
 ; }
+;
+; int boo(int, int) {}
 
 ; Following variables/arguments/members should be counted:
 ;     - GlobalConst,
@@ -27,16 +29,17 @@
 ;     - s, s.constant,
 ;     - square::i,
 ;     - cube::i, cube::squared
+;     - boo::1, boo::2
 ; Skipped entities:
 ;     - declaration of test::a,
 ;     - non-constant member S:fn,
 ;     - arguments of S:fn.
 
-; CHECK: "unique source variables":7
+; CHECK: "unique source variables":9
 ; +1 extra inline i.
-; CHECK: "source variables":8
+; CHECK: "source variables":10
 ; -1 square::i
-; CHECK: "variables with location":7
+; CHECK: "variables with location":9
 ; CHECK: "scope bytes total":[[BYTES:[0-9]+]]
 ; Because of the dbg.value in the middle of the function, the pc range coverage
 ; must be below 100%.
@@ -99,6 +102,18 @@ entry:
   ret i32 %mul, !dbg !44
 }
 
+; Function Attrs: noinline optnone uwtable
+define dso_local i32 @_Z3booii(i32 %0, i32 %1) !dbg !52 {
+entry:
+  %.addr = alloca i32, align 4
+  %.addr1 = alloca i32, align 4
+  store i32 %0, i32* %.addr, align 4
+  call void @llvm.dbg.declare(metadata i32* %.addr, metadata !55, metadata !DIExpression()), !dbg !56
+  store i32 %1, i32* %.addr1, align 4
+  call void @llvm.dbg.declare(metadata i32* %.addr1, metadata !57, metadata !DIExpression()), !dbg !58
+  ret i32 0, !dbg !58
+}
+
 attributes #0 = { alwaysinline nounwind ssp uwtable }
 attributes #1 = { nounwind readnone speculatable }
 attributes #2 = { noinline nounwind optnone ssp uwtable }
@@ -159,3 +174,10 @@ attributes #2 = { noinline nounwind optnone ssp uwtable }
 !49 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !2, entity: !50, file: !3, line: 2)
 !50 = !DIGlobalVariable(name: "a", linkageName: "_ZN4test1aE", scope: !51, file: !3, line: 2, type: !8, isLocal: false, isDefinition: false)
 !51 = !DINamespace(name: "test", scope: !2)
+!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)
+!53 = !DISubroutineType(types: !54)
+!54 = !{!8, !8, !8}
+!55 = !DILocalVariable(arg: 1, scope: !52, file: !3, line: 10, type: !8)
+!56 = !DILocation(line: 10, column: 12, scope: !52)
+!57 = !DILocalVariable(arg: 2, scope: !52, file: !3, line: 10, type: !8)
+!58 = !DILocation(line: 10, column: 17, scope: !52)

diff  --git a/llvm/tools/llvm-dwarfdump/Statistics.cpp b/llvm/tools/llvm-dwarfdump/Statistics.cpp
index 456ea23a189e..92d17c3c8d14 100644
--- a/llvm/tools/llvm-dwarfdump/Statistics.cpp
+++ b/llvm/tools/llvm-dwarfdump/Statistics.cpp
@@ -436,11 +436,14 @@ static void collectStatsRecursive(DWARFDie Die, std::string FnPrefix,
 
   // Traverse children.
   unsigned LexicalBlockIndex = 0;
+  unsigned FormalParameterIndex = 0;
   DWARFDie Child = Die.getFirstChild();
   while (Child) {
     std::string ChildVarPrefix = VarPrefix;
     if (Child.getTag() == dwarf::DW_TAG_lexical_block)
       ChildVarPrefix += toHex(LexicalBlockIndex++) + '.';
+    if (Child.getTag() == dwarf::DW_TAG_formal_parameter)
+      ChildVarPrefix += 'p' + toHex(FormalParameterIndex++) + '.';
 
     collectStatsRecursive(Child, FnPrefix, ChildVarPrefix, BytesInScope,
                           InlineDepth, FnStatMap, GlobalStats, LocStats);


        


More information about the llvm-commits mailing list