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; 4087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainarstruct CatchTypeInfo; 413a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis 423b2adf237ab033173d7789ec1214d654eec17697James Dennett/// \brief Implements C++ ABI-specific code generation functions. 43071cc7deffad608165b1ddd5263e8bf181861520Charles Davisclass CGCXXABI { 44d608cdb7c044365cf4e8764ade1e11e99c176078John McCallprotected: 45d608cdb7c044365cf4e8764ade1e11e99c176078John McCall CodeGenModule &CGM; 46651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::unique_ptr<MangleContext> MangleCtx; 47d608cdb7c044365cf4e8764ade1e11e99c176078John McCall 4814110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne CGCXXABI(CodeGenModule &CGM) 4914110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne : CGM(CGM), MangleCtx(CGM.getContext().createMangleContext()) {} 50d608cdb7c044365cf4e8764ade1e11e99c176078John McCall 514c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCallprotected: 5287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar ImplicitParamDecl *getThisDecl(CodeGenFunction &CGF) { 53cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman return CGF.CXXABIThisDecl; 544c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall } 5587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *getThisValue(CodeGenFunction &CGF) { 56cec5ebd4a6a89a7023d04cec728fd340b541ed61Eli Friedman return CGF.CXXABIThisValue; 574c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall } 5887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address getThisAddress(CodeGenFunction &CGF) { 5987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar return Address(CGF.CXXABIThisValue, CGF.CXXABIThisAlignment); 6087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar } 614c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 62a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner /// Issue a diagnostic about unsupported features in the ABI. 63a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner void ErrorUnsupportedABI(CodeGenFunction &CGF, StringRef S); 64a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner 65a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner /// Get a null value for unsupported member pointers. 66a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner llvm::Constant *GetBogusMemberPointer(QualType T); 67a8a0f769ff4113a7f98c232fb0fc773a65371559Reid Kleckner 6859660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov ImplicitParamDecl *&getStructorImplicitParamDecl(CodeGenFunction &CGF) { 6959660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov return CGF.CXXStructorImplicitParamDecl; 7059660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov } 7159660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov llvm::Value *&getStructorImplicitParamValue(CodeGenFunction &CGF) { 7259660c21178b6af518bd4b564e032d5c9cc218cbTimur Iskhodzhanov return CGF.CXXStructorImplicitParamValue; 734c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall } 744c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 754c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// Perform prolog initialization of the parameter variable suitable 76651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// for 'this' emitted by buildThisParam. 774c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall void EmitThisParam(CodeGenFunction &CGF); 784c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 791e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall ASTContext &getContext() const { return CGM.getContext(); } 801e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall 81e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall virtual bool requiresArrayCookie(const CXXDeleteExpr *E, QualType eltType); 82e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall virtual bool requiresArrayCookie(const CXXNewExpr *E); 83e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall 8487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Determine whether there's something special about the rules of 8587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// the ABI tell us that 'this' is a complete object within the 8687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// given function. Obvious common logic like being defined on a 8787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// final class will have been taken care of by the caller. 8887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual bool isThisCompleteObject(GlobalDecl GD) const = 0; 8987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 903a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davispublic: 91d608cdb7c044365cf4e8764ade1e11e99c176078John McCall 921af610f8533b8b4a7b0b176aa8082f5b6dde904cAnders Carlsson virtual ~CGCXXABI(); 933a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis 943a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis /// Gets the mangle context. 9514110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne MangleContext &getMangleContext() { 9614110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne return *MangleCtx; 9714110477887e3dc168ffc6c191e72d705051f99ePeter Collingbourne } 9893d557bc1867b7d7b102f87290194b4be7932c92John McCall 993b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin /// Returns true if the given constructor or destructor is one of the 1003b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin /// kinds that the ABI says returns 'this' (only applies when called 1013b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin /// non-virtually for destructors). 1023b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin /// 1033b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin /// There currently is no way to indicate if a destructor returns 'this' 1043b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin /// when called virtually, and code generation does not support the case. 10563fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren virtual bool HasThisReturn(GlobalDecl GD) const { return false; } 10663fd408a61ae9b94e8d8a986832f526f7cdbfa84Manman Ren 107176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines virtual bool hasMostDerivedReturn(GlobalDecl GD) const { return false; } 108176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 1094967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Returns true if the target allows calling a function through a pointer 1104967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// with a different signature than the actual function (or equivalently, 1114967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// bitcasting a function or function pointer to a different function type). 1124967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// In principle in the most general case this could depend on the target, the 1134967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// calling convention, and the actual types of the arguments and return 1144967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// value. Here it just means whether the signature mismatch could *ever* be 1154967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// allowed; in other words, does the target do strict checking of signatures 1164967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// for all calls. 1174967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar virtual bool canCallMismatchedFunctionType() const { return true; } 1184967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 1196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// If the C++ ABI requires the given type be returned in a particular way, 1206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// this method sets RetAI and returns true. 1216bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual bool classifyReturnType(CGFunctionInfo &FI) const = 0; 122ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov 123ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov /// Specify how one should pass an argument of a record type. 124ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov enum RecordArgABI { 125ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov /// Pass it using the normal C aggregate rules for the ABI, potentially 126ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov /// introducing extra copies and passing some or all of it in registers. 127ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov RAA_Default = 0, 128ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov 129ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov /// Pass it on the stack using its defined layout. The argument must be 130ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov /// evaluated directly into the correct stack position in the arguments area, 131ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov /// and the call machinery must not move it or introduce extra copies. 132ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov RAA_DirectInMemory, 133ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov 134ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov /// Pass it as a pointer to temporary memory. 135ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov RAA_Indirect 136ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov }; 137ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov 1386bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// Returns true if C++ allows us to copy the memory of an object of type RD 1396bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// when it is passed as an argument. 1406bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines bool canCopyArgument(const CXXRecordDecl *RD) const; 1416bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 142ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov /// Returns how an argument of the given record type should be passed. 143ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const = 0; 144ed23bdf69dd63e4fd01c02b12a13d1e6cbff9c2fTimur Iskhodzhanov 1456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// Returns true if the implicit 'sret' parameter comes after the implicit 1466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines /// 'this' parameter of C++ instance methods. 1476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines virtual bool isSRetParameterAfterThis() const { return false; } 1486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 1490bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Find the LLVM type used to represent the given member pointer 1500bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// type. 1519cbe4f0ba01ec304e1e3d071c071f7bca33631c0Chris Lattner virtual llvm::Type * 1520bab0cdab751248ca389a5592bcb70eac5d39260John McCall ConvertMemberPointerType(const MemberPointerType *MPT); 1530bab0cdab751248ca389a5592bcb70eac5d39260John McCall 1540bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Load a member function from an object and a member function 1550bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// pointer. Apply the this-adjustment and set 'This' to the 1560bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// adjusted value. 157651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines virtual llvm::Value *EmitLoadOfMemberFunctionPointer( 15887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CodeGenFunction &CGF, const Expr *E, Address This, 15987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *&ThisPtrForCall, llvm::Value *MemPtr, 16087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const MemberPointerType *MPT); 1613023def6bea3af6dbb51eea51f8cb8ea892d26cfJohn McCall 1626c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall /// Calculate an l-value from an object and a data member pointer. 163651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines virtual llvm::Value * 164651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines EmitMemberDataPointerAddress(CodeGenFunction &CGF, const Expr *E, 16587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address Base, llvm::Value *MemPtr, 166651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const MemberPointerType *MPT); 1676c2ab1d578c6cc1f3ddcc948532cd625f1092ef2John McCall 1684d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// Perform a derived-to-base, base-to-derived, or bitcast member 1694d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// pointer conversion. 1700bab0cdab751248ca389a5592bcb70eac5d39260John McCall virtual llvm::Value *EmitMemberPointerConversion(CodeGenFunction &CGF, 1710bab0cdab751248ca389a5592bcb70eac5d39260John McCall const CastExpr *E, 1720bab0cdab751248ca389a5592bcb70eac5d39260John McCall llvm::Value *Src); 173d608cdb7c044365cf4e8764ade1e11e99c176078John McCall 1744d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// Perform a derived-to-base, base-to-derived, or bitcast member 1754d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// pointer conversion on a constant value. 1764d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall virtual llvm::Constant *EmitMemberPointerConversion(const CastExpr *E, 1774d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall llvm::Constant *Src); 1784d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall 1790bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Return true if the given member pointer can be zero-initialized 1800bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// (in the C++ sense) with an LLVM zeroinitializer. 181f16aa103d3afd42fbca2ab346f191bf745cec092John McCall virtual bool isZeroInitializable(const MemberPointerType *MPT); 182cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall 183176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// Return whether or not a member pointers type is convertible to an IR type. 184176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines virtual bool isMemberPointerConvertible(const MemberPointerType *MPT) const { 185176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines return true; 186176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines } 187176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 1880bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Create a null member pointer of the given type. 1890bab0cdab751248ca389a5592bcb70eac5d39260John McCall virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT); 190cf2c85e76fdafe7e634810a292321a6c8322483dJohn McCall 1910bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Create a member pointer for the given method. 19287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual llvm::Constant *EmitMemberFunctionPointer(const CXXMethodDecl *MD); 193875ab10245d3bf37252dd822aa1616bb0a391095John McCall 1940bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Create a member pointer for the given field. 1955808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT, 1965808ce43f8d7e71f5acacc9ca320268c4f37565aJohn McCall CharUnits offset); 197e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall 1982d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith /// Create a member pointer for the given member pointer constant. 1992d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith virtual llvm::Constant *EmitMemberPointer(const APValue &MP, QualType MPT); 2002d6a5670465cb3f1d811695a9f23e372508240d2Richard Smith 2010bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Emit a comparison between two member pointers. Returns an i1. 202e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall virtual llvm::Value * 2030bab0cdab751248ca389a5592bcb70eac5d39260John McCall EmitMemberPointerComparison(CodeGenFunction &CGF, 2040bab0cdab751248ca389a5592bcb70eac5d39260John McCall llvm::Value *L, 2050bab0cdab751248ca389a5592bcb70eac5d39260John McCall llvm::Value *R, 2060bab0cdab751248ca389a5592bcb70eac5d39260John McCall const MemberPointerType *MPT, 2070bab0cdab751248ca389a5592bcb70eac5d39260John McCall bool Inequality); 208e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall 2090bab0cdab751248ca389a5592bcb70eac5d39260John McCall /// Determine if a member pointer is non-null. Returns an i1. 210e9fd7eb6c67676dc27e84eac429aec4f3be51f26John McCall virtual llvm::Value * 2110bab0cdab751248ca389a5592bcb70eac5d39260John McCall EmitMemberPointerIsNotNull(CodeGenFunction &CGF, 2120bab0cdab751248ca389a5592bcb70eac5d39260John McCall llvm::Value *MemPtr, 2130bab0cdab751248ca389a5592bcb70eac5d39260John McCall const MemberPointerType *MPT); 2144c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 2154d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCallprotected: 2164d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// A utility method for computing the offset required for the given 2174d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// base-to-derived or derived-to-base member-pointer conversion. 2184d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// Does not handle virtual conversions (in case we ever fully 2194d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// support an ABI that allows this). Returns null if no adjustment 2204d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall /// is required. 2214d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall llvm::Constant *getMemberPointerAdjustment(const CastExpr *E); 2224d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCall 223f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner /// \brief Computes the non-virtual adjustment needed for a member pointer 224f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner /// conversion along an inheritance path stored in an APValue. Unlike 225f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner /// getMemberPointerAdjustment(), the adjustment can be negative if the path 226f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner /// is from a derived type to a base type. 227f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner CharUnits getMemberPointerPathAdjustment(const APValue &MP); 228f632730ffb0b8ca531a35e737b29cc9f9774ca1dReid Kleckner 2294d4e5c1ae83f4510caa486b3ad19de13048f9f04John McCallpublic: 230176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines virtual void emitVirtualObjectDelete(CodeGenFunction &CGF, 231176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const CXXDeleteExpr *DE, 23287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address Ptr, QualType ElementType, 233176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const CXXDestructorDecl *Dtor) = 0; 2340e2c34f92f00628d48968dfea096d36381f494cbStephen Hines virtual void emitRethrow(CodeGenFunction &CGF, bool isNoReturn) = 0; 2353ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar virtual void emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) = 0; 2363ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar virtual llvm::GlobalVariable *getThrowInfo(QualType T) { return nullptr; } 2373ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 23887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// \brief Determine whether it's possible to emit a vtable for \p RD, even 23987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// though we do not know that the vtable has been marked as used by semantic 24087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// analysis. 24187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const = 0; 24287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 2433ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar virtual void emitBeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *C) = 0; 2443ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar 2453ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar virtual llvm::CallInst * 2463ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar emitTerminateForUnexpectedException(CodeGenFunction &CGF, 2473ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar llvm::Value *Exn); 248ecd03b447bb0e2ed1954c77441d49a4a17ca8138John McCall 249c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines virtual llvm::Constant *getAddrOfRTTIDescriptor(QualType Ty) = 0; 25087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual CatchTypeInfo 25158878f85ab89b13e9eea4af3ccf055e42c557bc8Pirama Arumuga Nainar getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType) = 0; 25287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual CatchTypeInfo getCatchAllTypeInfo(); 253c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 254c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines virtual bool shouldTypeidBeNullChecked(bool IsDeref, 255c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines QualType SrcRecordTy) = 0; 256c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines virtual void EmitBadTypeidCall(CodeGenFunction &CGF) = 0; 257c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines virtual llvm::Value *EmitTypeid(CodeGenFunction &CGF, QualType SrcRecordTy, 25887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address ThisPtr, 259c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines llvm::Type *StdTypeInfoPtrTy) = 0; 260c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 261c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines virtual bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr, 262c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines QualType SrcRecordTy) = 0; 263c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 264c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines virtual llvm::Value * 26587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar EmitDynamicCastCall(CodeGenFunction &CGF, Address Value, 266c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines QualType SrcRecordTy, QualType DestTy, 267c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines QualType DestRecordTy, llvm::BasicBlock *CastEnd) = 0; 268c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 269c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines virtual llvm::Value *EmitDynamicCastToVoid(CodeGenFunction &CGF, 27087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address Value, 271c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines QualType SrcRecordTy, 272c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines QualType DestTy) = 0; 273c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 274c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines virtual bool EmitBadCastCall(CodeGenFunction &CGF) = 0; 275c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines 276b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner virtual llvm::Value *GetVirtualBaseClassOffset(CodeGenFunction &CGF, 27787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address This, 278b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner const CXXRecordDecl *ClassDecl, 279b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner const CXXRecordDecl *BaseClassDecl) = 0; 280b0f533e716ae5a21ca5682ea235a68082fd5ed28Reid Kleckner 2819063302a82423cb83f002257a416741850739a70Reid Kleckner virtual llvm::BasicBlock *EmitCtorCompleteObjectHandler(CodeGenFunction &CGF, 2829063302a82423cb83f002257a416741850739a70Reid Kleckner const CXXRecordDecl *RD); 2831d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov 2845bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov /// Emit the code to initialize hidden members required 2855bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov /// to handle virtual inheritance, if needed by the ABI. 2865bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov virtual void 2875bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov initializeHiddenVirtualInheritanceMembers(CodeGenFunction &CGF, 2885bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov const CXXRecordDecl *RD) {} 2895bd0d44c8da50f3a629c90fee92ce5cf1e31c9ffTimur Iskhodzhanov 290bb1b797d2e432293563747bd9704b22cf0787061Timur Iskhodzhanov /// Emit constructor variants required by this ABI. 291bb1b797d2e432293563747bd9704b22cf0787061Timur Iskhodzhanov virtual void EmitCXXConstructors(const CXXConstructorDecl *D) = 0; 292bb1b797d2e432293563747bd9704b22cf0787061Timur Iskhodzhanov 293176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// Build the signature of the given constructor or destructor variant by 294176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// adding any required parameters. For convenience, ArgTys has been 295176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// initialized with the type of 'this'. 296176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines virtual void buildStructorSignature(const CXXMethodDecl *MD, StructorType T, 297176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines SmallVectorImpl<CanQualType> &ArgTys) = 0; 2984c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 299a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner /// Returns true if the given destructor type should be emitted as a linkonce 300a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner /// delegating thunk, regardless of whether the dtor is defined in this TU or 301a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner /// not. 302a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor, 303a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner CXXDtorType DT) const = 0; 304a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner 305a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner /// Emit destructor variants required by this ABI. 306a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner virtual void EmitCXXDestructors(const CXXDestructorDecl *D) = 0; 307a4130baad9d10b7feabb7e003da53424e986d269Reid Kleckner 3088f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov /// Get the type of the implicit "this" parameter used by a method. May return 3098f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov /// zero if no specific type is applicable, e.g. if the ABI expects the "this" 3108f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov /// parameter to point to some artificial offset in a complete object due to 3118f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov /// vbases being reordered. 3128f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov virtual const CXXRecordDecl * 3138f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov getThisArgumentTypeForMethod(const CXXMethodDecl *MD) { 3148f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov return MD->getParent(); 3158f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov } 3168f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov 3178f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov /// Perform ABI-specific "this" argument adjustment required prior to 318651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// a call of a virtual function. 319651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// The "VirtualCall" argument is true iff the call itself is virtual. 32087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual Address 321651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines adjustThisArgumentForVirtualFunctionCall(CodeGenFunction &CGF, GlobalDecl GD, 32287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address This, bool VirtualCall) { 3238f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov return This; 3248f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov } 3258f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov 326651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// Build a parameter variable suitable for 'this'. 327651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params); 328651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 329651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// Insert any ABI-specific implicit parameters into the parameter list for a 330651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// function. This generally involves extra data for constructors and 331651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// destructors. 3324c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// 3334c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// ABIs may also choose to override the return type, which has been 3343b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin /// initialized with the type of 'this' if HasThisReturn(CGF.CurGD) is true or 3353b50e8d78c34fc57e25781015a2cb0536ca54f89Stephen Lin /// the formal return type of the function otherwise. 336651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy, 337651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines FunctionArgList &Params) = 0; 3384c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 3394967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// Get the ABI-specific "this" parameter adjustment to apply in the prologue 3404967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar /// of a virtual function. 3414967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar virtual CharUnits getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD) { 3424967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar return CharUnits::Zero(); 3434967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar } 3444967a710c84587c654b56c828382219c3937dacbPirama Arumuga Nainar 3458f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov /// Perform ABI-specific "this" parameter adjustment in a virtual function 3468f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov /// prologue. 3478f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov virtual llvm::Value *adjustThisParameterInVirtualFunctionPrologue( 3488f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov CodeGenFunction &CGF, GlobalDecl GD, llvm::Value *This) { 3498f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov return This; 3508f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov } 3518f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov 3524c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall /// Emit the ABI-specific prolog for the function. 3534c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF) = 0; 3544c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall 355651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// Add any ABI-specific implicit arguments needed to call a constructor. 356651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// 357651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \return The number of args added to the call, which is typically zero or 358651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// one. 359651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines virtual unsigned 360651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines addImplicitConstructorArgs(CodeGenFunction &CGF, const CXXConstructorDecl *D, 361651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines CXXCtorType Type, bool ForVirtualBase, 362651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool Delegating, CallArgList &Args) = 0; 363651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 364651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// Emit the destructor call. 365651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines virtual void EmitDestructorCall(CodeGenFunction &CGF, 366651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const CXXDestructorDecl *DD, CXXDtorType Type, 367651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines bool ForVirtualBase, bool Delegating, 36887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address This) = 0; 3691d4fff5551c2347010b955b4337a2aa7d65a050eTimur Iskhodzhanov 370a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov /// Emits the VTable definitions required for the given record type. 371a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov virtual void emitVTableDefinitions(CodeGenVTables &CGVT, 372a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov const CXXRecordDecl *RD) = 0; 373a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov 37487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Checks if ABI requires extra virtual offset for vtable field. 37587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual bool 37687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar isVirtualOffsetNeededForVTableField(CodeGenFunction &CGF, 37787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CodeGenFunction::VPtr Vptr) = 0; 37887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 37987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Checks if ABI requires to initilize vptrs for given dynamic class. 38087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual bool doStructorsInitializeVPtrs(const CXXRecordDecl *VTableClass) = 0; 38187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 38287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Get the address point of the vtable for the given base subobject. 38387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual llvm::Constant * 38487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar getVTableAddressPoint(BaseSubobject Base, 38587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CXXRecordDecl *VTableClass) = 0; 38687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 387a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov /// Get the address point of the vtable for the given base subobject while 38887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// building a constructor or a destructor. 38987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual llvm::Value * 39087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar getVTableAddressPointInStructor(CodeGenFunction &CGF, const CXXRecordDecl *RD, 39187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar BaseSubobject Base, 39287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CXXRecordDecl *NearestVBase) = 0; 393a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov 394a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov /// Get the address point of the vtable for the given base subobject while 395a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov /// building a constexpr. 396a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov virtual llvm::Constant * 397a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov getVTableAddressPointForConstExpr(BaseSubobject Base, 398a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov const CXXRecordDecl *VTableClass) = 0; 399a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov 400a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov /// Get the address of the vtable for the given record decl which should be 401a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov /// used for the vptr at the given offset in RD. 402a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov virtual llvm::GlobalVariable *getAddrOfVTable(const CXXRecordDecl *RD, 403a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov CharUnits VPtrOffset) = 0; 404a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov 4058f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov /// Build a virtual function pointer in the ABI-specific way. 4068f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov virtual llvm::Value *getVirtualFunctionPointer(CodeGenFunction &CGF, 4078f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov GlobalDecl GD, 40887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address This, 40987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Type *Ty, 41087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar SourceLocation Loc) = 0; 4118f189a9911a992a5c4118c3789485a85bd96e045Timur Iskhodzhanov 4120f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov /// Emit the ABI-specific virtual destructor call. 413176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines virtual llvm::Value * 414176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines EmitVirtualDestructorCall(CodeGenFunction &CGF, const CXXDestructorDecl *Dtor, 41587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CXXDtorType DtorType, Address This, 416176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines const CXXMemberCallExpr *CE) = 0; 4170f9827f5d6248d7008063768eb5f2c3e6ba83e94Timur Iskhodzhanov 4182cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov virtual void adjustCallArgsForDestructorThunk(CodeGenFunction &CGF, 4192cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov GlobalDecl GD, 4202cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov CallArgList &CallArgs) {} 4212cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov 4229063302a82423cb83f002257a416741850739a70Reid Kleckner /// Emit any tables needed to implement virtual inheritance. For Itanium, 4239063302a82423cb83f002257a416741850739a70Reid Kleckner /// this emits virtual table tables. For the MSVC++ ABI, this emits virtual 4249063302a82423cb83f002257a416741850739a70Reid Kleckner /// base tables. 425a53d7a0259ff88f78ba8ecac7d0cb3ea96302b1dTimur Iskhodzhanov virtual void emitVirtualInheritanceTables(const CXXRecordDecl *RD) = 0; 4269063302a82423cb83f002257a416741850739a70Reid Kleckner 427c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines virtual void setThunkLinkage(llvm::Function *Thunk, bool ForVTable, 428c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines GlobalDecl GD, bool ReturnAdjustment) = 0; 4292cb17a06befb61b1434aaa991652fea4338c95d7Timur Iskhodzhanov 430c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov virtual llvm::Value *performThisAdjustment(CodeGenFunction &CGF, 43187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address This, 432c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov const ThisAdjustment &TA) = 0; 433c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov 434c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov virtual llvm::Value *performReturnAdjustment(CodeGenFunction &CGF, 43587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address Ret, 436c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov const ReturnAdjustment &RA) = 0; 437c70cc5d90403f99ccce5cab3a6c022ad9cdcb66cTimur Iskhodzhanov 4384c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall virtual void EmitReturnFromThunk(CodeGenFunction &CGF, 4394c40d98ab7acf5f27fa89b17bd8fc0ef7683df37John McCall RValue RV, QualType ResultType); 4401e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall 441176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines virtual size_t getSrcArgforCopyCtor(const CXXConstructorDecl *, 442176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines FunctionArgList &Args) const = 0; 443176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 44487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar /// Gets the offsets of all the virtual base pointers in a given class. 44587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual std::vector<CharUnits> getVBPtrOffsets(const CXXRecordDecl *RD); 44687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar 447285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos /// Gets the pure virtual member call function. 448285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos virtual StringRef GetPureVirtualCallName() = 0; 449285baac67d722beb6854f5faa45ee1aa62a7ce92Joao Matos 4502eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie /// Gets the deleted virtual member call name. 4512eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie virtual StringRef GetDeletedVirtualCallName() = 0; 4522eb9a959d24ad757a82ecab61f343635ad67749aDavid Blaikie 4531e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /**************************** Array cookies ******************************/ 4541e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall 4551e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// Returns the extra size required in order to store the array 45616ae9de07730832945204877d752db7f1c070962James Dennett /// cookie for the given new-expression. May return 0 to indicate that no 4571e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// array cookie is required. 4581e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// 4591e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// Several cases are filtered out before this method is called: 4601e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// - non-array allocations never need a cookie 4615900103d6606edef5fc81bbac685fa3651f1b936James Dennett /// - calls to \::operator new(size_t, void*) never need a cookie 4621e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// 46316ae9de07730832945204877d752db7f1c070962James Dennett /// \param expr - the new-expression being allocated. 4646ec278d1a354517e20f13a877481453ee7940c78John McCall virtual CharUnits GetArrayCookieSize(const CXXNewExpr *expr); 4651e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall 4661e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// Initialize the array cookie for the given allocation. 4671e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// 4681e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param NewPtr - a char* which is the presumed-non-null 4691e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// return value of the allocation function 4701e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param NumElements - the computed number of elements, 471e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// potentially collapsed from the multidimensional array case; 472e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// always a size_t 4731e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param ElementType - the base element allocated type, 4741e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// i.e. the allocated type after stripping all array types 47587d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual Address InitializeArrayCookie(CodeGenFunction &CGF, 47687d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar Address NewPtr, 47787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar llvm::Value *NumElements, 47887d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar const CXXNewExpr *expr, 47987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar QualType ElementType); 4801e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall 4811e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// Reads the array cookie associated with the given pointer, 4821e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// if it has one. 4831e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// 4841e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param Ptr - a pointer to the first element in the array 4851e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param ElementType - the base element type of elements of the array 4861e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param NumElements - an out parameter which will be initialized 4871e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// with the number of elements allocated, or zero if there is no 4881e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// cookie 4891e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param AllocPtr - an out parameter which will be initialized 4901e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// with a char* pointing to the address returned by the allocation 4911e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// function 4921e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// \param CookieSize - an out parameter which will be initialized 4931e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall /// with the size of the cookie, or zero if there is no cookie 49487d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual void ReadArrayCookie(CodeGenFunction &CGF, Address Ptr, 4956ec278d1a354517e20f13a877481453ee7940c78John McCall const CXXDeleteExpr *expr, 4961e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall QualType ElementType, llvm::Value *&NumElements, 4971e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall llvm::Value *&AllocPtr, CharUnits &CookieSize); 4981e7fe751466ea82665fd21e9162fd7cc9c5f412dJohn McCall 499e1e35f761970fd662696b803a839c1f4a56f61b2Peter Collingbourne /// Return whether the given global decl needs a VTT parameter. 500e1e35f761970fd662696b803a839c1f4a56f61b2Peter Collingbourne virtual bool NeedsVTTParameter(GlobalDecl GD); 501e1e35f761970fd662696b803a839c1f4a56f61b2Peter Collingbourne 502e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCallprotected: 503e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// Returns the extra size required in order to store the array 504e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// cookie for the given type. Assumes that an array cookie is 505e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// required. 506e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall virtual CharUnits getArrayCookieSizeImpl(QualType elementType); 507e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall 508e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// Reads the array cookie for an allocation which is known to have one. 509e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// This is called by the standard implementation of ReadArrayCookie. 510e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// 511e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// \param ptr - a pointer to the allocation made for an array, as a char* 512e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// \param cookieSize - the computed cookie size of an array 5133b2adf237ab033173d7789ec1214d654eec17697James Dennett /// 514e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// Other parameters are as above. 5153b2adf237ab033173d7789ec1214d654eec17697James Dennett /// 516e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall /// \return a size_t 51787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar virtual llvm::Value *readArrayCookieImpl(CodeGenFunction &IGF, Address ptr, 518e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall CharUnits cookieSize); 519e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall 520e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCallpublic: 521e2b45e2a43ae46bc00026b63ba7c04ef2b78c3ffJohn McCall 5225cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall /*************************** Static local guards ****************************/ 5235cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall 5243030eb82593097502469a8b3fc26112c79c75605John McCall /// Emits the guarded initializer and destructor setup for the given 5253030eb82593097502469a8b3fc26112c79c75605John McCall /// variable, given that it couldn't be emitted as a constant. 5267ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith /// If \p PerformInit is false, the initialization has been folded to a 5277ca4850a3e3530fa6c93b64b740446e32c97f992Richard Smith /// constant and should not be performed. 5283030eb82593097502469a8b3fc26112c79c75605John McCall /// 5293030eb82593097502469a8b3fc26112c79c75605John McCall /// The variable may be: 5303030eb82593097502469a8b3fc26112c79c75605John McCall /// - a static local variable 5313030eb82593097502469a8b3fc26112c79c75605John McCall /// - a static data member of a class template instantiation 5323030eb82593097502469a8b3fc26112c79c75605John McCall virtual void EmitGuardedInit(CodeGenFunction &CGF, const VarDecl &D, 533942f9fe11d3a9583eef6bc4ca2549b1f0d1694daReid Kleckner llvm::GlobalVariable *DeclPtr, 534942f9fe11d3a9583eef6bc4ca2549b1f0d1694daReid Kleckner bool PerformInit) = 0; 5355cd91b513455fd7753e8815b54f0a49bbca6602dJohn McCall 53620bb175cb8ae5844034828db094fb948c0e3454aJohn McCall /// Emit code to force the execution of a destructor during global 53720bb175cb8ae5844034828db094fb948c0e3454aJohn McCall /// teardown. The default implementation of this uses atexit. 53820bb175cb8ae5844034828db094fb948c0e3454aJohn McCall /// 539176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \param Dtor - a function taking a single pointer argument 540176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \param Addr - a pointer to pass to the destructor function. 54104e517650569598e847c2ab609672e6df93effe5Richard Smith virtual void registerGlobalDtor(CodeGenFunction &CGF, const VarDecl &D, 542176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines llvm::Constant *Dtor, 543176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines llvm::Constant *Addr) = 0; 544b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith 545b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith /*************************** thread_local initialization ********************/ 546b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith 547b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith /// Emits ABI-required functions necessary to initialize thread_local 548b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith /// variables in this translation unit. 549b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith /// 550176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \param CXXThreadLocals - The thread_local declarations in this translation 551176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// unit. 552176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// \param CXXThreadLocalInits - If this translation unit contains any 553176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// non-constant initialization or non-trivial destruction for 554176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// thread_local variables, a list of functions to perform the 555176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// initialization. 556b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith virtual void EmitThreadLocalInitFuncs( 55787d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar CodeGenModule &CGM, ArrayRef<const VarDecl *> CXXThreadLocals, 558176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines ArrayRef<llvm::Function *> CXXThreadLocalInits, 55987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar ArrayRef<const VarDecl *> CXXThreadLocalInitVars) = 0; 560176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 561176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // Determine if references to thread_local global variables can be made 562176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines // directly or require access through a thread wrapper function. 563176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines virtual bool usesThreadWrapperFunction() const = 0; 564b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith 565b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith /// Emit a reference to a non-local thread_local variable (including 566b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith /// triggering the initialization of all thread_local variables in its 567b80a16eadd0dacabfc1c32412e243ccb99dd664dRichard Smith /// translation unit). 568651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines virtual LValue EmitThreadLocalVarDeclLValue(CodeGenFunction &CGF, 569651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const VarDecl *VD, 570176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines QualType LValType) = 0; 571176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines 572176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// Emit a single constructor/destructor with the given type from a C++ 573176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines /// constructor Decl. 574176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines virtual void emitCXXStructor(const CXXMethodDecl *MD, StructorType Type) = 0; 5753a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis}; 5763a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis 57796fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall// Create an instance of a C++ ABI class: 57896fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall 57996fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall/// Creates an Itanium-family ABI. 580071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCGCXXABI *CreateItaniumCXXABI(CodeGenModule &CGM); 58196fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall 58296fcde0b8ed8bdf99d326312ca7be6447b0fe5fcJohn McCall/// Creates a Microsoft-family ABI. 583071cc7deffad608165b1ddd5263e8bf181861520Charles DavisCGCXXABI *CreateMicrosoftCXXABI(CodeGenModule &CGM); 58493d557bc1867b7d7b102f87290194b4be7932c92John McCall 5853a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis} 5863a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis} 5873a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis 5883a811f1f4286ee3fd0c563c1cfe623956f3caa24Charles Davis#endif 589