blob: b315e851c283538be1975045db8d91b9ad14fdb5 [file] [log] [blame]
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00001//===---- TargetInfo.cpp - Encapsulate target details -----------*- C++ -*-===//
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002//
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 Korobeynikov82d0a412010-01-10 12:58:08 +000015#include "TargetInfo.h"
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000016#include "ABIInfo.h"
17#include "CodeGenFunction.h"
Anders Carlsson19cc4ab2009-07-18 19:43:29 +000018#include "clang/AST/RecordLayout.h"
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000019#include "llvm/Type.h"
Chris Lattner9c254f02010-06-29 06:01:59 +000020#include "llvm/Target/TargetData.h"
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000021#include "llvm/ADT/StringExtras.h"
Daniel Dunbar2c0843f2009-08-24 08:52:16 +000022#include "llvm/ADT/Triple.h"
Daniel Dunbar28df7a52009-12-03 09:13:49 +000023#include "llvm/Support/raw_ostream.h"
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000024using namespace clang;
25using namespace CodeGen;
26
John McCallaeeb7012010-05-27 06:19:26 +000027static 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
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000039ABIInfo::~ABIInfo() {}
40
41void ABIArgInfo::dump() const {
Daniel Dunbar28df7a52009-12-03 09:13:49 +000042 llvm::raw_ostream &OS = llvm::errs();
43 OS << "(ABIArgInfo Kind=";
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000044 switch (TheKind) {
45 case Direct:
Daniel Dunbar28df7a52009-12-03 09:13:49 +000046 OS << "Direct";
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000047 break;
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +000048 case Extend:
Daniel Dunbar28df7a52009-12-03 09:13:49 +000049 OS << "Extend";
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +000050 break;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000051 case Ignore:
Daniel Dunbar28df7a52009-12-03 09:13:49 +000052 OS << "Ignore";
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000053 break;
54 case Coerce:
Daniel Dunbar28df7a52009-12-03 09:13:49 +000055 OS << "Coerce Type=";
56 getCoerceToType()->print(OS);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000057 break;
58 case Indirect:
Daniel Dunbardc6d5742010-04-21 19:10:51 +000059 OS << "Indirect Align=" << getIndirectAlign()
60 << " Byal=" << getIndirectByVal();
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000061 break;
62 case Expand:
Daniel Dunbar28df7a52009-12-03 09:13:49 +000063 OS << "Expand";
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000064 break;
65 }
Daniel Dunbar28df7a52009-12-03 09:13:49 +000066 OS << ")\n";
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000067}
68
Anton Korobeynikov82d0a412010-01-10 12:58:08 +000069TargetCodeGenInfo::~TargetCodeGenInfo() { delete Info; }
70
Daniel Dunbar98303b92009-09-13 08:03:58 +000071static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000072
73/// isEmptyField - Return true iff a the field is "empty", that is it
74/// is an unnamed bit-field or an (array of) empty record(s).
Daniel Dunbar98303b92009-09-13 08:03:58 +000075static bool isEmptyField(ASTContext &Context, const FieldDecl *FD,
76 bool AllowArrays) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000077 if (FD->isUnnamedBitfield())
78 return true;
79
80 QualType FT = FD->getType();
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000081
Daniel Dunbar98303b92009-09-13 08:03:58 +000082 // Constant arrays of empty records count as empty, strip them off.
83 if (AllowArrays)
84 while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT))
85 FT = AT->getElementType();
86
Daniel Dunbar5ea68612010-05-17 16:46:00 +000087 const RecordType *RT = FT->getAs<RecordType>();
88 if (!RT)
89 return false;
90
91 // C++ record fields are never empty, at least in the Itanium ABI.
92 //
93 // FIXME: We should use a predicate for whether this behavior is true in the
94 // current ABI.
95 if (isa<CXXRecordDecl>(RT->getDecl()))
96 return false;
97
Daniel Dunbar98303b92009-09-13 08:03:58 +000098 return isEmptyRecord(Context, FT, AllowArrays);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +000099}
100
101/// isEmptyRecord - Return true iff a structure contains only empty
102/// fields. Note that a structure with a flexible array member is not
103/// considered empty.
Daniel Dunbar98303b92009-09-13 08:03:58 +0000104static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays) {
Ted Kremenek6217b802009-07-29 21:53:49 +0000105 const RecordType *RT = T->getAs<RecordType>();
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000106 if (!RT)
107 return 0;
108 const RecordDecl *RD = RT->getDecl();
109 if (RD->hasFlexibleArrayMember())
110 return false;
Daniel Dunbar5ea68612010-05-17 16:46:00 +0000111
112 // If this is a C++ record, check the bases first.
113 if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
114 for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(),
115 e = CXXRD->bases_end(); i != e; ++i)
116 if (!isEmptyRecord(Context, i->getType(), true))
117 return false;
118
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000119 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
120 i != e; ++i)
Daniel Dunbar98303b92009-09-13 08:03:58 +0000121 if (!isEmptyField(Context, *i, AllowArrays))
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000122 return false;
123 return true;
124}
125
Anders Carlsson0a8f8472009-09-16 15:53:40 +0000126/// hasNonTrivialDestructorOrCopyConstructor - Determine if a type has either
127/// a non-trivial destructor or a non-trivial copy constructor.
128static bool hasNonTrivialDestructorOrCopyConstructor(const RecordType *RT) {
129 const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
130 if (!RD)
131 return false;
132
133 return !RD->hasTrivialDestructor() || !RD->hasTrivialCopyConstructor();
134}
135
136/// isRecordWithNonTrivialDestructorOrCopyConstructor - Determine if a type is
137/// a record type with either a non-trivial destructor or a non-trivial copy
138/// constructor.
139static bool isRecordWithNonTrivialDestructorOrCopyConstructor(QualType T) {
140 const RecordType *RT = T->getAs<RecordType>();
141 if (!RT)
142 return false;
143
144 return hasNonTrivialDestructorOrCopyConstructor(RT);
145}
146
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000147/// isSingleElementStruct - Determine if a structure is a "single
148/// element struct", i.e. it has exactly one non-empty field or
149/// exactly one field which is itself a single element
150/// struct. Structures with flexible array members are never
151/// considered single element structs.
152///
153/// \return The field declaration for the single non-empty field, if
154/// it exists.
155static const Type *isSingleElementStruct(QualType T, ASTContext &Context) {
156 const RecordType *RT = T->getAsStructureType();
157 if (!RT)
158 return 0;
159
160 const RecordDecl *RD = RT->getDecl();
161 if (RD->hasFlexibleArrayMember())
162 return 0;
163
164 const Type *Found = 0;
Daniel Dunbar9430d5a2010-05-11 21:15:36 +0000165
166 // If this is a C++ record, check the bases first.
167 if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
168 for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(),
169 e = CXXRD->bases_end(); i != e; ++i) {
Daniel Dunbar9430d5a2010-05-11 21:15:36 +0000170 // Ignore empty records.
Daniel Dunbar5ea68612010-05-17 16:46:00 +0000171 if (isEmptyRecord(Context, i->getType(), true))
Daniel Dunbar9430d5a2010-05-11 21:15:36 +0000172 continue;
173
174 // If we already found an element then this isn't a single-element struct.
175 if (Found)
176 return 0;
177
178 // If this is non-empty and not a single element struct, the composite
179 // cannot be a single element struct.
180 Found = isSingleElementStruct(i->getType(), Context);
181 if (!Found)
182 return 0;
183 }
184 }
185
186 // Check for single element.
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000187 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
188 i != e; ++i) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000189 const FieldDecl *FD = *i;
190 QualType FT = FD->getType();
191
192 // Ignore empty fields.
Daniel Dunbar98303b92009-09-13 08:03:58 +0000193 if (isEmptyField(Context, FD, true))
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000194 continue;
195
196 // If we already found an element then this isn't a single-element
197 // struct.
198 if (Found)
199 return 0;
200
201 // Treat single element arrays as the element.
202 while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT)) {
203 if (AT->getSize().getZExtValue() != 1)
204 break;
205 FT = AT->getElementType();
206 }
207
208 if (!CodeGenFunction::hasAggregateLLVMType(FT)) {
209 Found = FT.getTypePtr();
210 } else {
211 Found = isSingleElementStruct(FT, Context);
212 if (!Found)
213 return 0;
214 }
215 }
216
217 return Found;
218}
219
220static bool is32Or64BitBasicType(QualType Ty, ASTContext &Context) {
Daniel Dunbara1842d32010-05-14 03:40:53 +0000221 if (!Ty->getAs<BuiltinType>() && !Ty->hasPointerRepresentation() &&
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000222 !Ty->isAnyComplexType() && !Ty->isEnumeralType() &&
223 !Ty->isBlockPointerType())
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000224 return false;
225
226 uint64_t Size = Context.getTypeSize(Ty);
227 return Size == 32 || Size == 64;
228}
229
Daniel Dunbar53012f42009-11-09 01:33:53 +0000230/// canExpandIndirectArgument - Test whether an argument type which is to be
231/// passed indirectly (on the stack) would have the equivalent layout if it was
232/// expanded into separate arguments. If so, we prefer to do the latter to avoid
233/// inhibiting optimizations.
234///
235// FIXME: This predicate is missing many cases, currently it just follows
236// llvm-gcc (checks that all fields are 32-bit or 64-bit primitive types). We
237// should probably make this smarter, or better yet make the LLVM backend
238// capable of handling it.
239static bool canExpandIndirectArgument(QualType Ty, ASTContext &Context) {
240 // We can only expand structure types.
241 const RecordType *RT = Ty->getAs<RecordType>();
242 if (!RT)
243 return false;
244
245 // We can only expand (C) structures.
246 //
247 // FIXME: This needs to be generalized to handle classes as well.
248 const RecordDecl *RD = RT->getDecl();
249 if (!RD->isStruct() || isa<CXXRecordDecl>(RD))
250 return false;
251
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000252 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
253 i != e; ++i) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000254 const FieldDecl *FD = *i;
255
256 if (!is32Or64BitBasicType(FD->getType(), Context))
257 return false;
258
259 // FIXME: Reject bit-fields wholesale; there are two problems, we don't know
260 // how to expand them yet, and the predicate for telling if a bitfield still
261 // counts as "basic" is more complicated than what we were doing previously.
262 if (FD->isBitField())
263 return false;
264 }
265
266 return true;
267}
268
269namespace {
270/// DefaultABIInfo - The default implementation for ABI specific
271/// details. This implementation provides information which results in
272/// self-consistent and sensible LLVM IR generation, but does not
273/// conform to any particular ABI.
274class DefaultABIInfo : public ABIInfo {
275 ABIArgInfo classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000276 ASTContext &Context,
277 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000278
279 ABIArgInfo classifyArgumentType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000280 ASTContext &Context,
281 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000282
Owen Andersona1cf15f2009-07-14 23:10:40 +0000283 virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context,
Chris Lattner8640cd62010-06-29 01:08:48 +0000284 llvm::LLVMContext &VMContext,
285 const llvm::Type *const *PrefTypes,
286 unsigned NumPrefTypes) const {
Owen Andersona1cf15f2009-07-14 23:10:40 +0000287 FI.getReturnInfo() = classifyReturnType(FI.getReturnType(), Context,
288 VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000289 for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
290 it != ie; ++it)
Owen Andersona1cf15f2009-07-14 23:10:40 +0000291 it->info = classifyArgumentType(it->type, Context, VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000292 }
293
294 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
295 CodeGenFunction &CGF) const;
296};
297
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000298class DefaultTargetCodeGenInfo : public TargetCodeGenInfo {
299public:
Douglas Gregor568bb2d2010-01-22 15:41:14 +0000300 DefaultTargetCodeGenInfo():TargetCodeGenInfo(new DefaultABIInfo()) {}
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000301};
302
303llvm::Value *DefaultABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
304 CodeGenFunction &CGF) const {
305 return 0;
306}
307
308ABIArgInfo DefaultABIInfo::classifyArgumentType(QualType Ty,
309 ASTContext &Context,
310 llvm::LLVMContext &VMContext) const {
Chris Lattnera14db752010-03-11 18:19:55 +0000311 if (CodeGenFunction::hasAggregateLLVMType(Ty))
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000312 return ABIArgInfo::getIndirect(0);
Daniel Dunbardc6d5742010-04-21 19:10:51 +0000313
Chris Lattnera14db752010-03-11 18:19:55 +0000314 // Treat an enum type as its underlying type.
315 if (const EnumType *EnumTy = Ty->getAs<EnumType>())
316 Ty = EnumTy->getDecl()->getIntegerType();
Douglas Gregoraa74a1e2010-02-02 20:10:50 +0000317
Chris Lattnera14db752010-03-11 18:19:55 +0000318 return (Ty->isPromotableIntegerType() ?
319 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000320}
321
Chris Lattnerdce5ad02010-06-28 20:05:43 +0000322//===----------------------------------------------------------------------===//
323// X86-32 ABI Implementation
324//===----------------------------------------------------------------------===//
325
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000326/// X86_32ABIInfo - The X86-32 ABI information.
327class X86_32ABIInfo : public ABIInfo {
328 ASTContext &Context;
David Chisnall1e4249c2009-08-17 23:08:21 +0000329 bool IsDarwinVectorABI;
330 bool IsSmallStructInRegABI;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000331
332 static bool isRegisterSize(unsigned Size) {
333 return (Size == 8 || Size == 16 || Size == 32 || Size == 64);
334 }
335
336 static bool shouldReturnTypeInRegister(QualType Ty, ASTContext &Context);
337
Daniel Dunbardc6d5742010-04-21 19:10:51 +0000338 /// getIndirectResult - Give a source type \arg Ty, return a suitable result
339 /// such that the argument will be passed in memory.
340 ABIArgInfo getIndirectResult(QualType Ty, ASTContext &Context,
341 bool ByVal = true) const;
342
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000343public:
344 ABIArgInfo classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000345 ASTContext &Context,
346 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000347
348 ABIArgInfo classifyArgumentType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000349 ASTContext &Context,
350 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000351
Owen Andersona1cf15f2009-07-14 23:10:40 +0000352 virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context,
Chris Lattner8640cd62010-06-29 01:08:48 +0000353 llvm::LLVMContext &VMContext,
354 const llvm::Type *const *PrefTypes,
355 unsigned NumPrefTypes) const {
Owen Andersona1cf15f2009-07-14 23:10:40 +0000356 FI.getReturnInfo() = classifyReturnType(FI.getReturnType(), Context,
357 VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000358 for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
359 it != ie; ++it)
Owen Andersona1cf15f2009-07-14 23:10:40 +0000360 it->info = classifyArgumentType(it->type, Context, VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000361 }
362
363 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
364 CodeGenFunction &CGF) const;
365
David Chisnall1e4249c2009-08-17 23:08:21 +0000366 X86_32ABIInfo(ASTContext &Context, bool d, bool p)
Mike Stump1eb44332009-09-09 15:08:12 +0000367 : ABIInfo(), Context(Context), IsDarwinVectorABI(d),
David Chisnall1e4249c2009-08-17 23:08:21 +0000368 IsSmallStructInRegABI(p) {}
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000369};
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000370
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000371class X86_32TargetCodeGenInfo : public TargetCodeGenInfo {
372public:
373 X86_32TargetCodeGenInfo(ASTContext &Context, bool d, bool p)
Douglas Gregor568bb2d2010-01-22 15:41:14 +0000374 :TargetCodeGenInfo(new X86_32ABIInfo(Context, d, p)) {}
Charles Davis74f72932010-02-13 15:54:06 +0000375
376 void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
377 CodeGen::CodeGenModule &CGM) const;
John McCall6374c332010-03-06 00:35:14 +0000378
379 int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const {
380 // Darwin uses different dwarf register numbers for EH.
381 if (CGM.isTargetDarwin()) return 5;
382
383 return 4;
384 }
385
386 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
387 llvm::Value *Address) const;
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000388};
389
390}
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000391
392/// shouldReturnTypeInRegister - Determine if the given type should be
393/// passed in a register (for the Darwin ABI).
394bool X86_32ABIInfo::shouldReturnTypeInRegister(QualType Ty,
395 ASTContext &Context) {
396 uint64_t Size = Context.getTypeSize(Ty);
397
398 // Type must be register sized.
399 if (!isRegisterSize(Size))
400 return false;
401
402 if (Ty->isVectorType()) {
403 // 64- and 128- bit vectors inside structures are not returned in
404 // registers.
405 if (Size == 64 || Size == 128)
406 return false;
407
408 return true;
409 }
410
Daniel Dunbar77115232010-05-15 00:00:30 +0000411 // If this is a builtin, pointer, enum, complex type, member pointer, or
412 // member function pointer it is ok.
Daniel Dunbara1842d32010-05-14 03:40:53 +0000413 if (Ty->getAs<BuiltinType>() || Ty->hasPointerRepresentation() ||
Daniel Dunbar55e59e12009-09-24 05:12:36 +0000414 Ty->isAnyComplexType() || Ty->isEnumeralType() ||
Daniel Dunbar77115232010-05-15 00:00:30 +0000415 Ty->isBlockPointerType() || Ty->isMemberPointerType())
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000416 return true;
417
418 // Arrays are treated like records.
419 if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty))
420 return shouldReturnTypeInRegister(AT->getElementType(), Context);
421
422 // Otherwise, it must be a record type.
Ted Kremenek6217b802009-07-29 21:53:49 +0000423 const RecordType *RT = Ty->getAs<RecordType>();
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000424 if (!RT) return false;
425
Anders Carlssona8874232010-01-27 03:25:19 +0000426 // FIXME: Traverse bases here too.
427
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000428 // Structure types are passed in register if all fields would be
429 // passed in a register.
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000430 for (RecordDecl::field_iterator i = RT->getDecl()->field_begin(),
431 e = RT->getDecl()->field_end(); i != e; ++i) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000432 const FieldDecl *FD = *i;
433
434 // Empty fields are ignored.
Daniel Dunbar98303b92009-09-13 08:03:58 +0000435 if (isEmptyField(Context, FD, true))
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000436 continue;
437
438 // Check fields recursively.
439 if (!shouldReturnTypeInRegister(FD->getType(), Context))
440 return false;
441 }
442
443 return true;
444}
445
446ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000447 ASTContext &Context,
448 llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000449 if (RetTy->isVoidType()) {
450 return ABIArgInfo::getIgnore();
John McCall183700f2009-09-21 23:43:11 +0000451 } else if (const VectorType *VT = RetTy->getAs<VectorType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000452 // On Darwin, some vectors are returned in registers.
David Chisnall1e4249c2009-08-17 23:08:21 +0000453 if (IsDarwinVectorABI) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000454 uint64_t Size = Context.getTypeSize(RetTy);
455
456 // 128-bit vectors are a special case; they are returned in
457 // registers and we need to make sure to pick a type the LLVM
458 // backend will like.
459 if (Size == 128)
Owen Anderson0032b272009-08-13 21:57:51 +0000460 return ABIArgInfo::getCoerce(llvm::VectorType::get(
461 llvm::Type::getInt64Ty(VMContext), 2));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000462
463 // Always return in register if it fits in a general purpose
464 // register, or if it is 64 bits and has a single element.
465 if ((Size == 8 || Size == 16 || Size == 32) ||
466 (Size == 64 && VT->getNumElements() == 1))
Owen Anderson0032b272009-08-13 21:57:51 +0000467 return ABIArgInfo::getCoerce(llvm::IntegerType::get(VMContext, Size));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000468
469 return ABIArgInfo::getIndirect(0);
470 }
471
472 return ABIArgInfo::getDirect();
473 } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
Anders Carlssona8874232010-01-27 03:25:19 +0000474 if (const RecordType *RT = RetTy->getAs<RecordType>()) {
Anders Carlsson40092972009-10-20 22:07:59 +0000475 // Structures with either a non-trivial destructor or a non-trivial
476 // copy constructor are always indirect.
477 if (hasNonTrivialDestructorOrCopyConstructor(RT))
478 return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
479
480 // Structures with flexible arrays are always indirect.
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000481 if (RT->getDecl()->hasFlexibleArrayMember())
482 return ABIArgInfo::getIndirect(0);
Anders Carlsson40092972009-10-20 22:07:59 +0000483 }
484
David Chisnall1e4249c2009-08-17 23:08:21 +0000485 // If specified, structs and unions are always indirect.
486 if (!IsSmallStructInRegABI && !RetTy->isAnyComplexType())
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000487 return ABIArgInfo::getIndirect(0);
488
489 // Classify "single element" structs as their element type.
490 if (const Type *SeltTy = isSingleElementStruct(RetTy, Context)) {
John McCall183700f2009-09-21 23:43:11 +0000491 if (const BuiltinType *BT = SeltTy->getAs<BuiltinType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000492 if (BT->isIntegerType()) {
493 // We need to use the size of the structure, padding
494 // bit-fields can adjust that to be larger than the single
495 // element type.
496 uint64_t Size = Context.getTypeSize(RetTy);
Owen Andersona1cf15f2009-07-14 23:10:40 +0000497 return ABIArgInfo::getCoerce(
Owen Anderson0032b272009-08-13 21:57:51 +0000498 llvm::IntegerType::get(VMContext, (unsigned) Size));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000499 } else if (BT->getKind() == BuiltinType::Float) {
500 assert(Context.getTypeSize(RetTy) == Context.getTypeSize(SeltTy) &&
501 "Unexpect single element structure size!");
Owen Anderson0032b272009-08-13 21:57:51 +0000502 return ABIArgInfo::getCoerce(llvm::Type::getFloatTy(VMContext));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000503 } else if (BT->getKind() == BuiltinType::Double) {
504 assert(Context.getTypeSize(RetTy) == Context.getTypeSize(SeltTy) &&
505 "Unexpect single element structure size!");
Owen Anderson0032b272009-08-13 21:57:51 +0000506 return ABIArgInfo::getCoerce(llvm::Type::getDoubleTy(VMContext));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000507 }
508 } else if (SeltTy->isPointerType()) {
509 // FIXME: It would be really nice if this could come out as the proper
510 // pointer type.
Benjamin Kramer3c0ef8c2009-10-13 10:07:13 +0000511 const llvm::Type *PtrTy = llvm::Type::getInt8PtrTy(VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000512 return ABIArgInfo::getCoerce(PtrTy);
513 } else if (SeltTy->isVectorType()) {
514 // 64- and 128-bit vectors are never returned in a
515 // register when inside a structure.
516 uint64_t Size = Context.getTypeSize(RetTy);
517 if (Size == 64 || Size == 128)
518 return ABIArgInfo::getIndirect(0);
519
Owen Andersona1cf15f2009-07-14 23:10:40 +0000520 return classifyReturnType(QualType(SeltTy, 0), Context, VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000521 }
522 }
523
524 // Small structures which are register sized are generally returned
525 // in a register.
526 if (X86_32ABIInfo::shouldReturnTypeInRegister(RetTy, Context)) {
527 uint64_t Size = Context.getTypeSize(RetTy);
Owen Anderson0032b272009-08-13 21:57:51 +0000528 return ABIArgInfo::getCoerce(llvm::IntegerType::get(VMContext, Size));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000529 }
530
531 return ABIArgInfo::getIndirect(0);
532 } else {
Douglas Gregoraa74a1e2010-02-02 20:10:50 +0000533 // Treat an enum type as its underlying type.
534 if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
535 RetTy = EnumTy->getDecl()->getIntegerType();
536
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000537 return (RetTy->isPromotableIntegerType() ?
538 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000539 }
540}
541
Daniel Dunbardc6d5742010-04-21 19:10:51 +0000542ABIArgInfo X86_32ABIInfo::getIndirectResult(QualType Ty,
543 ASTContext &Context,
544 bool ByVal) const {
Daniel Dunbar46c54fb2010-04-21 19:49:55 +0000545 if (!ByVal)
546 return ABIArgInfo::getIndirect(0, false);
547
548 // Compute the byval alignment. We trust the back-end to honor the
549 // minimum ABI alignment for byval, to make cleaner IR.
550 const unsigned MinABIAlign = 4;
551 unsigned Align = Context.getTypeAlign(Ty) / 8;
552 if (Align > MinABIAlign)
553 return ABIArgInfo::getIndirect(Align);
554 return ABIArgInfo::getIndirect(0);
Daniel Dunbardc6d5742010-04-21 19:10:51 +0000555}
556
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000557ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000558 ASTContext &Context,
559 llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000560 // FIXME: Set alignment on indirect arguments.
561 if (CodeGenFunction::hasAggregateLLVMType(Ty)) {
562 // Structures with flexible arrays are always indirect.
Anders Carlssona8874232010-01-27 03:25:19 +0000563 if (const RecordType *RT = Ty->getAs<RecordType>()) {
564 // Structures with either a non-trivial destructor or a non-trivial
565 // copy constructor are always indirect.
566 if (hasNonTrivialDestructorOrCopyConstructor(RT))
Daniel Dunbardc6d5742010-04-21 19:10:51 +0000567 return getIndirectResult(Ty, Context, /*ByVal=*/false);
568
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000569 if (RT->getDecl()->hasFlexibleArrayMember())
Daniel Dunbardc6d5742010-04-21 19:10:51 +0000570 return getIndirectResult(Ty, Context);
Anders Carlssona8874232010-01-27 03:25:19 +0000571 }
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000572
573 // Ignore empty structs.
Eli Friedmana1e6de92009-06-13 21:37:10 +0000574 if (Ty->isStructureType() && Context.getTypeSize(Ty) == 0)
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000575 return ABIArgInfo::getIgnore();
576
Daniel Dunbar53012f42009-11-09 01:33:53 +0000577 // Expand small (<= 128-bit) record types when we know that the stack layout
578 // of those arguments will match the struct. This is important because the
579 // LLVM backend isn't smart enough to remove byval, which inhibits many
580 // optimizations.
581 if (Context.getTypeSize(Ty) <= 4*32 &&
582 canExpandIndirectArgument(Ty, Context))
583 return ABIArgInfo::getExpand();
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000584
Daniel Dunbardc6d5742010-04-21 19:10:51 +0000585 return getIndirectResult(Ty, Context);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000586 } else {
Douglas Gregoraa74a1e2010-02-02 20:10:50 +0000587 if (const EnumType *EnumTy = Ty->getAs<EnumType>())
588 Ty = EnumTy->getDecl()->getIntegerType();
589
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +0000590 return (Ty->isPromotableIntegerType() ?
591 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000592 }
593}
594
595llvm::Value *X86_32ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
596 CodeGenFunction &CGF) const {
Benjamin Kramer3c0ef8c2009-10-13 10:07:13 +0000597 const llvm::Type *BP = llvm::Type::getInt8PtrTy(CGF.getLLVMContext());
Owen Anderson96e0fc72009-07-29 22:16:19 +0000598 const llvm::Type *BPP = llvm::PointerType::getUnqual(BP);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000599
600 CGBuilderTy &Builder = CGF.Builder;
601 llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP,
602 "ap");
603 llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
604 llvm::Type *PTy =
Owen Anderson96e0fc72009-07-29 22:16:19 +0000605 llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000606 llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
607
608 uint64_t Offset =
609 llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4);
610 llvm::Value *NextAddr =
Chris Lattner77b89b82010-06-27 07:15:29 +0000611 Builder.CreateGEP(Addr, llvm::ConstantInt::get(CGF.Int32Ty, Offset),
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000612 "ap.next");
613 Builder.CreateStore(NextAddr, VAListAddrAsBPP);
614
615 return AddrTyped;
616}
617
Charles Davis74f72932010-02-13 15:54:06 +0000618void X86_32TargetCodeGenInfo::SetTargetAttributes(const Decl *D,
619 llvm::GlobalValue *GV,
620 CodeGen::CodeGenModule &CGM) const {
621 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
622 if (FD->hasAttr<X86ForceAlignArgPointerAttr>()) {
623 // Get the LLVM function.
624 llvm::Function *Fn = cast<llvm::Function>(GV);
625
626 // Now add the 'alignstack' attribute with a value of 16.
627 Fn->addFnAttr(llvm::Attribute::constructStackAlignmentFromInt(16));
628 }
629 }
630}
631
John McCall6374c332010-03-06 00:35:14 +0000632bool X86_32TargetCodeGenInfo::initDwarfEHRegSizeTable(
633 CodeGen::CodeGenFunction &CGF,
634 llvm::Value *Address) const {
635 CodeGen::CGBuilderTy &Builder = CGF.Builder;
636 llvm::LLVMContext &Context = CGF.getLLVMContext();
637
638 const llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context);
639 llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4);
640
641 // 0-7 are the eight integer registers; the order is different
642 // on Darwin (for EH), but the range is the same.
643 // 8 is %eip.
John McCallaeeb7012010-05-27 06:19:26 +0000644 AssignToArrayRange(Builder, Address, Four8, 0, 8);
John McCall6374c332010-03-06 00:35:14 +0000645
646 if (CGF.CGM.isTargetDarwin()) {
647 // 12-16 are st(0..4). Not sure why we stop at 4.
648 // These have size 16, which is sizeof(long double) on
649 // platforms with 8-byte alignment for that type.
650 llvm::Value *Sixteen8 = llvm::ConstantInt::get(i8, 16);
John McCallaeeb7012010-05-27 06:19:26 +0000651 AssignToArrayRange(Builder, Address, Sixteen8, 12, 16);
John McCall6374c332010-03-06 00:35:14 +0000652
653 } else {
654 // 9 is %eflags, which doesn't get a size on Darwin for some
655 // reason.
656 Builder.CreateStore(Four8, Builder.CreateConstInBoundsGEP1_32(Address, 9));
657
658 // 11-16 are st(0..5). Not sure why we stop at 5.
659 // These have size 12, which is sizeof(long double) on
660 // platforms with 4-byte alignment for that type.
661 llvm::Value *Twelve8 = llvm::ConstantInt::get(i8, 12);
John McCallaeeb7012010-05-27 06:19:26 +0000662 AssignToArrayRange(Builder, Address, Twelve8, 11, 16);
663 }
John McCall6374c332010-03-06 00:35:14 +0000664
665 return false;
666}
667
Chris Lattnerdce5ad02010-06-28 20:05:43 +0000668//===----------------------------------------------------------------------===//
669// X86-64 ABI Implementation
670//===----------------------------------------------------------------------===//
671
672
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000673namespace {
674/// X86_64ABIInfo - The X86_64 ABI information.
675class X86_64ABIInfo : public ABIInfo {
Chris Lattner9c254f02010-06-29 06:01:59 +0000676 ASTContext &Context;
677 const llvm::TargetData &TD;
678
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000679 enum Class {
680 Integer = 0,
681 SSE,
682 SSEUp,
683 X87,
684 X87Up,
685 ComplexX87,
686 NoClass,
687 Memory
688 };
689
690 /// merge - Implement the X86_64 ABI merging algorithm.
691 ///
692 /// Merge an accumulating classification \arg Accum with a field
693 /// classification \arg Field.
694 ///
695 /// \param Accum - The accumulating classification. This should
696 /// always be either NoClass or the result of a previous merge
697 /// call. In addition, this should never be Memory (the caller
698 /// should just return Memory for the aggregate).
Chris Lattner1090a9b2010-06-28 21:43:59 +0000699 static Class merge(Class Accum, Class Field);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000700
701 /// classify - Determine the x86_64 register classes in which the
702 /// given type T should be passed.
703 ///
704 /// \param Lo - The classification for the parts of the type
705 /// residing in the low word of the containing object.
706 ///
707 /// \param Hi - The classification for the parts of the type
708 /// residing in the high word of the containing object.
709 ///
710 /// \param OffsetBase - The bit offset of this type in the
711 /// containing object. Some parameters are classified different
712 /// depending on whether they straddle an eightbyte boundary.
713 ///
714 /// If a word is unused its result will be NoClass; if a type should
715 /// be passed in Memory then at least the classification of \arg Lo
716 /// will be Memory.
717 ///
718 /// The \arg Lo class will be NoClass iff the argument is ignored.
719 ///
720 /// If the \arg Lo class is ComplexX87, then the \arg Hi class will
721 /// also be ComplexX87.
Chris Lattner9c254f02010-06-29 06:01:59 +0000722 void classify(QualType T, uint64_t OffsetBase, Class &Lo, Class &Hi) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000723
724 /// getCoerceResult - Given a source type \arg Ty and an LLVM type
725 /// to coerce to, chose the best way to pass Ty in the same place
726 /// that \arg CoerceTo would be passed, but while keeping the
727 /// emitted code as simple as possible.
728 ///
729 /// FIXME: Note, this should be cleaned up to just take an enumeration of all
730 /// the ways we might want to pass things, instead of constructing an LLVM
731 /// type. This makes this code more explicit, and it makes it clearer that we
732 /// are also doing this for correctness in the case of passing scalar types.
733 ABIArgInfo getCoerceResult(QualType Ty,
Chris Lattner9c254f02010-06-29 06:01:59 +0000734 const llvm::Type *CoerceTo) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000735
736 /// getIndirectResult - Give a source type \arg Ty, return a suitable result
Daniel Dunbar46c54fb2010-04-21 19:49:55 +0000737 /// such that the argument will be returned in memory.
Chris Lattner9c254f02010-06-29 06:01:59 +0000738 ABIArgInfo getIndirectReturnResult(QualType Ty) const;
Daniel Dunbar46c54fb2010-04-21 19:49:55 +0000739
740 /// getIndirectResult - Give a source type \arg Ty, return a suitable result
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000741 /// such that the argument will be passed in memory.
Chris Lattner9c254f02010-06-29 06:01:59 +0000742 ABIArgInfo getIndirectResult(QualType Ty) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000743
744 ABIArgInfo classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000745 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000746
747 ABIArgInfo classifyArgumentType(QualType Ty,
Owen Andersona1cf15f2009-07-14 23:10:40 +0000748 llvm::LLVMContext &VMContext,
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000749 unsigned &neededInt,
Chris Lattnera159c2e2010-06-29 01:14:09 +0000750 unsigned &neededSSE,
751 const llvm::Type *PrefType) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000752
753public:
Chris Lattner9c254f02010-06-29 06:01:59 +0000754 X86_64ABIInfo(ASTContext &Ctx, const llvm::TargetData &td)
755 : Context(Ctx), TD(td) {}
756
Owen Andersona1cf15f2009-07-14 23:10:40 +0000757 virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context,
Chris Lattner8640cd62010-06-29 01:08:48 +0000758 llvm::LLVMContext &VMContext,
759 const llvm::Type *const *PrefTypes,
760 unsigned NumPrefTypes) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000761
762 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
763 CodeGenFunction &CGF) const;
764};
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000765
766class X86_64TargetCodeGenInfo : public TargetCodeGenInfo {
767public:
Chris Lattner9c254f02010-06-29 06:01:59 +0000768 X86_64TargetCodeGenInfo(ASTContext &Ctx, const llvm::TargetData &TD)
769 : TargetCodeGenInfo(new X86_64ABIInfo(Ctx, TD)) {}
John McCall6374c332010-03-06 00:35:14 +0000770
771 int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const {
772 return 7;
773 }
774
775 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
776 llvm::Value *Address) const {
777 CodeGen::CGBuilderTy &Builder = CGF.Builder;
778 llvm::LLVMContext &Context = CGF.getLLVMContext();
779
780 const llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context);
781 llvm::Value *Eight8 = llvm::ConstantInt::get(i8, 8);
782
John McCallaeeb7012010-05-27 06:19:26 +0000783 // 0-15 are the 16 integer registers.
784 // 16 is %rip.
785 AssignToArrayRange(Builder, Address, Eight8, 0, 16);
John McCall6374c332010-03-06 00:35:14 +0000786
787 return false;
788 }
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000789};
790
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000791}
792
Chris Lattner1090a9b2010-06-28 21:43:59 +0000793X86_64ABIInfo::Class X86_64ABIInfo::merge(Class Accum, Class Field) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000794 // AMD64-ABI 3.2.3p2: Rule 4. Each field of an object is
795 // classified recursively so that always two fields are
796 // considered. The resulting class is calculated according to
797 // the classes of the fields in the eightbyte:
798 //
799 // (a) If both classes are equal, this is the resulting class.
800 //
801 // (b) If one of the classes is NO_CLASS, the resulting class is
802 // the other class.
803 //
804 // (c) If one of the classes is MEMORY, the result is the MEMORY
805 // class.
806 //
807 // (d) If one of the classes is INTEGER, the result is the
808 // INTEGER.
809 //
810 // (e) If one of the classes is X87, X87UP, COMPLEX_X87 class,
811 // MEMORY is used as class.
812 //
813 // (f) Otherwise class SSE is used.
814
815 // Accum should never be memory (we should have returned) or
816 // ComplexX87 (because this cannot be passed in a structure).
817 assert((Accum != Memory && Accum != ComplexX87) &&
818 "Invalid accumulated classification during merge.");
819 if (Accum == Field || Field == NoClass)
820 return Accum;
Chris Lattner1090a9b2010-06-28 21:43:59 +0000821 if (Field == Memory)
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000822 return Memory;
Chris Lattner1090a9b2010-06-28 21:43:59 +0000823 if (Accum == NoClass)
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000824 return Field;
Chris Lattner1090a9b2010-06-28 21:43:59 +0000825 if (Accum == Integer || Field == Integer)
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000826 return Integer;
Chris Lattner1090a9b2010-06-28 21:43:59 +0000827 if (Field == X87 || Field == X87Up || Field == ComplexX87 ||
828 Accum == X87 || Accum == X87Up)
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000829 return Memory;
Chris Lattner1090a9b2010-06-28 21:43:59 +0000830 return SSE;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000831}
832
Chris Lattnerbcaedae2010-06-30 19:14:05 +0000833void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase,
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000834 Class &Lo, Class &Hi) const {
835 // FIXME: This code can be simplified by introducing a simple value class for
836 // Class pairs with appropriate constructor methods for the various
837 // situations.
838
839 // FIXME: Some of the split computations are wrong; unaligned vectors
840 // shouldn't be passed in registers for example, so there is no chance they
841 // can straddle an eightbyte. Verify & simplify.
842
843 Lo = Hi = NoClass;
844
845 Class &Current = OffsetBase < 64 ? Lo : Hi;
846 Current = Memory;
847
John McCall183700f2009-09-21 23:43:11 +0000848 if (const BuiltinType *BT = Ty->getAs<BuiltinType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000849 BuiltinType::Kind k = BT->getKind();
850
851 if (k == BuiltinType::Void) {
852 Current = NoClass;
853 } else if (k == BuiltinType::Int128 || k == BuiltinType::UInt128) {
854 Lo = Integer;
855 Hi = Integer;
856 } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
857 Current = Integer;
858 } else if (k == BuiltinType::Float || k == BuiltinType::Double) {
859 Current = SSE;
860 } else if (k == BuiltinType::LongDouble) {
861 Lo = X87;
862 Hi = X87Up;
863 }
864 // FIXME: _Decimal32 and _Decimal64 are SSE.
865 // FIXME: _float128 and _Decimal128 are (SSE, SSEUp).
Chris Lattner1090a9b2010-06-28 21:43:59 +0000866 return;
867 }
868
869 if (const EnumType *ET = Ty->getAs<EnumType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000870 // Classify the underlying integer type.
Chris Lattner9c254f02010-06-29 06:01:59 +0000871 classify(ET->getDecl()->getIntegerType(), OffsetBase, Lo, Hi);
Chris Lattner1090a9b2010-06-28 21:43:59 +0000872 return;
873 }
874
875 if (Ty->hasPointerRepresentation()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000876 Current = Integer;
Chris Lattner1090a9b2010-06-28 21:43:59 +0000877 return;
878 }
879
880 if (Ty->isMemberPointerType()) {
Daniel Dunbar67d438d2010-05-15 00:00:37 +0000881 if (Ty->isMemberFunctionPointerType())
882 Lo = Hi = Integer;
883 else
884 Current = Integer;
Chris Lattner1090a9b2010-06-28 21:43:59 +0000885 return;
886 }
887
888 if (const VectorType *VT = Ty->getAs<VectorType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000889 uint64_t Size = Context.getTypeSize(VT);
890 if (Size == 32) {
891 // gcc passes all <4 x char>, <2 x short>, <1 x int>, <1 x
892 // float> as integer.
893 Current = Integer;
894
895 // If this type crosses an eightbyte boundary, it should be
896 // split.
897 uint64_t EB_Real = (OffsetBase) / 64;
898 uint64_t EB_Imag = (OffsetBase + Size - 1) / 64;
899 if (EB_Real != EB_Imag)
900 Hi = Lo;
901 } else if (Size == 64) {
902 // gcc passes <1 x double> in memory. :(
903 if (VT->getElementType()->isSpecificBuiltinType(BuiltinType::Double))
904 return;
905
906 // gcc passes <1 x long long> as INTEGER.
907 if (VT->getElementType()->isSpecificBuiltinType(BuiltinType::LongLong))
908 Current = Integer;
909 else
910 Current = SSE;
911
912 // If this type crosses an eightbyte boundary, it should be
913 // split.
914 if (OffsetBase && OffsetBase != 64)
915 Hi = Lo;
916 } else if (Size == 128) {
917 Lo = SSE;
918 Hi = SSEUp;
919 }
Chris Lattner1090a9b2010-06-28 21:43:59 +0000920 return;
921 }
922
923 if (const ComplexType *CT = Ty->getAs<ComplexType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000924 QualType ET = Context.getCanonicalType(CT->getElementType());
925
926 uint64_t Size = Context.getTypeSize(Ty);
Douglas Gregor2ade35e2010-06-16 00:17:44 +0000927 if (ET->isIntegralOrEnumerationType()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000928 if (Size <= 64)
929 Current = Integer;
930 else if (Size <= 128)
931 Lo = Hi = Integer;
932 } else if (ET == Context.FloatTy)
933 Current = SSE;
934 else if (ET == Context.DoubleTy)
935 Lo = Hi = SSE;
936 else if (ET == Context.LongDoubleTy)
937 Current = ComplexX87;
938
939 // If this complex type crosses an eightbyte boundary then it
940 // should be split.
941 uint64_t EB_Real = (OffsetBase) / 64;
942 uint64_t EB_Imag = (OffsetBase + Context.getTypeSize(ET)) / 64;
943 if (Hi == NoClass && EB_Real != EB_Imag)
944 Hi = Lo;
Chris Lattner1090a9b2010-06-28 21:43:59 +0000945
946 return;
947 }
948
949 if (const ConstantArrayType *AT = Context.getAsConstantArrayType(Ty)) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000950 // Arrays are treated like structures.
951
952 uint64_t Size = Context.getTypeSize(Ty);
953
954 // AMD64-ABI 3.2.3p2: Rule 1. If the size of an object is larger
955 // than two eightbytes, ..., it has class MEMORY.
956 if (Size > 128)
957 return;
958
959 // AMD64-ABI 3.2.3p2: Rule 1. If ..., or it contains unaligned
960 // fields, it has class MEMORY.
961 //
962 // Only need to check alignment of array base.
963 if (OffsetBase % Context.getTypeAlign(AT->getElementType()))
964 return;
965
966 // Otherwise implement simplified merge. We could be smarter about
967 // this, but it isn't worth it and would be harder to verify.
968 Current = NoClass;
969 uint64_t EltSize = Context.getTypeSize(AT->getElementType());
970 uint64_t ArraySize = AT->getSize().getZExtValue();
971 for (uint64_t i=0, Offset=OffsetBase; i<ArraySize; ++i, Offset += EltSize) {
972 Class FieldLo, FieldHi;
Chris Lattner9c254f02010-06-29 06:01:59 +0000973 classify(AT->getElementType(), Offset, FieldLo, FieldHi);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000974 Lo = merge(Lo, FieldLo);
975 Hi = merge(Hi, FieldHi);
976 if (Lo == Memory || Hi == Memory)
977 break;
978 }
979
980 // Do post merger cleanup (see below). Only case we worry about is Memory.
981 if (Hi == Memory)
982 Lo = Memory;
983 assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp array classification.");
Chris Lattner1090a9b2010-06-28 21:43:59 +0000984 return;
985 }
986
987 if (const RecordType *RT = Ty->getAs<RecordType>()) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +0000988 uint64_t Size = Context.getTypeSize(Ty);
989
990 // AMD64-ABI 3.2.3p2: Rule 1. If the size of an object is larger
991 // than two eightbytes, ..., it has class MEMORY.
992 if (Size > 128)
993 return;
994
Anders Carlsson0a8f8472009-09-16 15:53:40 +0000995 // AMD64-ABI 3.2.3p2: Rule 2. If a C++ object has either a non-trivial
996 // copy constructor or a non-trivial destructor, it is passed by invisible
997 // reference.
998 if (hasNonTrivialDestructorOrCopyConstructor(RT))
999 return;
Daniel Dunbarce9f4232009-11-22 23:01:23 +00001000
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001001 const RecordDecl *RD = RT->getDecl();
1002
1003 // Assume variable sized types are passed in memory.
1004 if (RD->hasFlexibleArrayMember())
1005 return;
1006
1007 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
1008
1009 // Reset Lo class, this will be recomputed.
1010 Current = NoClass;
Daniel Dunbarce9f4232009-11-22 23:01:23 +00001011
1012 // If this is a C++ record, classify the bases first.
1013 if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
1014 for (CXXRecordDecl::base_class_const_iterator i = CXXRD->bases_begin(),
1015 e = CXXRD->bases_end(); i != e; ++i) {
1016 assert(!i->isVirtual() && !i->getType()->isDependentType() &&
1017 "Unexpected base class!");
1018 const CXXRecordDecl *Base =
1019 cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
1020
1021 // Classify this field.
1022 //
1023 // AMD64-ABI 3.2.3p2: Rule 3. If the size of the aggregate exceeds a
1024 // single eightbyte, each is classified separately. Each eightbyte gets
1025 // initialized to class NO_CLASS.
1026 Class FieldLo, FieldHi;
1027 uint64_t Offset = OffsetBase + Layout.getBaseClassOffset(Base);
Chris Lattner9c254f02010-06-29 06:01:59 +00001028 classify(i->getType(), Offset, FieldLo, FieldHi);
Daniel Dunbarce9f4232009-11-22 23:01:23 +00001029 Lo = merge(Lo, FieldLo);
1030 Hi = merge(Hi, FieldHi);
1031 if (Lo == Memory || Hi == Memory)
1032 break;
1033 }
Daniel Dunbar4971ff82009-12-22 01:19:25 +00001034
1035 // If this record has no fields but isn't empty, classify as INTEGER.
1036 if (RD->field_empty() && Size)
1037 Current = Integer;
Daniel Dunbarce9f4232009-11-22 23:01:23 +00001038 }
1039
1040 // Classify the fields one at a time, merging the results.
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001041 unsigned idx = 0;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001042 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
1043 i != e; ++i, ++idx) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001044 uint64_t Offset = OffsetBase + Layout.getFieldOffset(idx);
1045 bool BitField = i->isBitField();
1046
1047 // AMD64-ABI 3.2.3p2: Rule 1. If ..., or it contains unaligned
1048 // fields, it has class MEMORY.
1049 //
1050 // Note, skip this test for bit-fields, see below.
1051 if (!BitField && Offset % Context.getTypeAlign(i->getType())) {
1052 Lo = Memory;
1053 return;
1054 }
1055
1056 // Classify this field.
1057 //
1058 // AMD64-ABI 3.2.3p2: Rule 3. If the size of the aggregate
1059 // exceeds a single eightbyte, each is classified
1060 // separately. Each eightbyte gets initialized to class
1061 // NO_CLASS.
1062 Class FieldLo, FieldHi;
1063
1064 // Bit-fields require special handling, they do not force the
1065 // structure to be passed in memory even if unaligned, and
1066 // therefore they can straddle an eightbyte.
1067 if (BitField) {
1068 // Ignore padding bit-fields.
1069 if (i->isUnnamedBitfield())
1070 continue;
1071
1072 uint64_t Offset = OffsetBase + Layout.getFieldOffset(idx);
1073 uint64_t Size = i->getBitWidth()->EvaluateAsInt(Context).getZExtValue();
1074
1075 uint64_t EB_Lo = Offset / 64;
1076 uint64_t EB_Hi = (Offset + Size - 1) / 64;
1077 FieldLo = FieldHi = NoClass;
1078 if (EB_Lo) {
1079 assert(EB_Hi == EB_Lo && "Invalid classification, type > 16 bytes.");
1080 FieldLo = NoClass;
1081 FieldHi = Integer;
1082 } else {
1083 FieldLo = Integer;
1084 FieldHi = EB_Hi ? Integer : NoClass;
1085 }
1086 } else
Chris Lattner9c254f02010-06-29 06:01:59 +00001087 classify(i->getType(), Offset, FieldLo, FieldHi);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001088 Lo = merge(Lo, FieldLo);
1089 Hi = merge(Hi, FieldHi);
1090 if (Lo == Memory || Hi == Memory)
1091 break;
1092 }
1093
1094 // AMD64-ABI 3.2.3p2: Rule 5. Then a post merger cleanup is done:
1095 //
1096 // (a) If one of the classes is MEMORY, the whole argument is
1097 // passed in memory.
1098 //
1099 // (b) If SSEUP is not preceeded by SSE, it is converted to SSE.
1100
1101 // The first of these conditions is guaranteed by how we implement
1102 // the merge (just bail).
1103 //
1104 // The second condition occurs in the case of unions; for example
1105 // union { _Complex double; unsigned; }.
1106 if (Hi == Memory)
1107 Lo = Memory;
1108 if (Hi == SSEUp && Lo != SSE)
1109 Hi = SSE;
1110 }
1111}
1112
1113ABIArgInfo X86_64ABIInfo::getCoerceResult(QualType Ty,
Chris Lattner9c254f02010-06-29 06:01:59 +00001114 const llvm::Type *CoerceTo) const {
Chris Lattner1daf8082010-07-28 22:15:08 +00001115 // If this is a pointer passed as a pointer, just pass it directly.
1116 if ((isa<llvm::PointerType>(CoerceTo) || CoerceTo->isIntegerTy(64)) &&
1117 Ty->hasPointerRepresentation())
1118 return ABIArgInfo::getExtend();
1119
1120 if (isa<llvm::IntegerType>(CoerceTo)) {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001121 // Integer and pointer types will end up in a general purpose
1122 // register.
Douglas Gregoraa74a1e2010-02-02 20:10:50 +00001123
1124 // Treat an enum type as its underlying type.
1125 if (const EnumType *EnumTy = Ty->getAs<EnumType>())
1126 Ty = EnumTy->getDecl()->getIntegerType();
1127
Chris Lattner1daf8082010-07-28 22:15:08 +00001128 if (Ty->isIntegralOrEnumerationType())
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +00001129 return (Ty->isPromotableIntegerType() ?
1130 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Chris Lattnerfaf23b72010-06-28 19:56:59 +00001131
Chris Lattner1daf8082010-07-28 22:15:08 +00001132 // FIXME: Zap this.
1133
Chris Lattner8ff29642010-06-28 21:59:07 +00001134 // If this is a 8/16/32-bit structure that is passed as an int64, then it
1135 // will be passed in the low 8/16/32-bits of a 64-bit GPR, which is the same
1136 // as how an i8/i16/i32 is passed. Coerce to a i8/i16/i32 instead of a i64.
1137 switch (Context.getTypeSizeInChars(Ty).getQuantity()) {
1138 default: break;
1139 case 1: CoerceTo = llvm::Type::getInt8Ty(CoerceTo->getContext()); break;
1140 case 2: CoerceTo = llvm::Type::getInt16Ty(CoerceTo->getContext()); break;
1141 case 4: CoerceTo = llvm::Type::getInt32Ty(CoerceTo->getContext()); break;
1142 }
Chris Lattnerfaf23b72010-06-28 19:56:59 +00001143
Chris Lattner7f215c12010-06-26 21:52:32 +00001144 } else if (CoerceTo->isDoubleTy()) {
John McCall0b0ef0a2010-02-24 07:14:12 +00001145 assert(Ty.isCanonical() && "should always have a canonical type here");
1146 assert(!Ty.hasQualifiers() && "should never have a qualified type here");
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001147
1148 // Float and double end up in a single SSE reg.
John McCall0b0ef0a2010-02-24 07:14:12 +00001149 if (Ty == Context.FloatTy || Ty == Context.DoubleTy)
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001150 return ABIArgInfo::getDirect();
1151
Chris Lattnerfaf23b72010-06-28 19:56:59 +00001152 // If this is a 32-bit structure that is passed as a double, then it will be
1153 // passed in the low 32-bits of the XMM register, which is the same as how a
1154 // float is passed. Coerce to a float instead of a double.
1155 if (Context.getTypeSizeInChars(Ty).getQuantity() == 4)
1156 CoerceTo = llvm::Type::getFloatTy(CoerceTo->getContext());
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001157 }
1158
1159 return ABIArgInfo::getCoerce(CoerceTo);
1160}
1161
Chris Lattner9c254f02010-06-29 06:01:59 +00001162ABIArgInfo X86_64ABIInfo::getIndirectReturnResult(QualType Ty) const {
Daniel Dunbar46c54fb2010-04-21 19:49:55 +00001163 // If this is a scalar LLVM value then assume LLVM will pass it in the right
1164 // place naturally.
1165 if (!CodeGenFunction::hasAggregateLLVMType(Ty)) {
1166 // Treat an enum type as its underlying type.
1167 if (const EnumType *EnumTy = Ty->getAs<EnumType>())
1168 Ty = EnumTy->getDecl()->getIntegerType();
1169
1170 return (Ty->isPromotableIntegerType() ?
1171 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
1172 }
1173
1174 return ABIArgInfo::getIndirect(0);
1175}
1176
Chris Lattner9c254f02010-06-29 06:01:59 +00001177ABIArgInfo X86_64ABIInfo::getIndirectResult(QualType Ty) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001178 // If this is a scalar LLVM value then assume LLVM will pass it in the right
1179 // place naturally.
Douglas Gregoraa74a1e2010-02-02 20:10:50 +00001180 if (!CodeGenFunction::hasAggregateLLVMType(Ty)) {
1181 // Treat an enum type as its underlying type.
1182 if (const EnumType *EnumTy = Ty->getAs<EnumType>())
1183 Ty = EnumTy->getDecl()->getIntegerType();
1184
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +00001185 return (Ty->isPromotableIntegerType() ?
1186 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Douglas Gregoraa74a1e2010-02-02 20:10:50 +00001187 }
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001188
Daniel Dunbar46c54fb2010-04-21 19:49:55 +00001189 if (isRecordWithNonTrivialDestructorOrCopyConstructor(Ty))
1190 return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
Anders Carlsson0a8f8472009-09-16 15:53:40 +00001191
Daniel Dunbar46c54fb2010-04-21 19:49:55 +00001192 // Compute the byval alignment. We trust the back-end to honor the
1193 // minimum ABI alignment for byval, to make cleaner IR.
1194 const unsigned MinABIAlign = 8;
1195 unsigned Align = Context.getTypeAlign(Ty) / 8;
1196 if (Align > MinABIAlign)
1197 return ABIArgInfo::getIndirect(Align);
1198 return ABIArgInfo::getIndirect(0);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001199}
1200
Chris Lattner1090a9b2010-06-28 21:43:59 +00001201ABIArgInfo X86_64ABIInfo::
Chris Lattner9c254f02010-06-29 06:01:59 +00001202classifyReturnType(QualType RetTy, llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001203 // AMD64-ABI 3.2.3p4: Rule 1. Classify the return type with the
1204 // classification algorithm.
1205 X86_64ABIInfo::Class Lo, Hi;
Chris Lattner9c254f02010-06-29 06:01:59 +00001206 classify(RetTy, 0, Lo, Hi);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001207
1208 // Check some invariants.
1209 assert((Hi != Memory || Lo == Memory) && "Invalid memory classification.");
1210 assert((Lo != NoClass || Hi == NoClass) && "Invalid null classification.");
1211 assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp classification.");
1212
1213 const llvm::Type *ResType = 0;
1214 switch (Lo) {
1215 case NoClass:
1216 return ABIArgInfo::getIgnore();
1217
1218 case SSEUp:
1219 case X87Up:
1220 assert(0 && "Invalid classification for lo word.");
1221
1222 // AMD64-ABI 3.2.3p4: Rule 2. Types of class memory are returned via
1223 // hidden argument.
1224 case Memory:
Chris Lattner9c254f02010-06-29 06:01:59 +00001225 return getIndirectReturnResult(RetTy);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001226
1227 // AMD64-ABI 3.2.3p4: Rule 3. If the class is INTEGER, the next
1228 // available register of the sequence %rax, %rdx is used.
1229 case Integer:
Owen Anderson0032b272009-08-13 21:57:51 +00001230 ResType = llvm::Type::getInt64Ty(VMContext); break;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001231
1232 // AMD64-ABI 3.2.3p4: Rule 4. If the class is SSE, the next
1233 // available SSE register of the sequence %xmm0, %xmm1 is used.
1234 case SSE:
Owen Anderson0032b272009-08-13 21:57:51 +00001235 ResType = llvm::Type::getDoubleTy(VMContext); break;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001236
1237 // AMD64-ABI 3.2.3p4: Rule 6. If the class is X87, the value is
1238 // returned on the X87 stack in %st0 as 80-bit x87 number.
1239 case X87:
Owen Anderson0032b272009-08-13 21:57:51 +00001240 ResType = llvm::Type::getX86_FP80Ty(VMContext); break;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001241
1242 // AMD64-ABI 3.2.3p4: Rule 8. If the class is COMPLEX_X87, the real
1243 // part of the value is returned in %st0 and the imaginary part in
1244 // %st1.
1245 case ComplexX87:
1246 assert(Hi == ComplexX87 && "Unexpected ComplexX87 classification.");
Chris Lattner52d9ae32010-04-06 17:29:22 +00001247 ResType = llvm::StructType::get(VMContext,
1248 llvm::Type::getX86_FP80Ty(VMContext),
Owen Anderson0032b272009-08-13 21:57:51 +00001249 llvm::Type::getX86_FP80Ty(VMContext),
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001250 NULL);
1251 break;
1252 }
1253
1254 switch (Hi) {
1255 // Memory was handled previously and X87 should
1256 // never occur as a hi class.
1257 case Memory:
1258 case X87:
1259 assert(0 && "Invalid classification for hi word.");
1260
1261 case ComplexX87: // Previously handled.
1262 case NoClass: break;
1263
1264 case Integer:
Owen Anderson47a434f2009-08-05 23:18:46 +00001265 ResType = llvm::StructType::get(VMContext, ResType,
Owen Anderson0032b272009-08-13 21:57:51 +00001266 llvm::Type::getInt64Ty(VMContext), NULL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001267 break;
1268 case SSE:
Owen Anderson47a434f2009-08-05 23:18:46 +00001269 ResType = llvm::StructType::get(VMContext, ResType,
Owen Anderson0032b272009-08-13 21:57:51 +00001270 llvm::Type::getDoubleTy(VMContext), NULL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001271 break;
1272
1273 // AMD64-ABI 3.2.3p4: Rule 5. If the class is SSEUP, the eightbyte
1274 // is passed in the upper half of the last used SSE register.
1275 //
1276 // SSEUP should always be preceeded by SSE, just widen.
1277 case SSEUp:
1278 assert(Lo == SSE && "Unexpected SSEUp classification.");
Owen Anderson0032b272009-08-13 21:57:51 +00001279 ResType = llvm::VectorType::get(llvm::Type::getDoubleTy(VMContext), 2);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001280 break;
1281
1282 // AMD64-ABI 3.2.3p4: Rule 7. If the class is X87UP, the value is
1283 // returned together with the previous X87 value in %st0.
1284 case X87Up:
1285 // If X87Up is preceeded by X87, we don't need to do
1286 // anything. However, in some cases with unions it may not be
1287 // preceeded by X87. In such situations we follow gcc and pass the
1288 // extra bits in an SSE reg.
1289 if (Lo != X87)
Owen Anderson47a434f2009-08-05 23:18:46 +00001290 ResType = llvm::StructType::get(VMContext, ResType,
Owen Anderson0032b272009-08-13 21:57:51 +00001291 llvm::Type::getDoubleTy(VMContext), NULL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001292 break;
1293 }
1294
Chris Lattner9c254f02010-06-29 06:01:59 +00001295 return getCoerceResult(RetTy, ResType);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001296}
1297
Chris Lattner9c254f02010-06-29 06:01:59 +00001298static const llvm::Type *Get8ByteTypeAtOffset(const llvm::Type *PrefType,
1299 unsigned Offset,
1300 const llvm::TargetData &TD) {
1301 if (PrefType == 0) return 0;
1302
1303 // Pointers are always 8-bytes at offset 0.
1304 if (Offset == 0 && isa<llvm::PointerType>(PrefType))
1305 return PrefType;
1306
1307 // TODO: 1/2/4/8 byte integers are also interesting, but we have to know that
1308 // the "hole" is not used in the containing struct (just undef padding).
1309 const llvm::StructType *STy = dyn_cast<llvm::StructType>(PrefType);
1310 if (STy == 0) return 0;
1311
1312 // If this is a struct, recurse into the field at the specified offset.
1313 const llvm::StructLayout *SL = TD.getStructLayout(STy);
1314 if (Offset >= SL->getSizeInBytes()) return 0;
1315
1316 unsigned FieldIdx = SL->getElementContainingOffset(Offset);
1317 Offset -= SL->getElementOffset(FieldIdx);
1318
1319 return Get8ByteTypeAtOffset(STy->getElementType(FieldIdx), Offset, TD);
1320}
1321
1322ABIArgInfo X86_64ABIInfo::classifyArgumentType(QualType Ty,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001323 llvm::LLVMContext &VMContext,
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001324 unsigned &neededInt,
Chris Lattnera159c2e2010-06-29 01:14:09 +00001325 unsigned &neededSSE,
1326 const llvm::Type *PrefType)const{
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001327 X86_64ABIInfo::Class Lo, Hi;
Chris Lattner9c254f02010-06-29 06:01:59 +00001328 classify(Ty, 0, Lo, Hi);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001329
Chris Lattner1daf8082010-07-28 22:15:08 +00001330 uint64_t TySizeInBytes = Context.getTypeSizeInChars(Ty).getQuantity();
1331
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001332 // Check some invariants.
1333 // FIXME: Enforce these by construction.
1334 assert((Hi != Memory || Lo == Memory) && "Invalid memory classification.");
1335 assert((Lo != NoClass || Hi == NoClass) && "Invalid null classification.");
1336 assert((Hi != SSEUp || Lo == SSE) && "Invalid SSEUp classification.");
1337
1338 neededInt = 0;
1339 neededSSE = 0;
1340 const llvm::Type *ResType = 0;
1341 switch (Lo) {
1342 case NoClass:
1343 return ABIArgInfo::getIgnore();
1344
1345 // AMD64-ABI 3.2.3p3: Rule 1. If the class is MEMORY, pass the argument
1346 // on the stack.
1347 case Memory:
1348
1349 // AMD64-ABI 3.2.3p3: Rule 5. If the class is X87, X87UP or
1350 // COMPLEX_X87, it is passed in memory.
1351 case X87:
1352 case ComplexX87:
Chris Lattner9c254f02010-06-29 06:01:59 +00001353 return getIndirectResult(Ty);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001354
1355 case SSEUp:
1356 case X87Up:
1357 assert(0 && "Invalid classification for lo word.");
1358
1359 // AMD64-ABI 3.2.3p3: Rule 2. If the class is INTEGER, the next
1360 // available register of the sequence %rdi, %rsi, %rdx, %rcx, %r8
1361 // and %r9 is used.
1362 case Integer:
Chris Lattner9c254f02010-06-29 06:01:59 +00001363 ++neededInt;
1364
1365 // If we can choose a better 8-byte type based on the preferred type, and if
1366 // that type is still passed in a GPR, use it.
1367 if (const llvm::Type *PrefTypeLo = Get8ByteTypeAtOffset(PrefType, 0, TD))
1368 if (isa<llvm::IntegerType>(PrefTypeLo) ||
1369 isa<llvm::PointerType>(PrefTypeLo))
1370 ResType = PrefTypeLo;
Chris Lattner1daf8082010-07-28 22:15:08 +00001371
1372 if (ResType == 0) {
1373 // It is always safe to classify this as an integer type up to i64 that
1374 // isn't larger than the structure.
1375 if (TySizeInBytes == 1)
1376 ResType = llvm::Type::getInt8Ty(VMContext);
1377 else if (TySizeInBytes == 2)
1378 ResType = llvm::Type::getInt16Ty(VMContext);
1379 else if (TySizeInBytes <= 4)
1380 ResType = llvm::Type::getInt32Ty(VMContext);
1381 else
1382 ResType = llvm::Type::getInt64Ty(VMContext);
1383 }
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001384 break;
1385
1386 // AMD64-ABI 3.2.3p3: Rule 3. If the class is SSE, the next
1387 // available SSE register is used, the registers are taken in the
1388 // order from %xmm0 to %xmm7.
1389 case SSE:
1390 ++neededSSE;
Owen Anderson0032b272009-08-13 21:57:51 +00001391 ResType = llvm::Type::getDoubleTy(VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001392 break;
1393 }
1394
1395 switch (Hi) {
1396 // Memory was handled previously, ComplexX87 and X87 should
1397 // never occur as hi classes, and X87Up must be preceed by X87,
1398 // which is passed in memory.
1399 case Memory:
1400 case X87:
1401 case ComplexX87:
1402 assert(0 && "Invalid classification for hi word.");
1403 break;
1404
1405 case NoClass: break;
Chris Lattner9c254f02010-06-29 06:01:59 +00001406
1407 case Integer: {
Chris Lattner1daf8082010-07-28 22:15:08 +00001408 const llvm::Type *HiType = 0;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001409 ++neededInt;
Chris Lattner9c254f02010-06-29 06:01:59 +00001410
1411 // If we can choose a better 8-byte type based on the preferred type, and if
1412 // that type is still passed in a GPR, use it.
1413 if (const llvm::Type *PrefTypeHi = Get8ByteTypeAtOffset(PrefType, 8, TD))
1414 if (isa<llvm::IntegerType>(PrefTypeHi) ||
1415 isa<llvm::PointerType>(PrefTypeHi))
1416 HiType = PrefTypeHi;
Chris Lattner1daf8082010-07-28 22:15:08 +00001417
1418 if (HiType == 0) {
1419 // It is always safe to classify this as an integer type up to i64 that
1420 // isn't larger than the structure.
1421 if (TySizeInBytes == 9)
1422 HiType = llvm::Type::getInt8Ty(VMContext);
1423 else if (TySizeInBytes == 10)
1424 HiType = llvm::Type::getInt16Ty(VMContext);
1425 else if (TySizeInBytes <= 12)
1426 HiType = llvm::Type::getInt32Ty(VMContext);
1427 else
1428 HiType = llvm::Type::getInt64Ty(VMContext);
1429 }
1430
Chris Lattner9c254f02010-06-29 06:01:59 +00001431 ResType = llvm::StructType::get(VMContext, ResType, HiType, NULL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001432 break;
Chris Lattner9c254f02010-06-29 06:01:59 +00001433 }
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001434
1435 // X87Up generally doesn't occur here (long double is passed in
1436 // memory), except in situations involving unions.
1437 case X87Up:
1438 case SSE:
Owen Anderson47a434f2009-08-05 23:18:46 +00001439 ResType = llvm::StructType::get(VMContext, ResType,
Owen Anderson0032b272009-08-13 21:57:51 +00001440 llvm::Type::getDoubleTy(VMContext), NULL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001441 ++neededSSE;
1442 break;
1443
1444 // AMD64-ABI 3.2.3p3: Rule 4. If the class is SSEUP, the
1445 // eightbyte is passed in the upper half of the last used SSE
1446 // register.
1447 case SSEUp:
1448 assert(Lo == SSE && "Unexpected SSEUp classification.");
Owen Anderson0032b272009-08-13 21:57:51 +00001449 ResType = llvm::VectorType::get(llvm::Type::getDoubleTy(VMContext), 2);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001450 break;
1451 }
1452
Chris Lattner9c254f02010-06-29 06:01:59 +00001453 return getCoerceResult(Ty, ResType);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001454}
1455
Owen Andersona1cf15f2009-07-14 23:10:40 +00001456void X86_64ABIInfo::computeInfo(CGFunctionInfo &FI, ASTContext &Context,
Chris Lattner8640cd62010-06-29 01:08:48 +00001457 llvm::LLVMContext &VMContext,
1458 const llvm::Type *const *PrefTypes,
1459 unsigned NumPrefTypes) const {
Chris Lattner9c254f02010-06-29 06:01:59 +00001460 FI.getReturnInfo() = classifyReturnType(FI.getReturnType(), VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001461
1462 // Keep track of the number of assigned registers.
1463 unsigned freeIntRegs = 6, freeSSERegs = 8;
1464
1465 // If the return value is indirect, then the hidden argument is consuming one
1466 // integer register.
1467 if (FI.getReturnInfo().isIndirect())
1468 --freeIntRegs;
1469
1470 // AMD64-ABI 3.2.3p3: Once arguments are classified, the registers
1471 // get assigned (in left-to-right order) for passing as follows...
1472 for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
1473 it != ie; ++it) {
Chris Lattnera159c2e2010-06-29 01:14:09 +00001474 // If the client specified a preferred IR type to use, pass it down to
1475 // classifyArgumentType.
1476 const llvm::Type *PrefType = 0;
1477 if (NumPrefTypes) {
1478 PrefType = *PrefTypes++;
1479 --NumPrefTypes;
1480 }
1481
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001482 unsigned neededInt, neededSSE;
Chris Lattner9c254f02010-06-29 06:01:59 +00001483 it->info = classifyArgumentType(it->type, VMContext,
Chris Lattnera159c2e2010-06-29 01:14:09 +00001484 neededInt, neededSSE, PrefType);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001485
1486 // AMD64-ABI 3.2.3p3: If there are no registers available for any
1487 // eightbyte of an argument, the whole argument is passed on the
1488 // stack. If registers have already been assigned for some
1489 // eightbytes of such an argument, the assignments get reverted.
1490 if (freeIntRegs >= neededInt && freeSSERegs >= neededSSE) {
1491 freeIntRegs -= neededInt;
1492 freeSSERegs -= neededSSE;
1493 } else {
Chris Lattner9c254f02010-06-29 06:01:59 +00001494 it->info = getIndirectResult(it->type);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001495 }
1496 }
1497}
1498
1499static llvm::Value *EmitVAArgFromMemory(llvm::Value *VAListAddr,
1500 QualType Ty,
1501 CodeGenFunction &CGF) {
1502 llvm::Value *overflow_arg_area_p =
1503 CGF.Builder.CreateStructGEP(VAListAddr, 2, "overflow_arg_area_p");
1504 llvm::Value *overflow_arg_area =
1505 CGF.Builder.CreateLoad(overflow_arg_area_p, "overflow_arg_area");
1506
1507 // AMD64-ABI 3.5.7p5: Step 7. Align l->overflow_arg_area upwards to a 16
1508 // byte boundary if alignment needed by type exceeds 8 byte boundary.
1509 uint64_t Align = CGF.getContext().getTypeAlign(Ty) / 8;
1510 if (Align > 8) {
1511 // Note that we follow the ABI & gcc here, even though the type
1512 // could in theory have an alignment greater than 16. This case
1513 // shouldn't ever matter in practice.
1514
1515 // overflow_arg_area = (overflow_arg_area + 15) & ~15;
Owen Anderson0032b272009-08-13 21:57:51 +00001516 llvm::Value *Offset =
Chris Lattner77b89b82010-06-27 07:15:29 +00001517 llvm::ConstantInt::get(CGF.Int32Ty, 15);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001518 overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset);
1519 llvm::Value *AsInt = CGF.Builder.CreatePtrToInt(overflow_arg_area,
Chris Lattner77b89b82010-06-27 07:15:29 +00001520 CGF.Int64Ty);
1521 llvm::Value *Mask = llvm::ConstantInt::get(CGF.Int64Ty, ~15LL);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001522 overflow_arg_area =
1523 CGF.Builder.CreateIntToPtr(CGF.Builder.CreateAnd(AsInt, Mask),
1524 overflow_arg_area->getType(),
1525 "overflow_arg_area.align");
1526 }
1527
1528 // AMD64-ABI 3.5.7p5: Step 8. Fetch type from l->overflow_arg_area.
1529 const llvm::Type *LTy = CGF.ConvertTypeForMem(Ty);
1530 llvm::Value *Res =
1531 CGF.Builder.CreateBitCast(overflow_arg_area,
Owen Anderson96e0fc72009-07-29 22:16:19 +00001532 llvm::PointerType::getUnqual(LTy));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001533
1534 // AMD64-ABI 3.5.7p5: Step 9. Set l->overflow_arg_area to:
1535 // l->overflow_arg_area + sizeof(type).
1536 // AMD64-ABI 3.5.7p5: Step 10. Align l->overflow_arg_area upwards to
1537 // an 8 byte boundary.
1538
1539 uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
Owen Anderson0032b272009-08-13 21:57:51 +00001540 llvm::Value *Offset =
Chris Lattner77b89b82010-06-27 07:15:29 +00001541 llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7) & ~7);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001542 overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset,
1543 "overflow_arg_area.next");
1544 CGF.Builder.CreateStore(overflow_arg_area, overflow_arg_area_p);
1545
1546 // AMD64-ABI 3.5.7p5: Step 11. Return the fetched type.
1547 return Res;
1548}
1549
1550llvm::Value *X86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
1551 CodeGenFunction &CGF) const {
Owen Andersona1cf15f2009-07-14 23:10:40 +00001552 llvm::LLVMContext &VMContext = CGF.getLLVMContext();
Mike Stump1eb44332009-09-09 15:08:12 +00001553
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001554 // Assume that va_list type is correct; should be pointer to LLVM type:
1555 // struct {
1556 // i32 gp_offset;
1557 // i32 fp_offset;
1558 // i8* overflow_arg_area;
1559 // i8* reg_save_area;
1560 // };
1561 unsigned neededInt, neededSSE;
Chris Lattnera14db752010-03-11 18:19:55 +00001562
1563 Ty = CGF.getContext().getCanonicalType(Ty);
Chris Lattner9c254f02010-06-29 06:01:59 +00001564 ABIArgInfo AI = classifyArgumentType(Ty, VMContext, neededInt, neededSSE, 0);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001565
1566 // AMD64-ABI 3.5.7p5: Step 1. Determine whether type may be passed
1567 // in the registers. If not go to step 7.
1568 if (!neededInt && !neededSSE)
1569 return EmitVAArgFromMemory(VAListAddr, Ty, CGF);
1570
1571 // AMD64-ABI 3.5.7p5: Step 2. Compute num_gp to hold the number of
1572 // general purpose registers needed to pass type and num_fp to hold
1573 // the number of floating point registers needed.
1574
1575 // AMD64-ABI 3.5.7p5: Step 3. Verify whether arguments fit into
1576 // registers. In the case: l->gp_offset > 48 - num_gp * 8 or
1577 // l->fp_offset > 304 - num_fp * 16 go to step 7.
1578 //
1579 // NOTE: 304 is a typo, there are (6 * 8 + 8 * 16) = 176 bytes of
1580 // register save space).
1581
1582 llvm::Value *InRegs = 0;
1583 llvm::Value *gp_offset_p = 0, *gp_offset = 0;
1584 llvm::Value *fp_offset_p = 0, *fp_offset = 0;
1585 if (neededInt) {
1586 gp_offset_p = CGF.Builder.CreateStructGEP(VAListAddr, 0, "gp_offset_p");
1587 gp_offset = CGF.Builder.CreateLoad(gp_offset_p, "gp_offset");
Chris Lattner1090a9b2010-06-28 21:43:59 +00001588 InRegs = llvm::ConstantInt::get(CGF.Int32Ty, 48 - neededInt * 8);
1589 InRegs = CGF.Builder.CreateICmpULE(gp_offset, InRegs, "fits_in_gp");
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001590 }
1591
1592 if (neededSSE) {
1593 fp_offset_p = CGF.Builder.CreateStructGEP(VAListAddr, 1, "fp_offset_p");
1594 fp_offset = CGF.Builder.CreateLoad(fp_offset_p, "fp_offset");
1595 llvm::Value *FitsInFP =
Chris Lattner1090a9b2010-06-28 21:43:59 +00001596 llvm::ConstantInt::get(CGF.Int32Ty, 176 - neededSSE * 16);
1597 FitsInFP = CGF.Builder.CreateICmpULE(fp_offset, FitsInFP, "fits_in_fp");
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001598 InRegs = InRegs ? CGF.Builder.CreateAnd(InRegs, FitsInFP) : FitsInFP;
1599 }
1600
1601 llvm::BasicBlock *InRegBlock = CGF.createBasicBlock("vaarg.in_reg");
1602 llvm::BasicBlock *InMemBlock = CGF.createBasicBlock("vaarg.in_mem");
1603 llvm::BasicBlock *ContBlock = CGF.createBasicBlock("vaarg.end");
1604 CGF.Builder.CreateCondBr(InRegs, InRegBlock, InMemBlock);
1605
1606 // Emit code to load the value if it was passed in registers.
1607
1608 CGF.EmitBlock(InRegBlock);
1609
1610 // AMD64-ABI 3.5.7p5: Step 4. Fetch type from l->reg_save_area with
1611 // an offset of l->gp_offset and/or l->fp_offset. This may require
1612 // copying to a temporary location in case the parameter is passed
1613 // in different register classes or requires an alignment greater
1614 // than 8 for general purpose registers and 16 for XMM registers.
1615 //
1616 // FIXME: This really results in shameful code when we end up needing to
1617 // collect arguments from different places; often what should result in a
1618 // simple assembling of a structure from scattered addresses has many more
1619 // loads than necessary. Can we clean this up?
1620 const llvm::Type *LTy = CGF.ConvertTypeForMem(Ty);
1621 llvm::Value *RegAddr =
1622 CGF.Builder.CreateLoad(CGF.Builder.CreateStructGEP(VAListAddr, 3),
1623 "reg_save_area");
1624 if (neededInt && neededSSE) {
1625 // FIXME: Cleanup.
1626 assert(AI.isCoerce() && "Unexpected ABI info for mixed regs");
1627 const llvm::StructType *ST = cast<llvm::StructType>(AI.getCoerceToType());
1628 llvm::Value *Tmp = CGF.CreateTempAlloca(ST);
1629 assert(ST->getNumElements() == 2 && "Unexpected ABI info for mixed regs");
1630 const llvm::Type *TyLo = ST->getElementType(0);
1631 const llvm::Type *TyHi = ST->getElementType(1);
Duncan Sandsf177d9d2010-02-15 16:14:01 +00001632 assert((TyLo->isFloatingPointTy() ^ TyHi->isFloatingPointTy()) &&
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001633 "Unexpected ABI info for mixed regs");
Owen Anderson96e0fc72009-07-29 22:16:19 +00001634 const llvm::Type *PTyLo = llvm::PointerType::getUnqual(TyLo);
1635 const llvm::Type *PTyHi = llvm::PointerType::getUnqual(TyHi);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001636 llvm::Value *GPAddr = CGF.Builder.CreateGEP(RegAddr, gp_offset);
1637 llvm::Value *FPAddr = CGF.Builder.CreateGEP(RegAddr, fp_offset);
Duncan Sandsf177d9d2010-02-15 16:14:01 +00001638 llvm::Value *RegLoAddr = TyLo->isFloatingPointTy() ? FPAddr : GPAddr;
1639 llvm::Value *RegHiAddr = TyLo->isFloatingPointTy() ? GPAddr : FPAddr;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001640 llvm::Value *V =
1641 CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegLoAddr, PTyLo));
1642 CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0));
1643 V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegHiAddr, PTyHi));
1644 CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
1645
Owen Andersona1cf15f2009-07-14 23:10:40 +00001646 RegAddr = CGF.Builder.CreateBitCast(Tmp,
Owen Anderson96e0fc72009-07-29 22:16:19 +00001647 llvm::PointerType::getUnqual(LTy));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001648 } else if (neededInt) {
1649 RegAddr = CGF.Builder.CreateGEP(RegAddr, gp_offset);
1650 RegAddr = CGF.Builder.CreateBitCast(RegAddr,
Owen Anderson96e0fc72009-07-29 22:16:19 +00001651 llvm::PointerType::getUnqual(LTy));
Chris Lattnerdce5ad02010-06-28 20:05:43 +00001652 } else if (neededSSE == 1) {
1653 RegAddr = CGF.Builder.CreateGEP(RegAddr, fp_offset);
1654 RegAddr = CGF.Builder.CreateBitCast(RegAddr,
1655 llvm::PointerType::getUnqual(LTy));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001656 } else {
Chris Lattnerdce5ad02010-06-28 20:05:43 +00001657 assert(neededSSE == 2 && "Invalid number of needed registers!");
1658 // SSE registers are spaced 16 bytes apart in the register save
1659 // area, we need to collect the two eightbytes together.
1660 llvm::Value *RegAddrLo = CGF.Builder.CreateGEP(RegAddr, fp_offset);
Chris Lattner1090a9b2010-06-28 21:43:59 +00001661 llvm::Value *RegAddrHi = CGF.Builder.CreateConstGEP1_32(RegAddrLo, 16);
Chris Lattnerdce5ad02010-06-28 20:05:43 +00001662 const llvm::Type *DoubleTy = llvm::Type::getDoubleTy(VMContext);
1663 const llvm::Type *DblPtrTy =
1664 llvm::PointerType::getUnqual(DoubleTy);
1665 const llvm::StructType *ST = llvm::StructType::get(VMContext, DoubleTy,
1666 DoubleTy, NULL);
1667 llvm::Value *V, *Tmp = CGF.CreateTempAlloca(ST);
1668 V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegAddrLo,
1669 DblPtrTy));
1670 CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0));
1671 V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegAddrHi,
1672 DblPtrTy));
1673 CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
1674 RegAddr = CGF.Builder.CreateBitCast(Tmp,
1675 llvm::PointerType::getUnqual(LTy));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001676 }
1677
1678 // AMD64-ABI 3.5.7p5: Step 5. Set:
1679 // l->gp_offset = l->gp_offset + num_gp * 8
1680 // l->fp_offset = l->fp_offset + num_fp * 16.
1681 if (neededInt) {
Chris Lattner77b89b82010-06-27 07:15:29 +00001682 llvm::Value *Offset = llvm::ConstantInt::get(CGF.Int32Ty, neededInt * 8);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001683 CGF.Builder.CreateStore(CGF.Builder.CreateAdd(gp_offset, Offset),
1684 gp_offset_p);
1685 }
1686 if (neededSSE) {
Chris Lattner77b89b82010-06-27 07:15:29 +00001687 llvm::Value *Offset = llvm::ConstantInt::get(CGF.Int32Ty, neededSSE * 16);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001688 CGF.Builder.CreateStore(CGF.Builder.CreateAdd(fp_offset, Offset),
1689 fp_offset_p);
1690 }
1691 CGF.EmitBranch(ContBlock);
1692
1693 // Emit code to load the value if it was passed in memory.
1694
1695 CGF.EmitBlock(InMemBlock);
1696 llvm::Value *MemAddr = EmitVAArgFromMemory(VAListAddr, Ty, CGF);
1697
1698 // Return the appropriate result.
1699
1700 CGF.EmitBlock(ContBlock);
1701 llvm::PHINode *ResAddr = CGF.Builder.CreatePHI(RegAddr->getType(),
1702 "vaarg.addr");
1703 ResAddr->reserveOperandSpace(2);
1704 ResAddr->addIncoming(RegAddr, InRegBlock);
1705 ResAddr->addIncoming(MemAddr, InMemBlock);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001706 return ResAddr;
1707}
1708
Chris Lattnerdce5ad02010-06-28 20:05:43 +00001709
1710
1711//===----------------------------------------------------------------------===//
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001712// PIC16 ABI Implementation
Chris Lattnerdce5ad02010-06-28 20:05:43 +00001713//===----------------------------------------------------------------------===//
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001714
1715namespace {
1716
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001717class PIC16ABIInfo : public ABIInfo {
1718 ABIArgInfo classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001719 ASTContext &Context,
1720 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001721
1722 ABIArgInfo classifyArgumentType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001723 ASTContext &Context,
1724 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001725
Owen Andersona1cf15f2009-07-14 23:10:40 +00001726 virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context,
Chris Lattner8640cd62010-06-29 01:08:48 +00001727 llvm::LLVMContext &VMContext,
1728 const llvm::Type *const *PrefTypes,
1729 unsigned NumPrefTypes) const {
Owen Andersona1cf15f2009-07-14 23:10:40 +00001730 FI.getReturnInfo() = classifyReturnType(FI.getReturnType(), Context,
1731 VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001732 for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
1733 it != ie; ++it)
Owen Andersona1cf15f2009-07-14 23:10:40 +00001734 it->info = classifyArgumentType(it->type, Context, VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001735 }
1736
1737 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
1738 CodeGenFunction &CGF) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001739};
1740
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00001741class PIC16TargetCodeGenInfo : public TargetCodeGenInfo {
1742public:
Douglas Gregor568bb2d2010-01-22 15:41:14 +00001743 PIC16TargetCodeGenInfo():TargetCodeGenInfo(new PIC16ABIInfo()) {}
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00001744};
1745
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001746}
1747
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001748ABIArgInfo PIC16ABIInfo::classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001749 ASTContext &Context,
1750 llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001751 if (RetTy->isVoidType()) {
1752 return ABIArgInfo::getIgnore();
1753 } else {
1754 return ABIArgInfo::getDirect();
1755 }
1756}
1757
1758ABIArgInfo PIC16ABIInfo::classifyArgumentType(QualType Ty,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001759 ASTContext &Context,
1760 llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001761 return ABIArgInfo::getDirect();
1762}
1763
1764llvm::Value *PIC16ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
Chris Lattner77b89b82010-06-27 07:15:29 +00001765 CodeGenFunction &CGF) const {
Chris Lattner52d9ae32010-04-06 17:29:22 +00001766 const llvm::Type *BP = llvm::Type::getInt8PtrTy(CGF.getLLVMContext());
Sanjiv Guptaa446ecd2010-02-17 02:25:52 +00001767 const llvm::Type *BPP = llvm::PointerType::getUnqual(BP);
1768
1769 CGBuilderTy &Builder = CGF.Builder;
1770 llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP,
1771 "ap");
1772 llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
1773 llvm::Type *PTy =
1774 llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
1775 llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
1776
1777 uint64_t Offset = CGF.getContext().getTypeSize(Ty) / 8;
1778
1779 llvm::Value *NextAddr =
1780 Builder.CreateGEP(Addr, llvm::ConstantInt::get(
1781 llvm::Type::getInt32Ty(CGF.getLLVMContext()), Offset),
1782 "ap.next");
1783 Builder.CreateStore(NextAddr, VAListAddrAsBPP);
1784
1785 return AddrTyped;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001786}
1787
Sanjiv Guptaa446ecd2010-02-17 02:25:52 +00001788
John McCallec853ba2010-03-11 00:10:12 +00001789// PowerPC-32
1790
1791namespace {
1792class PPC32TargetCodeGenInfo : public DefaultTargetCodeGenInfo {
1793public:
1794 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
1795 // This is recovered from gcc output.
1796 return 1; // r1 is the dedicated stack pointer
1797 }
1798
1799 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
1800 llvm::Value *Address) const;
1801};
1802
1803}
1804
1805bool
1806PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
1807 llvm::Value *Address) const {
1808 // This is calculated from the LLVM and GCC tables and verified
1809 // against gcc output. AFAIK all ABIs use the same encoding.
1810
1811 CodeGen::CGBuilderTy &Builder = CGF.Builder;
1812 llvm::LLVMContext &Context = CGF.getLLVMContext();
1813
1814 const llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context);
1815 llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4);
1816 llvm::Value *Eight8 = llvm::ConstantInt::get(i8, 8);
1817 llvm::Value *Sixteen8 = llvm::ConstantInt::get(i8, 16);
1818
1819 // 0-31: r0-31, the 4-byte general-purpose registers
John McCallaeeb7012010-05-27 06:19:26 +00001820 AssignToArrayRange(Builder, Address, Four8, 0, 31);
John McCallec853ba2010-03-11 00:10:12 +00001821
1822 // 32-63: fp0-31, the 8-byte floating-point registers
John McCallaeeb7012010-05-27 06:19:26 +00001823 AssignToArrayRange(Builder, Address, Eight8, 32, 63);
John McCallec853ba2010-03-11 00:10:12 +00001824
1825 // 64-76 are various 4-byte special-purpose registers:
1826 // 64: mq
1827 // 65: lr
1828 // 66: ctr
1829 // 67: ap
1830 // 68-75 cr0-7
1831 // 76: xer
John McCallaeeb7012010-05-27 06:19:26 +00001832 AssignToArrayRange(Builder, Address, Four8, 64, 76);
John McCallec853ba2010-03-11 00:10:12 +00001833
1834 // 77-108: v0-31, the 16-byte vector registers
John McCallaeeb7012010-05-27 06:19:26 +00001835 AssignToArrayRange(Builder, Address, Sixteen8, 77, 108);
John McCallec853ba2010-03-11 00:10:12 +00001836
1837 // 109: vrsave
1838 // 110: vscr
1839 // 111: spe_acc
1840 // 112: spefscr
1841 // 113: sfp
John McCallaeeb7012010-05-27 06:19:26 +00001842 AssignToArrayRange(Builder, Address, Four8, 109, 113);
John McCallec853ba2010-03-11 00:10:12 +00001843
1844 return false;
1845}
1846
1847
Chris Lattnerdce5ad02010-06-28 20:05:43 +00001848//===----------------------------------------------------------------------===//
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001849// ARM ABI Implementation
Chris Lattnerdce5ad02010-06-28 20:05:43 +00001850//===----------------------------------------------------------------------===//
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001851
1852namespace {
1853
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001854class ARMABIInfo : public ABIInfo {
Daniel Dunbar5e7bace2009-09-12 01:00:39 +00001855public:
1856 enum ABIKind {
1857 APCS = 0,
1858 AAPCS = 1,
1859 AAPCS_VFP
1860 };
1861
1862private:
1863 ABIKind Kind;
1864
1865public:
1866 ARMABIInfo(ABIKind _Kind) : Kind(_Kind) {}
1867
1868private:
1869 ABIKind getABIKind() const { return Kind; }
1870
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001871 ABIArgInfo classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001872 ASTContext &Context,
1873 llvm::LLVMContext &VMCOntext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001874
1875 ABIArgInfo classifyArgumentType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001876 ASTContext &Context,
1877 llvm::LLVMContext &VMContext) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001878
Owen Andersona1cf15f2009-07-14 23:10:40 +00001879 virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context,
Chris Lattner8640cd62010-06-29 01:08:48 +00001880 llvm::LLVMContext &VMContext,
1881 const llvm::Type *const *PrefTypes,
1882 unsigned NumPrefTypes) const;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001883
1884 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
1885 CodeGenFunction &CGF) const;
1886};
1887
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00001888class ARMTargetCodeGenInfo : public TargetCodeGenInfo {
1889public:
1890 ARMTargetCodeGenInfo(ARMABIInfo::ABIKind K)
Douglas Gregor568bb2d2010-01-22 15:41:14 +00001891 :TargetCodeGenInfo(new ARMABIInfo(K)) {}
John McCall6374c332010-03-06 00:35:14 +00001892
1893 int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const {
1894 return 13;
1895 }
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00001896};
1897
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00001898}
1899
Owen Andersona1cf15f2009-07-14 23:10:40 +00001900void ARMABIInfo::computeInfo(CGFunctionInfo &FI, ASTContext &Context,
Chris Lattner8640cd62010-06-29 01:08:48 +00001901 llvm::LLVMContext &VMContext,
1902 const llvm::Type *const *PrefTypes,
1903 unsigned NumPrefTypes) const {
Mike Stump1eb44332009-09-09 15:08:12 +00001904 FI.getReturnInfo() = classifyReturnType(FI.getReturnType(), Context,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001905 VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001906 for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
1907 it != ie; ++it) {
Owen Andersona1cf15f2009-07-14 23:10:40 +00001908 it->info = classifyArgumentType(it->type, Context, VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001909 }
Daniel Dunbar5e7bace2009-09-12 01:00:39 +00001910
Rafael Espindola25117ab2010-06-16 16:13:39 +00001911 const llvm::Triple &Triple(Context.Target.getTriple());
1912 llvm::CallingConv::ID DefaultCC;
Rafael Espindola1ed1a592010-06-16 19:01:17 +00001913 if (Triple.getEnvironmentName() == "gnueabi" ||
1914 Triple.getEnvironmentName() == "eabi")
Rafael Espindola25117ab2010-06-16 16:13:39 +00001915 DefaultCC = llvm::CallingConv::ARM_AAPCS;
Rafael Espindola1ed1a592010-06-16 19:01:17 +00001916 else
1917 DefaultCC = llvm::CallingConv::ARM_APCS;
Rafael Espindola25117ab2010-06-16 16:13:39 +00001918
Daniel Dunbar5e7bace2009-09-12 01:00:39 +00001919 switch (getABIKind()) {
1920 case APCS:
Rafael Espindola25117ab2010-06-16 16:13:39 +00001921 if (DefaultCC != llvm::CallingConv::ARM_APCS)
1922 FI.setEffectiveCallingConvention(llvm::CallingConv::ARM_APCS);
Daniel Dunbar5e7bace2009-09-12 01:00:39 +00001923 break;
1924
1925 case AAPCS:
Rafael Espindola25117ab2010-06-16 16:13:39 +00001926 if (DefaultCC != llvm::CallingConv::ARM_AAPCS)
1927 FI.setEffectiveCallingConvention(llvm::CallingConv::ARM_AAPCS);
Daniel Dunbar5e7bace2009-09-12 01:00:39 +00001928 break;
1929
1930 case AAPCS_VFP:
1931 FI.setEffectiveCallingConvention(llvm::CallingConv::ARM_AAPCS_VFP);
1932 break;
1933 }
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001934}
1935
1936ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty,
Owen Andersona1cf15f2009-07-14 23:10:40 +00001937 ASTContext &Context,
1938 llvm::LLVMContext &VMContext) const {
Douglas Gregoraa74a1e2010-02-02 20:10:50 +00001939 if (!CodeGenFunction::hasAggregateLLVMType(Ty)) {
1940 // Treat an enum type as its underlying type.
1941 if (const EnumType *EnumTy = Ty->getAs<EnumType>())
1942 Ty = EnumTy->getDecl()->getIntegerType();
1943
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +00001944 return (Ty->isPromotableIntegerType() ?
1945 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Douglas Gregoraa74a1e2010-02-02 20:10:50 +00001946 }
Daniel Dunbar98303b92009-09-13 08:03:58 +00001947
Daniel Dunbar42025572009-09-14 21:54:03 +00001948 // Ignore empty records.
1949 if (isEmptyRecord(Context, Ty, true))
1950 return ABIArgInfo::getIgnore();
1951
Rafael Espindola0eb1d972010-06-08 02:42:08 +00001952 // Structures with either a non-trivial destructor or a non-trivial
1953 // copy constructor are always indirect.
1954 if (isRecordWithNonTrivialDestructorOrCopyConstructor(Ty))
1955 return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
1956
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001957 // FIXME: This is kind of nasty... but there isn't much choice because the ARM
1958 // backend doesn't support byval.
1959 // FIXME: This doesn't handle alignment > 64 bits.
1960 const llvm::Type* ElemTy;
1961 unsigned SizeRegs;
1962 if (Context.getTypeAlign(Ty) > 32) {
Owen Anderson0032b272009-08-13 21:57:51 +00001963 ElemTy = llvm::Type::getInt64Ty(VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001964 SizeRegs = (Context.getTypeSize(Ty) + 63) / 64;
1965 } else {
Owen Anderson0032b272009-08-13 21:57:51 +00001966 ElemTy = llvm::Type::getInt32Ty(VMContext);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001967 SizeRegs = (Context.getTypeSize(Ty) + 31) / 32;
1968 }
1969 std::vector<const llvm::Type*> LLVMFields;
Owen Anderson96e0fc72009-07-29 22:16:19 +00001970 LLVMFields.push_back(llvm::ArrayType::get(ElemTy, SizeRegs));
Owen Anderson47a434f2009-08-05 23:18:46 +00001971 const llvm::Type* STy = llvm::StructType::get(VMContext, LLVMFields, true);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00001972 return ABIArgInfo::getCoerce(STy);
1973}
1974
Daniel Dunbar98303b92009-09-13 08:03:58 +00001975static bool isIntegerLikeType(QualType Ty,
1976 ASTContext &Context,
1977 llvm::LLVMContext &VMContext) {
1978 // APCS, C Language Calling Conventions, Non-Simple Return Values: A structure
1979 // is called integer-like if its size is less than or equal to one word, and
1980 // the offset of each of its addressable sub-fields is zero.
1981
1982 uint64_t Size = Context.getTypeSize(Ty);
1983
1984 // Check that the type fits in a word.
1985 if (Size > 32)
1986 return false;
1987
1988 // FIXME: Handle vector types!
1989 if (Ty->isVectorType())
1990 return false;
1991
Daniel Dunbarb0d58192009-09-14 02:20:34 +00001992 // Float types are never treated as "integer like".
1993 if (Ty->isRealFloatingType())
1994 return false;
1995
Daniel Dunbar98303b92009-09-13 08:03:58 +00001996 // If this is a builtin or pointer type then it is ok.
John McCall183700f2009-09-21 23:43:11 +00001997 if (Ty->getAs<BuiltinType>() || Ty->isPointerType())
Daniel Dunbar98303b92009-09-13 08:03:58 +00001998 return true;
1999
Daniel Dunbar45815812010-02-01 23:31:26 +00002000 // Small complex integer types are "integer like".
2001 if (const ComplexType *CT = Ty->getAs<ComplexType>())
2002 return isIntegerLikeType(CT->getElementType(), Context, VMContext);
Daniel Dunbar98303b92009-09-13 08:03:58 +00002003
2004 // Single element and zero sized arrays should be allowed, by the definition
2005 // above, but they are not.
2006
2007 // Otherwise, it must be a record type.
2008 const RecordType *RT = Ty->getAs<RecordType>();
2009 if (!RT) return false;
2010
2011 // Ignore records with flexible arrays.
2012 const RecordDecl *RD = RT->getDecl();
2013 if (RD->hasFlexibleArrayMember())
2014 return false;
2015
2016 // Check that all sub-fields are at offset 0, and are themselves "integer
2017 // like".
2018 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
2019
2020 bool HadField = false;
2021 unsigned idx = 0;
2022 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
2023 i != e; ++i, ++idx) {
2024 const FieldDecl *FD = *i;
2025
Daniel Dunbar679855a2010-01-29 03:22:29 +00002026 // Bit-fields are not addressable, we only need to verify they are "integer
2027 // like". We still have to disallow a subsequent non-bitfield, for example:
2028 // struct { int : 0; int x }
2029 // is non-integer like according to gcc.
2030 if (FD->isBitField()) {
2031 if (!RD->isUnion())
2032 HadField = true;
Daniel Dunbar98303b92009-09-13 08:03:58 +00002033
Daniel Dunbar679855a2010-01-29 03:22:29 +00002034 if (!isIntegerLikeType(FD->getType(), Context, VMContext))
2035 return false;
Daniel Dunbar98303b92009-09-13 08:03:58 +00002036
Daniel Dunbar679855a2010-01-29 03:22:29 +00002037 continue;
Daniel Dunbar98303b92009-09-13 08:03:58 +00002038 }
2039
Daniel Dunbar679855a2010-01-29 03:22:29 +00002040 // Check if this field is at offset 0.
2041 if (Layout.getFieldOffset(idx) != 0)
2042 return false;
2043
Daniel Dunbar98303b92009-09-13 08:03:58 +00002044 if (!isIntegerLikeType(FD->getType(), Context, VMContext))
2045 return false;
2046
Daniel Dunbar679855a2010-01-29 03:22:29 +00002047 // Only allow at most one field in a structure. This doesn't match the
2048 // wording above, but follows gcc in situations with a field following an
2049 // empty structure.
Daniel Dunbar98303b92009-09-13 08:03:58 +00002050 if (!RD->isUnion()) {
2051 if (HadField)
2052 return false;
2053
2054 HadField = true;
2055 }
2056 }
2057
2058 return true;
2059}
2060
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002061ABIArgInfo ARMABIInfo::classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00002062 ASTContext &Context,
2063 llvm::LLVMContext &VMContext) const {
Daniel Dunbar98303b92009-09-13 08:03:58 +00002064 if (RetTy->isVoidType())
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002065 return ABIArgInfo::getIgnore();
Daniel Dunbar98303b92009-09-13 08:03:58 +00002066
Douglas Gregoraa74a1e2010-02-02 20:10:50 +00002067 if (!CodeGenFunction::hasAggregateLLVMType(RetTy)) {
2068 // Treat an enum type as its underlying type.
2069 if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
2070 RetTy = EnumTy->getDecl()->getIntegerType();
2071
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +00002072 return (RetTy->isPromotableIntegerType() ?
2073 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Douglas Gregoraa74a1e2010-02-02 20:10:50 +00002074 }
Daniel Dunbar98303b92009-09-13 08:03:58 +00002075
Rafael Espindola0eb1d972010-06-08 02:42:08 +00002076 // Structures with either a non-trivial destructor or a non-trivial
2077 // copy constructor are always indirect.
2078 if (isRecordWithNonTrivialDestructorOrCopyConstructor(RetTy))
2079 return ABIArgInfo::getIndirect(0, /*ByVal=*/false);
2080
Daniel Dunbar98303b92009-09-13 08:03:58 +00002081 // Are we following APCS?
2082 if (getABIKind() == APCS) {
2083 if (isEmptyRecord(Context, RetTy, false))
2084 return ABIArgInfo::getIgnore();
2085
Daniel Dunbar4cc753f2010-02-01 23:31:19 +00002086 // Complex types are all returned as packed integers.
2087 //
2088 // FIXME: Consider using 2 x vector types if the back end handles them
2089 // correctly.
2090 if (RetTy->isAnyComplexType())
2091 return ABIArgInfo::getCoerce(llvm::IntegerType::get(
2092 VMContext, Context.getTypeSize(RetTy)));
2093
Daniel Dunbar98303b92009-09-13 08:03:58 +00002094 // Integer like structures are returned in r0.
2095 if (isIntegerLikeType(RetTy, Context, VMContext)) {
2096 // Return in the smallest viable integer type.
2097 uint64_t Size = Context.getTypeSize(RetTy);
2098 if (Size <= 8)
2099 return ABIArgInfo::getCoerce(llvm::Type::getInt8Ty(VMContext));
2100 if (Size <= 16)
2101 return ABIArgInfo::getCoerce(llvm::Type::getInt16Ty(VMContext));
2102 return ABIArgInfo::getCoerce(llvm::Type::getInt32Ty(VMContext));
2103 }
2104
2105 // Otherwise return in memory.
2106 return ABIArgInfo::getIndirect(0);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002107 }
Daniel Dunbar98303b92009-09-13 08:03:58 +00002108
2109 // Otherwise this is an AAPCS variant.
2110
Daniel Dunbar16a08082009-09-14 00:56:55 +00002111 if (isEmptyRecord(Context, RetTy, true))
2112 return ABIArgInfo::getIgnore();
2113
Daniel Dunbar98303b92009-09-13 08:03:58 +00002114 // Aggregates <= 4 bytes are returned in r0; other aggregates
2115 // are returned indirectly.
2116 uint64_t Size = Context.getTypeSize(RetTy);
Daniel Dunbar16a08082009-09-14 00:56:55 +00002117 if (Size <= 32) {
2118 // Return in the smallest viable integer type.
2119 if (Size <= 8)
2120 return ABIArgInfo::getCoerce(llvm::Type::getInt8Ty(VMContext));
2121 if (Size <= 16)
2122 return ABIArgInfo::getCoerce(llvm::Type::getInt16Ty(VMContext));
Daniel Dunbar98303b92009-09-13 08:03:58 +00002123 return ABIArgInfo::getCoerce(llvm::Type::getInt32Ty(VMContext));
Daniel Dunbar16a08082009-09-14 00:56:55 +00002124 }
2125
Daniel Dunbar98303b92009-09-13 08:03:58 +00002126 return ABIArgInfo::getIndirect(0);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002127}
2128
2129llvm::Value *ARMABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
Chris Lattner77b89b82010-06-27 07:15:29 +00002130 CodeGenFunction &CGF) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002131 // FIXME: Need to handle alignment
Benjamin Kramer3c0ef8c2009-10-13 10:07:13 +00002132 const llvm::Type *BP = llvm::Type::getInt8PtrTy(CGF.getLLVMContext());
Owen Anderson96e0fc72009-07-29 22:16:19 +00002133 const llvm::Type *BPP = llvm::PointerType::getUnqual(BP);
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002134
2135 CGBuilderTy &Builder = CGF.Builder;
2136 llvm::Value *VAListAddrAsBPP = Builder.CreateBitCast(VAListAddr, BPP,
2137 "ap");
2138 llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
2139 llvm::Type *PTy =
Owen Anderson96e0fc72009-07-29 22:16:19 +00002140 llvm::PointerType::getUnqual(CGF.ConvertType(Ty));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002141 llvm::Value *AddrTyped = Builder.CreateBitCast(Addr, PTy);
2142
2143 uint64_t Offset =
2144 llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4);
2145 llvm::Value *NextAddr =
Chris Lattner77b89b82010-06-27 07:15:29 +00002146 Builder.CreateGEP(Addr, llvm::ConstantInt::get(CGF.Int32Ty, Offset),
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002147 "ap.next");
2148 Builder.CreateStore(NextAddr, VAListAddrAsBPP);
2149
2150 return AddrTyped;
2151}
2152
2153ABIArgInfo DefaultABIInfo::classifyReturnType(QualType RetTy,
Owen Andersona1cf15f2009-07-14 23:10:40 +00002154 ASTContext &Context,
2155 llvm::LLVMContext &VMContext) const {
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002156 if (RetTy->isVoidType()) {
2157 return ABIArgInfo::getIgnore();
2158 } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
2159 return ABIArgInfo::getIndirect(0);
2160 } else {
Douglas Gregoraa74a1e2010-02-02 20:10:50 +00002161 // Treat an enum type as its underlying type.
2162 if (const EnumType *EnumTy = RetTy->getAs<EnumType>())
2163 RetTy = EnumTy->getDecl()->getIntegerType();
2164
Anton Korobeynikovcc6fa882009-06-06 09:36:29 +00002165 return (RetTy->isPromotableIntegerType() ?
2166 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002167 }
2168}
2169
Chris Lattnerdce5ad02010-06-28 20:05:43 +00002170//===----------------------------------------------------------------------===//
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00002171// SystemZ ABI Implementation
Chris Lattnerdce5ad02010-06-28 20:05:43 +00002172//===----------------------------------------------------------------------===//
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00002173
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002174namespace {
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00002175
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002176class SystemZABIInfo : public ABIInfo {
2177 bool isPromotableIntegerType(QualType Ty) const;
2178
2179 ABIArgInfo classifyReturnType(QualType RetTy, ASTContext &Context,
2180 llvm::LLVMContext &VMContext) const;
2181
2182 ABIArgInfo classifyArgumentType(QualType RetTy, ASTContext &Context,
2183 llvm::LLVMContext &VMContext) const;
2184
2185 virtual void computeInfo(CGFunctionInfo &FI, ASTContext &Context,
Chris Lattner8640cd62010-06-29 01:08:48 +00002186 llvm::LLVMContext &VMContext,
2187 const llvm::Type *const *PrefTypes,
2188 unsigned NumPrefTypes) const {
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002189 FI.getReturnInfo() = classifyReturnType(FI.getReturnType(),
2190 Context, VMContext);
2191 for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie = FI.arg_end();
2192 it != ie; ++it)
2193 it->info = classifyArgumentType(it->type, Context, VMContext);
2194 }
2195
2196 virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
2197 CodeGenFunction &CGF) const;
2198};
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00002199
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002200class SystemZTargetCodeGenInfo : public TargetCodeGenInfo {
2201public:
Douglas Gregor568bb2d2010-01-22 15:41:14 +00002202 SystemZTargetCodeGenInfo():TargetCodeGenInfo(new SystemZABIInfo()) {}
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002203};
2204
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002205}
2206
2207bool SystemZABIInfo::isPromotableIntegerType(QualType Ty) const {
2208 // SystemZ ABI requires all 8, 16 and 32 bit quantities to be extended.
John McCall183700f2009-09-21 23:43:11 +00002209 if (const BuiltinType *BT = Ty->getAs<BuiltinType>())
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002210 switch (BT->getKind()) {
2211 case BuiltinType::Bool:
2212 case BuiltinType::Char_S:
2213 case BuiltinType::Char_U:
2214 case BuiltinType::SChar:
2215 case BuiltinType::UChar:
2216 case BuiltinType::Short:
2217 case BuiltinType::UShort:
2218 case BuiltinType::Int:
2219 case BuiltinType::UInt:
2220 return true;
2221 default:
2222 return false;
2223 }
2224 return false;
2225}
2226
2227llvm::Value *SystemZABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
2228 CodeGenFunction &CGF) const {
2229 // FIXME: Implement
2230 return 0;
2231}
2232
2233
2234ABIArgInfo SystemZABIInfo::classifyReturnType(QualType RetTy,
2235 ASTContext &Context,
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00002236 llvm::LLVMContext &VMContext) const {
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002237 if (RetTy->isVoidType()) {
2238 return ABIArgInfo::getIgnore();
2239 } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
2240 return ABIArgInfo::getIndirect(0);
2241 } else {
2242 return (isPromotableIntegerType(RetTy) ?
2243 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
2244 }
2245}
2246
2247ABIArgInfo SystemZABIInfo::classifyArgumentType(QualType Ty,
2248 ASTContext &Context,
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00002249 llvm::LLVMContext &VMContext) const {
Anton Korobeynikov89e887f2009-07-16 20:09:57 +00002250 if (CodeGenFunction::hasAggregateLLVMType(Ty)) {
2251 return ABIArgInfo::getIndirect(0);
2252 } else {
2253 return (isPromotableIntegerType(Ty) ?
2254 ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
2255 }
2256}
2257
Chris Lattnerdce5ad02010-06-28 20:05:43 +00002258//===----------------------------------------------------------------------===//
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002259// MSP430 ABI Implementation
Chris Lattnerdce5ad02010-06-28 20:05:43 +00002260//===----------------------------------------------------------------------===//
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002261
2262namespace {
2263
2264class MSP430TargetCodeGenInfo : public TargetCodeGenInfo {
2265public:
Douglas Gregor568bb2d2010-01-22 15:41:14 +00002266 MSP430TargetCodeGenInfo():TargetCodeGenInfo(new DefaultABIInfo()) {}
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002267 void SetTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
2268 CodeGen::CodeGenModule &M) const;
2269};
2270
2271}
2272
2273void MSP430TargetCodeGenInfo::SetTargetAttributes(const Decl *D,
2274 llvm::GlobalValue *GV,
2275 CodeGen::CodeGenModule &M) const {
2276 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
2277 if (const MSP430InterruptAttr *attr = FD->getAttr<MSP430InterruptAttr>()) {
2278 // Handle 'interrupt' attribute:
2279 llvm::Function *F = cast<llvm::Function>(GV);
2280
2281 // Step 1: Set ISR calling convention.
2282 F->setCallingConv(llvm::CallingConv::MSP430_INTR);
2283
2284 // Step 2: Add attributes goodness.
2285 F->addFnAttr(llvm::Attribute::NoInline);
2286
2287 // Step 3: Emit ISR vector alias.
2288 unsigned Num = attr->getNumber() + 0xffe0;
2289 new llvm::GlobalAlias(GV->getType(), llvm::Function::ExternalLinkage,
2290 "vector_" +
2291 llvm::LowercaseString(llvm::utohexstr(Num)),
2292 GV, &M.getModule());
2293 }
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002294 }
2295}
2296
Chris Lattnerdce5ad02010-06-28 20:05:43 +00002297//===----------------------------------------------------------------------===//
John McCallaeeb7012010-05-27 06:19:26 +00002298// MIPS ABI Implementation. This works for both little-endian and
2299// big-endian variants.
Chris Lattnerdce5ad02010-06-28 20:05:43 +00002300//===----------------------------------------------------------------------===//
2301
John McCallaeeb7012010-05-27 06:19:26 +00002302namespace {
2303class MIPSTargetCodeGenInfo : public TargetCodeGenInfo {
2304public:
2305 MIPSTargetCodeGenInfo(): TargetCodeGenInfo(new DefaultABIInfo()) {}
2306
2307 int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM) const {
2308 return 29;
2309 }
2310
2311 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
2312 llvm::Value *Address) const;
2313};
2314}
2315
2316bool
2317MIPSTargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
2318 llvm::Value *Address) const {
2319 // This information comes from gcc's implementation, which seems to
2320 // as canonical as it gets.
2321
2322 CodeGen::CGBuilderTy &Builder = CGF.Builder;
2323 llvm::LLVMContext &Context = CGF.getLLVMContext();
2324
2325 // Everything on MIPS is 4 bytes. Double-precision FP registers
2326 // are aliased to pairs of single-precision FP registers.
2327 const llvm::IntegerType *i8 = llvm::Type::getInt8Ty(Context);
2328 llvm::Value *Four8 = llvm::ConstantInt::get(i8, 4);
2329
2330 // 0-31 are the general purpose registers, $0 - $31.
2331 // 32-63 are the floating-point registers, $f0 - $f31.
2332 // 64 and 65 are the multiply/divide registers, $hi and $lo.
2333 // 66 is the (notional, I think) register for signal-handler return.
2334 AssignToArrayRange(Builder, Address, Four8, 0, 65);
2335
2336 // 67-74 are the floating-point status registers, $fcc0 - $fcc7.
2337 // They are one bit wide and ignored here.
2338
2339 // 80-111 are the coprocessor 0 registers, $c0r0 - $c0r31.
2340 // (coprocessor 1 is the FP unit)
2341 // 112-143 are the coprocessor 2 registers, $c2r0 - $c2r31.
2342 // 144-175 are the coprocessor 3 registers, $c3r0 - $c3r31.
2343 // 176-181 are the DSP accumulator registers.
2344 AssignToArrayRange(Builder, Address, Four8, 80, 181);
2345
2346 return false;
2347}
2348
2349
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002350const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() const {
2351 if (TheTargetCodeGenInfo)
2352 return *TheTargetCodeGenInfo;
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002353
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002354 // For now we just cache the TargetCodeGenInfo in CodeGenModule and don't
2355 // free it.
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00002356
Chris Lattner9c254f02010-06-29 06:01:59 +00002357 const llvm::Triple &Triple = getContext().Target.getTriple();
Daniel Dunbar1752ee42009-08-24 09:10:05 +00002358 switch (Triple.getArch()) {
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00002359 default:
Chris Lattner9c254f02010-06-29 06:01:59 +00002360 return *(TheTargetCodeGenInfo = new DefaultTargetCodeGenInfo());
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00002361
John McCallaeeb7012010-05-27 06:19:26 +00002362 case llvm::Triple::mips:
2363 case llvm::Triple::mipsel:
2364 return *(TheTargetCodeGenInfo = new MIPSTargetCodeGenInfo());
2365
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00002366 case llvm::Triple::arm:
2367 case llvm::Triple::thumb:
Daniel Dunbar5e7bace2009-09-12 01:00:39 +00002368 // FIXME: We want to know the float calling convention as well.
Daniel Dunbar018ba5a2009-09-14 00:35:03 +00002369 if (strcmp(getContext().Target.getABI(), "apcs-gnu") == 0)
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002370 return *(TheTargetCodeGenInfo =
2371 new ARMTargetCodeGenInfo(ARMABIInfo::APCS));
Daniel Dunbar5e7bace2009-09-12 01:00:39 +00002372
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002373 return *(TheTargetCodeGenInfo =
2374 new ARMTargetCodeGenInfo(ARMABIInfo::AAPCS));
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00002375
2376 case llvm::Triple::pic16:
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002377 return *(TheTargetCodeGenInfo = new PIC16TargetCodeGenInfo());
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00002378
John McCallec853ba2010-03-11 00:10:12 +00002379 case llvm::Triple::ppc:
2380 return *(TheTargetCodeGenInfo = new PPC32TargetCodeGenInfo());
2381
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00002382 case llvm::Triple::systemz:
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002383 return *(TheTargetCodeGenInfo = new SystemZTargetCodeGenInfo());
2384
2385 case llvm::Triple::msp430:
2386 return *(TheTargetCodeGenInfo = new MSP430TargetCodeGenInfo());
Daniel Dunbar34d91fd2009-09-12 00:59:49 +00002387
Daniel Dunbar1752ee42009-08-24 09:10:05 +00002388 case llvm::Triple::x86:
Daniel Dunbar1752ee42009-08-24 09:10:05 +00002389 switch (Triple.getOS()) {
Edward O'Callaghan7ee68bd2009-10-20 17:22:50 +00002390 case llvm::Triple::Darwin:
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002391 return *(TheTargetCodeGenInfo =
2392 new X86_32TargetCodeGenInfo(Context, true, true));
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00002393 case llvm::Triple::Cygwin:
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00002394 case llvm::Triple::MinGW32:
2395 case llvm::Triple::MinGW64:
Edward O'Callaghan727e2682009-10-21 11:58:24 +00002396 case llvm::Triple::AuroraUX:
2397 case llvm::Triple::DragonFly:
David Chisnall75c135a2009-09-03 01:48:05 +00002398 case llvm::Triple::FreeBSD:
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00002399 case llvm::Triple::OpenBSD:
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002400 return *(TheTargetCodeGenInfo =
2401 new X86_32TargetCodeGenInfo(Context, false, true));
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00002402
2403 default:
Anton Korobeynikov82d0a412010-01-10 12:58:08 +00002404 return *(TheTargetCodeGenInfo =
2405 new X86_32TargetCodeGenInfo(Context, false, false));
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002406 }
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002407
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00002408 case llvm::Triple::x86_64:
Chris Lattner9c254f02010-06-29 06:01:59 +00002409 return *(TheTargetCodeGenInfo =
2410 new X86_64TargetCodeGenInfo(Context, TheTargetData));
Daniel Dunbar2c0843f2009-08-24 08:52:16 +00002411 }
Anton Korobeynikovc4a59eb2009-06-05 22:08:42 +00002412}