Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 //===- subzero/src/IceClFlags.cpp - Command line flags and parsing --------===// | |
| 2 // | |
| 3 // The Subzero Code Generator | |
| 4 // | |
| 5 // This file is distributed under the University of Illinois Open Source | |
| 6 // License. See LICENSE.TXT for details. | |
| 7 // | |
| 8 //===----------------------------------------------------------------------===// | |
| 9 // | |
| 10 // This file defines commandline flags parsing. | |
| 11 // This currently relies on llvm::cl to parse. In the future, the minimal | |
| 12 // build can have a simpler parser. | |
| 13 // | |
| 14 //===----------------------------------------------------------------------===// | |
| 15 | |
| 16 #include "llvm/Support/CommandLine.h" | |
| 17 | |
| 18 #include "IceClFlags.h" | |
| 19 #include "IceClFlagsExtra.h" | |
| 20 | |
| 21 // Options which are captured in Ice::ClFlags and propagated. | |
| 22 | |
| 23 namespace cl = llvm::cl; | |
|
Jim Stichnoth
2015/03/25 16:34:06
Move this to be above the comment above? Since na
jvoung (off chromium)
2015/03/25 18:14:35
Done.
| |
| 24 | |
| 25 static cl::opt<bool> AllowErrorRecovery( | |
|
Jim Stichnoth
2015/03/25 16:34:06
Can change all these from being static to being in
jvoung (off chromium)
2015/03/25 18:14:35
Done.
| |
| 26 "allow-pnacl-reader-error-recovery", | |
| 27 cl::desc("Allow error recovery when reading PNaCl bitcode."), | |
| 28 cl::init(false)); | |
| 29 | |
| 30 // This is currently needed by crosstest.py. | |
| 31 static cl::opt<bool> AllowUninitializedGlobals( | |
| 32 "allow-uninitialized-globals", | |
| 33 cl::desc("Allow global variables to be uninitialized")); | |
| 34 | |
| 35 static cl::opt<bool> | |
| 36 DataSections("fdata-sections", | |
| 37 cl::desc("Emit (global) data into separate sections")); | |
| 38 | |
| 39 static cl::opt<bool> DecorateAsm( | |
| 40 "asm-verbose", | |
| 41 cl::desc("Decorate textual asm output with register liveness info")); | |
| 42 | |
| 43 static cl::opt<std::string> | |
| 44 DefaultFunctionPrefix("default-function-prefix", | |
| 45 cl::desc("Define default function prefix for naming " | |
| 46 "unnamed functions"), | |
| 47 cl::init("Function")); | |
| 48 | |
| 49 static cl::opt<std::string> | |
| 50 DefaultGlobalPrefix("default-global-prefix", | |
| 51 cl::desc("Define default global prefix for naming " | |
| 52 "unnamed globals"), | |
| 53 cl::init("Global")); | |
| 54 static cl::opt<bool> DisableInternal("externalize", | |
| 55 cl::desc("Externalize all symbols")); | |
| 56 // Note: Modifiable only if ALLOW_DISABLE_IR_GEN. | |
| 57 static cl::opt<bool> | |
| 58 DisableIRGeneration("no-ir-gen", | |
| 59 cl::desc("Disable generating Subzero IR.")); | |
| 60 static cl::opt<bool> | |
| 61 DisableTranslation("notranslate", cl::desc("Disable Subzero translation")); | |
| 62 | |
| 63 static cl::opt<bool> | |
| 64 DumpStats("szstats", | |
| 65 cl::desc("Print statistics after translating each function")); | |
| 66 | |
| 67 static cl::opt<bool> | |
| 68 FunctionSections("ffunction-sections", | |
| 69 cl::desc("Emit functions into separate sections")); | |
| 70 | |
| 71 // Number of translation threads (in addition to the parser thread and | |
| 72 // the emitter thread). The special case of 0 means purely | |
| 73 // sequential, i.e. parser, translator, and emitter all within the | |
| 74 // same single thread. (This may need a slight rework if we expand to | |
| 75 // multiple parser or emitter threads.) | |
| 76 static cl::opt<uint32_t> NumThreads( | |
| 77 "threads", | |
| 78 cl::desc("Number of translation threads (0 for purely sequential)"), | |
| 79 // TODO(stichnot): Settle on a good default. Consider | |
| 80 // something related to std::thread::hardware_concurrency(). | |
| 81 cl::init(2)); | |
| 82 | |
| 83 static cl::opt<Ice::OptLevel> | |
| 84 OLevel(cl::desc("Optimization level"), cl::init(Ice::Opt_m1), | |
| 85 cl::value_desc("level"), | |
| 86 cl::values(clEnumValN(Ice::Opt_m1, "Om1", "-1"), | |
| 87 clEnumValN(Ice::Opt_m1, "O-1", "-1"), | |
| 88 clEnumValN(Ice::Opt_0, "O0", "0"), | |
| 89 clEnumValN(Ice::Opt_1, "O1", "1"), | |
| 90 clEnumValN(Ice::Opt_2, "O2", "2"), clEnumValEnd)); | |
| 91 | |
| 92 static cl::opt<bool> | |
| 93 EnablePhiEdgeSplit("phi-edge-split", | |
| 94 cl::desc("Enable edge splitting for Phi lowering"), | |
| 95 cl::init(true)); | |
| 96 | |
| 97 // TODO(stichnot): See if we can easily use LLVM's -rng-seed option | |
| 98 // and implementation. I expect the implementation is different and | |
| 99 // therefore the tests would need to be changed. | |
| 100 static cl::opt<unsigned long long> | |
| 101 RandomSeed("sz-seed", cl::desc("Seed the random number generator"), | |
| 102 cl::init(time(0))); | |
| 103 | |
| 104 static cl::opt<bool> ShouldDoNopInsertion("nop-insertion", | |
| 105 cl::desc("Randomly insert NOPs"), | |
| 106 cl::init(false)); | |
| 107 | |
| 108 static cl::opt<bool> | |
| 109 RandomizeRegisterAllocation("randomize-regalloc", | |
| 110 cl::desc("Randomize register allocation"), | |
| 111 cl::init(false)); | |
| 112 | |
| 113 static cl::opt<bool> SubzeroTimingEnabled( | |
| 114 "timing", cl::desc("Enable breakdown timing of Subzero translation")); | |
| 115 | |
| 116 static cl::opt<Ice::TargetArch> | |
| 117 TArch("target", cl::desc("Target architecture:"), | |
| 118 cl::init(Ice::Target_X8632), | |
| 119 cl::values( | |
| 120 clEnumValN(Ice::Target_X8632, "x8632", "x86-32"), | |
| 121 clEnumValN(Ice::Target_X8632, "x86-32", "x86-32 (same as x8632)"), | |
| 122 clEnumValN(Ice::Target_X8632, "x86_32", "x86-32 (same as x8632)"), | |
| 123 clEnumValN(Ice::Target_X8664, "x8664", "x86-64"), | |
| 124 clEnumValN(Ice::Target_X8664, "x86-64", "x86-64 (same as x8664)"), | |
| 125 clEnumValN(Ice::Target_X8664, "x86_64", "x86-64 (same as x8664)"), | |
| 126 clEnumValN(Ice::Target_ARM32, "arm", "arm32"), | |
| 127 clEnumValN(Ice::Target_ARM32, "arm32", "arm32 (same as arm)"), | |
| 128 clEnumValN(Ice::Target_ARM64, "arm64", "arm64"), clEnumValEnd)); | |
| 129 static cl::opt<Ice::TargetInstructionSet> TInstructionSet( | |
| 130 "mattr", cl::desc("Target architecture attributes"), | |
| 131 cl::init(Ice::X86InstructionSet_SSE2), | |
| 132 cl::values(clEnumValN(Ice::X86InstructionSet_SSE2, "sse2", | |
| 133 "Enable SSE2 instructions (default)"), | |
| 134 clEnumValN(Ice::X86InstructionSet_SSE4_1, "sse4.1", | |
| 135 "Enable SSE 4.1 instructions"), | |
| 136 clEnumValEnd)); | |
| 137 static cl::opt<std::string> | |
| 138 TestPrefix("prefix", | |
| 139 cl::desc("Prepend a prefix to symbol names for testing"), | |
| 140 cl::init(""), cl::value_desc("prefix")); | |
| 141 | |
| 142 static cl::opt<bool> TimeEachFunction( | |
| 143 "timing-funcs", cl::desc("Print total translation time for each function")); | |
| 144 | |
| 145 static cl::opt<std::string> TimingFocusOn( | |
| 146 "timing-focus", | |
| 147 cl::desc("Break down timing for a specific function (use '*' for all)"), | |
| 148 cl::init("")); | |
| 149 | |
| 150 static cl::opt<std::string> | |
| 151 TranslateOnly("translate-only", | |
| 152 cl::desc("Translate only the given function"), cl::init("")); | |
| 153 | |
| 154 static cl::opt<bool> UseSandboxing("sandbox", cl::desc("Use sandboxing")); | |
| 155 | |
| 156 static cl::opt<std::string> VerboseFocusOn( | |
| 157 "verbose-focus", | |
| 158 cl::desc("Temporarily enable full verbosity for a specific function"), | |
| 159 cl::init("")); | |
| 160 | |
| 161 static cl::opt<Ice::FileType> OutFileType( | |
| 162 "filetype", cl::desc("Output file type"), cl::init(Ice::FT_Iasm), | |
| 163 cl::values(clEnumValN(Ice::FT_Elf, "obj", "Native ELF object ('.o') file"), | |
| 164 clEnumValN(Ice::FT_Asm, "asm", "Assembly ('.s') file"), | |
| 165 clEnumValN(Ice::FT_Iasm, "iasm", | |
| 166 "Low-level integrated assembly ('.s') file"), | |
| 167 clEnumValEnd)); | |
| 168 | |
| 169 static cl::opt<int> MaxNopsPerInstruction( | |
| 170 "max-nops-per-instruction", | |
| 171 cl::desc("Max number of nops to insert per instruction"), cl::init(1)); | |
| 172 | |
| 173 static cl::opt<int> NopProbabilityAsPercentage( | |
| 174 "nop-insertion-percentage", | |
| 175 cl::desc("Nop insertion probability as percentage"), cl::init(10)); | |
| 176 | |
| 177 static cl::list<Ice::VerboseItem> VerboseList( | |
| 178 "verbose", cl::CommaSeparated, | |
| 179 cl::desc("Verbose options (can be comma-separated):"), | |
| 180 cl::values( | |
| 181 clEnumValN(Ice::IceV_Instructions, "inst", "Print basic instructions"), | |
| 182 clEnumValN(Ice::IceV_Deleted, "del", "Include deleted instructions"), | |
| 183 clEnumValN(Ice::IceV_InstNumbers, "instnum", | |
| 184 "Print instruction numbers"), | |
| 185 clEnumValN(Ice::IceV_Preds, "pred", "Show predecessors"), | |
| 186 clEnumValN(Ice::IceV_Succs, "succ", "Show successors"), | |
| 187 clEnumValN(Ice::IceV_Liveness, "live", "Liveness information"), | |
| 188 clEnumValN(Ice::IceV_RegOrigins, "orig", "Physical register origins"), | |
| 189 clEnumValN(Ice::IceV_LinearScan, "regalloc", "Linear scan details"), | |
| 190 clEnumValN(Ice::IceV_Frame, "frame", "Stack frame layout details"), | |
| 191 clEnumValN(Ice::IceV_AddrOpt, "addropt", "Address mode optimization"), | |
| 192 clEnumValN(Ice::IceV_Random, "random", "Randomization details"), | |
| 193 clEnumValN(Ice::IceV_All, "all", "Use all verbose options"), | |
| 194 clEnumValN(Ice::IceV_Most, "most", | |
| 195 "Use all verbose options except 'regalloc' and 'time'"), | |
|
Jim Stichnoth
2015/03/25 16:34:06
Oops, there's no longer a "time" option, can you r
jvoung (off chromium)
2015/03/25 18:14:35
Done.
| |
| 196 clEnumValN(Ice::IceV_None, "none", "No verbosity"), clEnumValEnd)); | |
| 197 | |
| 198 // Options not captured in Ice::ClFlags and propagated. | |
| 199 | |
| 200 static cl::opt<bool> AlwaysExitSuccess( | |
| 201 "exit-success", cl::desc("Exit with success status, even if errors found"), | |
| 202 cl::init(false)); | |
| 203 | |
| 204 // Note: While this flag isn't used in the minimal build, we keep this | |
| 205 // flag so that tests can set this command-line flag without concern | |
| 206 // to the type of build. We double check that this flag at runtime | |
| 207 // to make sure the consistency is maintained. | |
| 208 static cl::opt<bool> | |
| 209 BuildOnRead("build-on-read", | |
| 210 cl::desc("Build ICE instructions when reading bitcode"), | |
| 211 cl::init(true)); | |
| 212 | |
| 213 static cl::opt<llvm::NaClFileFormat> InputFileFormat( | |
| 214 "bitcode-format", cl::desc("Define format of input file:"), | |
| 215 cl::values(clEnumValN(llvm::LLVMFormat, "llvm", "LLVM file (default)"), | |
| 216 clEnumValN(llvm::PNaClFormat, "pnacl", "PNaCl bitcode file"), | |
| 217 clEnumValEnd), | |
| 218 cl::init(llvm::LLVMFormat)); | |
| 219 | |
| 220 static cl::opt<bool> GenerateBuildAtts( | |
| 221 "build-atts", cl::desc("Generate list of build attributes associated with " | |
| 222 "this executable."), | |
| 223 cl::init(false)); | |
| 224 | |
| 225 static cl::opt<std::string> IRFilename(cl::Positional, cl::desc("<IR file>"), | |
| 226 cl::init("-")); | |
| 227 static cl::opt<std::string> LogFilename("log", cl::desc("Set log filename"), | |
| 228 cl::init("-"), | |
| 229 cl::value_desc("filename")); | |
| 230 static cl::opt<bool> LLVMVerboseErrors( | |
| 231 "verbose-llvm-parse-errors", | |
| 232 cl::desc("Print out more descriptive PNaCl bitcode parse errors when " | |
| 233 "building LLVM IR first"), | |
| 234 cl::init(false)); | |
| 235 static cl::opt<std::string> OutputFilename("o", | |
| 236 cl::desc("Override output filename"), | |
| 237 cl::init("-"), | |
| 238 cl::value_desc("filename")); | |
| 239 | |
| 240 namespace Ice { | |
| 241 | |
| 242 static IceString AppName; | |
|
Jim Stichnoth
2015/03/25 16:34:06
Don't use static global variables - either make "g
jvoung (off chromium)
2015/03/25 18:14:35
Done.
| |
| 243 | |
| 244 void ClFlags::parseFlags(int argc, char **argv) { | |
| 245 cl::ParseCommandLineOptions(argc, argv); | |
| 246 AppName = IceString(argv[0]); | |
| 247 } | |
| 248 | |
| 249 void ClFlags::getParsedClFlags(ClFlags &OutFlags) { | |
| 250 if (::DisableIRGeneration) | |
| 251 ::DisableTranslation = true; | |
| 252 | |
| 253 Ice::VerboseMask VMask = Ice::IceV_None; | |
| 254 // Don't generate verbose messages if routines | |
| 255 // to dump messages are not available. | |
| 256 if (ALLOW_DUMP) { | |
| 257 for (unsigned i = 0; i != VerboseList.size(); ++i) | |
| 258 VMask |= VerboseList[i]; | |
| 259 } | |
| 260 | |
| 261 OutFlags.setAllowErrorRecovery(::AllowErrorRecovery); | |
| 262 OutFlags.setAllowUninitializedGlobals(::AllowUninitializedGlobals); | |
| 263 OutFlags.setDataSections(::DataSections); | |
| 264 OutFlags.setDecorateAsm(::DecorateAsm); | |
| 265 OutFlags.setDefaultFunctionPrefix(::DefaultFunctionPrefix); | |
| 266 OutFlags.setDefaultGlobalPrefix(::DefaultGlobalPrefix); | |
| 267 OutFlags.setDisableInternal(::DisableInternal); | |
| 268 OutFlags.setDisableIRGeneration(::DisableIRGeneration); | |
| 269 OutFlags.setDisableTranslation(::DisableTranslation); | |
| 270 OutFlags.setDumpStats(::DumpStats); | |
| 271 OutFlags.setFunctionSections(::FunctionSections); | |
| 272 OutFlags.setNumTranslationThreads(::NumThreads); | |
| 273 OutFlags.setOptLevel(::OLevel); | |
| 274 OutFlags.setPhiEdgeSplit(::EnablePhiEdgeSplit); | |
| 275 OutFlags.setRandomSeed(::RandomSeed); | |
| 276 OutFlags.setShouldDoNopInsertion(::ShouldDoNopInsertion); | |
| 277 OutFlags.setShouldRandomizeRegAlloc(::RandomizeRegisterAllocation); | |
| 278 OutFlags.setSubzeroTimingEnabled(::SubzeroTimingEnabled); | |
| 279 OutFlags.setTargetArch(::TArch); | |
| 280 OutFlags.setTargetInstructionSet(::TInstructionSet); | |
| 281 OutFlags.setTestPrefix(::TestPrefix); | |
| 282 OutFlags.setTimeEachFunction(::TimeEachFunction); | |
| 283 OutFlags.setTimingFocusOn(::TimingFocusOn); | |
| 284 OutFlags.setTranslateOnly(::TranslateOnly); | |
| 285 OutFlags.setUseSandboxing(::UseSandboxing); | |
| 286 OutFlags.setVerboseFocusOn(::VerboseFocusOn); | |
| 287 OutFlags.setOutFileType(::OutFileType); | |
| 288 OutFlags.setMaxNopsPerInstruction(::MaxNopsPerInstruction); | |
| 289 OutFlags.setNopProbabilityAsPercentage(::NopProbabilityAsPercentage); | |
| 290 OutFlags.setVerbose(VMask); | |
| 291 } | |
| 292 | |
| 293 void ClFlags::getParsedClFlagsExtra(ClFlagsExtra &OutFlagsExtra) { | |
| 294 OutFlagsExtra.setAlwaysExitSuccess(AlwaysExitSuccess); | |
| 295 OutFlagsExtra.setBuildOnRead(BuildOnRead); | |
| 296 OutFlagsExtra.setGenerateBuildAtts(GenerateBuildAtts); | |
| 297 OutFlagsExtra.setLLVMVerboseErrors(LLVMVerboseErrors); | |
| 298 OutFlagsExtra.setAppName(AppName); | |
| 299 OutFlagsExtra.setInputFileFormat(InputFileFormat); | |
| 300 OutFlagsExtra.setIRFilename(IRFilename); | |
| 301 OutFlagsExtra.setLogFilename(LogFilename); | |
| 302 OutFlagsExtra.setOutputFilename(OutputFilename); | |
| 303 } | |
| 304 | |
| 305 } // end of namespace Ice | |
| OLD | NEW |