From 3fa6b3bbdb0f9de18def8596d1f7fcec2ef77b5e Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 20 May 2024 17:15:52 -0700 Subject: [PATCH] [llvm-profdata] Fix some style and clang-tidy issues Fix #92761 Fix #92762 --- .../llvm/ProfileData/SampleProfReader.h | 10 ++++----- llvm/lib/ProfileData/SampleProfReader.cpp | 8 +++---- llvm/tools/llvm-profdata/llvm-profdata.cpp | 21 +++++++++---------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h index 9e8f543909cdbd..d7c70064ca429f 100644 --- a/llvm/include/llvm/ProfileData/SampleProfReader.h +++ b/llvm/include/llvm/ProfileData/SampleProfReader.h @@ -274,8 +274,8 @@ class SampleProfileReaderItaniumRemapper { /// Create a remapper from the given remapping file. The remapper will /// be used for profile read in by Reader. static ErrorOr> - create(const std::string Filename, vfs::FileSystem &FS, - SampleProfileReader &Reader, LLVMContext &C); + create(StringRef Filename, vfs::FileSystem &FS, SampleProfileReader &Reader, + LLVMContext &C); /// Create a remapper from the given Buffer. The remapper will /// be used for profile read in by Reader. @@ -436,9 +436,9 @@ class SampleProfileReader { /// Create a remapper underlying if RemapFilename is not empty. /// Parameter P specifies the FSDiscriminatorPass. static ErrorOr> - create(const std::string Filename, LLVMContext &C, vfs::FileSystem &FS, + create(StringRef Filename, LLVMContext &C, vfs::FileSystem &FS, FSDiscriminatorPass P = FSDiscriminatorPass::Base, - const std::string RemapFilename = ""); + StringRef RemapFilename = ""); /// Create a sample profile reader from the supplied memory buffer. /// Create a remapper underlying if RemapFilename is not empty. @@ -446,7 +446,7 @@ class SampleProfileReader { static ErrorOr> create(std::unique_ptr &B, LLVMContext &C, vfs::FileSystem &FS, FSDiscriminatorPass P = FSDiscriminatorPass::Base, - const std::string RemapFilename = ""); + StringRef RemapFilename = ""); /// Return the profile summary. ProfileSummary &getSummary() const { return *(Summary.get()); } diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp index f91a0e6177ea02..a4b2d0668a5a54 100644 --- a/llvm/lib/ProfileData/SampleProfReader.cpp +++ b/llvm/lib/ProfileData/SampleProfReader.cpp @@ -1822,9 +1822,9 @@ setupMemoryBuffer(const Twine &Filename, vfs::FileSystem &FS) { /// /// \returns an error code indicating the status of the created reader. ErrorOr> -SampleProfileReader::create(const std::string Filename, LLVMContext &C, +SampleProfileReader::create(StringRef Filename, LLVMContext &C, vfs::FileSystem &FS, FSDiscriminatorPass P, - const std::string RemapFilename) { + StringRef RemapFilename) { auto BufferOrError = setupMemoryBuffer(Filename, FS); if (std::error_code EC = BufferOrError.getError()) return EC; @@ -1842,7 +1842,7 @@ SampleProfileReader::create(const std::string Filename, LLVMContext &C, /// /// \returns an error code indicating the status of the created reader. ErrorOr> -SampleProfileReaderItaniumRemapper::create(const std::string Filename, +SampleProfileReaderItaniumRemapper::create(StringRef Filename, vfs::FileSystem &FS, SampleProfileReader &Reader, LLVMContext &C) { @@ -1895,7 +1895,7 @@ SampleProfileReaderItaniumRemapper::create(std::unique_ptr &B, ErrorOr> SampleProfileReader::create(std::unique_ptr &B, LLVMContext &C, vfs::FileSystem &FS, FSDiscriminatorPass P, - const std::string RemapFilename) { + StringRef RemapFilename) { std::unique_ptr Reader; if (SampleProfileReaderRawBinary::hasFormat(*B)) Reader.reset(new SampleProfileReaderRawBinary(std::move(B), C)); diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp index 4126b55576ddc3..693af066bc0fbf 100644 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -75,7 +75,6 @@ cl::SubCommand MergeSubcommand( namespace { enum ProfileKinds { instr, sample, memory }; enum FailureMode { warnOnly, failIfAnyAreInvalid, failIfAllAreInvalid }; -} // namespace enum ProfileFormat { PF_None = 0, @@ -87,6 +86,7 @@ enum ProfileFormat { }; enum class ShowFormat { Text, Json, Yaml }; +} // namespace // Common options. cl::opt OutputFilename("output", cl::value_desc("output"), @@ -443,8 +443,7 @@ cl::opt ShowProfileVersion("profile-version", cl::init(false), // multiple static functions map to the same name. const std::string DuplicateNameStr = "----"; -static void warn(Twine Message, std::string Whence = "", - std::string Hint = "") { +static void warn(Twine Message, StringRef Whence = "", StringRef Hint = "") { WithColor::warning(); if (!Whence.empty()) errs() << Whence << ": "; @@ -456,13 +455,13 @@ static void warn(Twine Message, std::string Whence = "", static void warn(Error E, StringRef Whence = "") { if (E.isA()) { handleAllErrors(std::move(E), [&](const InstrProfError &IPE) { - warn(IPE.message(), std::string(Whence), std::string("")); + warn(IPE.message(), Whence); }); } } -static void exitWithError(Twine Message, std::string Whence = "", - std::string Hint = "") { +static void exitWithError(Twine Message, StringRef Whence = "", + StringRef Hint = "") { WithColor::error(); if (!Whence.empty()) errs() << Whence << ": "; @@ -481,16 +480,16 @@ static void exitWithError(Error E, StringRef Whence = "") { // Hint in case user missed specifying the profile type. Hint = "Perhaps you forgot to use the --sample or --memory option?"; } - exitWithError(IPE.message(), std::string(Whence), std::string(Hint)); + exitWithError(IPE.message(), Whence, Hint); }); return; } - exitWithError(toString(std::move(E)), std::string(Whence)); + exitWithError(toString(std::move(E)), Whence); } static void exitWithErrorCode(std::error_code EC, StringRef Whence = "") { - exitWithError(EC.message(), std::string(Whence)); + exitWithError(EC.message(), Whence); } static void warnOrExitGivenError(FailureMode FailMode, std::error_code EC, @@ -498,7 +497,7 @@ static void warnOrExitGivenError(FailureMode FailMode, std::error_code EC, if (FailMode == failIfAnyAreInvalid) exitWithErrorCode(EC, Whence); else - warn(EC.message(), std::string(Whence)); + warn(EC.message(), Whence); } static void handleMergeWriterError(Error E, StringRef WhenceFile = "", @@ -1585,7 +1584,7 @@ static void mergeSampleProfile(const WeightedFileVector &Inputs, // If OutputSizeLimit is 0 (default), it is the same as write(). if (std::error_code EC = Writer->writeWithSizeLimit(ProfileMap, OutputSizeLimit)) - exitWithErrorCode(std::move(EC)); + exitWithErrorCode(EC); } static WeightedFile parseWeightedFile(const StringRef &WeightedFilename) {