LLVM  16.0.0git
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)
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 
84  MCSection *Section,
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  getStreamer().getContext().getTargetTriple(),
98  OS, SubSection);
99  // DWARF sections are enclosed into braces - emit the open one.
100  OS << "\t{\n";
101  HasSections = true;
102  }
103 }
104 
107  // TODO: enable this once the bug in the ptxas with the packed bytes is
108  // resolved. Currently, (it is confirmed by NVidia) it causes a crash in
109  // ptxas.
110 #if 0
111  const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
112  const char *Directive = MAI->getData8bitsDirective();
113  unsigned NumElements = Data.size();
114  const unsigned MaxLen = 40;
115  unsigned NumChunks = 1 + ((NumElements - 1) / MaxLen);
116  // Split the very long directives into several parts if the limit is
117  // specified.
118  for (unsigned I = 0; I < NumChunks; ++I) {
119  SmallString<128> Str;
120  raw_svector_ostream OS(Str);
121 
122  const char *Label = Directive;
123  for (auto It = std::next(Data.bytes_begin(), I * MaxLen),
124  End = (I == NumChunks - 1)
125  ? Data.bytes_end()
126  : std::next(Data.bytes_begin(), (I + 1) * MaxLen);
127  It != End; ++It) {
128  OS << Label << (unsigned)*It;
129  if (Label == Directive)
130  Label = ",";
131  }
132  Streamer.emitRawText(OS.str());
133  }
134 #endif
135 }
136 
llvm::MCTargetStreamer::getStreamer
MCStreamer & getStreamer()
Definition: MCStreamer.h:101
llvm::MCObjectFileInfo::getDwarfRangesSection
MCSection * getDwarfRangesSection() const
Definition: MCObjectFileInfo.h:295
llvm::NVPTXTargetStreamer::NVPTXTargetStreamer
NVPTXTargetStreamer(MCStreamer &S)
Definition: NVPTXTargetStreamer.cpp:23
llvm::MCObjectFileInfo::getDwarfAddrSection
MCSection * getDwarfAddrSection() const
Definition: MCObjectFileInfo.h:325
llvm::MCContext::getObjectFileInfo
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:450
llvm::MCObjectFileInfo::getDwarfAccelObjCSection
MCSection * getDwarfAccelObjCSection() const
Definition: MCObjectFileInfo.h:307
llvm::MCObjectFileInfo::getDwarfFrameSection
MCSection * getDwarfFrameSection() const
Definition: MCObjectFileInfo.h:280
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::NVPTXTargetStreamer::outputDwarfFileDirectives
void outputDwarfFileDirectives()
Outputs the list of the DWARF '.file' directives to the streamer.
Definition: NVPTXTargetStreamer.cpp:27
llvm::MCObjectFileInfo::getDwarfPubTypesSection
MCSection * getDwarfPubTypesSection() const
Definition: MCObjectFileInfo.h:282
llvm::MCTargetStreamer::emitRawBytes
virtual void emitRawBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:80
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
llvm::MCObjectFileInfo::getDwarfCUIndexSection
MCSection * getDwarfCUIndexSection() const
Definition: MCObjectFileInfo.h:336
MCObjectFileInfo.h
llvm::MCObjectFileInfo::getDwarfLocSection
MCSection * getDwarfLocSection() const
Definition: MCObjectFileInfo.h:293
llvm::MCObjectFileInfo::getDwarfStrOffSection
MCSection * getDwarfStrOffSection() const
Definition: MCObjectFileInfo.h:324
NVPTXTargetStreamer.h
llvm::MCObjectFileInfo::getDwarfGnuPubTypesSection
MCSection * getDwarfGnuPubTypesSection() const
Definition: MCObjectFileInfo.h:286
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MCObjectFileInfo::getDwarfInfoSection
MCSection * getDwarfInfoSection() const
Definition: MCObjectFileInfo.h:274
llvm::MCObjectFileInfo::getDwarfPubNamesSection
MCSection * getDwarfPubNamesSection() const
Definition: MCObjectFileInfo.h:281
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:212
llvm::MCObjectFileInfo::getDwarfARangesSection
MCSection * getDwarfARangesSection() const
Definition: MCObjectFileInfo.h:294
MCContext.h
llvm::MCObjectFileInfo::getDwarfMacinfoSection
MCSection * getDwarfMacinfoSection() const
Definition: MCObjectFileInfo.h:298
llvm::MCObjectFileInfo::getDwarfInfoDWOSection
MCSection * getDwarfInfoDWOSection() const
Definition: MCObjectFileInfo.h:314
llvm::MCObjectFileInfo::getDwarfLocDWOSection
MCSection * getDwarfLocDWOSection() const
Definition: MCObjectFileInfo.h:322
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::MCTargetStreamer
Target specific streamer interface.
Definition: MCStreamer.h:93
llvm::MCObjectFileInfo::getDwarfStrDWOSection
MCSection * getDwarfStrDWOSection() const
Definition: MCObjectFileInfo.h:320
llvm::MCObjectFileInfo::getDwarfAccelNamespaceSection
MCSection * getDwarfAccelNamespaceSection() const
Definition: MCObjectFileInfo.h:308
llvm::MCAsmInfo::getData8bitsDirective
const char * getData8bitsDirective() const
Definition: MCAsmInfo.h:566
llvm::SmallString< 128 >
llvm::NVPTXTargetStreamer::~NVPTXTargetStreamer
~NVPTXTargetStreamer() override
llvm::MCObjectFileInfo::getDwarfSwiftASTSection
MCSection * getDwarfSwiftASTSection() const
Definition: MCObjectFileInfo.h:338
llvm::MCContext::getAsmInfo
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:446
llvm::MCObjectFileInfo::getDwarfDebugNamesSection
MCSection * getDwarfDebugNamesSection() const
Definition: MCObjectFileInfo.h:301
llvm::MCTargetStreamer::Streamer
MCStreamer & Streamer
Definition: MCStreamer.h:95
llvm::MCStreamer::emitRawText
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:993
llvm::MCObjectFileInfo::getDwarfAccelNamesSection
MCSection * getDwarfAccelNamesSection() const
Definition: MCObjectFileInfo.h:304
I
#define I(x, y, z)
Definition: MD5.cpp:58
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::NVPTXTargetStreamer::closeLastSection
void closeLastSection()
Close last section.
Definition: NVPTXTargetStreamer.cpp:33
MCAsmInfo.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::raw_svector_ostream::str
StringRef str() const
Return a StringRef for the vector contents.
Definition: raw_ostream.h:683
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MCObjectFileInfo::getDwarfTUIndexSection
MCSection * getDwarfTUIndexSection() const
Definition: MCObjectFileInfo.h:337
llvm::MCObjectFileInfo::getDwarfTypesDWOSection
MCSection * getDwarfTypesDWOSection() const
Definition: MCObjectFileInfo.h:318
llvm::MCObjectFileInfo::getDwarfLineDWOSection
MCSection * getDwarfLineDWOSection() const
Definition: MCObjectFileInfo.h:321
llvm::MCObjectFileInfo::getDwarfAbbrevSection
MCSection * getDwarfAbbrevSection() const
Definition: MCObjectFileInfo.h:273
llvm::MCObjectFileInfo::getDwarfLineStrSection
MCSection * getDwarfLineStrSection() const
Definition: MCObjectFileInfo.h:279
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:293
llvm::MCObjectFileInfo::getDwarfAbbrevDWOSection
MCSection * getDwarfAbbrevDWOSection() const
Definition: MCObjectFileInfo.h:319
llvm::MCObjectFileInfo::getDwarfDebugInlineSection
const MCSection * getDwarfDebugInlineSection() const
Definition: MCObjectFileInfo.h:289
llvm::MCObjectFileInfo::getDwarfStrSection
MCSection * getDwarfStrSection() const
Definition: MCObjectFileInfo.h:292
llvm::NVPTXTargetStreamer::changeSection
void changeSection(const MCSection *CurSection, MCSection *Section, const MCExpr *SubSection, raw_ostream &OS) override
Update streamer for a new active section.
Definition: NVPTXTargetStreamer.cpp:83
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:658
llvm::MCObjectFileInfo::getDwarfAccelTypesSection
MCSection * getDwarfAccelTypesSection() const
Definition: MCObjectFileInfo.h:311
isDwarfSection
static bool isDwarfSection(const MCObjectFileInfo *FI, const MCSection *Section)
Definition: NVPTXTargetStreamer.cpp:42
llvm::NVPTXTargetStreamer::emitDwarfFileDirective
void emitDwarfFileDirective(StringRef Directive) override
Record DWARF file directives for later output.
Definition: NVPTXTargetStreamer.cpp:38
llvm::MCObjectFileInfo::getDwarfLineSection
MCSection * getDwarfLineSection() const
Definition: MCObjectFileInfo.h:278
llvm::Directive
Definition: DirectiveEmitter.h:100
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::NVPTXTargetStreamer::emitRawBytes
void emitRawBytes(StringRef Data) override
Emit the bytes in Data into the output.
Definition: NVPTXTargetStreamer.cpp:105
llvm::MCObjectFileInfo::getDwarfStrOffDWOSection
MCSection * getDwarfStrOffDWOSection() const
Definition: MCObjectFileInfo.h:323
llvm::MCObjectFileInfo
Definition: MCObjectFileInfo.h:27
llvm::MCObjectFileInfo::getDwarfGnuPubNamesSection
MCSection * getDwarfGnuPubNamesSection() const
Definition: MCObjectFileInfo.h:283
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:925