diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2022-07-14 18:50:02 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2022-07-14 18:50:02 +0000 |
| commit | 1f917f69ff07f09b6dbb670971f57f8efe718b84 (patch) | |
| tree | 99293cbc1411737cd995dac10a99b2c40ef0944c /llvm/lib/ProfileData | |
| parent | 145449b1e420787bb99721a429341fa6be3adfb6 (diff) | |
Diffstat (limited to 'llvm/lib/ProfileData')
| -rw-r--r-- | llvm/lib/ProfileData/Coverage/CoverageMapping.cpp | 6 | ||||
| -rw-r--r-- | llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp | 12 | ||||
| -rw-r--r-- | llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp | 12 | ||||
| -rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 32 | ||||
| -rw-r--r-- | llvm/lib/ProfileData/SampleProf.cpp | 6 | ||||
| -rw-r--r-- | llvm/lib/ProfileData/SampleProfReader.cpp | 10 | ||||
| -rw-r--r-- | llvm/lib/ProfileData/SampleProfWriter.cpp | 11 |
7 files changed, 41 insertions, 48 deletions
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp index f9e58fd6afa5..f4f13bafb233 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp @@ -25,7 +25,6 @@ #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> @@ -897,10 +896,9 @@ std::string CoverageMapError::message() const { return getCoverageMapErrString(Err); } -static ManagedStatic<CoverageMappingErrorCategoryType> ErrorCategory; - const std::error_category &llvm::coverage::coveragemap_category() { - return *ErrorCategory; + static CoverageMappingErrorCategoryType ErrorCategory; + return ErrorCategory; } char CoverageMapError::ID = 0; diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp index 1a187795a8a0..552140a52ad4 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp @@ -119,26 +119,26 @@ Error RawCoverageFilenamesReader::read(CovMapVersion Version) { return Err; if (CompressedLen > 0) { - if (!zlib::isAvailable()) + if (!compression::zlib::isAvailable()) return make_error<CoverageMapError>( coveragemap_error::decompression_failed); // Allocate memory for the decompressed filenames. - SmallVector<char, 0> StorageBuf; + SmallVector<uint8_t, 0> StorageBuf; // Read compressed filenames. StringRef CompressedFilenames = Data.substr(0, CompressedLen); Data = Data.substr(CompressedLen); - auto Err = - zlib::uncompress(CompressedFilenames, StorageBuf, UncompressedLen); + auto Err = compression::zlib::uncompress( + arrayRefFromStringRef(CompressedFilenames), StorageBuf, + UncompressedLen); if (Err) { consumeError(std::move(Err)); return make_error<CoverageMapError>( coveragemap_error::decompression_failed); } - StringRef UncompressedFilenames(StorageBuf.data(), StorageBuf.size()); - RawCoverageFilenamesReader Delegate(UncompressedFilenames, Filenames, + RawCoverageFilenamesReader Delegate(toStringRef(StorageBuf), Filenames, CompilationDir); return Delegate.readUncompressed(Version, NumFilenames); } diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp index 781a2901dbb9..db9be34d5248 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp @@ -46,11 +46,13 @@ void CoverageFilenamesSectionWriter::write(raw_ostream &OS, bool Compress) { } } - SmallString<128> CompressedStr; - bool doCompression = - Compress && zlib::isAvailable() && DoInstrProfNameCompression; + SmallVector<uint8_t, 128> CompressedStr; + bool doCompression = Compress && compression::zlib::isAvailable() && + DoInstrProfNameCompression; if (doCompression) - zlib::compress(FilenamesStr, CompressedStr, zlib::BestSizeCompression); + compression::zlib::compress(arrayRefFromStringRef(FilenamesStr), + CompressedStr, + compression::zlib::BestSizeCompression); // ::= <num-filenames> // <uncompressed-len> @@ -59,7 +61,7 @@ void CoverageFilenamesSectionWriter::write(raw_ostream &OS, bool Compress) { encodeULEB128(Filenames.size(), OS); encodeULEB128(FilenamesStr.size(), OS); encodeULEB128(doCompression ? CompressedStr.size() : 0U, OS); - OS << (doCompression ? CompressedStr.str() : StringRef(FilenamesStr)); + OS << (doCompression ? toStringRef(CompressedStr) : StringRef(FilenamesStr)); } namespace { diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index 48ac5ce0d607..f8d7c4d36481 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -39,7 +39,6 @@ #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/LEB128.h" -#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/Path.h" #include "llvm/Support/SwapByteOrder.h" @@ -177,10 +176,9 @@ class InstrProfErrorCategoryType : public std::error_category { } // end anonymous namespace -static ManagedStatic<InstrProfErrorCategoryType> ErrorCategory; - const std::error_category &llvm::instrprof_category() { - return *ErrorCategory; + static InstrProfErrorCategoryType ErrorCategory; + return ErrorCategory; } namespace { @@ -466,12 +464,13 @@ Error collectPGOFuncNameStrings(ArrayRef<std::string> NameStrs, return WriteStringToResult(0, UncompressedNameStrings); } - SmallString<128> CompressedNameStrings; - zlib::compress(StringRef(UncompressedNameStrings), CompressedNameStrings, - zlib::BestSizeCompression); + SmallVector<uint8_t, 128> CompressedNameStrings; + compression::zlib::compress(arrayRefFromStringRef(UncompressedNameStrings), + CompressedNameStrings, + compression::zlib::BestSizeCompression); return WriteStringToResult(CompressedNameStrings.size(), - CompressedNameStrings); + toStringRef(CompressedNameStrings)); } StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar) { @@ -488,7 +487,7 @@ Error collectPGOFuncNameStrings(ArrayRef<GlobalVariable *> NameVars, NameStrs.push_back(std::string(getPGOFuncNameVarInitializer(NameVar))); } return collectPGOFuncNameStrings( - NameStrs, zlib::isAvailable() && doCompression, Result); + NameStrs, compression::zlib::isAvailable() && doCompression, Result); } Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) { @@ -501,23 +500,20 @@ Error readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) { uint64_t CompressedSize = decodeULEB128(P, &N); P += N; bool isCompressed = (CompressedSize != 0); - SmallString<128> UncompressedNameStrings; + SmallVector<uint8_t, 128> UncompressedNameStrings; StringRef NameStrings; if (isCompressed) { - if (!llvm::zlib::isAvailable()) + if (!llvm::compression::zlib::isAvailable()) return make_error<InstrProfError>(instrprof_error::zlib_unavailable); - StringRef CompressedNameStrings(reinterpret_cast<const char *>(P), - CompressedSize); - if (Error E = - zlib::uncompress(CompressedNameStrings, UncompressedNameStrings, - UncompressedSize)) { + if (Error E = compression::zlib::uncompress( + makeArrayRef(P, CompressedSize), UncompressedNameStrings, + UncompressedSize)) { consumeError(std::move(E)); return make_error<InstrProfError>(instrprof_error::uncompress_failed); } P += CompressedSize; - NameStrings = StringRef(UncompressedNameStrings.data(), - UncompressedNameStrings.size()); + NameStrings = toStringRef(UncompressedNameStrings); } else { NameStrings = StringRef(reinterpret_cast<const char *>(P), UncompressedSize); diff --git a/llvm/lib/ProfileData/SampleProf.cpp b/llvm/lib/ProfileData/SampleProf.cpp index f794e64a13e7..b4d5550a1721 100644 --- a/llvm/lib/ProfileData/SampleProf.cpp +++ b/llvm/lib/ProfileData/SampleProf.cpp @@ -20,7 +20,6 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/raw_ostream.h" #include <string> #include <system_error> @@ -98,10 +97,9 @@ class SampleProfErrorCategoryType : public std::error_category { } // end anonymous namespace -static ManagedStatic<SampleProfErrorCategoryType> ErrorCategory; - const std::error_category &llvm::sampleprof_category() { - return *ErrorCategory; + static SampleProfErrorCategoryType ErrorCategory; + return ErrorCategory; } void LineLocation::print(raw_ostream &OS) const { diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp index 280e3c6cb8d1..204e34bff879 100644 --- a/llvm/lib/ProfileData/SampleProfReader.cpp +++ b/llvm/lib/ProfileData/SampleProfReader.cpp @@ -877,15 +877,13 @@ std::error_code SampleProfileReaderExtBinaryBase::decompressSection( if (std::error_code EC = CompressSize.getError()) return EC; - if (!llvm::zlib::isAvailable()) + if (!llvm::compression::zlib::isAvailable()) return sampleprof_error::zlib_unavailable; - StringRef CompressedStrings(reinterpret_cast<const char *>(Data), - *CompressSize); - char *Buffer = Allocator.Allocate<char>(DecompressBufSize); + uint8_t *Buffer = Allocator.Allocate<uint8_t>(DecompressBufSize); size_t UCSize = DecompressBufSize; - llvm::Error E = - zlib::uncompress(CompressedStrings, Buffer, UCSize); + llvm::Error E = compression::zlib::uncompress( + makeArrayRef(Data, *CompressSize), Buffer, UCSize); if (E) return sampleprof_error::uncompress_failed; DecompressBuf = reinterpret_cast<const uint8_t *>(Buffer); diff --git a/llvm/lib/ProfileData/SampleProfWriter.cpp b/llvm/lib/ProfileData/SampleProfWriter.cpp index 8ec6b7ebc29e..093790afe2d6 100644 --- a/llvm/lib/ProfileData/SampleProfWriter.cpp +++ b/llvm/lib/ProfileData/SampleProfWriter.cpp @@ -78,19 +78,20 @@ SampleProfileWriterExtBinaryBase::markSectionStart(SecType Type, } std::error_code SampleProfileWriterExtBinaryBase::compressAndOutput() { - if (!llvm::zlib::isAvailable()) + if (!llvm::compression::zlib::isAvailable()) return sampleprof_error::zlib_unavailable; std::string &UncompressedStrings = static_cast<raw_string_ostream *>(LocalBufStream.get())->str(); if (UncompressedStrings.size() == 0) return sampleprof_error::success; auto &OS = *OutputStream; - SmallString<128> CompressedStrings; - zlib::compress(UncompressedStrings, CompressedStrings, - zlib::BestSizeCompression); + SmallVector<uint8_t, 128> CompressedStrings; + compression::zlib::compress(arrayRefFromStringRef(UncompressedStrings), + CompressedStrings, + compression::zlib::BestSizeCompression); encodeULEB128(UncompressedStrings.size(), OS); encodeULEB128(CompressedStrings.size(), OS); - OS << CompressedStrings.str(); + OS << toStringRef(CompressedStrings); UncompressedStrings.clear(); return sampleprof_error::success; } |
