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