1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
//=====- NVPTXTargetStreamer.cpp - NVPTXTargetStreamer class ------------=====//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements the NVPTXTargetStreamer class.
//
//===----------------------------------------------------------------------===//
#include "NVPTXTargetStreamer.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCObjectFileInfo.h"
using namespace llvm;
//
// NVPTXTargetStreamer Implemenation
//
NVPTXTargetStreamer::NVPTXTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
NVPTXTargetStreamer::~NVPTXTargetStreamer() = default;
NVPTXAsmTargetStreamer::NVPTXAsmTargetStreamer(MCStreamer &S)
: NVPTXTargetStreamer(S) {}
NVPTXAsmTargetStreamer::~NVPTXAsmTargetStreamer() = default;
void NVPTXTargetStreamer::outputDwarfFileDirectives() {
for (const std::string &S : DwarfFiles)
getStreamer().emitRawText(S);
DwarfFiles.clear();
}
void NVPTXTargetStreamer::closeLastSection() {
if (HasSections)
getStreamer().emitRawText("\t}");
}
void NVPTXTargetStreamer::emitDwarfFileDirective(StringRef Directive) {
DwarfFiles.emplace_back(Directive);
}
static bool isDwarfSection(const MCObjectFileInfo *FI,
const MCSection *Section) {
// FIXME: the checks for the DWARF sections are very fragile and should be
// fixed up in a followup patch.
if (!Section || Section->getKind().isText() ||
Section->getKind().isWriteable())
return false;
return Section == FI->getDwarfAbbrevSection() ||
Section == FI->getDwarfInfoSection() ||
Section == FI->getDwarfMacinfoSection() ||
Section == FI->getDwarfFrameSection() ||
Section == FI->getDwarfAddrSection() ||
Section == FI->getDwarfRangesSection() ||
Section == FI->getDwarfARangesSection() ||
Section == FI->getDwarfLocSection() ||
Section == FI->getDwarfStrSection() ||
Section == FI->getDwarfLineSection() ||
Section == FI->getDwarfStrOffSection() ||
Section == FI->getDwarfLineStrSection() ||
Section == FI->getDwarfPubNamesSection() ||
Section == FI->getDwarfPubTypesSection() ||
Section == FI->getDwarfSwiftASTSection() ||
Section == FI->getDwarfTypesDWOSection() ||
Section == FI->getDwarfAbbrevDWOSection() ||
Section == FI->getDwarfAccelObjCSection() ||
Section == FI->getDwarfAccelNamesSection() ||
Section == FI->getDwarfAccelTypesSection() ||
Section == FI->getDwarfAccelNamespaceSection() ||
Section == FI->getDwarfLocDWOSection() ||
Section == FI->getDwarfStrDWOSection() ||
Section == FI->getDwarfCUIndexSection() ||
Section == FI->getDwarfInfoDWOSection() ||
Section == FI->getDwarfLineDWOSection() ||
Section == FI->getDwarfTUIndexSection() ||
Section == FI->getDwarfStrOffDWOSection() ||
Section == FI->getDwarfDebugNamesSection() ||
Section == FI->getDwarfDebugInlineSection() ||
Section == FI->getDwarfGnuPubNamesSection() ||
Section == FI->getDwarfGnuPubTypesSection();
}
void NVPTXTargetStreamer::changeSection(const MCSection *CurSection,
MCSection *Section,
const MCExpr *SubSection,
raw_ostream &OS) {
assert(!SubSection && "SubSection is not null!");
const MCObjectFileInfo *FI = getStreamer().getContext().getObjectFileInfo();
// Emit closing brace for DWARF sections only.
if (isDwarfSection(FI, CurSection))
OS << "\t}\n";
if (isDwarfSection(FI, Section)) {
// Emit DWARF .file directives in the outermost scope.
outputDwarfFileDirectives();
OS << "\t.section";
Section->printSwitchToSection(*getStreamer().getContext().getAsmInfo(),
getStreamer().getContext().getTargetTriple(),
OS, SubSection);
// DWARF sections are enclosed into braces - emit the open one.
OS << "\t{\n";
HasSections = true;
}
}
void NVPTXTargetStreamer::emitRawBytes(StringRef Data) {
MCTargetStreamer::emitRawBytes(Data);
// TODO: enable this once the bug in the ptxas with the packed bytes is
// resolved. Currently, (it is confirmed by NVidia) it causes a crash in
// ptxas.
#if 0
const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo();
const char *Directive = MAI->getData8bitsDirective();
unsigned NumElements = Data.size();
const unsigned MaxLen = 40;
unsigned NumChunks = 1 + ((NumElements - 1) / MaxLen);
// Split the very long directives into several parts if the limit is
// specified.
for (unsigned I = 0; I < NumChunks; ++I) {
SmallString<128> Str;
raw_svector_ostream OS(Str);
const char *Label = Directive;
for (auto It = std::next(Data.bytes_begin(), I * MaxLen),
End = (I == NumChunks - 1)
? Data.bytes_end()
: std::next(Data.bytes_begin(), (I + 1) * MaxLen);
It != End; ++It) {
OS << Label << (unsigned)*It;
if (Label == Directive)
Label = ",";
}
Streamer.emitRawText(OS.str());
}
#endif
}
|