[RFC] [DebugInfo][NVPTX] Adding support for inlined_at debug directive in NVPTX backend

This PR adds support for emitting the enhanced PTX debugging directives function_name and inlined_at as part of the .loc directive in the NVPTX backend.

.loc syntax -

.loc file_index line_number column_position

.loc syntax with inlined_at attribute -

.loc file_index line_number column_position,function_name label {+ immediate }, inlined_at file_index2 line_number2 column_position2

inlined_at attribute specified as part of the .loc directive indicates PTX instructions that are generated from a function that got inlined. It specifies the source location at which the specified function is inlined. file_index2, line_number2, and column_position2 specify the location at which the function is inlined.

The function_name attribute specifies an offset in the DWARF section- .debug_str. Offset is specified as a label expression or a label + immediate expression, where label is defined in the .debug_str section. DWARF section .debug_str contains ASCII null-terminated strings that specify the name of the function that is inlined.

These attributes were introduced in PTX ISA version 7.2 (see NVIDIA’s documentation: https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#debugging-directives-loc ).

To support these features, the PR introduces a new NVPTXDwarfDebug class derived from DwarfDebug, which implements NVPTX-specific logic for emitting these directives. The base DwarfDebug infrastructure is extended with new virtual hooks (beginFunctionHook() and recordSourceLineHook()) that enable the NVPTX backend to generate this additional debug information.

The MC layer is also updated to emit the NVPTX-specific .loc attributes (function_name and inlined_at). The implementation applies to PTX ISA 7.2 and later when the debug-info emission kind is either lineTableOnly or DebugDirectiveOnly. A new command-line option, --line-info-inlined-at=<true/false>, is added to control whether the inlined_at attribute is generated.

Note - The NVCC compiler already emits the .loc directive with inlined_at when compiled with -lineinfo option.

CC: @dblaikie @jmorse @enferex @ayermolo @Michael137

Thanks for the PR, it seems to be a good way of extending DwarfDebug with some target-specific information,

Do you have plans for further extensions to DWARF textual output, or is it just this PR? If there’s more restructuring coming, it’ll be helpful to know in advance.

It is just this PR at the moment. This debug directive was in public PTX ISA for some time, but was missing in upstream NVPTX.

We are planning to upstream more debug-related changes in the near future, but I believe we won’t need any major restructuring. I’ll keep it posted here if something changes.