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
15176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines#ifndef LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H
16176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines#define LLVM_CLANG_LIB_CODEGEN_CGCXXABI_H
173a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
184c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall#include "CodeGenFunction.h"
1955fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include "clang/Basic/LLVM.h"
204c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
2193d557bc1867b7d7b102f87290194b4be7932c92John McCallnamespace llvm {
226bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass Constant;
236bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass Type;
246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass Value;
253ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainarclass CallInst;
2693d557bc1867b7d7b102f87290194b4be7932c92John McCall}
2793d557bc1867b7d7b102f87290194b4be7932c92John McCall
283a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davisnamespace clang {
296bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CastExpr;
306bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CXXConstructorDecl;
316bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CXXDestructorDecl;
326bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CXXMethodDecl;
336bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CXXRecordDecl;
346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass FieldDecl;
356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass MangleContext;
3693d557bc1867b7d7b102f87290194b4be7932c92John McCall
373a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davisnamespace CodeGen {
386bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CodeGenFunction;
396bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hinesclass CodeGenModule;
403a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
413b2adf237ab033173d7789ec1214d654eec17697James Dennett/// \brief Implements C++ ABI-specific code generation functions.
42071cc7deffad608165b1ddd5263e8bf181861520Charles Davisclass CGCXXABI {
43d608cdb7c044365cf4e8764ade1e11e99c176078John McCallprotected:
44d608cdb7c044365cf4e8764ade1e11e99c176078John McCall  CodeGenModule &CGM;
45651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  std::unique_ptr<MangleContext> MangleCtx;
46d608cdb7c044365cf4e8764ade1e11e99c176078John McCall
4714110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne  CGCXXABI(CodeGenModule &CGM)
4814110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne    : CGM(CGM), MangleCtx(CGM.getContext().createMangleContext()) {}
49d608cdb7c044365cf4e8764ade1e11e99c176078John McCall
504c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCallprotected:
514c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  ImplicitParamDecl *&getThisDecl(CodeGenFunction &CGF) {
52cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman    return CGF.CXXABIThisDecl;
534c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  }
544c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  llvm::Value *&getThisValue(CodeGenFunction &CGF) {
55cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman    return CGF.CXXABIThisValue;
564c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  }
574c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
58a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner  /// Issue a diagnostic about unsupported features in the ABI.
59a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner  void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S);
60a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner
61a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner  /// Get a null value for unsupported member pointers.
62a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner  llvm::Constant *GetBogusMemberPointer(QualType T);
63a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner
6459660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  ImplicitParamDecl *&getStructorImplicitParamDecl(CodeGenFunction &CGF) {
6559660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    return CGF.CXXStructorImplicitParamDecl;
6659660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  }
6759660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov  llvm::Value *&getStructorImplicitParamValue(CodeGenFunction &CGF) {
6859660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov    return CGF.CXXStructorImplicitParamValue;
694c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  }
704c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
714c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Perform prolog initialization of the parameter variable suitable
72651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// for 'this' emitted by buildThisParam.
734c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  void EmitThisParam(CodeGenFunction &CGF);
744c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
751e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ASTContext &getContext() const { return CGM.getContext(); }
761e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
77e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType);
78e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual bool requiresArrayCookie(const CXXNewExpr *E);
79e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
803a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davispublic:
81d608cdb7c044365cf4e8764ade1e11e99c176078John McCall
821af610f8533b8b4a7b0b176aa8082f5b6dde904cAnders Carlsson  virtual ~CGCXXABI();
833a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
843a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis  /// Gets the mangle context.
8514110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne  MangleContext &getMangleContext() {
8614110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne    return *MangleCtx;
8714110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne  }
8893d557bc1867b7d7b102f87290194b4be7932c92John McCall
893b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// Returns true if the given constructor or destructor is one of the
903b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// kinds that the ABI says returns 'this' (only applies when called
913b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// non-virtually for destructors).
923b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  ///
933b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// There currently is no way to indicate if a destructor returns 'this'
943b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// when called virtually, and code generation does not support the case.
9563fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren  virtual bool HasThisReturn(GlobalDecl GD) const { return false; }
9663fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren
97176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  virtual bool hasMostDerivedReturn(GlobalDecl GD) const { return false; }
98176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
996bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// If the C++ ABI requires the given type be returned in a particular way,
1006bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// this method sets RetAI and returns true.
1016bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  virtual bool classifyReturnType(CGFunctionInfo &FI) const = 0;
102ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov
103ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov  /// Specify how one should pass an argument of a record type.
104ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov  enum RecordArgABI {
105ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    /// Pass it using the normal C aggregate rules for the ABI, potentially
106ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    /// introducing extra copies and passing some or all of it in registers.
107ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    RAA_Default = 0,
108ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov
109ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    /// Pass it on the stack using its defined layout.  The argument must be
110ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    /// evaluated directly into the correct stack position in the arguments area,
111ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    /// and the call machinery must not move it or introduce extra copies.
112ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    RAA_DirectInMemory,
113ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov
114ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    /// Pass it as a pointer to temporary memory.
115ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov    RAA_Indirect
116ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov  };
117ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov
1186bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// Returns true if C++ allows us to copy the memory of an object of type RD
1196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// when it is passed as an argument.
1206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool canCopyArgument(const CXXRecordDecl *RD) const;
1216bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
122ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov  /// Returns how an argument of the given record type should be passed.
123ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov  virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const = 0;
124ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov
1256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// Returns true if the implicit 'sret' parameter comes after the implicit
1266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// 'this' parameter of C++ instance methods.
1276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  virtual bool isSRetParameterAfterThis() const { return false; }
1286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
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.
137651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  virtual llvm::Value *EmitLoadOfMemberFunctionPointer(
138651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      CodeGenFunction &CGF, const Expr *E, llvm::Value *&This,
139651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines      llvm::Value *MemPtr, const MemberPointerType *MPT);
1403023def6bea3af6dbb51eea51f8cb8ea892d26cfJohn McCall
1416c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall  /// Calculate an l-value from an object and a data member pointer.
142651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  virtual llvm::Value *
143651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  EmitMemberDataPointerAddress(CodeGenFunction &CGF, const Expr *E,
144651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                               llvm::Value *Base, llvm::Value *MemPtr,
145651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                               const MemberPointerType *MPT);
1466c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall
1474d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// Perform a derived-to-base, base-to-derived, or bitcast member
1484d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// pointer conversion.
1490bab0cdab751248ca389a5592bcb70eac5d39260John McCall  virtual llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF,
1500bab0cdab751248ca389a5592bcb70eac5d39260John McCall                                                   const CastExpr *E,
1510bab0cdab751248ca389a5592bcb70eac5d39260John McCall                                                   llvm::Value *Src);
152d608cdb7c044365cf4e8764ade1e11e99c176078John McCall
1534d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// Perform a derived-to-base, base-to-derived, or bitcast member
1544d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// pointer conversion on a constant value.
1554d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  virtual llvm::Constant *EmitMemberPointerConversion(const CastExpr *E,
1564d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall                                                      llvm::Constant *Src);
1574d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall
1580bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Return true if the given member pointer can be zero-initialized
1590bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// (in the C++ sense) with an LLVM zeroinitializer.
160f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  virtual bool isZeroInitializable(const MemberPointerType *MPT);
161cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall
162176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// Return whether or not a member pointers type is convertible to an IR type.
163176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const {
164176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    return true;
165176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  }
166176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
167176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  virtual bool isTypeInfoCalculable(QualType Ty) const {
168176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    return !Ty->isIncompleteType();
169176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  }
170176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
1710bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Create a null member pointer of the given type.
1720bab0cdab751248ca389a5592bcb70eac5d39260John McCall  virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
173cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall
1740bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Create a member pointer for the given method.
175755d8497e39071aa24acc173ff07083e3256b8f8John McCall  virtual llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD);
176875ab10245d3bf37252dd822aa1616bb0a391095John McCall
1770bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Create a member pointer for the given field.
1785808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall  virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
1795808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall                                                CharUnits offset);
180e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall
1812d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  /// Create a member pointer for the given member pointer constant.
1822d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  virtual llvm::Constant *EmitMemberPointer(const APValue &MP, QualType MPT);
1832d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith
1840bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Emit a comparison between two member pointers.  Returns an i1.
185e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall  virtual llvm::Value *
1860bab0cdab751248ca389a5592bcb70eac5d39260John McCall  EmitMemberPointerComparison(CodeGenFunction &CGF,
1870bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              llvm::Value *L,
1880bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              llvm::Value *R,
1890bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              const MemberPointerType *MPT,
1900bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              bool Inequality);
191e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall
1920bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Determine if a member pointer is non-null.  Returns an i1.
193e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall  virtual llvm::Value *
1940bab0cdab751248ca389a5592bcb70eac5d39260John McCall  EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
1950bab0cdab751248ca389a5592bcb70eac5d39260John McCall                             llvm::Value *MemPtr,
1960bab0cdab751248ca389a5592bcb70eac5d39260John McCall                             const MemberPointerType *MPT);
1974c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
1984d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCallprotected:
1994d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// A utility method for computing the offset required for the given
2004d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// base-to-derived or derived-to-base member-pointer conversion.
2014d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// Does not handle virtual conversions (in case we ever fully
2024d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// support an ABI that allows this).  Returns null if no adjustment
2034d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// is required.
2044d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  llvm::Constant *getMemberPointerAdjustment(const CastExpr *E);
2054d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall
206f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner  /// \brief Computes the non-virtual adjustment needed for a member pointer
207f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner  /// conversion along an inheritance path stored in an APValue.  Unlike
208f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner  /// getMemberPointerAdjustment(), the adjustment can be negative if the path
209f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner  /// is from a derived type to a base type.
210f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner  CharUnits getMemberPointerPathAdjustment(const APValue &MP);
211f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner
2124d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCallpublic:
213176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  virtual void emitVirtualObjectDelete(CodeGenFunction &CGF,
214176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                       const CXXDeleteExpr *DE,
215176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                       llvm::Value *Ptr, QualType ElementType,
216176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                       const CXXDestructorDecl *Dtor) = 0;
2170e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  virtual void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) = 0;
2183ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar  virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) = 0;
2193ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar  virtual llvm::GlobalVariable *getThrowInfo(QualType T) { return nullptr; }
2203ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar
2213ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar  virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) = 0;
2223ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar
2233ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar  virtual llvm::CallInst *
2243ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar  emitTerminateForUnexpectedException(CodeGenFunction &CGF,
2253ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar                                      llvm::Value *Exn);
226ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall
227c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  virtual llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) = 0;
2283ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar  virtual llvm::Constant *
22933337ca4d89605025818daf83390ab4271d598d9Pirama Arumuga Nainar  getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType) = 0;
230c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
231c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  virtual bool shouldTypeidBeNullChecked(bool IsDeref,
232c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines                                         QualType SrcRecordTy) = 0;
233c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  virtual void EmitBadTypeidCall(CodeGenFunction &CGF) = 0;
234c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  virtual llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy,
235c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines                                  llvm::Value *ThisPtr,
236c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines                                  llvm::Type *StdTypeInfoPtrTy) = 0;
237c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
238c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr,
239c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines                                                  QualType SrcRecordTy) = 0;
240c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
241c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  virtual llvm::Value *
242c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  EmitDynamicCastCall(CodeGenFunction &CGF, llvm::Value *Value,
243c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines                      QualType SrcRecordTy, QualType DestTy,
244c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines                      QualType DestRecordTy, llvm::BasicBlock *CastEnd) = 0;
245c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
246c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  virtual llvm::Value *EmitDynamicCastToVoid(CodeGenFunction &CGF,
247c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines                                             llvm::Value *Value,
248c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines                                             QualType SrcRecordTy,
249c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines                                             QualType DestTy) = 0;
250c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
251c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  virtual bool EmitBadCastCall(CodeGenFunction &CGF) = 0;
252c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
253b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner  virtual llvm::Value *GetVirtualBaseClassOffset(CodeGenFunction &CGF,
254b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner                                                 llvm::Value *This,
255b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner                                                 const CXXRecordDecl *ClassDecl,
256b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner                                        const CXXRecordDecl *BaseClassDecl) = 0;
257b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner
2589063302a82423cb83f002257a416741850739a70Reid Kleckner  virtual llvm::BasicBlock *EmitCtorCompleteObjectHandler(CodeGenFunction &CGF,
2599063302a82423cb83f002257a416741850739a70Reid Kleckner                                                          const CXXRecordDecl *RD);
2601d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov
2615bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov  /// Emit the code to initialize hidden members required
2625bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov  /// to handle virtual inheritance, if needed by the ABI.
2635bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov  virtual void
2645bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov  initializeHiddenVirtualInheritanceMembers(CodeGenFunction &CGF,
2655bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov                                            const CXXRecordDecl *RD) {}
2665bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov
267bb1b797d2e432293563747bd9704b22cf0787061Timur Iskhodzhanov  /// Emit constructor variants required by this ABI.
268bb1b797d2e432293563747bd9704b22cf0787061Timur Iskhodzhanov  virtual void EmitCXXConstructors(const CXXConstructorDecl *D) = 0;
269bb1b797d2e432293563747bd9704b22cf0787061Timur Iskhodzhanov
270176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// Build the signature of the given constructor or destructor variant by
271176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// adding any required parameters.  For convenience, ArgTys has been
272176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// initialized with the type of 'this'.
273176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  virtual void buildStructorSignature(const CXXMethodDecl *MD, StructorType T,
274176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                      SmallVectorImpl<CanQualType> &ArgTys) = 0;
2754c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
276a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  /// Returns true if the given destructor type should be emitted as a linkonce
277a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  /// delegating thunk, regardless of whether the dtor is defined in this TU or
278a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  /// not.
279a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor,
280a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner                                      CXXDtorType DT) const = 0;
281a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner
282a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  /// Emit destructor variants required by this ABI.
283a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner  virtual void EmitCXXDestructors(const CXXDestructorDecl *D) = 0;
284a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner
2858f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// Get the type of the implicit "this" parameter used by a method. May return
2868f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// zero if no specific type is applicable, e.g. if the ABI expects the "this"
2878f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// parameter to point to some artificial offset in a complete object due to
2888f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// vbases being reordered.
2898f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  virtual const CXXRecordDecl *
2908f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  getThisArgumentTypeForMethod(const CXXMethodDecl *MD) {
2918f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov    return MD->getParent();
2928f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  }
2938f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov
2948f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// Perform ABI-specific "this" argument adjustment required prior to
295651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// a call of a virtual function.
296651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// The "VirtualCall" argument is true iff the call itself is virtual.
297651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  virtual llvm::Value *
298651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD,
299651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                                           llvm::Value *This,
300651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                                           bool VirtualCall) {
3018f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov    return This;
3028f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  }
3038f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov
304651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// Build a parameter variable suitable for 'this'.
305651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params);
306651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
307651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// Insert any ABI-specific implicit parameters into the parameter list for a
308651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// function.  This generally involves extra data for constructors and
309651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// destructors.
3104c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  ///
3114c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// ABIs may also choose to override the return type, which has been
3123b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or
3133b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin  /// the formal return type of the function otherwise.
314651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy,
315651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                                         FunctionArgList &Params) = 0;
3164c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
3178f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// Perform ABI-specific "this" parameter adjustment in a virtual function
3188f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// prologue.
3198f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  virtual llvm::Value *adjustThisParameterInVirtualFunctionPrologue(
3208f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov      CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This) {
3218f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov    return This;
3228f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  }
3238f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov
3244c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Emit the ABI-specific prolog for the function.
3254c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0;
3264c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
327651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// Add any ABI-specific implicit arguments needed to call a constructor.
328651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  ///
329651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \return The number of args added to the call, which is typically zero or
330651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// one.
331651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  virtual unsigned
332651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D,
333651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                             CXXCtorType Type, bool ForVirtualBase,
334651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                             bool Delegating, CallArgList &Args) = 0;
335651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
336651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// Emit the destructor call.
337651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  virtual void EmitDestructorCall(CodeGenFunction &CGF,
338651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                                  const CXXDestructorDecl *DD, CXXDtorType Type,
339651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                                  bool ForVirtualBase, bool Delegating,
340651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                                  llvm::Value *This) = 0;
3411d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov
342a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// Emits the VTable definitions required for the given record type.
343a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  virtual void emitVTableDefinitions(CodeGenVTables &CGVT,
344a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov                                     const CXXRecordDecl *RD) = 0;
345a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov
346a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// Get the address point of the vtable for the given base subobject while
347a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// building a constructor or a destructor. On return, NeedsVirtualOffset
348a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// tells if a virtual base adjustment is needed in order to get the offset
349a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// of the base subobject.
350a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  virtual llvm::Value *getVTableAddressPointInStructor(
351a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov      CodeGenFunction &CGF, const CXXRecordDecl *RD, BaseSubobject Base,
352a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov      const CXXRecordDecl *NearestVBase, bool &NeedsVirtualOffset) = 0;
353a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov
354a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// Get the address point of the vtable for the given base subobject while
355a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// building a constexpr.
356a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  virtual llvm::Constant *
357a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  getVTableAddressPointForConstExpr(BaseSubobject Base,
358a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov                                    const CXXRecordDecl *VTableClass) = 0;
359a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov
360a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// Get the address of the vtable for the given record decl which should be
361a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  /// used for the vptr at the given offset in RD.
362a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  virtual llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD,
363a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov                                                CharUnits VPtrOffset) = 0;
364a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov
3658f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  /// Build a virtual function pointer in the ABI-specific way.
3668f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov  virtual llvm::Value *getVirtualFunctionPointer(CodeGenFunction &CGF,
3678f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov                                                 GlobalDecl GD,
3688f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov                                                 llvm::Value *This,
3698f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov                                                 llvm::Type *Ty) = 0;
3708f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov
3710f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov  /// Emit the ABI-specific virtual destructor call.
372176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  virtual llvm::Value *
373176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor,
374176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                            CXXDtorType DtorType, llvm::Value *This,
375176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                            const CXXMemberCallExpr *CE) = 0;
3760f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov
3772cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov  virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF,
3782cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov                                                GlobalDecl GD,
3792cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov                                                CallArgList &CallArgs) {}
3802cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov
3819063302a82423cb83f002257a416741850739a70Reid Kleckner  /// Emit any tables needed to implement virtual inheritance.  For Itanium,
3829063302a82423cb83f002257a416741850739a70Reid Kleckner  /// this emits virtual table tables.  For the MSVC++ ABI, this emits virtual
3839063302a82423cb83f002257a416741850739a70Reid Kleckner  /// base tables.
384a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov  virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD) = 0;
3859063302a82423cb83f002257a416741850739a70Reid Kleckner
386c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines  virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable,
387c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines                               GlobalDecl GD, bool ReturnAdjustment) = 0;
3882cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov
389c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov  virtual llvm::Value *performThisAdjustment(CodeGenFunction &CGF,
390c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov                                             llvm::Value *This,
391c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov                                             const ThisAdjustment &TA) = 0;
392c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov
393c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov  virtual llvm::Value *performReturnAdjustment(CodeGenFunction &CGF,
394c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov                                               llvm::Value *Ret,
395c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov                                               const ReturnAdjustment &RA) = 0;
396c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov
3974c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void EmitReturnFromThunk(CodeGenFunction &CGF,
3984c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                   RValue RV, QualType ResultType);
3991e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
400176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *,
401176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                      FunctionArgList &Args) const = 0;
402176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
403285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos  /// Gets the pure virtual member call function.
404285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos  virtual StringRef GetPureVirtualCallName() = 0;
405285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos
4062eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie  /// Gets the deleted virtual member call name.
4072eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie  virtual StringRef GetDeletedVirtualCallName() = 0;
4082eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie
4091e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /**************************** Array cookies ******************************/
4101e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
4111e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Returns the extra size required in order to store the array
41216ae9de07730832945204877d752db7f1c070962James Dennett  /// cookie for the given new-expression.  May return 0 to indicate that no
4131e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// array cookie is required.
4141e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
4151e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Several cases are filtered out before this method is called:
4161e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   - non-array allocations never need a cookie
4175900103d6606edef5fc81bbac685fa3651f1b936James Dennett  ///   - calls to \::operator new(size_t, void*) never need a cookie
4181e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
41916ae9de07730832945204877d752db7f1c070962James Dennett  /// \param expr - the new-expression being allocated.
4206ec278d1a354517e20f13a877481453ee7940c78John McCall  virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr);
4211e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
4221e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Initialize the array cookie for the given allocation.
4231e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
4241e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param NewPtr - a char* which is the presumed-non-null
4251e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   return value of the allocation function
4261e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param NumElements - the computed number of elements,
427e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  ///   potentially collapsed from the multidimensional array case;
428e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  ///   always a size_t
4291e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param ElementType - the base element allocated type,
4301e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   i.e. the allocated type after stripping all array types
4311e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  virtual llvm::Value *InitializeArrayCookie(CodeGenFunction &CGF,
4321e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                                             llvm::Value *NewPtr,
4331e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                                             llvm::Value *NumElements,
4346ec278d1a354517e20f13a877481453ee7940c78John McCall                                             const CXXNewExpr *expr,
4351e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                                             QualType ElementType);
4361e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
4371e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Reads the array cookie associated with the given pointer,
4381e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// if it has one.
4391e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
4401e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param Ptr - a pointer to the first element in the array
4411e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param ElementType - the base element type of elements of the array
4421e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param NumElements - an out parameter which will be initialized
4431e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   with the number of elements allocated, or zero if there is no
4441e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   cookie
4451e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param AllocPtr - an out parameter which will be initialized
4461e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   with a char* pointing to the address returned by the allocation
4471e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   function
4481e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param CookieSize - an out parameter which will be initialized
4491e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   with the size of the cookie, or zero if there is no cookie
4501e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  virtual void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
4516ec278d1a354517e20f13a877481453ee7940c78John McCall                               const CXXDeleteExpr *expr,
4521e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                               QualType ElementType, llvm::Value *&NumElements,
4531e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                               llvm::Value *&AllocPtr, CharUnits &CookieSize);
4541e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
455e1e35f761970fd662696b803a839c1f4a56f61b2Peter Collingbourne  /// Return whether the given global decl needs a VTT parameter.
456e1e35f761970fd662696b803a839c1f4a56f61b2Peter Collingbourne  virtual bool NeedsVTTParameter(GlobalDecl GD);
457e1e35f761970fd662696b803a839c1f4a56f61b2Peter Collingbourne
458e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCallprotected:
459e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// Returns the extra size required in order to store the array
460e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// cookie for the given type.  Assumes that an array cookie is
461e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// required.
462e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual CharUnits getArrayCookieSizeImpl(QualType elementType);
463e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
464e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// Reads the array cookie for an allocation which is known to have one.
465e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// This is called by the standard implementation of ReadArrayCookie.
466e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  ///
467e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// \param ptr - a pointer to the allocation made for an array, as a char*
468e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// \param cookieSize - the computed cookie size of an array
4693b2adf237ab033173d7789ec1214d654eec17697James Dennett  ///
470e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// Other parameters are as above.
4713b2adf237ab033173d7789ec1214d654eec17697James Dennett  ///
472e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// \return a size_t
473e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual llvm::Value *readArrayCookieImpl(CodeGenFunction &IGF,
474e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall                                           llvm::Value *ptr,
475e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall                                           CharUnits cookieSize);
476e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
477e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCallpublic:
478e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
4795cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall  /*************************** Static local guards ****************************/
4805cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall
4813030eb82593097502469a8b3fc26112c79c75605John McCall  /// Emits the guarded initializer and destructor setup for the given
4823030eb82593097502469a8b3fc26112c79c75605John McCall  /// variable, given that it couldn't be emitted as a constant.
4837ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith  /// If \p PerformInit is false, the initialization has been folded to a
4847ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith  /// constant and should not be performed.
4853030eb82593097502469a8b3fc26112c79c75605John McCall  ///
4863030eb82593097502469a8b3fc26112c79c75605John McCall  /// The variable may be:
4873030eb82593097502469a8b3fc26112c79c75605John McCall  ///   - a static local variable
4883030eb82593097502469a8b3fc26112c79c75605John McCall  ///   - a static data member of a class template instantiation
4893030eb82593097502469a8b3fc26112c79c75605John McCall  virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
490942f9fe11d3a9583eef6bc4ca2549b1f0d1694daReid Kleckner                               llvm::GlobalVariable *DeclPtr,
491942f9fe11d3a9583eef6bc4ca2549b1f0d1694daReid Kleckner                               bool PerformInit) = 0;
4925cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall
49320bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// Emit code to force the execution of a destructor during global
49420bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// teardown.  The default implementation of this uses atexit.
49520bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  ///
496176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// \param Dtor - a function taking a single pointer argument
497176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// \param Addr - a pointer to pass to the destructor function.
49804e517650569598e847c2ab609672e6df93effe5Richard Smith  virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D,
499176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                  llvm::Constant *Dtor,
500176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                  llvm::Constant *Addr) = 0;
501b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith
502b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /*************************** thread_local initialization ********************/
503b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith
504b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// Emits ABI-required functions necessary to initialize thread_local
505b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// variables in this translation unit.
506b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  ///
507176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// \param CXXThreadLocals - The thread_local declarations in this translation
508176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ///        unit.
509176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// \param CXXThreadLocalInits - If this translation unit contains any
510176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ///        non-constant initialization or non-trivial destruction for
511176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ///        thread_local variables, a list of functions to perform the
512176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ///        initialization.
513b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  virtual void EmitThreadLocalInitFuncs(
514176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      CodeGenModule &CGM,
515176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      ArrayRef<std::pair<const VarDecl *, llvm::GlobalVariable *>>
516176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines          CXXThreadLocals,
517176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      ArrayRef<llvm::Function *> CXXThreadLocalInits,
518176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      ArrayRef<llvm::GlobalVariable *> CXXThreadLocalInitVars) = 0;
519176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
520176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  // Determine if references to thread_local global variables can be made
521176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  // directly or require access through a thread wrapper function.
522176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  virtual bool usesThreadWrapperFunction() const = 0;
523b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith
524b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// Emit a reference to a non-local thread_local variable (including
525b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// triggering the initialization of all thread_local variables in its
526b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith  /// translation unit).
527651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF,
528651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                                              const VarDecl *VD,
529176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                              QualType LValType) = 0;
530176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
531176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// Emit a single constructor/destructor with the given type from a C++
532176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// constructor Decl.
533176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  virtual void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) = 0;
5343a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis};
5353a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
53696fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall// Create an instance of a C++ ABI class:
53796fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall
53896fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall/// Creates an Itanium-family ABI.
539071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
54096fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall
54196fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall/// Creates a Microsoft-family ABI.
542071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
54393d557bc1867b7d7b102f87290194b4be7932c92John McCall
5443a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis}
5453a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis}
5463a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
5473a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis#endif
548