]> granicus.if.org Git - clang/commitdiff
Thread CGFunctionInfo construction through CodeGenTypes.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 2 Feb 2009 23:23:47 +0000 (23:23 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 2 Feb 2009 23:23:47 +0000 (23:23 +0000)
 - Inefficient & leaks memory currently, will be cleaned up subsequently.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63567 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCall.cpp
lib/CodeGen/CGCall.h
lib/CodeGen/CGExpr.cpp
lib/CodeGen/CGObjC.cpp
lib/CodeGen/CGObjCGNU.cpp
lib/CodeGen/CGObjCMac.cpp
lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/CodeGenTypes.cpp
lib/CodeGen/CodeGenTypes.h

index c7b2a5dc895f9fbe34546e1042bd3cd92fb15350..7e2592206e0bb67de4f29f1abba3b68598befa3a 100644 (file)
@@ -31,50 +31,70 @@ using namespace CodeGen;
 
 // FIXME: Use iterator and sidestep silly type array creation.
 
-CGFunctionInfo::CGFunctionInfo(const FunctionTypeNoProto *FTNP) {
-  ArgTypes.push_back(FTNP->getResultType());
+const 
+CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionTypeNoProto *FTNP) {
+  return getFunctionInfo(FTNP->getResultType(), 
+                         llvm::SmallVector<QualType, 16>());
 }
 
-CGFunctionInfo::CGFunctionInfo(const FunctionTypeProto *FTP) {
-  ArgTypes.push_back(FTP->getResultType());
+const 
+CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionTypeProto *FTP) {
+  llvm::SmallVector<QualType, 16> ArgTys;
+  // FIXME: Kill copy.
   for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
-    ArgTypes.push_back(FTP->getArgType(i));
+    ArgTys.push_back(FTP->getArgType(i));
+  return getFunctionInfo(FTP->getResultType(), ArgTys);
 }
 
-// FIXME: Is there really any reason to have this still?
-CGFunctionInfo::CGFunctionInfo(const FunctionDecl *FD) {
+const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionDecl *FD) {
   const FunctionType *FTy = FD->getType()->getAsFunctionType();
-  const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(FTy);
-
-  ArgTypes.push_back(FTy->getResultType());
-  if (FTP) {
-    for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
-      ArgTypes.push_back(FTP->getArgType(i));
-  }
+  if (const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(FTy))
+    return getFunctionInfo(FTP);
+  return getFunctionInfo(cast<FunctionTypeNoProto>(FTy));
 }
 
-CGFunctionInfo::CGFunctionInfo(const ObjCMethodDecl *MD,
-                               const ASTContext &Context) {
-  ArgTypes.push_back(MD->getResultType());
-  ArgTypes.push_back(MD->getSelfDecl()->getType());
-  ArgTypes.push_back(Context.getObjCSelType());
+const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const ObjCMethodDecl *MD) {
+  llvm::SmallVector<QualType, 16> ArgTys;
+  ArgTys.push_back(MD->getSelfDecl()->getType());
+  ArgTys.push_back(Context.getObjCSelType());
+  // FIXME: Kill copy?
   for (ObjCMethodDecl::param_const_iterator i = MD->param_begin(),
          e = MD->param_end(); i != e; ++i)
-    ArgTypes.push_back((*i)->getType());
+    ArgTys.push_back((*i)->getType());
+  return getFunctionInfo(MD->getResultType(), ArgTys);
 }
 
-CGFunctionInfo::CGFunctionInfo(QualType ResTy, const CallArgList &Args) {
-  ArgTypes.push_back(ResTy);
+const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy, 
+                                                    const CallArgList &Args) {
+  // FIXME: Kill copy.
+  llvm::SmallVector<QualType, 16> ArgTys;
   for (CallArgList::const_iterator i = Args.begin(), e = Args.end(); 
        i != e; ++i)
-    ArgTypes.push_back(i->second);
+    ArgTys.push_back(i->second);
+  return getFunctionInfo(ResTy, ArgTys);
 }
 
-CGFunctionInfo::CGFunctionInfo(QualType ResTy, const FunctionArgList &Args) {
-  ArgTypes.push_back(ResTy);
+const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy, 
+                                                  const FunctionArgList &Args) {
+  // FIXME: Kill copy.
+  llvm::SmallVector<QualType, 16> ArgTys;
   for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end(); 
        i != e; ++i)
-    ArgTypes.push_back(i->second);
+    ArgTys.push_back(i->second);
+  return getFunctionInfo(ResTy, ArgTys);
+}
+
+const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy,
+                               const llvm::SmallVector<QualType, 16> &ArgTys) {
+  return *new CGFunctionInfo(ResTy, ArgTys);
+}
+
+/***/
+
+CGFunctionInfo::CGFunctionInfo(QualType ResTy, 
+                               const llvm::SmallVector<QualType, 16> &ArgTys) {
+  ArgTypes.push_back(ResTy);
+  ArgTypes.insert(ArgTypes.end(), ArgTys.begin(), ArgTys.end());
 }
 
 ArgTypeIterator CGFunctionInfo::argtypes_begin() const {
index 7ca5f26a8f8cffe573eed5af3fa9c47d8020ef43..f8fb32b15a4e6fb2a3f4ea8760e6b8739794b27f 100644 (file)
@@ -57,12 +57,8 @@ namespace CodeGen {
     llvm::SmallVector<QualType, 16> ArgTypes;
 
   public:
-    CGFunctionInfo(const FunctionTypeNoProto *FTNP);
-    CGFunctionInfo(const FunctionTypeProto *FTP);
-    CGFunctionInfo(const FunctionDecl *FD);
-    CGFunctionInfo(const ObjCMethodDecl *MD, const ASTContext &Context);
-    CGFunctionInfo(QualType ResTy, const CallArgList &Args);
-    CGFunctionInfo(QualType ResTy, const FunctionArgList &Args);
+    CGFunctionInfo(QualType ResTy, 
+                   const llvm::SmallVector<QualType, 16> &ArgTys);
 
     ArgTypeIterator argtypes_begin() const;
     ArgTypeIterator argtypes_end() const;
index 5ed215164b7e72731662ec01030dcab9c1458616..2c16c1940b55550c18d0c21b66612e4360802d1f 100644 (file)
@@ -1102,5 +1102,6 @@ RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType CalleeType,
     Args.push_back(std::make_pair(EmitAnyExprToTemp(*I), 
                                   I->getType()));
 
-  return EmitCall(CGFunctionInfo(ResultType, Args), Callee, Args);
+  return EmitCall(CGM.getTypes().getFunctionInfo(ResultType, Args), 
+                  Callee, Args);
 }
index cf37886e6d37bcf5a7c0edb282baa65ce52930cc..9dc45efc6872c7c51c4a9ef96e3b1132dc83f72c 100644 (file)
@@ -183,7 +183,7 @@ void CodeGenFunction::GenerateObjCGetter(ObjCImplementationDecl *IMP,
     Args.push_back(std::make_pair(RValue::get(CmdVal), Cmd->getType()));
     Args.push_back(std::make_pair(RValue::get(Offset), getContext().LongTy));
     Args.push_back(std::make_pair(RValue::get(True), getContext().BoolTy));
-    RValue RV = EmitCall(CGFunctionInfo(PD->getType(), Args), 
+    RValue RV = EmitCall(Types.getFunctionInfo(PD->getType(), Args), 
                          GetPropertyFn, Args);
     // We need to fix the type here. Ivars with copy & retain are
     // always objects so we don't need to worry about complex or
@@ -268,7 +268,8 @@ void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP,
                                   getContext().BoolTy));
     Args.push_back(std::make_pair(RValue::get(IsCopy ? True : False), 
                                   getContext().BoolTy));
-    EmitCall(CGFunctionInfo(PD->getType(), Args), SetPropertyFn, Args);
+    EmitCall(Types.getFunctionInfo(PD->getType(), Args), 
+             SetPropertyFn, Args);
   } else {
     SourceLocation Loc = PD->getLocation();
     ValueDecl *Self = OMD->getSelfDecl();
index e6ae6f36b4e131aa541d7a8127b154abec1242fa..1ce28bf91d40451c83241468be339944033e1ad5 100644 (file)
@@ -311,7 +311,8 @@ CGObjCGNU::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
   ActualArgs.push_back(std::make_pair(RValue::get(cmd),
                                       CGF.getContext().getObjCSelType()));
   ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
-  return CGF.EmitCall(CGFunctionInfo(ResultType, ActualArgs), imp, ActualArgs);
+  return CGF.EmitCall(CGM.getTypes().getFunctionInfo(ResultType, ActualArgs), 
+                      imp, ActualArgs);
 }
 
 /// Generate code for a message send expression.  
