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