2021-12-21 10:21:41 -08:00
|
|
|
//===- bolt/Utils/CommandLineOpts.cpp - BOLT CLI options ------------------===//
|
2021-10-08 11:47:10 -07:00
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// BOLT CLI options
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "bolt/Utils/CommandLineOpts.h"
|
2024-07-25 08:18:14 -07:00
|
|
|
#include "VCSVersion.inc"
|
2021-10-08 11:47:10 -07:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace bolt {
|
2022-04-15 06:13:19 -07:00
|
|
|
const char *BoltRevision =
|
2024-07-25 08:18:14 -07:00
|
|
|
#ifdef BOLT_REVISION
|
|
|
|
BOLT_REVISION;
|
2022-04-15 06:13:19 -07:00
|
|
|
#else
|
|
|
|
"<unknown>";
|
|
|
|
#endif
|
2021-10-08 11:47:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace opts {
|
|
|
|
|
|
|
|
bool HeatmapMode = false;
|
|
|
|
|
|
|
|
cl::OptionCategory BoltCategory("BOLT generic options");
|
|
|
|
cl::OptionCategory BoltDiffCategory("BOLTDIFF generic options");
|
|
|
|
cl::OptionCategory BoltOptCategory("BOLT optimization options");
|
|
|
|
cl::OptionCategory BoltRelocCategory("BOLT options in relocation mode");
|
|
|
|
cl::OptionCategory BoltOutputCategory("Output options");
|
|
|
|
cl::OptionCategory AggregatorCategory("Data aggregation options");
|
|
|
|
cl::OptionCategory BoltInstrCategory("BOLT instrumentation options");
|
2022-02-07 21:30:38 +03:00
|
|
|
cl::OptionCategory HeatmapCategory("Heatmap options");
|
2021-10-08 11:47:10 -07:00
|
|
|
|
2022-06-05 13:29:49 -07:00
|
|
|
cl::opt<unsigned> AlignText("align-text",
|
|
|
|
cl::desc("alignment of .text section"), cl::Hidden,
|
|
|
|
cl::cat(BoltCategory));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
2022-03-10 21:38:55 +03:00
|
|
|
cl::opt<unsigned> AlignFunctions(
|
|
|
|
"align-functions",
|
|
|
|
cl::desc("align functions at a given value (relocation mode)"),
|
2022-06-04 00:10:42 -07:00
|
|
|
cl::init(64), cl::cat(BoltOptCategory));
|
2022-03-10 21:38:55 +03:00
|
|
|
|
2021-10-08 11:47:10 -07:00
|
|
|
cl::opt<bool>
|
|
|
|
AggregateOnly("aggregate-only",
|
|
|
|
cl::desc("exit after writing aggregated data file"),
|
|
|
|
cl::Hidden,
|
|
|
|
cl::cat(AggregatorCategory));
|
|
|
|
|
|
|
|
cl::opt<unsigned>
|
2022-02-07 21:30:38 +03:00
|
|
|
BucketsPerLine("line-size",
|
|
|
|
cl::desc("number of entries per line (default 256)"),
|
|
|
|
cl::init(256), cl::Optional, cl::cat(HeatmapCategory));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
|
|
|
cl::opt<bool>
|
|
|
|
DiffOnly("diff-only",
|
|
|
|
cl::desc("stop processing once we have enough to compare two binaries"),
|
|
|
|
cl::Hidden,
|
|
|
|
cl::cat(BoltDiffCategory));
|
|
|
|
|
|
|
|
cl::opt<bool>
|
|
|
|
EnableBAT("enable-bat",
|
|
|
|
cl::desc("write BOLT Address Translation tables"),
|
|
|
|
cl::init(false),
|
|
|
|
cl::ZeroOrMore,
|
|
|
|
cl::cat(BoltCategory));
|
|
|
|
|
2022-05-20 19:43:07 -07:00
|
|
|
cl::opt<bool> EqualizeBBCounts(
|
|
|
|
"equalize-bb-counts",
|
|
|
|
cl::desc("use same count for BBs that should have equivalent count (used "
|
|
|
|
"in non-LBR and shrink wrapping)"),
|
|
|
|
cl::ZeroOrMore, cl::init(false), cl::Hidden, cl::cat(BoltOptCategory));
|
|
|
|
|
2021-10-08 11:47:10 -07:00
|
|
|
cl::opt<bool> RemoveSymtab("remove-symtab", cl::desc("Remove .symtab section"),
|
|
|
|
cl::cat(BoltCategory));
|
|
|
|
|
|
|
|
cl::opt<unsigned>
|
|
|
|
ExecutionCountThreshold("execution-count-threshold",
|
|
|
|
cl::desc("perform profiling accuracy-sensitive optimizations only if "
|
|
|
|
"function execution count >= the threshold (default: 0)"),
|
|
|
|
cl::init(0),
|
|
|
|
cl::ZeroOrMore,
|
|
|
|
cl::Hidden,
|
|
|
|
cl::cat(BoltOptCategory));
|
|
|
|
|
|
|
|
cl::opt<unsigned>
|
2022-02-07 21:30:38 +03:00
|
|
|
HeatmapBlock("block-size",
|
|
|
|
cl::desc("size of a heat map block in bytes (default 64)"),
|
|
|
|
cl::init(64), cl::cat(HeatmapCategory));
|
|
|
|
|
|
|
|
cl::opt<unsigned long long> HeatmapMaxAddress(
|
|
|
|
"max-address", cl::init(0xffffffff),
|
|
|
|
cl::desc("maximum address considered valid for heatmap (default 4GB)"),
|
|
|
|
cl::Optional, cl::cat(HeatmapCategory));
|
|
|
|
|
|
|
|
cl::opt<unsigned long long> HeatmapMinAddress(
|
|
|
|
"min-address", cl::init(0x0),
|
|
|
|
cl::desc("minimum address considered valid for heatmap (default 0)"),
|
|
|
|
cl::Optional, cl::cat(HeatmapCategory));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
2024-07-15 10:23:06 +03:00
|
|
|
cl::opt<bool> HeatmapPrintMappings(
|
|
|
|
"print-mappings", cl::init(false),
|
|
|
|
cl::desc("print mappings in the legend, between characters/blocks and text "
|
|
|
|
"sections (default false)"),
|
|
|
|
cl::Optional, cl::cat(HeatmapCategory));
|
|
|
|
|
2022-06-05 13:29:49 -07:00
|
|
|
cl::opt<bool> HotData("hot-data",
|
|
|
|
cl::desc("hot data symbols support (relocation mode)"),
|
|
|
|
cl::cat(BoltCategory));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
2022-06-05 13:29:49 -07:00
|
|
|
cl::opt<bool> HotFunctionsAtEnd(
|
|
|
|
"hot-functions-at-end",
|
|
|
|
cl::desc(
|
|
|
|
"if reorder-functions is used, order functions putting hottest last"),
|
|
|
|
cl::cat(BoltCategory));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
|
|
|
cl::opt<bool> HotText(
|
|
|
|
"hot-text",
|
|
|
|
cl::desc(
|
|
|
|
"Generate hot text symbols. Apply this option to a precompiled binary "
|
|
|
|
"that manually calls into hugify, such that at runtime hugify call "
|
|
|
|
"will put hot code into 2M pages. This requires relocation."),
|
|
|
|
cl::ZeroOrMore, cl::cat(BoltCategory));
|
|
|
|
|
|
|
|
cl::opt<bool>
|
|
|
|
Instrument("instrument",
|
|
|
|
cl::desc("instrument code to generate accurate profile data"),
|
2022-06-05 13:29:49 -07:00
|
|
|
cl::cat(BoltOptCategory));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
2024-06-29 21:19:00 -07:00
|
|
|
cl::opt<bool> Lite("lite", cl::desc("skip processing of cold functions"),
|
|
|
|
cl::cat(BoltCategory));
|
|
|
|
|
2021-10-08 11:47:10 -07:00
|
|
|
cl::opt<std::string>
|
|
|
|
OutputFilename("o",
|
|
|
|
cl::desc("<output file>"),
|
|
|
|
cl::Optional,
|
|
|
|
cl::cat(BoltOutputCategory));
|
|
|
|
|
2022-06-29 12:32:45 +02:00
|
|
|
cl::opt<std::string> PerfData("perfdata", cl::desc("<data file>"), cl::Optional,
|
|
|
|
cl::cat(AggregatorCategory),
|
|
|
|
cl::sub(cl::SubCommand::getAll()));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
|
|
|
static cl::alias
|
|
|
|
PerfDataA("p",
|
|
|
|
cl::desc("alias for -perfdata"),
|
|
|
|
cl::aliasopt(PerfData),
|
|
|
|
cl::cat(AggregatorCategory));
|
|
|
|
|
2022-06-05 13:29:49 -07:00
|
|
|
cl::opt<bool> PrintCacheMetrics(
|
|
|
|
"print-cache-metrics",
|
|
|
|
cl::desc("calculate and print various metrics for instruction cache"),
|
|
|
|
cl::cat(BoltOptCategory));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
2022-06-05 13:29:49 -07:00
|
|
|
cl::opt<bool> PrintSections("print-sections",
|
|
|
|
cl::desc("print all registered sections"),
|
|
|
|
cl::Hidden, cl::cat(BoltCategory));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
2022-09-19 13:36:50 -07:00
|
|
|
cl::opt<ProfileFormatKind> ProfileFormat(
|
|
|
|
"profile-format",
|
|
|
|
cl::desc(
|
|
|
|
"format to dump profile output in aggregation mode, default is fdata"),
|
|
|
|
cl::init(PF_Fdata),
|
|
|
|
cl::values(clEnumValN(PF_Fdata, "fdata", "offset-based plaintext format"),
|
2023-11-09 13:29:46 -06:00
|
|
|
clEnumValN(PF_YAML, "yaml", "dense YAML representation")),
|
2022-09-19 13:36:50 -07:00
|
|
|
cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory));
|
|
|
|
|
2024-03-21 14:32:13 -07:00
|
|
|
cl::opt<std::string> SaveProfile("w",
|
|
|
|
cl::desc("save recorded profile to a file"),
|
|
|
|
cl::cat(BoltOutputCategory));
|
|
|
|
|
[BOLT] Add profile density computation
Reuse the definition of profile density from llvm-profgen (#92144):
- the density is computed in perf2bolt using raw samples (perf.data or
pre-aggregated data),
- function density is the ratio of dynamically executed function bytes
to the static function size in bytes,
- profile density:
- functions are sorted by density in decreasing order, accumulating
their respective sample counts,
- profile density is the smallest density covering 99% of total sample
count.
In other words, BOLT binary profile density is the minimum amount of
profile information per function (excluding functions in tail 1% sample
count) which is sufficient to optimize the binary well.
The density threshold of 60 was determined through experiments with
large binaries by reducing the sample count and checking resulting
profile density and performance. The threshold is conservative.
perf2bolt would print the warning if the density is below the threshold
and suggest to increase the sampling duration and/or frequency to reach
a given density, e.g.:
```
BOLT-WARNING: BOLT is estimated to optimize better with 2.8x more samples.
```
Test Plan: updated pre-aggregated-perf.test
Reviewers: maksfb, wlei-llvm, rafaelauler, ayermolo, dcci, WenleiHe
Reviewed By: WenleiHe, wlei-llvm
Pull Request: https://github.com/llvm/llvm-project/pull/101094
2024-10-24 18:30:59 -07:00
|
|
|
cl::opt<bool> ShowDensity("show-density",
|
|
|
|
cl::desc("show profile density details"),
|
|
|
|
cl::Optional, cl::cat(AggregatorCategory));
|
|
|
|
|
2022-06-05 13:29:49 -07:00
|
|
|
cl::opt<bool> SplitEH("split-eh", cl::desc("split C++ exception handling code"),
|
|
|
|
cl::Hidden, cl::cat(BoltOptCategory));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
|
|
|
cl::opt<bool>
|
2022-06-05 13:29:49 -07:00
|
|
|
StrictMode("strict",
|
|
|
|
cl::desc("trust the input to be from a well-formed source"),
|
2021-10-08 11:47:10 -07:00
|
|
|
|
2022-06-05 13:29:49 -07:00
|
|
|
cl::cat(BoltCategory));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
2023-06-28 17:53:54 -07:00
|
|
|
cl::opt<bool> TimeOpts("time-opts",
|
|
|
|
cl::desc("print time spent in each optimization"),
|
|
|
|
cl::cat(BoltOptCategory));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
2024-05-22 11:04:12 -07:00
|
|
|
cl::opt<bool> TimeRewrite("time-rewrite",
|
|
|
|
cl::desc("print time spent in rewriting passes"),
|
|
|
|
cl::Hidden, cl::cat(BoltCategory));
|
|
|
|
|
2022-06-05 13:29:49 -07:00
|
|
|
cl::opt<bool> UseOldText(
|
|
|
|
"use-old-text",
|
|
|
|
cl::desc("re-use space in old .text if possible (relocation mode)"),
|
|
|
|
cl::cat(BoltCategory));
|
|
|
|
|
|
|
|
cl::opt<bool> UpdateDebugSections(
|
|
|
|
"update-debug-sections",
|
|
|
|
cl::desc("update DWARF debug sections of the executable"),
|
|
|
|
cl::cat(BoltCategory));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
|
|
|
cl::opt<unsigned>
|
2022-06-29 12:32:45 +02:00
|
|
|
Verbosity("v", cl::desc("set verbosity level for diagnostic output"),
|
|
|
|
cl::init(0), cl::ZeroOrMore, cl::cat(BoltCategory),
|
|
|
|
cl::sub(cl::SubCommand::getAll()));
|
2021-10-08 11:47:10 -07:00
|
|
|
|
|
|
|
bool processAllFunctions() {
|
|
|
|
if (opts::AggregateOnly)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (UseOldText || StrictMode)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace opts
|