the big refactoring bits of PR3782.

This introduces FunctionType::ExtInfo to hold the calling convention and the
noreturn attribute. The next patch will extend it to include the regparm
attribute and fix the bug.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99920 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp
index c10a401..9217859 100644
--- a/lib/CodeGen/CGBlocks.cpp
+++ b/lib/CodeGen/CGBlocks.cpp
@@ -192,7 +192,7 @@
       CallArgList Args;
       CodeGenTypes &Types = CGM.getTypes();
       const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, Args,
-                                                       CC_Default, false);
+                                                       FunctionType::ExtInfo());
       if (CGM.ReturnTypeUsesSret(FnInfo))
         flags |= BLOCK_USE_STRET;
     }
@@ -472,8 +472,8 @@
   QualType ResultType = FuncTy->getResultType();
 
   const CGFunctionInfo &FnInfo =
-    CGM.getTypes().getFunctionInfo(ResultType, Args, FuncTy->getCallConv(),
-                                   FuncTy->getNoReturnAttr());
+    CGM.getTypes().getFunctionInfo(ResultType, Args,
+                                   FuncTy->getExtInfo());
 
   // Cast the function pointer to the right type.
   const llvm::Type *BlockFTy =
@@ -678,8 +678,7 @@
 
   const FunctionType *BlockFunctionType = BExpr->getFunctionType();
   QualType ResultType;
-  CallingConv CC = BlockFunctionType->getCallConv();
-  bool NoReturn = BlockFunctionType->getNoReturnAttr();
+  FunctionType::ExtInfo EInfo = getFunctionExtInfo(*BlockFunctionType);
   bool IsVariadic;
   if (const FunctionProtoType *FTy =
       dyn_cast<FunctionProtoType>(BlockFunctionType)) {
@@ -718,7 +717,7 @@
     Args.push_back(std::make_pair(*i, (*i)->getType()));
 
   const CGFunctionInfo &FI =
-    CGM.getTypes().getFunctionInfo(ResultType, Args, CC, NoReturn);
+    CGM.getTypes().getFunctionInfo(ResultType, Args, EInfo);
 
   CodeGenTypes &Types = CGM.getTypes();
   const llvm::FunctionType *LTy = Types.GetFunctionType(FI, IsVariadic);
@@ -843,7 +842,7 @@
   Args.push_back(std::make_pair(Src, Src->getType()));
 
   const CGFunctionInfo &FI =
-    CGM.getTypes().getFunctionInfo(R, Args, CC_Default, false);
+      CGM.getTypes().getFunctionInfo(R, Args, FunctionType::ExtInfo());
 
   // FIXME: We'd like to put these into a mergable by content, with
   // internal linkage.
@@ -924,7 +923,7 @@
   Args.push_back(std::make_pair(Src, Src->getType()));
 
   const CGFunctionInfo &FI =
-    CGM.getTypes().getFunctionInfo(R, Args, CC_Default, false);
+      CGM.getTypes().getFunctionInfo(R, Args, FunctionType::ExtInfo());
 
   // FIXME: We'd like to put these into a mergable by content, with
   // internal linkage.
@@ -1008,7 +1007,7 @@
   Args.push_back(std::make_pair(Src, Src->getType()));
 
   const CGFunctionInfo &FI =
-    CGM.getTypes().getFunctionInfo(R, Args, CC_Default, false);
+      CGM.getTypes().getFunctionInfo(R, Args, FunctionType::ExtInfo());
 
   CodeGenTypes &Types = CGM.getTypes();
   const llvm::FunctionType *LTy = Types.GetFunctionType(FI, false);
@@ -1071,7 +1070,7 @@
   Args.push_back(std::make_pair(Src, Src->getType()));
 
   const CGFunctionInfo &FI =
-    CGM.getTypes().getFunctionInfo(R, Args, CC_Default, false);
+      CGM.getTypes().getFunctionInfo(R, Args, FunctionType::ExtInfo());
 
   CodeGenTypes &Types = CGM.getTypes();
   const llvm::FunctionType *LTy = Types.GetFunctionType(FI, false);
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index dcd0bea..d861348 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -67,8 +67,7 @@
 CodeGenTypes::getFunctionInfo(CanQual<FunctionNoProtoType> FTNP) {
   return getFunctionInfo(FTNP->getResultType().getUnqualifiedType(),
                          llvm::SmallVector<CanQualType, 16>(),
-                         FTNP->getCallConv(),
-                         FTNP->getNoReturnAttr());
+                         FTNP->getExtInfo());
 }
 
 /// \param Args - contains any initial parameters besides those
