llvm.org GIT mirror llvm / 2ff22b7
[ProfileData] Clean up string handling a bit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271180 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 4 years ago
6 changed file(s) with 15 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
271271 /// Create the PGOFuncName meta data if PGOFuncName is different from
272272 /// function's raw name. This should only apply to internal linkage functions
273273 /// declared by users only.
274 void createPGOFuncNameMetadata(Function &F, const std::string &PGOFuncName);
274 void createPGOFuncNameMetadata(Function &F, StringRef PGOFuncName);
275275
276276 const std::error_category &instrprof_category();
277277
104104
105105 /// Factory method to create an appropriately typed reader for the given
106106 /// instrprof file.
107 static Expected> create(std::string Path);
107 static Expected> create(const Twine &Path);
108108
109109 static Expected>
110110 create(std::unique_ptr Buffer);
402402
403403 /// Factory method to create an indexed reader.
404404 static Expected>
405 create(std::string Path);
405 create(const Twine &Path);
406406
407407 static Expected>
408408 create(std::unique_ptr Buffer);
288288
289289 /// \brief Create a sample profile reader appropriate to the file format.
290290 static ErrorOr>
291 create(StringRef Filename, LLVMContext &C);
291 create(const Twine &Filename, LLVMContext &C);
292292
293293 /// \brief Create a sample profile reader from the supplied memory buffer.
294294 static ErrorOr>
240240 unsigned EncLen = encodeULEB128(UncompressedNameStrings.length(), P);
241241 P += EncLen;
242242
243 auto WriteStringToResult = [&](size_t CompressedLen,
244 const std::string &InputStr) {
243 auto WriteStringToResult = [&](size_t CompressedLen, StringRef InputStr) {
245244 EncLen = encodeULEB128(CompressedLen, P);
246245 P += EncLen;
247246 char *HeaderStr = reinterpret_cast(&Header[0]);
255254 return WriteStringToResult(0, UncompressedNameStrings);
256255 }
257256
258 SmallVector128> CompressedNameStrings;
257 SmallString<128> CompressedNameStrings;
259258 zlib::Status Success =
260259 zlib::compress(StringRef(UncompressedNameStrings), CompressedNameStrings,
261260 zlib::BestSizeCompression);
263262 if (Success != zlib::StatusOK)
264263 return make_error(instrprof_error::compress_failed);
265264
266 return WriteStringToResult(
267 CompressedNameStrings.size(),
268 std::string(CompressedNameStrings.data(), CompressedNameStrings.size()));
265 return WriteStringToResult(CompressedNameStrings.size(),
266 CompressedNameStrings);
269267 }
270268
271269 StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar) {
760758 return F.getMetadata(getPGOFuncNameMetadataName());
761759 }
762760
763 void createPGOFuncNameMetadata(Function &F, const std::string &PGOFuncName) {
761 void createPGOFuncNameMetadata(Function &F, StringRef PGOFuncName) {
764762 // Only for internal linkage functions.
765763 if (PGOFuncName == F.getName())
766764 return;
768766 if (getPGOFuncNameMetadata(F))
769767 return;
770768 LLVMContext &C = F.getContext();
771 MDNode *N = MDNode::get(C, MDString::get(C, PGOFuncName.c_str()));
769 MDNode *N = MDNode::get(C, MDString::get(C, PGOFuncName));
772770 F.setMetadata(getPGOFuncNameMetadataName(), N);
773771 }
774772
1818 using namespace llvm;
1919
2020 static Expected>
21 setupMemoryBuffer(std::string Path) {
21 setupMemoryBuffer(const Twine &Path) {
2222 ErrorOr> BufferOrErr =
2323 MemoryBuffer::getFileOrSTDIN(Path);
2424 if (std::error_code EC = BufferOrErr.getError())
3131 }
3232
3333 Expected>
34 InstrProfReader::create(std::string Path) {
34 InstrProfReader::create(const Twine &Path) {
3535 // Set up the buffer to read.
3636 auto BufferOrError = setupMemoryBuffer(Path);
3737 if (Error E = BufferOrError.takeError())
6666 }
6767
6868 Expected>
69 IndexedInstrProfReader::create(std::string Path) {
69 IndexedInstrProfReader::create(const Twine &Path) {
7070 // Set up the buffer to read.
7171 auto BufferOrError = setupMemoryBuffer(Path);
7272 if (Error E = BufferOrError.takeError())
732732 ///
733733 /// \returns an error code indicating the status of the buffer.
734734 static ErrorOr>
735 setupMemoryBuffer(std::string Filename) {
735 setupMemoryBuffer(const Twine &Filename) {
736736 auto BufferOrErr = MemoryBuffer::getFileOrSTDIN(Filename);
737737 if (std::error_code EC = BufferOrErr.getError())
738738 return EC;
755755 ///
756756 /// \returns an error code indicating the status of the created reader.
757757 ErrorOr>
758 SampleProfileReader::create(StringRef Filename, LLVMContext &C) {
758 SampleProfileReader::create(const Twine &Filename, LLVMContext &C) {
759759 auto BufferOrError = setupMemoryBuffer(Filename);
760760 if (std::error_code EC = BufferOrError.getError())
761761 return EC;