clang API Documentation

Public Member Functions | Protected Member Functions | Protected Attributes
clang::CodeGen::CGCXXABI Class Reference

Implements C++ ABI-specific code generation functions. More...

#include <CGCXXABI.h>

Collaboration diagram for clang::CodeGen::CGCXXABI:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual ~CGCXXABI ()
MangleContextgetMangleContext ()
 Gets the mangle context.
virtual llvm::Type * ConvertMemberPointerType (const MemberPointerType *MPT)
virtual llvm::ValueEmitLoadOfMemberFunctionPointer (CodeGenFunction &CGF, llvm::Value *&This, llvm::Value *MemPtr, const MemberPointerType *MPT)
virtual llvm::ValueEmitMemberDataPointerAddress (CodeGenFunction &CGF, llvm::Value *Base, llvm::Value *MemPtr, const MemberPointerType *MPT)
 Calculate an l-value from an object and a data member pointer.
virtual llvm::ValueEmitMemberPointerConversion (CodeGenFunction &CGF, const CastExpr *E, llvm::Value *Src)
virtual llvm::Constant * EmitMemberPointerConversion (const CastExpr *E, llvm::Constant *Src)
virtual bool isZeroInitializable (const MemberPointerType *MPT)
virtual llvm::Constant * EmitNullMemberPointer (const MemberPointerType *MPT)
 Create a null member pointer of the given type.
virtual llvm::Constant * EmitMemberPointer (const CXXMethodDecl *MD)
 Create a member pointer for the given method.
virtual llvm::Constant * EmitMemberDataPointer (const MemberPointerType *MPT, CharUnits offset)
 Create a member pointer for the given field.
virtual llvm::Constant * EmitMemberPointer (const APValue &MP, QualType MPT)
 Create a member pointer for the given member pointer constant.
virtual llvm::ValueEmitMemberPointerComparison (CodeGenFunction &CGF, llvm::Value *L, llvm::Value *R, const MemberPointerType *MPT, bool Inequality)
 Emit a comparison between two member pointers. Returns an i1.
virtual llvm::ValueEmitMemberPointerIsNotNull (CodeGenFunction &CGF, llvm::Value *MemPtr, const MemberPointerType *MPT)
 Determine if a member pointer is non-null. Returns an i1.
virtual void BuildConstructorSignature (const CXXConstructorDecl *Ctor, CXXCtorType T, CanQualType &ResTy, SmallVectorImpl< CanQualType > &ArgTys)=0
virtual void BuildDestructorSignature (const CXXDestructorDecl *Dtor, CXXDtorType T, CanQualType &ResTy, SmallVectorImpl< CanQualType > &ArgTys)=0
virtual void BuildInstanceFunctionParams (CodeGenFunction &CGF, QualType &ResTy, FunctionArgList &Params)=0
virtual void EmitInstanceFunctionProlog (CodeGenFunction &CGF)=0
 Emit the ABI-specific prolog for the function.
virtual void EmitReturnFromThunk (CodeGenFunction &CGF, RValue RV, QualType ResultType)
virtual CharUnits GetArrayCookieSize (const CXXNewExpr *expr)
virtual llvm::ValueInitializeArrayCookie (CodeGenFunction &CGF, llvm::Value *NewPtr, llvm::Value *NumElements, const CXXNewExpr *expr, QualType ElementType)
virtual void ReadArrayCookie (CodeGenFunction &CGF, llvm::Value *Ptr, const CXXDeleteExpr *expr, QualType ElementType, llvm::Value *&NumElements, llvm::Value *&AllocPtr, CharUnits &CookieSize)
virtual void EmitGuardedInit (CodeGenFunction &CGF, const VarDecl &D, llvm::GlobalVariable *DeclPtr, bool PerformInit)
virtual void registerGlobalDtor (CodeGenFunction &CGF, llvm::Constant *dtor, llvm::Constant *addr)

Protected Member Functions

 CGCXXABI (CodeGenModule &CGM)
