CGCXXABI.h revision 2eb9a959d24ad757a82ecab61f343635ad67749a
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 18d47d3b0cfeb7e8564ff77f48130fe63282b6d127Chris Lattner#include "clang/Basic/LLVM.h" 19d47d3b0cfeb7e8564ff77f48130fe63282b6d127Chris Lattner 204c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall#include "CodeGenFunction.h" 214c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 2293d557bc1867b7d7b102f87290194b4be7932c92John McCallnamespace llvm { 23cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall class Constant; 240bab0cdab751248ca389a5592bcb70eac5d39260John McCall class Type; 2593d557bc1867b7d7b102f87290194b4be7932c92John McCall class Value; 2693d557bc1867b7d7b102f87290194b4be7932c92John McCall} 2793d557bc1867b7d7b102f87290194b4be7932c92John McCall 283a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davisnamespace clang { 293023def6bea3af6dbb51eea51f8cb8ea892d26cfJohn McCall class CastExpr; 304c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall class CXXConstructorDecl; 314c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall class CXXDestructorDecl; 32875ab10245d3bf37252dd822aa1616bb0a391095John McCall class CXXMethodDecl; 33cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall class CXXRecordDecl; 340bab0cdab751248ca389a5592bcb70eac5d39260John McCall class FieldDecl; 3514110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne class MangleContext; 3693d557bc1867b7d7b102f87290194b4be7932c92John McCall 373a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davisnamespace CodeGen { 3893d557bc1867b7d7b102f87290194b4be7932c92John McCall class CodeGenFunction; 393a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis class CodeGenModule; 403a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis 413b2adf237ab033173d7789ec1214d654eec17697James Dennett/// \brief Implements C++ ABI-specific code generation functions. 42071cc7deffad608165b1ddd5263e8bf181861520Charles Davisclass CGCXXABI { 43d608cdb7c044365cf4e8764ade1e11e99c176078John McCallprotected: 44d608cdb7c044365cf4e8764ade1e11e99c176078John McCall CodeGenModule &CGM; 456f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith OwningPtr<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 584c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall ImplicitParamDecl *&getVTTDecl(CodeGenFunction &CGF) { 594c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall return CGF.CXXVTTDecl; 604c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall } 614c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall llvm::Value *&getVTTValue(CodeGenFunction &CGF) { 624c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall return CGF.CXXVTTValue; 634c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall } 644c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 654c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// Build a parameter variable suitable for 'this'. 664c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall void BuildThisParam(CodeGenFunction &CGF, FunctionArgList &Params); 674c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 684c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// Perform prolog initialization of the parameter variable suitable 694c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// for 'this' emitted by BuildThisParam. 704c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall void EmitThisParam(CodeGenFunction &CGF); 714c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 721e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall ASTContext &getContext() const { return CGM.getContext(); } 731e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall 74e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType); 75e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall virtual bool requiresArrayCookie(const CXXNewExpr *E); 76e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall 773a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davispublic: 78d608cdb7c044365cf4e8764ade1e11e99c176078John McCall 791af610f8533b8b4a7b0b176aa8082f5b6dde904cAnders Carlsson virtual ~CGCXXABI(); 803a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis 813a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis /// Gets the mangle context. 8214110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne MangleContext &getMangleContext() { 8314110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne return *MangleCtx; 8414110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne } 8593d557bc1867b7d7b102f87290194b4be7932c92John McCall 860bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Find the LLVM type used to represent the given member pointer 870bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// type. 889cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner virtual llvm::Type * 890bab0cdab751248ca389a5592bcb70eac5d39260John McCall ConvertMemberPointerType(const MemberPointerType *MPT); 900bab0cdab751248ca389a5592bcb70eac5d39260John McCall 910bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Load a member function from an object and a member function 920bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// pointer. Apply the this-adjustment and set 'This' to the 930bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// adjusted value. 9493d557bc1867b7d7b102f87290194b4be7932c92John McCall virtual llvm::Value * 9593d557bc1867b7d7b102f87290194b4be7932c92John McCall EmitLoadOfMemberFunctionPointer(CodeGenFunction &CGF, 9693d557bc1867b7d7b102f87290194b4be7932c92John McCall llvm::Value *&This, 9793d557bc1867b7d7b102f87290194b4be7932c92John McCall llvm::Value *MemPtr, 9893d557bc1867b7d7b102f87290194b4be7932c92John McCall const MemberPointerType *MPT); 993023def6bea3af6dbb51eea51f8cb8ea892d26cfJohn McCall 1006c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall /// Calculate an l-value from an object and a data member pointer. 1016c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall virtual llvm::Value *EmitMemberDataPointerAddress(CodeGenFunction &CGF, 1026c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall llvm::Value *Base, 1036c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall llvm::Value *MemPtr, 1046c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall const MemberPointerType *MPT); 1056c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall 1064d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// Perform a derived-to-base, base-to-derived, or bitcast member 1074d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// pointer conversion. 1080bab0cdab751248ca389a5592bcb70eac5d39260John McCall virtual llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF, 1090bab0cdab751248ca389a5592bcb70eac5d39260John McCall const CastExpr *E, 1100bab0cdab751248ca389a5592bcb70eac5d39260John McCall llvm::Value *Src); 111d608cdb7c044365cf4e8764ade1e11e99c176078John McCall 1124d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// Perform a derived-to-base, base-to-derived, or bitcast member 1134d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// pointer conversion on a constant value. 1144d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall virtual llvm::Constant *EmitMemberPointerConversion(const CastExpr *E, 1154d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall llvm::Constant *Src); 1164d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall 1170bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Return true if the given member pointer can be zero-initialized 1180bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// (in the C++ sense) with an LLVM zeroinitializer. 119f16aa103d3afd42fbca2ab346f191bf745cec092John McCall virtual bool isZeroInitializable(const MemberPointerType *MPT); 120cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall 1210bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Create a null member pointer of the given type. 1220bab0cdab751248ca389a5592bcb70eac5d39260John McCall virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT); 123cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall 1240bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Create a member pointer for the given method. 125755d8497e39071aa24acc173ff07083e3256b8f8John McCall virtual llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD); 126875ab10245d3bf37252dd822aa1616bb0a391095John McCall 1270bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Create a member pointer for the given field. 1285808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT, 1295808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall CharUnits offset); 130e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall 1312d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith /// Create a member pointer for the given member pointer constant. 1322d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith virtual llvm::Constant *EmitMemberPointer(const APValue &MP, QualType MPT); 1332d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith 1340bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Emit a comparison between two member pointers. Returns an i1. 135e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall virtual llvm::Value * 1360bab0cdab751248ca389a5592bcb70eac5d39260John McCall EmitMemberPointerComparison(CodeGenFunction &CGF, 1370bab0cdab751248ca389a5592bcb70eac5d39260John McCall llvm::Value *L, 1380bab0cdab751248ca389a5592bcb70eac5d39260John McCall llvm::Value *R, 1390bab0cdab751248ca389a5592bcb70eac5d39260John McCall const MemberPointerType *MPT, 1400bab0cdab751248ca389a5592bcb70eac5d39260John McCall bool Inequality); 141e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall 1420bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Determine if a member pointer is non-null. Returns an i1. 143e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall virtual llvm::Value * 1440bab0cdab751248ca389a5592bcb70eac5d39260John McCall EmitMemberPointerIsNotNull(CodeGenFunction &CGF, 1450bab0cdab751248ca389a5592bcb70eac5d39260John McCall llvm::Value *MemPtr, 1460bab0cdab751248ca389a5592bcb70eac5d39260John McCall const MemberPointerType *MPT); 1474c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 1484d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCallprotected: 1494d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// A utility method for computing the offset required for the given 1504d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// base-to-derived or derived-to-base member-pointer conversion. 1514d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// Does not handle virtual conversions (in case we ever fully 1524d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// support an ABI that allows this). Returns null if no adjustment 1534d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// is required. 1544d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall llvm::Constant *getMemberPointerAdjustment(const CastExpr *E); 1554d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall 1564d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCallpublic: 157ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall /// Adjust the given non-null pointer to an object of polymorphic 158ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall /// type to point to the complete object. 159ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall /// 160ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall /// The IR type of the result should be a pointer but is otherwise 161ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall /// irrelevant. 162ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall virtual llvm::Value *adjustToCompleteObject(CodeGenFunction &CGF, 163ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall llvm::Value *ptr, 164ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall QualType type) = 0; 165ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall 1664c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// Build the signature of the given constructor variant by adding 1674c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// any required parameters. For convenience, ResTy has been 1684c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// initialized to 'void', and ArgTys has been initialized with the 1694c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// type of 'this' (although this may be changed by the ABI) and 1704c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// will have the formal parameters added to it afterwards. 1714c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// 1724c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// If there are ever any ABIs where the implicit parameters are 1734c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// intermixed with the formal parameters, we can address those 1744c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// then. 1754c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall virtual void BuildConstructorSignature(const CXXConstructorDecl *Ctor, 1764c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall CXXCtorType T, 1774c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall CanQualType &ResTy, 178686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<CanQualType> &ArgTys) = 0; 1794c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 1804c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// Build the signature of the given destructor variant by adding 1814c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// any required parameters. For convenience, ResTy has been 1824c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// initialized to 'void' and ArgTys has been initialized with the 1834c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// type of 'this' (although this may be changed by the ABI). 1844c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall virtual void BuildDestructorSignature(const CXXDestructorDecl *Dtor, 1854c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall CXXDtorType T, 1864c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall CanQualType &ResTy, 187686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<CanQualType> &ArgTys) = 0; 1884c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 1894c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// Build the ABI-specific portion of the parameter list for a 1904c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// function. This generally involves a 'this' parameter and 1914c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// possibly some extra data for constructors and destructors. 1924c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// 1934c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// ABIs may also choose to override the return type, which has been 1944c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// initialized with the formal return type of the function. 1954c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall virtual void BuildInstanceFunctionParams(CodeGenFunction &CGF, 1964c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall QualType &ResTy, 1974c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall FunctionArgList &Params) = 0; 1984c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 1994c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// Emit the ABI-specific prolog for the function. 2004c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0; 2014c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 2024c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall virtual void EmitReturnFromThunk(CodeGenFunction &CGF, 2034c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall RValue RV, QualType ResultType); 2041e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall 205285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos /// Gets the pure virtual member call function. 206285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos virtual StringRef GetPureVirtualCallName() = 0; 207285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos 2082eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie /// Gets the deleted virtual member call name. 2092eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie virtual StringRef GetDeletedVirtualCallName() = 0; 2102eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie 2111e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /**************************** Array cookies ******************************/ 2121e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall 2131e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// Returns the extra size required in order to store the array 21416ae9de07730832945204877d752db7f1c070962James Dennett /// cookie for the given new-expression. May return 0 to indicate that no 2151e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// array cookie is required. 2161e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// 2171e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// Several cases are filtered out before this method is called: 2181e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// - non-array allocations never need a cookie 2195900103d6606edef5fc81bbac685fa3651f1b936James Dennett /// - calls to \::operator new(size_t, void*) never need a cookie 2201e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// 22116ae9de07730832945204877d752db7f1c070962James Dennett /// \param expr - the new-expression being allocated. 2226ec278d1a354517e20f13a877481453ee7940c78John McCall virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr); 2231e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall 2241e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// Initialize the array cookie for the given allocation. 2251e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// 2261e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param NewPtr - a char* which is the presumed-non-null 2271e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// return value of the allocation function 2281e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param NumElements - the computed number of elements, 229e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// potentially collapsed from the multidimensional array case; 230e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// always a size_t 2311e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param ElementType - the base element allocated type, 2321e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// i.e. the allocated type after stripping all array types 2331e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall virtual llvm::Value *InitializeArrayCookie(CodeGenFunction &CGF, 2341e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall llvm::Value *NewPtr, 2351e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall llvm::Value *NumElements, 2366ec278d1a354517e20f13a877481453ee7940c78John McCall const CXXNewExpr *expr, 2371e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall QualType ElementType); 2381e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall 2391e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// Reads the array cookie associated with the given pointer, 2401e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// if it has one. 2411e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// 2421e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param Ptr - a pointer to the first element in the array 2431e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param ElementType - the base element type of elements of the array 2441e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param NumElements - an out parameter which will be initialized 2451e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// with the number of elements allocated, or zero if there is no 2461e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// cookie 2471e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param AllocPtr - an out parameter which will be initialized 2481e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// with a char* pointing to the address returned by the allocation 2491e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// function 2501e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param CookieSize - an out parameter which will be initialized 2511e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// with the size of the cookie, or zero if there is no cookie 2521e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall virtual void ReadArrayCookie(CodeGenFunction &CGF, llvm::Value *Ptr, 2536ec278d1a354517e20f13a877481453ee7940c78John McCall const CXXDeleteExpr *expr, 2541e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall QualType ElementType, llvm::Value *&NumElements, 2551e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall llvm::Value *&AllocPtr, CharUnits &CookieSize); 2561e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall 257e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCallprotected: 258e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// Returns the extra size required in order to store the array 259e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// cookie for the given type. Assumes that an array cookie is 260e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// required. 261e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall virtual CharUnits getArrayCookieSizeImpl(QualType elementType); 262e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall 263e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// Reads the array cookie for an allocation which is known to have one. 264e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// This is called by the standard implementation of ReadArrayCookie. 265e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// 266e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// \param ptr - a pointer to the allocation made for an array, as a char* 267e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// \param cookieSize - the computed cookie size of an array 2683b2adf237ab033173d7789ec1214d654eec17697James Dennett /// 269e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// Other parameters are as above. 2703b2adf237ab033173d7789ec1214d654eec17697James Dennett /// 271e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// \return a size_t 272e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall virtual llvm::Value *readArrayCookieImpl(CodeGenFunction &IGF, 273e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall llvm::Value *ptr, 274e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall CharUnits cookieSize); 275e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall 276e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCallpublic: 277e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall 2785cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall /*************************** Static local guards ****************************/ 2795cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall 2803030eb82593097502469a8b3fc26112c79c75605John McCall /// Emits the guarded initializer and destructor setup for the given 2813030eb82593097502469a8b3fc26112c79c75605John McCall /// variable, given that it couldn't be emitted as a constant. 2827ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith /// If \p PerformInit is false, the initialization has been folded to a 2837ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith /// constant and should not be performed. 2843030eb82593097502469a8b3fc26112c79c75605John McCall /// 2853030eb82593097502469a8b3fc26112c79c75605John McCall /// The variable may be: 2863030eb82593097502469a8b3fc26112c79c75605John McCall /// - a static local variable 2873030eb82593097502469a8b3fc26112c79c75605John McCall /// - a static data member of a class template instantiation 2883030eb82593097502469a8b3fc26112c79c75605John McCall virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D, 2890f30a12ce7b3d4d86c9ca9072f587da77c8eef34Chandler Carruth llvm::GlobalVariable *DeclPtr, bool PerformInit); 2905cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall 29120bb175cb8ae5844034828db094fb948c0e3454aJohn McCall /// Emit code to force the execution of a destructor during global 29220bb175cb8ae5844034828db094fb948c0e3454aJohn McCall /// teardown. The default implementation of this uses atexit. 29320bb175cb8ae5844034828db094fb948c0e3454aJohn McCall /// 29420bb175cb8ae5844034828db094fb948c0e3454aJohn McCall /// \param dtor - a function taking a single pointer argument 29520bb175cb8ae5844034828db094fb948c0e3454aJohn McCall /// \param addr - a pointer to pass to the destructor function. 29620bb175cb8ae5844034828db094fb948c0e3454aJohn McCall virtual void registerGlobalDtor(CodeGenFunction &CGF, llvm::Constant *dtor, 29720bb175cb8ae5844034828db094fb948c0e3454aJohn McCall llvm::Constant *addr); 2989ee494f98610dcd79441dce469d7bf609fcd7b92Charles Davis 2999ee494f98610dcd79441dce469d7bf609fcd7b92Charles Davis /***************************** Virtual Tables *******************************/ 3009ee494f98610dcd79441dce469d7bf609fcd7b92Charles Davis 3019ee494f98610dcd79441dce469d7bf609fcd7b92Charles Davis /// Generates and emits the virtual tables for a class. 3029ee494f98610dcd79441dce469d7bf609fcd7b92Charles Davis virtual void EmitVTables(const CXXRecordDecl *Class) = 0; 3033a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis}; 3043a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis 3053a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis/// Creates an instance of a C++ ABI class. 306ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCallCGCXXABI *CreateARMCXXABI(CodeGenModule &CGM); 307071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM); 308071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM); 30993d557bc1867b7d7b102f87290194b4be7932c92John McCall 3103a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis} 3113a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis} 3123a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis 3133a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis#endif 314