@@ -81,8 +80,7 @@
     ArgTys.push_back(FTP->getArgType(i));
   CanQualType ResTy = FTP->getResultType().getUnqualifiedType();
   return CGT.getFunctionInfo(ResTy, ArgTys,
-                             FTP->getCallConv(),
-                             FTP->getNoReturnAttr());
+                             FTP->getExtInfo());
 }
 
 const CGFunctionInfo &
@@ -175,8 +173,9 @@
   }
   return getFunctionInfo(GetReturnType(MD->getResultType()),
                          ArgTys,
-                         getCallingConventionForDecl(MD),
-                         /*NoReturn*/ false);
+                         FunctionType::ExtInfo(
+                             /*NoReturn*/ false,
+                             getCallingConventionForDecl(MD)));
 }
 
 const CGFunctionInfo &CodeGenTypes::getFunctionInfo(GlobalDecl GD) {
@@ -194,32 +193,32 @@
 
 const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy,
                                                     const CallArgList &Args,
-                                                    CallingConv CC,
-                                                    bool NoReturn) {
+                                            const FunctionType::ExtInfo &Info) {
   // FIXME: Kill copy.
   llvm::SmallVector<CanQualType, 16> ArgTys;
   for (CallArgList::const_iterator i = Args.begin(), e = Args.end();
        i != e; ++i)
     ArgTys.push_back(Context.getCanonicalParamType(i->second));
-  return getFunctionInfo(GetReturnType(ResTy), ArgTys, CC, NoReturn);
+  return getFunctionInfo(GetReturnType(ResTy), ArgTys, Info);
 }
 
 const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy,
                                                     const FunctionArgList &Args,
-                                                    CallingConv CC,
-                                                    bool NoReturn) {
+                                            const FunctionType::ExtInfo &Info) {
   // FIXME: Kill copy.
   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));
-  return getFunctionInfo(GetReturnType(ResTy), ArgTys, CC, NoReturn);
+  return getFunctionInfo(GetReturnType(ResTy), ArgTys, Info);
 }
 
 const CGFunctionInfo &CodeGenTypes::getFunctionInfo(CanQualType ResTy,
                            const llvm::SmallVectorImpl<CanQualType> &ArgTys,
-                                                    CallingConv CallConv,
-                                                    bool NoReturn) {
+                                            const FunctionType::ExtInfo &Info) {
+  const CallingConv CallConv = Info.getCC();
+  const bool NoReturn = Info.getNoReturn();
+
 #ifndef NDEBUG
   for (llvm::SmallVectorImpl<CanQualType>::const_iterator
          I = ArgTys.begin(), E = ArgTys.end(); I != E; ++I)
@@ -230,7 +229,7 @@
 
   // Lookup or create unique function info.
   llvm::FoldingSetNodeID ID;
-  CGFunctionInfo::Profile(ID, CC, NoReturn, ResTy,
+  CGFunctionInfo::Profile(ID, Info, ResTy,
                           ArgTys.begin(), ArgTys.end());
 
   void *InsertPos = 0;
diff --git a/lib/CodeGen/CGCall.h b/lib/CodeGen/CGCall.h
index 3d81165..235ff9c 100644
--- a/lib/CodeGen/CGCall.h
+++ b/lib/CodeGen/CGCall.h
@@ -122,13 +122,12 @@
     }
     template<class Iterator>
     static void Profile(llvm::FoldingSetNodeID &ID,
-                        unsigned CallingConvention,
-                        bool NoReturn,
+                        const FunctionType::ExtInfo &Info,
                         CanQualType ResTy,
                         Iterator begin,
                         Iterator end) {
-      ID.AddInteger(CallingConvention);
-      ID.AddBoolean(NoReturn);
+      ID.AddInteger(Info.getCC());
+      ID.AddBoolean(Info.getNoReturn());
       ResTy.Profile(ID);
       for (; begin != end; ++begin) {
         CanQualType T = *begin; // force iterator to be over canonical types
diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp
index e702c5e..177e862 100644
--- a/lib/CodeGen/CGClass.cpp
+++ b/lib/CodeGen/CGClass.cpp
@@ -1379,7 +1379,7 @@
   llvm::raw_svector_ostream(Name) << "__tcf_" << (++UniqueAggrDestructorCount);
   QualType R = getContext().VoidTy;
   const CGFunctionInfo &FI
-    = CGM.getTypes().getFunctionInfo(R, Args, CC_Default, false);
+      = CGM.getTypes().getFunctionInfo(R, Args, FunctionType::ExtInfo());
   const llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI, false);
   llvm::Function *Fn =
     llvm::Function::Create(FTy, llvm::GlobalValue::InternalLinkage,
diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp
index 28b1d3b..d9585c9 100644
--- a/lib/CodeGen/CGExprCXX.cpp
+++ b/lib/CodeGen/CGExprCXX.cpp
@@ -44,9 +44,8 @@
 
   QualType ResultType = FPT->getResultType();
   return EmitCall(CGM.getTypes().getFunctionInfo(ResultType, Args,
-                                                 FPT->getCallConv(),
-                                                 FPT->getNoReturnAttr()), Callee, 
-                  ReturnValue, Args, MD);
+                                                 FPT->getExtInfo()),
+                  Callee, ReturnValue, Args, MD);
 }
 
 /// canDevirtualizeMemberFunctionCalls - Checks whether virtual calls on given
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index d2b7a24..9eaf57c 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -191,7 +191,7 @@
     // FIXME: We shouldn't need to get the function info here, the
     // runtime already should have computed it to build the function.
     RValue RV = EmitCall(Types.getFunctionInfo(PD->getType(), Args,
-                                               CC_Default, false),
+                                               FunctionType::ExtInfo()),
                          GetPropertyFn, ReturnValueSlot(), 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
