]> granicus.if.org Git - llvm/commitdiff
[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338039 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 248358414694876d9de23fdcd9dd49e45e2789fe..b6056380916ca936b9ac98632a86523d1a3840c7 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 aec161c6dd75944c2b967851beeebe48ca72b95e..5c3e6c865f5cfcd3bfe66d11096e04043f604127 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 b41a8316379e81ed01b1ad469dc57102d0f90757..a966b99284007fae3efa048260bc1664ba59e9fa 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 02d1a041a15fd4716c937bfd493bce096a004b78..3b042c74b26cd5adab7fb52014c4c33f57307f55 100644 (file)
@@ -310,6 +310,8 @@ public:
   }
 
   std::string getVirtualRegisterName(unsigned) const;
+
+  const MCSymbol *getFunctionFrameSymbol() const override;
 };
 
 } // end namespace llvm
index 729f3ed7b79e82c65fe9e642931adb40781a7a55..e5e6637967b2054cde64f5503b1fe96645d400b8 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 a802cf85d2e00a4cd52bb37e77178aa44b06f0e2..0a7856b9d5de1138ae98380e115652af6c43396e 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 be9ef26cac37d72a81bc40ff7e0389397c1d9523..2f8d660663562f86bc97956b84fa7141654de115 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