33
33
#include " llvm/MC/MCSymbolWasm.h"
34
34
#include " llvm/MC/MachineLocation.h"
35
35
#include " llvm/Support/CommandLine.h"
36
+ #include " llvm/Support/NVPTXAddrSpace.h"
36
37
#include " llvm/Target/TargetLoweringObjectFile.h"
37
38
#include " llvm/Target/TargetMachine.h"
38
39
#include " llvm/Target/TargetOptions.h"
@@ -75,6 +76,26 @@ static dwarf::Tag GetCompileUnitType(UnitKind Kind, DwarfDebug *DW) {
75
76
return dwarf::DW_TAG_compile_unit;
76
77
}
77
78
79
+ // / Translate NVVM IR address space code to DWARF correspondent value
80
+ static unsigned translateToNVVMDWARFAddrSpace (unsigned AddrSpace) {
81
+ switch (AddrSpace) {
82
+ case NVPTXAS::ADDRESS_SPACE_GENERIC:
83
+ return NVPTXAS::DWARF_ADDR_generic_space;
84
+ case NVPTXAS::ADDRESS_SPACE_GLOBAL:
85
+ return NVPTXAS::DWARF_ADDR_global_space;
86
+ case NVPTXAS::ADDRESS_SPACE_SHARED:
87
+ return NVPTXAS::DWARF_ADDR_shared_space;
88
+ case NVPTXAS::ADDRESS_SPACE_CONST:
89
+ return NVPTXAS::DWARF_ADDR_const_space;
90
+ case NVPTXAS::ADDRESS_SPACE_LOCAL:
91
+ return NVPTXAS::DWARF_ADDR_local_space;
92
+ default :
93
+ llvm_unreachable (
94
+ " Cannot translate unknown address space to DWARF address space" );
95
+ return AddrSpace;
96
+ }
97
+ }
98
+
78
99
DwarfCompileUnit::DwarfCompileUnit (unsigned UID, const DICompileUnit *Node,
79
100
AsmPrinter *A, DwarfDebug *DW,
80
101
DwarfFile *DWU, UnitKind Kind)
@@ -264,14 +285,11 @@ void DwarfCompileUnit::addLocationAttribute(
264
285
}
265
286
266
287
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.
288
+ // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace
271
289
// Decode DW_OP_constu <DWARF Address Space> DW_OP_swap DW_OP_xderef
272
- // sequence for the NVPTX + gdb target.
273
- unsigned LocalNVPTXAddressSpace;
290
+ // sequence to specify corresponding address space.
274
291
if (Asm->TM .getTargetTriple ().isNVPTX () && DD->tuneForGDB ()) {
292
+ unsigned LocalNVPTXAddressSpace;
275
293
const DIExpression *NewExpr =
276
294
DIExpression::extractAddressClass (Expr, LocalNVPTXAddressSpace);
277
295
if (NewExpr != Expr) {
@@ -363,6 +381,10 @@ void DwarfCompileUnit::addLocationAttribute(
363
381
DD->addArangeLabel (SymbolCU (this , Sym));
364
382
addOpAddress (*Loc, Sym);
365
383
}
384
+ if (Asm->TM .getTargetTriple ().isNVPTX () && DD->tuneForGDB () &&
385
+ !NVPTXAddressSpace)
386
+ NVPTXAddressSpace =
387
+ translateToNVVMDWARFAddrSpace (Global->getType ()->getAddressSpace ());
366
388
}
367
389
// Global variables attached to symbols are memory locations.
368
390
// It would be better if this were unconditional, but malformed input that
@@ -373,13 +395,9 @@ void DwarfCompileUnit::addLocationAttribute(
373
395
DwarfExpr->addExpression (Expr);
374
396
}
375
397
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 ;
398
+ // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace
381
399
addUInt (*VariableDIE, dwarf::DW_AT_address_class, dwarf::DW_FORM_data1,
382
- NVPTXAddressSpace.value_or (NVPTX_ADDR_global_space ));
400
+ NVPTXAddressSpace.value_or (NVPTXAS::DWARF_ADDR_global_space ));
383
401
}
384
402
if (Loc)
385
403
addBlock (*VariableDIE, dwarf::DW_AT_location, DwarfExpr->finalize ());
@@ -793,10 +811,10 @@ void DwarfCompileUnit::applyConcreteDbgVariableAttributes(
793
811
const DbgValueLoc *DVal = &Single.getValueLoc ();
794
812
if (Asm->TM .getTargetTriple ().isNVPTX () && DD->tuneForGDB () &&
795
813
!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 );
814
+ // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace
815
+ // Lack of expression means it is a register.
816
+ addUInt (VariableDie, dwarf::DW_AT_address_class, dwarf::DW_FORM_data1,
817
+ NVPTXAS::DWARF_ADDR_reg_space );
800
818
}
801
819
if (!DVal->isVariadic ()) {
802
820
const DbgValueLocEntry *Entry = DVal->getLocEntries ().begin ();
@@ -922,14 +940,11 @@ void DwarfCompileUnit::applyConcreteDbgVariableAttributes(const Loc::MMI &MMI,
922
940
SmallVector<uint64_t , 8 > Ops;
923
941
TRI->getOffsetOpcodes (Offset, Ops);
924
942
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;
943
+ // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace.
944
+ // Decode DW_OP_constu <DWARF Address Space> DW_OP_swap
945
+ // DW_OP_xderef sequence to specify address space.
932
946
if (Asm->TM .getTargetTriple ().isNVPTX () && DD->tuneForGDB ()) {
947
+ unsigned LocalNVPTXAddressSpace;
933
948
const DIExpression *NewExpr =
934
949
DIExpression::extractAddressClass (Expr, LocalNVPTXAddressSpace);
935
950
if (NewExpr != Expr) {
@@ -949,14 +964,9 @@ void DwarfCompileUnit::applyConcreteDbgVariableAttributes(const Loc::MMI &MMI,
949
964
DwarfExpr.addExpression (std::move (Cursor));
950
965
}
951
966
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 ;
967
+ // cuda-gdb special requirement. See NVPTXAS::DWARF_AddressSpace.
958
968
addUInt (VariableDie, dwarf::DW_AT_address_class, dwarf::DW_FORM_data1,
959
- NVPTXAddressSpace.value_or (NVPTX_ADDR_local_space ));
969
+ NVPTXAddressSpace.value_or (NVPTXAS::DWARF_ADDR_local_space ));
960
970
}
961
971
addBlock (VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize ());
962
972
if (DwarfExpr.TagOffset )
0 commit comments