Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 1 | //===---- TargetInfo.cpp - Encapsulate target details -----------*- C++ -*-===// |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 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 | |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 15 | #include "TargetInfo.h" |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 16 | #include "ABIInfo.h" |
| 17 | #include "CodeGenFunction.h" |
Anders Carlsson | 19cc4ab | 2009-07-18 19:43:29 +0000 | [diff] [blame] | 18 | #include "clang/AST/RecordLayout.h" |
Sandeep Patel | 34c1af8 | 2011-04-05 00:23:47 +0000 | [diff] [blame] | 19 | #include "clang/Frontend/CodeGenOptions.h" |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 20 | #include "llvm/Type.h" |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetData.h" |
Daniel Dunbar | 2c0843f | 2009-08-24 08:52:16 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/Triple.h" |
Daniel Dunbar | 28df7a5 | 2009-12-03 09:13:49 +0000 | [diff] [blame] | 23 | #include "llvm/Support/raw_ostream.h" |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | using namespace CodeGen; |
| 26 | |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 27 | static void AssignToArrayRange(CodeGen::CGBuilderTy &Builder, |
| 28 | llvm::Value *Array, |
| 29 | llvm::Value *Value, |
| 30 | unsigned FirstIndex, |
| 31 | unsigned LastIndex) { |
| 32 | // Alternatively, we could emit this as a loop in the source. |
| 33 | for (unsigned I = FirstIndex; I <= LastIndex; ++I) { |
| 34 | llvm::Value *Cell = Builder.CreateConstInBoundsGEP1_32(Array, I); |
| 35 | Builder.CreateStore(Value, Cell); |
| 36 | } |
| 37 | } |
| 38 | |
John McCall | d608cdb | 2010-08-22 10:59:02 +0000 | [diff] [blame] | 39 | static bool isAggregateTypeForABI(QualType T) { |
| 40 | return CodeGenFunction::hasAggregateLLVMType(T) || |
| 41 | T->isMemberFunctionPointerType(); |
| 42 | } |
| 43 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 44 | ABIInfo::~ABIInfo() {} |
| 45 | |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 46 | ASTContext &ABIInfo::getContext() const { |
| 47 | return CGT.getContext(); |
| 48 | } |
| 49 | |
| 50 | llvm::LLVMContext &ABIInfo::getVMContext() const { |
| 51 | return CGT.getLLVMContext(); |
| 52 | } |
| 53 | |
| 54 | const llvm::TargetData &ABIInfo::getTargetData() const { |
| 55 | return CGT.getTargetData(); |
| 56 | } |
| 57 | |
| 58 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 59 | void ABIArgInfo::dump() const { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 60 | raw_ostream &OS = llvm::errs(); |
Daniel Dunbar | 28df7a5 | 2009-12-03 09:13:49 +0000 | [diff] [blame] | 61 | OS << "(ABIArgInfo Kind="; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 62 | switch (TheKind) { |
| 63 | case Direct: |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 64 | OS << "Direct Type="; |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 65 | if (llvm::Type *Ty = getCoerceToType()) |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 66 | Ty->print(OS); |
| 67 | else |
| 68 | OS << "null"; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 69 | break; |
Anton Korobeynikov | cc6fa88 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 70 | case Extend: |
Daniel Dunbar | 28df7a5 | 2009-12-03 09:13:49 +0000 | [diff] [blame] | 71 | OS << "Extend"; |
Anton Korobeynikov | cc6fa88 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 72 | break; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 73 | case Ignore: |
Daniel Dunbar | 28df7a5 | 2009-12-03 09:13:49 +0000 | [diff] [blame] | 74 | OS << "Ignore"; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 75 | break; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 76 | case Indirect: |
Daniel Dunbar | dc6d574 | 2010-04-21 19:10:51 +0000 | [diff] [blame] | 77 | OS << "Indirect Align=" << getIndirectAlign() |
Joerg Sonnenberger | e9b5d77 | 2011-07-15 18:23:44 +0000 | [diff] [blame] | 78 | << " ByVal=" << getIndirectByVal() |
Daniel Dunbar | cf3b6f2 | 2010-09-16 20:42:02 +0000 | [diff] [blame] | 79 | << " Realign=" << getIndirectRealign(); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 80 | break; |
| 81 | case Expand: |
Daniel Dunbar | 28df7a5 | 2009-12-03 09:13:49 +0000 | [diff] [blame] | 82 | OS << "Expand"; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 83 | break; |
| 84 | } |
Daniel Dunbar | 28df7a5 | 2009-12-03 09:13:49 +0000 | [diff] [blame] | 85 | OS << ")\n"; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 88 | TargetCodeGenInfo::~TargetCodeGenInfo() { delete Info; } |
| 89 | |
John McCall | 49e34be | 2011-08-30 01:42:09 +0000 | [diff] [blame] | 90 | // If someone can figure out a general rule for this, that would be great. |
| 91 | // It's probably just doomed to be platform-dependent, though. |
| 92 | unsigned TargetCodeGenInfo::getSizeOfUnwindException() const { |
| 93 | // Verified for: |
| 94 | // x86-64 FreeBSD, Linux, Darwin |
| 95 | // x86-32 FreeBSD, Linux, Darwin |
| 96 | // PowerPC Linux, Darwin |
| 97 | // ARM Darwin (*not* EABI) |
| 98 | return 32; |
| 99 | } |
| 100 | |
John McCall | 01f151e | 2011-09-21 08:08:30 +0000 | [diff] [blame] | 101 | bool TargetCodeGenInfo::isNoProtoCallVariadic(CallingConv CC) const { |
| 102 | // The following conventions are known to require this to be false: |
| 103 | // x86_stdcall |
| 104 | // MIPS |
| 105 | // For everything else, we just prefer false unless we opt out. |
| 106 | return false; |
| 107 | } |
| 108 | |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 109 | static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 110 | |
| 111 | /// isEmptyField - Return true iff a the field is "empty", that is it |
| 112 | /// is an unnamed bit-field or an (array of) empty record(s). |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 113 | static bool isEmptyField(ASTContext &Context, const FieldDecl *FD, |
| 114 | bool AllowArrays) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 115 | if (FD->isUnnamedBitfield()) |
| 116 | return true; |
| 117 | |
| 118 | QualType FT = FD->getType(); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 119 | |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 120 | // Constant arrays of empty records count as empty, strip them off. |
| 121 | if (AllowArrays) |
| 122 | while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT)) |
| 123 | FT = AT->getElementType(); |
| 124 | |
Daniel Dunbar | 5ea6861 | 2010-05-17 16:46:00 +0000 | [diff] [blame] | 125 | const RecordType *RT = FT->getAs<RecordType>(); |
| 126 | if (!RT) |
| 127 | return false; |
| 128 | |
| 129 | // C++ record fields are never empty, at least in the Itanium ABI. |
| 130 | // |
| 131 | // FIXME: We should use a predicate for whether this behavior is true in the |
| 132 | // current ABI. |
| 133 | if (isa<CXXRecordDecl>(RT->getDecl())) |
| 134 | return false; |
| 135 | |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 136 | return isEmptyRecord(Context, FT, AllowArrays); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /// isEmptyRecord - Return true iff a structure contains only empty |
| 140 | /// fields. Note that a structure with a flexible array member is not |
| 141 | /// considered empty. |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 142 | static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays) { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 143 | const RecordType *RT = T->getAs<RecordType>(); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 144 | if (!RT) |
| 145 | return 0; |
| 146 | const RecordDecl *RD = RT->getDecl(); |
| 147 | if (RD->hasFlexibleArrayMember()) |
| 148 | return false; |
Daniel Dunbar | 5ea6861 | 2010-05-17 16:46:00 +0000 | [diff] [blame] | 149 | |
Argyrios Kyrtzidis | c5f18f3 | 2011-05-17 02:17:52 +0000 | [diff] [blame] | 150 | // If this is a C++ record, check the bases first. |
Daniel Dunbar | 5ea6861 | 2010-05-17 16:46:00 +0000 | [diff] [blame] | 151 | if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) |
Argyrios Kyrtzidis | c5f18f3 | 2011-05-17 02:17:52 +0000 | [diff] [blame] | 152 | for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(), |
| 153 | e = CXXRD->bases_end(); i != e; ++i) |
| 154 | if (!isEmptyRecord(Context, i->getType(), true)) |
| 155 | return false; |
Daniel Dunbar | 5ea6861 | 2010-05-17 16:46:00 +0000 | [diff] [blame] | 156 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 157 | for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); |
| 158 | i != e; ++i) |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 159 | if (!isEmptyField(Context, *i, AllowArrays)) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 160 | return false; |
| 161 | return true; |
| 162 | } |
| 163 | |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 164 | /// hasNonTrivialDestructorOrCopyConstructor - Determine if a type has either |
| 165 | /// a non-trivial destructor or a non-trivial copy constructor. |
| 166 | static bool hasNonTrivialDestructorOrCopyConstructor(const RecordType *RT) { |
| 167 | const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()); |
| 168 | if (!RD) |
| 169 | return false; |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 170 | |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 171 | return !RD->hasTrivialDestructor() || !RD->hasTrivialCopyConstructor(); |
| 172 | } |
| 173 | |
| 174 | /// isRecordWithNonTrivialDestructorOrCopyConstructor - Determine if a type is |
| 175 | /// a record type with either a non-trivial destructor or a non-trivial copy |
| 176 | /// constructor. |
| 177 | static bool isRecordWithNonTrivialDestructorOrCopyConstructor(QualType T) { |
| 178 | const RecordType *RT = T->getAs<RecordType>(); |
| 179 | if (!RT) |
| 180 | return false; |
| 181 | |
| 182 | return hasNonTrivialDestructorOrCopyConstructor(RT); |
| 183 | } |
| 184 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 185 | /// isSingleElementStruct - Determine if a structure is a "single |
| 186 | /// element struct", i.e. it has exactly one non-empty field or |
| 187 | /// exactly one field which is itself a single element |
| 188 | /// struct. Structures with flexible array members are never |
| 189 | /// considered single element structs. |
| 190 | /// |
| 191 | /// \return The field declaration for the single non-empty field, if |
| 192 | /// it exists. |
| 193 | static const Type *isSingleElementStruct(QualType T, ASTContext &Context) { |
| 194 | const RecordType *RT = T->getAsStructureType(); |
| 195 | if (!RT) |
| 196 | return 0; |
| 197 | |
| 198 | const RecordDecl *RD = RT->getDecl(); |
| 199 | if (RD->hasFlexibleArrayMember()) |
| 200 | return 0; |
| 201 | |
| 202 | const Type *Found = 0; |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 203 | |
Daniel Dunbar | 9430d5a | 2010-05-11 21:15:36 +0000 | [diff] [blame] | 204 | // If this is a C++ record, check the bases first. |
| 205 | if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) { |
| 206 | for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(), |
| 207 | e = CXXRD->bases_end(); i != e; ++i) { |
Daniel Dunbar | 9430d5a | 2010-05-11 21:15:36 +0000 | [diff] [blame] | 208 | // Ignore empty records. |
Daniel Dunbar | 5ea6861 | 2010-05-17 16:46:00 +0000 | [diff] [blame] | 209 | if (isEmptyRecord(Context, i->getType(), true)) |
Daniel Dunbar | 9430d5a | 2010-05-11 21:15:36 +0000 | [diff] [blame] | 210 | continue; |
| 211 | |
| 212 | // If we already found an element then this isn't a single-element struct. |
| 213 | if (Found) |
| 214 | return 0; |
| 215 | |
| 216 | // If this is non-empty and not a single element struct, the composite |
| 217 | // cannot be a single element struct. |
| 218 | Found = isSingleElementStruct(i->getType(), Context); |
| 219 | if (!Found) |
| 220 | return 0; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | // Check for single element. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 225 | for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); |
| 226 | i != e; ++i) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 227 | const FieldDecl *FD = *i; |
| 228 | QualType FT = FD->getType(); |
| 229 | |
| 230 | // Ignore empty fields. |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 231 | if (isEmptyField(Context, FD, true)) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 232 | continue; |
| 233 | |
| 234 | // If we already found an element then this isn't a single-element |
| 235 | // struct. |
| 236 | if (Found) |
| 237 | return 0; |
| 238 | |
| 239 | // Treat single element arrays as the element. |
| 240 | while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT)) { |
| 241 | if (AT->getSize().getZExtValue() != 1) |
| 242 | break; |
| 243 | FT = AT->getElementType(); |
| 244 | } |
| 245 | |
John McCall | d608cdb | 2010-08-22 10:59:02 +0000 | [diff] [blame] | 246 | if (!isAggregateTypeForABI(FT)) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 247 | Found = FT.getTypePtr(); |
| 248 | } else { |
| 249 | Found = isSingleElementStruct(FT, Context); |
| 250 | if (!Found) |
| 251 | return 0; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | return Found; |
| 256 | } |
| 257 | |
| 258 | static bool is32Or64BitBasicType(QualType Ty, ASTContext &Context) { |
Daniel Dunbar | a1842d3 | 2010-05-14 03:40:53 +0000 | [diff] [blame] | 259 | if (!Ty->getAs<BuiltinType>() && !Ty->hasPointerRepresentation() && |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 260 | !Ty->isAnyComplexType() && !Ty->isEnumeralType() && |
| 261 | !Ty->isBlockPointerType()) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 262 | return false; |
| 263 | |
| 264 | uint64_t Size = Context.getTypeSize(Ty); |
| 265 | return Size == 32 || Size == 64; |
| 266 | } |
| 267 | |
Daniel Dunbar | 53012f4 | 2009-11-09 01:33:53 +0000 | [diff] [blame] | 268 | /// canExpandIndirectArgument - Test whether an argument type which is to be |
| 269 | /// passed indirectly (on the stack) would have the equivalent layout if it was |
| 270 | /// expanded into separate arguments. If so, we prefer to do the latter to avoid |
| 271 | /// inhibiting optimizations. |
| 272 | /// |
| 273 | // FIXME: This predicate is missing many cases, currently it just follows |
| 274 | // llvm-gcc (checks that all fields are 32-bit or 64-bit primitive types). We |
| 275 | // should probably make this smarter, or better yet make the LLVM backend |
| 276 | // capable of handling it. |
| 277 | static bool canExpandIndirectArgument(QualType Ty, ASTContext &Context) { |
| 278 | // We can only expand structure types. |
| 279 | const RecordType *RT = Ty->getAs<RecordType>(); |
| 280 | if (!RT) |
| 281 | return false; |
| 282 | |
| 283 | // We can only expand (C) structures. |
| 284 | // |
| 285 | // FIXME: This needs to be generalized to handle classes as well. |
| 286 | const RecordDecl *RD = RT->getDecl(); |
| 287 | if (!RD->isStruct() || isa<CXXRecordDecl>(RD)) |
| 288 | return false; |
| 289 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 290 | for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); |
| 291 | i != e; ++i) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 292 | const FieldDecl *FD = *i; |
| 293 | |
| 294 | if (!is32Or64BitBasicType(FD->getType(), Context)) |
| 295 | return false; |
| 296 | |
| 297 | // FIXME: Reject bit-fields wholesale; there are two problems, we don't know |
| 298 | // how to expand them yet, and the predicate for telling if a bitfield still |
| 299 | // counts as "basic" is more complicated than what we were doing previously. |
| 300 | if (FD->isBitField()) |
| 301 | return false; |
| 302 | } |
| 303 | |
| 304 | return true; |
| 305 | } |
| 306 | |
| 307 | namespace { |
| 308 | /// DefaultABIInfo - The default implementation for ABI specific |
| 309 | /// details. This implementation provides information which results in |
| 310 | /// self-consistent and sensible LLVM IR generation, but does not |
| 311 | /// conform to any particular ABI. |
| 312 | class DefaultABIInfo : public ABIInfo { |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 313 | public: |
| 314 | DefaultABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {} |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 315 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 316 | ABIArgInfo classifyReturnType(QualType RetTy) const; |
| 317 | ABIArgInfo classifyArgumentType(QualType RetTy) const; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 318 | |
Chris Lattner | ee5dcd0 | 2010-07-29 02:31:05 +0000 | [diff] [blame] | 319 | virtual void computeInfo(CGFunctionInfo &FI) const { |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 320 | FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 321 | for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end(); |
| 322 | it != ie; ++it) |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 323 | it->info = classifyArgumentType(it->type); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 327 | CodeGenFunction &CGF) const; |
| 328 | }; |
| 329 | |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 330 | class DefaultTargetCodeGenInfo : public TargetCodeGenInfo { |
| 331 | public: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 332 | DefaultTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT) |
| 333 | : TargetCodeGenInfo(new DefaultABIInfo(CGT)) {} |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 334 | }; |
| 335 | |
| 336 | llvm::Value *DefaultABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 337 | CodeGenFunction &CGF) const { |
| 338 | return 0; |
| 339 | } |
| 340 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 341 | ABIArgInfo DefaultABIInfo::classifyArgumentType(QualType Ty) const { |
Jan Wen Voung | 9030693 | 2011-11-03 00:59:44 +0000 | [diff] [blame] | 342 | if (isAggregateTypeForABI(Ty)) { |
| 343 | // Records with non trivial destructors/constructors should not be passed |
| 344 | // by value. |
| 345 | if (isRecordWithNonTrivialDestructorOrCopyConstructor(Ty)) |
| 346 | return ABIArgInfo::getIndirect(0, /*ByVal=*/false); |
| 347 | |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 348 | return ABIArgInfo::getIndirect(0); |
Jan Wen Voung | 9030693 | 2011-11-03 00:59:44 +0000 | [diff] [blame] | 349 | } |
Daniel Dunbar | dc6d574 | 2010-04-21 19:10:51 +0000 | [diff] [blame] | 350 | |
Chris Lattner | a14db75 | 2010-03-11 18:19:55 +0000 | [diff] [blame] | 351 | // Treat an enum type as its underlying type. |
| 352 | if (const EnumType *EnumTy = Ty->getAs<EnumType>()) |
| 353 | Ty = EnumTy->getDecl()->getIntegerType(); |
Douglas Gregor | aa74a1e | 2010-02-02 20:10:50 +0000 | [diff] [blame] | 354 | |
Chris Lattner | a14db75 | 2010-03-11 18:19:55 +0000 | [diff] [blame] | 355 | return (Ty->isPromotableIntegerType() ? |
| 356 | ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Bob Wilson | 0024f94 | 2011-01-10 23:54:17 +0000 | [diff] [blame] | 359 | ABIArgInfo DefaultABIInfo::classifyReturnType(QualType RetTy) const { |
| 360 | if (RetTy->isVoidType()) |
| 361 | return ABIArgInfo::getIgnore(); |
| 362 | |
| 363 | if (isAggregateTypeForABI(RetTy)) |
| 364 | return ABIArgInfo::getIndirect(0); |
| 365 | |
| 366 | // Treat an enum type as its underlying type. |
| 367 | if (const EnumType *EnumTy = RetTy->getAs<EnumType>()) |
| 368 | RetTy = EnumTy->getDecl()->getIntegerType(); |
| 369 | |
| 370 | return (RetTy->isPromotableIntegerType() ? |
| 371 | ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
| 372 | } |
| 373 | |
Bill Wendling | bb465d7 | 2010-10-18 03:41:31 +0000 | [diff] [blame] | 374 | /// UseX86_MMXType - Return true if this is an MMX type that should use the special |
| 375 | /// x86_mmx type. |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 376 | bool UseX86_MMXType(llvm::Type *IRType) { |
Bill Wendling | bb465d7 | 2010-10-18 03:41:31 +0000 | [diff] [blame] | 377 | // If the type is an MMX type <2 x i32>, <4 x i16>, or <8 x i8>, use the |
| 378 | // special x86_mmx type. |
| 379 | return IRType->isVectorTy() && IRType->getPrimitiveSizeInBits() == 64 && |
| 380 | cast<llvm::VectorType>(IRType)->getElementType()->isIntegerTy() && |
| 381 | IRType->getScalarSizeInBits() != 64; |
| 382 | } |
| 383 | |
Jay Foad | ef6de3d | 2011-07-11 09:56:20 +0000 | [diff] [blame] | 384 | static llvm::Type* X86AdjustInlineAsmType(CodeGen::CodeGenFunction &CGF, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 385 | StringRef Constraint, |
Jay Foad | ef6de3d | 2011-07-11 09:56:20 +0000 | [diff] [blame] | 386 | llvm::Type* Ty) { |
Bill Wendling | 0507be6 | 2011-03-07 22:47:14 +0000 | [diff] [blame] | 387 | if ((Constraint == "y" || Constraint == "&y") && Ty->isVectorTy()) |
Peter Collingbourne | 4b93d66 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 388 | return llvm::Type::getX86_MMXTy(CGF.getLLVMContext()); |
| 389 | return Ty; |
| 390 | } |
| 391 | |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 392 | //===----------------------------------------------------------------------===// |
| 393 | // X86-32 ABI Implementation |
| 394 | //===----------------------------------------------------------------------===// |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 395 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 396 | /// X86_32ABIInfo - The X86-32 ABI information. |
| 397 | class X86_32ABIInfo : public ABIInfo { |
Daniel Dunbar | fb67d6c | 2010-09-16 20:41:56 +0000 | [diff] [blame] | 398 | static const unsigned MinABIStackAlignInBytes = 4; |
| 399 | |
David Chisnall | 1e4249c | 2009-08-17 23:08:21 +0000 | [diff] [blame] | 400 | bool IsDarwinVectorABI; |
| 401 | bool IsSmallStructInRegABI; |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 402 | bool IsMMXDisabled; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 403 | |
| 404 | static bool isRegisterSize(unsigned Size) { |
| 405 | return (Size == 8 || Size == 16 || Size == 32 || Size == 64); |
| 406 | } |
| 407 | |
| 408 | static bool shouldReturnTypeInRegister(QualType Ty, ASTContext &Context); |
| 409 | |
Daniel Dunbar | dc6d574 | 2010-04-21 19:10:51 +0000 | [diff] [blame] | 410 | /// getIndirectResult - Give a source type \arg Ty, return a suitable result |
| 411 | /// such that the argument will be passed in memory. |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 412 | ABIArgInfo getIndirectResult(QualType Ty, bool ByVal = true) const; |
Daniel Dunbar | dc6d574 | 2010-04-21 19:10:51 +0000 | [diff] [blame] | 413 | |
Daniel Dunbar | fb67d6c | 2010-09-16 20:41:56 +0000 | [diff] [blame] | 414 | /// \brief Return the alignment to use for the given type on the stack. |
Daniel Dunbar | e59d858 | 2010-09-16 20:42:06 +0000 | [diff] [blame] | 415 | unsigned getTypeStackAlignInBytes(QualType Ty, unsigned Align) const; |
Daniel Dunbar | fb67d6c | 2010-09-16 20:41:56 +0000 | [diff] [blame] | 416 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 417 | public: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 418 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 419 | ABIArgInfo classifyReturnType(QualType RetTy) const; |
| 420 | ABIArgInfo classifyArgumentType(QualType RetTy) const; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 421 | |
Chris Lattner | ee5dcd0 | 2010-07-29 02:31:05 +0000 | [diff] [blame] | 422 | virtual void computeInfo(CGFunctionInfo &FI) const { |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 423 | FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 424 | for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end(); |
| 425 | it != ie; ++it) |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 426 | it->info = classifyArgumentType(it->type); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 430 | CodeGenFunction &CGF) const; |
| 431 | |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 432 | X86_32ABIInfo(CodeGen::CodeGenTypes &CGT, bool d, bool p, bool m) |
| 433 | : ABIInfo(CGT), IsDarwinVectorABI(d), IsSmallStructInRegABI(p), |
| 434 | IsMMXDisabled(m) {} |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 435 | }; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 436 | |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 437 | class X86_32TargetCodeGenInfo : public TargetCodeGenInfo { |
| 438 | public: |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 439 | X86_32TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, bool d, bool p, bool m) |
| 440 | :TargetCodeGenInfo(new X86_32ABIInfo(CGT, d, p, m)) {} |
Charles Davis | 74f7293 | 2010-02-13 15:54:06 +0000 | [diff] [blame] | 441 | |
| 442 | void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV, |
| 443 | CodeGen::CodeGenModule &CGM) const; |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 444 | |
| 445 | int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const { |
| 446 | // Darwin uses different dwarf register numbers for EH. |
| 447 | if (CGM.isTargetDarwin()) return 5; |
| 448 | |
| 449 | return 4; |
| 450 | } |
| 451 | |
| 452 | bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, |
| 453 | llvm::Value *Address) const; |
Peter Collingbourne | 4b93d66 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 454 | |
Jay Foad | ef6de3d | 2011-07-11 09:56:20 +0000 | [diff] [blame] | 455 | llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 456 | StringRef Constraint, |
Jay Foad | ef6de3d | 2011-07-11 09:56:20 +0000 | [diff] [blame] | 457 | llvm::Type* Ty) const { |
Peter Collingbourne | 4b93d66 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 458 | return X86AdjustInlineAsmType(CGF, Constraint, Ty); |
| 459 | } |
| 460 | |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 461 | }; |
| 462 | |
| 463 | } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 464 | |
| 465 | /// shouldReturnTypeInRegister - Determine if the given type should be |
| 466 | /// passed in a register (for the Darwin ABI). |
| 467 | bool X86_32ABIInfo::shouldReturnTypeInRegister(QualType Ty, |
| 468 | ASTContext &Context) { |
| 469 | uint64_t Size = Context.getTypeSize(Ty); |
| 470 | |
| 471 | // Type must be register sized. |
| 472 | if (!isRegisterSize(Size)) |
| 473 | return false; |
| 474 | |
| 475 | if (Ty->isVectorType()) { |
| 476 | // 64- and 128- bit vectors inside structures are not returned in |
| 477 | // registers. |
| 478 | if (Size == 64 || Size == 128) |
| 479 | return false; |
| 480 | |
| 481 | return true; |
| 482 | } |
| 483 | |
Daniel Dunbar | 7711523 | 2010-05-15 00:00:30 +0000 | [diff] [blame] | 484 | // If this is a builtin, pointer, enum, complex type, member pointer, or |
| 485 | // member function pointer it is ok. |
Daniel Dunbar | a1842d3 | 2010-05-14 03:40:53 +0000 | [diff] [blame] | 486 | if (Ty->getAs<BuiltinType>() || Ty->hasPointerRepresentation() || |
Daniel Dunbar | 55e59e1 | 2009-09-24 05:12:36 +0000 | [diff] [blame] | 487 | Ty->isAnyComplexType() || Ty->isEnumeralType() || |
Daniel Dunbar | 7711523 | 2010-05-15 00:00:30 +0000 | [diff] [blame] | 488 | Ty->isBlockPointerType() || Ty->isMemberPointerType()) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 489 | return true; |
| 490 | |
| 491 | // Arrays are treated like records. |
| 492 | if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty)) |
| 493 | return shouldReturnTypeInRegister(AT->getElementType(), Context); |
| 494 | |
| 495 | // Otherwise, it must be a record type. |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 496 | const RecordType *RT = Ty->getAs<RecordType>(); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 497 | if (!RT) return false; |
| 498 | |
Anders Carlsson | a887423 | 2010-01-27 03:25:19 +0000 | [diff] [blame] | 499 | // FIXME: Traverse bases here too. |
| 500 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 501 | // Structure types are passed in register if all fields would be |
| 502 | // passed in a register. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 503 | for (RecordDecl::field_iterator i = RT->getDecl()->field_begin(), |
| 504 | e = RT->getDecl()->field_end(); i != e; ++i) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 505 | const FieldDecl *FD = *i; |
| 506 | |
| 507 | // Empty fields are ignored. |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 508 | if (isEmptyField(Context, FD, true)) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 509 | continue; |
| 510 | |
| 511 | // Check fields recursively. |
| 512 | if (!shouldReturnTypeInRegister(FD->getType(), Context)) |
| 513 | return false; |
| 514 | } |
| 515 | |
| 516 | return true; |
| 517 | } |
| 518 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 519 | ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy) const { |
| 520 | if (RetTy->isVoidType()) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 521 | return ABIArgInfo::getIgnore(); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 522 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 523 | if (const VectorType *VT = RetTy->getAs<VectorType>()) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 524 | // On Darwin, some vectors are returned in registers. |
David Chisnall | 1e4249c | 2009-08-17 23:08:21 +0000 | [diff] [blame] | 525 | if (IsDarwinVectorABI) { |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 526 | uint64_t Size = getContext().getTypeSize(RetTy); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 527 | |
| 528 | // 128-bit vectors are a special case; they are returned in |
| 529 | // registers and we need to make sure to pick a type the LLVM |
| 530 | // backend will like. |
| 531 | if (Size == 128) |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 532 | return ABIArgInfo::getDirect(llvm::VectorType::get( |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 533 | llvm::Type::getInt64Ty(getVMContext()), 2)); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 534 | |
| 535 | // Always return in register if it fits in a general purpose |
| 536 | // register, or if it is 64 bits and has a single element. |
| 537 | if ((Size == 8 || Size == 16 || Size == 32) || |
| 538 | (Size == 64 && VT->getNumElements() == 1)) |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 539 | return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(), |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 540 | Size)); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 541 | |
| 542 | return ABIArgInfo::getIndirect(0); |
| 543 | } |
| 544 | |
| 545 | return ABIArgInfo::getDirect(); |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 546 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 547 | |
John McCall | d608cdb | 2010-08-22 10:59:02 +0000 | [diff] [blame] | 548 | if (isAggregateTypeForABI(RetTy)) { |
Anders Carlsson | a887423 | 2010-01-27 03:25:19 +0000 | [diff] [blame] | 549 | if (const RecordType *RT = RetTy->getAs<RecordType>()) { |
Anders Carlsson | 4009297 | 2009-10-20 22:07:59 +0000 | [diff] [blame] | 550 | // Structures with either a non-trivial destructor or a non-trivial |
| 551 | // copy constructor are always indirect. |
| 552 | if (hasNonTrivialDestructorOrCopyConstructor(RT)) |
| 553 | return ABIArgInfo::getIndirect(0, /*ByVal=*/false); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 554 | |
Anders Carlsson | 4009297 | 2009-10-20 22:07:59 +0000 | [diff] [blame] | 555 | // Structures with flexible arrays are always indirect. |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 556 | if (RT->getDecl()->hasFlexibleArrayMember()) |
| 557 | return ABIArgInfo::getIndirect(0); |
Anders Carlsson | 4009297 | 2009-10-20 22:07:59 +0000 | [diff] [blame] | 558 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 559 | |
David Chisnall | 1e4249c | 2009-08-17 23:08:21 +0000 | [diff] [blame] | 560 | // If specified, structs and unions are always indirect. |
| 561 | if (!IsSmallStructInRegABI && !RetTy->isAnyComplexType()) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 562 | return ABIArgInfo::getIndirect(0); |
| 563 | |
| 564 | // Classify "single element" structs as their element type. |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 565 | if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext())) { |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 566 | if (const BuiltinType *BT = SeltTy->getAs<BuiltinType>()) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 567 | if (BT->isIntegerType()) { |
| 568 | // We need to use the size of the structure, padding |
| 569 | // bit-fields can adjust that to be larger than the single |
| 570 | // element type. |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 571 | uint64_t Size = getContext().getTypeSize(RetTy); |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 572 | return ABIArgInfo::getDirect( |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 573 | llvm::IntegerType::get(getVMContext(), (unsigned)Size)); |
| 574 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 575 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 576 | if (BT->getKind() == BuiltinType::Float) { |
| 577 | assert(getContext().getTypeSize(RetTy) == |
| 578 | getContext().getTypeSize(SeltTy) && |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 579 | "Unexpect single element structure size!"); |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 580 | return ABIArgInfo::getDirect(llvm::Type::getFloatTy(getVMContext())); |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 581 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 582 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 583 | if (BT->getKind() == BuiltinType::Double) { |
| 584 | assert(getContext().getTypeSize(RetTy) == |
| 585 | getContext().getTypeSize(SeltTy) && |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 586 | "Unexpect single element structure size!"); |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 587 | return ABIArgInfo::getDirect(llvm::Type::getDoubleTy(getVMContext())); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 588 | } |
| 589 | } else if (SeltTy->isPointerType()) { |
| 590 | // FIXME: It would be really nice if this could come out as the proper |
| 591 | // pointer type. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 592 | llvm::Type *PtrTy = llvm::Type::getInt8PtrTy(getVMContext()); |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 593 | return ABIArgInfo::getDirect(PtrTy); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 594 | } else if (SeltTy->isVectorType()) { |
| 595 | // 64- and 128-bit vectors are never returned in a |
| 596 | // register when inside a structure. |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 597 | uint64_t Size = getContext().getTypeSize(RetTy); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 598 | if (Size == 64 || Size == 128) |
| 599 | return ABIArgInfo::getIndirect(0); |
| 600 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 601 | return classifyReturnType(QualType(SeltTy, 0)); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 602 | } |
| 603 | } |
| 604 | |
| 605 | // Small structures which are register sized are generally returned |
| 606 | // in a register. |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 607 | if (X86_32ABIInfo::shouldReturnTypeInRegister(RetTy, getContext())) { |
| 608 | uint64_t Size = getContext().getTypeSize(RetTy); |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 609 | return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(),Size)); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | return ABIArgInfo::getIndirect(0); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 613 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 614 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 615 | // Treat an enum type as its underlying type. |
| 616 | if (const EnumType *EnumTy = RetTy->getAs<EnumType>()) |
| 617 | RetTy = EnumTy->getDecl()->getIntegerType(); |
| 618 | |
| 619 | return (RetTy->isPromotableIntegerType() ? |
| 620 | ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Daniel Dunbar | 93ae947 | 2010-09-16 20:42:00 +0000 | [diff] [blame] | 623 | static bool isRecordWithSSEVectorType(ASTContext &Context, QualType Ty) { |
| 624 | const RecordType *RT = Ty->getAs<RecordType>(); |
| 625 | if (!RT) |
| 626 | return 0; |
| 627 | const RecordDecl *RD = RT->getDecl(); |
| 628 | |
| 629 | // If this is a C++ record, check the bases first. |
| 630 | if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) |
| 631 | for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(), |
| 632 | e = CXXRD->bases_end(); i != e; ++i) |
| 633 | if (!isRecordWithSSEVectorType(Context, i->getType())) |
| 634 | return false; |
| 635 | |
| 636 | for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); |
| 637 | i != e; ++i) { |
| 638 | QualType FT = i->getType(); |
| 639 | |
| 640 | if (FT->getAs<VectorType>() && Context.getTypeSize(Ty) == 128) |
| 641 | return true; |
| 642 | |
| 643 | if (isRecordWithSSEVectorType(Context, FT)) |
| 644 | return true; |
| 645 | } |
| 646 | |
| 647 | return false; |
| 648 | } |
| 649 | |
Daniel Dunbar | e59d858 | 2010-09-16 20:42:06 +0000 | [diff] [blame] | 650 | unsigned X86_32ABIInfo::getTypeStackAlignInBytes(QualType Ty, |
| 651 | unsigned Align) const { |
| 652 | // Otherwise, if the alignment is less than or equal to the minimum ABI |
| 653 | // alignment, just use the default; the backend will handle this. |
Daniel Dunbar | fb67d6c | 2010-09-16 20:41:56 +0000 | [diff] [blame] | 654 | if (Align <= MinABIStackAlignInBytes) |
Daniel Dunbar | e59d858 | 2010-09-16 20:42:06 +0000 | [diff] [blame] | 655 | return 0; // Use default alignment. |
| 656 | |
| 657 | // On non-Darwin, the stack type alignment is always 4. |
| 658 | if (!IsDarwinVectorABI) { |
| 659 | // Set explicit alignment, since we may need to realign the top. |
Daniel Dunbar | fb67d6c | 2010-09-16 20:41:56 +0000 | [diff] [blame] | 660 | return MinABIStackAlignInBytes; |
Daniel Dunbar | e59d858 | 2010-09-16 20:42:06 +0000 | [diff] [blame] | 661 | } |
Daniel Dunbar | fb67d6c | 2010-09-16 20:41:56 +0000 | [diff] [blame] | 662 | |
Daniel Dunbar | 93ae947 | 2010-09-16 20:42:00 +0000 | [diff] [blame] | 663 | // Otherwise, if the type contains an SSE vector type, the alignment is 16. |
| 664 | if (isRecordWithSSEVectorType(getContext(), Ty)) |
| 665 | return 16; |
| 666 | |
| 667 | return MinABIStackAlignInBytes; |
Daniel Dunbar | fb67d6c | 2010-09-16 20:41:56 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 670 | ABIArgInfo X86_32ABIInfo::getIndirectResult(QualType Ty, bool ByVal) const { |
Daniel Dunbar | 46c54fb | 2010-04-21 19:49:55 +0000 | [diff] [blame] | 671 | if (!ByVal) |
| 672 | return ABIArgInfo::getIndirect(0, false); |
| 673 | |
Daniel Dunbar | e59d858 | 2010-09-16 20:42:06 +0000 | [diff] [blame] | 674 | // Compute the byval alignment. |
| 675 | unsigned TypeAlign = getContext().getTypeAlign(Ty) / 8; |
| 676 | unsigned StackAlign = getTypeStackAlignInBytes(Ty, TypeAlign); |
| 677 | if (StackAlign == 0) |
Chris Lattner | de92d73 | 2011-05-22 23:35:00 +0000 | [diff] [blame] | 678 | return ABIArgInfo::getIndirect(4); |
Daniel Dunbar | e59d858 | 2010-09-16 20:42:06 +0000 | [diff] [blame] | 679 | |
| 680 | // If the stack alignment is less than the type alignment, realign the |
| 681 | // argument. |
| 682 | if (StackAlign < TypeAlign) |
| 683 | return ABIArgInfo::getIndirect(StackAlign, /*ByVal=*/true, |
| 684 | /*Realign=*/true); |
| 685 | |
| 686 | return ABIArgInfo::getIndirect(StackAlign); |
Daniel Dunbar | dc6d574 | 2010-04-21 19:10:51 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 689 | ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty) const { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 690 | // FIXME: Set alignment on indirect arguments. |
John McCall | d608cdb | 2010-08-22 10:59:02 +0000 | [diff] [blame] | 691 | if (isAggregateTypeForABI(Ty)) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 692 | // Structures with flexible arrays are always indirect. |
Anders Carlsson | a887423 | 2010-01-27 03:25:19 +0000 | [diff] [blame] | 693 | if (const RecordType *RT = Ty->getAs<RecordType>()) { |
| 694 | // Structures with either a non-trivial destructor or a non-trivial |
| 695 | // copy constructor are always indirect. |
| 696 | if (hasNonTrivialDestructorOrCopyConstructor(RT)) |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 697 | return getIndirectResult(Ty, /*ByVal=*/false); |
Daniel Dunbar | dc6d574 | 2010-04-21 19:10:51 +0000 | [diff] [blame] | 698 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 699 | if (RT->getDecl()->hasFlexibleArrayMember()) |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 700 | return getIndirectResult(Ty); |
Anders Carlsson | a887423 | 2010-01-27 03:25:19 +0000 | [diff] [blame] | 701 | } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 702 | |
| 703 | // Ignore empty structs. |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 704 | if (Ty->isStructureType() && getContext().getTypeSize(Ty) == 0) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 705 | return ABIArgInfo::getIgnore(); |
| 706 | |
Daniel Dunbar | 53012f4 | 2009-11-09 01:33:53 +0000 | [diff] [blame] | 707 | // Expand small (<= 128-bit) record types when we know that the stack layout |
| 708 | // of those arguments will match the struct. This is important because the |
| 709 | // LLVM backend isn't smart enough to remove byval, which inhibits many |
| 710 | // optimizations. |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 711 | if (getContext().getTypeSize(Ty) <= 4*32 && |
| 712 | canExpandIndirectArgument(Ty, getContext())) |
Daniel Dunbar | 53012f4 | 2009-11-09 01:33:53 +0000 | [diff] [blame] | 713 | return ABIArgInfo::getExpand(); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 714 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 715 | return getIndirectResult(Ty); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Chris Lattner | bbae8b4 | 2010-08-26 20:05:13 +0000 | [diff] [blame] | 718 | if (const VectorType *VT = Ty->getAs<VectorType>()) { |
Chris Lattner | 7b73350 | 2010-08-26 20:08:43 +0000 | [diff] [blame] | 719 | // On Darwin, some vectors are passed in memory, we handle this by passing |
| 720 | // it as an i8/i16/i32/i64. |
Chris Lattner | bbae8b4 | 2010-08-26 20:05:13 +0000 | [diff] [blame] | 721 | if (IsDarwinVectorABI) { |
| 722 | uint64_t Size = getContext().getTypeSize(Ty); |
Chris Lattner | bbae8b4 | 2010-08-26 20:05:13 +0000 | [diff] [blame] | 723 | if ((Size == 8 || Size == 16 || Size == 32) || |
| 724 | (Size == 64 && VT->getNumElements() == 1)) |
| 725 | return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(), |
| 726 | Size)); |
Chris Lattner | bbae8b4 | 2010-08-26 20:05:13 +0000 | [diff] [blame] | 727 | } |
Bill Wendling | bb465d7 | 2010-10-18 03:41:31 +0000 | [diff] [blame] | 728 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 729 | llvm::Type *IRType = CGT.ConvertType(Ty); |
Bill Wendling | bb465d7 | 2010-10-18 03:41:31 +0000 | [diff] [blame] | 730 | if (UseX86_MMXType(IRType)) { |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 731 | if (IsMMXDisabled) |
| 732 | return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(), |
| 733 | 64)); |
Bill Wendling | bb465d7 | 2010-10-18 03:41:31 +0000 | [diff] [blame] | 734 | ABIArgInfo AAI = ABIArgInfo::getDirect(IRType); |
| 735 | AAI.setCoerceToType(llvm::Type::getX86_MMXTy(getVMContext())); |
| 736 | return AAI; |
| 737 | } |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 738 | |
Chris Lattner | bbae8b4 | 2010-08-26 20:05:13 +0000 | [diff] [blame] | 739 | return ABIArgInfo::getDirect(); |
| 740 | } |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 741 | |
| 742 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 743 | if (const EnumType *EnumTy = Ty->getAs<EnumType>()) |
| 744 | Ty = EnumTy->getDecl()->getIntegerType(); |
Douglas Gregor | aa74a1e | 2010-02-02 20:10:50 +0000 | [diff] [blame] | 745 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 746 | return (Ty->isPromotableIntegerType() ? |
| 747 | ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | llvm::Value *X86_32ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 751 | CodeGenFunction &CGF) const { |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 752 | llvm::Type *BP = llvm::Type::getInt8PtrTy(CGF.getLLVMContext()); |
| 753 | llvm::Type *BPP = llvm::PointerType::getUnqual(BP); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 754 | |
| 755 | CGBuilderTy &Builder = CGF.Builder; |
| 756 | llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP, |
| 757 | "ap"); |
| 758 | llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur"); |
| 759 | llvm::Type *PTy = |
Owen Anderson | 96e0fc7 | 2009-07-29 22:16:19 +0000 | [diff] [blame] | 760 | llvm::PointerType::getUnqual(CGF.ConvertType(Ty)); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 761 | llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy); |
| 762 | |
| 763 | uint64_t Offset = |
| 764 | llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4); |
| 765 | llvm::Value *NextAddr = |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 766 | Builder.CreateGEP(Addr, llvm::ConstantInt::get(CGF.Int32Ty, Offset), |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 767 | "ap.next"); |
| 768 | Builder.CreateStore(NextAddr, VAListAddrAsBPP); |
| 769 | |
| 770 | return AddrTyped; |
| 771 | } |
| 772 | |
Charles Davis | 74f7293 | 2010-02-13 15:54:06 +0000 | [diff] [blame] | 773 | void X86_32TargetCodeGenInfo::SetTargetAttributes(const Decl *D, |
| 774 | llvm::GlobalValue *GV, |
| 775 | CodeGen::CodeGenModule &CGM) const { |
| 776 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 777 | if (FD->hasAttr<X86ForceAlignArgPointerAttr>()) { |
| 778 | // Get the LLVM function. |
| 779 | llvm::Function *Fn = cast<llvm::Function>(GV); |
| 780 | |
| 781 | // Now add the 'alignstack' attribute with a value of 16. |
| 782 | Fn->addFnAttr(llvm::Attribute::constructStackAlignmentFromInt(16)); |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 787 | bool X86_32TargetCodeGenInfo::initDwarfEHRegSizeTable( |
| 788 | CodeGen::CodeGenFunction &CGF, |
| 789 | llvm::Value *Address) const { |
| 790 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 791 | llvm::LLVMContext &Context = CGF.getLLVMContext(); |
| 792 | |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 793 | llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context); |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 794 | llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 795 | |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 796 | // 0-7 are the eight integer registers; the order is different |
| 797 | // on Darwin (for EH), but the range is the same. |
| 798 | // 8 is %eip. |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 799 | AssignToArrayRange(Builder, Address, Four8, 0, 8); |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 800 | |
| 801 | if (CGF.CGM.isTargetDarwin()) { |
| 802 | // 12-16 are st(0..4). Not sure why we stop at 4. |
| 803 | // These have size 16, which is sizeof(long double) on |
| 804 | // platforms with 8-byte alignment for that type. |
| 805 | llvm::Value *Sixteen8 = llvm::ConstantInt::get(i8, 16); |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 806 | AssignToArrayRange(Builder, Address, Sixteen8, 12, 16); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 807 | |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 808 | } else { |
| 809 | // 9 is %eflags, which doesn't get a size on Darwin for some |
| 810 | // reason. |
| 811 | Builder.CreateStore(Four8, Builder.CreateConstInBoundsGEP1_32(Address, 9)); |
| 812 | |
| 813 | // 11-16 are st(0..5). Not sure why we stop at 5. |
| 814 | // These have size 12, which is sizeof(long double) on |
| 815 | // platforms with 4-byte alignment for that type. |
| 816 | llvm::Value *Twelve8 = llvm::ConstantInt::get(i8, 12); |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 817 | AssignToArrayRange(Builder, Address, Twelve8, 11, 16); |
| 818 | } |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 819 | |
| 820 | return false; |
| 821 | } |
| 822 | |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 823 | //===----------------------------------------------------------------------===// |
| 824 | // X86-64 ABI Implementation |
| 825 | //===----------------------------------------------------------------------===// |
| 826 | |
| 827 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 828 | namespace { |
| 829 | /// X86_64ABIInfo - The X86_64 ABI information. |
| 830 | class X86_64ABIInfo : public ABIInfo { |
| 831 | enum Class { |
| 832 | Integer = 0, |
| 833 | SSE, |
| 834 | SSEUp, |
| 835 | X87, |
| 836 | X87Up, |
| 837 | ComplexX87, |
| 838 | NoClass, |
| 839 | Memory |
| 840 | }; |
| 841 | |
| 842 | /// merge - Implement the X86_64 ABI merging algorithm. |
| 843 | /// |
| 844 | /// Merge an accumulating classification \arg Accum with a field |
| 845 | /// classification \arg Field. |
| 846 | /// |
| 847 | /// \param Accum - The accumulating classification. This should |
| 848 | /// always be either NoClass or the result of a previous merge |
| 849 | /// call. In addition, this should never be Memory (the caller |
| 850 | /// should just return Memory for the aggregate). |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 851 | static Class merge(Class Accum, Class Field); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 852 | |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 853 | /// postMerge - Implement the X86_64 ABI post merging algorithm. |
| 854 | /// |
| 855 | /// Post merger cleanup, reduces a malformed Hi and Lo pair to |
| 856 | /// final MEMORY or SSE classes when necessary. |
| 857 | /// |
| 858 | /// \param AggregateSize - The size of the current aggregate in |
| 859 | /// the classification process. |
| 860 | /// |
| 861 | /// \param Lo - The classification for the parts of the type |
| 862 | /// residing in the low word of the containing object. |
| 863 | /// |
| 864 | /// \param Hi - The classification for the parts of the type |
| 865 | /// residing in the higher words of the containing object. |
| 866 | /// |
| 867 | void postMerge(unsigned AggregateSize, Class &Lo, Class &Hi) const; |
| 868 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 869 | /// classify - Determine the x86_64 register classes in which the |
| 870 | /// given type T should be passed. |
| 871 | /// |
| 872 | /// \param Lo - The classification for the parts of the type |
| 873 | /// residing in the low word of the containing object. |
| 874 | /// |
| 875 | /// \param Hi - The classification for the parts of the type |
| 876 | /// residing in the high word of the containing object. |
| 877 | /// |
| 878 | /// \param OffsetBase - The bit offset of this type in the |
| 879 | /// containing object. Some parameters are classified different |
| 880 | /// depending on whether they straddle an eightbyte boundary. |
| 881 | /// |
| 882 | /// If a word is unused its result will be NoClass; if a type should |
| 883 | /// be passed in Memory then at least the classification of \arg Lo |
| 884 | /// will be Memory. |
| 885 | /// |
| 886 | /// The \arg Lo class will be NoClass iff the argument is ignored. |
| 887 | /// |
| 888 | /// If the \arg Lo class is ComplexX87, then the \arg Hi class will |
| 889 | /// also be ComplexX87. |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 890 | void classify(QualType T, uint64_t OffsetBase, Class &Lo, Class &Hi) const; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 891 | |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 892 | llvm::Type *GetByteVectorType(QualType Ty) const; |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 893 | llvm::Type *GetSSETypeAtOffset(llvm::Type *IRType, |
| 894 | unsigned IROffset, QualType SourceTy, |
| 895 | unsigned SourceOffset) const; |
| 896 | llvm::Type *GetINTEGERTypeAtOffset(llvm::Type *IRType, |
| 897 | unsigned IROffset, QualType SourceTy, |
| 898 | unsigned SourceOffset) const; |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 899 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 900 | /// getIndirectResult - Give a source type \arg Ty, return a suitable result |
Daniel Dunbar | 46c54fb | 2010-04-21 19:49:55 +0000 | [diff] [blame] | 901 | /// such that the argument will be returned in memory. |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 902 | ABIArgInfo getIndirectReturnResult(QualType Ty) const; |
Daniel Dunbar | 46c54fb | 2010-04-21 19:49:55 +0000 | [diff] [blame] | 903 | |
| 904 | /// getIndirectResult - Give a source type \arg Ty, return a suitable result |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 905 | /// such that the argument will be passed in memory. |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 906 | ABIArgInfo getIndirectResult(QualType Ty) const; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 907 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 908 | ABIArgInfo classifyReturnType(QualType RetTy) const; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 909 | |
Bill Wendling | bb465d7 | 2010-10-18 03:41:31 +0000 | [diff] [blame] | 910 | ABIArgInfo classifyArgumentType(QualType Ty, |
| 911 | unsigned &neededInt, |
Bill Wendling | 99aaae8 | 2010-10-18 23:51:38 +0000 | [diff] [blame] | 912 | unsigned &neededSSE) const; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 913 | |
John McCall | 67a5773 | 2011-04-21 01:20:55 +0000 | [diff] [blame] | 914 | /// The 0.98 ABI revision clarified a lot of ambiguities, |
| 915 | /// unfortunately in ways that were not always consistent with |
| 916 | /// certain previous compilers. In particular, platforms which |
| 917 | /// required strict binary compatibility with older versions of GCC |
| 918 | /// may need to exempt themselves. |
| 919 | bool honorsRevision0_98() const { |
Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 920 | return !getContext().getTargetInfo().getTriple().isOSDarwin(); |
John McCall | 67a5773 | 2011-04-21 01:20:55 +0000 | [diff] [blame] | 921 | } |
| 922 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 923 | public: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 924 | X86_64ABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {} |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 925 | |
Chris Lattner | ee5dcd0 | 2010-07-29 02:31:05 +0000 | [diff] [blame] | 926 | virtual void computeInfo(CGFunctionInfo &FI) const; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 927 | |
| 928 | virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 929 | CodeGenFunction &CGF) const; |
| 930 | }; |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 931 | |
Chris Lattner | f13721d | 2010-08-31 16:44:54 +0000 | [diff] [blame] | 932 | /// WinX86_64ABIInfo - The Windows X86_64 ABI information. |
NAKAMURA Takumi | a757322 | 2011-01-17 22:56:31 +0000 | [diff] [blame] | 933 | class WinX86_64ABIInfo : public ABIInfo { |
| 934 | |
| 935 | ABIArgInfo classify(QualType Ty) const; |
| 936 | |
Chris Lattner | f13721d | 2010-08-31 16:44:54 +0000 | [diff] [blame] | 937 | public: |
NAKAMURA Takumi | a757322 | 2011-01-17 22:56:31 +0000 | [diff] [blame] | 938 | WinX86_64ABIInfo(CodeGen::CodeGenTypes &CGT) : ABIInfo(CGT) {} |
| 939 | |
| 940 | virtual void computeInfo(CGFunctionInfo &FI) const; |
Chris Lattner | f13721d | 2010-08-31 16:44:54 +0000 | [diff] [blame] | 941 | |
| 942 | virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 943 | CodeGenFunction &CGF) const; |
| 944 | }; |
| 945 | |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 946 | class X86_64TargetCodeGenInfo : public TargetCodeGenInfo { |
| 947 | public: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 948 | X86_64TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT) |
| 949 | : TargetCodeGenInfo(new X86_64ABIInfo(CGT)) {} |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 950 | |
| 951 | int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const { |
| 952 | return 7; |
| 953 | } |
| 954 | |
| 955 | bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, |
| 956 | llvm::Value *Address) const { |
| 957 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 958 | llvm::LLVMContext &Context = CGF.getLLVMContext(); |
| 959 | |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 960 | llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context); |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 961 | llvm::Value *Eight8 = llvm::ConstantInt::get(i8, 8); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 962 | |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 963 | // 0-15 are the 16 integer registers. |
| 964 | // 16 is %rip. |
| 965 | AssignToArrayRange(Builder, Address, Eight8, 0, 16); |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 966 | |
| 967 | return false; |
| 968 | } |
Peter Collingbourne | 4b93d66 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 969 | |
Jay Foad | ef6de3d | 2011-07-11 09:56:20 +0000 | [diff] [blame] | 970 | llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 971 | StringRef Constraint, |
Jay Foad | ef6de3d | 2011-07-11 09:56:20 +0000 | [diff] [blame] | 972 | llvm::Type* Ty) const { |
Peter Collingbourne | 4b93d66 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 973 | return X86AdjustInlineAsmType(CGF, Constraint, Ty); |
| 974 | } |
| 975 | |
John McCall | 01f151e | 2011-09-21 08:08:30 +0000 | [diff] [blame] | 976 | bool isNoProtoCallVariadic(CallingConv CC) const { |
| 977 | // The default CC on x86-64 sets %al to the number of SSA |
| 978 | // registers used, and GCC sets this when calling an unprototyped |
| 979 | // function, so we override the default behavior. |
| 980 | if (CC == CC_Default || CC == CC_C) return true; |
| 981 | |
| 982 | return TargetCodeGenInfo::isNoProtoCallVariadic(CC); |
| 983 | } |
| 984 | |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 985 | }; |
| 986 | |
Chris Lattner | f13721d | 2010-08-31 16:44:54 +0000 | [diff] [blame] | 987 | class WinX86_64TargetCodeGenInfo : public TargetCodeGenInfo { |
| 988 | public: |
| 989 | WinX86_64TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT) |
| 990 | : TargetCodeGenInfo(new WinX86_64ABIInfo(CGT)) {} |
| 991 | |
| 992 | int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const { |
| 993 | return 7; |
| 994 | } |
| 995 | |
| 996 | bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, |
| 997 | llvm::Value *Address) const { |
| 998 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 999 | llvm::LLVMContext &Context = CGF.getLLVMContext(); |
| 1000 | |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1001 | llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context); |
Chris Lattner | f13721d | 2010-08-31 16:44:54 +0000 | [diff] [blame] | 1002 | llvm::Value *Eight8 = llvm::ConstantInt::get(i8, 8); |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1003 | |
Chris Lattner | f13721d | 2010-08-31 16:44:54 +0000 | [diff] [blame] | 1004 | // 0-15 are the 16 integer registers. |
| 1005 | // 16 is %rip. |
| 1006 | AssignToArrayRange(Builder, Address, Eight8, 0, 16); |
| 1007 | |
| 1008 | return false; |
| 1009 | } |
| 1010 | }; |
| 1011 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 1014 | void X86_64ABIInfo::postMerge(unsigned AggregateSize, Class &Lo, |
| 1015 | Class &Hi) const { |
| 1016 | // AMD64-ABI 3.2.3p2: Rule 5. Then a post merger cleanup is done: |
| 1017 | // |
| 1018 | // (a) If one of the classes is Memory, the whole argument is passed in |
| 1019 | // memory. |
| 1020 | // |
| 1021 | // (b) If X87UP is not preceded by X87, the whole argument is passed in |
| 1022 | // memory. |
| 1023 | // |
| 1024 | // (c) If the size of the aggregate exceeds two eightbytes and the first |
| 1025 | // eightbyte isn't SSE or any other eightbyte isn't SSEUP, the whole |
| 1026 | // argument is passed in memory. NOTE: This is necessary to keep the |
| 1027 | // ABI working for processors that don't support the __m256 type. |
| 1028 | // |
| 1029 | // (d) If SSEUP is not preceded by SSE or SSEUP, it is converted to SSE. |
| 1030 | // |
| 1031 | // Some of these are enforced by the merging logic. Others can arise |
| 1032 | // only with unions; for example: |
| 1033 | // union { _Complex double; unsigned; } |
| 1034 | // |
| 1035 | // Note that clauses (b) and (c) were added in 0.98. |
| 1036 | // |
| 1037 | if (Hi == Memory) |
| 1038 | Lo = Memory; |
| 1039 | if (Hi == X87Up && Lo != X87 && honorsRevision0_98()) |
| 1040 | Lo = Memory; |
| 1041 | if (AggregateSize > 128 && (Lo != SSE || Hi != SSEUp)) |
| 1042 | Lo = Memory; |
| 1043 | if (Hi == SSEUp && Lo != SSE) |
| 1044 | Hi = SSE; |
| 1045 | } |
| 1046 | |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1047 | X86_64ABIInfo::Class X86_64ABIInfo::merge(Class Accum, Class Field) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1048 | // AMD64-ABI 3.2.3p2: Rule 4. Each field of an object is |
| 1049 | // classified recursively so that always two fields are |
| 1050 | // considered. The resulting class is calculated according to |
| 1051 | // the classes of the fields in the eightbyte: |
| 1052 | // |
| 1053 | // (a) If both classes are equal, this is the resulting class. |
| 1054 | // |
| 1055 | // (b) If one of the classes is NO_CLASS, the resulting class is |
| 1056 | // the other class. |
| 1057 | // |
| 1058 | // (c) If one of the classes is MEMORY, the result is the MEMORY |
| 1059 | // class. |
| 1060 | // |
| 1061 | // (d) If one of the classes is INTEGER, the result is the |
| 1062 | // INTEGER. |
| 1063 | // |
| 1064 | // (e) If one of the classes is X87, X87UP, COMPLEX_X87 class, |
| 1065 | // MEMORY is used as class. |
| 1066 | // |
| 1067 | // (f) Otherwise class SSE is used. |
| 1068 | |
| 1069 | // Accum should never be memory (we should have returned) or |
| 1070 | // ComplexX87 (because this cannot be passed in a structure). |
| 1071 | assert((Accum != Memory && Accum != ComplexX87) && |
| 1072 | "Invalid accumulated classification during merge."); |
| 1073 | if (Accum == Field || Field == NoClass) |
| 1074 | return Accum; |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1075 | if (Field == Memory) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1076 | return Memory; |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1077 | if (Accum == NoClass) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1078 | return Field; |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1079 | if (Accum == Integer || Field == Integer) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1080 | return Integer; |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1081 | if (Field == X87 || Field == X87Up || Field == ComplexX87 || |
| 1082 | Accum == X87 || Accum == X87Up) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1083 | return Memory; |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1084 | return SSE; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Chris Lattner | bcaedae | 2010-06-30 19:14:05 +0000 | [diff] [blame] | 1087 | void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1088 | Class &Lo, Class &Hi) const { |
| 1089 | // FIXME: This code can be simplified by introducing a simple value class for |
| 1090 | // Class pairs with appropriate constructor methods for the various |
| 1091 | // situations. |
| 1092 | |
| 1093 | // FIXME: Some of the split computations are wrong; unaligned vectors |
| 1094 | // shouldn't be passed in registers for example, so there is no chance they |
| 1095 | // can straddle an eightbyte. Verify & simplify. |
| 1096 | |
| 1097 | Lo = Hi = NoClass; |
| 1098 | |
| 1099 | Class &Current = OffsetBase < 64 ? Lo : Hi; |
| 1100 | Current = Memory; |
| 1101 | |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 1102 | if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1103 | BuiltinType::Kind k = BT->getKind(); |
| 1104 | |
| 1105 | if (k == BuiltinType::Void) { |
| 1106 | Current = NoClass; |
| 1107 | } else if (k == BuiltinType::Int128 || k == BuiltinType::UInt128) { |
| 1108 | Lo = Integer; |
| 1109 | Hi = Integer; |
| 1110 | } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) { |
| 1111 | Current = Integer; |
| 1112 | } else if (k == BuiltinType::Float || k == BuiltinType::Double) { |
| 1113 | Current = SSE; |
| 1114 | } else if (k == BuiltinType::LongDouble) { |
| 1115 | Lo = X87; |
| 1116 | Hi = X87Up; |
| 1117 | } |
| 1118 | // FIXME: _Decimal32 and _Decimal64 are SSE. |
| 1119 | // FIXME: _float128 and _Decimal128 are (SSE, SSEUp). |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1120 | return; |
| 1121 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1122 | |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1123 | if (const EnumType *ET = Ty->getAs<EnumType>()) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1124 | // Classify the underlying integer type. |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 1125 | classify(ET->getDecl()->getIntegerType(), OffsetBase, Lo, Hi); |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1126 | return; |
| 1127 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1128 | |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1129 | if (Ty->hasPointerRepresentation()) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1130 | Current = Integer; |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1131 | return; |
| 1132 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1133 | |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1134 | if (Ty->isMemberPointerType()) { |
Daniel Dunbar | 67d438d | 2010-05-15 00:00:37 +0000 | [diff] [blame] | 1135 | if (Ty->isMemberFunctionPointerType()) |
| 1136 | Lo = Hi = Integer; |
| 1137 | else |
| 1138 | Current = Integer; |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1139 | return; |
| 1140 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1141 | |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1142 | if (const VectorType *VT = Ty->getAs<VectorType>()) { |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1143 | uint64_t Size = getContext().getTypeSize(VT); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1144 | if (Size == 32) { |
| 1145 | // gcc passes all <4 x char>, <2 x short>, <1 x int>, <1 x |
| 1146 | // float> as integer. |
| 1147 | Current = Integer; |
| 1148 | |
| 1149 | // If this type crosses an eightbyte boundary, it should be |
| 1150 | // split. |
| 1151 | uint64_t EB_Real = (OffsetBase) / 64; |
| 1152 | uint64_t EB_Imag = (OffsetBase + Size - 1) / 64; |
| 1153 | if (EB_Real != EB_Imag) |
| 1154 | Hi = Lo; |
| 1155 | } else if (Size == 64) { |
| 1156 | // gcc passes <1 x double> in memory. :( |
| 1157 | if (VT->getElementType()->isSpecificBuiltinType(BuiltinType::Double)) |
| 1158 | return; |
| 1159 | |
| 1160 | // gcc passes <1 x long long> as INTEGER. |
Chris Lattner | 473f8e7 | 2010-08-26 18:03:20 +0000 | [diff] [blame] | 1161 | if (VT->getElementType()->isSpecificBuiltinType(BuiltinType::LongLong) || |
Chris Lattner | 0fefa41 | 2010-08-26 18:13:50 +0000 | [diff] [blame] | 1162 | VT->getElementType()->isSpecificBuiltinType(BuiltinType::ULongLong) || |
| 1163 | VT->getElementType()->isSpecificBuiltinType(BuiltinType::Long) || |
| 1164 | VT->getElementType()->isSpecificBuiltinType(BuiltinType::ULong)) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1165 | Current = Integer; |
| 1166 | else |
| 1167 | Current = SSE; |
| 1168 | |
| 1169 | // If this type crosses an eightbyte boundary, it should be |
| 1170 | // split. |
| 1171 | if (OffsetBase && OffsetBase != 64) |
| 1172 | Hi = Lo; |
Bruno Cardoso Lopes | 75d28b5 | 2011-07-12 02:47:38 +0000 | [diff] [blame] | 1173 | } else if (Size == 128 || Size == 256) { |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 1174 | // Arguments of 256-bits are split into four eightbyte chunks. The |
| 1175 | // least significant one belongs to class SSE and all the others to class |
| 1176 | // SSEUP. The original Lo and Hi design considers that types can't be |
| 1177 | // greater than 128-bits, so a 64-bit split in Hi and Lo makes sense. |
| 1178 | // This design isn't correct for 256-bits, but since there're no cases |
| 1179 | // where the upper parts would need to be inspected, avoid adding |
| 1180 | // complexity and just consider Hi to match the 64-256 part. |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1181 | Lo = SSE; |
| 1182 | Hi = SSEUp; |
| 1183 | } |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1184 | return; |
| 1185 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1186 | |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1187 | if (const ComplexType *CT = Ty->getAs<ComplexType>()) { |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1188 | QualType ET = getContext().getCanonicalType(CT->getElementType()); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1189 | |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1190 | uint64_t Size = getContext().getTypeSize(Ty); |
Douglas Gregor | 2ade35e | 2010-06-16 00:17:44 +0000 | [diff] [blame] | 1191 | if (ET->isIntegralOrEnumerationType()) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1192 | if (Size <= 64) |
| 1193 | Current = Integer; |
| 1194 | else if (Size <= 128) |
| 1195 | Lo = Hi = Integer; |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1196 | } else if (ET == getContext().FloatTy) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1197 | Current = SSE; |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1198 | else if (ET == getContext().DoubleTy) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1199 | Lo = Hi = SSE; |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1200 | else if (ET == getContext().LongDoubleTy) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1201 | Current = ComplexX87; |
| 1202 | |
| 1203 | // If this complex type crosses an eightbyte boundary then it |
| 1204 | // should be split. |
| 1205 | uint64_t EB_Real = (OffsetBase) / 64; |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1206 | uint64_t EB_Imag = (OffsetBase + getContext().getTypeSize(ET)) / 64; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1207 | if (Hi == NoClass && EB_Real != EB_Imag) |
| 1208 | Hi = Lo; |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1209 | |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1210 | return; |
| 1211 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1212 | |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1213 | if (const ConstantArrayType *AT = getContext().getAsConstantArrayType(Ty)) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1214 | // Arrays are treated like structures. |
| 1215 | |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1216 | uint64_t Size = getContext().getTypeSize(Ty); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1217 | |
| 1218 | // AMD64-ABI 3.2.3p2: Rule 1. If the size of an object is larger |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 1219 | // than four eightbytes, ..., it has class MEMORY. |
| 1220 | if (Size > 256) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1221 | return; |
| 1222 | |
| 1223 | // AMD64-ABI 3.2.3p2: Rule 1. If ..., or it contains unaligned |
| 1224 | // fields, it has class MEMORY. |
| 1225 | // |
| 1226 | // Only need to check alignment of array base. |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1227 | if (OffsetBase % getContext().getTypeAlign(AT->getElementType())) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1228 | return; |
| 1229 | |
| 1230 | // Otherwise implement simplified merge. We could be smarter about |
| 1231 | // this, but it isn't worth it and would be harder to verify. |
| 1232 | Current = NoClass; |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1233 | uint64_t EltSize = getContext().getTypeSize(AT->getElementType()); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1234 | uint64_t ArraySize = AT->getSize().getZExtValue(); |
Bruno Cardoso Lopes | 089d892 | 2011-07-12 01:27:38 +0000 | [diff] [blame] | 1235 | |
| 1236 | // The only case a 256-bit wide vector could be used is when the array |
| 1237 | // contains a single 256-bit element. Since Lo and Hi logic isn't extended |
| 1238 | // to work for sizes wider than 128, early check and fallback to memory. |
| 1239 | if (Size > 128 && EltSize != 256) |
| 1240 | return; |
| 1241 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1242 | for (uint64_t i=0, Offset=OffsetBase; i<ArraySize; ++i, Offset += EltSize) { |
| 1243 | Class FieldLo, FieldHi; |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 1244 | classify(AT->getElementType(), Offset, FieldLo, FieldHi); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1245 | Lo = merge(Lo, FieldLo); |
| 1246 | Hi = merge(Hi, FieldHi); |
| 1247 | if (Lo == Memory || Hi == Memory) |
| 1248 | break; |
| 1249 | } |
| 1250 | |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 1251 | postMerge(Size, Lo, Hi); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1252 | assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp array classification."); |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1253 | return; |
| 1254 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1255 | |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 1256 | if (const RecordType *RT = Ty->getAs<RecordType>()) { |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1257 | uint64_t Size = getContext().getTypeSize(Ty); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1258 | |
| 1259 | // AMD64-ABI 3.2.3p2: Rule 1. If the size of an object is larger |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 1260 | // than four eightbytes, ..., it has class MEMORY. |
| 1261 | if (Size > 256) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1262 | return; |
| 1263 | |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 1264 | // AMD64-ABI 3.2.3p2: Rule 2. If a C++ object has either a non-trivial |
| 1265 | // copy constructor or a non-trivial destructor, it is passed by invisible |
| 1266 | // reference. |
| 1267 | if (hasNonTrivialDestructorOrCopyConstructor(RT)) |
| 1268 | return; |
Daniel Dunbar | ce9f423 | 2009-11-22 23:01:23 +0000 | [diff] [blame] | 1269 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1270 | const RecordDecl *RD = RT->getDecl(); |
| 1271 | |
| 1272 | // Assume variable sized types are passed in memory. |
| 1273 | if (RD->hasFlexibleArrayMember()) |
| 1274 | return; |
| 1275 | |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1276 | const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1277 | |
| 1278 | // Reset Lo class, this will be recomputed. |
| 1279 | Current = NoClass; |
Daniel Dunbar | ce9f423 | 2009-11-22 23:01:23 +0000 | [diff] [blame] | 1280 | |
| 1281 | // If this is a C++ record, classify the bases first. |
| 1282 | if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) { |
| 1283 | for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(), |
| 1284 | e = CXXRD->bases_end(); i != e; ++i) { |
| 1285 | assert(!i->isVirtual() && !i->getType()->isDependentType() && |
| 1286 | "Unexpected base class!"); |
| 1287 | const CXXRecordDecl *Base = |
| 1288 | cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); |
| 1289 | |
| 1290 | // Classify this field. |
| 1291 | // |
| 1292 | // AMD64-ABI 3.2.3p2: Rule 3. If the size of the aggregate exceeds a |
| 1293 | // single eightbyte, each is classified separately. Each eightbyte gets |
| 1294 | // initialized to class NO_CLASS. |
| 1295 | Class FieldLo, FieldHi; |
Anders Carlsson | a14f597 | 2010-10-31 23:22:37 +0000 | [diff] [blame] | 1296 | uint64_t Offset = OffsetBase + Layout.getBaseClassOffsetInBits(Base); |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 1297 | classify(i->getType(), Offset, FieldLo, FieldHi); |
Daniel Dunbar | ce9f423 | 2009-11-22 23:01:23 +0000 | [diff] [blame] | 1298 | Lo = merge(Lo, FieldLo); |
| 1299 | Hi = merge(Hi, FieldHi); |
| 1300 | if (Lo == Memory || Hi == Memory) |
| 1301 | break; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | // Classify the fields one at a time, merging the results. |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1306 | unsigned idx = 0; |
Bruno Cardoso Lopes | 548e478 | 2011-07-12 22:30:58 +0000 | [diff] [blame] | 1307 | for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1308 | i != e; ++i, ++idx) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1309 | uint64_t Offset = OffsetBase + Layout.getFieldOffset(idx); |
| 1310 | bool BitField = i->isBitField(); |
| 1311 | |
Bruno Cardoso Lopes | b8981df | 2011-07-13 21:58:55 +0000 | [diff] [blame] | 1312 | // AMD64-ABI 3.2.3p2: Rule 1. If the size of an object is larger than |
| 1313 | // four eightbytes, or it contains unaligned fields, it has class MEMORY. |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1314 | // |
Bruno Cardoso Lopes | b8981df | 2011-07-13 21:58:55 +0000 | [diff] [blame] | 1315 | // The only case a 256-bit wide vector could be used is when the struct |
| 1316 | // contains a single 256-bit element. Since Lo and Hi logic isn't extended |
| 1317 | // to work for sizes wider than 128, early check and fallback to memory. |
| 1318 | // |
| 1319 | if (Size > 128 && getContext().getTypeSize(i->getType()) != 256) { |
| 1320 | Lo = Memory; |
| 1321 | return; |
| 1322 | } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1323 | // Note, skip this test for bit-fields, see below. |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1324 | if (!BitField && Offset % getContext().getTypeAlign(i->getType())) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1325 | Lo = Memory; |
| 1326 | return; |
| 1327 | } |
| 1328 | |
| 1329 | // Classify this field. |
| 1330 | // |
| 1331 | // AMD64-ABI 3.2.3p2: Rule 3. If the size of the aggregate |
| 1332 | // exceeds a single eightbyte, each is classified |
| 1333 | // separately. Each eightbyte gets initialized to class |
| 1334 | // NO_CLASS. |
| 1335 | Class FieldLo, FieldHi; |
| 1336 | |
| 1337 | // Bit-fields require special handling, they do not force the |
| 1338 | // structure to be passed in memory even if unaligned, and |
| 1339 | // therefore they can straddle an eightbyte. |
| 1340 | if (BitField) { |
| 1341 | // Ignore padding bit-fields. |
| 1342 | if (i->isUnnamedBitfield()) |
| 1343 | continue; |
| 1344 | |
| 1345 | uint64_t Offset = OffsetBase + Layout.getFieldOffset(idx); |
Richard Smith | a6b8b2c | 2011-10-10 18:28:20 +0000 | [diff] [blame] | 1346 | uint64_t Size = i->getBitWidthValue(getContext()); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1347 | |
| 1348 | uint64_t EB_Lo = Offset / 64; |
| 1349 | uint64_t EB_Hi = (Offset + Size - 1) / 64; |
| 1350 | FieldLo = FieldHi = NoClass; |
| 1351 | if (EB_Lo) { |
| 1352 | assert(EB_Hi == EB_Lo && "Invalid classification, type > 16 bytes."); |
| 1353 | FieldLo = NoClass; |
| 1354 | FieldHi = Integer; |
| 1355 | } else { |
| 1356 | FieldLo = Integer; |
| 1357 | FieldHi = EB_Hi ? Integer : NoClass; |
| 1358 | } |
| 1359 | } else |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 1360 | classify(i->getType(), Offset, FieldLo, FieldHi); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1361 | Lo = merge(Lo, FieldLo); |
| 1362 | Hi = merge(Hi, FieldHi); |
| 1363 | if (Lo == Memory || Hi == Memory) |
| 1364 | break; |
| 1365 | } |
| 1366 | |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 1367 | postMerge(Size, Lo, Hi); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1368 | } |
| 1369 | } |
| 1370 | |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 1371 | ABIArgInfo X86_64ABIInfo::getIndirectReturnResult(QualType Ty) const { |
Daniel Dunbar | 46c54fb | 2010-04-21 19:49:55 +0000 | [diff] [blame] | 1372 | // If this is a scalar LLVM value then assume LLVM will pass it in the right |
| 1373 | // place naturally. |
John McCall | d608cdb | 2010-08-22 10:59:02 +0000 | [diff] [blame] | 1374 | if (!isAggregateTypeForABI(Ty)) { |
Daniel Dunbar | 46c54fb | 2010-04-21 19:49:55 +0000 | [diff] [blame] | 1375 | // Treat an enum type as its underlying type. |
| 1376 | if (const EnumType *EnumTy = Ty->getAs<EnumType>()) |
| 1377 | Ty = EnumTy->getDecl()->getIntegerType(); |
| 1378 | |
| 1379 | return (Ty->isPromotableIntegerType() ? |
| 1380 | ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
| 1381 | } |
| 1382 | |
| 1383 | return ABIArgInfo::getIndirect(0); |
| 1384 | } |
| 1385 | |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 1386 | ABIArgInfo X86_64ABIInfo::getIndirectResult(QualType Ty) const { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1387 | // If this is a scalar LLVM value then assume LLVM will pass it in the right |
| 1388 | // place naturally. |
John McCall | d608cdb | 2010-08-22 10:59:02 +0000 | [diff] [blame] | 1389 | if (!isAggregateTypeForABI(Ty)) { |
Douglas Gregor | aa74a1e | 2010-02-02 20:10:50 +0000 | [diff] [blame] | 1390 | // Treat an enum type as its underlying type. |
| 1391 | if (const EnumType *EnumTy = Ty->getAs<EnumType>()) |
| 1392 | Ty = EnumTy->getDecl()->getIntegerType(); |
| 1393 | |
Anton Korobeynikov | cc6fa88 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 1394 | return (Ty->isPromotableIntegerType() ? |
| 1395 | ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
Douglas Gregor | aa74a1e | 2010-02-02 20:10:50 +0000 | [diff] [blame] | 1396 | } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1397 | |
Daniel Dunbar | 46c54fb | 2010-04-21 19:49:55 +0000 | [diff] [blame] | 1398 | if (isRecordWithNonTrivialDestructorOrCopyConstructor(Ty)) |
| 1399 | return ABIArgInfo::getIndirect(0, /*ByVal=*/false); |
Anders Carlsson | 0a8f847 | 2009-09-16 15:53:40 +0000 | [diff] [blame] | 1400 | |
Chris Lattner | 855d227 | 2011-05-22 23:21:23 +0000 | [diff] [blame] | 1401 | // Compute the byval alignment. We specify the alignment of the byval in all |
| 1402 | // cases so that the mid-level optimizer knows the alignment of the byval. |
| 1403 | unsigned Align = std::max(getContext().getTypeAlign(Ty) / 8, 8U); |
| 1404 | return ABIArgInfo::getIndirect(Align); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 1407 | /// GetByteVectorType - The ABI specifies that a value should be passed in an |
| 1408 | /// full vector XMM/YMM register. Pick an LLVM IR type that will be passed as a |
Chris Lattner | 0f408f5 | 2010-07-29 04:56:46 +0000 | [diff] [blame] | 1409 | /// vector register. |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 1410 | llvm::Type *X86_64ABIInfo::GetByteVectorType(QualType Ty) const { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1411 | llvm::Type *IRType = CGT.ConvertType(Ty); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1412 | |
Chris Lattner | 15842bd | 2010-07-29 05:02:29 +0000 | [diff] [blame] | 1413 | // Wrapper structs that just contain vectors are passed just like vectors, |
| 1414 | // strip them off if present. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1415 | llvm::StructType *STy = dyn_cast<llvm::StructType>(IRType); |
Chris Lattner | 15842bd | 2010-07-29 05:02:29 +0000 | [diff] [blame] | 1416 | while (STy && STy->getNumElements() == 1) { |
| 1417 | IRType = STy->getElementType(0); |
| 1418 | STy = dyn_cast<llvm::StructType>(IRType); |
| 1419 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1420 | |
Bruno Cardoso Lopes | 528a8c7 | 2011-07-08 22:57:35 +0000 | [diff] [blame] | 1421 | // If the preferred type is a 16-byte vector, prefer to pass it. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1422 | if (llvm::VectorType *VT = dyn_cast<llvm::VectorType>(IRType)){ |
| 1423 | llvm::Type *EltTy = VT->getElementType(); |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 1424 | unsigned BitWidth = VT->getBitWidth(); |
| 1425 | if ((BitWidth == 128 || BitWidth == 256) && |
Chris Lattner | 0f408f5 | 2010-07-29 04:56:46 +0000 | [diff] [blame] | 1426 | (EltTy->isFloatTy() || EltTy->isDoubleTy() || |
| 1427 | EltTy->isIntegerTy(8) || EltTy->isIntegerTy(16) || |
| 1428 | EltTy->isIntegerTy(32) || EltTy->isIntegerTy(64) || |
| 1429 | EltTy->isIntegerTy(128))) |
| 1430 | return VT; |
| 1431 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1432 | |
Chris Lattner | 0f408f5 | 2010-07-29 04:56:46 +0000 | [diff] [blame] | 1433 | return llvm::VectorType::get(llvm::Type::getDoubleTy(getVMContext()), 2); |
| 1434 | } |
| 1435 | |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1436 | /// BitsContainNoUserData - Return true if the specified [start,end) bit range |
| 1437 | /// is known to either be off the end of the specified type or being in |
| 1438 | /// alignment padding. The user type specified is known to be at most 128 bits |
| 1439 | /// in size, and have passed through X86_64ABIInfo::classify with a successful |
| 1440 | /// classification that put one of the two halves in the INTEGER class. |
| 1441 | /// |
| 1442 | /// It is conservatively correct to return false. |
| 1443 | static bool BitsContainNoUserData(QualType Ty, unsigned StartBit, |
| 1444 | unsigned EndBit, ASTContext &Context) { |
| 1445 | // If the bytes being queried are off the end of the type, there is no user |
| 1446 | // data hiding here. This handles analysis of builtins, vectors and other |
| 1447 | // types that don't contain interesting padding. |
| 1448 | unsigned TySize = (unsigned)Context.getTypeSize(Ty); |
| 1449 | if (TySize <= StartBit) |
| 1450 | return true; |
| 1451 | |
Chris Lattner | 021c3a3 | 2010-07-29 07:43:55 +0000 | [diff] [blame] | 1452 | if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty)) { |
| 1453 | unsigned EltSize = (unsigned)Context.getTypeSize(AT->getElementType()); |
| 1454 | unsigned NumElts = (unsigned)AT->getSize().getZExtValue(); |
| 1455 | |
| 1456 | // Check each element to see if the element overlaps with the queried range. |
| 1457 | for (unsigned i = 0; i != NumElts; ++i) { |
| 1458 | // If the element is after the span we care about, then we're done.. |
| 1459 | unsigned EltOffset = i*EltSize; |
| 1460 | if (EltOffset >= EndBit) break; |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1461 | |
Chris Lattner | 021c3a3 | 2010-07-29 07:43:55 +0000 | [diff] [blame] | 1462 | unsigned EltStart = EltOffset < StartBit ? StartBit-EltOffset :0; |
| 1463 | if (!BitsContainNoUserData(AT->getElementType(), EltStart, |
| 1464 | EndBit-EltOffset, Context)) |
| 1465 | return false; |
| 1466 | } |
| 1467 | // If it overlaps no elements, then it is safe to process as padding. |
| 1468 | return true; |
| 1469 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1470 | |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1471 | if (const RecordType *RT = Ty->getAs<RecordType>()) { |
| 1472 | const RecordDecl *RD = RT->getDecl(); |
| 1473 | const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1474 | |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1475 | // If this is a C++ record, check the bases first. |
| 1476 | if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) { |
| 1477 | for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(), |
| 1478 | e = CXXRD->bases_end(); i != e; ++i) { |
| 1479 | assert(!i->isVirtual() && !i->getType()->isDependentType() && |
| 1480 | "Unexpected base class!"); |
| 1481 | const CXXRecordDecl *Base = |
| 1482 | cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1483 | |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1484 | // If the base is after the span we care about, ignore it. |
Anders Carlsson | a14f597 | 2010-10-31 23:22:37 +0000 | [diff] [blame] | 1485 | unsigned BaseOffset = (unsigned)Layout.getBaseClassOffsetInBits(Base); |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1486 | if (BaseOffset >= EndBit) continue; |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1487 | |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1488 | unsigned BaseStart = BaseOffset < StartBit ? StartBit-BaseOffset :0; |
| 1489 | if (!BitsContainNoUserData(i->getType(), BaseStart, |
| 1490 | EndBit-BaseOffset, Context)) |
| 1491 | return false; |
| 1492 | } |
| 1493 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1494 | |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1495 | // Verify that no field has data that overlaps the region of interest. Yes |
| 1496 | // this could be sped up a lot by being smarter about queried fields, |
| 1497 | // however we're only looking at structs up to 16 bytes, so we don't care |
| 1498 | // much. |
| 1499 | unsigned idx = 0; |
| 1500 | for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); |
| 1501 | i != e; ++i, ++idx) { |
| 1502 | unsigned FieldOffset = (unsigned)Layout.getFieldOffset(idx); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1503 | |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1504 | // If we found a field after the region we care about, then we're done. |
| 1505 | if (FieldOffset >= EndBit) break; |
| 1506 | |
| 1507 | unsigned FieldStart = FieldOffset < StartBit ? StartBit-FieldOffset :0; |
| 1508 | if (!BitsContainNoUserData(i->getType(), FieldStart, EndBit-FieldOffset, |
| 1509 | Context)) |
| 1510 | return false; |
| 1511 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1512 | |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1513 | // If nothing in this record overlapped the area of interest, then we're |
| 1514 | // clean. |
| 1515 | return true; |
| 1516 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1517 | |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1518 | return false; |
| 1519 | } |
| 1520 | |
Chris Lattner | 0b36200 | 2010-07-29 18:39:32 +0000 | [diff] [blame] | 1521 | /// ContainsFloatAtOffset - Return true if the specified LLVM IR type has a |
| 1522 | /// float member at the specified offset. For example, {int,{float}} has a |
| 1523 | /// float at offset 4. It is conservatively correct for this routine to return |
| 1524 | /// false. |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1525 | static bool ContainsFloatAtOffset(llvm::Type *IRType, unsigned IROffset, |
Chris Lattner | 0b36200 | 2010-07-29 18:39:32 +0000 | [diff] [blame] | 1526 | const llvm::TargetData &TD) { |
| 1527 | // Base case if we find a float. |
| 1528 | if (IROffset == 0 && IRType->isFloatTy()) |
| 1529 | return true; |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1530 | |
Chris Lattner | 0b36200 | 2010-07-29 18:39:32 +0000 | [diff] [blame] | 1531 | // If this is a struct, recurse into the field at the specified offset. |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1532 | if (llvm::StructType *STy = dyn_cast<llvm::StructType>(IRType)) { |
Chris Lattner | 0b36200 | 2010-07-29 18:39:32 +0000 | [diff] [blame] | 1533 | const llvm::StructLayout *SL = TD.getStructLayout(STy); |
| 1534 | unsigned Elt = SL->getElementContainingOffset(IROffset); |
| 1535 | IROffset -= SL->getElementOffset(Elt); |
| 1536 | return ContainsFloatAtOffset(STy->getElementType(Elt), IROffset, TD); |
| 1537 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1538 | |
Chris Lattner | 0b36200 | 2010-07-29 18:39:32 +0000 | [diff] [blame] | 1539 | // If this is an array, recurse into the field at the specified offset. |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1540 | if (llvm::ArrayType *ATy = dyn_cast<llvm::ArrayType>(IRType)) { |
| 1541 | llvm::Type *EltTy = ATy->getElementType(); |
Chris Lattner | 0b36200 | 2010-07-29 18:39:32 +0000 | [diff] [blame] | 1542 | unsigned EltSize = TD.getTypeAllocSize(EltTy); |
| 1543 | IROffset -= IROffset/EltSize*EltSize; |
| 1544 | return ContainsFloatAtOffset(EltTy, IROffset, TD); |
| 1545 | } |
| 1546 | |
| 1547 | return false; |
| 1548 | } |
| 1549 | |
Chris Lattner | f47c944 | 2010-07-29 18:13:09 +0000 | [diff] [blame] | 1550 | |
| 1551 | /// GetSSETypeAtOffset - Return a type that will be passed by the backend in the |
| 1552 | /// low 8 bytes of an XMM register, corresponding to the SSE class. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1553 | llvm::Type *X86_64ABIInfo:: |
| 1554 | GetSSETypeAtOffset(llvm::Type *IRType, unsigned IROffset, |
Chris Lattner | f47c944 | 2010-07-29 18:13:09 +0000 | [diff] [blame] | 1555 | QualType SourceTy, unsigned SourceOffset) const { |
Chris Lattner | cba8d31 | 2010-07-29 18:19:50 +0000 | [diff] [blame] | 1556 | // The only three choices we have are either double, <2 x float>, or float. We |
Chris Lattner | f47c944 | 2010-07-29 18:13:09 +0000 | [diff] [blame] | 1557 | // pass as float if the last 4 bytes is just padding. This happens for |
| 1558 | // structs that contain 3 floats. |
| 1559 | if (BitsContainNoUserData(SourceTy, SourceOffset*8+32, |
| 1560 | SourceOffset*8+64, getContext())) |
| 1561 | return llvm::Type::getFloatTy(getVMContext()); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1562 | |
Chris Lattner | 0b36200 | 2010-07-29 18:39:32 +0000 | [diff] [blame] | 1563 | // We want to pass as <2 x float> if the LLVM IR type contains a float at |
| 1564 | // offset+0 and offset+4. Walk the LLVM IR type to find out if this is the |
| 1565 | // case. |
| 1566 | if (ContainsFloatAtOffset(IRType, IROffset, getTargetData()) && |
Chris Lattner | 22fd4ba | 2010-08-25 23:39:14 +0000 | [diff] [blame] | 1567 | ContainsFloatAtOffset(IRType, IROffset+4, getTargetData())) |
| 1568 | return llvm::VectorType::get(llvm::Type::getFloatTy(getVMContext()), 2); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1569 | |
Chris Lattner | f47c944 | 2010-07-29 18:13:09 +0000 | [diff] [blame] | 1570 | return llvm::Type::getDoubleTy(getVMContext()); |
| 1571 | } |
| 1572 | |
| 1573 | |
Chris Lattner | 0d2656d | 2010-07-29 17:40:35 +0000 | [diff] [blame] | 1574 | /// GetINTEGERTypeAtOffset - The ABI specifies that a value should be passed in |
| 1575 | /// an 8-byte GPR. This means that we either have a scalar or we are talking |
| 1576 | /// about the high or low part of an up-to-16-byte struct. This routine picks |
| 1577 | /// the best LLVM IR type to represent this, which may be i64 or may be anything |
Chris Lattner | 49382de | 2010-07-28 22:44:07 +0000 | [diff] [blame] | 1578 | /// else that the backend will pass in a GPR that works better (e.g. i8, %foo*, |
| 1579 | /// etc). |
| 1580 | /// |
| 1581 | /// PrefType is an LLVM IR type that corresponds to (part of) the IR type for |
| 1582 | /// the source type. IROffset is an offset in bytes into the LLVM IR type that |
| 1583 | /// the 8-byte value references. PrefType may be null. |
| 1584 | /// |
| 1585 | /// SourceTy is the source level type for the entire argument. SourceOffset is |
| 1586 | /// an offset into this that we're processing (which is always either 0 or 8). |
| 1587 | /// |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1588 | llvm::Type *X86_64ABIInfo:: |
| 1589 | GetINTEGERTypeAtOffset(llvm::Type *IRType, unsigned IROffset, |
Chris Lattner | 0d2656d | 2010-07-29 17:40:35 +0000 | [diff] [blame] | 1590 | QualType SourceTy, unsigned SourceOffset) const { |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1591 | // If we're dealing with an un-offset LLVM IR type, then it means that we're |
| 1592 | // returning an 8-byte unit starting with it. See if we can safely use it. |
| 1593 | if (IROffset == 0) { |
| 1594 | // Pointers and int64's always fill the 8-byte unit. |
| 1595 | if (isa<llvm::PointerType>(IRType) || IRType->isIntegerTy(64)) |
| 1596 | return IRType; |
Chris Lattner | 49382de | 2010-07-28 22:44:07 +0000 | [diff] [blame] | 1597 | |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1598 | // If we have a 1/2/4-byte integer, we can use it only if the rest of the |
| 1599 | // goodness in the source type is just tail padding. This is allowed to |
| 1600 | // kick in for struct {double,int} on the int, but not on |
| 1601 | // struct{double,int,int} because we wouldn't return the second int. We |
| 1602 | // have to do this analysis on the source type because we can't depend on |
| 1603 | // unions being lowered a specific way etc. |
| 1604 | if (IRType->isIntegerTy(8) || IRType->isIntegerTy(16) || |
| 1605 | IRType->isIntegerTy(32)) { |
| 1606 | unsigned BitWidth = cast<llvm::IntegerType>(IRType)->getBitWidth(); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1607 | |
Chris Lattner | e2962be | 2010-07-29 07:30:00 +0000 | [diff] [blame] | 1608 | if (BitsContainNoUserData(SourceTy, SourceOffset*8+BitWidth, |
| 1609 | SourceOffset*8+64, getContext())) |
| 1610 | return IRType; |
| 1611 | } |
| 1612 | } |
Chris Lattner | 49382de | 2010-07-28 22:44:07 +0000 | [diff] [blame] | 1613 | |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1614 | if (llvm::StructType *STy = dyn_cast<llvm::StructType>(IRType)) { |
Chris Lattner | 49382de | 2010-07-28 22:44:07 +0000 | [diff] [blame] | 1615 | // If this is a struct, recurse into the field at the specified offset. |
Chris Lattner | 44f0fd2 | 2010-07-29 02:20:19 +0000 | [diff] [blame] | 1616 | const llvm::StructLayout *SL = getTargetData().getStructLayout(STy); |
Chris Lattner | 49382de | 2010-07-28 22:44:07 +0000 | [diff] [blame] | 1617 | if (IROffset < SL->getSizeInBytes()) { |
| 1618 | unsigned FieldIdx = SL->getElementContainingOffset(IROffset); |
| 1619 | IROffset -= SL->getElementOffset(FieldIdx); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1620 | |
Chris Lattner | 0d2656d | 2010-07-29 17:40:35 +0000 | [diff] [blame] | 1621 | return GetINTEGERTypeAtOffset(STy->getElementType(FieldIdx), IROffset, |
| 1622 | SourceTy, SourceOffset); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1623 | } |
Chris Lattner | 49382de | 2010-07-28 22:44:07 +0000 | [diff] [blame] | 1624 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1625 | |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 1626 | if (llvm::ArrayType *ATy = dyn_cast<llvm::ArrayType>(IRType)) { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1627 | llvm::Type *EltTy = ATy->getElementType(); |
Chris Lattner | 021c3a3 | 2010-07-29 07:43:55 +0000 | [diff] [blame] | 1628 | unsigned EltSize = getTargetData().getTypeAllocSize(EltTy); |
| 1629 | unsigned EltOffset = IROffset/EltSize*EltSize; |
Chris Lattner | 0d2656d | 2010-07-29 17:40:35 +0000 | [diff] [blame] | 1630 | return GetINTEGERTypeAtOffset(EltTy, IROffset-EltOffset, SourceTy, |
| 1631 | SourceOffset); |
Chris Lattner | 021c3a3 | 2010-07-29 07:43:55 +0000 | [diff] [blame] | 1632 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1633 | |
Chris Lattner | 49382de | 2010-07-28 22:44:07 +0000 | [diff] [blame] | 1634 | // Okay, we don't have any better idea of what to pass, so we pass this in an |
| 1635 | // integer register that isn't too big to fit the rest of the struct. |
Chris Lattner | 9e45a3d | 2010-07-29 17:34:39 +0000 | [diff] [blame] | 1636 | unsigned TySizeInBytes = |
| 1637 | (unsigned)getContext().getTypeSizeInChars(SourceTy).getQuantity(); |
Chris Lattner | 49382de | 2010-07-28 22:44:07 +0000 | [diff] [blame] | 1638 | |
Chris Lattner | 9e45a3d | 2010-07-29 17:34:39 +0000 | [diff] [blame] | 1639 | assert(TySizeInBytes != SourceOffset && "Empty field?"); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1640 | |
Chris Lattner | 49382de | 2010-07-28 22:44:07 +0000 | [diff] [blame] | 1641 | // It is always safe to classify this as an integer type up to i64 that |
| 1642 | // isn't larger than the structure. |
Chris Lattner | 9e45a3d | 2010-07-29 17:34:39 +0000 | [diff] [blame] | 1643 | return llvm::IntegerType::get(getVMContext(), |
| 1644 | std::min(TySizeInBytes-SourceOffset, 8U)*8); |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Chris Lattner | 66e7b68 | 2010-09-01 00:50:20 +0000 | [diff] [blame] | 1647 | |
| 1648 | /// GetX86_64ByValArgumentPair - Given a high and low type that can ideally |
| 1649 | /// be used as elements of a two register pair to pass or return, return a |
| 1650 | /// first class aggregate to represent them. For example, if the low part of |
| 1651 | /// a by-value argument should be passed as i32* and the high part as float, |
| 1652 | /// return {i32*, float}. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1653 | static llvm::Type * |
Jay Foad | ef6de3d | 2011-07-11 09:56:20 +0000 | [diff] [blame] | 1654 | GetX86_64ByValArgumentPair(llvm::Type *Lo, llvm::Type *Hi, |
Chris Lattner | 66e7b68 | 2010-09-01 00:50:20 +0000 | [diff] [blame] | 1655 | const llvm::TargetData &TD) { |
| 1656 | // In order to correctly satisfy the ABI, we need to the high part to start |
| 1657 | // at offset 8. If the high and low parts we inferred are both 4-byte types |
| 1658 | // (e.g. i32 and i32) then the resultant struct type ({i32,i32}) won't have |
| 1659 | // the second element at offset 8. Check for this: |
| 1660 | unsigned LoSize = (unsigned)TD.getTypeAllocSize(Lo); |
| 1661 | unsigned HiAlign = TD.getABITypeAlignment(Hi); |
| 1662 | unsigned HiStart = llvm::TargetData::RoundUpAlignment(LoSize, HiAlign); |
| 1663 | assert(HiStart != 0 && HiStart <= 8 && "Invalid x86-64 argument pair!"); |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1664 | |
Chris Lattner | 66e7b68 | 2010-09-01 00:50:20 +0000 | [diff] [blame] | 1665 | // To handle this, we have to increase the size of the low part so that the |
| 1666 | // second element will start at an 8 byte offset. We can't increase the size |
| 1667 | // of the second element because it might make us access off the end of the |
| 1668 | // struct. |
| 1669 | if (HiStart != 8) { |
| 1670 | // There are only two sorts of types the ABI generation code can produce for |
| 1671 | // the low part of a pair that aren't 8 bytes in size: float or i8/i16/i32. |
| 1672 | // Promote these to a larger type. |
| 1673 | if (Lo->isFloatTy()) |
| 1674 | Lo = llvm::Type::getDoubleTy(Lo->getContext()); |
| 1675 | else { |
| 1676 | assert(Lo->isIntegerTy() && "Invalid/unknown lo type"); |
| 1677 | Lo = llvm::Type::getInt64Ty(Lo->getContext()); |
| 1678 | } |
| 1679 | } |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1680 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1681 | llvm::StructType *Result = llvm::StructType::get(Lo, Hi, NULL); |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1682 | |
| 1683 | |
Chris Lattner | 66e7b68 | 2010-09-01 00:50:20 +0000 | [diff] [blame] | 1684 | // Verify that the second element is at an 8-byte offset. |
| 1685 | assert(TD.getStructLayout(Result)->getElementOffset(1) == 8 && |
| 1686 | "Invalid x86-64 argument pair!"); |
| 1687 | return Result; |
| 1688 | } |
| 1689 | |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1690 | ABIArgInfo X86_64ABIInfo:: |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 1691 | classifyReturnType(QualType RetTy) const { |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1692 | // AMD64-ABI 3.2.3p4: Rule 1. Classify the return type with the |
| 1693 | // classification algorithm. |
| 1694 | X86_64ABIInfo::Class Lo, Hi; |
| 1695 | classify(RetTy, 0, Lo, Hi); |
| 1696 | |
| 1697 | // Check some invariants. |
| 1698 | assert((Hi != Memory || Lo == Memory) && "Invalid memory classification."); |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1699 | assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp classification."); |
| 1700 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1701 | llvm::Type *ResType = 0; |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1702 | switch (Lo) { |
| 1703 | case NoClass: |
Chris Lattner | 117e3f4 | 2010-07-30 04:02:24 +0000 | [diff] [blame] | 1704 | if (Hi == NoClass) |
| 1705 | return ABIArgInfo::getIgnore(); |
| 1706 | // If the low part is just padding, it takes no register, leave ResType |
| 1707 | // null. |
| 1708 | assert((Hi == SSE || Hi == Integer || Hi == X87Up) && |
| 1709 | "Unknown missing lo part"); |
| 1710 | break; |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1711 | |
| 1712 | case SSEUp: |
| 1713 | case X87Up: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1714 | llvm_unreachable("Invalid classification for lo word."); |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1715 | |
| 1716 | // AMD64-ABI 3.2.3p4: Rule 2. Types of class memory are returned via |
| 1717 | // hidden argument. |
| 1718 | case Memory: |
| 1719 | return getIndirectReturnResult(RetTy); |
| 1720 | |
| 1721 | // AMD64-ABI 3.2.3p4: Rule 3. If the class is INTEGER, the next |
| 1722 | // available register of the sequence %rax, %rdx is used. |
| 1723 | case Integer: |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1724 | ResType = GetINTEGERTypeAtOffset(CGT.ConvertType(RetTy), 0, RetTy, 0); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1725 | |
Chris Lattner | eb518b4 | 2010-07-29 21:42:50 +0000 | [diff] [blame] | 1726 | // If we have a sign or zero extended integer, make sure to return Extend |
| 1727 | // so that the parameter gets the right LLVM IR attributes. |
| 1728 | if (Hi == NoClass && isa<llvm::IntegerType>(ResType)) { |
| 1729 | // Treat an enum type as its underlying type. |
| 1730 | if (const EnumType *EnumTy = RetTy->getAs<EnumType>()) |
| 1731 | RetTy = EnumTy->getDecl()->getIntegerType(); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1732 | |
Chris Lattner | eb518b4 | 2010-07-29 21:42:50 +0000 | [diff] [blame] | 1733 | if (RetTy->isIntegralOrEnumerationType() && |
| 1734 | RetTy->isPromotableIntegerType()) |
| 1735 | return ABIArgInfo::getExtend(); |
| 1736 | } |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1737 | break; |
| 1738 | |
| 1739 | // AMD64-ABI 3.2.3p4: Rule 4. If the class is SSE, the next |
| 1740 | // available SSE register of the sequence %xmm0, %xmm1 is used. |
| 1741 | case SSE: |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1742 | ResType = GetSSETypeAtOffset(CGT.ConvertType(RetTy), 0, RetTy, 0); |
Chris Lattner | 0b30c67 | 2010-07-28 23:12:33 +0000 | [diff] [blame] | 1743 | break; |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1744 | |
| 1745 | // AMD64-ABI 3.2.3p4: Rule 6. If the class is X87, the value is |
| 1746 | // returned on the X87 stack in %st0 as 80-bit x87 number. |
| 1747 | case X87: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1748 | ResType = llvm::Type::getX86_FP80Ty(getVMContext()); |
Chris Lattner | 0b30c67 | 2010-07-28 23:12:33 +0000 | [diff] [blame] | 1749 | break; |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1750 | |
| 1751 | // AMD64-ABI 3.2.3p4: Rule 8. If the class is COMPLEX_X87, the real |
| 1752 | // part of the value is returned in %st0 and the imaginary part in |
| 1753 | // %st1. |
| 1754 | case ComplexX87: |
| 1755 | assert(Hi == ComplexX87 && "Unexpected ComplexX87 classification."); |
Chris Lattner | 7650d95 | 2011-06-18 22:49:11 +0000 | [diff] [blame] | 1756 | ResType = llvm::StructType::get(llvm::Type::getX86_FP80Ty(getVMContext()), |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 1757 | llvm::Type::getX86_FP80Ty(getVMContext()), |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1758 | NULL); |
| 1759 | break; |
| 1760 | } |
| 1761 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1762 | llvm::Type *HighPart = 0; |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1763 | switch (Hi) { |
| 1764 | // Memory was handled previously and X87 should |
| 1765 | // never occur as a hi class. |
| 1766 | case Memory: |
| 1767 | case X87: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1768 | llvm_unreachable("Invalid classification for hi word."); |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1769 | |
| 1770 | case ComplexX87: // Previously handled. |
Chris Lattner | 0b30c67 | 2010-07-28 23:12:33 +0000 | [diff] [blame] | 1771 | case NoClass: |
| 1772 | break; |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1773 | |
Chris Lattner | 3db4dde | 2010-09-01 00:20:33 +0000 | [diff] [blame] | 1774 | case Integer: |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1775 | HighPart = GetINTEGERTypeAtOffset(CGT.ConvertType(RetTy), 8, RetTy, 8); |
Chris Lattner | 3db4dde | 2010-09-01 00:20:33 +0000 | [diff] [blame] | 1776 | if (Lo == NoClass) // Return HighPart at offset 8 in memory. |
| 1777 | return ABIArgInfo::getDirect(HighPart, 8); |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1778 | break; |
Chris Lattner | 3db4dde | 2010-09-01 00:20:33 +0000 | [diff] [blame] | 1779 | case SSE: |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1780 | HighPart = GetSSETypeAtOffset(CGT.ConvertType(RetTy), 8, RetTy, 8); |
Chris Lattner | 3db4dde | 2010-09-01 00:20:33 +0000 | [diff] [blame] | 1781 | if (Lo == NoClass) // Return HighPart at offset 8 in memory. |
| 1782 | return ABIArgInfo::getDirect(HighPart, 8); |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1783 | break; |
| 1784 | |
| 1785 | // AMD64-ABI 3.2.3p4: Rule 5. If the class is SSEUP, the eightbyte |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 1786 | // is passed in the next available eightbyte chunk if the last used |
| 1787 | // vector register. |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1788 | // |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 1789 | // SSEUP should always be preceded by SSE, just widen. |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1790 | case SSEUp: |
| 1791 | assert(Lo == SSE && "Unexpected SSEUp classification."); |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 1792 | ResType = GetByteVectorType(RetTy); |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1793 | break; |
| 1794 | |
| 1795 | // AMD64-ABI 3.2.3p4: Rule 7. If the class is X87UP, the value is |
| 1796 | // returned together with the previous X87 value in %st0. |
| 1797 | case X87Up: |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 1798 | // If X87Up is preceded by X87, we don't need to do |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1799 | // anything. However, in some cases with unions it may not be |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 1800 | // preceded by X87. In such situations we follow gcc and pass the |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1801 | // extra bits in an SSE reg. |
Chris Lattner | 603519d | 2010-07-29 17:49:08 +0000 | [diff] [blame] | 1802 | if (Lo != X87) { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1803 | HighPart = GetSSETypeAtOffset(CGT.ConvertType(RetTy), 8, RetTy, 8); |
Chris Lattner | 3db4dde | 2010-09-01 00:20:33 +0000 | [diff] [blame] | 1804 | if (Lo == NoClass) // Return HighPart at offset 8 in memory. |
| 1805 | return ABIArgInfo::getDirect(HighPart, 8); |
Chris Lattner | 603519d | 2010-07-29 17:49:08 +0000 | [diff] [blame] | 1806 | } |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1807 | break; |
| 1808 | } |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1809 | |
Chris Lattner | 3db4dde | 2010-09-01 00:20:33 +0000 | [diff] [blame] | 1810 | // If a high part was specified, merge it together with the low part. It is |
Chris Lattner | 645406a | 2010-09-01 00:24:35 +0000 | [diff] [blame] | 1811 | // known to pass in the high eightbyte of the result. We do this by forming a |
| 1812 | // first class struct aggregate with the high and low part: {low, high} |
Chris Lattner | 66e7b68 | 2010-09-01 00:50:20 +0000 | [diff] [blame] | 1813 | if (HighPart) |
| 1814 | ResType = GetX86_64ByValArgumentPair(ResType, HighPart, getTargetData()); |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1815 | |
Chris Lattner | eb518b4 | 2010-07-29 21:42:50 +0000 | [diff] [blame] | 1816 | return ABIArgInfo::getDirect(ResType); |
Chris Lattner | 519f68c | 2010-07-28 23:06:14 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 1819 | ABIArgInfo X86_64ABIInfo::classifyArgumentType(QualType Ty, unsigned &neededInt, |
Bill Wendling | 99aaae8 | 2010-10-18 23:51:38 +0000 | [diff] [blame] | 1820 | unsigned &neededSSE) const { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1821 | X86_64ABIInfo::Class Lo, Hi; |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 1822 | classify(Ty, 0, Lo, Hi); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1823 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1824 | // Check some invariants. |
| 1825 | // FIXME: Enforce these by construction. |
| 1826 | assert((Hi != Memory || Lo == Memory) && "Invalid memory classification."); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1827 | assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp classification."); |
| 1828 | |
| 1829 | neededInt = 0; |
| 1830 | neededSSE = 0; |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1831 | llvm::Type *ResType = 0; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1832 | switch (Lo) { |
| 1833 | case NoClass: |
Chris Lattner | 117e3f4 | 2010-07-30 04:02:24 +0000 | [diff] [blame] | 1834 | if (Hi == NoClass) |
| 1835 | return ABIArgInfo::getIgnore(); |
| 1836 | // If the low part is just padding, it takes no register, leave ResType |
| 1837 | // null. |
| 1838 | assert((Hi == SSE || Hi == Integer || Hi == X87Up) && |
| 1839 | "Unknown missing lo part"); |
| 1840 | break; |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1841 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1842 | // AMD64-ABI 3.2.3p3: Rule 1. If the class is MEMORY, pass the argument |
| 1843 | // on the stack. |
| 1844 | case Memory: |
| 1845 | |
| 1846 | // AMD64-ABI 3.2.3p3: Rule 5. If the class is X87, X87UP or |
| 1847 | // COMPLEX_X87, it is passed in memory. |
| 1848 | case X87: |
| 1849 | case ComplexX87: |
Eli Friedman | ded137f | 2011-06-29 07:04:55 +0000 | [diff] [blame] | 1850 | if (isRecordWithNonTrivialDestructorOrCopyConstructor(Ty)) |
| 1851 | ++neededInt; |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 1852 | return getIndirectResult(Ty); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1853 | |
| 1854 | case SSEUp: |
| 1855 | case X87Up: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1856 | llvm_unreachable("Invalid classification for lo word."); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1857 | |
| 1858 | // AMD64-ABI 3.2.3p3: Rule 2. If the class is INTEGER, the next |
| 1859 | // available register of the sequence %rdi, %rsi, %rdx, %rcx, %r8 |
| 1860 | // and %r9 is used. |
| 1861 | case Integer: |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 1862 | ++neededInt; |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1863 | |
Chris Lattner | 49382de | 2010-07-28 22:44:07 +0000 | [diff] [blame] | 1864 | // Pick an 8-byte type based on the preferred type. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1865 | ResType = GetINTEGERTypeAtOffset(CGT.ConvertType(Ty), 0, Ty, 0); |
Chris Lattner | eb518b4 | 2010-07-29 21:42:50 +0000 | [diff] [blame] | 1866 | |
| 1867 | // If we have a sign or zero extended integer, make sure to return Extend |
| 1868 | // so that the parameter gets the right LLVM IR attributes. |
| 1869 | if (Hi == NoClass && isa<llvm::IntegerType>(ResType)) { |
| 1870 | // Treat an enum type as its underlying type. |
| 1871 | if (const EnumType *EnumTy = Ty->getAs<EnumType>()) |
| 1872 | Ty = EnumTy->getDecl()->getIntegerType(); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1873 | |
Chris Lattner | eb518b4 | 2010-07-29 21:42:50 +0000 | [diff] [blame] | 1874 | if (Ty->isIntegralOrEnumerationType() && |
| 1875 | Ty->isPromotableIntegerType()) |
| 1876 | return ABIArgInfo::getExtend(); |
| 1877 | } |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1878 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1879 | break; |
| 1880 | |
| 1881 | // AMD64-ABI 3.2.3p3: Rule 3. If the class is SSE, the next |
| 1882 | // available SSE register is used, the registers are taken in the |
| 1883 | // order from %xmm0 to %xmm7. |
Bill Wendling | bb465d7 | 2010-10-18 03:41:31 +0000 | [diff] [blame] | 1884 | case SSE: { |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1885 | llvm::Type *IRType = CGT.ConvertType(Ty); |
Eli Friedman | 14508ff | 2011-07-02 00:57:27 +0000 | [diff] [blame] | 1886 | ResType = GetSSETypeAtOffset(IRType, 0, Ty, 0); |
Bill Wendling | 99aaae8 | 2010-10-18 23:51:38 +0000 | [diff] [blame] | 1887 | ++neededSSE; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1888 | break; |
| 1889 | } |
Bill Wendling | bb465d7 | 2010-10-18 03:41:31 +0000 | [diff] [blame] | 1890 | } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1891 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1892 | llvm::Type *HighPart = 0; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1893 | switch (Hi) { |
| 1894 | // Memory was handled previously, ComplexX87 and X87 should |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 1895 | // never occur as hi classes, and X87Up must be preceded by X87, |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1896 | // which is passed in memory. |
| 1897 | case Memory: |
| 1898 | case X87: |
| 1899 | case ComplexX87: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1900 | llvm_unreachable("Invalid classification for hi word."); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1901 | |
| 1902 | case NoClass: break; |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1903 | |
Chris Lattner | 645406a | 2010-09-01 00:24:35 +0000 | [diff] [blame] | 1904 | case Integer: |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1905 | ++neededInt; |
Chris Lattner | 49382de | 2010-07-28 22:44:07 +0000 | [diff] [blame] | 1906 | // Pick an 8-byte type based on the preferred type. |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1907 | HighPart = GetINTEGERTypeAtOffset(CGT.ConvertType(Ty), 8, Ty, 8); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1908 | |
Chris Lattner | 645406a | 2010-09-01 00:24:35 +0000 | [diff] [blame] | 1909 | if (Lo == NoClass) // Pass HighPart at offset 8 in memory. |
| 1910 | return ABIArgInfo::getDirect(HighPart, 8); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1911 | break; |
| 1912 | |
| 1913 | // X87Up generally doesn't occur here (long double is passed in |
| 1914 | // memory), except in situations involving unions. |
| 1915 | case X87Up: |
Chris Lattner | 645406a | 2010-09-01 00:24:35 +0000 | [diff] [blame] | 1916 | case SSE: |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 1917 | HighPart = GetSSETypeAtOffset(CGT.ConvertType(Ty), 8, Ty, 8); |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1918 | |
Chris Lattner | 645406a | 2010-09-01 00:24:35 +0000 | [diff] [blame] | 1919 | if (Lo == NoClass) // Pass HighPart at offset 8 in memory. |
| 1920 | return ABIArgInfo::getDirect(HighPart, 8); |
Chris Lattner | 117e3f4 | 2010-07-30 04:02:24 +0000 | [diff] [blame] | 1921 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1922 | ++neededSSE; |
| 1923 | break; |
| 1924 | |
| 1925 | // AMD64-ABI 3.2.3p3: Rule 4. If the class is SSEUP, the |
| 1926 | // eightbyte is passed in the upper half of the last used SSE |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1927 | // register. This only happens when 128-bit vectors are passed. |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1928 | case SSEUp: |
Chris Lattner | ab5722e | 2010-07-28 23:47:21 +0000 | [diff] [blame] | 1929 | assert(Lo == SSE && "Unexpected SSEUp classification"); |
Bruno Cardoso Lopes | 4943c15 | 2011-07-11 22:41:29 +0000 | [diff] [blame] | 1930 | ResType = GetByteVectorType(Ty); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1931 | break; |
| 1932 | } |
| 1933 | |
Chris Lattner | 645406a | 2010-09-01 00:24:35 +0000 | [diff] [blame] | 1934 | // If a high part was specified, merge it together with the low part. It is |
| 1935 | // known to pass in the high eightbyte of the result. We do this by forming a |
| 1936 | // first class struct aggregate with the high and low part: {low, high} |
| 1937 | if (HighPart) |
Chris Lattner | 66e7b68 | 2010-09-01 00:50:20 +0000 | [diff] [blame] | 1938 | ResType = GetX86_64ByValArgumentPair(ResType, HighPart, getTargetData()); |
Michael J. Spencer | 9cac494 | 2010-10-19 06:39:39 +0000 | [diff] [blame] | 1939 | |
Chris Lattner | eb518b4 | 2010-07-29 21:42:50 +0000 | [diff] [blame] | 1940 | return ABIArgInfo::getDirect(ResType); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
Chris Lattner | ee5dcd0 | 2010-07-29 02:31:05 +0000 | [diff] [blame] | 1943 | void X86_64ABIInfo::computeInfo(CGFunctionInfo &FI) const { |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 1944 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 1945 | FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1946 | |
| 1947 | // Keep track of the number of assigned registers. |
Bill Wendling | 99aaae8 | 2010-10-18 23:51:38 +0000 | [diff] [blame] | 1948 | unsigned freeIntRegs = 6, freeSSERegs = 8; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1949 | |
| 1950 | // If the return value is indirect, then the hidden argument is consuming one |
| 1951 | // integer register. |
| 1952 | if (FI.getReturnInfo().isIndirect()) |
| 1953 | --freeIntRegs; |
| 1954 | |
| 1955 | // AMD64-ABI 3.2.3p3: Once arguments are classified, the registers |
| 1956 | // get assigned (in left-to-right order) for passing as follows... |
| 1957 | for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end(); |
| 1958 | it != ie; ++it) { |
Bill Wendling | 99aaae8 | 2010-10-18 23:51:38 +0000 | [diff] [blame] | 1959 | unsigned neededInt, neededSSE; |
| 1960 | it->info = classifyArgumentType(it->type, neededInt, neededSSE); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1961 | |
| 1962 | // AMD64-ABI 3.2.3p3: If there are no registers available for any |
| 1963 | // eightbyte of an argument, the whole argument is passed on the |
| 1964 | // stack. If registers have already been assigned for some |
| 1965 | // eightbytes of such an argument, the assignments get reverted. |
Bill Wendling | 99aaae8 | 2010-10-18 23:51:38 +0000 | [diff] [blame] | 1966 | if (freeIntRegs >= neededInt && freeSSERegs >= neededSSE) { |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1967 | freeIntRegs -= neededInt; |
| 1968 | freeSSERegs -= neededSSE; |
| 1969 | } else { |
Chris Lattner | 9c254f0 | 2010-06-29 06:01:59 +0000 | [diff] [blame] | 1970 | it->info = getIndirectResult(it->type); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1971 | } |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | static llvm::Value *EmitVAArgFromMemory(llvm::Value *VAListAddr, |
| 1976 | QualType Ty, |
| 1977 | CodeGenFunction &CGF) { |
| 1978 | llvm::Value *overflow_arg_area_p = |
| 1979 | CGF.Builder.CreateStructGEP(VAListAddr, 2, "overflow_arg_area_p"); |
| 1980 | llvm::Value *overflow_arg_area = |
| 1981 | CGF.Builder.CreateLoad(overflow_arg_area_p, "overflow_arg_area"); |
| 1982 | |
| 1983 | // AMD64-ABI 3.5.7p5: Step 7. Align l->overflow_arg_area upwards to a 16 |
| 1984 | // byte boundary if alignment needed by type exceeds 8 byte boundary. |
| 1985 | uint64_t Align = CGF.getContext().getTypeAlign(Ty) / 8; |
| 1986 | if (Align > 8) { |
| 1987 | // Note that we follow the ABI & gcc here, even though the type |
| 1988 | // could in theory have an alignment greater than 16. This case |
| 1989 | // shouldn't ever matter in practice. |
| 1990 | |
| 1991 | // overflow_arg_area = (overflow_arg_area + 15) & ~15; |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 1992 | llvm::Value *Offset = |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1993 | llvm::ConstantInt::get(CGF.Int32Ty, 15); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1994 | overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset); |
| 1995 | llvm::Value *AsInt = CGF.Builder.CreatePtrToInt(overflow_arg_area, |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 1996 | CGF.Int64Ty); |
| 1997 | llvm::Value *Mask = llvm::ConstantInt::get(CGF.Int64Ty, ~15LL); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 1998 | overflow_arg_area = |
| 1999 | CGF.Builder.CreateIntToPtr(CGF.Builder.CreateAnd(AsInt, Mask), |
| 2000 | overflow_arg_area->getType(), |
| 2001 | "overflow_arg_area.align"); |
| 2002 | } |
| 2003 | |
| 2004 | // AMD64-ABI 3.5.7p5: Step 8. Fetch type from l->overflow_arg_area. |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2005 | llvm::Type *LTy = CGF.ConvertTypeForMem(Ty); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2006 | llvm::Value *Res = |
| 2007 | CGF.Builder.CreateBitCast(overflow_arg_area, |
Owen Anderson | 96e0fc7 | 2009-07-29 22:16:19 +0000 | [diff] [blame] | 2008 | llvm::PointerType::getUnqual(LTy)); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2009 | |
| 2010 | // AMD64-ABI 3.5.7p5: Step 9. Set l->overflow_arg_area to: |
| 2011 | // l->overflow_arg_area + sizeof(type). |
| 2012 | // AMD64-ABI 3.5.7p5: Step 10. Align l->overflow_arg_area upwards to |
| 2013 | // an 8 byte boundary. |
| 2014 | |
| 2015 | uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8; |
Owen Anderson | 0032b27 | 2009-08-13 21:57:51 +0000 | [diff] [blame] | 2016 | llvm::Value *Offset = |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 2017 | llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7) & ~7); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2018 | overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset, |
| 2019 | "overflow_arg_area.next"); |
| 2020 | CGF.Builder.CreateStore(overflow_arg_area, overflow_arg_area_p); |
| 2021 | |
| 2022 | // AMD64-ABI 3.5.7p5: Step 11. Return the fetched type. |
| 2023 | return Res; |
| 2024 | } |
| 2025 | |
| 2026 | llvm::Value *X86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 2027 | CodeGenFunction &CGF) const { |
Owen Anderson | a1cf15f | 2009-07-14 23:10:40 +0000 | [diff] [blame] | 2028 | llvm::LLVMContext &VMContext = CGF.getLLVMContext(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2029 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2030 | // Assume that va_list type is correct; should be pointer to LLVM type: |
| 2031 | // struct { |
| 2032 | // i32 gp_offset; |
| 2033 | // i32 fp_offset; |
| 2034 | // i8* overflow_arg_area; |
| 2035 | // i8* reg_save_area; |
| 2036 | // }; |
Bill Wendling | 99aaae8 | 2010-10-18 23:51:38 +0000 | [diff] [blame] | 2037 | unsigned neededInt, neededSSE; |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 2038 | |
Chris Lattner | a14db75 | 2010-03-11 18:19:55 +0000 | [diff] [blame] | 2039 | Ty = CGF.getContext().getCanonicalType(Ty); |
Bill Wendling | 99aaae8 | 2010-10-18 23:51:38 +0000 | [diff] [blame] | 2040 | ABIArgInfo AI = classifyArgumentType(Ty, neededInt, neededSSE); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2041 | |
| 2042 | // AMD64-ABI 3.5.7p5: Step 1. Determine whether type may be passed |
| 2043 | // in the registers. If not go to step 7. |
| 2044 | if (!neededInt && !neededSSE) |
| 2045 | return EmitVAArgFromMemory(VAListAddr, Ty, CGF); |
| 2046 | |
| 2047 | // AMD64-ABI 3.5.7p5: Step 2. Compute num_gp to hold the number of |
| 2048 | // general purpose registers needed to pass type and num_fp to hold |
| 2049 | // the number of floating point registers needed. |
| 2050 | |
| 2051 | // AMD64-ABI 3.5.7p5: Step 3. Verify whether arguments fit into |
| 2052 | // registers. In the case: l->gp_offset > 48 - num_gp * 8 or |
| 2053 | // l->fp_offset > 304 - num_fp * 16 go to step 7. |
| 2054 | // |
| 2055 | // NOTE: 304 is a typo, there are (6 * 8 + 8 * 16) = 176 bytes of |
| 2056 | // register save space). |
| 2057 | |
| 2058 | llvm::Value *InRegs = 0; |
| 2059 | llvm::Value *gp_offset_p = 0, *gp_offset = 0; |
| 2060 | llvm::Value *fp_offset_p = 0, *fp_offset = 0; |
| 2061 | if (neededInt) { |
| 2062 | gp_offset_p = CGF.Builder.CreateStructGEP(VAListAddr, 0, "gp_offset_p"); |
| 2063 | gp_offset = CGF.Builder.CreateLoad(gp_offset_p, "gp_offset"); |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 2064 | InRegs = llvm::ConstantInt::get(CGF.Int32Ty, 48 - neededInt * 8); |
| 2065 | InRegs = CGF.Builder.CreateICmpULE(gp_offset, InRegs, "fits_in_gp"); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | if (neededSSE) { |
| 2069 | fp_offset_p = CGF.Builder.CreateStructGEP(VAListAddr, 1, "fp_offset_p"); |
| 2070 | fp_offset = CGF.Builder.CreateLoad(fp_offset_p, "fp_offset"); |
| 2071 | llvm::Value *FitsInFP = |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 2072 | llvm::ConstantInt::get(CGF.Int32Ty, 176 - neededSSE * 16); |
| 2073 | FitsInFP = CGF.Builder.CreateICmpULE(fp_offset, FitsInFP, "fits_in_fp"); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2074 | InRegs = InRegs ? CGF.Builder.CreateAnd(InRegs, FitsInFP) : FitsInFP; |
| 2075 | } |
| 2076 | |
| 2077 | llvm::BasicBlock *InRegBlock = CGF.createBasicBlock("vaarg.in_reg"); |
| 2078 | llvm::BasicBlock *InMemBlock = CGF.createBasicBlock("vaarg.in_mem"); |
| 2079 | llvm::BasicBlock *ContBlock = CGF.createBasicBlock("vaarg.end"); |
| 2080 | CGF.Builder.CreateCondBr(InRegs, InRegBlock, InMemBlock); |
| 2081 | |
| 2082 | // Emit code to load the value if it was passed in registers. |
| 2083 | |
| 2084 | CGF.EmitBlock(InRegBlock); |
| 2085 | |
| 2086 | // AMD64-ABI 3.5.7p5: Step 4. Fetch type from l->reg_save_area with |
| 2087 | // an offset of l->gp_offset and/or l->fp_offset. This may require |
| 2088 | // copying to a temporary location in case the parameter is passed |
| 2089 | // in different register classes or requires an alignment greater |
| 2090 | // than 8 for general purpose registers and 16 for XMM registers. |
| 2091 | // |
| 2092 | // FIXME: This really results in shameful code when we end up needing to |
| 2093 | // collect arguments from different places; often what should result in a |
| 2094 | // simple assembling of a structure from scattered addresses has many more |
| 2095 | // loads than necessary. Can we clean this up? |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2096 | llvm::Type *LTy = CGF.ConvertTypeForMem(Ty); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2097 | llvm::Value *RegAddr = |
| 2098 | CGF.Builder.CreateLoad(CGF.Builder.CreateStructGEP(VAListAddr, 3), |
| 2099 | "reg_save_area"); |
| 2100 | if (neededInt && neededSSE) { |
| 2101 | // FIXME: Cleanup. |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 2102 | assert(AI.isDirect() && "Unexpected ABI info for mixed regs"); |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2103 | llvm::StructType *ST = cast<llvm::StructType>(AI.getCoerceToType()); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2104 | llvm::Value *Tmp = CGF.CreateTempAlloca(ST); |
| 2105 | assert(ST->getNumElements() == 2 && "Unexpected ABI info for mixed regs"); |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2106 | llvm::Type *TyLo = ST->getElementType(0); |
| 2107 | llvm::Type *TyHi = ST->getElementType(1); |
Chris Lattner | a8b7a7d | 2010-08-26 06:28:35 +0000 | [diff] [blame] | 2108 | assert((TyLo->isFPOrFPVectorTy() ^ TyHi->isFPOrFPVectorTy()) && |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2109 | "Unexpected ABI info for mixed regs"); |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2110 | llvm::Type *PTyLo = llvm::PointerType::getUnqual(TyLo); |
| 2111 | llvm::Type *PTyHi = llvm::PointerType::getUnqual(TyHi); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2112 | llvm::Value *GPAddr = CGF.Builder.CreateGEP(RegAddr, gp_offset); |
| 2113 | llvm::Value *FPAddr = CGF.Builder.CreateGEP(RegAddr, fp_offset); |
Duncan Sands | f177d9d | 2010-02-15 16:14:01 +0000 | [diff] [blame] | 2114 | llvm::Value *RegLoAddr = TyLo->isFloatingPointTy() ? FPAddr : GPAddr; |
| 2115 | llvm::Value *RegHiAddr = TyLo->isFloatingPointTy() ? GPAddr : FPAddr; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2116 | llvm::Value *V = |
| 2117 | CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegLoAddr, PTyLo)); |
| 2118 | CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0)); |
| 2119 | V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegHiAddr, PTyHi)); |
| 2120 | CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1)); |
| 2121 | |
Owen Anderson | a1cf15f | 2009-07-14 23:10:40 +0000 | [diff] [blame] | 2122 | RegAddr = CGF.Builder.CreateBitCast(Tmp, |
Owen Anderson | 96e0fc7 | 2009-07-29 22:16:19 +0000 | [diff] [blame] | 2123 | llvm::PointerType::getUnqual(LTy)); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2124 | } else if (neededInt) { |
| 2125 | RegAddr = CGF.Builder.CreateGEP(RegAddr, gp_offset); |
| 2126 | RegAddr = CGF.Builder.CreateBitCast(RegAddr, |
Owen Anderson | 96e0fc7 | 2009-07-29 22:16:19 +0000 | [diff] [blame] | 2127 | llvm::PointerType::getUnqual(LTy)); |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 2128 | } else if (neededSSE == 1) { |
| 2129 | RegAddr = CGF.Builder.CreateGEP(RegAddr, fp_offset); |
| 2130 | RegAddr = CGF.Builder.CreateBitCast(RegAddr, |
| 2131 | llvm::PointerType::getUnqual(LTy)); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2132 | } else { |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 2133 | assert(neededSSE == 2 && "Invalid number of needed registers!"); |
| 2134 | // SSE registers are spaced 16 bytes apart in the register save |
| 2135 | // area, we need to collect the two eightbytes together. |
| 2136 | llvm::Value *RegAddrLo = CGF.Builder.CreateGEP(RegAddr, fp_offset); |
Chris Lattner | 1090a9b | 2010-06-28 21:43:59 +0000 | [diff] [blame] | 2137 | llvm::Value *RegAddrHi = CGF.Builder.CreateConstGEP1_32(RegAddrLo, 16); |
Jay Foad | ef6de3d | 2011-07-11 09:56:20 +0000 | [diff] [blame] | 2138 | llvm::Type *DoubleTy = llvm::Type::getDoubleTy(VMContext); |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2139 | llvm::Type *DblPtrTy = |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 2140 | llvm::PointerType::getUnqual(DoubleTy); |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2141 | llvm::StructType *ST = llvm::StructType::get(DoubleTy, |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 2142 | DoubleTy, NULL); |
| 2143 | llvm::Value *V, *Tmp = CGF.CreateTempAlloca(ST); |
| 2144 | V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegAddrLo, |
| 2145 | DblPtrTy)); |
| 2146 | CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0)); |
| 2147 | V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegAddrHi, |
| 2148 | DblPtrTy)); |
| 2149 | CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1)); |
| 2150 | RegAddr = CGF.Builder.CreateBitCast(Tmp, |
| 2151 | llvm::PointerType::getUnqual(LTy)); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | // AMD64-ABI 3.5.7p5: Step 5. Set: |
| 2155 | // l->gp_offset = l->gp_offset + num_gp * 8 |
| 2156 | // l->fp_offset = l->fp_offset + num_fp * 16. |
| 2157 | if (neededInt) { |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 2158 | llvm::Value *Offset = llvm::ConstantInt::get(CGF.Int32Ty, neededInt * 8); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2159 | CGF.Builder.CreateStore(CGF.Builder.CreateAdd(gp_offset, Offset), |
| 2160 | gp_offset_p); |
| 2161 | } |
| 2162 | if (neededSSE) { |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 2163 | llvm::Value *Offset = llvm::ConstantInt::get(CGF.Int32Ty, neededSSE * 16); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2164 | CGF.Builder.CreateStore(CGF.Builder.CreateAdd(fp_offset, Offset), |
| 2165 | fp_offset_p); |
| 2166 | } |
| 2167 | CGF.EmitBranch(ContBlock); |
| 2168 | |
| 2169 | // Emit code to load the value if it was passed in memory. |
| 2170 | |
| 2171 | CGF.EmitBlock(InMemBlock); |
| 2172 | llvm::Value *MemAddr = EmitVAArgFromMemory(VAListAddr, Ty, CGF); |
| 2173 | |
| 2174 | // Return the appropriate result. |
| 2175 | |
| 2176 | CGF.EmitBlock(ContBlock); |
Jay Foad | bbf3bac | 2011-03-30 11:28:58 +0000 | [diff] [blame] | 2177 | llvm::PHINode *ResAddr = CGF.Builder.CreatePHI(RegAddr->getType(), 2, |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2178 | "vaarg.addr"); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2179 | ResAddr->addIncoming(RegAddr, InRegBlock); |
| 2180 | ResAddr->addIncoming(MemAddr, InMemBlock); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2181 | return ResAddr; |
| 2182 | } |
| 2183 | |
NAKAMURA Takumi | a757322 | 2011-01-17 22:56:31 +0000 | [diff] [blame] | 2184 | ABIArgInfo WinX86_64ABIInfo::classify(QualType Ty) const { |
| 2185 | |
| 2186 | if (Ty->isVoidType()) |
| 2187 | return ABIArgInfo::getIgnore(); |
| 2188 | |
| 2189 | if (const EnumType *EnumTy = Ty->getAs<EnumType>()) |
| 2190 | Ty = EnumTy->getDecl()->getIntegerType(); |
| 2191 | |
| 2192 | uint64_t Size = getContext().getTypeSize(Ty); |
| 2193 | |
| 2194 | if (const RecordType *RT = Ty->getAs<RecordType>()) { |
NAKAMURA Takumi | ff8be0e | 2011-01-19 00:11:33 +0000 | [diff] [blame] | 2195 | if (hasNonTrivialDestructorOrCopyConstructor(RT) || |
| 2196 | RT->getDecl()->hasFlexibleArrayMember()) |
NAKAMURA Takumi | a757322 | 2011-01-17 22:56:31 +0000 | [diff] [blame] | 2197 | return ABIArgInfo::getIndirect(0, /*ByVal=*/false); |
| 2198 | |
NAKAMURA Takumi | 6f17433 | 2011-02-22 03:56:57 +0000 | [diff] [blame] | 2199 | // FIXME: mingw-w64-gcc emits 128-bit struct as i128 |
| 2200 | if (Size == 128 && |
Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 2201 | getContext().getTargetInfo().getTriple().getOS() == llvm::Triple::MinGW32) |
NAKAMURA Takumi | 6f17433 | 2011-02-22 03:56:57 +0000 | [diff] [blame] | 2202 | return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(), |
| 2203 | Size)); |
| 2204 | |
| 2205 | // MS x64 ABI requirement: "Any argument that doesn't fit in 8 bytes, or is |
| 2206 | // not 1, 2, 4, or 8 bytes, must be passed by reference." |
| 2207 | if (Size <= 64 && |
NAKAMURA Takumi | ff8be0e | 2011-01-19 00:11:33 +0000 | [diff] [blame] | 2208 | (Size & (Size - 1)) == 0) |
NAKAMURA Takumi | a757322 | 2011-01-17 22:56:31 +0000 | [diff] [blame] | 2209 | return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(), |
| 2210 | Size)); |
| 2211 | |
| 2212 | return ABIArgInfo::getIndirect(0, /*ByVal=*/false); |
| 2213 | } |
| 2214 | |
| 2215 | if (Ty->isPromotableIntegerType()) |
| 2216 | return ABIArgInfo::getExtend(); |
| 2217 | |
| 2218 | return ABIArgInfo::getDirect(); |
| 2219 | } |
| 2220 | |
| 2221 | void WinX86_64ABIInfo::computeInfo(CGFunctionInfo &FI) const { |
| 2222 | |
| 2223 | QualType RetTy = FI.getReturnType(); |
| 2224 | FI.getReturnInfo() = classify(RetTy); |
| 2225 | |
NAKAMURA Takumi | a757322 | 2011-01-17 22:56:31 +0000 | [diff] [blame] | 2226 | for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end(); |
| 2227 | it != ie; ++it) |
| 2228 | it->info = classify(it->type); |
| 2229 | } |
| 2230 | |
Chris Lattner | f13721d | 2010-08-31 16:44:54 +0000 | [diff] [blame] | 2231 | llvm::Value *WinX86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 2232 | CodeGenFunction &CGF) const { |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2233 | llvm::Type *BP = llvm::Type::getInt8PtrTy(CGF.getLLVMContext()); |
| 2234 | llvm::Type *BPP = llvm::PointerType::getUnqual(BP); |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 2235 | |
Chris Lattner | f13721d | 2010-08-31 16:44:54 +0000 | [diff] [blame] | 2236 | CGBuilderTy &Builder = CGF.Builder; |
| 2237 | llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP, |
| 2238 | "ap"); |
| 2239 | llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur"); |
| 2240 | llvm::Type *PTy = |
| 2241 | llvm::PointerType::getUnqual(CGF.ConvertType(Ty)); |
| 2242 | llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy); |
| 2243 | |
| 2244 | uint64_t Offset = |
| 2245 | llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 8); |
| 2246 | llvm::Value *NextAddr = |
| 2247 | Builder.CreateGEP(Addr, llvm::ConstantInt::get(CGF.Int32Ty, Offset), |
| 2248 | "ap.next"); |
| 2249 | Builder.CreateStore(NextAddr, VAListAddrAsBPP); |
| 2250 | |
| 2251 | return AddrTyped; |
| 2252 | } |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 2253 | |
John McCall | ec853ba | 2010-03-11 00:10:12 +0000 | [diff] [blame] | 2254 | // PowerPC-32 |
| 2255 | |
| 2256 | namespace { |
| 2257 | class PPC32TargetCodeGenInfo : public DefaultTargetCodeGenInfo { |
| 2258 | public: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 2259 | PPC32TargetCodeGenInfo(CodeGenTypes &CGT) : DefaultTargetCodeGenInfo(CGT) {} |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 2260 | |
John McCall | ec853ba | 2010-03-11 00:10:12 +0000 | [diff] [blame] | 2261 | int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const { |
| 2262 | // This is recovered from gcc output. |
| 2263 | return 1; // r1 is the dedicated stack pointer |
| 2264 | } |
| 2265 | |
| 2266 | bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 2267 | llvm::Value *Address) const; |
John McCall | ec853ba | 2010-03-11 00:10:12 +0000 | [diff] [blame] | 2268 | }; |
| 2269 | |
| 2270 | } |
| 2271 | |
| 2272 | bool |
| 2273 | PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, |
| 2274 | llvm::Value *Address) const { |
| 2275 | // This is calculated from the LLVM and GCC tables and verified |
| 2276 | // against gcc output. AFAIK all ABIs use the same encoding. |
| 2277 | |
| 2278 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 2279 | llvm::LLVMContext &Context = CGF.getLLVMContext(); |
| 2280 | |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2281 | llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context); |
John McCall | ec853ba | 2010-03-11 00:10:12 +0000 | [diff] [blame] | 2282 | llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4); |
| 2283 | llvm::Value *Eight8 = llvm::ConstantInt::get(i8, 8); |
| 2284 | llvm::Value *Sixteen8 = llvm::ConstantInt::get(i8, 16); |
| 2285 | |
| 2286 | // 0-31: r0-31, the 4-byte general-purpose registers |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 2287 | AssignToArrayRange(Builder, Address, Four8, 0, 31); |
John McCall | ec853ba | 2010-03-11 00:10:12 +0000 | [diff] [blame] | 2288 | |
| 2289 | // 32-63: fp0-31, the 8-byte floating-point registers |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 2290 | AssignToArrayRange(Builder, Address, Eight8, 32, 63); |
John McCall | ec853ba | 2010-03-11 00:10:12 +0000 | [diff] [blame] | 2291 | |
| 2292 | // 64-76 are various 4-byte special-purpose registers: |
| 2293 | // 64: mq |
| 2294 | // 65: lr |
| 2295 | // 66: ctr |
| 2296 | // 67: ap |
| 2297 | // 68-75 cr0-7 |
| 2298 | // 76: xer |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 2299 | AssignToArrayRange(Builder, Address, Four8, 64, 76); |
John McCall | ec853ba | 2010-03-11 00:10:12 +0000 | [diff] [blame] | 2300 | |
| 2301 | // 77-108: v0-31, the 16-byte vector registers |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 2302 | AssignToArrayRange(Builder, Address, Sixteen8, 77, 108); |
John McCall | ec853ba | 2010-03-11 00:10:12 +0000 | [diff] [blame] | 2303 | |
| 2304 | // 109: vrsave |
| 2305 | // 110: vscr |
| 2306 | // 111: spe_acc |
| 2307 | // 112: spefscr |
| 2308 | // 113: sfp |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 2309 | AssignToArrayRange(Builder, Address, Four8, 109, 113); |
John McCall | ec853ba | 2010-03-11 00:10:12 +0000 | [diff] [blame] | 2310 | |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 2311 | return false; |
John McCall | ec853ba | 2010-03-11 00:10:12 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 2315 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 34d91fd | 2009-09-12 00:59:49 +0000 | [diff] [blame] | 2316 | // ARM ABI Implementation |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 2317 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | 34d91fd | 2009-09-12 00:59:49 +0000 | [diff] [blame] | 2318 | |
| 2319 | namespace { |
| 2320 | |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2321 | class ARMABIInfo : public ABIInfo { |
Daniel Dunbar | 5e7bace | 2009-09-12 01:00:39 +0000 | [diff] [blame] | 2322 | public: |
| 2323 | enum ABIKind { |
| 2324 | APCS = 0, |
| 2325 | AAPCS = 1, |
| 2326 | AAPCS_VFP |
| 2327 | }; |
| 2328 | |
| 2329 | private: |
| 2330 | ABIKind Kind; |
| 2331 | |
| 2332 | public: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 2333 | ARMABIInfo(CodeGenTypes &CGT, ABIKind _Kind) : ABIInfo(CGT), Kind(_Kind) {} |
Daniel Dunbar | 5e7bace | 2009-09-12 01:00:39 +0000 | [diff] [blame] | 2334 | |
John McCall | 49e34be | 2011-08-30 01:42:09 +0000 | [diff] [blame] | 2335 | bool isEABI() const { |
Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 2336 | StringRef Env = getContext().getTargetInfo().getTriple().getEnvironmentName(); |
John McCall | 49e34be | 2011-08-30 01:42:09 +0000 | [diff] [blame] | 2337 | return (Env == "gnueabi" || Env == "eabi"); |
| 2338 | } |
| 2339 | |
Daniel Dunbar | 5e7bace | 2009-09-12 01:00:39 +0000 | [diff] [blame] | 2340 | private: |
| 2341 | ABIKind getABIKind() const { return Kind; } |
| 2342 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2343 | ABIArgInfo classifyReturnType(QualType RetTy) const; |
| 2344 | ABIArgInfo classifyArgumentType(QualType RetTy) const; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2345 | |
Chris Lattner | ee5dcd0 | 2010-07-29 02:31:05 +0000 | [diff] [blame] | 2346 | virtual void computeInfo(CGFunctionInfo &FI) const; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2347 | |
| 2348 | virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 2349 | CodeGenFunction &CGF) const; |
| 2350 | }; |
| 2351 | |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 2352 | class ARMTargetCodeGenInfo : public TargetCodeGenInfo { |
| 2353 | public: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 2354 | ARMTargetCodeGenInfo(CodeGenTypes &CGT, ARMABIInfo::ABIKind K) |
| 2355 | :TargetCodeGenInfo(new ARMABIInfo(CGT, K)) {} |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 2356 | |
John McCall | 49e34be | 2011-08-30 01:42:09 +0000 | [diff] [blame] | 2357 | const ARMABIInfo &getABIInfo() const { |
| 2358 | return static_cast<const ARMABIInfo&>(TargetCodeGenInfo::getABIInfo()); |
| 2359 | } |
| 2360 | |
John McCall | 6374c33 | 2010-03-06 00:35:14 +0000 | [diff] [blame] | 2361 | int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const { |
| 2362 | return 13; |
| 2363 | } |
Roman Divacky | 09345d1 | 2011-05-18 19:36:54 +0000 | [diff] [blame] | 2364 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2365 | StringRef getARCRetainAutoreleasedReturnValueMarker() const { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 2366 | return "mov\tr7, r7\t\t@ marker for objc_retainAutoreleaseReturnValue"; |
| 2367 | } |
| 2368 | |
Roman Divacky | 09345d1 | 2011-05-18 19:36:54 +0000 | [diff] [blame] | 2369 | bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, |
| 2370 | llvm::Value *Address) const { |
| 2371 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 2372 | llvm::LLVMContext &Context = CGF.getLLVMContext(); |
| 2373 | |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2374 | llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context); |
Roman Divacky | 09345d1 | 2011-05-18 19:36:54 +0000 | [diff] [blame] | 2375 | llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4); |
| 2376 | |
| 2377 | // 0-15 are the 16 integer registers. |
| 2378 | AssignToArrayRange(Builder, Address, Four8, 0, 15); |
| 2379 | |
| 2380 | return false; |
| 2381 | } |
John McCall | 49e34be | 2011-08-30 01:42:09 +0000 | [diff] [blame] | 2382 | |
| 2383 | unsigned getSizeOfUnwindException() const { |
| 2384 | if (getABIInfo().isEABI()) return 88; |
| 2385 | return TargetCodeGenInfo::getSizeOfUnwindException(); |
| 2386 | } |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 2387 | }; |
| 2388 | |
Daniel Dunbar | 34d91fd | 2009-09-12 00:59:49 +0000 | [diff] [blame] | 2389 | } |
| 2390 | |
Chris Lattner | ee5dcd0 | 2010-07-29 02:31:05 +0000 | [diff] [blame] | 2391 | void ARMABIInfo::computeInfo(CGFunctionInfo &FI) const { |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2392 | FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2393 | for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end(); |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2394 | it != ie; ++it) |
| 2395 | it->info = classifyArgumentType(it->type); |
Daniel Dunbar | 5e7bace | 2009-09-12 01:00:39 +0000 | [diff] [blame] | 2396 | |
Anton Korobeynikov | 414d896 | 2011-04-14 20:06:49 +0000 | [diff] [blame] | 2397 | // Always honor user-specified calling convention. |
| 2398 | if (FI.getCallingConvention() != llvm::CallingConv::C) |
| 2399 | return; |
| 2400 | |
| 2401 | // Calling convention as default by an ABI. |
Rafael Espindola | 25117ab | 2010-06-16 16:13:39 +0000 | [diff] [blame] | 2402 | llvm::CallingConv::ID DefaultCC; |
John McCall | 49e34be | 2011-08-30 01:42:09 +0000 | [diff] [blame] | 2403 | if (isEABI()) |
Rafael Espindola | 25117ab | 2010-06-16 16:13:39 +0000 | [diff] [blame] | 2404 | DefaultCC = llvm::CallingConv::ARM_AAPCS; |
Rafael Espindola | 1ed1a59 | 2010-06-16 19:01:17 +0000 | [diff] [blame] | 2405 | else |
| 2406 | DefaultCC = llvm::CallingConv::ARM_APCS; |
Rafael Espindola | 25117ab | 2010-06-16 16:13:39 +0000 | [diff] [blame] | 2407 | |
Anton Korobeynikov | 414d896 | 2011-04-14 20:06:49 +0000 | [diff] [blame] | 2408 | // If user did not ask for specific calling convention explicitly (e.g. via |
| 2409 | // pcs attribute), set effective calling convention if it's different than ABI |
| 2410 | // default. |
Daniel Dunbar | 5e7bace | 2009-09-12 01:00:39 +0000 | [diff] [blame] | 2411 | switch (getABIKind()) { |
| 2412 | case APCS: |
Rafael Espindola | 25117ab | 2010-06-16 16:13:39 +0000 | [diff] [blame] | 2413 | if (DefaultCC != llvm::CallingConv::ARM_APCS) |
| 2414 | FI.setEffectiveCallingConvention(llvm::CallingConv::ARM_APCS); |
Daniel Dunbar | 5e7bace | 2009-09-12 01:00:39 +0000 | [diff] [blame] | 2415 | break; |
Daniel Dunbar | 5e7bace | 2009-09-12 01:00:39 +0000 | [diff] [blame] | 2416 | case AAPCS: |
Rafael Espindola | 25117ab | 2010-06-16 16:13:39 +0000 | [diff] [blame] | 2417 | if (DefaultCC != llvm::CallingConv::ARM_AAPCS) |
| 2418 | FI.setEffectiveCallingConvention(llvm::CallingConv::ARM_AAPCS); |
Daniel Dunbar | 5e7bace | 2009-09-12 01:00:39 +0000 | [diff] [blame] | 2419 | break; |
Daniel Dunbar | 5e7bace | 2009-09-12 01:00:39 +0000 | [diff] [blame] | 2420 | case AAPCS_VFP: |
Anton Korobeynikov | 414d896 | 2011-04-14 20:06:49 +0000 | [diff] [blame] | 2421 | if (DefaultCC != llvm::CallingConv::ARM_AAPCS_VFP) |
| 2422 | FI.setEffectiveCallingConvention(llvm::CallingConv::ARM_AAPCS_VFP); |
Daniel Dunbar | 5e7bace | 2009-09-12 01:00:39 +0000 | [diff] [blame] | 2423 | break; |
| 2424 | } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
Bob Wilson | 194f06a | 2011-08-03 05:58:22 +0000 | [diff] [blame] | 2427 | /// isHomogeneousAggregate - Return true if a type is an AAPCS-VFP homogeneous |
| 2428 | /// aggregate. If HAMembers is non-null, the number of base elements |
| 2429 | /// contained in the type is returned through it; this is used for the |
| 2430 | /// recursive calls that check aggregate component types. |
| 2431 | static bool isHomogeneousAggregate(QualType Ty, const Type *&Base, |
| 2432 | ASTContext &Context, |
| 2433 | uint64_t *HAMembers = 0) { |
| 2434 | uint64_t Members; |
| 2435 | if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty)) { |
| 2436 | if (!isHomogeneousAggregate(AT->getElementType(), Base, Context, &Members)) |
| 2437 | return false; |
| 2438 | Members *= AT->getSize().getZExtValue(); |
| 2439 | } else if (const RecordType *RT = Ty->getAs<RecordType>()) { |
| 2440 | const RecordDecl *RD = RT->getDecl(); |
| 2441 | if (RD->isUnion() || RD->hasFlexibleArrayMember()) |
| 2442 | return false; |
| 2443 | if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) { |
| 2444 | if (!CXXRD->isAggregate()) |
| 2445 | return false; |
| 2446 | } |
| 2447 | Members = 0; |
| 2448 | for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); |
| 2449 | i != e; ++i) { |
| 2450 | const FieldDecl *FD = *i; |
| 2451 | uint64_t FldMembers; |
| 2452 | if (!isHomogeneousAggregate(FD->getType(), Base, Context, &FldMembers)) |
| 2453 | return false; |
| 2454 | Members += FldMembers; |
| 2455 | } |
| 2456 | } else { |
| 2457 | Members = 1; |
| 2458 | if (const ComplexType *CT = Ty->getAs<ComplexType>()) { |
| 2459 | Members = 2; |
| 2460 | Ty = CT->getElementType(); |
| 2461 | } |
| 2462 | |
| 2463 | // Homogeneous aggregates for AAPCS-VFP must have base types of float, |
| 2464 | // double, or 64-bit or 128-bit vectors. |
| 2465 | if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) { |
| 2466 | if (BT->getKind() != BuiltinType::Float && |
| 2467 | BT->getKind() != BuiltinType::Double) |
| 2468 | return false; |
| 2469 | } else if (const VectorType *VT = Ty->getAs<VectorType>()) { |
| 2470 | unsigned VecSize = Context.getTypeSize(VT); |
| 2471 | if (VecSize != 64 && VecSize != 128) |
| 2472 | return false; |
| 2473 | } else { |
| 2474 | return false; |
| 2475 | } |
| 2476 | |
| 2477 | // The base type must be the same for all members. Vector types of the |
| 2478 | // same total size are treated as being equivalent here. |
| 2479 | const Type *TyPtr = Ty.getTypePtr(); |
| 2480 | if (!Base) |
| 2481 | Base = TyPtr; |
| 2482 | if (Base != TyPtr && |
| 2483 | (!Base->isVectorType() || !TyPtr->isVectorType() || |
| 2484 | Context.getTypeSize(Base) != Context.getTypeSize(TyPtr))) |
| 2485 | return false; |
| 2486 | } |
| 2487 | |
| 2488 | // Homogeneous Aggregates can have at most 4 members of the base type. |
| 2489 | if (HAMembers) |
| 2490 | *HAMembers = Members; |
| 2491 | return (Members <= 4); |
| 2492 | } |
| 2493 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2494 | ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty) const { |
John McCall | d608cdb | 2010-08-22 10:59:02 +0000 | [diff] [blame] | 2495 | if (!isAggregateTypeForABI(Ty)) { |
Douglas Gregor | aa74a1e | 2010-02-02 20:10:50 +0000 | [diff] [blame] | 2496 | // Treat an enum type as its underlying type. |
| 2497 | if (const EnumType *EnumTy = Ty->getAs<EnumType>()) |
| 2498 | Ty = EnumTy->getDecl()->getIntegerType(); |
| 2499 | |
Anton Korobeynikov | cc6fa88 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 2500 | return (Ty->isPromotableIntegerType() ? |
| 2501 | ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
Douglas Gregor | aa74a1e | 2010-02-02 20:10:50 +0000 | [diff] [blame] | 2502 | } |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2503 | |
Daniel Dunbar | 4202557 | 2009-09-14 21:54:03 +0000 | [diff] [blame] | 2504 | // Ignore empty records. |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2505 | if (isEmptyRecord(getContext(), Ty, true)) |
Daniel Dunbar | 4202557 | 2009-09-14 21:54:03 +0000 | [diff] [blame] | 2506 | return ABIArgInfo::getIgnore(); |
| 2507 | |
Rafael Espindola | 0eb1d97 | 2010-06-08 02:42:08 +0000 | [diff] [blame] | 2508 | // Structures with either a non-trivial destructor or a non-trivial |
| 2509 | // copy constructor are always indirect. |
| 2510 | if (isRecordWithNonTrivialDestructorOrCopyConstructor(Ty)) |
| 2511 | return ABIArgInfo::getIndirect(0, /*ByVal=*/false); |
| 2512 | |
Bob Wilson | 194f06a | 2011-08-03 05:58:22 +0000 | [diff] [blame] | 2513 | if (getABIKind() == ARMABIInfo::AAPCS_VFP) { |
| 2514 | // Homogeneous Aggregates need to be expanded. |
| 2515 | const Type *Base = 0; |
| 2516 | if (isHomogeneousAggregate(Ty, Base, getContext())) |
| 2517 | return ABIArgInfo::getExpand(); |
| 2518 | } |
| 2519 | |
Daniel Dunbar | 8aa87c7 | 2010-09-23 01:54:28 +0000 | [diff] [blame] | 2520 | // Otherwise, pass by coercing to a structure of the appropriate size. |
| 2521 | // |
Bob Wilson | 53fc1a6 | 2011-08-01 23:39:04 +0000 | [diff] [blame] | 2522 | // FIXME: This is kind of nasty... but there isn't much choice because the ARM |
| 2523 | // backend doesn't support byval. |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2524 | // FIXME: This doesn't handle alignment > 64 bits. |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2525 | llvm::Type* ElemTy; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2526 | unsigned SizeRegs; |
Bob Wilson | 53fc1a6 | 2011-08-01 23:39:04 +0000 | [diff] [blame] | 2527 | if (getContext().getTypeAlign(Ty) > 32) { |
Stuart Hastings | 67d097e | 2011-04-27 17:24:02 +0000 | [diff] [blame] | 2528 | ElemTy = llvm::Type::getInt64Ty(getVMContext()); |
| 2529 | SizeRegs = (getContext().getTypeSize(Ty) + 63) / 64; |
Bob Wilson | 53fc1a6 | 2011-08-01 23:39:04 +0000 | [diff] [blame] | 2530 | } else { |
| 2531 | ElemTy = llvm::Type::getInt32Ty(getVMContext()); |
| 2532 | SizeRegs = (getContext().getTypeSize(Ty) + 31) / 32; |
Stuart Hastings | 67d097e | 2011-04-27 17:24:02 +0000 | [diff] [blame] | 2533 | } |
Stuart Hastings | b7f62d0 | 2011-04-28 18:16:06 +0000 | [diff] [blame] | 2534 | |
Chris Lattner | 9cbe4f0 | 2011-07-09 17:41:47 +0000 | [diff] [blame] | 2535 | llvm::Type *STy = |
Chris Lattner | 7650d95 | 2011-06-18 22:49:11 +0000 | [diff] [blame] | 2536 | llvm::StructType::get(llvm::ArrayType::get(ElemTy, SizeRegs), NULL); |
Stuart Hastings | b7f62d0 | 2011-04-28 18:16:06 +0000 | [diff] [blame] | 2537 | return ABIArgInfo::getDirect(STy); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2540 | static bool isIntegerLikeType(QualType Ty, ASTContext &Context, |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2541 | llvm::LLVMContext &VMContext) { |
| 2542 | // APCS, C Language Calling Conventions, Non-Simple Return Values: A structure |
| 2543 | // is called integer-like if its size is less than or equal to one word, and |
| 2544 | // the offset of each of its addressable sub-fields is zero. |
| 2545 | |
| 2546 | uint64_t Size = Context.getTypeSize(Ty); |
| 2547 | |
| 2548 | // Check that the type fits in a word. |
| 2549 | if (Size > 32) |
| 2550 | return false; |
| 2551 | |
| 2552 | // FIXME: Handle vector types! |
| 2553 | if (Ty->isVectorType()) |
| 2554 | return false; |
| 2555 | |
Daniel Dunbar | b0d5819 | 2009-09-14 02:20:34 +0000 | [diff] [blame] | 2556 | // Float types are never treated as "integer like". |
| 2557 | if (Ty->isRealFloatingType()) |
| 2558 | return false; |
| 2559 | |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2560 | // If this is a builtin or pointer type then it is ok. |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2561 | if (Ty->getAs<BuiltinType>() || Ty->isPointerType()) |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2562 | return true; |
| 2563 | |
Daniel Dunbar | 4581581 | 2010-02-01 23:31:26 +0000 | [diff] [blame] | 2564 | // Small complex integer types are "integer like". |
| 2565 | if (const ComplexType *CT = Ty->getAs<ComplexType>()) |
| 2566 | return isIntegerLikeType(CT->getElementType(), Context, VMContext); |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2567 | |
| 2568 | // Single element and zero sized arrays should be allowed, by the definition |
| 2569 | // above, but they are not. |
| 2570 | |
| 2571 | // Otherwise, it must be a record type. |
| 2572 | const RecordType *RT = Ty->getAs<RecordType>(); |
| 2573 | if (!RT) return false; |
| 2574 | |
| 2575 | // Ignore records with flexible arrays. |
| 2576 | const RecordDecl *RD = RT->getDecl(); |
| 2577 | if (RD->hasFlexibleArrayMember()) |
| 2578 | return false; |
| 2579 | |
| 2580 | // Check that all sub-fields are at offset 0, and are themselves "integer |
| 2581 | // like". |
| 2582 | const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); |
| 2583 | |
| 2584 | bool HadField = false; |
| 2585 | unsigned idx = 0; |
| 2586 | for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); |
| 2587 | i != e; ++i, ++idx) { |
| 2588 | const FieldDecl *FD = *i; |
| 2589 | |
Daniel Dunbar | 679855a | 2010-01-29 03:22:29 +0000 | [diff] [blame] | 2590 | // Bit-fields are not addressable, we only need to verify they are "integer |
| 2591 | // like". We still have to disallow a subsequent non-bitfield, for example: |
| 2592 | // struct { int : 0; int x } |
| 2593 | // is non-integer like according to gcc. |
| 2594 | if (FD->isBitField()) { |
| 2595 | if (!RD->isUnion()) |
| 2596 | HadField = true; |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2597 | |
Daniel Dunbar | 679855a | 2010-01-29 03:22:29 +0000 | [diff] [blame] | 2598 | if (!isIntegerLikeType(FD->getType(), Context, VMContext)) |
| 2599 | return false; |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2600 | |
Daniel Dunbar | 679855a | 2010-01-29 03:22:29 +0000 | [diff] [blame] | 2601 | continue; |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2602 | } |
| 2603 | |
Daniel Dunbar | 679855a | 2010-01-29 03:22:29 +0000 | [diff] [blame] | 2604 | // Check if this field is at offset 0. |
| 2605 | if (Layout.getFieldOffset(idx) != 0) |
| 2606 | return false; |
| 2607 | |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2608 | if (!isIntegerLikeType(FD->getType(), Context, VMContext)) |
| 2609 | return false; |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 2610 | |
Daniel Dunbar | 679855a | 2010-01-29 03:22:29 +0000 | [diff] [blame] | 2611 | // Only allow at most one field in a structure. This doesn't match the |
| 2612 | // wording above, but follows gcc in situations with a field following an |
| 2613 | // empty structure. |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2614 | if (!RD->isUnion()) { |
| 2615 | if (HadField) |
| 2616 | return false; |
| 2617 | |
| 2618 | HadField = true; |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | return true; |
| 2623 | } |
| 2624 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2625 | ABIArgInfo ARMABIInfo::classifyReturnType(QualType RetTy) const { |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2626 | if (RetTy->isVoidType()) |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2627 | return ABIArgInfo::getIgnore(); |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2628 | |
Daniel Dunbar | f554b1c | 2010-09-23 01:54:32 +0000 | [diff] [blame] | 2629 | // Large vector types should be returned via memory. |
| 2630 | if (RetTy->isVectorType() && getContext().getTypeSize(RetTy) > 128) |
| 2631 | return ABIArgInfo::getIndirect(0); |
| 2632 | |
John McCall | d608cdb | 2010-08-22 10:59:02 +0000 | [diff] [blame] | 2633 | if (!isAggregateTypeForABI(RetTy)) { |
Douglas Gregor | aa74a1e | 2010-02-02 20:10:50 +0000 | [diff] [blame] | 2634 | // Treat an enum type as its underlying type. |
| 2635 | if (const EnumType *EnumTy = RetTy->getAs<EnumType>()) |
| 2636 | RetTy = EnumTy->getDecl()->getIntegerType(); |
| 2637 | |
Anton Korobeynikov | cc6fa88 | 2009-06-06 09:36:29 +0000 | [diff] [blame] | 2638 | return (RetTy->isPromotableIntegerType() ? |
| 2639 | ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
Douglas Gregor | aa74a1e | 2010-02-02 20:10:50 +0000 | [diff] [blame] | 2640 | } |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2641 | |
Rafael Espindola | 0eb1d97 | 2010-06-08 02:42:08 +0000 | [diff] [blame] | 2642 | // Structures with either a non-trivial destructor or a non-trivial |
| 2643 | // copy constructor are always indirect. |
| 2644 | if (isRecordWithNonTrivialDestructorOrCopyConstructor(RetTy)) |
| 2645 | return ABIArgInfo::getIndirect(0, /*ByVal=*/false); |
| 2646 | |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2647 | // Are we following APCS? |
| 2648 | if (getABIKind() == APCS) { |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2649 | if (isEmptyRecord(getContext(), RetTy, false)) |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2650 | return ABIArgInfo::getIgnore(); |
| 2651 | |
Daniel Dunbar | 4cc753f | 2010-02-01 23:31:19 +0000 | [diff] [blame] | 2652 | // Complex types are all returned as packed integers. |
| 2653 | // |
| 2654 | // FIXME: Consider using 2 x vector types if the back end handles them |
| 2655 | // correctly. |
| 2656 | if (RetTy->isAnyComplexType()) |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 2657 | return ABIArgInfo::getDirect(llvm::IntegerType::get(getVMContext(), |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2658 | getContext().getTypeSize(RetTy))); |
Daniel Dunbar | 4cc753f | 2010-02-01 23:31:19 +0000 | [diff] [blame] | 2659 | |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2660 | // Integer like structures are returned in r0. |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2661 | if (isIntegerLikeType(RetTy, getContext(), getVMContext())) { |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2662 | // Return in the smallest viable integer type. |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2663 | uint64_t Size = getContext().getTypeSize(RetTy); |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2664 | if (Size <= 8) |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 2665 | return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext())); |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2666 | if (Size <= 16) |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 2667 | return ABIArgInfo::getDirect(llvm::Type::getInt16Ty(getVMContext())); |
| 2668 | return ABIArgInfo::getDirect(llvm::Type::getInt32Ty(getVMContext())); |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | // Otherwise return in memory. |
| 2672 | return ABIArgInfo::getIndirect(0); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2673 | } |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2674 | |
| 2675 | // Otherwise this is an AAPCS variant. |
| 2676 | |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2677 | if (isEmptyRecord(getContext(), RetTy, true)) |
Daniel Dunbar | 16a0808 | 2009-09-14 00:56:55 +0000 | [diff] [blame] | 2678 | return ABIArgInfo::getIgnore(); |
| 2679 | |
Bob Wilson | 3b694fa | 2011-11-02 04:51:36 +0000 | [diff] [blame] | 2680 | // Check for homogeneous aggregates with AAPCS-VFP. |
| 2681 | if (getABIKind() == AAPCS_VFP) { |
| 2682 | const Type *Base = 0; |
| 2683 | if (isHomogeneousAggregate(RetTy, Base, getContext())) |
| 2684 | // Homogeneous Aggregates are returned directly. |
| 2685 | return ABIArgInfo::getDirect(); |
| 2686 | } |
| 2687 | |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2688 | // Aggregates <= 4 bytes are returned in r0; other aggregates |
| 2689 | // are returned indirectly. |
Chris Lattner | a3c109b | 2010-07-29 02:16:43 +0000 | [diff] [blame] | 2690 | uint64_t Size = getContext().getTypeSize(RetTy); |
Daniel Dunbar | 16a0808 | 2009-09-14 00:56:55 +0000 | [diff] [blame] | 2691 | if (Size <= 32) { |
| 2692 | // Return in the smallest viable integer type. |
| 2693 | if (Size <= 8) |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 2694 | return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext())); |
Daniel Dunbar | 16a0808 | 2009-09-14 00:56:55 +0000 | [diff] [blame] | 2695 | if (Size <= 16) |
Chris Lattner | 800588f | 2010-07-29 06:26:06 +0000 | [diff] [blame] | 2696 | return ABIArgInfo::getDirect(llvm::Type::getInt16Ty(getVMContext())); |
| 2697 | return ABIArgInfo::getDirect(llvm::Type::getInt32Ty(getVMContext())); |
Daniel Dunbar | 16a0808 | 2009-09-14 00:56:55 +0000 | [diff] [blame] | 2698 | } |
| 2699 | |
Daniel Dunbar | 98303b9 | 2009-09-13 08:03:58 +0000 | [diff] [blame] | 2700 | return ABIArgInfo::getIndirect(0); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | llvm::Value *ARMABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 2704 | CodeGenFunction &CGF) const { |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 2705 | llvm::Type *BP = llvm::Type::getInt8PtrTy(CGF.getLLVMContext()); |
| 2706 | llvm::Type *BPP = llvm::PointerType::getUnqual(BP); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2707 | |
| 2708 | CGBuilderTy &Builder = CGF.Builder; |
| 2709 | llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP, |
| 2710 | "ap"); |
| 2711 | llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur"); |
Rafael Espindola | e164c18 | 2011-08-02 22:33:37 +0000 | [diff] [blame] | 2712 | // Handle address alignment for type alignment > 32 bits |
| 2713 | uint64_t TyAlign = CGF.getContext().getTypeAlign(Ty) / 8; |
| 2714 | if (TyAlign > 4) { |
| 2715 | assert((TyAlign & (TyAlign - 1)) == 0 && |
| 2716 | "Alignment is not power of 2!"); |
| 2717 | llvm::Value *AddrAsInt = Builder.CreatePtrToInt(Addr, CGF.Int32Ty); |
| 2718 | AddrAsInt = Builder.CreateAdd(AddrAsInt, Builder.getInt32(TyAlign - 1)); |
| 2719 | AddrAsInt = Builder.CreateAnd(AddrAsInt, Builder.getInt32(~(TyAlign - 1))); |
| 2720 | Addr = Builder.CreateIntToPtr(AddrAsInt, BP); |
| 2721 | } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2722 | llvm::Type *PTy = |
Owen Anderson | 96e0fc7 | 2009-07-29 22:16:19 +0000 | [diff] [blame] | 2723 | llvm::PointerType::getUnqual(CGF.ConvertType(Ty)); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2724 | llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy); |
| 2725 | |
| 2726 | uint64_t Offset = |
| 2727 | llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4); |
| 2728 | llvm::Value *NextAddr = |
Chris Lattner | 77b89b8 | 2010-06-27 07:15:29 +0000 | [diff] [blame] | 2729 | Builder.CreateGEP(Addr, llvm::ConstantInt::get(CGF.Int32Ty, Offset), |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2730 | "ap.next"); |
| 2731 | Builder.CreateStore(NextAddr, VAListAddrAsBPP); |
| 2732 | |
| 2733 | return AddrTyped; |
| 2734 | } |
| 2735 | |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 2736 | //===----------------------------------------------------------------------===// |
Justin Holewinski | 0259c3a | 2011-04-22 11:10:38 +0000 | [diff] [blame] | 2737 | // PTX ABI Implementation |
| 2738 | //===----------------------------------------------------------------------===// |
| 2739 | |
| 2740 | namespace { |
| 2741 | |
| 2742 | class PTXABIInfo : public ABIInfo { |
| 2743 | public: |
| 2744 | PTXABIInfo(CodeGenTypes &CGT) : ABIInfo(CGT) {} |
| 2745 | |
| 2746 | ABIArgInfo classifyReturnType(QualType RetTy) const; |
| 2747 | ABIArgInfo classifyArgumentType(QualType Ty) const; |
| 2748 | |
| 2749 | virtual void computeInfo(CGFunctionInfo &FI) const; |
| 2750 | virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 2751 | CodeGenFunction &CFG) const; |
| 2752 | }; |
| 2753 | |
| 2754 | class PTXTargetCodeGenInfo : public TargetCodeGenInfo { |
| 2755 | public: |
| 2756 | PTXTargetCodeGenInfo(CodeGenTypes &CGT) |
| 2757 | : TargetCodeGenInfo(new PTXABIInfo(CGT)) {} |
Justin Holewinski | 818eafb | 2011-10-05 17:58:44 +0000 | [diff] [blame] | 2758 | |
Peter Collingbourne | 2f7aa99 | 2011-10-13 16:24:41 +0000 | [diff] [blame] | 2759 | virtual void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV, |
| 2760 | CodeGen::CodeGenModule &M) const; |
Justin Holewinski | 0259c3a | 2011-04-22 11:10:38 +0000 | [diff] [blame] | 2761 | }; |
| 2762 | |
| 2763 | ABIArgInfo PTXABIInfo::classifyReturnType(QualType RetTy) const { |
| 2764 | if (RetTy->isVoidType()) |
| 2765 | return ABIArgInfo::getIgnore(); |
| 2766 | if (isAggregateTypeForABI(RetTy)) |
| 2767 | return ABIArgInfo::getIndirect(0); |
| 2768 | return ABIArgInfo::getDirect(); |
| 2769 | } |
| 2770 | |
| 2771 | ABIArgInfo PTXABIInfo::classifyArgumentType(QualType Ty) const { |
| 2772 | if (isAggregateTypeForABI(Ty)) |
| 2773 | return ABIArgInfo::getIndirect(0); |
| 2774 | |
| 2775 | return ABIArgInfo::getDirect(); |
| 2776 | } |
| 2777 | |
| 2778 | void PTXABIInfo::computeInfo(CGFunctionInfo &FI) const { |
| 2779 | FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); |
| 2780 | for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end(); |
| 2781 | it != ie; ++it) |
| 2782 | it->info = classifyArgumentType(it->type); |
| 2783 | |
| 2784 | // Always honor user-specified calling convention. |
| 2785 | if (FI.getCallingConvention() != llvm::CallingConv::C) |
| 2786 | return; |
| 2787 | |
| 2788 | // Calling convention as default by an ABI. |
| 2789 | llvm::CallingConv::ID DefaultCC; |
Peter Collingbourne | 744d90b | 2011-10-06 16:49:54 +0000 | [diff] [blame] | 2790 | const LangOptions &LangOpts = getContext().getLangOptions(); |
| 2791 | if (LangOpts.OpenCL || LangOpts.CUDA) { |
| 2792 | // If we are in OpenCL or CUDA mode, then default to device functions |
Justin Holewinski | 0259c3a | 2011-04-22 11:10:38 +0000 | [diff] [blame] | 2793 | DefaultCC = llvm::CallingConv::PTX_Device; |
Justin Holewinski | 818eafb | 2011-10-05 17:58:44 +0000 | [diff] [blame] | 2794 | } else { |
| 2795 | // If we are in standard C/C++ mode, use the triple to decide on the default |
| 2796 | StringRef Env = |
| 2797 | getContext().getTargetInfo().getTriple().getEnvironmentName(); |
| 2798 | if (Env == "device") |
| 2799 | DefaultCC = llvm::CallingConv::PTX_Device; |
| 2800 | else |
| 2801 | DefaultCC = llvm::CallingConv::PTX_Kernel; |
| 2802 | } |
Justin Holewinski | 0259c3a | 2011-04-22 11:10:38 +0000 | [diff] [blame] | 2803 | FI.setEffectiveCallingConvention(DefaultCC); |
Justin Holewinski | 818eafb | 2011-10-05 17:58:44 +0000 | [diff] [blame] | 2804 | |
Justin Holewinski | 0259c3a | 2011-04-22 11:10:38 +0000 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | llvm::Value *PTXABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 2808 | CodeGenFunction &CFG) const { |
| 2809 | llvm_unreachable("PTX does not support varargs"); |
| 2810 | return 0; |
| 2811 | } |
| 2812 | |
Justin Holewinski | 818eafb | 2011-10-05 17:58:44 +0000 | [diff] [blame] | 2813 | void PTXTargetCodeGenInfo::SetTargetAttributes(const Decl *D, |
| 2814 | llvm::GlobalValue *GV, |
| 2815 | CodeGen::CodeGenModule &M) const{ |
| 2816 | const FunctionDecl *FD = dyn_cast<FunctionDecl>(D); |
| 2817 | if (!FD) return; |
| 2818 | |
| 2819 | llvm::Function *F = cast<llvm::Function>(GV); |
| 2820 | |
| 2821 | // Perform special handling in OpenCL mode |
Peter Collingbourne | 744d90b | 2011-10-06 16:49:54 +0000 | [diff] [blame] | 2822 | if (M.getLangOptions().OpenCL) { |
Justin Holewinski | 818eafb | 2011-10-05 17:58:44 +0000 | [diff] [blame] | 2823 | // Use OpenCL function attributes to set proper calling conventions |
| 2824 | // By default, all functions are device functions |
Justin Holewinski | 818eafb | 2011-10-05 17:58:44 +0000 | [diff] [blame] | 2825 | if (FD->hasAttr<OpenCLKernelAttr>()) { |
| 2826 | // OpenCL __kernel functions get a kernel calling convention |
Peter Collingbourne | 744d90b | 2011-10-06 16:49:54 +0000 | [diff] [blame] | 2827 | F->setCallingConv(llvm::CallingConv::PTX_Kernel); |
Justin Holewinski | 818eafb | 2011-10-05 17:58:44 +0000 | [diff] [blame] | 2828 | // And kernel functions are not subject to inlining |
| 2829 | F->addFnAttr(llvm::Attribute::NoInline); |
| 2830 | } |
Peter Collingbourne | 744d90b | 2011-10-06 16:49:54 +0000 | [diff] [blame] | 2831 | } |
Justin Holewinski | 818eafb | 2011-10-05 17:58:44 +0000 | [diff] [blame] | 2832 | |
Peter Collingbourne | 744d90b | 2011-10-06 16:49:54 +0000 | [diff] [blame] | 2833 | // Perform special handling in CUDA mode. |
| 2834 | if (M.getLangOptions().CUDA) { |
| 2835 | // CUDA __global__ functions get a kernel calling convention. Since |
| 2836 | // __global__ functions cannot be called from the device, we do not |
| 2837 | // need to set the noinline attribute. |
| 2838 | if (FD->getAttr<CUDAGlobalAttr>()) |
| 2839 | F->setCallingConv(llvm::CallingConv::PTX_Kernel); |
Justin Holewinski | 818eafb | 2011-10-05 17:58:44 +0000 | [diff] [blame] | 2840 | } |
| 2841 | } |
| 2842 | |
Justin Holewinski | 0259c3a | 2011-04-22 11:10:38 +0000 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | //===----------------------------------------------------------------------===// |
Wesley Peck | 276fdf4 | 2010-12-19 19:57:51 +0000 | [diff] [blame] | 2846 | // MBlaze ABI Implementation |
| 2847 | //===----------------------------------------------------------------------===// |
| 2848 | |
| 2849 | namespace { |
| 2850 | |
| 2851 | class MBlazeABIInfo : public ABIInfo { |
| 2852 | public: |
| 2853 | MBlazeABIInfo(CodeGenTypes &CGT) : ABIInfo(CGT) {} |
| 2854 | |
| 2855 | bool isPromotableIntegerType(QualType Ty) const; |
| 2856 | |
| 2857 | ABIArgInfo classifyReturnType(QualType RetTy) const; |
| 2858 | ABIArgInfo classifyArgumentType(QualType RetTy) const; |
| 2859 | |
| 2860 | virtual void computeInfo(CGFunctionInfo &FI) const { |
| 2861 | FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); |
| 2862 | for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end(); |
| 2863 | it != ie; ++it) |
| 2864 | it->info = classifyArgumentType(it->type); |
| 2865 | } |
| 2866 | |
| 2867 | virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 2868 | CodeGenFunction &CGF) const; |
| 2869 | }; |
| 2870 | |
| 2871 | class MBlazeTargetCodeGenInfo : public TargetCodeGenInfo { |
| 2872 | public: |
| 2873 | MBlazeTargetCodeGenInfo(CodeGenTypes &CGT) |
| 2874 | : TargetCodeGenInfo(new MBlazeABIInfo(CGT)) {} |
| 2875 | void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV, |
| 2876 | CodeGen::CodeGenModule &M) const; |
| 2877 | }; |
| 2878 | |
| 2879 | } |
| 2880 | |
| 2881 | bool MBlazeABIInfo::isPromotableIntegerType(QualType Ty) const { |
| 2882 | // MBlaze ABI requires all 8 and 16 bit quantities to be extended. |
| 2883 | if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) |
| 2884 | switch (BT->getKind()) { |
| 2885 | case BuiltinType::Bool: |
| 2886 | case BuiltinType::Char_S: |
| 2887 | case BuiltinType::Char_U: |
| 2888 | case BuiltinType::SChar: |
| 2889 | case BuiltinType::UChar: |
| 2890 | case BuiltinType::Short: |
| 2891 | case BuiltinType::UShort: |
| 2892 | return true; |
| 2893 | default: |
| 2894 | return false; |
| 2895 | } |
| 2896 | return false; |
| 2897 | } |
| 2898 | |
| 2899 | llvm::Value *MBlazeABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 2900 | CodeGenFunction &CGF) const { |
| 2901 | // FIXME: Implement |
| 2902 | return 0; |
| 2903 | } |
| 2904 | |
| 2905 | |
| 2906 | ABIArgInfo MBlazeABIInfo::classifyReturnType(QualType RetTy) const { |
| 2907 | if (RetTy->isVoidType()) |
| 2908 | return ABIArgInfo::getIgnore(); |
| 2909 | if (isAggregateTypeForABI(RetTy)) |
| 2910 | return ABIArgInfo::getIndirect(0); |
| 2911 | |
| 2912 | return (isPromotableIntegerType(RetTy) ? |
| 2913 | ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
| 2914 | } |
| 2915 | |
| 2916 | ABIArgInfo MBlazeABIInfo::classifyArgumentType(QualType Ty) const { |
| 2917 | if (isAggregateTypeForABI(Ty)) |
| 2918 | return ABIArgInfo::getIndirect(0); |
| 2919 | |
| 2920 | return (isPromotableIntegerType(Ty) ? |
| 2921 | ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
| 2922 | } |
| 2923 | |
| 2924 | void MBlazeTargetCodeGenInfo::SetTargetAttributes(const Decl *D, |
| 2925 | llvm::GlobalValue *GV, |
| 2926 | CodeGen::CodeGenModule &M) |
| 2927 | const { |
| 2928 | const FunctionDecl *FD = dyn_cast<FunctionDecl>(D); |
| 2929 | if (!FD) return; |
NAKAMURA Takumi | 125b4cb | 2011-02-17 08:50:50 +0000 | [diff] [blame] | 2930 | |
Wesley Peck | 276fdf4 | 2010-12-19 19:57:51 +0000 | [diff] [blame] | 2931 | llvm::CallingConv::ID CC = llvm::CallingConv::C; |
| 2932 | if (FD->hasAttr<MBlazeInterruptHandlerAttr>()) |
| 2933 | CC = llvm::CallingConv::MBLAZE_INTR; |
| 2934 | else if (FD->hasAttr<MBlazeSaveVolatilesAttr>()) |
| 2935 | CC = llvm::CallingConv::MBLAZE_SVOL; |
| 2936 | |
| 2937 | if (CC != llvm::CallingConv::C) { |
| 2938 | // Handle 'interrupt_handler' attribute: |
| 2939 | llvm::Function *F = cast<llvm::Function>(GV); |
| 2940 | |
| 2941 | // Step 1: Set ISR calling convention. |
| 2942 | F->setCallingConv(CC); |
| 2943 | |
| 2944 | // Step 2: Add attributes goodness. |
| 2945 | F->addFnAttr(llvm::Attribute::NoInline); |
| 2946 | } |
| 2947 | |
| 2948 | // Step 3: Emit _interrupt_handler alias. |
| 2949 | if (CC == llvm::CallingConv::MBLAZE_INTR) |
| 2950 | new llvm::GlobalAlias(GV->getType(), llvm::Function::ExternalLinkage, |
| 2951 | "_interrupt_handler", GV, &M.getModule()); |
| 2952 | } |
| 2953 | |
| 2954 | |
| 2955 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 2956 | // MSP430 ABI Implementation |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 2957 | //===----------------------------------------------------------------------===// |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 2958 | |
| 2959 | namespace { |
| 2960 | |
| 2961 | class MSP430TargetCodeGenInfo : public TargetCodeGenInfo { |
| 2962 | public: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 2963 | MSP430TargetCodeGenInfo(CodeGenTypes &CGT) |
| 2964 | : TargetCodeGenInfo(new DefaultABIInfo(CGT)) {} |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 2965 | void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV, |
| 2966 | CodeGen::CodeGenModule &M) const; |
| 2967 | }; |
| 2968 | |
| 2969 | } |
| 2970 | |
| 2971 | void MSP430TargetCodeGenInfo::SetTargetAttributes(const Decl *D, |
| 2972 | llvm::GlobalValue *GV, |
| 2973 | CodeGen::CodeGenModule &M) const { |
| 2974 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 2975 | if (const MSP430InterruptAttr *attr = FD->getAttr<MSP430InterruptAttr>()) { |
| 2976 | // Handle 'interrupt' attribute: |
| 2977 | llvm::Function *F = cast<llvm::Function>(GV); |
| 2978 | |
| 2979 | // Step 1: Set ISR calling convention. |
| 2980 | F->setCallingConv(llvm::CallingConv::MSP430_INTR); |
| 2981 | |
| 2982 | // Step 2: Add attributes goodness. |
| 2983 | F->addFnAttr(llvm::Attribute::NoInline); |
| 2984 | |
| 2985 | // Step 3: Emit ISR vector alias. |
| 2986 | unsigned Num = attr->getNumber() + 0xffe0; |
| 2987 | new llvm::GlobalAlias(GV->getType(), llvm::Function::ExternalLinkage, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2988 | "vector_" + Twine::utohexstr(Num), |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 2989 | GV, &M.getModule()); |
| 2990 | } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 2991 | } |
| 2992 | } |
| 2993 | |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 2994 | //===----------------------------------------------------------------------===// |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 2995 | // MIPS ABI Implementation. This works for both little-endian and |
| 2996 | // big-endian variants. |
Chris Lattner | dce5ad0 | 2010-06-28 20:05:43 +0000 | [diff] [blame] | 2997 | //===----------------------------------------------------------------------===// |
| 2998 | |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 2999 | namespace { |
Akira Hatanaka | 619e887 | 2011-06-02 00:09:17 +0000 | [diff] [blame] | 3000 | class MipsABIInfo : public ABIInfo { |
Akira Hatanaka | c0e3b66 | 2011-11-02 23:14:57 +0000 | [diff] [blame] | 3001 | bool IsO32; |
Akira Hatanaka | b551dd3 | 2011-11-03 00:05:50 +0000 | [diff] [blame] | 3002 | unsigned MinABIStackAlignInBytes; |
Akira Hatanaka | d5a257f | 2011-11-02 23:54:49 +0000 | [diff] [blame] | 3003 | llvm::Type* HandleStructTy(QualType Ty) const; |
Akira Hatanaka | 619e887 | 2011-06-02 00:09:17 +0000 | [diff] [blame] | 3004 | public: |
Akira Hatanaka | b551dd3 | 2011-11-03 00:05:50 +0000 | [diff] [blame] | 3005 | MipsABIInfo(CodeGenTypes &CGT, bool _IsO32) : |
| 3006 | ABIInfo(CGT), IsO32(_IsO32), MinABIStackAlignInBytes(IsO32 ? 4 : 8) {} |
Akira Hatanaka | 619e887 | 2011-06-02 00:09:17 +0000 | [diff] [blame] | 3007 | |
| 3008 | ABIArgInfo classifyReturnType(QualType RetTy) const; |
| 3009 | ABIArgInfo classifyArgumentType(QualType RetTy) const; |
| 3010 | virtual void computeInfo(CGFunctionInfo &FI) const; |
| 3011 | virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 3012 | CodeGenFunction &CGF) const; |
| 3013 | }; |
| 3014 | |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 3015 | class MIPSTargetCodeGenInfo : public TargetCodeGenInfo { |
Akira Hatanaka | e624fa0 | 2011-09-20 18:23:28 +0000 | [diff] [blame] | 3016 | unsigned SizeOfUnwindException; |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 3017 | public: |
Akira Hatanaka | c0e3b66 | 2011-11-02 23:14:57 +0000 | [diff] [blame] | 3018 | MIPSTargetCodeGenInfo(CodeGenTypes &CGT, bool IsO32) |
| 3019 | : TargetCodeGenInfo(new MipsABIInfo(CGT, IsO32)), |
| 3020 | SizeOfUnwindException(IsO32 ? 24 : 32) {} |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 3021 | |
| 3022 | int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const { |
| 3023 | return 29; |
| 3024 | } |
| 3025 | |
| 3026 | bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, |
Michael J. Spencer | 8bea82f | 2010-08-25 18:17:27 +0000 | [diff] [blame] | 3027 | llvm::Value *Address) const; |
John McCall | 49e34be | 2011-08-30 01:42:09 +0000 | [diff] [blame] | 3028 | |
| 3029 | unsigned getSizeOfUnwindException() const { |
Akira Hatanaka | e624fa0 | 2011-09-20 18:23:28 +0000 | [diff] [blame] | 3030 | return SizeOfUnwindException; |
John McCall | 49e34be | 2011-08-30 01:42:09 +0000 | [diff] [blame] | 3031 | } |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 3032 | }; |
| 3033 | } |
| 3034 | |
Akira Hatanaka | d5a257f | 2011-11-02 23:54:49 +0000 | [diff] [blame] | 3035 | // In N32/64, an aligned double precision floating point field is passed in |
| 3036 | // a register. |
| 3037 | llvm::Type* MipsABIInfo::HandleStructTy(QualType Ty) const { |
| 3038 | if (IsO32) |
| 3039 | return 0; |
| 3040 | |
| 3041 | const RecordType *RT = Ty->getAsStructureType(); |
| 3042 | |
| 3043 | if (!RT) |
| 3044 | return 0; |
| 3045 | |
| 3046 | const RecordDecl *RD = RT->getDecl(); |
| 3047 | const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD); |
| 3048 | uint64_t StructSize = getContext().getTypeSize(Ty); |
| 3049 | assert(!(StructSize % 8) && "Size of structure must be multiple of 8."); |
| 3050 | |
| 3051 | SmallVector<llvm::Type*, 8> ArgList; |
| 3052 | uint64_t LastOffset = 0; |
| 3053 | unsigned idx = 0; |
| 3054 | llvm::IntegerType *I64 = llvm::IntegerType::get(getVMContext(), 64); |
| 3055 | |
| 3056 | for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end(); |
| 3057 | i != e; ++i, ++idx) { |
| 3058 | const QualType Ty = (*i)->getType(); |
| 3059 | const BuiltinType *BT = Ty->getAs<BuiltinType>(); |
| 3060 | |
| 3061 | if (!BT || BT->getKind() != BuiltinType::Double) |
| 3062 | continue; |
| 3063 | |
| 3064 | uint64_t Offset = Layout.getFieldOffset(idx); |
| 3065 | if (Offset % 64) // Ignore doubles that are not aligned. |
| 3066 | continue; |
| 3067 | |
| 3068 | // Add ((Offset - LastOffset) / 64) args of type i64. |
| 3069 | for (unsigned j = (Offset - LastOffset) / 64; j > 0; --j) |
| 3070 | ArgList.push_back(I64); |
| 3071 | |
| 3072 | // Add double type. |
| 3073 | ArgList.push_back(llvm::Type::getDoubleTy(getVMContext())); |
| 3074 | LastOffset = Offset + 64; |
| 3075 | } |
| 3076 | |
| 3077 | // This structure doesn't have an aligned double field. |
| 3078 | if (!LastOffset) |
| 3079 | return 0; |
| 3080 | |
| 3081 | // Add ((StructSize - LastOffset) / 64) args of type i64. |
| 3082 | for (unsigned N = (StructSize - LastOffset) / 64; N; --N) |
| 3083 | ArgList.push_back(I64); |
| 3084 | |
| 3085 | // Whatever is left over goes into a structure consisting of sub-doubleword |
| 3086 | // types. For example, if the size of the remainder is 40-bytes, |
| 3087 | // struct {i32, i8} is added to ArgList. |
| 3088 | unsigned R = (StructSize - LastOffset) % 64; |
| 3089 | SmallVector<llvm::Type*, 3> ArgList2; |
| 3090 | |
| 3091 | for (; R; R &= (R - 1)) |
| 3092 | ArgList2.insert(ArgList2.begin(), |
| 3093 | llvm::IntegerType::get(getVMContext(), (R & (R - 1)) ^ R)); |
| 3094 | |
| 3095 | if (!ArgList2.empty()) |
| 3096 | ArgList.push_back(llvm::StructType::get(getVMContext(), ArgList2)); |
| 3097 | |
| 3098 | return llvm::StructType::get(getVMContext(), ArgList); |
| 3099 | } |
| 3100 | |
Akira Hatanaka | 619e887 | 2011-06-02 00:09:17 +0000 | [diff] [blame] | 3101 | ABIArgInfo MipsABIInfo::classifyArgumentType(QualType Ty) const { |
| 3102 | if (isAggregateTypeForABI(Ty)) { |
| 3103 | // Ignore empty aggregates. |
| 3104 | if (getContext().getTypeSize(Ty) == 0) |
| 3105 | return ABIArgInfo::getIgnore(); |
| 3106 | |
Akira Hatanaka | 511949b | 2011-08-01 18:09:58 +0000 | [diff] [blame] | 3107 | // Records with non trivial destructors/constructors should not be passed |
| 3108 | // by value. |
| 3109 | if (isRecordWithNonTrivialDestructorOrCopyConstructor(Ty)) |
| 3110 | return ABIArgInfo::getIndirect(0, /*ByVal=*/false); |
| 3111 | |
Akira Hatanaka | d5a257f | 2011-11-02 23:54:49 +0000 | [diff] [blame] | 3112 | llvm::Type *ResType; |
| 3113 | if ((ResType = HandleStructTy(Ty))) |
| 3114 | return ABIArgInfo::getDirect(ResType); |
| 3115 | |
Akira Hatanaka | 619e887 | 2011-06-02 00:09:17 +0000 | [diff] [blame] | 3116 | return ABIArgInfo::getIndirect(0); |
| 3117 | } |
| 3118 | |
| 3119 | // Treat an enum type as its underlying type. |
| 3120 | if (const EnumType *EnumTy = Ty->getAs<EnumType>()) |
| 3121 | Ty = EnumTy->getDecl()->getIntegerType(); |
| 3122 | |
| 3123 | return (Ty->isPromotableIntegerType() ? |
| 3124 | ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
| 3125 | } |
| 3126 | |
| 3127 | ABIArgInfo MipsABIInfo::classifyReturnType(QualType RetTy) const { |
| 3128 | if (RetTy->isVoidType()) |
| 3129 | return ABIArgInfo::getIgnore(); |
| 3130 | |
| 3131 | if (isAggregateTypeForABI(RetTy)) { |
Akira Hatanaka | c0e3b66 | 2011-11-02 23:14:57 +0000 | [diff] [blame] | 3132 | if ((IsO32 && RetTy->isAnyComplexType()) || |
| 3133 | (!IsO32 && (getContext().getTypeSize(RetTy) <= 128))) |
Akira Hatanaka | 619e887 | 2011-06-02 00:09:17 +0000 | [diff] [blame] | 3134 | return ABIArgInfo::getDirect(); |
| 3135 | |
| 3136 | return ABIArgInfo::getIndirect(0); |
| 3137 | } |
| 3138 | |
| 3139 | // Treat an enum type as its underlying type. |
| 3140 | if (const EnumType *EnumTy = RetTy->getAs<EnumType>()) |
| 3141 | RetTy = EnumTy->getDecl()->getIntegerType(); |
| 3142 | |
| 3143 | return (RetTy->isPromotableIntegerType() ? |
| 3144 | ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); |
| 3145 | } |
| 3146 | |
| 3147 | void MipsABIInfo::computeInfo(CGFunctionInfo &FI) const { |
| 3148 | FI.getReturnInfo() = classifyReturnType(FI.getReturnType()); |
| 3149 | for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end(); |
| 3150 | it != ie; ++it) |
| 3151 | it->info = classifyArgumentType(it->type); |
| 3152 | } |
| 3153 | |
| 3154 | llvm::Value* MipsABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty, |
| 3155 | CodeGenFunction &CGF) const { |
Akira Hatanaka | c35e69d | 2011-08-01 20:48:01 +0000 | [diff] [blame] | 3156 | llvm::Type *BP = llvm::Type::getInt8PtrTy(CGF.getLLVMContext()); |
| 3157 | llvm::Type *BPP = llvm::PointerType::getUnqual(BP); |
| 3158 | |
| 3159 | CGBuilderTy &Builder = CGF.Builder; |
| 3160 | llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP, "ap"); |
| 3161 | llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur"); |
| 3162 | unsigned TypeAlign = getContext().getTypeAlign(Ty) / 8; |
| 3163 | llvm::Type *PTy = llvm::PointerType::getUnqual(CGF.ConvertType(Ty)); |
| 3164 | llvm::Value *AddrTyped; |
| 3165 | |
| 3166 | if (TypeAlign > MinABIStackAlignInBytes) { |
| 3167 | llvm::Value *AddrAsInt32 = CGF.Builder.CreatePtrToInt(Addr, CGF.Int32Ty); |
| 3168 | llvm::Value *Inc = llvm::ConstantInt::get(CGF.Int32Ty, TypeAlign - 1); |
| 3169 | llvm::Value *Mask = llvm::ConstantInt::get(CGF.Int32Ty, -TypeAlign); |
| 3170 | llvm::Value *Add = CGF.Builder.CreateAdd(AddrAsInt32, Inc); |
| 3171 | llvm::Value *And = CGF.Builder.CreateAnd(Add, Mask); |
| 3172 | AddrTyped = CGF.Builder.CreateIntToPtr(And, PTy); |
| 3173 | } |
| 3174 | else |
| 3175 | AddrTyped = Builder.CreateBitCast(Addr, PTy); |
| 3176 | |
| 3177 | llvm::Value *AlignedAddr = Builder.CreateBitCast(AddrTyped, BP); |
Akira Hatanaka | 7b0a038 | 2011-08-12 02:30:14 +0000 | [diff] [blame] | 3178 | TypeAlign = std::max(TypeAlign, MinABIStackAlignInBytes); |
Akira Hatanaka | c35e69d | 2011-08-01 20:48:01 +0000 | [diff] [blame] | 3179 | uint64_t Offset = |
| 3180 | llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, TypeAlign); |
| 3181 | llvm::Value *NextAddr = |
| 3182 | Builder.CreateGEP(AlignedAddr, llvm::ConstantInt::get(CGF.Int32Ty, Offset), |
| 3183 | "ap.next"); |
| 3184 | Builder.CreateStore(NextAddr, VAListAddrAsBPP); |
| 3185 | |
| 3186 | return AddrTyped; |
Akira Hatanaka | 619e887 | 2011-06-02 00:09:17 +0000 | [diff] [blame] | 3187 | } |
| 3188 | |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 3189 | bool |
| 3190 | MIPSTargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF, |
| 3191 | llvm::Value *Address) const { |
| 3192 | // This information comes from gcc's implementation, which seems to |
| 3193 | // as canonical as it gets. |
| 3194 | |
| 3195 | CodeGen::CGBuilderTy &Builder = CGF.Builder; |
| 3196 | llvm::LLVMContext &Context = CGF.getLLVMContext(); |
| 3197 | |
| 3198 | // Everything on MIPS is 4 bytes. Double-precision FP registers |
| 3199 | // are aliased to pairs of single-precision FP registers. |
Chris Lattner | 2acc6e3 | 2011-07-18 04:24:23 +0000 | [diff] [blame] | 3200 | llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context); |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 3201 | llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4); |
| 3202 | |
| 3203 | // 0-31 are the general purpose registers, $0 - $31. |
| 3204 | // 32-63 are the floating-point registers, $f0 - $f31. |
| 3205 | // 64 and 65 are the multiply/divide registers, $hi and $lo. |
| 3206 | // 66 is the (notional, I think) register for signal-handler return. |
| 3207 | AssignToArrayRange(Builder, Address, Four8, 0, 65); |
| 3208 | |
| 3209 | // 67-74 are the floating-point status registers, $fcc0 - $fcc7. |
| 3210 | // They are one bit wide and ignored here. |
| 3211 | |
| 3212 | // 80-111 are the coprocessor 0 registers, $c0r0 - $c0r31. |
| 3213 | // (coprocessor 1 is the FP unit) |
| 3214 | // 112-143 are the coprocessor 2 registers, $c2r0 - $c2r31. |
| 3215 | // 144-175 are the coprocessor 3 registers, $c3r0 - $c3r31. |
| 3216 | // 176-181 are the DSP accumulator registers. |
| 3217 | AssignToArrayRange(Builder, Address, Four8, 80, 181); |
| 3218 | |
| 3219 | return false; |
| 3220 | } |
| 3221 | |
Peter Collingbourne | 2f7aa99 | 2011-10-13 16:24:41 +0000 | [diff] [blame] | 3222 | //===----------------------------------------------------------------------===// |
| 3223 | // TCE ABI Implementation (see http://tce.cs.tut.fi). Uses mostly the defaults. |
| 3224 | // Currently subclassed only to implement custom OpenCL C function attribute |
| 3225 | // handling. |
| 3226 | //===----------------------------------------------------------------------===// |
| 3227 | |
| 3228 | namespace { |
| 3229 | |
| 3230 | class TCETargetCodeGenInfo : public DefaultTargetCodeGenInfo { |
| 3231 | public: |
| 3232 | TCETargetCodeGenInfo(CodeGenTypes &CGT) |
| 3233 | : DefaultTargetCodeGenInfo(CGT) {} |
| 3234 | |
| 3235 | virtual void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV, |
| 3236 | CodeGen::CodeGenModule &M) const; |
| 3237 | }; |
| 3238 | |
| 3239 | void TCETargetCodeGenInfo::SetTargetAttributes(const Decl *D, |
| 3240 | llvm::GlobalValue *GV, |
| 3241 | CodeGen::CodeGenModule &M) const { |
| 3242 | const FunctionDecl *FD = dyn_cast<FunctionDecl>(D); |
| 3243 | if (!FD) return; |
| 3244 | |
| 3245 | llvm::Function *F = cast<llvm::Function>(GV); |
| 3246 | |
| 3247 | if (M.getLangOptions().OpenCL) { |
| 3248 | if (FD->hasAttr<OpenCLKernelAttr>()) { |
| 3249 | // OpenCL C Kernel functions are not subject to inlining |
| 3250 | F->addFnAttr(llvm::Attribute::NoInline); |
| 3251 | |
| 3252 | if (FD->hasAttr<ReqdWorkGroupSizeAttr>()) { |
| 3253 | |
| 3254 | // Convert the reqd_work_group_size() attributes to metadata. |
| 3255 | llvm::LLVMContext &Context = F->getContext(); |
| 3256 | llvm::NamedMDNode *OpenCLMetadata = |
| 3257 | M.getModule().getOrInsertNamedMetadata("opencl.kernel_wg_size_info"); |
| 3258 | |
| 3259 | SmallVector<llvm::Value*, 5> Operands; |
| 3260 | Operands.push_back(F); |
| 3261 | |
| 3262 | Operands.push_back(llvm::Constant::getIntegerValue( |
| 3263 | llvm::Type::getInt32Ty(Context), |
| 3264 | llvm::APInt( |
| 3265 | 32, |
| 3266 | FD->getAttr<ReqdWorkGroupSizeAttr>()->getXDim()))); |
| 3267 | Operands.push_back(llvm::Constant::getIntegerValue( |
| 3268 | llvm::Type::getInt32Ty(Context), |
| 3269 | llvm::APInt( |
| 3270 | 32, |
| 3271 | FD->getAttr<ReqdWorkGroupSizeAttr>()->getYDim()))); |
| 3272 | Operands.push_back(llvm::Constant::getIntegerValue( |
| 3273 | llvm::Type::getInt32Ty(Context), |
| 3274 | llvm::APInt( |
| 3275 | 32, |
| 3276 | FD->getAttr<ReqdWorkGroupSizeAttr>()->getZDim()))); |
| 3277 | |
| 3278 | // Add a boolean constant operand for "required" (true) or "hint" (false) |
| 3279 | // for implementing the work_group_size_hint attr later. Currently |
| 3280 | // always true as the hint is not yet implemented. |
| 3281 | Operands.push_back(llvm::ConstantInt::getTrue(llvm::Type::getInt1Ty(Context))); |
| 3282 | |
| 3283 | OpenCLMetadata->addOperand(llvm::MDNode::get(Context, Operands)); |
| 3284 | } |
| 3285 | } |
| 3286 | } |
| 3287 | } |
| 3288 | |
| 3289 | } |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 3290 | |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 3291 | const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() { |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 3292 | if (TheTargetCodeGenInfo) |
| 3293 | return *TheTargetCodeGenInfo; |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 3294 | |
Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 3295 | const llvm::Triple &Triple = getContext().getTargetInfo().getTriple(); |
Daniel Dunbar | 1752ee4 | 2009-08-24 09:10:05 +0000 | [diff] [blame] | 3296 | switch (Triple.getArch()) { |
Daniel Dunbar | 2c0843f | 2009-08-24 08:52:16 +0000 | [diff] [blame] | 3297 | default: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 3298 | return *(TheTargetCodeGenInfo = new DefaultTargetCodeGenInfo(Types)); |
Daniel Dunbar | 2c0843f | 2009-08-24 08:52:16 +0000 | [diff] [blame] | 3299 | |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 3300 | case llvm::Triple::mips: |
| 3301 | case llvm::Triple::mipsel: |
Akira Hatanaka | c0e3b66 | 2011-11-02 23:14:57 +0000 | [diff] [blame] | 3302 | return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types, true)); |
John McCall | aeeb701 | 2010-05-27 06:19:26 +0000 | [diff] [blame] | 3303 | |
Akira Hatanaka | 8c6dfbe | 2011-09-20 18:30:57 +0000 | [diff] [blame] | 3304 | case llvm::Triple::mips64: |
| 3305 | case llvm::Triple::mips64el: |
Akira Hatanaka | c0e3b66 | 2011-11-02 23:14:57 +0000 | [diff] [blame] | 3306 | return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo(Types, false)); |
Akira Hatanaka | 8c6dfbe | 2011-09-20 18:30:57 +0000 | [diff] [blame] | 3307 | |
Daniel Dunbar | 34d91fd | 2009-09-12 00:59:49 +0000 | [diff] [blame] | 3308 | case llvm::Triple::arm: |
| 3309 | case llvm::Triple::thumb: |
Sandeep Patel | 34c1af8 | 2011-04-05 00:23:47 +0000 | [diff] [blame] | 3310 | { |
| 3311 | ARMABIInfo::ABIKind Kind = ARMABIInfo::AAPCS; |
Daniel Dunbar | 5e7bace | 2009-09-12 01:00:39 +0000 | [diff] [blame] | 3312 | |
Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 3313 | if (strcmp(getContext().getTargetInfo().getABI(), "apcs-gnu") == 0) |
Sandeep Patel | 34c1af8 | 2011-04-05 00:23:47 +0000 | [diff] [blame] | 3314 | Kind = ARMABIInfo::APCS; |
| 3315 | else if (CodeGenOpts.FloatABI == "hard") |
| 3316 | Kind = ARMABIInfo::AAPCS_VFP; |
| 3317 | |
| 3318 | return *(TheTargetCodeGenInfo = new ARMTargetCodeGenInfo(Types, Kind)); |
| 3319 | } |
Daniel Dunbar | 34d91fd | 2009-09-12 00:59:49 +0000 | [diff] [blame] | 3320 | |
John McCall | ec853ba | 2010-03-11 00:10:12 +0000 | [diff] [blame] | 3321 | case llvm::Triple::ppc: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 3322 | return *(TheTargetCodeGenInfo = new PPC32TargetCodeGenInfo(Types)); |
John McCall | ec853ba | 2010-03-11 00:10:12 +0000 | [diff] [blame] | 3323 | |
Justin Holewinski | 0259c3a | 2011-04-22 11:10:38 +0000 | [diff] [blame] | 3324 | case llvm::Triple::ptx32: |
| 3325 | case llvm::Triple::ptx64: |
| 3326 | return *(TheTargetCodeGenInfo = new PTXTargetCodeGenInfo(Types)); |
| 3327 | |
Wesley Peck | 276fdf4 | 2010-12-19 19:57:51 +0000 | [diff] [blame] | 3328 | case llvm::Triple::mblaze: |
| 3329 | return *(TheTargetCodeGenInfo = new MBlazeTargetCodeGenInfo(Types)); |
| 3330 | |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 3331 | case llvm::Triple::msp430: |
Chris Lattner | ea04432 | 2010-07-29 02:01:43 +0000 | [diff] [blame] | 3332 | return *(TheTargetCodeGenInfo = new MSP430TargetCodeGenInfo(Types)); |
Daniel Dunbar | 34d91fd | 2009-09-12 00:59:49 +0000 | [diff] [blame] | 3333 | |
Peter Collingbourne | 2f7aa99 | 2011-10-13 16:24:41 +0000 | [diff] [blame] | 3334 | case llvm::Triple::tce: |
| 3335 | return *(TheTargetCodeGenInfo = new TCETargetCodeGenInfo(Types)); |
| 3336 | |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 3337 | case llvm::Triple::x86: { |
Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 3338 | bool DisableMMX = strcmp(getContext().getTargetInfo().getABI(), "no-mmx") == 0; |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 3339 | |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 3340 | if (Triple.isOSDarwin()) |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 3341 | return *(TheTargetCodeGenInfo = |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 3342 | new X86_32TargetCodeGenInfo(Types, true, true, DisableMMX)); |
Daniel Dunbar | db57a4c | 2011-04-19 21:43:27 +0000 | [diff] [blame] | 3343 | |
| 3344 | switch (Triple.getOS()) { |
Daniel Dunbar | 2c0843f | 2009-08-24 08:52:16 +0000 | [diff] [blame] | 3345 | case llvm::Triple::Cygwin: |
Daniel Dunbar | 2c0843f | 2009-08-24 08:52:16 +0000 | [diff] [blame] | 3346 | case llvm::Triple::MinGW32: |
Edward O'Callaghan | 727e268 | 2009-10-21 11:58:24 +0000 | [diff] [blame] | 3347 | case llvm::Triple::AuroraUX: |
| 3348 | case llvm::Triple::DragonFly: |
David Chisnall | 75c135a | 2009-09-03 01:48:05 +0000 | [diff] [blame] | 3349 | case llvm::Triple::FreeBSD: |
Daniel Dunbar | 2c0843f | 2009-08-24 08:52:16 +0000 | [diff] [blame] | 3350 | case llvm::Triple::OpenBSD: |
Benjamin Kramer | 8e50a96 | 2011-02-02 18:59:27 +0000 | [diff] [blame] | 3351 | case llvm::Triple::NetBSD: |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 3352 | return *(TheTargetCodeGenInfo = |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 3353 | new X86_32TargetCodeGenInfo(Types, false, true, DisableMMX)); |
Daniel Dunbar | 2c0843f | 2009-08-24 08:52:16 +0000 | [diff] [blame] | 3354 | |
| 3355 | default: |
Anton Korobeynikov | 82d0a41 | 2010-01-10 12:58:08 +0000 | [diff] [blame] | 3356 | return *(TheTargetCodeGenInfo = |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 3357 | new X86_32TargetCodeGenInfo(Types, false, false, DisableMMX)); |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 3358 | } |
Eli Friedman | c3e0fb4 | 2011-07-08 23:31:17 +0000 | [diff] [blame] | 3359 | } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 3360 | |
Daniel Dunbar | 2c0843f | 2009-08-24 08:52:16 +0000 | [diff] [blame] | 3361 | case llvm::Triple::x86_64: |
Chris Lattner | f13721d | 2010-08-31 16:44:54 +0000 | [diff] [blame] | 3362 | switch (Triple.getOS()) { |
| 3363 | case llvm::Triple::Win32: |
NAKAMURA Takumi | 0aa2057 | 2011-02-17 08:51:38 +0000 | [diff] [blame] | 3364 | case llvm::Triple::MinGW32: |
Chris Lattner | f13721d | 2010-08-31 16:44:54 +0000 | [diff] [blame] | 3365 | case llvm::Triple::Cygwin: |
| 3366 | return *(TheTargetCodeGenInfo = new WinX86_64TargetCodeGenInfo(Types)); |
| 3367 | default: |
| 3368 | return *(TheTargetCodeGenInfo = new X86_64TargetCodeGenInfo(Types)); |
| 3369 | } |
Daniel Dunbar | 2c0843f | 2009-08-24 08:52:16 +0000 | [diff] [blame] | 3370 | } |
Anton Korobeynikov | c4a59eb | 2009-06-05 22:08:42 +0000 | [diff] [blame] | 3371 | } |