12f09f445SMaksim Panchenko //===- bolt/Utils/CommandLineOpts.cpp - BOLT CLI options ------------------===// 2a34c753fSRafael Auler // 3a34c753fSRafael Auler // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4a34c753fSRafael Auler // See https://llvm.org/LICENSE.txt for license information. 5a34c753fSRafael Auler // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6a34c753fSRafael Auler // 7a34c753fSRafael Auler //===----------------------------------------------------------------------===// 8a34c753fSRafael Auler // 9a34c753fSRafael Auler // BOLT CLI options 10a34c753fSRafael Auler // 11a34c753fSRafael Auler //===----------------------------------------------------------------------===// 12a34c753fSRafael Auler 13a34c753fSRafael Auler #include "bolt/Utils/CommandLineOpts.h" 14abc2eae6STristan Ross #include "VCSVersion.inc" 15a34c753fSRafael Auler 16a34c753fSRafael Auler using namespace llvm; 17a34c753fSRafael Auler 18a34c753fSRafael Auler namespace llvm { 19a34c753fSRafael Auler namespace bolt { 204f277f28SAmir Ayupov const char *BoltRevision = 21abc2eae6STristan Ross #ifdef BOLT_REVISION 22abc2eae6STristan Ross BOLT_REVISION; 234f277f28SAmir Ayupov #else 244f277f28SAmir Ayupov "<unknown>"; 254f277f28SAmir Ayupov #endif 26a34c753fSRafael Auler } 27a34c753fSRafael Auler } 28a34c753fSRafael Auler 29a34c753fSRafael Auler namespace opts { 30a34c753fSRafael Auler 31a34c753fSRafael Auler bool HeatmapMode = false; 32*ceb7214bSKristof Beyls bool BinaryAnalysisMode = false; 33a34c753fSRafael Auler 34a34c753fSRafael Auler cl::OptionCategory BoltCategory("BOLT generic options"); 35a34c753fSRafael Auler cl::OptionCategory BoltDiffCategory("BOLTDIFF generic options"); 36a34c753fSRafael Auler cl::OptionCategory BoltOptCategory("BOLT optimization options"); 37a34c753fSRafael Auler cl::OptionCategory BoltRelocCategory("BOLT options in relocation mode"); 38a34c753fSRafael Auler cl::OptionCategory BoltOutputCategory("Output options"); 39a34c753fSRafael Auler cl::OptionCategory AggregatorCategory("Data aggregation options"); 40a34c753fSRafael Auler cl::OptionCategory BoltInstrCategory("BOLT instrumentation options"); 415c2ae5f4SVladislav Khmelevsky cl::OptionCategory HeatmapCategory("Heatmap options"); 42*ceb7214bSKristof Beyls cl::OptionCategory BinaryAnalysisCategory("BinaryAnalysis options"); 43a34c753fSRafael Auler 44b92436efSFangrui Song cl::opt<unsigned> AlignText("align-text", 45b92436efSFangrui Song cl::desc("alignment of .text section"), cl::Hidden, 46a34c753fSRafael Auler cl::cat(BoltCategory)); 47a34c753fSRafael Auler 488ab69baaSVladislav Khmelevsky cl::opt<unsigned> AlignFunctions( 498ab69baaSVladislav Khmelevsky "align-functions", 508ab69baaSVladislav Khmelevsky cl::desc("align functions at a given value (relocation mode)"), 5136c7d79dSFangrui Song cl::init(64), cl::cat(BoltOptCategory)); 528ab69baaSVladislav Khmelevsky 53a34c753fSRafael Auler cl::opt<bool> 54a34c753fSRafael Auler AggregateOnly("aggregate-only", 55a34c753fSRafael Auler cl::desc("exit after writing aggregated data file"), 56a34c753fSRafael Auler cl::Hidden, 57a34c753fSRafael Auler cl::cat(AggregatorCategory)); 58a34c753fSRafael Auler 59a34c753fSRafael Auler cl::opt<unsigned> 60a34c753fSRafael Auler BucketsPerLine("line-size", 61a34c753fSRafael Auler cl::desc("number of entries per line (default 256)"), 625c2ae5f4SVladislav Khmelevsky cl::init(256), cl::Optional, cl::cat(HeatmapCategory)); 63a34c753fSRafael Auler 64a34c753fSRafael Auler cl::opt<bool> 65a34c753fSRafael Auler DiffOnly("diff-only", 66a34c753fSRafael Auler cl::desc("stop processing once we have enough to compare two binaries"), 67a34c753fSRafael Auler cl::Hidden, 68a34c753fSRafael Auler cl::cat(BoltDiffCategory)); 69a34c753fSRafael Auler 70a34c753fSRafael Auler cl::opt<bool> 71a34c753fSRafael Auler EnableBAT("enable-bat", 72a34c753fSRafael Auler cl::desc("write BOLT Address Translation tables"), 73a34c753fSRafael Auler cl::init(false), 74a34c753fSRafael Auler cl::ZeroOrMore, 75a34c753fSRafael Auler cl::cat(BoltCategory)); 76a34c753fSRafael Auler 773332904aSRafael Auler cl::opt<bool> EqualizeBBCounts( 783332904aSRafael Auler "equalize-bb-counts", 793332904aSRafael Auler cl::desc("use same count for BBs that should have equivalent count (used " 803332904aSRafael Auler "in non-LBR and shrink wrapping)"), 813332904aSRafael Auler cl::ZeroOrMore, cl::init(false), cl::Hidden, cl::cat(BoltOptCategory)); 823332904aSRafael Auler 83a34c753fSRafael Auler cl::opt<bool> RemoveSymtab("remove-symtab", cl::desc("Remove .symtab section"), 84a34c753fSRafael Auler cl::cat(BoltCategory)); 85a34c753fSRafael Auler 86a34c753fSRafael Auler cl::opt<unsigned> 87a34c753fSRafael Auler ExecutionCountThreshold("execution-count-threshold", 88a34c753fSRafael Auler cl::desc("perform profiling accuracy-sensitive optimizations only if " 89a34c753fSRafael Auler "function execution count >= the threshold (default: 0)"), 90a34c753fSRafael Auler cl::init(0), 91a34c753fSRafael Auler cl::ZeroOrMore, 92a34c753fSRafael Auler cl::Hidden, 93a34c753fSRafael Auler cl::cat(BoltOptCategory)); 94a34c753fSRafael Auler 95a34c753fSRafael Auler cl::opt<unsigned> 96a34c753fSRafael Auler HeatmapBlock("block-size", 97a34c753fSRafael Auler cl::desc("size of a heat map block in bytes (default 64)"), 985c2ae5f4SVladislav Khmelevsky cl::init(64), cl::cat(HeatmapCategory)); 99a34c753fSRafael Auler 1005c2ae5f4SVladislav Khmelevsky cl::opt<unsigned long long> HeatmapMaxAddress( 1015c2ae5f4SVladislav Khmelevsky "max-address", cl::init(0xffffffff), 102a34c753fSRafael Auler cl::desc("maximum address considered valid for heatmap (default 4GB)"), 1035c2ae5f4SVladislav Khmelevsky cl::Optional, cl::cat(HeatmapCategory)); 104a34c753fSRafael Auler 1055c2ae5f4SVladislav Khmelevsky cl::opt<unsigned long long> HeatmapMinAddress( 1065c2ae5f4SVladislav Khmelevsky "min-address", cl::init(0x0), 107a34c753fSRafael Auler cl::desc("minimum address considered valid for heatmap (default 0)"), 1085c2ae5f4SVladislav Khmelevsky cl::Optional, cl::cat(HeatmapCategory)); 109a34c753fSRafael Auler 11034433fdcSPaschalis Mpeis cl::opt<bool> HeatmapPrintMappings( 11134433fdcSPaschalis Mpeis "print-mappings", cl::init(false), 11234433fdcSPaschalis Mpeis cl::desc("print mappings in the legend, between characters/blocks and text " 11334433fdcSPaschalis Mpeis "sections (default false)"), 11434433fdcSPaschalis Mpeis cl::Optional, cl::cat(HeatmapCategory)); 11534433fdcSPaschalis Mpeis 116b92436efSFangrui Song cl::opt<bool> HotData("hot-data", 117a34c753fSRafael Auler cl::desc("hot data symbols support (relocation mode)"), 118a34c753fSRafael Auler cl::cat(BoltCategory)); 119a34c753fSRafael Auler 120b92436efSFangrui Song cl::opt<bool> HotFunctionsAtEnd( 121a34c753fSRafael Auler "hot-functions-at-end", 122a34c753fSRafael Auler cl::desc( 123a34c753fSRafael Auler "if reorder-functions is used, order functions putting hottest last"), 124a34c753fSRafael Auler cl::cat(BoltCategory)); 125a34c753fSRafael Auler 126a34c753fSRafael Auler cl::opt<bool> HotText( 127a34c753fSRafael Auler "hot-text", 128a34c753fSRafael Auler cl::desc( 129a34c753fSRafael Auler "Generate hot text symbols. Apply this option to a precompiled binary " 130a34c753fSRafael Auler "that manually calls into hugify, such that at runtime hugify call " 131a34c753fSRafael Auler "will put hot code into 2M pages. This requires relocation."), 132a34c753fSRafael Auler cl::ZeroOrMore, cl::cat(BoltCategory)); 133a34c753fSRafael Auler 134a34c753fSRafael Auler cl::opt<bool> 135a34c753fSRafael Auler Instrument("instrument", 136a34c753fSRafael Auler cl::desc("instrument code to generate accurate profile data"), 137b92436efSFangrui Song cl::cat(BoltOptCategory)); 138a34c753fSRafael Auler 13949fdbbcfSShaw Young cl::opt<bool> Lite("lite", cl::desc("skip processing of cold functions"), 14049fdbbcfSShaw Young cl::cat(BoltCategory)); 14149fdbbcfSShaw Young 142a34c753fSRafael Auler cl::opt<std::string> 143a34c753fSRafael Auler OutputFilename("o", 144a34c753fSRafael Auler cl::desc("<output file>"), 145a34c753fSRafael Auler cl::Optional, 146a34c753fSRafael Auler cl::cat(BoltOutputCategory)); 147a34c753fSRafael Auler 148f7872cdcSNicolai Hähnle cl::opt<std::string> PerfData("perfdata", cl::desc("<data file>"), cl::Optional, 149a34c753fSRafael Auler cl::cat(AggregatorCategory), 150f7872cdcSNicolai Hähnle cl::sub(cl::SubCommand::getAll())); 151a34c753fSRafael Auler 152a34c753fSRafael Auler static cl::alias 153a34c753fSRafael Auler PerfDataA("p", 154a34c753fSRafael Auler cl::desc("alias for -perfdata"), 155a34c753fSRafael Auler cl::aliasopt(PerfData), 156a34c753fSRafael Auler cl::cat(AggregatorCategory)); 157a34c753fSRafael Auler 158b92436efSFangrui Song cl::opt<bool> PrintCacheMetrics( 159b92436efSFangrui Song "print-cache-metrics", 160a34c753fSRafael Auler cl::desc("calculate and print various metrics for instruction cache"), 161a34c753fSRafael Auler cl::cat(BoltOptCategory)); 162a34c753fSRafael Auler 163b92436efSFangrui Song cl::opt<bool> PrintSections("print-sections", 164a34c753fSRafael Auler cl::desc("print all registered sections"), 165b92436efSFangrui Song cl::Hidden, cl::cat(BoltCategory)); 166a34c753fSRafael Auler 16739336fc0SAmir Ayupov cl::opt<ProfileFormatKind> ProfileFormat( 16839336fc0SAmir Ayupov "profile-format", 16939336fc0SAmir Ayupov cl::desc( 17039336fc0SAmir Ayupov "format to dump profile output in aggregation mode, default is fdata"), 17139336fc0SAmir Ayupov cl::init(PF_Fdata), 17239336fc0SAmir Ayupov cl::values(clEnumValN(PF_Fdata, "fdata", "offset-based plaintext format"), 1731a2f8336Sspaette clEnumValN(PF_YAML, "yaml", "dense YAML representation")), 17439336fc0SAmir Ayupov cl::ZeroOrMore, cl::Hidden, cl::cat(BoltCategory)); 17539336fc0SAmir Ayupov 17662806811SAmir Ayupov cl::opt<std::string> SaveProfile("w", 17762806811SAmir Ayupov cl::desc("save recorded profile to a file"), 17862806811SAmir Ayupov cl::cat(BoltOutputCategory)); 17962806811SAmir Ayupov 1806ee5ff95SAmir Ayupov cl::opt<bool> ShowDensity("show-density", 1816ee5ff95SAmir Ayupov cl::desc("show profile density details"), 1826ee5ff95SAmir Ayupov cl::Optional, cl::cat(AggregatorCategory)); 1836ee5ff95SAmir Ayupov 184b92436efSFangrui Song cl::opt<bool> SplitEH("split-eh", cl::desc("split C++ exception handling code"), 185b92436efSFangrui Song cl::Hidden, cl::cat(BoltOptCategory)); 186a34c753fSRafael Auler 187a34c753fSRafael Auler cl::opt<bool> 188a34c753fSRafael Auler StrictMode("strict", 189a34c753fSRafael Auler cl::desc("trust the input to be from a well-formed source"), 190b92436efSFangrui Song 191a34c753fSRafael Auler cl::cat(BoltCategory)); 192a34c753fSRafael Auler 1932f3f7d12SAmir Ayupov cl::opt<bool> TimeOpts("time-opts", 194a34c753fSRafael Auler cl::desc("print time spent in each optimization"), 195a34c753fSRafael Auler cl::cat(BoltOptCategory)); 196a34c753fSRafael Auler 19796378b3dSshaw young cl::opt<bool> TimeRewrite("time-rewrite", 19896378b3dSshaw young cl::desc("print time spent in rewriting passes"), 19996378b3dSshaw young cl::Hidden, cl::cat(BoltCategory)); 20096378b3dSshaw young 201b92436efSFangrui Song cl::opt<bool> UseOldText( 202b92436efSFangrui Song "use-old-text", 203a34c753fSRafael Auler cl::desc("re-use space in old .text if possible (relocation mode)"), 204a34c753fSRafael Auler cl::cat(BoltCategory)); 205a34c753fSRafael Auler 206b92436efSFangrui Song cl::opt<bool> UpdateDebugSections( 207b92436efSFangrui Song "update-debug-sections", 208a34c753fSRafael Auler cl::desc("update DWARF debug sections of the executable"), 209a34c753fSRafael Auler cl::cat(BoltCategory)); 210a34c753fSRafael Auler 211a34c753fSRafael Auler cl::opt<unsigned> 212f7872cdcSNicolai Hähnle Verbosity("v", cl::desc("set verbosity level for diagnostic output"), 213f7872cdcSNicolai Hähnle cl::init(0), cl::ZeroOrMore, cl::cat(BoltCategory), 214f7872cdcSNicolai Hähnle cl::sub(cl::SubCommand::getAll())); 215a34c753fSRafael Auler 216a34c753fSRafael Auler bool processAllFunctions() { 217a34c753fSRafael Auler if (opts::AggregateOnly) 218a34c753fSRafael Auler return false; 219a34c753fSRafael Auler 220a34c753fSRafael Auler if (UseOldText || StrictMode) 221a34c753fSRafael Auler return true; 222a34c753fSRafael Auler 223a34c753fSRafael Auler return false; 224a34c753fSRafael Auler } 225a34c753fSRafael Auler 226a34c753fSRafael Auler } // namespace opts 227