More ABI API cleanup.
- 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
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index a592ace..c7b2a5d 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -935,8 +935,8 @@
/***/
-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 @@
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 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 @@
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 @@
}
}
-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 @@
// 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()));
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 0e13a8d..5ed2151 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -1102,5 +1102,5 @@
Args.push_back(std::make_pair(EmitAnyExprToTemp(*I),
I->getType()));
- return EmitCall(Callee, CGFunctionInfo(ResultType, Args), Args);
+ return EmitCall(CGFunctionInfo(ResultType, Args), Callee, Args);
}
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index 0c0b251..cf37886 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -183,8 +183,8 @@
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 @@
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();
diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp
index 6eca3f1..e6ae6f3 100644
--- a/lib/CodeGen/CGObjCGNU.cpp
+++ b/lib/CodeGen/CGObjCGNU.cpp
@@ -311,7 +311,7 @@
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 @@
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
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index 6bc03fe..d8e873b 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -810,7 +810,7 @@
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 @@
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,
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index 5d34f65..fe28b3a 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -125,7 +125,7 @@
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 @@
}
}
- 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.
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index 1bacff2..9033a65 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -70,6 +70,7 @@
// Holds the Decl for the current function or method
const Decl *CurFuncDecl;
+ const CGFunctionInfo *CurFnInfo;
QualType FnRetTy;
llvm::Function *CurFn;
@@ -219,13 +220,13 @@
/// 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 @@
/// 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);
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index bdb99d6..d02812a 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -265,7 +265,7 @@
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()));
diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h
index 724ca28..bedefca 100644
--- a/lib/CodeGen/CodeGenModule.h
+++ b/lib/CodeGen/CodeGenModule.h
@@ -244,10 +244,10 @@
/// 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: