[llvm] r292624 - [mips] Fix debug information for __thread variable

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 8 08:35:23 PST 2017


> On Feb 8, 2017, at 8:12 AM, David Blaikie <dblaikie at gmail.com> wrote:
> 
> Simon: What's the motivation for that name, given the specific role the function appears to have (at least according to the doc comment)?
> 
> Others (Adrian, mostly): Ideas/preferences?
> 

When I last looked at this patch (before the rename) naming the method EmitDebugThreadLocal made sense to me. But after re-reading the patch I think I overlooked that it is being invoked by DIExpr::EmitValue and that feels wrong (or at least strange). Why are all instances of DIEExpr::EmitValue calling EmitDebugThreadLocal (as opposed to adding a method that only affects TLS)?

-- adrian



> On Wed, Feb 8, 2017 at 7:05 AM Petar Jovanovic <Petar.Jovanovic at imgtec.com> wrote:
> > Seems the 'EmitDebugValue' should probably have some mention of 'Thread' in it, given the comment describes this as specifically for thread locals?
> 
> In the original change (see [1]), this was named EmitDebugThreadLocal, but one of the reviewers requested this to be renamed to EmitDebugValue.
> 
> [1] https://reviews.llvm.org/D28770?id=84545#inline-249536
> 
> From: David Blaikie [dblaikie at gmail.com]
> Sent: Monday, February 06, 2017 9:54 PM
> To: Petar Jovanovic; llvm-commits at lists.llvm.org; Eric Christopher; Adrian Prantl
> Subject: Re: [llvm] r292624 - [mips] Fix debug information for __thread variable
> 
> Seems the 'EmitDebugValue' should probably have some mention of 'Thread' in it, given the comment describes this as specifically for thread locals?
> 
> On Fri, Jan 20, 2017 at 10:04 AM Petar Jovanovic via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> Author: petarj
> Date: Fri Jan 20 11:53:30 2017
> New Revision: 292624
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=292624&view=rev
> Log:
> [mips] Fix debug information for __thread variable
> 
> This patch fixes debug information for __thread variable on Mips
> using .dtprelword and .dtpreldword directives.
> 
> Patch by Aleksandar Beserminji.
> 
> Differential Revision: http://reviews.llvm.org/D28770
> 
> Added:
>     llvm/trunk/test/DebugInfo/Mips/tls.ll
> Modified:
>     llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
>     llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
>     llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
>     llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
>     llvm/trunk/lib/Target/Mips/MipsAsmPrinter.h
>     llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp
>     llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.h
> 
> Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=292624&r1=292623&r2=292624&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Fri Jan 20 11:53:30 2017
> @@ -480,6 +480,12 @@ public:
>    /// Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
>    virtual unsigned getISAEncoding() { return 0; }
> 
> +  /// Emit the directive and value for debug thread local expression
> +  ///
> +  /// \p Value - The value to emit.
> +  /// \p Size - The size of the integer (in bytes) to emit.
> +  virtual void EmitDebugValue(const MCExpr *Value, unsigned Size) const;
> +
>    //===------------------------------------------------------------------===//
>    // Dwarf Lowering Routines
>    //===------------------------------------------------------------------===//
> 
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=292624&r1=292623&r2=292624&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Fri Jan 20 11:53:30 2017
> @@ -567,6 +567,15 @@ void AsmPrinter::EmitGlobalVariable(cons
>    OutStreamer->AddBlankLine();
>  }
> 
> +/// Emit the directive and value for debug thread local expression
> +///
> +/// \p Value - The value to emit.
> +/// \p Size - The size of the integer (in bytes) to emit.
> +void AsmPrinter::EmitDebugValue(const MCExpr *Value,
> +                                      unsigned Size) const {
> +  OutStreamer->EmitValue(Value, Size);
> +}
> +
>  /// EmitFunctionHeader - This method emits the header for the current
>  /// function.
>  void AsmPrinter::EmitFunctionHeader() {
> 
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp?rev=292624&r1=292623&r2=292624&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DIE.cpp Fri Jan 20 11:53:30 2017
> @@ -484,7 +484,7 @@ void DIEInteger::print(raw_ostream &O) c
>  /// EmitValue - Emit expression value.
>  ///
>  void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
> -  AP->OutStreamer->EmitValue(Expr, SizeOf(AP, Form));
> +  AP->EmitDebugValue(Expr, SizeOf(AP, Form));
>  }
> 
>  /// SizeOf - Determine size of expression value in bytes.
> 
> Modified: llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp?rev=292624&r1=292623&r2=292624&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp (original)
> +++ llvm/trunk/lib/Target/Mips/MipsAsmPrinter.cpp Fri Jan 20 11:53:30 2017
> @@ -1037,6 +1037,22 @@ void MipsAsmPrinter::PrintDebugValueComm
>    // TODO: implement
>  }
> 
> +// Emit .dtprelword or .dtpreldword directive
> +// and value for debug thread local expression.
> +void MipsAsmPrinter::EmitDebugValue(const MCExpr *Value,
> +                                          unsigned Size) const {
> +  switch (Size) {
> +  case 4:
> +    OutStreamer->EmitDTPRel32Value(Value);
> +    break;
> +  case 8:
> +    OutStreamer->EmitDTPRel64Value(Value);
> +    break;
> +  default:
> +    llvm_unreachable("Unexpected size of expression value.");
> +  }
> +}
> +
>  // Align all targets of indirect branches on bundle size.  Used only if target
>  // is NaCl.
>  void MipsAsmPrinter::NaClAlignIndirectJumpTargets(MachineFunction &MF) {
> 
> Modified: llvm/trunk/lib/Target/Mips/MipsAsmPrinter.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsAsmPrinter.h?rev=292624&r1=292623&r2=292624&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MipsAsmPrinter.h (original)
> +++ llvm/trunk/lib/Target/Mips/MipsAsmPrinter.h Fri Jan 20 11:53:30 2017
> @@ -140,6 +140,7 @@ public:
>    void EmitStartOfAsmFile(Module &M) override;
>    void EmitEndOfAsmFile(Module &M) override;
>    void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
> +  void EmitDebugValue(const MCExpr *Value, unsigned Size) const override;
>  };
>  }
> 
> 
> Modified: llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp?rev=292624&r1=292623&r2=292624&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp (original)
> +++ llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.cpp Fri Jan 20 11:53:30 2017
> @@ -148,3 +148,11 @@ MCSection *MipsTargetObjectFile::getSect
>    // Otherwise, we work the same as ELF.
>    return TargetLoweringObjectFileELF::getSectionForConstant(DL, Kind, C, Align);
>  }
> +
> +const MCExpr *
> +MipsTargetObjectFile::getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
> +  const MCExpr *Expr =
> +      MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, getContext());
> +  return MCBinaryExpr::createAdd(
> +      Expr, MCConstantExpr::create(0x8000, getContext()), getContext());
> +}
> 
> Modified: llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.h?rev=292624&r1=292623&r2=292624&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.h (original)
> +++ llvm/trunk/lib/Target/Mips/MipsTargetObjectFile.h Fri Jan 20 11:53:30 2017
> @@ -42,6 +42,8 @@ class MipsTargetMachine;
>      MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
>                                       const Constant *C,
>                                       unsigned &Align) const override;
> +    /// Describe a TLS variable address within debug info.
> +    const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const override;
>    };
>  } // end namespace llvm
> 
> 
> Added: llvm/trunk/test/DebugInfo/Mips/tls.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Mips/tls.ll?rev=292624&view=auto
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/Mips/tls.ll (added)
> +++ llvm/trunk/test/DebugInfo/Mips/tls.ll Fri Jan 20 11:53:30 2017
> @@ -0,0 +1,22 @@
> +; RUN: llc -O0 -march=mips -mcpu=mips32r2 -filetype=asm < %s | FileCheck %s -check-prefix=CHECK-WORD
> +; RUN: llc -O0 -march=mips64 -mcpu=mips64r2 -filetype=asm < %s | FileCheck %s -check-prefix=CHECK-DWORD
> +
> + at x = thread_local global i32 5, align 4, !dbg !0
> +
> +; CHECK-WORD: .dtprelword x+32768
> +; CHECK-DWORD: .dtpreldword x+32768
> +
> +!llvm.dbg.cu = !{!2}
> +!llvm.module.flags = !{!7, !8}
> +!llvm.ident = !{!9}
> +
> +!0 = !DIGlobalVariableExpression(var: !1)
> +!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
> +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 4.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
> +!3 = !DIFile(filename: "tls.c", directory: "/tmp")
> +!4 = !{}
> +!5 = !{!0}
> +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
> +!7 = !{i32 2, !"Dwarf Version", i32 4}
> +!8 = !{i32 2, !"Debug Info Version", i32 3}
> +!9 = !{!"clang version 4.0.0"}
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list