Skip to content

Commit 6a1ba86

Browse files
committed
llvm-profgen: Options cleanup / fixes
- Add cl::cat(ProfGenCategory) where missing so the options show up in --help output. - Introduce `Options.h` to shared declarations for options referenced in multiple files.
1 parent efcedbf commit 6a1ba86

File tree

7 files changed

+111
-68
lines changed

7 files changed

+111
-68
lines changed

llvm/tools/llvm-profgen/MissingFrameInferrer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "MissingFrameInferrer.h"
10+
#include "Options.h"
1011
#include "PerfReader.h"
1112
#include "ProfiledBinary.h"
1213
#include "llvm/ADT/SCCIterator.h"
@@ -37,7 +38,8 @@ STATISTIC(TailCallMaxTailCallPath, "Length of the longest tail call path");
3738
static cl::opt<uint32_t>
3839
MaximumSearchDepth("max-search-depth", cl::init(UINT32_MAX - 1),
3940
cl::desc("The maximum levels the DFS-based missing "
40-
"frame search should go with"));
41+
"frame search should go with"),
42+
cl::cat(ProfGenCategory));
4143

4244
void MissingFrameInferrer::initialize(
4345
const ContextSampleCounterMap *SampleCounters) {

llvm/tools/llvm-profgen/Options.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===-- Options.h -----------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#ifndef LLVM_TOOLS_LLVM_PROFGEN_OPTIONS_H
9+
#define LLVM_TOOLS_LLVM_PROFGEN_OPTIONS_H
10+
11+
#include "llvm/Support/CommandLine.h"
12+
13+
namespace llvm {
14+
15+
extern cl::OptionCategory ProfGenCategory;
16+
17+
extern cl::opt<std::string> OutputFilename;
18+
extern cl::opt<bool> ShowDisassemblyOnly;
19+
extern cl::opt<bool> ShowSourceLocations;
20+
extern cl::opt<bool> SkipSymbolization;
21+
extern cl::opt<bool> ShowDetailedWarning;
22+
extern cl::opt<bool> InferMissingFrames;
23+
extern cl::opt<bool> EnableCSPreInliner;
24+
extern cl::opt<bool> UseContextCostForPreInliner;
25+
26+
} // end namespace llvm
27+
28+
#endif

llvm/tools/llvm-profgen/PerfReader.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88
#include "PerfReader.h"
9+
10+
#include "Options.h"
911
#include "ProfileGenerator.h"
1012
#include "llvm/ADT/SmallString.h"
1113
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
@@ -15,43 +17,47 @@
1517

1618
#define DEBUG_TYPE "perf-reader"
1719

18-
using namespace llvm;
20+
namespace llvm {
1921

2022
cl::opt<bool> SkipSymbolization("skip-symbolization",
2123
cl::desc("Dump the unsymbolized profile to the "
2224
"output file. It will show unwinder "
23-
"output for CS profile generation."));
25+
"output for CS profile generation."),
26+
cl::cat(ProfGenCategory));
2427

2528
static cl::opt<bool> ShowMmapEvents("show-mmap-events",
26-
cl::desc("Print binary load events."));
29+
cl::desc("Print binary load events."),
30+
cl::cat(ProfGenCategory));
2731

2832
static cl::opt<bool>
2933
UseOffset("use-offset", cl::init(true),
3034
cl::desc("Work with `--skip-symbolization` or "
3135
"`--unsymbolized-profile` to write/read the "
32-
"offset instead of virtual address."));
36+
"offset instead of virtual address."),
37+
cl::cat(ProfGenCategory));
3338

3439
static cl::opt<bool> UseLoadableSegmentAsBase(
3540
"use-first-loadable-segment-as-base",
3641
cl::desc("Use first loadable segment address as base address "
3742
"for offsets in unsymbolized profile. By default "
38-
"first executable segment address is used"));
43+
"first executable segment address is used"),
44+
cl::cat(ProfGenCategory));
3945

