[cfe-commits] r127314 - in /cfe/trunk/lib/CodeGen: CGBlocks.cpp CGCXX.cpp CGCXXABI.cpp CGCall.cpp CGCall.h CGClass.cpp CGDeclCXX.cpp CGObjC.cpp CGVTables.cpp CodeGenFunction.cpp CodeGenFunction.h CodeGenModule.cpp CodeGenModule.h CodeGenTypes.h ItaniumCXXABI.cpp

John McCall rjmccall at apple.com
Tue Mar 8 20:27:21 PST 2011


Author: rjmccall
Date: Tue Mar  8 22:27:21 2011
New Revision: 127314

URL: http://llvm.org/viewvc/llvm-project?rev=127314&view=rev
Log:
Use the "undergoes default argument promotion" bit on parameters to
simplify the logic of initializing function parameters so that we don't need
both a variable declaration and a type in FunctionArgList.  This also means
that we need to propagate the CGFunctionInfo down in a lot of places rather
than recalculating it from the FAL.  There's more we can do to eliminate
redundancy here, and I've left FIXMEs behind to do it.


Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp
    cfe/trunk/lib/CodeGen/CGCXX.cpp
    cfe/trunk/lib/CodeGen/CGCXXABI.cpp
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/CodeGen/CGCall.h
    cfe/trunk/lib/CodeGen/CGClass.cpp
    cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
    cfe/trunk/lib/CodeGen/CGObjC.cpp
    cfe/trunk/lib/CodeGen/CGVTables.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h
    cfe/trunk/lib/CodeGen/CodeGenTypes.h
    cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Tue Mar  8 22:27:21 2011
@@ -902,12 +902,12 @@
 
   ImplicitParamDecl selfDecl(const_cast<BlockDecl*>(blockDecl),
                              SourceLocation(), II, selfTy);
-  args.push_back(std::make_pair(&selfDecl, selfTy));
+  args.push_back(&selfDecl);
 
   // Now add the rest of the parameters.
   for (BlockDecl::param_const_iterator i = blockDecl->param_begin(),
        e = blockDecl->param_end(); i != e; ++i)
-    args.push_back(std::make_pair(*i, (*i)->getType()));
+    args.push_back(*i);
 
   // Create the function declaration.
   const FunctionProtoType *fnType =
@@ -926,7 +926,7 @@
   CGM.SetInternalFunctionAttributes(blockDecl, fn, fnInfo);
 
   // Begin generating the function.
-  StartFunction(blockDecl, fnType->getResultType(), fn, args,
+  StartFunction(blockDecl, fnType->getResultType(), fn, fnInfo, args,
                 blockInfo.getBlockExpr()->getBody()->getLocEnd());
   CurFuncDecl = outerFnDecl; // StartFunction sets this to blockDecl
 
@@ -1054,13 +1054,10 @@
   ASTContext &C = getContext();
 
   FunctionArgList args;
-  // FIXME: This leaks
-  ImplicitParamDecl *dstDecl =
-    ImplicitParamDecl::Create(C, 0, SourceLocation(), 0, C.VoidPtrTy);
-  args.push_back(std::make_pair(dstDecl, dstDecl->getType()));
-  ImplicitParamDecl *srcDecl =
-    ImplicitParamDecl::Create(C, 0, SourceLocation(), 0, C.VoidPtrTy);
-  args.push_back(std::make_pair(srcDecl, srcDecl->getType()));
+  ImplicitParamDecl dstDecl(0, SourceLocation(), 0, C.VoidPtrTy);
+  args.push_back(&dstDecl);
+  ImplicitParamDecl srcDecl(0, SourceLocation(), 0, C.VoidPtrTy);
+  args.push_back(&srcDecl);
 
   const CGFunctionInfo &FI =
       CGM.getTypes().getFunctionInfo(C.VoidTy, args, FunctionType::ExtInfo());
@@ -1084,15 +1081,15 @@
                                           SC_None,
                                           false,
                                           true);
-  StartFunction(FD, C.VoidTy, Fn, args, SourceLocation());
+  StartFunction(FD, C.VoidTy, Fn, FI, args, SourceLocation());
 
   const llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();
 
-  llvm::Value *src = GetAddrOfLocalVar(srcDecl);
+  llvm::Value *src = GetAddrOfLocalVar(&srcDecl);
   src = Builder.CreateLoad(src);
   src = Builder.CreateBitCast(src, structPtrTy, "block.source");
 
