diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp --- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp +++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp @@ -1989,6 +1989,7 @@ .Case("tma_hi", AMDGPU::TMA_HI) .Case("tba_lo", AMDGPU::TBA_LO) .Case("tba_hi", AMDGPU::TBA_HI) + .Case("pc", AMDGPU::PC_REG) .Case("null", AMDGPU::SGPR_NULL) .Default(AMDGPU::NoRegister); } diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h @@ -23,6 +23,7 @@ : MCInstPrinter(MAI, MII, MRI) {} //Autogenerated by tblgen + void printRegName(raw_ostream &OS, unsigned RegNo) const override; void printInstruction(const MCInst *MI, uint64_t Address, const MCSubtargetInfo &STI, raw_ostream &O); static const char *getRegisterName(unsigned RegNo); diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp @@ -26,6 +26,10 @@ using namespace llvm; using namespace llvm::AMDGPU; +void AMDGPUInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { + OS << getRegisterName(RegNo); +} + void AMDGPUInstPrinter::printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &OS) { diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCTargetDesc.cpp @@ -61,7 +61,7 @@ if (TT.getArch() == Triple::r600) InitR600MCRegisterInfo(X, 0); else - InitAMDGPUMCRegisterInfo(X, 0); + InitAMDGPUMCRegisterInfo(X, AMDGPU::PC_REG); return X; } diff --git a/llvm/lib/Target/AMDGPU/SIRegisterInfo.td b/llvm/lib/Target/AMDGPU/SIRegisterInfo.td --- a/llvm/lib/Target/AMDGPU/SIRegisterInfo.td +++ b/llvm/lib/Target/AMDGPU/SIRegisterInfo.td @@ -84,8 +84,7 @@ // Declarations that describe the SI registers //===----------------------------------------------------------------------===// class SIReg regIdx = 0> : - Register, - DwarfRegNum<[!cast(HWEncoding)]> { + Register { let Namespace = "AMDGPU"; // This is the not yet the complete register encoding. An additional @@ -104,19 +103,25 @@ def SP_REG : SIReg<"sp", 0>; def SCRATCH_WAVE_OFFSET_REG : SIReg<"scratch_wave_offset", 0>; +// Pseudo-register to represent the program-counter DWARF register. +def PC_REG : SIReg<"pc", 0>, DwarfRegNum<[16]> { + // There is no physical register corresponding to a "program counter", but + // we need to encode the concept in debug information in order to represent + // things like the return value in unwind information. + let isArtificial = 1; +} + // VCC for 64-bit instructions -def VCC : RegisterWithSubRegs<"vcc", [VCC_LO, VCC_HI]>, - DwarfRegAlias { +def VCC : RegisterWithSubRegs<"vcc", [VCC_LO, VCC_HI]> { let Namespace = "AMDGPU"; let SubRegIndices = [sub0, sub1]; let HWEncoding = 106; } -def EXEC_LO : SIReg<"exec_lo", 126>; +def EXEC_LO : SIReg<"exec_lo", 126>, DwarfRegNum<[1]>; def EXEC_HI : SIReg<"exec_hi", 127>; -def EXEC : RegisterWithSubRegs<"exec", [EXEC_LO, EXEC_HI]>, - DwarfRegAlias { +def EXEC : RegisterWithSubRegs<"exec", [EXEC_LO, EXEC_HI]>, DwarfRegNum<[17]> { let Namespace = "AMDGPU"; let SubRegIndices = [sub0, sub1]; let HWEncoding = 126; @@ -151,8 +156,8 @@ def XNACK_MASK_LO : SIReg<"xnack_mask_lo", 104>; def XNACK_MASK_HI : SIReg<"xnack_mask_hi", 105>; -def XNACK_MASK : RegisterWithSubRegs<"xnack_mask", [XNACK_MASK_LO, XNACK_MASK_HI]>, - DwarfRegAlias { +def XNACK_MASK : + RegisterWithSubRegs<"xnack_mask", [XNACK_MASK_LO, XNACK_MASK_HI]> { let Namespace = "AMDGPU"; let SubRegIndices = [sub0, sub1]; let HWEncoding = 104; @@ -162,8 +167,7 @@ def TBA_LO : SIReg<"tba_lo", 108>; def TBA_HI : SIReg<"tba_hi", 109>; -def TBA : RegisterWithSubRegs<"tba", [TBA_LO, TBA_HI]>, - DwarfRegAlias { +def TBA : RegisterWithSubRegs<"tba", [TBA_LO, TBA_HI]> { let Namespace = "AMDGPU"; let SubRegIndices = [sub0, sub1]; let HWEncoding = 108; @@ -172,8 +176,7 @@ def TMA_LO : SIReg<"tma_lo", 110>; def TMA_HI : SIReg<"tma_hi", 111>; -def TMA : RegisterWithSubRegs<"tma", [TMA_LO, TMA_HI]>, - DwarfRegAlias { +def TMA : RegisterWithSubRegs<"tma", [TMA_LO, TMA_HI]> { let Namespace = "AMDGPU"; let SubRegIndices = [sub0, sub1]; let HWEncoding = 110; @@ -192,8 +195,7 @@ } class FlatReg encoding> : - RegisterWithSubRegs<"flat_scratch", [lo, hi]>, - DwarfRegAlias { + RegisterWithSubRegs<"flat_scratch", [lo, hi]> { let Namespace = "AMDGPU"; let SubRegIndices = [sub0, sub1]; let HWEncoding = encoding; @@ -208,19 +210,25 @@ // SGPR registers foreach Index = 0-105 in { - def SGPR#Index : SIReg <"s"#Index, Index>; + def SGPR#Index : + SIReg <"s"#Index, Index>, + DwarfRegNum<[!if(!le(Index, 63), !add(Index, 32), !add(Index, 1024))]>; } // VGPR registers foreach Index = 0-255 in { - def VGPR#Index : SIReg <"v"#Index, Index> { + def VGPR#Index : + SIReg <"v"#Index, Index>, + DwarfRegNum<[!add(Index, 2560)]> { let HWEncoding{8} = 1; } } // AccVGPR registers foreach Index = 0-255 in { - def AGPR#Index : SIReg <"a"#Index, Index> { + def AGPR#Index : + SIReg <"a"#Index, Index>, + DwarfRegNum<[!add(Index, 3072)]> { let HWEncoding{8} = 1; } } diff --git a/llvm/test/DebugInfo/AMDGPU/print-reg-name.s b/llvm/test/DebugInfo/AMDGPU/print-reg-name.s new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/AMDGPU/print-reg-name.s @@ -0,0 +1,10 @@ +; RUN: llvm-mc -triple=amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=asm %s | FileCheck %s + +; Check that we can print symbolic register operands in CFI instructions. + +.text +f: +.cfi_startproc +; CHECK: .cfi_undefined s0 +.cfi_undefined s0 +.cfi_endproc diff --git a/llvm/test/DebugInfo/AMDGPU/register-mapping.s b/llvm/test/DebugInfo/AMDGPU/register-mapping.s new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/AMDGPU/register-mapping.s @@ -0,0 +1,37 @@ +; RUN: llvm-mc -triple=amdgcn-amd-amdhsa -mcpu=gfx1010 -filetype=obj %s | llvm-dwarfdump -debug-frame - | FileCheck %s + +; Check that we implement the DWARF register mapping. + +.text +f: +.cfi_startproc +; CHECK: CIE +; CHECK: Return address column: 16 + +; CHECK: FDE +; CHECK: DW_CFA_undefined: reg16 +.cfi_undefined pc +; CHECK: DW_CFA_undefined: reg17 +.cfi_undefined exec + +; CHECK: DW_CFA_undefined: reg32 +.cfi_undefined s0 +; CHECK: DW_CFA_undefined: reg95 +.cfi_undefined s63 + +; CHECK: DW_CFA_undefined: reg1088 +.cfi_undefined s64 +; CHECK: DW_CFA_undefined: reg1129 +.cfi_undefined s105 + +; CHECK: DW_CFA_undefined: reg2560 +.cfi_undefined v0 +; CHECK: DW_CFA_undefined: reg2815 +.cfi_undefined v255 + +; CHECK: DW_CFA_undefined: reg3072 +.cfi_undefined a0 +; CHECK: DW_CFA_undefined: reg3327 +.cfi_undefined a255 + +.cfi_endproc diff --git a/llvm/test/DebugInfo/AMDGPU/variable-locations.ll b/llvm/test/DebugInfo/AMDGPU/variable-locations.ll --- a/llvm/test/DebugInfo/AMDGPU/variable-locations.ll +++ b/llvm/test/DebugInfo/AMDGPU/variable-locations.ll @@ -32,7 +32,7 @@ @GlobB = common addrspace(1) global i32 0, align 4, !dbg !6 ; CHECK: {{.*}}DW_TAG_subprogram -; CHECK: DW_AT_frame_base [DW_FORM_block1] (DW_OP_reg9 SGPR9) +; CHECK: DW_AT_frame_base [DW_FORM_block1] (DW_OP_reg{{.*}} SGPR9) define amdgpu_kernel void @kernel1( ; CHECK: {{.*}}DW_TAG_formal_parameter