Skip to content

Commit bf8c24a

Browse files
committed
Thread CGFunctionInfo construction through CodeGenTypes.
- Inefficient & leaks memory currently, will be cleaned up subsequently. llvm-svn: 63567
1 parent f126e59 commit bf8c24a

File tree

10 files changed

+83
-48
lines changed

10 files changed

+83
-48
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,50 +31,70 @@ using namespace CodeGen;
3131

3232
// FIXME: Use iterator and sidestep silly type array creation.
3333

34-
CGFunctionInfo::CGFunctionInfo(const FunctionTypeNoProto *FTNP) {
35-
ArgTypes.push_back(FTNP->getResultType());
34+
const
35+
CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionTypeNoProto *FTNP) {
36+
return getFunctionInfo(FTNP->getResultType(),
37+
llvm::SmallVector<QualType, 16>());
3638
}
3739

38-
CGFunctionInfo::CGFunctionInfo(const FunctionTypeProto *FTP) {
39-
ArgTypes.push_back(FTP->getResultType());
40+
const
41+
CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionTypeProto *FTP) {
42+
llvm::SmallVector<QualType, 16> ArgTys;
43+
// FIXME: Kill copy.
4044
for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
41-
ArgTypes.push_back(FTP->getArgType(i));
45+
ArgTys.push_back(FTP->getArgType(i));
46+
return getFunctionInfo(FTP->getResultType(), ArgTys);
4247
}
4348

44-
// FIXME: Is there really any reason to have this still?
45-
CGFunctionInfo::CGFunctionInfo(const FunctionDecl *FD) {
49+
const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionDecl *FD) {
4650
const FunctionType *FTy = FD->getType()->getAsFunctionType();
47-
const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(FTy);
48-
49-
ArgTypes.push_back(FTy->getResultType());
50-
if (FTP) {
51-
for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
52-
ArgTypes.push_back(FTP->getArgType(i));
53-
}
51+
if (const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(FTy))
52+
return getFunctionInfo(FTP);
53+
return getFunctionInfo(cast<FunctionTypeNoProto>(FTy));
5454
}
5555

56-
CGFunctionInfo::CGFunctionInfo(const ObjCMethodDecl *MD,
57-
const ASTContext &Context) {
58-
ArgTypes.push_back(MD->getResultType());
59-
ArgTypes.push_back(MD->getSelfDecl()->getType());
60-
ArgTypes.push_back(Context.getObjCSelType());
56+
const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const ObjCMethodDecl *MD) {
57+
llvm::SmallVector<QualType, 16> ArgTys;
58+
ArgTys.push_back(MD->getSelfDecl()->getType());
59+
ArgTys.push_back(Context.getObjCSelType());
60+
// FIXME: Kill copy?
6161
for (ObjCMethodDecl::param_const_iterator i = MD->param_begin(),
6262
e = MD->param_end(); i != e; ++i)
63-
ArgTypes.push_back((*i)->getType());
63+
ArgTys.push_back((*i)->getType());
64+
return getFunctionInfo(MD->getResultType(), ArgTys);
6465
}
6566

66-
CGFunctionInfo::CGFunctionInfo(QualType ResTy, const CallArgList &Args) {
67-
ArgTypes.push_back(ResTy);
67+
const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy,
68+
const CallArgList &Args) {
69+
// FIXME: Kill copy.
70+
llvm::SmallVector<QualType, 16> ArgTys;
6871
for (CallArgList::const_iterator i = Args.begin(), e = Args.end();
6972
i != e; ++i)
70-
ArgTypes.push_back(i->second);
73+
ArgTys.push_back(i->second);
74+
return getFunctionInfo(ResTy, ArgTys);
7175
}
7276

73-
CGFunctionInfo::CGFunctionInfo(QualType ResTy, const FunctionArgList &Args) {
74-
ArgTypes.push_back(ResTy);
77+
const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy,
78+
const FunctionArgList &Args) {
79+
// FIXME: Kill copy.
80+
llvm::SmallVector<QualType, 16> ArgTys;
7581
for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
7682
i != e; ++i)
77-
ArgTypes.push_back(i->second);
83+
ArgTys.push_back(i->second);
84+
return getFunctionInfo(ResTy, ArgTys);
85+
}
86+
87+
const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy,
88+
const llvm::SmallVector<QualType, 16> &ArgTys) {
89+
return *new CGFunctionInfo(ResTy, ArgTys);
90+
}
91+
92+
/***/
93+
94+
CGFunctionInfo::CGFunctionInfo(QualType ResTy,
95+
const llvm::SmallVector<QualType, 16> &ArgTys) {
96+
ArgTypes.push_back(ResTy);
97+
ArgTypes.insert(ArgTypes.end(), ArgTys.begin(), ArgTys.end());
7898
}
7999