-  llvm::Value *dst = GetAddrOfLocalVar(dstDecl);
+  llvm::Value *dst = GetAddrOfLocalVar(&dstDecl);
   dst = Builder.CreateLoad(dst);
   dst = Builder.CreateBitCast(dst, structPtrTy, "block.dest");
 
@@ -1149,10 +1146,8 @@
   ASTContext &C = getContext();
 
   FunctionArgList args;
-  // FIXME: This leaks
-  ImplicitParamDecl *srcDecl =
-    ImplicitParamDecl::Create(C, 0, SourceLocation(), 0, C.VoidPtrTy);
-  args.push_back(std::make_pair(srcDecl, srcDecl->getType()));
+  ImplicitParamDecl srcDecl(0, SourceLocation(), 0, C.VoidPtrTy);
+  args.push_back(&srcDecl);
 
   const CGFunctionInfo &FI =
       CGM.getTypes().getFunctionInfo(C.VoidTy, args, FunctionType::ExtInfo());
@@ -1174,11 +1169,11 @@
                                           SC_Static,
                                           SC_None,
                                           false, true);
-  StartFunction(FD, C.VoidTy, Fn, args, SourceLocation());
+  StartFunction(FD, C.VoidTy, Fn, FI, args, SourceLocation());
 
   const llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();
 
-  llvm::Value *src = GetAddrOfLocalVar(srcDecl);
+  llvm::Value *src = GetAddrOfLocalVar(&srcDecl);
   src = Builder.CreateLoad(src);
   src = Builder.CreateBitCast(src, structPtrTy, "block");
 
@@ -1241,23 +1236,15 @@
                                 const VarDecl *variable) {
   QualType R = getContext().VoidTy;
 
-  FunctionArgList Args;
-  // FIXME: This leaks
-  ImplicitParamDecl *Dst =
-    ImplicitParamDecl::Create(getContext(), 0,
-                              SourceLocation(), 0,
-                              getContext().getPointerType(getContext().VoidTy));
-  Args.push_back(std::make_pair(Dst, Dst->getType()));
-
-  // FIXME: This leaks
-  ImplicitParamDecl *Src =
-    ImplicitParamDecl::Create(getContext(), 0,
-                              SourceLocation(), 0,
-                              getContext().getPointerType(getContext().VoidTy));
-  Args.push_back(std::make_pair(Src, Src->getType()));
+  FunctionArgList args;
+  ImplicitParamDecl dst(0, SourceLocation(), 0, getContext().VoidPtrTy);
+  args.push_back(&dst);
+
+  ImplicitParamDecl src(0, SourceLocation(), 0, getContext().VoidPtrTy);
+  args.push_back(&src);
 
   const CGFunctionInfo &FI =
-      CGM.getTypes().getFunctionInfo(R, Args, FunctionType::ExtInfo());
+      CGM.getTypes().getFunctionInfo(R, args, FunctionType::ExtInfo());
 
   CodeGenTypes &Types = CGM.getTypes();
   const llvm::FunctionType *LTy = Types.GetFunctionType(FI, false);
@@ -1278,17 +1265,17 @@
                                           SC_Static,
                                           SC_None,
                                           false, true);
-  StartFunction(FD, R, Fn, Args, SourceLocation());
+  StartFunction(FD, R, Fn, FI, args, SourceLocation());
 
   // dst->x
-  llvm::Value *V = GetAddrOfLocalVar(Dst);
+  llvm::Value *V = GetAddrOfLocalVar(&dst);
   V = Builder.CreateBitCast(V, llvm::PointerType::get(T, 0));
   V = Builder.CreateLoad(V);
   V = Builder.CreateStructGEP(V, 6, "x");
   llvm::Value *DstObj = V;
 
   // src->x
-  V = GetAddrOfLocalVar(Src);
+  V = GetAddrOfLocalVar(&src);
   V = Builder.CreateLoad(V);
   V = Builder.CreateBitCast(V, T);
   V = Builder.CreateStructGEP(V, 6, "x");
