diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2016-05-29 10:31:00 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2016-05-29 10:31:00 +0000 |
commit | 2ff22b74ed49f84211ba07ddecf8f3740ee5c785 (patch) | |
tree | ae5038c3eb7e36d2ababda361cd6a7d1c9ee539f | |
parent | a83f08e633465e46ebb75c17475754a8c7075d20 (diff) |
[ProfileData] Clean up string handling a bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271180 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/ProfileData/InstrProf.h | 2 | ||||
-rw-r--r-- | include/llvm/ProfileData/InstrProfReader.h | 4 | ||||
-rw-r--r-- | include/llvm/ProfileData/SampleProfReader.h | 2 | ||||
-rw-r--r-- | lib/ProfileData/InstrProf.cpp | 14 | ||||
-rw-r--r-- | lib/ProfileData/InstrProfReader.cpp | 6 | ||||
-rw-r--r-- | lib/ProfileData/SampleProfReader.cpp | 4 |
6 files changed, 15 insertions, 17 deletions
diff --git a/include/llvm/ProfileData/InstrProf.h b/include/llvm/ProfileData/InstrProf.h index e403f053c77..75646b76165 100644 --- a/include/llvm/ProfileData/InstrProf.h +++ b/include/llvm/ProfileData/InstrProf.h @@ -272,7 +272,7 @@ MDNode *getPGOFuncNameMetadata(const Function &F); /// Create the PGOFuncName meta data if PGOFuncName is different from /// function's raw name. This should only apply to internal linkage functions /// declared by users only. -void createPGOFuncNameMetadata(Function &F, const std::string &PGOFuncName); +void createPGOFuncNameMetadata(Function &F, StringRef PGOFuncName); const std::error_category &instrprof_category(); diff --git a/include/llvm/ProfileData/InstrProfReader.h b/include/llvm/ProfileData/InstrProfReader.h index 4c2e5fc913c..65b11f61d10 100644 --- a/include/llvm/ProfileData/InstrProfReader.h +++ b/include/llvm/ProfileData/InstrProfReader.h @@ -105,7 +105,7 @@ public: /// Factory method to create an appropriately typed reader for the given /// instrprof file. - static Expected<std::unique_ptr<InstrProfReader>> create(std::string Path); + static Expected<std::unique_ptr<InstrProfReader>> create(const Twine &Path); static Expected<std::unique_ptr<InstrProfReader>> create(std::unique_ptr<MemoryBuffer> Buffer); @@ -403,7 +403,7 @@ public: /// Factory method to create an indexed reader. static Expected<std::unique_ptr<IndexedInstrProfReader>> - create(std::string Path); + create(const Twine &Path); static Expected<std::unique_ptr<IndexedInstrProfReader>> create(std::unique_ptr<MemoryBuffer> Buffer); diff --git a/include/llvm/ProfileData/SampleProfReader.h b/include/llvm/ProfileData/SampleProfReader.h index dacf6d06c13..bf86721709c 100644 --- a/include/llvm/ProfileData/SampleProfReader.h +++ b/include/llvm/ProfileData/SampleProfReader.h @@ -289,7 +289,7 @@ public: /// \brief Create a sample profile reader appropriate to the file format. static ErrorOr<std::unique_ptr<SampleProfileReader>> - create(StringRef Filename, LLVMContext &C); + create(const Twine &Filename, LLVMContext &C); /// \brief Create a sample profile reader from the supplied memory buffer. static ErrorOr<std::unique_ptr<SampleProfileReader>> diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp index 69bb9bb37b3..19b3f036b28 100644 --- a/lib/ProfileData/InstrProf.cpp +++ b/lib/ProfileData/InstrProf.cpp @@ -241,8 +241,7 @@ Error collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs, unsigned EncLen = encodeULEB128(UncompressedNameStrings.length(), P); P += EncLen; - auto WriteStringToResult = [&](size_t CompressedLen, - const std::string &InputStr) { + auto WriteStringToResult = [&](size_t CompressedLen, StringRef InputStr) { EncLen = encodeULEB128(CompressedLen, P); P += EncLen; char *HeaderStr = reinterpret_cast<char *>(&Header[0]); @@ -256,7 +255,7 @@ Error collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs, return WriteStringToResult(0, UncompressedNameStrings); } - SmallVector<char, 128> CompressedNameStrings; + SmallString<128> CompressedNameStrings; zlib::Status Success = zlib::compress(StringRef(UncompressedNameStrings), CompressedNameStrings, zlib::BestSizeCompression); @@ -264,9 +263,8 @@ Error collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs, if (Success != zlib::StatusOK) return make_error<InstrProfError>(instrprof_error::compress_failed); - return WriteStringToResult( - CompressedNameStrings.size(), - std::string(CompressedNameStrings.data(), CompressedNameStrings.size())); + return WriteStringToResult(CompressedNameStrings.size(), + CompressedNameStrings); } StringRef getPGOFuncNameVarInitializer(GlobalVariable *NameVar) { @@ -761,7 +759,7 @@ MDNode *getPGOFuncNameMetadata(const Function &F) { return F.getMetadata(getPGOFuncNameMetadataName()); } -void createPGOFuncNameMetadata(Function &F, const std::string &PGOFuncName) { +void createPGOFuncNameMetadata(Function &F, StringRef PGOFuncName) { // Only for internal linkage functions. if (PGOFuncName == F.getName()) return; @@ -769,7 +767,7 @@ void createPGOFuncNameMetadata(Function &F, const std::string &PGOFuncName) { if (getPGOFuncNameMetadata(F)) return; LLVMContext &C = F.getContext(); - MDNode *N = MDNode::get(C, MDString::get(C, PGOFuncName.c_str())); + MDNode *N = MDNode::get(C, MDString::get(C, PGOFuncName)); F.setMetadata(getPGOFuncNameMetadataName(), N); } diff --git a/lib/ProfileData/InstrProfReader.cpp b/lib/ProfileData/InstrProfReader.cpp index a7d8fcf76e1..81c13b35ce3 100644 --- a/lib/ProfileData/InstrProfReader.cpp +++ b/lib/ProfileData/InstrProfReader.cpp @@ -19,7 +19,7 @@ using namespace llvm; static Expected<std::unique_ptr<MemoryBuffer>> -setupMemoryBuffer(std::string Path) { +setupMemoryBuffer(const Twine &Path) { ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr = MemoryBuffer::getFileOrSTDIN(Path); if (std::error_code EC = BufferOrErr.getError()) @@ -32,7 +32,7 @@ static Error initializeReader(InstrProfReader &Reader) { } Expected<std::unique_ptr<InstrProfReader>> -InstrProfReader::create(std::string Path) { +InstrProfReader::create(const Twine &Path) { // Set up the buffer to read. auto BufferOrError = setupMemoryBuffer(Path); if (Error E = BufferOrError.takeError()) @@ -67,7 +67,7 @@ InstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) { } Expected<std::unique_ptr<IndexedInstrProfReader>> -IndexedInstrProfReader::create(std::string Path) { +IndexedInstrProfReader::create(const Twine &Path) { // Set up the buffer to read. auto BufferOrError = setupMemoryBuffer(Path); if (Error E = BufferOrError.takeError()) diff --git a/lib/ProfileData/SampleProfReader.cpp b/lib/ProfileData/SampleProfReader.cpp index d3929e81ff4..af80b036a5b 100644 --- a/lib/ProfileData/SampleProfReader.cpp +++ b/lib/ProfileData/SampleProfReader.cpp @@ -733,7 +733,7 @@ bool SampleProfileReaderGCC::hasFormat(const MemoryBuffer &Buffer) { /// /// \returns an error code indicating the status of the buffer. static ErrorOr<std::unique_ptr<MemoryBuffer>> -setupMemoryBuffer(std::string Filename) { +setupMemoryBuffer(const Twine &Filename) { auto BufferOrErr = MemoryBuffer::getFileOrSTDIN(Filename); if (std::error_code EC = BufferOrErr.getError()) return EC; @@ -756,7 +756,7 @@ setupMemoryBuffer(std::string Filename) { /// /// \returns an error code indicating the status of the created reader. ErrorOr<std::unique_ptr<SampleProfileReader>> -SampleProfileReader::create(StringRef Filename, LLVMContext &C) { +SampleProfileReader::create(const Twine &Filename, LLVMContext &C) { auto BufferOrError = setupMemoryBuffer(Filename); if (std::error_code EC = BufferOrError.getError()) return EC; |