summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ProfileData/SampleProf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/ProfileData/SampleProf.cpp')
-rw-r--r--llvm/lib/ProfileData/SampleProf.cpp55
1 files changed, 11 insertions, 44 deletions
diff --git a/llvm/lib/ProfileData/SampleProf.cpp b/llvm/lib/ProfileData/SampleProf.cpp
index e94848df24e..2150c5d5a70 100644
--- a/llvm/lib/ProfileData/SampleProf.cpp
+++ b/llvm/lib/ProfileData/SampleProf.cpp
@@ -15,7 +15,6 @@
#include "llvm/Config/llvm-config.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/Support/Compiler.h"
-#include "llvm/Support/Compression.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
@@ -198,66 +197,34 @@ FunctionSamples::findFunctionSamples(const DILocation *DIL) const {
LLVM_DUMP_METHOD void FunctionSamples::dump() const { print(dbgs(), 0); }
#endif
-std::error_code ProfileSymbolList::read(uint64_t CompressSize,
- uint64_t UncompressSize,
- const uint8_t *Data) {
+std::error_code ProfileSymbolList::read(const uint8_t *Data,
+ uint64_t ListSize) {
const char *ListStart = reinterpret_cast<const char *>(Data);
- // CompressSize being non-zero means the profile is compressed and
- // needs to be uncompressed first.
- if (CompressSize) {
- if (!llvm::zlib::isAvailable())
- return sampleprof_error::zlib_unavailable;
-
- StringRef CompressedStrings(reinterpret_cast<const char *>(Data),
- CompressSize);
- char *Buffer = Allocator.Allocate<char>(UncompressSize);
- size_t UCSize = UncompressSize;
- llvm::Error E = zlib::uncompress(CompressedStrings, Buffer, UCSize);
- if (E)
- return sampleprof_error::uncompress_failed;
- ListStart = Buffer;
- }
-
uint64_t Size = 0;
- while (Size < UncompressSize) {
+ while (Size < ListSize) {
StringRef Str(ListStart + Size);
add(Str);
Size += Str.size() + 1;
}
+ if (Size != ListSize)
+ return sampleprof_error::malformed;
return sampleprof_error::success;
}
std::error_code ProfileSymbolList::write(raw_ostream &OS) {
- // Sort the symbols before doing compression. It will make the
- // compression much more effective.
+ // Sort the symbols before output. If doing compression.
+ // It will make the compression much more effective.
std::vector<StringRef> SortedList;
SortedList.insert(SortedList.begin(), Syms.begin(), Syms.end());
llvm::sort(SortedList);
- std::string UncompressedStrings;
+ std::string OutputString;
for (auto &Sym : SortedList) {
- UncompressedStrings.append(Sym.str());
- UncompressedStrings.append(1, '\0');
+ OutputString.append(Sym.str());
+ OutputString.append(1, '\0');
}
- if (ToCompress) {
- if (!llvm::zlib::isAvailable())
- return sampleprof_error::zlib_unavailable;
- SmallString<128> CompressedStrings;
- llvm::Error E = zlib::compress(UncompressedStrings, CompressedStrings,
- zlib::BestSizeCompression);
- if (E)
- return sampleprof_error::compress_failed;
- encodeULEB128(UncompressedStrings.size(), OS);
- encodeULEB128(CompressedStrings.size(), OS);
- OS << CompressedStrings.str();
- } else {
- encodeULEB128(UncompressedStrings.size(), OS);
- // If profile symbol list is not compressed, we will still save
- // a compressed size value, but the value of the size is 0.
- encodeULEB128(0, OS);
- OS << UncompressedStrings;
- }
+ OS << OutputString;
return sampleprof_error::success;
}
OpenPOWER on IntegriCloud