@@ -1317,17 +1304,12 @@
                                                     const VarDecl *variable) {
   QualType R = getContext().VoidTy;
 
-  FunctionArgList Args;
-  // FIXME: This leaks
-  ImplicitParamDecl *Src =
-    ImplicitParamDecl::Create(getContext(), 0,
-                              SourceLocation(), 0,
-                              getContext().getPointerType(getContext().VoidTy));
-
-  Args.push_back(std::make_pair(Src, Src->getType()));
+  FunctionArgList args;
+  ImplicitParamDecl src(0, SourceLocation(), 0, getContext().VoidPtrTy);
+  args.push_back(&src);
 
   const CGFunctionInfo &FI =
-      CGM.getTypes().getFunctionInfo(R, Args, FunctionType::ExtInfo());
+      CGM.getTypes().getFunctionInfo(R, args, FunctionType::ExtInfo());
 
   CodeGenTypes &Types = CGM.getTypes();
   const llvm::FunctionType *LTy = Types.GetFunctionType(FI, false);
@@ -1349,9 +1331,9 @@
                                           SC_Static,
                                           SC_None,
                                           false, true);
-  StartFunction(FD, R, Fn, Args, SourceLocation());
+  StartFunction(FD, R, Fn, FI, args, SourceLocation());
 
-  llvm::Value *V = GetAddrOfLocalVar(Src);
+  llvm::Value *V = GetAddrOfLocalVar(&src);
   V = Builder.CreateBitCast(V, llvm::PointerType::get(T, 0));
   V = Builder.CreateLoad(V);
   V = Builder.CreateStructGEP(V, 6, "x");

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Mar  8 22:27:21 2011
@@ -204,10 +204,13 @@
                                 GlobalDecl(D, Ctor_Base)))
     return;
 
+  const CGFunctionInfo &FnInfo = getTypes().getFunctionInfo(D, Type);
+
+  // FIXME: re-use FnInfo in this computation!
   llvm::Function *Fn = cast<llvm::Function>(GetAddrOfCXXConstructor(D, Type));
   setFunctionLinkage(D, Fn);
 
-  CodeGenFunction(*this).GenerateCode(GlobalDecl(D, Type), Fn);
+  CodeGenFunction(*this).GenerateCode(GlobalDecl(D, Type), Fn, FnInfo);
 
   SetFunctionDefinitionAttributes(D, Fn);
   SetLLVMFunctionAttributesForDefinition(D, Fn);
@@ -263,10 +266,13 @@
   if (Type == Dtor_Base && !TryEmitBaseDestructorAsAlias(D))
     return;
 
+  const CGFunctionInfo &FnInfo = getTypes().getFunctionInfo(D, Type);
+
+  // FIXME: re-use FnInfo in this computation!
   llvm::Function *Fn = cast<llvm::Function>(GetAddrOfCXXDestructor(D, Type));
   setFunctionLinkage(D, Fn);
 
-  CodeGenFunction(*this).GenerateCode(GlobalDecl(D, Type), Fn);
+  CodeGenFunction(*this).GenerateCode(GlobalDecl(D, Type), Fn, FnInfo);
 
   SetFunctionDefinitionAttributes(D, Fn);
   SetLLVMFunctionAttributesForDefinition(D, Fn);

Modified: cfe/trunk/lib/CodeGen/CGCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXXABI.cpp?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXXABI.cpp Tue Mar  8 22:27:21 2011
@@ -115,7 +115,7 @@
   return true;
 }
 
-void CGCXXABI::BuildThisParam(CodeGenFunction &CGF, FunctionArgList &Params) {
+void CGCXXABI::BuildThisParam(CodeGenFunction &CGF, FunctionArgList &params) {
   const CXXMethodDecl *MD = cast<CXXMethodDecl>(CGF.CurGD.getDecl());
 
   // FIXME: I'm not entirely sure I like using a fake decl just for code
@@ -124,7 +124,7 @@
     = ImplicitParamDecl::Create(CGM.getContext(), 0, MD->getLocation(),
                                 &CGM.getContext().Idents.get("this"),
                                 MD->getThisType(CGM.getContext()));
-  Params.push_back(std::make_pair(ThisDecl, ThisDecl->getType()));
+  params.push_back(ThisDecl);
   getThisDecl(CGF) = ThisDecl;
 }
 

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Tue Mar  8 22:27:21 2011
@@ -223,10 +223,15 @@
   llvm::SmallVector<CanQualType, 16> ArgTys;
   for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
        i != e; ++i)
-    ArgTys.push_back(Context.getCanonicalParamType(i->second));
+    ArgTys.push_back(Context.getCanonicalParamType((*i)->getType()));
   return getFunctionInfo(GetReturnType(ResTy), ArgTys, Info);
 }
 
+const CGFunctionInfo &CodeGenTypes::getNullaryFunctionInfo() {
+  llvm::SmallVector<CanQualType, 1> args;
+  return getFunctionInfo(getContext().VoidTy, args, FunctionType::ExtInfo());
+}
+
 const CGFunctionInfo &CodeGenTypes::getFunctionInfo(CanQualType ResTy,
                            const llvm::SmallVectorImpl<CanQualType> &ArgTys,
                                             const FunctionType::ExtInfo &Info,
@@ -826,6 +831,26 @@
     PAL.push_back(llvm::AttributeWithIndex::get(~0, FuncAttrs));
 }
 
+/// An argument came in as a promoted argument; demote it back to its
+/// declared type.
+static llvm::Value *emitArgumentDemotion(CodeGenFunction &CGF,
+                                         const VarDecl *var,
+                                         llvm::Value *value) {
+  const llvm::Type *varType = CGF.ConvertType(var->getType());
+
+  // This can happen with promotions that actually don't change the
+  // underlying type, like the enum promotions.
+  if (value->getType() == varType) return value;
+
+  assert((varType->isIntegerTy() || varType->isFloatingPointTy())
+         && "unexpected promotion type");
+
+  if (isa<llvm::IntegerType>(varType))
+    return CGF.Builder.CreateTrunc(value, varType, "arg.unpromote");
+
+  return CGF.Builder.CreateFPCast(value, varType, "arg.unpromote");
+}
+
 void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
                                          llvm::Function *Fn,
                                          const FunctionArgList &Args) {
@@ -860,10 +885,13 @@
   CGFunctionInfo::const_arg_iterator info_it = FI.arg_begin();
   for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end(); 
        i != e; ++i, ++info_it, ++ArgNo) {
-    const VarDecl *Arg = i->first;
+    const VarDecl *Arg = *i;
     QualType Ty = info_it->type;
     const ABIArgInfo &ArgI = info_it->info;
 
+    bool isPromoted =
+      isa<ParmVarDecl>(Arg) && cast<ParmVarDecl>(Arg)->isKNRPromoted();
+
     switch (ArgI.getKind()) {
     case ABIArgInfo::Indirect: {
       llvm::Value *V = AI;
@@ -893,11 +921,9 @@
         // Load scalar value from indirect argument.
         CharUnits Alignment = getContext().getTypeAlignInChars(Ty);
         V = EmitLoadOfScalar(V, false, Alignment.getQuantity(), Ty);
-        if (!getContext().typesAreCompatible(Ty, Arg->getType())) {
-          // This must be a promotion, for something like
-          // "void a(x) short x; {..."
-          V = EmitScalarConversion(V, Ty, Arg->getType());
-        }
+
+        if (isPromoted)
+          V = emitArgumentDemotion(*this, Arg, V);
       }
       EmitParmDecl(*Arg, V, ArgNo);
       break;
@@ -915,11 +941,9 @@
         if (Arg->getType().isRestrictQualified())
           AI->addAttr(llvm::Attribute::NoAlias);
 
-        if (!getContext().typesAreCompatible(Ty, Arg->getType())) {
-          // This must be a promotion, for something like
-          // "void a(x) short x; {..."
-          V = EmitScalarConversion(V, Ty, Arg->getType());
-        }
+        if (isPromoted)
+          V = emitArgumentDemotion(*this, Arg, V);
+
         EmitParmDecl(*Arg, V, ArgNo);
         break;
       }
@@ -969,11 +993,8 @@
       // Match to what EmitParmDecl is expecting for this type.
       if (!CodeGenFunction::hasAggregateLLVMType(Ty)) {
         V = EmitLoadOfScalar(V, false, AlignmentToUse, Ty);
-        if (!getContext().typesAreCompatible(Ty, Arg->getType())) {
-          // This must be a promotion, for something like
-          // "void a(x) short x; {..."
-          V = EmitScalarConversion(V, Ty, Arg->getType());
-        }
+        if (isPromoted)
+          V = emitArgumentDemotion(*this, Arg, V);
       }
       EmitParmDecl(*Arg, V, ArgNo);
       continue;  // Skip ++AI increment, already done.

Modified: cfe/trunk/lib/CodeGen/CGCall.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.h?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.h (original)
+++ cfe/trunk/lib/CodeGen/CGCall.h Tue Mar  8 22:27:21 2011
@@ -46,13 +46,15 @@
 
   /// CallArgList - Type for representing both the value and type of
   /// arguments in a call.
-  typedef llvm::SmallVector<std::pair<RValue, QualType>, 16> CallArgList;
+  class CallArgList :
+    public llvm::SmallVector<std::pair<RValue, QualType>, 16> {
+  };
 
   /// FunctionArgList - Type for representing both the decl and type
   /// of parameters to a function. The decl must be either a
   /// ParmVarDecl or ImplicitParamDecl.
-  typedef llvm::SmallVector<std::pair<const VarDecl*, QualType>,
-                            16> FunctionArgList;
+  class FunctionArgList : public llvm::SmallVector<const VarDecl*, 16> {
+  };
 
   /// CGFunctionInfo - Class to encapsulate the information about a
   /// function definition.

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Tue Mar  8 22:27:21 2011
@@ -589,8 +589,7 @@
         // we know we're in a copy constructor.
         unsigned SrcArgIndex = Args.size() - 1;
         llvm::Value *SrcPtr
-          = CGF.Builder.CreateLoad(
-                               CGF.GetAddrOfLocalVar(Args[SrcArgIndex].first));
+          = CGF.Builder.CreateLoad(CGF.GetAddrOfLocalVar(Args[SrcArgIndex]));
         LValue Src = CGF.EmitLValueForFieldInitialization(SrcPtr, Field, 0);
         
         // Copy the aggregate.
@@ -1244,7 +1243,7 @@
 
   // this
   DelegateArgs.push_back(std::make_pair(RValue::get(LoadCXXThis()),
-                                        I->second));
+                                        (*I)->getType()));
   ++I;
 
   // vtt
