1*67e74705SXin Li //===----- CGCXXABI.h - Interface to C++ ABIs -------------------*- C++ -*-===// 2*67e74705SXin Li // 3*67e74705SXin Li // The LLVM Compiler Infrastructure 4*67e74705SXin Li // 5*67e74705SXin Li // This file is distributed under the University of Illinois Open Source 6*67e74705SXin Li // License. See LICENSE.TXT for details. 7*67e74705SXin Li // 8*67e74705SXin Li //===----------------------------------------------------------------------===// 9*67e74705SXin Li // 10*67e74705SXin Li // This provides an abstract class for C++ code generation. Concrete subclasses 11*67e74705SXin Li // of this implement code generation for specific C++ ABIs. 12*67e74705SXin Li // 13*67e74705SXin Li //===----------------------------------------------------------------------===// 14*67e74705SXin Li 15*67e74705SXin Li #ifndef LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H 16*67e74705SXin Li #define LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H 17*67e74705SXin Li 18*67e74705SXin Li #include "CodeGenFunction.h" 19*67e74705SXin Li #include "clang/Basic/LLVM.h" 20*67e74705SXin Li 21*67e74705SXin Li namespace llvm { 22*67e74705SXin Li class Constant; 23*67e74705SXin Li class Type; 24*67e74705SXin Li class Value; 25*67e74705SXin Li class CallInst; 26*67e74705SXin Li } 27*67e74705SXin Li 28*67e74705SXin Li namespace clang { 29*67e74705SXin Li class CastExpr; 30*67e74705SXin Li class CXXConstructorDecl; 31*67e74705SXin Li class CXXDestructorDecl; 32*67e74705SXin Li class CXXMethodDecl; 33*67e74705SXin Li class CXXRecordDecl; 34*67e74705SXin Li class FieldDecl; 35*67e74705SXin Li class MangleContext; 36*67e74705SXin Li 37*67e74705SXin Li namespace CodeGen { 38*67e74705SXin Li class CodeGenFunction; 39*67e74705SXin Li class CodeGenModule; 40*67e74705SXin Li struct CatchTypeInfo; 41*67e74705SXin Li 42*67e74705SXin Li /// \brief Implements C++ ABI-specific code generation functions. 43*67e74705SXin Li class CGCXXABI { 44*67e74705SXin Li protected: 45*67e74705SXin Li CodeGenModule &CGM; 46*67e74705SXin Li std::unique_ptr<MangleContext> MangleCtx; 47*67e74705SXin Li CGCXXABI(CodeGenModule & CGM)48*67e74705SXin Li CGCXXABI(CodeGenModule &CGM) 49*67e74705SXin Li : CGM(CGM), MangleCtx(CGM.getContext().createMangleContext()) {} 50*67e74705SXin Li 51*67e74705SXin Li protected: getThisDecl(CodeGenFunction & CGF)52*67e74705SXin Li ImplicitParamDecl *getThisDecl(CodeGenFunction &CGF) { 53*67e74705SXin Li return CGF.CXXABIThisDecl; 54*67e74705SXin Li } getThisValue(CodeGenFunction & CGF)55*67e74705SXin Li llvm::Value *getThisValue(CodeGenFunction &CGF) { 56*67e74705SXin Li return CGF.CXXABIThisValue; 57*67e74705SXin Li } getThisAddress(CodeGenFunction & CGF)58*67e74705SXin Li Address getThisAddress(CodeGenFunction &CGF) { 59*67e74705SXin Li return Address(CGF.CXXABIThisValue, CGF.CXXABIThisAlignment); 60*67e74705SXin Li } 61*67e74705SXin Li 62*67e74705SXin Li /// Issue a diagnostic about unsupported features in the ABI. 63*67e74705SXin Li void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S); 64*67e74705SXin Li 65*67e74705SXin Li /// Get a null value for unsupported member pointers. 66*67e74705SXin Li llvm::Constant *GetBogusMemberPointer(QualType T); 67*67e74705SXin Li getStructorImplicitParamDecl(CodeGenFunction & CGF)68*67e74705SXin Li ImplicitParamDecl *&getStructorImplicitParamDecl(CodeGenFunction &CGF) { 69*67e74705SXin Li return CGF.CXXStructorImplicitParamDecl; 70*67e74705SXin Li } getStructorImplicitParamValue(CodeGenFunction & CGF)71*67e74705SXin Li llvm::Value *&getStructorImplicitParamValue(CodeGenFunction &CGF) { 72*67e74705SXin Li return CGF.CXXStructorImplicitParamValue; 73*67e74705SXin Li } 74*67e74705SXin Li 75*67e74705SXin Li /// Perform prolog initialization of the parameter variable suitable 76*67e74705SXin Li /// for 'this' emitted by buildThisParam. 77*67e74705SXin Li void EmitThisParam(CodeGenFunction &CGF); 78*67e74705SXin Li getContext()79*67e74705SXin Li ASTContext &getContext() const { return CGM.getContext(); } 80*67e74705SXin Li 81*67e74705SXin Li virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType); 82*67e74705SXin Li virtual bool requiresArrayCookie(const CXXNewExpr *E); 83*67e74705SXin Li 84*67e74705SXin Li /// Determine whether there's something special about the rules of 85*67e74705SXin Li /// the ABI tell us that 'this' is a complete object within the 86*67e74705SXin Li /// given function. Obvious common logic like being defined on a 87*67e74705SXin Li /// final class will have been taken care of by the caller. 88*67e74705SXin Li virtual bool isThisCompleteObject(GlobalDecl GD) const = 0; 89*67e74705SXin Li 90*67e74705SXin Li public: 91*67e74705SXin Li 92*67e74705SXin Li virtual ~CGCXXABI(); 93*67e74705SXin Li 94*67e74705SXin Li /// Gets the mangle context. getMangleContext()95*67e74705SXin Li MangleContext &getMangleContext() { 96*67e74705SXin Li return *MangleCtx; 97*67e74705SXin Li } 98*67e74705SXin Li 99*67e74705SXin Li /// Returns true if the given constructor or destructor is one of the 100*67e74705SXin Li /// kinds that the ABI says returns 'this' (only applies when called 101*67e74705SXin Li /// non-virtually for destructors). 102*67e74705SXin Li /// 103*67e74705SXin Li /// There currently is no way to indicate if a destructor returns 'this' 104*67e74705SXin Li /// when called virtually, and code generation does not support the case. HasThisReturn(GlobalDecl GD)105*67e74705SXin Li virtual bool HasThisReturn(GlobalDecl GD) const { return false; } 106*67e74705SXin Li hasMostDerivedReturn(GlobalDecl GD)107*67e74705SXin Li virtual bool hasMostDerivedReturn(GlobalDecl GD) const { return false; } 108*67e74705SXin Li 109*67e74705SXin Li /// Returns true if the target allows calling a function through a pointer 110*67e74705SXin Li /// with a different signature than the actual function (or equivalently, 111*67e74705SXin Li /// bitcasting a function or function pointer to a different function type). 112*67e74705SXin Li /// In principle in the most general case this could depend on the target, the 113*67e74705SXin Li /// calling convention, and the actual types of the arguments and return 114*67e74705SXin Li /// value. Here it just means whether the signature mismatch could *ever* be 115*67e74705SXin Li /// allowed; in other words, does the target do strict checking of signatures 116*67e74705SXin Li /// for all calls. canCallMismatchedFunctionType()117*67e74705SXin Li virtual bool canCallMismatchedFunctionType() const { return true; } 118*67e74705SXin Li 119*67e74705SXin Li /// If the C++ ABI requires the given type be returned in a particular way, 120*67e74705SXin Li /// this method sets RetAI and returns true. 121*67e74705SXin Li virtual bool classifyReturnType(CGFunctionInfo &FI) const = 0; 122*67e74705SXin Li 123*67e74705SXin Li /// Specify how one should pass an argument of a record type. 124*67e74705SXin Li enum RecordArgABI { 125*67e74705SXin Li /// Pass it using the normal C aggregate rules for the ABI, potentially 126*67e74705SXin Li /// introducing extra copies and passing some or all of it in registers. 127*67e74705SXin Li RAA_Default = 0, 128*67e74705SXin Li 129*67e74705SXin Li /// Pass it on the stack using its defined layout. The argument must be 130*67e74705SXin Li /// evaluated directly into the correct stack position in the arguments area, 131*67e74705SXin Li /// and the call machinery must not move it or introduce extra copies. 132*67e74705SXin Li RAA_DirectInMemory, 133*67e74705SXin Li 134*67e74705SXin Li /// Pass it as a pointer to temporary memory. 135*67e74705SXin Li RAA_Indirect 136*67e74705SXin Li }; 137*67e74705SXin Li 138*67e74705SXin Li /// Returns true if C++ allows us to copy the memory of an object of type RD 139*67e74705SXin Li /// when it is passed as an argument. 140*67e74705SXin Li bool canCopyArgument(const CXXRecordDecl *RD) const; 141*67e74705SXin Li 142*67e74705SXin Li /// Returns how an argument of the given record type should be passed. 143*67e74705SXin Li virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const = 0; 144*67e74705SXin Li 145*67e74705SXin Li /// Returns true if the implicit 'sret' parameter comes after the implicit 146*67e74705SXin Li /// 'this' parameter of C++ instance methods. isSRetParameterAfterThis()147*67e74705SXin Li virtual bool isSRetParameterAfterThis() const { return false; } 148*67e74705SXin Li 149*67e74705SXin Li /// Find the LLVM type used to represent the given member pointer 150*67e74705SXin Li /// type. 151*67e74705SXin Li virtual llvm::Type * 152*67e74705SXin Li ConvertMemberPointerType(const MemberPointerType *MPT); 153*67e74705SXin Li 154*67e74705SXin Li /// Load a member function from an object and a member function 155*67e74705SXin Li /// pointer. Apply the this-adjustment and set 'This' to the 156*67e74705SXin Li /// adjusted value. 157*67e74705SXin Li virtual llvm::Value *EmitLoadOfMemberFunctionPointer( 158*67e74705SXin Li CodeGenFunction &CGF, const Expr *E, Address This, 159*67e74705SXin Li llvm::Value *&ThisPtrForCall, llvm::Value *MemPtr, 160*67e74705SXin Li const MemberPointerType *MPT); 161*67e74705SXin Li 162*67e74705SXin Li /// Calculate an l-value from an object and a data member pointer. 163*67e74705SXin Li virtual llvm::Value * 164*67e74705SXin Li EmitMemberDataPointerAddress(CodeGenFunction &CGF, const Expr *E, 165*67e74705SXin Li Address Base, llvm::Value *MemPtr, 166*67e74705SXin Li const MemberPointerType *MPT); 167*67e74705SXin Li 168*67e74705SXin Li /// Perform a derived-to-base, base-to-derived, or bitcast member 169*67e74705SXin Li /// pointer conversion. 170*67e74705SXin Li virtual llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF, 171*67e74705SXin Li const CastExpr *E, 172*67e74705SXin Li llvm::Value *Src); 173*67e74705SXin Li 174*67e74705SXin Li /// Perform a derived-to-base, base-to-derived, or bitcast member 175*67e74705SXin Li /// pointer conversion on a constant value. 176*67e74705SXin Li virtual llvm::Constant *EmitMemberPointerConversion(const CastExpr *E, 177*67e74705SXin Li llvm::Constant *Src); 178*67e74705SXin Li 179*67e74705SXin Li /// Return true if the given member pointer can be zero-initialized 180*67e74705SXin Li /// (in the C++ sense) with an LLVM zeroinitializer. 181*67e74705SXin Li virtual bool isZeroInitializable(const MemberPointerType *MPT); 182*67e74705SXin Li 183*67e74705SXin Li /// Return whether or not a member pointers type is convertible to an IR type. isMemberPointerConvertible(const MemberPointerType * MPT)184*67e74705SXin Li virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const { 185*67e74705SXin Li return true; 186*67e74705SXin Li } 187*67e74705SXin Li 188*67e74705SXin Li /// Create a null member pointer of the given type. 189*67e74705SXin Li virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT); 190*67e74705SXin Li 191*67e74705SXin Li /// Create a member pointer for the given method. 192*67e74705SXin Li virtual llvm::Constant *EmitMemberFunctionPointer(const CXXMethodDecl *MD); 193*67e74705SXin Li 194*67e74705SXin Li /// Create a member pointer for the given field. 195*67e74705SXin Li virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT, 196*67e74705SXin Li CharUnits offset); 197*67e74705SXin Li 198*67e74705SXin Li /// Create a member pointer for the given member pointer constant. 199*67e74705SXin Li virtual llvm::Constant *EmitMemberPointer(const APValue &MP, QualType MPT); 200*67e74705SXin Li 201*67e74705SXin Li /// Emit a comparison between two member pointers. Returns an i1. 202*67e74705SXin Li virtual llvm::Value * 203*67e74705SXin Li EmitMemberPointerComparison(CodeGenFunction &CGF, 204*67e74705SXin Li llvm::Value *L, 205*67e74705SXin Li llvm::Value *R, 206*67e74705SXin Li const MemberPointerType *MPT, 207*67e74705SXin Li bool Inequality); 208*67e74705SXin Li 209*67e74705SXin Li /// Determine if a member pointer is non-null. Returns an i1. 210*67e74705SXin Li virtual llvm::Value * 211*67e74705SXin Li EmitMemberPointerIsNotNull(CodeGenFunction &CGF, 212*67e74705SXin Li llvm::Value *MemPtr, 213*67e74705SXin Li const MemberPointerType *MPT); 214*67e74705SXin Li 215*67e74705SXin Li protected: 216*67e74705SXin Li /// A utility method for computing the offset required for the given 217*67e74705SXin Li /// base-to-derived or derived-to-base member-pointer conversion. 218*67e74705SXin Li /// Does not handle virtual conversions (in case we ever fully 219*67e74705SXin Li /// support an ABI that allows this). Returns null if no adjustment 220*67e74705SXin Li /// is required. 221*67e74705SXin Li llvm::Constant *getMemberPointerAdjustment(const CastExpr *E); 222*67e74705SXin Li 223*67e74705SXin Li /// \brief Computes the non-virtual adjustment needed for a member pointer 224*67e74705SXin Li /// conversion along an inheritance path stored in an APValue. Unlike 225*67e74705SXin Li /// getMemberPointerAdjustment(), the adjustment can be negative if the path 226*67e74705SXin Li /// is from a derived type to a base type. 227*67e74705SXin Li CharUnits getMemberPointerPathAdjustment(const APValue &MP); 228*67e74705SXin Li 229*67e74705SXin Li public: 230*67e74705SXin Li virtual void emitVirtualObjectDelete(CodeGenFunction &CGF, 231*67e74705SXin Li const CXXDeleteExpr *DE, 232*67e74705SXin Li Address Ptr, QualType ElementType, 233*67e74705SXin Li const CXXDestructorDecl *Dtor) = 0; 234*67e74705SXin Li virtual void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) = 0; 235*67e74705SXin Li virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) = 0; getThrowInfo(QualType T)236*67e74705SXin Li virtual llvm::GlobalVariable *getThrowInfo(QualType T) { return nullptr; } 237*67e74705SXin Li 238*67e74705SXin Li /// \brief Determine whether it's possible to emit a vtable for \p RD, even 239*67e74705SXin Li /// though we do not know that the vtable has been marked as used by semantic 240*67e74705SXin Li /// analysis. 241*67e74705SXin Li virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const = 0; 242*67e74705SXin Li 243*67e74705SXin Li virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) = 0; 244*67e74705SXin Li 245*67e74705SXin Li virtual llvm::CallInst * 246*67e74705SXin Li emitTerminateForUnexpectedException(CodeGenFunction &CGF, 247*67e74705SXin Li llvm::Value *Exn); 248*67e74705SXin Li 249*67e74705SXin Li virtual llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) = 0; 250*67e74705SXin Li virtual CatchTypeInfo 251*67e74705SXin Li getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType) = 0; 252*67e74705SXin Li virtual CatchTypeInfo getCatchAllTypeInfo(); 253*67e74705SXin Li 254*67e74705SXin Li virtual bool shouldTypeidBeNullChecked(bool IsDeref, 255*67e74705SXin Li QualType SrcRecordTy) = 0; 256*67e74705SXin Li virtual void EmitBadTypeidCall(CodeGenFunction &CGF) = 0; 257*67e74705SXin Li virtual llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy, 258*67e74705SXin Li Address ThisPtr, 259*67e74705SXin Li llvm::Type *StdTypeInfoPtrTy) = 0; 260*67e74705SXin Li 261*67e74705SXin Li virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr, 262*67e74705SXin Li QualType SrcRecordTy) = 0; 263*67e74705SXin Li 264*67e74705SXin Li virtual llvm::Value * 265*67e74705SXin Li EmitDynamicCastCall(CodeGenFunction &CGF, Address Value, 266*67e74705SXin Li QualType SrcRecordTy, QualType DestTy, 267*67e74705SXin Li QualType DestRecordTy, llvm::BasicBlock *CastEnd) = 0; 268*67e74705SXin Li 269*67e74705SXin Li virtual llvm::Value *EmitDynamicCastToVoid(CodeGenFunction &CGF, 270*67e74705SXin Li Address Value, 271*67e74705SXin Li QualType SrcRecordTy, 272*67e74705SXin Li QualType DestTy) = 0; 273*67e74705SXin Li 274*67e74705SXin Li virtual bool EmitBadCastCall(CodeGenFunction &CGF) = 0; 275*67e74705SXin Li 276*67e74705SXin Li virtual llvm::Value *GetVirtualBaseClassOffset(CodeGenFunction &CGF, 277*67e74705SXin Li Address This, 278*67e74705SXin Li const CXXRecordDecl *ClassDecl, 279*67e74705SXin Li const CXXRecordDecl *BaseClassDecl) = 0; 280*67e74705SXin Li 281*67e74705SXin Li virtual llvm::BasicBlock *EmitCtorCompleteObjectHandler(CodeGenFunction &CGF, 282*67e74705SXin Li const CXXRecordDecl *RD); 283*67e74705SXin Li 284*67e74705SXin Li /// Emit the code to initialize hidden members required 285*67e74705SXin Li /// to handle virtual inheritance, if needed by the ABI. 286*67e74705SXin Li virtual void initializeHiddenVirtualInheritanceMembers(CodeGenFunction & CGF,const CXXRecordDecl * RD)287*67e74705SXin Li initializeHiddenVirtualInheritanceMembers(CodeGenFunction &CGF, 288*67e74705SXin Li const CXXRecordDecl *RD) {} 289*67e74705SXin Li 290*67e74705SXin Li /// Emit constructor variants required by this ABI. 291*67e74705SXin Li virtual void EmitCXXConstructors(const CXXConstructorDecl *D) = 0; 292*67e74705SXin Li 293*67e74705SXin Li /// Build the signature of the given constructor or destructor variant by 294*67e74705SXin Li /// adding any required parameters. For convenience, ArgTys has been 295*67e74705SXin Li /// initialized with the type of 'this'. 296*67e74705SXin Li virtual void buildStructorSignature(const CXXMethodDecl *MD, StructorType T, 297*67e74705SXin Li SmallVectorImpl<CanQualType> &ArgTys) = 0; 298*67e74705SXin Li 299*67e74705SXin Li /// Returns true if the given destructor type should be emitted as a linkonce 300*67e74705SXin Li /// delegating thunk, regardless of whether the dtor is defined in this TU or 301*67e74705SXin Li /// not. 302*67e74705SXin Li virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor, 303*67e74705SXin Li CXXDtorType DT) const = 0; 304*67e74705SXin Li 305*67e74705SXin Li /// Emit destructor variants required by this ABI. 306*67e74705SXin Li virtual void EmitCXXDestructors(const CXXDestructorDecl *D) = 0; 307*67e74705SXin Li 308*67e74705SXin Li /// Get the type of the implicit "this" parameter used by a method. May return 309*67e74705SXin Li /// zero if no specific type is applicable, e.g. if the ABI expects the "this" 310*67e74705SXin Li /// parameter to point to some artificial offset in a complete object due to 311*67e74705SXin Li /// vbases being reordered. 312*67e74705SXin Li virtual const CXXRecordDecl * getThisArgumentTypeForMethod(const CXXMethodDecl * MD)313*67e74705SXin Li getThisArgumentTypeForMethod(const CXXMethodDecl *MD) { 314*67e74705SXin Li return MD->getParent(); 315*67e74705SXin Li } 316*67e74705SXin Li 317*67e74705SXin Li /// Perform ABI-specific "this" argument adjustment required prior to 318*67e74705SXin Li /// a call of a virtual function. 319*67e74705SXin Li /// The "VirtualCall" argument is true iff the call itself is virtual. 320*67e74705SXin Li virtual Address adjustThisArgumentForVirtualFunctionCall(CodeGenFunction & CGF,GlobalDecl GD,Address This,bool VirtualCall)321*67e74705SXin Li adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD, 322*67e74705SXin Li Address This, bool VirtualCall) { 323*67e74705SXin Li return This; 324*67e74705SXin Li } 325*67e74705SXin Li 326*67e74705SXin Li /// Build a parameter variable suitable for 'this'. 327*67e74705SXin Li void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params); 328*67e74705SXin Li 329*67e74705SXin Li /// Insert any ABI-specific implicit parameters into the parameter list for a 330*67e74705SXin Li /// function. This generally involves extra data for constructors and 331*67e74705SXin Li /// destructors. 332*67e74705SXin Li /// 333*67e74705SXin Li /// ABIs may also choose to override the return type, which has been 334*67e74705SXin Li /// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or 335*67e74705SXin Li /// the formal return type of the function otherwise. 336*67e74705SXin Li virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy, 337*67e74705SXin Li FunctionArgList &Params) = 0; 338*67e74705SXin Li 339*67e74705SXin Li /// Get the ABI-specific "this" parameter adjustment to apply in the prologue 340*67e74705SXin Li /// of a virtual function. getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD)341*67e74705SXin Li virtual CharUnits getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD) { 342*67e74705SXin Li return CharUnits::Zero(); 343*67e74705SXin Li } 344*67e74705SXin Li 345*67e74705SXin Li /// Perform ABI-specific "this" parameter adjustment in a virtual function 346*67e74705SXin Li /// prologue. adjustThisParameterInVirtualFunctionPrologue(CodeGenFunction & CGF,GlobalDecl GD,llvm::Value * This)347*67e74705SXin Li virtual llvm::Value *adjustThisParameterInVirtualFunctionPrologue( 348*67e74705SXin Li CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This) { 349*67e74705SXin Li return This; 350*67e74705SXin Li } 351*67e74705SXin Li 352*67e74705SXin Li /// Emit the ABI-specific prolog for the function. 353*67e74705SXin Li virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0; 354*67e74705SXin Li 355*67e74705SXin Li /// Add any ABI-specific implicit arguments needed to call a constructor. 356*67e74705SXin Li /// 357*67e74705SXin Li /// \return The number of args added to the call, which is typically zero or 358*67e74705SXin Li /// one. 359*67e74705SXin Li virtual unsigned 360*67e74705SXin Li addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D, 361*67e74705SXin Li CXXCtorType Type, bool ForVirtualBase, 362*67e74705SXin Li bool Delegating, CallArgList &Args) = 0; 363*67e74705SXin Li 364*67e74705SXin Li /// Emit the destructor call. 365*67e74705SXin Li virtual void EmitDestructorCall(CodeGenFunction &CGF, 366*67e74705SXin Li const CXXDestructorDecl *DD, CXXDtorType Type, 367*67e74705SXin Li bool ForVirtualBase, bool Delegating, 368*67e74705SXin Li Address This) = 0; 369*67e74705SXin Li 370*67e74705SXin Li /// Emits the VTable definitions required for the given record type. 371*67e74705SXin Li virtual void emitVTableDefinitions(CodeGenVTables &CGVT, 372*67e74705SXin Li const CXXRecordDecl *RD) = 0; 373*67e74705SXin Li 374*67e74705SXin Li /// Checks if ABI requires extra virtual offset for vtable field. 375*67e74705SXin Li virtual bool 376*67e74705SXin Li isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF, 377*67e74705SXin Li CodeGenFunction::VPtr Vptr) = 0; 378*67e74705SXin Li 379*67e74705SXin Li /// Checks if ABI requires to initilize vptrs for given dynamic class. 380*67e74705SXin Li virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) = 0; 381*67e74705SXin Li 382*67e74705SXin Li /// Get the address point of the vtable for the given base subobject. 383*67e74705SXin Li virtual llvm::Constant * 384*67e74705SXin Li getVTableAddressPoint(BaseSubobject Base, 385*67e74705SXin Li const CXXRecordDecl *VTableClass) = 0; 386*67e74705SXin Li 387*67e74705SXin Li /// Get the address point of the vtable for the given base subobject while 388*67e74705SXin Li /// building a constructor or a destructor. 389*67e74705SXin Li virtual llvm::Value * 390*67e74705SXin Li getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl *RD, 391*67e74705SXin Li BaseSubobject Base, 392*67e74705SXin Li const CXXRecordDecl *NearestVBase) = 0; 393*67e74705SXin Li 394*67e74705SXin Li /// Get the address point of the vtable for the given base subobject while 395*67e74705SXin Li /// building a constexpr. 396*67e74705SXin Li virtual llvm::Constant * 397*67e74705SXin Li getVTableAddressPointForConstExpr(BaseSubobject Base, 398*67e74705SXin Li const CXXRecordDecl *VTableClass) = 0; 399*67e74705SXin Li 400*67e74705SXin Li /// Get the address of the vtable for the given record decl which should be 401*67e74705SXin Li /// used for the vptr at the given offset in RD. 402*67e74705SXin Li virtual llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD, 403*67e74705SXin Li CharUnits VPtrOffset) = 0; 404*67e74705SXin Li 405*67e74705SXin Li /// Build a virtual function pointer in the ABI-specific way. 406*67e74705SXin Li virtual llvm::Value *getVirtualFunctionPointer(CodeGenFunction &CGF, 407*67e74705SXin Li GlobalDecl GD, 408*67e74705SXin Li Address This, 409*67e74705SXin Li llvm::Type *Ty, 410*67e74705SXin Li SourceLocation Loc) = 0; 411*67e74705SXin Li 412*67e74705SXin Li /// Emit the ABI-specific virtual destructor call. 413*67e74705SXin Li virtual llvm::Value * 414*67e74705SXin Li EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor, 415*67e74705SXin Li CXXDtorType DtorType, Address This, 416*67e74705SXin Li const CXXMemberCallExpr *CE) = 0; 417*67e74705SXin Li adjustCallArgsForDestructorThunk(CodeGenFunction & CGF,GlobalDecl GD,CallArgList & CallArgs)418*67e74705SXin Li virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF, 419*67e74705SXin Li GlobalDecl GD, 420*67e74705SXin Li CallArgList &CallArgs) {} 421*67e74705SXin Li 422*67e74705SXin Li /// Emit any tables needed to implement virtual inheritance. For Itanium, 423*67e74705SXin Li /// this emits virtual table tables. For the MSVC++ ABI, this emits virtual 424*67e74705SXin Li /// base tables. 425*67e74705SXin Li virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD) = 0; 426*67e74705SXin Li 427*67e74705SXin Li virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable, 428*67e74705SXin Li GlobalDecl GD, bool ReturnAdjustment) = 0; 429*67e74705SXin Li 430*67e74705SXin Li virtual llvm::Value *performThisAdjustment(CodeGenFunction &CGF, 431*67e74705SXin Li Address This, 432*67e74705SXin Li const ThisAdjustment &TA) = 0; 433*67e74705SXin Li 434*67e74705SXin Li virtual llvm::Value *performReturnAdjustment(CodeGenFunction &CGF, 435*67e74705SXin Li Address Ret, 436*67e74705SXin Li const ReturnAdjustment &RA) = 0; 437*67e74705SXin Li 438*67e74705SXin Li virtual void EmitReturnFromThunk(CodeGenFunction &CGF, 439*67e74705SXin Li RValue RV, QualType ResultType); 440*67e74705SXin Li 441*67e74705SXin Li virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *, 442*67e74705SXin Li FunctionArgList &Args) const = 0; 443*67e74705SXin Li 444*67e74705SXin Li /// Gets the offsets of all the virtual base pointers in a given class. 445*67e74705SXin Li virtual std::vector<CharUnits> getVBPtrOffsets(const CXXRecordDecl *RD); 446*67e74705SXin Li 447*67e74705SXin Li /// Gets the pure virtual member call function. 448*67e74705SXin Li virtual StringRef GetPureVirtualCallName() = 0; 449*67e74705SXin Li 450*67e74705SXin Li /// Gets the deleted virtual member call name. 451*67e74705SXin Li virtual StringRef GetDeletedVirtualCallName() = 0; 452*67e74705SXin Li 453*67e74705SXin Li /**************************** Array cookies ******************************/ 454*67e74705SXin Li 455*67e74705SXin Li /// Returns the extra size required in order to store the array 456*67e74705SXin Li /// cookie for the given new-expression. May return 0 to indicate that no 457*67e74705SXin Li /// array cookie is required. 458*67e74705SXin Li /// 459*67e74705SXin Li /// Several cases are filtered out before this method is called: 460*67e74705SXin Li /// - non-array allocations never need a cookie 461*67e74705SXin Li /// - calls to \::operator new(size_t, void*) never need a cookie 462*67e74705SXin Li /// 463*67e74705SXin Li /// \param expr - the new-expression being allocated. 464*67e74705SXin Li virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr); 465*67e74705SXin Li 466*67e74705SXin Li /// Initialize the array cookie for the given allocation. 467*67e74705SXin Li /// 468*67e74705SXin Li /// \param NewPtr - a char* which is the presumed-non-null 469*67e74705SXin Li /// return value of the allocation function 470*67e74705SXin Li /// \param NumElements - the computed number of elements, 471*67e74705SXin Li /// potentially collapsed from the multidimensional array case; 472*67e74705SXin Li /// always a size_t 473*67e74705SXin Li /// \param ElementType - the base element allocated type, 474*67e74705SXin Li /// i.e. the allocated type after stripping all array types 475*67e74705SXin Li virtual Address InitializeArrayCookie(CodeGenFunction &CGF, 476*67e74705SXin Li Address NewPtr, 477*67e74705SXin Li llvm::Value *NumElements, 478*67e74705SXin Li const CXXNewExpr *expr, 479*67e74705SXin Li QualType ElementType); 480*67e74705SXin Li 481*67e74705SXin Li /// Reads the array cookie associated with the given pointer, 482*67e74705SXin Li /// if it has one. 483*67e74705SXin Li /// 484*67e74705SXin Li /// \param Ptr - a pointer to the first element in the array 485*67e74705SXin Li /// \param ElementType - the base element type of elements of the array 486*67e74705SXin Li /// \param NumElements - an out parameter which will be initialized 487*67e74705SXin Li /// with the number of elements allocated, or zero if there is no 488*67e74705SXin Li /// cookie 489*67e74705SXin Li /// \param AllocPtr - an out parameter which will be initialized 490*67e74705SXin Li /// with a char* pointing to the address returned by the allocation 491*67e74705SXin Li /// function 492*67e74705SXin Li /// \param CookieSize - an out parameter which will be initialized 493*67e74705SXin Li /// with the size of the cookie, or zero if there is no cookie 494*67e74705SXin Li virtual void ReadArrayCookie(CodeGenFunction &CGF, Address Ptr, 495*67e74705SXin Li const CXXDeleteExpr *expr, 496*67e74705SXin Li QualType ElementType, llvm::Value *&NumElements, 497*67e74705SXin Li llvm::Value *&AllocPtr, CharUnits &CookieSize); 498*67e74705SXin Li 499*67e74705SXin Li /// Return whether the given global decl needs a VTT parameter. 500*67e74705SXin Li virtual bool NeedsVTTParameter(GlobalDecl GD); 501*67e74705SXin Li 502*67e74705SXin Li protected: 503*67e74705SXin Li /// Returns the extra size required in order to store the array 504*67e74705SXin Li /// cookie for the given type. Assumes that an array cookie is 505*67e74705SXin Li /// required. 506*67e74705SXin Li virtual CharUnits getArrayCookieSizeImpl(QualType elementType); 507*67e74705SXin Li 508*67e74705SXin Li /// Reads the array cookie for an allocation which is known to have one. 509*67e74705SXin Li /// This is called by the standard implementation of ReadArrayCookie. 510*67e74705SXin Li /// 511*67e74705SXin Li /// \param ptr - a pointer to the allocation made for an array, as a char* 512*67e74705SXin Li /// \param cookieSize - the computed cookie size of an array 513*67e74705SXin Li /// 514*67e74705SXin Li /// Other parameters are as above. 515*67e74705SXin Li /// 516*67e74705SXin Li /// \return a size_t 517*67e74705SXin Li virtual llvm::Value *readArrayCookieImpl(CodeGenFunction &IGF, Address ptr, 518*67e74705SXin Li CharUnits cookieSize); 519*67e74705SXin Li 520*67e74705SXin Li public: 521*67e74705SXin Li 522*67e74705SXin Li /*************************** Static local guards ****************************/ 523*67e74705SXin Li 524*67e74705SXin Li /// Emits the guarded initializer and destructor setup for the given 525*67e74705SXin Li /// variable, given that it couldn't be emitted as a constant. 526*67e74705SXin Li /// If \p PerformInit is false, the initialization has been folded to a 527*67e74705SXin Li /// constant and should not be performed. 528*67e74705SXin Li /// 529*67e74705SXin Li /// The variable may be: 530*67e74705SXin Li /// - a static local variable 531*67e74705SXin Li /// - a static data member of a class template instantiation 532*67e74705SXin Li virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D, 533*67e74705SXin Li llvm::GlobalVariable *DeclPtr, 534*67e74705SXin Li bool PerformInit) = 0; 535*67e74705SXin Li 536*67e74705SXin Li /// Emit code to force the execution of a destructor during global 537*67e74705SXin Li /// teardown. The default implementation of this uses atexit. 538*67e74705SXin Li /// 539*67e74705SXin Li /// \param Dtor - a function taking a single pointer argument 540*67e74705SXin Li /// \param Addr - a pointer to pass to the destructor function. 541*67e74705SXin Li virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, 542*67e74705SXin Li llvm::Constant *Dtor, 543*67e74705SXin Li llvm::Constant *Addr) = 0; 544*67e74705SXin Li 545*67e74705SXin Li /*************************** thread_local initialization ********************/ 546*67e74705SXin Li 547*67e74705SXin Li /// Emits ABI-required functions necessary to initialize thread_local 548*67e74705SXin Li /// variables in this translation unit. 549*67e74705SXin Li /// 550*67e74705SXin Li /// \param CXXThreadLocals - The thread_local declarations in this translation 551*67e74705SXin Li /// unit. 552*67e74705SXin Li /// \param CXXThreadLocalInits - If this translation unit contains any 553*67e74705SXin Li /// non-constant initialization or non-trivial destruction for 554*67e74705SXin Li /// thread_local variables, a list of functions to perform the 555*67e74705SXin Li /// initialization. 556*67e74705SXin Li virtual void EmitThreadLocalInitFuncs( 557*67e74705SXin Li CodeGenModule &CGM, ArrayRef<const VarDecl *> CXXThreadLocals, 558*67e74705SXin Li ArrayRef<llvm::Function *> CXXThreadLocalInits, 559*67e74705SXin Li ArrayRef<const VarDecl *> CXXThreadLocalInitVars) = 0; 560*67e74705SXin Li 561*67e74705SXin Li // Determine if references to thread_local global variables can be made 562*67e74705SXin Li // directly or require access through a thread wrapper function. 563*67e74705SXin Li virtual bool usesThreadWrapperFunction() const = 0; 564*67e74705SXin Li 565*67e74705SXin Li /// Emit a reference to a non-local thread_local variable (including 566*67e74705SXin Li /// triggering the initialization of all thread_local variables in its 567*67e74705SXin Li /// translation unit). 568*67e74705SXin Li virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF, 569*67e74705SXin Li const VarDecl *VD, 570*67e74705SXin Li QualType LValType) = 0; 571*67e74705SXin Li 572*67e74705SXin Li /// Emit a single constructor/destructor with the given type from a C++ 573*67e74705SXin Li /// constructor Decl. 574*67e74705SXin Li virtual void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) = 0; 575*67e74705SXin Li }; 576*67e74705SXin Li 577*67e74705SXin Li // Create an instance of a C++ ABI class: 578*67e74705SXin Li 579*67e74705SXin Li /// Creates an Itanium-family ABI. 580*67e74705SXin Li CGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM); 581*67e74705SXin Li 582*67e74705SXin Li /// Creates a Microsoft-family ABI. 583*67e74705SXin Li CGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM); 584*67e74705SXin Li 585*67e74705SXin Li } 586*67e74705SXin Li } 587*67e74705SXin Li 588*67e74705SXin Li #endif 589