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