@@ -1255,14 +1254,14 @@
 
     if (CodeGenVTables::needsVTTParameter(CurGD)) {
       assert(I != E && "cannot skip vtt parameter, already done with args");
-      assert(I->second == VoidPP && "skipping parameter not of vtt type");
+      assert((*I)->getType() == VoidPP && "skipping parameter not of vtt type");
       ++I;
     }
   }
 
   // Explicit arguments.
   for (; I != E; ++I) {
-    const VarDecl *Param = I->first;
+    const VarDecl *Param = *I;
     QualType ArgType = Param->getType(); // because we're passing it to itself
     RValue Arg = EmitDelegateCallArg(Param);
 

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Tue Mar  8 22:27:21 2011
@@ -260,8 +260,9 @@
 void CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
                                                        const VarDecl *D,
                                                  llvm::GlobalVariable *Addr) {
-  StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FunctionArgList(),
-                SourceLocation());
+  StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
+                getTypes().getNullaryFunctionInfo(),
+                FunctionArgList(), SourceLocation());
 
   // Use guarded initialization if the global variable is weak due to
   // being a class template's static data member.
@@ -277,8 +278,9 @@
 void CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
                                                 llvm::Constant **Decls,
                                                 unsigned NumDecls) {
-  StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FunctionArgList(),
-                SourceLocation());
+  StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
+                getTypes().getNullaryFunctionInfo(),
+                FunctionArgList(), SourceLocation());
 
   for (unsigned i = 0; i != NumDecls; ++i)
     if (Decls[i])
