LLVM 22.0.0git
Compression.h
Go to the documentation of this file.
1//===-- llvm/Support/Compression.h ---Compression----------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains basic functions for compression/decompression.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_SUPPORT_COMPRESSION_H
14#define LLVM_SUPPORT_COMPRESSION_H
15
16#include "llvm/ADT/ArrayRef.h"
19
20namespace llvm {
21template <typename T> class SmallVectorImpl;
22class Error;
23
24// None indicates no compression. The other members are a subset of
25// compression::Format, which is used for compressed debug sections in some
26// object file formats (e.g. ELF). This is a separate class as we may add new
27// compression::Format members for non-debugging purposes.
29 None, ///< No compression
30 Zlib, ///< zlib
31 Zstd, ///< Zstandard
32};
33
34namespace compression {
35namespace zlib {
36
37constexpr int NoCompression = 0;
38constexpr int BestSpeedCompression = 1;
39constexpr int DefaultCompression = 6;
40constexpr int BestSizeCompression = 9;
41
43
45 SmallVectorImpl<uint8_t> &CompressedBuffer,
46 int Level = DefaultCompression);
47
49 size_t &UncompressedSize);
50
53 size_t UncompressedSize);
54
55} // End of namespace zlib
56
57namespace zstd {
58
59constexpr int NoCompression = -5;
60constexpr int BestSpeedCompression = 1;
61constexpr int DefaultCompression = 5;
62constexpr int BestSizeCompression = 12;
63
65
67 SmallVectorImpl<uint8_t> &CompressedBuffer,
68 int Level = DefaultCompression, bool EnableLdm = false);
69
71 size_t &UncompressedSize);
72
75 size_t UncompressedSize);
76
77} // End of namespace zstd
78
79enum class Format {
82};
83
85 switch (Type) {
87 llvm_unreachable("not a compression type");
89 return Format::Zlib;
91 return Format::Zstd;
92 }
94}
95
96struct Params {
97 constexpr Params(Format F)
98 : format(F), level(F == Format::Zlib ? zlib::DefaultCompression
99 : zstd::DefaultCompression) {}
100 constexpr Params(Format F, int L, bool Ldm = false)
101 : format(F), level(L), zstdEnableLdm(Ldm) {}
103
105 int level;
106 bool zstdEnableLdm = false; // Enable zstd long distance matching
107 // This may support multi-threading for zstd in the future. Note that
108 // different threads may produce different output, so be careful if certain
109 // output determinism is desired.
110};
111
112// Return nullptr if LLVM was built with support (LLVM_ENABLE_ZLIB,
113// LLVM_ENABLE_ZSTD) for the specified compression format; otherwise
114// return a string literal describing the reason.
116
117// Compress Input with the specified format P.Format. If Level is -1, use
118// *::DefaultCompression for the format.
121
122// Decompress Input. The uncompressed size must be available.
124 uint8_t *Output, size_t UncompressedSize);
127 size_t UncompressedSize);
130 size_t UncompressedSize);
131
132} // End of namespace compression
133
134} // End of namespace llvm
135
136#endif
#define LLVM_ABI
Definition Compiler.h:213
#define F(x, y, z)
Definition MD5.cpp:55
#define T
#define P(N)
The Input class is used to parse a yaml document into in-memory structs and vectors.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI void compress(ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &CompressedBuffer, int Level=DefaultCompression)
LLVM_ABI Error decompress(ArrayRef< uint8_t > Input, uint8_t *Output, size_t &UncompressedSize)
LLVM_ABI bool isAvailable()
constexpr int NoCompression
Definition Compression.h:37
constexpr int BestSizeCompression
Definition Compression.h:40
constexpr int DefaultCompression
Definition Compression.h:39
constexpr int BestSpeedCompression
Definition Compression.h:38
LLVM_ABI Error decompress(ArrayRef< uint8_t > Input, uint8_t *Output, size_t &UncompressedSize)
constexpr int NoCompression
Definition Compression.h:59
LLVM_ABI bool isAvailable()
LLVM_ABI void compress(ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &CompressedBuffer, int Level=DefaultCompression, bool EnableLdm=false)
constexpr int BestSpeedCompression
Definition Compression.h:60
constexpr int DefaultCompression
Definition Compression.h:61
constexpr int BestSizeCompression
Definition Compression.h:62
LLVM_ABI const char * getReasonIfUnsupported(Format F)
LLVM_ABI Error decompress(DebugCompressionType T, ArrayRef< uint8_t > Input, uint8_t *Output, size_t UncompressedSize)
Format formatFor(DebugCompressionType Type)
Definition Compression.h:84
LLVM_ABI void compress(Params P, ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &Output)
This is an optimization pass for GlobalISel generic memory operations.
DebugCompressionType
Definition Compression.h:28
@ None
No compression.
Definition Compression.h:29
Params(DebugCompressionType Type)
constexpr Params(Format F)
Definition Compression.h:97
constexpr Params(Format F, int L, bool Ldm=false)