[llvm] 3fa6b3b - [llvm-profdata] Fix some style and clang-tidy issues
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon May 20 17:15:56 PDT 2024
Author: Fangrui Song
Date: 2024-05-20T17:15:52-07:00
New Revision: 3fa6b3bbdb0f9de18def8596d1f7fcec2ef77b5e
URL: https://github.com/llvm/llvm-project/commit/3fa6b3bbdb0f9de18def8596d1f7fcec2ef77b5e
DIFF: https://github.com/llvm/llvm-project/commit/3fa6b3bbdb0f9de18def8596d1f7fcec2ef77b5e.diff
LOG: [llvm-profdata] Fix some style and clang-tidy issues
Fix #92761
Fix #92762
Added:
Modified:
llvm/include/llvm/ProfileData/SampleProfReader.h
llvm/lib/ProfileData/SampleProfReader.cpp
llvm/tools/llvm-profdata/llvm-profdata.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/SampleProfReader.h b/llvm/include/llvm/ProfileData/SampleProfReader.h
index 9e8f543909cdb..d7c70064ca429 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<std::unique_ptr<SampleProfileReaderItaniumRemapper>>
- 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<std::unique_ptr<SampleProfileReader>>
- 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<std::unique_ptr<SampleProfileReader>>
create(std::unique_ptr<MemoryBuffer> &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 f91a0e6177ea0..a4b2d0668a5a5 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<std::unique_ptr<SampleProfileReader>>
-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<std::unique_ptr<SampleProfileReaderItaniumRemapper>>
-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<MemoryBuffer> &B,
ErrorOr<std::unique_ptr<SampleProfileReader>>
SampleProfileReader::create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C,
vfs::FileSystem &FS, FSDiscriminatorPass P,
- const std::string RemapFilename) {
+ StringRef RemapFilename) {
std::unique_ptr<SampleProfileReader> 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 4126b55576ddc..693af066bc0fb 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<std::string> OutputFilename("output", cl::value_desc("output"),
@@ -443,8 +443,7 @@ cl::opt<bool> 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<InstrProfError>()) {
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) {
More information about the llvm-commits
mailing list