Skip to content

Commit 7b5d8a0

Browse files
authored
Revert "[NFC][profdata] Apply lints and other format fixes" (#149601)
Reverts #149433 This broke the hwasan buildbot: https://lab.llvm.org/buildbot/#/builders/55/builds/14455
1 parent b9aa06f commit 7b5d8a0

File tree

1 file changed

+62
-58
lines changed

1 file changed

+62
-58
lines changed

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

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/Debuginfod/HTTPClient.h"
1717
#include "llvm/IR/LLVMContext.h"
1818
#include "llvm/Object/Binary.h"
19+
#include "llvm/ProfileData/DataAccessProf.h"
1920
#include "llvm/ProfileData/InstrProfCorrelator.h"
2021
#include "llvm/ProfileData/InstrProfReader.h"
2122
#include "llvm/ProfileData/InstrProfWriter.h"
@@ -52,23 +53,23 @@ using ProfCorrelatorKind = InstrProfCorrelator::ProfCorrelatorKind;
5253

5354
// https://llvm.org/docs/CommandGuide/llvm-profdata.html has documentations
5455
// on each subcommand.
55-
static cl::SubCommand ShowSubcommand(
56+
cl::SubCommand ShowSubcommand(
5657
"show",
5758
"Takes a profile data file and displays the profiles. See detailed "
5859
"documentation in "
5960
"https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-show");
60-
static cl::SubCommand OrderSubcommand(
61+
cl::SubCommand OrderSubcommand(
6162
"order",
6263
"Reads temporal profiling traces from a profile and outputs a function "
6364
"order that reduces the number of page faults for those traces. See "
6465
"detailed documentation in "
6566
"https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-order");
66-
static cl::SubCommand OverlapSubcommand(
67+
cl::SubCommand OverlapSubcommand(
6768
"overlap",
6869
"Computes and displays the overlap between two profiles. See detailed "
6970
"documentation in "
7071
"https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-overlap");
71-
static cl::SubCommand MergeSubcommand(
72+
cl::SubCommand MergeSubcommand(
7273
"merge",
7374
"Takes several profiles and merge them together. See detailed "
7475
"documentation in "
@@ -91,11 +92,12 @@ enum class ShowFormat { Text, Json, Yaml };
9192
} // namespace
9293

9394
// Common options.
94-
static cl::opt<std::string>
95-
OutputFilename("output", cl::value_desc("output"), cl::init("-"),
96-
cl::desc("Output file"), cl::sub(ShowSubcommand),
97-
cl::sub(OrderSubcommand), cl::sub(OverlapSubcommand),
98-
cl::sub(MergeSubcommand));
95+
cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
96+
cl::init("-"), cl::desc("Output file"),
97+
cl::sub(ShowSubcommand),
98+
cl::sub(OrderSubcommand),
99+
cl::sub(OverlapSubcommand),
100+
cl::sub(MergeSubcommand));
99101
// NOTE: cl::alias must not have cl::sub(), since aliased option's cl::sub()
100102
// will be used. llvm::cl::alias::done() method asserts this condition.
101103
static cl::alias OutputFilenameA("o", cl::desc("Alias for --output"),
@@ -525,9 +527,9 @@ static void exitWithError(Twine Message, StringRef Whence = "",
525527
static void exitWithError(Error E, StringRef Whence = "") {
526528
if (E.isA<InstrProfError>()) {
527529
handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {
528-
instrprof_error InstrError = IPE.get();
530+
instrprof_error instrError = IPE.get();
529531
StringRef Hint = "";
530-
if (InstrError == instrprof_error::unrecognized_format) {
532+
if (instrError == instrprof_error::unrecognized_format) {
531533
// Hint in case user missed specifying the profile type.
532534
Hint = "Perhaps you forgot to use the --sample or --memory option?";
533535
}
@@ -634,7 +636,7 @@ class SymbolRemapper {
634636
return New.empty() ? Name : FunctionId(New);
635637
}
636638
};
637-
} // namespace
639+
}
638640

639641
struct WeightedFile {
640642
std::string Filename;
@@ -824,18 +826,18 @@ loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
824826
// Only show hint the first time an error occurs.
825827
auto [ErrCode, Msg] = InstrProfError::take(std::move(E));
826828
std::unique_lock<std::mutex> ErrGuard{WC->ErrLock};
827-
bool FirstTime = WC->WriterErrorCodes.insert(ErrCode).second;
829+
bool firstTime = WC->WriterErrorCodes.insert(ErrCode).second;
828830
handleMergeWriterError(make_error<InstrProfError>(ErrCode, Msg),
829-
Input.Filename, FuncName, FirstTime);
831+
Input.Filename, FuncName, firstTime);
830832
});
831833
}
832834

833835
if (KeepVTableSymbols) {
834-
const InstrProfSymtab &Symtab = Reader->getSymtab();
835-
const auto &VTableNames = Symtab.getVTableNames();
836+
const InstrProfSymtab &symtab = Reader->getSymtab();
837+
const auto &VTableNames = symtab.getVTableNames();
836838

837-
for (const auto &KV : VTableNames)
838-
WC->Writer.addVTableName(KV.getKey());
839+
for (const auto &kv : VTableNames)
840+
WC->Writer.addVTableName(kv.getKey());
839841
}
840842

841843
if (Reader->hasTemporalProfile()) {
@@ -876,8 +878,8 @@ static void mergeWriterContexts(WriterContext *Dst, WriterContext *Src) {
876878
Dst->Writer.mergeRecordsFromWriter(std::move(Src->Writer), [&](Error E) {
877879
auto [ErrorCode, Msg] = InstrProfError::take(std::move(E));
878880
std::unique_lock<std::mutex> ErrGuard{Dst->ErrLock};
879-
bool FirstTime = Dst->WriterErrorCodes.insert(ErrorCode).second;
880-
if (FirstTime)
881+
bool firstTime = Dst->WriterErrorCodes.insert(ErrorCode).second;
882+
if (firstTime)
881883
warn(toString(make_error<InstrProfError>(ErrorCode, Msg)));
882884
});
883885
}
@@ -887,32 +889,34 @@ getFuncName(const StringMap<InstrProfWriter::ProfilingData>::value_type &Val) {
887889
return Val.first();
888890
}
889891

890-
static std::string getFuncName(const SampleProfileMap::value_type &Val) {
892+
static std::string
893+
getFuncName(const SampleProfileMap::value_type &Val) {
891894
return Val.second.getContext().toString();
892895
}
893896

894-
template <typename T> static void filterFunctions(T &ProfileMap) {
895-
bool HasFilter = !FuncNameFilter.empty();
896-
bool HasNegativeFilter = !FuncNameNegativeFilter.empty();
897-
if (!HasFilter && !HasNegativeFilter)
897+
template <typename T>
898+
static void filterFunctions(T &ProfileMap) {
899+
bool hasFilter = !FuncNameFilter.empty();
900+
bool hasNegativeFilter = !FuncNameNegativeFilter.empty();
901+
if (!hasFilter && !hasNegativeFilter)
898902
return;
899903

900904
// If filter starts with '?' it is MSVC mangled name, not a regex.
901905
llvm::Regex ProbablyMSVCMangledName("[?@$_0-9A-Za-z]+");
902-
if (HasFilter && FuncNameFilter[0] == '?' &&
906+
if (hasFilter && FuncNameFilter[0] == '?' &&
903907
ProbablyMSVCMangledName.match(FuncNameFilter))
904908
FuncNameFilter = llvm::Regex::escape(FuncNameFilter);
905-
if (HasNegativeFilter && FuncNameNegativeFilter[0] == '?' &&
909+
if (hasNegativeFilter && FuncNameNegativeFilter[0] == '?' &&
906910
ProbablyMSVCMangledName.match(FuncNameNegativeFilter))
907911
FuncNameNegativeFilter = llvm::Regex::escape(FuncNameNegativeFilter);
908912

909913
size_t Count = ProfileMap.size();
910914
llvm::Regex Pattern(FuncNameFilter);
911915
llvm::Regex NegativePattern(FuncNameNegativeFilter);
912916
std::string Error;
913-
if (HasFilter && !Pattern.isValid(Error))
917+
if (hasFilter && !Pattern.isValid(Error))
914918
exitWithError(Error);
915-
if (HasNegativeFilter && !NegativePattern.isValid(Error))
919+
if (hasNegativeFilter && !NegativePattern.isValid(Error))
916920
exitWithError(Error);
917921

918922
// Handle MD5 profile, so it is still able to match using the original name.
@@ -924,10 +928,10 @@ template <typename T> static void filterFunctions(T &ProfileMap) {
924928
auto Tmp = I++;
925929
const auto &FuncName = getFuncName(*Tmp);
926930
// Negative filter has higher precedence than positive filter.
927-
if ((HasNegativeFilter &&
931+
if ((hasNegativeFilter &&
928932
(NegativePattern.match(FuncName) ||
929933
(FunctionSamples::UseMD5 && NegativeMD5Name == FuncName))) ||
930-
(HasFilter && !(Pattern.match(FuncName) ||
934+
(hasFilter && !(Pattern.match(FuncName) ||
931935
(FunctionSamples::UseMD5 && MD5Name == FuncName))))
932936
ProfileMap.erase(Tmp);
933937
}
@@ -1188,7 +1192,7 @@ adjustInstrProfile(std::unique_ptr<WriterContext> &WC,
11881192
StringMap<StringRef> StaticFuncMap;
11891193
InstrProfSummaryBuilder IPBuilder(ProfileSummaryBuilder::DefaultCutoffs);
11901194

1191-
auto CheckSampleProfileHasFUnique = [&Reader]() {
1195+
auto checkSampleProfileHasFUnique = [&Reader]() {
11921196
for (const auto &PD : Reader->getProfiles()) {
11931197
auto &FContext = PD.second.getContext();
11941198
if (FContext.toString().find(FunctionSamples::UniqSuffix) !=
@@ -1199,9 +1203,9 @@ adjustInstrProfile(std::unique_ptr<WriterContext> &WC,
11991203
return false;
12001204
};
12011205

1202-
bool SampleProfileHasFUnique = CheckSampleProfileHasFUnique();
1206+
bool SampleProfileHasFUnique = checkSampleProfileHasFUnique();
12031207

1204-
auto BuildStaticFuncMap = [&StaticFuncMap,
1208+
auto buildStaticFuncMap = [&StaticFuncMap,
12051209
SampleProfileHasFUnique](const StringRef Name) {
12061210
std::string FilePrefixes[] = {".cpp", "cc", ".c", ".hpp", ".h"};
12071211
size_t PrefixPos = StringRef::npos;
@@ -1361,7 +1365,7 @@ adjustInstrProfile(std::unique_ptr<WriterContext> &WC,
13611365
InstrProfRecord *R = &PD.getValue().begin()->second;
13621366
StringRef FullName = PD.getKey();
13631367
InstrProfileMap[FullName] = InstrProfileEntry(R);
1364-
BuildStaticFuncMap(FullName);
1368+
buildStaticFuncMap(FullName);
13651369
}
13661370

13671371
for (auto &PD : Reader->getProfiles()) {
@@ -1492,8 +1496,8 @@ remapSamples(const sampleprof::FunctionSamples &Samples,
14921496
BodySample.second.getSamples());
14931497
for (const auto &Target : BodySample.second.getCallTargets()) {
14941498
Result.addCalledTargetSamples(BodySample.first.LineOffset,
1495-
MaskedDiscriminator, Remapper(Target.first),
1496-
Target.second);
1499+
MaskedDiscriminator,
1500+
Remapper(Target.first), Target.second);
14971501
}
14981502
}
14991503
for (const auto &CallsiteSamples : Samples.getCallsiteSamples()) {
@@ -1754,7 +1758,7 @@ static void parseInputFilenamesFile(MemoryBuffer *Buffer,
17541758
if (SanitizedEntry.starts_with("#"))
17551759
continue;
17561760
// If there's no comma, it's an unweighted profile.
1757-
if (!SanitizedEntry.contains(','))
1761+
else if (!SanitizedEntry.contains(','))
17581762
addWeightedInput(WFV, {std::string(SanitizedEntry), 1});
17591763
else
17601764
addWeightedInput(WFV, parseWeightedFile(SanitizedEntry));
@@ -2735,11 +2739,10 @@ std::error_code SampleOverlapAggregator::loadProfiles() {
27352739
return std::error_code();
27362740
}
27372741

2738-
static void overlapSampleProfile(const std::string &BaseFilename,
2739-
const std::string &TestFilename,
2740-
const OverlapFuncFilters &FuncFilter,
2741-
uint64_t SimilarityCutoff,
2742-
raw_fd_ostream &OS) {
2742+
void overlapSampleProfile(const std::string &BaseFilename,
2743+
const std::string &TestFilename,
2744+
const OverlapFuncFilters &FuncFilter,
2745+
uint64_t SimilarityCutoff, raw_fd_ostream &OS) {
27432746
using namespace sampleprof;
27442747

27452748
// We use 0.000005 to initialize OverlapAggr.Epsilon because the final metrics
@@ -2870,15 +2873,17 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
28702873
OS << ":ir\n";
28712874

28722875
for (const auto &Func : *Reader) {
2873-
if (IsIRInstr) {
2876+
if (Reader->isIRLevelProfile()) {
28742877
bool FuncIsCS = NamedInstrProfRecord::hasCSFlagInHash(Func.Hash);
28752878
if (FuncIsCS != ShowCS)
28762879
continue;
28772880
}
28782881
bool Show = ShowAllFunctions ||
28792882
(!FuncNameFilter.empty() && Func.Name.contains(FuncNameFilter));
28802883

2881-
if (Show && TextFormat) {
2884+
bool doTextFormatDump = (Show && TextFormat);
2885+
2886+
if (doTextFormatDump) {
28822887
InstrProfSymtab &Symtab = Reader->getSymtab();
28832888
InstrProfWriter::writeRecordInText(Func.Name, Func.Hash, Func, Symtab,
28842889
OS);
@@ -2916,9 +2921,9 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
29162921
continue;
29172922
}
29182923

2919-
for (const auto &Count : Func.Counts) {
2920-
FuncMax = std::max(FuncMax, Count);
2921-
FuncSum += Count;
2924+
for (size_t I = 0, E = Func.Counts.size(); I < E; ++I) {
2925+
FuncMax = std::max(FuncMax, Func.Counts[I]);
2926+
FuncSum += Func.Counts[I];
29222927
}
29232928

29242929
if (FuncMax < ShowValueCutoff) {
@@ -2928,8 +2933,7 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
29282933
<< " Sum = " << FuncSum << ")\n";
29292934
}
29302935
continue;
2931-
}
2932-
if (OnlyListBelow)
2936+
} else if (OnlyListBelow)
29332937
continue;
29342938

29352939
if (TopNFunctions || ShowHotFuncList)
@@ -2996,8 +3000,9 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
29963000
if (TextFormat || ShowCovered)
29973001
return 0;
29983002
std::unique_ptr<ProfileSummary> PS(Builder.getSummary());
2999-
OS << "Instrumentation level: " << (IsIRInstr ? "IR" : "Front-end");
3000-
if (IsIRInstr) {
3003+
bool IsIR = Reader->isIRLevelProfile();
3004+
OS << "Instrumentation level: " << (IsIR ? "IR" : "Front-end");
3005+
if (IsIR) {
30013006
OS << " entry_first = " << Reader->instrEntryBBEnabled();
30023007
OS << " instrument_loop_entries = " << Reader->instrLoopEntriesEnabled();
30033008
}
@@ -3065,10 +3070,10 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
30653070
auto &Traces = Reader->getTemporalProfTraces();
30663071
OS << "Temporal Profile Traces (samples=" << Traces.size()
30673072
<< " seen=" << Reader->getTemporalProfTraceStreamSize() << "):\n";
3068-
for (auto [Index, Trace] : llvm::enumerate(Traces)) {
3069-
OS << " Temporal Profile Trace " << Index << " (weight=" << Trace.Weight
3070-
<< " count=" << Trace.FunctionNameRefs.size() << "):\n";
3071-
for (auto &NameRef : Trace.FunctionNameRefs)
3073+
for (unsigned i = 0; i < Traces.size(); i++) {
3074+
OS << " Temporal Profile Trace " << i << " (weight=" << Traces[i].Weight
3075+
<< " count=" << Traces[i].FunctionNameRefs.size() << "):\n";
3076+
for (auto &NameRef : Traces[i].FunctionNameRefs)
30723077
OS << " " << Reader->getSymtab().getFuncOrVarName(NameRef) << "\n";
30733078
}
30743079
}
@@ -3381,8 +3386,7 @@ static int show_main(StringRef ProgName) {
33813386
exitWithErrorCode(EC, OutputFilename);
33823387

33833388
if (ShowAllFunctions && !FuncNameFilter.empty())
3384-
WithColor::warning()
3385-
<< "-function argument ignored: showing all functions\n";
3389+
WithColor::warning() << "-function argument ignored: showing all functions\n";
33863390

33873391
if (!DebugInfoFilename.empty())
33883392
return showDebugInfoCorrelation(DebugInfoFilename, SFormat, OS);

0 commit comments

Comments
 (0)