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