1 //===- bolt/Utils/CommandLineOpts.cpp - BOLT CLI options ------------------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // BOLT CLI options 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "bolt/Utils/CommandLineOpts.h" 14 #include "llvm/Support/VCSRevision.h" 15 16 using namespace llvm; 17 18 namespace llvm { 19 namespace bolt { 20 const char *BoltRevision = 21 #ifdef LLVM_REVISION 22 LLVM_REVISION; 23 #else 24 "<unknown>"; 25 #endif 26 } 27 } 28 29 namespace opts { 30 31 bool HeatmapMode = false; 32 bool LinuxKernelMode = false; 33 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"); 42 43 cl::opt<unsigned> AlignText("align-text", 44 cl::desc("alignment of .text section"), cl::Hidden, 45 cl::cat(BoltCategory)); 46 47 cl::opt<unsigned> AlignFunctions( 48 "align-functions", 49 cl::desc("align functions at a given value (relocation mode)"), 50 cl::init(64), cl::cat(BoltOptCategory)); 51 52 cl::opt<bool> 53 AggregateOnly("aggregate-only", 54 cl::desc("exit after writing aggregated data file"), 55 cl::Hidden, 56 cl::cat(AggregatorCategory)); 57 58 cl::opt<unsigned> 59 BucketsPerLine("line-size", 60 cl::desc("number of entries per line (default 256)"), 61 cl::init(256), cl::Optional, cl::cat(HeatmapCategory)); 62 63 cl::opt<bool> 64 DiffOnly("diff-only", 65 cl::desc("stop processing once we have enough to compare two binaries"), 66 cl::Hidden, 67 cl::cat(BoltDiffCategory)); 68 69 cl::opt<bool> 70 EnableBAT("enable-bat", 71 cl::desc("write BOLT Address Translation tables"), 72 cl::init(false), 73 cl::ZeroOrMore, 74 cl::cat(BoltCategory)); 75 76 cl::opt<bool> EqualizeBBCounts( 77 "equalize-bb-counts", 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)); 81 82 cl::opt<bool> RemoveSymtab("remove-symtab", cl::desc("Remove .symtab section"), 83 cl::cat(BoltCategory)); 84 85 cl::opt<unsigned> 86 ExecutionCountThreshold("execution-count-threshold", 87 cl::desc("perform profiling accuracy-sensitive optimizations only if " 88 "function execution count >= the threshold (default: 0)"), 89 cl::init(0), 90 cl::ZeroOrMore, 91 cl::Hidden, 92 cl::cat(BoltOptCategory)); 93 94 cl::opt<unsigned> 95 HeatmapBlock("block-size", 96 cl::desc("size of a heat map block in bytes (default 64)"), 97 cl::init(64), cl::cat(HeatmapCategory)); 98 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)); 103 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)); 108 109 cl::opt<bool> HotData("hot-data", 110 cl::desc("hot data symbols support (relocation mode)"), 111 cl::cat(BoltCategory)); 112 113 cl::opt<bool> HotFunctionsAtEnd( 114 "hot-functions-at-end", 115 cl::desc( 116 "if reorder-functions is used, order functions putting hottest last"), 117 cl::cat(BoltCategory)); 118 119 cl::opt<bool> HotText( 120 "hot-text", 121 cl::desc( 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)); 126 127 cl::opt<bool> 128 Instrument("instrument", 129 cl::desc("instrument code to generate accurate profile data"), 130 cl::cat(BoltOptCategory)); 131 132 cl::opt<std::string> 133 OutputFilename("o", 134 cl::desc("<output file>"), 135 cl::Optional, 136 cl::cat(BoltOutputCategory)); 137 138 cl::opt<std::string> 139 PerfData("perfdata", 140 cl::desc("<data file>"), 141 cl::Optional, 142 cl::cat(AggregatorCategory), 143 cl::sub(*cl::AllSubCommands)); 144 145 static cl::alias 146 PerfDataA("p", 147 cl::desc("alias for -perfdata"), 148 cl::aliasopt(PerfData), 149 cl::cat(AggregatorCategory)); 150 151 cl::opt<bool> PrintCacheMetrics( 152 "print-cache-metrics", 153 cl::desc("calculate and print various metrics for instruction cache"), 154 cl::cat(BoltOptCategory)); 155 156 cl::opt<bool> PrintSections("print-sections", 157 cl::desc("print all registered sections"), 158 cl::Hidden, cl::cat(BoltCategory)); 159 160 cl::opt<bool> SplitEH("split-eh", cl::desc("split C++ exception handling code"), 161 cl::Hidden, cl::cat(BoltOptCategory)); 162 163 cl::opt<bool> 164 StrictMode("strict", 165 cl::desc("trust the input to be from a well-formed source"), 166 167 cl::cat(BoltCategory)); 168 169 llvm::cl::opt<bool> TimeOpts("time-opts", 170 cl::desc("print time spent in each optimization"), 171 cl::cat(BoltOptCategory)); 172 173 cl::opt<bool> UseOldText( 174 "use-old-text", 175 cl::desc("re-use space in old .text if possible (relocation mode)"), 176 cl::cat(BoltCategory)); 177 178 cl::opt<bool> UpdateDebugSections( 179 "update-debug-sections", 180 cl::desc("update DWARF debug sections of the executable"), 181 cl::cat(BoltCategory)); 182 183 cl::opt<unsigned> 184 Verbosity("v", 185 cl::desc("set verbosity level for diagnostic output"), 186 cl::init(0), 187 cl::ZeroOrMore, 188 cl::cat(BoltCategory), 189 cl::sub(*cl::AllSubCommands)); 190 191 bool processAllFunctions() { 192 if (opts::AggregateOnly) 193 return false; 194 195 if (UseOldText || StrictMode) 196 return true; 197 198 return false; 199 } 200 201 } // namespace opts 202