LLVM 22.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 "NVPTXUtilities.h"
15#include "llvm/MC/MCAsmInfo.h"
16#include "llvm/MC/MCContext.h"
17#include "llvm/MC/MCExpr.h"
19#include "llvm/MC/MCSymbol.h"
21
22using namespace llvm;
23
24//
25// NVPTXTargetStreamer Implemenation
26//
29
33
35 for (const std::string &S : DwarfFiles)
37 DwarfFiles.clear();
38}
39
41 if (HasSections)
42 getStreamer().emitRawText("\t}");
43}
44
46 DwarfFiles.emplace_back(Directive);
47}
48
49static bool isDwarfSection(const MCObjectFileInfo *FI,
50 const MCSection *Section) {
51 // FIXME: the checks for the DWARF sections are very fragile and should be
52 // fixed up in a followup patch.
53 if (!Section || Section->isText())
54 return false;
55 return Section == FI->getDwarfAbbrevSection() ||
56 Section == FI->getDwarfInfoSection() ||
57 Section == FI->getDwarfMacinfoSection() ||
58 Section == FI->getDwarfFrameSection() ||
59 Section == FI->getDwarfAddrSection() ||
60 Section == FI->getDwarfRangesSection() ||
61 Section == FI->getDwarfARangesSection() ||
62 Section == FI->getDwarfLocSection() ||
63 Section == FI->getDwarfStrSection() ||
64 Section == FI->getDwarfLineSection() ||
65 Section == FI->getDwarfStrOffSection() ||
66 Section == FI->getDwarfLineStrSection() ||
67 Section == FI->getDwarfPubNamesSection() ||
68 Section == FI->getDwarfPubTypesSection() ||
69 Section == FI->getDwarfSwiftASTSection() ||
70 Section == FI->getDwarfTypesDWOSection() ||
71 Section == FI->getDwarfAbbrevDWOSection() ||
72 Section == FI->getDwarfAccelObjCSection() ||
73 Section == FI->getDwarfAccelNamesSection() ||
74 Section == FI->getDwarfAccelTypesSection() ||
75 Section == FI->getDwarfAccelNamespaceSection() ||
76 Section == FI->getDwarfLocDWOSection() ||
77 Section == FI->getDwarfStrDWOSection() ||
78 Section == FI->getDwarfCUIndexSection() ||
79 Section == FI->getDwarfInfoDWOSection() ||
80 Section == FI->getDwarfLineDWOSection() ||
81 Section == FI->getDwarfTUIndexSection() ||
82 Section == FI->getDwarfStrOffDWOSection() ||
83 Section == FI->getDwarfDebugNamesSection() ||
84 Section == FI->getDwarfDebugInlineSection() ||
85 Section == FI->getDwarfGnuPubNamesSection() ||
86 Section == FI->getDwarfGnuPubTypesSection();
87}
88
90 MCSection *Section, uint32_t SubSection,
91 raw_ostream &OS) {
92 assert(!SubSection && "SubSection is not null!");
94 // Emit closing brace for DWARF sections only.
95 if (isDwarfSection(FI, CurSection))
96 OS << "\t}\n";
97 if (isDwarfSection(FI, Section)) {
98 // Emit DWARF .file directives in the outermost scope.
100 OS << "\t.section\t" << Section->getName() << '\n';
101 // DWARF sections are enclosed into braces - emit the open one.
102 OS << "\t{\n";
103 HasSections = true;
104 }
105}
106
109 // TODO: enable this once the bug in the ptxas with the packed bytes is
110 // resolved. Currently, (it is confirmed by NVidia) it causes a crash in
111 // ptxas.
112#if 0
113 const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
114 const char *Directive = MAI->getData8bitsDirective();
115 unsigned NumElements = Data.size();
116 const unsigned MaxLen = 40;
117 unsigned NumChunks = 1 + ((NumElements - 1) / MaxLen);
118 // Split the very long directives into several parts if the limit is
119 // specified.
120 for (unsigned I = 0; I < NumChunks; ++I) {
123
124 const char *Label = Directive;
125 for (auto It = std::next(Data.bytes_begin(), I * MaxLen),
126 End = (I == NumChunks - 1)
127 ? Data.bytes_end()
128 : std::next(Data.bytes_begin(), (I + 1) * MaxLen);
129 It != End; ++It) {
130 OS << Label << (unsigned)*It;
131 if (Label == Directive)
132 Label = ",";
133 }
134 Streamer.emitRawText(OS.str());
135 }
136#endif
137}
138
140 if (Value->getKind() == MCExpr::SymbolRef) {
141 const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*Value);
142 StringRef SymName = SRE.getSymbol().getName();
143 if (!SymName.starts_with(".debug")) {
145 return;
146 }
147 // Fall through to the normal printing.
148 }
149 // Otherwise, print the Value normally.
151}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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)
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:64
const char * getData8bitsDirective() const
Definition: MCAsmInfo.h:461
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:416
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:412
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
@ SymbolRef
References to labels and assigned expressions.
Definition: MCExpr.h:43
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:496
Streaming machine code generation interface.
Definition: MCStreamer.h:220
MCContext & getContext() const
Definition: MCStreamer.h:314
void emitRawText(const Twine &String)
If this file is backed by a assembly streamer, this dumps the specified string in the output ....
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:190
const MCSymbol & getSymbol() const
Definition: MCExpr.h:227
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:188
Target specific streamer interface.
Definition: MCStreamer.h:93
virtual void emitValue(const MCExpr *Value)
Definition: MCStreamer.cpp:70
MCStreamer & getStreamer()
Definition: MCStreamer.h:101
virtual void emitRawBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:78
MCStreamer & Streamer
Definition: MCStreamer.h:95
Implments NVPTX-specific streamer.
void emitDwarfFileDirective(StringRef Directive) override
Record DWARF file directives for later output.
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 changeSection(const MCSection *CurSection, MCSection *Section, uint32_t SubSection, raw_ostream &OS) override
Update streamer for a new active section.
void emitValue(const MCExpr *Value) override
Makes sure that labels are mangled the same way as the actual symbols.
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:938
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:269
LLVM Value Representation.
Definition: Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:692
std::string getValidPTXIdentifier(StringRef Name)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18