1 //===- bolt/Utils/CommandLineOpts.cpp - BOLT CLI options ------------------===//
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
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
13 #include "bolt/Utils/CommandLineOpts.h"
14 #include "llvm/Support/VCSRevision.h"
20 const char *BoltRevision
=
31 bool HeatmapMode
= false;
33 cl::OptionCategory
BoltCategory("BOLT generic options");
34 cl::OptionCategory
BoltDiffCategory("BOLTDIFF generic options");
35 cl::OptionCategory
BoltOptCategory("BOLT optimization options");
36 cl::OptionCategory
BoltRelocCategory("BOLT options in relocation mode");
37 cl::OptionCategory
BoltOutputCategory("Output options");
38 cl::OptionCategory
AggregatorCategory("Data aggregation options");
39 cl::OptionCategory
BoltInstrCategory("BOLT instrumentation options");
40 cl::OptionCategory
HeatmapCategory("Heatmap options");
42 cl::opt
<unsigned> AlignText("align-text",
43 cl::desc("alignment of .text section"), cl::Hidden
,
44 cl::cat(BoltCategory
));
46 cl::opt
<unsigned> AlignFunctions(
48 cl::desc("align functions at a given value (relocation mode)"),
49 cl::init(64), cl::cat(BoltOptCategory
));
52 AggregateOnly("aggregate-only",
53 cl::desc("exit after writing aggregated data file"),
55 cl::cat(AggregatorCategory
));
58 BucketsPerLine("line-size",
59 cl::desc("number of entries per line (default 256)"),
60 cl::init(256), cl::Optional
, cl::cat(HeatmapCategory
));
64 cl::desc("stop processing once we have enough to compare two binaries"),
66 cl::cat(BoltDiffCategory
));
69 EnableBAT("enable-bat",
70 cl::desc("write BOLT Address Translation tables"),
73 cl::cat(BoltCategory
));
75 cl::opt
<bool> EqualizeBBCounts(
77 cl::desc("use same count for BBs that should have equivalent count (used "
78 "in non-LBR and shrink wrapping)"),
79 cl::ZeroOrMore
, cl::init(false), cl::Hidden
, cl::cat(BoltOptCategory
));
81 cl::opt
<bool> RemoveSymtab("remove-symtab", cl::desc("Remove .symtab section"),
82 cl::cat(BoltCategory
));
85 ExecutionCountThreshold("execution-count-threshold",
86 cl::desc("perform profiling accuracy-sensitive optimizations only if "
87 "function execution count >= the threshold (default: 0)"),
91 cl::cat(BoltOptCategory
));
94 HeatmapBlock("block-size",
95 cl::desc("size of a heat map block in bytes (default 64)"),
96 cl::init(64), cl::cat(HeatmapCategory
));
98 cl::opt
<unsigned long long> HeatmapMaxAddress(
99 "max-address", cl::init(0xffffffff),
100 cl::desc("maximum address considered valid for heatmap (default 4GB)"),
101 cl::Optional
, cl::cat(HeatmapCategory
));
103 cl::opt
<unsigned long long> HeatmapMinAddress(
104 "min-address", cl::init(0x0),
105 cl::desc("minimum address considered valid for heatmap (default 0)"),
106 cl::Optional
, cl::cat(HeatmapCategory
));
108 cl::opt
<bool> HeatmapPrintMappings(
109 "print-mappings", cl::init(false),
110 cl::desc("print mappings in the legend, between characters/blocks and text "
111 "sections (default false)"),
112 cl::Optional
, cl::cat(HeatmapCategory
));
114 cl::opt
<bool> HotData("hot-data",
115 cl::desc("hot data symbols support (relocation mode)"),
116 cl::cat(BoltCategory
));
118 cl::opt
<bool> HotFunctionsAtEnd(
119 "hot-functions-at-end",
121 "if reorder-functions is used, order functions putting hottest last"),
122 cl::cat(BoltCategory
));
124 cl::opt
<bool> HotText(
127 "Generate hot text symbols. Apply this option to a precompiled binary "
128 "that manually calls into hugify, such that at runtime hugify call "
129 "will put hot code into 2M pages. This requires relocation."),
130 cl::ZeroOrMore
, cl::cat(BoltCategory
));
133 Instrument("instrument",
134 cl::desc("instrument code to generate accurate profile data"),
135 cl::cat(BoltOptCategory
));
137 cl::opt
<bool> Lite("lite", cl::desc("skip processing of cold functions"),
138 cl::cat(BoltCategory
));
142 cl::desc("<output file>"),
144 cl::cat(BoltOutputCategory
));
146 cl::opt
<std::string
> PerfData("perfdata", cl::desc("<data file>"), cl::Optional
,
147 cl::cat(AggregatorCategory
),
148 cl::sub(cl::SubCommand::getAll()));
152 cl::desc("alias for -perfdata"),
153 cl::aliasopt(PerfData
),
154 cl::cat(AggregatorCategory
));
156 cl::opt
<bool> PrintCacheMetrics(
157 "print-cache-metrics",
158 cl::desc("calculate and print various metrics for instruction cache"),
159 cl::cat(BoltOptCategory
));
161 cl::opt
<bool> PrintSections("print-sections",
162 cl::desc("print all registered sections"),
163 cl::Hidden
, cl::cat(BoltCategory
));
165 cl::opt
<ProfileFormatKind
> ProfileFormat(
168 "format to dump profile output in aggregation mode, default is fdata"),
170 cl::values(clEnumValN(PF_Fdata
, "fdata", "offset-based plaintext format"),
171 clEnumValN(PF_YAML
, "yaml", "dense YAML representation")),
172 cl::ZeroOrMore
, cl::Hidden
, cl::cat(BoltCategory
));
174 cl::opt
<std::string
> SaveProfile("w",
175 cl::desc("save recorded profile to a file"),
176 cl::cat(BoltOutputCategory
));
178 cl::opt
<bool> SplitEH("split-eh", cl::desc("split C++ exception handling code"),
179 cl::Hidden
, cl::cat(BoltOptCategory
));
183 cl::desc("trust the input to be from a well-formed source"),
185 cl::cat(BoltCategory
));
187 cl::opt
<bool> TimeOpts("time-opts",
188 cl::desc("print time spent in each optimization"),
189 cl::cat(BoltOptCategory
));
191 cl::opt
<bool> TimeRewrite("time-rewrite",
192 cl::desc("print time spent in rewriting passes"),
193 cl::Hidden
, cl::cat(BoltCategory
));
195 cl::opt
<bool> UseOldText(
197 cl::desc("re-use space in old .text if possible (relocation mode)"),
198 cl::cat(BoltCategory
));
200 cl::opt
<bool> UpdateDebugSections(
201 "update-debug-sections",
202 cl::desc("update DWARF debug sections of the executable"),
203 cl::cat(BoltCategory
));
206 Verbosity("v", cl::desc("set verbosity level for diagnostic output"),
207 cl::init(0), cl::ZeroOrMore
, cl::cat(BoltCategory
),
208 cl::sub(cl::SubCommand::getAll()));
210 bool processAllFunctions() {
211 if (opts::AggregateOnly
)
214 if (UseOldText
|| StrictMode
)