Skip to content

Commit d65e7a5

Browse files
Use zlib compression on DIEDistinctData
(cherry picked from commit 582282a)
1 parent 1312409 commit d65e7a5

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

llvm/lib/MCCAS/MCCASObjectV1.cpp

Lines changed: 23 additions & 6 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>
@@ -1893,7 +1894,13 @@ struct DIEDataWriter : public DataWriter {
18931894
/// is described by some DIEAbbrevRef block.
18941895
struct DistinctDataWriter : public DataWriter {
18951896
Expected<DIEDistinctDataRef> getCASNode(MCCASBuilder &CASBuilder) {
1896-
return DIEDistinctDataRef::create(CASBuilder, toStringRef(Data));
1897+
SmallVector<uint8_t> CompressedBuff;
1898+
compression::zlib::compress(arrayRefFromStringRef(toStringRef(Data)),
1899+
CompressedBuff);
1900+
// Reserve 8 bytes for ULEB to store the size of the uncompressed data.
1901+
CompressedBuff.append(8, 0);
1902+
encodeULEB128(Data.size(), CompressedBuff.end() - 8, 8 /*Pad to*/);
1903+
return DIEDistinctDataRef::create(CASBuilder, toStringRef(CompressedBuff));
18971904
}
18981905
};
18991906

@@ -3401,7 +3408,16 @@ Error mccasformats::v1::visitDebugInfo(
34013408
return LoadedTopRef.takeError();
34023409

34033410
StringRef DistinctData = LoadedTopRef->DistinctData.getData();
3404-
BinaryStreamReader DistinctReader(DistinctData, support::endianness::little);
3411+
ArrayRef<uint8_t> BuffRef = arrayRefFromStringRef(DistinctData);
3412+
auto UncompressedSize = decodeULEB128(BuffRef.data() + BuffRef.size() - 8);
3413+
BuffRef = BuffRef.drop_back(8);
3414+
SmallVector<uint8_t> OutBuff;
3415+
if (auto E =
3416+
compression::zlib::decompress(BuffRef, OutBuff, UncompressedSize))
3417+
return E;
3418+
auto UncompressedDistinctData = toStringRef(OutBuff);
3419+
BinaryStreamReader DistinctReader(UncompressedDistinctData,
3420+
support::endianness::little);
34053421
ArrayRef<char> HeaderData;
34063422

34073423
auto BeginOffset = DistinctReader.getOffset();
@@ -3423,8 +3439,9 @@ Error mccasformats::v1::visitDebugInfo(
34233439
HeaderCallback(toStringRef(HeaderData));
34243440

34253441
append_range(TotAbbrevEntries, LoadedTopRef->AbbrevEntries);
3426-
DIEVisitor Visitor{TotAbbrevEntries, DistinctReader, DistinctData,
3427-
HeaderCallback, StartTagCallback, AttrCallback,
3428-
EndTagCallback, NewBlockCallback};
3442+
DIEVisitor Visitor{TotAbbrevEntries, DistinctReader,
3443+
UncompressedDistinctData, HeaderCallback,
3444+
StartTagCallback, AttrCallback,
3445+
EndTagCallback, NewBlockCallback};
34293446
return Visitor.visitDIERef(LoadedTopRef->RootDIE);
34303447
}

0 commit comments

Comments
 (0)