[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
Tue Sep 14 03:57:20 PDT 2021


alok added a comment.

In D109343#2998361 <https://reviews.llvm.org/D109343#2998361>, @dblaikie wrote:

> The subject might be slightly misleading - DIImportedEntity already supports importing variables (see C++ like this:
>
>   namespace ns {
>   extern int i;
>   int i;
>   }
>   namespace ns2 {
>   using ns::i;
>   }
>   int main() {
>     return ns2::i;
>   }
>
> which produces a DW_TAG_imported_declaration in DW_TAG_namespace ns2 that imports the DW_TAG_variable i from DW_TAG_namespace ns.
>
> . This patch is specifically about supporting a single imported entity declaration importing multiple entities at the same time, but not a whole namespace of them?
>
> Hmm, nope - it looks like it's only testing importing a single variable. What sort of DWARF are you expecting to generate when importing multiple variables (when "children" has a size greater than 1). Oh, in the implementation in DwarfDebug it's still generating separate DW_TAG_imported_declaration for each thing - so why not encode these as separate DIImportedDeclarations, which would already be supported in the current IR handling, so far as I can tell?

I am sorry for not being clear earlier.

Please consider below testcase.

  module mymod
    integer :: var1
    integer :: var2
    integer :: var3
    integer :: var4
    integer :: var5
  end module mymod
  
  Program main
    implicit none
    call use_renamed()
    contains
      subroutine use_renamed()
        use mymod, alias1 => var1, alias2 => var2
        print *, alias1
        print *, alias2
        print *, var3
        print *, var4
        print *, var5
      end subroutine use_renamed
  end program main

Please note that inside subroutine "use_renamed", entire module "mymod" is imported but "var1" and "var2" are identified as "alias1" and "alias2".

Currently this can be represented in DWARF as

  0x0000000b: DW_TAG_compile_unit
                DW_AT_language    (DW_LANG_Fortran90)
                DW_AT_name        ("mymoduse.f90")
  
  0x0000002a:   DW_TAG_module
                  DW_AT_name      ("mymod")
  
  0x00000031:     DW_TAG_variable
                    DW_AT_name    ("var1")
                    DW_AT_location        (DW_OP_addr 0x0)
  
  0x00000046:     DW_TAG_variable
                    DW_AT_name    ("var2")
                    DW_AT_location        (DW_OP_addr 0x0, DW_OP_plus_uconst 0x4)
  
  0x0000005d:     DW_TAG_variable
                    DW_AT_name    ("var3")
                    DW_AT_location        (DW_OP_addr 0x0, DW_OP_plus_uconst 0x8)
  
  0x00000074:     DW_TAG_variable
                    DW_AT_name    ("var4")
                    DW_AT_location        (DW_OP_addr 0x0, DW_OP_plus_uconst 0xc)
  
  0x0000008b:     DW_TAG_variable
                    DW_AT_name    ("var5")
                    DW_AT_location        (DW_OP_addr 0x0, DW_OP_plus_uconst 0x10)
  
  0x000000a2:     NULL
  
  
  0x000000d4:     DW_TAG_subprogram
                    DW_AT_low_pc  (0x0000000000000030)
                    DW_AT_high_pc (0x0000000000000274)
                    DW_AT_frame_base      (DW_OP_reg7 RSP)
                    DW_AT_name    ("use_renamed")
  
  0x000000fe:       DW_TAG_imported_declaration
                      DW_AT_import        (0x0000008b)
  
  0x00000105:       DW_TAG_imported_declaration
                      DW_AT_import        (0x00000074)
  
  0x0000010c:       DW_TAG_imported_declaration
                      DW_AT_import        (0x0000005d)
  
  0x00000113:       DW_TAG_imported_declaration
                      DW_AT_import        (0x00000046)
                      DW_AT_name  ("alias2")
  
  0x0000011e:       DW_TAG_imported_declaration
                      DW_AT_import        (0x00000031)
                      DW_AT_name  ("alias1")
  
  0x00000129:       NULL

Please note that subroutine "use_rename" need to include 5 import entities here, just think about a module having 100 variables with 2 renamed entities will have to inlcude 100 "DW_TAG_imported_declaration".

gfortran dumps below DWARF for same case as,

  0x000000d4:     DW_TAG_subprogram
                    DW_AT_name    ("use_renamed")
                    DW_AT_low_pc  (0x0000000000000000)
                    DW_AT_high_pc (0x000000000000020e)
                    DW_AT_frame_base      (DW_OP_call_frame_cfa)
                    DW_AT_static_link     (DW_OP_fbreg -504, DW_OP_deref, DW_OP_deref)
  
  0x00000100:       DW_TAG_imported_module
                      DW_AT_import        (0x0000002a)
  
  0x0000010b:          DW_TAG_imported_declaration
                         DW_AT_name        ("alias1")
                         DW_AT_import      (0x00000031)
  
  0x00000116:          DW_TAG_imported_declaration
                         DW_AT_name        ("alias2")
                         DW_AT_import      (0x00000046)
  
  0x00000121:         NULL

Please note that DW_TAG_imported_module has two child entities (for renamed variable), which denotes all variables in module (renamed entities are overridden). The case of module having 100 members and 2 renames can be represented with only 3 DIEs. (saving 97 DIEs).

The new representation (with DIImportedEntity having child) is surely going to save us some DWARF space in case of huge modules with few renames getting imported.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109343/new/

https://reviews.llvm.org/D109343



More information about the llvm-commits mailing list