ImplicitParamDecl *& getThisDecl (CodeGenFunction &CGF)
llvm::Value *& getThisValue (CodeGenFunction &CGF)
ImplicitParamDecl *& getVTTDecl (CodeGenFunction &CGF)
llvm::Value *& getVTTValue (CodeGenFunction &CGF)
void BuildThisParam (CodeGenFunction &CGF, FunctionArgList &Params)
 Build a parameter variable suitable for 'this'.
void EmitThisParam (CodeGenFunction &CGF)
ASTContextgetContext () const
virtual bool requiresArrayCookie (const CXXDeleteExpr *E, QualType eltType)
virtual bool requiresArrayCookie (const CXXNewExpr *E)
llvm::Constant * getMemberPointerAdjustment (const CastExpr *E)
virtual CharUnits getArrayCookieSizeImpl (QualType elementType)
virtual llvm::ValuereadArrayCookieImpl (CodeGenFunction &IGF, llvm::Value *ptr, CharUnits cookieSize)

Protected Attributes

CodeGenModuleCGM
OwningPtr< MangleContextMangleCtx

Detailed Description

Implements C++ ABI-specific code generation functions.

Definition at line 42 of file CGCXXABI.h.


Constructor & Destructor Documentation

clang::CodeGen::CGCXXABI::CGCXXABI ( CodeGenModule CGM) [inline, protected]

Definition at line 47 of file CGCXXABI.h.

CGCXXABI::~CGCXXABI ( ) [virtual]

Definition at line 20 of file CGCXXABI.cpp.


Member Function Documentation

virtual void clang::CodeGen::CGCXXABI::BuildConstructorSignature ( const CXXConstructorDecl Ctor,
CXXCtorType  T,
CanQualType ResTy,
SmallVectorImpl< CanQualType > &  ArgTys 
) [pure virtual]

Build the signature of the given constructor variant by adding any required parameters. For convenience, ResTy has been initialized to 'void', and ArgTys has been initialized with the type of 'this' (although this may be changed by the ABI) and will have the formal parameters added to it afterwards.

If there are ever any ABIs where the implicit parameters are intermixed with the formal parameters, we can address those then.

Referenced by clang::CodeGen::CodeGenTypes::arrangeCXXConstructorDeclaration().

virtual void clang::CodeGen::CGCXXABI::BuildDestructorSignature ( const CXXDestructorDecl Dtor,
CXXDtorType  T,
CanQualType ResTy,
SmallVectorImpl< CanQualType > &  ArgTys 
) [pure virtual]

Build the signature of the given destructor variant by adding any required parameters. For convenience, ResTy has been initialized to 'void' and ArgTys has been initialized with the type of 'this' (although this may be changed by the ABI).

Referenced by clang::CodeGen::CodeGenTypes::arrangeCXXDestructor().

virtual void clang::CodeGen::CGCXXABI::BuildInstanceFunctionParams ( CodeGenFunction CGF,
QualType ResTy,
FunctionArgList Params 
) [pure virtual]

Build the ABI-specific portion of the parameter list for a function. This generally involves a 'this' parameter and possibly some extra data for constructors and destructors.

ABIs may also choose to override the return type, which has been initialized with the formal return type of the function.

Referenced by clang::CodeGen::CodeGenFunction::GenerateCode(), and clang::CodeGen::CodeGenFunction::GenerateThunk().

void CGCXXABI::BuildThisParam ( CodeGenFunction CGF,
FunctionArgList Params 
) [protected]
llvm::Type * CGCXXABI::ConvertMemberPointerType ( const MemberPointerType MPT) [virtual]
void CGCXXABI::EmitGuardedInit ( CodeGenFunction CGF,
const VarDecl D,
llvm::GlobalVariable *  DeclPtr,
bool  PerformInit 
) [virtual]

Emits the guarded initializer and destructor setup for the given variable, given that it couldn't be emitted as a constant. If PerformInit is false, the initialization has been folded to a constant and should not be performed.

The variable may be:

  • a static local variable
  • a static data member of a class template instantiation

