Skip to content

Commit d3c9a79

Browse files
committed
Change Offloading API to require a output stream to be passed for decompress/compress.
Default the output stream to errs().
1 parent 856bb01 commit d3c9a79

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

llvm/include/llvm/Object/OffloadBundle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class CompressedOffloadBundle {
6363

6464
static llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
6565
compress(llvm::compression::Params P, const llvm::MemoryBuffer &Input,
66-
uint16_t Version, bool Verbose = false);
66+
uint16_t Version, bool Verbose = false, raw_ostream &OutS = errs());
6767
static llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
68-
decompress(const llvm::MemoryBuffer &Input, bool Verbose = false);
68+
decompress(const llvm::MemoryBuffer &Input, bool Verbose = false, raw_ostream &OS = errs());
6969
};
7070

7171
/// Bundle entry in binary clang-offload-bundler format.

llvm/lib/Object/OffloadBundle.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Error extractOffloadBundle(MemoryBufferRef Contents, uint64_t SectionOffset,
6262
return createFileError(FileName, EC);
6363

6464
Expected<std::unique_ptr<MemoryBuffer>> DecompressedBufferOrErr =
65-
CompressedOffloadBundle::decompress(**CodeOrErr, false);
65+
CompressedOffloadBundle::decompress(**CodeOrErr, false, errs());
6666
if (!DecompressedBufferOrErr)
6767
return createStringError(
6868
inconvertibleErrorCode(),
@@ -297,7 +297,7 @@ static std::string formatWithCommas(unsigned long long Value) {
297297
Expected<std::unique_ptr<MemoryBuffer>>
298298
CompressedOffloadBundle::compress(compression::Params P,
299299
const MemoryBuffer &Input, uint16_t Version,
300-
bool Verbose) {
300+
bool Verbose, raw_ostream &OutS) {
301301
if (!compression::zstd::isAvailable() && !compression::zlib::isAvailable())
302302
return createStringError("compression not supported.");
303303
Timer HashTimer("Hash Calculation Timer", "Hash calculation time",
@@ -385,7 +385,7 @@ CompressedOffloadBundle::compress(compression::Params P,
385385
double CompressionTimeSeconds = CompressTimer.getTotalTime().getWallTime();
386386
double CompressionSpeedMBs =
387387
(UncompressedSize64 / (1024.0 * 1024.0)) / CompressionTimeSeconds;
388-
errs() << "Compressed bundle format version: " << Version << "\n"
388+
OutS << "Compressed bundle format version: " << Version << "\n"
389389
<< "Total file size (including headers): "
390390
<< formatWithCommas(TotalFileSize64) << " bytes\n"
391391
<< "Compression method used: " << MethodUsed << "\n"
@@ -510,7 +510,7 @@ CompressedOffloadBundle::CompressedBundleHeader::tryParse(StringRef Blob) {
510510
}
511511

512512
Expected<std::unique_ptr<MemoryBuffer>>
513-
CompressedOffloadBundle::decompress(const MemoryBuffer &Input, bool Verbose) {
513+
CompressedOffloadBundle::decompress(const MemoryBuffer &Input, bool Verbose, raw_ostream &OS) {
514514
StringRef Blob = Input.getBuffer();
515515

516516
// Check minimum header size (using V1 as it's the smallest).
@@ -519,7 +519,7 @@ CompressedOffloadBundle::decompress(const MemoryBuffer &Input, bool Verbose) {
519519

520520
if (identify_magic(Blob) != file_magic::offload_bundle_compressed) {
521521
if (Verbose)
522-
errs() << "Uncompressed bundle\n";
522+
OS << "Uncompressed bundle\n";
523523
return MemoryBuffer::getMemBufferCopy(Blob);
524524
}
525525

@@ -577,11 +577,11 @@ CompressedOffloadBundle::decompress(const MemoryBuffer &Input, bool Verbose) {
577577
double DecompressionSpeedMBs =
578578
(UncompressedSize / (1024.0 * 1024.0)) / DecompressionTimeSeconds;
579579

580-
errs() << "Compressed bundle format version: " << ThisVersion << "\n";
580+
OS << "Compressed bundle format version: " << ThisVersion << "\n";
581581
if (ThisVersion >= 2)
582-
errs() << "Total file size (from header): "
582+
OS << "Total file size (from header): "
583583
<< formatWithCommas(TotalFileSize) << " bytes\n";
584-
errs() << "Decompression method: "
584+
OS << "Decompression method: "
585585
<< (CompressionFormat == compression::Format::Zlib ? "zlib" : "zstd")
586586
<< "\n"
587587
<< "Size before decompression: "

0 commit comments

Comments
 (0)