Skip to content

Commit 582282a

Browse files
Use zlib compression on DIEDistinctData
1 parent a0fea2b commit 582282a

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
1717
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
1818
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
19-
#include "llvm/MCCAS/MCCASDebugV1.h"
2019
#include "llvm/MC/MCAsmBackend.h"
2120
#include "llvm/MC/MCContext.h"
2221
#include "llvm/MC/MCObjectFileInfo.h"
22+
#include "llvm/MCCAS/MCCASDebugV1.h"
2323
#include "llvm/Support/BinaryStreamWriter.h"
24+
#include "llvm/Support/Compression.h"
2425
#include "llvm/Support/Endian.h"
2526
#include "llvm/Support/EndianStream.h"
2627
#include <memory>
@@ -1905,7 +1906,13 @@ struct DIEDataWriter : public DataWriter {
19051906
/// is described by some DIEAbbrevRef block.
19061907
struct DistinctDataWriter : public DataWriter {
19071908
Expected<DIEDistinctDataRef> getCASNode(MCCASBuilder &CASBuilder) {
1908-
return DIEDistinctDataRef::create(CASBuilder, toStringRef(Data));
1909+
SmallVector<uint8_t> CompressedBuff;
1910+
compression::zlib::compress(arrayRefFromStringRef(toStringRef(Data)),
1911+
CompressedBuff);
1912+
// Reserve 8 bytes for ULEB to store the size of the uncompressed data.
1913+
CompressedBuff.append(8, 0);
1914+
encodeULEB128(Data.size(), CompressedBuff.end() - 8, 8 /*Pad to*/);
1915+
return DIEDistinctDataRef::create(CASBuilder, toStringRef(CompressedBuff));
19091916
}
19101917
};
19111918

@@ -3243,7 +3250,16 @@ Error mccasformats::v1::visitDebugInfo(
32433250
return LoadedTopRef.takeError();
32443251

32453252
StringRef DistinctData = LoadedTopRef->DistinctData.getData();
3246-
BinaryStreamReader DistinctReader(DistinctData, endianness::little);
3253+
ArrayRef<uint8_t> BuffRef = arrayRefFromStringRef(DistinctData);
3254+
auto UncompressedSize = decodeULEB128(BuffRef.data() + BuffRef.size() - 8);
3255+
BuffRef = BuffRef.drop_back(8);
3256+
SmallVector<uint8_t> OutBuff;
3257+
if (auto E =
3258+
compression::zlib::decompress(BuffRef, OutBuff, UncompressedSize))
3259+
return E;
3260+
auto UncompressedDistinctData = toStringRef(OutBuff);
3261+
BinaryStreamReader DistinctReader(UncompressedDistinctData,
3262+
endianness::little);
32473263
ArrayRef<char> HeaderData;
32483264

32493265
auto BeginOffset = DistinctReader.getOffset();
@@ -3265,7 +3281,7 @@ Error mccasformats::v1::visitDebugInfo(
32653281
HeaderCallback(toStringRef(HeaderData));
32663282

32673283
append_range(TotAbbrevEntries, LoadedTopRef->AbbrevEntries);
3268-
DIEVisitor Visitor{TotAbbrevEntries, DistinctReader, DistinctData,
3284+
DIEVisitor Visitor{TotAbbrevEntries, DistinctReader, UncompressedDistinctData,
32693285
HeaderCallback, StartTagCallback, AttrCallback,
32703286
EndTagCallback, NewBlockCallback};
32713287
return Visitor.visitDIERef(LoadedTopRef->RootDIE);

0 commit comments

Comments
 (0)