Definition at line 217 of file CGCXXABI.cpp.

References ErrorUnsupportedABI().

Referenced by clang::CodeGen::CodeGenFunction::EmitCXXGuardedInit().

virtual void clang::CodeGen::CGCXXABI::EmitInstanceFunctionProlog ( CodeGenFunction CGF) [pure virtual]

Emit the ABI-specific prolog for the function.

Referenced by clang::CodeGen::CodeGenFunction::GenerateThunk(), and clang::CodeGen::CodeGenFunction::StartFunction().

llvm::Value * CGCXXABI::EmitLoadOfMemberFunctionPointer ( CodeGenFunction CGF,
llvm::Value *&  This,
llvm::Value MemPtr,
const MemberPointerType MPT 
) [virtual]
llvm::Constant * CGCXXABI::EmitMemberDataPointer ( const MemberPointerType MPT,
CharUnits  offset 
) [virtual]

Create a member pointer for the given field.

Definition at line 107 of file CGCXXABI.cpp.

References CGM, and GetBogusMemberPointer().

Referenced by clang::CodeGen::CodeGenModule::getMemberPointerConstant().

llvm::Value * CGCXXABI::EmitMemberDataPointerAddress ( CodeGenFunction CGF,
llvm::Value Base,
llvm::Value MemPtr,
const MemberPointerType MPT 
) [virtual]

Calculate an l-value from an object and a data member pointer.

Definition at line 57 of file CGCXXABI.cpp.

References clang::CodeGen::CodeGenFunction::ConvertType(), ErrorUnsupportedABI(), and clang::MemberPointerType::getPointeeType().

Referenced by clang::CodeGen::CodeGenFunction::EmitPointerToDataMemberBinaryExpr().

llvm::Constant * CGCXXABI::EmitMemberPointer ( const CXXMethodDecl MD) [virtual]
llvm::Constant * CGCXXABI::EmitMemberPointer ( const APValue MP,
QualType  MPT 
) [virtual]

Create a member pointer for the given member pointer constant.

Definition at line 112 of file CGCXXABI.cpp.

References CGM, and GetBogusMemberPointer().

llvm::Value * CGCXXABI::EmitMemberPointerComparison ( CodeGenFunction CGF,
llvm::Value L,
llvm::Value R,
const MemberPointerType MPT,
bool  Inequality 
) [virtual]

Emit a comparison between two member pointers. Returns an i1.

Definition at line 79 of file CGCXXABI.cpp.

References clang::CodeGen::CodeGenFunction::Builder, and ErrorUnsupportedABI().

llvm::Value * CGCXXABI::EmitMemberPointerConversion ( CodeGenFunction CGF,
const CastExpr E,
llvm::Value Src 
) [virtual]

Perform a derived-to-base, base-to-derived, or bitcast member pointer conversion.

Definition at line 66 of file CGCXXABI.cpp.

References CGM, ErrorUnsupportedABI(), GetBogusMemberPointer(), and clang::Expr::getType().

llvm::Constant * CGCXXABI::EmitMemberPointerConversion ( const CastExpr E,
llvm::Constant *  Src 
) [virtual]

Perform a derived-to-base, base-to-derived, or bitcast member pointer conversion on a constant value.

Definition at line 73 of file CGCXXABI.cpp.

References CGM, GetBogusMemberPointer(), and clang::Expr::getType().

llvm::Value * CGCXXABI::EmitMemberPointerIsNotNull ( CodeGenFunction CGF,
llvm::Value MemPtr,
const MemberPointerType MPT 
) [virtual]

Determine if a member pointer is non-null. Returns an i1.

Definition at line 89 of file CGCXXABI.cpp.

References clang::CodeGen::CodeGenFunction::Builder, and ErrorUnsupportedABI().

Referenced by clang::CodeGen::CodeGenFunction::EvaluateExprAsBool().

llvm::Constant * CGCXXABI::EmitNullMemberPointer ( const MemberPointerType MPT) [virtual]

Create a null member pointer of the given type.

