[llvm] r333121 - [Tablegen] Tidying up InstRegexOp a little, NFC

Roman Tereshin via llvm-commits llvm-commits at lists.llvm.org
Wed May 23 13:45:43 PDT 2018


Author: rtereshin
Date: Wed May 23 13:45:43 2018
New Revision: 333121

URL: http://llvm.org/viewvc/llvm-project?rev=333121&view=rev
Log:
[Tablegen] Tidying up InstRegexOp a little, NFC

Differential Review: https://reviews.llvm.org/D47240

Modified:
    llvm/trunk/utils/TableGen/CodeGenSchedule.cpp
    llvm/trunk/utils/TableGen/CodeGenTarget.h

Modified: llvm/trunk/utils/TableGen/CodeGenSchedule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenSchedule.cpp?rev=333121&r1=333120&r2=333121&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenSchedule.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenSchedule.cpp Wed May 23 13:45:43 2018
@@ -78,6 +78,13 @@ struct InstRegexOp : public SetTheory::O
 
   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::O
 
       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::O
         }
       }
 
-      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::O
                  !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);

Modified: llvm/trunk/utils/TableGen/CodeGenTarget.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenTarget.h?rev=333121&r1=333120&r2=333121&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenTarget.h (original)
+++ llvm/trunk/utils/TableGen/CodeGenTarget.h Wed May 23 13:45:43 2018
@@ -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;
   }
 




More information about the llvm-commits mailing list