@@ -290,8 +292,9 @@
 void CodeGenFunction::GenerateCXXGlobalDtorFunc(llvm::Function *Fn,
                   const std::vector<std::pair<llvm::WeakVH, llvm::Constant*> >
                                                 &DtorsAndObjects) {
-  StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FunctionArgList(),
-                SourceLocation());
+  StartFunction(GlobalDecl(), getContext().VoidTy, Fn,
+                getTypes().getNullaryFunctionInfo(),
+                FunctionArgList(), SourceLocation());
 
   // Emit the dtors, in reverse order from construction.
   for (unsigned i = 0, e = DtorsAndObjects.size(); i != e; ++i) {
@@ -313,21 +316,19 @@
 CodeGenFunction::GenerateCXXAggrDestructorHelper(const CXXDestructorDecl *D,
                                                  const ArrayType *Array,
                                                  llvm::Value *This) {
-  FunctionArgList Args;
-  ImplicitParamDecl *Dst =
-    ImplicitParamDecl::Create(getContext(), 0,
-                              SourceLocation(), 0,
-                              getContext().getPointerType(getContext().VoidTy));
-  Args.push_back(std::make_pair(Dst, Dst->getType()));
+  FunctionArgList args;
+  ImplicitParamDecl dst(0, SourceLocation(), 0, getContext().VoidPtrTy);
+  args.push_back(&dst);
   
   const CGFunctionInfo &FI = 
-    CGM.getTypes().getFunctionInfo(getContext().VoidTy, Args, 
+    CGM.getTypes().getFunctionInfo(getContext().VoidTy, args, 
                                    FunctionType::ExtInfo());
   const llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI, false);
   llvm::Function *Fn = 
     CreateGlobalInitOrDestructFunction(CGM, FTy, "__cxx_global_array_dtor");
 
-  StartFunction(GlobalDecl(), getContext().VoidTy, Fn, Args, SourceLocation());
+  StartFunction(GlobalDecl(), getContext().VoidTy, Fn, FI, args,
+                SourceLocation());
 
   QualType BaseElementTy = getContext().getBaseElementType(Array);
   const llvm::Type *BasePtr = ConvertType(BaseElementTy)->getPointerTo();

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Tue Mar  8 22:27:21 2011
@@ -119,7 +119,7 @@
 /// CodeGenFunction.
 void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD,
                                       const ObjCContainerDecl *CD) {
-  FunctionArgList Args;
+  FunctionArgList args;
   // Check if we should generate debug info for this method.
   if (CGM.getModuleDebugInfo() && !OMD->hasAttr<NoDebugAttr>())
     DebugInfo = CGM.getModuleDebugInfo();
@@ -129,18 +129,16 @@
   const CGFunctionInfo &FI = CGM.getTypes().getFunctionInfo(OMD);
   CGM.SetInternalFunctionAttributes(OMD, Fn, FI);
 
-  Args.push_back(std::make_pair(OMD->getSelfDecl(),
-                                OMD->getSelfDecl()->getType()));
-  Args.push_back(std::make_pair(OMD->getCmdDecl(),
-                                OMD->getCmdDecl()->getType()));
+  args.push_back(OMD->getSelfDecl());
+  args.push_back(OMD->getCmdDecl());
 
   for (ObjCMethodDecl::param_iterator PI = OMD->param_begin(),
        E = OMD->param_end(); PI != E; ++PI)
-    Args.push_back(std::make_pair(*PI, (*PI)->getType()));
+    args.push_back(*PI);
 
   CurGD = OMD;
 
-  StartFunction(OMD, OMD->getResultType(), Fn, Args, OMD->getLocStart());
+  StartFunction(OMD, OMD->getResultType(), Fn, FI, args, OMD->getLocStart());
 }
 
 void CodeGenFunction::GenerateObjCGetterBody(ObjCIvarDecl *Ivar, 

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Tue Mar  8 22:27:21 2011
@@ -2559,8 +2559,9 @@
   Fn->setVisibility(llvm::GlobalValue::HiddenVisibility);
 }
 
-void CodeGenFunction::GenerateThunk(llvm::Function *Fn, GlobalDecl GD,
-                                    const ThunkInfo &Thunk) {
+void CodeGenFunction::GenerateThunk(llvm::Function *Fn,
+                                    const CGFunctionInfo &FnInfo,
+                                    GlobalDecl GD, const ThunkInfo &Thunk) {
   const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
   const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
   QualType ResultType = FPT->getResultType();
@@ -2580,10 +2581,11 @@
        E = MD->param_end(); I != E; ++I) {
     ParmVarDecl *Param = *I;
     
-    FunctionArgs.push_back(std::make_pair(Param, Param->getType()));
+    FunctionArgs.push_back(Param);
   }
   
-  StartFunction(GlobalDecl(), ResultType, Fn, FunctionArgs, SourceLocation());
+  StartFunction(GlobalDecl(), ResultType, Fn, FnInfo, FunctionArgs,
+                SourceLocation());
 
   CGM.getCXXABI().EmitInstanceFunctionProlog(*this);
 
@@ -2614,9 +2616,11 @@
                                    FPT->isVariadic());
   llvm::Value *Callee = CGM.GetAddrOfFunction(GD, Ty, /*ForVTable=*/true);
 
-  const CGFunctionInfo &FnInfo = 
-    CGM.getTypes().getFunctionInfo(ResultType, CallArgs,
-                                   FPT->getExtInfo());
+#ifndef NDEBUG
+  const CGFunctionInfo &CallFnInfo = 
+    CGM.getTypes().getFunctionInfo(ResultType, CallArgs, FPT->getExtInfo());
+  assert(&CallFnInfo == &FnInfo && "thunk has different CC from callee?");
+#endif
   
   // Determine whether we have a return value slot to use.
   ReturnValueSlot Slot;
@@ -2684,6 +2688,9 @@
 void CodeGenVTables::EmitThunk(GlobalDecl GD, const ThunkInfo &Thunk, 
                                bool UseAvailableExternallyLinkage)
 {
+  const CGFunctionInfo &FnInfo = CGM.getTypes().getFunctionInfo(GD);
+
+  // FIXME: re-use FnInfo in this computation.
   llvm::Constant *Entry = CGM.GetAddrOfThunk(GD, Thunk);
   
   // Strip off a bitcast if we got one back.
@@ -2735,7 +2742,7 @@
   }
 
   // Actually generate the thunk body.
-  CodeGenFunction(CGM).GenerateThunk(ThunkFn, GD, Thunk);
+  CodeGenFunction(CGM).GenerateThunk(ThunkFn, FnInfo, GD, Thunk);
 
   if (UseAvailableExternallyLinkage)
     ThunkFn->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Mar  8 22:27:21 2011
@@ -210,6 +210,7 @@
 
 void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
                                     llvm::Function *Fn,
+                                    const CGFunctionInfo &FnInfo,
                                     const FunctionArgList &Args,
                                     SourceLocation StartLoc) {
   const Decl *D = GD.getDecl();
@@ -218,6 +219,7 @@
   CurCodeDecl = CurFuncDecl = D;
   FnRetTy = RetTy;
   CurFn = Fn;
+  CurFnInfo = &FnInfo;
   assert(CurFn->isDeclaration() && "Function already has body?");
 
   // Pass inline keyword to optimizer if it appears explicitly on any
@@ -275,11 +277,6 @@
   if (CGM.getCodeGenOpts().InstrumentForProfiling)
     EmitMCountInstrumentation();
 
-  // FIXME: Leaked.
-  // CC info is ignored, hopefully?
-  CurFnInfo = &CGM.getTypes().getFunctionInfo(FnRetTy, Args,
-                                              FunctionType::ExtInfo());
-
   if (RetTy->isVoidType()) {
     // Void type; nothing to return.
     ReturnValue = 0;
@@ -302,7 +299,7 @@
   // emit the type size.
   for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
        i != e; ++i) {
-    QualType Ty = i->second;
+    QualType Ty = (*i)->getType();
 
     if (Ty->isVariablyModifiedType())
       EmitVLASize(Ty);
@@ -332,7 +329,8 @@
   F->setDoesNotThrow(true);
 }
 
-void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn) {
+void CodeGenFunction::GenerateCode(GlobalDecl GD, llvm::Function *Fn,
+                                   const CGFunctionInfo &FnInfo) {
   const FunctionDecl *FD = cast<FunctionDecl>(GD.getDecl());
   
   // Check if we should generate debug info for this function.
@@ -346,20 +344,15 @@
   if (isa<CXXMethodDecl>(FD) && cast<CXXMethodDecl>(FD)->isInstance())
     CGM.getCXXABI().BuildInstanceFunctionParams(*this, ResTy, Args);
 
-  if (FD->getNumParams()) {
-    const FunctionProtoType* FProto = FD->getType()->getAs<FunctionProtoType>();
-    assert(FProto && "Function def must have prototype!");
-
+  if (FD->getNumParams())
     for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i)
-      Args.push_back(std::make_pair(FD->getParamDecl(i),
-                                    FProto->getArgType(i)));
-  }
+      Args.push_back(FD->getParamDecl(i));
 
   SourceRange BodyRange;
   if (Stmt *Body = FD->getBody()) BodyRange = Body->getSourceRange();
 
   // Emit the standard function prologue.
-  StartFunction(GD, ResTy, Fn, Args, BodyRange.getBegin());
+  StartFunction(GD, ResTy, Fn, FnInfo, Args, BodyRange.getBegin());
 
   // Generate the body of the function.
   if (isa<CXXDestructorDecl>(FD))

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Mar  8 22:27:21 2011
@@ -25,7 +25,6 @@
 #include "llvm/Support/ValueHandle.h"
 #include "CodeGenModule.h"
 #include "CGBuilder.h"
-#include "CGCall.h"
 #include "CGValue.h"
 
 namespace llvm {
@@ -1130,9 +1129,11 @@
   llvm::Value *GetAddrOfBlockDecl(const VarDecl *var, bool ByRef);
   const llvm::Type *BuildByRefType(const VarDecl *var);
 
-  void GenerateCode(GlobalDecl GD, llvm::Function *Fn);
+  void GenerateCode(GlobalDecl GD, llvm::Function *Fn,
+                    const CGFunctionInfo &FnInfo);
   void StartFunction(GlobalDecl GD, QualType RetTy,
                      llvm::Function *Fn,
+                     const CGFunctionInfo &FnInfo,
                      const FunctionArgList &Args,
                      SourceLocation StartLoc);
 
@@ -1149,7 +1150,8 @@
   void FinishFunction(SourceLocation EndLoc=SourceLocation());
 
   /// GenerateThunk - Generate a thunk for the given method.
-  void GenerateThunk(llvm::Function *Fn, GlobalDecl GD, const ThunkInfo &Thunk);
+  void GenerateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo,
+                     GlobalDecl GD, const ThunkInfo &Thunk);
 
   void EmitCtorPrologue(const CXXConstructorDecl *CD, CXXCtorType Type,
                         FunctionArgList &Args);
@@ -2036,7 +2038,8 @@
                                  const std::vector<std::pair<llvm::WeakVH,
                                    llvm::Constant*> > &DtorsAndObjects);
 
