xref: /llvm-project/bolt/lib/Utils/CommandLineOpts.cpp (revision f7872cdce1102a5c12633dad462a1d9763a578d3)
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 
43b92436efSFangrui Song cl::opt<unsigned> AlignText("align-text",
44b92436efSFangrui Song                             cl::desc("alignment of .text section"), cl::Hidden,
45a34c753fSRafael Auler                             cl::cat(BoltCategory));
46a34c753fSRafael Auler 
478ab69baaSVladislav Khmelevsky cl::opt<unsigned> AlignFunctions(
488ab69baaSVladislav Khmelevsky     "align-functions",
498ab69baaSVladislav Khmelevsky     cl::desc("align functions at a given value (relocation mode)"),
5036c7d79dSFangrui Song     cl::init(64), cl::cat(BoltOptCategory));
518ab69baaSVladislav Khmelevsky 
52a34c753fSRafael Auler cl::opt<bool>
53a34c753fSRafael Auler AggregateOnly("aggregate-only",
54a34c753fSRafael Auler   cl::desc("exit after writing aggregated data file"),
55a34c753fSRafael Auler   cl::Hidden,
56a34c753fSRafael Auler   cl::cat(AggregatorCategory));
57a34c753fSRafael Auler 
58a34c753fSRafael Auler cl::opt<unsigned>
59a34c753fSRafael Auler     BucketsPerLine("line-size",
60a34c753fSRafael Auler                    cl::desc("number of entries per line (default 256)"),
615c2ae5f4SVladislav Khmelevsky                    cl::init(256), cl::Optional, cl::cat(HeatmapCategory));
62a34c753fSRafael Auler 
63a34c753fSRafael Auler cl::opt<bool>
64a34c753fSRafael Auler DiffOnly("diff-only",
65a34c753fSRafael Auler   cl::desc("stop processing once we have enough to compare two binaries"),
66a34c753fSRafael Auler   cl::Hidden,
67a34c753fSRafael Auler   cl::cat(BoltDiffCategory));
68a34c753fSRafael Auler 
69a34c753fSRafael Auler cl::opt<bool>
70a34c753fSRafael Auler EnableBAT("enable-bat",
71a34c753fSRafael Auler   cl::desc("write BOLT Address Translation tables"),
72a34c753fSRafael Auler   cl::init(false),
73a34c753fSRafael Auler   cl::ZeroOrMore,
74a34c753fSRafael Auler   cl::cat(BoltCategory));
75a34c753fSRafael Auler 
763332904aSRafael Auler cl::opt<bool> EqualizeBBCounts(
773332904aSRafael Auler     "equalize-bb-counts",
783332904aSRafael Auler     cl::desc("use same count for BBs that should have equivalent count (used "
793332904aSRafael Auler              "in non-LBR and shrink wrapping)"),
803332904aSRafael Auler     cl::ZeroOrMore, cl::init(false), cl::Hidden, cl::cat(BoltOptCategory));
813332904aSRafael Auler 
82a34c753fSRafael Auler cl::opt<bool> RemoveSymtab("remove-symtab", cl::desc("Remove .symtab section"),
83a34c753fSRafael Auler                            cl::cat(BoltCategory));
84a34c753fSRafael Auler 
85a34c753fSRafael Auler cl::opt<unsigned>
86a34c753fSRafael Auler ExecutionCountThreshold("execution-count-threshold",
87a34c753fSRafael Auler   cl::desc("perform profiling accuracy-sensitive optimizations only if "
88a34c753fSRafael Auler            "function execution count >= the threshold (default: 0)"),
89a34c753fSRafael Auler   cl::init(0),
90a34c753fSRafael Auler   cl::ZeroOrMore,
91a34c753fSRafael Auler   cl::Hidden,
92a34c753fSRafael Auler   cl::cat(BoltOptCategory));
93a34c753fSRafael Auler 
94a34c753fSRafael Auler cl::opt<unsigned>
95a34c753fSRafael Auler     HeatmapBlock("block-size",
96a34c753fSRafael Auler                  cl::desc("size of a heat map block in bytes (default 64)"),
975c2ae5f4SVladislav Khmelevsky                  cl::init(64), cl::cat(HeatmapCategory));
98a34c753fSRafael Auler 
995c2ae5f4SVladislav Khmelevsky cl::opt<unsigned long long> HeatmapMaxAddress(
1005c2ae5f4SVladislav Khmelevsky     "max-address", cl::init(0xffffffff),
101a34c753fSRafael Auler     cl::desc("maximum address considered valid for heatmap (default 4GB)"),
1025c2ae5f4SVladislav Khmelevsky     cl::Optional, cl::cat(HeatmapCategory));
103a34c753fSRafael Auler 
1045c2ae5f4SVladislav Khmelevsky cl::opt<unsigned long long> HeatmapMinAddress(
1055c2ae5f4SVladislav Khmelevsky     "min-address", cl::init(0x0),
106a34c753fSRafael Auler     cl::desc("minimum address considered valid for heatmap (default 0)"),
1075c2ae5f4SVladislav Khmelevsky     cl::Optional, cl::cat(HeatmapCategory));
108a34c753fSRafael Auler 
109b92436efSFangrui Song cl::opt<bool> HotData("hot-data",
110a34c753fSRafael Auler                       cl::desc("hot data symbols support (relocation mode)"),
111a34c753fSRafael Auler                       cl::cat(BoltCategory));
112a34c753fSRafael Auler 
113b92436efSFangrui Song cl::opt<bool> 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::cat(BoltCategory));
118a34c753fSRafael Auler 
119a34c753fSRafael Auler cl::opt<bool> HotText(
120a34c753fSRafael Auler     "hot-text",
121a34c753fSRafael Auler     cl::desc(
122a34c753fSRafael Auler         "Generate hot text symbols. Apply this option to a precompiled binary "
123a34c753fSRafael Auler         "that manually calls into hugify, such that at runtime hugify call "
124a34c753fSRafael Auler         "will put hot code into 2M pages. This requires relocation."),
125a34c753fSRafael Auler     cl::ZeroOrMore, cl::cat(BoltCategory));
126a34c753fSRafael Auler 
127a34c753fSRafael Auler cl::opt<bool>
128a34c753fSRafael Auler     Instrument("instrument",
129a34c753fSRafael Auler                cl::desc("instrument code to generate accurate profile data"),
130b92436efSFangrui Song                cl::cat(BoltOptCategory));
131a34c753fSRafael Auler 
132a34c753fSRafael Auler cl::opt<std::string>
133a34c753fSRafael Auler OutputFilename("o",
134a34c753fSRafael Auler   cl::desc("<output file>"),
135a34c753fSRafael Auler   cl::Optional,
136a34c753fSRafael Auler   cl::cat(BoltOutputCategory));
137a34c753fSRafael Auler 
138*f7872cdcSNicolai Hähnle cl::opt<std::string> PerfData("perfdata", cl::desc("<data file>"), cl::Optional,
139a34c753fSRafael Auler                               cl::cat(AggregatorCategory),
140*f7872cdcSNicolai Hähnle                               cl::sub(cl::SubCommand::getAll()));
141a34c753fSRafael Auler 
142a34c753fSRafael Auler static cl::alias
143a34c753fSRafael Auler PerfDataA("p",
144a34c753fSRafael Auler   cl::desc("alias for -perfdata"),
145a34c753fSRafael Auler   cl::aliasopt(PerfData),
146a34c753fSRafael Auler   cl::cat(AggregatorCategory));
147a34c753fSRafael Auler 
148b92436efSFangrui Song cl::opt<bool> PrintCacheMetrics(
149b92436efSFangrui Song     "print-cache-metrics",
150a34c753fSRafael Auler     cl::desc("calculate and print various metrics for instruction cache"),
151a34c753fSRafael Auler     cl::cat(BoltOptCategory));
152a34c753fSRafael Auler 
153b92436efSFangrui Song cl::opt<bool> PrintSections("print-sections",
154a34c753fSRafael Auler                             cl::desc("print all registered sections"),
155b92436efSFangrui Song                             cl::Hidden, cl::cat(BoltCategory));
156a34c753fSRafael Auler 
157b92436efSFangrui Song cl::opt<bool> SplitEH("split-eh", cl::desc("split C++ exception handling code"),
158b92436efSFangrui Song                       cl::Hidden, cl::cat(BoltOptCategory));
159a34c753fSRafael Auler 
160a34c753fSRafael Auler cl::opt<bool>
161a34c753fSRafael Auler     StrictMode("strict",
162a34c753fSRafael Auler                cl::desc("trust the input to be from a well-formed source"),
163b92436efSFangrui Song 
164a34c753fSRafael Auler                cl::cat(BoltCategory));
165a34c753fSRafael Auler 
166b92436efSFangrui Song llvm::cl::opt<bool> TimeOpts("time-opts",
167a34c753fSRafael Auler                              cl::desc("print time spent in each optimization"),
168a34c753fSRafael Auler                              cl::cat(BoltOptCategory));
169a34c753fSRafael Auler 
170b92436efSFangrui Song cl::opt<bool> UseOldText(
171b92436efSFangrui Song     "use-old-text",
172a34c753fSRafael Auler     cl::desc("re-use space in old .text if possible (relocation mode)"),
173a34c753fSRafael Auler     cl::cat(BoltCategory));
174a34c753fSRafael Auler 
175b92436efSFangrui Song cl::opt<bool> UpdateDebugSections(
176b92436efSFangrui Song     "update-debug-sections",
177a34c753fSRafael Auler     cl::desc("update DWARF debug sections of the executable"),
178a34c753fSRafael Auler     cl::cat(BoltCategory));
179a34c753fSRafael Auler 
180a34c753fSRafael Auler cl::opt<unsigned>
181*f7872cdcSNicolai Hähnle     Verbosity("v", cl::desc("set verbosity level for diagnostic output"),
182*f7872cdcSNicolai Hähnle               cl::init(0), cl::ZeroOrMore, cl::cat(BoltCategory),
183*f7872cdcSNicolai Hähnle               cl::sub(cl::SubCommand::getAll()));
184a34c753fSRafael Auler 
185a34c753fSRafael Auler bool processAllFunctions() {
186a34c753fSRafael Auler   if (opts::AggregateOnly)
187a34c753fSRafael Auler     return false;
188a34c753fSRafael Auler 
189a34c753fSRafael Auler   if (UseOldText || StrictMode)
190a34c753fSRafael Auler     return true;
191a34c753fSRafael Auler 
192a34c753fSRafael Auler   return false;
193a34c753fSRafael Auler }
194a34c753fSRafael Auler 
195a34c753fSRafael Auler } // namespace opts
196