80100
ArgTypeIterator CGFunctionInfo::argtypes_begin() const {

clang/lib/CodeGen/CGCall.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ namespace CodeGen {
5757
llvm::SmallVector<QualType, 16> ArgTypes;
5858

5959
public:
60-
CGFunctionInfo(const FunctionTypeNoProto *FTNP);
61-
CGFunctionInfo(const FunctionTypeProto *FTP);
62-
CGFunctionInfo(const FunctionDecl *FD);
63-
CGFunctionInfo(const ObjCMethodDecl *MD, const ASTContext &Context);
64-
CGFunctionInfo(QualType ResTy, const CallArgList &Args);
65-
CGFunctionInfo(QualType ResTy, const FunctionArgList &Args);
60+
CGFunctionInfo(QualType ResTy,
61+
const llvm::SmallVector<QualType, 16> &ArgTys);
6662

6763
ArgTypeIterator argtypes_begin() const;
6864
ArgTypeIterator argtypes_end() const;

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,5 +1102,6 @@ RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType CalleeType,
11021102
Args.push_back(std::make_pair(EmitAnyExprToTemp(*I),
11031103
I->getType()));
11041104

1105-
return EmitCall(CGFunctionInfo(ResultType, Args), Callee, Args);
1105+
return EmitCall(CGM.getTypes().getFunctionInfo(ResultType, Args),
1106+
Callee, Args);
11061107
}

clang/lib/CodeGen/CGObjC.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void CodeGenFunction::GenerateObjCGetter(ObjCImplementationDecl *IMP,
183183
Args.push_back(std::make_pair(RValue::get(CmdVal), Cmd->getType()));
184184
Args.push_back(std::make_pair(RValue::get(Offset), getContext().LongTy));
185185
Args.push_back(std::make_pair(RValue::get(True), getContext().BoolTy));
186-
RValue RV = EmitCall(CGFunctionInfo(PD->getType(), Args),
186+
RValue RV = EmitCall(Types.getFunctionInfo(PD->getType(), Args),
187187
GetPropertyFn, Args);
188188
// We need to fix the type here. Ivars with copy & retain are
189189
// always objects so we don't need to worry about complex or
@@ -268,7 +268,8 @@ void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP,
268268
getContext().BoolTy));
269269
Args.push_back(std::make_pair(RValue::get(IsCopy ? True : False),
270270
getContext().BoolTy));
271-
EmitCall(CGFunctionInfo(PD->getType(), Args), SetPropertyFn, Args);
271+
EmitCall(Types.getFunctionInfo(PD->getType(), Args),
272+
SetPropertyFn, Args);
272273
} else {
273274
SourceLocation Loc = PD->getLocation();
274275
ValueDecl *Self = OMD->getSelfDecl();

clang/lib/CodeGen/CGObjCGNU.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ CGObjCGNU::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF,
311311
ActualArgs.push_back(std::make_pair(RValue::get(cmd),
312312
CGF.getContext().getObjCSelType()));
313313
ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
314-
return CGF.EmitCall(CGFunctionInfo(ResultType, ActualArgs), imp, ActualArgs);
314+
return CGF.EmitCall(CGM.getTypes().getFunctionInfo(ResultType, ActualArgs),
315+
imp, ActualArgs);
315316
}
316317

317318
/// Generate code for a message send expression.
@@ -358,7 +359,8 @@ CGObjCGNU::GenerateMessageSend(CodeGen::CodeGenFunction &CGF,
358359
ActualArgs.push_back(std::make_pair(RValue::get(cmd),
359360
CGF.getContext().getObjCSelType()));
360361
ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
361-
return CGF.EmitCall(CGFunctionInfo(ResultType, ActualArgs), imp, ActualArgs);
362+
return CGF.EmitCall(CGM.getTypes().getFunctionInfo(ResultType, ActualArgs),
363+
imp, ActualArgs);
362364
}
363365

364366
/// Generates a MethodList. Used in construction of a objc_class and
@@ -969,9 +971,9 @@ llvm::Function *CGObjCGNU::GenerateMethod(const ObjCMethodDecl *OMD,
969971
std::string MethodName = OMD->getSelector().getAsString();
970972
bool isClassMethod = !OMD->isInstanceMethod();
971973

974+
CodeGenTypes &Types = CGM.getTypes();
972975
const llvm::FunctionType *MethodTy =
973-
CGM.getTypes().GetFunctionType(CGFunctionInfo(OMD, CGM.getContext()),
974-
OMD->isVariadic());
976+
Types.GetFunctionType(Types.getFunctionInfo(OMD), OMD->isVariadic());
975977
std::string FunctionName = SymbolNameForMethod(ClassName, CategoryName,
976978
MethodName, isClassMethod);
977979

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,9 @@ CodeGen::RValue CGObjCMac::EmitMessageSend(CodeGen::CodeGenFunction &CGF,
806806
CGF.getContext().getObjCSelType()));
807807
ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end());
808808

