// 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 {
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;
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);
}
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
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();
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.
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
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);
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)) {
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,
}
// 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
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);
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:
/// 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.