16
16
#include " llvm/Debuginfod/HTTPClient.h"
17
17
#include " llvm/IR/LLVMContext.h"
18
18
#include " llvm/Object/Binary.h"
19
- #include " llvm/ProfileData/DataAccessProf.h"
20
19
#include " llvm/ProfileData/InstrProfCorrelator.h"
21
20
#include " llvm/ProfileData/InstrProfReader.h"
22
21
#include " llvm/ProfileData/InstrProfWriter.h"
@@ -54,23 +53,23 @@ using ProfCorrelatorKind = InstrProfCorrelator::ProfCorrelatorKind;
54
53
55
54
// https://llvm.org/docs/CommandGuide/llvm-profdata.html has documentations
56
55
// on each subcommand.
57
- cl::SubCommand ShowSubcommand (
56
+ static cl::SubCommand ShowSubcommand (
58
57
" show" ,
59
58
" Takes a profile data file and displays the profiles. See detailed "
60
59
" documentation in "
61
60
" https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-show" );
62
- cl::SubCommand OrderSubcommand (
61
+ static cl::SubCommand OrderSubcommand (
63
62
" order" ,
64
63
" Reads temporal profiling traces from a profile and outputs a function "
65
64
" order that reduces the number of page faults for those traces. See "
66
65
" detailed documentation in "
67
66
" https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-order" );
68
- cl::SubCommand OverlapSubcommand (
67
+ static cl::SubCommand OverlapSubcommand (
69
68
" overlap" ,
70
69
" Computes and displays the overlap between two profiles. See detailed "
71
70
" documentation in "
72
71
" https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-overlap" );
73
- cl::SubCommand MergeSubcommand (
72
+ static cl::SubCommand MergeSubcommand (
74
73
" merge" ,
75
74
" Takes several profiles and merge them together. See detailed "
76
75
" documentation in "
@@ -93,12 +92,11 @@ enum class ShowFormat { Text, Json, Yaml };
93
92
} // namespace
94
93
95
94
// Common options.
96
- cl::opt<std::string> OutputFilename (" output" , cl::value_desc(" output" ),
97
- cl::init(" -" ), cl::desc(" Output file" ),
98
- cl::sub(ShowSubcommand),
99
- cl::sub(OrderSubcommand),
100
- cl::sub(OverlapSubcommand),
101
- cl::sub(MergeSubcommand));
95
+ static cl::opt<std::string>
96
+ OutputFilename (" output" , cl::value_desc(" output" ), cl::init(" -" ),
97
+ cl::desc(" Output file" ), cl::sub(ShowSubcommand),
98
+ cl::sub(OrderSubcommand), cl::sub(OverlapSubcommand),
99
+ cl::sub(MergeSubcommand));
102
100
// NOTE: cl::alias must not have cl::sub(), since aliased option's cl::sub()
103
101
// will be used. llvm::cl::alias::done() method asserts this condition.
104
102
static cl::alias OutputFilenameA (" o" , cl::desc(" Alias for --output" ),
@@ -528,9 +526,9 @@ static void exitWithError(Twine Message, StringRef Whence = "",
528
526
static void exitWithError (Error E, StringRef Whence = " " ) {
529
527
if (E.isA <InstrProfError>()) {
530
528
handleAllErrors (std::move (E), [&](const InstrProfError &IPE) {
531
- instrprof_error instrError = IPE.get ();
529
+ instrprof_error InstrError = IPE.get ();
532
530
StringRef Hint = " " ;
533
- if (instrError == instrprof_error::unrecognized_format) {
531
+ if (InstrError == instrprof_error::unrecognized_format) {
534
532
// Hint in case user missed specifying the profile type.
535
533
Hint = " Perhaps you forgot to use the --sample or --memory option?" ;
536
534
}
@@ -637,7 +635,7 @@ class SymbolRemapper {
637
635
return New.empty () ? Name : FunctionId (New);
638
636
}
639
637
};
640
- }
638
+ } // namespace
641
639
642
640
struct WeightedFile {
643
641
std::string Filename;
@@ -827,18 +825,18 @@ loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
827
825
// Only show hint the first time an error occurs.
828
826
auto [ErrCode, Msg] = InstrProfError::take (std::move (E));
829
827
std::unique_lock<std::mutex> ErrGuard{WC->ErrLock };
830
- bool firstTime = WC->WriterErrorCodes .insert (ErrCode).second ;
828
+ bool FirstTime = WC->WriterErrorCodes .insert (ErrCode).second ;
831
829
handleMergeWriterError (make_error<InstrProfError>(ErrCode, Msg),
832
- Input.Filename , FuncName, firstTime );
830
+ Input.Filename , FuncName, FirstTime );
833
831
});
834
832
}
835
833
836
834
if (KeepVTableSymbols) {
837
- const InstrProfSymtab &symtab = Reader->getSymtab ();
838
- const auto &VTableNames = symtab .getVTableNames ();
835
+ const InstrProfSymtab &Symtab = Reader->getSymtab ();
836
+ const auto &VTableNames = Symtab .getVTableNames ();
839
837
840
- for (const auto &kv : VTableNames)
841
- WC->Writer .addVTableName (kv .getKey ());
838
+ for (const auto &KV : VTableNames)
839
+ WC->Writer .addVTableName (KV .getKey ());
842
840
}
843
841
844
842
if (Reader->hasTemporalProfile ()) {
@@ -879,8 +877,8 @@ static void mergeWriterContexts(WriterContext *Dst, WriterContext *Src) {
879
877
Dst->Writer .mergeRecordsFromWriter (std::move (Src->Writer ), [&](Error E) {
880
878
auto [ErrorCode, Msg] = InstrProfError::take (std::move (E));
881
879
std::unique_lock<std::mutex> ErrGuard{Dst->ErrLock };
882
- bool firstTime = Dst->WriterErrorCodes .insert (ErrorCode).second ;
883
- if (firstTime )
880
+ bool FirstTime = Dst->WriterErrorCodes .insert (ErrorCode).second ;
881
+ if (FirstTime )
884
882
warn (toString (make_error<InstrProfError>(ErrorCode, Msg)));
885
883
});
886
884
}
@@ -890,34 +888,32 @@ getFuncName(const StringMap<InstrProfWriter::ProfilingData>::value_type &Val) {
890
888
return Val.first ();
891
889
}
892
890
893
- static std::string
894
- getFuncName (const SampleProfileMap::value_type &Val) {
891
+ static std::string getFuncName (const SampleProfileMap::value_type &Val) {
895
892
return Val.second .getContext ().toString ();
896
893
}
897
894
898
- template <typename T>
899
- static void filterFunctions (T &ProfileMap) {
900
- bool hasFilter = !FuncNameFilter.empty ();
901
- bool hasNegativeFilter = !FuncNameNegativeFilter.empty ();
902
- if (!hasFilter && !hasNegativeFilter)
895
+ template <typename T> static void filterFunctions (T &ProfileMap) {
896
+ bool HasFilter = !FuncNameFilter.empty ();
897
+ bool HasNegativeFilter = !FuncNameNegativeFilter.empty ();
898
+ if (!HasFilter && !HasNegativeFilter)
903
899
return ;
904
900
905
901
// If filter starts with '?' it is MSVC mangled name, not a regex.
906
902
llvm::Regex ProbablyMSVCMangledName (" [?@$_0-9A-Za-z]+" );
907
- if (hasFilter && FuncNameFilter[0 ] == ' ?' &&
903
+ if (HasFilter && FuncNameFilter[0 ] == ' ?' &&
908
904
ProbablyMSVCMangledName.match (FuncNameFilter))
909
905
FuncNameFilter = llvm::Regex::escape (FuncNameFilter);
910
- if (hasNegativeFilter && FuncNameNegativeFilter[0 ] == ' ?' &&
906
+ if (HasNegativeFilter && FuncNameNegativeFilter[0 ] == ' ?' &&
911
907
ProbablyMSVCMangledName.match (FuncNameNegativeFilter))
912
908
FuncNameNegativeFilter = llvm::Regex::escape (FuncNameNegativeFilter);
913
909
914
910
size_t Count = ProfileMap.size ();
915
911
llvm::Regex Pattern (FuncNameFilter);
916
912
llvm::Regex NegativePattern (FuncNameNegativeFilter);
917
913
std::string Error;
918
- if (hasFilter && !Pattern.isValid (Error))
914
+ if (HasFilter && !Pattern.isValid (Error))
919
915
exitWithError (Error);
920
- if (hasNegativeFilter && !NegativePattern.isValid (Error))
916
+ if (HasNegativeFilter && !NegativePattern.isValid (Error))
921
917
exitWithError (Error);
922
918
923
919
// Handle MD5 profile, so it is still able to match using the original name.
@@ -929,10 +925,10 @@ static void filterFunctions(T &ProfileMap) {
929
925
auto Tmp = I++;
930
926
const auto &FuncName = getFuncName (*Tmp);
931
927
// Negative filter has higher precedence than positive filter.
932
- if ((hasNegativeFilter &&
928
+ if ((HasNegativeFilter &&
933
929
(NegativePattern.match (FuncName) ||
934
930
(FunctionSamples::UseMD5 && NegativeMD5Name == FuncName))) ||
935
- (hasFilter && !(Pattern.match (FuncName) ||
931
+ (HasFilter && !(Pattern.match (FuncName) ||
936
932
(FunctionSamples::UseMD5 && MD5Name == FuncName))))
937
933
ProfileMap.erase (Tmp);
938
934
}
@@ -1193,7 +1189,7 @@ adjustInstrProfile(std::unique_ptr<WriterContext> &WC,
1193
1189
StringMap<StringRef> StaticFuncMap;
1194
1190
InstrProfSummaryBuilder IPBuilder (ProfileSummaryBuilder::DefaultCutoffs);
1195
1191
1196
- auto checkSampleProfileHasFUnique = [&Reader]() {
1192
+ auto CheckSampleProfileHasFUnique = [&Reader]() {
1197
1193
for (const auto &PD : Reader->getProfiles ()) {
1198
1194
auto &FContext = PD.second .getContext ();
1199
1195
if (FContext.toString ().find (FunctionSamples::UniqSuffix) !=
@@ -1204,9 +1200,9 @@ adjustInstrProfile(std::unique_ptr<WriterContext> &WC,
1204
1200
return false ;
1205
1201
};
1206
1202
1207
- bool SampleProfileHasFUnique = checkSampleProfileHasFUnique ();
1203
+ bool SampleProfileHasFUnique = CheckSampleProfileHasFUnique ();
1208
1204
1209
- auto buildStaticFuncMap = [&StaticFuncMap,
1205
+ auto BuildStaticFuncMap = [&StaticFuncMap,
1210
1206
SampleProfileHasFUnique](const StringRef Name) {
1211
1207
std::string FilePrefixes[] = {" .cpp" , " cc" , " .c" , " .hpp" , " .h" };
1212
1208
size_t PrefixPos = StringRef::npos;
@@ -1366,7 +1362,7 @@ adjustInstrProfile(std::unique_ptr<WriterContext> &WC,
1366
1362
InstrProfRecord *R = &PD.getValue ().begin ()->second ;
1367
1363
StringRef FullName = PD.getKey ();
1368
1364
InstrProfileMap[FullName] = InstrProfileEntry (R);
1369
- buildStaticFuncMap (FullName);
1365
+ BuildStaticFuncMap (FullName);
1370
1366
}
1371
1367
1372
1368
for (auto &PD : Reader->getProfiles ()) {
@@ -1497,8 +1493,8 @@ remapSamples(const sampleprof::FunctionSamples &Samples,
1497
1493
BodySample.second .getSamples ());
1498
1494
for (const auto &Target : BodySample.second .getCallTargets ()) {
1499
1495
Result.addCalledTargetSamples (BodySample.first .LineOffset ,
1500
- MaskedDiscriminator,
1501
- Remapper (Target. first ), Target.second );
1496
+ MaskedDiscriminator, Remapper (Target. first ),
1497
+ Target.second );
1502
1498
}
1503
1499
}
1504
1500
for (const auto &CallsiteSamples : Samples.getCallsiteSamples ()) {
@@ -1759,7 +1755,7 @@ static void parseInputFilenamesFile(MemoryBuffer *Buffer,
1759
1755
if (SanitizedEntry.starts_with (" #" ))
1760
1756
continue ;
1761
1757
// If there's no comma, it's an unweighted profile.
1762
- else if (!SanitizedEntry.contains (' ,' ))
1758
+ if (!SanitizedEntry.contains (' ,' ))
1763
1759
addWeightedInput (WFV, {std::string (SanitizedEntry), 1 });
1764
1760
else
1765
1761
addWeightedInput (WFV, parseWeightedFile (SanitizedEntry));
@@ -2740,10 +2736,11 @@ std::error_code SampleOverlapAggregator::loadProfiles() {
2740
2736
return std::error_code ();
2741
2737
}
2742
2738
2743
- void overlapSampleProfile (const std::string &BaseFilename,
2744
- const std::string &TestFilename,
2745
- const OverlapFuncFilters &FuncFilter,
2746
- uint64_t SimilarityCutoff, raw_fd_ostream &OS) {
2739
+ static void overlapSampleProfile (const std::string &BaseFilename,
2740
+ const std::string &TestFilename,
2741
+ const OverlapFuncFilters &FuncFilter,
2742
+ uint64_t SimilarityCutoff,
2743
+ raw_fd_ostream &OS) {
2747
2744
using namespace sampleprof ;
2748
2745
2749
2746
// We use 0.000005 to initialize OverlapAggr.Epsilon because the final metrics
@@ -2883,17 +2880,15 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
2883
2880
OS << " :ir\n " ;
2884
2881
2885
2882
for (const auto &Func : *Reader) {
2886
- if (Reader-> isIRLevelProfile () ) {
2883
+ if (IsIRInstr ) {
2887
2884
bool FuncIsCS = NamedInstrProfRecord::hasCSFlagInHash (Func.Hash );
2888
2885
if (FuncIsCS != ShowCS)
2889
2886
continue ;
2890
2887
}
2891
2888
bool Show = ShowAllFunctions ||
2892
2889
(!FuncNameFilter.empty () && Func.Name .contains (FuncNameFilter));
2893
2890
2894
- bool doTextFormatDump = (Show && TextFormat);
2895
-
2896
- if (doTextFormatDump) {
2891
+ if (Show && TextFormat) {
2897
2892
InstrProfSymtab &Symtab = Reader->getSymtab ();
2898
2893
InstrProfWriter::writeRecordInText (Func.Name , Func.Hash , Func, Symtab,
2899
2894
OS);
@@ -2931,9 +2926,9 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
2931
2926
continue ;
2932
2927
}
2933
2928
2934
- for (size_t I = 0 , E = Func.Counts . size (); I < E; ++I ) {
2935
- FuncMax = std::max (FuncMax, Func. Counts [I] );
2936
- FuncSum += Func. Counts [I] ;
2929
+ for (const auto &Count : Func.Counts ) {
2930
+ FuncMax = std::max (FuncMax, Count );
2931
+ FuncSum += Count ;
2937
2932
}
2938
2933
2939
2934
if (FuncMax < ShowValueCutoff) {
@@ -2943,7 +2938,8 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
2943
2938
<< " Sum = " << FuncSum << " )\n " ;
2944
2939
}
2945
2940
continue ;
2946
- } else if (OnlyListBelow)
2941
+ }
2942
+ if (OnlyListBelow)
2947
2943
continue ;
2948
2944
2949
2945
if (TopNFunctions) {
@@ -3017,9 +3013,8 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
3017
3013
if (TextFormat || ShowCovered)
3018
3014
return 0 ;
3019
3015
std::unique_ptr<ProfileSummary> PS (Builder.getSummary ());
3020
- bool IsIR = Reader->isIRLevelProfile ();
3021
- OS << " Instrumentation level: " << (IsIR ? " IR" : " Front-end" );
3022
- if (IsIR) {
3016
+ OS << " Instrumentation level: " << (IsIRInstr ? " IR" : " Front-end" );
3017
+ if (IsIRInstr) {
3023
3018
OS << " entry_first = " << Reader->instrEntryBBEnabled ();
3024
3019
OS << " instrument_loop_entries = " << Reader->instrLoopEntriesEnabled ();
3025
3020
}
@@ -3076,10 +3071,10 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
3076
3071
auto &Traces = Reader->getTemporalProfTraces ();
3077
3072
OS << " Temporal Profile Traces (samples=" << Traces.size ()
3078
3073
<< " seen=" << Reader->getTemporalProfTraceStreamSize () << " ):\n " ;
3079
- for (unsigned i = 0 ; i < Traces. size (); i++ ) {
3080
- OS << " Temporal Profile Trace " << i << " (weight=" << Traces[i] .Weight
3081
- << " count=" << Traces[i] .FunctionNameRefs .size () << " ):\n " ;
3082
- for (auto &NameRef : Traces[i] .FunctionNameRefs )
3074
+ for (auto [Index, Trace] : llvm::enumerate (Traces) ) {
3075
+ OS << " Temporal Profile Trace " << Index << " (weight=" << Trace .Weight
3076
+ << " count=" << Trace .FunctionNameRefs .size () << " ):\n " ;
3077
+ for (auto &NameRef : Trace .FunctionNameRefs )
3083
3078
OS << " " << Reader->getSymtab ().getFuncOrVarName (NameRef) << " \n " ;
3084
3079
}
3085
3080
}
@@ -3392,7 +3387,8 @@ static int show_main(StringRef ProgName) {
3392
3387
exitWithErrorCode (EC, OutputFilename);
3393
3388
3394
3389
if (ShowAllFunctions && !FuncNameFilter.empty ())
3395
- WithColor::warning () << " -function argument ignored: showing all functions\n " ;
3390
+ WithColor::warning ()
3391
+ << " -function argument ignored: showing all functions\n " ;
3396
3392
3397
3393
if (!DebugInfoFilename.empty ())
3398
3394
return showDebugInfoCorrelation (DebugInfoFilename, SFormat, OS);
0 commit comments