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

via llvm-dev llvm-dev at lists.llvm.org
Fri Feb 12 09:48:18 PST 2021


Hi Sourabh,

Just from reading the commit messages you quoted, I can guess what happened:  Trying to use DW_TAG_constant for a single-valued variable, when in the C family this should be a DW_TAG_variable (presumably with a const type) and ideally DW_AT_const_value.

I think you should proceed with the plan to introduce DIConstant, as Flang is not the only Fortran compiler planning to use LLVM and Fortran is not the only language that has true constants.  And if we can fix the scoping issues with enumerations along the way, so much the better!

Thanks,
--paulr

From: Tomar, Sourabh Singh <SourabhSingh.Tomar at amd.com>
Sent: Friday, February 12, 2021 12:30 PM
To: Robinson, Paul <paul.robinson at sony.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>; Adrian Prantl <aprantl at apple.com>; Eric Schweitz <eschweitz at nvidia.com>
Subject: RE: [DebugInfo]: Representing constants in debug-info


[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<https://urldefense.com/v3/__https:/bugs.llvm.org/show_bug.cgi?id=49153__;!!JmoZiZGBv3RvKRSx!oWg4CKJ0NJ1vUiS7pBgrLjF4WvHEcqyQgzvRTYLov5T6rGwz3qxj9LzMNwo9OLGVtQ$>

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<mailto:paul.robinson at sony.com> <paul.robinson at sony.com<mailto:paul.robinson at sony.com>>
Sent: Wednesday, February 10, 2021 7:23 PM
To: Tomar, Sourabh Singh <SourabhSingh.Tomar at amd.com<mailto:SourabhSingh.Tomar at amd.com>>; 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>>; 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: 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/e612dd36/attachment-0001.html>


More information about the llvm-dev mailing list