3333#include " llvm/MC/MCSymbolWasm.h"
3434#include " llvm/MC/MachineLocation.h"
3535#include " llvm/Support/CommandLine.h"
36+ #include " llvm/Support/NVPTXAddrSpace.h"
3637#include " llvm/Target/TargetLoweringObjectFile.h"
3738#include " llvm/Target/TargetMachine.h"
3839#include " llvm/Target/TargetOptions.h"
@@ -75,6 +76,25 @@ static dwarf::Tag GetCompileUnitType(UnitKind Kind, DwarfDebug *DW) {
7576 return dwarf::DW_TAG_compile_unit;
7677}
7778
79+ static unsigned translateToNVVMDWARFAddrSpace (unsigned AddrSpace) {
80+ switch (AddrSpace) {
81+ case NVPTXAS::ADDRESS_SPACE_GENERIC:
82+ return NVPTXAS::DWARF_ADDR_generic_space;
83+ case NVPTXAS::ADDRESS_SPACE_GLOBAL:
84+ return NVPTXAS::DWARF_ADDR_global_space;
85+ case NVPTXAS::ADDRESS_SPACE_SHARED:
86+ return NVPTXAS::DWARF_ADDR_shared_space;
87+ case NVPTXAS::ADDRESS_SPACE_CONST:
88+ return NVPTXAS::DWARF_ADDR_const_space;
89+ case NVPTXAS::ADDRESS_SPACE_LOCAL:
90+ return NVPTXAS::DWARF_ADDR_local_space;
91+ default :
92+ llvm_unreachable (
93+ " Cannot translate unknown address space to DWARF address space" );
94+ return AddrSpace;
95+ }
96+ }
97+
7898DwarfCompileUnit::DwarfCompileUnit (unsigned UID, const DICompileUnit *Node,
7999 AsmPrinter *A, DwarfDebug *DW,
80100 DwarfFile *DWU, UnitKind Kind)
@@ -264,14 +284,11 @@ void DwarfCompileUnit::addLocationAttribute(
264284 }
265285
266286 if (Expr) {
267- // According to
268- // https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf
269- // cuda-gdb requires DW_AT_address_class for all variables to be able to
270- // correctly interpret address space of the variable address.
287+ // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace
271288 // Decode DW_OP_constu <DWARF Address Space> DW_OP_swap DW_OP_xderef
272- // sequence for the NVPTX + gdb target.
273- unsigned LocalNVPTXAddressSpace;
289+ // sequence to specify corresponding address space.
274290 if (Asm->TM .getTargetTriple ().isNVPTX () && DD->tuneForGDB ()) {
291+ unsigned LocalNVPTXAddressSpace;
275292 const DIExpression *NewExpr =
276293 DIExpression::extractAddressClass (Expr, LocalNVPTXAddressSpace);
277294 if (NewExpr != Expr) {
@@ -363,6 +380,10 @@ void DwarfCompileUnit::addLocationAttribute(
363380 DD->addArangeLabel (SymbolCU (this , Sym));
364381 addOpAddress (*Loc, Sym);
365382 }
383+ if (Asm->TM .getTargetTriple ().isNVPTX () && DD->tuneForGDB () &&
384+ !NVPTXAddressSpace)
385+ NVPTXAddressSpace = translateToNVVMDWARFAddrSpace (
386+ Global->getType ()->getAddressSpace ());
366387 }
367388 // Global variables attached to symbols are memory locations.
368389 // It would be better if this were unconditional, but malformed input that
@@ -373,13 +394,9 @@ void DwarfCompileUnit::addLocationAttribute(
373394 DwarfExpr->addExpression (Expr);
374395 }
375396 if (Asm->TM .getTargetTriple ().isNVPTX () && DD->tuneForGDB ()) {
376- // According to
377- // https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf
378- // cuda-gdb requires DW_AT_address_class for all variables to be able to
379- // correctly interpret address space of the variable address.
380- const unsigned NVPTX_ADDR_global_space = 5 ;
397+ // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace
381398 addUInt (*VariableDIE, dwarf::DW_AT_address_class, dwarf::DW_FORM_data1,
382- NVPTXAddressSpace.value_or (NVPTX_ADDR_global_space ));
399+ NVPTXAddressSpace.value_or (NVPTXAS::DWARF_ADDR_global_space ));
383400 }
384401 if (Loc)
385402 addBlock (*VariableDIE, dwarf::DW_AT_location, DwarfExpr->finalize ());
@@ -793,10 +810,10 @@ void DwarfCompileUnit::applyConcreteDbgVariableAttributes(
793810 const DbgValueLoc *DVal = &Single.getValueLoc ();
794811 if (Asm->TM .getTargetTriple ().isNVPTX () && DD->tuneForGDB () &&
795812 !Single.getExpr ()) {
796- // Lack of expression means it is a register. Registers for PTX need to
797- // be marked with DW_AT_address_class = 2. See
798- // https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific- dwarf
799- addUInt (VariableDie, dwarf::DW_AT_address_class, dwarf::DW_FORM_data1, 2 );
813+ // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace
814+ // Lack of expression means it is a register.
815+ addUInt (VariableDie, dwarf::DW_AT_address_class, dwarf::DW_FORM_data1,
816+ NVPTXAS::DWARF_ADDR_reg_space );
800817 }
801818 if (!DVal->isVariadic ()) {
802819 const DbgValueLocEntry *Entry = DVal->getLocEntries ().begin ();
@@ -922,14 +939,11 @@ void DwarfCompileUnit::applyConcreteDbgVariableAttributes(const Loc::MMI &MMI,
922939 SmallVector<uint64_t , 8 > Ops;
923940 TRI->getOffsetOpcodes (Offset, Ops);
924941
925- // According to
926- // https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf
927- // cuda-gdb requires DW_AT_address_class for all variables to be
928- // able to correctly interpret address space of the variable
929- // address. Decode DW_OP_constu <DWARF Address Space> DW_OP_swap
930- // DW_OP_xderef sequence for the NVPTX + gdb target.
931- unsigned LocalNVPTXAddressSpace;
942+ // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace.
943+ // Decode DW_OP_constu <DWARF Address Space> DW_OP_swap
944+ // DW_OP_xderef sequence to specify address space.
932945 if (Asm->TM .getTargetTriple ().isNVPTX () && DD->tuneForGDB ()) {
946+ unsigned LocalNVPTXAddressSpace;
933947 const DIExpression *NewExpr =
934948 DIExpression::extractAddressClass (Expr, LocalNVPTXAddressSpace);
935949 if (NewExpr != Expr) {
@@ -949,14 +963,9 @@ void DwarfCompileUnit::applyConcreteDbgVariableAttributes(const Loc::MMI &MMI,
949963 DwarfExpr.addExpression (std::move (Cursor));
950964 }
951965 if (Asm->TM .getTargetTriple ().isNVPTX () && DD->tuneForGDB ()) {
952- // According to
953- // https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf
954- // cuda-gdb requires DW_AT_address_class for all variables to be
955- // able to correctly interpret address space of the variable
956- // address.
957- const unsigned NVPTX_ADDR_local_space = 6 ;
966+ // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace.
958967 addUInt (VariableDie, dwarf::DW_AT_address_class, dwarf::DW_FORM_data1,
959- NVPTXAddressSpace.value_or (NVPTX_ADDR_local_space ));
968+ NVPTXAddressSpace.value_or (NVPTXAS::DWARF_ADDR_local_space ));
960969 }
961970 addBlock (VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize ());
962971 if (DwarfExpr.TagOffset )
0 commit comments