blob: 259c878f7fab09682305fb852a2142c559ccddca [file] [log] [blame]
Charles Davis4e786dd2010-05-25 19:52:27 +00001//===----- 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 Kramer2f5db8b2014-08-13 16:25:19 +000015#ifndef LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H
16#define LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H
Charles Davis4e786dd2010-05-25 19:52:27 +000017
John McCall5d865c322010-08-31 07:33:07 +000018#include "CodeGenFunction.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000019#include "clang/Basic/LLVM.h"
John McCall5d865c322010-08-31 07:33:07 +000020
John McCall475999d2010-08-22 00:05:51 +000021namespace llvm {
Rafael Espindola14048092014-05-09 00:26:20 +000022class Constant;
23class Type;
24class Value;
Reid Klecknerfff8e7f2015-03-03 19:21:04 +000025class CallInst;
John McCall475999d2010-08-22 00:05:51 +000026}
27
Charles Davis4e786dd2010-05-25 19:52:27 +000028namespace clang {
Rafael Espindola14048092014-05-09 00:26:20 +000029class CastExpr;
30class CXXConstructorDecl;
31class CXXDestructorDecl;
32class CXXMethodDecl;
33class CXXRecordDecl;
34class FieldDecl;
35class MangleContext;
John McCall475999d2010-08-22 00:05:51 +000036
Charles Davis4e786dd2010-05-25 19:52:27 +000037namespace CodeGen {
Rafael Espindola14048092014-05-09 00:26:20 +000038class CodeGenFunction;
39class CodeGenModule;
Charles Davis4e786dd2010-05-25 19:52:27 +000040
James Dennett6e5cffb2012-06-15 07:35:42 +000041/// \brief Implements C++ ABI-specific code generation functions.
Charles Davis53c59df2010-08-16 03:33:14 +000042class CGCXXABI {
John McCalla1dee5302010-08-22 10:59:02 +000043protected:
44 CodeGenModule &CGM;
Ahmed Charlesb8984322014-03-07 20:03:18 +000045 std::unique_ptr<MangleContext> MangleCtx;
John McCalla1dee5302010-08-22 10:59:02 +000046
Peter Collingbourne0ff0b372011-01-13 18:57:25 +000047 CGCXXABI(CodeGenModule &CGM)
48 : CGM(CGM), MangleCtx(CGM.getContext().createMangleContext()) {}
John McCalla1dee5302010-08-22 10:59:02 +000049
John McCall5d865c322010-08-31 07:33:07 +000050protected:
51 ImplicitParamDecl *&getThisDecl(CodeGenFunction &CGF) {
Eli Friedman9fbeba02012-02-11 02:57:39 +000052 return CGF.CXXABIThisDecl;
John McCall5d865c322010-08-31 07:33:07 +000053 }
54 llvm::Value *&getThisValue(CodeGenFunction &CGF) {
Eli Friedman9fbeba02012-02-11 02:57:39 +000055 return CGF.CXXABIThisValue;
John McCall5d865c322010-08-31 07:33:07 +000056 }
57
Reid Kleckner407e8b62013-03-22 19:02:54 +000058 /// Issue a diagnostic about unsupported features in the ABI.
59 void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S);
60
61 /// Get a null value for unsupported member pointers.
62 llvm::Constant *GetBogusMemberPointer(QualType T);
63
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +000064 ImplicitParamDecl *&getStructorImplicitParamDecl(CodeGenFunction &CGF) {
65 return CGF.CXXStructorImplicitParamDecl;
66 }
67 llvm::Value *&getStructorImplicitParamValue(CodeGenFunction &CGF) {
68 return CGF.CXXStructorImplicitParamValue;
John McCall5d865c322010-08-31 07:33:07 +000069 }
70
John McCall5d865c322010-08-31 07:33:07 +000071 /// Perform prolog initialization of the parameter variable suitable
Reid Kleckner89077a12013-12-17 19:46:40 +000072 /// for 'this' emitted by buildThisParam.
John McCall5d865c322010-08-31 07:33:07 +000073 void EmitThisParam(CodeGenFunction &CGF);
74
John McCall8ed55a52010-09-02 09:58:18 +000075 ASTContext &getContext() const { return CGM.getContext(); }
76
John McCallb91cd662012-05-01 05:23:51 +000077 virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType);
78 virtual bool requiresArrayCookie(const CXXNewExpr *E);
79
Charles Davis4e786dd2010-05-25 19:52:27 +000080public:
John McCalla1dee5302010-08-22 10:59:02 +000081
Anders Carlssone8ba4732010-11-28 17:50:09 +000082 virtual ~CGCXXABI();
Charles Davis4e786dd2010-05-25 19:52:27 +000083
84 /// Gets the mangle context.
Peter Collingbourne0ff0b372011-01-13 18:57:25 +000085 MangleContext &getMangleContext() {
86 return *MangleCtx;
87 }
John McCall475999d2010-08-22 00:05:51 +000088
Stephen Lin9dc6eef2013-06-30 20:40:16 +000089 /// Returns true if the given constructor or destructor is one of the
90 /// kinds that the ABI says returns 'this' (only applies when called
91 /// non-virtually for destructors).
92 ///
93 /// There currently is no way to indicate if a destructor returns 'this'
94 /// when called virtually, and code generation does not support the case.
Manman Ren01754612013-03-20 16:59:38 +000095 virtual bool HasThisReturn(GlobalDecl GD) const { return false; }
96
David Majnemer0c0b6d92014-10-31 20:09:12 +000097 virtual bool hasMostDerivedReturn(GlobalDecl GD) const { return false; }
98
Reid Kleckner40ca9132014-05-13 22:05:45 +000099 /// If the C++ ABI requires the given type be returned in a particular way,
100 /// this method sets RetAI and returns true.
101 virtual bool classifyReturnType(CGFunctionInfo &FI) const = 0;
Timur Iskhodzhanov8fe501d2013-04-17 12:54:10 +0000102
103 /// Specify how one should pass an argument of a record type.
104 enum RecordArgABI {
105 /// Pass it using the normal C aggregate rules for the ABI, potentially
106 /// introducing extra copies and passing some or all of it in registers.
107 RAA_Default = 0,
108
109 /// Pass it on the stack using its defined layout. The argument must be
110 /// evaluated directly into the correct stack position in the arguments area,
111 /// and the call machinery must not move it or introduce extra copies.
112 RAA_DirectInMemory,
113
114 /// Pass it as a pointer to temporary memory.
115 RAA_Indirect
116 };
117
Reid Klecknercf87e102014-05-14 16:02:09 +0000118 /// Returns true if C++ allows us to copy the memory of an object of type RD
119 /// when it is passed as an argument.
120 bool canCopyArgument(const CXXRecordDecl *RD) const;
121
Timur Iskhodzhanov8fe501d2013-04-17 12:54:10 +0000122 /// Returns how an argument of the given record type should be passed.
123 virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const = 0;
124
Reid Kleckner37abaca2014-05-09 22:46:15 +0000125 /// Returns true if the implicit 'sret' parameter comes after the implicit
126 /// 'this' parameter of C++ instance methods.
127 virtual bool isSRetParameterAfterThis() const { return false; }
128
John McCall7a9aac22010-08-23 01:21:21 +0000129 /// Find the LLVM type used to represent the given member pointer
130 /// type.
Chris Lattnera5f58b02011-07-09 17:41:47 +0000131 virtual llvm::Type *
John McCall7a9aac22010-08-23 01:21:21 +0000132 ConvertMemberPointerType(const MemberPointerType *MPT);
133
134 /// Load a member function from an object and a member function
135 /// pointer. Apply the this-adjustment and set 'This' to the
136 /// adjusted value.
David Majnemer2b0d66d2014-02-20 23:22:07 +0000137 virtual llvm::Value *EmitLoadOfMemberFunctionPointer(
138 CodeGenFunction &CGF, const Expr *E, llvm::Value *&This,
139 llvm::Value *MemPtr, const MemberPointerType *MPT);
John McCalla8bbb822010-08-22 03:04:22 +0000140
John McCallc134eb52010-08-31 21:07:20 +0000141 /// Calculate an l-value from an object and a data member pointer.
David Majnemer2b0d66d2014-02-20 23:22:07 +0000142 virtual llvm::Value *
143 EmitMemberDataPointerAddress(CodeGenFunction &CGF, const Expr *E,
144 llvm::Value *Base, llvm::Value *MemPtr,
145 const MemberPointerType *MPT);
John McCallc134eb52010-08-31 21:07:20 +0000146
John McCallc62bb392012-02-15 01:22:51 +0000147 /// Perform a derived-to-base, base-to-derived, or bitcast member
148 /// pointer conversion.
John McCall7a9aac22010-08-23 01:21:21 +0000149 virtual llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF,
150 const CastExpr *E,
151 llvm::Value *Src);
John McCall84fa5102010-08-22 04:16:24 +0000152
John McCallc62bb392012-02-15 01:22:51 +0000153 /// Perform a derived-to-base, base-to-derived, or bitcast member
154 /// pointer conversion on a constant value.
155 virtual llvm::Constant *EmitMemberPointerConversion(const CastExpr *E,
156 llvm::Constant *Src);
157
John McCall7a9aac22010-08-23 01:21:21 +0000158 /// Return true if the given member pointer can be zero-initialized
159 /// (in the C++ sense) with an LLVM zeroinitializer.
John McCall614dbdc2010-08-22 21:01:12 +0000160 virtual bool isZeroInitializable(const MemberPointerType *MPT);
John McCall84fa5102010-08-22 04:16:24 +0000161
David Majnemerb3e56542014-08-07 22:56:13 +0000162 /// Return whether or not a member pointers type is convertible to an IR type.
163 virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const {
164 return true;
165 }
166
David Majnemer99281062014-09-18 22:05:54 +0000167 virtual bool isTypeInfoCalculable(QualType Ty) const {
168 return !Ty->isIncompleteType();
169 }
170
John McCall7a9aac22010-08-23 01:21:21 +0000171 /// Create a null member pointer of the given type.
172 virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
John McCall84fa5102010-08-22 04:16:24 +0000173
John McCall7a9aac22010-08-23 01:21:21 +0000174 /// Create a member pointer for the given method.
David Majnemere2be95b2015-06-23 07:31:01 +0000175 virtual llvm::Constant *EmitMemberFunctionPointer(const CXXMethodDecl *MD);
John McCall1c456c82010-08-22 06:43:33 +0000176
John McCall7a9aac22010-08-23 01:21:21 +0000177 /// Create a member pointer for the given field.
John McCallf3a88602011-02-03 08:15:49 +0000178 virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
179 CharUnits offset);
John McCall131d97d2010-08-22 08:30:07 +0000180
Richard Smithdafff942012-01-14 04:30:29 +0000181 /// Create a member pointer for the given member pointer constant.
182 virtual llvm::Constant *EmitMemberPointer(const APValue &MP, QualType MPT);
183
John McCall7a9aac22010-08-23 01:21:21 +0000184 /// Emit a comparison between two member pointers. Returns an i1.
John McCall131d97d2010-08-22 08:30:07 +0000185 virtual llvm::Value *
John McCall7a9aac22010-08-23 01:21:21 +0000186 EmitMemberPointerComparison(CodeGenFunction &CGF,
187 llvm::Value *L,
188 llvm::Value *R,
189 const MemberPointerType *MPT,
190 bool Inequality);
John McCall131d97d2010-08-22 08:30:07 +0000191
John McCall7a9aac22010-08-23 01:21:21 +0000192 /// Determine if a member pointer is non-null. Returns an i1.
John McCall131d97d2010-08-22 08:30:07 +0000193 virtual llvm::Value *
John McCall7a9aac22010-08-23 01:21:21 +0000194 EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
195 llvm::Value *MemPtr,
196 const MemberPointerType *MPT);
John McCall5d865c322010-08-31 07:33:07 +0000197
John McCallc62bb392012-02-15 01:22:51 +0000198protected:
199 /// A utility method for computing the offset required for the given
200 /// base-to-derived or derived-to-base member-pointer conversion.
201 /// Does not handle virtual conversions (in case we ever fully
202 /// support an ABI that allows this). Returns null if no adjustment
203 /// is required.
204 llvm::Constant *getMemberPointerAdjustment(const CastExpr *E);
205
Reid Kleckner452abac2013-05-09 21:01:17 +0000206 /// \brief Computes the non-virtual adjustment needed for a member pointer
207 /// conversion along an inheritance path stored in an APValue. Unlike
208 /// getMemberPointerAdjustment(), the adjustment can be negative if the path
209 /// is from a derived type to a base type.
210 CharUnits getMemberPointerPathAdjustment(const APValue &MP);
211
John McCallc62bb392012-02-15 01:22:51 +0000212public:
David Majnemer0c0b6d92014-10-31 20:09:12 +0000213 virtual void emitVirtualObjectDelete(CodeGenFunction &CGF,
David Majnemer08681372014-11-01 07:37:17 +0000214 const CXXDeleteExpr *DE,
David Majnemer0c0b6d92014-10-31 20:09:12 +0000215 llvm::Value *Ptr, QualType ElementType,
David Majnemer0c0b6d92014-10-31 20:09:12 +0000216 const CXXDestructorDecl *Dtor) = 0;
David Majnemer442d0a22014-11-25 07:20:20 +0000217 virtual void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) = 0;
David Majnemer7c237072015-03-05 00:46:22 +0000218 virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) = 0;
David Majnemerba3e5ec2015-03-13 18:26:17 +0000219 virtual llvm::GlobalVariable *getThrowInfo(QualType T) { return nullptr; }
John McCall82fb8922012-09-25 10:10:39 +0000220
Piotr Padlewski81461a42015-08-27 21:35:41 +0000221 /// \brief Determine whether it's possible to emit a vtable for \p RD, even
222 /// though we do not know that the vtable has been marked as used by semantic
223 /// analysis.
224 virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const = 0;
Piotr Padlewskia68a7872015-07-24 04:04:49 +0000225
Reid Klecknerfff8e7f2015-03-03 19:21:04 +0000226 virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) = 0;
227
228 virtual llvm::CallInst *
229 emitTerminateForUnexpectedException(CodeGenFunction &CGF,
230 llvm::Value *Exn);
231
David Majnemer443250f2015-03-17 20:35:00 +0000232 virtual llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) = 0;
David Majnemer5f0dd612015-03-17 20:35:05 +0000233 virtual llvm::Constant *
David Majnemer37b417f2015-03-29 21:55:10 +0000234 getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType) = 0;
David Majnemere2cb8d12014-07-07 06:20:47 +0000235
David Majnemer1162d252014-06-22 19:05:33 +0000236 virtual bool shouldTypeidBeNullChecked(bool IsDeref,
237 QualType SrcRecordTy) = 0;
238 virtual void EmitBadTypeidCall(CodeGenFunction &CGF) = 0;
239 virtual llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy,
240 llvm::Value *ThisPtr,
241 llvm::Type *StdTypeInfoPtrTy) = 0;
242
243 virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr,
244 QualType SrcRecordTy) = 0;
245
246 virtual llvm::Value *
247 EmitDynamicCastCall(CodeGenFunction &CGF, llvm::Value *Value,
248 QualType SrcRecordTy, QualType DestTy,
249 QualType DestRecordTy, llvm::BasicBlock *CastEnd) = 0;
250
251 virtual llvm::Value *EmitDynamicCastToVoid(CodeGenFunction &CGF,
252 llvm::Value *Value,
253 QualType SrcRecordTy,
254 QualType DestTy) = 0;
255
256 virtual bool EmitBadCastCall(CodeGenFunction &CGF) = 0;
257
Reid Klecknerd8cbeec2013-05-29 18:02:47 +0000258 virtual llvm::Value *GetVirtualBaseClassOffset(CodeGenFunction &CGF,
259 llvm::Value *This,
260 const CXXRecordDecl *ClassDecl,
261 const CXXRecordDecl *BaseClassDecl) = 0;
262
Reid Kleckner7810af02013-06-19 15:20:38 +0000263 virtual llvm::BasicBlock *EmitCtorCompleteObjectHandler(CodeGenFunction &CGF,
264 const CXXRecordDecl *RD);
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000265
Timur Iskhodzhanovb6487322013-10-09 18:16:58 +0000266 /// Emit the code to initialize hidden members required
267 /// to handle virtual inheritance, if needed by the ABI.
268 virtual void
269 initializeHiddenVirtualInheritanceMembers(CodeGenFunction &CGF,
270 const CXXRecordDecl *RD) {}
271
Timur Iskhodzhanov40f2fa92013-08-04 17:30:04 +0000272 /// Emit constructor variants required by this ABI.
273 virtual void EmitCXXConstructors(const CXXConstructorDecl *D) = 0;
274
Rafael Espindola8d2a19b2014-09-08 16:01:27 +0000275 /// Build the signature of the given constructor or destructor variant by
276 /// adding any required parameters. For convenience, ArgTys has been
277 /// initialized with the type of 'this'.
278 virtual void buildStructorSignature(const CXXMethodDecl *MD, StructorType T,
279 SmallVectorImpl<CanQualType> &ArgTys) = 0;
John McCall5d865c322010-08-31 07:33:07 +0000280
Reid Klecknere7de47e2013-07-22 13:51:44 +0000281 /// Returns true if the given destructor type should be emitted as a linkonce
282 /// delegating thunk, regardless of whether the dtor is defined in this TU or
283 /// not.
284 virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor,
285 CXXDtorType DT) const = 0;
286
287 /// Emit destructor variants required by this ABI.
288 virtual void EmitCXXDestructors(const CXXDestructorDecl *D) = 0;
289
Timur Iskhodzhanov88fd4392013-08-21 06:25:03 +0000290 /// Get the type of the implicit "this" parameter used by a method. May return
291 /// zero if no specific type is applicable, e.g. if the ABI expects the "this"
292 /// parameter to point to some artificial offset in a complete object due to
293 /// vbases being reordered.
294 virtual const CXXRecordDecl *
295 getThisArgumentTypeForMethod(const CXXMethodDecl *MD) {
296 return MD->getParent();
297 }
298
299 /// Perform ABI-specific "this" argument adjustment required prior to
Timur Iskhodzhanovf1749422014-03-14 17:43:37 +0000300 /// a call of a virtual function.
301 /// The "VirtualCall" argument is true iff the call itself is virtual.
302 virtual llvm::Value *
303 adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD,
304 llvm::Value *This,
305 bool VirtualCall) {
Timur Iskhodzhanov88fd4392013-08-21 06:25:03 +0000306 return This;
307 }
308
Reid Kleckner89077a12013-12-17 19:46:40 +0000309 /// Build a parameter variable suitable for 'this'.
310 void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params);
311
312 /// Insert any ABI-specific implicit parameters into the parameter list for a
313 /// function. This generally involves extra data for constructors and
314 /// destructors.
John McCall5d865c322010-08-31 07:33:07 +0000315 ///
316 /// ABIs may also choose to override the return type, which has been
Stephen Lin9dc6eef2013-06-30 20:40:16 +0000317 /// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or
318 /// the formal return type of the function otherwise.
Reid Kleckner89077a12013-12-17 19:46:40 +0000319 virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy,
320 FunctionArgList &Params) = 0;
John McCall5d865c322010-08-31 07:33:07 +0000321
Timur Iskhodzhanov88fd4392013-08-21 06:25:03 +0000322 /// Perform ABI-specific "this" parameter adjustment in a virtual function
323 /// prologue.
324 virtual llvm::Value *adjustThisParameterInVirtualFunctionPrologue(
325 CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This) {
326 return This;
327 }
328
John McCall5d865c322010-08-31 07:33:07 +0000329 /// Emit the ABI-specific prolog for the function.
330 virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0;
331
Reid Kleckner89077a12013-12-17 19:46:40 +0000332 /// Add any ABI-specific implicit arguments needed to call a constructor.
333 ///
334 /// \return The number of args added to the call, which is typically zero or
335 /// one.
336 virtual unsigned
337 addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D,
338 CXXCtorType Type, bool ForVirtualBase,
339 bool Delegating, CallArgList &Args) = 0;
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000340
Reid Kleckner6fe771a2013-12-13 00:53:54 +0000341 /// Emit the destructor call.
342 virtual void EmitDestructorCall(CodeGenFunction &CGF,
343 const CXXDestructorDecl *DD, CXXDtorType Type,
344 bool ForVirtualBase, bool Delegating,
345 llvm::Value *This) = 0;
346
Timur Iskhodzhanov8b5987e2013-09-27 14:48:01 +0000347 /// Emits the VTable definitions required for the given record type.
348 virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
349 const CXXRecordDecl *RD) = 0;
350
Piotr Padlewski525f7462015-08-27 21:35:37 +0000351 /// Checks if ABI requires extra virtual offset for vtable field.
352 virtual bool
353 isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF,
354 CodeGenFunction::VPtr Vptr) = 0;
355
356 /// Checks if ABI requires to initilize vptrs for given dynamic class.
357 virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) = 0;
358
359 /// Get the address point of the vtable for the given base subobject.
360 virtual llvm::Constant *
361 getVTableAddressPoint(BaseSubobject Base,
362 const CXXRecordDecl *VTableClass) = 0;
363
Timur Iskhodzhanov8b5987e2013-09-27 14:48:01 +0000364 /// Get the address point of the vtable for the given base subobject while
Piotr Padlewski525f7462015-08-27 21:35:37 +0000365 /// building a constructor or a destructor.
366 virtual llvm::Value *
367 getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl *RD,
368 BaseSubobject Base,
369 const CXXRecordDecl *NearestVBase) = 0;
Timur Iskhodzhanov8b5987e2013-09-27 14:48:01 +0000370
371 /// Get the address point of the vtable for the given base subobject while
372 /// building a constexpr.
373 virtual llvm::Constant *
374 getVTableAddressPointForConstExpr(BaseSubobject Base,
375 const CXXRecordDecl *VTableClass) = 0;
376
377 /// Get the address of the vtable for the given record decl which should be
378 /// used for the vptr at the given offset in RD.
379 virtual llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
380 CharUnits VPtrOffset) = 0;
381
Timur Iskhodzhanov88fd4392013-08-21 06:25:03 +0000382 /// Build a virtual function pointer in the ABI-specific way.
383 virtual llvm::Value *getVirtualFunctionPointer(CodeGenFunction &CGF,
384 GlobalDecl GD,
385 llvm::Value *This,
Peter Collingbourne6708c4a2015-06-19 01:51:54 +0000386 llvm::Type *Ty,
387 SourceLocation Loc) = 0;
Timur Iskhodzhanov88fd4392013-08-21 06:25:03 +0000388
Timur Iskhodzhanovd6197112013-02-15 14:45:22 +0000389 /// Emit the ABI-specific virtual destructor call.
David Majnemer0c0b6d92014-10-31 20:09:12 +0000390 virtual llvm::Value *
391 EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor,
392 CXXDtorType DtorType, llvm::Value *This,
393 const CXXMemberCallExpr *CE) = 0;
Timur Iskhodzhanovd6197112013-02-15 14:45:22 +0000394
Timur Iskhodzhanovad9d3b82013-10-09 09:23:58 +0000395 virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF,
396 GlobalDecl GD,
397 CallArgList &CallArgs) {}
398
Reid Kleckner7810af02013-06-19 15:20:38 +0000399 /// Emit any tables needed to implement virtual inheritance. For Itanium,
400 /// this emits virtual table tables. For the MSVC++ ABI, this emits virtual
401 /// base tables.
Timur Iskhodzhanov8b5987e2013-09-27 14:48:01 +0000402 virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD) = 0;
Reid Kleckner7810af02013-06-19 15:20:38 +0000403
Hans Wennborgc94391d2014-06-06 20:04:01 +0000404 virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable,
405 GlobalDecl GD, bool ReturnAdjustment) = 0;
Timur Iskhodzhanovad9d3b82013-10-09 09:23:58 +0000406
Timur Iskhodzhanov02014322013-10-30 11:55:43 +0000407 virtual llvm::Value *performThisAdjustment(CodeGenFunction &CGF,
408 llvm::Value *This,
409 const ThisAdjustment &TA) = 0;
410
411 virtual llvm::Value *performReturnAdjustment(CodeGenFunction &CGF,
412 llvm::Value *Ret,
413 const ReturnAdjustment &RA) = 0;
414
John McCall5d865c322010-08-31 07:33:07 +0000415 virtual void EmitReturnFromThunk(CodeGenFunction &CGF,
416 RValue RV, QualType ResultType);
John McCall8ed55a52010-09-02 09:58:18 +0000417
David Majnemer196ac332014-09-11 23:05:02 +0000418 virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *,
419 FunctionArgList &Args) const = 0;
420
Joao Matos2ce88ef2012-07-17 17:10:11 +0000421 /// Gets the pure virtual member call function.
422 virtual StringRef GetPureVirtualCallName() = 0;
423
David Blaikieeb7d5982012-10-16 22:56:05 +0000424 /// Gets the deleted virtual member call name.
425 virtual StringRef GetDeletedVirtualCallName() = 0;
426
John McCall8ed55a52010-09-02 09:58:18 +0000427 /**************************** Array cookies ******************************/
428
429 /// Returns the extra size required in order to store the array
James Dennett41725122012-06-22 10:16:05 +0000430 /// cookie for the given new-expression. May return 0 to indicate that no
John McCall8ed55a52010-09-02 09:58:18 +0000431 /// array cookie is required.
432 ///
433 /// Several cases are filtered out before this method is called:
434 /// - non-array allocations never need a cookie
James Dennetta02e11f2012-06-20 00:57:15 +0000435 /// - calls to \::operator new(size_t, void*) never need a cookie
John McCall8ed55a52010-09-02 09:58:18 +0000436 ///
James Dennett41725122012-06-22 10:16:05 +0000437 /// \param expr - the new-expression being allocated.
John McCall284c48f2011-01-27 09:37:56 +0000438 virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr);
John McCall8ed55a52010-09-02 09:58:18 +0000439
440 /// Initialize the array cookie for the given allocation.
441 ///
442 /// \param NewPtr - a char* which is the presumed-non-null
443 /// return value of the allocation function
444 /// \param NumElements - the computed number of elements,
John McCallb91cd662012-05-01 05:23:51 +0000445 /// potentially collapsed from the multidimensional array case;
446 /// always a size_t
John McCall8ed55a52010-09-02 09:58:18 +0000447 /// \param ElementType - the base element allocated type,
448 /// i.e. the allocated type after stripping all array types
449 virtual llvm::Value *InitializeArrayCookie(CodeGenFunction &CGF,
450 llvm::Value *NewPtr,
451 llvm::Value *NumElements,
John McCall284c48f2011-01-27 09:37:56 +0000452 const CXXNewExpr *expr,
John McCall8ed55a52010-09-02 09:58:18 +0000453 QualType ElementType);
454
455 /// Reads the array cookie associated with the given pointer,
456 /// if it has one.
457 ///
458 /// \param Ptr - a pointer to the first element in the array
459 /// \param ElementType - the base element type of elements of the array
460 /// \param NumElements - an out parameter which will be initialized
461 /// with the number of elements allocated, or zero if there is no
462 /// cookie
463 /// \param AllocPtr - an out parameter which will be initialized
464 /// with a char* pointing to the address returned by the allocation
465 /// function
466 /// \param CookieSize - an out parameter which will be initialized
467 /// with the size of the cookie, or zero if there is no cookie
468 virtual void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
John McCall284c48f2011-01-27 09:37:56 +0000469 const CXXDeleteExpr *expr,
John McCall8ed55a52010-09-02 09:58:18 +0000470 QualType ElementType, llvm::Value *&NumElements,
471 llvm::Value *&AllocPtr, CharUnits &CookieSize);
472
Peter Collingbourne66f82e62013-06-28 20:45:28 +0000473 /// Return whether the given global decl needs a VTT parameter.
474 virtual bool NeedsVTTParameter(GlobalDecl GD);
475
John McCallb91cd662012-05-01 05:23:51 +0000476protected:
477 /// Returns the extra size required in order to store the array
478 /// cookie for the given type. Assumes that an array cookie is
479 /// required.
480 virtual CharUnits getArrayCookieSizeImpl(QualType elementType);
481
482 /// Reads the array cookie for an allocation which is known to have one.
483 /// This is called by the standard implementation of ReadArrayCookie.
484 ///
485 /// \param ptr - a pointer to the allocation made for an array, as a char*
486 /// \param cookieSize - the computed cookie size of an array
James Dennett6e5cffb2012-06-15 07:35:42 +0000487 ///
John McCallb91cd662012-05-01 05:23:51 +0000488 /// Other parameters are as above.
James Dennett6e5cffb2012-06-15 07:35:42 +0000489 ///
John McCallb91cd662012-05-01 05:23:51 +0000490 /// \return a size_t
491 virtual llvm::Value *readArrayCookieImpl(CodeGenFunction &IGF,
492 llvm::Value *ptr,
493 CharUnits cookieSize);
494
495public:
496
John McCall68ff0372010-09-08 01:44:27 +0000497 /*************************** Static local guards ****************************/
498
John McCallcdf7ef52010-11-06 09:44:32 +0000499 /// Emits the guarded initializer and destructor setup for the given
500 /// variable, given that it couldn't be emitted as a constant.
Richard Smith6331c402012-02-13 22:16:19 +0000501 /// If \p PerformInit is false, the initialization has been folded to a
502 /// constant and should not be performed.
John McCallcdf7ef52010-11-06 09:44:32 +0000503 ///
504 /// The variable may be:
505 /// - a static local variable
506 /// - a static data member of a class template instantiation
507 virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
Reid Klecknerd8110b62013-09-10 20:14:30 +0000508 llvm::GlobalVariable *DeclPtr,
509 bool PerformInit) = 0;
John McCall68ff0372010-09-08 01:44:27 +0000510
John McCallc84ed6a2012-05-01 06:13:13 +0000511 /// Emit code to force the execution of a destructor during global
512 /// teardown. The default implementation of this uses atexit.
513 ///
David Majnemerb3341ea2014-10-05 05:05:40 +0000514 /// \param Dtor - a function taking a single pointer argument
515 /// \param Addr - a pointer to pass to the destructor function.
Richard Smithdbf74ba2013-04-14 23:01:42 +0000516 virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
David Majnemerb3341ea2014-10-05 05:05:40 +0000517 llvm::Constant *Dtor,
518 llvm::Constant *Addr) = 0;
Richard Smith2fd1d7a2013-04-19 16:42:07 +0000519
520 /*************************** thread_local initialization ********************/
521
522 /// Emits ABI-required functions necessary to initialize thread_local
523 /// variables in this translation unit.
524 ///
David Majnemerb3341ea2014-10-05 05:05:40 +0000525 /// \param CXXThreadLocals - The thread_local declarations in this translation
526 /// unit.
527 /// \param CXXThreadLocalInits - If this translation unit contains any
528 /// non-constant initialization or non-trivial destruction for
529 /// thread_local variables, a list of functions to perform the
530 /// initialization.
Richard Smith2fd1d7a2013-04-19 16:42:07 +0000531 virtual void EmitThreadLocalInitFuncs(
David Majnemerb3341ea2014-10-05 05:05:40 +0000532 CodeGenModule &CGM,
533 ArrayRef<std::pair<const VarDecl *, llvm::GlobalVariable *>>
534 CXXThreadLocals,
535 ArrayRef<llvm::Function *> CXXThreadLocalInits,
536 ArrayRef<llvm::GlobalVariable *> CXXThreadLocalInitVars) = 0;
537
538 // Determine if references to thread_local global variables can be made
539 // directly or require access through a thread wrapper function.
540 virtual bool usesThreadWrapperFunction() const = 0;
Richard Smith2fd1d7a2013-04-19 16:42:07 +0000541
542 /// Emit a reference to a non-local thread_local variable (including
543 /// triggering the initialization of all thread_local variables in its
544 /// translation unit).
Richard Smith0f383742014-03-26 22:48:22 +0000545 virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF,
546 const VarDecl *VD,
David Majnemerb3341ea2014-10-05 05:05:40 +0000547 QualType LValType) = 0;
Rafael Espindola91f68b42014-09-15 19:20:10 +0000548
549 /// Emit a single constructor/destructor with the given type from a C++
550 /// constructor Decl.
551 virtual void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) = 0;
Charles Davis4e786dd2010-05-25 19:52:27 +0000552};
553
John McCall57625922013-01-25 23:36:14 +0000554// Create an instance of a C++ ABI class:
555
556/// Creates an Itanium-family ABI.
Charles Davis53c59df2010-08-16 03:33:14 +0000557CGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
John McCall57625922013-01-25 23:36:14 +0000558
559/// Creates a Microsoft-family ABI.
Charles Davis53c59df2010-08-16 03:33:14 +0000560CGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
John McCall475999d2010-08-22 00:05:51 +0000561
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000562}
563}
Charles Davis4e786dd2010-05-25 19:52:27 +0000564
565#endif