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