[clang] [llvm] [HIP] change compress level (PR #83605)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 1 10:30:58 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Yaxun (Sam) Liu (yxsamliu)
<details>
<summary>Changes</summary>
Change compression level to 20 for zstd better
compression rate.
---
Full diff: https://github.com/llvm/llvm-project/pull/83605.diff
4 Files Affected:
- (modified) clang/lib/Driver/OffloadBundler.cpp (+12-4)
- (modified) clang/test/Driver/clang-offload-bundler-zlib.c (+3-2)
- (modified) clang/test/Driver/clang-offload-bundler-zstd.c (+2-1)
- (modified) llvm/include/llvm/Support/Compression.h (+2)
``````````diff
diff --git a/clang/lib/Driver/OffloadBundler.cpp b/clang/lib/Driver/OffloadBundler.cpp
index 99a34d25cfcd56..ef48b2f33d3783 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -942,12 +942,19 @@ CompressedOffloadBundle::compress(const llvm::MemoryBuffer &Input,
Input.getBuffer().size());
llvm::compression::Format CompressionFormat;
+ int Level;
- if (llvm::compression::zstd::isAvailable())
+ if (llvm::compression::zstd::isAvailable()) {
CompressionFormat = llvm::compression::Format::Zstd;
- else if (llvm::compression::zlib::isAvailable())
+ // Use a high zstd compress level by default for better size reduction.
+ const int DefaultZstdLevel = 20;
+ Level = DefaultZstdLevel;
+ } else if (llvm::compression::zlib::isAvailable()) {
CompressionFormat = llvm::compression::Format::Zlib;
- else
+ // Use default level for zlib since higher level does not have significant
+ // improvement.
+ Level = llvm::compression::zlib::DefaultCompression;
+ } else
return createStringError(llvm::inconvertibleErrorCode(),
"Compression not supported");
@@ -955,7 +962,7 @@ CompressedOffloadBundle::compress(const llvm::MemoryBuffer &Input,
ClangOffloadBundlerTimerGroup);
if (Verbose)
CompressTimer.startTimer();
- llvm::compression::compress(CompressionFormat, BufferUint8, CompressedBuffer);
+ llvm::compression::compress({CompressionFormat, Level}, BufferUint8, CompressedBuffer);
if (Verbose)
CompressTimer.stopTimer();
@@ -980,6 +987,7 @@ CompressedOffloadBundle::compress(const llvm::MemoryBuffer &Input,
CompressionFormat == llvm::compression::Format::Zstd ? "zstd" : "zlib";
llvm::errs() << "Compressed bundle format version: " << Version << "\n"
<< "Compression method used: " << MethodUsed << "\n"
+ << "Compression level: " << Level << "\n"
<< "Binary size before compression: " << UncompressedSize
<< " bytes\n"
<< "Binary size after compression: " << CompressedBuffer.size()
diff --git a/clang/test/Driver/clang-offload-bundler-zlib.c b/clang/test/Driver/clang-offload-bundler-zlib.c
index a57ee6da9a86a6..aed3a03d5341b5 100644
--- a/clang/test/Driver/clang-offload-bundler-zlib.c
+++ b/clang/test/Driver/clang-offload-bundler-zlib.c
@@ -1,4 +1,4 @@
-// REQUIRES: zlib
+// REQUIRES: zlib && !zstd
// REQUIRES: x86-registered-target
// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
@@ -34,7 +34,8 @@
// RUN: diff %t.tgt2 %t.res.tgt2
//
-// COMPRESS: Compression method used:
+// COMPRESS: Compression method used: zlib
+// COMPRESS: Compression level: 9
// DECOMPRESS: Decompression method:
// NOHOST-NOT: host-
// NOHOST-DAG: hip-amdgcn-amd-amdhsa--gfx900
diff --git a/clang/test/Driver/clang-offload-bundler-zstd.c b/clang/test/Driver/clang-offload-bundler-zstd.c
index 3b577d4d166a3f..200634e05fa145 100644
--- a/clang/test/Driver/clang-offload-bundler-zstd.c
+++ b/clang/test/Driver/clang-offload-bundler-zstd.c
@@ -31,7 +31,8 @@
// RUN: diff %t.tgt1 %t.res.tgt1
// RUN: diff %t.tgt2 %t.res.tgt2
//
-// COMPRESS: Compression method used
+// COMPRESS: Compression method used: zstd
+// COMPRESS: Compression level: 20
// DECOMPRESS: Decompression method
// NOHOST-NOT: host-
// NOHOST-DAG: hip-amdgcn-amd-amdhsa--gfx900
diff --git a/llvm/include/llvm/Support/Compression.h b/llvm/include/llvm/Support/Compression.h
index c3ba3274d6ed87..9c9c3e2cc4a6c0 100644
--- a/llvm/include/llvm/Support/Compression.h
+++ b/llvm/include/llvm/Support/Compression.h
@@ -94,6 +94,8 @@ struct Params {
constexpr Params(Format F)
: format(F), level(F == Format::Zlib ? zlib::DefaultCompression
: zstd::DefaultCompression) {}
+ constexpr Params(Format F, int L)
+ : format(F), level(L) {}
Params(DebugCompressionType Type) : Params(formatFor(Type)) {}
Format format;
``````````
</details>
https://github.com/llvm/llvm-project/pull/83605
More information about the cfe-commits
mailing list