Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: src/IceClFlags.cpp

Issue 997773002: Refactor Subzero initialization and add a browser callback handler. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Add argv note Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceClFlags.h ('k') | src/IceClFlagsExtra.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 namespace cl = llvm::cl;
22
23 // Options which are captured in Ice::ClFlags and propagated.
24
25 namespace {
26
27 cl::opt<bool> AllowErrorRecovery(
28 "allow-pnacl-reader-error-recovery",
29 cl::desc("Allow error recovery when reading PNaCl bitcode."),
30 cl::init(false));
31
32 // This is currently needed by crosstest.py.
33 cl::opt<bool> AllowUninitializedGlobals(
34 "allow-uninitialized-globals",
35 cl::desc("Allow global variables to be uninitialized"));
36
37 cl::opt<bool>
38 DataSections("fdata-sections",
39 cl::desc("Emit (global) data into separate sections"));
40
41 cl::opt<bool> DecorateAsm(
42 "asm-verbose",
43 cl::desc("Decorate textual asm output with register liveness info"));
44
45 cl::opt<std::string>
46 DefaultFunctionPrefix("default-function-prefix",
47 cl::desc("Define default function prefix for naming "
48 "unnamed functions"),
49 cl::init("Function"));
50
51 cl::opt<std::string>
52 DefaultGlobalPrefix("default-global-prefix",
53 cl::desc("Define default global prefix for naming "
54 "unnamed globals"),
55 cl::init("Global"));
56 cl::opt<bool> DisableInternal("externalize",
57 cl::desc("Externalize all symbols"));
58 // Note: Modifiable only if ALLOW_DISABLE_IR_GEN.
59 cl::opt<bool> DisableIRGeneration("no-ir-gen",
60 cl::desc("Disable generating Subzero IR."));
61 cl::opt<bool> DisableTranslation("notranslate",
62 cl::desc("Disable Subzero translation"));
63
64 cl::opt<bool>
65 DumpStats("szstats",
66 cl::desc("Print statistics after translating each function"));
67
68 cl::opt<bool>
69 FunctionSections("ffunction-sections",
70 cl::desc("Emit functions into separate sections"));
71
72 // Number of translation threads (in addition to the parser thread and
73 // the emitter thread). The special case of 0 means purely
74 // sequential, i.e. parser, translator, and emitter all within the
75 // same single thread. (This may need a slight rework if we expand to
76 // multiple parser or emitter threads.)
77 cl::opt<uint32_t> NumThreads(
78 "threads",
79 cl::desc("Number of translation threads (0 for purely sequential)"),
80 // TODO(stichnot): Settle on a good default. Consider
81 // something related to std::thread::hardware_concurrency().
82 cl::init(2));
83
84 cl::opt<Ice::OptLevel> OLevel(cl::desc("Optimization level"),
85 cl::init(Ice::Opt_m1), 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"),
91 clEnumValEnd));
92
93 cl::opt<bool>
94 EnablePhiEdgeSplit("phi-edge-split",
95 cl::desc("Enable edge splitting for Phi lowering"),
96 cl::init(true));
97
98 // TODO(stichnot): See if we can easily use LLVM's -rng-seed option
99 // and implementation. I expect the implementation is different and
100 // therefore the tests would need to be changed.
101 cl::opt<unsigned long long>
102 RandomSeed("sz-seed", cl::desc("Seed the random number generator"),
103 cl::init(time(0)));
104
105 cl::opt<bool> ShouldDoNopInsertion("nop-insertion",
106 cl::desc("Randomly insert NOPs"),
107 cl::init(false));
108
109 cl::opt<bool>
110 RandomizeRegisterAllocation("randomize-regalloc",
111 cl::desc("Randomize register allocation"),
112 cl::init(false));
113
114 cl::opt<bool> SubzeroTimingEnabled(
115 "timing", cl::desc("Enable breakdown timing of Subzero translation"));
116
117 cl::opt<Ice::TargetArch> TargetArch(
118 "target", cl::desc("Target architecture:"), 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 cl::opt<Ice::TargetInstructionSet> TargetInstructionSet(
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 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 cl::opt<bool> TimeEachFunction(
143 "timing-funcs", cl::desc("Print total translation time for each function"));
144
145 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 cl::opt<std::string>
151 TranslateOnly("translate-only",
152 cl::desc("Translate only the given function"), cl::init(""));
153
154 cl::opt<bool> UseSandboxing("sandbox", cl::desc("Use sandboxing"));
155
156 cl::opt<std::string> VerboseFocusOn(
157 "verbose-focus",
158 cl::desc("Temporarily enable full verbosity for a specific function"),
159 cl::init(""));
160
161 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 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 cl::opt<int> NopProbabilityAsPercentage(
174 "nop-insertion-percentage",
175 cl::desc("Nop insertion probability as percentage"), cl::init(10));
176
177 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'"),
196 clEnumValN(Ice::IceV_None, "none", "No verbosity"), clEnumValEnd));
197
198 // Options not captured in Ice::ClFlags and propagated.
199
200 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 cl::opt<bool>
209 BuildOnRead("build-on-read",
210 cl::desc("Build ICE instructions when reading bitcode"),
211 cl::init(true));
212
213 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 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 cl::opt<std::string> IRFilename(cl::Positional, cl::desc("<IR file>"),
226 cl::init("-"));
227 cl::opt<std::string> LogFilename("log", cl::desc("Set log filename"),
228 cl::init("-"), cl::value_desc("filename"));
229 cl::opt<bool> LLVMVerboseErrors(
230 "verbose-llvm-parse-errors",
231 cl::desc("Print out more descriptive PNaCl bitcode parse errors when "
232 "building LLVM IR first"),
233 cl::init(false));
234 cl::opt<std::string> OutputFilename("o", cl::desc("Override output filename"),
235 cl::init("-"), cl::value_desc("filename"));
236
237 Ice::IceString AppName;
238
239 } // end of anonymous namespace
240
241 namespace Ice {
242
243 void ClFlags::parseFlags(int argc, char **argv) {
244 cl::ParseCommandLineOptions(argc, argv);
245 AppName = IceString(argv[0]);
246 }
247
248 void ClFlags::getParsedClFlags(ClFlags &OutFlags) {
249 if (::DisableIRGeneration)
250 ::DisableTranslation = true;
251
252 Ice::VerboseMask VMask = Ice::IceV_None;
253 // Don't generate verbose messages if routines
254 // to dump messages are not available.
255 if (ALLOW_DUMP) {
256 for (unsigned i = 0; i != VerboseList.size(); ++i)
257 VMask |= VerboseList[i];
258 }
259
260 OutFlags.setAllowErrorRecovery(::AllowErrorRecovery);
261 OutFlags.setAllowUninitializedGlobals(::AllowUninitializedGlobals);
262 OutFlags.setDataSections(::DataSections);
263 OutFlags.setDecorateAsm(::DecorateAsm);
264 OutFlags.setDefaultFunctionPrefix(::DefaultFunctionPrefix);
265 OutFlags.setDefaultGlobalPrefix(::DefaultGlobalPrefix);
266 OutFlags.setDisableInternal(::DisableInternal);
267 OutFlags.setDisableIRGeneration(::DisableIRGeneration);
268 OutFlags.setDisableTranslation(::DisableTranslation);
269 OutFlags.setDumpStats(::DumpStats);
270 OutFlags.setFunctionSections(::FunctionSections);
271 OutFlags.setNumTranslationThreads(::NumThreads);
272 OutFlags.setOptLevel(::OLevel);
273 OutFlags.setPhiEdgeSplit(::EnablePhiEdgeSplit);
274 OutFlags.setRandomSeed(::RandomSeed);
275 OutFlags.setShouldDoNopInsertion(::ShouldDoNopInsertion);
276 OutFlags.setShouldRandomizeRegAlloc(::RandomizeRegisterAllocation);
277 OutFlags.setSubzeroTimingEnabled(::SubzeroTimingEnabled);
278 OutFlags.setTargetArch(::TargetArch);
279 OutFlags.setTargetInstructionSet(::TargetInstructionSet);
280 OutFlags.setTestPrefix(::TestPrefix);
281 OutFlags.setTimeEachFunction(::TimeEachFunction);
282 OutFlags.setTimingFocusOn(::TimingFocusOn);
283 OutFlags.setTranslateOnly(::TranslateOnly);
284 OutFlags.setUseSandboxing(::UseSandboxing);
285 OutFlags.setVerboseFocusOn(::VerboseFocusOn);
286 OutFlags.setOutFileType(::OutFileType);
287 OutFlags.setMaxNopsPerInstruction(::MaxNopsPerInstruction);
288 OutFlags.setNopProbabilityAsPercentage(::NopProbabilityAsPercentage);
289 OutFlags.setVerbose(VMask);
290 }
291
292 void ClFlags::getParsedClFlagsExtra(ClFlagsExtra &OutFlagsExtra) {
293 OutFlagsExtra.setAlwaysExitSuccess(AlwaysExitSuccess);
294 OutFlagsExtra.setBuildOnRead(BuildOnRead);
295 OutFlagsExtra.setGenerateBuildAtts(GenerateBuildAtts);
296 OutFlagsExtra.setLLVMVerboseErrors(LLVMVerboseErrors);
297 OutFlagsExtra.setAppName(AppName);
298 OutFlagsExtra.setInputFileFormat(InputFileFormat);
299 OutFlagsExtra.setIRFilename(IRFilename);
300 OutFlagsExtra.setLogFilename(LogFilename);
301 OutFlagsExtra.setOutputFilename(OutputFilename);
302 }
303
304 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceClFlags.h ('k') | src/IceClFlagsExtra.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698