[cfe-commits] r63567 - in /cfe/trunk/lib/CodeGen: CGCall.cpp CGCall.h CGExpr.cpp CGObjC.cpp CGObjCGNU.cpp CGObjCMac.cpp CodeGenFunction.cpp CodeGenModule.cpp CodeGenTypes.cpp CodeGenTypes.h

Daniel Dunbar daniel at zuster.org
Mon Feb 2 15:23:47 PST 2009


Author: ddunbar
Date: Mon Feb  2 17:23:47 2009
New Revision: 63567

URL: http://llvm.org/viewvc/llvm-project?rev=63567&view=rev
Log:
Thread CGFunctionInfo construction through CodeGenTypes.
 - Inefficient & leaks memory currently, will be cleaned up subsequently.

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/CodeGen/CGCall.h
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGObjC.cpp
    cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.h

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=63567&r1=63566&r2=63567&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Feb  2 17:23:47 2009
@@ -31,50 +31,70 @@
 
 // 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 {

Modified: cfe/trunk/lib/CodeGen/CGCall.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.h?rev=63567&r1=63566&r2=63567&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.h (original)
+++ cfe/trunk/lib/CodeGen/CGCall.h Mon Feb  2 17:23:47 2009
@@ -57,12 +57,8 @@
     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;

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=63567&r1=63566&r2=63567&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Feb  2 17:23:47 2009
@@ -1102,5 +1102,6 @@
     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);
 }

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=63567&r1=63566&r2=63567&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Mon Feb  2 17:23:47 2009
@@ -183,7 +183,7 @@
     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 @@
                                   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();

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=63567&r1=63566&r2=63567&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Mon Feb  2 17:23:47 2009
@@ -311,7 +311,8 @@
   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 @@
   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 @@
   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);
 

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=63567&r1=63566&r2=63567&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Mon Feb  2 17:23:47 2009
@@ -806,8 +806,9 @@
                                       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 @@
   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,

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=63567&r1=63566&r2=63567&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Mon Feb  2 17:23:47 2009
@@ -172,7 +172,7 @@
   }
 
   // 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

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=63567&r1=63566&r2=63567&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Feb  2 17:23:47 2009
@@ -299,14 +299,14 @@
 
 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);

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=63567&r1=63566&r2=63567&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Mon Feb  2 17:23:47 2009
@@ -256,11 +256,11 @@
                                  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:

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.h?rev=63567&r1=63566&r2=63567&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.h Mon Feb  2 17:23:47 2009
@@ -158,6 +158,20 @@
   /// 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.





More information about the cfe-commits mailing list