aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-02-03 00:07:12 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-02-03 00:07:12 +0000
commit40a6be686e5d5bb4198f1affda574e8a4b3a7710 (patch)
tree6216f275507740618af64dfc5e441e07085dbb8a
parent281481daeb97e56bb19e394efc34bfd4ab85a226 (diff)
Memoize CGFunctionInfo construction.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63576 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGCall.cpp13
-rw-r--r--lib/CodeGen/CGCall.h16
-rw-r--r--lib/CodeGen/CodeGenTypes.h3
3 files changed, 30 insertions, 2 deletions
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index 898c780aae..30257d2699 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/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/lib/CodeGen/CGCall.h b/lib/CodeGen/CGCall.h
index aaab36ca83..611304900f 100644
--- a/lib/CodeGen/CGCall.h
+++ b/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/lib/CodeGen/CodeGenTypes.h b/lib/CodeGen/CodeGenTypes.h
index d41c23d374..3070c85260 100644
--- a/lib/CodeGen/CodeGenTypes.h
+++ b/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: