blob: c52b8e29d127fcc2aba8e8824fdc6eeafc1bd59d [file] [log] [blame]
Charles Davis3a811f12010-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
Stephen Hines176edba2014-12-01 14:53:08 -080015#ifndef LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H
16#define LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H
Charles Davis3a811f12010-05-25 19:52:27 +000017
John McCall4c40d982010-08-31 07:33:07 +000018#include "CodeGenFunction.h"
Chandler Carruth55fc8732012-12-04 09:13:33 +000019#include "clang/Basic/LLVM.h"
John McCall4c40d982010-08-31 07:33:07 +000020
John McCall93d557b2010-08-22 00:05:51 +000021namespace llvm {
Stephen Hines6bcf27b2014-05-29 04:14:42 -070022class Constant;
23class Type;
24class Value;
John McCall93d557b2010-08-22 00:05:51 +000025}
26
Charles Davis3a811f12010-05-25 19:52:27 +000027namespace clang {
Stephen Hines6bcf27b2014-05-29 04:14:42 -070028class CastExpr;
29class CXXConstructorDecl;
30class CXXDestructorDecl;
31class CXXMethodDecl;
32class CXXRecordDecl;
33class FieldDecl;
34class MangleContext;
John McCall93d557b2010-08-22 00:05:51 +000035
Charles Davis3a811f12010-05-25 19:52:27 +000036namespace CodeGen {
Stephen Hines6bcf27b2014-05-29 04:14:42 -070037class CodeGenFunction;
38class CodeGenModule;
Charles Davis3a811f12010-05-25 19:52:27 +000039
James Dennett3b2adf22012-06-15 07:35:42 +000040/// \brief Implements C++ ABI-specific code generation functions.
Charles Davis071cc7d2010-08-16 03:33:14 +000041class CGCXXABI {
John McCalld608cdb2010-08-22 10:59:02 +000042protected:
43 CodeGenModule &CGM;
Stephen Hines651f13c2014-04-23 16:59:28 -070044 std::unique_ptr<MangleContext> MangleCtx;
John McCalld608cdb2010-08-22 10:59:02 +000045
Peter Collingbourne14110472011-01-13 18:57:25 +000046 CGCXXABI(CodeGenModule &CGM)
47 : CGM(CGM), MangleCtx(CGM.getContext().createMangleContext()) {}
John McCalld608cdb2010-08-22 10:59:02 +000048
John McCall4c40d982010-08-31 07:33:07 +000049protected:
50 ImplicitParamDecl *&getThisDecl(CodeGenFunction &CGF) {
Eli Friedmancec5ebd2012-02-11 02:57:39 +000051 return CGF.CXXABIThisDecl;
John McCall4c40d982010-08-31 07:33:07 +000052 }
53 llvm::Value *&getThisValue(CodeGenFunction &CGF) {
Eli Friedmancec5ebd2012-02-11 02:57:39 +000054 return CGF.CXXABIThisValue;
John McCall4c40d982010-08-31 07:33:07 +000055 }
56
Reid Klecknera8a0f762013-03-22 19:02:54 +000057 /// Issue a diagnostic about unsupported features in the ABI.
58 void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S);
59
60 /// Get a null value for unsupported member pointers.
61 llvm::Constant *GetBogusMemberPointer(QualType T);
62
Timur Iskhodzhanov59660c22013-02-13 08:37:51 +000063 ImplicitParamDecl *&getStructorImplicitParamDecl(CodeGenFunction &CGF) {
64 return CGF.CXXStructorImplicitParamDecl;
65 }
66 llvm::Value *&getStructorImplicitParamValue(CodeGenFunction &CGF) {
67 return CGF.CXXStructorImplicitParamValue;
John McCall4c40d982010-08-31 07:33:07 +000068 }
69
John McCall4c40d982010-08-31 07:33:07 +000070 /// Perform prolog initialization of the parameter variable suitable
Stephen Hines651f13c2014-04-23 16:59:28 -070071 /// for 'this' emitted by buildThisParam.
John McCall4c40d982010-08-31 07:33:07 +000072 void EmitThisParam(CodeGenFunction &CGF);
73
John McCall1e7fe752010-09-02 09:58:18 +000074 ASTContext &getContext() const { return CGM.getContext(); }
75
John McCalle2b45e22012-05-01 05:23:51 +000076 virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType);
77 virtual bool requiresArrayCookie(const CXXNewExpr *E);
78
Charles Davis3a811f12010-05-25 19:52:27 +000079public:
John McCalld608cdb2010-08-22 10:59:02 +000080
Anders Carlsson1af610f2010-11-28 17:50:09 +000081 virtual ~CGCXXABI();
Charles Davis3a811f12010-05-25 19:52:27 +000082
83 /// Gets the mangle context.
Peter Collingbourne14110472011-01-13 18:57:25 +000084 MangleContext &getMangleContext() {
85 return *MangleCtx;
86 }
John McCall93d557b2010-08-22 00:05:51 +000087
Stephen Lin3b50e8d2013-06-30 20:40:16 +000088 /// Returns true if the given constructor or destructor is one of the
89 /// kinds that the ABI says returns 'this' (only applies when called
90 /// non-virtually for destructors).
91 ///
92 /// There currently is no way to indicate if a destructor returns 'this'
93 /// when called virtually, and code generation does not support the case.
Manman Ren63fd4082013-03-20 16:59:38 +000094 virtual bool HasThisReturn(GlobalDecl GD) const { return false; }
95
Stephen Hines176edba2014-12-01 14:53:08 -080096 virtual bool hasMostDerivedReturn(GlobalDecl GD) const { return false; }
97
Stephen Hines6bcf27b2014-05-29 04:14:42 -070098 /// If the C++ ABI requires the given type be returned in a particular way,
99 /// this method sets RetAI and returns true.
100 virtual bool classifyReturnType(CGFunctionInfo &FI) const = 0;
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000101
102 /// Specify how one should pass an argument of a record type.
103 enum RecordArgABI {
104 /// Pass it using the normal C aggregate rules for the ABI, potentially
105 /// introducing extra copies and passing some or all of it in registers.
106 RAA_Default = 0,
107
108 /// Pass it on the stack using its defined layout. The argument must be
109 /// evaluated directly into the correct stack position in the arguments area,
110 /// and the call machinery must not move it or introduce extra copies.
111 RAA_DirectInMemory,
112
113 /// Pass it as a pointer to temporary memory.
114 RAA_Indirect
115 };
116
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700117 /// Returns true if C++ allows us to copy the memory of an object of type RD
118 /// when it is passed as an argument.
119 bool canCopyArgument(const CXXRecordDecl *RD) const;
120
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000121 /// Returns how an argument of the given record type should be passed.
122 virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const = 0;
123
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700124 /// Returns true if the implicit 'sret' parameter comes after the implicit
125 /// 'this' parameter of C++ instance methods.
126 virtual bool isSRetParameterAfterThis() const { return false; }
127
John McCall0bab0cd2010-08-23 01:21:21 +0000128 /// Find the LLVM type used to represent the given member pointer
129 /// type.
Chris Lattner9cbe4f02011-07-09 17:41:47 +0000130 virtual llvm::Type *
John McCall0bab0cd2010-08-23 01:21:21 +0000131 ConvertMemberPointerType(const MemberPointerType *MPT);
132
133 /// Load a member function from an object and a member function
134 /// pointer. Apply the this-adjustment and set 'This' to the
135 /// adjusted value.
Stephen Hines651f13c2014-04-23 16:59:28 -0700136 virtual llvm::Value *EmitLoadOfMemberFunctionPointer(
137 CodeGenFunction &CGF, const Expr *E, llvm::Value *&This,
138 llvm::Value *MemPtr, const MemberPointerType *MPT);
John McCall3023def2010-08-22 03:04:22 +0000139
John McCall6c2ab1d2010-08-31 21:07:20 +0000140 /// Calculate an l-value from an object and a data member pointer.
Stephen Hines651f13c2014-04-23 16:59:28 -0700141 virtual llvm::Value *
142 EmitMemberDataPointerAddress(CodeGenFunction &CGF, const Expr *E,
143 llvm::Value *Base, llvm::Value *MemPtr,
144 const MemberPointerType *MPT);
John McCall6c2ab1d2010-08-31 21:07:20 +0000145
John McCall4d4e5c12012-02-15 01:22:51 +0000146 /// Perform a derived-to-base, base-to-derived, or bitcast member
147 /// pointer conversion.
John McCall0bab0cd2010-08-23 01:21:21 +0000148 virtual llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF,
149 const CastExpr *E,
150 llvm::Value *Src);
John McCallcf2c85e2010-08-22 04:16:24 +0000151
John McCall4d4e5c12012-02-15 01:22:51 +0000152 /// Perform a derived-to-base, base-to-derived, or bitcast member
153 /// pointer conversion on a constant value.
154 virtual llvm::Constant *EmitMemberPointerConversion(const CastExpr *E,
155 llvm::Constant *Src);
156
John McCall0bab0cd2010-08-23 01:21:21 +0000157 /// Return true if the given member pointer can be zero-initialized
158 /// (in the C++ sense) with an LLVM zeroinitializer.
John McCallf16aa102010-08-22 21:01:12 +0000159 virtual bool isZeroInitializable(const MemberPointerType *MPT);
John McCallcf2c85e2010-08-22 04:16:24 +0000160
Stephen Hines176edba2014-12-01 14:53:08 -0800161 /// Return whether or not a member pointers type is convertible to an IR type.
162 virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const {
163 return true;
164 }
165
166 virtual bool isTypeInfoCalculable(QualType Ty) const {
167 return !Ty->isIncompleteType();
168 }
169
John McCall0bab0cd2010-08-23 01:21:21 +0000170 /// Create a null member pointer of the given type.
171 virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
John McCallcf2c85e2010-08-22 04:16:24 +0000172
John McCall0bab0cd2010-08-23 01:21:21 +0000173 /// Create a member pointer for the given method.
John McCall755d8492011-04-12 00:42:48 +0000174 virtual llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD);
John McCall875ab102010-08-22 06:43:33 +0000175
John McCall0bab0cd2010-08-23 01:21:21 +0000176 /// Create a member pointer for the given field.
John McCall5808ce42011-02-03 08:15:49 +0000177 virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
178 CharUnits offset);
John McCalle9fd7eb2010-08-22 08:30:07 +0000179
Richard Smith2d6a5672012-01-14 04:30:29 +0000180 /// Create a member pointer for the given member pointer constant.
181 virtual llvm::Constant *EmitMemberPointer(const APValue &MP, QualType MPT);
182
John McCall0bab0cd2010-08-23 01:21:21 +0000183 /// Emit a comparison between two member pointers. Returns an i1.
John McCalle9fd7eb2010-08-22 08:30:07 +0000184 virtual llvm::Value *
John McCall0bab0cd2010-08-23 01:21:21 +0000185 EmitMemberPointerComparison(CodeGenFunction &CGF,
186 llvm::Value *L,
187 llvm::Value *R,
188 const MemberPointerType *MPT,
189 bool Inequality);
John McCalle9fd7eb2010-08-22 08:30:07 +0000190
John McCall0bab0cd2010-08-23 01:21:21 +0000191 /// Determine if a member pointer is non-null. Returns an i1.
John McCalle9fd7eb2010-08-22 08:30:07 +0000192 virtual llvm::Value *
John McCall0bab0cd2010-08-23 01:21:21 +0000193 EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
194 llvm::Value *MemPtr,
195 const MemberPointerType *MPT);
John McCall4c40d982010-08-31 07:33:07 +0000196
John McCall4d4e5c12012-02-15 01:22:51 +0000197protected:
198 /// A utility method for computing the offset required for the given
199 /// base-to-derived or derived-to-base member-pointer conversion.
200 /// Does not handle virtual conversions (in case we ever fully
201 /// support an ABI that allows this). Returns null if no adjustment
202 /// is required.
203 llvm::Constant *getMemberPointerAdjustment(const CastExpr *E);
204
Reid Klecknerf6327302013-05-09 21:01:17 +0000205 /// \brief Computes the non-virtual adjustment needed for a member pointer
206 /// conversion along an inheritance path stored in an APValue. Unlike
207 /// getMemberPointerAdjustment(), the adjustment can be negative if the path
208 /// is from a derived type to a base type.
209 CharUnits getMemberPointerPathAdjustment(const APValue &MP);
210
John McCall4d4e5c12012-02-15 01:22:51 +0000211public:
Stephen Hines176edba2014-12-01 14:53:08 -0800212 virtual void emitVirtualObjectDelete(CodeGenFunction &CGF,
213 const CXXDeleteExpr *DE,
214 llvm::Value *Ptr, QualType ElementType,
215 const CXXDestructorDecl *Dtor) = 0;
John McCallecd03b42012-09-25 10:10:39 +0000216
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700217 virtual llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) = 0;
218
219 virtual bool shouldTypeidBeNullChecked(bool IsDeref,
220 QualType SrcRecordTy) = 0;
221 virtual void EmitBadTypeidCall(CodeGenFunction &CGF) = 0;
222 virtual llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy,
223 llvm::Value *ThisPtr,
224 llvm::Type *StdTypeInfoPtrTy) = 0;
225
226 virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr,
227 QualType SrcRecordTy) = 0;
228
229 virtual llvm::Value *
230 EmitDynamicCastCall(CodeGenFunction &CGF, llvm::Value *Value,
231 QualType SrcRecordTy, QualType DestTy,
232 QualType DestRecordTy, llvm::BasicBlock *CastEnd) = 0;
233
234 virtual llvm::Value *EmitDynamicCastToVoid(CodeGenFunction &CGF,
235 llvm::Value *Value,
236 QualType SrcRecordTy,
237 QualType DestTy) = 0;
238
239 virtual bool EmitBadCastCall(CodeGenFunction &CGF) = 0;
240
Reid Klecknerb0f533e2013-05-29 18:02:47 +0000241 virtual llvm::Value *GetVirtualBaseClassOffset(CodeGenFunction &CGF,
242 llvm::Value *This,
243 const CXXRecordDecl *ClassDecl,
244 const CXXRecordDecl *BaseClassDecl) = 0;
245
Reid Kleckner90633022013-06-19 15:20:38 +0000246 virtual llvm::BasicBlock *EmitCtorCompleteObjectHandler(CodeGenFunction &CGF,
247 const CXXRecordDecl *RD);
Timur Iskhodzhanov1d4fff52013-02-27 13:46:31 +0000248
Timur Iskhodzhanov5bd0d442013-10-09 18:16:58 +0000249 /// Emit the code to initialize hidden members required
250 /// to handle virtual inheritance, if needed by the ABI.
251 virtual void
252 initializeHiddenVirtualInheritanceMembers(CodeGenFunction &CGF,
253 const CXXRecordDecl *RD) {}
254
Timur Iskhodzhanovbb1b7972013-08-04 17:30:04 +0000255 /// Emit constructor variants required by this ABI.
256 virtual void EmitCXXConstructors(const CXXConstructorDecl *D) = 0;
257
Stephen Hines176edba2014-12-01 14:53:08 -0800258 /// Build the signature of the given constructor or destructor variant by
259 /// adding any required parameters. For convenience, ArgTys has been
260 /// initialized with the type of 'this'.
261 virtual void buildStructorSignature(const CXXMethodDecl *MD, StructorType T,
262 SmallVectorImpl<CanQualType> &ArgTys) = 0;
John McCall4c40d982010-08-31 07:33:07 +0000263
Reid Klecknera4130ba2013-07-22 13:51:44 +0000264 /// Returns true if the given destructor type should be emitted as a linkonce
265 /// delegating thunk, regardless of whether the dtor is defined in this TU or
266 /// not.
267 virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor,
268 CXXDtorType DT) const = 0;
269
270 /// Emit destructor variants required by this ABI.
271 virtual void EmitCXXDestructors(const CXXDestructorDecl *D) = 0;
272
Timur Iskhodzhanov8f189a92013-08-21 06:25:03 +0000273 /// Get the type of the implicit "this" parameter used by a method. May return
274 /// zero if no specific type is applicable, e.g. if the ABI expects the "this"
275 /// parameter to point to some artificial offset in a complete object due to
276 /// vbases being reordered.
277 virtual const CXXRecordDecl *
278 getThisArgumentTypeForMethod(const CXXMethodDecl *MD) {
279 return MD->getParent();
280 }
281
282 /// Perform ABI-specific "this" argument adjustment required prior to
Stephen Hines651f13c2014-04-23 16:59:28 -0700283 /// a call of a virtual function.
284 /// The "VirtualCall" argument is true iff the call itself is virtual.
285 virtual llvm::Value *
286 adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD,
287 llvm::Value *This,
288 bool VirtualCall) {
Timur Iskhodzhanov8f189a92013-08-21 06:25:03 +0000289 return This;
290 }
291
Stephen Hines651f13c2014-04-23 16:59:28 -0700292 /// Build a parameter variable suitable for 'this'.
293 void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params);
294
295 /// Insert any ABI-specific implicit parameters into the parameter list for a
296 /// function. This generally involves extra data for constructors and
297 /// destructors.
John McCall4c40d982010-08-31 07:33:07 +0000298 ///
299 /// ABIs may also choose to override the return type, which has been
Stephen Lin3b50e8d2013-06-30 20:40:16 +0000300 /// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or
301 /// the formal return type of the function otherwise.
Stephen Hines651f13c2014-04-23 16:59:28 -0700302 virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy,
303 FunctionArgList &Params) = 0;
John McCall4c40d982010-08-31 07:33:07 +0000304
Timur Iskhodzhanov8f189a92013-08-21 06:25:03 +0000305 /// Perform ABI-specific "this" parameter adjustment in a virtual function
306 /// prologue.
307 virtual llvm::Value *adjustThisParameterInVirtualFunctionPrologue(
308 CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This) {
309 return This;
310 }
311
John McCall4c40d982010-08-31 07:33:07 +0000312 /// Emit the ABI-specific prolog for the function.
313 virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0;
314
Stephen Hines651f13c2014-04-23 16:59:28 -0700315 /// Add any ABI-specific implicit arguments needed to call a constructor.
316 ///
317 /// \return The number of args added to the call, which is typically zero or
318 /// one.
319 virtual unsigned
320 addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D,
321 CXXCtorType Type, bool ForVirtualBase,
322 bool Delegating, CallArgList &Args) = 0;
323
324 /// Emit the destructor call.
325 virtual void EmitDestructorCall(CodeGenFunction &CGF,
326 const CXXDestructorDecl *DD, CXXDtorType Type,
327 bool ForVirtualBase, bool Delegating,
328 llvm::Value *This) = 0;
Timur Iskhodzhanov1d4fff52013-02-27 13:46:31 +0000329
Timur Iskhodzhanova53d7a02013-09-27 14:48:01 +0000330 /// Emits the VTable definitions required for the given record type.
331 virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
332 const CXXRecordDecl *RD) = 0;
333
334 /// Get the address point of the vtable for the given base subobject while
335 /// building a constructor or a destructor. On return, NeedsVirtualOffset
336 /// tells if a virtual base adjustment is needed in order to get the offset
337 /// of the base subobject.
338 virtual llvm::Value *getVTableAddressPointInStructor(
339 CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base,
340 const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset) = 0;
341
342 /// Get the address point of the vtable for the given base subobject while
343 /// building a constexpr.
344 virtual llvm::Constant *
345 getVTableAddressPointForConstExpr(BaseSubobject Base,
346 const CXXRecordDecl *VTableClass) = 0;
347
348 /// Get the address of the vtable for the given record decl which should be
349 /// used for the vptr at the given offset in RD.
350 virtual llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
351 CharUnits VPtrOffset) = 0;
352
Timur Iskhodzhanov8f189a92013-08-21 06:25:03 +0000353 /// Build a virtual function pointer in the ABI-specific way.
354 virtual llvm::Value *getVirtualFunctionPointer(CodeGenFunction &CGF,
355 GlobalDecl GD,
356 llvm::Value *This,
357 llvm::Type *Ty) = 0;
358
Timur Iskhodzhanov0f9827f2013-02-15 14:45:22 +0000359 /// Emit the ABI-specific virtual destructor call.
Stephen Hines176edba2014-12-01 14:53:08 -0800360 virtual llvm::Value *
361 EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor,
362 CXXDtorType DtorType, llvm::Value *This,
363 const CXXMemberCallExpr *CE) = 0;
Timur Iskhodzhanov0f9827f2013-02-15 14:45:22 +0000364
Timur Iskhodzhanov2cb17a02013-10-09 09:23:58 +0000365 virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF,
366 GlobalDecl GD,
367 CallArgList &CallArgs) {}
368
Reid Kleckner90633022013-06-19 15:20:38 +0000369 /// Emit any tables needed to implement virtual inheritance. For Itanium,
370 /// this emits virtual table tables. For the MSVC++ ABI, this emits virtual
371 /// base tables.
Timur Iskhodzhanova53d7a02013-09-27 14:48:01 +0000372 virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD) = 0;
Reid Kleckner90633022013-06-19 15:20:38 +0000373
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700374 virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable,
375 GlobalDecl GD, bool ReturnAdjustment) = 0;
Timur Iskhodzhanov2cb17a02013-10-09 09:23:58 +0000376
Timur Iskhodzhanovc70cc5d2013-10-30 11:55:43 +0000377 virtual llvm::Value *performThisAdjustment(CodeGenFunction &CGF,
378 llvm::Value *This,
379 const ThisAdjustment &TA) = 0;
380
381 virtual llvm::Value *performReturnAdjustment(CodeGenFunction &CGF,
382 llvm::Value *Ret,
383 const ReturnAdjustment &RA) = 0;
384
John McCall4c40d982010-08-31 07:33:07 +0000385 virtual void EmitReturnFromThunk(CodeGenFunction &CGF,
386 RValue RV, QualType ResultType);
John McCall1e7fe752010-09-02 09:58:18 +0000387
Stephen Hines176edba2014-12-01 14:53:08 -0800388 virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *,
389 FunctionArgList &Args) const = 0;
390
Joao Matos285baac2012-07-17 17:10:11 +0000391 /// Gets the pure virtual member call function.
392 virtual StringRef GetPureVirtualCallName() = 0;
393
David Blaikie2eb9a952012-10-16 22:56:05 +0000394 /// Gets the deleted virtual member call name.
395 virtual StringRef GetDeletedVirtualCallName() = 0;
396
John McCall1e7fe752010-09-02 09:58:18 +0000397 /**************************** Array cookies ******************************/
398
399 /// Returns the extra size required in order to store the array
James Dennett16ae9de2012-06-22 10:16:05 +0000400 /// cookie for the given new-expression. May return 0 to indicate that no
John McCall1e7fe752010-09-02 09:58:18 +0000401 /// array cookie is required.
402 ///
403 /// Several cases are filtered out before this method is called:
404 /// - non-array allocations never need a cookie
James Dennett59001032012-06-20 00:57:15 +0000405 /// - calls to \::operator new(size_t, void*) never need a cookie
John McCall1e7fe752010-09-02 09:58:18 +0000406 ///
James Dennett16ae9de2012-06-22 10:16:05 +0000407 /// \param expr - the new-expression being allocated.
John McCall6ec278d2011-01-27 09:37:56 +0000408 virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr);
John McCall1e7fe752010-09-02 09:58:18 +0000409
410 /// Initialize the array cookie for the given allocation.
411 ///
412 /// \param NewPtr - a char* which is the presumed-non-null
413 /// return value of the allocation function
414 /// \param NumElements - the computed number of elements,
John McCalle2b45e22012-05-01 05:23:51 +0000415 /// potentially collapsed from the multidimensional array case;
416 /// always a size_t
John McCall1e7fe752010-09-02 09:58:18 +0000417 /// \param ElementType - the base element allocated type,
418 /// i.e. the allocated type after stripping all array types
419 virtual llvm::Value *InitializeArrayCookie(CodeGenFunction &CGF,
420 llvm::Value *NewPtr,
421 llvm::Value *NumElements,
John McCall6ec278d2011-01-27 09:37:56 +0000422 const CXXNewExpr *expr,
John McCall1e7fe752010-09-02 09:58:18 +0000423 QualType ElementType);
424
425 /// Reads the array cookie associated with the given pointer,
426 /// if it has one.
427 ///
428 /// \param Ptr - a pointer to the first element in the array
429 /// \param ElementType - the base element type of elements of the array
430 /// \param NumElements - an out parameter which will be initialized
431 /// with the number of elements allocated, or zero if there is no
432 /// cookie
433 /// \param AllocPtr - an out parameter which will be initialized
434 /// with a char* pointing to the address returned by the allocation
435 /// function
436 /// \param CookieSize - an out parameter which will be initialized
437 /// with the size of the cookie, or zero if there is no cookie
438 virtual void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
John McCall6ec278d2011-01-27 09:37:56 +0000439 const CXXDeleteExpr *expr,
John McCall1e7fe752010-09-02 09:58:18 +0000440 QualType ElementType, llvm::Value *&NumElements,
441 llvm::Value *&AllocPtr, CharUnits &CookieSize);
442
Peter Collingbournee1e35f72013-06-28 20:45:28 +0000443 /// Return whether the given global decl needs a VTT parameter.
444 virtual bool NeedsVTTParameter(GlobalDecl GD);
445
John McCalle2b45e22012-05-01 05:23:51 +0000446protected:
447 /// Returns the extra size required in order to store the array
448 /// cookie for the given type. Assumes that an array cookie is
449 /// required.
450 virtual CharUnits getArrayCookieSizeImpl(QualType elementType);
451
452 /// Reads the array cookie for an allocation which is known to have one.
453 /// This is called by the standard implementation of ReadArrayCookie.
454 ///
455 /// \param ptr - a pointer to the allocation made for an array, as a char*
456 /// \param cookieSize - the computed cookie size of an array
James Dennett3b2adf22012-06-15 07:35:42 +0000457 ///
John McCalle2b45e22012-05-01 05:23:51 +0000458 /// Other parameters are as above.
James Dennett3b2adf22012-06-15 07:35:42 +0000459 ///
John McCalle2b45e22012-05-01 05:23:51 +0000460 /// \return a size_t
461 virtual llvm::Value *readArrayCookieImpl(CodeGenFunction &IGF,
462 llvm::Value *ptr,
463 CharUnits cookieSize);
464
465public:
466
John McCall5cd91b52010-09-08 01:44:27 +0000467 /*************************** Static local guards ****************************/
468
John McCall3030eb82010-11-06 09:44:32 +0000469 /// Emits the guarded initializer and destructor setup for the given
470 /// variable, given that it couldn't be emitted as a constant.
Richard Smith7ca48502012-02-13 22:16:19 +0000471 /// If \p PerformInit is false, the initialization has been folded to a
472 /// constant and should not be performed.
John McCall3030eb82010-11-06 09:44:32 +0000473 ///
474 /// The variable may be:
475 /// - a static local variable
476 /// - a static data member of a class template instantiation
477 virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
Reid Kleckner942f9fe2013-09-10 20:14:30 +0000478 llvm::GlobalVariable *DeclPtr,
479 bool PerformInit) = 0;
John McCall5cd91b52010-09-08 01:44:27 +0000480
John McCall20bb1752012-05-01 06:13:13 +0000481 /// Emit code to force the execution of a destructor during global
482 /// teardown. The default implementation of this uses atexit.
483 ///
Stephen Hines176edba2014-12-01 14:53:08 -0800484 /// \param Dtor - a function taking a single pointer argument
485 /// \param Addr - a pointer to pass to the destructor function.
Richard Smith04e51762013-04-14 23:01:42 +0000486 virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
Stephen Hines176edba2014-12-01 14:53:08 -0800487 llvm::Constant *Dtor,
488 llvm::Constant *Addr) = 0;
Richard Smithb80a16e2013-04-19 16:42:07 +0000489
490 /*************************** thread_local initialization ********************/
491
492 /// Emits ABI-required functions necessary to initialize thread_local
493 /// variables in this translation unit.
494 ///
Stephen Hines176edba2014-12-01 14:53:08 -0800495 /// \param CXXThreadLocals - The thread_local declarations in this translation
496 /// unit.
497 /// \param CXXThreadLocalInits - If this translation unit contains any
498 /// non-constant initialization or non-trivial destruction for
499 /// thread_local variables, a list of functions to perform the
500 /// initialization.
Richard Smithb80a16e2013-04-19 16:42:07 +0000501 virtual void EmitThreadLocalInitFuncs(
Stephen Hines176edba2014-12-01 14:53:08 -0800502 CodeGenModule &CGM,
503 ArrayRef<std::pair<const VarDecl *, llvm::GlobalVariable *>>
504 CXXThreadLocals,
505 ArrayRef<llvm::Function *> CXXThreadLocalInits,
506 ArrayRef<llvm::GlobalVariable *> CXXThreadLocalInitVars) = 0;
507
508 // Determine if references to thread_local global variables can be made
509 // directly or require access through a thread wrapper function.
510 virtual bool usesThreadWrapperFunction() const = 0;
Richard Smithb80a16e2013-04-19 16:42:07 +0000511
512 /// Emit a reference to a non-local thread_local variable (including
513 /// triggering the initialization of all thread_local variables in its
514 /// translation unit).
Stephen Hines651f13c2014-04-23 16:59:28 -0700515 virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF,
516 const VarDecl *VD,
Stephen Hines176edba2014-12-01 14:53:08 -0800517 QualType LValType) = 0;
518
519 /// Emit a single constructor/destructor with the given type from a C++
520 /// constructor Decl.
521 virtual void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) = 0;
Charles Davis3a811f12010-05-25 19:52:27 +0000522};
523
John McCall96fcde02013-01-25 23:36:14 +0000524// Create an instance of a C++ ABI class:
525
526/// Creates an Itanium-family ABI.
Charles Davis071cc7d2010-08-16 03:33:14 +0000527CGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
John McCall96fcde02013-01-25 23:36:14 +0000528
529/// Creates a Microsoft-family ABI.
Charles Davis071cc7d2010-08-16 03:33:14 +0000530CGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
John McCall93d557b2010-08-22 00:05:51 +0000531
Charles Davis3a811f12010-05-25 19:52:27 +0000532}
533}
534
535#endif