@@ -285,7 +285,8 @@
     // FIXME: We shouldn't need to get the function info here, the runtime
     // already should have computed it to build the function.
     EmitCall(Types.getFunctionInfo(getContext().VoidTy, Args,
-                                   CC_Default, false), SetPropertyFn,
+                                   FunctionType::ExtInfo()),
+             SetPropertyFn,
              ReturnValueSlot(), Args);
   } else {
     // FIXME: Find a clean way to avoid AST node creation.
@@ -561,7 +562,7 @@
   // FIXME: We shouldn't need to get the function info here, the runtime already
   // should have computed it to build the function.
   EmitCall(CGM.getTypes().getFunctionInfo(getContext().VoidTy, Args2,
-                                          CC_Default, false),
+                                          FunctionType::ExtInfo()),
            EnumerationMutationFn, ReturnValueSlot(), Args2);
 
   EmitBlock(WasNotMutated);
diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp
index 119819b..d445200 100644
--- a/lib/CodeGen/CGObjCGNU.cpp
+++ b/lib/CodeGen/CGObjCGNU.cpp
@@ -465,7 +465,7 @@
 
   CodeGenTypes &Types = CGM.getTypes();
   const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, ActualArgs,
-                                                       CC_Default, false);
+                                                       FunctionType::ExtInfo());
   const llvm::FunctionType *impType =
     Types.GetFunctionType(FnInfo, Method ? Method->isVariadic() : false);
 
@@ -573,7 +573,7 @@
 
   CodeGenTypes &Types = CGM.getTypes();
   const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, ActualArgs,
-                                                       CC_Default, false);
+                                                       FunctionType::ExtInfo());
   const llvm::FunctionType *impType =
     Types.GetFunctionType(FnInfo, Method ? Method->isVariadic() : false);
 
@@ -1694,7 +1694,7 @@
   Params.push_back(ASTIdTy);
   const llvm::FunctionType *FTy =
     Types.GetFunctionType(Types.getFunctionInfo(Ctx.VoidTy, Params,
-                                                CC_Default, false), false);
+                                              FunctionType::ExtInfo()), false);
   return CGM.CreateRuntimeFunction(FTy, "objc_enumerationMutation");
 }
 
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index 475280b..1ed41d0 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -306,7 +306,8 @@
     Params.push_back(Ctx.BoolTy);
     const llvm::FunctionType *FTy =
       Types.GetFunctionType(Types.getFunctionInfo(IdType, Params,
-                                                  CC_Default, false), false);
+                                                  FunctionType::ExtInfo()),
+                            false);
     return CGM.CreateRuntimeFunction(FTy, "objc_getProperty");
   }
 
@@ -325,7 +326,8 @@
     Params.push_back(Ctx.BoolTy);
     const llvm::FunctionType *FTy =
       Types.GetFunctionType(Types.getFunctionInfo(Ctx.VoidTy, Params,
-                                                  CC_Default, false), false);
+                                                  FunctionType::ExtInfo()),
+                            false);
     return CGM.CreateRuntimeFunction(FTy, "objc_setProperty");
   }
 
@@ -337,7 +339,8 @@
     Params.push_back(Ctx.getCanonicalParamType(Ctx.getObjCIdType()));
     const llvm::FunctionType *FTy =
       Types.GetFunctionType(Types.getFunctionInfo(Ctx.VoidTy, Params,
-                                                  CC_Default, false), false);
+                                                  FunctionType::ExtInfo()),
+                            false);
     return CGM.CreateRuntimeFunction(FTy, "objc_enumerationMutation");
   }
 
@@ -1559,7 +1562,7 @@
 
   CodeGenTypes &Types = CGM.getTypes();
   const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, ActualArgs,
-                                                       CC_Default, false);
+                                                       FunctionType::ExtInfo());
   const llvm::FunctionType *FTy =
     Types.GetFunctionType(FnInfo, Method ? Method->isVariadic() : false);
 
