Skip to content

Commit 3fa6b3b

Browse files
committed
[llvm-profdata] Fix some style and clang-tidy issues
Fix llvm#92761 Fix llvm#92762
1 parent 7064e4b commit 3fa6b3b

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

llvm/include/llvm/ProfileData/SampleProfReader.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ class SampleProfileReaderItaniumRemapper {
274274
/// Create a remapper from the given remapping file. The remapper will
275275
/// be used for profile read in by Reader.
276276
static ErrorOr<std::unique_ptr<SampleProfileReaderItaniumRemapper>>
277-
create(const std::string Filename, vfs::FileSystem &FS,
278-
SampleProfileReader &Reader, LLVMContext &C);
277+
create(StringRef Filename, vfs::FileSystem &FS, SampleProfileReader &Reader,
278+
LLVMContext &C);
279279

280280
/// Create a remapper from the given Buffer. The remapper will
281281
/// be used for profile read in by Reader.
@@ -436,17 +436,17 @@ class SampleProfileReader {
436436
/// Create a remapper underlying if RemapFilename is not empty.
437437
/// Parameter P specifies the FSDiscriminatorPass.
438438
static ErrorOr<std::unique_ptr<SampleProfileReader>>
439-
create(const std::string Filename, LLVMContext &C, vfs::FileSystem &FS,
439+
create(StringRef Filename, LLVMContext &C, vfs::FileSystem &FS,
440440
FSDiscriminatorPass P = FSDiscriminatorPass::Base,
441-
const std::string RemapFilename = "");
441+
StringRef RemapFilename = "");
442442

443443
/// Create a sample profile reader from the supplied memory buffer.
444444
/// Create a remapper underlying if RemapFilename is not empty.
445445
/// Parameter P specifies the FSDiscriminatorPass.
446446
static ErrorOr<std::unique_ptr<SampleProfileReader>>
447447
create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C, vfs::FileSystem &FS,
448448
FSDiscriminatorPass P = FSDiscriminatorPass::Base,
449-
const std::string RemapFilename = "");
449+
StringRef RemapFilename = "");
450450

451451
/// Return the profile summary.
452452
ProfileSummary &getSummary() const { return *(Summary.get()); }

