LLVM  8.0.1
NVPTXTargetStreamer.cpp
Go to the documentation of this file.
1 //=====- NVPTXTargetStreamer.cpp - NVPTXTargetStreamer class ------------=====//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the NVPTXTargetStreamer class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "NVPTXTargetStreamer.h"
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCContext.h"
18 
19 using namespace llvm;
20 
21 //
22 // NVPTXTargetStreamer Implemenation
23 //
25 
27 
29  for (const std::string &S : DwarfFiles)
30  getStreamer().EmitRawText(S.data());
31  DwarfFiles.clear();
32 }
33 
35  DwarfFiles.emplace_back(Directive);
36 }
37 
38 static bool isDwarfSection(const MCObjectFileInfo *FI,
39  const MCSection *Section) {
40  // FIXME: the checks for the DWARF sections are very fragile and should be
41  // fixed up in a followup patch.
42  if (!Section || Section->getKind().isText() ||
43  Section->getKind().isWriteable())
44  return false;
45  return Section == FI->getDwarfAbbrevSection() ||
46  Section == FI->getDwarfInfoSection() ||
47  Section == FI->getDwarfMacinfoSection() ||
48  Section == FI->getDwarfFrameSection() ||
49  Section == FI->getDwarfAddrSection() ||
50  Section == FI->getDwarfRangesSection() ||
51  Section == FI->getDwarfARangesSection() ||
52  Section == FI->getDwarfLocSection() ||
53  Section == FI->getDwarfStrSection() ||
54  Section == FI->getDwarfLineSection() ||
55  Section == FI->getDwarfStrOffSection() ||
56  Section == FI->getDwarfLineStrSection() ||
57  Section == FI->getDwarfPubNamesSection() ||
58  Section == FI->getDwarfPubTypesSection() ||
59  Section == FI->getDwarfSwiftASTSection() ||
60  Section == FI->getDwarfTypesDWOSection() ||
61  Section == FI->getDwarfAbbrevDWOSection() ||
62  Section == FI->getDwarfAccelObjCSection() ||
63  Section == FI->getDwarfAccelNamesSection() ||
64  Section == FI->getDwarfAccelTypesSection() ||
65  Section == FI->getDwarfAccelNamespaceSection() ||
66  Section == FI->getDwarfLocDWOSection() ||
67  Section == FI->getDwarfStrDWOSection() ||
68  Section == FI->getDwarfCUIndexSection() ||
69  Section == FI->getDwarfInfoDWOSection() ||
70  Section == FI->getDwarfLineDWOSection() ||
71  Section == FI->getDwarfTUIndexSection() ||
72  Section == FI->getDwarfStrOffDWOSection() ||
73  Section == FI->getDwarfDebugNamesSection() ||
74  Section == FI->getDwarfDebugInlineSection() ||
75  Section == FI->getDwarfGnuPubNamesSection() ||
76  Section == FI->getDwarfGnuPubTypesSection();
77 }
78 
81  const MCExpr *SubSection,
82  raw_ostream &OS) {
83  assert(!SubSection && "SubSection is not null!");
85  // FIXME: remove comment once debug info is properly supported.
86  // Emit closing brace for DWARF sections only.
87  if (isDwarfSection(FI, CurSection))
88  OS << "//\t}\n";
89  if (isDwarfSection(FI, Section)) {
90  // Emit DWARF .file directives in the outermost scope.
92  OS << "//\t.section";
93  Section->PrintSwitchToSection(*getStreamer().getContext().getAsmInfo(),
94  FI->getTargetTriple(), OS, SubSection);
95  // DWARF sections are enclosed into braces - emit the open one.
96  OS << "//\t{\n";
97  }
98 }
99 
101  const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
102  const char *Directive = MAI->getData8bitsDirective();
103  unsigned NumElements = Data.size();
104  const unsigned MaxLen = 40;
105  unsigned NumChunks = 1 + ((NumElements - 1) / MaxLen);
106  // Split the very long directives into several parts if the limit is
107  // specified.
108  for (unsigned I = 0; I < NumChunks; ++I) {
109  SmallString<128> Str;
110  raw_svector_ostream OS(Str);
111 
112  const char *Label = Directive;
113  for (auto It = std::next(Data.bytes_begin(), I * MaxLen),
114  End = (I == NumChunks - 1)
115  ? Data.bytes_end()
116  : std::next(Data.bytes_begin(), (I + 1) * MaxLen);
117  It != End; ++It) {
118  OS << Label << (unsigned)*It;
119  if (Label == Directive)
120  Label = ",";
121  }
122  Streamer.EmitRawText(OS.str());
123  }
124 }
125 
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:293
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
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:890
MCSection * getDwarfStrSection() const
This class represents lattice values for constants.
Definition: AllocatorList.h:24
MCSection * getDwarfLineSection() const
const unsigned char * bytes_end() const
Definition: StringRef.h:113
bool isWriteable() const
Definition: SectionKind.h:145
MCSection * getDwarfLocSection() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
Target specific streamer interface.
Definition: MCStreamer.h:84
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:510
MCSection * getDwarfARangesSection() const
MCSection * getDwarfPubNamesSection() const
MCContext & getContext() const
Definition: MCStreamer.h:251
MCSection * getDwarfMacinfoSection() const
MCSection * getDwarfLocDWOSection() const
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
MCSection * getDwarfFrameSection() const
bool isText() const
Definition: SectionKind.h:119
const MCSection * getDwarfDebugInlineSection() const
MCSection * getDwarfAccelTypesSection() const
MCSection * getDwarfAbbrevSection() const
MCSection * getDwarfAbbrevDWOSection() const
const char * getData8bitsDirective() const
Definition: MCAsmInfo.h:414
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:189
MCSection * getDwarfAddrSection() const
MCSection * getDwarfLineDWOSection() const
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:297
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:92
MCStreamer & Streamer
Definition: MCStreamer.h:86
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:535
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:110
void emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:652
#define I(x, y, z)
Definition: MD5.cpp:58
MCSection * getDwarfGnuPubNamesSection() const
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:46
MCSection * getDwarfInfoDWOSection() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
MCSection * getDwarfRangesSection() const
void outputDwarfFileDirectives()
Outputs the list of the DWARF &#39;.file&#39; directives to the streamer.