[cfe-commits] r156003 - in /cfe/trunk: lib/Sema/AttributeList.cpp utils/TableGen/ClangAttrEmitter.cpp

Douglas Gregor dgregor at apple.com
Wed May 2 10:33:51 PDT 2012


Author: dgregor
Date: Wed May  2 12:33:51 2012
New Revision: 156003

URL: http://llvm.org/viewvc/llvm-project?rev=156003&view=rev
Log:
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!

Modified:
    cfe/trunk/lib/Sema/AttributeList.cpp
    cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/lib/Sema/AttributeList.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AttributeList.cpp?rev=156003&r1=156002&r2=156003&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/AttributeList.cpp (original)
+++ cfe/trunk/lib/Sema/AttributeList.cpp Wed May  2 12:33:51 2012
@@ -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);
 }

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=156003&r1=156002&r2=156003&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Wed May  2 12:33:51 2012
@@ -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";
 }
 
 





More information about the cfe-commits mailing list