|
50 | 50 | namespace llvm {
|
51 | 51 | namespace exegesis {
|
52 | 52 |
|
53 |
| -struct OpcodeNameParser |
54 |
| - : public cl::parser<std::vector<std::pair<StringRef, StringRef>>> { |
55 |
| - OpcodeNameParser(cl::Option &O) |
56 |
| - : cl::parser<std::vector<std::pair<StringRef, StringRef>>>(O) {} |
57 |
| - bool parse(cl::Option &O, StringRef ArgName, const StringRef ArgValue, |
58 |
| - std::vector<std::pair<StringRef, StringRef>> &Val); |
59 |
| -}; |
60 |
| - |
61 | 53 | static cl::opt<int> OpcodeIndex(
|
62 | 54 | "opcode-index",
|
63 | 55 | cl::desc("opcode to measure, by index, or -1 to measure all opcodes"),
|
64 | 56 | cl::cat(BenchmarkOptions), cl::init(0));
|
65 | 57 |
|
66 |
| -static cl::opt<std::vector<std::pair<StringRef, StringRef>>, false, |
67 |
| - OpcodeNameParser> |
| 58 | +static cl::opt<std::string> |
68 | 59 | OpcodeNames("opcode-name",
|
69 |
| - cl::desc("comma-separated list of opcodes to measure, " |
70 |
| - "each item is either opcode name ('OP') " |
71 |
| - "or opcode range ('OP1..OP2', ends are inclusive)"), |
72 |
| - cl::cat(BenchmarkOptions), |
73 |
| - cl::init(std::vector<std::pair<StringRef, StringRef>>())); |
| 60 | + cl::desc("comma-separated list of opcodes to measure, by name"), |
| 61 | + cl::cat(BenchmarkOptions), cl::init("")); |
74 | 62 |
|
75 | 63 | static cl::opt<std::string> SnippetsFile("snippets-file",
|
76 | 64 | cl::desc("code snippets to measure"),
|
@@ -328,27 +316,6 @@ static bool isIgnoredOpcode(const LLVMState &State, unsigned Opcode) {
|
328 | 316 | return getIgnoredOpcodeReasonOrNull(State, Opcode) != nullptr;
|
329 | 317 | }
|
330 | 318 |
|
331 |
| -bool OpcodeNameParser::parse( |
332 |
| - cl::Option &O, StringRef ArgName, const StringRef OpcodeNames, |
333 |
| - std::vector<std::pair<StringRef, StringRef>> &Val) { |
334 |
| - SmallVector<StringRef, 2> Pieces; |
335 |
| - StringRef(OpcodeNames) |
336 |
| - .split(Pieces, ",", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
337 |
| - for (const StringRef &OpcodeName : Pieces) { |
338 |
| - size_t DotDotPos = OpcodeName.find(".."); |
339 |
| - if (DotDotPos == StringRef::npos) { |
340 |
| - Val.emplace_back(OpcodeName, OpcodeName); |
341 |
| - continue; |
342 |
| - } |
343 |
| - StringRef BeginOpcodeName = OpcodeName.substr(0, DotDotPos); |
344 |
| - StringRef EndOpcodeName = OpcodeName.substr(DotDotPos + 2); |
345 |
| - Val.emplace_back(BeginOpcodeName, EndOpcodeName); |
346 |
| - } |
347 |
| - if (Val.empty()) |
348 |
| - return O.error("No matching opcode names"); |
349 |
| - return false; |
350 |
| -} |
351 |
| - |
352 | 319 | // Checks that only one of OpcodeNames, OpcodeIndex or SnippetsFile is provided,
|
353 | 320 | // and returns the opcode indices or {} if snippets should be read from
|
354 | 321 | // `SnippetsFile`.
|
@@ -388,34 +355,16 @@ static std::vector<unsigned> getOpcodesOrDie(const LLVMState &State) {
|
388 | 355 | return 0u;
|
389 | 356 | };
|
390 | 357 |
|
| 358 | + SmallVector<StringRef, 2> Pieces; |
| 359 | + StringRef(OpcodeNames.getValue()) |
| 360 | + .split(Pieces, ",", /* MaxSplit */ -1, /* KeepEmpty */ false); |
391 | 361 | std::vector<unsigned> Result;
|
392 |
| - for (const std::pair<StringRef, StringRef> &OpcodeName : OpcodeNames) { |
393 |
| - if (OpcodeName.first == OpcodeName.second) { |
394 |
| - if (unsigned Opcode = ResolveName(OpcodeName.first)) { |
395 |
| - Result.push_back(Opcode); |
396 |
| - continue; |
397 |
| - } else { |
398 |
| - ExitWithError(Twine("unknown opcode ").concat(OpcodeName.first)); |
399 |
| - } |
400 |
| - } else { |
401 |
| - StringRef BeginOpcodeName = OpcodeName.first; |
402 |
| - unsigned BeginOpcode = |
403 |
| - BeginOpcodeName.empty() ? 1 : ResolveName(BeginOpcodeName); |
404 |
| - if (BeginOpcode == 0) { |
405 |
| - ExitWithError(Twine("unknown opcode ").concat(BeginOpcodeName)); |
406 |
| - } |
407 |
| - StringRef EndOpcodeName = OpcodeName.second; |
408 |
| - unsigned EndOpcode = EndOpcodeName.empty() |
409 |
| - ? State.getInstrInfo().getNumOpcodes() - 1 |
410 |
| - : ResolveName(EndOpcodeName); |
411 |
| - if (EndOpcode == 0) { |
412 |
| - ExitWithError(Twine("unknown opcode ").concat(EndOpcodeName)); |
413 |
| - } |
414 |
| - for (unsigned I = BeginOpcode; I <= EndOpcode; ++I) { |
415 |
| - if (!isIgnoredOpcode(State, I)) |
416 |
| - Result.push_back(I); |
417 |
| - } |
418 |
| - } |
| 362 | + Result.reserve(Pieces.size()); |
| 363 | + for (const StringRef &OpcodeName : Pieces) { |
| 364 | + if (unsigned Opcode = ResolveName(OpcodeName)) |
| 365 | + Result.push_back(Opcode); |
| 366 | + else |
| 367 | + ExitWithError(Twine("unknown opcode ").concat(OpcodeName)); |
419 | 368 | }
|
420 | 369 | return Result;
|
421 | 370 | }
|
|
0 commit comments