From: Douglas Gregor Date: Wed, 2 May 2012 17:33:51 +0000 (+0000) Subject: Replace the StringSwitch in AttributeList::getKind() with a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0c19b3c38e356058aeb2424d175eae232bf014d9;p=clang Replace the StringSwitch in AttributeList::getKind() with a TableGen-generated StringMatcher, for a 1.2% speedup in -fparse-only time in . 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 cbd2ba4194..101e0384fa 100644 --- a/lib/Sema/AttributeList.cpp +++ b/lib/Sema/AttributeList.cpp @@ -97,6 +97,8 @@ AttributePool::createIntegerAttribute(ASTContext &C, IdentifierInfo *Name, 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 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { AttrName.size() >= 4) AttrName = AttrName.substr(2, AttrName.size() - 4); - return llvm::StringSwitch(AttrName) - #include "clang/Sema/AttrParsedAttrKinds.inc" - .Default(UnknownAttribute); + return ::getAttrKind(AttrName); } diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp index 112d9a5f23..4177660e26 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 #include #include @@ -1085,9 +1086,11 @@ void ClangAttrParsedAttrListEmitter::run(raw_ostream &OS) { void ClangAttrParsedAttrKindsEmitter::run(raw_ostream &OS) { OS << "// This file is generated by TableGen. Do not edit.\n\n"; - + OS << "\n"; + std::vector Attrs = Records.getAllDerivedDefinitions("Attr"); + std::vector Matches; for (std::vector::iterator I = Attrs.begin(), E = Attrs.end(); I != E; ++I) { Record &Attr = **I; @@ -1107,12 +1110,23 @@ void ClangAttrParsedAttrKindsEmitter::run(raw_ostream &OS) { 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"; }