Skip to content

Commit

Permalink
[llvm-profdata] Fix some style and clang-tidy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed May 21, 2024
1 parent 7064e4b commit 3fa6b3b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
10 changes: 5 additions & 5 deletions llvm/include/llvm/ProfileData/SampleProfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -436,17 +436,17 @@ 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.
/// Parameter P specifies the FSDiscriminatorPass.
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()); }
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/ProfileData/SampleProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down
21 changes: 10 additions & 11 deletions llvm/tools/llvm-profdata/llvm-profdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ cl::SubCommand MergeSubcommand(
namespace {
enum ProfileKinds { instr, sample, memory };
enum FailureMode { warnOnly, failIfAnyAreInvalid, failIfAllAreInvalid };
} // namespace

enum ProfileFormat {
PF_None = 0,
Expand All @@ -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"),
Expand Down Expand Up @@ -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 << ": ";
Expand All @@ -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 << ": ";
Expand All @@ -481,24 +480,24 @@ 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,
StringRef Whence = "") {
if (FailMode == failIfAnyAreInvalid)
exitWithErrorCode(EC, Whence);
else
warn(EC.message(), std::string(Whence));
warn(EC.message(), Whence);
}

static void handleMergeWriterError(Error E, StringRef WhenceFile = "",
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3fa6b3b

Please sign in to comment.