[DEBUGINFO, NVPTX] Emit correct debug information for local variables.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 26 Jul 2018 16:29:52 +0000 (16:29 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 26 Jul 2018 16:29:52 +0000 (16:29 +0000)
Summary:
NVPTX target dos not use register-based frame information. Instead it
relies on the artificial local_depot that is used instead of the frame
and the data for variables must be emitted relatively to this
local_depot.

Reviewers: tra, jlebar, echristo

Subscribers: jholewinski, aprantl, JDevlieghere, llvm-commits

Differential Revision: https://reviews.llvm.org/D45963

llvm-svn: 338039

llvm/include/llvm/CodeGen/AsmPrinter.h
llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
llvm/lib/Target/NVPTX/NVPTXFrameLowering.cpp
llvm/lib/Target/NVPTX/NVPTXFrameLowering.h
llvm/test/DebugInfo/NVPTX/dbg-declare-alloca.ll

index 2483584..b605638 100644 (file)
@@ -201,6 +201,10 @@ public:
   /// Return a unique ID for the current function.
   unsigned getFunctionNumber() const;
 
+  /// Return symbol for the function pseudo stack if the stack frame is not a
+  /// register based.
+  virtual const MCSymbol *getFunctionFrameSymbol() const { return nullptr; }
+
   MCSymbol *getFunctionBegin() const { return CurrentFnBegin; }
   MCSymbol *getFunctionEnd() const { return CurrentFnEnd; }
   MCSymbol *getCurExceptionSym();
index aec161c..5c3e6c8 100644 (file)
@@ -578,8 +578,11 @@ DIE *DwarfCompileUnit::constructVariableDIEImpl(const DbgVariable &DV,
     Ops.append(Expr->elements_begin(), Expr->elements_end());
     DIExpressionCursor Cursor(Ops);
     DwarfExpr.setMemoryLocationKind();
-    DwarfExpr.addMachineRegExpression(
-        *Asm->MF->getSubtarget().getRegisterInfo(), Cursor, FrameReg);
+    if (const MCSymbol *FrameSymbol = Asm->getFunctionFrameSymbol())
+      addOpAddress(*Loc, FrameSymbol);
+    else
+      DwarfExpr.addMachineRegExpression(
+          *Asm->MF->getSubtarget().getRegisterInfo(), Cursor, FrameReg);
     DwarfExpr.addExpression(std::move(Cursor));
   }
   addBlock(*VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
index b41a831..a966b99 100644 (file)
@@ -495,6 +495,12 @@ void NVPTXAsmPrinter::EmitFunctionBodyEnd() {
   VRegMapping.clear();
 }
 
+const MCSymbol *NVPTXAsmPrinter::getFunctionFrameSymbol() const {
+    SmallString<128> Str;
+    raw_svector_ostream(Str) << DEPOTNAME << getFunctionNumber();
+    return OutContext.getOrCreateSymbol(Str);
+}
+
 void NVPTXAsmPrinter::emitImplicitDef(const MachineInstr *MI) const {
   unsigned RegNo = MI->getOperand(0).getReg();
   if (TargetRegisterInfo::isVirtualRegister(RegNo)) {
index 02d1a04..3b042c7 100644 (file)
@@ -310,6 +310,8 @@ public:
   }
 
   std::string getVirtualRegisterName(unsigned) const;
+
+  const MCSymbol *getFunctionFrameSymbol() const override;
 };
 
 } // end namespace llvm
index 729f3ed..e5e6637 100644 (file)
@@ -64,6 +64,14 @@ void NVPTXFrameLowering::emitPrologue(MachineFunction &MF,
   }
 }
 
+int NVPTXFrameLowering::getFrameIndexReference(const MachineFunction &MF,
+                                               int FI,
+                                               unsigned &FrameReg) const {
+  const MachineFrameInfo &MFI = MF.getFrameInfo();
+  FrameReg = NVPTX::VRDepot;
+  return MFI.getObjectOffset(FI) - getOffsetOfLocalArea();
+}
+
 void NVPTXFrameLowering::emitEpilogue(MachineFunction &MF,
                                       MachineBasicBlock &MBB) const {}
 
index a802cf8..0a7856b 100644 (file)
@@ -25,6 +25,8 @@ public:
   bool hasFP(const MachineFunction &MF) const override;
   void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
+  int getFrameIndexReference(const MachineFunction &MF, int FI,
+                             unsigned &FrameReg) const override;
 
   MachineBasicBlock::iterator
   eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