4046
static cl::opt<bool>
4147
IgnoreStackSamples("ignore-stack-samples",
4248
cl::desc("Ignore call stack samples for hybrid samples "
43-
"and produce context-insensitive profile."));
49+
"and produce context-insensitive profile."),
50+
cl::cat(ProfGenCategory));
4451
cl::opt<bool> ShowDetailedWarning("show-detailed-warning",
45-
cl::desc("Show detailed warning message."));
52+
cl::desc("Show detailed warning message."),
53+
cl::cat(ProfGenCategory));
4654

4755
static cl::opt<int> CSProfMaxUnsymbolizedCtxDepth(
4856
"csprof-max-unsymbolized-context-depth", cl::init(-1),
4957
cl::desc("Keep the last K contexts while merging unsymbolized profile. -1 "
50-
"means no depth limit."));
58+
"means no depth limit."),
59+
cl::cat(ProfGenCategory));
5160

52-
extern cl::opt<std::string> OutputFilename;
53-
54-
namespace llvm {
5561
namespace sampleprof {
5662

5763
void VirtualUnwinder::unwindCall(UnwindState &State) {

llvm/tools/llvm-profgen/ProfileGenerator.cpp

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "ProfileGenerator.h"
99
#include "ErrorHandling.h"
1010
#include "MissingFrameInferrer.h"
11+
#include "Options.h"
1112
#include "PerfReader.h"
1213
#include "ProfiledBinary.h"
1314
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
@@ -17,23 +18,24 @@
1718
#include <unordered_set>
1819
#include <utility>
1920

20-
using namespace llvm;
21-
using namespace sampleprof;
21+
namespace llvm {
2222

2323
cl::opt<std::string> OutputFilename("output", cl::value_desc("output"),
2424
cl::Required,
25-
cl::desc("Output profile file"));
25+
cl::desc("Output profile file"),
26+
cl::cat(ProfGenCategory));
2627
static cl::alias OutputA("o", cl::desc("Alias for --output"),
2728
cl::aliasopt(OutputFilename));
2829

2930
static cl::opt<SampleProfileFormat> OutputFormat(
3031
"format", cl::desc("Format of output profile"), cl::init(SPF_Ext_Binary),
31-
cl::values(
32-
clEnumValN(SPF_Binary, "binary", "Binary encoding (default)"),
33-
clEnumValN(SPF_Ext_Binary, "extbinary", "Extensible binary encoding"),
34-
clEnumValN(SPF_Text, "text", "Text encoding"),
35-
clEnumValN(SPF_GCC, "gcc",
36-
"GCC encoding (only meaningful for -sample)")));
32+
cl::values(clEnumValN(SPF_Binary, "binary", "Binary encoding (default)"),
33+
clEnumValN(SPF_Ext_Binary, "extbinary",
34+
"Extensible binary encoding"),
35+
clEnumValN(SPF_Text, "text", "Text encoding"),
36+
clEnumValN(SPF_GCC, "gcc",
37+
"GCC encoding (only meaningful for -sample)")),
38+
cl::cat(ProfGenCategory));
3739

3840
static cl::opt<bool> UseMD5(
3941
"use-md5", cl::Hidden,
@@ -59,55 +61,57 @@ static cl::opt<int32_t, true> RecursionCompression(
5961
static cl::opt<bool>
6062
TrimColdProfile("trim-cold-profile",
6163
cl::desc("If the total count of the profile is smaller "
62-
"than threshold, it will be trimmed."));
64+
"than threshold, it will be trimmed."),
65+
cl::cat(ProfGenCategory));
6366

6467
static cl::opt<bool> CSProfMergeColdContext(
6568
"csprof-merge-cold-context", cl::init(true),
6669
cl::desc("If the total count of context profile is smaller than "
6770
"the threshold, it will be merged into context-less base "
68-
"profile."));
71+
"profile."),
72+
cl::cat(ProfGenCategory));
6973

7074
static cl::opt<uint32_t> CSProfMaxColdContextDepth(
7175
"csprof-max-cold-context-depth", cl::init(1),
7276
cl::desc("Keep the last K contexts while merging cold profile. 1 means the "
73-
"context-less base profile"));
77+
"context-less base profile"),
78+
cl::cat(ProfGenCategory));
7479

