[cfe-commits] r173050 - in /cfe/trunk: include/clang/Serialization/ASTReader.h lib/Serialization/ASTCommon.cpp lib/Serialization/ASTCommon.h lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Mon Jan 21 10:29:59 PST 2013


On 21.01.2013, at 16:25, Douglas Gregor wrote:

> Author: dgregor
> Date: Mon Jan 21 09:25:38 2013
> New Revision: 173050
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=173050&view=rev
> Log:
> Introduce a fast path for the ASTReader's name lookup within a
> DeclContext. When the DeclContext is of a kind that can only be
> defined once and never updated, we limit the search to the module file
> that conatins the lookup table. Provides a 15% speedup in one
> modules-heavy source file.
> 
> Modified:
>    cfe/trunk/include/clang/Serialization/ASTReader.h
>    cfe/trunk/lib/Serialization/ASTCommon.cpp
>    cfe/trunk/lib/Serialization/ASTCommon.h
>    cfe/trunk/lib/Serialization/ASTReader.cpp
>    cfe/trunk/lib/Serialization/ASTWriter.cpp
> 
> Modified: cfe/trunk/lib/Serialization/ASTCommon.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTCommon.cpp?rev=173050&r1=173049&r2=173050&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTCommon.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTCommon.cpp Mon Jan 21 09:25:38 2013
> @@ -12,6 +12,7 @@
> //===----------------------------------------------------------------------===//
> 
> #include "ASTCommon.h"
> +#include "clang/AST/DeclObjC.h"
> #include "clang/Basic/IdentifierTable.h"
> #include "clang/Serialization/ASTDeserializationListener.h"
> #include "llvm/ADT/StringExtras.h"
> @@ -85,3 +86,60 @@
>       R = llvm::HashString(II->getName(), R);
>   return R;
> }
> +
> +const Decl *serialization::getDefinitiveDeclContext(const DeclContext *DC) {
> +  switch (DC->getDeclKind()) {
> +  // These entities may have multiple definitions.
> +  case Decl::TranslationUnit:
> +  case Decl::Namespace:
> +  case Decl::LinkageSpec:
> +    return 0;
> +
> +  // C/C++ tag types can only be defined in one place.
> +  case Decl::Enum:
> +  case Decl::Record:
> +    if (const TagDecl *Def = cast<TagDecl>(DC)->getDefinition())
> +      return Def;
> +    break;
> +
> +  // FIXME: These can be defined in one place... except special member
> +  // functions and out-of-line definitions.
> +  case Decl::CXXRecord:
> +  case Decl::ClassTemplateSpecialization:
> +  case Decl::ClassTemplatePartialSpecialization:
> +    return 0;
> +
> +  // Each function, method, and block declaration is its own DeclContext.
> +  case Decl::Function:
> +  case Decl::CXXMethod:
> +  case Decl::CXXConstructor:
> +  case Decl::CXXDestructor:
> +  case Decl::CXXConversion:
> +  case Decl::ObjCMethod:
> +  case Decl::Block:
> +    // Objective C categories, category implementations, and class
> +    // implementations can only be defined in one place.
> +  case Decl::ObjCCategory:
> +  case Decl::ObjCCategoryImpl:
> +  case Decl::ObjCImplementation:
> +    return cast<Decl>(DC);
> +
> +  case Decl::ObjCProtocol:
> +    if (const ObjCProtocolDecl *Def
> +          = cast<ObjCProtocolDecl>(DC)->getDefinition())
> +      return Def;
> +    break;
> +
> +  // FIXME: These are defined in one place, but properties in class extensions
> +  // end up being back-patched into the main interface. See
> +  // Sema::HandlePropertyInClassExtension for the offending code.
> +  case Decl::ObjCInterface:
> +    break;
> +    
> +  default:
> +    llvm_unreachable("Unhandled DeclContext in AST reader");
> +  }
> +  
> +  return 0;
> +
> +}

 Maybe this switch could be consistent between using break and return 0 for the cases that don't have a definitive declcontext. Also, why is it called getDefinitiveDeclContext but returns a Decl?

Sebastian



More information about the cfe-commits mailing list