index be9ef26..2f8d660 100644 (file)
 ; CHECK: // }
 ; CHECK: // .section .debug_info
 ; CHECK: // {
-; CHECK: // .b32 126                             // Length of Unit
+; CHECK: // .b32 135                             // Length of Unit
 ; CHECK: // .b8 2                                // DWARF version number
 ; CHECK: // .b8 0
 ; CHECK: // .b32 .debug_abbrev                   // Offset Into Abbrev. Section
 ; CHECK: // .b8 8                                // Address Size (in bytes)
-; CHECK: // .b8 1                                // Abbrev [1] 0xb:0x77 DW_TAG_compile_unit
+; CHECK: // .b8 1                                // Abbrev [1] 0xb:0x80 DW_TAG_compile_unit
 ; CHECK: // .b8 99                               // DW_AT_producer
 ; CHECK: // .b8 108
 ; CHECK: // .b8 97
 ; CHECK: // .b8 0
 ; CHECK: // .b64 Lfunc_begin0                    // DW_AT_low_pc
 ; CHECK: // .b64 Lfunc_end0                      // DW_AT_high_pc
-; CHECK: // .b8 2                                // Abbrev [2] 0x31:0x34 DW_TAG_subprogram
+; CHECK: // .b8 2                                // Abbrev [2] 0x31:0x3d DW_TAG_subprogram
 ; CHECK: // .b64 Lfunc_begin0                    // DW_AT_low_pc
 ; CHECK: // .b64 Lfunc_end0                      // DW_AT_high_pc
 ; CHECK: // .b8 1                                // DW_AT_frame_base
 ; CHECK: // .b8 3                                // DW_AT_decl_line
 ; CHECK: // .b8 1                                // DW_AT_prototyped
 ; CHECK: // .b8 1                                // DW_AT_external
-; CHECK: // .b8 3                                // Abbrev [3] 0x58:0xc DW_TAG_variable
-; CHECK: // .b8 2                                // DW_AT_location
+; CHECK: // .b8 3                                // Abbrev [3] 0x58:0x15 DW_TAG_variable
+; CHECK: // .b8 11                               // DW_AT_location
+; CHECK: // .b8 3
+; CHECK: // .b64 __local_depot0
 ; CHECK: // .b8 35
-; CHECK: // .b8 8
+; CHECK: // .b8 0
 ; CHECK: // .b8 111                              // DW_AT_name
 ; CHECK: // .b8 0
 ; CHECK: // .b8 1                                // DW_AT_decl_file
 ; CHECK: // .b8 4                                // DW_AT_decl_line
-; CHECK: // .b32 101                              // DW_AT_type
+; CHECK: // .b32 110                             // DW_AT_type
 ; CHECK: // .b8 0                                // End Of Children Mark
-; CHECK: // .b8 4                                // Abbrev [4] 0x65:0x15 DW_TAG_structure_type
+; CHECK: // .b8 4                                // Abbrev [4] 0x6e:0x15 DW_TAG_structure_type
 ; CHECK: // .b8 70                               // DW_AT_name
 ; CHECK: // .b8 111
 ; CHECK: // .b8 111
 ; CHECK: // .b8 4                                // DW_AT_byte_size
 ; CHECK: // .b8 1                                // DW_AT_decl_file
 ; CHECK: // .b8 1                                // DW_AT_decl_line
-; CHECK: // .b8 5                                // Abbrev [5] 0x6d:0xc DW_TAG_member
+; CHECK: // .b8 5                                // Abbrev [5] 0x76:0xc DW_TAG_member
 ; CHECK: // .b8 120                              // DW_AT_name
 ; CHECK: // .b8 0
-; CHECK: // .b32 122                             // DW_AT_type
+; CHECK: // .b32 131                             // DW_AT_type
 ; CHECK: // .b8 1                                // DW_AT_decl_file
 ; CHECK: // .b8 1                                // DW_AT_decl_line
 ; CHECK: // .b8 2                                // DW_AT_data_member_location
 ; CHECK: // .b8 35
 ; CHECK: // .b8 0
 ; CHECK: // .b8 0                                // End Of Children Mark
-; CHECK: // .b8 6                                // Abbrev [6] 0x7a:0x7 DW_TAG_base_type
+; CHECK: // .b8 6                                // Abbrev [6] 0x83:0x7 DW_TAG_base_type
 ; CHECK: // .b8 105                              // DW_AT_name
 ; CHECK: // .b8 110
 ; CHECK: // .b8 116