aboutsummaryrefslogtreecommitdiff
path: root/bolt/lib/Utils/CommandLineOpts.cpp
diff options
context:
space:
mode:
authorRafael Auler <rafaelauler@fb.com>2021-10-08 11:47:10 -0700
committerMaksim Panchenko <maks@fb.com>2021-10-08 11:47:10 -0700
commita34c753fe709a624f5b087397fb05adeac2311e4 (patch)
tree1c784a3d4ed1ad4ecaab64d448843f4346416d92 /bolt/lib/Utils/CommandLineOpts.cpp
parent46bc197d72a63ded00d7fce2b891e4324b7bbd9c (diff)
downloadllvm-a34c753fe709a624f5b087397fb05adeac2311e4.zip
llvm-a34c753fe709a624f5b087397fb05adeac2311e4.tar.gz
llvm-a34c753fe709a624f5b087397fb05adeac2311e4.tar.bz2
Rebase: [NFC] Refactor sources to be buildable in shared mode
Summary: Moves source files into separate components, and make explicit component dependency on each other, so LLVM build system knows how to build BOLT in BUILD_SHARED_LIBS=ON. Please use the -c merge.renamelimit=230 git option when rebasing your work on top of this change. To achieve this, we create a new library to hold core IR files (most classes beginning with Binary in their names), a new library to hold Utils, some command line options shared across both RewriteInstance and core IR files, a new library called Rewrite to hold most classes concerned with running top-level functions coordinating the binary rewriting process, and a new library called Profile to hold classes dealing with profile reading and writing. To remove the dependency from BinaryContext into X86-specific classes, we do some refactoring on the BinaryContext constructor to receive a reference to the specific backend directly from RewriteInstance. Then, the dependency on X86 or AArch64-specific classes is transfered to the Rewrite library. We can't have the Core library depend on targets because targets depend on Core (which would create a cycle). Files implementing the entry point of a tool are transferred to the tools/ folder. All header files are transferred to the include/ folder. The src/ folder was renamed to lib/. (cherry picked from FBD32746834)
Diffstat (limited to 'bolt/lib/Utils/CommandLineOpts.cpp')
-rw-r--r--bolt/lib/Utils/CommandLineOpts.cpp232
1 files changed, 232 insertions, 0 deletions
diff --git a/bolt/lib/Utils/CommandLineOpts.cpp b/bolt/lib/Utils/CommandLineOpts.cpp
new file mode 100644
index 0000000..30e98c1
--- /dev/null
+++ b/bolt/lib/Utils/CommandLineOpts.cpp
@@ -0,0 +1,232 @@
+//===--- CommandLineOpts.cpp - BOLT CLI options ---------------------------===//
+//
+// 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"
+
+using namespace llvm;
+
+namespace llvm {
+namespace bolt {
+const char *BoltRevision =
+#include "BoltRevision.inc"
+;
+}
+}
+
+namespace opts {
+
+bool HeatmapMode = false;
+bool LinuxKernelMode = 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");
+
+cl::SubCommand HeatmapCommand("heatmap", "generate heatmap");
+
+cl::opt<unsigned>
+AlignText("align-text",
+ cl::desc("alignment of .text section"),
+ cl::ZeroOrMore,
+ cl::Hidden,
+ cl::cat(BoltCategory));
+
+cl::opt<bool>
+AggregateOnly("aggregate-only",
+ cl::desc("exit after writing aggregated data file"),
+ cl::Hidden,
+ cl::cat(AggregatorCategory));
+
+cl::opt<unsigned>
+BucketsPerLine("line-size",
+ cl::desc("number of entries per line (default 256)"),
+ cl::init(256),
+ cl::Optional,
+ cl::sub(HeatmapCommand));
+
+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));
+
+cl::opt<bool> RemoveSymtab("remove-symtab", cl::desc("Remove .symtab section"),
+ cl::init(false), cl::ZeroOrMore,
+ 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>
+HeatmapBlock("block-size",
+ cl::desc("size of a heat map block in bytes (default 64)"),
+ cl::init(64),
+ cl::sub(HeatmapCommand));
+
+cl::opt<std::string>
+HeatmapFile("o",
+ cl::init("-"),
+ cl::desc("heatmap output file (default stdout)"),
+ cl::Optional,
+ cl::sub(HeatmapCommand));
+
+cl::opt<unsigned long long>
+HeatmapMaxAddress("max-address",
+ cl::init(0xffffffff),
+ cl::desc("maximum address considered valid for heatmap (default 4GB)"),
+ cl::Optional,
+ cl::sub(HeatmapCommand));
+
+cl::opt<unsigned long long>
+HeatmapMinAddress("min-address",
+ cl::init(0x0),
+ cl::desc("minimum address considered valid for heatmap (default 0)"),
+ cl::Optional,
+ cl::sub(HeatmapCommand));
+
+cl::opt<bool>
+HotData("hot-data",
+ cl::desc("hot data symbols support (relocation mode)"),
+ cl::ZeroOrMore,
+ cl::cat(BoltCategory));
+
+cl::opt<bool>
+HotFunctionsAtEnd(
+ "hot-functions-at-end",
+ cl::desc(
+ "if reorder-functions is used, order functions putting hottest last"),
+ cl::ZeroOrMore,
+ cl::cat(BoltCategory));
+
+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<std::string>
+InputFilename(
+ cl::Positional,
+ cl::desc("<executable>"),
+ cl::Required,
+ cl::cat(BoltCategory),
+ cl::sub(*cl::AllSubCommands));
+
+cl::opt<bool>
+ Instrument("instrument",
+ cl::desc("instrument code to generate accurate profile data"),
+ cl::ZeroOrMore, cl::cat(BoltOptCategory));
+
+cl::opt<std::string>
+OutputFilename("o",
+ cl::desc("<output file>"),
+ cl::Optional,
+ cl::cat(BoltOutputCategory));
+
+cl::opt<std::string>
+PerfData("perfdata",
+ cl::desc("<data file>"),
+ cl::Optional,
+ cl::cat(AggregatorCategory),
+ cl::sub(*cl::AllSubCommands));
+
+static cl::alias
+PerfDataA("p",
+ cl::desc("alias for -perfdata"),
+ cl::aliasopt(PerfData),
+ cl::cat(AggregatorCategory));
+
+cl::opt<bool>
+PrintCacheMetrics("print-cache-metrics",
+ cl::desc("calculate and print various metrics for instruction cache"),
+ cl::init(false),
+ cl::ZeroOrMore,
+ cl::cat(BoltOptCategory));
+
+cl::opt<bool>
+ PrintSections("print-sections",
+ cl::desc("print all registered sections"),
+ cl::ZeroOrMore,
+ cl::Hidden,
+ cl::cat(BoltCategory));
+
+cl::opt<bool>
+SplitEH("split-eh",
+ cl::desc("split C++ exception handling code"),
+ cl::ZeroOrMore,
+ cl::Hidden,
+ cl::cat(BoltOptCategory));
+
+cl::opt<bool>
+StrictMode("strict",
+ cl::desc("trust the input to be from a well-formed source"),
+ cl::init(false),
+ cl::ZeroOrMore,
+ cl::cat(BoltCategory));
+
+llvm::cl::opt<bool>
+TimeOpts("time-opts",
+ cl::desc("print time spent in each optimization"),
+ cl::init(false),
+ cl::ZeroOrMore,
+ cl::cat(BoltOptCategory));
+
+cl::opt<bool>
+UseOldText("use-old-text",
+ cl::desc("re-use space in old .text if possible (relocation mode)"),
+ cl::ZeroOrMore,
+ cl::cat(BoltCategory));
+
+cl::opt<bool>
+UpdateDebugSections("update-debug-sections",
+ cl::desc("update DWARF debug sections of the executable"),
+ cl::ZeroOrMore,
+ cl::cat(BoltCategory));
+
+cl::opt<unsigned>
+Verbosity("v",
+ cl::desc("set verbosity level for diagnostic output"),
+ cl::init(0),
+ cl::ZeroOrMore,
+ cl::cat(BoltCategory),
+ cl::sub(*cl::AllSubCommands));
+
+bool processAllFunctions() {
+ if (opts::AggregateOnly)
+ return false;
+
+ if (UseOldText || StrictMode)
+ return true;
+
+ return false;
+}
+
+} // namespace opts