This is an archive of the discontinued LLVM Phabricator instance.

[Support] - Implemented zlib::StreamCompression class.
AbandonedPublic

Authored by grimar on Apr 11 2017, 8:54 AM.

Details

Summary

Patch introduces zlib streaming API. I am using it in LLD.
(https://reviews.llvm.org/D31941).

Patch implements only compression (no decompression),
because that is what I was need and has simple API that allows to feed compressor
object with chunks of data and get compressed result part by part from client.

Docs uded in implementation were:
http://zlib.net/zlib_how.html
http://zlib.net/manual.html

Diff Detail

Event Timeline

grimar updated this revision to Diff 94840.Apr 11 2017, 9:07 AM
  • Last minux fix for llvm_unreachable messages text.
dblaikie edited edge metadata.Apr 11 2017, 9:35 AM

Thanks for working on this - it'll be great to have streaming compression APIs for LLVM (& especially in llvm-dwp - it could use streaming compression (& streaming decompression, but having one side's a great start/example!))

include/llvm/Support/Compression.h
60

It'd be tidier if this could be Expected<StreamCompression> instead (avoiding the unique_ptr indirection, etc) & helpful if the StreamCompression class was movable.

67

Should the OutFn be part of the StreamCompression object - rather than passed in for each chunk of compression?

67

Also "IsLastChunk" is probably a somewhat clunky API - might be nicer to have a separate "finalize" function for once all the chunks are done?

72

Would SmallVector be useful here?

unittests/Support/CompressionTest.cpp
82

No need for this variable - you should be able to pass 'In' directly as the ArrayRef parameter and rely on implicit conversion.

105–106

Rather than writing a for loop, can you test that the uncompressed data is equal to the original input data?

ruiu edited edge metadata.Apr 11 2017, 9:47 AM

I wonder why you want a streaming compression support to write compressed .debug sections. All you need is to call zlib's compress2 only once for each section, no?

grimar updated this revision to Diff 94981.Apr 12 2017, 9:03 AM

Thanks for review, David ! All comments addressed.

include/llvm/Support/Compression.h
60

Done.

67

Should the OutFn be part of the StreamCompression object - rather than passed in for each chunk of compression?

Yep, that simpler. Changed.

67

Also "IsLastChunk" is probably a somewhat clunky API - might be nicer to have a separate "finalize" function for once all the chunks are done?

Done.

72

I am not sure honestly. I would expect a few kilobytes output buffer size is reasonable, may be even more (I think about a megabyte for LLD use case). May be it is ok to have little buffer for some cases. Done.

unittests/Support/CompressionTest.cpp
82

Done.

105–106

Original input data is N input chunks in a row. So that anyways will be a loop here I think, I need to test N intervals.
I changed to test against input chunk instead of calculating value again.

grimar updated this revision to Diff 95091.Apr 13 2017, 2:52 AM
  • Updated stubs implementation for case when zlib was not available(defined) (update of signatures and names, code was not compilable in that case).
grimar abandoned this revision.Apr 18 2017, 6:41 AM

Was not used in LLD, abandoning for now.