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;
32 bool LinuxKernelMode
= false;
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");
43 cl::opt
<unsigned> AlignText("align-text",
44 cl::desc("alignment of .text section"), cl::Hidden
,
45 cl::cat(BoltCategory
));
47 cl::opt
<unsigned> AlignFunctions(
49 cl::desc("align functions at a given value (relocation mode)"),
50 cl::init(64), cl::cat(BoltOptCategory
));
53 AggregateOnly("aggregate-only",
54 cl::desc("exit after writing aggregated data file"),
56 cl::cat(AggregatorCategory
));
59 BucketsPerLine("line-size",
60 cl::desc("number of entries per line (default 256)"),
61 cl::init(256), cl::Optional
, cl::cat(HeatmapCategory
));
65 cl::desc("stop processing once we have enough to compare two binaries"),
67 cl::cat(BoltDiffCategory
));
70 EnableBAT("enable-bat",
71 cl::desc("write BOLT Address Translation tables"),
74 cl::cat(BoltCategory
));
76 cl::opt
<bool> EqualizeBBCounts(
78 cl::desc("use same count for BBs that should have equivalent count (used "
79 "in non-LBR and shrink wrapping)"),
80 cl::ZeroOrMore
, cl::init(false), cl::Hidden
, cl::cat(BoltOptCategory
));
82 cl::opt
<bool> RemoveSymtab("remove-symtab", cl::desc("Remove .symtab section"),
83 cl::cat(BoltCategory
));
86 ExecutionCountThreshold("execution-count-threshold",
87 cl::desc("perform profiling accuracy-sensitive optimizations only if "
88 "function execution count >= the threshold (default: 0)"),
92 cl::cat(BoltOptCategory
));
95 HeatmapBlock("block-size",
96 cl::desc("size of a heat map block in bytes (default 64)"),
97 cl::init(64), cl::cat(HeatmapCategory
));
99 cl::opt
<unsigned long long> HeatmapMaxAddress(
100 "max-address", cl::init(0xffffffff),
101 cl::desc("maximum address considered valid for heatmap (default 4GB)"),
102 cl::Optional
, cl::cat(HeatmapCategory
));
104 cl::opt
<unsigned long long> HeatmapMinAddress(
105 "min-address", cl::init(0x0),
106 cl::desc("minimum address considered valid for heatmap (default 0)"),
107 cl::Optional
, cl::cat(HeatmapCategory
));
109 cl::opt
<bool> HotData("hot-data",
110 cl::desc("hot data symbols support (relocation mode)"),
111 cl::cat(BoltCategory
));
113 cl::opt
<bool> HotFunctionsAtEnd(
114 "hot-functions-at-end",
116 "if reorder-functions is used, order functions putting hottest last"),
117 cl::cat(BoltCategory
));
119 cl::opt
<bool> HotText(
122 "Generate hot text symbols. Apply this option to a precompiled binary "
123 "that manually calls into hugify, such that at runtime hugify call "
124 "will put hot code into 2M pages. This requires relocation."),
125 cl::ZeroOrMore
, cl::cat(BoltCategory
));
128 Instrument("instrument",
129 cl::desc("instrument code to generate accurate profile data"),
130 cl::cat(BoltOptCategory
));
134 cl::desc("<output file>"),
136 cl::cat(BoltOutputCategory
));
138 cl::opt
<std::string
> PerfData("perfdata", cl::desc("<data file>"), cl::Optional
,
139 cl::cat(AggregatorCategory
),
140 cl::sub(cl::SubCommand::getAll()));
144 cl::desc("alias for -perfdata"),
145 cl::aliasopt(PerfData
),
146 cl::cat(AggregatorCategory
));
148 cl::opt
<bool> PrintCacheMetrics(
149 "print-cache-metrics",
150 cl::desc("calculate and print various metrics for instruction cache"),
151 cl::cat(BoltOptCategory
));
153 cl::opt
<bool> PrintSections("print-sections",
154 cl::desc("print all registered sections"),
155 cl::Hidden
, cl::cat(BoltCategory
));
157 cl::opt
<ProfileFormatKind
> ProfileFormat(
160 "format to dump profile output in aggregation mode, default is fdata"),
162 cl::values(clEnumValN(PF_Fdata
, "fdata", "offset-based plaintext format"),
163 clEnumValN(PF_YAML
, "yaml", "dense YAML reprensentation")),
164 cl::ZeroOrMore
, cl::Hidden
, cl::cat(BoltCategory
));
166 cl::opt
<bool> SplitEH("split-eh", cl::desc("split C++ exception handling code"),
167 cl::Hidden
, cl::cat(BoltOptCategory
));
171 cl::desc("trust the input to be from a well-formed source"),
173 cl::cat(BoltCategory
));
175 cl::opt
<bool> TimeOpts("time-opts",
176 cl::desc("print time spent in each optimization"),
177 cl::cat(BoltOptCategory
));
179 cl::opt
<bool> UseOldText(
181 cl::desc("re-use space in old .text if possible (relocation mode)"),
182 cl::cat(BoltCategory
));
184 cl::opt
<bool> UpdateDebugSections(
185 "update-debug-sections",
186 cl::desc("update DWARF debug sections of the executable"),
187 cl::cat(BoltCategory
));
190 Verbosity("v", cl::desc("set verbosity level for diagnostic output"),
191 cl::init(0), cl::ZeroOrMore
, cl::cat(BoltCategory
),
192 cl::sub(cl::SubCommand::getAll()));
194 bool processAllFunctions() {
195 if (opts::AggregateOnly
)
198 if (UseOldText
|| StrictMode
)