2007-07-11 21:01:13 +04:00
|
|
|
//===--- CodeGenTypes.h - Type translation for LLVM CodeGen -----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 22:59:25 +03:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-07-11 21:01:13 +04:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-09-09 19:08:12 +04:00
|
|
|
// This is the code that handles AST -> LLVM type lowering.
|
2007-07-11 21:01:13 +04:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-29 20:10:38 +03:00
|
|
|
#ifndef CLANG_CODEGEN_CODEGENTYPES_H
|
|
|
|
#define CLANG_CODEGEN_CODEGENTYPES_H
|
2007-07-11 21:01:13 +04:00
|
|
|
|
2009-08-06 03:18:46 +04:00
|
|
|
#include "llvm/Module.h"
|
2007-08-21 04:21:21 +04:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2008-02-05 05:39:50 +03:00
|
|
|
#include "llvm/ADT/SmallSet.h"
|
2007-07-11 21:01:13 +04:00
|
|
|
#include <vector>
|
|
|
|
|
2008-09-10 11:00:50 +04:00
|
|
|
#include "CGCall.h"
|
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
namespace llvm {
|
2008-09-10 08:01:49 +04:00
|
|
|
class FunctionType;
|
2007-08-18 02:00:32 +04:00
|
|
|
class Module;
|
2008-04-03 09:50:42 +04:00
|
|
|
class OpaqueType;
|
2007-10-25 22:32:36 +04:00
|
|
|
class PATypeHolder;
|
2007-10-31 23:01:01 +03:00
|
|
|
class TargetData;
|
2008-09-10 08:01:49 +04:00
|
|
|
class Type;
|
2009-08-11 21:46:57 +04:00
|
|
|
class LLVMContext;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
2008-10-13 21:02:26 +04:00
|
|
|
class ABIInfo;
|
2007-07-14 05:29:45 +04:00
|
|
|
class ASTContext;
|
2009-04-04 02:48:58 +04:00
|
|
|
class CXXMethodDecl;
|
2007-10-24 03:26:46 +04:00
|
|
|
class FieldDecl;
|
2009-02-27 02:50:07 +03:00
|
|
|
class FunctionProtoType;
|
2008-03-31 03:03:07 +04:00
|
|
|
class ObjCInterfaceDecl;
|
|
|
|
class ObjCIvarDecl;
|
2008-09-10 08:01:49 +04:00
|
|
|
class PointerType;
|
|
|
|
class QualType;
|
|
|
|
class RecordDecl;
|
|
|
|
class TagDecl;
|
|
|
|
class TargetInfo;
|
|
|
|
class Type;
|
2007-10-23 06:10:49 +04:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
namespace CodeGen {
|
2007-10-23 06:10:49 +04:00
|
|
|
class CodeGenTypes;
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
/// CGRecordLayout - This class handles struct and union layout info while
|
2007-10-23 06:10:49 +04:00
|
|
|
/// lowering AST types to LLVM types.
|
2007-11-01 22:11:01 +03:00
|
|
|
class CGRecordLayout {
|
|
|
|
CGRecordLayout(); // DO NOT IMPLEMENT
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-23 05:25:01 +04:00
|
|
|
/// LLVMType - The LLVMType corresponding to this record layout.
|
|
|
|
const llvm::Type *LLVMType;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-23 05:25:01 +04:00
|
|
|
/// ContainsMemberPointer - Whether one of the fields in this record layout
|
|
|
|
/// is a member pointer, or a struct that contains a member pointer.
|
|
|
|
bool ContainsMemberPointer;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2007-10-23 06:10:49 +04:00
|
|
|
public:
|
2009-09-09 19:08:12 +04:00
|
|
|
CGRecordLayout(const llvm::Type *T, bool ContainsMemberPointer)
|
2009-08-23 05:25:01 +04:00
|
|
|
: LLVMType(T), ContainsMemberPointer(ContainsMemberPointer) { }
|
2007-10-23 06:10:49 +04:00
|
|
|
|
|
|
|
/// getLLVMType - Return llvm type associated with this record.
|
2009-07-23 07:17:50 +04:00
|
|
|
const llvm::Type *getLLVMType() const {
|
2009-08-23 05:25:01 +04:00
|
|
|
return LLVMType;
|
2007-10-23 06:10:49 +04:00
|
|
|
}
|
|
|
|
|
2009-08-23 05:25:01 +04:00
|
|
|
bool containsMemberPointer() const {
|
|
|
|
return ContainsMemberPointer;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2007-10-23 06:10:49 +04:00
|
|
|
};
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
/// CodeGenTypes - This class organizes the cross-module state that is used
|
|
|
|
/// while lowering AST types to LLVM types.
|
|
|
|
class CodeGenTypes {
|
2007-07-14 05:29:45 +04:00
|
|
|
ASTContext &Context;
|
2007-07-11 21:01:13 +04:00
|
|
|
TargetInfo &Target;
|
2007-08-18 02:00:32 +04:00
|
|
|
llvm::Module& TheModule;
|
2007-10-31 23:01:01 +03:00
|
|
|
const llvm::TargetData& TheTargetData;
|
2008-10-13 21:02:26 +04:00
|
|
|
mutable const ABIInfo* TheABIInfo;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-26 22:48:14 +03:00
|
|
|
llvm::SmallVector<std::pair<QualType,
|
2008-04-03 09:50:42 +04:00
|
|
|
llvm::OpaqueType *>, 8> PointersToResolve;
|
|
|
|
|
2008-09-06 06:26:43 +04:00
|
|
|
llvm::DenseMap<const Type*, llvm::PATypeHolder> TagDeclTypes;
|
2007-10-23 06:10:49 +04:00
|
|
|
|
2009-03-05 06:16:41 +03:00
|
|
|
llvm::DenseMap<const Type*, llvm::PATypeHolder> FunctionTypes;
|
|
|
|
|
2009-04-22 14:28:39 +04:00
|
|
|
/// The opaque type map for Objective-C interfaces. All direct
|
|
|
|
/// manipulation is done by the runtime interfaces, which are
|
|
|
|
/// responsible for coercing to the appropriate type; these opaque
|
|
|
|
/// types are never refined.
|
|
|
|
llvm::DenseMap<const ObjCInterfaceType*, const llvm::Type *> InterfaceTypes;
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
/// CGRecordLayouts - This maps llvm struct type with corresponding
|
|
|
|
/// record layout info.
|
|
|
|
/// FIXME : If CGRecordLayout is less than 16 bytes then use
|
2007-10-24 04:32:16 +04:00
|
|
|
/// inline it in the map.
|
2008-09-06 06:26:43 +04:00
|
|
|
llvm::DenseMap<const Type*, CGRecordLayout *> CGRecordLayouts;
|
2007-10-23 06:10:49 +04:00
|
|
|
|
|
|
|
/// FieldInfo - This maps struct field with corresponding llvm struct type
|
|
|
|
/// field no. This info is populated by record organizer.
|
|
|
|
llvm::DenseMap<const FieldDecl *, unsigned> FieldInfo;
|
|
|
|
|
2009-02-03 03:07:12 +03:00
|
|
|
/// FunctionInfos - Hold memoized CGFunctionInfo results.
|
|
|
|
llvm::FoldingSet<CGFunctionInfo> FunctionInfos;
|
|
|
|
|
2008-01-22 23:17:04 +03:00
|
|
|
public:
|
2009-07-23 21:01:21 +04:00
|
|
|
struct BitFieldInfo {
|
2009-09-09 19:08:12 +04:00
|
|
|
BitFieldInfo(unsigned FieldNo,
|
|
|
|
unsigned Start,
|
2009-07-23 21:01:21 +04:00
|
|
|
unsigned Size)
|
|
|
|
: FieldNo(FieldNo), Start(Start), Size(Size) {}
|
|
|
|
|
|
|
|
unsigned FieldNo;
|
|
|
|
unsigned Start;
|
|
|
|
unsigned Size;
|
2007-11-07 04:57:13 +03:00
|
|
|
};
|
2008-01-22 23:17:04 +03:00
|
|
|
|
|
|
|
private:
|
2007-11-07 04:57:13 +03:00
|
|
|
llvm::DenseMap<const FieldDecl *, BitFieldInfo> BitFields;
|
|
|
|
|
2008-02-06 08:21:55 +03:00
|
|
|
/// TypeCache - This map keeps cache of llvm::Types (through PATypeHolder)
|
2007-10-25 22:32:36 +04:00
|
|
|
/// and maps llvm::Types to corresponding clang::Type. llvm::PATypeHolder is
|
2009-09-09 19:08:12 +04:00
|
|
|
/// used instead of llvm::Type because it allows us to bypass potential
|
2007-10-25 22:32:36 +04:00
|
|
|
/// dangling type pointers due to type refinement on llvm side.
|
2008-02-06 08:21:55 +03:00
|
|
|
llvm::DenseMap<Type *, llvm::PATypeHolder> TypeCache;
|
2007-10-26 01:40:12 +04:00
|
|
|
|
|
|
|
/// ConvertNewType - Convert type T into a llvm::Type. Do not use this
|
|
|
|
/// method directly because it does not do any type caching. This method
|
|
|
|
/// is available only for ConvertType(). CovertType() is preferred
|
|
|
|
/// interface to convert type T into a llvm::Type.
|
|
|
|
const llvm::Type *ConvertNewType(QualType T);
|
2007-07-11 21:01:13 +04:00
|
|
|
public:
|
2007-10-31 23:01:01 +03:00
|
|
|
CodeGenTypes(ASTContext &Ctx, llvm::Module &M, const llvm::TargetData &TD);
|
2007-10-23 06:10:49 +04:00
|
|
|
~CodeGenTypes();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2007-10-31 23:08:22 +03:00
|
|
|
const llvm::TargetData &getTargetData() const { return TheTargetData; }
|
2007-07-11 21:01:13 +04:00
|
|
|
TargetInfo &getTarget() const { return Target; }
|
2007-10-29 23:50:19 +03:00
|
|
|
ASTContext &getContext() const { return Context; }
|
2008-10-13 21:02:26 +04:00
|
|
|
const ABIInfo &getABIInfo() const;
|
2009-08-06 03:18:46 +04:00
|
|
|
llvm::LLVMContext &getLLVMContext() { return TheModule.getContext(); }
|
2007-10-26 01:40:12 +04:00
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
/// ConvertType - Convert type T into a llvm::Type.
|
2007-07-11 21:01:13 +04:00
|
|
|
const llvm::Type *ConvertType(QualType T);
|
2008-04-03 09:50:42 +04:00
|
|
|
const llvm::Type *ConvertTypeRecursive(QualType T);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-02-06 08:21:55 +03:00
|
|
|
/// ConvertTypeForMem - Convert type T into a llvm::Type. This differs from
|
|
|
|
/// ConvertType in that it is used to convert to the memory representation for
|
|
|
|
/// a type. For example, the scalar representation for _Bool is i1, but the
|
|
|
|
/// memory representation is usually i8 or i32, depending on the target.
|
2008-01-09 21:47:25 +03:00
|
|
|
const llvm::Type *ConvertTypeForMem(QualType T);
|
2009-03-03 07:48:01 +03:00
|
|
|
const llvm::Type *ConvertTypeForMemRecursive(QualType T);
|
2008-09-10 08:01:49 +04:00
|
|
|
|
2009-01-31 06:05:44 +03:00
|
|
|
/// GetFunctionType - Get the LLVM function type for \arg Info.
|
2009-02-03 00:43:58 +03:00
|
|
|
const llvm::FunctionType *GetFunctionType(const CGFunctionInfo &Info,
|
|
|
|
bool IsVariadic);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-24 21:16:23 +04:00
|
|
|
const CGRecordLayout &getCGRecordLayout(const TagDecl*) const;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2007-10-23 06:10:49 +04:00
|
|
|
/// getLLVMFieldNo - Return llvm::StructType element number
|
|
|
|
/// that corresponds to the field FD.
|
|
|
|
unsigned getLLVMFieldNo(const FieldDecl *FD);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-02-06 08:08:19 +03:00
|
|
|
/// UpdateCompletedType - When we find the full definition for a TagDecl,
|
|
|
|
/// replace the 'opaque' type we previously made for it if applicable.
|
|
|
|
void UpdateCompletedType(const TagDecl *TD);
|
2009-02-03 02:23:47 +03:00
|
|
|
|
|
|
|
/// getFunctionInfo - Get the CGFunctionInfo for this function signature.
|
2009-09-09 19:08:12 +04:00
|
|
|
const CGFunctionInfo &getFunctionInfo(QualType RetTy,
|
|
|
|
const llvm::SmallVector<QualType,16>
|
2009-02-03 02:23:47 +03:00
|
|
|
&ArgTys);
|
|
|
|
|
2009-02-27 02:50:07 +03:00
|
|
|
const CGFunctionInfo &getFunctionInfo(const FunctionNoProtoType *FTNP);
|
|
|
|
const CGFunctionInfo &getFunctionInfo(const FunctionProtoType *FTP);
|
2009-02-03 02:23:47 +03:00
|
|
|
const CGFunctionInfo &getFunctionInfo(const FunctionDecl *FD);
|
2009-04-04 02:48:58 +04:00
|
|
|
const CGFunctionInfo &getFunctionInfo(const CXXMethodDecl *MD);
|
2009-02-03 02:23:47 +03:00
|
|
|
const CGFunctionInfo &getFunctionInfo(const ObjCMethodDecl *MD);
|
2009-09-09 19:08:12 +04:00
|
|
|
const CGFunctionInfo &getFunctionInfo(QualType ResTy,
|
2009-02-03 02:23:47 +03:00
|
|
|
const CallArgList &Args);
|
2009-04-06 22:05:26 +04:00
|
|
|
public:
|
2009-09-09 19:08:12 +04:00
|
|
|
const CGFunctionInfo &getFunctionInfo(QualType ResTy,
|
2009-02-03 02:23:47 +03:00
|
|
|
const FunctionArgList &Args);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-01-09 21:47:25 +03:00
|
|
|
public: // These are internal details of CGT that shouldn't be used externally.
|
2007-10-23 06:10:49 +04:00
|
|
|
/// addFieldInfo - Assign field number to field FD.
|
2009-07-23 21:01:21 +04:00
|
|
|
void addFieldInfo(const FieldDecl *FD, unsigned FieldNo);
|
2008-01-22 01:54:57 +03:00
|
|
|
|
|
|
|
/// addBitFieldInfo - Assign a start bit and a size to field FD.
|
2009-07-23 21:01:21 +04:00
|
|
|
void addBitFieldInfo(const FieldDecl *FD, unsigned FieldNo,
|
|
|
|
unsigned Start, unsigned Size);
|
2008-01-22 01:54:57 +03:00
|
|
|
|
2008-02-06 08:18:32 +03:00
|
|
|
/// getBitFieldInfo - Return the BitFieldInfo that corresponds to the field
|
|
|
|
/// FD.
|
2008-01-22 01:54:57 +03:00
|
|
|
BitFieldInfo getBitFieldInfo(const FieldDecl *FD);
|
2008-02-06 08:18:32 +03:00
|
|
|
|
|
|
|
/// ConvertTagDeclType - Lay out a tagged decl type like struct or union or
|
|
|
|
/// enum.
|
2008-02-06 09:06:49 +03:00
|
|
|
const llvm::Type *ConvertTagDeclType(const TagDecl *TD);
|
2008-09-17 04:51:38 +04:00
|
|
|
|
|
|
|
/// GetExpandedTypes - Expand the type \arg Ty into the LLVM
|
|
|
|
/// argument types it would be passed as on the provided vector \arg
|
|
|
|
/// ArgTys. See ABIArgInfo::Expand.
|
|
|
|
void GetExpandedTypes(QualType Ty, std::vector<const llvm::Type*> &ArgTys);
|
2007-07-11 21:01:13 +04:00
|
|
|
};
|
2007-07-14 02:13:22 +04:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
} // end namespace CodeGen
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif
|