#ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENTYPES_H
#define LLVM_CLANG_LIB_CODEGEN_CODEGENTYPES_H
#include "CGCall.h"
#include "clang/AST/GlobalDecl.h"
#include "clang/CodeGen/CGFunctionInfo.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/IR/Module.h"
#include <vector>
namespace llvm {
class FunctionType;
class Module;
class DataLayout;
class Type;
class LLVMContext;
class StructType;
}
namespace clang {
class ASTContext;
template <typename> class CanQual;
class CXXConstructorDecl;
class CXXDestructorDecl;
class CXXMethodDecl;
class CodeGenOptions;
class FieldDecl;
class FunctionProtoType;
class ObjCInterfaceDecl;
class ObjCIvarDecl;
class PointerType;
class QualType;
class RecordDecl;
class TagDecl;
class TargetInfo;
class Type;
typedef CanQual<Type> CanQualType;
namespace CodeGen {
class ABIInfo;
class CGCXXABI;
class CGRecordLayout;
class CodeGenModule;
class RequiredArgs;
enum class StructorType {
Complete, Base, Deleting };
inline CXXCtorType toCXXCtorType(StructorType T) {
switch (T) {
case StructorType::Complete:
return Ctor_Complete;
case StructorType::Base:
return Ctor_Base;
case StructorType::Deleting:
llvm_unreachable("cannot have a deleting ctor");
}
llvm_unreachable("not a StructorType");
}
inline StructorType getFromCtorType(CXXCtorType T) {
switch (T) {
case Ctor_Complete:
return StructorType::Complete;
case Ctor_Base:
return StructorType::Base;
case Ctor_Comdat:
llvm_unreachable("not expecting a COMDAT");
case Ctor_CopyingClosure:
case Ctor_DefaultClosure:
llvm_unreachable("not expecting a closure");
}
llvm_unreachable("not a CXXCtorType");
}
inline CXXDtorType toCXXDtorType(StructorType T) {
switch (T) {
case StructorType::Complete:
return Dtor_Complete;
case StructorType::Base:
return Dtor_Base;
case StructorType::Deleting:
return Dtor_Deleting;
}
llvm_unreachable("not a StructorType");
}
inline StructorType getFromDtorType(CXXDtorType T) {
switch (T) {
case Dtor_Deleting:
return StructorType::Deleting;
case Dtor_Complete:
return StructorType::Complete;
case Dtor_Base:
return StructorType::Base;
case Dtor_Comdat:
llvm_unreachable("not expecting a COMDAT");
}
llvm_unreachable("not a CXXDtorType");
}
class CodeGenTypes {
CodeGenModule &CGM;
ASTContext &Context;
llvm::Module &TheModule;
const TargetInfo &Target;
CGCXXABI &TheCXXABI;
const ABIInfo &TheABIInfo;
llvm::DenseMap<const ObjCInterfaceType*, llvm::Type *> InterfaceTypes;
llvm::DenseMap<const Type*, CGRecordLayout *> CGRecordLayouts;
llvm::DenseMap<const Type*, llvm::StructType *> RecordDeclTypes;
llvm::FoldingSet<CGFunctionInfo> FunctionInfos;
llvm::SmallPtrSet<const Type*, 4> RecordsBeingLaidOut;
llvm::SmallPtrSet<const CGFunctionInfo*, 4> FunctionsBeingProcessed;
bool SkippedLayout;
SmallVector<const RecordDecl *, 8> DeferredRecords;
llvm::DenseMap<const Type *, llvm::Type *> TypeCache;
public:
CodeGenTypes(CodeGenModule &cgm);
~CodeGenTypes();
const llvm::DataLayout &getDataLayout() const {
return TheModule.getDataLayout();
}
ASTContext &getContext() const { return Context; }
const ABIInfo &getABIInfo() const { return TheABIInfo; }
const TargetInfo &getTarget() const { return Target; }
CGCXXABI &getCXXABI() const { return TheCXXABI; }
llvm::LLVMContext &getLLVMContext() { return TheModule.getContext(); }
llvm::Type *ConvertType(QualType T);
llvm::Type *ConvertFunctionType(QualType FT,
const FunctionDecl *FD = nullptr);
llvm::Type *ConvertTypeForMem(QualType T);
llvm::FunctionType *GetFunctionType(const CGFunctionInfo &Info);
llvm::FunctionType *GetFunctionType(GlobalDecl GD);
bool isFuncTypeConvertible(const FunctionType *FT);
bool isFuncParamTypeConvertible(QualType Ty);
llvm::Type *GetFunctionTypeForVTable(GlobalDecl GD);
const CGRecordLayout &getCGRecordLayout(const RecordDecl*);
void UpdateCompletedType(const TagDecl *TD);
void RefreshTypeCacheForClass(const CXXRecordDecl *RD);
const CGFunctionInfo &arrangeGlobalDeclaration(GlobalDecl GD);
const CGFunctionInfo &arrangeCall(const CGFunctionInfo &declFI,
const CallArgList &args);
const CGFunctionInfo &arrangeFunctionDeclaration(const FunctionDecl *FD);
const CGFunctionInfo &arrangeFreeFunctionCall(const CallArgList &Args,
const FunctionType *Ty,
bool ChainCall);
const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionProtoType> Ty,
const FunctionDecl *FD);
const CGFunctionInfo &arrangeFreeFunctionType(CanQual<FunctionNoProtoType> Ty);
const CGFunctionInfo &arrangeNullaryFunction();
const CGFunctionInfo &
arrangeBuiltinFunctionDeclaration(QualType resultType,
const FunctionArgList &args);
const CGFunctionInfo &
arrangeBuiltinFunctionDeclaration(CanQualType resultType,
ArrayRef<CanQualType> argTypes);
const CGFunctionInfo &arrangeBuiltinFunctionCall(QualType resultType,
const CallArgList &args);
const CGFunctionInfo &arrangeObjCMethodDeclaration(const ObjCMethodDecl *MD);
const CGFunctionInfo &arrangeObjCMessageSendSignature(const ObjCMethodDecl *MD,
QualType receiverType);
const CGFunctionInfo &arrangeUnprototypedObjCMessageSend(
QualType returnType,
const CallArgList &args);
const CGFunctionInfo &arrangeBlockFunctionDeclaration(
const FunctionProtoType *type,
const FunctionArgList &args);
const CGFunctionInfo &arrangeBlockFunctionCall(const CallArgList &args,
const FunctionType *type);
const CGFunctionInfo &arrangeCXXMethodDeclaration(const CXXMethodDecl *MD);
const CGFunctionInfo &arrangeCXXStructorDeclaration(const CXXMethodDecl *MD,
StructorType Type);
const CGFunctionInfo &arrangeCXXConstructorCall(const CallArgList &Args,
const CXXConstructorDecl *D,
CXXCtorType CtorKind,
unsigned ExtraArgs);
const CGFunctionInfo &arrangeCXXMethodCall(const CallArgList &args,
const FunctionProtoType *type,
RequiredArgs required);
const CGFunctionInfo &arrangeMSMemberPointerThunk(const CXXMethodDecl *MD);
const CGFunctionInfo &arrangeMSCtorClosure(const CXXConstructorDecl *CD,
CXXCtorType CT);
const CGFunctionInfo &arrangeCXXMethodType(const CXXRecordDecl *RD,
const FunctionProtoType *FTP,
const CXXMethodDecl *MD);
const CGFunctionInfo &arrangeLLVMFunctionInfo(CanQualType returnType,
bool instanceMethod,
bool chainCall,
ArrayRef<CanQualType> argTypes,
FunctionType::ExtInfo info,
ArrayRef<FunctionProtoType::ExtParameterInfo> paramInfos,
RequiredArgs args);
CGRecordLayout *ComputeRecordLayout(const RecordDecl *D,
llvm::StructType *Ty);
void addRecordTypeName(const RecordDecl *RD, llvm::StructType *Ty,
StringRef suffix);
public: llvm::StructType *ConvertRecordDeclType(const RecordDecl *TD);
void getExpandedTypes(QualType Ty,
SmallVectorImpl<llvm::Type *>::iterator &TI);
bool isZeroInitializable(QualType T);
bool isZeroInitializable(const RecordDecl *RD);
bool isRecordLayoutComplete(const Type *Ty) const;
bool noRecordsBeingLaidOut() const {
return RecordsBeingLaidOut.empty();
}
bool isRecordBeingLaidOut(const Type *Ty) const {
return RecordsBeingLaidOut.count(Ty);
}
};
} }
#endif