diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2018-10-24 14:04:00 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2018-10-24 14:04:00 +0000 |
commit | c15c853c3a4bf16e6065ad326c7279d38dba57db (patch) | |
tree | 00b128d85f70ad558f733ae529175f53effbf059 /llvm/lib/Target/NVPTX | |
parent | e8437cbf5e9c41c27da6be13996963529c8ca1bf (diff) | |
download | bcm5719-llvm-c15c853c3a4bf16e6065ad326c7279d38dba57db.tar.gz bcm5719-llvm-c15c853c3a4bf16e6065ad326c7279d38dba57db.zip |
[DEBUGINFO, NVPTX] Try to pack bytes data into a single string.
Summary:
If the target does not support `.asciz` and `.ascii` directives, the
strings are represented as bytes and each byte is placed on the new line
as a separate byte directive `.b8 <data>`. NVPTX target allows to
represent the vector of the data of the same type as a vector, where
values are separated using `,` symbol: `.b8 <data1>,<data2>,...`. This
allows to reduce the size of the final PTX file. Ptxas tool includes ptx
files into the resulting binary object, so reducing the size of the PTX
file is important.
Reviewers: tra, jlebar, echristo
Subscribers: jholewinski, llvm-commits
Differential Revision: https://reviews.llvm.org/D45822
llvm-svn: 345142
Diffstat (limited to 'llvm/lib/Target/NVPTX')
-rw-r--r-- | llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.cpp | 27 | ||||
-rw-r--r-- | llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXTargetStreamer.h | 4 |
2 files changed, 31 insertions, 0 deletions
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 |