Skip to content

Commit 4823259

Browse files
authored
llvm-profgen: Options cleanup / fixes (#147632)
- Add `cl::cat(ProfGenCategory)` to non-hidden options so they show up in `--help` output. - Introduce `Options.h` for options referenced in multiple files.
1 parent 50b55a5 commit 4823259

File tree

7 files changed

+109
-68
lines changed

7 files changed

+109
-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: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88
#include "PerfReader.h"
9+
#include "Options.h"
910
#include "ProfileGenerator.h"
1011
#include "llvm/ADT/SmallString.h"
1112
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
@@ -15,43 +16,47 @@
1516

1617
#define DEBUG_TYPE "perf-reader"
1718

18-
using namespace llvm;
19+
namespace llvm {
1920

2021
cl::opt<bool> SkipSymbolization("skip-symbolization",
2122
cl::desc("Dump the unsymbolized profile to the "
2223
"output file. It will show unwinder "
23-
"output for CS profile generation."));
24+
"output for CS profile generation."),
25+
cl::cat(ProfGenCategory));
2426

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

2831
static cl::opt<bool>
2932
UseOffset("use-offset", cl::init(true),
3033
cl::desc("Work with `--skip-symbolization` or "
3134
"`--unsymbolized-profile` to write/read the "
32-
"offset instead of virtual address."));
35+
"offset instead of virtual address."),
36+
cl::cat(ProfGenCategory));
3337

3438
static cl::opt<bool> UseLoadableSegmentAsBase(
3539
"use-first-loadable-segment-as-base",
3640
cl::desc("Use first loadable segment address as base address "
3741
"for offsets in unsymbolized profile. By default "
38-
"first executable segment address is used"));
42+
"first executable segment address is used"),
43+
cl::cat(ProfGenCategory));
3944

4045
static cl::opt<bool>
4146
IgnoreStackSamples("ignore-stack-samples",
4247
cl::desc("Ignore call stack samples for hybrid samples "
43-
"and produce context-insensitive profile."));
48+
"and produce context-insensitive profile."),
49+
cl::cat(ProfGenCategory));
4450
cl::opt<bool> ShowDetailedWarning("show-detailed-warning",
45-
cl::desc("Show detailed warning message."));
51+
cl::desc("Show detailed warning message."),
52+
cl::cat(ProfGenCategory));
4653

4754
static cl::opt<int> CSProfMaxUnsymbolizedCtxDepth(
4855
"csprof-max-unsymbolized-context-depth", cl::init(-1),
4956
cl::desc("Keep the last K contexts while merging unsymbolized profile. -1 "
50-
"means no depth limit."));
51-
52-
extern cl::opt<std::string> OutputFilename;
57+
"means no depth limit."),
58+
cl::cat(ProfGenCategory));
5359

54-
namespace llvm {
5560
namespace sampleprof {
5661

5762
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: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "ProfiledBinary.h"
1010
#include "ErrorHandling.h"
1111
#include "MissingFrameInferrer.h"
12+
#include "Options.h"
1213
#include "ProfileGenerator.h"
1314
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
1415
#include "llvm/Demangle/Demangle.h"
@@ -24,47 +25,51 @@
2425

2526
#define DEBUG_TYPE "load-binary"
2627

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

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

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

3740
static cl::opt<bool>
3841
ShowCanonicalFnName("show-canonical-fname",
39-
cl::desc("Print canonical function name."));
42+
cl::desc("Print canonical function name."),
43+
cl::cat(ProfGenCategory));
4044

4145
static cl::opt<bool> ShowPseudoProbe(
4246
"show-pseudo-probe",
43-
cl::desc("Print pseudo probe section and disassembled info."));
47+
cl::desc("Print pseudo probe section and disassembled info."),
48+
cl::cat(ProfGenCategory));
4449

4550
static cl::opt<bool> UseDwarfCorrelation(
4651
"use-dwarf-correlation",
4752
cl::desc("Use dwarf for profile correlation even when binary contains "
48-
"pseudo probe."));
53+
"pseudo probe."),
54+
cl::cat(ProfGenCategory));
4955

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

5562
static cl::list<std::string> DisassembleFunctions(
5663
"disassemble-functions", cl::CommaSeparated,
5764
cl::desc("List of functions to print disassembly for. Accept demangled "
58-
"names only. Only work with show-disassembly-only"));
65+
"names only. Only work with show-disassembly-only"),
66+
cl::cat(ProfGenCategory));
5967

6068
static cl::opt<bool>
6169
KernelBinary("kernel",
62-
cl::desc("Generate the profile for Linux kernel binary."));
70+
cl::desc("Generate the profile for Linux kernel binary."),
71+
cl::cat(ProfGenCategory));
6372

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

7075
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)