]> granicus.if.org Git - clang/commitdiff
Memoize CGFunctionInfo construction.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 3 Feb 2009 00:07:12 +0000 (00:07 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 3 Feb 2009 00:07:12 +0000 (00:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63576 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCall.cpp
lib/CodeGen/CGCall.h
lib/CodeGen/CodeGenTypes.h

index 898c780aaeccc2357da489be89078aba8ba12ce7..30257d2699e472d64fdc2296ddf947e956026175 100644 (file)
@@ -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;
 }
 
 /***/
index aaab36ca83ece92060eb078ca252d36f75d91b30..611304900f6237256b9d451b4341846cd85e049f 100644 (file)
@@ -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
index d41c23d37476276fce290b447aaf85a7a2344b74..3070c85260987af4d445c83a3edbeca950a2c479 100644 (file)
@@ -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: