blob: 16f4e7b533421cdd1e0071b2f48291c535e4eb57 [file] [log] [blame]
Daniel Dunbar0dbe2272008-09-08 21:33:45 +00001//===----- CGCall.h - Encapsulate calling convention details ----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// These classes wrap the information about a call or function
11// definition used to handle ABI compliancy.
12//
13//===----------------------------------------------------------------------===//
14
15#include "CGCall.h"
16#include "CodeGenFunction.h"
Daniel Dunbarb7688072008-09-10 00:41:16 +000017#include "CodeGenModule.h"
Daniel Dunbar6b1da0e2008-10-13 17:02:26 +000018#include "clang/Basic/TargetInfo.h"
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000019#include "clang/AST/Decl.h"
Anders Carlssonf6f8ae52009-04-03 22:48:58 +000020#include "clang/AST/DeclCXX.h"
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000021#include "clang/AST/DeclObjC.h"
Chandler Carruth2811ccf2009-11-12 17:24:48 +000022#include "clang/CodeGen/CodeGenOptions.h"
Devang Pateld0646bd2008-09-24 01:01:36 +000023#include "llvm/Attributes.h"
Daniel Dunbard14151d2009-03-02 04:32:35 +000024#include "llvm/Support/CallSite.h"
Daniel Dunbar54d1ccb2009-01-27 01:36:03 +000025#include "llvm/Target/TargetData.h"
Daniel Dunbar9eb5c6d2009-02-03 01:05:53 +000026
27#include "ABIInfo.h"
28
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000029using namespace clang;
30using namespace CodeGen;
31
32/***/
33
Daniel Dunbar0dbe2272008-09-08 21:33:45 +000034// FIXME: Use iterator and sidestep silly type array creation.
35
Mike Stump1eb44332009-09-09 15:08:12 +000036const
Douglas Gregor72564e72009-02-26 23:50:07 +000037CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionNoProtoType *FTNP) {
Daniel Dunbarbac7c252009-09-11 22:24:53 +000038 // FIXME: Set calling convention correctly, it needs to be associated with the
39 // type somehow.
Mike Stump1eb44332009-09-09 15:08:12 +000040 return getFunctionInfo(FTNP->getResultType(),
Daniel Dunbarbac7c252009-09-11 22:24:53 +000041 llvm::SmallVector<QualType, 16>(), 0);
Daniel Dunbar45c25ba2008-09-10 04:01:49 +000042}
43
Mike Stump1eb44332009-09-09 15:08:12 +000044const
Douglas Gregor72564e72009-02-26 23:50:07 +000045CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionProtoType *FTP) {
Daniel Dunbar541b63b2009-02-02 23:23:47 +000046 llvm::SmallVector<QualType, 16> ArgTys;
47 // FIXME: Kill copy.
Daniel Dunbar45c25ba2008-09-10 04:01:49 +000048 for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
Daniel Dunbar541b63b2009-02-02 23:23:47 +000049 ArgTys.push_back(FTP->getArgType(i));
Daniel Dunbarbac7c252009-09-11 22:24:53 +000050 // FIXME: Set calling convention correctly, it needs to be associated with the
51 // type somehow.
52 return getFunctionInfo(FTP->getResultType(), ArgTys, 0);
53}
54
55static unsigned getCallingConventionForDecl(const Decl *D) {
56 // Set the appropriate calling convention for the Function.
57 if (D->hasAttr<StdCallAttr>())
58 return llvm::CallingConv::X86_StdCall;
59
60 if (D->hasAttr<FastCallAttr>())
61 return llvm::CallingConv::X86_FastCall;
62
63 return llvm::CallingConv::C;
Daniel Dunbar45c25ba2008-09-10 04:01:49 +000064}
65
Anders Carlsson375c31c2009-10-03 19:43:08 +000066const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const CXXRecordDecl *RD,
67 const FunctionProtoType *FTP) {
68 llvm::SmallVector<QualType, 16> ArgTys;
69
70 // Add the 'this' pointer.
71 ArgTys.push_back(Context.getPointerType(Context.getTagDeclType(RD)));
72
73 for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
74 ArgTys.push_back(FTP->getArgType(i));
75
76 // FIXME: Set calling convention correctly, it needs to be associated with the
77 // type somehow.
78 return getFunctionInfo(FTP->getResultType(), ArgTys, 0);
79}
80
Anders Carlssonf6f8ae52009-04-03 22:48:58 +000081const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const CXXMethodDecl *MD) {
82 llvm::SmallVector<QualType, 16> ArgTys;
Chris Lattner3eb67ca2009-05-12 20:27:19 +000083 // Add the 'this' pointer unless this is a static method.
84 if (MD->isInstance())
85 ArgTys.push_back(MD->getThisType(Context));
Mike Stump1eb44332009-09-09 15:08:12 +000086
John McCall183700f2009-09-21 23:43:11 +000087 const FunctionProtoType *FTP = MD->getType()->getAs<FunctionProtoType>();
Anders Carlssonf6f8ae52009-04-03 22:48:58 +000088 for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
89 ArgTys.push_back(FTP->getArgType(i));
Daniel Dunbarbac7c252009-09-11 22:24:53 +000090 return getFunctionInfo(FTP->getResultType(), ArgTys,
91 getCallingConventionForDecl(MD));
Anders Carlssonf6f8ae52009-04-03 22:48:58 +000092}
93
Daniel Dunbar541b63b2009-02-02 23:23:47 +000094const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionDecl *FD) {
Chris Lattner3eb67ca2009-05-12 20:27:19 +000095 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
Anders Carlssonf6f8ae52009-04-03 22:48:58 +000096 if (MD->isInstance())
97 return getFunctionInfo(MD);
Mike Stump1eb44332009-09-09 15:08:12 +000098
Daniel Dunbarbac7c252009-09-11 22:24:53 +000099 unsigned CallingConvention = getCallingConventionForDecl(FD);
John McCall183700f2009-09-21 23:43:11 +0000100 const FunctionType *FTy = FD->getType()->getAs<FunctionType>();
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000101 if (const FunctionNoProtoType *FNTP = dyn_cast<FunctionNoProtoType>(FTy))
102 return getFunctionInfo(FNTP->getResultType(),
103 llvm::SmallVector<QualType, 16>(),
104 CallingConvention);
105
106 const FunctionProtoType *FPT = cast<FunctionProtoType>(FTy);
107 llvm::SmallVector<QualType, 16> ArgTys;
108 // FIXME: Kill copy.
109 for (unsigned i = 0, e = FPT->getNumArgs(); i != e; ++i)
110 ArgTys.push_back(FPT->getArgType(i));
111 return getFunctionInfo(FPT->getResultType(), ArgTys, CallingConvention);
Daniel Dunbar0dbe2272008-09-08 21:33:45 +0000112}
113
Daniel Dunbar541b63b2009-02-02 23:23:47 +0000114const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const ObjCMethodDecl *MD) {
115 llvm::SmallVector<QualType, 16> ArgTys;
116 ArgTys.push_back(MD->getSelfDecl()->getType());
117 ArgTys.push_back(Context.getObjCSelType());
118 // FIXME: Kill copy?
Chris Lattner20732162009-02-20 06:23:21 +0000119 for (ObjCMethodDecl::param_iterator i = MD->param_begin(),
Daniel Dunbar0dbe2272008-09-08 21:33:45 +0000120 e = MD->param_end(); i != e; ++i)
Daniel Dunbar541b63b2009-02-02 23:23:47 +0000121 ArgTys.push_back((*i)->getType());
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000122 return getFunctionInfo(MD->getResultType(), ArgTys,
123 getCallingConventionForDecl(MD));
Daniel Dunbar0dbe2272008-09-08 21:33:45 +0000124}
125
Mike Stump1eb44332009-09-09 15:08:12 +0000126const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy,
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000127 const CallArgList &Args,
128 unsigned CallingConvention){
Daniel Dunbar541b63b2009-02-02 23:23:47 +0000129 // FIXME: Kill copy.
130 llvm::SmallVector<QualType, 16> ArgTys;
Mike Stump1eb44332009-09-09 15:08:12 +0000131 for (CallArgList::const_iterator i = Args.begin(), e = Args.end();
Daniel Dunbar725ad312009-01-31 02:19:00 +0000132 i != e; ++i)
Daniel Dunbar541b63b2009-02-02 23:23:47 +0000133 ArgTys.push_back(i->second);
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000134 return getFunctionInfo(ResTy, ArgTys, CallingConvention);
Daniel Dunbar725ad312009-01-31 02:19:00 +0000135}
136
Mike Stump1eb44332009-09-09 15:08:12 +0000137const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy,
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000138 const FunctionArgList &Args,
139 unsigned CallingConvention){
Daniel Dunbar541b63b2009-02-02 23:23:47 +0000140 // FIXME: Kill copy.
141 llvm::SmallVector<QualType, 16> ArgTys;
Mike Stump1eb44332009-09-09 15:08:12 +0000142 for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
Daniel Dunbarbb36d332009-02-02 21:43:58 +0000143 i != e; ++i)
Daniel Dunbar541b63b2009-02-02 23:23:47 +0000144 ArgTys.push_back(i->second);
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000145 return getFunctionInfo(ResTy, ArgTys, CallingConvention);
Daniel Dunbar541b63b2009-02-02 23:23:47 +0000146}
147
148const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy,
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000149 const llvm::SmallVector<QualType, 16> &ArgTys,
150 unsigned CallingConvention){
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000151 // Lookup or create unique function info.
152 llvm::FoldingSetNodeID ID;
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000153 CGFunctionInfo::Profile(ID, CallingConvention, ResTy,
154 ArgTys.begin(), ArgTys.end());
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000155
156 void *InsertPos = 0;
157 CGFunctionInfo *FI = FunctionInfos.FindNodeOrInsertPos(ID, InsertPos);
158 if (FI)
159 return *FI;
160
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000161 // Construct the function info.
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000162 FI = new CGFunctionInfo(CallingConvention, ResTy, ArgTys);
Daniel Dunbar35e67d42009-02-05 00:00:23 +0000163 FunctionInfos.InsertNode(FI, InsertPos);
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000164
165 // Compute ABI information.
Owen Andersona1cf15f2009-07-14 23:10:40 +0000166 getABIInfo().computeInfo(*FI, getContext(), TheModule.getContext());
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000167
Daniel Dunbar40a6be62009-02-03 00:07:12 +0000168 return *FI;
Daniel Dunbar541b63b2009-02-02 23:23:47 +0000169}
170
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000171CGFunctionInfo::CGFunctionInfo(unsigned _CallingConvention,
172 QualType ResTy,
173 const llvm::SmallVector<QualType, 16> &ArgTys)
Daniel Dunbarca6408c2009-09-12 00:59:20 +0000174 : CallingConvention(_CallingConvention),
175 EffectiveCallingConvention(_CallingConvention)
Daniel Dunbarbac7c252009-09-11 22:24:53 +0000176{
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000177 NumArgs = ArgTys.size();
178 Args = new ArgInfo[1 + NumArgs];
179 Args[0].type = ResTy;
180 for (unsigned i = 0; i < NumArgs; ++i)
181 Args[1 + i].type = ArgTys[i];
182}
183
184/***/
185
Mike Stump1eb44332009-09-09 15:08:12 +0000186void CodeGenTypes::GetExpandedTypes(QualType Ty,
Daniel Dunbar56273772008-09-17 00:51:38 +0000187 std::vector<const llvm::Type*> &ArgTys) {
188 const RecordType *RT = Ty->getAsStructureType();
189 assert(RT && "Can only expand structure types.");
190 const RecordDecl *RD = RT->getDecl();
Mike Stump1eb44332009-09-09 15:08:12 +0000191 assert(!RD->hasFlexibleArrayMember() &&
Daniel Dunbar56273772008-09-17 00:51:38 +0000192 "Cannot expand structure with flexible array.");
Mike Stump1eb44332009-09-09 15:08:12 +0000193
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000194 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
195 i != e; ++i) {
Daniel Dunbar56273772008-09-17 00:51:38 +0000196 const FieldDecl *FD = *i;
Mike Stump1eb44332009-09-09 15:08:12 +0000197 assert(!FD->isBitField() &&
Daniel Dunbar56273772008-09-17 00:51:38 +0000198 "Cannot expand structure with bit-field members.");
Mike Stump1eb44332009-09-09 15:08:12 +0000199
Daniel Dunbar56273772008-09-17 00:51:38 +0000200 QualType FT = FD->getType();
201 if (CodeGenFunction::hasAggregateLLVMType(FT)) {
202 GetExpandedTypes(FT, ArgTys);
203 } else {
204 ArgTys.push_back(ConvertType(FT));
205 }
206 }
207}
208
Mike Stump1eb44332009-09-09 15:08:12 +0000209llvm::Function::arg_iterator
Daniel Dunbar56273772008-09-17 00:51:38 +0000210CodeGenFunction::ExpandTypeFromArgs(QualType Ty, LValue LV,
211 llvm::Function::arg_iterator AI) {
212 const RecordType *RT = Ty->getAsStructureType();
213 assert(RT && "Can only expand structure types.");
214
215 RecordDecl *RD = RT->getDecl();
Mike Stump1eb44332009-09-09 15:08:12 +0000216 assert(LV.isSimple() &&
217 "Unexpected non-simple lvalue during struct expansion.");
Daniel Dunbar56273772008-09-17 00:51:38 +0000218 llvm::Value *Addr = LV.getAddress();
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000219 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
220 i != e; ++i) {
Mike Stump1eb44332009-09-09 15:08:12 +0000221 FieldDecl *FD = *i;
Daniel Dunbar56273772008-09-17 00:51:38 +0000222 QualType FT = FD->getType();
223
224 // FIXME: What are the right qualifiers here?
225 LValue LV = EmitLValueForField(Addr, FD, false, 0);
226 if (CodeGenFunction::hasAggregateLLVMType(FT)) {
227 AI = ExpandTypeFromArgs(FT, LV, AI);
228 } else {
229 EmitStoreThroughLValue(RValue::get(AI), LV, FT);
230 ++AI;
231 }
232 }
233
234 return AI;
235}
236
Mike Stump1eb44332009-09-09 15:08:12 +0000237void
238CodeGenFunction::ExpandTypeToArgs(QualType Ty, RValue RV,
Daniel Dunbar56273772008-09-17 00:51:38 +0000239 llvm::SmallVector<llvm::Value*, 16> &Args) {
240 const RecordType *RT = Ty->getAsStructureType();
241 assert(RT && "Can only expand structure types.");
242
243 RecordDecl *RD = RT->getDecl();
244 assert(RV.isAggregate() && "Unexpected rvalue during struct expansion");
245 llvm::Value *Addr = RV.getAggregateAddr();
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000246 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
247 i != e; ++i) {
Mike Stump1eb44332009-09-09 15:08:12 +0000248 FieldDecl *FD = *i;
Daniel Dunbar56273772008-09-17 00:51:38 +0000249 QualType FT = FD->getType();
Mike Stump1eb44332009-09-09 15:08:12 +0000250
Daniel Dunbar56273772008-09-17 00:51:38 +0000251 // FIXME: What are the right qualifiers here?
252 LValue LV = EmitLValueForField(Addr, FD, false, 0);
253 if (CodeGenFunction::hasAggregateLLVMType(FT)) {
254 ExpandTypeToArgs(FT, RValue::getAggregate(LV.getAddress()), Args);
255 } else {
256 RValue RV = EmitLoadOfLValue(LV, FT);
Mike Stump1eb44332009-09-09 15:08:12 +0000257 assert(RV.isScalar() &&
Daniel Dunbar56273772008-09-17 00:51:38 +0000258 "Unexpected non-scalar rvalue during struct expansion.");
259 Args.push_back(RV.getScalarVal());
260 }
261 }
262}
263
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000264/// CreateCoercedLoad - Create a load from \arg SrcPtr interpreted as
265/// a pointer to an object of type \arg Ty.
266///
267/// This safely handles the case when the src type is smaller than the
268/// destination type; in this situation the values of bits which not
269/// present in the src are undefined.
270static llvm::Value *CreateCoercedLoad(llvm::Value *SrcPtr,
271 const llvm::Type *Ty,
272 CodeGenFunction &CGF) {
Mike Stump1eb44332009-09-09 15:08:12 +0000273 const llvm::Type *SrcTy =
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000274 cast<llvm::PointerType>(SrcPtr->getType())->getElementType();
Duncan Sands9408c452009-05-09 07:08:47 +0000275 uint64_t SrcSize = CGF.CGM.getTargetData().getTypeAllocSize(SrcTy);
276 uint64_t DstSize = CGF.CGM.getTargetData().getTypeAllocSize(Ty);
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000277
Daniel Dunbarb225be42009-02-03 05:59:18 +0000278 // If load is legal, just bitcast the src pointer.
Daniel Dunbar7ef455b2009-05-13 18:54:26 +0000279 if (SrcSize >= DstSize) {
Mike Stumpf5408fe2009-05-16 07:57:57 +0000280 // Generally SrcSize is never greater than DstSize, since this means we are
281 // losing bits. However, this can happen in cases where the structure has
282 // additional padding, for example due to a user specified alignment.
Daniel Dunbar7ef455b2009-05-13 18:54:26 +0000283 //
Mike Stumpf5408fe2009-05-16 07:57:57 +0000284 // FIXME: Assert that we aren't truncating non-padding bits when have access
285 // to that information.
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000286 llvm::Value *Casted =
287 CGF.Builder.CreateBitCast(SrcPtr, llvm::PointerType::getUnqual(Ty));
Daniel Dunbar386621f2009-02-07 02:46:03 +0000288 llvm::LoadInst *Load = CGF.Builder.CreateLoad(Casted);
289 // FIXME: Use better alignment / avoid requiring aligned load.
290 Load->setAlignment(1);
291 return Load;
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000292 } else {
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000293 // Otherwise do coercion through memory. This is stupid, but
294 // simple.
295 llvm::Value *Tmp = CGF.CreateTempAlloca(Ty);
Mike Stump1eb44332009-09-09 15:08:12 +0000296 llvm::Value *Casted =
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000297 CGF.Builder.CreateBitCast(Tmp, llvm::PointerType::getUnqual(SrcTy));
Mike Stump1eb44332009-09-09 15:08:12 +0000298 llvm::StoreInst *Store =
Daniel Dunbar386621f2009-02-07 02:46:03 +0000299 CGF.Builder.CreateStore(CGF.Builder.CreateLoad(SrcPtr), Casted);
300 // FIXME: Use better alignment / avoid requiring aligned store.
301 Store->setAlignment(1);
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000302 return CGF.Builder.CreateLoad(Tmp);
303 }
304}
305
306/// CreateCoercedStore - Create a store to \arg DstPtr from \arg Src,
307/// where the source and destination may have different types.
308///
309/// This safely handles the case when the src type is larger than the
310/// destination type; the upper bits of the src will be lost.
311static void CreateCoercedStore(llvm::Value *Src,
312 llvm::Value *DstPtr,
313 CodeGenFunction &CGF) {
314 const llvm::Type *SrcTy = Src->getType();
Mike Stump1eb44332009-09-09 15:08:12 +0000315 const llvm::Type *DstTy =
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000316 cast<llvm::PointerType>(DstPtr->getType())->getElementType();
317
Duncan Sands9408c452009-05-09 07:08:47 +0000318 uint64_t SrcSize = CGF.CGM.getTargetData().getTypeAllocSize(SrcTy);
319 uint64_t DstSize = CGF.CGM.getTargetData().getTypeAllocSize(DstTy);
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000320
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000321 // If store is legal, just bitcast the src pointer.
Daniel Dunbarfdf49862009-06-05 07:58:54 +0000322 if (SrcSize <= DstSize) {
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000323 llvm::Value *Casted =
324 CGF.Builder.CreateBitCast(DstPtr, llvm::PointerType::getUnqual(SrcTy));
Daniel Dunbar386621f2009-02-07 02:46:03 +0000325 // FIXME: Use better alignment / avoid requiring aligned store.
326 CGF.Builder.CreateStore(Src, Casted)->setAlignment(1);
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000327 } else {
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000328 // Otherwise do coercion through memory. This is stupid, but
329 // simple.
Daniel Dunbarfdf49862009-06-05 07:58:54 +0000330
331 // Generally SrcSize is never greater than DstSize, since this means we are
332 // losing bits. However, this can happen in cases where the structure has
333 // additional padding, for example due to a user specified alignment.
334 //
335 // FIXME: Assert that we aren't truncating non-padding bits when have access
336 // to that information.
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000337 llvm::Value *Tmp = CGF.CreateTempAlloca(SrcTy);
338 CGF.Builder.CreateStore(Src, Tmp);
Mike Stump1eb44332009-09-09 15:08:12 +0000339 llvm::Value *Casted =
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000340 CGF.Builder.CreateBitCast(Tmp, llvm::PointerType::getUnqual(DstTy));
Daniel Dunbar386621f2009-02-07 02:46:03 +0000341 llvm::LoadInst *Load = CGF.Builder.CreateLoad(Casted);
342 // FIXME: Use better alignment / avoid requiring aligned load.
343 Load->setAlignment(1);
344 CGF.Builder.CreateStore(Load, DstPtr);
Daniel Dunbar275e10d2009-02-02 19:06:38 +0000345 }
346}
347
Daniel Dunbar56273772008-09-17 00:51:38 +0000348/***/
349
Daniel Dunbar88b53962009-02-02 22:03:45 +0000350bool CodeGenModule::ReturnTypeUsesSret(const CGFunctionInfo &FI) {
Daniel Dunbar11e383a2009-02-05 08:00:50 +0000351 return FI.getReturnInfo().isIndirect();
Daniel Dunbarbb36d332009-02-02 21:43:58 +0000352}
353
Daniel Dunbar45c25ba2008-09-10 04:01:49 +0000354const llvm::FunctionType *
Daniel Dunbarbb36d332009-02-02 21:43:58 +0000355CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI, bool IsVariadic) {
Daniel Dunbar45c25ba2008-09-10 04:01:49 +0000356 std::vector<const llvm::Type*> ArgTys;
357
358 const llvm::Type *ResultType = 0;
359
Daniel Dunbara0a99e02009-02-02 23:43:58 +0000360 QualType RetTy = FI.getReturnType();
Daniel Dunbarb225be42009-02-03 05:59:18 +0000361 const ABIArgInfo &RetAI = FI.getReturnInfo();
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000362 switch (RetAI.getKind()) {
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000363 case ABIArgInfo::Expand:
364 assert(0 && "Invalid ABI kind for return argument");
365
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000366 case ABIArgInfo::Extend:
Daniel Dunbar46327aa2009-02-03 06:17:37 +0000367 case ABIArgInfo::Direct:
368 ResultType = ConvertType(RetTy);
369 break;
370
Daniel Dunbar11e383a2009-02-05 08:00:50 +0000371 case ABIArgInfo::Indirect: {
372 assert(!RetAI.getIndirectAlign() && "Align unused on indirect return.");
Owen Anderson0032b272009-08-13 21:57:51 +0000373 ResultType = llvm::Type::getVoidTy(getLLVMContext());
Daniel Dunbar62d5c1b2008-09-10 07:00:50 +0000374 const llvm::Type *STy = ConvertType(RetTy);
Daniel Dunbar45c25ba2008-09-10 04:01:49 +0000375 ArgTys.push_back(llvm::PointerType::get(STy, RetTy.getAddressSpace()));
376 break;
377 }
378
Daniel Dunbar11434922009-01-26 21:26:08 +0000379 case ABIArgInfo::Ignore:
Owen Anderson0032b272009-08-13 21:57:51 +0000380 ResultType = llvm::Type::getVoidTy(getLLVMContext());
Daniel Dunbar11434922009-01-26 21:26:08 +0000381 break;
382
Daniel Dunbar45c25ba2008-09-10 04:01:49 +0000383 case ABIArgInfo::Coerce:
Daniel Dunbar639ffe42008-09-10 07:04:09 +0000384 ResultType = RetAI.getCoerceToType();
Daniel Dunbar45c25ba2008-09-10 04:01:49 +0000385 break;
386 }
Mike Stump1eb44332009-09-09 15:08:12 +0000387
388 for (CGFunctionInfo::const_arg_iterator it = FI.arg_begin(),
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000389 ie = FI.arg_end(); it != ie; ++it) {
390 const ABIArgInfo &AI = it->info;
Mike Stump1eb44332009-09-09 15:08:12 +0000391
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000392 switch (AI.getKind()) {
Daniel Dunbar11434922009-01-26 21:26:08 +0000393 case ABIArgInfo::Ignore:
394 break;
395
Daniel Dunbar56273772008-09-17 00:51:38 +0000396 case ABIArgInfo::Coerce:
Daniel Dunbar89c9d8e2009-02-03 19:12:28 +0000397 ArgTys.push_back(AI.getCoerceToType());
398 break;
399
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000400 case ABIArgInfo::Indirect: {
Daniel Dunbar11e383a2009-02-05 08:00:50 +0000401 // indirect arguments are always on the stack, which is addr space #0.
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000402 const llvm::Type *LTy = ConvertTypeForMem(it->type);
403 ArgTys.push_back(llvm::PointerType::getUnqual(LTy));
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000404 break;
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000405 }
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000406
407 case ABIArgInfo::Extend:
Daniel Dunbar46327aa2009-02-03 06:17:37 +0000408 case ABIArgInfo::Direct:
Daniel Dunbar1f745982009-02-05 09:16:39 +0000409 ArgTys.push_back(ConvertType(it->type));
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000410 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000411
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000412 case ABIArgInfo::Expand:
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000413 GetExpandedTypes(it->type, ArgTys);
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000414 break;
415 }
Daniel Dunbar45c25ba2008-09-10 04:01:49 +0000416 }
417
Daniel Dunbarbb36d332009-02-02 21:43:58 +0000418 return llvm::FunctionType::get(ResultType, ArgTys, IsVariadic);
Daniel Dunbar3913f182008-09-09 23:48:28 +0000419}
420
Anders Carlssonecf282b2009-11-24 05:08:52 +0000421static bool HasIncompleteReturnTypeOrArgumentTypes(const FunctionProtoType *T) {
422 if (const TagType *TT = T->getResultType()->getAs<TagType>()) {
423 if (!TT->getDecl()->isDefinition())
424 return true;
425 }
426
427 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
428 if (const TagType *TT = T->getArgType(i)->getAs<TagType>()) {
429 if (!TT->getDecl()->isDefinition())
430 return true;
431 }
432 }
433
434 return false;
435}
436
437const llvm::Type *
438CodeGenTypes::GetFunctionTypeForVtable(const CXXMethodDecl *MD) {
439 const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
440
441 if (!HasIncompleteReturnTypeOrArgumentTypes(FPT))
442 return GetFunctionType(getFunctionInfo(MD), FPT->isVariadic());
443
444 return llvm::OpaqueType::get(getLLVMContext());
445}
446
Daniel Dunbara0a99e02009-02-02 23:43:58 +0000447void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI,
Daniel Dunbar88b53962009-02-02 22:03:45 +0000448 const Decl *TargetDecl,
Daniel Dunbarca6408c2009-09-12 00:59:20 +0000449 AttributeListType &PAL,
450 unsigned &CallingConv) {
Daniel Dunbar5323a4b2008-09-10 00:32:18 +0000451 unsigned FuncAttrs = 0;
Devang Patela2c69122008-09-26 22:53:57 +0000452 unsigned RetAttrs = 0;
Daniel Dunbar5323a4b2008-09-10 00:32:18 +0000453
Daniel Dunbarca6408c2009-09-12 00:59:20 +0000454 CallingConv = FI.getEffectiveCallingConvention();
455
Anton Korobeynikov1102f422009-04-04 00:49:24 +0000456 // FIXME: handle sseregparm someday...
Daniel Dunbar5323a4b2008-09-10 00:32:18 +0000457 if (TargetDecl) {
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000458 if (TargetDecl->hasAttr<NoThrowAttr>())
Devang Patel761d7f72008-09-25 21:02:23 +0000459 FuncAttrs |= llvm::Attribute::NoUnwind;
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000460 if (TargetDecl->hasAttr<NoReturnAttr>())
Devang Patel761d7f72008-09-25 21:02:23 +0000461 FuncAttrs |= llvm::Attribute::NoReturn;
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000462 if (TargetDecl->hasAttr<ConstAttr>())
Anders Carlsson232eb7d2008-10-05 23:32:53 +0000463 FuncAttrs |= llvm::Attribute::ReadNone;
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000464 else if (TargetDecl->hasAttr<PureAttr>())
Daniel Dunbar64c2e072009-04-10 22:14:52 +0000465 FuncAttrs |= llvm::Attribute::ReadOnly;
Ryan Flynn76168e22009-08-09 20:07:29 +0000466 if (TargetDecl->hasAttr<MallocAttr>())
467 RetAttrs |= llvm::Attribute::NoAlias;
Daniel Dunbar5323a4b2008-09-10 00:32:18 +0000468 }
469
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000470 if (CodeGenOpts.OptimizeSize)
Daniel Dunbar7ab1c3e2009-10-27 19:48:08 +0000471 FuncAttrs |= llvm::Attribute::OptimizeForSize;
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000472 if (CodeGenOpts.DisableRedZone)
Devang Patel24095da2009-06-04 23:32:02 +0000473 FuncAttrs |= llvm::Attribute::NoRedZone;
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000474 if (CodeGenOpts.NoImplicitFloat)
Devang Patelacebb392009-06-05 22:05:48 +0000475 FuncAttrs |= llvm::Attribute::NoImplicitFloat;
Devang Patel24095da2009-06-04 23:32:02 +0000476
Daniel Dunbara0a99e02009-02-02 23:43:58 +0000477 QualType RetTy = FI.getReturnType();
Daniel Dunbar5323a4b2008-09-10 00:32:18 +0000478 unsigned Index = 1;
Daniel Dunbarb225be42009-02-03 05:59:18 +0000479 const ABIArgInfo &RetAI = FI.getReturnInfo();
Daniel Dunbar45c25ba2008-09-10 04:01:49 +0000480 switch (RetAI.getKind()) {
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000481 case ABIArgInfo::Extend:
482 if (RetTy->isSignedIntegerType()) {
483 RetAttrs |= llvm::Attribute::SExt;
484 } else if (RetTy->isUnsignedIntegerType()) {
485 RetAttrs |= llvm::Attribute::ZExt;
486 }
487 // FALLTHROUGH
Daniel Dunbar46327aa2009-02-03 06:17:37 +0000488 case ABIArgInfo::Direct:
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000489 break;
490
Daniel Dunbar11e383a2009-02-05 08:00:50 +0000491 case ABIArgInfo::Indirect:
Mike Stump1eb44332009-09-09 15:08:12 +0000492 PAL.push_back(llvm::AttributeWithIndex::get(Index,
Daniel Dunbar725ad312009-01-31 02:19:00 +0000493 llvm::Attribute::StructRet |
494 llvm::Attribute::NoAlias));
Daniel Dunbar5323a4b2008-09-10 00:32:18 +0000495 ++Index;
Daniel Dunbar0ac86f02009-03-18 19:51:01 +0000496 // sret disables readnone and readonly
497 FuncAttrs &= ~(llvm::Attribute::ReadOnly |
498 llvm::Attribute::ReadNone);
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000499 break;
500
Daniel Dunbar11434922009-01-26 21:26:08 +0000501 case ABIArgInfo::Ignore:
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000502 case ABIArgInfo::Coerce:
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000503 break;
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000504
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000505 case ABIArgInfo::Expand:
Mike Stump1eb44332009-09-09 15:08:12 +0000506 assert(0 && "Invalid ABI kind for return argument");
Daniel Dunbar5323a4b2008-09-10 00:32:18 +0000507 }
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000508
Devang Patela2c69122008-09-26 22:53:57 +0000509 if (RetAttrs)
510 PAL.push_back(llvm::AttributeWithIndex::get(0, RetAttrs));
Anton Korobeynikov1102f422009-04-04 00:49:24 +0000511
512 // FIXME: we need to honour command line settings also...
513 // FIXME: RegParm should be reduced in case of nested functions and/or global
514 // register variable.
515 signed RegParm = 0;
516 if (TargetDecl)
Mike Stump1eb44332009-09-09 15:08:12 +0000517 if (const RegparmAttr *RegParmAttr
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000518 = TargetDecl->getAttr<RegparmAttr>())
Anton Korobeynikov1102f422009-04-04 00:49:24 +0000519 RegParm = RegParmAttr->getNumParams();
520
521 unsigned PointerWidth = getContext().Target.getPointerWidth(0);
Mike Stump1eb44332009-09-09 15:08:12 +0000522 for (CGFunctionInfo::const_arg_iterator it = FI.arg_begin(),
Daniel Dunbar88c2fa92009-02-03 05:31:23 +0000523 ie = FI.arg_end(); it != ie; ++it) {
524 QualType ParamType = it->type;
525 const ABIArgInfo &AI = it->info;
Devang Patel761d7f72008-09-25 21:02:23 +0000526 unsigned Attributes = 0;
Anton Korobeynikov1102f422009-04-04 00:49:24 +0000527
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000528 switch (AI.getKind()) {
Daniel Dunbar89c9d8e2009-02-03 19:12:28 +0000529 case ABIArgInfo::Coerce:
530 break;
531
Daniel Dunbar11e383a2009-02-05 08:00:50 +0000532 case ABIArgInfo::Indirect:
Anders Carlsson0a8f8472009-09-16 15:53:40 +0000533 if (AI.getIndirectByVal())
534 Attributes |= llvm::Attribute::ByVal;
535
Anton Korobeynikov1102f422009-04-04 00:49:24 +0000536 Attributes |=
Daniel Dunbar11e383a2009-02-05 08:00:50 +0000537 llvm::Attribute::constructAlignmentFromInt(AI.getIndirectAlign());
Daniel Dunbar0ac86f02009-03-18 19:51:01 +0000538 // byval disables readnone and readonly.
539 FuncAttrs &= ~(llvm::Attribute::ReadOnly |
540 llvm::Attribute::ReadNone);
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000541 break;
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000542
543 case ABIArgInfo::Extend:
544 if (ParamType->isSignedIntegerType()) {
545 Attributes |= llvm::Attribute::SExt;
546 } else if (ParamType->isUnsignedIntegerType()) {
547 Attributes |= llvm::Attribute::ZExt;
548 }
549 // FALLS THROUGH
Daniel Dunbar46327aa2009-02-03 06:17:37 +0000550 case ABIArgInfo::Direct:
Anton Korobeynikov1102f422009-04-04 00:49:24 +0000551 if (RegParm > 0 &&
552 (ParamType->isIntegerType() || ParamType->isPointerType())) {
553 RegParm -=
554 (Context.getTypeSize(ParamType) + PointerWidth - 1) / PointerWidth;
555 if (RegParm >= 0)
556 Attributes |= llvm::Attribute::InReg;
557 }
558 // FIXME: handle sseregparm someday...
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000559 break;
Anton Korobeynikov1102f422009-04-04 00:49:24 +0000560
Daniel Dunbar11434922009-01-26 21:26:08 +0000561 case ABIArgInfo::Ignore:
562 // Skip increment, no matching LLVM parameter.
Mike Stump1eb44332009-09-09 15:08:12 +0000563 continue;
Daniel Dunbar11434922009-01-26 21:26:08 +0000564
Daniel Dunbar56273772008-09-17 00:51:38 +0000565 case ABIArgInfo::Expand: {
Mike Stump1eb44332009-09-09 15:08:12 +0000566 std::vector<const llvm::Type*> Tys;
Mike Stumpf5408fe2009-05-16 07:57:57 +0000567 // FIXME: This is rather inefficient. Do we ever actually need to do
568 // anything here? The result should be just reconstructed on the other
569 // side, so extension should be a non-issue.
Daniel Dunbar56273772008-09-17 00:51:38 +0000570 getTypes().GetExpandedTypes(ParamType, Tys);
571 Index += Tys.size();
572 continue;
573 }
Daniel Dunbar5323a4b2008-09-10 00:32:18 +0000574 }
Mike Stump1eb44332009-09-09 15:08:12 +0000575
Devang Patel761d7f72008-09-25 21:02:23 +0000576 if (Attributes)
577 PAL.push_back(llvm::AttributeWithIndex::get(Index, Attributes));
Daniel Dunbar56273772008-09-17 00:51:38 +0000578 ++Index;
Daniel Dunbar5323a4b2008-09-10 00:32:18 +0000579 }
Devang Patela2c69122008-09-26 22:53:57 +0000580 if (FuncAttrs)
581 PAL.push_back(llvm::AttributeWithIndex::get(~0, FuncAttrs));
Daniel Dunbar5323a4b2008-09-10 00:32:18 +0000582}
583
Daniel Dunbar88b53962009-02-02 22:03:45 +0000584void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
585 llvm::Function *Fn,
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000586 const FunctionArgList &Args) {
John McCall0cfeb632009-07-28 01:00:58 +0000587 // If this is an implicit-return-zero function, go ahead and
588 // initialize the return value. TODO: it might be nice to have
589 // a more general mechanism for this that didn't require synthesized
590 // return statements.
Anders Carlsson89ed31d2009-08-08 23:24:23 +0000591 if (const FunctionDecl* FD = dyn_cast_or_null<FunctionDecl>(CurFuncDecl)) {
John McCall0cfeb632009-07-28 01:00:58 +0000592 if (FD->hasImplicitReturnZero()) {
593 QualType RetTy = FD->getResultType().getUnqualifiedType();
594 const llvm::Type* LLVMTy = CGM.getTypes().ConvertType(RetTy);
Owen Andersonc9c88b42009-07-31 20:28:54 +0000595 llvm::Constant* Zero = llvm::Constant::getNullValue(LLVMTy);
John McCall0cfeb632009-07-28 01:00:58 +0000596 Builder.CreateStore(Zero, ReturnValue);
597 }
598 }
599
Mike Stumpf5408fe2009-05-16 07:57:57 +0000600 // FIXME: We no longer need the types from FunctionArgList; lift up and
601 // simplify.
Daniel Dunbar5251afa2009-02-03 06:02:10 +0000602
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000603 // Emit allocs for param decls. Give the LLVM Argument nodes names.
604 llvm::Function::arg_iterator AI = Fn->arg_begin();
Mike Stump1eb44332009-09-09 15:08:12 +0000605
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000606 // Name the struct return argument.
Daniel Dunbar88b53962009-02-02 22:03:45 +0000607 if (CGM.ReturnTypeUsesSret(FI)) {
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000608 AI->setName("agg.result");
609 ++AI;
610 }
Mike Stump1eb44332009-09-09 15:08:12 +0000611
Daniel Dunbar4b5f0a42009-02-04 21:17:21 +0000612 assert(FI.arg_size() == Args.size() &&
613 "Mismatch between function signature & arguments.");
Daniel Dunbarb225be42009-02-03 05:59:18 +0000614 CGFunctionInfo::const_arg_iterator info_it = FI.arg_begin();
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000615 for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
Daniel Dunbarb225be42009-02-03 05:59:18 +0000616 i != e; ++i, ++info_it) {
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000617 const VarDecl *Arg = i->first;
Daniel Dunbarb225be42009-02-03 05:59:18 +0000618 QualType Ty = info_it->type;
619 const ABIArgInfo &ArgI = info_it->info;
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000620
621 switch (ArgI.getKind()) {
Daniel Dunbar1f745982009-02-05 09:16:39 +0000622 case ABIArgInfo::Indirect: {
623 llvm::Value* V = AI;
624 if (hasAggregateLLVMType(Ty)) {
625 // Do nothing, aggregates and complex variables are accessed by
626 // reference.
627 } else {
628 // Load scalar value from indirect argument.
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000629 V = EmitLoadOfScalar(V, false, Ty);
Daniel Dunbar1f745982009-02-05 09:16:39 +0000630 if (!getContext().typesAreCompatible(Ty, Arg->getType())) {
631 // This must be a promotion, for something like
632 // "void a(x) short x; {..."
633 V = EmitScalarConversion(V, Ty, Arg->getType());
634 }
635 }
Mike Stump1eb44332009-09-09 15:08:12 +0000636 EmitParmDecl(*Arg, V);
Daniel Dunbar1f745982009-02-05 09:16:39 +0000637 break;
638 }
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000639
640 case ABIArgInfo::Extend:
Daniel Dunbar46327aa2009-02-03 06:17:37 +0000641 case ABIArgInfo::Direct: {
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000642 assert(AI != Fn->arg_end() && "Argument mismatch!");
643 llvm::Value* V = AI;
Daniel Dunbar2fbf2f52009-02-05 11:13:54 +0000644 if (hasAggregateLLVMType(Ty)) {
645 // Create a temporary alloca to hold the argument; the rest of
646 // codegen expects to access aggregates & complex values by
647 // reference.
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000648 V = CreateTempAlloca(ConvertTypeForMem(Ty));
Daniel Dunbar2fbf2f52009-02-05 11:13:54 +0000649 Builder.CreateStore(AI, V);
650 } else {
651 if (!getContext().typesAreCompatible(Ty, Arg->getType())) {
652 // This must be a promotion, for something like
653 // "void a(x) short x; {..."
654 V = EmitScalarConversion(V, Ty, Arg->getType());
655 }
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000656 }
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000657 EmitParmDecl(*Arg, V);
658 break;
659 }
Mike Stump1eb44332009-09-09 15:08:12 +0000660
Daniel Dunbar56273772008-09-17 00:51:38 +0000661 case ABIArgInfo::Expand: {
Daniel Dunbarb225be42009-02-03 05:59:18 +0000662 // If this structure was expanded into multiple arguments then
Daniel Dunbar56273772008-09-17 00:51:38 +0000663 // we need to create a temporary and reconstruct it from the
664 // arguments.
Mike Stump1eb44332009-09-09 15:08:12 +0000665 llvm::Value *Temp = CreateTempAlloca(ConvertTypeForMem(Ty),
Daniel Dunbar259e9cc2009-10-19 01:21:05 +0000666 Arg->getName() + ".addr");
Daniel Dunbar56273772008-09-17 00:51:38 +0000667 // FIXME: What are the right qualifiers here?
Mike Stump1eb44332009-09-09 15:08:12 +0000668 llvm::Function::arg_iterator End =
John McCall0953e762009-09-24 19:53:00 +0000669 ExpandTypeFromArgs(Ty, LValue::MakeAddr(Temp, Qualifiers()), AI);
Daniel Dunbar56273772008-09-17 00:51:38 +0000670 EmitParmDecl(*Arg, Temp);
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000671
Daniel Dunbar56273772008-09-17 00:51:38 +0000672 // Name the arguments used in expansion and increment AI.
673 unsigned Index = 0;
674 for (; AI != End; ++AI, ++Index)
Daniel Dunbar259e9cc2009-10-19 01:21:05 +0000675 AI->setName(Arg->getName() + "." + llvm::Twine(Index));
Daniel Dunbar56273772008-09-17 00:51:38 +0000676 continue;
677 }
Daniel Dunbar11434922009-01-26 21:26:08 +0000678
679 case ABIArgInfo::Ignore:
Daniel Dunbar8b979d92009-02-10 00:06:49 +0000680 // Initialize the local variable appropriately.
Mike Stump1eb44332009-09-09 15:08:12 +0000681 if (hasAggregateLLVMType(Ty)) {
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000682 EmitParmDecl(*Arg, CreateTempAlloca(ConvertTypeForMem(Ty)));
Daniel Dunbar8b979d92009-02-10 00:06:49 +0000683 } else {
684 EmitParmDecl(*Arg, llvm::UndefValue::get(ConvertType(Arg->getType())));
685 }
Mike Stump1eb44332009-09-09 15:08:12 +0000686
Daniel Dunbar59e5a0e2009-02-03 20:00:13 +0000687 // Skip increment, no matching LLVM parameter.
Mike Stump1eb44332009-09-09 15:08:12 +0000688 continue;
Daniel Dunbar11434922009-01-26 21:26:08 +0000689
Daniel Dunbar89c9d8e2009-02-03 19:12:28 +0000690 case ABIArgInfo::Coerce: {
691 assert(AI != Fn->arg_end() && "Argument mismatch!");
Mike Stumpf5408fe2009-05-16 07:57:57 +0000692 // FIXME: This is very wasteful; EmitParmDecl is just going to drop the
693 // result in a new alloca anyway, so we could just store into that
694 // directly if we broke the abstraction down more.
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000695 llvm::Value *V = CreateTempAlloca(ConvertTypeForMem(Ty), "coerce");
Daniel Dunbar89c9d8e2009-02-03 19:12:28 +0000696 CreateCoercedStore(AI, V, *this);
697 // Match to what EmitParmDecl is expecting for this type.
Daniel Dunbar8b29a382009-02-04 07:22:24 +0000698 if (!CodeGenFunction::hasAggregateLLVMType(Ty)) {
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000699 V = EmitLoadOfScalar(V, false, Ty);
Daniel Dunbar8b29a382009-02-04 07:22:24 +0000700 if (!getContext().typesAreCompatible(Ty, Arg->getType())) {
701 // This must be a promotion, for something like
702 // "void a(x) short x; {..."
703 V = EmitScalarConversion(V, Ty, Arg->getType());
704 }
705 }
Daniel Dunbar89c9d8e2009-02-03 19:12:28 +0000706 EmitParmDecl(*Arg, V);
707 break;
708 }
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000709 }
Daniel Dunbar56273772008-09-17 00:51:38 +0000710
711 ++AI;
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000712 }
713 assert(AI == Fn->arg_end() && "Argument mismatch!");
714}
715
Daniel Dunbar88b53962009-02-02 22:03:45 +0000716void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000717 llvm::Value *ReturnValue) {
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000718 llvm::Value *RV = 0;
719
720 // Functions with no result always return void.
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000721 if (ReturnValue) {
Daniel Dunbar88b53962009-02-02 22:03:45 +0000722 QualType RetTy = FI.getReturnType();
Daniel Dunbarb225be42009-02-03 05:59:18 +0000723 const ABIArgInfo &RetAI = FI.getReturnInfo();
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000724
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000725 switch (RetAI.getKind()) {
Daniel Dunbar11e383a2009-02-05 08:00:50 +0000726 case ABIArgInfo::Indirect:
Daniel Dunbar3aea8ca2008-12-18 04:52:14 +0000727 if (RetTy->isAnyComplexType()) {
Daniel Dunbar3aea8ca2008-12-18 04:52:14 +0000728 ComplexPairTy RT = LoadComplexFromAddr(ReturnValue, false);
729 StoreComplexToAddr(RT, CurFn->arg_begin(), false);
730 } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
731 EmitAggregateCopy(CurFn->arg_begin(), ReturnValue, RetTy);
732 } else {
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000733 EmitStoreOfScalar(Builder.CreateLoad(ReturnValue), CurFn->arg_begin(),
Anders Carlssonb4aa4662009-05-19 18:50:41 +0000734 false, RetTy);
Daniel Dunbar3aea8ca2008-12-18 04:52:14 +0000735 }
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000736 break;
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000737
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000738 case ABIArgInfo::Extend:
Daniel Dunbar46327aa2009-02-03 06:17:37 +0000739 case ABIArgInfo::Direct:
Daniel Dunbar2fbf2f52009-02-05 11:13:54 +0000740 // The internal return value temp always will have
741 // pointer-to-return-type type.
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000742 RV = Builder.CreateLoad(ReturnValue);
743 break;
744
Daniel Dunbar11434922009-01-26 21:26:08 +0000745 case ABIArgInfo::Ignore:
746 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000747
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000748 case ABIArgInfo::Coerce:
Daniel Dunbar54d1ccb2009-01-27 01:36:03 +0000749 RV = CreateCoercedLoad(ReturnValue, RetAI.getCoerceToType(), *this);
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000750 break;
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000751
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000752 case ABIArgInfo::Expand:
Mike Stump1eb44332009-09-09 15:08:12 +0000753 assert(0 && "Invalid ABI kind for return argument");
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000754 }
755 }
Mike Stump1eb44332009-09-09 15:08:12 +0000756
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000757 if (RV) {
758 Builder.CreateRet(RV);
759 } else {
760 Builder.CreateRetVoid();
761 }
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000762}
763
Anders Carlsson0139bb92009-04-08 20:47:54 +0000764RValue CodeGenFunction::EmitCallArg(const Expr *E, QualType ArgType) {
Anders Carlsson4029ca72009-05-20 00:24:07 +0000765 if (ArgType->isReferenceType())
766 return EmitReferenceBindingToExpr(E, ArgType);
Mike Stump1eb44332009-09-09 15:08:12 +0000767
Anders Carlsson0139bb92009-04-08 20:47:54 +0000768 return EmitAnyExprToTemp(E);
769}
770
Daniel Dunbar88b53962009-02-02 22:03:45 +0000771RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
Mike Stump1eb44332009-09-09 15:08:12 +0000772 llvm::Value *Callee,
Daniel Dunbarc0ef9f52009-02-20 18:06:48 +0000773 const CallArgList &CallArgs,
774 const Decl *TargetDecl) {
Mike Stumpf5408fe2009-05-16 07:57:57 +0000775 // FIXME: We no longer need the types from CallArgs; lift up and simplify.
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000776 llvm::SmallVector<llvm::Value*, 16> Args;
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000777
778 // Handle struct-return functions by passing a pointer to the
779 // location that we would like to return into.
Daniel Dunbarbb36d332009-02-02 21:43:58 +0000780 QualType RetTy = CallInfo.getReturnType();
Daniel Dunbarb225be42009-02-03 05:59:18 +0000781 const ABIArgInfo &RetAI = CallInfo.getReturnInfo();
Mike Stump1eb44332009-09-09 15:08:12 +0000782
783
Chris Lattner5db7ae52009-06-13 00:26:38 +0000784 // If the call returns a temporary with struct return, create a temporary
785 // alloca to hold the result.
786 if (CGM.ReturnTypeUsesSret(CallInfo))
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000787 Args.push_back(CreateTempAlloca(ConvertTypeForMem(RetTy)));
Mike Stump1eb44332009-09-09 15:08:12 +0000788
Daniel Dunbar4b5f0a42009-02-04 21:17:21 +0000789 assert(CallInfo.arg_size() == CallArgs.size() &&
790 "Mismatch between function signature & arguments.");
Daniel Dunbarb225be42009-02-03 05:59:18 +0000791 CGFunctionInfo::const_arg_iterator info_it = CallInfo.arg_begin();
Mike Stump1eb44332009-09-09 15:08:12 +0000792 for (CallArgList::const_iterator I = CallArgs.begin(), E = CallArgs.end();
Daniel Dunbarb225be42009-02-03 05:59:18 +0000793 I != E; ++I, ++info_it) {
794 const ABIArgInfo &ArgInfo = info_it->info;
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000795 RValue RV = I->first;
Daniel Dunbar56273772008-09-17 00:51:38 +0000796
797 switch (ArgInfo.getKind()) {
Daniel Dunbar11e383a2009-02-05 08:00:50 +0000798 case ABIArgInfo::Indirect:
Daniel Dunbar1f745982009-02-05 09:16:39 +0000799 if (RV.isScalar() || RV.isComplex()) {
800 // Make a temporary alloca to pass the argument.
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000801 Args.push_back(CreateTempAlloca(ConvertTypeForMem(I->second)));
Daniel Dunbar1f745982009-02-05 09:16:39 +0000802 if (RV.isScalar())
Anders Carlssonb4aa4662009-05-19 18:50:41 +0000803 EmitStoreOfScalar(RV.getScalarVal(), Args.back(), false, I->second);
Daniel Dunbar1f745982009-02-05 09:16:39 +0000804 else
Mike Stump1eb44332009-09-09 15:08:12 +0000805 StoreComplexToAddr(RV.getComplexVal(), Args.back(), false);
Daniel Dunbar1f745982009-02-05 09:16:39 +0000806 } else {
807 Args.push_back(RV.getAggregateAddr());
808 }
809 break;
810
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000811 case ABIArgInfo::Extend:
Daniel Dunbar46327aa2009-02-03 06:17:37 +0000812 case ABIArgInfo::Direct:
Daniel Dunbar56273772008-09-17 00:51:38 +0000813 if (RV.isScalar()) {
814 Args.push_back(RV.getScalarVal());
815 } else if (RV.isComplex()) {
Daniel Dunbar2fbf2f52009-02-05 11:13:54 +0000816 llvm::Value *Tmp = llvm::UndefValue::get(ConvertType(I->second));
817 Tmp = Builder.CreateInsertValue(Tmp, RV.getComplexVal().first, 0);
818 Tmp = Builder.CreateInsertValue(Tmp, RV.getComplexVal().second, 1);
819 Args.push_back(Tmp);
Daniel Dunbar56273772008-09-17 00:51:38 +0000820 } else {
Daniel Dunbar2fbf2f52009-02-05 11:13:54 +0000821 Args.push_back(Builder.CreateLoad(RV.getAggregateAddr()));
Daniel Dunbar56273772008-09-17 00:51:38 +0000822 }
823 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000824
Daniel Dunbar11434922009-01-26 21:26:08 +0000825 case ABIArgInfo::Ignore:
826 break;
827
Daniel Dunbar89c9d8e2009-02-03 19:12:28 +0000828 case ABIArgInfo::Coerce: {
829 // FIXME: Avoid the conversion through memory if possible.
830 llvm::Value *SrcPtr;
831 if (RV.isScalar()) {
Daniel Dunbar5a1be6e2009-02-03 23:04:57 +0000832 SrcPtr = CreateTempAlloca(ConvertTypeForMem(I->second), "coerce");
Anders Carlssonb4aa4662009-05-19 18:50:41 +0000833 EmitStoreOfScalar(RV.getScalarVal(), SrcPtr, false, I->second);
Daniel Dunbar89c9d8e2009-02-03 19:12:28 +0000834 } else if (RV.isComplex()) {
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000835 SrcPtr = CreateTempAlloca(ConvertTypeForMem(I->second), "coerce");
Daniel Dunbar89c9d8e2009-02-03 19:12:28 +0000836 StoreComplexToAddr(RV.getComplexVal(), SrcPtr, false);
Mike Stump1eb44332009-09-09 15:08:12 +0000837 } else
Daniel Dunbar89c9d8e2009-02-03 19:12:28 +0000838 SrcPtr = RV.getAggregateAddr();
Mike Stump1eb44332009-09-09 15:08:12 +0000839 Args.push_back(CreateCoercedLoad(SrcPtr, ArgInfo.getCoerceToType(),
Daniel Dunbar89c9d8e2009-02-03 19:12:28 +0000840 *this));
841 break;
842 }
843
Daniel Dunbar56273772008-09-17 00:51:38 +0000844 case ABIArgInfo::Expand:
845 ExpandTypeToArgs(I->second, RV, Args);
846 break;
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000847 }
848 }
Mike Stump1eb44332009-09-09 15:08:12 +0000849
Chris Lattner5db7ae52009-06-13 00:26:38 +0000850 // If the callee is a bitcast of a function to a varargs pointer to function
851 // type, check to see if we can remove the bitcast. This handles some cases
852 // with unprototyped functions.
853 if (llvm::ConstantExpr *CE = dyn_cast<llvm::ConstantExpr>(Callee))
854 if (llvm::Function *CalleeF = dyn_cast<llvm::Function>(CE->getOperand(0))) {
855 const llvm::PointerType *CurPT=cast<llvm::PointerType>(Callee->getType());
856 const llvm::FunctionType *CurFT =
857 cast<llvm::FunctionType>(CurPT->getElementType());
858 const llvm::FunctionType *ActualFT = CalleeF->getFunctionType();
Mike Stump1eb44332009-09-09 15:08:12 +0000859
Chris Lattner5db7ae52009-06-13 00:26:38 +0000860 if (CE->getOpcode() == llvm::Instruction::BitCast &&
861 ActualFT->getReturnType() == CurFT->getReturnType() &&
Chris Lattnerd6bebbf2009-06-23 01:38:41 +0000862 ActualFT->getNumParams() == CurFT->getNumParams() &&
863 ActualFT->getNumParams() == Args.size()) {
Chris Lattner5db7ae52009-06-13 00:26:38 +0000864 bool ArgsMatch = true;
865 for (unsigned i = 0, e = ActualFT->getNumParams(); i != e; ++i)
866 if (ActualFT->getParamType(i) != CurFT->getParamType(i)) {
867 ArgsMatch = false;
868 break;
869 }
Mike Stump1eb44332009-09-09 15:08:12 +0000870
Chris Lattner5db7ae52009-06-13 00:26:38 +0000871 // Strip the cast if we can get away with it. This is a nice cleanup,
872 // but also allows us to inline the function at -O0 if it is marked
873 // always_inline.
874 if (ArgsMatch)
875 Callee = CalleeF;
876 }
877 }
Mike Stump1eb44332009-09-09 15:08:12 +0000878
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000879
Daniel Dunbar9834ffb2009-02-23 17:26:39 +0000880 llvm::BasicBlock *InvokeDest = getInvokeDest();
Daniel Dunbarca6408c2009-09-12 00:59:20 +0000881 unsigned CallingConv;
Devang Patel761d7f72008-09-25 21:02:23 +0000882 CodeGen::AttributeListType AttributeList;
Daniel Dunbarca6408c2009-09-12 00:59:20 +0000883 CGM.ConstructAttributeList(CallInfo, TargetDecl, AttributeList, CallingConv);
Daniel Dunbar9834ffb2009-02-23 17:26:39 +0000884 llvm::AttrListPtr Attrs = llvm::AttrListPtr::get(AttributeList.begin(),
885 AttributeList.end());
Mike Stump1eb44332009-09-09 15:08:12 +0000886
Daniel Dunbard14151d2009-03-02 04:32:35 +0000887 llvm::CallSite CS;
888 if (!InvokeDest || (Attrs.getFnAttributes() & llvm::Attribute::NoUnwind)) {
Jay Foadbeaaccd2009-05-21 09:52:38 +0000889 CS = Builder.CreateCall(Callee, Args.data(), Args.data()+Args.size());
Daniel Dunbar9834ffb2009-02-23 17:26:39 +0000890 } else {
891 llvm::BasicBlock *Cont = createBasicBlock("invoke.cont");
Mike Stump1eb44332009-09-09 15:08:12 +0000892 CS = Builder.CreateInvoke(Callee, Cont, InvokeDest,
Jay Foadbeaaccd2009-05-21 09:52:38 +0000893 Args.data(), Args.data()+Args.size());
Daniel Dunbar9834ffb2009-02-23 17:26:39 +0000894 EmitBlock(Cont);
Daniel Dunbarf4fe0f02009-02-20 18:54:31 +0000895 }
896
Daniel Dunbard14151d2009-03-02 04:32:35 +0000897 CS.setAttributes(Attrs);
Daniel Dunbarca6408c2009-09-12 00:59:20 +0000898 CS.setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
Daniel Dunbard14151d2009-03-02 04:32:35 +0000899
900 // If the call doesn't return, finish the basic block and clear the
901 // insertion point; this allows the rest of IRgen to discard
902 // unreachable code.
903 if (CS.doesNotReturn()) {
904 Builder.CreateUnreachable();
905 Builder.ClearInsertionPoint();
Mike Stump1eb44332009-09-09 15:08:12 +0000906
Mike Stumpf5408fe2009-05-16 07:57:57 +0000907 // FIXME: For now, emit a dummy basic block because expr emitters in
908 // generally are not ready to handle emitting expressions at unreachable
909 // points.
Daniel Dunbard14151d2009-03-02 04:32:35 +0000910 EnsureInsertPoint();
Mike Stump1eb44332009-09-09 15:08:12 +0000911
Daniel Dunbard14151d2009-03-02 04:32:35 +0000912 // Return a reasonable RValue.
913 return GetUndefRValue(RetTy);
Mike Stump1eb44332009-09-09 15:08:12 +0000914 }
Daniel Dunbard14151d2009-03-02 04:32:35 +0000915
916 llvm::Instruction *CI = CS.getInstruction();
Benjamin Kramerffbb15e2009-10-05 13:47:21 +0000917 if (Builder.isNamePreserving() && !CI->getType()->isVoidTy())
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000918 CI->setName("call");
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000919
920 switch (RetAI.getKind()) {
Daniel Dunbar11e383a2009-02-05 08:00:50 +0000921 case ABIArgInfo::Indirect:
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000922 if (RetTy->isAnyComplexType())
Daniel Dunbar56273772008-09-17 00:51:38 +0000923 return RValue::getComplex(LoadComplexFromAddr(Args[0], false));
Chris Lattner34030842009-03-22 00:32:22 +0000924 if (CodeGenFunction::hasAggregateLLVMType(RetTy))
Daniel Dunbar56273772008-09-17 00:51:38 +0000925 return RValue::getAggregate(Args[0]);
Chris Lattner34030842009-03-22 00:32:22 +0000926 return RValue::get(EmitLoadOfScalar(Args[0], false, RetTy));
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000927
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000928 case ABIArgInfo::Extend:
Daniel Dunbar46327aa2009-02-03 06:17:37 +0000929 case ABIArgInfo::Direct:
Daniel Dunbar2fbf2f52009-02-05 11:13:54 +0000930 if (RetTy->isAnyComplexType()) {
931 llvm::Value *Real = Builder.CreateExtractValue(CI, 0);
932 llvm::Value *Imag = Builder.CreateExtractValue(CI, 1);
933 return RValue::getComplex(std::make_pair(Real, Imag));
Chris Lattner34030842009-03-22 00:32:22 +0000934 }
935 if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000936 llvm::Value *V = CreateTempAlloca(ConvertTypeForMem(RetTy), "agg.tmp");
Daniel Dunbar2fbf2f52009-02-05 11:13:54 +0000937 Builder.CreateStore(CI, V);
938 return RValue::getAggregate(V);
Chris Lattner34030842009-03-22 00:32:22 +0000939 }
940 return RValue::get(CI);
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000941
Daniel Dunbar11434922009-01-26 21:26:08 +0000942 case ABIArgInfo::Ignore:
Daniel Dunbar0bcc5212009-02-03 06:30:17 +0000943 // If we are ignoring an argument that had a result, make sure to
944 // construct the appropriate return value for our caller.
Daniel Dunbar13e81732009-02-05 07:09:07 +0000945 return GetUndefRValue(RetTy);
Daniel Dunbar11434922009-01-26 21:26:08 +0000946
Daniel Dunbar639ffe42008-09-10 07:04:09 +0000947 case ABIArgInfo::Coerce: {
Daniel Dunbar89c9d8e2009-02-03 19:12:28 +0000948 // FIXME: Avoid the conversion through memory if possible.
Daniel Dunbaradc8bdd2009-02-10 01:51:39 +0000949 llvm::Value *V = CreateTempAlloca(ConvertTypeForMem(RetTy), "coerce");
Daniel Dunbar54d1ccb2009-01-27 01:36:03 +0000950 CreateCoercedStore(CI, V, *this);
Anders Carlssonad3d6912008-11-25 22:21:48 +0000951 if (RetTy->isAnyComplexType())
952 return RValue::getComplex(LoadComplexFromAddr(V, false));
Chris Lattner34030842009-03-22 00:32:22 +0000953 if (CodeGenFunction::hasAggregateLLVMType(RetTy))
Anders Carlssonad3d6912008-11-25 22:21:48 +0000954 return RValue::getAggregate(V);
Chris Lattner34030842009-03-22 00:32:22 +0000955 return RValue::get(EmitLoadOfScalar(V, false, RetTy));
Daniel Dunbar639ffe42008-09-10 07:04:09 +0000956 }
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000957
Daniel Dunbar8951dbd2008-09-11 01:48:57 +0000958 case ABIArgInfo::Expand:
Mike Stump1eb44332009-09-09 15:08:12 +0000959 assert(0 && "Invalid ABI kind for return argument");
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000960 }
Daniel Dunbar2c8e0f32008-09-10 02:41:04 +0000961
962 assert(0 && "Unhandled ABIArgInfo::Kind");
963 return RValue::get(0);
Daniel Dunbar17b708d2008-09-09 23:27:19 +0000964}
Daniel Dunbarb4094ea2009-02-10 20:44:09 +0000965
966/* VarArg handling */
967
968llvm::Value *CodeGenFunction::EmitVAArg(llvm::Value *VAListAddr, QualType Ty) {
969 return CGM.getTypes().getABIInfo().EmitVAArg(VAListAddr, Ty, *this);
970}