[PATCH] D109343: [DebugInfo] Enhance DIImportedEntity to accept children entities for renamed variables

Alok Kumar Sharma via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 6 23:14:50 PDT 2021


alok created this revision.
alok added reviewers: aprantl, djtodoro, jmorse, jini.susan.
alok added a project: debug-info.
Herald added a reviewer: deadalnix.
Herald added subscribers: dexonsmith, jdoerfert, ormris, hiraditya.
Herald added a reviewer: sscalpone.
alok requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

   This is needed to dump optimized debugging information when imported entity
   has renamed entities (member variables, subprograms)
  
   Please consider blow test case.
   `````````````````````````
   Consider the testcase below
  
   module mymod
     integer :: var1 = 11
     integer :: var2 = 12
     integer :: var3 = 13
   end module mymod
  
   Program main
     call use_renamed()
     contains
       subroutine use_renamed()
         use mymod, var4 => var1
         print *, var4
       end subroutine use_renamed
   end program main
   `````````````````````````
   Which currently produces IR as
  
   !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
   !1 = distinct !DIGlobalVariable(name: "var1", scope: !2, file: !3, line: 2, type: !9, isLocal: false, isDefinition: true)
   !2 = !DIModule(scope: !4, name: "mymod", file: !3, line: 1)
   !3 = !DIFile(filename: "usemodulealias.f90", directory: "/tmp")
   !4 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: false, flags: "'+flang -g -S -emit-llvm usemodulealias.f90'", runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, **imports: !12**, nameTableKind: None)
   !5 = !{}
   !6 = !{!0, !7, !10}
   !7 = !DIGlobalVariableExpression(var: !8, expr: !DIExpression(DW_OP_plus_uconst, 4))
   !8 = distinct !DIGlobalVariable(name: "var2", scope: !2, file: !3, line: 3, type: !9, isLocal: false, isDefinition: true)
   !9 = !DIBasicType(name: "integer", size: 32, align: 32, encoding: DW_ATE_signed)
   !10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression(DW_OP_plus_uconst, 8))
   !11 = distinct !DIGlobalVariable(name: "var3", scope: !2, file: !3, line: 4, type: !9, isLocal: false, isDefinition: true)
  ** !12 = !{!13, !19, !20}**
   !13 = !**DIImportedEntity**(tag: DW_TAG_imported_declaration, scope: !14, entity: !11, file: !3, line: 10)
   !14 = distinct !DISubprogram(name: "use_renamed", scope: !15, file: !3, line: 10, type: !18, scopeLine: 10, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !4)
   !15 = distinct !DISubprogram(name: "main", scope: !4, file: !3, line: 7, type: !16, scopeLine: 7, flags: DIFlagAllCallsDescribed, spFlags: DISPFlag

Definition | DISPFlagMainSubprogram, unit: !4)

   !16 = !DISubroutineType(cc: DW_CC_program, types: !17)
   !17 = !{null}
   !18 = !DISubroutineType(types: !17)
   !19 = !**DIImportedEntity**(tag: DW_TAG_imported_declaration, scope: !14, entity: !8, file: !3, line: 10)
   !20 = !**DIImportedEntity**(tag: DW_TAG_imported_declaration, name: "var4", scope: !14, entity: !1, file: !3, line: 10)
  
   Please consider an imported Module having one renamed member out of
    total thousand members. With above representation we need to generate
   thousand DIImportedEntity's for each member.
   which can be optimize to
  
   !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
   !1 = distinct !DIGlobalVariable(name: "var1", scope: !2, file: !3, line: 2, type: !9, isLocal: false, isDefinition: true)
   !2 = !DIModule(scope: !4, name: "mymod", file: !3, line: 1)
   !3 = !DIFile(filename: "usemodulealias.f90", directory: "/tmp")
   !4 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01", isOptimized: false, flags: "'+flang usemodulealias.f90 -g -S -emit-llvm'", runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, **imports: !12**, nameTableKind: None)
   !5 = !{}
   !6 = !{!0, !7, !10}
   !7 = !DIGlobalVariableExpression(var: !8, expr: !DIExpression(DW_OP_plus_uconst, 4))
   !8 = distinct !DIGlobalVariable(name: "var2", scope: !2, file: !3, line: 3, type: !9, isLocal: false, isDefinition: true)
   !9 = !DIBasicType(name: "integer", size: 32, align: 32, encoding: DW_ATE_signed)
   !10 = !DIGlobalVariableExpression(var: !11, expr: !DIExpression(DW_OP_plus_uconst, 8))
   !11 = distinct !DIGlobalVariable(name: "var3", scope: !2, file: !3, line: 4, type: !9, isLocal: false, isDefinition: true)
   **!12 = !{!13}**
   !13 = !**DIImportedEntity**(tag: DW_TAG_imported_module, scope: !14, entity: !2, file: !3, line: 10, **elements**: **!19**)
   !14 = distinct !DISubprogram(name: "use_renamed", scope: !15, file: !3, line: 10, type: !18, scopeLine: 10, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !4)
   **!19 = !{!20}**
  ** !20 = !DIImportedEntity**(tag: DW_TAG_imported_declaration, **name: "var4"**, scope: !14, entity: !1, file: !3, line: 10)
  
   DIImportedEntity should include elements field which includes renamed variables only.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109343

Files:
  llvm/docs/LangRef.rst
  llvm/include/llvm-c/DebugInfo.h
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/DebugInfo.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/test/Bitcode/DIImportedEntity_elements.ll
  llvm/test/DebugInfo/X86/dwarfdump-DIImportedEntity_elements.ll
  llvm/tools/llvm-c-test/debuginfo.c
  llvm/unittests/IR/IRBuilderTest.cpp
  llvm/unittests/IR/MetadataTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109343.370991.patch
Type: text/x-patch
Size: 39717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210907/72cb6b74/attachment.bin>


More information about the llvm-commits mailing list