xref: /llvm-project/bolt/lib/Utils/CommandLineOpts.cpp (revision 32e4906c28952d2dd8ed193cfd37856b98233ef5)
1 //===- bolt/Utils/CommandLineOpts.cpp - BOLT CLI options ------------------===//
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 //
9 // BOLT CLI options
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "bolt/Utils/CommandLineOpts.h"
14 #include "llvm/Support/VCSRevision.h"
15 
16 using namespace llvm;
17 
18 namespace llvm {
19 namespace bolt {
20 const char *BoltRevision =
21 #ifdef LLVM_REVISION
22     LLVM_REVISION;
23 #else
24     "<unknown>";
25 #endif
26 }
27 }
28 
29 namespace opts {
30 
31 bool HeatmapMode = false;
32 
33 cl::OptionCategory BoltCategory("BOLT generic options");
34 cl::OptionCategory BoltDiffCategory("BOLTDIFF generic options");
35 cl::OptionCategory BoltOptCategory("BOLT optimization options");
36 cl::OptionCategory BoltRelocCategory("BOLT options in relocation mode");
37 cl::OptionCategory BoltOutputCategory("Output options");
38 cl::OptionCategory AggregatorCategory("Data aggregation options");
39 cl::OptionCategory BoltInstrCategory("BOLT instrumentation options");
40 cl::OptionCategory HeatmapCategory("Heatmap options");
41 
42 cl::opt<unsigned> AlignText("align-text",
43                             cl::desc("alignment of .text section"), cl::Hidden,
44                             cl::cat(BoltCategory));
45 
46 cl::opt<unsigned> AlignFunctions(
47     "align-functions",
48     cl::desc("align functions at a given value (relocation mode)"),
49     cl::init(64), cl::cat(BoltOptCategory));
50 
51 cl::opt<bool>
52 AggregateOnly("aggregate-only",
53   cl::desc("exit after writing aggregated data file"),
54   cl::Hidden,
55   cl::cat(AggregatorCategory));
56 
57 cl::opt<unsigned>
58     BucketsPerLine("line-size",
59                    cl::desc("number of entries per line (default 256)"),
60                    cl::init(256), cl::Optional, cl::cat(HeatmapCategory));
61 
62 cl::opt<bool>
63 DiffOnly("diff-only",
64   cl::desc("stop processing once we have enough to compare two binaries"),
65   cl::Hidden,
66   cl::cat(BoltDiffCategory));
67 
68 cl::opt<bool>
69 EnableBAT("enable-bat",
70   cl::desc("write BOLT Address Translation tables"),
71   cl::init(false),
72   cl::ZeroOrMore,
73   cl::cat(BoltCategory));
74 
75 cl::opt<bool> EqualizeBBCounts(
76     "equalize-bb-counts",
77     cl::desc("use same count for BBs that should have equivalent count (used "
78              "in non-LBR and shrink wrapping)"),
79     cl::ZeroOrMore, cl::init(false), cl::Hidden, cl::cat(BoltOptCategory));
80 
81 cl::opt<bool> RemoveSymtab("remove-symtab", cl::desc("Remove .symtab section"),
82                            cl::cat(BoltCategory));
83 
84 cl::opt<unsigned>
85 ExecutionCountThreshold("execution-count-threshold",
86   cl::desc("perform profiling accuracy-sensitive optimizations only if "
87            "function execution count >= the threshold (default: 0)"),
88   cl::init(0),
89   cl::ZeroOrMore,
90   cl::Hidden,
91   cl::cat(BoltOptCategory));
92 
93 cl::opt<unsigned>
94     HeatmapBlock("block-size",
95                  cl::desc("size of a heat map block in bytes (default 64)"),
96                  cl::init(64), cl::cat(HeatmapCategory));
97 
98 cl::opt<unsigned long long> HeatmapMaxAddress(
99     "max-address", cl::init(0xffffffff),
100     cl::desc("maximum address considered valid for heatmap (default 4GB)"),
101     cl::Optional, cl::cat(HeatmapCategory));
102 
103 cl::opt<unsigned long long> HeatmapMinAddress(
104     "min-address", cl::init(0x0),
105     cl::desc("minimum address considered valid for heatmap (default 0)"),
106     cl::Optional, cl::cat(HeatmapCategory));
107 
108 cl::opt<bool> HotData("hot-data",
109                       cl::desc("hot data symbols support (relocation mode)"),
110                       cl::cat(BoltCategory));
111 
112 cl::opt<bool> HotFunctionsAtEnd(
113     "hot-functions-at-end",
114     cl::desc(
115         "if reorder-functions is used, order functions putting hottest last"),
116     cl::cat(BoltCategory));
117 
118 cl::opt<bool> HotText(
119     "hot-text",
120     cl::desc(
121         "Generate hot text symbols. Apply this option to a precompiled binary "
122         "that manually calls into hugify, such that at runtime hugify call "
123         "will put hot code into 2M pages. This requires relocation."),
124     cl::ZeroOrMore, cl::cat(BoltCategory));
125 
126 cl::opt<bool>
127     Instrument("instrument",
128                cl::desc("instrument code to generate accurate profile data"),
129                cl::cat(BoltOptCategory));
130 
131 cl::opt<std::string>
132 OutputFilename("o",
133   cl::desc("<output file>"),
134   cl::Optional,
135   cl::cat(BoltOutputCategory));
136 
137 cl::opt<std::string> PerfData("perfdata", cl::desc("<data file>"), cl::Optional,
138                               cl::cat(AggregatorCategory),
139                               cl::sub(cl::SubCommand::getAll()));
140 
141 static cl::alias
142 PerfDataA("p",
143   cl::desc("alias for -perfdata"),
144   cl::aliasopt(PerfData),
145   cl::cat(AggregatorCategory));
146 
147 cl::opt<bool> PrintCacheMetrics(
148     "print-cache-metrics",
149     cl::desc("calculate and print various metrics for instruction cache"),
150     cl::cat(BoltOptCategory));
151 
152 cl::opt<bool> PrintSections("print-sections",
153                             cl::desc("print all registered sections"),
154                             cl::Hidden, cl::cat(BoltCategory));
155 
156 cl::opt<ProfileFormatKind> ProfileFormat(
157     "profile-format",
158     cl::desc(
159         "format to dump profile output in aggregation mode, default is fdata"),
160     cl::init(PF_Fdata),
161     cl::values(clEnumValN(PF_Fdata, "fdata", "offset-based plaintext format"),
162                clEnumValN(PF_YAML, "yaml", "dense YAML representation")),
163     cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory));
164 
165 cl::opt<std::string> SaveProfile("w",
166                                  cl::desc("save recorded profile to a file"),
167                                  cl::cat(BoltOutputCategory));
168 
169 cl::opt<bool> SplitEH("split-eh", cl::desc("split C++ exception handling code"),
170                       cl::Hidden, cl::cat(BoltOptCategory));
171 
172 cl::opt<bool>
173     StrictMode("strict",
174                cl::desc("trust the input to be from a well-formed source"),
175 
176                cl::cat(BoltCategory));
177 
178 cl::opt<bool> TimeOpts("time-opts",
179                        cl::desc("print time spent in each optimization"),
180                        cl::cat(BoltOptCategory));
181 
182 cl::opt<bool> TimeRewrite("time-rewrite",
183                           cl::desc("print time spent in rewriting passes"),
184                           cl::Hidden, cl::cat(BoltCategory));
185 
186 cl::opt<bool> UseOldText(
187     "use-old-text",
188     cl::desc("re-use space in old .text if possible (relocation mode)"),
189     cl::cat(BoltCategory));
190 
191 cl::opt<bool> UpdateDebugSections(
192     "update-debug-sections",
193     cl::desc("update DWARF debug sections of the executable"),
194     cl::cat(BoltCategory));
195 
196 cl::opt<unsigned>
197     Verbosity("v", cl::desc("set verbosity level for diagnostic output"),
198               cl::init(0), cl::ZeroOrMore, cl::cat(BoltCategory),
199               cl::sub(cl::SubCommand::getAll()));
200 
201 bool processAllFunctions() {
202   if (opts::AggregateOnly)
203     return false;
204 
205   if (UseOldText || StrictMode)
206     return true;
207 
208   return false;
209 }
210 
211 } // namespace opts
212