From a663b0aee8fef8552996f03415d3e48ee72e838f Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Fri, 21 Oct 2016 21:45:01 +0000 Subject: [PATCH] Switch SmallSetVector to use DenseSet when it overflows its inline space. Summary: SetVector already used DenseSet, but SmallSetVector used std::set. This leads to surprising performance differences. Moreover, it means that the set of key types accepted by SetVector and SmallSetVector are quite different! In order to make this change, we had to convert some callsites that used SmallSetVector to use SmallSetVector instead. Reviewers: timshen Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25648 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284887 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/HeaderSearchOptions.h | 3 ++- lib/CodeGen/CGObjCMac.cpp | 7 ++++--- lib/Frontend/CompilerInstance.cpp | 3 ++- lib/Frontend/CompilerInvocation.cpp | 6 ++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/clang/Lex/HeaderSearchOptions.h b/include/clang/Lex/HeaderSearchOptions.h index 53909e6a32..815b68c60e 100644 --- a/include/clang/Lex/HeaderSearchOptions.h +++ b/include/clang/Lex/HeaderSearchOptions.h @@ -11,6 +11,7 @@ #define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H #include "clang/Basic/LLVM.h" +#include "llvm/ADT/CachedHashString.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/StringRef.h" @@ -144,7 +145,7 @@ public: /// \brief The set of macro names that should be ignored for the purposes /// of computing the module hash. - llvm::SmallSetVector ModulesIgnoreMacros; + llvm::SmallSetVector ModulesIgnoreMacros; /// \brief The set of user-provided virtual filesystem overlay files. std::vector VFSOverlayFiles; diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 70fefec574..b290ae3723 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -11,9 +11,9 @@ // //===----------------------------------------------------------------------===// -#include "CGObjCRuntime.h" #include "CGBlocks.h" #include "CGCleanup.h" +#include "CGObjCRuntime.h" #include "CGRecordLayout.h" #include "CodeGenFunction.h" #include "CodeGenModule.h" @@ -25,6 +25,7 @@ #include "clang/Basic/LangOptions.h" #include "clang/CodeGen/CGFunctionInfo.h" #include "clang/Frontend/CodeGenOptions.h" +#include "llvm/ADT/CachedHashString.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" @@ -843,7 +844,7 @@ protected: llvm::DenseMap MethodVarNames; /// DefinedCategoryNames - list of category names in form Class_Category. - llvm::SmallSetVector DefinedCategoryNames; + llvm::SmallSetVector DefinedCategoryNames; /// MethodVarTypes - uniqued method type signatures. We have to use /// a StringMap here because have no other unique reference. @@ -3156,7 +3157,7 @@ void CGObjCMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) { "__OBJC,__category,regular,no_dead_strip", CGM.getPointerAlign(), true); DefinedCategories.push_back(GV); - DefinedCategoryNames.insert(ExtName.str()); + DefinedCategoryNames.insert(llvm::CachedHashString(ExtName)); // method definition entries must be clear for next implementation. MethodDefinitions.clear(); } diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index f3e883959d..b2b7b7c67b 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -955,7 +955,8 @@ static bool compileModuleImpl(CompilerInstance &ImportingInstance, std::remove_if(PPOpts.Macros.begin(), PPOpts.Macros.end(), [&HSOpts](const std::pair &def) { StringRef MacroDef = def.first; - return HSOpts.ModulesIgnoreMacros.count(MacroDef.split('=').first) > 0; + return HSOpts.ModulesIgnoreMacros.count( + llvm::CachedHashString(MacroDef.split('=').first)) > 0; }), PPOpts.Macros.end()); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 03d400b9ca..3f2e303b5c 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1432,7 +1432,8 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) { for (const Arg *A : Args.filtered(OPT_fmodules_ignore_macro)) { StringRef MacroDef = A->getValue(); - Opts.ModulesIgnoreMacros.insert(MacroDef.split('=').first); + Opts.ModulesIgnoreMacros.insert( + llvm::CachedHashString(MacroDef.split('=').first)); } // Add -I..., -F..., and -index-header-map options in order. @@ -2519,7 +2520,8 @@ std::string CompilerInvocation::getModuleHash() const { if (!hsOpts.ModulesIgnoreMacros.empty()) { // Check whether we're ignoring this macro. StringRef MacroDef = I->first; - if (hsOpts.ModulesIgnoreMacros.count(MacroDef.split('=').first)) + if (hsOpts.ModulesIgnoreMacros.count( + llvm::CachedHashString(MacroDef.split('=').first))) continue; } -- 2.40.0