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