diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DIE.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/MC/MCAsmStreamer.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/MC/MCStreamer.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp | 27 | ||||
-rw-r--r-- | llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h | 4 |
5 files changed, 52 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DIE.cpp b/llvm/lib/CodeGen/AsmPrinter/DIE.cpp index ca3a7506789..301fd9ef81b 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DIE.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DIE.cpp @@ -589,8 +589,7 @@ void DIEString::print(raw_ostream &O) const { //===----------------------------------------------------------------------===// void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const { if (Form == dwarf::DW_FORM_string) { - for (char ch : S) - AP->emitInt8(ch); + AP->OutStreamer->EmitBytes(S); AP->emitInt8(0); return; } diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index c4744ac5d51..f75a8e077e4 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -858,10 +858,14 @@ void MCAsmStreamer::EmitBytes(StringRef Data) { // supported, emit as vector of 8bits data. if (Data.size() == 1 || !(MAI->getAscizDirective() || MAI->getAsciiDirective())) { - const char *Directive = MAI->getData8bitsDirective(); - for (const unsigned char C : Data.bytes()) { - OS << Directive << (unsigned)C; - EmitEOL(); + if (MCTargetStreamer *TS = getTargetStreamer()) { + TS->emitRawBytes(Data); + } else { + const char *Directive = MAI->getData8bitsDirective(); + for (const unsigned char C : Data.bytes()) { + OS << Directive << (unsigned)C; + EmitEOL(); + } } return; } diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index bfcf6d47a78..1b704b89320 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -72,6 +72,18 @@ void MCTargetStreamer::emitValue(const MCExpr *Value) { Streamer.EmitRawText(OS.str()); } +void MCTargetStreamer::emitRawBytes(StringRef Data) { + const MCAsmInfo *MAI = Streamer.getContext().getAsmInfo(); + const char *Directive = MAI->getData8bitsDirective(); + for (const unsigned char C : Data.bytes()) { + SmallString<128> Str; + raw_svector_ostream OS(Str); + + OS << Directive << (unsigned)C; + Streamer.EmitRawText(OS.str()); + } +} + void MCTargetStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {} MCStreamer::MCStreamer(MCContext &Ctx) diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp index aeb90eca3a0..71ca7a5ca8d 100644 --- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp +++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp @@ -92,3 +92,30 @@ void NVPTXTargetStreamer::changeSection(const MCSection *CurSection, OS << "//\t{\n"; } } + +void NVPTXTargetStreamer::emitRawBytes(StringRef Data) { + 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()); + } +} + diff --git a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h index 30831ab8bbe..34391a8b9ab 100644 --- a/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h +++ b/llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h @@ -39,6 +39,10 @@ public: void emitDwarfFileDirective(StringRef Directive) override; void changeSection(const MCSection *CurSection, MCSection *Section, const MCExpr *SubSection, raw_ostream &OS) override; + /// Emit the bytes in \p Data into the output. + /// + /// This is used to emit bytes in \p Data as sequence of .byte directives. + void emitRawBytes(StringRef Data) override; }; } // end namespace llvm |