File indexing completed on 2026-05-10 08:44:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_SUPPORT_COMPRESSION_H
0014 #define LLVM_SUPPORT_COMPRESSION_H
0015
0016 #include "llvm/ADT/ArrayRef.h"
0017 #include "llvm/Support/DataTypes.h"
0018
0019 namespace llvm {
0020 template <typename T> class SmallVectorImpl;
0021 class Error;
0022
0023
0024
0025
0026
0027 enum class DebugCompressionType {
0028 None,
0029 Zlib,
0030 Zstd,
0031 };
0032
0033 namespace compression {
0034 namespace zlib {
0035
0036 constexpr int NoCompression = 0;
0037 constexpr int BestSpeedCompression = 1;
0038 constexpr int DefaultCompression = 6;
0039 constexpr int BestSizeCompression = 9;
0040
0041 bool isAvailable();
0042
0043 void compress(ArrayRef<uint8_t> Input,
0044 SmallVectorImpl<uint8_t> &CompressedBuffer,
0045 int Level = DefaultCompression);
0046
0047 Error decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
0048 size_t &UncompressedSize);
0049
0050 Error decompress(ArrayRef<uint8_t> Input, SmallVectorImpl<uint8_t> &Output,
0051 size_t UncompressedSize);
0052
0053 }
0054
0055 namespace zstd {
0056
0057 constexpr int NoCompression = -5;
0058 constexpr int BestSpeedCompression = 1;
0059 constexpr int DefaultCompression = 5;
0060 constexpr int BestSizeCompression = 12;
0061
0062 bool isAvailable();
0063
0064 void compress(ArrayRef<uint8_t> Input,
0065 SmallVectorImpl<uint8_t> &CompressedBuffer,
0066 int Level = DefaultCompression, bool EnableLdm = false);
0067
0068 Error decompress(ArrayRef<uint8_t> Input, uint8_t *Output,
0069 size_t &UncompressedSize);
0070
0071 Error decompress(ArrayRef<uint8_t> Input, SmallVectorImpl<uint8_t> &Output,
0072 size_t UncompressedSize);
0073
0074 }
0075
0076 enum class Format {
0077 Zlib,
0078 Zstd,
0079 };
0080
0081 inline Format formatFor(DebugCompressionType Type) {
0082 switch (Type) {
0083 case DebugCompressionType::None:
0084 llvm_unreachable("not a compression type");
0085 case DebugCompressionType::Zlib:
0086 return Format::Zlib;
0087 case DebugCompressionType::Zstd:
0088 return Format::Zstd;
0089 }
0090 llvm_unreachable("");
0091 }
0092
0093 struct Params {
0094 constexpr Params(Format F)
0095 : format(F), level(F == Format::Zlib ? zlib::DefaultCompression
0096 : zstd::DefaultCompression) {}
0097 constexpr Params(Format F, int L, bool Ldm = false)
0098 : format(F), level(L), zstdEnableLdm(Ldm) {}
0099 Params(DebugCompressionType Type) : Params(formatFor(Type)) {}
0100
0101 Format format;
0102 int level;
0103 bool zstdEnableLdm = false;
0104
0105
0106
0107 };
0108
0109
0110
0111
0112 const char *getReasonIfUnsupported(Format F);
0113
0114
0115
0116 void compress(Params P, ArrayRef<uint8_t> Input,
0117 SmallVectorImpl<uint8_t> &Output);
0118
0119
0120 Error decompress(DebugCompressionType T, ArrayRef<uint8_t> Input,
0121 uint8_t *Output, size_t UncompressedSize);
0122 Error decompress(Format F, ArrayRef<uint8_t> Input,
0123 SmallVectorImpl<uint8_t> &Output, size_t UncompressedSize);
0124 Error decompress(DebugCompressionType T, ArrayRef<uint8_t> Input,
0125 SmallVectorImpl<uint8_t> &Output, size_t UncompressedSize);
0126
0127 }
0128
0129 }
0130
0131 #endif