CGCXXABI.h revision a8a0f769ff4113a7f98c232fb0fc773a65371559
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
10063fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren  /// Returns true if the given instance method is one of the
10163fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren  /// kinds that the ABI says returns 'this'.
10263fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren  virtual bool HasThisReturn(GlobalDecl GD) const { return false; }
10363fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren
1040bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Find the LLVM type used to represent the given member pointer
1050bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// type.
1069cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner  virtual llvm::Type *
1070bab0cdab751248ca389a5592bcb70eac5d39260John McCall  ConvertMemberPointerType(const MemberPointerType *MPT);
1080bab0cdab751248ca389a5592bcb70eac5d39260John McCall
1090bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Load a member function from an object and a member function
1100bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// pointer.  Apply the this-adjustment and set 'This' to the
1110bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// adjusted value.
11293d557bc1867b7d7b102f87290194b4be7932c92John McCall  virtual llvm::Value *
11393d557bc1867b7d7b102f87290194b4be7932c92John McCall  EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF,
11493d557bc1867b7d7b102f87290194b4be7932c92John McCall                                  llvm::Value *&This,
11593d557bc1867b7d7b102f87290194b4be7932c92John McCall                                  llvm::Value *MemPtr,
11693d557bc1867b7d7b102f87290194b4be7932c92John McCall                                  const MemberPointerType *MPT);
1173023def6bea3af6dbb51eea51f8cb8ea892d26cfJohn McCall
1186c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall  /// Calculate an l-value from an object and a data member pointer.
1196c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall  virtual llvm::Value *EmitMemberDataPointerAddress(CodeGenFunction &CGF,
1206c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall                                                    llvm::Value *Base,
1216c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall                                                    llvm::Value *MemPtr,
1226c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall                                            const MemberPointerType *MPT);
1236c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall
1244d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// Perform a derived-to-base, base-to-derived, or bitcast member
1254d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// pointer conversion.
1260bab0cdab751248ca389a5592bcb70eac5d39260John McCall  virtual llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF,
1270bab0cdab751248ca389a5592bcb70eac5d39260John McCall                                                   const CastExpr *E,
1280bab0cdab751248ca389a5592bcb70eac5d39260John McCall                                                   llvm::Value *Src);
129d608cdb7c044365cf4e8764ade1e11e99c176078John McCall
1304d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// Perform a derived-to-base, base-to-derived, or bitcast member
1314d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// pointer conversion on a constant value.
1324d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  virtual llvm::Constant *EmitMemberPointerConversion(const CastExpr *E,
1334d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall                                                      llvm::Constant *Src);
1344d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall
1350bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Return true if the given member pointer can be zero-initialized
1360bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// (in the C++ sense) with an LLVM zeroinitializer.
137f16aa103d3afd42fbca2ab346f191bf745cec092John McCall  virtual bool isZeroInitializable(const MemberPointerType *MPT);
138cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall
1390bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Create a null member pointer of the given type.
1400bab0cdab751248ca389a5592bcb70eac5d39260John McCall  virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
141cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall
1420bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Create a member pointer for the given method.
143755d8497e39071aa24acc173ff07083e3256b8f8John McCall  virtual llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD);
144875ab10245d3bf37252dd822aa1616bb0a391095John McCall
1450bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Create a member pointer for the given field.
1465808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall  virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
1475808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall                                                CharUnits offset);
148e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall
1492d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  /// Create a member pointer for the given member pointer constant.
1502d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith  virtual llvm::Constant *EmitMemberPointer(const APValue &MP, QualType MPT);
1512d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith
1520bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Emit a comparison between two member pointers.  Returns an i1.
153e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall  virtual llvm::Value *
1540bab0cdab751248ca389a5592bcb70eac5d39260John McCall  EmitMemberPointerComparison(CodeGenFunction &CGF,
1550bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              llvm::Value *L,
1560bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              llvm::Value *R,
1570bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              const MemberPointerType *MPT,
1580bab0cdab751248ca389a5592bcb70eac5d39260John McCall                              bool Inequality);
159e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall
1600bab0cdab751248ca389a5592bcb70eac5d39260John McCall  /// Determine if a member pointer is non-null.  Returns an i1.
161e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall  virtual llvm::Value *
1620bab0cdab751248ca389a5592bcb70eac5d39260John McCall  EmitMemberPointerIsNotNull(CodeGenFunction &CGF,
1630bab0cdab751248ca389a5592bcb70eac5d39260John McCall                             llvm::Value *MemPtr,
1640bab0cdab751248ca389a5592bcb70eac5d39260John McCall                             const MemberPointerType *MPT);
1654c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
1664d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCallprotected:
1674d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// A utility method for computing the offset required for the given
1684d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// base-to-derived or derived-to-base member-pointer conversion.
1694d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// Does not handle virtual conversions (in case we ever fully
1704d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// support an ABI that allows this).  Returns null if no adjustment
1714d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  /// is required.
1724d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall  llvm::Constant *getMemberPointerAdjustment(const CastExpr *E);
1734d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall
1744d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCallpublic:
175ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  /// Adjust the given non-null pointer to an object of polymorphic
176ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  /// type to point to the complete object.
177ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  ///
178ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  /// The IR type of the result should be a pointer but is otherwise
179ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  /// irrelevant.
180ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall  virtual llvm::Value *adjustToCompleteObject(CodeGenFunction &CGF,
181ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall                                              llvm::Value *ptr,
182ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall                                              QualType type) = 0;
183ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall
1844c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Build the signature of the given constructor variant by adding
1854c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// any required parameters.  For convenience, ResTy has been
1864c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// initialized to 'void', and ArgTys has been initialized with the
1874c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// type of 'this' (although this may be changed by the ABI) and
1884c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// will have the formal parameters added to it afterwards.
1894c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  ///
1904c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// If there are ever any ABIs where the implicit parameters are
1914c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// intermixed with the formal parameters, we can address those
1924c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// then.
1934c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void BuildConstructorSignature(const CXXConstructorDecl *Ctor,
1944c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                         CXXCtorType T,
1954c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                         CanQualType &ResTy,
196686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               SmallVectorImpl<CanQualType> &ArgTys) = 0;
1974c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
1981d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov  virtual llvm::BasicBlock *EmitCtorCompleteObjectHandler(CodeGenFunction &CGF);
1991d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov
2004c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Build the signature of the given destructor variant by adding
2014c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// any required parameters.  For convenience, ResTy has been
2024c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// initialized to 'void' and ArgTys has been initialized with the
2034c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// type of 'this' (although this may be changed by the ABI).
2044c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void BuildDestructorSignature(const CXXDestructorDecl *Dtor,
2054c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                        CXXDtorType T,
2064c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                        CanQualType &ResTy,
207686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               SmallVectorImpl<CanQualType> &ArgTys) = 0;
2084c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
2094c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Build the ABI-specific portion of the parameter list for a
2104c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// function.  This generally involves a 'this' parameter and
2114c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// possibly some extra data for constructors and destructors.
2124c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  ///
2134c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// ABIs may also choose to override the return type, which has been
2144c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// initialized with the formal return type of the function.
2154c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void BuildInstanceFunctionParams(CodeGenFunction &CGF,
2164c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                           QualType &ResTy,
2174c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                           FunctionArgList &Params) = 0;
2184c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
2194c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  /// Emit the ABI-specific prolog for the function.
2204c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0;
2214c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall
22263fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren  /// Emit the constructor call. Return the function that is called.
22363fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren  virtual llvm::Value *EmitConstructorCall(CodeGenFunction &CGF,
2241d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov                                   const CXXConstructorDecl *D,
2251d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov                                   CXXCtorType Type, bool ForVirtualBase,
2261d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov                                   bool Delegating,
2271d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov                                   llvm::Value *This,
2281d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov                                   CallExpr::const_arg_iterator ArgBeg,
2291d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov                                   CallExpr::const_arg_iterator ArgEnd) = 0;
2301d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov
2310f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov  /// Emit the ABI-specific virtual destructor call.
2320f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov  virtual RValue EmitVirtualDestructorCall(CodeGenFunction &CGF,
2330f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov                                           const CXXDestructorDecl *Dtor,
2340f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov                                           CXXDtorType DtorType,
2350f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov                                           SourceLocation CallLoc,
2360f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov                                           ReturnValueSlot ReturnValue,
2370f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov                                           llvm::Value *This) = 0;
2380f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov
2394c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall  virtual void EmitReturnFromThunk(CodeGenFunction &CGF,
2404c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall                                   RValue RV, QualType ResultType);
2411e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
242285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos  /// Gets the pure virtual member call function.
243285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos  virtual StringRef GetPureVirtualCallName() = 0;
244285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos
2452eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie  /// Gets the deleted virtual member call name.
2462eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie  virtual StringRef GetDeletedVirtualCallName() = 0;
2472eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie
2481e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /**************************** Array cookies ******************************/
2491e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
2501e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Returns the extra size required in order to store the array
25116ae9de07730832945204877d752db7f1c070962James Dennett  /// cookie for the given new-expression.  May return 0 to indicate that no
2521e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// array cookie is required.
2531e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
2541e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Several cases are filtered out before this method is called:
2551e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   - non-array allocations never need a cookie
2565900103d6606edef5fc81bbac685fa3651f1b936James Dennett  ///   - calls to \::operator new(size_t, void*) never need a cookie
2571e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
25816ae9de07730832945204877d752db7f1c070962James Dennett  /// \param expr - the new-expression being allocated.
2596ec278d1a354517e20f13a877481453ee7940c78John McCall  virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr);
2601e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
2611e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Initialize the array cookie for the given allocation.
2621e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
2631e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param NewPtr - a char* which is the presumed-non-null
2641e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   return value of the allocation function
2651e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param NumElements - the computed number of elements,
266e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  ///   potentially collapsed from the multidimensional array case;
267e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  ///   always a size_t
2681e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param ElementType - the base element allocated type,
2691e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   i.e. the allocated type after stripping all array types
2701e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  virtual llvm::Value *InitializeArrayCookie(CodeGenFunction &CGF,
2711e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                                             llvm::Value *NewPtr,
2721e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                                             llvm::Value *NumElements,
2736ec278d1a354517e20f13a877481453ee7940c78John McCall                                             const CXXNewExpr *expr,
2741e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                                             QualType ElementType);
2751e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
2761e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// Reads the array cookie associated with the given pointer,
2771e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// if it has one.
2781e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///
2791e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param Ptr - a pointer to the first element in the array
2801e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param ElementType - the base element type of elements of the array
2811e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param NumElements - an out parameter which will be initialized
2821e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   with the number of elements allocated, or zero if there is no
2831e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   cookie
2841e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param AllocPtr - an out parameter which will be initialized
2851e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   with a char* pointing to the address returned by the allocation
2861e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   function
2871e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  /// \param CookieSize - an out parameter which will be initialized
2881e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  ///   with the size of the cookie, or zero if there is no cookie
2891e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall  virtual void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr,
2906ec278d1a354517e20f13a877481453ee7940c78John McCall                               const CXXDeleteExpr *expr,
2911e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                               QualType ElementType, llvm::Value *&NumElements,
2921e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall                               llvm::Value *&AllocPtr, CharUnits &CookieSize);
2931e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall
294e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCallprotected:
295e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// Returns the extra size required in order to store the array
296e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// cookie for the given type.  Assumes that an array cookie is
297e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// required.
298e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual CharUnits getArrayCookieSizeImpl(QualType elementType);
299e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
300e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// Reads the array cookie for an allocation which is known to have one.
301e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// This is called by the standard implementation of ReadArrayCookie.
302e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  ///
303e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// \param ptr - a pointer to the allocation made for an array, as a char*
304e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// \param cookieSize - the computed cookie size of an array
3053b2adf237ab033173d7789ec1214d654eec17697James Dennett  ///
306e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// Other parameters are as above.
3073b2adf237ab033173d7789ec1214d654eec17697James Dennett  ///
308e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  /// \return a size_t
309e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall  virtual llvm::Value *readArrayCookieImpl(CodeGenFunction &IGF,
310e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall                                           llvm::Value *ptr,
311e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall                                           CharUnits cookieSize);
312e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
313e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCallpublic:
314e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall
3155cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall  /*************************** Static local guards ****************************/
3165cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall
3173030eb82593097502469a8b3fc26112c79c75605John McCall  /// Emits the guarded initializer and destructor setup for the given
3183030eb82593097502469a8b3fc26112c79c75605John McCall  /// variable, given that it couldn't be emitted as a constant.
3197ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith  /// If \p PerformInit is false, the initialization has been folded to a
3207ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith  /// constant and should not be performed.
3213030eb82593097502469a8b3fc26112c79c75605John McCall  ///
3223030eb82593097502469a8b3fc26112c79c75605John McCall  /// The variable may be:
3233030eb82593097502469a8b3fc26112c79c75605John McCall  ///   - a static local variable
3243030eb82593097502469a8b3fc26112c79c75605John McCall  ///   - a static data member of a class template instantiation
3253030eb82593097502469a8b3fc26112c79c75605John McCall  virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D,
3260f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth                               llvm::GlobalVariable *DeclPtr, bool PerformInit);
3275cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall
32820bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// Emit code to force the execution of a destructor during global
32920bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// teardown.  The default implementation of this uses atexit.
33020bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  ///
33120bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// \param dtor - a function taking a single pointer argument
33220bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  /// \param addr - a pointer to pass to the destructor function.
33320bb175cb8ae5844034828db094fb948c0e3454aJohn McCall  virtual void registerGlobalDtor(CodeGenFunction &CGF, llvm::Constant *dtor,
33420bb175cb8ae5844034828db094fb948c0e3454aJohn McCall                                  llvm::Constant *addr);
3353a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis};
3363a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
33796fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall// Create an instance of a C++ ABI class:
33896fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall
33996fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall/// Creates an Itanium-family ABI.
340071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM);
34196fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall
34296fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall/// Creates a Microsoft-family ABI.
343071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM);
34493d557bc1867b7d7b102f87290194b4be7932c92John McCall
3453a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis}
3463a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis}
3473a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis
3483a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis#endif
349