blob: cc5c1b2e0ae66393042da5d6c92e4d80d51e98f1 [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;
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700216 virtual void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) = 0;
John McCallecd03b42012-09-25 10:10:39 +0000217
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700218 virtual llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) = 0;
219
220 virtual bool shouldTypeidBeNullChecked(bool IsDeref,
221 QualType SrcRecordTy) = 0;
222 virtual void EmitBadTypeidCall(CodeGenFunction &CGF) = 0;
223 virtual llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy,
224 llvm::Value *ThisPtr,
225 llvm::Type *StdTypeInfoPtrTy) = 0;
226
227 virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr,
228 QualType SrcRecordTy) = 0;
229
230 virtual llvm::Value *
231 EmitDynamicCastCall(CodeGenFunction &CGF, llvm::Value *Value,
232 QualType SrcRecordTy, QualType DestTy,
233 QualType DestRecordTy, llvm::BasicBlock *CastEnd) = 0;
234
235 virtual llvm::Value *EmitDynamicCastToVoid(CodeGenFunction &CGF,
236 llvm::Value *Value,
237 QualType SrcRecordTy,
238 QualType DestTy) = 0;
239
240 virtual bool EmitBadCastCall(CodeGenFunction &CGF) = 0;
241
Reid Klecknerb0f533e2013-05-29 18:02:47 +0000242 virtual llvm::Value *GetVirtualBaseClassOffset(CodeGenFunction &CGF,
243 llvm::Value *This,
244 const CXXRecordDecl *ClassDecl,
245 const CXXRecordDecl *BaseClassDecl) = 0;
246
Reid Kleckner90633022013-06-19 15:20:38 +0000247 virtual llvm::BasicBlock *EmitCtorCompleteObjectHandler(CodeGenFunction &CGF,
248 const CXXRecordDecl *RD);
Timur Iskhodzhanov1d4fff52013-02-27 13:46:31 +0000249
Timur Iskhodzhanov5bd0d442013-10-09 18:16:58 +0000250 /// Emit the code to initialize hidden members required
251 /// to handle virtual inheritance, if needed by the ABI.
252 virtual void
253 initializeHiddenVirtualInheritanceMembers(CodeGenFunction &CGF,
254 const CXXRecordDecl *RD) {}
255
Timur Iskhodzhanovbb1b7972013-08-04 17:30:04 +0000256 /// Emit constructor variants required by this ABI.
257 virtual void EmitCXXConstructors(const CXXConstructorDecl *D) = 0;
258
Stephen Hines176edba2014-12-01 14:53:08 -0800259 /// Build the signature of the given constructor or destructor variant by
260 /// adding any required parameters. For convenience, ArgTys has been
261 /// initialized with the type of 'this'.
262 virtual void buildStructorSignature(const CXXMethodDecl *MD, StructorType T,
263 SmallVectorImpl<CanQualType> &ArgTys) = 0;
John McCall4c40d982010-08-31 07:33:07 +0000264
Reid Klecknera4130ba2013-07-22 13:51:44 +0000265 /// Returns true if the given destructor type should be emitted as a linkonce
266 /// delegating thunk, regardless of whether the dtor is defined in this TU or
267 /// not.
268 virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor,
269 CXXDtorType DT) const = 0;
270
271 /// Emit destructor variants required by this ABI.
272 virtual void EmitCXXDestructors(const CXXDestructorDecl *D) = 0;
273
Timur Iskhodzhanov8f189a92013-08-21 06:25:03 +0000274 /// Get the type of the implicit "this" parameter used by a method. May return
275 /// zero if no specific type is applicable, e.g. if the ABI expects the "this"
276 /// parameter to point to some artificial offset in a complete object due to
277 /// vbases being reordered.
278 virtual const CXXRecordDecl *
279 getThisArgumentTypeForMethod(const CXXMethodDecl *MD) {
280 return MD->getParent();
281 }
282
283 /// Perform ABI-specific "this" argument adjustment required prior to
Stephen Hines651f13c2014-04-23 16:59:28 -0700284 /// a call of a virtual function.
285 /// The "VirtualCall" argument is true iff the call itself is virtual.
286 virtual llvm::Value *
287 adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD,
288 llvm::Value *This,
289 bool VirtualCall) {
Timur Iskhodzhanov8f189a92013-08-21 06:25:03 +0000290 return This;
291 }
292
Stephen Hines651f13c2014-04-23 16:59:28 -0700293 /// Build a parameter variable suitable for 'this'.
294 void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params);
295
296 /// Insert any ABI-specific implicit parameters into the parameter list for a
297 /// function. This generally involves extra data for constructors and
298 /// destructors.
John McCall4c40d982010-08-31 07:33:07 +0000299 ///
300 /// ABIs may also choose to override the return type, which has been
Stephen Lin3b50e8d2013-06-30 20:40:16 +0000301 /// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or
302 /// the formal return type of the function otherwise.
Stephen Hines651f13c2014-04-23 16:59:28 -0700303 virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy,
304 FunctionArgList &Params) = 0;
John McCall4c40d982010-08-31 07:33:07 +0000305
Timur Iskhodzhanov8f189a92013-08-21 06:25:03 +0000306 /// Perform ABI-specific "this" parameter adjustment in a virtual function
307 /// prologue.
308 virtual llvm::Value *adjustThisParameterInVirtualFunctionPrologue(
309 CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This) {
310 return This;
311 }
312
John McCall4c40d982010-08-31 07:33:07 +0000313 /// Emit the ABI-specific prolog for the function.
314 virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0;
315
Stephen Hines651f13c2014-04-23 16:59:28 -0700316 /// Add any ABI-specific implicit arguments needed to call a constructor.
317 ///
318 /// \return The number of args added to the call, which is typically zero or
319 /// one.
320 virtual unsigned
321 addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D,
322 CXXCtorType Type, bool ForVirtualBase,
323 bool Delegating, CallArgList &Args) = 0;
324
325 /// Emit the destructor call.
326 virtual void EmitDestructorCall(CodeGenFunction &CGF,
327 const CXXDestructorDecl *DD, CXXDtorType Type,
328 bool ForVirtualBase, bool Delegating,
329 llvm::Value *This) = 0;
Timur Iskhodzhanov1d4fff52013-02-27 13:46:31 +0000330
Timur Iskhodzhanova53d7a02013-09-27 14:48:01 +0000331 /// Emits the VTable definitions required for the given record type.
332 virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
333 const CXXRecordDecl *RD) = 0;
334
335 /// Get the address point of the vtable for the given base subobject while
336 /// building a constructor or a destructor. On return, NeedsVirtualOffset
337 /// tells if a virtual base adjustment is needed in order to get the offset
338 /// of the base subobject.
339 virtual llvm::Value *getVTableAddressPointInStructor(
340 CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base,
341 const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset) = 0;
342
343 /// Get the address point of the vtable for the given base subobject while
344 /// building a constexpr.
345 virtual llvm::Constant *
346 getVTableAddressPointForConstExpr(BaseSubobject Base,
347 const CXXRecordDecl *VTableClass) = 0;
348
349 /// Get the address of the vtable for the given record decl which should be
350 /// used for the vptr at the given offset in RD.
351 virtual llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
352 CharUnits VPtrOffset) = 0;
353
Timur Iskhodzhanov8f189a92013-08-21 06:25:03 +0000354 /// Build a virtual function pointer in the ABI-specific way.
355 virtual llvm::Value *getVirtualFunctionPointer(CodeGenFunction &CGF,
356 GlobalDecl GD,
357 llvm::Value *This,
358 llvm::Type *Ty) = 0;
359
Timur Iskhodzhanov0f9827f2013-02-15 14:45:22 +0000360 /// Emit the ABI-specific virtual destructor call.
Stephen Hines176edba2014-12-01 14:53:08 -0800361 virtual llvm::Value *
362 EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor,
363 CXXDtorType DtorType, llvm::Value *This,
364 const CXXMemberCallExpr *CE) = 0;
Timur Iskhodzhanov0f9827f2013-02-15 14:45:22 +0000365
Timur Iskhodzhanov2cb17a02013-10-09 09:23:58 +0000366 virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF,
367 GlobalDecl GD,
368 CallArgList &CallArgs) {}
369
Reid Kleckner90633022013-06-19 15:20:38 +0000370 /// Emit any tables needed to implement virtual inheritance. For Itanium,
371 /// this emits virtual table tables. For the MSVC++ ABI, this emits virtual
372 /// base tables.
Timur Iskhodzhanova53d7a02013-09-27 14:48:01 +0000373 virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD) = 0;
Reid Kleckner90633022013-06-19 15:20:38 +0000374
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700375 virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable,
376 GlobalDecl GD, bool ReturnAdjustment) = 0;
Timur Iskhodzhanov2cb17a02013-10-09 09:23:58 +0000377
Timur Iskhodzhanovc70cc5d2013-10-30 11:55:43 +0000378 virtual llvm::Value *performThisAdjustment(CodeGenFunction &CGF,
379 llvm::Value *This,
380 const ThisAdjustment &TA) = 0;
381
382 virtual llvm::Value *performReturnAdjustment(CodeGenFunction &CGF,
383 llvm::Value *Ret,
384 const ReturnAdjustment &RA) = 0;
385
John McCall4c40d982010-08-31 07:33:07 +0000386 virtual void EmitReturnFromThunk(CodeGenFunction &CGF,
387 RValue RV, QualType ResultType);
John McCall1e7fe752010-09-02 09:58:18 +0000388
Stephen Hines176edba2014-12-01 14:53:08 -0800389 virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *,
390 FunctionArgList &Args) const = 0;
391
Joao Matos285baac2012-07-17 17:10:11 +0000392 /// Gets the pure virtual member call function.
393 virtual StringRef GetPureVirtualCallName() = 0;
394
David Blaikie2eb9a952012-10-16 22:56:05 +0000395 /// Gets the deleted virtual member call name.
396 virtual StringRef GetDeletedVirtualCallName() = 0;
397
John McCall1e7fe752010-09-02 09:58:18 +0000398 /**************************** Array cookies ******************************/
399
400 /// Returns the extra size required in order to store the array
James Dennett16ae9de2012-06-22 10:16:05 +0000401 /// cookie for the given new-expression. May return 0 to indicate that no
John McCall1e7fe752010-09-02 09:58:18 +0000402 /// array cookie is required.
403 ///
404 /// Several cases are filtered out before this method is called:
405 /// - non-array allocations never need a cookie
James Dennett59001032012-06-20 00:57:15 +0000406 /// - calls to \::operator new(size_t, void*) never need a cookie
John McCall1e7fe752010-09-02 09:58:18 +0000407 ///
James Dennett16ae9de2012-06-22 10:16:05 +0000408 /// \param expr - the new-expression being allocated.
John McCall6ec278d2011-01-27 09:37:56 +0000409 virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr);
John McCall1e7fe752010-09-02 09:58:18 +0000410
411 /// Initialize the array cookie for the given allocation.
412 ///
413 /// \param NewPtr - a char* which is the presumed-non-null
414 /// return value of the allocation function
415 /// \param NumElements - the computed number of elements,
John McCalle2b45e22012-05-01 05:23:51 +0000416 /// potentially collapsed from the multidimensional array case;
417 /// always a size_t
John McCall1e7fe752010-09-02 09:58:18 +0000418 /// \param ElementType - the base element allocated type,
419 /// i.e. the allocated type after stripping all array types
420 virtual llvm::Value *InitializeArrayCookie(CodeGenFunction &CGF,
421 llvm::Value *NewPtr,
422 llvm::Value *NumElements,
John McCall6ec278d2011-01-27 09:37:56 +0000423 const CXXNewExpr *expr,
John McCall1e7fe752010-09-02 09:58:18 +0000424 QualType ElementType);
425
426 /// Reads the array cookie associated with the given pointer,
427 /// if it has one.
428 ///
429 /// \param Ptr - a pointer to the first element in the array
430 /// \param ElementType - the base element type of elements of the array
431 /// \param NumElements - an out parameter which will be initialized
432 /// with the number of elements allocated, or zero if there is no
433 /// cookie
434 /// \param AllocPtr - an out parameter which will be initialized
435 /// with a char* pointing to the address returned by the allocation
436 /// function
437 /// \param CookieSize - an out parameter which will be initialized
438 /// with the size of the cookie, or zero if there is no cookie
439 virtual void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
John McCall6ec278d2011-01-27 09:37:56 +0000440 const CXXDeleteExpr *expr,
John McCall1e7fe752010-09-02 09:58:18 +0000441 QualType ElementType, llvm::Value *&NumElements,
442 llvm::Value *&AllocPtr, CharUnits &CookieSize);
443
Peter Collingbournee1e35f72013-06-28 20:45:28 +0000444 /// Return whether the given global decl needs a VTT parameter.
445 virtual bool NeedsVTTParameter(GlobalDecl GD);
446
John McCalle2b45e22012-05-01 05:23:51 +0000447protected:
448 /// Returns the extra size required in order to store the array
449 /// cookie for the given type. Assumes that an array cookie is
450 /// required.
451 virtual CharUnits getArrayCookieSizeImpl(QualType elementType);
452
453 /// Reads the array cookie for an allocation which is known to have one.
454 /// This is called by the standard implementation of ReadArrayCookie.
455 ///
456 /// \param ptr - a pointer to the allocation made for an array, as a char*
457 /// \param cookieSize - the computed cookie size of an array
James Dennett3b2adf22012-06-15 07:35:42 +0000458 ///
John McCalle2b45e22012-05-01 05:23:51 +0000459 /// Other parameters are as above.
James Dennett3b2adf22012-06-15 07:35:42 +0000460 ///
John McCalle2b45e22012-05-01 05:23:51 +0000461 /// \return a size_t
462 virtual llvm::Value *readArrayCookieImpl(CodeGenFunction &IGF,
463 llvm::Value *ptr,
464 CharUnits cookieSize);
465
466public:
467
John McCall5cd91b52010-09-08 01:44:27 +0000468 /*************************** Static local guards ****************************/
469
John McCall3030eb82010-11-06 09:44:32 +0000470 /// Emits the guarded initializer and destructor setup for the given
471 /// variable, given that it couldn't be emitted as a constant.
Richard Smith7ca48502012-02-13 22:16:19 +0000472 /// If \p PerformInit is false, the initialization has been folded to a
473 /// constant and should not be performed.
John McCall3030eb82010-11-06 09:44:32 +0000474 ///
475 /// The variable may be:
476 /// - a static local variable
477 /// - a static data member of a class template instantiation
478 virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
Reid Kleckner942f9fe2013-09-10 20:14:30 +0000479 llvm::GlobalVariable *DeclPtr,
480 bool PerformInit) = 0;
John McCall5cd91b52010-09-08 01:44:27 +0000481
John McCall20bb1752012-05-01 06:13:13 +0000482 /// Emit code to force the execution of a destructor during global
483 /// teardown. The default implementation of this uses atexit.
484 ///
Stephen Hines176edba2014-12-01 14:53:08 -0800485 /// \param Dtor - a function taking a single pointer argument
486 /// \param Addr - a pointer to pass to the destructor function.
Richard Smith04e51762013-04-14 23:01:42 +0000487 virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
Stephen Hines176edba2014-12-01 14:53:08 -0800488 llvm::Constant *Dtor,
489 llvm::Constant *Addr) = 0;
Richard Smithb80a16e2013-04-19 16:42:07 +0000490
491 /*************************** thread_local initialization ********************/
492
493 /// Emits ABI-required functions necessary to initialize thread_local
494 /// variables in this translation unit.
495 ///
Stephen Hines176edba2014-12-01 14:53:08 -0800496 /// \param CXXThreadLocals - The thread_local declarations in this translation
497 /// unit.
498 /// \param CXXThreadLocalInits - If this translation unit contains any
499 /// non-constant initialization or non-trivial destruction for
500 /// thread_local variables, a list of functions to perform the
501 /// initialization.
Richard Smithb80a16e2013-04-19 16:42:07 +0000502 virtual void EmitThreadLocalInitFuncs(
Stephen Hines176edba2014-12-01 14:53:08 -0800503 CodeGenModule &CGM,
504 ArrayRef<std::pair<const VarDecl *, llvm::GlobalVariable *>>
505 CXXThreadLocals,
506 ArrayRef<llvm::Function *> CXXThreadLocalInits,
507 ArrayRef<llvm::GlobalVariable *> CXXThreadLocalInitVars) = 0;
508
509 // Determine if references to thread_local global variables can be made
510 // directly or require access through a thread wrapper function.
511 virtual bool usesThreadWrapperFunction() const = 0;
Richard Smithb80a16e2013-04-19 16:42:07 +0000512
513 /// Emit a reference to a non-local thread_local variable (including
514 /// triggering the initialization of all thread_local variables in its
515 /// translation unit).
Stephen Hines651f13c2014-04-23 16:59:28 -0700516 virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF,
517 const VarDecl *VD,
Stephen Hines176edba2014-12-01 14:53:08 -0800518 QualType LValType) = 0;
519
520 /// Emit a single constructor/destructor with the given type from a C++
521 /// constructor Decl.
522 virtual void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) = 0;
Charles Davis3a811f12010-05-25 19:52:27 +0000523};
524
John McCall96fcde02013-01-25 23:36:14 +0000525// Create an instance of a C++ ABI class:
526
527/// Creates an Itanium-family ABI.
Charles Davis071cc7d2010-08-16 03:33:14 +0000528CGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
John McCall96fcde02013-01-25 23:36:14 +0000529
530/// Creates a Microsoft-family ABI.
Charles Davis071cc7d2010-08-16 03:33:14 +0000531CGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
John McCall93d557b2010-08-22 00:05:51 +0000532
Charles Davis3a811f12010-05-25 19:52:27 +0000533}
534}
535
536#endif