Definition at line 97 of file CGCXXABI.cpp.

References CGM, and GetBogusMemberPointer().

Referenced by clang::CodeGen::CodeGenModule::EmitNullConstant().

void CGCXXABI::EmitReturnFromThunk ( CodeGenFunction CGF,
RValue  RV,
QualType  ResultType 
) [virtual]

Definition at line 142 of file CGCXXABI.cpp.

Referenced by clang::CodeGen::CodeGenFunction::GenerateThunk().

void CGCXXABI::EmitThisParam ( CodeGenFunction CGF) [protected]

Perform prolog initialization of the parameter variable suitable for 'this' emitted by BuildThisParam.

Initialize the 'this' slot.

Definition at line 134 of file CGCXXABI.cpp.

References clang::CodeGen::CodeGenFunction::Builder, clang::CodeGen::CodeGenFunction::GetAddrOfLocalVar(), getThisDecl(), and getThisValue().

CharUnits CGCXXABI::GetArrayCookieSize ( const CXXNewExpr expr) [virtual]

Returns the extra size required in order to store the array cookie for the given type. May return 0 to indicate that no array cookie is required.

Several cases are filtered out before this method is called:

  • non-array allocations never need a cookie
  • calls to ::operator new(size_t, void*) never need a cookie
Parameters:
ElementType- the allocated type of the expression, i.e. the pointee type of the expression result type

Definition at line 147 of file CGCXXABI.cpp.

References clang::CXXNewExpr::getAllocatedType(), getArrayCookieSizeImpl(), requiresArrayCookie(), and clang::CharUnits::Zero().

Referenced by CalculateCookiePadding().

CharUnits CGCXXABI::getArrayCookieSizeImpl ( QualType  elementType) [protected, virtual]

Returns the extra size required in order to store the array cookie for the given type. Assumes that an array cookie is required.

Definition at line 153 of file CGCXXABI.cpp.

References clang::CharUnits::Zero().

Referenced by GetArrayCookieSize(), and ReadArrayCookie().

ASTContext& clang::CodeGen::CGCXXABI::getContext ( ) const [inline, protected]

Definition at line 72 of file CGCXXABI.h.

References CGM, and clang::CodeGen::CodeGenModule::getContext().

MangleContext& clang::CodeGen::CGCXXABI::getMangleContext ( ) [inline]
llvm::Constant * CGCXXABI::getMemberPointerAdjustment ( const CastExpr E) [protected]

A utility method for computing the offset required for the given base-to-derived or derived-to-base member-pointer conversion. Does not handle virtual conversions (in case we ever fully support an ABI that allows this). Returns null if no adjustment is required.

Returns the adjustment, in bytes, required for the given member-pointer operation. Returns null if no adjustment is required.

Definition at line 234 of file CGCXXABI.cpp.

References CGM, clang::CK_BaseToDerivedMemberPointer, clang::CK_DerivedToBaseMemberPointer, clang::Type::getAsCXXRecordDecl(), clang::CastExpr::getCastKind(), clang::CodeGen::CodeGenModule::GetNonVirtualBaseClassOffset(), clang::CastExpr::getSubExpr(), clang::Expr::getType(), clang::CastExpr::path_begin(), and clang::CastExpr::path_end().

ImplicitParamDecl*& clang::CodeGen::CGCXXABI::getThisDecl ( CodeGenFunction CGF) [inline, protected]

Definition at line 51 of file CGCXXABI.h.

Referenced by BuildThisParam(), and EmitThisParam().

llvm::Value*& clang::CodeGen::CGCXXABI::getThisValue ( CodeGenFunction CGF) [inline, protected]

Definition at line 54 of file CGCXXABI.h.

Referenced by EmitThisParam().

ImplicitParamDecl*& clang::CodeGen::CGCXXABI::getVTTDecl ( CodeGenFunction CGF) [inline, protected]

Definition at line 58 of file CGCXXABI.h.

llvm::Value*& clang::CodeGen::CGCXXABI::getVTTValue ( CodeGenFunction CGF) [inline, protected]

