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