7580
static cl::opt<int, true> CSProfMaxContextDepth(
7681
"csprof-max-context-depth",
7782
cl::desc("Keep the last K contexts while merging profile. -1 means no "
7883
"depth limit."),
79-
cl::location(llvm::sampleprof::CSProfileGenerator::MaxContextDepth));
84+
cl::location(llvm::sampleprof::CSProfileGenerator::MaxContextDepth),
85+
cl::cat(ProfGenCategory));
8086

8187
static cl::opt<double> ProfileDensityThreshold(
82-
"profile-density-threshold", llvm::cl::init(50),
83-
llvm::cl::desc("If the profile density is below the given threshold, it "
84-
"will be suggested to increase the sampling rate."),
85-
llvm::cl::Optional);
86-
static cl::opt<bool> ShowDensity("show-density", llvm::cl::init(false),
87-
llvm::cl::desc("show profile density details"),
88-
llvm::cl::Optional);
88+
"profile-density-threshold", cl::init(50),
89+
cl::desc("If the profile density is below the given threshold, it "
90+
"will be suggested to increase the sampling rate."),
91+
cl::Optional, cl::cat(ProfGenCategory));
92+
static cl::opt<bool> ShowDensity("show-density", cl::init(false),
93+
cl::desc("show profile density details"),
94+
cl::Optional, cl::cat(ProfGenCategory));
8995
static cl::opt<int> ProfileDensityCutOffHot(
90-
"profile-density-cutoff-hot", llvm::cl::init(990000),
91-
llvm::cl::desc("Total samples cutoff for functions used to calculate "
92-
"profile density."));
96+
"profile-density-cutoff-hot", cl::init(990000),
97+
cl::desc("Total samples cutoff for functions used to calculate "
98+
"profile density."),
99+
cl::cat(ProfGenCategory));
93100

94101
static cl::opt<bool> UpdateTotalSamples(
95-
"update-total-samples", llvm::cl::init(false),
96-
llvm::cl::desc(
97-
"Update total samples by accumulating all its body samples."),
98-
llvm::cl::Optional);
102+
"update-total-samples", cl::init(false),
103+
cl::desc("Update total samples by accumulating all its body samples."),
104+
cl::Optional, cl::cat(ProfGenCategory));
99105

100106
static cl::opt<bool> GenCSNestedProfile(
101107
"gen-cs-nested-profile", cl::Hidden, cl::init(true),
102108
cl::desc("Generate nested function profiles for CSSPGO"));
103109

104110
cl::opt<bool> InferMissingFrames(
105-
"infer-missing-frames", llvm::cl::init(true),
106-
llvm::cl::desc(
111+
"infer-missing-frames", cl::init(true),
112+
cl::desc(
107113
"Infer missing call frames due to compiler tail call elimination."),
108-
llvm::cl::Optional);
109-
110-
namespace llvm {
114+
cl::Optional, cl::cat(ProfGenCategory));
111115

112116
namespace sampleprof {
113117

llvm/tools/llvm-profgen/ProfiledBinary.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "ProfiledBinary.h"
10+
1011
#include "ErrorHandling.h"
1112
#include "MissingFrameInferrer.h"
13+
#include "Options.h"
1214
#include "ProfileGenerator.h"
1315
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
1416
#include "llvm/Demangle/Demangle.h"
@@ -24,47 +26,51 @@
2426

2527
#define DEBUG_TYPE "load-binary"
2628

27-
using namespace llvm;
28-
using namespace llvm::object;
29-
using namespace sampleprof;
29+
namespace llvm {
30+
31+
using namespace object;
3032

3133
cl::opt<bool> ShowDisassemblyOnly("show-disassembly-only",
32-
cl::desc("Print disassembled code."));
34+
cl::desc("Print disassembled code."),
35+
cl::cat(ProfGenCategory));
3336

3437
cl::opt<bool> ShowSourceLocations("show-source-locations",
35-
cl::desc("Print source locations."));
38+
cl::desc("Print source locations."),
39+
cl::cat(ProfGenCategory));
3640

3741
static cl::opt<bool>
3842
ShowCanonicalFnName("show-canonical-fname",
39-
cl::desc("Print canonical function name."));
43+
cl::desc("Print canonical function name."),
44+
cl::cat(ProfGenCategory));
4045

