LLVM  10.0.0svn
NVPTXTargetStreamer.cpp
Go to the documentation of this file.
1 //=====- NVPTXTargetStreamer.cpp - NVPTXTargetStreamer class ------------=====//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the NVPTXTargetStreamer class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "NVPTXTargetStreamer.h"
14 #include "llvm/MC/MCAsmInfo.h"
15 #include "llvm/MC/MCContext.h"
17 
18 using namespace llvm;
19 
20 //
21 // NVPTXTargetStreamer Implemenation
22 //
24 
26 
28  for (const std::string &S : DwarfFiles)
29  getStreamer().EmitRawText(S.data());
30  DwarfFiles.clear();
31 }
32 
34  if (HasSections)
35  getStreamer().EmitRawText("\t}");
36 }
37 
39  DwarfFiles.emplace_back(Directive);
40 }
41 
42 static bool isDwarfSection(const MCObjectFileInfo *FI,
43  const MCSection *Section) {
44  // FIXME: the checks for the DWARF sections are very fragile and should be
45  // fixed up in a followup patch.
46  if (!Section || Section->getKind().isText() ||
47  Section->getKind().isWriteable())
48  return false;
49  return Section == FI->getDwarfAbbrevSection() ||
50  Section == FI->getDwarfInfoSection() ||
51  Section == FI->getDwarfMacinfoSection() ||
52  Section == FI->getDwarfFrameSection() ||
53  Section == FI->getDwarfAddrSection() ||
54  Section == FI->getDwarfRangesSection() ||
55  Section == FI->getDwarfARangesSection() ||
56  Section == FI->getDwarfLocSection() ||
57  Section == FI->getDwarfStrSection() ||
58  Section == FI->getDwarfLineSection() ||
59  Section == FI->getDwarfStrOffSection() ||
60  Section == FI->getDwarfLineStrSection() ||
61  Section == FI->getDwarfPubNamesSection() ||
62  Section == FI->getDwarfPubTypesSection() ||
63  Section == FI->getDwarfSwiftASTSection() ||
64  Section == FI->getDwarfTypesDWOSection() ||
65  Section == FI->getDwarfAbbrevDWOSection() ||
66  Section == FI->getDwarfAccelObjCSection() ||
67  Section == FI->getDwarfAccelNamesSection() ||
68  Section == FI->getDwarfAccelTypesSection() ||
69  Section == FI->getDwarfAccelNamespaceSection() ||
70  Section == FI->getDwarfLocDWOSection() ||
71  Section == FI->getDwarfStrDWOSection() ||
72  Section == FI->getDwarfCUIndexSection() ||
73  Section == FI->getDwarfInfoDWOSection() ||
74  Section == FI->getDwarfLineDWOSection() ||
75  Section == FI->getDwarfTUIndexSection() ||
76  Section == FI->getDwarfStrOffDWOSection() ||
77  Section == FI->getDwarfDebugNamesSection() ||
78  Section == FI->getDwarfDebugInlineSection() ||
79  Section == FI->getDwarfGnuPubNamesSection() ||
80  Section == FI->getDwarfGnuPubTypesSection();
81 }
82 
85  const MCExpr *SubSection,
86  raw_ostream &OS) {
87  assert(!SubSection && "SubSection is not null!");
89  // Emit closing brace for DWARF sections only.
90  if (isDwarfSection(FI, CurSection))
91  OS << "\t}\n";
92  if (isDwarfSection(FI, Section)) {
93  // Emit DWARF .file directives in the outermost scope.
95  OS << "\t.section";
96  Section->PrintSwitchToSection(*getStreamer().getContext().getAsmInfo(),
97  FI->getTargetTriple(), OS, SubSection);
98  // DWARF sections are enclosed into braces - emit the open one.
99  OS << "\t{\n";
100  HasSections = true;
101  }
102 }
103 
106  // TODO: enable this once the bug in the ptxas with the packed bytes is
107  // resolved. Currently, (it is confirmed by NVidia) it causes a crash in
108  // ptxas.
109 #if 0
110  const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
111  const char *Directive = MAI->getData8bitsDirective();
112  unsigned NumElements = Data.size();
113  const unsigned MaxLen = 40;
114  unsigned NumChunks = 1 + ((NumElements - 1) / MaxLen);
115  // Split the very long directives into several parts if the limit is
116  // specified.
117  for (unsigned I = 0; I < NumChunks; ++I) {
118  SmallString<128> Str;
119  raw_svector_ostream OS(Str);
120 
121  const char *Label = Directive;
122  for (auto It = std::next(Data.bytes_begin(), I * MaxLen),
123  End = (I == NumChunks - 1)
124  ? Data.bytes_end()
125  : std::next(Data.bytes_begin(), (I + 1) * MaxLen);
126  It != End; ++It) {
127  OS << Label << (unsigned)*It;
128  if (Label == Directive)
129  Label = ",";
130  }
131  Streamer.EmitRawText(OS.str());
132  }
133 #endif
134 }
135 
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:318
void closeLastSection()
Close last section.
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:641
MCSection * getDwarfStrOffSection() const
SectionKind getKind() const
Definition: MCSection.h:106
MCSection * getDwarfTUIndexSection() const
MCSection * getDwarfAccelObjCSection() const
MCSection * getDwarfCUIndexSection() const
void EmitRawText(const Twine &String)
If this file is backed by a assembly streamer, this dumps the specified string in the output ...
Definition: MCStreamer.cpp:948
MCSection * getDwarfStrSection() const
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MCSection * getDwarfLineSection() const
const unsigned char * bytes_end() const
Definition: StringRef.h:122
bool isWriteable() const
Definition: SectionKind.h:144
MCSection * getDwarfLocSection() const
Target specific streamer interface.
Definition: MCStreamer.h:91
MCSection * getDwarfAccelNamesSection() const
MCSection * getDwarfLineStrSection() const
void emitRawBytes(StringRef Data) override
Emit the bytes in Data into the output.
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:530
MCSection * getDwarfARangesSection() const
MCSection * getDwarfPubNamesSection() const
MCContext & getContext() const
Definition: MCStreamer.h:258
MCSection * getDwarfMacinfoSection() const
MCSection * getDwarfLocDWOSection() const
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
MCSection * getDwarfFrameSection() const
bool isText() const
Definition: SectionKind.h:118
const MCSection * getDwarfDebugInlineSection() const
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:144
MCSection * getDwarfAccelTypesSection() const
MCSection * getDwarfAbbrevSection() const
MCSection * getDwarfAbbrevDWOSection() const
const char * getData8bitsDirective() const
Definition: MCAsmInfo.h:425
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
MCSection * getDwarfGnuPubTypesSection() const
MCSection * getDwarfTypesDWOSection() const
Streaming machine code generation interface.
Definition: MCStreamer.h:196
MCSection * getDwarfAddrSection() const
MCSection * getDwarfLineDWOSection() const
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:322
MCSection * getDwarfSwiftASTSection() const
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const =0
void changeSection(const MCSection *CurSection, MCSection *Section, const MCExpr *SubSection, raw_ostream &OS) override
Update streamer for a new active section.
MCStreamer & getStreamer()
Definition: MCStreamer.h:99
MCStreamer & Streamer
Definition: MCStreamer.h:93
const Triple & getTargetTriple() const
static bool isDwarfSection(const MCObjectFileInfo *FI, const MCSection *Section)
StringRef str()
Return a StringRef for the vector contents.
Definition: raw_ostream.h:555
MCSection * getDwarfInfoSection() const
MCSection * getDwarfDebugNamesSection() const
MCSection * getDwarfStrOffDWOSection() const
void emitDwarfFileDirective(StringRef Directive) override
Record DWARF file directives for later output.
MCSection * getDwarfPubTypesSection() const
MCSection * getDwarfStrDWOSection() const
const unsigned char * bytes_begin() const
Definition: StringRef.h:119
#define I(x, y, z)
Definition: MD5.cpp:58
MCSection * getDwarfGnuPubNamesSection() const
virtual void emitRawBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:77
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSection * getDwarfAccelNamespaceSection() const
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
MCSection * getDwarfInfoDWOSection() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
MCSection * getDwarfRangesSection() const
void outputDwarfFileDirectives()
Outputs the list of the DWARF &#39;.file&#39; directives to the streamer.