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