4146
static cl::opt<bool> ShowPseudoProbe(
4247
"show-pseudo-probe",
43-
cl::desc("Print pseudo probe section and disassembled info."));
48+
cl::desc("Print pseudo probe section and disassembled info."),
49+
cl::cat(ProfGenCategory));
4450

4551
static cl::opt<bool> UseDwarfCorrelation(
4652
"use-dwarf-correlation",
4753
cl::desc("Use dwarf for profile correlation even when binary contains "
48-
"pseudo probe."));
54+
"pseudo probe."),
55+
cl::cat(ProfGenCategory));
4956

5057
static cl::opt<std::string>
5158
DWPPath("dwp", cl::init(""),
5259
cl::desc("Path of .dwp file. When not specified, it will be "
53-
"<binary>.dwp in the same directory as the main binary."));
60+
"<binary>.dwp in the same directory as the main binary."),
61+
cl::cat(ProfGenCategory));
5462

5563
static cl::list<std::string> DisassembleFunctions(
5664
"disassemble-functions", cl::CommaSeparated,
5765
cl::desc("List of functions to print disassembly for. Accept demangled "
58-
"names only. Only work with show-disassembly-only"));
66+
"names only. Only work with show-disassembly-only"),
67+
cl::cat(ProfGenCategory));
5968

6069
static cl::opt<bool>
6170
KernelBinary("kernel",
62-
cl::desc("Generate the profile for Linux kernel binary."));
71+
cl::desc("Generate the profile for Linux kernel binary."),
72+
cl::cat(ProfGenCategory));
6373

64-
extern cl::opt<bool> ShowDetailedWarning;
65-
extern cl::opt<bool> InferMissingFrames;
66-
67-
namespace llvm {
6874
namespace sampleprof {
6975

7076
static const Target *getTarget(const ObjectFile *Obj) {

llvm/tools/llvm-profgen/ProfiledBinary.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@
4242
#include <vector>
4343

4444
namespace llvm {
45-
46-
extern cl::opt<bool> EnableCSPreInliner;
47-
extern cl::opt<bool> UseContextCostForPreInliner;
48-
4945
namespace sampleprof {
5046

5147
class ProfiledBinary;

llvm/tools/llvm-profgen/llvm-profgen.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "ErrorHandling.h"
14+
#include "Options.h"
1415
#include "PerfReader.h"
1516
#include "ProfileGenerator.h"
1617
#include "ProfiledBinary.h"
@@ -24,7 +25,9 @@
2425
using namespace llvm;
2526
using namespace sampleprof;
2627

27-
static cl::OptionCategory ProfGenCategory("ProfGen Options");
28+
namespace llvm {
29+
30+
cl::OptionCategory ProfGenCategory("ProfGen Options");
2831

2932
static cl::opt<std::string> PerfScriptFilename(
3033
"perfscript", cl::value_desc("perfscript"),
@@ -70,10 +73,6 @@ static cl::opt<std::string> DebugBinPath(
7073
"from it instead of the executable binary."),
7174
cl::cat(ProfGenCategory));
7275

73-
extern cl::opt<bool> ShowDisassemblyOnly;
74-
extern cl::opt<bool> ShowSourceLocations;
75-
extern cl::opt<bool> SkipSymbolization;
76-
7776
// Validate the command line input.
7877
static void validateCommandLine() {
7978
// Allow the missing perfscript if we only use to show binary disassembly.
@@ -138,6 +137,8 @@ static PerfInputFile getPerfInputFile() {
138137
return File;
139138
}
140139

140+
} // end namespace llvm
141+
141142
int main(int argc, const char *argv[]) {
142143
InitLLVM X(argc, argv);
143144

0 commit comments

Comments
 (0)