This is an archive of the discontinued LLVM Phabricator instance.

[DEBUG_INFO][NVPTX] Generate DW_AT_address_class to get the values in debugger.
ClosedPublic

Authored by ABataev on Jan 24 2019, 7:30 AM.

Details

Summary

According to
https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf,
the compiler should emit the DW_AT_address_class attribute for all
variable and parameter. It means, that DW_AT_address_class attribute
should be used in the non-standard way to support compatibility with the
cuda-gdb debugger.
Clang is able to generate the information about the variable address
class. This information is emitted as the expression sequence
DW_OP_constu <DWARF Address Space> DW_OP_swap DW_OP_xderef. The patch
tries to find all such expressions and transform them into
DW_AT_address_class <DWARF Address Space> if target is NVPTX and the debugger is gdb.
If the expression is not found, then default values are used. For the
local variables <DWARF Address Space> is set to ADDR_local_space(6), for
the globals <DWARF Address Space> is set to ADDR_global_space(5). The
values are taken from the table in the same section 5.2. CUDA-Specific
DWARF Definitions.

Diff Detail

Repository
rL LLVM

Event Timeline

ABataev created this revision.Jan 24 2019, 7:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 5 2019, 7:46 AM
aprantl added inline comments.Feb 5 2019, 9:33 AM
lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
112 ↗(On Diff #183313)

This should be a member function of DIExpression instead. We have other similar properties there already.

113 ↗(On Diff #183313)

This is not general enough. You probably want to check that the last 4 elements of the DIExpression match this pattern instead, since the LLVM optimizer may insert additional operations at the beginning of the Expression at any time.

ABataev updated this revision to Diff 185348.Feb 5 2019, 10:43 AM

Reworked according to the comments from Adrian Prantl.

ABataev marked 2 inline comments as done.Feb 5 2019, 10:46 AM

Adrian, thanks a lot for the review!

lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
112 ↗(On Diff #183313)

Made it a static member function instead of the DIExpression class. Need to modify the expression by deleting the last 4 elements after AddressClass extraction, but function is applied to const expressions. Need to create the new expression, if the pattern was recognized.

aprantl added inline comments.Feb 5 2019, 11:01 AM
include/llvm/IR/DebugInfoMetadata.h
2516 ↗(On Diff #185348)

I understand that you copied the interface from the function above, but could you please make it

Optional<unsigned> getAddressClass() const;

instead?

We should also change extractIfOffset this way...

ABataev marked an inline comment as done.Feb 5 2019, 11:02 AM
ABataev added inline comments.
include/llvm/IR/DebugInfoMetadata.h
2516 ↗(On Diff #185348)

I cannot make it const, it modifies the expression itself and should build the new expression if the pattern is found.

ABataev marked an inline comment as done.Feb 5 2019, 11:04 AM
ABataev added inline comments.
include/llvm/IR/DebugInfoMetadata.h
2516 ↗(On Diff #185348)

I mean, it should(!) modify the expression itself, but I can not do it, because this function is applied to the constant expressions.

aprantl accepted this revision.Feb 5 2019, 11:05 AM

Sorry, I overlooked the second part of the function.

This revision is now accepted and ready to land.Feb 5 2019, 11:05 AM
This revision was automatically updated to reflect the committed changes.