Daniel Dunbar | 0dbe227 | 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 | b768807 | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 17 | #include "CodeGenModule.h" |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 18 | #include "clang/Basic/TargetInfo.h" |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTContext.h" |
| 20 | #include "clang/AST/Decl.h" |
| 21 | #include "clang/AST/DeclObjC.h" |
Daniel Dunbar | 99037e5 | 2009-01-29 08:13:58 +0000 | [diff] [blame] | 22 | #include "clang/AST/RecordLayout.h" |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringExtras.h" |
Devang Patel | d0646bd | 2008-09-24 01:01:36 +0000 | [diff] [blame] | 24 | #include "llvm/Attributes.h" |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 25 | #include "llvm/Support/CommandLine.h" |
Daniel Dunbar | 54d1ccb | 2009-01-27 01:36:03 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetData.h" |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 27 | using namespace clang; |
| 28 | using namespace CodeGen; |
| 29 | |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 30 | static llvm::cl::opt<bool> |
| 31 | UseX86_64ABI("use-x86_64-abi", |
| 32 | llvm::cl::desc("Enable use of experimental x86_64 ABI."), |
| 33 | llvm::cl::init(false)); |
| 34 | |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 35 | /***/ |
| 36 | |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 37 | // FIXME: Use iterator and sidestep silly type array creation. |
| 38 | |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 39 | CGFunctionInfo::CGFunctionInfo(const FunctionTypeNoProto *FTNP) |
| 40 | : IsVariadic(true) |
| 41 | { |
| 42 | ArgTypes.push_back(FTNP->getResultType()); |
| 43 | } |
| 44 | |
| 45 | CGFunctionInfo::CGFunctionInfo(const FunctionTypeProto *FTP) |
| 46 | : IsVariadic(FTP->isVariadic()) |
| 47 | { |
| 48 | ArgTypes.push_back(FTP->getResultType()); |
| 49 | for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) |
| 50 | ArgTypes.push_back(FTP->getArgType(i)); |
| 51 | } |
| 52 | |
| 53 | // FIXME: Is there really any reason to have this still? |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 54 | CGFunctionInfo::CGFunctionInfo(const FunctionDecl *FD) |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 55 | { |
| 56 | const FunctionType *FTy = FD->getType()->getAsFunctionType(); |
| 57 | const FunctionTypeProto *FTP = dyn_cast<FunctionTypeProto>(FTy); |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 58 | |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 59 | ArgTypes.push_back(FTy->getResultType()); |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 60 | if (FTP) { |
| 61 | IsVariadic = FTP->isVariadic(); |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 62 | for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) |
| 63 | ArgTypes.push_back(FTP->getArgType(i)); |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 64 | } else { |
| 65 | IsVariadic = true; |
| 66 | } |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | CGFunctionInfo::CGFunctionInfo(const ObjCMethodDecl *MD, |
| 70 | const ASTContext &Context) |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 71 | : IsVariadic(MD->isVariadic()) |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 72 | { |
| 73 | ArgTypes.push_back(MD->getResultType()); |
| 74 | ArgTypes.push_back(MD->getSelfDecl()->getType()); |
| 75 | ArgTypes.push_back(Context.getObjCSelType()); |
| 76 | for (ObjCMethodDecl::param_const_iterator i = MD->param_begin(), |
| 77 | e = MD->param_end(); i != e; ++i) |
| 78 | ArgTypes.push_back((*i)->getType()); |
| 79 | } |
| 80 | |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 81 | ArgTypeIterator CGFunctionInfo::argtypes_begin() const { |
| 82 | return ArgTypes.begin(); |
| 83 | } |
| 84 | |
| 85 | ArgTypeIterator CGFunctionInfo::argtypes_end() const { |
| 86 | return ArgTypes.end(); |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /***/ |
| 90 | |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 91 | CGCallInfo::CGCallInfo(QualType _ResultType, const CallArgList &_Args) { |
| 92 | ArgTypes.push_back(_ResultType); |
| 93 | for (CallArgList::const_iterator i = _Args.begin(), e = _Args.end(); i!=e; ++i) |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 94 | ArgTypes.push_back(i->second); |
| 95 | } |
| 96 | |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 97 | ArgTypeIterator CGCallInfo::argtypes_begin() const { |
| 98 | return ArgTypes.begin(); |
| 99 | } |
| 100 | |
| 101 | ArgTypeIterator CGCallInfo::argtypes_end() const { |
| 102 | return ArgTypes.end(); |
Daniel Dunbar | 0dbe227 | 2008-09-08 21:33:45 +0000 | [diff] [blame] | 103 | } |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 104 | |
| 105 | /***/ |
| 106 | |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 107 | /// ABIArgInfo - Helper class to encapsulate information about how a |
| 108 | /// specific C type should be passed to or returned from a function. |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 109 | class ABIArgInfo { |
| 110 | public: |
| 111 | enum Kind { |
| 112 | Default, |
Daniel Dunbar | 3aea8ca | 2008-12-18 04:52:14 +0000 | [diff] [blame] | 113 | StructRet, /// Only valid for return values. The return value |
| 114 | /// should be passed through a pointer to a caller |
| 115 | /// allocated location passed as an implicit first |
| 116 | /// argument to the function. |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 117 | |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 118 | Ignore, /// Ignore the argument (treat as void). Useful for |
| 119 | /// void and empty structs. |
| 120 | |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 121 | Coerce, /// Only valid for aggregate return types, the argument |
| 122 | /// should be accessed by coercion to a provided type. |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 123 | |
| 124 | ByVal, /// Only valid for aggregate argument types. The |
| 125 | /// structure should be passed "byval" with the |
| 126 | /// specified alignment (0 indicates default |
| 127 | /// alignment). |
| 128 | |
| 129 | Expand, /// Only valid for aggregate argument types. The |
| 130 | /// structure should be expanded into consecutive |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 131 | /// arguments for its constituent fields. Currently |
| 132 | /// expand is only allowed on structures whose fields |
| 133 | /// are all scalar types or are themselves expandable |
| 134 | /// types. |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 135 | |
| 136 | KindFirst=Default, KindLast=Expand |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | private: |
| 140 | Kind TheKind; |
Daniel Dunbar | 639ffe4 | 2008-09-10 07:04:09 +0000 | [diff] [blame] | 141 | const llvm::Type *TypeData; |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 142 | unsigned UIntData; |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 143 | |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 144 | ABIArgInfo(Kind K, const llvm::Type *TD=0, |
| 145 | unsigned UI=0) : TheKind(K), |
| 146 | TypeData(TD), |
| 147 | UIntData(0) {} |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 148 | public: |
| 149 | static ABIArgInfo getDefault() { |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 150 | return ABIArgInfo(Default); |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 151 | } |
| 152 | static ABIArgInfo getStructRet() { |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 153 | return ABIArgInfo(StructRet); |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 154 | } |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 155 | static ABIArgInfo getIgnore() { |
| 156 | return ABIArgInfo(Ignore); |
| 157 | } |
Daniel Dunbar | 639ffe4 | 2008-09-10 07:04:09 +0000 | [diff] [blame] | 158 | static ABIArgInfo getCoerce(const llvm::Type *T) { |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 159 | return ABIArgInfo(Coerce, T); |
| 160 | } |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 161 | static ABIArgInfo getByVal(unsigned Alignment) { |
| 162 | return ABIArgInfo(ByVal, 0, Alignment); |
| 163 | } |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 164 | static ABIArgInfo getExpand() { |
| 165 | return ABIArgInfo(Expand); |
| 166 | } |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 167 | |
| 168 | Kind getKind() const { return TheKind; } |
| 169 | bool isDefault() const { return TheKind == Default; } |
| 170 | bool isStructRet() const { return TheKind == StructRet; } |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 171 | bool isIgnore() const { return TheKind == Ignore; } |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 172 | bool isCoerce() const { return TheKind == Coerce; } |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 173 | bool isByVal() const { return TheKind == ByVal; } |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 174 | bool isExpand() const { return TheKind == Expand; } |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 175 | |
| 176 | // Coerce accessors |
Daniel Dunbar | 639ffe4 | 2008-09-10 07:04:09 +0000 | [diff] [blame] | 177 | const llvm::Type *getCoerceToType() const { |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 178 | assert(TheKind == Coerce && "Invalid kind!"); |
| 179 | return TypeData; |
| 180 | } |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 181 | |
| 182 | // ByVal accessors |
| 183 | unsigned getByValAlignment() const { |
| 184 | assert(TheKind == ByVal && "Invalid kind!"); |
| 185 | return UIntData; |
| 186 | } |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | /***/ |
| 190 | |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 191 | /* FIXME: All of this stuff should be part of the target interface |
| 192 | somehow. It is currently here because it is not clear how to factor |
| 193 | the targets to support this, since the Targets currently live in a |
| 194 | layer below types n'stuff. |
| 195 | */ |
| 196 | |
| 197 | /// ABIInfo - Target specific hooks for defining how a type should be |
| 198 | /// passed or returned from functions. |
| 199 | class clang::ABIInfo { |
| 200 | public: |
| 201 | virtual ~ABIInfo(); |
| 202 | |
| 203 | virtual ABIArgInfo classifyReturnType(QualType RetTy, |
| 204 | ASTContext &Context) const = 0; |
| 205 | |
| 206 | virtual ABIArgInfo classifyArgumentType(QualType Ty, |
| 207 | ASTContext &Context) const = 0; |
| 208 | }; |
| 209 | |
| 210 | ABIInfo::~ABIInfo() {} |
| 211 | |
Daniel Dunbar | 834af45 | 2008-09-17 21:22:33 +0000 | [diff] [blame] | 212 | /// isEmptyStruct - Return true iff a structure has no non-empty |
| 213 | /// members. Note that a structure with a flexible array member is not |
| 214 | /// considered empty. |
| 215 | static bool isEmptyStruct(QualType T) { |
| 216 | const RecordType *RT = T->getAsStructureType(); |
| 217 | if (!RT) |
| 218 | return 0; |
| 219 | const RecordDecl *RD = RT->getDecl(); |
| 220 | if (RD->hasFlexibleArrayMember()) |
| 221 | return false; |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 222 | for (RecordDecl::field_iterator i = RD->field_begin(), |
Daniel Dunbar | 834af45 | 2008-09-17 21:22:33 +0000 | [diff] [blame] | 223 | e = RD->field_end(); i != e; ++i) { |
| 224 | const FieldDecl *FD = *i; |
| 225 | if (!isEmptyStruct(FD->getType())) |
| 226 | return false; |
| 227 | } |
| 228 | return true; |
| 229 | } |
| 230 | |
| 231 | /// isSingleElementStruct - Determine if a structure is a "single |
| 232 | /// element struct", i.e. it has exactly one non-empty field or |
| 233 | /// exactly one field which is itself a single element |
| 234 | /// struct. Structures with flexible array members are never |
| 235 | /// considered single element structs. |
| 236 | /// |
| 237 | /// \return The field declaration for the single non-empty field, if |
| 238 | /// it exists. |
| 239 | static const FieldDecl *isSingleElementStruct(QualType T) { |
| 240 | const RecordType *RT = T->getAsStructureType(); |
| 241 | if (!RT) |
| 242 | return 0; |
| 243 | |
| 244 | const RecordDecl *RD = RT->getDecl(); |
| 245 | if (RD->hasFlexibleArrayMember()) |
| 246 | return 0; |
| 247 | |
| 248 | const FieldDecl *Found = 0; |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 249 | for (RecordDecl::field_iterator i = RD->field_begin(), |
Daniel Dunbar | 834af45 | 2008-09-17 21:22:33 +0000 | [diff] [blame] | 250 | e = RD->field_end(); i != e; ++i) { |
| 251 | const FieldDecl *FD = *i; |
| 252 | QualType FT = FD->getType(); |
| 253 | |
| 254 | if (isEmptyStruct(FT)) { |
| 255 | // Ignore |
| 256 | } else if (Found) { |
| 257 | return 0; |
| 258 | } else if (!CodeGenFunction::hasAggregateLLVMType(FT)) { |
| 259 | Found = FD; |
| 260 | } else { |
| 261 | Found = isSingleElementStruct(FT); |
| 262 | if (!Found) |
| 263 | return 0; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | return Found; |
| 268 | } |
| 269 | |
| 270 | static bool is32Or64BitBasicType(QualType Ty, ASTContext &Context) { |
| 271 | if (!Ty->getAsBuiltinType() && !Ty->isPointerType()) |
| 272 | return false; |
| 273 | |
| 274 | uint64_t Size = Context.getTypeSize(Ty); |
| 275 | return Size == 32 || Size == 64; |
| 276 | } |
| 277 | |
| 278 | static bool areAllFields32Or64BitBasicType(const RecordDecl *RD, |
| 279 | ASTContext &Context) { |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 280 | for (RecordDecl::field_iterator i = RD->field_begin(), |
Daniel Dunbar | 834af45 | 2008-09-17 21:22:33 +0000 | [diff] [blame] | 281 | e = RD->field_end(); i != e; ++i) { |
| 282 | const FieldDecl *FD = *i; |
| 283 | |
| 284 | if (!is32Or64BitBasicType(FD->getType(), Context)) |
| 285 | return false; |
| 286 | |
| 287 | // If this is a bit-field we need to make sure it is still a |
| 288 | // 32-bit or 64-bit type. |
| 289 | if (Expr *BW = FD->getBitWidth()) { |
| 290 | unsigned Width = BW->getIntegerConstantExprValue(Context).getZExtValue(); |
| 291 | if (Width <= 16) |
| 292 | return false; |
| 293 | } |
| 294 | } |
| 295 | return true; |
| 296 | } |
| 297 | |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 298 | namespace { |
| 299 | /// DefaultABIInfo - The default implementation for ABI specific |
| 300 | /// details. This implementation provides information which results in |
| 301 | /// sensible LLVM IR generation, but does not conform to any |
| 302 | /// particular ABI. |
| 303 | class DefaultABIInfo : public ABIInfo { |
| 304 | virtual ABIArgInfo classifyReturnType(QualType RetTy, |
| 305 | ASTContext &Context) const; |
| 306 | |
| 307 | virtual ABIArgInfo classifyArgumentType(QualType RetTy, |
| 308 | ASTContext &Context) const; |
| 309 | }; |
| 310 | |
| 311 | /// X86_32ABIInfo - The X86-32 ABI information. |
| 312 | class X86_32ABIInfo : public ABIInfo { |
| 313 | public: |
| 314 | virtual ABIArgInfo classifyReturnType(QualType RetTy, |
| 315 | ASTContext &Context) const; |
| 316 | |
| 317 | virtual ABIArgInfo classifyArgumentType(QualType RetTy, |
| 318 | ASTContext &Context) const; |
| 319 | }; |
| 320 | } |
| 321 | |
| 322 | ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy, |
| 323 | ASTContext &Context) const { |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 324 | if (CodeGenFunction::hasAggregateLLVMType(RetTy)) { |
Daniel Dunbar | 834af45 | 2008-09-17 21:22:33 +0000 | [diff] [blame] | 325 | // Classify "single element" structs as their element type. |
| 326 | const FieldDecl *SeltFD = isSingleElementStruct(RetTy); |
| 327 | if (SeltFD) { |
| 328 | QualType SeltTy = SeltFD->getType()->getDesugaredType(); |
| 329 | if (const BuiltinType *BT = SeltTy->getAsBuiltinType()) { |
| 330 | // FIXME: This is gross, it would be nice if we could just |
| 331 | // pass back SeltTy and have clients deal with it. Is it worth |
| 332 | // supporting coerce to both LLVM and clang Types? |
| 333 | if (BT->isIntegerType()) { |
| 334 | uint64_t Size = Context.getTypeSize(SeltTy); |
| 335 | return ABIArgInfo::getCoerce(llvm::IntegerType::get((unsigned) Size)); |
| 336 | } else if (BT->getKind() == BuiltinType::Float) { |
| 337 | return ABIArgInfo::getCoerce(llvm::Type::FloatTy); |
| 338 | } else if (BT->getKind() == BuiltinType::Double) { |
| 339 | return ABIArgInfo::getCoerce(llvm::Type::DoubleTy); |
| 340 | } |
| 341 | } else if (SeltTy->isPointerType()) { |
| 342 | // FIXME: It would be really nice if this could come out as |
| 343 | // the proper pointer type. |
| 344 | llvm::Type *PtrTy = |
| 345 | llvm::PointerType::getUnqual(llvm::Type::Int8Ty); |
| 346 | return ABIArgInfo::getCoerce(PtrTy); |
| 347 | } |
| 348 | } |
| 349 | |
Daniel Dunbar | 639ffe4 | 2008-09-10 07:04:09 +0000 | [diff] [blame] | 350 | uint64_t Size = Context.getTypeSize(RetTy); |
| 351 | if (Size == 8) { |
| 352 | return ABIArgInfo::getCoerce(llvm::Type::Int8Ty); |
| 353 | } else if (Size == 16) { |
| 354 | return ABIArgInfo::getCoerce(llvm::Type::Int16Ty); |
| 355 | } else if (Size == 32) { |
| 356 | return ABIArgInfo::getCoerce(llvm::Type::Int32Ty); |
| 357 | } else if (Size == 64) { |
| 358 | return ABIArgInfo::getCoerce(llvm::Type::Int64Ty); |
| 359 | } else { |
| 360 | return ABIArgInfo::getStructRet(); |
| 361 | } |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 362 | } else { |
| 363 | return ABIArgInfo::getDefault(); |
| 364 | } |
| 365 | } |
| 366 | |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 367 | ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, |
| 368 | ASTContext &Context) const { |
Daniel Dunbar | f035738 | 2008-09-17 20:11:04 +0000 | [diff] [blame] | 369 | if (CodeGenFunction::hasAggregateLLVMType(Ty)) { |
Daniel Dunbar | 834af45 | 2008-09-17 21:22:33 +0000 | [diff] [blame] | 370 | // Structures with flexible arrays are always byval. |
| 371 | if (const RecordType *RT = Ty->getAsStructureType()) |
| 372 | if (RT->getDecl()->hasFlexibleArrayMember()) |
| 373 | return ABIArgInfo::getByVal(0); |
| 374 | |
| 375 | // Expand empty structs (i.e. ignore) |
| 376 | uint64_t Size = Context.getTypeSize(Ty); |
| 377 | if (Ty->isStructureType() && Size == 0) |
| 378 | return ABIArgInfo::getExpand(); |
| 379 | |
| 380 | // Expand structs with size <= 128-bits which consist only of |
| 381 | // basic types (int, long long, float, double, xxx*). This is |
| 382 | // non-recursive and does not ignore empty fields. |
| 383 | if (const RecordType *RT = Ty->getAsStructureType()) { |
| 384 | if (Context.getTypeSize(Ty) <= 4*32 && |
| 385 | areAllFields32Or64BitBasicType(RT->getDecl(), Context)) |
| 386 | return ABIArgInfo::getExpand(); |
| 387 | } |
| 388 | |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 389 | return ABIArgInfo::getByVal(0); |
| 390 | } else { |
| 391 | return ABIArgInfo::getDefault(); |
| 392 | } |
| 393 | } |
| 394 | |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 395 | namespace { |
| 396 | /// X86_32ABIInfo - The X86_64 ABI information. |
| 397 | class X86_64ABIInfo : public ABIInfo { |
| 398 | enum Class { |
| 399 | Integer = 0, |
| 400 | SSE, |
| 401 | SSEUp, |
| 402 | X87, |
| 403 | X87Up, |
| 404 | ComplexX87, |
| 405 | NoClass, |
| 406 | Memory |
| 407 | }; |
| 408 | |
| 409 | /// classify - Determine the x86_64 register classes in which the |
| 410 | /// given type T should be passed. |
| 411 | /// |
| 412 | /// \param Lo - The classification for the low word of the type. |
| 413 | /// \param Hi - The classification for the high word of the type. |
Daniel Dunbar | f04d69b | 2009-01-29 09:42:07 +0000 | [diff] [blame] | 414 | /// \param OffsetBase - The byte position of the type in the root |
| 415 | /// structure. Some parameters are classified different depending on |
| 416 | /// whether they straddle an eightbyte boundary. |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 417 | /// |
| 418 | /// If a word is unused its result will be NoClass; if a type should |
| 419 | /// be passed in Memory then at least the classification of \arg Lo |
| 420 | /// will be Memory. |
| 421 | /// |
| 422 | /// The \arg Lo class will be NoClass iff the argument is ignored. |
| 423 | /// |
| 424 | /// If the \arg Lo class is ComplexX87, then the \arg Hi class will |
| 425 | /// be NoClass. |
Daniel Dunbar | e620ecd | 2009-01-30 00:47:38 +0000 | [diff] [blame^] | 426 | void classify(QualType T, ASTContext &Context, uint64_t OffsetBase, |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 427 | Class &Lo, Class &Hi) const; |
| 428 | |
| 429 | public: |
| 430 | virtual ABIArgInfo classifyReturnType(QualType RetTy, |
| 431 | ASTContext &Context) const; |
| 432 | |
| 433 | virtual ABIArgInfo classifyArgumentType(QualType RetTy, |
| 434 | ASTContext &Context) const; |
| 435 | }; |
| 436 | } |
| 437 | |
| 438 | void X86_64ABIInfo::classify(QualType Ty, |
| 439 | ASTContext &Context, |
Daniel Dunbar | e620ecd | 2009-01-30 00:47:38 +0000 | [diff] [blame^] | 440 | uint64_t OffsetBase, |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 441 | Class &Lo, Class &Hi) const { |
| 442 | Lo = Memory; |
| 443 | Hi = NoClass; |
| 444 | if (const BuiltinType *BT = Ty->getAsBuiltinType()) { |
| 445 | BuiltinType::Kind k = BT->getKind(); |
| 446 | |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 447 | if (k == BuiltinType::Void) { |
| 448 | Lo = NoClass; |
| 449 | } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) { |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 450 | Lo = Integer; |
| 451 | } else if (k == BuiltinType::Float || k == BuiltinType::Double) { |
| 452 | Lo = SSE; |
| 453 | } else if (k == BuiltinType::LongDouble) { |
| 454 | Lo = X87; |
| 455 | Hi = X87Up; |
| 456 | } |
Daniel Dunbar | 7a6605d | 2009-01-27 02:01:34 +0000 | [diff] [blame] | 457 | |
| 458 | // FIXME: _Decimal32 and _Decimal64 are SSE. |
| 459 | // FIXME: _float128 and _Decimal128 are (SSE, SSEUp). |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 460 | // FIXME: __int128 is (Integer, Integer). |
| 461 | } else if (Ty->isPointerLikeType() || Ty->isBlockPointerType() || |
| 462 | Ty->isObjCQualifiedInterfaceType()) { |
| 463 | Lo = Integer; |
Daniel Dunbar | 7a6605d | 2009-01-27 02:01:34 +0000 | [diff] [blame] | 464 | } else if (const VectorType *VT = Ty->getAsVectorType()) { |
Daniel Dunbar | e620ecd | 2009-01-30 00:47:38 +0000 | [diff] [blame^] | 465 | uint64_t Size = Context.getTypeSize(VT); |
Daniel Dunbar | 7a6605d | 2009-01-27 02:01:34 +0000 | [diff] [blame] | 466 | if (Size == 64) { |
| 467 | // FIXME: For some reason, gcc appears to be treating <1 x |
| 468 | // double> as INTEGER; this seems wrong, but we will match for |
| 469 | // now (icc rejects <1 x double>, so...). |
| 470 | Lo = (VT->getElementType() == Context.DoubleTy) ? Integer : SSE; |
| 471 | } else if (Size == 128) { |
| 472 | Lo = SSE; |
| 473 | Hi = SSEUp; |
| 474 | } |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 475 | } else if (const ComplexType *CT = Ty->getAsComplexType()) { |
| 476 | QualType ET = CT->getElementType(); |
| 477 | |
Daniel Dunbar | eac48dc | 2009-01-29 07:22:20 +0000 | [diff] [blame] | 478 | if (ET->isIntegerType()) { |
Daniel Dunbar | e620ecd | 2009-01-30 00:47:38 +0000 | [diff] [blame^] | 479 | uint64_t Size = Context.getTypeSize(Ty); |
Daniel Dunbar | eac48dc | 2009-01-29 07:22:20 +0000 | [diff] [blame] | 480 | if (Size <= 64) |
| 481 | Lo = Integer; |
| 482 | else if (Size <= 128) |
| 483 | Lo = Hi = Integer; |
| 484 | } else if (ET == Context.FloatTy) |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 485 | Lo = SSE; |
| 486 | else if (ET == Context.DoubleTy) |
| 487 | Lo = Hi = SSE; |
| 488 | else if (ET == Context.LongDoubleTy) |
| 489 | Lo = ComplexX87; |
Daniel Dunbar | f04d69b | 2009-01-29 09:42:07 +0000 | [diff] [blame] | 490 | |
| 491 | // If this complex type crosses an eightbyte boundary then it |
| 492 | // should be split. |
Daniel Dunbar | e620ecd | 2009-01-30 00:47:38 +0000 | [diff] [blame^] | 493 | uint64_t EB_Real = (OffsetBase) >> 3; |
| 494 | uint64_t EB_Imag = (OffsetBase + Context.getTypeSize(ET)) >> 3; |
Daniel Dunbar | f04d69b | 2009-01-29 09:42:07 +0000 | [diff] [blame] | 495 | if (Hi == NoClass && EB_Real != EB_Imag) |
| 496 | Hi = Lo; |
Daniel Dunbar | 99037e5 | 2009-01-29 08:13:58 +0000 | [diff] [blame] | 497 | } else if (const RecordType *RT = Ty->getAsRecordType()) { |
Daniel Dunbar | e620ecd | 2009-01-30 00:47:38 +0000 | [diff] [blame^] | 498 | uint64_t Size = Context.getTypeSize(Ty); |
Daniel Dunbar | 99037e5 | 2009-01-29 08:13:58 +0000 | [diff] [blame] | 499 | |
| 500 | // AMD64-ABI 3.2.3p2: Rule 1. If the size of an object is larger |
| 501 | // than two eightbytes, ..., it has class MEMORY. |
| 502 | if (Size > 128) |
| 503 | return; |
| 504 | |
| 505 | const RecordDecl *RD = RT->getDecl(); |
| 506 | |
| 507 | // Assume variable sized types are passed in memory. |
| 508 | if (RD->hasFlexibleArrayMember()) |
| 509 | return; |
| 510 | |
| 511 | const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); |
| 512 | |
| 513 | // Reset Lo class, this will be recomputed. |
| 514 | Lo = NoClass; |
| 515 | unsigned idx = 0; |
| 516 | for (RecordDecl::field_iterator i = RD->field_begin(), |
| 517 | e = RD->field_end(); i != e; ++i, ++idx) { |
Daniel Dunbar | f04d69b | 2009-01-29 09:42:07 +0000 | [diff] [blame] | 518 | unsigned Offset = OffsetBase + Layout.getFieldOffset(idx); |
Daniel Dunbar | 99037e5 | 2009-01-29 08:13:58 +0000 | [diff] [blame] | 519 | |
| 520 | // AMD64-ABI 3.2.3p2: Rule 1. If ..., or it contains unaligned |
| 521 | // fields, it has class MEMORY. |
| 522 | if (Offset % Context.getTypeAlign(i->getType())) { |
| 523 | Lo = Memory; |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | // Determine which half of the structure we are classifying. |
| 528 | // |
| 529 | // AMD64-ABI 3.2.3p2: Rule 3. f the size of the aggregate |
| 530 | // exceeds a single eightbyte, each is classified |
| 531 | // separately. Each eightbyte gets initialized to class |
| 532 | // NO_CLASS. |
| 533 | Class &Target = Offset < 64 ? Lo : Hi; |
| 534 | |
| 535 | // Classify this field. |
| 536 | Class FieldLo, FieldHi; |
Daniel Dunbar | f04d69b | 2009-01-29 09:42:07 +0000 | [diff] [blame] | 537 | classify(i->getType(), Context, Offset, FieldLo, FieldHi); |
Daniel Dunbar | 99037e5 | 2009-01-29 08:13:58 +0000 | [diff] [blame] | 538 | |
| 539 | // Merge the lo field classifcation. |
| 540 | // |
| 541 | // AMD64-ABI 3.2.3p2: Rule 4. Each field of an object is |
| 542 | // classified recursively so that always two fields are |
| 543 | // considered. The resulting class is calculated according to |
| 544 | // the classes of the fields in the eightbyte: |
| 545 | // |
| 546 | // (a) If both classes are equal, this is the resulting class. |
| 547 | // |
| 548 | // (b) If one of the classes is NO_CLASS, the resulting class is |
| 549 | // the other class. |
| 550 | // |
| 551 | // (c) If one of the classes is MEMORY, the result is the MEMORY |
| 552 | // class. |
| 553 | // |
| 554 | // (d) If one of the classes is INTEGER, the result is the |
| 555 | // INTEGER. |
| 556 | // |
| 557 | // (e) If one of the classes is X87, X87UP, COMPLEX_X87 class, |
| 558 | // MEMORY is used as class. |
| 559 | // |
| 560 | // (f) Otherwise class SSE is used. |
| 561 | if (Target == FieldLo || FieldLo == NoClass) ; |
Daniel Dunbar | 99037e5 | 2009-01-29 08:13:58 +0000 | [diff] [blame] | 562 | else if (FieldLo == Memory) { |
| 563 | // Memory is never over-ridden, just bail. |
| 564 | Lo = Memory; |
| 565 | return; |
| 566 | } |
Daniel Dunbar | 7f102f8 | 2009-01-29 08:35:40 +0000 | [diff] [blame] | 567 | else if (Target == NoClass) |
| 568 | Target = FieldLo; |
Daniel Dunbar | 99037e5 | 2009-01-29 08:13:58 +0000 | [diff] [blame] | 569 | else if (Target == Integer || FieldLo == Integer) |
| 570 | Target = Integer; |
| 571 | else if (FieldLo == X87 || FieldLo == X87Up || FieldLo == ComplexX87) { |
| 572 | // As before, just bail once we generate a memory class. |
| 573 | Lo = Memory; |
| 574 | return; |
| 575 | } else |
| 576 | Target = SSE; |
| 577 | |
| 578 | // It isn't clear from the ABI spec what the role of the high |
| 579 | // classification is here, but since this should only happen |
| 580 | // when we have a struct with a two eightbyte member, we can |
| 581 | // just push the field high class into the overall high class. |
| 582 | if (FieldHi != NoClass) |
| 583 | Hi = FieldHi; |
| 584 | } |
| 585 | |
| 586 | // AMD64-ABI 3.2.3p2: Rule 5. Then a post merger cleanup is done: |
| 587 | // |
| 588 | // (a) If one of the classes is MEMORY, the whole argument is |
| 589 | // passed in memory. |
| 590 | // |
| 591 | // (b) If SSEUP is not preceeded by SSE, it is converted to SSE. |
| 592 | |
| 593 | // The first of these conditions is guaranteed by how we implement |
| 594 | // the merge (just bail). I don't believe the second is actually |
| 595 | // possible at all. |
| 596 | assert(Lo != Memory && "Unexpected memory classification."); |
| 597 | if (Hi == SSEUp && Lo != SSE) |
| 598 | Hi = SSE; |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
Daniel Dunbar | d4edfe4 | 2009-01-15 18:18:40 +0000 | [diff] [blame] | 602 | ABIArgInfo X86_64ABIInfo::classifyReturnType(QualType RetTy, |
| 603 | ASTContext &Context) const { |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 604 | // AMD64-ABI 3.2.3p4: Rule 1. Classify the return type with the |
| 605 | // classification algorithm. |
| 606 | X86_64ABIInfo::Class Lo, Hi; |
Daniel Dunbar | f04d69b | 2009-01-29 09:42:07 +0000 | [diff] [blame] | 607 | classify(RetTy, Context, 0, Lo, Hi); |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 608 | |
| 609 | const llvm::Type *ResType = 0; |
| 610 | switch (Lo) { |
| 611 | case NoClass: |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 612 | return ABIArgInfo::getIgnore(); |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 613 | |
| 614 | case SSEUp: |
| 615 | case X87Up: |
| 616 | assert(0 && "Invalid classification for lo word."); |
| 617 | |
| 618 | // AMD64-ABI 3.2.3p4: Rule 2. Types of class memory are returned via |
| 619 | // hidden argument, i.e. structret. |
| 620 | case Memory: |
| 621 | return ABIArgInfo::getStructRet(); |
| 622 | |
| 623 | // AMD64-ABI 3.2.3p4: Rule 3. If the class is INTEGER, the next |
| 624 | // available register of the sequence %rax, %rdx is used. |
| 625 | case Integer: |
| 626 | ResType = llvm::Type::Int64Ty; break; |
| 627 | |
| 628 | // AMD64-ABI 3.2.3p4: Rule 4. If the class is SSE, the next |
| 629 | // available SSE register of the sequence %xmm0, %xmm1 is used. |
| 630 | case SSE: |
| 631 | ResType = llvm::Type::DoubleTy; break; |
| 632 | |
| 633 | // AMD64-ABI 3.2.3p4: Rule 6. If the class is X87, the value is |
| 634 | // returned on the X87 stack in %st0 as 80-bit x87 number. |
| 635 | case X87: |
| 636 | ResType = llvm::Type::X86_FP80Ty; break; |
| 637 | |
| 638 | // AMD64-ABI 3.2.3p4: Rule 8. If the class is COMPLEX_X87, the real |
| 639 | // part of the value is returned in %st0 and the imaginary part in |
| 640 | // %st1. |
| 641 | case ComplexX87: |
| 642 | assert(Hi == NoClass && "Unexpected ComplexX87 classification."); |
| 643 | ResType = llvm::VectorType::get(llvm::Type::X86_FP80Ty, 2); |
| 644 | break; |
| 645 | } |
| 646 | |
| 647 | switch (Hi) { |
| 648 | // Memory was handled previously, and ComplexX87 and X87 should |
| 649 | // never occur as hi classes. |
| 650 | case Memory: |
| 651 | case X87: |
| 652 | case ComplexX87: |
| 653 | assert(0 && "Invalid classification for hi word."); |
| 654 | |
| 655 | case NoClass: break; |
| 656 | case Integer: |
Daniel Dunbar | b0e14f2 | 2009-01-29 07:36:07 +0000 | [diff] [blame] | 657 | ResType = llvm::StructType::get(ResType, llvm::Type::Int64Ty, NULL); |
| 658 | break; |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 659 | case SSE: |
Daniel Dunbar | b0e14f2 | 2009-01-29 07:36:07 +0000 | [diff] [blame] | 660 | ResType = llvm::StructType::get(ResType, llvm::Type::DoubleTy, NULL); |
| 661 | break; |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 662 | |
| 663 | // AMD64-ABI 3.2.3p4: Rule 5. If the class is SSEUP, the eightbyte |
| 664 | // is passed in the upper half of the last used SSE register. |
| 665 | // |
| 666 | // SSEUP should always be preceeded by SSE, just widen. |
| 667 | case SSEUp: |
| 668 | assert(Lo == SSE && "Unexpected SSEUp classification."); |
| 669 | ResType = llvm::VectorType::get(llvm::Type::DoubleTy, 2); |
| 670 | break; |
| 671 | |
| 672 | // AMD64-ABI 3.2.3p4: Rule 7. If the class is X87UP, the value is |
Daniel Dunbar | b0e14f2 | 2009-01-29 07:36:07 +0000 | [diff] [blame] | 673 | // returned together with the previous X87 value in %st0. |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 674 | // |
| 675 | // X87UP should always be preceeded by X87, so we don't need to do |
| 676 | // anything here. |
| 677 | case X87Up: |
| 678 | assert(Lo == X87 && "Unexpected X87Up classification."); |
| 679 | break; |
| 680 | } |
| 681 | |
| 682 | return ABIArgInfo::getCoerce(ResType); |
Daniel Dunbar | d4edfe4 | 2009-01-15 18:18:40 +0000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | ABIArgInfo X86_64ABIInfo::classifyArgumentType(QualType Ty, |
| 686 | ASTContext &Context) const { |
| 687 | return ABIArgInfo::getDefault(); |
| 688 | } |
| 689 | |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 690 | ABIArgInfo DefaultABIInfo::classifyReturnType(QualType RetTy, |
| 691 | ASTContext &Context) const { |
| 692 | return ABIArgInfo::getDefault(); |
| 693 | } |
| 694 | |
| 695 | ABIArgInfo DefaultABIInfo::classifyArgumentType(QualType Ty, |
| 696 | ASTContext &Context) const { |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 697 | return ABIArgInfo::getDefault(); |
| 698 | } |
| 699 | |
| 700 | const ABIInfo &CodeGenTypes::getABIInfo() const { |
| 701 | if (TheABIInfo) |
| 702 | return *TheABIInfo; |
| 703 | |
| 704 | // For now we just cache this in the CodeGenTypes and don't bother |
| 705 | // to free it. |
| 706 | const char *TargetPrefix = getContext().Target.getTargetPrefix(); |
| 707 | if (strcmp(TargetPrefix, "x86") == 0) { |
Daniel Dunbar | d4edfe4 | 2009-01-15 18:18:40 +0000 | [diff] [blame] | 708 | switch (getContext().Target.getPointerWidth(0)) { |
| 709 | case 32: |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 710 | return *(TheABIInfo = new X86_32ABIInfo()); |
Daniel Dunbar | d4edfe4 | 2009-01-15 18:18:40 +0000 | [diff] [blame] | 711 | case 64: |
Daniel Dunbar | 6f3e7fa | 2009-01-24 08:32:22 +0000 | [diff] [blame] | 712 | if (UseX86_64ABI) |
| 713 | return *(TheABIInfo = new X86_64ABIInfo()); |
Daniel Dunbar | d4edfe4 | 2009-01-15 18:18:40 +0000 | [diff] [blame] | 714 | } |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | return *(TheABIInfo = new DefaultABIInfo); |
| 718 | } |
| 719 | |
| 720 | // getABIReturnInfo - Wrap the ABIInfo getABIReturnInfo, altering |
| 721 | // "default" types to StructRet when appropriate for simplicity. |
| 722 | static ABIArgInfo getABIReturnInfo(QualType Ty, CodeGenTypes &CGT) { |
| 723 | assert(!Ty->isArrayType() && |
| 724 | "Array types cannot be passed directly."); |
| 725 | ABIArgInfo Info = CGT.getABIInfo().classifyReturnType(Ty, CGT.getContext()); |
Daniel Dunbar | f035738 | 2008-09-17 20:11:04 +0000 | [diff] [blame] | 726 | // Ensure default on aggregate types is StructRet. |
| 727 | if (Info.isDefault() && CodeGenFunction::hasAggregateLLVMType(Ty)) |
| 728 | return ABIArgInfo::getStructRet(); |
| 729 | return Info; |
| 730 | } |
| 731 | |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 732 | // getABIArgumentInfo - Wrap the ABIInfo getABIReturnInfo, altering |
| 733 | // "default" types to ByVal when appropriate for simplicity. |
| 734 | static ABIArgInfo getABIArgumentInfo(QualType Ty, CodeGenTypes &CGT) { |
| 735 | assert(!Ty->isArrayType() && |
| 736 | "Array types cannot be passed directly."); |
| 737 | ABIArgInfo Info = CGT.getABIInfo().classifyArgumentType(Ty, CGT.getContext()); |
Daniel Dunbar | f035738 | 2008-09-17 20:11:04 +0000 | [diff] [blame] | 738 | // Ensure default on aggregate types is ByVal. |
| 739 | if (Info.isDefault() && CodeGenFunction::hasAggregateLLVMType(Ty)) |
| 740 | return ABIArgInfo::getByVal(0); |
| 741 | return Info; |
| 742 | } |
| 743 | |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 744 | /***/ |
| 745 | |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 746 | void CodeGenTypes::GetExpandedTypes(QualType Ty, |
| 747 | std::vector<const llvm::Type*> &ArgTys) { |
| 748 | const RecordType *RT = Ty->getAsStructureType(); |
| 749 | assert(RT && "Can only expand structure types."); |
| 750 | const RecordDecl *RD = RT->getDecl(); |
| 751 | assert(!RD->hasFlexibleArrayMember() && |
| 752 | "Cannot expand structure with flexible array."); |
| 753 | |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 754 | for (RecordDecl::field_iterator i = RD->field_begin(), |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 755 | e = RD->field_end(); i != e; ++i) { |
| 756 | const FieldDecl *FD = *i; |
| 757 | assert(!FD->isBitField() && |
| 758 | "Cannot expand structure with bit-field members."); |
| 759 | |
| 760 | QualType FT = FD->getType(); |
| 761 | if (CodeGenFunction::hasAggregateLLVMType(FT)) { |
| 762 | GetExpandedTypes(FT, ArgTys); |
| 763 | } else { |
| 764 | ArgTys.push_back(ConvertType(FT)); |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | llvm::Function::arg_iterator |
| 770 | CodeGenFunction::ExpandTypeFromArgs(QualType Ty, LValue LV, |
| 771 | llvm::Function::arg_iterator AI) { |
| 772 | const RecordType *RT = Ty->getAsStructureType(); |
| 773 | assert(RT && "Can only expand structure types."); |
| 774 | |
| 775 | RecordDecl *RD = RT->getDecl(); |
| 776 | assert(LV.isSimple() && |
| 777 | "Unexpected non-simple lvalue during struct expansion."); |
| 778 | llvm::Value *Addr = LV.getAddress(); |
| 779 | for (RecordDecl::field_iterator i = RD->field_begin(), |
| 780 | e = RD->field_end(); i != e; ++i) { |
| 781 | FieldDecl *FD = *i; |
| 782 | QualType FT = FD->getType(); |
| 783 | |
| 784 | // FIXME: What are the right qualifiers here? |
| 785 | LValue LV = EmitLValueForField(Addr, FD, false, 0); |
| 786 | if (CodeGenFunction::hasAggregateLLVMType(FT)) { |
| 787 | AI = ExpandTypeFromArgs(FT, LV, AI); |
| 788 | } else { |
| 789 | EmitStoreThroughLValue(RValue::get(AI), LV, FT); |
| 790 | ++AI; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | return AI; |
| 795 | } |
| 796 | |
| 797 | void |
| 798 | CodeGenFunction::ExpandTypeToArgs(QualType Ty, RValue RV, |
| 799 | llvm::SmallVector<llvm::Value*, 16> &Args) { |
| 800 | const RecordType *RT = Ty->getAsStructureType(); |
| 801 | assert(RT && "Can only expand structure types."); |
| 802 | |
| 803 | RecordDecl *RD = RT->getDecl(); |
| 804 | assert(RV.isAggregate() && "Unexpected rvalue during struct expansion"); |
| 805 | llvm::Value *Addr = RV.getAggregateAddr(); |
| 806 | for (RecordDecl::field_iterator i = RD->field_begin(), |
| 807 | e = RD->field_end(); i != e; ++i) { |
| 808 | FieldDecl *FD = *i; |
| 809 | QualType FT = FD->getType(); |
| 810 | |
| 811 | // FIXME: What are the right qualifiers here? |
| 812 | LValue LV = EmitLValueForField(Addr, FD, false, 0); |
| 813 | if (CodeGenFunction::hasAggregateLLVMType(FT)) { |
| 814 | ExpandTypeToArgs(FT, RValue::getAggregate(LV.getAddress()), Args); |
| 815 | } else { |
| 816 | RValue RV = EmitLoadOfLValue(LV, FT); |
| 817 | assert(RV.isScalar() && |
| 818 | "Unexpected non-scalar rvalue during struct expansion."); |
| 819 | Args.push_back(RV.getScalarVal()); |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | /***/ |
| 825 | |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 826 | const llvm::FunctionType * |
Daniel Dunbar | 62d5c1b | 2008-09-10 07:00:50 +0000 | [diff] [blame] | 827 | CodeGenTypes::GetFunctionType(const CGCallInfo &CI, bool IsVariadic) { |
| 828 | return GetFunctionType(CI.argtypes_begin(), CI.argtypes_end(), IsVariadic); |
| 829 | } |
| 830 | |
| 831 | const llvm::FunctionType * |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 832 | CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) { |
Daniel Dunbar | 62d5c1b | 2008-09-10 07:00:50 +0000 | [diff] [blame] | 833 | return GetFunctionType(FI.argtypes_begin(), FI.argtypes_end(), FI.isVariadic()); |
| 834 | } |
| 835 | |
| 836 | const llvm::FunctionType * |
| 837 | CodeGenTypes::GetFunctionType(ArgTypeIterator begin, ArgTypeIterator end, |
| 838 | bool IsVariadic) { |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 839 | std::vector<const llvm::Type*> ArgTys; |
| 840 | |
| 841 | const llvm::Type *ResultType = 0; |
| 842 | |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 843 | QualType RetTy = *begin; |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 844 | ABIArgInfo RetAI = getABIReturnInfo(RetTy, *this); |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 845 | switch (RetAI.getKind()) { |
| 846 | case ABIArgInfo::ByVal: |
| 847 | case ABIArgInfo::Expand: |
| 848 | assert(0 && "Invalid ABI kind for return argument"); |
| 849 | |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 850 | case ABIArgInfo::Default: |
| 851 | if (RetTy->isVoidType()) { |
| 852 | ResultType = llvm::Type::VoidTy; |
| 853 | } else { |
Daniel Dunbar | 62d5c1b | 2008-09-10 07:00:50 +0000 | [diff] [blame] | 854 | ResultType = ConvertType(RetTy); |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 855 | } |
| 856 | break; |
| 857 | |
| 858 | case ABIArgInfo::StructRet: { |
| 859 | ResultType = llvm::Type::VoidTy; |
Daniel Dunbar | 62d5c1b | 2008-09-10 07:00:50 +0000 | [diff] [blame] | 860 | const llvm::Type *STy = ConvertType(RetTy); |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 861 | ArgTys.push_back(llvm::PointerType::get(STy, RetTy.getAddressSpace())); |
| 862 | break; |
| 863 | } |
| 864 | |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 865 | case ABIArgInfo::Ignore: |
| 866 | ResultType = llvm::Type::VoidTy; |
| 867 | break; |
| 868 | |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 869 | case ABIArgInfo::Coerce: |
Daniel Dunbar | 639ffe4 | 2008-09-10 07:04:09 +0000 | [diff] [blame] | 870 | ResultType = RetAI.getCoerceToType(); |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 871 | break; |
| 872 | } |
| 873 | |
| 874 | for (++begin; begin != end; ++begin) { |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 875 | ABIArgInfo AI = getABIArgumentInfo(*begin, *this); |
Daniel Dunbar | 62d5c1b | 2008-09-10 07:00:50 +0000 | [diff] [blame] | 876 | const llvm::Type *Ty = ConvertType(*begin); |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 877 | |
| 878 | switch (AI.getKind()) { |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 879 | case ABIArgInfo::Ignore: |
| 880 | break; |
| 881 | |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 882 | case ABIArgInfo::Coerce: |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 883 | case ABIArgInfo::StructRet: |
| 884 | assert(0 && "Invalid ABI kind for non-return argument"); |
| 885 | |
| 886 | case ABIArgInfo::ByVal: |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 887 | // byval arguments are always on the stack, which is addr space #0. |
| 888 | ArgTys.push_back(llvm::PointerType::getUnqual(Ty)); |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 889 | assert(AI.getByValAlignment() == 0 && "FIXME: alignment unhandled"); |
| 890 | break; |
| 891 | |
| 892 | case ABIArgInfo::Default: |
| 893 | ArgTys.push_back(Ty); |
| 894 | break; |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 895 | |
| 896 | case ABIArgInfo::Expand: |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 897 | GetExpandedTypes(*begin, ArgTys); |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 898 | break; |
| 899 | } |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Daniel Dunbar | 62d5c1b | 2008-09-10 07:00:50 +0000 | [diff] [blame] | 902 | return llvm::FunctionType::get(ResultType, ArgTys, IsVariadic); |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Daniel Dunbar | b768807 | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 905 | bool CodeGenModule::ReturnTypeUsesSret(QualType RetTy) { |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 906 | return getABIReturnInfo(RetTy, getTypes()).isStructRet(); |
Daniel Dunbar | 3913f18 | 2008-09-09 23:48:28 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 909 | void CodeGenModule::ConstructAttributeList(const Decl *TargetDecl, |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 910 | ArgTypeIterator begin, |
| 911 | ArgTypeIterator end, |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 912 | AttributeListType &PAL) { |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 913 | unsigned FuncAttrs = 0; |
Devang Patel | a2c6912 | 2008-09-26 22:53:57 +0000 | [diff] [blame] | 914 | unsigned RetAttrs = 0; |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 915 | |
| 916 | if (TargetDecl) { |
| 917 | if (TargetDecl->getAttr<NoThrowAttr>()) |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 918 | FuncAttrs |= llvm::Attribute::NoUnwind; |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 919 | if (TargetDecl->getAttr<NoReturnAttr>()) |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 920 | FuncAttrs |= llvm::Attribute::NoReturn; |
Anders Carlsson | 232eb7d | 2008-10-05 23:32:53 +0000 | [diff] [blame] | 921 | if (TargetDecl->getAttr<PureAttr>()) |
| 922 | FuncAttrs |= llvm::Attribute::ReadOnly; |
| 923 | if (TargetDecl->getAttr<ConstAttr>()) |
| 924 | FuncAttrs |= llvm::Attribute::ReadNone; |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 927 | QualType RetTy = *begin; |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 928 | unsigned Index = 1; |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 929 | ABIArgInfo RetAI = getABIReturnInfo(RetTy, getTypes()); |
Daniel Dunbar | 45c25ba | 2008-09-10 04:01:49 +0000 | [diff] [blame] | 930 | switch (RetAI.getKind()) { |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 931 | case ABIArgInfo::Default: |
| 932 | if (RetTy->isPromotableIntegerType()) { |
| 933 | if (RetTy->isSignedIntegerType()) { |
Devang Patel | a2c6912 | 2008-09-26 22:53:57 +0000 | [diff] [blame] | 934 | RetAttrs |= llvm::Attribute::SExt; |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 935 | } else if (RetTy->isUnsignedIntegerType()) { |
Devang Patel | a2c6912 | 2008-09-26 22:53:57 +0000 | [diff] [blame] | 936 | RetAttrs |= llvm::Attribute::ZExt; |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | break; |
| 940 | |
| 941 | case ABIArgInfo::StructRet: |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 942 | PAL.push_back(llvm::AttributeWithIndex::get(Index, |
| 943 | llvm::Attribute::StructRet| |
| 944 | llvm::Attribute::NoAlias)); |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 945 | ++Index; |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 946 | break; |
| 947 | |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 948 | case ABIArgInfo::Ignore: |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 949 | case ABIArgInfo::Coerce: |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 950 | break; |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 951 | |
| 952 | case ABIArgInfo::ByVal: |
| 953 | case ABIArgInfo::Expand: |
| 954 | assert(0 && "Invalid ABI kind for return argument"); |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 955 | } |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 956 | |
Devang Patel | a2c6912 | 2008-09-26 22:53:57 +0000 | [diff] [blame] | 957 | if (RetAttrs) |
| 958 | PAL.push_back(llvm::AttributeWithIndex::get(0, RetAttrs)); |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 959 | for (++begin; begin != end; ++begin) { |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 960 | QualType ParamType = *begin; |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 961 | unsigned Attributes = 0; |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 962 | ABIArgInfo AI = getABIArgumentInfo(ParamType, getTypes()); |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 963 | |
| 964 | switch (AI.getKind()) { |
| 965 | case ABIArgInfo::StructRet: |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 966 | case ABIArgInfo::Coerce: |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 967 | assert(0 && "Invalid ABI kind for non-return argument"); |
| 968 | |
| 969 | case ABIArgInfo::ByVal: |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 970 | Attributes |= llvm::Attribute::ByVal; |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 971 | assert(AI.getByValAlignment() == 0 && "FIXME: alignment unhandled"); |
| 972 | break; |
| 973 | |
| 974 | case ABIArgInfo::Default: |
| 975 | if (ParamType->isPromotableIntegerType()) { |
| 976 | if (ParamType->isSignedIntegerType()) { |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 977 | Attributes |= llvm::Attribute::SExt; |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 978 | } else if (ParamType->isUnsignedIntegerType()) { |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 979 | Attributes |= llvm::Attribute::ZExt; |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 980 | } |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 981 | } |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 982 | break; |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 983 | |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 984 | case ABIArgInfo::Ignore: |
| 985 | // Skip increment, no matching LLVM parameter. |
| 986 | continue; |
| 987 | |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 988 | case ABIArgInfo::Expand: { |
| 989 | std::vector<const llvm::Type*> Tys; |
| 990 | // FIXME: This is rather inefficient. Do we ever actually need |
| 991 | // to do anything here? The result should be just reconstructed |
| 992 | // on the other side, so extension should be a non-issue. |
| 993 | getTypes().GetExpandedTypes(ParamType, Tys); |
| 994 | Index += Tys.size(); |
| 995 | continue; |
| 996 | } |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 997 | } |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 998 | |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 999 | if (Attributes) |
| 1000 | PAL.push_back(llvm::AttributeWithIndex::get(Index, Attributes)); |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1001 | ++Index; |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 1002 | } |
Devang Patel | a2c6912 | 2008-09-26 22:53:57 +0000 | [diff] [blame] | 1003 | if (FuncAttrs) |
| 1004 | PAL.push_back(llvm::AttributeWithIndex::get(~0, FuncAttrs)); |
| 1005 | |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1008 | void CodeGenFunction::EmitFunctionProlog(llvm::Function *Fn, |
| 1009 | QualType RetTy, |
| 1010 | const FunctionArgList &Args) { |
| 1011 | // Emit allocs for param decls. Give the LLVM Argument nodes names. |
| 1012 | llvm::Function::arg_iterator AI = Fn->arg_begin(); |
| 1013 | |
| 1014 | // Name the struct return argument. |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1015 | if (CGM.ReturnTypeUsesSret(RetTy)) { |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1016 | AI->setName("agg.result"); |
| 1017 | ++AI; |
| 1018 | } |
| 1019 | |
| 1020 | for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end(); |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1021 | i != e; ++i) { |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1022 | const VarDecl *Arg = i->first; |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1023 | QualType Ty = i->second; |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 1024 | ABIArgInfo ArgI = getABIArgumentInfo(Ty, CGM.getTypes()); |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 1025 | |
| 1026 | switch (ArgI.getKind()) { |
| 1027 | case ABIArgInfo::ByVal: |
| 1028 | case ABIArgInfo::Default: { |
| 1029 | assert(AI != Fn->arg_end() && "Argument mismatch!"); |
| 1030 | llvm::Value* V = AI; |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1031 | if (!getContext().typesAreCompatible(Ty, Arg->getType())) { |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 1032 | // This must be a promotion, for something like |
| 1033 | // "void a(x) short x; {..." |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1034 | V = EmitScalarConversion(V, Ty, Arg->getType()); |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1035 | } |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 1036 | EmitParmDecl(*Arg, V); |
| 1037 | break; |
| 1038 | } |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1039 | |
| 1040 | case ABIArgInfo::Expand: { |
| 1041 | // If this was structure was expand into multiple arguments then |
| 1042 | // we need to create a temporary and reconstruct it from the |
| 1043 | // arguments. |
Chris Lattner | 39f34e9 | 2008-11-24 04:00:27 +0000 | [diff] [blame] | 1044 | std::string Name = Arg->getNameAsString(); |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1045 | llvm::Value *Temp = CreateTempAlloca(ConvertType(Ty), |
| 1046 | (Name + ".addr").c_str()); |
| 1047 | // FIXME: What are the right qualifiers here? |
| 1048 | llvm::Function::arg_iterator End = |
| 1049 | ExpandTypeFromArgs(Ty, LValue::MakeAddr(Temp,0), AI); |
| 1050 | EmitParmDecl(*Arg, Temp); |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 1051 | |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1052 | // Name the arguments used in expansion and increment AI. |
| 1053 | unsigned Index = 0; |
| 1054 | for (; AI != End; ++AI, ++Index) |
| 1055 | AI->setName(Name + "." + llvm::utostr(Index)); |
| 1056 | continue; |
| 1057 | } |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 1058 | |
| 1059 | case ABIArgInfo::Ignore: |
| 1060 | break; |
| 1061 | |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 1062 | case ABIArgInfo::Coerce: |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 1063 | case ABIArgInfo::StructRet: |
| 1064 | assert(0 && "Invalid ABI kind for non-return argument"); |
| 1065 | } |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1066 | |
| 1067 | ++AI; |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1068 | } |
| 1069 | assert(AI == Fn->arg_end() && "Argument mismatch!"); |
| 1070 | } |
| 1071 | |
Daniel Dunbar | 54d1ccb | 2009-01-27 01:36:03 +0000 | [diff] [blame] | 1072 | /// CreateCoercedLoad - Create a load from \arg SrcPtr interpreted as |
| 1073 | /// a pointer to an object of type \arg Ty. |
| 1074 | /// |
| 1075 | /// This safely handles the case when the src type is smaller than the |
| 1076 | /// destination type; in this situation the values of bits which not |
| 1077 | /// present in the src are undefined. |
| 1078 | static llvm::Value *CreateCoercedLoad(llvm::Value *SrcPtr, |
| 1079 | const llvm::Type *Ty, |
| 1080 | CodeGenFunction &CGF) { |
| 1081 | const llvm::Type *SrcTy = |
| 1082 | cast<llvm::PointerType>(SrcPtr->getType())->getElementType(); |
Daniel Dunbar | e620ecd | 2009-01-30 00:47:38 +0000 | [diff] [blame^] | 1083 | uint64_t SrcSize = CGF.CGM.getTargetData().getTypePaddedSize(SrcTy); |
| 1084 | uint64_t DstSize = CGF.CGM.getTargetData().getTypePaddedSize(Ty); |
Daniel Dunbar | 54d1ccb | 2009-01-27 01:36:03 +0000 | [diff] [blame] | 1085 | |
| 1086 | // If load is legal, just bitcase the src pointer. |
| 1087 | if (SrcSize == DstSize) { |
| 1088 | llvm::Value *Casted = |
| 1089 | CGF.Builder.CreateBitCast(SrcPtr, llvm::PointerType::getUnqual(Ty)); |
| 1090 | return CGF.Builder.CreateLoad(Casted); |
| 1091 | } else { |
| 1092 | assert(SrcSize < DstSize && "Coercion is losing source bits!"); |
| 1093 | |
| 1094 | // Otherwise do coercion through memory. This is stupid, but |
| 1095 | // simple. |
| 1096 | llvm::Value *Tmp = CGF.CreateTempAlloca(Ty); |
| 1097 | llvm::Value *Casted = |
| 1098 | CGF.Builder.CreateBitCast(Tmp, llvm::PointerType::getUnqual(SrcTy)); |
| 1099 | CGF.Builder.CreateStore(CGF.Builder.CreateLoad(SrcPtr), Casted); |
| 1100 | return CGF.Builder.CreateLoad(Tmp); |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | /// CreateCoercedStore - Create a store to \arg DstPtr from \arg Src, |
| 1105 | /// where the source and destination may have different types. |
| 1106 | /// |
| 1107 | /// This safely handles the case when the src type is larger than the |
| 1108 | /// destination type; the upper bits of the src will be lost. |
| 1109 | static void CreateCoercedStore(llvm::Value *Src, |
| 1110 | llvm::Value *DstPtr, |
| 1111 | CodeGenFunction &CGF) { |
| 1112 | const llvm::Type *SrcTy = Src->getType(); |
| 1113 | const llvm::Type *DstTy = |
| 1114 | cast<llvm::PointerType>(DstPtr->getType())->getElementType(); |
| 1115 | |
Daniel Dunbar | e620ecd | 2009-01-30 00:47:38 +0000 | [diff] [blame^] | 1116 | uint64_t SrcSize = CGF.CGM.getTargetData().getTypePaddedSize(SrcTy); |
| 1117 | uint64_t DstSize = CGF.CGM.getTargetData().getTypePaddedSize(DstTy); |
Daniel Dunbar | 54d1ccb | 2009-01-27 01:36:03 +0000 | [diff] [blame] | 1118 | |
| 1119 | // If store is legal, just bitcase the src pointer. |
| 1120 | if (SrcSize == DstSize) { |
| 1121 | llvm::Value *Casted = |
| 1122 | CGF.Builder.CreateBitCast(DstPtr, llvm::PointerType::getUnqual(SrcTy)); |
| 1123 | CGF.Builder.CreateStore(Src, Casted); |
| 1124 | } else { |
| 1125 | assert(SrcSize > DstSize && "Coercion is missing bits!"); |
| 1126 | |
| 1127 | // Otherwise do coercion through memory. This is stupid, but |
| 1128 | // simple. |
| 1129 | llvm::Value *Tmp = CGF.CreateTempAlloca(SrcTy); |
| 1130 | CGF.Builder.CreateStore(Src, Tmp); |
| 1131 | llvm::Value *Casted = |
| 1132 | CGF.Builder.CreateBitCast(Tmp, llvm::PointerType::getUnqual(DstTy)); |
| 1133 | CGF.Builder.CreateStore(CGF.Builder.CreateLoad(Casted), DstPtr); |
| 1134 | } |
| 1135 | } |
| 1136 | |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1137 | void CodeGenFunction::EmitFunctionEpilog(QualType RetTy, |
| 1138 | llvm::Value *ReturnValue) { |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1139 | llvm::Value *RV = 0; |
| 1140 | |
| 1141 | // Functions with no result always return void. |
| 1142 | if (ReturnValue) { |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 1143 | ABIArgInfo RetAI = getABIReturnInfo(RetTy, CGM.getTypes()); |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1144 | |
| 1145 | switch (RetAI.getKind()) { |
| 1146 | case ABIArgInfo::StructRet: |
Daniel Dunbar | 3aea8ca | 2008-12-18 04:52:14 +0000 | [diff] [blame] | 1147 | if (RetTy->isAnyComplexType()) { |
| 1148 | // FIXME: Volatile |
| 1149 | ComplexPairTy RT = LoadComplexFromAddr(ReturnValue, false); |
| 1150 | StoreComplexToAddr(RT, CurFn->arg_begin(), false); |
| 1151 | } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) { |
| 1152 | EmitAggregateCopy(CurFn->arg_begin(), ReturnValue, RetTy); |
| 1153 | } else { |
| 1154 | Builder.CreateStore(Builder.CreateLoad(ReturnValue), |
| 1155 | CurFn->arg_begin()); |
| 1156 | } |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1157 | break; |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 1158 | |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1159 | case ABIArgInfo::Default: |
| 1160 | RV = Builder.CreateLoad(ReturnValue); |
| 1161 | break; |
| 1162 | |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 1163 | case ABIArgInfo::Ignore: |
| 1164 | break; |
| 1165 | |
Daniel Dunbar | 639ffe4 | 2008-09-10 07:04:09 +0000 | [diff] [blame] | 1166 | case ABIArgInfo::Coerce: { |
Daniel Dunbar | 54d1ccb | 2009-01-27 01:36:03 +0000 | [diff] [blame] | 1167 | RV = CreateCoercedLoad(ReturnValue, RetAI.getCoerceToType(), *this); |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 1168 | break; |
Daniel Dunbar | 639ffe4 | 2008-09-10 07:04:09 +0000 | [diff] [blame] | 1169 | } |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 1170 | |
| 1171 | case ABIArgInfo::ByVal: |
| 1172 | case ABIArgInfo::Expand: |
| 1173 | assert(0 && "Invalid ABI kind for return argument"); |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1174 | } |
| 1175 | } |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1176 | |
| 1177 | if (RV) { |
| 1178 | Builder.CreateRet(RV); |
| 1179 | } else { |
| 1180 | Builder.CreateRetVoid(); |
| 1181 | } |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | RValue CodeGenFunction::EmitCall(llvm::Value *Callee, |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1185 | QualType RetTy, |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1186 | const CallArgList &CallArgs) { |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1187 | llvm::SmallVector<llvm::Value*, 16> Args; |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1188 | |
| 1189 | // Handle struct-return functions by passing a pointer to the |
| 1190 | // location that we would like to return into. |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 1191 | ABIArgInfo RetAI = getABIReturnInfo(RetTy, CGM.getTypes()); |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1192 | switch (RetAI.getKind()) { |
| 1193 | case ABIArgInfo::StructRet: |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1194 | // Create a temporary alloca to hold the result of the call. :( |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1195 | Args.push_back(CreateTempAlloca(ConvertType(RetTy))); |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1196 | break; |
| 1197 | |
| 1198 | case ABIArgInfo::Default: |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 1199 | case ABIArgInfo::Ignore: |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1200 | case ABIArgInfo::Coerce: |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1201 | break; |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 1202 | |
| 1203 | case ABIArgInfo::ByVal: |
| 1204 | case ABIArgInfo::Expand: |
| 1205 | assert(0 && "Invalid ABI kind for return argument"); |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | for (CallArgList::const_iterator I = CallArgs.begin(), E = CallArgs.end(); |
| 1209 | I != E; ++I) { |
Daniel Dunbar | 6b1da0e | 2008-10-13 17:02:26 +0000 | [diff] [blame] | 1210 | ABIArgInfo ArgInfo = getABIArgumentInfo(I->second, CGM.getTypes()); |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1211 | RValue RV = I->first; |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1212 | |
| 1213 | switch (ArgInfo.getKind()) { |
| 1214 | case ABIArgInfo::ByVal: // Default is byval |
| 1215 | case ABIArgInfo::Default: |
| 1216 | if (RV.isScalar()) { |
| 1217 | Args.push_back(RV.getScalarVal()); |
| 1218 | } else if (RV.isComplex()) { |
| 1219 | // Make a temporary alloca to pass the argument. |
| 1220 | Args.push_back(CreateTempAlloca(ConvertType(I->second))); |
| 1221 | StoreComplexToAddr(RV.getComplexVal(), Args.back(), false); |
| 1222 | } else { |
| 1223 | Args.push_back(RV.getAggregateAddr()); |
| 1224 | } |
| 1225 | break; |
| 1226 | |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 1227 | case ABIArgInfo::Ignore: |
| 1228 | break; |
| 1229 | |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1230 | case ABIArgInfo::StructRet: |
| 1231 | case ABIArgInfo::Coerce: |
| 1232 | assert(0 && "Invalid ABI kind for non-return argument"); |
| 1233 | break; |
| 1234 | |
| 1235 | case ABIArgInfo::Expand: |
| 1236 | ExpandTypeToArgs(I->second, RV, Args); |
| 1237 | break; |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | llvm::CallInst *CI = Builder.CreateCall(Callee,&Args[0],&Args[0]+Args.size()); |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1242 | CGCallInfo CallInfo(RetTy, CallArgs); |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1243 | |
Daniel Dunbar | 5323a4b | 2008-09-10 00:32:18 +0000 | [diff] [blame] | 1244 | // FIXME: Provide TargetDecl so nounwind, noreturn, etc, etc get set. |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 1245 | CodeGen::AttributeListType AttributeList; |
| 1246 | CGM.ConstructAttributeList(0, |
Daniel Dunbar | b768807 | 2008-09-10 00:41:16 +0000 | [diff] [blame] | 1247 | CallInfo.argtypes_begin(), CallInfo.argtypes_end(), |
Devang Patel | 761d7f7 | 2008-09-25 21:02:23 +0000 | [diff] [blame] | 1248 | AttributeList); |
| 1249 | CI->setAttributes(llvm::AttrListPtr::get(AttributeList.begin(), |
| 1250 | AttributeList.size())); |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1251 | |
| 1252 | if (const llvm::Function *F = dyn_cast<llvm::Function>(Callee)) |
| 1253 | CI->setCallingConv(F->getCallingConv()); |
| 1254 | if (CI->getType() != llvm::Type::VoidTy) |
| 1255 | CI->setName("call"); |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1256 | |
| 1257 | switch (RetAI.getKind()) { |
| 1258 | case ABIArgInfo::StructRet: |
| 1259 | if (RetTy->isAnyComplexType()) |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1260 | return RValue::getComplex(LoadComplexFromAddr(Args[0], false)); |
Daniel Dunbar | 3aea8ca | 2008-12-18 04:52:14 +0000 | [diff] [blame] | 1261 | else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) |
Daniel Dunbar | 5627377 | 2008-09-17 00:51:38 +0000 | [diff] [blame] | 1262 | return RValue::getAggregate(Args[0]); |
Daniel Dunbar | 3aea8ca | 2008-12-18 04:52:14 +0000 | [diff] [blame] | 1263 | else |
| 1264 | return RValue::get(Builder.CreateLoad(Args[0])); |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 1265 | |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1266 | case ABIArgInfo::Default: |
| 1267 | return RValue::get(RetTy->isVoidType() ? 0 : CI); |
| 1268 | |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 1269 | case ABIArgInfo::Ignore: |
Daniel Dunbar | cc039fe | 2009-01-29 08:24:57 +0000 | [diff] [blame] | 1270 | if (RetTy->isVoidType()) |
| 1271 | return RValue::get(0); |
| 1272 | if (CodeGenFunction::hasAggregateLLVMType(RetTy)) { |
| 1273 | llvm::Value *Res = |
| 1274 | llvm::UndefValue::get(llvm::PointerType::getUnqual(ConvertType(RetTy))); |
| 1275 | return RValue::getAggregate(Res); |
| 1276 | } |
| 1277 | return RValue::get(llvm::UndefValue::get(ConvertType(RetTy))); |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 1278 | |
Daniel Dunbar | 639ffe4 | 2008-09-10 07:04:09 +0000 | [diff] [blame] | 1279 | case ABIArgInfo::Coerce: { |
Daniel Dunbar | 54d1ccb | 2009-01-27 01:36:03 +0000 | [diff] [blame] | 1280 | llvm::Value *V = CreateTempAlloca(ConvertType(RetTy), "coerce"); |
| 1281 | CreateCoercedStore(CI, V, *this); |
Anders Carlsson | ad3d691 | 2008-11-25 22:21:48 +0000 | [diff] [blame] | 1282 | if (RetTy->isAnyComplexType()) |
| 1283 | return RValue::getComplex(LoadComplexFromAddr(V, false)); |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 1284 | else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) |
Anders Carlsson | ad3d691 | 2008-11-25 22:21:48 +0000 | [diff] [blame] | 1285 | return RValue::getAggregate(V); |
Daniel Dunbar | 1143492 | 2009-01-26 21:26:08 +0000 | [diff] [blame] | 1286 | else |
| 1287 | return RValue::get(Builder.CreateLoad(V)); |
Daniel Dunbar | 639ffe4 | 2008-09-10 07:04:09 +0000 | [diff] [blame] | 1288 | } |
Daniel Dunbar | 8951dbd | 2008-09-11 01:48:57 +0000 | [diff] [blame] | 1289 | |
| 1290 | case ABIArgInfo::ByVal: |
| 1291 | case ABIArgInfo::Expand: |
| 1292 | assert(0 && "Invalid ABI kind for return argument"); |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1293 | } |
Daniel Dunbar | 2c8e0f3 | 2008-09-10 02:41:04 +0000 | [diff] [blame] | 1294 | |
| 1295 | assert(0 && "Unhandled ABIArgInfo::Kind"); |
| 1296 | return RValue::get(0); |
Daniel Dunbar | 17b708d | 2008-09-09 23:27:19 +0000 | [diff] [blame] | 1297 | } |