1 //===--- 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 "bolt/Utils/BoltRevision.inc" 15 16 using namespace llvm; 17 18 namespace llvm { 19 namespace bolt { 20 const char *BoltRevision = BOLT_VERSION_STRING; 21 } 22 } 23 24 namespace opts { 25 26 bool HeatmapMode = false; 27 bool LinuxKernelMode = false; 28 29 cl::OptionCategory BoltCategory("BOLT generic options"); 30 cl::OptionCategory BoltDiffCategory("BOLTDIFF generic options"); 31 cl::OptionCategory BoltOptCategory("BOLT optimization options"); 32 cl::OptionCategory BoltRelocCategory("BOLT options in relocation mode"); 33 cl::OptionCategory BoltOutputCategory("Output options"); 34 cl::OptionCategory AggregatorCategory("Data aggregation options"); 35 cl::OptionCategory BoltInstrCategory("BOLT instrumentation options"); 36 37 cl::SubCommand HeatmapCommand("heatmap", "generate heatmap"); 38 39 cl::opt<unsigned> 40 AlignText("align-text", 41 cl::desc("alignment of .text section"), 42 cl::ZeroOrMore, 43 cl::Hidden, 44 cl::cat(BoltCategory)); 45 46 cl::opt<bool> 47 AggregateOnly("aggregate-only", 48 cl::desc("exit after writing aggregated data file"), 49 cl::Hidden, 50 cl::cat(AggregatorCategory)); 51 52 cl::opt<unsigned> 53 BucketsPerLine("line-size", 54 cl::desc("number of entries per line (default 256)"), 55 cl::init(256), 56 cl::Optional, 57 cl::sub(HeatmapCommand)); 58 59 cl::opt<bool> 60 DiffOnly("diff-only", 61 cl::desc("stop processing once we have enough to compare two binaries"), 62 cl::Hidden, 63 cl::cat(BoltDiffCategory)); 64 65 cl::opt<bool> 66 EnableBAT("enable-bat", 67 cl::desc("write BOLT Address Translation tables"), 68 cl::init(false), 69 cl::ZeroOrMore, 70 cl::cat(BoltCategory)); 71 72 cl::opt<bool> RemoveSymtab("remove-symtab", cl::desc("Remove .symtab section"), 73 cl::init(false), cl::ZeroOrMore, 74 cl::cat(BoltCategory)); 75 76 cl::opt<unsigned> 77 ExecutionCountThreshold("execution-count-threshold", 78 cl::desc("perform profiling accuracy-sensitive optimizations only if " 79 "function execution count >= the threshold (default: 0)"), 80 cl::init(0), 81 cl::ZeroOrMore, 82 cl::Hidden, 83 cl::cat(BoltOptCategory)); 84 85 cl::opt<unsigned> 86 HeatmapBlock("block-size", 87 cl::desc("size of a heat map block in bytes (default 64)"), 88 cl::init(64), 89 cl::sub(HeatmapCommand)); 90 91 cl::opt<std::string> 92 HeatmapFile("o", 93 cl::init("-"), 94 cl::desc("heatmap output file (default stdout)"), 95 cl::Optional, 96 cl::sub(HeatmapCommand)); 97 98 cl::opt<unsigned long long> 99 HeatmapMaxAddress("max-address", 100 cl::init(0xffffffff), 101 cl::desc("maximum address considered valid for heatmap (default 4GB)"), 102 cl::Optional, 103 cl::sub(HeatmapCommand)); 104 105 cl::opt<unsigned long long> 106 HeatmapMinAddress("min-address", 107 cl::init(0x0), 108 cl::desc("minimum address considered valid for heatmap (default 0)"), 109 cl::Optional, 110 cl::sub(HeatmapCommand)); 111 112 cl::opt<bool> 113 HotData("hot-data", 114 cl::desc("hot data symbols support (relocation mode)"), 115 cl::ZeroOrMore, 116 cl::cat(BoltCategory)); 117 118 cl::opt<bool> 119 HotFunctionsAtEnd( 120 "hot-functions-at-end", 121 cl::desc( 122 "if reorder-functions is used, order functions putting hottest last"), 123 cl::ZeroOrMore, 124 cl::cat(BoltCategory)); 125 126 cl::opt<bool> HotText( 127 "hot-text", 128 cl::desc( 129 "Generate hot text symbols. Apply this option to a precompiled binary " 130 "that manually calls into hugify, such that at runtime hugify call " 131 "will put hot code into 2M pages. This requires relocation."), 132 cl::ZeroOrMore, cl::cat(BoltCategory)); 133 134 cl::opt<std::string> 135 InputFilename( 136 cl::Positional, 137 cl::desc("<executable>"), 138 cl::Required, 139 cl::cat(BoltCategory), 140 cl::sub(*cl::AllSubCommands)); 141 142 cl::opt<bool> 143 Instrument("instrument", 144 cl::desc("instrument code to generate accurate profile data"), 145 cl::ZeroOrMore, cl::cat(BoltOptCategory)); 146 147 cl::opt<std::string> 148 OutputFilename("o", 149 cl::desc("<output file>"), 150 cl::Optional, 151 cl::cat(BoltOutputCategory)); 152 153 cl::opt<std::string> 154 PerfData("perfdata", 155 cl::desc("<data file>"), 156 cl::Optional, 157 cl::cat(AggregatorCategory), 158 cl::sub(*cl::AllSubCommands)); 159 160 static cl::alias 161 PerfDataA("p", 162 cl::desc("alias for -perfdata"), 163 cl::aliasopt(PerfData), 164 cl::cat(AggregatorCategory)); 165 166 cl::opt<bool> 167 PrintCacheMetrics("print-cache-metrics", 168 cl::desc("calculate and print various metrics for instruction cache"), 169 cl::init(false), 170 cl::ZeroOrMore, 171 cl::cat(BoltOptCategory)); 172 173 cl::opt<bool> 174 PrintSections("print-sections", 175 cl::desc("print all registered sections"), 176 cl::ZeroOrMore, 177 cl::Hidden, 178 cl::cat(BoltCategory)); 179 180 cl::opt<bool> 181 SplitEH("split-eh", 182 cl::desc("split C++ exception handling code"), 183 cl::ZeroOrMore, 184 cl::Hidden, 185 cl::cat(BoltOptCategory)); 186 187 cl::opt<bool> 188 StrictMode("strict", 189 cl::desc("trust the input to be from a well-formed source"), 190 cl::init(false), 191 cl::ZeroOrMore, 192 cl::cat(BoltCategory)); 193 194 llvm::cl::opt<bool> 195 TimeOpts("time-opts", 196 cl::desc("print time spent in each optimization"), 197 cl::init(false), 198 cl::ZeroOrMore, 199 cl::cat(BoltOptCategory)); 200 201 cl::opt<bool> 202 UseOldText("use-old-text", 203 cl::desc("re-use space in old .text if possible (relocation mode)"), 204 cl::ZeroOrMore, 205 cl::cat(BoltCategory)); 206 207 cl::opt<bool> 208 UpdateDebugSections("update-debug-sections", 209 cl::desc("update DWARF debug sections of the executable"), 210 cl::ZeroOrMore, 211 cl::cat(BoltCategory)); 212 213 cl::opt<unsigned> 214 Verbosity("v", 215 cl::desc("set verbosity level for diagnostic output"), 216 cl::init(0), 217 cl::ZeroOrMore, 218 cl::cat(BoltCategory), 219 cl::sub(*cl::AllSubCommands)); 220 221 bool processAllFunctions() { 222 if (opts::AggregateOnly) 223 return false; 224 225 if (UseOldText || StrictMode) 226 return true; 227 228 return false; 229 } 230 231 } // namespace opts 232