[llvm] r321178 - [NVPTX] Initial adaptation of MCAsmStreamer/MCTargetStreamer for debug info in Cuda.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 2 09:35:56 PST 2018


On Wed, Dec 20, 2017 at 6:55 AM Alexey Bataev via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: abataev
> Date: Wed Dec 20 06:55:10 2017
> New Revision: 321178
>
> URL: http://llvm.org/viewvc/llvm-project?rev=321178&view=rev
> Log:
> [NVPTX] Initial adaptation of MCAsmStreamer/MCTargetStreamer for debug
> info in Cuda.
>
> Summary:
> Initial changes in interfaces of MCAsmStreamer/MCTargetStreamer for
> correct debug info emission for Cuda.
> 1. PTX foramt does not support `.ascii` directives. Added the ability to
> nullify it.
> 2. The initial function label must follow the first debug `.loc`
> directive, not be followed by.
> 3. DWARF sections must be enclosed in braces.
>
> Reviewers: hfinkel, probinson, jlebar, rafael, echristo
>
> Subscribers: sdardis, nemanjai, llvm-commits, aprantl
>
> Differential Revision: https://reviews.llvm.org/D40033
>
> Modified:
>     llvm/trunk/include/llvm/MC/MCAsmInfo.h
>     llvm/trunk/include/llvm/MC/MCStreamer.h
>     llvm/trunk/lib/MC/MCAsmStreamer.cpp
>     llvm/trunk/lib/MC/MCStreamer.cpp
>
> Modified: llvm/trunk/include/llvm/MC/MCAsmInfo.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmInfo.h?rev=321178&r1=321177&r2=321178&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCAsmInfo.h (original)
> +++ llvm/trunk/include/llvm/MC/MCAsmInfo.h Wed Dec 20 06:55:10 2017
> @@ -165,7 +165,8 @@ protected:
>    const char *ZeroDirective;
>
>    /// This directive allows emission of an ascii string with the standard
> C
> -  /// escape characters embedded into it.  Defaults to "\t.ascii\t"
> +  /// escape characters embedded into it.  If a target doesn't support
> this, it
> +  /// can be set to null. Defaults to "\t.ascii\t"
>    const char *AsciiDirective;
>
>    /// If not null, this allows for special handling of zero terminated
> strings
>
> Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=321178&r1=321177&r2=321178&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
> +++ llvm/trunk/include/llvm/MC/MCStreamer.h Wed Dec 20 06:55:10 2017
> @@ -95,6 +95,17 @@ public:
>    virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS,
>                                const MCInst &Inst, const MCSubtargetInfo
> &STI);
>
> +  virtual void emitDwarfFileDirective(StringRef Directive);
> +
> +  /// Update streamer for a new active section.
> +  ///
> +  /// This is called by PopSection and SwitchSection, if the current
> +  /// section changes.
> +  virtual void changeSection(const MCSection *CurSection, MCSection
> *Section,
> +                             const MCExpr *SubSection, raw_ostream &OS);
> +
> +  virtual void emitValue(const MCExpr *Value);
> +
>    virtual void finish();
>  };
>
>
> Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=321178&r1=321177&r2=321178&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Wed Dec 20 06:55:10 2017
> @@ -405,9 +405,13 @@ void MCAsmStreamer::emitExplicitComments
>  void MCAsmStreamer::ChangeSection(MCSection *Section,
>                                    const MCExpr *Subsection) {
>    assert(Section && "Cannot switch to a null section!");
> -  Section->PrintSwitchToSection(
> -      *MAI, getContext().getObjectFileInfo()->getTargetTriple(), OS,
> -      Subsection);
> +  if (MCTargetStreamer *TS = getTargetStreamer()) {
> +    TS->changeSection(getCurrentSectionOnly(), Section, Subsection, OS);
> +  } else {
> +    Section->PrintSwitchToSection(
> +        *MAI, getContext().getObjectFileInfo()->getTargetTriple(), OS,
> +        Subsection);
> +  }
>

This ^ seems awkward. Is there any way to common these two codepaths? (I
see the default implementation of changeSection calls PrintSwitchToSection,
which should make them common... except in this case where MCAsmStreamer
has no target streamer? When does that happen?)


>  }
>
>  void MCAsmStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
> @@ -796,10 +800,15 @@ void MCAsmStreamer::EmitBytes(StringRef
>           "Cannot emit contents before setting section!");
>    if (Data.empty()) return;
>
> -  if (Data.size() == 1) {
> -    OS << MAI->getData8bitsDirective();
> -    OS << (unsigned)(unsigned char)Data[0];
> -    EmitEOL();
> +  // If only single byte is provided or no ascii or asciz directives is
> +  // supported, emit as vector of 8bits data.
> +  if (Data.size() == 1 ||
> +      !(MAI->getAscizDirective() || MAI->getAsciiDirective())) {
> +    const char *Directive = MAI->getData8bitsDirective();
> +    for (const unsigned char C : Data.bytes()) {
> +      OS << Directive << (unsigned)C;
> +      EmitEOL();
> +    }
>      return;
>    }
>
> @@ -884,8 +893,12 @@ void MCAsmStreamer::EmitValueImpl(const
>
>    assert(Directive && "Invalid size for machine code value!");
>    OS << Directive;
> -  Value->print(OS, MAI);
> -  EmitEOL();
> +  if (MCTargetStreamer *TS = getTargetStreamer()) {
> +    TS->emitValue(Value);
> +  } else {
> +    Value->print(OS, MAI);
> +    EmitEOL();
> +  }
>  }
>
>  void MCAsmStreamer::EmitULEB128Value(const MCExpr *Value) {
> @@ -1097,13 +1110,19 @@ unsigned MCAsmStreamer::EmitDwarfFileDir
>      }
>    }
>
> -  OS << "\t.file\t" << FileNo << ' ';
> +  SmallString<128> Str;
> +  raw_svector_ostream OS1(Str);
> +  OS1 << "\t.file\t" << FileNo << ' ';
>    if (!Directory.empty()) {
> -    PrintQuotedString(Directory, OS);
> -    OS << ' ';
> +    PrintQuotedString(Directory, OS1);
> +    OS1 << ' ';
> +  }
> +  PrintQuotedString(Filename, OS1);
> +  if (MCTargetStreamer *TS = getTargetStreamer()) {
> +    TS->emitDwarfFileDirective(OS1.str());
> +  } else {
> +    EmitRawText(OS1.str());
>    }
> -  PrintQuotedString(Filename, OS);
> -  EmitEOL();
>
>    return FileNo;
>  }
>
> Modified: llvm/trunk/lib/MC/MCStreamer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=321178&r1=321177&r2=321178&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/MC/MCStreamer.cpp (original)
> +++ llvm/trunk/lib/MC/MCStreamer.cpp Wed Dec 20 06:55:10 2017
> @@ -49,6 +49,28 @@ void MCTargetStreamer::emitLabel(MCSymbo
>
>  void MCTargetStreamer::finish() {}
>
> +void MCTargetStreamer::changeSection(const MCSection *CurSection,
> +                                     MCSection *Section,
> +                                     const MCExpr *Subsection,
> +                                     raw_ostream &OS) {
> +  Section->PrintSwitchToSection(
> +      *Streamer.getContext().getAsmInfo(),
> +      Streamer.getContext().getObjectFileInfo()->getTargetTriple(), OS,
> +      Subsection);
> +}
> +
> +void MCTargetStreamer::emitDwarfFileDirective(StringRef Directive) {
> +  Streamer.EmitRawText(Directive);
> +}
> +
> +void MCTargetStreamer::emitValue(const MCExpr *Value) {
> +  SmallString<128> Str;
> +  raw_svector_ostream OS(Str);
> +
> +  Value->print(OS, Streamer.getContext().getAsmInfo());
> +  Streamer.EmitRawText(OS.str());
> +}
> +
>  void MCTargetStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr
> *Value) {}
>
>  MCStreamer::MCStreamer(MCContext &Ctx)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180102/ace92779/attachment.html>


More information about the llvm-commits mailing list