@@ -358,7 +359,8 @@ CGObjCGNU::GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
   ActualArgs.push_back(std::make_pair(RValue::get(cmd),
                                       CGF.getContext().getObjCSelType()));
   ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
-  return CGF.EmitCall(CGFunctionInfo(ResultType, ActualArgs), imp, ActualArgs);
+  return CGF.EmitCall(CGM.getTypes().getFunctionInfo(ResultType, ActualArgs), 
+                      imp, ActualArgs);
 }
 
 /// Generates a MethodList.  Used in construction of a objc_class and 
@@ -969,9 +971,9 @@ llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD,
   std::string MethodName = OMD->getSelector().getAsString();
   bool isClassMethod = !OMD->isInstanceMethod();
 
+  CodeGenTypes &Types = CGM.getTypes();
   const llvm::FunctionType *MethodTy = 
-    CGM.getTypes().GetFunctionType(CGFunctionInfo(OMD, CGM.getContext()), 
-                                   OMD->isVariadic());
+    Types.GetFunctionType(Types.getFunctionInfo(OMD), OMD->isVariadic());
   std::string FunctionName = SymbolNameForMethod(ClassName, CategoryName,
       MethodName, isClassMethod);
 
index d8e873b845927485b7065e4bf5d0e2590a64aadc..a577bd03cb261d52f3d9ea8b99fd99b1ae1def0f 100644 (file)
@@ -806,8 +806,9 @@ CodeGen::RValue CGObjCMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF,
                                       CGF.getContext().getObjCSelType()));
   ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
 
