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 "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<bool> 135 Instrument("instrument", 136 cl::desc("instrument code to generate accurate profile data"), 137 cl::ZeroOrMore, cl::cat(BoltOptCategory)); 138 139 cl::opt<std::string> 140 OutputFilename("o", 141 cl::desc("<output file>"), 142 cl::Optional, 143 cl::cat(BoltOutputCategory)); 144 145 cl::opt<std::string> 146 PerfData("perfdata", 147 cl::desc("<data file>"), 148 cl::Optional, 149 cl::cat(AggregatorCategory), 150 cl::sub(*cl::AllSubCommands)); 151 152 static cl::alias 153 PerfDataA("p", 154 cl::desc("alias for -perfdata"), 155 cl::aliasopt(PerfData), 156 cl::cat(AggregatorCategory)); 157 158 cl::opt<bool> 159 PrintCacheMetrics("print-cache-metrics", 160 cl::desc("calculate and print various metrics for instruction cache"), 161 cl::init(false), 162 cl::ZeroOrMore, 163 cl::cat(BoltOptCategory)); 164 165 cl::opt<bool> 166 PrintSections("print-sections", 167 cl::desc("print all registered sections"), 168 cl::ZeroOrMore, 169 cl::Hidden, 170 cl::cat(BoltCategory)); 171 172 cl::opt<bool> 173 SplitEH("split-eh", 174 cl::desc("split C++ exception handling code"), 175 cl::ZeroOrMore, 176 cl::Hidden, 177 cl::cat(BoltOptCategory)); 178 179 cl::opt<bool> 180 StrictMode("strict", 181 cl::desc("trust the input to be from a well-formed source"), 182 cl::init(false), 183 cl::ZeroOrMore, 184 cl::cat(BoltCategory)); 185 186 llvm::cl::opt<bool> 187 TimeOpts("time-opts", 188 cl::desc("print time spent in each optimization"), 189 cl::init(false), 190 cl::ZeroOrMore, 191 cl::cat(BoltOptCategory)); 192 193 cl::opt<bool> 194 UseOldText("use-old-text", 195 cl::desc("re-use space in old .text if possible (relocation mode)"), 196 cl::ZeroOrMore, 197 cl::cat(BoltCategory)); 198 199 cl::opt<bool> 200 UpdateDebugSections("update-debug-sections", 201 cl::desc("update DWARF debug sections of the executable"), 202 cl::ZeroOrMore, 203 cl::cat(BoltCategory)); 204 205 cl::opt<unsigned> 206 Verbosity("v", 207 cl::desc("set verbosity level for diagnostic output"), 208 cl::init(0), 209 cl::ZeroOrMore, 210 cl::cat(BoltCategory), 211 cl::sub(*cl::AllSubCommands)); 212 213 bool processAllFunctions() { 214 if (opts::AggregateOnly) 215 return false; 216 217 if (UseOldText || StrictMode) 218 return true; 219 220 return false; 221 } 222 223 } // namespace opts 224