LLVM 19.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
18using namespace llvm;
19
20//
21// NVPTXTargetStreamer Implemenation
22//
25
29
31 for (const std::string &S : DwarfFiles)
33 DwarfFiles.clear();
34}
35
37 if (HasSections)
38 getStreamer().emitRawText("\t}");
39}
40
42 DwarfFiles.emplace_back(Directive);
43}
44
45static bool isDwarfSection(const MCObjectFileInfo *FI,
46 const MCSection *Section) {
47 // FIXME: the checks for the DWARF sections are very fragile and should be
48 // fixed up in a followup patch.
49 if (!Section || Section->getKind().isText() ||
50 Section->getKind().isWriteable())
51 return false;
52 return Section == FI->getDwarfAbbrevSection() ||
53 Section == FI->getDwarfInfoSection() ||
54 Section == FI->getDwarfMacinfoSection() ||
55 Section == FI->getDwarfFrameSection() ||
56 Section == FI->getDwarfAddrSection() ||
57 Section == FI->getDwarfRangesSection() ||
58 Section == FI->getDwarfARangesSection() ||
59 Section == FI->getDwarfLocSection() ||
60 Section == FI->getDwarfStrSection() ||
61 Section == FI->getDwarfLineSection() ||
62 Section == FI->getDwarfStrOffSection() ||
63 Section == FI->getDwarfLineStrSection() ||
64 Section == FI->getDwarfPubNamesSection() ||
65 Section == FI->getDwarfPubTypesSection() ||
66 Section == FI->getDwarfSwiftASTSection() ||
67 Section == FI->getDwarfTypesDWOSection() ||
68 Section == FI->getDwarfAbbrevDWOSection() ||
69 Section == FI->getDwarfAccelObjCSection() ||
70 Section == FI->getDwarfAccelNamesSection() ||
71 Section == FI->getDwarfAccelTypesSection() ||
72 Section == FI->getDwarfAccelNamespaceSection() ||
73 Section == FI->getDwarfLocDWOSection() ||
74 Section == FI->getDwarfStrDWOSection() ||
75 Section == FI->getDwarfCUIndexSection() ||
76 Section == FI->getDwarfInfoDWOSection() ||
77 Section == FI->getDwarfLineDWOSection() ||
78 Section == FI->getDwarfTUIndexSection() ||
79 Section == FI->getDwarfStrOffDWOSection() ||
80 Section == FI->getDwarfDebugNamesSection() ||
81 Section == FI->getDwarfDebugInlineSection() ||
82 Section == FI->getDwarfGnuPubNamesSection() ||
83 Section == FI->getDwarfGnuPubTypesSection();
84}
85
87 MCSection *Section,
88 const MCExpr *SubSection,
89 raw_ostream &OS) {
90 assert(!SubSection && "SubSection is not null!");
92 // Emit closing brace for DWARF sections only.
93 if (isDwarfSection(FI, CurSection))
94 OS << "\t}\n";
95 if (isDwarfSection(FI, Section)) {
96 // Emit DWARF .file directives in the outermost scope.
98 OS << "\t.section";
99 Section->printSwitchToSection(*getStreamer().getContext().getAsmInfo(),
100 getStreamer().getContext().getTargetTriple(),
101 OS, SubSection);
102 // DWARF sections are enclosed into braces - emit the open one.
103 OS << "\t{\n";
104 HasSections = true;
105 }
106}
107
110 // TODO: enable this once the bug in the ptxas with the packed bytes is
111 // resolved. Currently, (it is confirmed by NVidia) it causes a crash in
112 // ptxas.
113#if 0
114 const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
115 const char *Directive = MAI->getData8bitsDirective();
116 unsigned NumElements = Data.size();
117 const unsigned MaxLen = 40;
118 unsigned NumChunks = 1 + ((NumElements - 1) / MaxLen);
119 // Split the very long directives into several parts if the limit is
120 // specified.
121 for (unsigned I = 0; I < NumChunks; ++I) {
124
125 const char *Label = Directive;
126 for (auto It = std::next(Data.bytes_begin(), I * MaxLen),
127 End = (I == NumChunks - 1)
128 ? Data.bytes_end()
129 : std::next(Data.bytes_begin(), (I + 1) * MaxLen);
130 It != End; ++It) {
131 OS << Label << (unsigned)*It;
132 if (Label == Directive)
133 Label = ",";
134 }
135 Streamer.emitRawText(OS.str());
136 }
137#endif
138}
139
bool End
Definition: ELF_riscv.cpp:480
#define I(x, y, z)
Definition: MD5.cpp:58
static bool isDwarfSection(const MCObjectFileInfo *FI, const MCSection *Section)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
const char * getData8bitsDirective() const
Definition: MCAsmInfo.h:564
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:450
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:446
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
MCSection * getDwarfAccelTypesSection() const
MCSection * getDwarfGnuPubNamesSection() const
MCSection * getDwarfStrOffDWOSection() const
MCSection * getDwarfRangesSection() const
MCSection * getDwarfAccelNamespaceSection() const
MCSection * getDwarfLineDWOSection() const
MCSection * getDwarfStrOffSection() const
MCSection * getDwarfInfoDWOSection() const
MCSection * getDwarfTypesDWOSection() const
MCSection * getDwarfPubNamesSection() const
MCSection * getDwarfStrSection() const
MCSection * getDwarfLineStrSection() const
MCSection * getDwarfTUIndexSection() const
MCSection * getDwarfDebugNamesSection() const
MCSection * getDwarfAddrSection() const
MCSection * getDwarfLineSection() const
MCSection * getDwarfInfoSection() const
MCSection * getDwarfFrameSection() const
MCSection * getDwarfPubTypesSection() const
const MCSection * getDwarfDebugInlineSection() const
MCSection * getDwarfGnuPubTypesSection() const
MCSection * getDwarfStrDWOSection() const
MCSection * getDwarfAccelNamesSection() const
MCSection * getDwarfAbbrevDWOSection() const
MCSection * getDwarfAbbrevSection() const
MCSection * getDwarfSwiftASTSection() const
MCSection * getDwarfCUIndexSection() const
MCSection * getDwarfMacinfoSection() const
MCSection * getDwarfLocDWOSection() const
MCSection * getDwarfARangesSection() const
MCSection * getDwarfAccelObjCSection() const
MCSection * getDwarfLocSection() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
Streaming machine code generation interface.
Definition: MCStreamer.h:212
MCContext & getContext() const
Definition: MCStreamer.h:297
void emitRawText(const Twine &String)
If this file is backed by a assembly streamer, this dumps the specified string in the output ....
Target specific streamer interface.
Definition: MCStreamer.h:93
MCStreamer & getStreamer()
Definition: MCStreamer.h:101
virtual void emitRawBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:80
MCStreamer & Streamer
Definition: MCStreamer.h:95
Implments NVPTX-specific streamer.
void emitDwarfFileDirective(StringRef Directive) override
Record DWARF file directives for later output.
void changeSection(const MCSection *CurSection, MCSection *Section, const MCExpr *SubSection, raw_ostream &OS) override
Update streamer for a new active section.
void outputDwarfFileDirectives()
Outputs the list of the DWARF '.file' directives to the streamer.
void emitRawBytes(StringRef Data) override
Emit the bytes in Data into the output.
void closeLastSection()
Close last section.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:950
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:690
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18