Skip to content

Commit 7702cfd

Browse files
Merge pull request swiftlang#7847 from rastogishubham/Compression
Use zlib compression in DIEDistinctData block to reduce size of distinct data in the debug info representation of MCCAS
2 parents 09b24c2 + 582282a commit 7702cfd

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>
@@ -1900,7 +1901,13 @@ struct DIEDataWriter : public DataWriter {
19001901
/// is described by some DIEAbbrevRef block.
19011902
struct DistinctDataWriter : public DataWriter {
19021903
Expected<DIEDistinctDataRef> getCASNode(MCCASBuilder &CASBuilder) {
1903-
return DIEDistinctDataRef::create(CASBuilder, toStringRef(Data));
1904+
SmallVector<uint8_t> CompressedBuff;
1905+
compression::zlib::compress(arrayRefFromStringRef(toStringRef(Data)),
1906+
CompressedBuff);
1907+
// Reserve 8 bytes for ULEB to store the size of the uncompressed data.
1908+
CompressedBuff.append(8, 0);
1909+
encodeULEB128(Data.size(), CompressedBuff.end() - 8, 8 /*Pad to*/);
1910+
return DIEDistinctDataRef::create(CASBuilder, toStringRef(CompressedBuff));
19041911
}
19051912
};
19061913

@@ -3413,7 +3420,16 @@ Error mccasformats::v1::visitDebugInfo(
34133420
return LoadedTopRef.takeError();
34143421

34153422
StringRef DistinctData = LoadedTopRef->DistinctData.getData();
3416-
BinaryStreamReader DistinctReader(DistinctData, endianness::little);
3423+
ArrayRef<uint8_t> BuffRef = arrayRefFromStringRef(DistinctData);
3424+
auto UncompressedSize = decodeULEB128(BuffRef.data() + BuffRef.size() - 8);
3425+
BuffRef = BuffRef.drop_back(8);
3426+
SmallVector<uint8_t> OutBuff;
3427+
if (auto E =
3428+
compression::zlib::decompress(BuffRef, OutBuff, UncompressedSize))
3429+
return E;
3430+
auto UncompressedDistinctData = toStringRef(OutBuff);
3431+
BinaryStreamReader DistinctReader(UncompressedDistinctData,
3432+
endianness::little);
34173433
ArrayRef<char> HeaderData;
34183434

34193435
auto BeginOffset = DistinctReader.getOffset();
@@ -3435,7 +3451,7 @@ Error mccasformats::v1::visitDebugInfo(
34353451
HeaderCallback(toStringRef(HeaderData));
34363452

34373453
append_range(TotAbbrevEntries, LoadedTopRef->AbbrevEntries);
3438-
DIEVisitor Visitor{TotAbbrevEntries, DistinctReader, DistinctData,
3454+
DIEVisitor Visitor{TotAbbrevEntries, DistinctReader, UncompressedDistinctData,
34393455
HeaderCallback, StartTagCallback, AttrCallback,
34403456
EndTagCallback, NewBlockCallback};
34413457
return Visitor.visitDIERef(LoadedTopRef->RootDIE);

0 commit comments

Comments
 (0)