diff options
author | Chris Lattner <sabre@nondot.org> | 2009-01-20 19:11:22 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-01-20 19:11:22 +0000 |
commit | 1ce41edd8da47d7c438c18a819ced3237a2f49f7 (patch) | |
tree | cdc57b07696a11d253611686b05a923a5435b89f /clang/lib/Parse/DeclSpec.cpp | |
parent | 72854c3811e7c952e3f26e5eed6b51a49dd218be (diff) | |
download | bcm5719-llvm-1ce41edd8da47d7c438c18a819ced3237a2f49f7.tar.gz bcm5719-llvm-1ce41edd8da47d7c438c18a819ced3237a2f49f7.zip |
Optimize Declarator to avoid malloc/free traffic for the argument list of a
function DeclaratorChunk in common cases. This uses a fixed array in
Declarator when it is small enough for the first function declarator chunk
in a declarator.
This eliminates all malloc/free traffic from DeclaratorChunk::getFunction
when running on Cocoa.h except for five functions: signal/bsd_signal/sigset,
which have multiple Function DeclChunk's, and
CFUUIDCreateWithBytes/CFUUIDGetConstantUUIDWithBytes, which take more than
16 arguments.
This patch was pair programmed with Steve.
llvm-svn: 62599
Diffstat (limited to 'clang/lib/Parse/DeclSpec.cpp')
-rw-r--r-- | clang/lib/Parse/DeclSpec.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/clang/lib/Parse/DeclSpec.cpp b/clang/lib/Parse/DeclSpec.cpp index 4459c804f37..83bf36c7163 100644 --- a/clang/lib/Parse/DeclSpec.cpp +++ b/clang/lib/Parse/DeclSpec.cpp @@ -14,6 +14,7 @@ #include "clang/Parse/DeclSpec.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/LangOptions.h" +#include "llvm/ADT/STLExtras.h" using namespace clang; @@ -23,6 +24,43 @@ static DiagnosticBuilder Diag(Diagnostic &D, SourceLocation Loc, } +/// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. +/// "TheDeclarator" is the declarator that this will be added to. +DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, bool isVariadic, + ParamInfo *ArgInfo, + unsigned NumArgs, + unsigned TypeQuals, + SourceLocation Loc, + Declarator &TheDeclarator) { + DeclaratorChunk I; + I.Kind = Function; + I.Loc = Loc; + I.Fun.hasPrototype = hasProto; + I.Fun.isVariadic = isVariadic; + I.Fun.DeleteArgInfo = false; + I.Fun.TypeQuals = TypeQuals; + I.Fun.NumArgs = NumArgs; + I.Fun.ArgInfo = 0; + + // new[] an argument array if needed. + if (NumArgs) { + // If the 'InlineParams' in Declarator is unused and big enough, put our + // parameter list there (in an effort to avoid new/delete traffic). If it + // is already used (consider a function returning a function pointer) or too + // small (function taking too many arguments), go to the heap. + if (!TheDeclarator.InlineParamsUsed && + NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) { + I.Fun.ArgInfo = TheDeclarator.InlineParams; + I.Fun.DeleteArgInfo = false; + TheDeclarator.InlineParamsUsed = true; + } else { + I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs]; + I.Fun.DeleteArgInfo = true; + } + memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs); + } + return I; +} /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this /// |