Replace the StringSwitch in AttributeList::getKind() with a
TableGen-generated StringMatcher, for a 1.2% speedup in -fparse-only
time in <rdar://problem/11004361>. Thanks to Benjamin for pointing me
at StringMatcher!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156003 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/AttributeList.cpp b/lib/Sema/AttributeList.cpp
index cbd2ba4..101e0384f 100644
--- a/lib/Sema/AttributeList.cpp
+++ b/lib/Sema/AttributeList.cpp
@@ -97,6 +97,8 @@
   return create(Name, TokLoc, 0, TokLoc, 0, TokLoc, &IArg, 1, 0);
 }
 
+#include "clang/Sema/AttrParsedAttrKinds.inc"
+
 AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {
   StringRef AttrName = Name->getName();
 
@@ -105,7 +107,5 @@
       AttrName.size() >= 4)
     AttrName = AttrName.substr(2, AttrName.size() - 4);
 
-  return llvm::StringSwitch<AttributeList::Kind>(AttrName)
-    #include "clang/Sema/AttrParsedAttrKinds.inc"
-    .Default(UnknownAttribute);
+  return ::getAttrKind(AttrName);
 }
diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp
index 112d9a5..4177660 100644
--- a/utils/TableGen/ClangAttrEmitter.cpp
+++ b/utils/TableGen/ClangAttrEmitter.cpp
@@ -14,6 +14,7 @@
 #include "ClangAttrEmitter.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/StringMatcher.h"
 #include <algorithm>
 #include <cctype>
 #include <set>
@@ -1085,9 +1086,11 @@
 
 void ClangAttrParsedAttrKindsEmitter::run(raw_ostream &OS) {
   OS << "// This file is generated by TableGen. Do not edit.\n\n";
-
+  OS << "\n";
+  
   std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
 
+  std::vector<StringMatcher::StringPair> Matches;
   for (std::vector<Record*>::iterator I = Attrs.begin(), E = Attrs.end();
        I != E; ++I) {
     Record &Attr = **I;
@@ -1107,12 +1110,23 @@
         Spelling = NormalizeAttrSpelling(Spelling);
 
         if (SemaHandler)
-          OS << ".Case(\"" << Spelling << "\", " << "AT_" << AttrName << ")\n";
+          Matches.push_back(
+            StringMatcher::StringPair(Spelling,
+                                      std::string("return AttributeList::AT_") +
+                                      AttrName.str() + ";"));
         else
-          OS << ".Case(\"" << Spelling << "\", IgnoredAttribute)\n";
+          Matches.push_back(
+            StringMatcher::StringPair(
+              Spelling,
+              std::string("return AttributeList::IgnoredAttribute;")));
       }
     }
   }
+  
+  OS << "static AttributeList::Kind getAttrKind(StringRef Name) {\n";
+  StringMatcher("Name", Matches, OS).Emit();
+  OS << "return AttributeList::UnknownAttribute;\n"
+     << "}\n";
 }