diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2009-02-03 00:07:12 +0000 |
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2009-02-03 00:07:12 +0000 |
| commit | e0be82956b3d1f8d2cad3954d14921cacb72ff7c (patch) | |
| tree | 5eb72ab917e05cffa39a168686ef664f54dfbfae | |
| parent | 7403751e16ab476c881ae24b1f58594d16f011d8 (diff) | |
| download | bcm5719-llvm-e0be82956b3d1f8d2cad3954d14921cacb72ff7c.tar.gz bcm5719-llvm-e0be82956b3d1f8d2cad3954d14921cacb72ff7c.zip | |
Memoize CGFunctionInfo construction.
llvm-svn: 63576
| -rw-r--r-- | clang/lib/CodeGen/CGCall.cpp | 13 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGCall.h | 16 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenTypes.h | 3 |
3 files changed, 30 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 898c780aaec..30257d2699e 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -86,7 +86,18 @@ const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy, const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy, const llvm::SmallVector<QualType, 16> &ArgTys) { - return *new CGFunctionInfo(ResTy, ArgTys); + // Lookup or create unique function info. + llvm::FoldingSetNodeID ID; + CGFunctionInfo::Profile(ID, ResTy, ArgTys.begin(), ArgTys.end()); + + void *InsertPos = 0; + CGFunctionInfo *FI = FunctionInfos.FindNodeOrInsertPos(ID, InsertPos); + if (FI) + return *FI; + + FI = new CGFunctionInfo(ResTy, ArgTys); + FunctionInfos.InsertNode(FI, InsertPos); + return *FI; } /***/ diff --git a/clang/lib/CodeGen/CGCall.h b/clang/lib/CodeGen/CGCall.h index aaab36ca83e..611304900f6 100644 --- a/clang/lib/CodeGen/CGCall.h +++ b/clang/lib/CodeGen/CGCall.h @@ -15,6 +15,7 @@ #ifndef CLANG_CODEGEN_CGCALL_H #define CLANG_CODEGEN_CGCALL_H +#include <llvm/ADT/FoldingSet.h> #include "clang/AST/Type.h" #include "CGValue.h" @@ -49,7 +50,7 @@ namespace CodeGen { /// CGFunctionInfo - Class to encapsulate the information about a /// function definition. - class CGFunctionInfo { + class CGFunctionInfo : public llvm::FoldingSetNode { llvm::SmallVector<QualType, 16> ArgTypes; public: @@ -62,6 +63,19 @@ namespace CodeGen { arg_iterator arg_end() const; QualType getReturnType() const { return ArgTypes[0]; } + + void Profile(llvm::FoldingSetNodeID &ID) { + Profile(ID, getReturnType(), arg_begin(), arg_end()); + } + template<class Iterator> + static void Profile(llvm::FoldingSetNodeID &ID, + QualType ResTy, + Iterator begin, + Iterator end) { + ResTy.Profile(ID); + for (; begin != end; ++begin) + begin->Profile(ID); + } }; } // end namespace CodeGen } // end namespace clang diff --git a/clang/lib/CodeGen/CodeGenTypes.h b/clang/lib/CodeGen/CodeGenTypes.h index d41c23d3747..3070c852609 100644 --- a/clang/lib/CodeGen/CodeGenTypes.h +++ b/clang/lib/CodeGen/CodeGenTypes.h @@ -100,6 +100,9 @@ class CodeGenTypes { /// field no. This info is populated by record organizer. llvm::DenseMap<const FieldDecl *, unsigned> FieldInfo; + /// FunctionInfos - Hold memoized CGFunctionInfo results. + llvm::FoldingSet<CGFunctionInfo> FunctionInfos; + public: class BitFieldInfo { public: |

