]> granicus.if.org Git - clang/commitdiff
More ABI API cleanup.
authorDaniel Dunbar <daniel@zuster.org>
Mon, 2 Feb 2009 22:03:45 +0000 (22:03 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 2 Feb 2009 22:03:45 +0000 (22:03 +0000)
 - Lift CGFunctionInfo creation above ReturnTypeUsesSret and
   EmitFunction{Epi,Pro}log.

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

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

index a592ace68a13856bad13e9856fbf16eed4d6fda0..c7b2a5dc895f9fbe34546e1042bd3cd92fb15350 100644 (file)
@@ -935,8 +935,8 @@ static void CreateCoercedStore(llvm::Value *Src,
 
 /***/
 
-bool CodeGenModule::ReturnTypeUsesSret(QualType RetTy) {
-  return getABIReturnInfo(RetTy, getTypes()).isStructRet();
+bool CodeGenModule::ReturnTypeUsesSret(const CGFunctionInfo &FI) {
+  return getABIReturnInfo(FI.getReturnType(), getTypes()).isStructRet();
 }
 
 const llvm::FunctionType *
@@ -1008,8 +1008,8 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI, bool IsVariadic) {
   return llvm::FunctionType::get(ResultType, ArgTys, IsVariadic);
 }
 
-void CodeGenModule::ConstructAttributeList(const Decl *TargetDecl,
-                                           const CGFunctionInfo &Info,
+void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &Info,
+                                           const Decl *TargetDecl,
                                            AttributeListType &PAL) {
   unsigned FuncAttrs = 0;
   unsigned RetAttrs = 0;
@@ -1107,16 +1107,14 @@ void CodeGenModule::ConstructAttributeList(const Decl *TargetDecl,
 
 }
 
-void CodeGenFunction::EmitFunctionProlog(llvm::Function *Fn,
-                                         QualType RetTy, 
+void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
+                                         llvm::Function *Fn,
                                          const FunctionArgList &Args) {
-  CGFunctionInfo FnInfo(RetTy, Args);
-
   // Emit allocs for param decls.  Give the LLVM Argument nodes names.
   llvm::Function::arg_iterator AI = Fn->arg_begin();
   
   // Name the struct return argument.
-  if (CGM.ReturnTypeUsesSret(RetTy)) {
+  if (CGM.ReturnTypeUsesSret(FI)) {
     AI->setName("agg.result");
     ++AI;
   }
@@ -1173,12 +1171,13 @@ void CodeGenFunction::EmitFunctionProlog(llvm::Function *Fn,
   assert(AI == Fn->arg_end() && "Argument mismatch!");
 }
 
-void CodeGenFunction::EmitFunctionEpilog(QualType RetTy, 
+void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
                                          llvm::Value *ReturnValue) {
   llvm::Value *RV = 0;
 
   // Functions with no result always return void.
   if (ReturnValue) { 
+    QualType RetTy = FI.getReturnType();
     ABIArgInfo RetAI = getABIReturnInfo(RetTy, CGM.getTypes());
     
     switch (RetAI.getKind()) {
@@ -1220,8 +1219,8 @@ void CodeGenFunction::EmitFunctionEpilog(QualType RetTy,
   }
 }
 
-RValue CodeGenFunction::EmitCall(llvm::Value *Callee, 
-                                 const CGFunctionInfo &CallInfo,
+RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
+                                 llvm::Value *Callee, 
                                  const CallArgList &CallArgs) {
   llvm::SmallVector<llvm::Value*, 16> Args;
 
@@ -1282,7 +1281,7 @@ RValue CodeGenFunction::EmitCall(llvm::Value *Callee,
 
   // FIXME: Provide TargetDecl so nounwind, noreturn, etc, etc get set.
   CodeGen::AttributeListType AttributeList;
-  CGM.ConstructAttributeList(0, CallInfo, AttributeList);
+  CGM.ConstructAttributeList(CallInfo, 0, AttributeList);
   CI->setAttributes(llvm::AttrListPtr::get(AttributeList.begin(), 
                                            AttributeList.size()));  
   
index 0e13a8ddcd6ddefa3be3a9c767ce5ba71045fa30..5ed215164b7e72731662ec01030dcab9c1458616 100644 (file)
@@ -1102,5 +1102,5 @@ RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType CalleeType,
     Args.push_back(std::make_pair(EmitAnyExprToTemp(*I), 
                                   I->getType()));
 
-  return EmitCall(Callee, CGFunctionInfo(ResultType, Args), Args);
+  return EmitCall(CGFunctionInfo(ResultType, Args), Callee, Args);
 }
index 0c0b2510e9ebf704eb8f8562b049828cc2e7013f..cf37886e6d37bcf5a7c0edb282baa65ce52930cc 100644 (file)
@@ -183,8 +183,8 @@ 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(GetPropertyFn, CGFunctionInfo(PD->getType(), Args), 
-                         Args);
+    RValue RV = EmitCall(CGFunctionInfo(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
     // aggregates.
@@ -268,7 +268,7 @@ void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP,
                                   getContext().BoolTy));
     Args.push_back(std::make_pair(RValue::get(IsCopy ? True : False), 
                                   getContext().BoolTy));
-    EmitCall(SetPropertyFn, CGFunctionInfo(PD->getType(), Args), Args);
+    EmitCall(CGFunctionInfo(PD->getType(), Args), SetPropertyFn, Args);
   } else {
     SourceLocation Loc = PD->getLocation();
     ValueDecl *Self = OMD->getSelfDecl();
index 6eca3f127196c0014a2a55710d70bf5e55b37f99..e6ae6f36b4e131aa541d7a8127b154abec1242fa 100644 (file)
@@ -311,7 +311,7 @@ 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(imp, CGFunctionInfo(ResultType, ActualArgs), ActualArgs);
+  return CGF.EmitCall(CGFunctionInfo(ResultType, ActualArgs), imp, ActualArgs);
 }
 
 /// Generate code for a message send expression.  
@@ -358,7 +358,7 @@ 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(imp, CGFunctionInfo(ResultType, ActualArgs), ActualArgs);
+  return CGF.EmitCall(CGFunctionInfo(ResultType, ActualArgs), imp, ActualArgs);
 }
 
 /// Generates a MethodList.  Used in construction of a objc_class and 
index 6bc03fe08590102286086cf95d894a696181a260..d8e873b845927485b7065e4bf5d0e2590a64aadc 100644 (file)
@@ -810,7 +810,7 @@ CodeGen::RValue CGObjCMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF,
   const llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FnInfo, false);
 
   llvm::Constant *Fn;
-  if (CGM.ReturnTypeUsesSret(ResultType)) {
+  if (CGM.ReturnTypeUsesSret(FnInfo)) {
     Fn = ObjCTypes.getSendStretFn(IsSuper);
   } else if (ResultType->isFloatingType()) {
     // FIXME: Sadly, this is wrong. This actually depends on the
@@ -820,7 +820,7 @@ CodeGen::RValue CGObjCMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF,
     Fn = ObjCTypes.getSendFn(IsSuper);
   }
   Fn = llvm::ConstantExpr::getBitCast(Fn, llvm::PointerType::getUnqual(FTy));
-  return CGF.EmitCall(Fn, FnInfo, ActualArgs);
+  return CGF.EmitCall(FnInfo, Fn, ActualArgs);
 }
 
 llvm::Value *CGObjCMac::GenerateProtocolRef(CGBuilderTy &Builder, 
index 5d34f65fc14dce36a4cf051cfca30b1294646cf9..fe28b3aeccdd25c9775434657f6f76c083433334 100644 (file)
@@ -125,7 +125,7 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
     DI->EmitRegionEnd(CurFn, Builder);
   }
 
-  EmitFunctionEpilog(FnRetTy, ReturnValue);
+  EmitFunctionEpilog(*CurFnInfo, ReturnValue);
 
   // Remove the AllocaInsertPt instruction, which is just a convenience for us.
   AllocaInsertPt->eraseFromParent();
@@ -171,7 +171,9 @@ void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy,
     }
   }
 
-  EmitFunctionProlog(CurFn, FnRetTy, Args);
+  // FIXME: Leaked.
+  CurFnInfo = new CGFunctionInfo(FnRetTy, Args);
+  EmitFunctionProlog(*CurFnInfo, CurFn, Args);
   
   // If any of the arguments have a variably modified type, make sure to
   // emit the type size.
index 1bacff2480bfdd30b3e5c3a3e2d785d8adda826d..9033a65be26bc14e02f2fd8f8bd6ce3c98227b8a 100644 (file)
@@ -70,6 +70,7 @@ public:
   
   // Holds the Decl for the current function or method
   const Decl *CurFuncDecl;
+  const CGFunctionInfo *CurFnInfo;
   QualType FnRetTy;
   llvm::Function *CurFn;
 
@@ -219,13 +220,13 @@ public:
   /// EmitFunctionProlog - Emit the target specific LLVM code to load
   /// the arguments for the given function. This is also responsible
   /// for naming the LLVM function arguments.
-  void EmitFunctionProlog(llvm::Function *Fn, QualType RetTy, 
+  void EmitFunctionProlog(const CGFunctionInfo &FI,
+                          llvm::Function *Fn,
                           const FunctionArgList &Args);
 
   /// EmitFunctionEpilog - Emit the target specific LLVM code to
   /// return the given temporary.
-  void EmitFunctionEpilog(QualType RetTy, 
-                          llvm::Value *ReturnValue);
+  void EmitFunctionEpilog(const CGFunctionInfo &FI, llvm::Value *ReturnValue);
 
   const llvm::Type *ConvertType(QualType T);
 
@@ -543,8 +544,8 @@ public:
   /// given result type, and using the given argument list which
   /// specifies both the LLVM arguments and the types they were
   /// derived from.
-  RValue EmitCall(llvm::Value *Callee,
-                  const CGFunctionInfo &FnInfo,
+  RValue EmitCall(const CGFunctionInfo &FnInfo,
+                  llvm::Value *Callee,
                   const CallArgList &Args);
 
   RValue EmitCallExpr(const CallExpr *E);
index bdb99d6439b7fe21f151b7486ba557788ab98fd1..d02812ac5d9ce5f8fa80dc6966b25f5cfac46f6d 100644 (file)
@@ -265,7 +265,7 @@ void CodeGenModule::SetFunctionAttributes(const Decl *D,
                                           const CGFunctionInfo &Info, 
                                           llvm::Function *F) {
   AttributeListType AttributeList;
-  ConstructAttributeList(D, Info, AttributeList);
+  ConstructAttributeList(Info, D, AttributeList);
 
   F->setAttributes(llvm::AttrListPtr::get(AttributeList.begin(),
                                         AttributeList.size()));
index 724ca28b886fcefd502fa376583585fd79dc7483..bedefcaa3f9977fefaa68d470e8d12c5dd76a6bb 100644 (file)
@@ -244,10 +244,10 @@ public:
 
   /// ReturnTypeUsesSret - Return true iff the given type uses 'sret'
   /// when used as a return type.
-  bool ReturnTypeUsesSret(QualType RetTy);
+  bool ReturnTypeUsesSret(const CGFunctionInfo &FI);
 
-  void ConstructAttributeList(const Decl *TargetDecl,
-                              const CGFunctionInfo &Info,
+  void ConstructAttributeList(const CGFunctionInfo &Info,
+                              const Decl *TargetDecl,
                               AttributeListType &PAL);
 
 private: