Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 1 | //===----- 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 Dunbar | c68897d | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 17 | #include "CodeGenModule.h" |
Daniel Dunbar | d9eff3d | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 18 | #include "clang/Basic/TargetInfo.h" |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Anders Carlsson | b15b55c | 2009-04-03 22:48:58 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclCXX.h" |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclObjC.h" |
Devang Patel | 6e467b1 | 2009-06-04 23:32:02 +0000 | [diff] [blame] | 22 | #include "clang/Frontend/CompileOptions.h" |
Devang Patel | 3e1f51b | 2008-09-24 01:01:36 +0000 | [diff] [blame] | 23 | #include "llvm/Attributes.h" |
Daniel Dunbar | b960b7b | 2009-03-02 04:32:35 +0000 | [diff] [blame] | 24 | #include "llvm/Support/CallSite.h" |
Daniel Dunbar | 0f4aa3c | 2009-01-27 01:36:03 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetData.h" |
Daniel Dunbar | 6d6b0d3 | 2009-02-03 01:05:53 +0000 | [diff] [blame] | 26 | |
| 27 | #include "ABIInfo.h" |
| 28 | |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 29 | using namespace clang; |
| 30 | using namespace CodeGen; |
| 31 | |
| 32 | /***/ |
| 33 | |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 34 | // FIXME: Use iterator and sidestep silly type array creation. |
| 35 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 36 | const |
Douglas Gregor | deaad8c | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 37 | CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionNoProtoType *FTNP) { |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 38 | // FIXME: Set calling convention correctly, it needs to be associated with the |
| 39 | // type somehow. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 40 | return getFunctionInfo(FTNP->getResultType(), |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 41 | llvm::SmallVector<QualType, 16>(), 0); |
Daniel Dunbar | 7a95ca3 | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 44 | const |
Douglas Gregor | deaad8c | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 45 | CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionProtoType *FTP) { |
Daniel Dunbar | bf8c24a | 2009-02-02 23:23:47 +0000 | [diff] [blame] | 46 | llvm::SmallVector<QualType, 16> ArgTys; |
| 47 | // FIXME: Kill copy. |
Daniel Dunbar | 7a95ca3 | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 48 | for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) |
Daniel Dunbar | bf8c24a | 2009-02-02 23:23:47 +0000 | [diff] [blame] | 49 | ArgTys.push_back(FTP->getArgType(i)); |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 50 | // FIXME: Set calling convention correctly, it needs to be associated with the |
| 51 | // type somehow. |
| 52 | return getFunctionInfo(FTP->getResultType(), ArgTys, 0); |
| 53 | } |
| 54 | |
| 55 | static 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 Dunbar | 7a95ca3 | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Anders Carlsson | b15b55c | 2009-04-03 22:48:58 +0000 | [diff] [blame] | 66 | const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const CXXMethodDecl *MD) { |
| 67 | llvm::SmallVector<QualType, 16> ArgTys; |
Chris Lattner | bea5b62 | 2009-05-12 20:27:19 +0000 | [diff] [blame] | 68 | // Add the 'this' pointer unless this is a static method. |
| 69 | if (MD->isInstance()) |
| 70 | ArgTys.push_back(MD->getThisType(Context)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 71 | |
Anders Carlsson | b15b55c | 2009-04-03 22:48:58 +0000 | [diff] [blame] | 72 | const FunctionProtoType *FTP = MD->getType()->getAsFunctionProtoType(); |
| 73 | for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) |
| 74 | ArgTys.push_back(FTP->getArgType(i)); |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 75 | return getFunctionInfo(FTP->getResultType(), ArgTys, |
| 76 | getCallingConventionForDecl(MD)); |
Anders Carlsson | b15b55c | 2009-04-03 22:48:58 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Daniel Dunbar | bf8c24a | 2009-02-02 23:23:47 +0000 | [diff] [blame] | 79 | const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const FunctionDecl *FD) { |
Chris Lattner | bea5b62 | 2009-05-12 20:27:19 +0000 | [diff] [blame] | 80 | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) |
Anders Carlsson | b15b55c | 2009-04-03 22:48:58 +0000 | [diff] [blame] | 81 | if (MD->isInstance()) |
| 82 | return getFunctionInfo(MD); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 83 | |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 84 | unsigned CallingConvention = getCallingConventionForDecl(FD); |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 85 | const FunctionType *FTy = FD->getType()->getAsFunctionType(); |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 86 | if (const FunctionNoProtoType *FNTP = dyn_cast<FunctionNoProtoType>(FTy)) |
| 87 | return getFunctionInfo(FNTP->getResultType(), |
| 88 | llvm::SmallVector<QualType, 16>(), |
| 89 | CallingConvention); |
| 90 | |
| 91 | const FunctionProtoType *FPT = cast<FunctionProtoType>(FTy); |
| 92 | llvm::SmallVector<QualType, 16> ArgTys; |
| 93 | // FIXME: Kill copy. |
| 94 | for (unsigned i = 0, e = FPT->getNumArgs(); i != e; ++i) |
| 95 | ArgTys.push_back(FPT->getArgType(i)); |
| 96 | return getFunctionInfo(FPT->getResultType(), ArgTys, CallingConvention); |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Daniel Dunbar | bf8c24a | 2009-02-02 23:23:47 +0000 | [diff] [blame] | 99 | const CGFunctionInfo &CodeGenTypes::getFunctionInfo(const ObjCMethodDecl *MD) { |
| 100 | llvm::SmallVector<QualType, 16> ArgTys; |
| 101 | ArgTys.push_back(MD->getSelfDecl()->getType()); |
| 102 | ArgTys.push_back(Context.getObjCSelType()); |
| 103 | // FIXME: Kill copy? |
Chris Lattner | 90669d0 | 2009-02-20 06:23:21 +0000 | [diff] [blame] | 104 | for (ObjCMethodDecl::param_iterator i = MD->param_begin(), |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 105 | e = MD->param_end(); i != e; ++i) |
Daniel Dunbar | bf8c24a | 2009-02-02 23:23:47 +0000 | [diff] [blame] | 106 | ArgTys.push_back((*i)->getType()); |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 107 | return getFunctionInfo(MD->getResultType(), ArgTys, |
| 108 | getCallingConventionForDecl(MD)); |
Daniel Dunbar | 3d7c90b | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 111 | const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy, |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 112 | const CallArgList &Args, |
| 113 | unsigned CallingConvention){ |
Daniel Dunbar | bf8c24a | 2009-02-02 23:23:47 +0000 | [diff] [blame] | 114 | // FIXME: Kill copy. |
| 115 | llvm::SmallVector<QualType, 16> ArgTys; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 116 | for (CallArgList::const_iterator i = Args.begin(), e = Args.end(); |
Daniel Dunbar | 3cd2063 | 2009-01-31 02:19:00 +0000 | [diff] [blame] | 117 | i != e; ++i) |
Daniel Dunbar | bf8c24a | 2009-02-02 23:23:47 +0000 | [diff] [blame] | 118 | ArgTys.push_back(i->second); |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 119 | return getFunctionInfo(ResTy, ArgTys, CallingConvention); |
Daniel Dunbar | 3cd2063 | 2009-01-31 02:19:00 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 122 | const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy, |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 123 | const FunctionArgList &Args, |
| 124 | unsigned CallingConvention){ |
Daniel Dunbar | bf8c24a | 2009-02-02 23:23:47 +0000 | [diff] [blame] | 125 | // FIXME: Kill copy. |
| 126 | llvm::SmallVector<QualType, 16> ArgTys; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 127 | for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end(); |
Daniel Dunbar | 7633cbf | 2009-02-02 21:43:58 +0000 | [diff] [blame] | 128 | i != e; ++i) |
Daniel Dunbar | bf8c24a | 2009-02-02 23:23:47 +0000 | [diff] [blame] | 129 | ArgTys.push_back(i->second); |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 130 | return getFunctionInfo(ResTy, ArgTys, CallingConvention); |
Daniel Dunbar | bf8c24a | 2009-02-02 23:23:47 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | const CGFunctionInfo &CodeGenTypes::getFunctionInfo(QualType ResTy, |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 134 | const llvm::SmallVector<QualType, 16> &ArgTys, |
| 135 | unsigned CallingConvention){ |
Daniel Dunbar | e0be829 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 136 | // Lookup or create unique function info. |
| 137 | llvm::FoldingSetNodeID ID; |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 138 | CGFunctionInfo::Profile(ID, CallingConvention, ResTy, |
| 139 | ArgTys.begin(), ArgTys.end()); |
Daniel Dunbar | e0be829 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 140 | |
| 141 | void *InsertPos = 0; |
| 142 | CGFunctionInfo *FI = FunctionInfos.FindNodeOrInsertPos(ID, InsertPos); |
| 143 | if (FI) |
| 144 | return *FI; |
| 145 | |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 146 | // Construct the function info. |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 147 | FI = new CGFunctionInfo(CallingConvention, ResTy, ArgTys); |
Daniel Dunbar | fff09f3 | 2009-02-05 00:00:23 +0000 | [diff] [blame] | 148 | FunctionInfos.InsertNode(FI, InsertPos); |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 149 | |
| 150 | // Compute ABI information. |
Owen Anderson | 170229f | 2009-07-14 23:10:40 +0000 | [diff] [blame] | 151 | getABIInfo().computeInfo(*FI, getContext(), TheModule.getContext()); |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 152 | |
Daniel Dunbar | e0be829 | 2009-02-03 00:07:12 +0000 | [diff] [blame] | 153 | return *FI; |
Daniel Dunbar | bf8c24a | 2009-02-02 23:23:47 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Daniel Dunbar | 7feafc7 | 2009-09-11 22:24:53 +0000 | [diff] [blame] | 156 | CGFunctionInfo::CGFunctionInfo(unsigned _CallingConvention, |
| 157 | QualType ResTy, |
| 158 | const llvm::SmallVector<QualType, 16> &ArgTys) |
| 159 | : CallingConvention(_CallingConvention) |
| 160 | { |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 161 | NumArgs = ArgTys.size(); |
| 162 | Args = new ArgInfo[1 + NumArgs]; |
| 163 | Args[0].type = ResTy; |
| 164 | for (unsigned i = 0; i < NumArgs; ++i) |
| 165 | Args[1 + i].type = ArgTys[i]; |
| 166 | } |
| 167 | |
| 168 | /***/ |
| 169 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 170 | void CodeGenTypes::GetExpandedTypes(QualType Ty, |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 171 | std::vector<const llvm::Type*> &ArgTys) { |
| 172 | const RecordType *RT = Ty->getAsStructureType(); |
| 173 | assert(RT && "Can only expand structure types."); |
| 174 | const RecordDecl *RD = RT->getDecl(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 175 | assert(!RD->hasFlexibleArrayMember() && |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 176 | "Cannot expand structure with flexible array."); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 178 | for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); |
| 179 | i != e; ++i) { |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 180 | const FieldDecl *FD = *i; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 181 | assert(!FD->isBitField() && |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 182 | "Cannot expand structure with bit-field members."); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 184 | QualType FT = FD->getType(); |
| 185 | if (CodeGenFunction::hasAggregateLLVMType(FT)) { |
| 186 | GetExpandedTypes(FT, ArgTys); |
| 187 | } else { |
| 188 | ArgTys.push_back(ConvertType(FT)); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 193 | llvm::Function::arg_iterator |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 194 | CodeGenFunction::ExpandTypeFromArgs(QualType Ty, LValue LV, |
| 195 | llvm::Function::arg_iterator AI) { |
| 196 | const RecordType *RT = Ty->getAsStructureType(); |
| 197 | assert(RT && "Can only expand structure types."); |
| 198 | |
| 199 | RecordDecl *RD = RT->getDecl(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 200 | assert(LV.isSimple() && |
| 201 | "Unexpected non-simple lvalue during struct expansion."); |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 202 | llvm::Value *Addr = LV.getAddress(); |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 203 | for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); |
| 204 | i != e; ++i) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 205 | FieldDecl *FD = *i; |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 206 | QualType FT = FD->getType(); |
| 207 | |
| 208 | // FIXME: What are the right qualifiers here? |
| 209 | LValue LV = EmitLValueForField(Addr, FD, false, 0); |
| 210 | if (CodeGenFunction::hasAggregateLLVMType(FT)) { |
| 211 | AI = ExpandTypeFromArgs(FT, LV, AI); |
| 212 | } else { |
| 213 | EmitStoreThroughLValue(RValue::get(AI), LV, FT); |
| 214 | ++AI; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | return AI; |
| 219 | } |
| 220 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 221 | void |
| 222 | CodeGenFunction::ExpandTypeToArgs(QualType Ty, RValue RV, |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 223 | llvm::SmallVector<llvm::Value*, 16> &Args) { |
| 224 | const RecordType *RT = Ty->getAsStructureType(); |
| 225 | assert(RT && "Can only expand structure types."); |
| 226 | |
| 227 | RecordDecl *RD = RT->getDecl(); |
| 228 | assert(RV.isAggregate() && "Unexpected rvalue during struct expansion"); |
| 229 | llvm::Value *Addr = RV.getAggregateAddr(); |
Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 230 | for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); |
| 231 | i != e; ++i) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 232 | FieldDecl *FD = *i; |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 233 | QualType FT = FD->getType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 235 | // FIXME: What are the right qualifiers here? |
| 236 | LValue LV = EmitLValueForField(Addr, FD, false, 0); |
| 237 | if (CodeGenFunction::hasAggregateLLVMType(FT)) { |
| 238 | ExpandTypeToArgs(FT, RValue::getAggregate(LV.getAddress()), Args); |
| 239 | } else { |
| 240 | RValue RV = EmitLoadOfLValue(LV, FT); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 241 | assert(RV.isScalar() && |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 242 | "Unexpected non-scalar rvalue during struct expansion."); |
| 243 | Args.push_back(RV.getScalarVal()); |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 248 | /// CreateCoercedLoad - Create a load from \arg SrcPtr interpreted as |
| 249 | /// a pointer to an object of type \arg Ty. |
| 250 | /// |
| 251 | /// This safely handles the case when the src type is smaller than the |
| 252 | /// destination type; in this situation the values of bits which not |
| 253 | /// present in the src are undefined. |
| 254 | static llvm::Value *CreateCoercedLoad(llvm::Value *SrcPtr, |
| 255 | const llvm::Type *Ty, |
| 256 | CodeGenFunction &CGF) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 257 | const llvm::Type *SrcTy = |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 258 | cast<llvm::PointerType>(SrcPtr->getType())->getElementType(); |
Duncan Sands | c76fe8b | 2009-05-09 07:08:47 +0000 | [diff] [blame] | 259 | uint64_t SrcSize = CGF.CGM.getTargetData().getTypeAllocSize(SrcTy); |
| 260 | uint64_t DstSize = CGF.CGM.getTargetData().getTypeAllocSize(Ty); |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 261 | |
Daniel Dunbar | b52d077 | 2009-02-03 05:59:18 +0000 | [diff] [blame] | 262 | // If load is legal, just bitcast the src pointer. |
Daniel Dunbar | ffdb843 | 2009-05-13 18:54:26 +0000 | [diff] [blame] | 263 | if (SrcSize >= DstSize) { |
Mike Stump | 18bb928 | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 264 | // Generally SrcSize is never greater than DstSize, since this means we are |
| 265 | // losing bits. However, this can happen in cases where the structure has |
| 266 | // additional padding, for example due to a user specified alignment. |
Daniel Dunbar | ffdb843 | 2009-05-13 18:54:26 +0000 | [diff] [blame] | 267 | // |
Mike Stump | 18bb928 | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 268 | // FIXME: Assert that we aren't truncating non-padding bits when have access |
| 269 | // to that information. |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 270 | llvm::Value *Casted = |
| 271 | CGF.Builder.CreateBitCast(SrcPtr, llvm::PointerType::getUnqual(Ty)); |
Daniel Dunbar | ee9e4c2 | 2009-02-07 02:46:03 +0000 | [diff] [blame] | 272 | llvm::LoadInst *Load = CGF.Builder.CreateLoad(Casted); |
| 273 | // FIXME: Use better alignment / avoid requiring aligned load. |
| 274 | Load->setAlignment(1); |
| 275 | return Load; |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 276 | } else { |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 277 | // Otherwise do coercion through memory. This is stupid, but |
| 278 | // simple. |
| 279 | llvm::Value *Tmp = CGF.CreateTempAlloca(Ty); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 280 | llvm::Value *Casted = |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 281 | CGF.Builder.CreateBitCast(Tmp, llvm::PointerType::getUnqual(SrcTy)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | llvm::StoreInst *Store = |
Daniel Dunbar | ee9e4c2 | 2009-02-07 02:46:03 +0000 | [diff] [blame] | 283 | CGF.Builder.CreateStore(CGF.Builder.CreateLoad(SrcPtr), Casted); |
| 284 | // FIXME: Use better alignment / avoid requiring aligned store. |
| 285 | Store->setAlignment(1); |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 286 | return CGF.Builder.CreateLoad(Tmp); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | /// CreateCoercedStore - Create a store to \arg DstPtr from \arg Src, |
| 291 | /// where the source and destination may have different types. |
| 292 | /// |
| 293 | /// This safely handles the case when the src type is larger than the |
| 294 | /// destination type; the upper bits of the src will be lost. |
| 295 | static void CreateCoercedStore(llvm::Value *Src, |
| 296 | llvm::Value *DstPtr, |
| 297 | CodeGenFunction &CGF) { |
| 298 | const llvm::Type *SrcTy = Src->getType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 299 | const llvm::Type *DstTy = |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 300 | cast<llvm::PointerType>(DstPtr->getType())->getElementType(); |
| 301 | |
Duncan Sands | c76fe8b | 2009-05-09 07:08:47 +0000 | [diff] [blame] | 302 | uint64_t SrcSize = CGF.CGM.getTargetData().getTypeAllocSize(SrcTy); |
| 303 | uint64_t DstSize = CGF.CGM.getTargetData().getTypeAllocSize(DstTy); |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 304 | |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 305 | // If store is legal, just bitcast the src pointer. |
Daniel Dunbar | 4be99ff | 2009-06-05 07:58:54 +0000 | [diff] [blame] | 306 | if (SrcSize <= DstSize) { |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 307 | llvm::Value *Casted = |
| 308 | CGF.Builder.CreateBitCast(DstPtr, llvm::PointerType::getUnqual(SrcTy)); |
Daniel Dunbar | ee9e4c2 | 2009-02-07 02:46:03 +0000 | [diff] [blame] | 309 | // FIXME: Use better alignment / avoid requiring aligned store. |
| 310 | CGF.Builder.CreateStore(Src, Casted)->setAlignment(1); |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 311 | } else { |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 312 | // Otherwise do coercion through memory. This is stupid, but |
| 313 | // simple. |
Daniel Dunbar | 4be99ff | 2009-06-05 07:58:54 +0000 | [diff] [blame] | 314 | |
| 315 | // Generally SrcSize is never greater than DstSize, since this means we are |
| 316 | // losing bits. However, this can happen in cases where the structure has |
| 317 | // additional padding, for example due to a user specified alignment. |
| 318 | // |
| 319 | // FIXME: Assert that we aren't truncating non-padding bits when have access |
| 320 | // to that information. |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 321 | llvm::Value *Tmp = CGF.CreateTempAlloca(SrcTy); |
| 322 | CGF.Builder.CreateStore(Src, Tmp); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 323 | llvm::Value *Casted = |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 324 | CGF.Builder.CreateBitCast(Tmp, llvm::PointerType::getUnqual(DstTy)); |
Daniel Dunbar | ee9e4c2 | 2009-02-07 02:46:03 +0000 | [diff] [blame] | 325 | llvm::LoadInst *Load = CGF.Builder.CreateLoad(Casted); |
| 326 | // FIXME: Use better alignment / avoid requiring aligned load. |
| 327 | Load->setAlignment(1); |
| 328 | CGF.Builder.CreateStore(Load, DstPtr); |
Daniel Dunbar | f5589ac | 2009-02-02 19:06:38 +0000 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 332 | /***/ |
| 333 | |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 334 | bool CodeGenModule::ReturnTypeUsesSret(const CGFunctionInfo &FI) { |
Daniel Dunbar | b8b1c67 | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 335 | return FI.getReturnInfo().isIndirect(); |
Daniel Dunbar | 7633cbf | 2009-02-02 21:43:58 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Daniel Dunbar | 7a95ca3 | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 338 | const llvm::FunctionType * |
Daniel Dunbar | 7633cbf | 2009-02-02 21:43:58 +0000 | [diff] [blame] | 339 | CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI, bool IsVariadic) { |
Daniel Dunbar | 7a95ca3 | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 340 | std::vector<const llvm::Type*> ArgTys; |
| 341 | |
| 342 | const llvm::Type *ResultType = 0; |
| 343 | |
Daniel Dunbar | 3668cb2 | 2009-02-02 23:43:58 +0000 | [diff] [blame] | 344 | QualType RetTy = FI.getReturnType(); |
Daniel Dunbar | b52d077 | 2009-02-03 05:59:18 +0000 | [diff] [blame] | 345 | const ABIArgInfo &RetAI = FI.getReturnInfo(); |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 346 | switch (RetAI.getKind()) { |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 347 | case ABIArgInfo::Expand: |
| 348 | assert(0 && "Invalid ABI kind for return argument"); |
| 349 | |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 350 | case ABIArgInfo::Extend: |
Daniel Dunbar | 67dace89 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 351 | case ABIArgInfo::Direct: |
| 352 | ResultType = ConvertType(RetTy); |
| 353 | break; |
| 354 | |
Daniel Dunbar | b8b1c67 | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 355 | case ABIArgInfo::Indirect: { |
| 356 | assert(!RetAI.getIndirectAlign() && "Align unused on indirect return."); |
Owen Anderson | 41a7502 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 357 | ResultType = llvm::Type::getVoidTy(getLLVMContext()); |
Daniel Dunbar | b8b4759 | 2008-09-10 07:00:50 +0000 | [diff] [blame] | 358 | const llvm::Type *STy = ConvertType(RetTy); |
Daniel Dunbar | 7a95ca3 | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 359 | ArgTys.push_back(llvm::PointerType::get(STy, RetTy.getAddressSpace())); |
| 360 | break; |
| 361 | } |
| 362 | |
Daniel Dunbar | 94a6f25 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 363 | case ABIArgInfo::Ignore: |
Owen Anderson | 41a7502 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 364 | ResultType = llvm::Type::getVoidTy(getLLVMContext()); |
Daniel Dunbar | 94a6f25 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 365 | break; |
| 366 | |
Daniel Dunbar | 7a95ca3 | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 367 | case ABIArgInfo::Coerce: |
Daniel Dunbar | 573884e | 2008-09-10 07:04:09 +0000 | [diff] [blame] | 368 | ResultType = RetAI.getCoerceToType(); |
Daniel Dunbar | 7a95ca3 | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 369 | break; |
| 370 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 371 | |
| 372 | for (CGFunctionInfo::const_arg_iterator it = FI.arg_begin(), |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 373 | ie = FI.arg_end(); it != ie; ++it) { |
| 374 | const ABIArgInfo &AI = it->info; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 376 | switch (AI.getKind()) { |
Daniel Dunbar | 94a6f25 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 377 | case ABIArgInfo::Ignore: |
| 378 | break; |
| 379 | |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 380 | case ABIArgInfo::Coerce: |
Daniel Dunbar | 2f219b0 | 2009-02-03 19:12:28 +0000 | [diff] [blame] | 381 | ArgTys.push_back(AI.getCoerceToType()); |
| 382 | break; |
| 383 | |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 384 | case ABIArgInfo::Indirect: { |
Daniel Dunbar | b8b1c67 | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 385 | // indirect arguments are always on the stack, which is addr space #0. |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 386 | const llvm::Type *LTy = ConvertTypeForMem(it->type); |
| 387 | ArgTys.push_back(llvm::PointerType::getUnqual(LTy)); |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 388 | break; |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 389 | } |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 390 | |
| 391 | case ABIArgInfo::Extend: |
Daniel Dunbar | 67dace89 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 392 | case ABIArgInfo::Direct: |
Daniel Dunbar | 747865a | 2009-02-05 09:16:39 +0000 | [diff] [blame] | 393 | ArgTys.push_back(ConvertType(it->type)); |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 394 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 396 | case ABIArgInfo::Expand: |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 397 | GetExpandedTypes(it->type, ArgTys); |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 398 | break; |
| 399 | } |
Daniel Dunbar | 7a95ca3 | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Daniel Dunbar | 7633cbf | 2009-02-02 21:43:58 +0000 | [diff] [blame] | 402 | return llvm::FunctionType::get(ResultType, ArgTys, IsVariadic); |
Daniel Dunbar | 81cf67f | 2008-09-09 23:48:28 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Daniel Dunbar | 3668cb2 | 2009-02-02 23:43:58 +0000 | [diff] [blame] | 405 | void CodeGenModule::ConstructAttributeList(const CGFunctionInfo &FI, |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 406 | const Decl *TargetDecl, |
Devang Patel | 322300d | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 407 | AttributeListType &PAL) { |
Daniel Dunbar | 76c8eb7 | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 408 | unsigned FuncAttrs = 0; |
Devang Patel | 597e708 | 2008-09-26 22:53:57 +0000 | [diff] [blame] | 409 | unsigned RetAttrs = 0; |
Daniel Dunbar | 76c8eb7 | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 410 | |
Anton Korobeynikov | c847824 | 2009-04-04 00:49:24 +0000 | [diff] [blame] | 411 | // FIXME: handle sseregparm someday... |
Daniel Dunbar | 76c8eb7 | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 412 | if (TargetDecl) { |
Argyrios Kyrtzidis | b4b64ca | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 413 | if (TargetDecl->hasAttr<NoThrowAttr>()) |
Devang Patel | 322300d | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 414 | FuncAttrs |= llvm::Attribute::NoUnwind; |
Argyrios Kyrtzidis | b4b64ca | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 415 | if (TargetDecl->hasAttr<NoReturnAttr>()) |
Devang Patel | 322300d | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 416 | FuncAttrs |= llvm::Attribute::NoReturn; |
Argyrios Kyrtzidis | b4b64ca | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 417 | if (TargetDecl->hasAttr<ConstAttr>()) |
Anders Carlsson | b831628 | 2008-10-05 23:32:53 +0000 | [diff] [blame] | 418 | FuncAttrs |= llvm::Attribute::ReadNone; |
Argyrios Kyrtzidis | b4b64ca | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 419 | else if (TargetDecl->hasAttr<PureAttr>()) |
Daniel Dunbar | 8c920c9 | 2009-04-10 22:14:52 +0000 | [diff] [blame] | 420 | FuncAttrs |= llvm::Attribute::ReadOnly; |
Ryan Flynn | 1f1fdc0 | 2009-08-09 20:07:29 +0000 | [diff] [blame] | 421 | if (TargetDecl->hasAttr<MallocAttr>()) |
| 422 | RetAttrs |= llvm::Attribute::NoAlias; |
Daniel Dunbar | 76c8eb7 | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Devang Patel | 6e467b1 | 2009-06-04 23:32:02 +0000 | [diff] [blame] | 425 | if (CompileOpts.DisableRedZone) |
| 426 | FuncAttrs |= llvm::Attribute::NoRedZone; |
Devang Patel | 9e24386 | 2009-06-05 22:05:48 +0000 | [diff] [blame] | 427 | if (CompileOpts.NoImplicitFloat) |
| 428 | FuncAttrs |= llvm::Attribute::NoImplicitFloat; |
Devang Patel | 6e467b1 | 2009-06-04 23:32:02 +0000 | [diff] [blame] | 429 | |
Bill Wendling | 1835107 | 2009-06-28 23:01:01 +0000 | [diff] [blame] | 430 | if (Features.getStackProtectorMode() == LangOptions::SSPOn) |
Bill Wendling | d63bbad | 2009-06-28 07:36:13 +0000 | [diff] [blame] | 431 | FuncAttrs |= llvm::Attribute::StackProtect; |
Bill Wendling | 1835107 | 2009-06-28 23:01:01 +0000 | [diff] [blame] | 432 | else if (Features.getStackProtectorMode() == LangOptions::SSPReq) |
Bill Wendling | d63bbad | 2009-06-28 07:36:13 +0000 | [diff] [blame] | 433 | FuncAttrs |= llvm::Attribute::StackProtectReq; |
| 434 | |
Daniel Dunbar | 3668cb2 | 2009-02-02 23:43:58 +0000 | [diff] [blame] | 435 | QualType RetTy = FI.getReturnType(); |
Daniel Dunbar | 76c8eb7 | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 436 | unsigned Index = 1; |
Daniel Dunbar | b52d077 | 2009-02-03 05:59:18 +0000 | [diff] [blame] | 437 | const ABIArgInfo &RetAI = FI.getReturnInfo(); |
Daniel Dunbar | 7a95ca3 | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 438 | switch (RetAI.getKind()) { |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 439 | case ABIArgInfo::Extend: |
| 440 | if (RetTy->isSignedIntegerType()) { |
| 441 | RetAttrs |= llvm::Attribute::SExt; |
| 442 | } else if (RetTy->isUnsignedIntegerType()) { |
| 443 | RetAttrs |= llvm::Attribute::ZExt; |
| 444 | } |
| 445 | // FALLTHROUGH |
Daniel Dunbar | 67dace89 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 446 | case ABIArgInfo::Direct: |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 447 | break; |
| 448 | |
Daniel Dunbar | b8b1c67 | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 449 | case ABIArgInfo::Indirect: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 450 | PAL.push_back(llvm::AttributeWithIndex::get(Index, |
Daniel Dunbar | 3cd2063 | 2009-01-31 02:19:00 +0000 | [diff] [blame] | 451 | llvm::Attribute::StructRet | |
| 452 | llvm::Attribute::NoAlias)); |
Daniel Dunbar | 76c8eb7 | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 453 | ++Index; |
Daniel Dunbar | c230443 | 2009-03-18 19:51:01 +0000 | [diff] [blame] | 454 | // sret disables readnone and readonly |
| 455 | FuncAttrs &= ~(llvm::Attribute::ReadOnly | |
| 456 | llvm::Attribute::ReadNone); |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 457 | break; |
| 458 | |
Daniel Dunbar | 94a6f25 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 459 | case ABIArgInfo::Ignore: |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 460 | case ABIArgInfo::Coerce: |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 461 | break; |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 462 | |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 463 | case ABIArgInfo::Expand: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 464 | assert(0 && "Invalid ABI kind for return argument"); |
Daniel Dunbar | 76c8eb7 | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 465 | } |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 466 | |
Devang Patel | 597e708 | 2008-09-26 22:53:57 +0000 | [diff] [blame] | 467 | if (RetAttrs) |
| 468 | PAL.push_back(llvm::AttributeWithIndex::get(0, RetAttrs)); |
Anton Korobeynikov | c847824 | 2009-04-04 00:49:24 +0000 | [diff] [blame] | 469 | |
| 470 | // FIXME: we need to honour command line settings also... |
| 471 | // FIXME: RegParm should be reduced in case of nested functions and/or global |
| 472 | // register variable. |
| 473 | signed RegParm = 0; |
| 474 | if (TargetDecl) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 475 | if (const RegparmAttr *RegParmAttr |
Argyrios Kyrtzidis | b4b64ca | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 476 | = TargetDecl->getAttr<RegparmAttr>()) |
Anton Korobeynikov | c847824 | 2009-04-04 00:49:24 +0000 | [diff] [blame] | 477 | RegParm = RegParmAttr->getNumParams(); |
| 478 | |
| 479 | unsigned PointerWidth = getContext().Target.getPointerWidth(0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 480 | for (CGFunctionInfo::const_arg_iterator it = FI.arg_begin(), |
Daniel Dunbar | 313321e | 2009-02-03 05:31:23 +0000 | [diff] [blame] | 481 | ie = FI.arg_end(); it != ie; ++it) { |
| 482 | QualType ParamType = it->type; |
| 483 | const ABIArgInfo &AI = it->info; |
Devang Patel | 322300d | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 484 | unsigned Attributes = 0; |
Anton Korobeynikov | c847824 | 2009-04-04 00:49:24 +0000 | [diff] [blame] | 485 | |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 486 | switch (AI.getKind()) { |
Daniel Dunbar | 2f219b0 | 2009-02-03 19:12:28 +0000 | [diff] [blame] | 487 | case ABIArgInfo::Coerce: |
| 488 | break; |
| 489 | |
Daniel Dunbar | b8b1c67 | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 490 | case ABIArgInfo::Indirect: |
Devang Patel | 322300d | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 491 | Attributes |= llvm::Attribute::ByVal; |
Anton Korobeynikov | c847824 | 2009-04-04 00:49:24 +0000 | [diff] [blame] | 492 | Attributes |= |
Daniel Dunbar | b8b1c67 | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 493 | llvm::Attribute::constructAlignmentFromInt(AI.getIndirectAlign()); |
Daniel Dunbar | c230443 | 2009-03-18 19:51:01 +0000 | [diff] [blame] | 494 | // byval disables readnone and readonly. |
| 495 | FuncAttrs &= ~(llvm::Attribute::ReadOnly | |
| 496 | llvm::Attribute::ReadNone); |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 497 | break; |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 498 | |
| 499 | case ABIArgInfo::Extend: |
| 500 | if (ParamType->isSignedIntegerType()) { |
| 501 | Attributes |= llvm::Attribute::SExt; |
| 502 | } else if (ParamType->isUnsignedIntegerType()) { |
| 503 | Attributes |= llvm::Attribute::ZExt; |
| 504 | } |
| 505 | // FALLS THROUGH |
Daniel Dunbar | 67dace89 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 506 | case ABIArgInfo::Direct: |
Anton Korobeynikov | c847824 | 2009-04-04 00:49:24 +0000 | [diff] [blame] | 507 | if (RegParm > 0 && |
| 508 | (ParamType->isIntegerType() || ParamType->isPointerType())) { |
| 509 | RegParm -= |
| 510 | (Context.getTypeSize(ParamType) + PointerWidth - 1) / PointerWidth; |
| 511 | if (RegParm >= 0) |
| 512 | Attributes |= llvm::Attribute::InReg; |
| 513 | } |
| 514 | // FIXME: handle sseregparm someday... |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 515 | break; |
Anton Korobeynikov | c847824 | 2009-04-04 00:49:24 +0000 | [diff] [blame] | 516 | |
Daniel Dunbar | 94a6f25 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 517 | case ABIArgInfo::Ignore: |
| 518 | // Skip increment, no matching LLVM parameter. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | continue; |
Daniel Dunbar | 94a6f25 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 520 | |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 521 | case ABIArgInfo::Expand: { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 522 | std::vector<const llvm::Type*> Tys; |
Mike Stump | 18bb928 | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 523 | // FIXME: This is rather inefficient. Do we ever actually need to do |
| 524 | // anything here? The result should be just reconstructed on the other |
| 525 | // side, so extension should be a non-issue. |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 526 | getTypes().GetExpandedTypes(ParamType, Tys); |
| 527 | Index += Tys.size(); |
| 528 | continue; |
| 529 | } |
Daniel Dunbar | 76c8eb7 | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 530 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 531 | |
Devang Patel | 322300d | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 532 | if (Attributes) |
| 533 | PAL.push_back(llvm::AttributeWithIndex::get(Index, Attributes)); |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 534 | ++Index; |
Daniel Dunbar | 76c8eb7 | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 535 | } |
Devang Patel | 597e708 | 2008-09-26 22:53:57 +0000 | [diff] [blame] | 536 | if (FuncAttrs) |
| 537 | PAL.push_back(llvm::AttributeWithIndex::get(~0, FuncAttrs)); |
Daniel Dunbar | 76c8eb7 | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 538 | } |
| 539 | |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 540 | void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, |
| 541 | llvm::Function *Fn, |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 542 | const FunctionArgList &Args) { |
John McCall | caa1945 | 2009-07-28 01:00:58 +0000 | [diff] [blame] | 543 | // If this is an implicit-return-zero function, go ahead and |
| 544 | // initialize the return value. TODO: it might be nice to have |
| 545 | // a more general mechanism for this that didn't require synthesized |
| 546 | // return statements. |
Anders Carlsson | b8be93f | 2009-08-08 23:24:23 +0000 | [diff] [blame] | 547 | if (const FunctionDecl* FD = dyn_cast_or_null<FunctionDecl>(CurFuncDecl)) { |
John McCall | caa1945 | 2009-07-28 01:00:58 +0000 | [diff] [blame] | 548 | if (FD->hasImplicitReturnZero()) { |
| 549 | QualType RetTy = FD->getResultType().getUnqualifiedType(); |
| 550 | const llvm::Type* LLVMTy = CGM.getTypes().ConvertType(RetTy); |
Owen Anderson | 0b75f23 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 551 | llvm::Constant* Zero = llvm::Constant::getNullValue(LLVMTy); |
John McCall | caa1945 | 2009-07-28 01:00:58 +0000 | [diff] [blame] | 552 | Builder.CreateStore(Zero, ReturnValue); |
| 553 | } |
| 554 | } |
| 555 | |
Mike Stump | 18bb928 | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 556 | // FIXME: We no longer need the types from FunctionArgList; lift up and |
| 557 | // simplify. |
Daniel Dunbar | 5a0acdc9 | 2009-02-03 06:02:10 +0000 | [diff] [blame] | 558 | |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 559 | // Emit allocs for param decls. Give the LLVM Argument nodes names. |
| 560 | llvm::Function::arg_iterator AI = Fn->arg_begin(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 561 | |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 562 | // Name the struct return argument. |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 563 | if (CGM.ReturnTypeUsesSret(FI)) { |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 564 | AI->setName("agg.result"); |
| 565 | ++AI; |
| 566 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 567 | |
Daniel Dunbar | a45bdbb | 2009-02-04 21:17:21 +0000 | [diff] [blame] | 568 | assert(FI.arg_size() == Args.size() && |
| 569 | "Mismatch between function signature & arguments."); |
Daniel Dunbar | b52d077 | 2009-02-03 05:59:18 +0000 | [diff] [blame] | 570 | CGFunctionInfo::const_arg_iterator info_it = FI.arg_begin(); |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 571 | for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end(); |
Daniel Dunbar | b52d077 | 2009-02-03 05:59:18 +0000 | [diff] [blame] | 572 | i != e; ++i, ++info_it) { |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 573 | const VarDecl *Arg = i->first; |
Daniel Dunbar | b52d077 | 2009-02-03 05:59:18 +0000 | [diff] [blame] | 574 | QualType Ty = info_it->type; |
| 575 | const ABIArgInfo &ArgI = info_it->info; |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 576 | |
| 577 | switch (ArgI.getKind()) { |
Daniel Dunbar | 747865a | 2009-02-05 09:16:39 +0000 | [diff] [blame] | 578 | case ABIArgInfo::Indirect: { |
| 579 | llvm::Value* V = AI; |
| 580 | if (hasAggregateLLVMType(Ty)) { |
| 581 | // Do nothing, aggregates and complex variables are accessed by |
| 582 | // reference. |
| 583 | } else { |
| 584 | // Load scalar value from indirect argument. |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 585 | V = EmitLoadOfScalar(V, false, Ty); |
Daniel Dunbar | 747865a | 2009-02-05 09:16:39 +0000 | [diff] [blame] | 586 | if (!getContext().typesAreCompatible(Ty, Arg->getType())) { |
| 587 | // This must be a promotion, for something like |
| 588 | // "void a(x) short x; {..." |
| 589 | V = EmitScalarConversion(V, Ty, Arg->getType()); |
| 590 | } |
| 591 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 592 | EmitParmDecl(*Arg, V); |
Daniel Dunbar | 747865a | 2009-02-05 09:16:39 +0000 | [diff] [blame] | 593 | break; |
| 594 | } |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 595 | |
| 596 | case ABIArgInfo::Extend: |
Daniel Dunbar | 67dace89 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 597 | case ABIArgInfo::Direct: { |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 598 | assert(AI != Fn->arg_end() && "Argument mismatch!"); |
| 599 | llvm::Value* V = AI; |
Daniel Dunbar | 5d3dbd6 | 2009-02-05 11:13:54 +0000 | [diff] [blame] | 600 | if (hasAggregateLLVMType(Ty)) { |
| 601 | // Create a temporary alloca to hold the argument; the rest of |
| 602 | // codegen expects to access aggregates & complex values by |
| 603 | // reference. |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 604 | V = CreateTempAlloca(ConvertTypeForMem(Ty)); |
Daniel Dunbar | 5d3dbd6 | 2009-02-05 11:13:54 +0000 | [diff] [blame] | 605 | Builder.CreateStore(AI, V); |
| 606 | } else { |
| 607 | if (!getContext().typesAreCompatible(Ty, Arg->getType())) { |
| 608 | // This must be a promotion, for something like |
| 609 | // "void a(x) short x; {..." |
| 610 | V = EmitScalarConversion(V, Ty, Arg->getType()); |
| 611 | } |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 612 | } |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 613 | EmitParmDecl(*Arg, V); |
| 614 | break; |
| 615 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 616 | |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 617 | case ABIArgInfo::Expand: { |
Daniel Dunbar | b52d077 | 2009-02-03 05:59:18 +0000 | [diff] [blame] | 618 | // If this structure was expanded into multiple arguments then |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 619 | // we need to create a temporary and reconstruct it from the |
| 620 | // arguments. |
Chris Lattner | 1cbaacc | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 621 | std::string Name = Arg->getNameAsString(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 622 | llvm::Value *Temp = CreateTempAlloca(ConvertTypeForMem(Ty), |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 623 | (Name + ".addr").c_str()); |
| 624 | // FIXME: What are the right qualifiers here? |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 625 | llvm::Function::arg_iterator End = |
| 626 | ExpandTypeFromArgs(Ty, LValue::MakeAddr(Temp,0), AI); |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 627 | EmitParmDecl(*Arg, Temp); |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 628 | |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 629 | // Name the arguments used in expansion and increment AI. |
| 630 | unsigned Index = 0; |
| 631 | for (; AI != End; ++AI, ++Index) |
Daniel Dunbar | 4074b931 | 2009-08-02 01:43:57 +0000 | [diff] [blame] | 632 | AI->setName(Name + "." + llvm::Twine(Index)); |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 633 | continue; |
| 634 | } |
Daniel Dunbar | 94a6f25 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 635 | |
| 636 | case ABIArgInfo::Ignore: |
Daniel Dunbar | d5f1f55 | 2009-02-10 00:06:49 +0000 | [diff] [blame] | 637 | // Initialize the local variable appropriately. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 638 | if (hasAggregateLLVMType(Ty)) { |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 639 | EmitParmDecl(*Arg, CreateTempAlloca(ConvertTypeForMem(Ty))); |
Daniel Dunbar | d5f1f55 | 2009-02-10 00:06:49 +0000 | [diff] [blame] | 640 | } else { |
| 641 | EmitParmDecl(*Arg, llvm::UndefValue::get(ConvertType(Arg->getType()))); |
| 642 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 643 | |
Daniel Dunbar | fc7c761 | 2009-02-03 20:00:13 +0000 | [diff] [blame] | 644 | // Skip increment, no matching LLVM parameter. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 645 | continue; |
Daniel Dunbar | 94a6f25 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 646 | |
Daniel Dunbar | 2f219b0 | 2009-02-03 19:12:28 +0000 | [diff] [blame] | 647 | case ABIArgInfo::Coerce: { |
| 648 | assert(AI != Fn->arg_end() && "Argument mismatch!"); |
Mike Stump | 18bb928 | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 649 | // FIXME: This is very wasteful; EmitParmDecl is just going to drop the |
| 650 | // result in a new alloca anyway, so we could just store into that |
| 651 | // directly if we broke the abstraction down more. |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 652 | llvm::Value *V = CreateTempAlloca(ConvertTypeForMem(Ty), "coerce"); |
Daniel Dunbar | 2f219b0 | 2009-02-03 19:12:28 +0000 | [diff] [blame] | 653 | CreateCoercedStore(AI, V, *this); |
| 654 | // Match to what EmitParmDecl is expecting for this type. |
Daniel Dunbar | 6e3b7df | 2009-02-04 07:22:24 +0000 | [diff] [blame] | 655 | if (!CodeGenFunction::hasAggregateLLVMType(Ty)) { |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 656 | V = EmitLoadOfScalar(V, false, Ty); |
Daniel Dunbar | 6e3b7df | 2009-02-04 07:22:24 +0000 | [diff] [blame] | 657 | if (!getContext().typesAreCompatible(Ty, Arg->getType())) { |
| 658 | // This must be a promotion, for something like |
| 659 | // "void a(x) short x; {..." |
| 660 | V = EmitScalarConversion(V, Ty, Arg->getType()); |
| 661 | } |
| 662 | } |
Daniel Dunbar | 2f219b0 | 2009-02-03 19:12:28 +0000 | [diff] [blame] | 663 | EmitParmDecl(*Arg, V); |
| 664 | break; |
| 665 | } |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 666 | } |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 667 | |
| 668 | ++AI; |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 669 | } |
| 670 | assert(AI == Fn->arg_end() && "Argument mismatch!"); |
| 671 | } |
| 672 | |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 673 | void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI, |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 674 | llvm::Value *ReturnValue) { |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 675 | llvm::Value *RV = 0; |
| 676 | |
| 677 | // Functions with no result always return void. |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 678 | if (ReturnValue) { |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 679 | QualType RetTy = FI.getReturnType(); |
Daniel Dunbar | b52d077 | 2009-02-03 05:59:18 +0000 | [diff] [blame] | 680 | const ABIArgInfo &RetAI = FI.getReturnInfo(); |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 681 | |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 682 | switch (RetAI.getKind()) { |
Daniel Dunbar | b8b1c67 | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 683 | case ABIArgInfo::Indirect: |
Daniel Dunbar | 9ae0afd | 2008-12-18 04:52:14 +0000 | [diff] [blame] | 684 | if (RetTy->isAnyComplexType()) { |
Daniel Dunbar | 9ae0afd | 2008-12-18 04:52:14 +0000 | [diff] [blame] | 685 | ComplexPairTy RT = LoadComplexFromAddr(ReturnValue, false); |
| 686 | StoreComplexToAddr(RT, CurFn->arg_begin(), false); |
| 687 | } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) { |
| 688 | EmitAggregateCopy(CurFn->arg_begin(), ReturnValue, RetTy); |
| 689 | } else { |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 690 | EmitStoreOfScalar(Builder.CreateLoad(ReturnValue), CurFn->arg_begin(), |
Anders Carlsson | 8370964 | 2009-05-19 18:50:41 +0000 | [diff] [blame] | 691 | false, RetTy); |
Daniel Dunbar | 9ae0afd | 2008-12-18 04:52:14 +0000 | [diff] [blame] | 692 | } |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 693 | break; |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 694 | |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 695 | case ABIArgInfo::Extend: |
Daniel Dunbar | 67dace89 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 696 | case ABIArgInfo::Direct: |
Daniel Dunbar | 5d3dbd6 | 2009-02-05 11:13:54 +0000 | [diff] [blame] | 697 | // The internal return value temp always will have |
| 698 | // pointer-to-return-type type. |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 699 | RV = Builder.CreateLoad(ReturnValue); |
| 700 | break; |
| 701 | |
Daniel Dunbar | 94a6f25 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 702 | case ABIArgInfo::Ignore: |
| 703 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 704 | |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 705 | case ABIArgInfo::Coerce: |
Daniel Dunbar | 0f4aa3c | 2009-01-27 01:36:03 +0000 | [diff] [blame] | 706 | RV = CreateCoercedLoad(ReturnValue, RetAI.getCoerceToType(), *this); |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 707 | break; |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 708 | |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 709 | case ABIArgInfo::Expand: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | assert(0 && "Invalid ABI kind for return argument"); |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 711 | } |
| 712 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 713 | |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 714 | if (RV) { |
| 715 | Builder.CreateRet(RV); |
| 716 | } else { |
| 717 | Builder.CreateRetVoid(); |
| 718 | } |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 719 | } |
| 720 | |
Anders Carlsson | 60ce3fe | 2009-04-08 20:47:54 +0000 | [diff] [blame] | 721 | RValue CodeGenFunction::EmitCallArg(const Expr *E, QualType ArgType) { |
Anders Carlsson | 6f5a015 | 2009-05-20 00:24:07 +0000 | [diff] [blame] | 722 | if (ArgType->isReferenceType()) |
| 723 | return EmitReferenceBindingToExpr(E, ArgType); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 724 | |
Anders Carlsson | 60ce3fe | 2009-04-08 20:47:54 +0000 | [diff] [blame] | 725 | return EmitAnyExprToTemp(E); |
| 726 | } |
| 727 | |
Daniel Dunbar | d931a87 | 2009-02-02 22:03:45 +0000 | [diff] [blame] | 728 | RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 729 | llvm::Value *Callee, |
Daniel Dunbar | cdbb5e3 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 730 | const CallArgList &CallArgs, |
| 731 | const Decl *TargetDecl) { |
Mike Stump | 18bb928 | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 732 | // FIXME: We no longer need the types from CallArgs; lift up and simplify. |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 733 | llvm::SmallVector<llvm::Value*, 16> Args; |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 734 | |
| 735 | // Handle struct-return functions by passing a pointer to the |
| 736 | // location that we would like to return into. |
Daniel Dunbar | 7633cbf | 2009-02-02 21:43:58 +0000 | [diff] [blame] | 737 | QualType RetTy = CallInfo.getReturnType(); |
Daniel Dunbar | b52d077 | 2009-02-03 05:59:18 +0000 | [diff] [blame] | 738 | const ABIArgInfo &RetAI = CallInfo.getReturnInfo(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | |
| 740 | |
Chris Lattner | 4ca97c3 | 2009-06-13 00:26:38 +0000 | [diff] [blame] | 741 | // If the call returns a temporary with struct return, create a temporary |
| 742 | // alloca to hold the result. |
| 743 | if (CGM.ReturnTypeUsesSret(CallInfo)) |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 744 | Args.push_back(CreateTempAlloca(ConvertTypeForMem(RetTy))); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 745 | |
Daniel Dunbar | a45bdbb | 2009-02-04 21:17:21 +0000 | [diff] [blame] | 746 | assert(CallInfo.arg_size() == CallArgs.size() && |
| 747 | "Mismatch between function signature & arguments."); |
Daniel Dunbar | b52d077 | 2009-02-03 05:59:18 +0000 | [diff] [blame] | 748 | CGFunctionInfo::const_arg_iterator info_it = CallInfo.arg_begin(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 749 | for (CallArgList::const_iterator I = CallArgs.begin(), E = CallArgs.end(); |
Daniel Dunbar | b52d077 | 2009-02-03 05:59:18 +0000 | [diff] [blame] | 750 | I != E; ++I, ++info_it) { |
| 751 | const ABIArgInfo &ArgInfo = info_it->info; |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 752 | RValue RV = I->first; |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 753 | |
| 754 | switch (ArgInfo.getKind()) { |
Daniel Dunbar | b8b1c67 | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 755 | case ABIArgInfo::Indirect: |
Daniel Dunbar | 747865a | 2009-02-05 09:16:39 +0000 | [diff] [blame] | 756 | if (RV.isScalar() || RV.isComplex()) { |
| 757 | // Make a temporary alloca to pass the argument. |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 758 | Args.push_back(CreateTempAlloca(ConvertTypeForMem(I->second))); |
Daniel Dunbar | 747865a | 2009-02-05 09:16:39 +0000 | [diff] [blame] | 759 | if (RV.isScalar()) |
Anders Carlsson | 8370964 | 2009-05-19 18:50:41 +0000 | [diff] [blame] | 760 | EmitStoreOfScalar(RV.getScalarVal(), Args.back(), false, I->second); |
Daniel Dunbar | 747865a | 2009-02-05 09:16:39 +0000 | [diff] [blame] | 761 | else |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | StoreComplexToAddr(RV.getComplexVal(), Args.back(), false); |
Daniel Dunbar | 747865a | 2009-02-05 09:16:39 +0000 | [diff] [blame] | 763 | } else { |
| 764 | Args.push_back(RV.getAggregateAddr()); |
| 765 | } |
| 766 | break; |
| 767 | |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 768 | case ABIArgInfo::Extend: |
Daniel Dunbar | 67dace89 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 769 | case ABIArgInfo::Direct: |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 770 | if (RV.isScalar()) { |
| 771 | Args.push_back(RV.getScalarVal()); |
| 772 | } else if (RV.isComplex()) { |
Daniel Dunbar | 5d3dbd6 | 2009-02-05 11:13:54 +0000 | [diff] [blame] | 773 | llvm::Value *Tmp = llvm::UndefValue::get(ConvertType(I->second)); |
| 774 | Tmp = Builder.CreateInsertValue(Tmp, RV.getComplexVal().first, 0); |
| 775 | Tmp = Builder.CreateInsertValue(Tmp, RV.getComplexVal().second, 1); |
| 776 | Args.push_back(Tmp); |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 777 | } else { |
Daniel Dunbar | 5d3dbd6 | 2009-02-05 11:13:54 +0000 | [diff] [blame] | 778 | Args.push_back(Builder.CreateLoad(RV.getAggregateAddr())); |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 779 | } |
| 780 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 781 | |
Daniel Dunbar | 94a6f25 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 782 | case ABIArgInfo::Ignore: |
| 783 | break; |
| 784 | |
Daniel Dunbar | 2f219b0 | 2009-02-03 19:12:28 +0000 | [diff] [blame] | 785 | case ABIArgInfo::Coerce: { |
| 786 | // FIXME: Avoid the conversion through memory if possible. |
| 787 | llvm::Value *SrcPtr; |
| 788 | if (RV.isScalar()) { |
Daniel Dunbar | a334611 | 2009-02-03 23:04:57 +0000 | [diff] [blame] | 789 | SrcPtr = CreateTempAlloca(ConvertTypeForMem(I->second), "coerce"); |
Anders Carlsson | 8370964 | 2009-05-19 18:50:41 +0000 | [diff] [blame] | 790 | EmitStoreOfScalar(RV.getScalarVal(), SrcPtr, false, I->second); |
Daniel Dunbar | 2f219b0 | 2009-02-03 19:12:28 +0000 | [diff] [blame] | 791 | } else if (RV.isComplex()) { |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 792 | SrcPtr = CreateTempAlloca(ConvertTypeForMem(I->second), "coerce"); |
Daniel Dunbar | 2f219b0 | 2009-02-03 19:12:28 +0000 | [diff] [blame] | 793 | StoreComplexToAddr(RV.getComplexVal(), SrcPtr, false); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 794 | } else |
Daniel Dunbar | 2f219b0 | 2009-02-03 19:12:28 +0000 | [diff] [blame] | 795 | SrcPtr = RV.getAggregateAddr(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 796 | Args.push_back(CreateCoercedLoad(SrcPtr, ArgInfo.getCoerceToType(), |
Daniel Dunbar | 2f219b0 | 2009-02-03 19:12:28 +0000 | [diff] [blame] | 797 | *this)); |
| 798 | break; |
| 799 | } |
| 800 | |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 801 | case ABIArgInfo::Expand: |
| 802 | ExpandTypeToArgs(I->second, RV, Args); |
| 803 | break; |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 804 | } |
| 805 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 806 | |
Chris Lattner | 4ca97c3 | 2009-06-13 00:26:38 +0000 | [diff] [blame] | 807 | // If the callee is a bitcast of a function to a varargs pointer to function |
| 808 | // type, check to see if we can remove the bitcast. This handles some cases |
| 809 | // with unprototyped functions. |
| 810 | if (llvm::ConstantExpr *CE = dyn_cast<llvm::ConstantExpr>(Callee)) |
| 811 | if (llvm::Function *CalleeF = dyn_cast<llvm::Function>(CE->getOperand(0))) { |
| 812 | const llvm::PointerType *CurPT=cast<llvm::PointerType>(Callee->getType()); |
| 813 | const llvm::FunctionType *CurFT = |
| 814 | cast<llvm::FunctionType>(CurPT->getElementType()); |
| 815 | const llvm::FunctionType *ActualFT = CalleeF->getFunctionType(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 816 | |
Chris Lattner | 4ca97c3 | 2009-06-13 00:26:38 +0000 | [diff] [blame] | 817 | if (CE->getOpcode() == llvm::Instruction::BitCast && |
| 818 | ActualFT->getReturnType() == CurFT->getReturnType() && |
Chris Lattner | 4c8da96 | 2009-06-23 01:38:41 +0000 | [diff] [blame] | 819 | ActualFT->getNumParams() == CurFT->getNumParams() && |
| 820 | ActualFT->getNumParams() == Args.size()) { |
Chris Lattner | 4ca97c3 | 2009-06-13 00:26:38 +0000 | [diff] [blame] | 821 | bool ArgsMatch = true; |
| 822 | for (unsigned i = 0, e = ActualFT->getNumParams(); i != e; ++i) |
| 823 | if (ActualFT->getParamType(i) != CurFT->getParamType(i)) { |
| 824 | ArgsMatch = false; |
| 825 | break; |
| 826 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 827 | |
Chris Lattner | 4ca97c3 | 2009-06-13 00:26:38 +0000 | [diff] [blame] | 828 | // Strip the cast if we can get away with it. This is a nice cleanup, |
| 829 | // but also allows us to inline the function at -O0 if it is marked |
| 830 | // always_inline. |
| 831 | if (ArgsMatch) |
| 832 | Callee = CalleeF; |
| 833 | } |
| 834 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 835 | |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 836 | |
Daniel Dunbar | 1234749 | 2009-02-23 17:26:39 +0000 | [diff] [blame] | 837 | llvm::BasicBlock *InvokeDest = getInvokeDest(); |
Devang Patel | 322300d | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 838 | CodeGen::AttributeListType AttributeList; |
Daniel Dunbar | cdbb5e3 | 2009-02-20 18:06:48 +0000 | [diff] [blame] | 839 | CGM.ConstructAttributeList(CallInfo, TargetDecl, AttributeList); |
Daniel Dunbar | 1234749 | 2009-02-23 17:26:39 +0000 | [diff] [blame] | 840 | llvm::AttrListPtr Attrs = llvm::AttrListPtr::get(AttributeList.begin(), |
| 841 | AttributeList.end()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 842 | |
Daniel Dunbar | b960b7b | 2009-03-02 04:32:35 +0000 | [diff] [blame] | 843 | llvm::CallSite CS; |
| 844 | if (!InvokeDest || (Attrs.getFnAttributes() & llvm::Attribute::NoUnwind)) { |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 845 | CS = Builder.CreateCall(Callee, Args.data(), Args.data()+Args.size()); |
Daniel Dunbar | 1234749 | 2009-02-23 17:26:39 +0000 | [diff] [blame] | 846 | } else { |
| 847 | llvm::BasicBlock *Cont = createBasicBlock("invoke.cont"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 848 | CS = Builder.CreateInvoke(Callee, Cont, InvokeDest, |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 849 | Args.data(), Args.data()+Args.size()); |
Daniel Dunbar | 1234749 | 2009-02-23 17:26:39 +0000 | [diff] [blame] | 850 | EmitBlock(Cont); |
Daniel Dunbar | 5006f4a | 2009-02-20 18:54:31 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Daniel Dunbar | b960b7b | 2009-03-02 04:32:35 +0000 | [diff] [blame] | 853 | CS.setAttributes(Attrs); |
Daniel Dunbar | bbaeca4 | 2009-09-11 22:25:00 +0000 | [diff] [blame] | 854 | llvm::CallingConv::ID CC = |
| 855 | static_cast<llvm::CallingConv::ID>(CallInfo.getCallingConvention()); |
| 856 | CS.setCallingConv(CC); |
Daniel Dunbar | b960b7b | 2009-03-02 04:32:35 +0000 | [diff] [blame] | 857 | |
| 858 | // If the call doesn't return, finish the basic block and clear the |
| 859 | // insertion point; this allows the rest of IRgen to discard |
| 860 | // unreachable code. |
| 861 | if (CS.doesNotReturn()) { |
| 862 | Builder.CreateUnreachable(); |
| 863 | Builder.ClearInsertionPoint(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 864 | |
Mike Stump | 18bb928 | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 865 | // FIXME: For now, emit a dummy basic block because expr emitters in |
| 866 | // generally are not ready to handle emitting expressions at unreachable |
| 867 | // points. |
Daniel Dunbar | b960b7b | 2009-03-02 04:32:35 +0000 | [diff] [blame] | 868 | EnsureInsertPoint(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 869 | |
Daniel Dunbar | b960b7b | 2009-03-02 04:32:35 +0000 | [diff] [blame] | 870 | // Return a reasonable RValue. |
| 871 | return GetUndefRValue(RetTy); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 872 | } |
Daniel Dunbar | b960b7b | 2009-03-02 04:32:35 +0000 | [diff] [blame] | 873 | |
| 874 | llvm::Instruction *CI = CS.getInstruction(); |
Owen Anderson | 41a7502 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 875 | if (Builder.isNamePreserving() && |
| 876 | CI->getType() != llvm::Type::getVoidTy(VMContext)) |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 877 | CI->setName("call"); |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 878 | |
| 879 | switch (RetAI.getKind()) { |
Daniel Dunbar | b8b1c67 | 2009-02-05 08:00:50 +0000 | [diff] [blame] | 880 | case ABIArgInfo::Indirect: |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 881 | if (RetTy->isAnyComplexType()) |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 882 | return RValue::getComplex(LoadComplexFromAddr(Args[0], false)); |
Chris Lattner | e09ad90 | 2009-03-22 00:32:22 +0000 | [diff] [blame] | 883 | if (CodeGenFunction::hasAggregateLLVMType(RetTy)) |
Daniel Dunbar | 8fc81b0 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 884 | return RValue::getAggregate(Args[0]); |
Chris Lattner | e09ad90 | 2009-03-22 00:32:22 +0000 | [diff] [blame] | 885 | return RValue::get(EmitLoadOfScalar(Args[0], false, RetTy)); |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 886 | |
Anton Korobeynikov | 18adbf5 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 887 | case ABIArgInfo::Extend: |
Daniel Dunbar | 67dace89 | 2009-02-03 06:17:37 +0000 | [diff] [blame] | 888 | case ABIArgInfo::Direct: |
Daniel Dunbar | 5d3dbd6 | 2009-02-05 11:13:54 +0000 | [diff] [blame] | 889 | if (RetTy->isAnyComplexType()) { |
| 890 | llvm::Value *Real = Builder.CreateExtractValue(CI, 0); |
| 891 | llvm::Value *Imag = Builder.CreateExtractValue(CI, 1); |
| 892 | return RValue::getComplex(std::make_pair(Real, Imag)); |
Chris Lattner | e09ad90 | 2009-03-22 00:32:22 +0000 | [diff] [blame] | 893 | } |
| 894 | if (CodeGenFunction::hasAggregateLLVMType(RetTy)) { |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 895 | llvm::Value *V = CreateTempAlloca(ConvertTypeForMem(RetTy), "agg.tmp"); |
Daniel Dunbar | 5d3dbd6 | 2009-02-05 11:13:54 +0000 | [diff] [blame] | 896 | Builder.CreateStore(CI, V); |
| 897 | return RValue::getAggregate(V); |
Chris Lattner | e09ad90 | 2009-03-22 00:32:22 +0000 | [diff] [blame] | 898 | } |
| 899 | return RValue::get(CI); |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 900 | |
Daniel Dunbar | 94a6f25 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 901 | case ABIArgInfo::Ignore: |
Daniel Dunbar | 0136282 | 2009-02-03 06:30:17 +0000 | [diff] [blame] | 902 | // If we are ignoring an argument that had a result, make sure to |
| 903 | // construct the appropriate return value for our caller. |
Daniel Dunbar | c79407f | 2009-02-05 07:09:07 +0000 | [diff] [blame] | 904 | return GetUndefRValue(RetTy); |
Daniel Dunbar | 94a6f25 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 905 | |
Daniel Dunbar | 573884e | 2008-09-10 07:04:09 +0000 | [diff] [blame] | 906 | case ABIArgInfo::Coerce: { |
Daniel Dunbar | 2f219b0 | 2009-02-03 19:12:28 +0000 | [diff] [blame] | 907 | // FIXME: Avoid the conversion through memory if possible. |
Daniel Dunbar | 9bfb4de | 2009-02-10 01:51:39 +0000 | [diff] [blame] | 908 | llvm::Value *V = CreateTempAlloca(ConvertTypeForMem(RetTy), "coerce"); |
Daniel Dunbar | 0f4aa3c | 2009-01-27 01:36:03 +0000 | [diff] [blame] | 909 | CreateCoercedStore(CI, V, *this); |
Anders Carlsson | 32ef8ce | 2008-11-25 22:21:48 +0000 | [diff] [blame] | 910 | if (RetTy->isAnyComplexType()) |
| 911 | return RValue::getComplex(LoadComplexFromAddr(V, false)); |
Chris Lattner | e09ad90 | 2009-03-22 00:32:22 +0000 | [diff] [blame] | 912 | if (CodeGenFunction::hasAggregateLLVMType(RetTy)) |
Anders Carlsson | 32ef8ce | 2008-11-25 22:21:48 +0000 | [diff] [blame] | 913 | return RValue::getAggregate(V); |
Chris Lattner | e09ad90 | 2009-03-22 00:32:22 +0000 | [diff] [blame] | 914 | return RValue::get(EmitLoadOfScalar(V, false, RetTy)); |
Daniel Dunbar | 573884e | 2008-09-10 07:04:09 +0000 | [diff] [blame] | 915 | } |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 916 | |
Daniel Dunbar | d3674e6 | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 917 | case ABIArgInfo::Expand: |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 918 | assert(0 && "Invalid ABI kind for return argument"); |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 919 | } |
Daniel Dunbar | a72d4ae | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 920 | |
| 921 | assert(0 && "Unhandled ABIArgInfo::Kind"); |
| 922 | return RValue::get(0); |
Daniel Dunbar | 613855c | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 923 | } |
Daniel Dunbar | 2d0746f | 2009-02-10 20:44:09 +0000 | [diff] [blame] | 924 | |
| 925 | /* VarArg handling */ |
| 926 | |
| 927 | llvm::Value *CodeGenFunction::EmitVAArg(llvm::Value *VAListAddr, QualType Ty) { |
| 928 | return CGM.getTypes().getABIInfo().EmitVAArg(VAListAddr, Ty, *this); |
| 929 | } |