[llvm-dev] [DebugInfo]: Representing constants in debug-info

Tomar, Sourabh Singh via llvm-dev llvm-dev at lists.llvm.org
Fri Feb 12 09:30:05 PST 2021


[AMD Public Use]

Hi Paul,
Thanks for the hints for a possible implementation by mimicking something close to Enumerations. I noticed 2 problems doing so:

  1.  Enumerators are integers, while a constant can be of any type(at least basic types provided by the base language).
  2.  Restricting Scope of a Constant, Scoping concerns with Enumerator as depicted in https://bugs.llvm.org/show_bug.cgi?id=49153

We did some digging in LLVM history, seems like there were some attempts for bringing DW_TAG_constant back in 2010;
However things are not clear with respect to overall support, as a result it was dropped.

Second last commit cites some GDB related concerns(back in 2010) for removal of DW_TAG_constant from LLVM.
[...]
commit b407bb2789e0c1daea1b7d7e896e6a600e408cf0
Author: Duncan P. N. Exon Smith <dexonsmith at apple.com<mailto:dexonsmith at apple.com>>
Date:   Mon Feb 9 22:48:04 2015 +0000

    DebugInfo: Remove DW_TAG_constant

    Remove handling for DW_TAG_constant.  We started producing it in
    r110656, but reverted that in r110876 without dropping the support.
    Finish the job.

    llvm-svn: 228623

commit 4d597e82684d462bc98f2ff934e37d3c5e38a0c9
Author: Devang Patel <dpatel at apple.com<mailto:dpatel at apple.com>>
Date:   Wed Aug 11 23:17:54 2010 +0000

    Even if a variable has constant value all the time, it is still a variable in gdb's eyes.
    Tested by scope.exp in gdb testsuite.

    llvm-svn: 110876

commit b219746c80be195e914d6f620427217818476ba8
Author: Devang Patel <dpatel at apple.com<mailto:dpatel at apple.com>>
Date:   Tue Aug 10 07:11:13 2010 +0000

    Handle TAG_constant for integers.

    llvm-svn: 110656
[...]

Now, that GDB has support for DW_TAG_constant is pretty decent. So I wanted to take this opportunity to define a new DIConstant metadata which will eventually materialize as DW_TAG_constant in DWARF.

Supporting arguments with respect to this:

  1.  Languages such as Fortran and the new Frontend Flang(now part of LLVM) can utilize this for producing debug-info.
  2.  Other languages that have named constant and there potential front-ends(living down-stream or not part of LLVM)  should be able utilize this too.

Thanks ..much!
Sourabh.

From: paul.robinson at sony.com <paul.robinson at sony.com>
Sent: Wednesday, February 10, 2021 7:23 PM
To: Tomar, Sourabh Singh <SourabhSingh.Tomar at amd.com>; llvm-dev at lists.llvm.org
Cc: George, Jini Susan <JiniSusan.George at amd.com>; chih-ping.chen at intel.com; Sharma, Alok Kumar <AlokKumar.Sharma at amd.com>
Subject: RE: [DebugInfo]: Representing constants in debug-info

[CAUTION: External Email]
I don't see any use of DW_TAG_constant in the LLVM tree, except in the DWARFLinker, which isn't what you need.

Most things not needed by C-family languages aren't supported, because to date nobody has needed them (or if they did, they implemented the support downstream).  The closest similar thing would be enumerator constants; you could probably imitate what's done for those fairly easily.
--paulr

From: llvm-dev <llvm-dev-bounces at lists.llvm.org<mailto:llvm-dev-bounces at lists.llvm.org>> On Behalf Of Tomar, Sourabh Singh via llvm-dev
Sent: Wednesday, February 10, 2021 12:54 AM
To: llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>>
Cc: George, Jini Susan <JiniSusan.George at amd.com<mailto:JiniSusan.George at amd.com>>; Chen, Chih-Ping <chih-ping.chen at intel.com<mailto:chih-ping.chen at intel.com>>; Sharma, Alok Kumar <AlokKumar.Sharma at amd.com<mailto:AlokKumar.Sharma at amd.com>>
Subject: [llvm-dev] [DebugInfo]: Representing constants in debug-info


[AMD Public Use]

Hi Everyone,

Is there a way of representing **constants** in LLVM debug-info ? Languages such as FORTRAN has constants

i.e, consider the following Fortran snippet
[...]
Module foo
Integer, parameter :: bar = 200 ! Constant
End module foo
[...]

A front-end may choose to emit as Global Constant in LLVM IR as:
[...]
@bar.. = internal constant i32 200

A naïve attempt to represent it as GlobalVariable(or constant) as
[...]
!7 = !DIGlobalVariableExpression(var: !8, expr: !DIExpression(DW_OP_consts, 200))
!8 = distinct !DIGlobalVariable(name: "bar", scope: !2, file: !3, line: 3, type: !9, isLocal: false, isDefinition: true)

This will materialize in DWARF as:
0x0000004a:     DW_TAG_variable
                  DW_AT_name    ("bar")
                  ...
                 DW_AT_location        (DW_OP_addr 0x2007d4, DW_OP_consts +200)  // This is incorrect, pointing to data section
[...]

Gfortran is representing this as: **DW_TAG_constant**
0x00000055:     **DW_TAG_constant**
                  DW_AT_name    ("bar")
                 ...
                  DW_AT_type    (0x0000006a "const integer(kind=4)")
                  DW_AT_external        (true)
                  DW_AT_const_value     (0xc8)

Do we have Metadata analog of (DW_TAG_constant) ? I think the primary question here is to how represent this ?

Any inputs appreciated!

Thanks.. much!
Sourabh.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210212/77b37203/attachment.html>


More information about the llvm-dev mailing list