CGCXXABI.h revision c70cc5d90403f99ccce5cab3a6c022ad9cdcb66c
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
57a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner  /// Issue a diagnostic about unsupported features in the ABI.
58a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner  void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S);
59a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner
60a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner  /// Get a null value for unsupported member pointers.
61a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner  llvm::Constant *GetBogusMemberPointer(QualType T);
62a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner
6359660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  // FIXME: Every place that calls getVTT{Decl,Value} is something
6459660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  // that needs to be abstracted properly.
654c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  ImplicitParamDecl *&getVTTDecl(CodeGenFunction &CGF) {
6659660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    return CGF.CXXStructorImplicitParamDecl;
674c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  }
684c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  llvm::Value *&getVTTValue(CodeGenFunction &CGF) {
6959660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    return CGF.CXXStructorImplicitParamValue;
7059660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  }
7159660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov
7259660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  ImplicitParamDecl *&getStructorImplicitParamDecl(CodeGenFunction &CGF) {
7359660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    return CGF.CXXStructorImplicitParamDecl;
7459660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  }
7559660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  llvm::Value *&getStructorImplicitParamValue(CodeGenFunction &CGF) {
7659660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    return CGF.CXXStructorImplicitParamValue;
774c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  }
784c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
794c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Build a parameter variable suitable for 'this'.
804c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  void BuildThisParam(CodeGenFunction &CGF, FunctionArgList &Params);
814c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
824c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Perform prolog initialization of the parameter variable suitable
834c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// for 'this' emitted by BuildThisParam.
844c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  void EmitThisParam(CodeGenFunction &CGF);
854c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
861e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ASTContext &getContext() const { return CGM.getContext(); }
871e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
88e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType);
89e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual bool requiresArrayCookie(const CXXNewExpr *E);
90e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
913a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davispublic:
92d608cdb7c044365cf4e8764ade1e11e99c176078John McCall
931af610f8533b8b4a7b0b176aa8082f5b6dde904cAnders Carlsson  virtual ~CGCXXABI();
943a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
953a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis  /// Gets the mangle context.
9614110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne  MangleContext &getMangleContext() {
9714110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne    return *MangleCtx;
9814110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne  }
9993d557bc1867b7d7b102f87290194b4be7932c92John McCall
1003b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// Returns true if the given constructor or destructor is one of the
1013b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// kinds that the ABI says returns 'this' (only applies when called
1023b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// non-virtually for destructors).
1033b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  ///
1043b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// There currently is no way to indicate if a destructor returns 'this'
1053b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// when called virtually, and code generation does not support the case.
10663fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren  virtual bool HasThisReturn(GlobalDecl GD) const { return false; }
10763fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren
108ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov  /// Returns true if the given record type should be returned indirectly.
109ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov  virtual bool isReturnTypeIndirect(const CXXRecordDecl *RD) const = 0;
110ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov
111ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov  /// Specify how one should pass an argument of a record type.
112ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov  enum RecordArgABI {
113ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    /// Pass it using the normal C aggregate rules for the ABI, potentially
114ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    /// introducing extra copies and passing some or all of it in registers.
115ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    RAA_Default = 0,
116ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov
117ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    /// Pass it on the stack using its defined layout.  The argument must be
118ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    /// evaluated directly into the correct stack position in the arguments area,
119ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    /// and the call machinery must not move it or introduce extra copies.
120ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    RAA_DirectInMemory,
121ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov
122ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    /// Pass it as a pointer to temporary memory.
123ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    RAA_Indirect
124ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov  };
125ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov
126ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov  /// Returns how an argument of the given record type should be passed.
127ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov  virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const = 0;
128ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov
1290bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Find the LLVM type used to represent the given member pointer
1300bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// type.
1319cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  virtual llvm::Type *
1320bab0cdab751248ca389a5592bcb70eac5d39260John McCall  ConvertMemberPointerType(const MemberPointerType *MPT);
1330bab0cdab751248ca389a5592bcb70eac5d39260John McCall
1340bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Load a member function from an object and a member function
1350bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// pointer.  Apply the this-adjustment and set 'This' to the
1360bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// adjusted value.
13793d557bc1867b7d7b102f87290194b4be7932c92John McCall  virtual llvm::Value *
13893d557bc1867b7d7b102f87290194b4be7932c92John McCall  EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF,
13993d557bc1867b7d7b102f87290194b4be7932c92John McCall                                  llvm::Value *&This,
14093d557bc1867b7d7b102f87290194b4be7932c92John McCall                                  llvm::Value *MemPtr,
14193d557bc1867b7d7b102f87290194b4be7932c92John McCall                                  const MemberPointerType *MPT);
1423023def6bea3af6dbb51eea51f8cb8ea892d26cfJohn McCall
1436c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall  /// Calculate an l-value from an object and a data member pointer.
1446c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall  virtual llvm::Value *EmitMemberDataPointerAddress(CodeGenFunction &CGF,
1456c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall                                                    llvm::Value *Base,
1466c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall                                                    llvm::Value *MemPtr,
1476c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall                                            const MemberPointerType *MPT);
1486c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall
1494d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// Perform a derived-to-base, base-to-derived, or bitcast member
1504d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// pointer conversion.
1510bab0cdab751248ca389a5592bcb70eac5d39260John McCall  virtual llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF,
1520bab0cdab751248ca389a5592bcb70eac5d39260John McCall                                                   const CastExpr *E,
1530bab0cdab751248ca389a5592bcb70eac5d39260John McCall                                                   llvm::Value *Src);
154d608cdb7c044365cf4e8764ade1e11e99c176078John McCall
1554d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// Perform a derived-to-base, base-to-derived, or bitcast member
1564d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// pointer conversion on a constant value.
1574d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  virtual llvm::Constant *EmitMemberPointerConversion(const CastExpr *E,
1584d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall                                                      llvm::Constant *Src);
1594d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall
1600bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Return true if the given member pointer can be zero-initialized
1610bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// (in the C++ sense) with an LLVM zeroinitializer.
162f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  virtual bool isZeroInitializable(const MemberPointerType *MPT);
163cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall
1640bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Create a null member pointer of the given type.
1650bab0cdab751248ca389a5592bcb70eac5d39260John McCall  virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
166cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall
1670bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Create a member pointer for the given method.
168755d8497e39071aa24acc173ff07083e3256b8f8John McCall  virtual llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD);
169875ab10245d3bf37252dd822aa1616bb0a391095John McCall
1700bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Create a member pointer for the given field.
1715808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall  virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
1725808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall                                                CharUnits offset);
173e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall
1742d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  /// Create a member pointer for the given member pointer constant.
1752d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  virtual llvm::Constant *EmitMemberPointer(const APValue &MP, QualType MPT);
1762d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith
1770bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Emit a comparison between two member pointers.  Returns an i1.
178e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall  virtual llvm::Value *
1790bab0cdab751248ca389a5592bcb70eac5d39260John McCall  EmitMemberPointerComparison(CodeGenFunction &CGF,
1800bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              llvm::Value *L,
1810bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              llvm::Value *R,
1820bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              const MemberPointerType *MPT,
1830bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              bool Inequality);
184e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall
1850bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Determine if a member pointer is non-null.  Returns an i1.
186e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall  virtual llvm::Value *
1870bab0cdab751248ca389a5592bcb70eac5d39260John McCall  EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
1880bab0cdab751248ca389a5592bcb70eac5d39260John McCall                             llvm::Value *MemPtr,
1890bab0cdab751248ca389a5592bcb70eac5d39260John McCall                             const MemberPointerType *MPT);
1904c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
1914d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCallprotected:
1924d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// A utility method for computing the offset required for the given
1934d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// base-to-derived or derived-to-base member-pointer conversion.
1944d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// Does not handle virtual conversions (in case we ever fully
1954d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// support an ABI that allows this).  Returns null if no adjustment
1964d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// is required.
1974d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  llvm::Constant *getMemberPointerAdjustment(const CastExpr *E);
1984d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall
199f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner  /// \brief Computes the non-virtual adjustment needed for a member pointer
200f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner  /// conversion along an inheritance path stored in an APValue.  Unlike
201f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner  /// getMemberPointerAdjustment(), the adjustment can be negative if the path
202f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner  /// is from a derived type to a base type.
203f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner  CharUnits getMemberPointerPathAdjustment(const APValue &MP);
204f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner
2054d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCallpublic:
206ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  /// Adjust the given non-null pointer to an object of polymorphic
207ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  /// type to point to the complete object.
208ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  ///
209ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  /// The IR type of the result should be a pointer but is otherwise
210ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  /// irrelevant.
211ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  virtual llvm::Value *adjustToCompleteObject(CodeGenFunction &CGF,
212ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall                                              llvm::Value *ptr,
213ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall                                              QualType type) = 0;
214ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall
215b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner  virtual llvm::Value *GetVirtualBaseClassOffset(CodeGenFunction &CGF,
216b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner                                                 llvm::Value *This,
217b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner                                                 const CXXRecordDecl *ClassDecl,
218b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner                                        const CXXRecordDecl *BaseClassDecl) = 0;
219b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner
2204c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Build the signature of the given constructor variant by adding
2213b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// any required parameters.  For convenience, ArgTys has been initialized
2223b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// with the type of 'this' and ResTy has been initialized with the type of
2233b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// 'this' if HasThisReturn(GlobalDecl(Ctor, T)) is true or 'void' otherwise
2243b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// (although both may be changed by the ABI).
2254c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  ///
2264c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// If there are ever any ABIs where the implicit parameters are
2274c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// intermixed with the formal parameters, we can address those
2284c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// then.
2294c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void BuildConstructorSignature(const CXXConstructorDecl *Ctor,
2304c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                         CXXCtorType T,
2314c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                         CanQualType &ResTy,
232686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               SmallVectorImpl<CanQualType> &ArgTys) = 0;
2334c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
2349063302a82423cb83f002257a416741850739a70Reid Kleckner  virtual llvm::BasicBlock *EmitCtorCompleteObjectHandler(CodeGenFunction &CGF,
2359063302a82423cb83f002257a416741850739a70Reid Kleckner                                                          const CXXRecordDecl *RD);
2361d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov
2375bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov  /// Emit the code to initialize hidden members required
2385bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov  /// to handle virtual inheritance, if needed by the ABI.
2395bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov  virtual void
2405bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov  initializeHiddenVirtualInheritanceMembers(CodeGenFunction &CGF,
2415bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov                                            const CXXRecordDecl *RD) {}
2425bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov
243bb1b797d2e432293563747bd9704b22cf0787061Timur Iskhodzhanov  /// Emit constructor variants required by this ABI.
244bb1b797d2e432293563747bd9704b22cf0787061Timur Iskhodzhanov  virtual void EmitCXXConstructors(const CXXConstructorDecl *D) = 0;
245bb1b797d2e432293563747bd9704b22cf0787061Timur Iskhodzhanov
2464c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Build the signature of the given destructor variant by adding
2473b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// any required parameters.  For convenience, ArgTys has been initialized
2483b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// with the type of 'this' and ResTy has been initialized with the type of
2493b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// 'this' if HasThisReturn(GlobalDecl(Dtor, T)) is true or 'void' otherwise
2503b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// (although both may be changed by the ABI).
2514c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void BuildDestructorSignature(const CXXDestructorDecl *Dtor,
2524c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                        CXXDtorType T,
2534c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                        CanQualType &ResTy,
254686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               SmallVectorImpl<CanQualType> &ArgTys) = 0;
2554c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
256a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  /// Returns true if the given destructor type should be emitted as a linkonce
257a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  /// delegating thunk, regardless of whether the dtor is defined in this TU or
258a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  /// not.
259a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor,
260a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner                                      CXXDtorType DT) const = 0;
261a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner
262a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  /// Emit destructor variants required by this ABI.
263a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  virtual void EmitCXXDestructors(const CXXDestructorDecl *D) = 0;
264a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner
2658f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// Get the type of the implicit "this" parameter used by a method. May return
2668f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// zero if no specific type is applicable, e.g. if the ABI expects the "this"
2678f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// parameter to point to some artificial offset in a complete object due to
2688f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// vbases being reordered.
2698f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  virtual const CXXRecordDecl *
2708f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  getThisArgumentTypeForMethod(const CXXMethodDecl *MD) {
2718f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov    return MD->getParent();
2728f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  }
2738f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov
2748f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// Perform ABI-specific "this" argument adjustment required prior to
2758f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// a virtual function call.
2768f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  virtual llvm::Value *adjustThisArgumentForVirtualCall(CodeGenFunction &CGF,
2778f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov                                                        GlobalDecl GD,
2788f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov                                                        llvm::Value *This) {
2798f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov    return This;
2808f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  }
2818f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov
2824c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Build the ABI-specific portion of the parameter list for a
2834c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// function.  This generally involves a 'this' parameter and
2844c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// possibly some extra data for constructors and destructors.
2854c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  ///
2864c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// ABIs may also choose to override the return type, which has been
2873b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or
2883b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// the formal return type of the function otherwise.
2894c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void BuildInstanceFunctionParams(CodeGenFunction &CGF,
2904c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                           QualType &ResTy,
2914c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                           FunctionArgList &Params) = 0;
2924c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
2938f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// Perform ABI-specific "this" parameter adjustment in a virtual function
2948f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// prologue.
2958f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  virtual llvm::Value *adjustThisParameterInVirtualFunctionPrologue(
2968f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov      CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This) {
2978f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov    return This;
2988f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  }
2998f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov
3004c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Emit the ABI-specific prolog for the function.
3014c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0;
3024c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
30363fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren  /// Emit the constructor call. Return the function that is called.
3043b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  virtual void EmitConstructorCall(CodeGenFunction &CGF,
3054444dbbb96ba55ff8a05a1918627f609a387db9fStephen Lin                                   const CXXConstructorDecl *D,
3063b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin                                   CXXCtorType Type,
3073b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin                                   bool ForVirtualBase, bool Delegating,
3084444dbbb96ba55ff8a05a1918627f609a387db9fStephen Lin                                   llvm::Value *This,
3094444dbbb96ba55ff8a05a1918627f609a387db9fStephen Lin                                   CallExpr::const_arg_iterator ArgBeg,
3104444dbbb96ba55ff8a05a1918627f609a387db9fStephen Lin                                   CallExpr::const_arg_iterator ArgEnd) = 0;
3111d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov
312a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// Emits the VTable definitions required for the given record type.
313a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
314a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov                                     const CXXRecordDecl *RD) = 0;
315a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov
316a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// Get the address point of the vtable for the given base subobject while
317a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// building a constructor or a destructor. On return, NeedsVirtualOffset
318a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// tells if a virtual base adjustment is needed in order to get the offset
319a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// of the base subobject.
320a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  virtual llvm::Value *getVTableAddressPointInStructor(
321a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov      CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base,
322a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov      const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset) = 0;
323a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov
324a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// Get the address point of the vtable for the given base subobject while
325a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// building a constexpr.
326a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  virtual llvm::Constant *
327a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  getVTableAddressPointForConstExpr(BaseSubobject Base,
328a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov                                    const CXXRecordDecl *VTableClass) = 0;
329a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov
330a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// Get the address of the vtable for the given record decl which should be
331a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// used for the vptr at the given offset in RD.
332a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  virtual llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
333a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov                                                CharUnits VPtrOffset) = 0;
334a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov
3358f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// Build a virtual function pointer in the ABI-specific way.
3368f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  virtual llvm::Value *getVirtualFunctionPointer(CodeGenFunction &CGF,
3378f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov                                                 GlobalDecl GD,
3388f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov                                                 llvm::Value *This,
3398f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov                                                 llvm::Type *Ty) = 0;
3408f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov
3410f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov  /// Emit the ABI-specific virtual destructor call.
3423b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  virtual void EmitVirtualDestructorCall(CodeGenFunction &CGF,
3433b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin                                         const CXXDestructorDecl *Dtor,
3443b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin                                         CXXDtorType DtorType,
3453b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin                                         SourceLocation CallLoc,
3463b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin                                         llvm::Value *This) = 0;
3470f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov
3482cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov  virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF,
3492cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov                                                GlobalDecl GD,
3502cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov                                                CallArgList &CallArgs) {}
3512cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov
3529063302a82423cb83f002257a416741850739a70Reid Kleckner  /// Emit any tables needed to implement virtual inheritance.  For Itanium,
3539063302a82423cb83f002257a416741850739a70Reid Kleckner  /// this emits virtual table tables.  For the MSVC++ ABI, this emits virtual
3549063302a82423cb83f002257a416741850739a70Reid Kleckner  /// base tables.
355a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD) = 0;
3569063302a82423cb83f002257a416741850739a70Reid Kleckner
3572cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov  virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable) = 0;
3582cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov
359c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov  virtual llvm::Value *performThisAdjustment(CodeGenFunction &CGF,
360c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov                                             llvm::Value *This,
361c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov                                             const ThisAdjustment &TA) = 0;
362c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov
363c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov  virtual llvm::Value *performReturnAdjustment(CodeGenFunction &CGF,
364c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov                                               llvm::Value *Ret,
365c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov                                               const ReturnAdjustment &RA) = 0;
366c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov
3674c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void EmitReturnFromThunk(CodeGenFunction &CGF,
3684c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                   RValue RV, QualType ResultType);
3691e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
370285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos  /// Gets the pure virtual member call function.
371285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos  virtual StringRef GetPureVirtualCallName() = 0;
372285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos
3732eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie  /// Gets the deleted virtual member call name.
3742eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie  virtual StringRef GetDeletedVirtualCallName() = 0;
3752eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie
3761e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /**************************** Array cookies ******************************/
3771e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
3781e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Returns the extra size required in order to store the array
37916ae9de07730832945204877d752db7f1c070962James Dennett  /// cookie for the given new-expression.  May return 0 to indicate that no
3801e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// array cookie is required.
3811e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
3821e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Several cases are filtered out before this method is called:
3831e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   - non-array allocations never need a cookie
3845900103d6606edef5fc81bbac685fa3651f1b936James Dennett  ///   - calls to \::operator new(size_t, void*) never need a cookie
3851e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
38616ae9de07730832945204877d752db7f1c070962James Dennett  /// \param expr - the new-expression being allocated.
3876ec278d1a354517e20f13a877481453ee7940c78John McCall  virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr);
3881e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
3891e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Initialize the array cookie for the given allocation.
3901e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
3911e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param NewPtr - a char* which is the presumed-non-null
3921e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   return value of the allocation function
3931e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param NumElements - the computed number of elements,
394e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  ///   potentially collapsed from the multidimensional array case;
395e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  ///   always a size_t
3961e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param ElementType - the base element allocated type,
3971e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   i.e. the allocated type after stripping all array types
3981e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  virtual llvm::Value *InitializeArrayCookie(CodeGenFunction &CGF,
3991e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                                             llvm::Value *NewPtr,
4001e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                                             llvm::Value *NumElements,
4016ec278d1a354517e20f13a877481453ee7940c78John McCall                                             const CXXNewExpr *expr,
4021e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                                             QualType ElementType);
4031e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
4041e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Reads the array cookie associated with the given pointer,
4051e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// if it has one.
4061e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
4071e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param Ptr - a pointer to the first element in the array
4081e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param ElementType - the base element type of elements of the array
4091e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param NumElements - an out parameter which will be initialized
4101e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   with the number of elements allocated, or zero if there is no
4111e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   cookie
4121e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param AllocPtr - an out parameter which will be initialized
4131e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   with a char* pointing to the address returned by the allocation
4141e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   function
4151e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param CookieSize - an out parameter which will be initialized
4161e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   with the size of the cookie, or zero if there is no cookie
4171e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  virtual void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
4186ec278d1a354517e20f13a877481453ee7940c78John McCall                               const CXXDeleteExpr *expr,
4191e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                               QualType ElementType, llvm::Value *&NumElements,
4201e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                               llvm::Value *&AllocPtr, CharUnits &CookieSize);
4211e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
422e1e35f761970fd662696b803a839c1f4a56f61b2Peter Collingbourne  /// Return whether the given global decl needs a VTT parameter.
423e1e35f761970fd662696b803a839c1f4a56f61b2Peter Collingbourne  virtual bool NeedsVTTParameter(GlobalDecl GD);
424e1e35f761970fd662696b803a839c1f4a56f61b2Peter Collingbourne
425e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCallprotected:
426e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// Returns the extra size required in order to store the array
427e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// cookie for the given type.  Assumes that an array cookie is
428e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// required.
429e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual CharUnits getArrayCookieSizeImpl(QualType elementType);
430e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
431e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// Reads the array cookie for an allocation which is known to have one.
432e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// This is called by the standard implementation of ReadArrayCookie.
433e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  ///
434e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// \param ptr - a pointer to the allocation made for an array, as a char*
435e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// \param cookieSize - the computed cookie size of an array
4363b2adf237ab033173d7789ec1214d654eec17697James Dennett  ///
437e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// Other parameters are as above.
4383b2adf237ab033173d7789ec1214d654eec17697James Dennett  ///
439e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// \return a size_t
440e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual llvm::Value *readArrayCookieImpl(CodeGenFunction &IGF,
441e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall                                           llvm::Value *ptr,
442e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall                                           CharUnits cookieSize);
443e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
444e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCallpublic:
445e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
4465cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall  /*************************** Static local guards ****************************/
4475cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall
4483030eb82593097502469a8b3fc26112c79c75605John McCall  /// Emits the guarded initializer and destructor setup for the given
4493030eb82593097502469a8b3fc26112c79c75605John McCall  /// variable, given that it couldn't be emitted as a constant.
4507ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith  /// If \p PerformInit is false, the initialization has been folded to a
4517ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith  /// constant and should not be performed.
4523030eb82593097502469a8b3fc26112c79c75605John McCall  ///
4533030eb82593097502469a8b3fc26112c79c75605John McCall  /// The variable may be:
4543030eb82593097502469a8b3fc26112c79c75605John McCall  ///   - a static local variable
4553030eb82593097502469a8b3fc26112c79c75605John McCall  ///   - a static data member of a class template instantiation
4563030eb82593097502469a8b3fc26112c79c75605John McCall  virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
457942f9fe11d3a9583eef6bc4ca2549b1f0d1694daReid Kleckner                               llvm::GlobalVariable *DeclPtr,
458942f9fe11d3a9583eef6bc4ca2549b1f0d1694daReid Kleckner                               bool PerformInit) = 0;
4595cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall
46020bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// Emit code to force the execution of a destructor during global
46120bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// teardown.  The default implementation of this uses atexit.
46220bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  ///
46320bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// \param dtor - a function taking a single pointer argument
46420bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// \param addr - a pointer to pass to the destructor function.
46504e517650569598e847c2ab609672e6df93effe5Richard Smith  virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
46604e517650569598e847c2ab609672e6df93effe5Richard Smith                                  llvm::Constant *dtor, llvm::Constant *addr);
467b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith
468b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /*************************** thread_local initialization ********************/
469b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith
470b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// Emits ABI-required functions necessary to initialize thread_local
471b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// variables in this translation unit.
472b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  ///
473b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// \param Decls The thread_local declarations in this translation unit.
474b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// \param InitFunc If this translation unit contains any non-constant
475b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  ///        initialization or non-trivial destruction for thread_local
476b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  ///        variables, a function to perform the initialization. Otherwise, 0.
477b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  virtual void EmitThreadLocalInitFuncs(
478b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith      llvm::ArrayRef<std::pair<const VarDecl *, llvm::GlobalVariable *> > Decls,
479b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith      llvm::Function *InitFunc);
480b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith
481b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// Emit a reference to a non-local thread_local variable (including
482b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// triggering the initialization of all thread_local variables in its
483b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// translation unit).
484b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  virtual LValue EmitThreadLocalDeclRefExpr(CodeGenFunction &CGF,
485b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith                                            const DeclRefExpr *DRE);
4863a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis};
4873a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
48896fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall// Create an instance of a C++ ABI class:
48996fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall
49096fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall/// Creates an Itanium-family ABI.
491071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
49296fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall
49396fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall/// Creates a Microsoft-family ABI.
494071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
49593d557bc1867b7d7b102f87290194b4be7932c92John McCall
4963a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis}
4973a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis}
4983a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
4993a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis#endif
500