15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- CodeGenTypes.h - Type translation for LLVM CodeGen -----*- C++ -*-===//
25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//                     The LLVM Compiler Infrastructure
45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source
60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details.
75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump// This is the code that handles AST -> LLVM type lowering.
115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//
125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
14ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#ifndef CLANG_CODEGEN_CODEGENTYPES_H
15ef52a2fb2ace36c92f88c6e125bd7defa17dafa5Chris Lattner#define CLANG_CODEGEN_CODEGENTYPES_H
165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
17800588fd230d2c37ddce8fbf4a3881352715d700Chris Lattner#include "CGCall.h"
18fd05ca03abdfb38f78b9535d996ecc9c39d3b0dbPeter Collingbourne#include "clang/AST/GlobalDecl.h"
1947a434ff3d49e7906eda88e8e8242e4297725b32Owen Anderson#include "llvm/Module.h"
20c9e2091efcb535110474434dd12015afdc3b1637Anders Carlsson#include "llvm/ADT/DenseMap.h"
215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include <vector>
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace llvm {
2445c25ba11cbf8c9a461def5b03f6ee9481e06769Daniel Dunbar  class FunctionType;
254e533287e6a9adac78c9ac370612581aad9b8c5eAnders Carlsson  class Module;
267a4718e813e5e99d478567a482217c7eef8572c5Devang Patel  class TargetData;
2745c25ba11cbf8c9a461def5b03f6ee9481e06769Daniel Dunbar  class Type;
28f21efe9088a0b3eda1209d1706529f6cb2073092Benjamin Kramer  class LLVMContext;
299cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  class StructType;
305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang {
336b1da0ea19c12346192f5ea4d70872c13bfcc82aDaniel Dunbar  class ABIInfo;
34d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattner  class ASTContext;
35ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  template <typename> class CanQual;
36f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  class CXXConstructorDecl;
37f6c56e2323c3f973253805a2f35629f3253ebed4Anders Carlsson  class CXXDestructorDecl;
38f6f8ae561ef78af169cbd2c067cae7ee4b2044e9Anders Carlsson  class CXXMethodDecl;
3908d4792bb5d9e0e7f122c6273636807029c06aaaDaniel Dunbar  class CodeGenOptions;
40b1e3989731b69e692f9fa2ad080406850c772b40Devang Patel  class FieldDecl;
4172564e73277e29f6db3305d1f27ba408abb7ed88Douglas Gregor  class FunctionProtoType;
42391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  class ObjCInterfaceDecl;
43391d77a26382dddf25da73e29fc1fa5aaaea4c6fChris Lattner  class ObjCIvarDecl;
4445c25ba11cbf8c9a461def5b03f6ee9481e06769Daniel Dunbar  class PointerType;
4545c25ba11cbf8c9a461def5b03f6ee9481e06769Daniel Dunbar  class QualType;
4645c25ba11cbf8c9a461def5b03f6ee9481e06769Daniel Dunbar  class RecordDecl;
4745c25ba11cbf8c9a461def5b03f6ee9481e06769Daniel Dunbar  class TagDecl;
4845c25ba11cbf8c9a461def5b03f6ee9481e06769Daniel Dunbar  class TargetInfo;
4945c25ba11cbf8c9a461def5b03f6ee9481e06769Daniel Dunbar  class Type;
50ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall  typedef CanQual<Type> CanQualType;
51b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace CodeGen {
53f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  class CGCXXABI;
542924ade97ee4228fcf3518d89cd4bd1653236b48Daniel Dunbar  class CGRecordLayout;
55de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  class CodeGenModule;
56de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  class RequiredArgs;
57b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel
585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// CodeGenTypes - This class organizes the cross-module state that is used
595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// while lowering AST types to LLVM types.
605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass CodeGenTypes {
61de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  // Some of this stuff should probably be left on the CGM.
62d2d2a11a91d7ddf468bfb70f66362d24806ed601Chris Lattner  ASTContext &Context;
63444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar  const TargetInfo &Target;
649cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::Module &TheModule;
659cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  const llvm::TargetData &TheTargetData;
669cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  const ABIInfo &TheABIInfo;
67f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  CGCXXABI &TheCXXABI;
6808d4792bb5d9e0e7f122c6273636807029c06aaaDaniel Dunbar  const CodeGenOptions &CodeGenOpts;
69de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  CodeGenModule &CGM;
701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
71412f59b23fc502b199b9ca96c72ef5d5ad21d62bDaniel Dunbar  /// The opaque type map for Objective-C interfaces. All direct
72412f59b23fc502b199b9ca96c72ef5d5ad21d62bDaniel Dunbar  /// manipulation is done by the runtime interfaces, which are
73412f59b23fc502b199b9ca96c72ef5d5ad21d62bDaniel Dunbar  /// responsible for coercing to the appropriate type; these opaque
74412f59b23fc502b199b9ca96c72ef5d5ad21d62bDaniel Dunbar  /// types are never refined.
759cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::DenseMap<const ObjCInterfaceType*, llvm::Type *> InterfaceTypes;
76412f59b23fc502b199b9ca96c72ef5d5ad21d62bDaniel Dunbar
771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// CGRecordLayouts - This maps llvm struct type with corresponding
781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// record layout info.
79efb6d0dc3eafbcf4f8cd053138bd1abed1dda8d4Daniel Dunbar  llvm::DenseMap<const Type*, CGRecordLayout *> CGRecordLayouts;
80b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel
819cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  /// RecordDeclTypes - This contains the LLVM IR type for any converted
829cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  /// RecordDecl.
839cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::DenseMap<const Type*, llvm::StructType *> RecordDeclTypes;
849cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner
8540a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar  /// FunctionInfos - Hold memoized CGFunctionInfo results.
8640a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar  llvm::FoldingSet<CGFunctionInfo> FunctionInfos;
8740a6be686e5d5bb4198f1affda574e8a4b3a7710Daniel Dunbar
8871305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  /// RecordsBeingLaidOut - This set keeps track of records that we're currently
8971305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  /// converting to an IR type.  For example, when converting:
9071305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  /// struct A { struct B { int x; } } when processing 'x', the 'A' and 'B'
9171305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  /// types will be in this set.
9271305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  llvm::SmallPtrSet<const Type*, 4> RecordsBeingLaidOut;
9371305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner
9471305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  llvm::SmallPtrSet<const CGFunctionInfo*, 4> FunctionsBeingProcessed;
9571305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner
9671305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  /// SkippedLayout - True if we didn't layout a function due to a being inside
9771305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  /// a recursive struct conversion, set this to true.
9857eb23f34ed2586069273c66f1a9994fe2b42967Chris Lattner  bool SkippedLayout;
9957eb23f34ed2586069273c66f1a9994fe2b42967Chris Lattner
100686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<const RecordDecl *, 8> DeferredRecords;
1019cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner
1023b8c22d93da1432b2d4cea779d14912645c93866Lauro Ramos Venancioprivate:
1039cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  /// TypeCache - This map keeps cache of llvm::Types
1049cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  /// and maps llvm::Types to corresponding clang::Type.
1059cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::DenseMap<const Type *, llvm::Type *> TypeCache;
106e9742b0f7281d0a21b79e661ec8879e01c4a02e4Anders Carlsson
1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic:
108de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  CodeGenTypes(CodeGenModule &CGM);
109b84a06e68ffd71da22e3c75b6e4bbdba37816413Devang Patel  ~CodeGenTypes();
1101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
111d9e9ede6b1703849da739629904dad197306e527Devang Patel  const llvm::TargetData &getTargetData() const { return TheTargetData; }
112444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar  const TargetInfo &getTarget() const { return Target; }
11386522b9e84d0c39f09b54e888538ad64e89788c4Devang Patel  ASTContext &getContext() const { return Context; }
11482d0a418c8699fc6f4a9417457ffe93d43bba1c1Anton Korobeynikov  const ABIInfo &getABIInfo() const { return TheABIInfo; }
11508d4792bb5d9e0e7f122c6273636807029c06aaaDaniel Dunbar  const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
116f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  CGCXXABI &getCXXABI() const { return TheCXXABI; }
11747a434ff3d49e7906eda88e8e8242e4297725b32Owen Anderson  llvm::LLVMContext &getLLVMContext() { return TheModule.getContext(); }
1185825ac2950db54ea5ce8a4f3f87fae569eeefe65Devang Patel
1191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// ConvertType - Convert type T into a llvm::Type.
1209cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::Type *ConvertType(QualType T);
1211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1224581fff8af09a156a9dcc4de62587385c5da9574Chris Lattner  /// ConvertTypeForMem - Convert type T into a llvm::Type.  This differs from
1234581fff8af09a156a9dcc4de62587385c5da9574Chris Lattner  /// ConvertType in that it is used to convert to the memory representation for
1244581fff8af09a156a9dcc4de62587385c5da9574Chris Lattner  /// a type.  For example, the scalar representation for _Bool is i1, but the
1254581fff8af09a156a9dcc4de62587385c5da9574Chris Lattner  /// memory representation is usually i8 or i32, depending on the target.
1269cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::Type *ConvertTypeForMem(QualType T);
12745c25ba11cbf8c9a461def5b03f6ee9481e06769Daniel Dunbar
12836b5f5ee026b6725bff9c5b8faba635d7dfeeb7dDaniel Dunbar  /// GetFunctionType - Get the LLVM function type for \arg Info.
129de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  llvm::FunctionType *GetFunctionType(const CGFunctionInfo &Info);
1301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1319cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::FunctionType *GetFunctionType(GlobalDecl GD);
132c0bf462cf35fe050bddbd8bff967298e4a67e79dJohn McCall
133f742eb0196e1b25c0b71e91da4a2b856d16a1dabChris Lattner  /// isFuncTypeConvertible - Utility to check whether a function type can
134c00129a08c829bb34f22dc13727043c994c85644Eli Friedman  /// be converted to an LLVM type (i.e. doesn't depend on an incomplete tag
135c00129a08c829bb34f22dc13727043c994c85644Eli Friedman  /// type).
136f742eb0196e1b25c0b71e91da4a2b856d16a1dabChris Lattner  bool isFuncTypeConvertible(const FunctionType *FT);
137f742eb0196e1b25c0b71e91da4a2b856d16a1dabChris Lattner  bool isFuncTypeArgumentConvertible(QualType Ty);
138f742eb0196e1b25c0b71e91da4a2b856d16a1dabChris Lattner
139046c294a43024874ff35656c6e785b64e72f1f36Anders Carlsson  /// GetFunctionTypeForVTable - Get the LLVM function type for use in a vtable,
1409cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer  /// given a CXXMethodDecl. If the method to has an incomplete return type,
141ecf282b0486873309fd58ec4d3ec0dbf983b33d4Anders Carlsson  /// and/or incomplete argument types, this will return the opaque type.
1422acc6e3feda5e4f7d9009bdcf8b1cd777fecfe2dChris Lattner  llvm::Type *GetFunctionTypeForVTable(GlobalDecl GD);
1439cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
144c8f01ebbce3c874b43ee78535f7d179517f5f436Anders Carlsson  const CGRecordLayout &getCGRecordLayout(const RecordDecl*);
1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
146c5b8806cda286cf41866176ef98011fdaa68da01Chris Lattner  /// UpdateCompletedType - When we find the full definition for a TagDecl,
147c5b8806cda286cf41866176ef98011fdaa68da01Chris Lattner  /// replace the 'opaque' type we previously made for it if applicable.
148c5b8806cda286cf41866176ef98011fdaa68da01Chris Lattner  void UpdateCompletedType(const TagDecl *TD);
149541b63b1a9db77e4a8670e9823711c2c12e58afbDaniel Dunbar
150d26bc76c98006609002d9930f8840490e88ac5b5John McCall  /// getNullaryFunctionInfo - Get the function info for a void()
151d26bc76c98006609002d9930f8840490e88ac5b5John McCall  /// function with standard CC.
152de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  const CGFunctionInfo &arrangeNullaryFunction();
153de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
154de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  // The arrangement methods are split into three families:
155de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  //   - those meant to drive the signature and prologue/epilogue
156de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  //     of a function declaration or definition,
157de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  //   - those meant for the computation of the LLVM type for an abstract
158de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  //     appearance of a function, and
159de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  //   - those meant for performing the IR-generation of a call.
160de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  // They differ mainly in how they deal with optional (i.e. variadic)
161de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  // arguments, as well as unprototyped functions.
162de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  //
163de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  // Key points:
164de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  // - The CGFunctionInfo for emitting a specific call site must include
165de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  //   entries for the optional arguments.
166de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  // - The function type used at the call site must reflect the formal
167de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  //   signature of the declaration being called, or else the call will
168de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  //   go awry.
169de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  // - For the most part, unprototyped functions are called by casting to
170de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  //   a formal signature inferred from the specific argument types used
171de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  //   at the call-site.  However, some targets (e.g. x86-64) screw with
172de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  //   this for compatibility reasons.
173de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
174de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  const CGFunctionInfo &arrangeGlobalDeclaration(GlobalDecl GD);
175de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  const CGFunctionInfo &arrangeFunctionDeclaration(const FunctionDecl *FD);
176de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  const CGFunctionInfo &arrangeFunctionDeclaration(QualType ResTy,
177de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                                   const FunctionArgList &Args,
178de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                             const FunctionType::ExtInfo &Info,
179de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                                   bool isVariadic);
180de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
181de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  const CGFunctionInfo &arrangeObjCMethodDeclaration(const ObjCMethodDecl *MD);
182de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  const CGFunctionInfo &arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD,
183de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                                        QualType receiverType);
184de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
185de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  const CGFunctionInfo &arrangeCXXMethodDeclaration(const CXXMethodDecl *MD);
186de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  const CGFunctionInfo &arrangeCXXConstructorDeclaration(
187de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                                    const CXXConstructorDecl *D,
188de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                                    CXXCtorType Type);
189de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  const CGFunctionInfo &arrangeCXXDestructor(const CXXDestructorDecl *D,
190de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                             CXXDtorType Type);
191de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall
1920f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall  const CGFunctionInfo &arrangeFreeFunctionCall(const CallArgList &Args,
1930f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall                                                const FunctionType *Ty);
1940f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall  const CGFunctionInfo &arrangeFreeFunctionCall(QualType ResTy,
1950f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall                                                const CallArgList &args,
1960f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall                                                FunctionType::ExtInfo info,
1970f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall                                                RequiredArgs required);
1980f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall
1990f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall  const CGFunctionInfo &arrangeCXXMethodCall(const CallArgList &args,
2000f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall                                             const FunctionProtoType *type,
2010f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall                                             RequiredArgs required);
2020f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall
2030f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall  const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionProtoType> Ty);
2040f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall  const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionNoProtoType> Ty);
205de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  const CGFunctionInfo &arrangeCXXMethodType(const CXXRecordDecl *RD,
206de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall                                             const FunctionProtoType *FTP);
207ead608af31b6c9abeae1ca6d0b75094dac4641c0John McCall
2080f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall  /// "Arrange" the LLVM information for a call or type with the given
2090f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall  /// signature.  This is largely an internal method; other clients
2100f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall  /// should use one of the above routines, which ultimately defer to
2110f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall  /// this.
2129cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer  ///
213de5d3c717684f3821b8db58037bc7140acf134aaJohn McCall  /// \param argTypes - must all actually be canonical as params
2140f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall  const CGFunctionInfo &arrangeLLVMFunctionInfo(CanQualType returnType,
2150f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall                                                ArrayRef<CanQualType> argTypes,
2160f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall                                                FunctionType::ExtInfo info,
2170f3d0970dcdf6cf17550b86838dff12813968dbcJohn McCall                                                RequiredArgs args);
2181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
219270e203b50ed8791e61afd357596bcf050cf2bfdDaniel Dunbar  /// \brief Compute a new LLVM record layout object for the given record.
2209cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  CGRecordLayout *ComputeRecordLayout(const RecordDecl *D,
2219cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner                                      llvm::StructType *Ty);
2229cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner
2239cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  /// addRecordTypeName - Compute a name from the given record decl with an
2249cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  /// optional suffix and name the given LLVM type using it.
2259cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  void addRecordTypeName(const RecordDecl *RD, llvm::StructType *Ty,
226686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                         StringRef suffix);
2279cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner
228270e203b50ed8791e61afd357596bcf050cf2bfdDaniel Dunbar
22919009e6fe7e0f51d2e49f4c94928a048c11c5281Chris Lattnerpublic:  // These are internal details of CGT that shouldn't be used externally.
2309cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  /// ConvertRecordDeclType - Lay out a tagged decl type like struct or union.
2319cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  llvm::StructType *ConvertRecordDeclType(const RecordDecl *TD);
2325627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar
2335627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// GetExpandedTypes - Expand the type \arg Ty into the LLVM
2345627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// argument types it would be passed as on the provided vector \arg
2355627377df5439a1d3d46a4e4cef4ae44f84a322bDaniel Dunbar  /// ArgTys. See ABIArgInfo::Expand.
23642e06119496e84e74cfc60230b18fcb53b35eb1cJohn McCall  void GetExpandedTypes(QualType type,
237686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                        SmallVectorImpl<llvm::Type*> &expanded);
2389cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
239f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  /// IsZeroInitializable - Return whether a type can be
240f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  /// zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
241f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  bool isZeroInitializable(QualType T);
2429cac4942b920d4c5514e71949e3062ed626bfbdfMichael J. Spencer
243f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  /// IsZeroInitializable - Return whether a record type can be
244f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  /// zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
245f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  bool isZeroInitializable(const CXXRecordDecl *RD);
24671305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner
24771305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  bool isRecordLayoutComplete(const Type *Ty) const;
24871305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  bool noRecordsBeingLaidOut() const {
24971305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner    return RecordsBeingLaidOut.empty();
25071305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  }
25171305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  bool isRecordBeingLaidOut(const Type *Ty) const {
25271305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner    return RecordsBeingLaidOut.count(Ty);
25371305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner  }
25471305cc81bd379ddb8aa0d49e268267383202ca9Chris Lattner
2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer};
256a7674d8a9a69f3f6fe16e70cf2a3b2b15fb7c43dChris Lattner
2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace CodeGen
2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}  // end namespace clang
2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif
261