llvm/lib/ProfileData/SampleProfReader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,9 +1822,9 @@ setupMemoryBuffer(const Twine &Filename, vfs::FileSystem &FS) {
18221822
///
18231823
/// \returns an error code indicating the status of the created reader.
18241824
ErrorOr<std::unique_ptr<SampleProfileReader>>
1825-
SampleProfileReader::create(const std::string Filename, LLVMContext &C,
1825+
SampleProfileReader::create(StringRef Filename, LLVMContext &C,
18261826
vfs::FileSystem &FS, FSDiscriminatorPass P,
1827-
const std::string RemapFilename) {
1827+
StringRef RemapFilename) {
18281828
auto BufferOrError = setupMemoryBuffer(Filename, FS);
18291829
if (std::error_code EC = BufferOrError.getError())
18301830
return EC;
@@ -1842,7 +1842,7 @@ SampleProfileReader::create(const std::string Filename, LLVMContext &C,
18421842
///
18431843
/// \returns an error code indicating the status of the created reader.
18441844
ErrorOr<std::unique_ptr<SampleProfileReaderItaniumRemapper>>
1845-
SampleProfileReaderItaniumRemapper::create(const std::string Filename,
1845+
SampleProfileReaderItaniumRemapper::create(StringRef Filename,
18461846
vfs::FileSystem &FS,
18471847
SampleProfileReader &Reader,
18481848
LLVMContext &C) {
@@ -1895,7 +1895,7 @@ SampleProfileReaderItaniumRemapper::create(std::unique_ptr<MemoryBuffer> &B,
18951895
ErrorOr<std::unique_ptr<SampleProfileReader>>
18961896
SampleProfileReader::create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C,
18971897
vfs::FileSystem &FS, FSDiscriminatorPass P,
1898-
const std::string RemapFilename) {
1898+
StringRef RemapFilename) {
18991899
std::unique_ptr<SampleProfileReader> Reader;
19001900
if (SampleProfileReaderRawBinary::hasFormat(*B))
19011901
Reader.reset(new SampleProfileReaderRawBinary(std::move(B), C));

llvm/tools/llvm-profdata/llvm-profdata.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ cl::SubCommand MergeSubcommand(
7575
namespace {
7676
enum ProfileKinds { instr, sample, memory };
7777
enum FailureMode { warnOnly, failIfAnyAreInvalid, failIfAllAreInvalid };
78-
} // namespace
7978

8079
enum ProfileFormat {
8180
PF_None = 0,
@@ -87,6 +86,7 @@ enum ProfileFormat {
8786
};
8887

8988
enum class ShowFormat { Text, Json, Yaml };
89+
} // namespace
9090

9191
// Common options.
9292
cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
@@ -443,8 +443,7 @@ cl::opt<bool> ShowProfileVersion("profile-version", cl::init(false),
443443
// multiple static functions map to the same name.
444444
const std::string DuplicateNameStr = "----";
445445

446-
static void warn(Twine Message, std::string Whence = "",
447-
std::string Hint = "") {
446+
static void warn(Twine Message, StringRef Whence = "", StringRef Hint = "") {
448447
WithColor::warning();
449448
if (!Whence.empty())
450449
errs() << Whence << ": ";
@@ -456,13 +455,13 @@ static void warn(Twine Message, std::string Whence = "",
456455
static void warn(Error E, StringRef Whence = "") {
457456
if (E.isA<InstrProfError>()) {
458457
handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {
459-
warn(IPE.message(), std::string(Whence), std::string(""));
458+
warn(IPE.message(), Whence);
460459
});
461460
}
462461
}
463462

464-
static void exitWithError(Twine Message, std::string Whence = "",
465-
std::string Hint = "") {
463+
static void exitWithError(Twine Message, StringRef Whence = "",
464+
StringRef Hint = "") {
466465
WithColor::error();
467466
if (!Whence.empty())
468467
errs() << Whence << ": ";
@@ -481,24 +480,24 @@ static void exitWithError(Error E, StringRef Whence = "") {
481480
// Hint in case user missed specifying the profile type.
482481
Hint = "Perhaps you forgot to use the --sample or --memory option?";
483482
}
484-
exitWithError(IPE.message(), std::string(Whence), std::string(Hint));
483+
exitWithError(IPE.message(), Whence, Hint);
485484
});
486485
return;
487486
}
488487

489-
exitWithError(toString(std::move(E)), std::string(Whence));
488+
exitWithError(toString(std::move(E)), Whence);
490489
}
491490

492491
static void exitWithErrorCode(std::error_code EC, StringRef Whence = "") {
493-
exitWithError(EC.message(), std::string(Whence));
492+
exitWithError(EC.message(), Whence);
494493
}
495494

496495
static void warnOrExitGivenError(FailureMode FailMode, std::error_code EC,
497496
StringRef Whence = "") {
498497
if (FailMode == failIfAnyAreInvalid)
499498
exitWithErrorCode(EC, Whence);
500499
else
501-
warn(EC.message(), std::string(Whence));
500+
warn(EC.message(), Whence);
502501
}
503502

504503
static void handleMergeWriterError(Error E, StringRef WhenceFile = "",
@@ -1585,7 +1584,7 @@ static void mergeSampleProfile(const WeightedFileVector &Inputs,
15851584
// If OutputSizeLimit is 0 (default), it is the same as write().
15861585
if (std::error_code EC =
15871586
Writer->writeWithSizeLimit(ProfileMap, OutputSizeLimit))
1588-
exitWithErrorCode(std::move(EC));
1587+
exitWithErrorCode(EC);
15891588
}
15901589

15911590
static WeightedFile parseWeightedFile(const StringRef &WeightedFilename) {

0 commit comments

Comments
 (0)