[PATCH] D18394: [TableGen] AsmMatcherEmitter.cpp: replace a sequence of "if" to "switch" in emitValidateOperandClass. NFC.

Valery Pykhtin via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 23 07:30:07 PDT 2016


vpykhtin created this revision.
vpykhtin added reviewers: craig.topper, dblaikie, grosbach, ddunbar, resistor.
vpykhtin added a subscriber: llvm-commits.

Hi, 

this NFC change replaces a sequence of generated

if (Kind == MCK_XXX) {
   if (Operand.isXXX())
      return MCTargetAsmParser::Match_Success;
}

to 

switch (Kind) {
default: break;
...
case MCK_xxx: ...
   if (Operand.isXXX())
      return MCTargetAsmParser::Match_Success;
break;
...
}

Potentially can generate faster Kind check and significantly eases step debugging.

Example of output (from AMDGPU backend):

  switch(Kind) {
  default: break;
  // 'Clamp' class
  case MCK_Clamp:
    if (Operand.isClamp())
      return MCTargetAsmParser::Match_Success;
    break;
  // 'DMask' class
  case MCK_DMask:
    if (Operand.isDMask())
      return MCTargetAsmParser::Match_Success;
    break;
...
  } // end switch(Kind)

http://reviews.llvm.org/D18394

Files:
  utils/TableGen/AsmMatcherEmitter.cpp

Index: utils/TableGen/AsmMatcherEmitter.cpp
===================================================================
--- utils/TableGen/AsmMatcherEmitter.cpp
+++ utils/TableGen/AsmMatcherEmitter.cpp
@@ -2153,19 +2153,23 @@
 
   // Check the user classes. We don't care what order since we're only
   // actually matching against one of them.
+  OS << "  switch(Kind) {\n"
+        "  default: break;\n";
   for (const auto &CI : Info.Classes) {
     if (!CI.isUserClass())
       continue;
 
     OS << "  // '" << CI.ClassName << "' class\n";
-    OS << "  if (Kind == " << CI.Name << ") {\n";
+    OS << "  case " << CI.Name << ":\n";
     OS << "    if (Operand." << CI.PredicateMethod << "())\n";
     OS << "      return MCTargetAsmParser::Match_Success;\n";
     if (!CI.DiagnosticType.empty())
       OS << "    return " << Info.Target.getName() << "AsmParser::Match_"
          << CI.DiagnosticType << ";\n";
-    OS << "  }\n\n";
+    else
+      OS << "    break;\n";
   }
+  OS << "  } // end switch(Kind)\n\n";
 
   // Check for register operands, including sub-classes.
   OS << "  if (Operand.isReg()) {\n";


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18394.51415.patch
Type: text/x-patch
Size: 1117 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160323/cac4460b/attachment.bin>


More information about the llvm-commits mailing list