809-
CGFunctionInfo FnInfo(ResultType, ActualArgs);
810-
const llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FnInfo, false);
809+
CodeGenTypes &Types = CGM.getTypes();
810+
const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, ActualArgs);
811+
const llvm::FunctionType *FTy = Types.GetFunctionType(FnInfo, false);
811812

812813
llvm::Constant *Fn;
813814
if (CGM.ReturnTypeUsesSret(FnInfo)) {
@@ -1668,9 +1669,9 @@ llvm::Function *CGObjCCommonMac::GenerateMethod(const ObjCMethodDecl *OMD,
16681669
std::string Name;
16691670
GetNameForMethod(OMD, CD, Name);
16701671

1672+
CodeGenTypes &Types = CGM.getTypes();
16711673
const llvm::FunctionType *MethodTy =
1672-
CGM.getTypes().GetFunctionType(CGFunctionInfo(OMD, CGM.getContext()),
1673-
OMD->isVariadic());
1674+
Types.GetFunctionType(Types.getFunctionInfo(OMD), OMD->isVariadic());
16741675
llvm::Function *Method =
16751676
llvm::Function::Create(MethodTy,
16761677
llvm::GlobalValue::InternalLinkage,

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy,
172172
}
173173

174174
// FIXME: Leaked.
175-
CurFnInfo = new CGFunctionInfo(FnRetTy, Args);
175+
CurFnInfo = &CGM.getTypes().getFunctionInfo(FnRetTy, Args);
176176
EmitFunctionProlog(*CurFnInfo, CurFn, Args);
177177

178178
// If any of the arguments have a variably modified type, make sure to

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,14 @@ void CodeGenModule::SetFunctionAttributesForDefinition(const Decl *D,
299299

300300
void CodeGenModule::SetMethodAttributes(const ObjCMethodDecl *MD,
301301
llvm::Function *F) {
302-
SetFunctionAttributes(MD, CGFunctionInfo(MD, Context), F);
302+
SetFunctionAttributes(MD, getTypes().getFunctionInfo(MD), F);
303303

304304
SetFunctionAttributesForDefinition(MD, F);
305305
}
306306

307307
void CodeGenModule::SetFunctionAttributes(const FunctionDecl *FD,
308308
llvm::Function *F) {
309-
SetFunctionAttributes(FD, CGFunctionInfo(FD), F);
309+
SetFunctionAttributes(FD, getTypes().getFunctionInfo(FD), F);
310310

311311
SetGlobalValueAttributes(FD, FD->getStorageClass() == FunctionDecl::Static,
312312
FD->isInline(), F, false);

clang/lib/CodeGen/CodeGenTypes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
256256
VT.getNumElements());
257257
}
258258
case Type::FunctionNoProto:
259-
return GetFunctionType(CGFunctionInfo(cast<FunctionTypeNoProto>(&Ty)),
259+
return GetFunctionType(getFunctionInfo(cast<FunctionTypeNoProto>(&Ty)),
260260
true);
261261
case Type::FunctionProto: {
262262
const FunctionTypeProto *FTP = cast<FunctionTypeProto>(&Ty);
263-
return GetFunctionType(CGFunctionInfo(FTP), FTP->isVariadic());
263+
return GetFunctionType(getFunctionInfo(FTP), FTP->isVariadic());
264264
}
265265

266266
case Type::ASQual:

clang/lib/CodeGen/CodeGenTypes.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ class CodeGenTypes {
158158
/// UpdateCompletedType - When we find the full definition for a TagDecl,
159159
/// replace the 'opaque' type we previously made for it if applicable.
160160
void UpdateCompletedType(const TagDecl *TD);
161+
162+
/// getFunctionInfo - Get the CGFunctionInfo for this function signature.
163+
const CGFunctionInfo &getFunctionInfo(QualType RetTy,
164+
const llvm::SmallVector<QualType,16>
165+
&ArgTys);
166+
167+
const CGFunctionInfo &getFunctionInfo(const FunctionTypeNoProto *FTNP);
168+
const CGFunctionInfo &getFunctionInfo(const FunctionTypeProto *FTP);
169+
const CGFunctionInfo &getFunctionInfo(const FunctionDecl *FD);
170+
const CGFunctionInfo &getFunctionInfo(const ObjCMethodDecl *MD);
171+
const CGFunctionInfo &getFunctionInfo(QualType ResTy,
172+
const CallArgList &Args);
173+
const CGFunctionInfo &getFunctionInfo(QualType ResTy,
174+
const FunctionArgList &Args);
161175

162176
public: // These are internal details of CGT that shouldn't be used externally.
163177
/// addFieldInfo - Assign field number to field FD.

0 commit comments

Comments
 (0)