[DebugInfo] Fortran namelist support

Hello Everyone,

I am planning to implement the LLVM changes for fortran NAMELIST feature from DebugInfo point of view.

gfortran already support namelist from DebugInfo point of view, it emits DW_TAG_namelist and DW_TAG_namelist_item die’s as shown below. But gdb does not understand these, hence we enhanced gdb to handle namelist variable/type. Soon upstreaming the gdb code changes.

In order to emit the DW_TAG_namelist and DW_TAG_namelist_item die’s in LLVM, following LLVM IR changes are proposed, could you please review and comment if any change is required. Namelist in fortran is basically group of variables or arrays. It can be represented as composite type. Already Metadata is created for each of the namelist items like !20, !22 in the below example, we just need to reference to these while handling DW_TAG_namelist_item. This proposal looks simple and uses the existing composite type with a new tag:DW_TAG_namelist. Please let me know if you have any comments or need more information on these.

NOTE: Currently flang also does not emit any metadata to handle namelist DebugInfo. flang code changes for the same will be taken up after the LLVM support for namelist.

Proposed LLVM IR changes for namelist DebugInfo handling (for the sample fortran program shown below):

. . .

!20 = !DILocalVariable(scope: !15, name: “a”, file: !3, line: 6, type: !19)

. . .

!22 = !DILocalVariable(scope: !15, name: “b”, file: !3, line: 7, type: !19)

. . .

!24 = !{ !26, !27 }

!25 = !DICompositeType(tag: DW_TAG_namelist, file: !3, name: “nml”, elements: !24)

!26 = !DIDerivedType(tag: DW_TAG_namelist_item, item: !20)

!27 = !DIDerivedType(tag: DW_TAG_namelist_item, item: !22)

. . .

Thanks and regards,

Bhuvan

Sample program :

program main

integer :: a, b

namelist /nml/ a, b

a = 10

b = 20

Write(*,nml)

end program main

dwarfdump of an gfortran emitted binary :

. . .

0x000000b4: DW_TAG_variable [10]

DW_AT_name [DW_FORM_string] (“a”)

DW_AT_decl_file [DW_FORM_data1] (“/home/bhuvan/work/fortran/test/3180/n2.f90”)

DW_AT_decl_line [DW_FORM_data1] (20)

DW_AT_type [DW_FORM_ref4] (cu + 0x006d => {0x0000006d} “integer(kind=4)”)

DW_AT_declaration [DW_FORM_flag_present] (true)

DW_AT_location [DW_FORM_exprloc] (DW_OP_fbreg -20)

0x000000c0: DW_TAG_variable [10]

DW_AT_name [DW_FORM_string] (“b”)

DW_AT_decl_file [DW_FORM_data1] (“/home/bhuvan/work/fortran/test/3180/n2.f90”)

DW_AT_decl_line [DW_FORM_data1] (20)

DW_AT_type [DW_FORM_ref4] (cu + 0x006d => {0x0000006d} “integer(kind=4)”)

DW_AT_declaration [DW_FORM_flag_present] (true)

DW_AT_location [DW_FORM_exprloc] (DW_OP_fbreg -24)

. . .

0x000000dd: DW_TAG_namelist [12] *

DW_AT_name [DW_FORM_string] (“nml”)

0x000000e2: DW_TAG_namelist_item [9]

DW_AT_namelist_item [DW_FORM_ref4] (cu + 0x00b4 => {0x000000b4})

0x000000e7: DW_TAG_namelist_item [9]

DW_AT_namelist_item [DW_FORM_ref4] (cu + 0x00c0 => {0x000000c0})

0x000000ec: NULL

Sample GDB commands output (GDB used here is internal, soon it will be upstreamed) :

(gdb) ptype nml

type = Type nml

integer(kind=4) :: a

integer(kind=4) :: b

End Type nml

(gdb) print nml

$1 = ( a = 10, b = 20 )

[AMD Official Use Only]

Hello Everyone,

I am planning to implement the LLVM changes for fortran NAMELIST feature from DebugInfo point of view.

gfortran already support namelist from DebugInfo point of view, it emits DW_TAG_namelist and DW_TAG_namelist_item die's as shown below. But gdb does not understand these, hence we enhanced gdb to handle namelist variable/type. Soon upstreaming the gdb code changes.

In order to emit the DW_TAG_namelist and DW_TAG_namelist_item die's in LLVM, following LLVM IR changes are proposed, could you please review and comment if any change is required. Namelist in fortran is basically group of variables or arrays. It can be represented as composite type. Already Metadata is created for each of the namelist items like !20, !22 in the below example, we just need to reference to these while handling DW_TAG_namelist_item. This proposal looks simple and uses the existing composite type with a new tag:DW_TAG_namelist. Please let me know if you have any comments or need more information on these.

NOTE: Currently flang also does not emit any metadata to handle namelist DebugInfo. flang code changes for the same will be taken up after the LLVM support for namelist.

Proposed LLVM IR changes for namelist DebugInfo handling (for the sample fortran program shown below):
. . .
!20 = !DILocalVariable(scope: !15, name: "a", file: !3, line: 6, type: !19)
. . .
!22 = !DILocalVariable(scope: !15, name: "b", file: !3, line: 7, type: !19)
. . .
!24 = !{ !26, !27 }
!25 = !DICompositeType(tag: DW_TAG_namelist, file: !3, name: "nml", elements: !24)
!26 = !DIDerivedType(tag: DW_TAG_namelist_item, item: !20)
!27 = !DIDerivedType(tag: DW_TAG_namelist_item, item: !22)
. . .

The DICompositeType looks reasonable, I'm not sure why the DIDerivedType is necessary. Wouldn't it be simpler to just use an MDList "elements: !{20, !22}"?

-- adrian

[Public]

Thanks a lot for the suggestion. I followed it and just raised the review request (https://reviews.llvm.org/D108553)

regards,

bhuvan