-  CGFunctionInfo FnInfo(ResultType, ActualArgs);
-  const llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FnInfo, false);
+  CodeGenTypes &Types = CGM.getTypes();
+  const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, ActualArgs);
+  const llvm::FunctionType *FTy = Types.GetFunctionType(FnInfo, false);
 
   llvm::Constant *Fn;
   if (CGM.ReturnTypeUsesSret(FnInfo)) {
@@ -1668,9 +1669,9 @@ llvm::Function *CGObjCCommonMac::GenerateMethod(const ObjCMethodDecl *OMD,
   std::string Name;
   GetNameForMethod(OMD, CD, Name);
 
+  CodeGenTypes &Types = CGM.getTypes();
   const llvm::FunctionType *MethodTy =
-    CGM.getTypes().GetFunctionType(CGFunctionInfo(OMD, CGM.getContext()), 
-                                   OMD->isVariadic());
+    Types.GetFunctionType(Types.getFunctionInfo(OMD), OMD->isVariadic());
   llvm::Function *Method = 
     llvm::Function::Create(MethodTy,
                            llvm::GlobalValue::InternalLinkage,
index fe28b3aeccdd25c9775434657f6f76c083433334..866b8826241c198efda2dbac057eb38bc0b92382 100644 (file)
@@ -172,7 +172,7 @@ void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy,
   }
 
   // FIXME: Leaked.
-  CurFnInfo = new CGFunctionInfo(FnRetTy, Args);
+  CurFnInfo = &CGM.getTypes().getFunctionInfo(FnRetTy, Args);
   EmitFunctionProlog(*CurFnInfo, CurFn, Args);
   
   // If any of the arguments have a variably modified type, make sure to
index d02812ac5d9ce5f8fa80dc6966b25f5cfac46f6d..18870722fa2821729d98bb7c61184e9069f125d6 100644 (file)
@@ -299,14 +299,14 @@ void CodeGenModule::SetFunctionAttributesForDefinition(const Decl *D,
 
 void CodeGenModule::SetMethodAttributes(const ObjCMethodDecl *MD,
                                         llvm::Function *F) {
-  SetFunctionAttributes(MD, CGFunctionInfo(MD, Context), F);
+  SetFunctionAttributes(MD, getTypes().getFunctionInfo(MD), F);
   
   SetFunctionAttributesForDefinition(MD, F);
 }
 
 void CodeGenModule::SetFunctionAttributes(const FunctionDecl *FD,
                                           llvm::Function *F) {
-  SetFunctionAttributes(FD, CGFunctionInfo(FD), F);
+  SetFunctionAttributes(FD, getTypes().getFunctionInfo(FD), F);
   
   SetGlobalValueAttributes(FD, FD->getStorageClass() == FunctionDecl::Static,
                            FD->isInline(), F, false);
index bcb3cc559158ee8ba43d477743e22185c36a9282..0b74e1e636fbb001e2909f40721373423b5f6b86 100644 (file)
@@ -256,11 +256,11 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
                                  VT.getNumElements());
   }
   case Type::FunctionNoProto:
-    return GetFunctionType(CGFunctionInfo(cast<FunctionTypeNoProto>(&Ty)), 
+    return GetFunctionType(getFunctionInfo(cast<FunctionTypeNoProto>(&Ty)), 
                            true);
   case Type::FunctionProto: {
     const FunctionTypeProto *FTP = cast<FunctionTypeProto>(&Ty);
-    return GetFunctionType(CGFunctionInfo(FTP), FTP->isVariadic());
+    return GetFunctionType(getFunctionInfo(FTP), FTP->isVariadic());
   }
   
   case Type::ASQual:
index 60c2946f131fcb80d52fce53f620beb4cbfdb2a8..d41c23d37476276fce290b447aaf85a7a2344b74 100644 (file)
@@ -158,6 +158,20 @@ public:
   /// UpdateCompletedType - When we find the full definition for a TagDecl,
   /// replace the 'opaque' type we previously made for it if applicable.
   void UpdateCompletedType(const TagDecl *TD);
+
+  /// getFunctionInfo - Get the CGFunctionInfo for this function signature.
+  const CGFunctionInfo &getFunctionInfo(QualType RetTy, 
+                                        const llvm::SmallVector<QualType,16> 
+                                        &ArgTys);
+
+  const CGFunctionInfo &getFunctionInfo(const FunctionTypeNoProto *FTNP);
+  const CGFunctionInfo &getFunctionInfo(const FunctionTypeProto *FTP);
+  const CGFunctionInfo &getFunctionInfo(const FunctionDecl *FD);
+  const CGFunctionInfo &getFunctionInfo(const ObjCMethodDecl *MD);
+  const CGFunctionInfo &getFunctionInfo(QualType ResTy, 
+                                        const CallArgList &Args);
+  const CGFunctionInfo &getFunctionInfo(QualType ResTy, 
+                                        const FunctionArgList &Args);
   
 public:  // These are internal details of CGT that shouldn't be used externally.
   /// addFieldInfo - Assign field number to field FD.