[llvm] r256784 - [PGO] Refactor string writer code
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 4 14:01:04 PST 2016
Author: davidxl
Date: Mon Jan 4 16:01:02 2016
New Revision: 256784
URL: http://llvm.org/viewvc/llvm-project?rev=256784&view=rev
Log:
[PGO] Refactor string writer code
For readability and code sharing.
(Adapted from Suggestions by Vedant).
Modified:
llvm/trunk/lib/ProfileData/InstrProf.cpp
Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=256784&r1=256783&r2=256784&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Mon Jan 4 16:01:02 2016
@@ -173,26 +173,32 @@ int collectPGOFuncNameStrings(const std:
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) {
More information about the llvm-commits
mailing list