diff options
author | Roman Tereshin <rtereshin@apple.com> | 2018-05-23 20:45:43 +0000 |
---|---|---|
committer | Roman Tereshin <rtereshin@apple.com> | 2018-05-23 20:45:43 +0000 |
commit | d760c20c94ebc1f16b723a0fd1b5c497d83a6b91 (patch) | |
tree | 810306b919b1edfd6389d0963f90a64e2ac8c8fb | |
parent | c7277e6e2be75a2bab92ce36d37fd018b2e19725 (diff) | |
download | bcm5719-llvm-d760c20c94ebc1f16b723a0fd1b5c497d83a6b91.tar.gz bcm5719-llvm-d760c20c94ebc1f16b723a0fd1b5c497d83a6b91.zip |
[Tablegen] Tidying up InstRegexOp a little, NFC
Differential Review: https://reviews.llvm.org/D47240
llvm-svn: 333121
-rw-r--r-- | llvm/utils/TableGen/CodeGenSchedule.cpp | 21 | ||||
-rw-r--r-- | llvm/utils/TableGen/CodeGenTarget.h | 10 |
2 files changed, 16 insertions, 15 deletions
diff --git a/llvm/utils/TableGen/CodeGenSchedule.cpp b/llvm/utils/TableGen/CodeGenSchedule.cpp index a520afb1382..ea22ce6ce9f 100644 --- a/llvm/utils/TableGen/CodeGenSchedule.cpp +++ b/llvm/utils/TableGen/CodeGenSchedule.cpp @@ -78,6 +78,13 @@ struct InstRegexOp : public SetTheory::Operator { void apply(SetTheory &ST, DagInit *Expr, SetTheory::RecSet &Elts, ArrayRef<SMLoc> Loc) override { + ArrayRef<const CodeGenInstruction *> Instructions = + Target.getInstructionsByEnumValue(); + + unsigned NumGeneric = Target.getNumFixedInstructions(); + auto Generics = Instructions.slice(0, NumGeneric); + auto NonGenerics = Instructions.slice(NumGeneric); + for (Init *Arg : make_range(Expr->arg_begin(), Expr->arg_end())) { StringInit *SI = dyn_cast<StringInit>(Arg); if (!SI) @@ -108,10 +115,6 @@ struct InstRegexOp : public SetTheory::Operator { int NumMatches = 0; - unsigned NumGeneric = Target.getNumFixedInstructions(); - ArrayRef<const CodeGenInstruction *> Generics = - Target.getInstructionsByEnumValue().slice(0, NumGeneric + 1); - // The generic opcodes are unsorted, handle them manually. for (auto *Inst : Generics) { StringRef InstName = Inst->TheDef->getName(); @@ -122,9 +125,6 @@ struct InstRegexOp : public SetTheory::Operator { } } - ArrayRef<const CodeGenInstruction *> Instructions = - Target.getInstructionsByEnumValue().slice(NumGeneric + 1); - // Target instructions are sorted. Find the range that starts with our // prefix. struct Comp { @@ -136,18 +136,19 @@ struct InstRegexOp : public SetTheory::Operator { !RHS->TheDef->getName().startswith(LHS); } }; - auto Range = std::equal_range(Instructions.begin(), Instructions.end(), + auto Range = std::equal_range(NonGenerics.begin(), NonGenerics.end(), Prefix, Comp()); // For this range we know that it starts with the prefix. Check if there's // a regex that needs to be checked. - for (auto *Inst : make_range(Range)) { + const auto HandleNonGeneric = [&](const CodeGenInstruction *Inst) { StringRef InstName = Inst->TheDef->getName(); if (!Regexpr || Regexpr->match(InstName.substr(Prefix.size()))) { Elts.insert(Inst->TheDef); NumMatches++; } - } + }; + std::for_each(Range.first, Range.second, HandleNonGeneric); if (0 == NumMatches) PrintFatalError(Loc, "instregex has no matches: " + Original); diff --git a/llvm/utils/TableGen/CodeGenTarget.h b/llvm/utils/TableGen/CodeGenTarget.h index c38f92bb979..ef6f8227f99 100644 --- a/llvm/utils/TableGen/CodeGenTarget.h +++ b/llvm/utils/TableGen/CodeGenTarget.h @@ -148,11 +148,11 @@ public: /// Returns the number of predefined instructions. static unsigned getNumFixedInstructions(); - /// getInstructionsByEnumValue - Return all of the instructions defined by the - /// target, ordered by their enum value. - ArrayRef<const CodeGenInstruction *> - getInstructionsByEnumValue() const { - if (InstrsByEnum.empty()) ComputeInstrsByEnum(); + /// Return all of the instructions defined by the target, ordered by their + /// enum value. + ArrayRef<const CodeGenInstruction *> getInstructionsByEnumValue() const { + if (InstrsByEnum.empty()) + ComputeInstrsByEnum(); return InstrsByEnum; } |