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