@@ -5094,7 +5097,8 @@
   // FIXME. This is too much work to get the ABI-specific result type needed to
   // find the message name.
   const CGFunctionInfo &FnInfo
-    = Types.getFunctionInfo(ResultType, CallArgList(), CC_Default, false);
+      = Types.getFunctionInfo(ResultType, CallArgList(),
+                              FunctionType::ExtInfo());
   llvm::Constant *Fn = 0;
   std::string Name("\01l_");
   if (CGM.ReturnTypeUsesSret(FnInfo)) {
@@ -5169,7 +5173,7 @@
                                       ObjCTypes.MessageRefCPtrTy));
   ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
   const CGFunctionInfo &FnInfo1 = Types.getFunctionInfo(ResultType, ActualArgs,
-                                                        CC_Default, false);
+                                                      FunctionType::ExtInfo());
   llvm::Value *Callee = CGF.Builder.CreateStructGEP(Arg1, 0);
   Callee = CGF.Builder.CreateLoad(Callee);
   const llvm::FunctionType *FTy = Types.GetFunctionType(FnInfo1, true);
diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp
index bae588a..2d1c734 100644
--- a/lib/CodeGen/CGVtable.cpp
+++ b/lib/CodeGen/CGVtable.cpp
@@ -2669,8 +2669,8 @@
   llvm::Value *Callee = CGM.GetAddrOfFunction(GD, Ty);
 
   const CGFunctionInfo &FnInfo = 
-    CGM.getTypes().getFunctionInfo(ResultType, CallArgs, FPT->getCallConv(), 
-                                   FPT->getNoReturnAttr());
+    CGM.getTypes().getFunctionInfo(ResultType, CallArgs,
+                                   FPT->getExtInfo());
   
   // Now emit our call.
   RValue RV = EmitCall(FnInfo, Callee, ReturnValueSlot(), CallArgs, MD);
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index ba5aaf6..b863aff 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -199,8 +199,8 @@
 
   QualType FnType = getContext().getFunctionType(RetTy, 0, 0, false, 0,
                                                  false, false, 0, 0,
-                                                 /*FIXME?*/false,
-                                                 /*FIXME?*/CC_Default);
+                                                 /*FIXME?*/
+                                                 FunctionType::ExtInfo());
 
   // Emit subprogram debug descriptor.
   if (CGDebugInfo *DI = getDebugInfo()) {
@@ -211,7 +211,7 @@
   // FIXME: Leaked.
   // CC info is ignored, hopefully?
   CurFnInfo = &CGM.getTypes().getFunctionInfo(FnRetTy, Args,
-                                              CC_Default, false);
+                                              FunctionType::ExtInfo());
 
   if (RetTy->isVoidType()) {
     // Void type; nothing to return.
diff --git a/lib/CodeGen/CodeGenTypes.h b/lib/CodeGen/CodeGenTypes.h
index b2912ef..173c4ad 100644
--- a/lib/CodeGen/CodeGenTypes.h
+++ b/lib/CodeGen/CodeGenTypes.h
@@ -202,7 +202,7 @@
   const CGFunctionInfo &getFunctionInfo(const CallArgList &Args,
                                         const FunctionType *Ty) {
     return getFunctionInfo(Ty->getResultType(), Args,
-                           Ty->getCallConv(), Ty->getNoReturnAttr());
+                           Ty->getExtInfo());
   }
   const CGFunctionInfo &getFunctionInfo(CanQual<FunctionProtoType> Ty);
   const CGFunctionInfo &getFunctionInfo(CanQual<FunctionNoProtoType> Ty);
@@ -216,20 +216,17 @@
   /// specified, the "C" calling convention will be used.
   const CGFunctionInfo &getFunctionInfo(QualType ResTy,
                                         const CallArgList &Args,
-                                        CallingConv CC,
-                                        bool NoReturn);
+                                        const FunctionType::ExtInfo &Info);
   const CGFunctionInfo &getFunctionInfo(QualType ResTy,
                                         const FunctionArgList &Args,
-                                        CallingConv CC,
-                                        bool NoReturn);
+                                        const FunctionType::ExtInfo &Info);
 
   /// Retrieves the ABI information for the given function signature.
   /// 
   /// \param ArgTys - must all actually be canonical as params
   const CGFunctionInfo &getFunctionInfo(CanQualType RetTy,
                                const llvm::SmallVectorImpl<CanQualType> &ArgTys,
-                                        CallingConv CC,
-                                        bool NoReturn);
+                                        const FunctionType::ExtInfo &Info);
 
 public:  // These are internal details of CGT that shouldn't be used externally.
   /// addFieldInfo - Assign field number to field FD.