Definition at line 61 of file CGCXXABI.h.

llvm::Value * CGCXXABI::InitializeArrayCookie ( CodeGenFunction CGF,
llvm::Value NewPtr,
llvm::Value NumElements,
const CXXNewExpr expr,
QualType  ElementType 
) [virtual]

Initialize the array cookie for the given allocation.

Parameters:
NewPtr- a char* which is the presumed-non-null return value of the allocation function
NumElements- the computed number of elements, potentially collapsed from the multidimensional array case; always a size_t
ElementType- the base element allocated type, i.e. the allocated type after stripping all array types

Definition at line 158 of file CGCXXABI.cpp.

References ErrorUnsupportedABI().

Referenced by clang::CodeGen::CodeGenFunction::EmitCXXNewExpr().

bool CGCXXABI::isZeroInitializable ( const MemberPointerType MPT) [virtual]

Return true if the given member pointer can be zero-initialized (in the C++ sense) with an LLVM zeroinitializer.

Definition at line 116 of file CGCXXABI.cpp.

Referenced by clang::CodeGen::CodeGenTypes::isZeroInitializable().

void CGCXXABI::ReadArrayCookie ( CodeGenFunction CGF,
llvm::Value Ptr,
const CXXDeleteExpr expr,
QualType  ElementType,
llvm::Value *&  NumElements,
llvm::Value *&  AllocPtr,
CharUnits CookieSize 
) [virtual]

Reads the array cookie associated with the given pointer, if it has one.

Parameters:
Ptr- a pointer to the first element in the array
ElementType- the base element type of elements of the array
NumElements- an out parameter which will be initialized with the number of elements allocated, or zero if there is no cookie
AllocPtr- an out parameter which will be initialized with a char* pointing to the address returned by the allocation function
CookieSize- an out parameter which will be initialized with the size of the cookie, or zero if there is no cookie

Definition at line 187 of file CGCXXABI.cpp.

References clang::CodeGen::CodeGenFunction::Builder, getArrayCookieSizeImpl(), clang::CharUnits::getQuantity(), clang::CodeGen::CodeGenTypeCache::Int8Ty, readArrayCookieImpl(), requiresArrayCookie(), and clang::CharUnits::Zero().

Referenced by EmitArrayDelete().

llvm::Value * CGCXXABI::readArrayCookieImpl ( CodeGenFunction IGF,
llvm::Value ptr,
CharUnits  cookieSize 
) [protected, virtual]

Reads the array cookie for an allocation which is known to have one. This is called by the standard implementation of ReadArrayCookie.

Parameters:
ptr- a pointer to the allocation made for an array, as a char*
cookieSize- the computed cookie size of an array Other parameters are as above.
Returns:
a size_t

Definition at line 210 of file CGCXXABI.cpp.

References ErrorUnsupportedABI(), and clang::CodeGen::CodeGenTypeCache::SizeTy.

Referenced by ReadArrayCookie().

void CGCXXABI::registerGlobalDtor ( CodeGenFunction CGF,
llvm::Constant *  dtor,
llvm::Constant *  addr 
) [virtual]

Emit code to force the execution of a destructor during global teardown. The default implementation of this uses atexit.

Parameters:
dtor- a function taking a single pointer argument
addr- a pointer to pass to the destructor function.

Definition at line 224 of file CGCXXABI.cpp.

References clang::CodeGen::CodeGenFunction::registerGlobalDtorWithAtExit().

Referenced by EmitDeclDestroy(), and clang::CodeGen::CodeGenFunction::EmitReferenceBindingToExpr().

bool CGCXXABI::requiresArrayCookie ( const CXXDeleteExpr E,
QualType  eltType 
) [protected, virtual]
bool CGCXXABI::requiresArrayCookie ( const CXXNewExpr E) [protected, virtual]

Member Data Documentation

Definition at line 45 of file CGCXXABI.h.

Referenced by getMangleContext().


The documentation for this class was generated from the following files: