opnsense-src/lib/CodeGen/CodeGenTypes.h

221 lines
8.9 KiB
C
Raw Normal View History

2009-06-02 13:58:47 -04:00
//===--- CodeGenTypes.h - Type translation for LLVM CodeGen -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
2009-10-14 14:03:49 -04:00
// This is the code that handles AST -> LLVM type lowering.
2009-06-02 13:58:47 -04:00
//
//===----------------------------------------------------------------------===//
#ifndef CLANG_CODEGEN_CODEGENTYPES_H
#define CLANG_CODEGEN_CODEGENTYPES_H
2009-10-14 14:03:49 -04:00
#include "llvm/Module.h"
2009-06-02 13:58:47 -04:00
#include "llvm/ADT/DenseMap.h"
#include <vector>
#include "CGCall.h"
2010-02-16 04:31:36 -05:00
#include "GlobalDecl.h"
2009-06-02 13:58:47 -04:00
namespace llvm {
class FunctionType;
class Module;
class OpaqueType;
class PATypeHolder;
class TargetData;
class Type;
2009-10-14 14:03:49 -04:00
class LLVMContext;
2009-06-02 13:58:47 -04:00
}
namespace clang {
class ABIInfo;
class ASTContext;
2010-03-03 12:28:16 -05:00
template <typename> class CanQual;
2009-12-01 06:08:04 -05:00
class CXXConstructorDecl;
class CXXDestructorDecl;
2009-06-02 13:58:47 -04:00
class CXXMethodDecl;
class FieldDecl;
class FunctionProtoType;
class ObjCInterfaceDecl;
class ObjCIvarDecl;
class PointerType;
class QualType;
class RecordDecl;
class TagDecl;
class TargetInfo;
class Type;
2010-03-03 12:28:16 -05:00
typedef CanQual<Type> CanQualType;
2009-06-02 13:58:47 -04:00
namespace CodeGen {
2010-04-02 04:55:10 -04:00
class CGRecordLayout;
2009-06-02 13:58:47 -04:00
/// CodeGenTypes - This class organizes the cross-module state that is used
/// while lowering AST types to LLVM types.
class CodeGenTypes {
ASTContext &Context;
2009-11-18 09:59:57 -05:00
const TargetInfo &Target;
2009-06-02 13:58:47 -04:00
llvm::Module& TheModule;
const llvm::TargetData& TheTargetData;
2010-01-15 10:39:40 -05:00
const ABIInfo& TheABIInfo;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
llvm::SmallVector<std::pair<QualType,
llvm::OpaqueType *>, 8> PointersToResolve;
llvm::DenseMap<const Type*, llvm::PATypeHolder> TagDeclTypes;
llvm::DenseMap<const Type*, llvm::PATypeHolder> FunctionTypes;
/// 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-10-14 14:03:49 -04:00
/// CGRecordLayouts - This maps llvm struct type with corresponding
/// record layout info.
2009-06-02 13:58:47 -04:00
llvm::DenseMap<const Type*, CGRecordLayout *> CGRecordLayouts;
/// FunctionInfos - Hold memoized CGFunctionInfo results.
llvm::FoldingSet<CGFunctionInfo> FunctionInfos;
private:
/// TypeCache - This map keeps cache of llvm::Types (through PATypeHolder)
/// and maps llvm::Types to corresponding clang::Type. llvm::PATypeHolder is
2009-10-14 14:03:49 -04:00
/// used instead of llvm::Type because it allows us to bypass potential
2009-06-02 13:58:47 -04:00
/// dangling type pointers due to type refinement on llvm side.
llvm::DenseMap<Type *, llvm::PATypeHolder> TypeCache;
/// 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);
2010-07-13 13:21:42 -04:00
/// HandleLateResolvedPointers - For top-level ConvertType calls, this handles
/// pointers that are referenced but have not been converted yet. This is
/// used to handle cyclic structures properly.
void HandleLateResolvedPointers();
2009-06-02 13:58:47 -04:00
public:
2010-01-15 10:39:40 -05:00
CodeGenTypes(ASTContext &Ctx, llvm::Module &M, const llvm::TargetData &TD,
const ABIInfo &Info);
2009-06-02 13:58:47 -04:00
~CodeGenTypes();
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04:00
const llvm::TargetData &getTargetData() const { return TheTargetData; }
2009-11-18 09:59:57 -05:00
const TargetInfo &getTarget() const { return Target; }
2009-06-02 13:58:47 -04:00
ASTContext &getContext() const { return Context; }
2010-01-15 10:39:40 -05:00
const ABIInfo &getABIInfo() const { return TheABIInfo; }
2009-10-14 14:03:49 -04:00
llvm::LLVMContext &getLLVMContext() { return TheModule.getContext(); }
2009-06-02 13:58:47 -04:00
2009-10-14 14:03:49 -04:00
/// ConvertType - Convert type T into a llvm::Type.
2010-07-13 13:21:42 -04:00
const llvm::Type *ConvertType(QualType T, bool IsRecursive = false);
2009-06-02 13:58:47 -04:00
const llvm::Type *ConvertTypeRecursive(QualType T);
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04: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.
2010-07-13 13:21:42 -04:00
const llvm::Type *ConvertTypeForMem(QualType T, bool IsRecursive = false);
const llvm::Type *ConvertTypeForMemRecursive(QualType T) {
return ConvertTypeForMem(T, true);
}
2009-06-02 13:58:47 -04:00
/// GetFunctionType - Get the LLVM function type for \arg Info.
const llvm::FunctionType *GetFunctionType(const CGFunctionInfo &Info,
2010-07-13 13:21:42 -04:00
bool IsVariadic,
bool IsRecursive = false);
2009-10-14 14:03:49 -04:00
2010-03-03 12:28:16 -05:00
const llvm::FunctionType *GetFunctionType(GlobalDecl GD);
2010-07-13 13:21:42 -04:00
/// VerifyFuncTypeComplete - Utility to check whether a function type can
/// be converted to an LLVM type (i.e. doesn't depend on an incomplete tag
/// type).
static const TagType *VerifyFuncTypeComplete(const Type* T);
2009-12-01 06:08:04 -05:00
2010-05-04 12:12:48 -04:00
/// GetFunctionTypeForVTable - Get the LLVM function type for use in a vtable,
2009-12-01 06:08:04 -05:00
/// given a CXXMethodDecl. If the method to has an incomplete return type,
/// and/or incomplete argument types, this will return the opaque type.
2010-05-04 12:12:48 -04:00
const llvm::Type *GetFunctionTypeForVTable(const CXXMethodDecl *MD);
2009-12-01 06:08:04 -05:00
2010-04-02 04:55:10 -04:00
const CGRecordLayout &getCGRecordLayout(const RecordDecl*) const;
2009-10-14 14:03:49 -04:00
2009-06-02 13:58:47 -04: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-10-14 14:03:49 -04:00
/// getFunctionInfo - Get the function info for the specified function decl.
2010-02-16 04:31:36 -05:00
const CGFunctionInfo &getFunctionInfo(GlobalDecl GD);
2009-06-02 13:58:47 -04:00
const CGFunctionInfo &getFunctionInfo(const FunctionDecl *FD);
const CGFunctionInfo &getFunctionInfo(const CXXMethodDecl *MD);
const CGFunctionInfo &getFunctionInfo(const ObjCMethodDecl *MD);
2009-12-01 06:08:04 -05:00
const CGFunctionInfo &getFunctionInfo(const CXXConstructorDecl *D,
CXXCtorType Type);
const CGFunctionInfo &getFunctionInfo(const CXXDestructorDecl *D,
CXXDtorType Type);
2010-02-16 04:31:36 -05:00
const CGFunctionInfo &getFunctionInfo(const CallArgList &Args,
const FunctionType *Ty) {
return getFunctionInfo(Ty->getResultType(), Args,
2010-04-02 04:55:10 -04:00
Ty->getExtInfo());
2010-02-16 04:31:36 -05:00
}
2010-07-13 13:21:42 -04:00
const CGFunctionInfo &getFunctionInfo(CanQual<FunctionProtoType> Ty,
bool IsRecursive = false);
const CGFunctionInfo &getFunctionInfo(CanQual<FunctionNoProtoType> Ty,
bool IsRecursive = false);
2010-02-16 04:31:36 -05:00
2009-10-14 14:03:49 -04:00
// getFunctionInfo - Get the function info for a member function.
const CGFunctionInfo &getFunctionInfo(const CXXRecordDecl *RD,
const FunctionProtoType *FTP);
/// getFunctionInfo - Get the function info for a function described by a
/// return type and argument types. If the calling convention is not
/// specified, the "C" calling convention will be used.
const CGFunctionInfo &getFunctionInfo(QualType ResTy,
const CallArgList &Args,
2010-04-02 04:55:10 -04:00
const FunctionType::ExtInfo &Info);
2009-10-14 14:03:49 -04:00
const CGFunctionInfo &getFunctionInfo(QualType ResTy,
const FunctionArgList &Args,
2010-04-02 04:55:10 -04:00
const FunctionType::ExtInfo &Info);
2010-03-03 12:28:16 -05:00
/// Retrieves the ABI information for the given function signature.
///
/// \param ArgTys - must all actually be canonical as params
const CGFunctionInfo &getFunctionInfo(CanQualType RetTy,
const llvm::SmallVectorImpl<CanQualType> &ArgTys,
2010-07-13 13:21:42 -04:00
const FunctionType::ExtInfo &Info,
bool IsRecursive = false);
2009-10-14 14:03:49 -04:00
2010-04-02 04:55:10 -04:00
/// \brief Compute a new LLVM record layout object for the given record.
CGRecordLayout *ComputeRecordLayout(const RecordDecl *D);
2009-06-02 13:58:47 -04:00
2010-04-02 04:55:10 -04:00
public: // These are internal details of CGT that shouldn't be used externally.
2009-06-02 13:58:47 -04:00
/// ConvertTagDeclType - Lay out a tagged decl type like struct or union or
/// enum.
const llvm::Type *ConvertTagDeclType(const TagDecl *TD);
/// 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.
2010-07-13 13:21:42 -04:00
void GetExpandedTypes(QualType Ty, std::vector<const llvm::Type*> &ArgTys,
bool IsRecursive);
2010-05-27 11:17:06 -04:00
/// ContainsPointerToDataMember - Return whether the given type contains a
/// pointer to a data member.
bool ContainsPointerToDataMember(QualType T);
/// ContainsPointerToDataMember - Return whether the record decl contains a
/// pointer to a data member.
bool ContainsPointerToDataMember(const CXXRecordDecl *RD);
2009-06-02 13:58:47 -04:00
};
} // end namespace CodeGen
} // end namespace clang
#endif