diff options
author | Xinliang David Li <davidxl@google.com> | 2016-01-04 22:01:02 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-01-04 22:01:02 +0000 |
commit | 120fe2e8981c8cede9e5ec60bd0411fb8c1eac35 (patch) | |
tree | ff82ed5a1e3819e9f8a9fe14a5da7a6aa03ef535 /llvm/lib/ProfileData/InstrProf.cpp | |
parent | 9d6c94006ef7e010814aa5d6b38fb81ae0dfc4f8 (diff) | |
download | bcm5719-llvm-120fe2e8981c8cede9e5ec60bd0411fb8c1eac35.tar.gz bcm5719-llvm-120fe2e8981c8cede9e5ec60bd0411fb8c1eac35.zip |
[PGO] Refactor string writer code
For readability and code sharing.
(Adapted from Suggestions by Vedant).
llvm-svn: 256784
Diffstat (limited to 'llvm/lib/ProfileData/InstrProf.cpp')
-rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index 58f70af39f6..bcb248e8305 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -173,26 +173,32 @@ int collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs, unsigned EncLen = encodeULEB128(UncompressedNameStrings.length(), P); P += EncLen; - if (!doCompression) { - EncLen = encodeULEB128(0, P); + + auto WriteStringToResult = [&](size_t CompressedLen, + const std::string &InputStr) { + EncLen = encodeULEB128(CompressedLen, P); P += EncLen; - Result.append(reinterpret_cast<char *>(&Header[0]), P - &Header[0]); - Result += UncompressedNameStrings; + char *HeaderStr = reinterpret_cast<char *>(&Header[0]); + unsigned HeaderLen = P - &Header[0]; + Result.append(HeaderStr, HeaderLen); + Result += InputStr; return 0; - } + }; + + if (!doCompression) + return WriteStringToResult(0, UncompressedNameStrings); + SmallVector<char, 128> CompressedNameStrings; zlib::Status Success = zlib::compress(StringRef(UncompressedNameStrings), CompressedNameStrings, zlib::BestSizeCompression); - assert(Success == zlib::StatusOK); + if (Success != zlib::StatusOK) return 1; - EncLen = encodeULEB128(CompressedNameStrings.size(), P); - P += EncLen; - Result.append(reinterpret_cast<char *>(&Header[0]), P - &Header[0]); - Result += - std::string(CompressedNameStrings.data(), CompressedNameStrings.size()); - return 0; + + return WriteStringToResult( + CompressedNameStrings.size(), + std::string(CompressedNameStrings.data(), CompressedNameStrings.size())); } StringRef getPGOFuncNameInitializer(GlobalVariable *NameVar) { |