LLVM  16.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"
17 #include "llvm/Support/DataTypes.h"
18 
19 namespace llvm {
20 template <typename T> class SmallVectorImpl;
21 class Error;
22 
23 // None indicates no compression. The other members are a subset of
24 // compression::Format, which is used for compressed debug sections in some
25 // object file formats (e.g. ELF). This is a separate class as we may add new
26 // compression::Format members for non-debugging purposes.
28  None, ///< No compression
29  Zlib, ///< zlib
30  Zstd, ///< Zstandard
31 };
32 
33 namespace compression {
34 namespace zlib {
35 
36 constexpr int NoCompression = 0;
37 constexpr int BestSpeedCompression = 1;
38 constexpr int DefaultCompression = 6;
39 constexpr int BestSizeCompression = 9;
40 
41 bool isAvailable();
42 
43 void compress(ArrayRef<uint8_t> Input,
44  SmallVectorImpl<uint8_t> &CompressedBuffer,
45  int Level = DefaultCompression);
46 
47 Error decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
48  size_t &UncompressedSize);
49 
51  size_t UncompressedSize);
52 
53 } // End of namespace zlib
54 
55 namespace zstd {
56 
57 constexpr int NoCompression = -5;
58 constexpr int BestSpeedCompression = 1;
59 constexpr int DefaultCompression = 5;
60 constexpr int BestSizeCompression = 12;
61 
62 bool isAvailable();
63 
64 void compress(ArrayRef<uint8_t> Input,
65  SmallVectorImpl<uint8_t> &CompressedBuffer,
66  int Level = DefaultCompression);
67 
68 Error decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
69  size_t &UncompressedSize);
70 
72  size_t UncompressedSize);
73 
74 } // End of namespace zstd
75 
76 enum class Format {
77  Zlib,
78  Zstd,
79 };
80 
82  switch (Type) {
84  llvm_unreachable("not a compression type");
86  return Format::Zlib;
88  return Format::Zstd;
89  }
90  llvm_unreachable("");
91 }
92 
93 struct Params {
94  constexpr Params(Format F)
95  : format(F), level(F == Format::Zlib ? zlib::DefaultCompression
96  : zstd::DefaultCompression) {}
98 
100  int level;
101  // This may support multi-threading for zstd in the future. Note that
102  // different threads may produce different output, so be careful if certain
103  // output determinism is desired.
104 };
105 
106 // Return nullptr if LLVM was built with support (LLVM_ENABLE_ZLIB,
107 // LLVM_ENABLE_ZSTD) for the specified compression format; otherwise
108 // return a string literal describing the reason.
109 const char *getReasonIfUnsupported(Format F);
110 
111 // Compress Input with the specified format P.Format. If Level is -1, use
112 // *::DefaultCompression for the format.
113 void compress(Params P, ArrayRef<uint8_t> Input,
114  SmallVectorImpl<uint8_t> &Output);
115 
116 // Decompress Input. The uncompressed size must be available.
118  uint8_t *Output, size_t UncompressedSize);
120  SmallVectorImpl<uint8_t> &Output, size_t UncompressedSize);
122  SmallVectorImpl<uint8_t> &Output, size_t UncompressedSize);
123 
124 } // End of namespace compression
125 
126 } // End of namespace llvm
127 
128 #endif
llvm::compression::zlib::decompress
Error decompress(ArrayRef< uint8_t > Input, uint8_t *Output, size_t &UncompressedSize)
Definition: Compression.cpp:123
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::lltok::Error
@ Error
Definition: LLToken.h:21
llvm::compression::Params
Definition: Compression.h:93
llvm::compression::Format
Format
Definition: Compression.h:76
llvm::compression::zlib::BestSpeedCompression
constexpr int BestSpeedCompression
Definition: Compression.h:37
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::compression::Params::level
int level
Definition: Compression.h:100
llvm::compression::zstd::DefaultCompression
constexpr int DefaultCompression
Definition: Compression.h:59
llvm::compression::zstd::BestSpeedCompression
constexpr int BestSpeedCompression
Definition: Compression.h:58
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::compression::zlib::NoCompression
constexpr int NoCompression
Definition: Compression.h:36
llvm::compression::Params::Params
constexpr Params(Format F)
Definition: Compression.h:94
llvm::DebugCompressionType::Zstd
@ Zstd
Zstandard.
llvm::compression::zlib::BestSizeCompression
constexpr int BestSizeCompression
Definition: Compression.h:39
llvm::compression::Params::format
Format format
Definition: Compression.h:99
llvm::DebugCompressionType::None
@ None
No compression.
llvm::compression::zlib::isAvailable
bool isAvailable()
Definition: Compression.cpp:105
llvm::compression::zstd::BestSizeCompression
constexpr int BestSizeCompression
Definition: Compression.h:60
llvm::compression::zstd::decompress
Error decompress(ArrayRef< uint8_t > Input, uint8_t *Output, size_t &UncompressedSize)
Definition: Compression.cpp:211
llvm::compression::zstd::NoCompression
constexpr int NoCompression
Definition: Compression.h:57
ArrayRef.h
llvm::compression::Params::Params
Params(DebugCompressionType Type)
Definition: Compression.h:97
llvm::ArrayRef< uint8_t >
llvm::DebugCompressionType
DebugCompressionType
Definition: Compression.h:27
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::compression::zstd::compress
void compress(ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &CompressedBuffer, int Level=DefaultCompression)
Definition: Compression.cpp:207
llvm::compression::compress
void compress(Params P, ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &Output)
Definition: Compression.cpp:46
llvm::DebugCompressionType::Zlib
@ Zlib
zlib
llvm::compression::zstd::isAvailable
bool isAvailable()
Definition: Compression.cpp:206
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::compression::zlib::compress
void compress(ArrayRef< uint8_t > Input, SmallVectorImpl< uint8_t > &CompressedBuffer, int Level=DefaultCompression)
Definition: Compression.cpp:107
llvm::compression::getReasonIfUnsupported
const char * getReasonIfUnsupported(Format F)
Definition: Compression.cpp:30
llvm::compression::formatFor
Format formatFor(DebugCompressionType Type)
Definition: Compression.h:81
llvm::SmallVectorImpl< uint8_t >
DataTypes.h
llvm::compression::Format::Zlib
@ Zlib
llvm::compression::zlib::DefaultCompression
constexpr int DefaultCompression
Definition: Compression.h:38
llvm::compression::decompress
Error decompress(DebugCompressionType T, ArrayRef< uint8_t > Input, uint8_t *Output, size_t UncompressedSize)
Definition: Compression.cpp:58
llvm::compression::Format::Zstd
@ Zstd