CGCXXABI.h revision 0f9827f5d6248d7008063768eb5f2c3e6ba83e94
13a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis//===----- CGCXXABI.h - Interface to C++ ABIs -------------------*- C++ -*-===//
23a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis//
33a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis//                     The LLVM Compiler Infrastructure
43a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis//
53a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis// This file is distributed under the University of Illinois Open Source
63a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis// License. See LICENSE.TXT for details.
73a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis//
83a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis//===----------------------------------------------------------------------===//
93a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis//
103a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis// This provides an abstract class for C++ code generation. Concrete subclasses
113a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis// of this implement code generation for specific C++ ABIs.
123a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis//
133a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis//===----------------------------------------------------------------------===//
143a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
153a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis#ifndef CLANG_CODEGEN_CXXABI_H
163a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis#define CLANG_CODEGEN_CXXABI_H
173a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
184c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall#include "CodeGenFunction.h"
1955fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Basic/LLVM.h"
204c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
2193d557bc1867b7d7b102f87290194b4be7932c92John McCallnamespace llvm {
22cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall  class Constant;
230bab0cdab751248ca389a5592bcb70eac5d39260John McCall  class Type;
2493d557bc1867b7d7b102f87290194b4be7932c92John McCall  class Value;
2593d557bc1867b7d7b102f87290194b4be7932c92John McCall}
2693d557bc1867b7d7b102f87290194b4be7932c92John McCall
273a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davisnamespace clang {
283023def6bea3af6dbb51eea51f8cb8ea892d26cfJohn McCall  class CastExpr;
294c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  class CXXConstructorDecl;
304c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  class CXXDestructorDecl;
31875ab10245d3bf37252dd822aa1616bb0a391095John McCall  class CXXMethodDecl;
32cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall  class CXXRecordDecl;
330bab0cdab751248ca389a5592bcb70eac5d39260John McCall  class FieldDecl;
3414110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne  class MangleContext;
3593d557bc1867b7d7b102f87290194b4be7932c92John McCall
363a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davisnamespace CodeGen {
3793d557bc1867b7d7b102f87290194b4be7932c92John McCall  class CodeGenFunction;
383a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis  class CodeGenModule;
393a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
403b2adf237ab033173d7789ec1214d654eec17697James Dennett/// \brief Implements C++ ABI-specific code generation functions.
41071cc7deffad608165b1ddd5263e8bf181861520Charles Davisclass CGCXXABI {
42d608cdb7c044365cf4e8764ade1e11e99c176078John McCallprotected:
43d608cdb7c044365cf4e8764ade1e11e99c176078John McCall  CodeGenModule &CGM;
446f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith  OwningPtr<MangleContext> MangleCtx;
45d608cdb7c044365cf4e8764ade1e11e99c176078John McCall
4614110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne  CGCXXABI(CodeGenModule &CGM)
4714110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne    : CGM(CGM), MangleCtx(CGM.getContext().createMangleContext()) {}
48d608cdb7c044365cf4e8764ade1e11e99c176078John McCall
494c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCallprotected:
504c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  ImplicitParamDecl *&getThisDecl(CodeGenFunction &CGF) {
51cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman    return CGF.CXXABIThisDecl;
524c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  }
534c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  llvm::Value *&getThisValue(CodeGenFunction &CGF) {
54cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman    return CGF.CXXABIThisValue;
554c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  }
564c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
5759660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  // FIXME: Every place that calls getVTT{Decl,Value} is something
5859660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  // that needs to be abstracted properly.
594c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  ImplicitParamDecl *&getVTTDecl(CodeGenFunction &CGF) {
6059660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    return CGF.CXXStructorImplicitParamDecl;
614c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  }
624c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  llvm::Value *&getVTTValue(CodeGenFunction &CGF) {
6359660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    return CGF.CXXStructorImplicitParamValue;
6459660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  }
6559660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov
6659660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  ImplicitParamDecl *&getStructorImplicitParamDecl(CodeGenFunction &CGF) {
6759660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    return CGF.CXXStructorImplicitParamDecl;
6859660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  }
6959660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  llvm::Value *&getStructorImplicitParamValue(CodeGenFunction &CGF) {
7059660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    return CGF.CXXStructorImplicitParamValue;
714c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  }
724c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
734c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Build a parameter variable suitable for 'this'.
744c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  void BuildThisParam(CodeGenFunction &CGF, FunctionArgList &Params);
754c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
764c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Perform prolog initialization of the parameter variable suitable
774c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// for 'this' emitted by BuildThisParam.
784c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  void EmitThisParam(CodeGenFunction &CGF);
794c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
801e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ASTContext &getContext() const { return CGM.getContext(); }
811e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
82e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType);
83e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual bool requiresArrayCookie(const CXXNewExpr *E);
84e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
853a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davispublic:
86d608cdb7c044365cf4e8764ade1e11e99c176078John McCall
871af610f8533b8b4a7b0b176aa8082f5b6dde904cAnders Carlsson  virtual ~CGCXXABI();
883a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
893a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis  /// Gets the mangle context.
9014110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne  MangleContext &getMangleContext() {
9114110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne    return *MangleCtx;
9214110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne  }
9393d557bc1867b7d7b102f87290194b4be7932c92John McCall
940bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Find the LLVM type used to represent the given member pointer
950bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// type.
969cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  virtual llvm::Type *
970bab0cdab751248ca389a5592bcb70eac5d39260John McCall  ConvertMemberPointerType(const MemberPointerType *MPT);
980bab0cdab751248ca389a5592bcb70eac5d39260John McCall
990bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Load a member function from an object and a member function
1000bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// pointer.  Apply the this-adjustment and set 'This' to the
1010bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// adjusted value.
10293d557bc1867b7d7b102f87290194b4be7932c92John McCall  virtual llvm::Value *
10393d557bc1867b7d7b102f87290194b4be7932c92John McCall  EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF,
10493d557bc1867b7d7b102f87290194b4be7932c92John McCall                                  llvm::Value *&This,
10593d557bc1867b7d7b102f87290194b4be7932c92John McCall                                  llvm::Value *MemPtr,
10693d557bc1867b7d7b102f87290194b4be7932c92John McCall                                  const MemberPointerType *MPT);
1073023def6bea3af6dbb51eea51f8cb8ea892d26cfJohn McCall
1086c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall  /// Calculate an l-value from an object and a data member pointer.
1096c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall  virtual llvm::Value *EmitMemberDataPointerAddress(CodeGenFunction &CGF,
1106c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall                                                    llvm::Value *Base,
1116c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall                                                    llvm::Value *MemPtr,
1126c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall                                            const MemberPointerType *MPT);
1136c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall
1144d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// Perform a derived-to-base, base-to-derived, or bitcast member
1154d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// pointer conversion.
1160bab0cdab751248ca389a5592bcb70eac5d39260John McCall  virtual llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF,
1170bab0cdab751248ca389a5592bcb70eac5d39260John McCall                                                   const CastExpr *E,
1180bab0cdab751248ca389a5592bcb70eac5d39260John McCall                                                   llvm::Value *Src);
119d608cdb7c044365cf4e8764ade1e11e99c176078John McCall
1204d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// Perform a derived-to-base, base-to-derived, or bitcast member
1214d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// pointer conversion on a constant value.
1224d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  virtual llvm::Constant *EmitMemberPointerConversion(const CastExpr *E,
1234d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall                                                      llvm::Constant *Src);
1244d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall
1250bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Return true if the given member pointer can be zero-initialized
1260bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// (in the C++ sense) with an LLVM zeroinitializer.
127f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  virtual bool isZeroInitializable(const MemberPointerType *MPT);
128cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall
1290bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Create a null member pointer of the given type.
1300bab0cdab751248ca389a5592bcb70eac5d39260John McCall  virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
131cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall
1320bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Create a member pointer for the given method.
133755d8497e39071aa24acc173ff07083e3256b8f8John McCall  virtual llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD);
134875ab10245d3bf37252dd822aa1616bb0a391095John McCall
1350bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Create a member pointer for the given field.
1365808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall  virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
1375808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall                                                CharUnits offset);
138e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall
1392d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  /// Create a member pointer for the given member pointer constant.
1402d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  virtual llvm::Constant *EmitMemberPointer(const APValue &MP, QualType MPT);
1412d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith
1420bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Emit a comparison between two member pointers.  Returns an i1.
143e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall  virtual llvm::Value *
1440bab0cdab751248ca389a5592bcb70eac5d39260John McCall  EmitMemberPointerComparison(CodeGenFunction &CGF,
1450bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              llvm::Value *L,
1460bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              llvm::Value *R,
1470bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              const MemberPointerType *MPT,
1480bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              bool Inequality);
149e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall
1500bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Determine if a member pointer is non-null.  Returns an i1.
151e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall  virtual llvm::Value *
1520bab0cdab751248ca389a5592bcb70eac5d39260John McCall  EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
1530bab0cdab751248ca389a5592bcb70eac5d39260John McCall                             llvm::Value *MemPtr,
1540bab0cdab751248ca389a5592bcb70eac5d39260John McCall                             const MemberPointerType *MPT);
1554c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
1564d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCallprotected:
1574d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// A utility method for computing the offset required for the given
1584d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// base-to-derived or derived-to-base member-pointer conversion.
1594d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// Does not handle virtual conversions (in case we ever fully
1604d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// support an ABI that allows this).  Returns null if no adjustment
1614d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// is required.
1624d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  llvm::Constant *getMemberPointerAdjustment(const CastExpr *E);
1634d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall
1644d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCallpublic:
165ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  /// Adjust the given non-null pointer to an object of polymorphic
166ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  /// type to point to the complete object.
167ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  ///
168ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  /// The IR type of the result should be a pointer but is otherwise
169ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  /// irrelevant.
170ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  virtual llvm::Value *adjustToCompleteObject(CodeGenFunction &CGF,
171ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall                                              llvm::Value *ptr,
172ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall                                              QualType type) = 0;
173ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall
1744c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Build the signature of the given constructor variant by adding
1754c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// any required parameters.  For convenience, ResTy has been
1764c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// initialized to 'void', and ArgTys has been initialized with the
1774c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// type of 'this' (although this may be changed by the ABI) and
1784c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// will have the formal parameters added to it afterwards.
1794c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  ///
1804c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// If there are ever any ABIs where the implicit parameters are
1814c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// intermixed with the formal parameters, we can address those
1824c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// then.
1834c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void BuildConstructorSignature(const CXXConstructorDecl *Ctor,
1844c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                         CXXCtorType T,
1854c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                         CanQualType &ResTy,
186686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               SmallVectorImpl<CanQualType> &ArgTys) = 0;
1874c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
1884c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Build the signature of the given destructor variant by adding
1894c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// any required parameters.  For convenience, ResTy has been
1904c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// initialized to 'void' and ArgTys has been initialized with the
1914c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// type of 'this' (although this may be changed by the ABI).
1924c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void BuildDestructorSignature(const CXXDestructorDecl *Dtor,
1934c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                        CXXDtorType T,
1944c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                        CanQualType &ResTy,
195686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               SmallVectorImpl<CanQualType> &ArgTys) = 0;
1964c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
1974c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Build the ABI-specific portion of the parameter list for a
1984c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// function.  This generally involves a 'this' parameter and
1994c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// possibly some extra data for constructors and destructors.
2004c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  ///
2014c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// ABIs may also choose to override the return type, which has been
2024c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// initialized with the formal return type of the function.
2034c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void BuildInstanceFunctionParams(CodeGenFunction &CGF,
2044c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                           QualType &ResTy,
2054c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                           FunctionArgList &Params) = 0;
2064c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
2074c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Emit the ABI-specific prolog for the function.
2084c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0;
2094c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
2100f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov  /// Emit the ABI-specific virtual destructor call.
2110f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov  virtual RValue EmitVirtualDestructorCall(CodeGenFunction &CGF,
2120f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov                                           const CXXDestructorDecl *Dtor,
2130f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov                                           CXXDtorType DtorType,
2140f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov                                           SourceLocation CallLoc,
2150f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov                                           ReturnValueSlot ReturnValue,
2160f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov                                           llvm::Value *This) = 0;
2170f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov
2184c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void EmitReturnFromThunk(CodeGenFunction &CGF,
2194c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                   RValue RV, QualType ResultType);
2201e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
221285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos  /// Gets the pure virtual member call function.
222285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos  virtual StringRef GetPureVirtualCallName() = 0;
223285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos
2242eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie  /// Gets the deleted virtual member call name.
2252eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie  virtual StringRef GetDeletedVirtualCallName() = 0;
2262eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie
2271e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /**************************** Array cookies ******************************/
2281e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
2291e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Returns the extra size required in order to store the array
23016ae9de07730832945204877d752db7f1c070962James Dennett  /// cookie for the given new-expression.  May return 0 to indicate that no
2311e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// array cookie is required.
2321e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
2331e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Several cases are filtered out before this method is called:
2341e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   - non-array allocations never need a cookie
2355900103d6606edef5fc81bbac685fa3651f1b936James Dennett  ///   - calls to \::operator new(size_t, void*) never need a cookie
2361e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
23716ae9de07730832945204877d752db7f1c070962James Dennett  /// \param expr - the new-expression being allocated.
2386ec278d1a354517e20f13a877481453ee7940c78John McCall  virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr);
2391e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
2401e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Initialize the array cookie for the given allocation.
2411e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
2421e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param NewPtr - a char* which is the presumed-non-null
2431e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   return value of the allocation function
2441e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param NumElements - the computed number of elements,
245e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  ///   potentially collapsed from the multidimensional array case;
246e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  ///   always a size_t
2471e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param ElementType - the base element allocated type,
2481e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   i.e. the allocated type after stripping all array types
2491e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  virtual llvm::Value *InitializeArrayCookie(CodeGenFunction &CGF,
2501e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                                             llvm::Value *NewPtr,
2511e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                                             llvm::Value *NumElements,
2526ec278d1a354517e20f13a877481453ee7940c78John McCall                                             const CXXNewExpr *expr,
2531e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                                             QualType ElementType);
2541e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
2551e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Reads the array cookie associated with the given pointer,
2561e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// if it has one.
2571e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
2581e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param Ptr - a pointer to the first element in the array
2591e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param ElementType - the base element type of elements of the array
2601e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param NumElements - an out parameter which will be initialized
2611e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   with the number of elements allocated, or zero if there is no
2621e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   cookie
2631e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param AllocPtr - an out parameter which will be initialized
2641e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   with a char* pointing to the address returned by the allocation
2651e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   function
2661e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param CookieSize - an out parameter which will be initialized
2671e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   with the size of the cookie, or zero if there is no cookie
2681e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  virtual void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
2696ec278d1a354517e20f13a877481453ee7940c78John McCall                               const CXXDeleteExpr *expr,
2701e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                               QualType ElementType, llvm::Value *&NumElements,
2711e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                               llvm::Value *&AllocPtr, CharUnits &CookieSize);
2721e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
273e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCallprotected:
274e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// Returns the extra size required in order to store the array
275e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// cookie for the given type.  Assumes that an array cookie is
276e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// required.
277e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual CharUnits getArrayCookieSizeImpl(QualType elementType);
278e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
279e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// Reads the array cookie for an allocation which is known to have one.
280e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// This is called by the standard implementation of ReadArrayCookie.
281e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  ///
282e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// \param ptr - a pointer to the allocation made for an array, as a char*
283e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// \param cookieSize - the computed cookie size of an array
2843b2adf237ab033173d7789ec1214d654eec17697James Dennett  ///
285e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// Other parameters are as above.
2863b2adf237ab033173d7789ec1214d654eec17697James Dennett  ///
287e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// \return a size_t
288e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual llvm::Value *readArrayCookieImpl(CodeGenFunction &IGF,
289e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall                                           llvm::Value *ptr,
290e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall                                           CharUnits cookieSize);
291e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
292e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCallpublic:
293e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
2945cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall  /*************************** Static local guards ****************************/
2955cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall
2963030eb82593097502469a8b3fc26112c79c75605John McCall  /// Emits the guarded initializer and destructor setup for the given
2973030eb82593097502469a8b3fc26112c79c75605John McCall  /// variable, given that it couldn't be emitted as a constant.
2987ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith  /// If \p PerformInit is false, the initialization has been folded to a
2997ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith  /// constant and should not be performed.
3003030eb82593097502469a8b3fc26112c79c75605John McCall  ///
3013030eb82593097502469a8b3fc26112c79c75605John McCall  /// The variable may be:
3023030eb82593097502469a8b3fc26112c79c75605John McCall  ///   - a static local variable
3033030eb82593097502469a8b3fc26112c79c75605John McCall  ///   - a static data member of a class template instantiation
3043030eb82593097502469a8b3fc26112c79c75605John McCall  virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
3050f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth                               llvm::GlobalVariable *DeclPtr, bool PerformInit);
3065cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall
30720bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// Emit code to force the execution of a destructor during global
30820bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// teardown.  The default implementation of this uses atexit.
30920bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  ///
31020bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// \param dtor - a function taking a single pointer argument
31120bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// \param addr - a pointer to pass to the destructor function.
31220bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  virtual void registerGlobalDtor(CodeGenFunction &CGF, llvm::Constant *dtor,
31320bb175cb8ae5844034828db094fb948c0e3454aJohn McCall                                  llvm::Constant *addr);
3143a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis};
3153a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
31696fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall// Create an instance of a C++ ABI class:
31796fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall
31896fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall/// Creates an Itanium-family ABI.
319071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
32096fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall
32196fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall/// Creates a Microsoft-family ABI.
322071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
32393d557bc1867b7d7b102f87290194b4be7932c92John McCall
3243a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis}
3253a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis}
3263a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
3273a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis#endif
328