blob: 010a42182135491bf89ee1787b54cb1b74997f75 [file] [log] [blame]
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001//===---- TargetABIInfo.cpp - Encapsulate target ABI details ----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// These classes wrap the information about a call or function
11// definition used to handle ABI compliancy.
12//
13//===----------------------------------------------------------------------===//
14
15#include "ABIInfo.h"
16#include "CodeGenFunction.h"
Anders Carlsson19cc4ab2009-07-18 19:43:29 +000017#include "clang/AST/RecordLayout.h"
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000018#include "llvm/Type.h"
Daniel Dunbar2c0843f2009-08-24 08:52:16 +000019#include "llvm/ADT/Triple.h"
Torok Edwinf42e4a62009-08-24 13:25:12 +000020#include <cstdio>
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000021
22using namespace clang;
23using namespace CodeGen;
24
25ABIInfo::~ABIInfo() {}
26
27void ABIArgInfo::dump() const {
28 fprintf(stderr, "(ABIArgInfo Kind=");
29 switch (TheKind) {
30 case Direct:
31 fprintf(stderr, "Direct");
32 break;
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +000033 case Extend:
34 fprintf(stderr, "Extend");
35 break;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000036 case Ignore:
37 fprintf(stderr, "Ignore");
38 break;
39 case Coerce:
40 fprintf(stderr, "Coerce Type=");
41 getCoerceToType()->print(llvm::errs());
42 break;
43 case Indirect:
44 fprintf(stderr, "Indirect Align=%d", getIndirectAlign());
45 break;
46 case Expand:
47 fprintf(stderr, "Expand");
48 break;
49 }
50 fprintf(stderr, ")\n");
51}
52
Daniel Dunbar98303b92009-09-13 08:03:58 +000053static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000054
55/// isEmptyField - Return true iff a the field is "empty", that is it
56/// is an unnamed bit-field or an (array of) empty record(s).
Daniel Dunbar98303b92009-09-13 08:03:58 +000057static bool isEmptyField(ASTContext &Context, const FieldDecl *FD,
58 bool AllowArrays) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000059 if (FD->isUnnamedBitfield())
60 return true;
61
62 QualType FT = FD->getType();
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000063
Daniel Dunbar98303b92009-09-13 08:03:58 +000064 // Constant arrays of empty records count as empty, strip them off.
65 if (AllowArrays)
66 while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT))
67 FT = AT->getElementType();
68
69 return isEmptyRecord(Context, FT, AllowArrays);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000070}
71
72/// isEmptyRecord - Return true iff a structure contains only empty
73/// fields. Note that a structure with a flexible array member is not
74/// considered empty.
Daniel Dunbar98303b92009-09-13 08:03:58 +000075static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays) {
Ted Kremenek6217b802009-07-29 21:53:49 +000076 const RecordType *RT = T->getAs<RecordType>();
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000077 if (!RT)
78 return 0;
79 const RecordDecl *RD = RT->getDecl();
80 if (RD->hasFlexibleArrayMember())
81 return false;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +000082 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
83 i != e; ++i)
Daniel Dunbar98303b92009-09-13 08:03:58 +000084 if (!isEmptyField(Context, *i, AllowArrays))
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000085 return false;
86 return true;
87}
88
Anders Carlsson0a8f8472009-09-16 15:53:40 +000089/// hasNonTrivialDestructorOrCopyConstructor - Determine if a type has either
90/// a non-trivial destructor or a non-trivial copy constructor.
91static bool hasNonTrivialDestructorOrCopyConstructor(const RecordType *RT) {
92 const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
93 if (!RD)
94 return false;
95
96 return !RD->hasTrivialDestructor() || !RD->hasTrivialCopyConstructor();
97}
98
99/// isRecordWithNonTrivialDestructorOrCopyConstructor - Determine if a type is
100/// a record type with either a non-trivial destructor or a non-trivial copy
101/// constructor.
102static bool isRecordWithNonTrivialDestructorOrCopyConstructor(QualType T) {
103 const RecordType *RT = T->getAs<RecordType>();
104 if (!RT)
105 return false;
106
107 return hasNonTrivialDestructorOrCopyConstructor(RT);
108}
109
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000110/// isSingleElementStruct - Determine if a structure is a "single
111/// element struct", i.e. it has exactly one non-empty field or
112/// exactly one field which is itself a single element
113/// struct. Structures with flexible array members are never
114/// considered single element structs.
115///
116/// \return The field declaration for the single non-empty field, if
117/// it exists.
118static const Type *isSingleElementStruct(QualType T, ASTContext &Context) {
119 const RecordType *RT = T->getAsStructureType();
120 if (!RT)
121 return 0;
122
123 const RecordDecl *RD = RT->getDecl();
124 if (RD->hasFlexibleArrayMember())
125 return 0;
126
127 const Type *Found = 0;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000128 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
129 i != e; ++i) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000130 const FieldDecl *FD = *i;
131 QualType FT = FD->getType();
132
133 // Ignore empty fields.
Daniel Dunbar98303b92009-09-13 08:03:58 +0000134 if (isEmptyField(Context, FD, true))
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000135 continue;
136
137 // If we already found an element then this isn't a single-element
138 // struct.
139 if (Found)
140 return 0;
141
142 // Treat single element arrays as the element.
143 while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT)) {
144 if (AT->getSize().getZExtValue() != 1)
145 break;
146 FT = AT->getElementType();
147 }
148
149 if (!CodeGenFunction::hasAggregateLLVMType(FT)) {
150 Found = FT.getTypePtr();
151 } else {
152 Found = isSingleElementStruct(FT, Context);
153 if (!Found)
154 return 0;
155 }
156 }
157
158 return Found;
159}
160
161static bool is32Or64BitBasicType(QualType Ty, ASTContext &Context) {
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000162 if (!Ty->getAs<BuiltinType>() && !Ty->isAnyPointerType() &&
163 !Ty->isAnyComplexType() && !Ty->isEnumeralType() &&
164 !Ty->isBlockPointerType())
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000165 return false;
166
167 uint64_t Size = Context.getTypeSize(Ty);
168 return Size == 32 || Size == 64;
169}
170
171static bool areAllFields32Or64BitBasicType(const RecordDecl *RD,
172 ASTContext &Context) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000173 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
174 i != e; ++i) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000175 const FieldDecl *FD = *i;
176
177 if (!is32Or64BitBasicType(FD->getType(), Context))
178 return false;
179
180 // FIXME: Reject bit-fields wholesale; there are two problems, we don't know
181 // how to expand them yet, and the predicate for telling if a bitfield still
182 // counts as "basic" is more complicated than what we were doing previously.
183 if (FD->isBitField())
184 return false;
185 }
186
187 return true;
188}
189
Eli Friedmana1e6de92009-06-13 21:37:10 +0000190static bool typeContainsSSEVector(const RecordDecl *RD, ASTContext &Context) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000191 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
192 i != e; ++i) {
Eli Friedmana1e6de92009-06-13 21:37:10 +0000193 const FieldDecl *FD = *i;
194
195 if (FD->getType()->isVectorType() &&
196 Context.getTypeSize(FD->getType()) >= 128)
197 return true;
198
Ted Kremenek6217b802009-07-29 21:53:49 +0000199 if (const RecordType* RT = FD->getType()->getAs<RecordType>())
Eli Friedmana1e6de92009-06-13 21:37:10 +0000200 if (typeContainsSSEVector(RT->getDecl(), Context))
201 return true;
202 }
203
204 return false;
205}
206
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000207namespace {
208/// DefaultABIInfo - The default implementation for ABI specific
209/// details. This implementation provides information which results in
210/// self-consistent and sensible LLVM IR generation, but does not
211/// conform to any particular ABI.
212class DefaultABIInfo : public ABIInfo {
213 ABIArgInfo classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000214 ASTContext &Context,
215 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000216
217 ABIArgInfo classifyArgumentType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000218 ASTContext &Context,
219 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000220
Owen Andersona1cf15f2009-07-14 23:10:40 +0000221 virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context,
222 llvm::LLVMContext &VMContext) const {
223 FI.getReturnInfo() = classifyReturnType(FI.getReturnType(), Context,
224 VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000225 for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
226 it != ie; ++it)
Owen Andersona1cf15f2009-07-14 23:10:40 +0000227 it->info = classifyArgumentType(it->type, Context, VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000228 }
229
230 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
231 CodeGenFunction &CGF) const;
232};
233
234/// X86_32ABIInfo - The X86-32 ABI information.
235class X86_32ABIInfo : public ABIInfo {
236 ASTContext &Context;
David Chisnall1e4249c2009-08-17 23:08:21 +0000237 bool IsDarwinVectorABI;
238 bool IsSmallStructInRegABI;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000239
240 static bool isRegisterSize(unsigned Size) {
241 return (Size == 8 || Size == 16 || Size == 32 || Size == 64);
242 }
243
244 static bool shouldReturnTypeInRegister(QualType Ty, ASTContext &Context);
245
Eli Friedmana1e6de92009-06-13 21:37:10 +0000246 static unsigned getIndirectArgumentAlignment(QualType Ty,
247 ASTContext &Context);
248
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000249public:
250 ABIArgInfo classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000251 ASTContext &Context,
252 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000253
254 ABIArgInfo classifyArgumentType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000255 ASTContext &Context,
256 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000257
Owen Andersona1cf15f2009-07-14 23:10:40 +0000258 virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context,
259 llvm::LLVMContext &VMContext) const {
260 FI.getReturnInfo() = classifyReturnType(FI.getReturnType(), Context,
261 VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000262 for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
263 it != ie; ++it)
Owen Andersona1cf15f2009-07-14 23:10:40 +0000264 it->info = classifyArgumentType(it->type, Context, VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000265 }
266
267 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
268 CodeGenFunction &CGF) const;
269
David Chisnall1e4249c2009-08-17 23:08:21 +0000270 X86_32ABIInfo(ASTContext &Context, bool d, bool p)
Mike Stump1eb44332009-09-09 15:08:12 +0000271 : ABIInfo(), Context(Context), IsDarwinVectorABI(d),
David Chisnall1e4249c2009-08-17 23:08:21 +0000272 IsSmallStructInRegABI(p) {}
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000273};
274}
275
276
277/// shouldReturnTypeInRegister - Determine if the given type should be
278/// passed in a register (for the Darwin ABI).
279bool X86_32ABIInfo::shouldReturnTypeInRegister(QualType Ty,
280 ASTContext &Context) {
281 uint64_t Size = Context.getTypeSize(Ty);
282
283 // Type must be register sized.
284 if (!isRegisterSize(Size))
285 return false;
286
287 if (Ty->isVectorType()) {
288 // 64- and 128- bit vectors inside structures are not returned in
289 // registers.
290 if (Size == 64 || Size == 128)
291 return false;
292
293 return true;
294 }
295
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000296 // If this is a builtin, pointer, enum, or complex type, it is ok.
297 if (Ty->getAs<BuiltinType>() || Ty->isAnyPointerType() ||
298 Ty->isAnyComplexType() || Ty->isEnumeralType() ||
299 Ty->isBlockPointerType())
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000300 return true;
301
302 // Arrays are treated like records.
303 if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty))
304 return shouldReturnTypeInRegister(AT->getElementType(), Context);
305
306 // Otherwise, it must be a record type.
Ted Kremenek6217b802009-07-29 21:53:49 +0000307 const RecordType *RT = Ty->getAs<RecordType>();
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000308 if (!RT) return false;
309
310 // Structure types are passed in register if all fields would be
311 // passed in a register.
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000312 for (RecordDecl::field_iterator i = RT->getDecl()->field_begin(),
313 e = RT->getDecl()->field_end(); i != e; ++i) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000314 const FieldDecl *FD = *i;
315
316 // Empty fields are ignored.
Daniel Dunbar98303b92009-09-13 08:03:58 +0000317 if (isEmptyField(Context, FD, true))
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000318 continue;
319
320 // Check fields recursively.
321 if (!shouldReturnTypeInRegister(FD->getType(), Context))
322 return false;
323 }
324
325 return true;
326}
327
328ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000329 ASTContext &Context,
330 llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000331 if (RetTy->isVoidType()) {
332 return ABIArgInfo::getIgnore();
John McCall183700f2009-09-21 23:43:11 +0000333 } else if (const VectorType *VT = RetTy->getAs<VectorType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000334 // On Darwin, some vectors are returned in registers.
David Chisnall1e4249c2009-08-17 23:08:21 +0000335 if (IsDarwinVectorABI) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000336 uint64_t Size = Context.getTypeSize(RetTy);
337
338 // 128-bit vectors are a special case; they are returned in
339 // registers and we need to make sure to pick a type the LLVM
340 // backend will like.
341 if (Size == 128)
Owen Anderson0032b272009-08-13 21:57:51 +0000342 return ABIArgInfo::getCoerce(llvm::VectorType::get(
343 llvm::Type::getInt64Ty(VMContext), 2));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000344
345 // Always return in register if it fits in a general purpose
346 // register, or if it is 64 bits and has a single element.
347 if ((Size == 8 || Size == 16 || Size == 32) ||
348 (Size == 64 && VT->getNumElements() == 1))
Owen Anderson0032b272009-08-13 21:57:51 +0000349 return ABIArgInfo::getCoerce(llvm::IntegerType::get(VMContext, Size));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000350
351 return ABIArgInfo::getIndirect(0);
352 }
353
354 return ABIArgInfo::getDirect();
355 } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
356 // Structures with flexible arrays are always indirect.
357 if (const RecordType *RT = RetTy->getAsStructureType())
358 if (RT->getDecl()->hasFlexibleArrayMember())
359 return ABIArgInfo::getIndirect(0);
360
David Chisnall1e4249c2009-08-17 23:08:21 +0000361 // If specified, structs and unions are always indirect.
362 if (!IsSmallStructInRegABI && !RetTy->isAnyComplexType())
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000363 return ABIArgInfo::getIndirect(0);
364
365 // Classify "single element" structs as their element type.
366 if (const Type *SeltTy = isSingleElementStruct(RetTy, Context)) {
John McCall183700f2009-09-21 23:43:11 +0000367 if (const BuiltinType *BT = SeltTy->getAs<BuiltinType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000368 if (BT->isIntegerType()) {
369 // We need to use the size of the structure, padding
370 // bit-fields can adjust that to be larger than the single
371 // element type.
372 uint64_t Size = Context.getTypeSize(RetTy);
Owen Andersona1cf15f2009-07-14 23:10:40 +0000373 return ABIArgInfo::getCoerce(
Owen Anderson0032b272009-08-13 21:57:51 +0000374 llvm::IntegerType::get(VMContext, (unsigned) Size));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000375 } else if (BT->getKind() == BuiltinType::Float) {
376 assert(Context.getTypeSize(RetTy) == Context.getTypeSize(SeltTy) &&
377 "Unexpect single element structure size!");
Owen Anderson0032b272009-08-13 21:57:51 +0000378 return ABIArgInfo::getCoerce(llvm::Type::getFloatTy(VMContext));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000379 } else if (BT->getKind() == BuiltinType::Double) {
380 assert(Context.getTypeSize(RetTy) == Context.getTypeSize(SeltTy) &&
381 "Unexpect single element structure size!");
Owen Anderson0032b272009-08-13 21:57:51 +0000382 return ABIArgInfo::getCoerce(llvm::Type::getDoubleTy(VMContext));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000383 }
384 } else if (SeltTy->isPointerType()) {
385 // FIXME: It would be really nice if this could come out as the proper
386 // pointer type.
387 llvm::Type *PtrTy =
Owen Anderson0032b272009-08-13 21:57:51 +0000388 llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000389 return ABIArgInfo::getCoerce(PtrTy);
390 } else if (SeltTy->isVectorType()) {
391 // 64- and 128-bit vectors are never returned in a
392 // register when inside a structure.
393 uint64_t Size = Context.getTypeSize(RetTy);
394 if (Size == 64 || Size == 128)
395 return ABIArgInfo::getIndirect(0);
396
Owen Andersona1cf15f2009-07-14 23:10:40 +0000397 return classifyReturnType(QualType(SeltTy, 0), Context, VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000398 }
399 }
400
401 // Small structures which are register sized are generally returned
402 // in a register.
403 if (X86_32ABIInfo::shouldReturnTypeInRegister(RetTy, Context)) {
404 uint64_t Size = Context.getTypeSize(RetTy);
Owen Anderson0032b272009-08-13 21:57:51 +0000405 return ABIArgInfo::getCoerce(llvm::IntegerType::get(VMContext, Size));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000406 }
407
408 return ABIArgInfo::getIndirect(0);
409 } else {
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000410 return (RetTy->isPromotableIntegerType() ?
411 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000412 }
413}
414
Eli Friedmana1e6de92009-06-13 21:37:10 +0000415unsigned X86_32ABIInfo::getIndirectArgumentAlignment(QualType Ty,
416 ASTContext &Context) {
417 unsigned Align = Context.getTypeAlign(Ty);
418 if (Align < 128) return 0;
Ted Kremenek6217b802009-07-29 21:53:49 +0000419 if (const RecordType* RT = Ty->getAs<RecordType>())
Eli Friedmana1e6de92009-06-13 21:37:10 +0000420 if (typeContainsSSEVector(RT->getDecl(), Context))
421 return 16;
422 return 0;
423}
424
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000425ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000426 ASTContext &Context,
427 llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000428 // FIXME: Set alignment on indirect arguments.
429 if (CodeGenFunction::hasAggregateLLVMType(Ty)) {
430 // Structures with flexible arrays are always indirect.
431 if (const RecordType *RT = Ty->getAsStructureType())
432 if (RT->getDecl()->hasFlexibleArrayMember())
Mike Stump1eb44332009-09-09 15:08:12 +0000433 return ABIArgInfo::getIndirect(getIndirectArgumentAlignment(Ty,
Eli Friedmana1e6de92009-06-13 21:37:10 +0000434 Context));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000435
436 // Ignore empty structs.
Eli Friedmana1e6de92009-06-13 21:37:10 +0000437 if (Ty->isStructureType() && Context.getTypeSize(Ty) == 0)
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000438 return ABIArgInfo::getIgnore();
439
440 // Expand structs with size <= 128-bits which consist only of
441 // basic types (int, long long, float, double, xxx*). This is
442 // non-recursive and does not ignore empty fields.
443 if (const RecordType *RT = Ty->getAsStructureType()) {
444 if (Context.getTypeSize(Ty) <= 4*32 &&
445 areAllFields32Or64BitBasicType(RT->getDecl(), Context))
446 return ABIArgInfo::getExpand();
447 }
448
Eli Friedmana1e6de92009-06-13 21:37:10 +0000449 return ABIArgInfo::getIndirect(getIndirectArgumentAlignment(Ty, Context));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000450 } else {
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000451 return (Ty->isPromotableIntegerType() ?
452 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000453 }
454}
455
456llvm::Value *X86_32ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
457 CodeGenFunction &CGF) const {
Owen Anderson0032b272009-08-13 21:57:51 +0000458 const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(CGF.getLLVMContext()));
Owen Anderson96e0fc72009-07-29 22:16:19 +0000459 const llvm::Type *BPP = llvm::PointerType::getUnqual(BP);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000460
461 CGBuilderTy &Builder = CGF.Builder;
462 llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP,
463 "ap");
464 llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
465 llvm::Type *PTy =
Owen Anderson96e0fc72009-07-29 22:16:19 +0000466 llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000467 llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
468
469 uint64_t Offset =
470 llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4);
471 llvm::Value *NextAddr =
Owen Anderson0032b272009-08-13 21:57:51 +0000472 Builder.CreateGEP(Addr, llvm::ConstantInt::get(
473 llvm::Type::getInt32Ty(CGF.getLLVMContext()), Offset),
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000474 "ap.next");
475 Builder.CreateStore(NextAddr, VAListAddrAsBPP);
476
477 return AddrTyped;
478}
479
480namespace {
481/// X86_64ABIInfo - The X86_64 ABI information.
482class X86_64ABIInfo : public ABIInfo {
483 enum Class {
484 Integer = 0,
485 SSE,
486 SSEUp,
487 X87,
488 X87Up,
489 ComplexX87,
490 NoClass,
491 Memory
492 };
493
494 /// merge - Implement the X86_64 ABI merging algorithm.
495 ///
496 /// Merge an accumulating classification \arg Accum with a field
497 /// classification \arg Field.
498 ///
499 /// \param Accum - The accumulating classification. This should
500 /// always be either NoClass or the result of a previous merge
501 /// call. In addition, this should never be Memory (the caller
502 /// should just return Memory for the aggregate).
503 Class merge(Class Accum, Class Field) const;
504
505 /// classify - Determine the x86_64 register classes in which the
506 /// given type T should be passed.
507 ///
508 /// \param Lo - The classification for the parts of the type
509 /// residing in the low word of the containing object.
510 ///
511 /// \param Hi - The classification for the parts of the type
512 /// residing in the high word of the containing object.
513 ///
514 /// \param OffsetBase - The bit offset of this type in the
515 /// containing object. Some parameters are classified different
516 /// depending on whether they straddle an eightbyte boundary.
517 ///
518 /// If a word is unused its result will be NoClass; if a type should
519 /// be passed in Memory then at least the classification of \arg Lo
520 /// will be Memory.
521 ///
522 /// The \arg Lo class will be NoClass iff the argument is ignored.
523 ///
524 /// If the \arg Lo class is ComplexX87, then the \arg Hi class will
525 /// also be ComplexX87.
526 void classify(QualType T, ASTContext &Context, uint64_t OffsetBase,
527 Class &Lo, Class &Hi) const;
528
529 /// getCoerceResult - Given a source type \arg Ty and an LLVM type
530 /// to coerce to, chose the best way to pass Ty in the same place
531 /// that \arg CoerceTo would be passed, but while keeping the
532 /// emitted code as simple as possible.
533 ///
534 /// FIXME: Note, this should be cleaned up to just take an enumeration of all
535 /// the ways we might want to pass things, instead of constructing an LLVM
536 /// type. This makes this code more explicit, and it makes it clearer that we
537 /// are also doing this for correctness in the case of passing scalar types.
538 ABIArgInfo getCoerceResult(QualType Ty,
539 const llvm::Type *CoerceTo,
540 ASTContext &Context) const;
541
542 /// getIndirectResult - Give a source type \arg Ty, return a suitable result
543 /// such that the argument will be passed in memory.
544 ABIArgInfo getIndirectResult(QualType Ty,
545 ASTContext &Context) const;
546
547 ABIArgInfo classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000548 ASTContext &Context,
549 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000550
551 ABIArgInfo classifyArgumentType(QualType Ty,
552 ASTContext &Context,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000553 llvm::LLVMContext &VMContext,
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000554 unsigned &neededInt,
555 unsigned &neededSSE) const;
556
557public:
Owen Andersona1cf15f2009-07-14 23:10:40 +0000558 virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context,
559 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000560
561 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
562 CodeGenFunction &CGF) const;
563};
564}
565
566X86_64ABIInfo::Class X86_64ABIInfo::merge(Class Accum,
567 Class Field) const {
568 // AMD64-ABI 3.2.3p2: Rule 4. Each field of an object is
569 // classified recursively so that always two fields are
570 // considered. The resulting class is calculated according to
571 // the classes of the fields in the eightbyte:
572 //
573 // (a) If both classes are equal, this is the resulting class.
574 //
575 // (b) If one of the classes is NO_CLASS, the resulting class is
576 // the other class.
577 //
578 // (c) If one of the classes is MEMORY, the result is the MEMORY
579 // class.
580 //
581 // (d) If one of the classes is INTEGER, the result is the
582 // INTEGER.
583 //
584 // (e) If one of the classes is X87, X87UP, COMPLEX_X87 class,
585 // MEMORY is used as class.
586 //
587 // (f) Otherwise class SSE is used.
588
589 // Accum should never be memory (we should have returned) or
590 // ComplexX87 (because this cannot be passed in a structure).
591 assert((Accum != Memory && Accum != ComplexX87) &&
592 "Invalid accumulated classification during merge.");
593 if (Accum == Field || Field == NoClass)
594 return Accum;
595 else if (Field == Memory)
596 return Memory;
597 else if (Accum == NoClass)
598 return Field;
599 else if (Accum == Integer || Field == Integer)
600 return Integer;
601 else if (Field == X87 || Field == X87Up || Field == ComplexX87 ||
602 Accum == X87 || Accum == X87Up)
603 return Memory;
604 else
605 return SSE;
606}
607
608void X86_64ABIInfo::classify(QualType Ty,
609 ASTContext &Context,
610 uint64_t OffsetBase,
611 Class &Lo, Class &Hi) const {
612 // FIXME: This code can be simplified by introducing a simple value class for
613 // Class pairs with appropriate constructor methods for the various
614 // situations.
615
616 // FIXME: Some of the split computations are wrong; unaligned vectors
617 // shouldn't be passed in registers for example, so there is no chance they
618 // can straddle an eightbyte. Verify & simplify.
619
620 Lo = Hi = NoClass;
621
622 Class &Current = OffsetBase < 64 ? Lo : Hi;
623 Current = Memory;
624
John McCall183700f2009-09-21 23:43:11 +0000625 if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000626 BuiltinType::Kind k = BT->getKind();
627
628 if (k == BuiltinType::Void) {
629 Current = NoClass;
630 } else if (k == BuiltinType::Int128 || k == BuiltinType::UInt128) {
631 Lo = Integer;
632 Hi = Integer;
633 } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
634 Current = Integer;
635 } else if (k == BuiltinType::Float || k == BuiltinType::Double) {
636 Current = SSE;
637 } else if (k == BuiltinType::LongDouble) {
638 Lo = X87;
639 Hi = X87Up;
640 }
641 // FIXME: _Decimal32 and _Decimal64 are SSE.
642 // FIXME: _float128 and _Decimal128 are (SSE, SSEUp).
John McCall183700f2009-09-21 23:43:11 +0000643 } else if (const EnumType *ET = Ty->getAs<EnumType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000644 // Classify the underlying integer type.
645 classify(ET->getDecl()->getIntegerType(), Context, OffsetBase, Lo, Hi);
646 } else if (Ty->hasPointerRepresentation()) {
647 Current = Integer;
John McCall183700f2009-09-21 23:43:11 +0000648 } else if (const VectorType *VT = Ty->getAs<VectorType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000649 uint64_t Size = Context.getTypeSize(VT);
650 if (Size == 32) {
651 // gcc passes all <4 x char>, <2 x short>, <1 x int>, <1 x
652 // float> as integer.
653 Current = Integer;
654
655 // If this type crosses an eightbyte boundary, it should be
656 // split.
657 uint64_t EB_Real = (OffsetBase) / 64;
658 uint64_t EB_Imag = (OffsetBase + Size - 1) / 64;
659 if (EB_Real != EB_Imag)
660 Hi = Lo;
661 } else if (Size == 64) {
662 // gcc passes <1 x double> in memory. :(
663 if (VT->getElementType()->isSpecificBuiltinType(BuiltinType::Double))
664 return;
665
666 // gcc passes <1 x long long> as INTEGER.
667 if (VT->getElementType()->isSpecificBuiltinType(BuiltinType::LongLong))
668 Current = Integer;
669 else
670 Current = SSE;
671
672 // If this type crosses an eightbyte boundary, it should be
673 // split.
674 if (OffsetBase && OffsetBase != 64)
675 Hi = Lo;
676 } else if (Size == 128) {
677 Lo = SSE;
678 Hi = SSEUp;
679 }
John McCall183700f2009-09-21 23:43:11 +0000680 } else if (const ComplexType *CT = Ty->getAs<ComplexType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000681 QualType ET = Context.getCanonicalType(CT->getElementType());
682
683 uint64_t Size = Context.getTypeSize(Ty);
684 if (ET->isIntegralType()) {
685 if (Size <= 64)
686 Current = Integer;
687 else if (Size <= 128)
688 Lo = Hi = Integer;
689 } else if (ET == Context.FloatTy)
690 Current = SSE;
691 else if (ET == Context.DoubleTy)
692 Lo = Hi = SSE;
693 else if (ET == Context.LongDoubleTy)
694 Current = ComplexX87;
695
696 // If this complex type crosses an eightbyte boundary then it
697 // should be split.
698 uint64_t EB_Real = (OffsetBase) / 64;
699 uint64_t EB_Imag = (OffsetBase + Context.getTypeSize(ET)) / 64;
700 if (Hi == NoClass && EB_Real != EB_Imag)
701 Hi = Lo;
702 } else if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty)) {
703 // Arrays are treated like structures.
704
705 uint64_t Size = Context.getTypeSize(Ty);
706
707 // AMD64-ABI 3.2.3p2: Rule 1. If the size of an object is larger
708 // than two eightbytes, ..., it has class MEMORY.
709 if (Size > 128)
710 return;
711
712 // AMD64-ABI 3.2.3p2: Rule 1. If ..., or it contains unaligned
713 // fields, it has class MEMORY.
714 //
715 // Only need to check alignment of array base.
716 if (OffsetBase % Context.getTypeAlign(AT->getElementType()))
717 return;
718
719 // Otherwise implement simplified merge. We could be smarter about
720 // this, but it isn't worth it and would be harder to verify.
721 Current = NoClass;
722 uint64_t EltSize = Context.getTypeSize(AT->getElementType());
723 uint64_t ArraySize = AT->getSize().getZExtValue();
724 for (uint64_t i=0, Offset=OffsetBase; i<ArraySize; ++i, Offset += EltSize) {
725 Class FieldLo, FieldHi;
726 classify(AT->getElementType(), Context, Offset, FieldLo, FieldHi);
727 Lo = merge(Lo, FieldLo);
728 Hi = merge(Hi, FieldHi);
729 if (Lo == Memory || Hi == Memory)
730 break;
731 }
732
733 // Do post merger cleanup (see below). Only case we worry about is Memory.
734 if (Hi == Memory)
735 Lo = Memory;
736 assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp array classification.");
Ted Kremenek6217b802009-07-29 21:53:49 +0000737 } else if (const RecordType *RT = Ty->getAs<RecordType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000738 uint64_t Size = Context.getTypeSize(Ty);
739
740 // AMD64-ABI 3.2.3p2: Rule 1. If the size of an object is larger
741 // than two eightbytes, ..., it has class MEMORY.
742 if (Size > 128)
743 return;
744
Anders Carlsson0a8f8472009-09-16 15:53:40 +0000745 // AMD64-ABI 3.2.3p2: Rule 2. If a C++ object has either a non-trivial
746 // copy constructor or a non-trivial destructor, it is passed by invisible
747 // reference.
748 if (hasNonTrivialDestructorOrCopyConstructor(RT))
749 return;
750
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000751 const RecordDecl *RD = RT->getDecl();
752
753 // Assume variable sized types are passed in memory.
754 if (RD->hasFlexibleArrayMember())
755 return;
756
757 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
758
759 // Reset Lo class, this will be recomputed.
760 Current = NoClass;
761 unsigned idx = 0;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000762 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
763 i != e; ++i, ++idx) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000764 uint64_t Offset = OffsetBase + Layout.getFieldOffset(idx);
765 bool BitField = i->isBitField();
766
767 // AMD64-ABI 3.2.3p2: Rule 1. If ..., or it contains unaligned
768 // fields, it has class MEMORY.
769 //
770 // Note, skip this test for bit-fields, see below.
771 if (!BitField && Offset % Context.getTypeAlign(i->getType())) {
772 Lo = Memory;
773 return;
774 }
775
776 // Classify this field.
777 //
778 // AMD64-ABI 3.2.3p2: Rule 3. If the size of the aggregate
779 // exceeds a single eightbyte, each is classified
780 // separately. Each eightbyte gets initialized to class
781 // NO_CLASS.
782 Class FieldLo, FieldHi;
783
784 // Bit-fields require special handling, they do not force the
785 // structure to be passed in memory even if unaligned, and
786 // therefore they can straddle an eightbyte.
787 if (BitField) {
788 // Ignore padding bit-fields.
789 if (i->isUnnamedBitfield())
790 continue;
791
792 uint64_t Offset = OffsetBase + Layout.getFieldOffset(idx);
793 uint64_t Size = i->getBitWidth()->EvaluateAsInt(Context).getZExtValue();
794
795 uint64_t EB_Lo = Offset / 64;
796 uint64_t EB_Hi = (Offset + Size - 1) / 64;
797 FieldLo = FieldHi = NoClass;
798 if (EB_Lo) {
799 assert(EB_Hi == EB_Lo && "Invalid classification, type > 16 bytes.");
800 FieldLo = NoClass;
801 FieldHi = Integer;
802 } else {
803 FieldLo = Integer;
804 FieldHi = EB_Hi ? Integer : NoClass;
805 }
806 } else
807 classify(i->getType(), Context, Offset, FieldLo, FieldHi);
808 Lo = merge(Lo, FieldLo);
809 Hi = merge(Hi, FieldHi);
810 if (Lo == Memory || Hi == Memory)
811 break;
812 }
813
814 // AMD64-ABI 3.2.3p2: Rule 5. Then a post merger cleanup is done:
815 //
816 // (a) If one of the classes is MEMORY, the whole argument is
817 // passed in memory.
818 //
819 // (b) If SSEUP is not preceeded by SSE, it is converted to SSE.
820
821 // The first of these conditions is guaranteed by how we implement
822 // the merge (just bail).
823 //
824 // The second condition occurs in the case of unions; for example
825 // union { _Complex double; unsigned; }.
826 if (Hi == Memory)
827 Lo = Memory;
828 if (Hi == SSEUp && Lo != SSE)
829 Hi = SSE;
830 }
831}
832
833ABIArgInfo X86_64ABIInfo::getCoerceResult(QualType Ty,
834 const llvm::Type *CoerceTo,
835 ASTContext &Context) const {
Owen Anderson0032b272009-08-13 21:57:51 +0000836 if (CoerceTo == llvm::Type::getInt64Ty(CoerceTo->getContext())) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000837 // Integer and pointer types will end up in a general purpose
838 // register.
Anders Carlsson5b3a2fc2009-09-26 03:56:53 +0000839 if (Ty->isIntegralType() || Ty->hasPointerRepresentation())
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000840 return (Ty->isPromotableIntegerType() ?
841 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Owen Anderson0032b272009-08-13 21:57:51 +0000842 } else if (CoerceTo == llvm::Type::getDoubleTy(CoerceTo->getContext())) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000843 // FIXME: It would probably be better to make CGFunctionInfo only map using
844 // canonical types than to canonize here.
845 QualType CTy = Context.getCanonicalType(Ty);
846
847 // Float and double end up in a single SSE reg.
848 if (CTy == Context.FloatTy || CTy == Context.DoubleTy)
849 return ABIArgInfo::getDirect();
850
851 }
852
853 return ABIArgInfo::getCoerce(CoerceTo);
854}
855
856ABIArgInfo X86_64ABIInfo::getIndirectResult(QualType Ty,
857 ASTContext &Context) const {
858 // If this is a scalar LLVM value then assume LLVM will pass it in the right
859 // place naturally.
860 if (!CodeGenFunction::hasAggregateLLVMType(Ty))
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000861 return (Ty->isPromotableIntegerType() ?
862 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000863
Anders Carlsson0a8f8472009-09-16 15:53:40 +0000864 bool ByVal = !isRecordWithNonTrivialDestructorOrCopyConstructor(Ty);
865
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000866 // FIXME: Set alignment correctly.
Anders Carlsson0a8f8472009-09-16 15:53:40 +0000867 return ABIArgInfo::getIndirect(0, ByVal);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000868}
869
870ABIArgInfo X86_64ABIInfo::classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000871 ASTContext &Context,
872 llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000873 // AMD64-ABI 3.2.3p4: Rule 1. Classify the return type with the
874 // classification algorithm.
875 X86_64ABIInfo::Class Lo, Hi;
876 classify(RetTy, Context, 0, Lo, Hi);
877
878 // Check some invariants.
879 assert((Hi != Memory || Lo == Memory) && "Invalid memory classification.");
880 assert((Lo != NoClass || Hi == NoClass) && "Invalid null classification.");
881 assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp classification.");
882
883 const llvm::Type *ResType = 0;
884 switch (Lo) {
885 case NoClass:
886 return ABIArgInfo::getIgnore();
887
888 case SSEUp:
889 case X87Up:
890 assert(0 && "Invalid classification for lo word.");
891
892 // AMD64-ABI 3.2.3p4: Rule 2. Types of class memory are returned via
893 // hidden argument.
894 case Memory:
895 return getIndirectResult(RetTy, Context);
896
897 // AMD64-ABI 3.2.3p4: Rule 3. If the class is INTEGER, the next
898 // available register of the sequence %rax, %rdx is used.
899 case Integer:
Owen Anderson0032b272009-08-13 21:57:51 +0000900 ResType = llvm::Type::getInt64Ty(VMContext); break;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000901
902 // AMD64-ABI 3.2.3p4: Rule 4. If the class is SSE, the next
903 // available SSE register of the sequence %xmm0, %xmm1 is used.
904 case SSE:
Owen Anderson0032b272009-08-13 21:57:51 +0000905 ResType = llvm::Type::getDoubleTy(VMContext); break;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000906
907 // AMD64-ABI 3.2.3p4: Rule 6. If the class is X87, the value is
908 // returned on the X87 stack in %st0 as 80-bit x87 number.
909 case X87:
Owen Anderson0032b272009-08-13 21:57:51 +0000910 ResType = llvm::Type::getX86_FP80Ty(VMContext); break;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000911
912 // AMD64-ABI 3.2.3p4: Rule 8. If the class is COMPLEX_X87, the real
913 // part of the value is returned in %st0 and the imaginary part in
914 // %st1.
915 case ComplexX87:
916 assert(Hi == ComplexX87 && "Unexpected ComplexX87 classification.");
Owen Anderson0032b272009-08-13 21:57:51 +0000917 ResType = llvm::StructType::get(VMContext, llvm::Type::getX86_FP80Ty(VMContext),
918 llvm::Type::getX86_FP80Ty(VMContext),
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000919 NULL);
920 break;
921 }
922
923 switch (Hi) {
924 // Memory was handled previously and X87 should
925 // never occur as a hi class.
926 case Memory:
927 case X87:
928 assert(0 && "Invalid classification for hi word.");
929
930 case ComplexX87: // Previously handled.
931 case NoClass: break;
932
933 case Integer:
Owen Anderson47a434f2009-08-05 23:18:46 +0000934 ResType = llvm::StructType::get(VMContext, ResType,
Owen Anderson0032b272009-08-13 21:57:51 +0000935 llvm::Type::getInt64Ty(VMContext), NULL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000936 break;
937 case SSE:
Owen Anderson47a434f2009-08-05 23:18:46 +0000938 ResType = llvm::StructType::get(VMContext, ResType,
Owen Anderson0032b272009-08-13 21:57:51 +0000939 llvm::Type::getDoubleTy(VMContext), NULL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000940 break;
941
942 // AMD64-ABI 3.2.3p4: Rule 5. If the class is SSEUP, the eightbyte
943 // is passed in the upper half of the last used SSE register.
944 //
945 // SSEUP should always be preceeded by SSE, just widen.
946 case SSEUp:
947 assert(Lo == SSE && "Unexpected SSEUp classification.");
Owen Anderson0032b272009-08-13 21:57:51 +0000948 ResType = llvm::VectorType::get(llvm::Type::getDoubleTy(VMContext), 2);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000949 break;
950
951 // AMD64-ABI 3.2.3p4: Rule 7. If the class is X87UP, the value is
952 // returned together with the previous X87 value in %st0.
953 case X87Up:
954 // If X87Up is preceeded by X87, we don't need to do
955 // anything. However, in some cases with unions it may not be
956 // preceeded by X87. In such situations we follow gcc and pass the
957 // extra bits in an SSE reg.
958 if (Lo != X87)
Owen Anderson47a434f2009-08-05 23:18:46 +0000959 ResType = llvm::StructType::get(VMContext, ResType,
Owen Anderson0032b272009-08-13 21:57:51 +0000960 llvm::Type::getDoubleTy(VMContext), NULL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000961 break;
962 }
963
964 return getCoerceResult(RetTy, ResType, Context);
965}
966
967ABIArgInfo X86_64ABIInfo::classifyArgumentType(QualType Ty, ASTContext &Context,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000968 llvm::LLVMContext &VMContext,
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000969 unsigned &neededInt,
970 unsigned &neededSSE) const {
971 X86_64ABIInfo::Class Lo, Hi;
972 classify(Ty, Context, 0, Lo, Hi);
973
974 // Check some invariants.
975 // FIXME: Enforce these by construction.
976 assert((Hi != Memory || Lo == Memory) && "Invalid memory classification.");
977 assert((Lo != NoClass || Hi == NoClass) && "Invalid null classification.");
978 assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp classification.");
979
980 neededInt = 0;
981 neededSSE = 0;
982 const llvm::Type *ResType = 0;
983 switch (Lo) {
984 case NoClass:
985 return ABIArgInfo::getIgnore();
986
987 // AMD64-ABI 3.2.3p3: Rule 1. If the class is MEMORY, pass the argument
988 // on the stack.
989 case Memory:
990
991 // AMD64-ABI 3.2.3p3: Rule 5. If the class is X87, X87UP or
992 // COMPLEX_X87, it is passed in memory.
993 case X87:
994 case ComplexX87:
995 return getIndirectResult(Ty, Context);
996
997 case SSEUp:
998 case X87Up:
999 assert(0 && "Invalid classification for lo word.");
1000
1001 // AMD64-ABI 3.2.3p3: Rule 2. If the class is INTEGER, the next
1002 // available register of the sequence %rdi, %rsi, %rdx, %rcx, %r8
1003 // and %r9 is used.
1004 case Integer:
1005 ++neededInt;
Owen Anderson0032b272009-08-13 21:57:51 +00001006 ResType = llvm::Type::getInt64Ty(VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001007 break;
1008
1009 // AMD64-ABI 3.2.3p3: Rule 3. If the class is SSE, the next
1010 // available SSE register is used, the registers are taken in the
1011 // order from %xmm0 to %xmm7.
1012 case SSE:
1013 ++neededSSE;
Owen Anderson0032b272009-08-13 21:57:51 +00001014 ResType = llvm::Type::getDoubleTy(VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001015 break;
1016 }
1017
1018 switch (Hi) {
1019 // Memory was handled previously, ComplexX87 and X87 should
1020 // never occur as hi classes, and X87Up must be preceed by X87,
1021 // which is passed in memory.
1022 case Memory:
1023 case X87:
1024 case ComplexX87:
1025 assert(0 && "Invalid classification for hi word.");
1026 break;
1027
1028 case NoClass: break;
1029 case Integer:
Owen Anderson47a434f2009-08-05 23:18:46 +00001030 ResType = llvm::StructType::get(VMContext, ResType,
Owen Anderson0032b272009-08-13 21:57:51 +00001031 llvm::Type::getInt64Ty(VMContext), NULL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001032 ++neededInt;
1033 break;
1034
1035 // X87Up generally doesn't occur here (long double is passed in
1036 // memory), except in situations involving unions.
1037 case X87Up:
1038 case SSE:
Owen Anderson47a434f2009-08-05 23:18:46 +00001039 ResType = llvm::StructType::get(VMContext, ResType,
Owen Anderson0032b272009-08-13 21:57:51 +00001040 llvm::Type::getDoubleTy(VMContext), NULL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001041 ++neededSSE;
1042 break;
1043
1044 // AMD64-ABI 3.2.3p3: Rule 4. If the class is SSEUP, the
1045 // eightbyte is passed in the upper half of the last used SSE
1046 // register.
1047 case SSEUp:
1048 assert(Lo == SSE && "Unexpected SSEUp classification.");
Owen Anderson0032b272009-08-13 21:57:51 +00001049 ResType = llvm::VectorType::get(llvm::Type::getDoubleTy(VMContext), 2);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001050 break;
1051 }
1052
1053 return getCoerceResult(Ty, ResType, Context);
1054}
1055
Owen Andersona1cf15f2009-07-14 23:10:40 +00001056void X86_64ABIInfo::computeInfo(CGFunctionInfo &FI, ASTContext &Context,
1057 llvm::LLVMContext &VMContext) const {
1058 FI.getReturnInfo() = classifyReturnType(FI.getReturnType(),
1059 Context, VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001060
1061 // Keep track of the number of assigned registers.
1062 unsigned freeIntRegs = 6, freeSSERegs = 8;
1063
1064 // If the return value is indirect, then the hidden argument is consuming one
1065 // integer register.
1066 if (FI.getReturnInfo().isIndirect())
1067 --freeIntRegs;
1068
1069 // AMD64-ABI 3.2.3p3: Once arguments are classified, the registers
1070 // get assigned (in left-to-right order) for passing as follows...
1071 for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
1072 it != ie; ++it) {
1073 unsigned neededInt, neededSSE;
Mike Stump1eb44332009-09-09 15:08:12 +00001074 it->info = classifyArgumentType(it->type, Context, VMContext,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001075 neededInt, neededSSE);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001076
1077 // AMD64-ABI 3.2.3p3: If there are no registers available for any
1078 // eightbyte of an argument, the whole argument is passed on the
1079 // stack. If registers have already been assigned for some
1080 // eightbytes of such an argument, the assignments get reverted.
1081 if (freeIntRegs >= neededInt && freeSSERegs >= neededSSE) {
1082 freeIntRegs -= neededInt;
1083 freeSSERegs -= neededSSE;
1084 } else {
1085 it->info = getIndirectResult(it->type, Context);
1086 }
1087 }
1088}
1089
1090static llvm::Value *EmitVAArgFromMemory(llvm::Value *VAListAddr,
1091 QualType Ty,
1092 CodeGenFunction &CGF) {
1093 llvm::Value *overflow_arg_area_p =
1094 CGF.Builder.CreateStructGEP(VAListAddr, 2, "overflow_arg_area_p");
1095 llvm::Value *overflow_arg_area =
1096 CGF.Builder.CreateLoad(overflow_arg_area_p, "overflow_arg_area");
1097
1098 // AMD64-ABI 3.5.7p5: Step 7. Align l->overflow_arg_area upwards to a 16
1099 // byte boundary if alignment needed by type exceeds 8 byte boundary.
1100 uint64_t Align = CGF.getContext().getTypeAlign(Ty) / 8;
1101 if (Align > 8) {
1102 // Note that we follow the ABI & gcc here, even though the type
1103 // could in theory have an alignment greater than 16. This case
1104 // shouldn't ever matter in practice.
1105
1106 // overflow_arg_area = (overflow_arg_area + 15) & ~15;
Owen Anderson0032b272009-08-13 21:57:51 +00001107 llvm::Value *Offset =
1108 llvm::ConstantInt::get(llvm::Type::getInt32Ty(CGF.getLLVMContext()), 15);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001109 overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset);
1110 llvm::Value *AsInt = CGF.Builder.CreatePtrToInt(overflow_arg_area,
Owen Anderson0032b272009-08-13 21:57:51 +00001111 llvm::Type::getInt64Ty(CGF.getLLVMContext()));
1112 llvm::Value *Mask = llvm::ConstantInt::get(
1113 llvm::Type::getInt64Ty(CGF.getLLVMContext()), ~15LL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001114 overflow_arg_area =
1115 CGF.Builder.CreateIntToPtr(CGF.Builder.CreateAnd(AsInt, Mask),
1116 overflow_arg_area->getType(),
1117 "overflow_arg_area.align");
1118 }
1119
1120 // AMD64-ABI 3.5.7p5: Step 8. Fetch type from l->overflow_arg_area.
1121 const llvm::Type *LTy = CGF.ConvertTypeForMem(Ty);
1122 llvm::Value *Res =
1123 CGF.Builder.CreateBitCast(overflow_arg_area,
Owen Anderson96e0fc72009-07-29 22:16:19 +00001124 llvm::PointerType::getUnqual(LTy));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001125
1126 // AMD64-ABI 3.5.7p5: Step 9. Set l->overflow_arg_area to:
1127 // l->overflow_arg_area + sizeof(type).
1128 // AMD64-ABI 3.5.7p5: Step 10. Align l->overflow_arg_area upwards to
1129 // an 8 byte boundary.
1130
1131 uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
Owen Anderson0032b272009-08-13 21:57:51 +00001132 llvm::Value *Offset =
1133 llvm::ConstantInt::get(llvm::Type::getInt32Ty(CGF.getLLVMContext()),
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001134 (SizeInBytes + 7) & ~7);
1135 overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset,
1136 "overflow_arg_area.next");
1137 CGF.Builder.CreateStore(overflow_arg_area, overflow_arg_area_p);
1138
1139 // AMD64-ABI 3.5.7p5: Step 11. Return the fetched type.
1140 return Res;
1141}
1142
1143llvm::Value *X86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
1144 CodeGenFunction &CGF) const {
Owen Andersona1cf15f2009-07-14 23:10:40 +00001145 llvm::LLVMContext &VMContext = CGF.getLLVMContext();
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001146 const llvm::Type *i32Ty = llvm::Type::getInt32Ty(VMContext);
1147 const llvm::Type *DoubleTy = llvm::Type::getDoubleTy(VMContext);
Mike Stump1eb44332009-09-09 15:08:12 +00001148
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001149 // Assume that va_list type is correct; should be pointer to LLVM type:
1150 // struct {
1151 // i32 gp_offset;
1152 // i32 fp_offset;
1153 // i8* overflow_arg_area;
1154 // i8* reg_save_area;
1155 // };
1156 unsigned neededInt, neededSSE;
Owen Andersona1cf15f2009-07-14 23:10:40 +00001157 ABIArgInfo AI = classifyArgumentType(Ty, CGF.getContext(), VMContext,
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001158 neededInt, neededSSE);
1159
1160 // AMD64-ABI 3.5.7p5: Step 1. Determine whether type may be passed
1161 // in the registers. If not go to step 7.
1162 if (!neededInt && !neededSSE)
1163 return EmitVAArgFromMemory(VAListAddr, Ty, CGF);
1164
1165 // AMD64-ABI 3.5.7p5: Step 2. Compute num_gp to hold the number of
1166 // general purpose registers needed to pass type and num_fp to hold
1167 // the number of floating point registers needed.
1168
1169 // AMD64-ABI 3.5.7p5: Step 3. Verify whether arguments fit into
1170 // registers. In the case: l->gp_offset > 48 - num_gp * 8 or
1171 // l->fp_offset > 304 - num_fp * 16 go to step 7.
1172 //
1173 // NOTE: 304 is a typo, there are (6 * 8 + 8 * 16) = 176 bytes of
1174 // register save space).
1175
1176 llvm::Value *InRegs = 0;
1177 llvm::Value *gp_offset_p = 0, *gp_offset = 0;
1178 llvm::Value *fp_offset_p = 0, *fp_offset = 0;
1179 if (neededInt) {
1180 gp_offset_p = CGF.Builder.CreateStructGEP(VAListAddr, 0, "gp_offset_p");
1181 gp_offset = CGF.Builder.CreateLoad(gp_offset_p, "gp_offset");
1182 InRegs =
1183 CGF.Builder.CreateICmpULE(gp_offset,
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001184 llvm::ConstantInt::get(i32Ty,
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001185 48 - neededInt * 8),
1186 "fits_in_gp");
1187 }
1188
1189 if (neededSSE) {
1190 fp_offset_p = CGF.Builder.CreateStructGEP(VAListAddr, 1, "fp_offset_p");
1191 fp_offset = CGF.Builder.CreateLoad(fp_offset_p, "fp_offset");
1192 llvm::Value *FitsInFP =
1193 CGF.Builder.CreateICmpULE(fp_offset,
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001194 llvm::ConstantInt::get(i32Ty,
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001195 176 - neededSSE * 16),
1196 "fits_in_fp");
1197 InRegs = InRegs ? CGF.Builder.CreateAnd(InRegs, FitsInFP) : FitsInFP;
1198 }
1199
1200 llvm::BasicBlock *InRegBlock = CGF.createBasicBlock("vaarg.in_reg");
1201 llvm::BasicBlock *InMemBlock = CGF.createBasicBlock("vaarg.in_mem");
1202 llvm::BasicBlock *ContBlock = CGF.createBasicBlock("vaarg.end");
1203 CGF.Builder.CreateCondBr(InRegs, InRegBlock, InMemBlock);
1204
1205 // Emit code to load the value if it was passed in registers.
1206
1207 CGF.EmitBlock(InRegBlock);
1208
1209 // AMD64-ABI 3.5.7p5: Step 4. Fetch type from l->reg_save_area with
1210 // an offset of l->gp_offset and/or l->fp_offset. This may require
1211 // copying to a temporary location in case the parameter is passed
1212 // in different register classes or requires an alignment greater
1213 // than 8 for general purpose registers and 16 for XMM registers.
1214 //
1215 // FIXME: This really results in shameful code when we end up needing to
1216 // collect arguments from different places; often what should result in a
1217 // simple assembling of a structure from scattered addresses has many more
1218 // loads than necessary. Can we clean this up?
1219 const llvm::Type *LTy = CGF.ConvertTypeForMem(Ty);
1220 llvm::Value *RegAddr =
1221 CGF.Builder.CreateLoad(CGF.Builder.CreateStructGEP(VAListAddr, 3),
1222 "reg_save_area");
1223 if (neededInt && neededSSE) {
1224 // FIXME: Cleanup.
1225 assert(AI.isCoerce() && "Unexpected ABI info for mixed regs");
1226 const llvm::StructType *ST = cast<llvm::StructType>(AI.getCoerceToType());
1227 llvm::Value *Tmp = CGF.CreateTempAlloca(ST);
1228 assert(ST->getNumElements() == 2 && "Unexpected ABI info for mixed regs");
1229 const llvm::Type *TyLo = ST->getElementType(0);
1230 const llvm::Type *TyHi = ST->getElementType(1);
1231 assert((TyLo->isFloatingPoint() ^ TyHi->isFloatingPoint()) &&
1232 "Unexpected ABI info for mixed regs");
Owen Anderson96e0fc72009-07-29 22:16:19 +00001233 const llvm::Type *PTyLo = llvm::PointerType::getUnqual(TyLo);
1234 const llvm::Type *PTyHi = llvm::PointerType::getUnqual(TyHi);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001235 llvm::Value *GPAddr = CGF.Builder.CreateGEP(RegAddr, gp_offset);
1236 llvm::Value *FPAddr = CGF.Builder.CreateGEP(RegAddr, fp_offset);
1237 llvm::Value *RegLoAddr = TyLo->isFloatingPoint() ? FPAddr : GPAddr;
1238 llvm::Value *RegHiAddr = TyLo->isFloatingPoint() ? GPAddr : FPAddr;
1239 llvm::Value *V =
1240 CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegLoAddr, PTyLo));
1241 CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0));
1242 V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegHiAddr, PTyHi));
1243 CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
1244
Owen Andersona1cf15f2009-07-14 23:10:40 +00001245 RegAddr = CGF.Builder.CreateBitCast(Tmp,
Owen Anderson96e0fc72009-07-29 22:16:19 +00001246 llvm::PointerType::getUnqual(LTy));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001247 } else if (neededInt) {
1248 RegAddr = CGF.Builder.CreateGEP(RegAddr, gp_offset);
1249 RegAddr = CGF.Builder.CreateBitCast(RegAddr,
Owen Anderson96e0fc72009-07-29 22:16:19 +00001250 llvm::PointerType::getUnqual(LTy));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001251 } else {
1252 if (neededSSE == 1) {
1253 RegAddr = CGF.Builder.CreateGEP(RegAddr, fp_offset);
1254 RegAddr = CGF.Builder.CreateBitCast(RegAddr,
Owen Anderson96e0fc72009-07-29 22:16:19 +00001255 llvm::PointerType::getUnqual(LTy));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001256 } else {
1257 assert(neededSSE == 2 && "Invalid number of needed registers!");
1258 // SSE registers are spaced 16 bytes apart in the register save
1259 // area, we need to collect the two eightbytes together.
1260 llvm::Value *RegAddrLo = CGF.Builder.CreateGEP(RegAddr, fp_offset);
1261 llvm::Value *RegAddrHi =
1262 CGF.Builder.CreateGEP(RegAddrLo,
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001263 llvm::ConstantInt::get(i32Ty, 16));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001264 const llvm::Type *DblPtrTy =
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001265 llvm::PointerType::getUnqual(DoubleTy);
1266 const llvm::StructType *ST = llvm::StructType::get(VMContext, DoubleTy,
1267 DoubleTy, NULL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001268 llvm::Value *V, *Tmp = CGF.CreateTempAlloca(ST);
1269 V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegAddrLo,
1270 DblPtrTy));
1271 CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0));
1272 V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegAddrHi,
1273 DblPtrTy));
1274 CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
1275 RegAddr = CGF.Builder.CreateBitCast(Tmp,
Owen Anderson96e0fc72009-07-29 22:16:19 +00001276 llvm::PointerType::getUnqual(LTy));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001277 }
1278 }
1279
1280 // AMD64-ABI 3.5.7p5: Step 5. Set:
1281 // l->gp_offset = l->gp_offset + num_gp * 8
1282 // l->fp_offset = l->fp_offset + num_fp * 16.
1283 if (neededInt) {
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001284 llvm::Value *Offset = llvm::ConstantInt::get(i32Ty, neededInt * 8);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001285 CGF.Builder.CreateStore(CGF.Builder.CreateAdd(gp_offset, Offset),
1286 gp_offset_p);
1287 }
1288 if (neededSSE) {
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001289 llvm::Value *Offset = llvm::ConstantInt::get(i32Ty, neededSSE * 16);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001290 CGF.Builder.CreateStore(CGF.Builder.CreateAdd(fp_offset, Offset),
1291 fp_offset_p);
1292 }
1293 CGF.EmitBranch(ContBlock);
1294
1295 // Emit code to load the value if it was passed in memory.
1296
1297 CGF.EmitBlock(InMemBlock);
1298 llvm::Value *MemAddr = EmitVAArgFromMemory(VAListAddr, Ty, CGF);
1299
1300 // Return the appropriate result.
1301
1302 CGF.EmitBlock(ContBlock);
1303 llvm::PHINode *ResAddr = CGF.Builder.CreatePHI(RegAddr->getType(),
1304 "vaarg.addr");
1305 ResAddr->reserveOperandSpace(2);
1306 ResAddr->addIncoming(RegAddr, InRegBlock);
1307 ResAddr->addIncoming(MemAddr, InMemBlock);
1308
1309 return ResAddr;
1310}
1311
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001312// PIC16 ABI Implementation
1313
1314namespace {
1315
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001316class PIC16ABIInfo : public ABIInfo {
1317 ABIArgInfo classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001318 ASTContext &Context,
1319 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001320
1321 ABIArgInfo classifyArgumentType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001322 ASTContext &Context,
1323 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001324
Owen Andersona1cf15f2009-07-14 23:10:40 +00001325 virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context,
1326 llvm::LLVMContext &VMContext) const {
1327 FI.getReturnInfo() = classifyReturnType(FI.getReturnType(), Context,
1328 VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001329 for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
1330 it != ie; ++it)
Owen Andersona1cf15f2009-07-14 23:10:40 +00001331 it->info = classifyArgumentType(it->type, Context, VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001332 }
1333
1334 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
1335 CodeGenFunction &CGF) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001336};
1337
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001338}
1339
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001340ABIArgInfo PIC16ABIInfo::classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001341 ASTContext &Context,
1342 llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001343 if (RetTy->isVoidType()) {
1344 return ABIArgInfo::getIgnore();
1345 } else {
1346 return ABIArgInfo::getDirect();
1347 }
1348}
1349
1350ABIArgInfo PIC16ABIInfo::classifyArgumentType(QualType Ty,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001351 ASTContext &Context,
1352 llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001353 return ABIArgInfo::getDirect();
1354}
1355
1356llvm::Value *PIC16ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
1357 CodeGenFunction &CGF) const {
1358 return 0;
1359}
1360
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001361// ARM ABI Implementation
1362
1363namespace {
1364
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001365class ARMABIInfo : public ABIInfo {
Daniel Dunbar5e7bace2009-09-12 01:00:39 +00001366public:
1367 enum ABIKind {
1368 APCS = 0,
1369 AAPCS = 1,
1370 AAPCS_VFP
1371 };
1372
1373private:
1374 ABIKind Kind;
1375
1376public:
1377 ARMABIInfo(ABIKind _Kind) : Kind(_Kind) {}
1378
1379private:
1380 ABIKind getABIKind() const { return Kind; }
1381
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001382 ABIArgInfo classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001383 ASTContext &Context,
1384 llvm::LLVMContext &VMCOntext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001385
1386 ABIArgInfo classifyArgumentType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001387 ASTContext &Context,
1388 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001389
Owen Andersona1cf15f2009-07-14 23:10:40 +00001390 virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context,
1391 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001392
1393 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
1394 CodeGenFunction &CGF) const;
1395};
1396
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001397}
1398
Owen Andersona1cf15f2009-07-14 23:10:40 +00001399void ARMABIInfo::computeInfo(CGFunctionInfo &FI, ASTContext &Context,
1400 llvm::LLVMContext &VMContext) const {
Mike Stump1eb44332009-09-09 15:08:12 +00001401 FI.getReturnInfo() = classifyReturnType(FI.getReturnType(), Context,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001402 VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001403 for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
1404 it != ie; ++it) {
Owen Andersona1cf15f2009-07-14 23:10:40 +00001405 it->info = classifyArgumentType(it->type, Context, VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001406 }
Daniel Dunbar5e7bace2009-09-12 01:00:39 +00001407
1408 // ARM always overrides the calling convention.
1409 switch (getABIKind()) {
1410 case APCS:
1411 FI.setEffectiveCallingConvention(llvm::CallingConv::ARM_APCS);
1412 break;
1413
1414 case AAPCS:
1415 FI.setEffectiveCallingConvention(llvm::CallingConv::ARM_AAPCS);
1416 break;
1417
1418 case AAPCS_VFP:
1419 FI.setEffectiveCallingConvention(llvm::CallingConv::ARM_AAPCS_VFP);
1420 break;
1421 }
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001422}
1423
1424ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001425 ASTContext &Context,
1426 llvm::LLVMContext &VMContext) const {
Daniel Dunbar98303b92009-09-13 08:03:58 +00001427 if (!CodeGenFunction::hasAggregateLLVMType(Ty))
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +00001428 return (Ty->isPromotableIntegerType() ?
1429 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Daniel Dunbar98303b92009-09-13 08:03:58 +00001430
Daniel Dunbar42025572009-09-14 21:54:03 +00001431 // Ignore empty records.
1432 if (isEmptyRecord(Context, Ty, true))
1433 return ABIArgInfo::getIgnore();
1434
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001435 // FIXME: This is kind of nasty... but there isn't much choice because the ARM
1436 // backend doesn't support byval.
1437 // FIXME: This doesn't handle alignment > 64 bits.
1438 const llvm::Type* ElemTy;
1439 unsigned SizeRegs;
1440 if (Context.getTypeAlign(Ty) > 32) {
Owen Anderson0032b272009-08-13 21:57:51 +00001441 ElemTy = llvm::Type::getInt64Ty(VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001442 SizeRegs = (Context.getTypeSize(Ty) + 63) / 64;
1443 } else {
Owen Anderson0032b272009-08-13 21:57:51 +00001444 ElemTy = llvm::Type::getInt32Ty(VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001445 SizeRegs = (Context.getTypeSize(Ty) + 31) / 32;
1446 }
1447 std::vector<const llvm::Type*> LLVMFields;
Owen Anderson96e0fc72009-07-29 22:16:19 +00001448 LLVMFields.push_back(llvm::ArrayType::get(ElemTy, SizeRegs));
Owen Anderson47a434f2009-08-05 23:18:46 +00001449 const llvm::Type* STy = llvm::StructType::get(VMContext, LLVMFields, true);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001450 return ABIArgInfo::getCoerce(STy);
1451}
1452
Daniel Dunbar98303b92009-09-13 08:03:58 +00001453static bool isIntegerLikeType(QualType Ty,
1454 ASTContext &Context,
1455 llvm::LLVMContext &VMContext) {
1456 // APCS, C Language Calling Conventions, Non-Simple Return Values: A structure
1457 // is called integer-like if its size is less than or equal to one word, and
1458 // the offset of each of its addressable sub-fields is zero.
1459
1460 uint64_t Size = Context.getTypeSize(Ty);
1461
1462 // Check that the type fits in a word.
1463 if (Size > 32)
1464 return false;
1465
1466 // FIXME: Handle vector types!
1467 if (Ty->isVectorType())
1468 return false;
1469
Daniel Dunbarb0d58192009-09-14 02:20:34 +00001470 // Float types are never treated as "integer like".
1471 if (Ty->isRealFloatingType())
1472 return false;
1473
Daniel Dunbar98303b92009-09-13 08:03:58 +00001474 // If this is a builtin or pointer type then it is ok.
John McCall183700f2009-09-21 23:43:11 +00001475 if (Ty->getAs<BuiltinType>() || Ty->isPointerType())
Daniel Dunbar98303b92009-09-13 08:03:58 +00001476 return true;
1477
1478 // Complex types "should" be ok by the definition above, but they are not.
1479 if (Ty->isAnyComplexType())
1480 return false;
1481
1482 // Single element and zero sized arrays should be allowed, by the definition
1483 // above, but they are not.
1484
1485 // Otherwise, it must be a record type.
1486 const RecordType *RT = Ty->getAs<RecordType>();
1487 if (!RT) return false;
1488
1489 // Ignore records with flexible arrays.
1490 const RecordDecl *RD = RT->getDecl();
1491 if (RD->hasFlexibleArrayMember())
1492 return false;
1493
1494 // Check that all sub-fields are at offset 0, and are themselves "integer
1495 // like".
1496 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
1497
1498 bool HadField = false;
1499 unsigned idx = 0;
1500 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
1501 i != e; ++i, ++idx) {
1502 const FieldDecl *FD = *i;
1503
1504 // Check if this field is at offset 0.
1505 uint64_t Offset = Layout.getFieldOffset(idx);
1506 if (Offset != 0) {
1507 // Allow padding bit-fields, but only if they are all at the end of the
1508 // structure (despite the wording above, this matches gcc).
1509 if (FD->isBitField() &&
1510 !FD->getBitWidth()->EvaluateAsInt(Context).getZExtValue()) {
1511 for (; i != e; ++i)
1512 if (!i->isBitField() ||
1513 i->getBitWidth()->EvaluateAsInt(Context).getZExtValue())
1514 return false;
1515
1516 // All remaining fields are padding, allow this.
1517 return true;
1518 }
1519
1520 return false;
1521 }
1522
1523 if (!isIntegerLikeType(FD->getType(), Context, VMContext))
1524 return false;
1525
1526 // Only allow at most one field in a structure. Again this doesn't match the
1527 // wording above, but follows gcc.
1528 if (!RD->isUnion()) {
1529 if (HadField)
1530 return false;
1531
1532 HadField = true;
1533 }
1534 }
1535
1536 return true;
1537}
1538
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001539ABIArgInfo ARMABIInfo::classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001540 ASTContext &Context,
1541 llvm::LLVMContext &VMContext) const {
Daniel Dunbar98303b92009-09-13 08:03:58 +00001542 if (RetTy->isVoidType())
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001543 return ABIArgInfo::getIgnore();
Daniel Dunbar98303b92009-09-13 08:03:58 +00001544
1545 if (!CodeGenFunction::hasAggregateLLVMType(RetTy))
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +00001546 return (RetTy->isPromotableIntegerType() ?
1547 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Daniel Dunbar98303b92009-09-13 08:03:58 +00001548
1549 // Are we following APCS?
1550 if (getABIKind() == APCS) {
1551 if (isEmptyRecord(Context, RetTy, false))
1552 return ABIArgInfo::getIgnore();
1553
1554 // Integer like structures are returned in r0.
1555 if (isIntegerLikeType(RetTy, Context, VMContext)) {
1556 // Return in the smallest viable integer type.
1557 uint64_t Size = Context.getTypeSize(RetTy);
1558 if (Size <= 8)
1559 return ABIArgInfo::getCoerce(llvm::Type::getInt8Ty(VMContext));
1560 if (Size <= 16)
1561 return ABIArgInfo::getCoerce(llvm::Type::getInt16Ty(VMContext));
1562 return ABIArgInfo::getCoerce(llvm::Type::getInt32Ty(VMContext));
1563 }
1564
1565 // Otherwise return in memory.
1566 return ABIArgInfo::getIndirect(0);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001567 }
Daniel Dunbar98303b92009-09-13 08:03:58 +00001568
1569 // Otherwise this is an AAPCS variant.
1570
Daniel Dunbar16a08082009-09-14 00:56:55 +00001571 if (isEmptyRecord(Context, RetTy, true))
1572 return ABIArgInfo::getIgnore();
1573
Daniel Dunbar98303b92009-09-13 08:03:58 +00001574 // Aggregates <= 4 bytes are returned in r0; other aggregates
1575 // are returned indirectly.
1576 uint64_t Size = Context.getTypeSize(RetTy);
Daniel Dunbar16a08082009-09-14 00:56:55 +00001577 if (Size <= 32) {
1578 // Return in the smallest viable integer type.
1579 if (Size <= 8)
1580 return ABIArgInfo::getCoerce(llvm::Type::getInt8Ty(VMContext));
1581 if (Size <= 16)
1582 return ABIArgInfo::getCoerce(llvm::Type::getInt16Ty(VMContext));
Daniel Dunbar98303b92009-09-13 08:03:58 +00001583 return ABIArgInfo::getCoerce(llvm::Type::getInt32Ty(VMContext));
Daniel Dunbar16a08082009-09-14 00:56:55 +00001584 }
1585
Daniel Dunbar98303b92009-09-13 08:03:58 +00001586 return ABIArgInfo::getIndirect(0);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001587}
1588
1589llvm::Value *ARMABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
1590 CodeGenFunction &CGF) const {
1591 // FIXME: Need to handle alignment
Mike Stump1eb44332009-09-09 15:08:12 +00001592 const llvm::Type *BP =
Owen Anderson0032b272009-08-13 21:57:51 +00001593 llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(CGF.getLLVMContext()));
Owen Anderson96e0fc72009-07-29 22:16:19 +00001594 const llvm::Type *BPP = llvm::PointerType::getUnqual(BP);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001595
1596 CGBuilderTy &Builder = CGF.Builder;
1597 llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP,
1598 "ap");
1599 llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
1600 llvm::Type *PTy =
Owen Anderson96e0fc72009-07-29 22:16:19 +00001601 llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001602 llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
1603
1604 uint64_t Offset =
1605 llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4);
1606 llvm::Value *NextAddr =
Owen Anderson0032b272009-08-13 21:57:51 +00001607 Builder.CreateGEP(Addr, llvm::ConstantInt::get(
1608 llvm::Type::getInt32Ty(CGF.getLLVMContext()), Offset),
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001609 "ap.next");
1610 Builder.CreateStore(NextAddr, VAListAddrAsBPP);
1611
1612 return AddrTyped;
1613}
1614
1615ABIArgInfo DefaultABIInfo::classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001616 ASTContext &Context,
1617 llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001618 if (RetTy->isVoidType()) {
1619 return ABIArgInfo::getIgnore();
1620 } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
1621 return ABIArgInfo::getIndirect(0);
1622 } else {
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +00001623 return (RetTy->isPromotableIntegerType() ?
1624 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001625 }
1626}
1627
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001628// SystemZ ABI Implementation
1629
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001630namespace {
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001631
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001632class SystemZABIInfo : public ABIInfo {
1633 bool isPromotableIntegerType(QualType Ty) const;
1634
1635 ABIArgInfo classifyReturnType(QualType RetTy, ASTContext &Context,
1636 llvm::LLVMContext &VMContext) const;
1637
1638 ABIArgInfo classifyArgumentType(QualType RetTy, ASTContext &Context,
1639 llvm::LLVMContext &VMContext) const;
1640
1641 virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context,
1642 llvm::LLVMContext &VMContext) const {
1643 FI.getReturnInfo() = classifyReturnType(FI.getReturnType(),
1644 Context, VMContext);
1645 for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
1646 it != ie; ++it)
1647 it->info = classifyArgumentType(it->type, Context, VMContext);
1648 }
1649
1650 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
1651 CodeGenFunction &CGF) const;
1652};
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001653
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001654}
1655
1656bool SystemZABIInfo::isPromotableIntegerType(QualType Ty) const {
1657 // SystemZ ABI requires all 8, 16 and 32 bit quantities to be extended.
John McCall183700f2009-09-21 23:43:11 +00001658 if (const BuiltinType *BT = Ty->getAs<BuiltinType>())
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001659 switch (BT->getKind()) {
1660 case BuiltinType::Bool:
1661 case BuiltinType::Char_S:
1662 case BuiltinType::Char_U:
1663 case BuiltinType::SChar:
1664 case BuiltinType::UChar:
1665 case BuiltinType::Short:
1666 case BuiltinType::UShort:
1667 case BuiltinType::Int:
1668 case BuiltinType::UInt:
1669 return true;
1670 default:
1671 return false;
1672 }
1673 return false;
1674}
1675
1676llvm::Value *SystemZABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
1677 CodeGenFunction &CGF) const {
1678 // FIXME: Implement
1679 return 0;
1680}
1681
1682
1683ABIArgInfo SystemZABIInfo::classifyReturnType(QualType RetTy,
1684 ASTContext &Context,
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001685 llvm::LLVMContext &VMContext) const {
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001686 if (RetTy->isVoidType()) {
1687 return ABIArgInfo::getIgnore();
1688 } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
1689 return ABIArgInfo::getIndirect(0);
1690 } else {
1691 return (isPromotableIntegerType(RetTy) ?
1692 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
1693 }
1694}
1695
1696ABIArgInfo SystemZABIInfo::classifyArgumentType(QualType Ty,
1697 ASTContext &Context,
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001698 llvm::LLVMContext &VMContext) const {
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00001699 if (CodeGenFunction::hasAggregateLLVMType(Ty)) {
1700 return ABIArgInfo::getIndirect(0);
1701 } else {
1702 return (isPromotableIntegerType(Ty) ?
1703 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
1704 }
1705}
1706
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001707ABIArgInfo DefaultABIInfo::classifyArgumentType(QualType Ty,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001708 ASTContext &Context,
1709 llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001710 if (CodeGenFunction::hasAggregateLLVMType(Ty)) {
1711 return ABIArgInfo::getIndirect(0);
1712 } else {
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +00001713 return (Ty->isPromotableIntegerType() ?
1714 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001715 }
1716}
1717
1718llvm::Value *DefaultABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
1719 CodeGenFunction &CGF) const {
1720 return 0;
1721}
1722
1723const ABIInfo &CodeGenTypes::getABIInfo() const {
1724 if (TheABIInfo)
1725 return *TheABIInfo;
1726
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00001727 // For now we just cache the ABIInfo in CodeGenTypes and don't free it.
1728
Daniel Dunbar1752ee42009-08-24 09:10:05 +00001729 const llvm::Triple &Triple(getContext().Target.getTriple());
1730 switch (Triple.getArch()) {
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00001731 default:
1732 return *(TheABIInfo = new DefaultABIInfo);
1733
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001734 case llvm::Triple::arm:
1735 case llvm::Triple::thumb:
Daniel Dunbar5e7bace2009-09-12 01:00:39 +00001736 // FIXME: We want to know the float calling convention as well.
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00001737 if (strcmp(getContext().Target.getABI(), "apcs-gnu") == 0)
Daniel Dunbar5e7bace2009-09-12 01:00:39 +00001738 return *(TheABIInfo = new ARMABIInfo(ARMABIInfo::APCS));
1739
1740 return *(TheABIInfo = new ARMABIInfo(ARMABIInfo::AAPCS));
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001741
1742 case llvm::Triple::pic16:
1743 return *(TheABIInfo = new PIC16ABIInfo());
1744
1745 case llvm::Triple::systemz:
1746 return *(TheABIInfo = new SystemZABIInfo());
1747
Daniel Dunbar1752ee42009-08-24 09:10:05 +00001748 case llvm::Triple::x86:
1749 if (Triple.getOS() == llvm::Triple::Darwin)
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00001750 return *(TheABIInfo = new X86_32ABIInfo(Context, true, true));
1751
Daniel Dunbar1752ee42009-08-24 09:10:05 +00001752 switch (Triple.getOS()) {
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00001753 case llvm::Triple::Cygwin:
1754 case llvm::Triple::DragonFly:
1755 case llvm::Triple::MinGW32:
1756 case llvm::Triple::MinGW64:
David Chisnall75c135a2009-09-03 01:48:05 +00001757 case llvm::Triple::FreeBSD:
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00001758 case llvm::Triple::OpenBSD:
1759 return *(TheABIInfo = new X86_32ABIInfo(Context, false, true));
1760
1761 default:
1762 return *(TheABIInfo = new X86_32ABIInfo(Context, false, false));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001763 }
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001764
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00001765 case llvm::Triple::x86_64:
1766 return *(TheABIInfo = new X86_64ABIInfo());
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00001767 }
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001768}