-  void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn, const VarDecl *D,
+  void GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
+                                        const VarDecl *D,
                                         llvm::GlobalVariable *Addr);
 
   void EmitCXXConstructExpr(const CXXConstructExpr *E, AggValueSlot Dest);

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Mar  8 22:27:21 2011
@@ -1391,7 +1391,12 @@
 
 void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD) {
   const FunctionDecl *D = cast<FunctionDecl>(GD.getDecl());
+
+  const CGFunctionInfo &FI = getTypes().getFunctionInfo(GD);
+
+  // FIXME: re-use FI in this computation!
   const llvm::FunctionType *Ty = getTypes().GetFunctionType(GD);
+
   // Get or create the prototype for the function.
   llvm::Constant *Entry = GetAddrOfFunction(GD, Ty);
 
@@ -1451,7 +1456,7 @@
   // FIXME: this is redundant with part of SetFunctionDefinitionAttributes
   setGlobalVisibility(Fn, D);
 
-  CodeGenFunction(*this).GenerateCode(D, Fn);
+  CodeGenFunction(*this).GenerateCode(D, Fn, FI);
 
   SetFunctionDefinitionAttributes(D, Fn);
   SetLLVMFunctionAttributesForDefinition(D, Fn);

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Tue Mar  8 22:27:21 2011
@@ -20,7 +20,6 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/Mangle.h"
-#include "CGCall.h"
 #include "CGVTables.h"
 #include "CodeGenTypes.h"
 #include "GlobalDecl.h"
@@ -69,12 +68,14 @@
 
 namespace CodeGen {
 
+  class CallArgList;
   class CodeGenFunction;
   class CodeGenTBAA;
   class CGCXXABI;
   class CGDebugInfo;
   class CGObjCRuntime;
   class BlockFieldFlags;
+  class FunctionArgList;
   
   struct OrderGlobalInits {
     unsigned int priority;

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.h?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.h Tue Mar  8 22:27:21 2011
@@ -149,6 +149,10 @@
   /// replace the 'opaque' type we previously made for it if applicable.
   void UpdateCompletedType(const TagDecl *TD);
 
+  /// getNullaryFunctionInfo - Get the function info for a void()
+  /// function with standard CC.
+  const CGFunctionInfo &getNullaryFunctionInfo();
+
   /// getFunctionInfo - Get the function info for the specified function decl.
   const CGFunctionInfo &getFunctionInfo(GlobalDecl GD);
 

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=127314&r1=127313&r2=127314&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Tue Mar  8 22:27:21 2011
@@ -745,7 +745,7 @@
     ImplicitParamDecl *VTTDecl
       = ImplicitParamDecl::Create(Context, 0, MD->getLocation(),
                                   &Context.Idents.get("vtt"), T);
-    Params.push_back(std::make_pair(VTTDecl, VTTDecl->getType()));
+    Params.push_back(VTTDecl);
     getVTTDecl(CGF) = VTTDecl;
   }
 }
@@ -757,7 +757,7 @@
 
   // Return 'this' from certain constructors and destructors.
   if (HasThisReturn(CGF.CurGD))
-    ResTy = Params[0].second;
+    ResTy = Params[0]->getType();
 }
 
 void ItaniumCXXABI::EmitInstanceFunctionProlog(CodeGenFunction &CGF) {





More information about the cfe-commits mailing list