[cfe-commits] r65103 - /cfe/trunk/lib/AST/DeclBase.cpp

Douglas Gregor dgregor at apple.com
Mon Feb 23 09:09:36 PST 2009


On Feb 19, 2009, at 5:44 PM, Chris Lattner wrote:

> Author: lattner
> Date: Thu Feb 19 19:44:05 2009
> New Revision: 65103
>
> URL: http://llvm.org/viewvc/llvm-project?rev=65103&view=rev
> Log:
> optimize the 'StoredDeclsMap' for the common case where there is
> exactly one decl with a specific name in a specific context.  This
> avoids a bunch of malloc traffic and shrinks StoredDeclsMap to hold
> one pointer instead of 3 words (for a std::vector).

Thanks!

> This speeds up -fsyntax-only on cocoa.h with PTH by ~7.3%.

Cool.

> Modified:
>    cfe/trunk/lib/AST/DeclBase.cpp
>
> Modified: cfe/trunk/lib/AST/DeclBase.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=65103&r1=65102&r2=65103&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/AST/DeclBase.cpp (original)
> +++ cfe/trunk/lib/AST/DeclBase.cpp Thu Feb 19 19:44:05 2009
> @@ -268,15 +268,119 @@
>   }
> }
>
> -// FIXME: We really want to use a DenseSet here to eliminate the
> -// redundant storage of the declaration names, but (1) it doesn't  
> give
> -// us the ability to search based on DeclarationName, (2) we really
> -// need something more like a DenseMultiSet, and (3) it's
> -// implemented in terms of DenseMap anyway. However, this data
> -// structure is really space-inefficient, so we'll have to do
> -// something.
> -typedef llvm::DenseMap<DeclarationName, std::vector<NamedDecl*> >
> -  StoredDeclsMap;
> +/// StoredDeclsList - This is an array of decls optimized a common  
> case of only
> +/// containing one entry.
> +struct StoredDeclsList {
> +  /// Data - If the integer is 0, then the pointer is a  
> NamedDecl*.  If the
> +  /// integer is 1, then it is a VectorTy;
> +  llvm::PointerIntPair<void*, 1, bool> Data;
> +
> +  /// VectorTy - When in vector form, this is what the Data pointer  
> points to.
> +  typedef llvm::SmallVector<NamedDecl*, 4> VectorTy;
> +public:
> +  StoredDeclsList() {}
> +  StoredDeclsList(const StoredDeclsList &RHS) : Data(RHS.Data) {
> +    if (isVector())
> +      Data.setPointer(new VectorTy(getVector()));
> +  }

Should also have a copy-assignment operator:

	StoredDeclsList& operator=(const StoredDeclsList &RHS);

	- Doug



More information about the cfe-commits mailing list