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