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