clang 20.0.0git
Typedefs | Functions
CGObjC.cpp File Reference
#include "CGDebugInfo.h"
#include "CGObjCRuntime.h"
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "ConstantEmitter.h"
#include "TargetInfo.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/StmtObjC.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/CodeGen/CGFunctionInfo.h"
#include "clang/CodeGen/CodeGenABITypes.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Analysis/ObjCARCUtil.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/InlineAsm.h"
#include <optional>

Go to the source code of this file.

Typedefs

typedef llvm::PointerIntPair< llvm::Value *, 1, boolTryEmitResult
 
typedef llvm::function_ref< llvm::Value *(CodeGenFunction &CGF, llvm::Value *value)> ValueTransform
 

Functions

static TryEmitResult tryEmitARCRetainScalarExpr (CodeGenFunction &CGF, const Expr *e)
 
static RValue AdjustObjCObjectType (CodeGenFunction &CGF, QualType ExpT, RValue Result)
 Adjust the type of an Objective-C object that doesn't match up due to type erasure at various points, e.g., related result types or the use of parameterized classes.
 
static llvm::Constant * getNullForVariable (Address addr)
 Given the address of a variable of pointer type, find the correct null to store into it.
 
static bool shouldExtendReceiverForInnerPointerMessage (const ObjCMessageExpr *message)
 Decide whether to extend the lifetime of the receiver of a returns-inner-pointer message.
 
static const ExprfindWeakLValue (const Expr *E)
 Given an expression of ObjC pointer type, check whether it was immediately loaded from an ARC __weak l-value.
 
static std::optional< llvm::Value * > tryGenerateSpecializedMessageSend (CodeGenFunction &CGF, QualType ResultType, llvm::Value *Receiver, const CallArgList &Args, Selector Sel, const ObjCMethodDecl *method, bool isClassMessage)
 The ObjC runtime may provide entrypoints that are likely to be faster than an ordinary message send of the appropriate selector.
 
static void AppendFirstImpliedRuntimeProtocols (const ObjCProtocolDecl *PD, llvm::UniqueVector< const ObjCProtocolDecl * > &PDs)
 
static std::optional< llvm::Value * > tryEmitSpecializedAllocInit (CodeGenFunction &CGF, const ObjCMessageExpr *OME)
 Instead of '[[MyClass alloc] init]', try to generate 'objc_alloc_init(MyClass)'.
 
static llvm::ValueemitARCRetainLoadOfScalar (CodeGenFunction &CGF, LValue lvalue, QualType type)
 
static void emitStructGetterCall (CodeGenFunction &CGF, ObjCIvarDecl *ivar, bool isAtomic, bool hasStrong)
 emitStructGetterCall - Call the runtime function to load a property into the return value slot.
 
static bool hasUnalignedAtomics (llvm::Triple::ArchType arch)
 Determine whether the given architecture supports unaligned atomic accesses.
 
static CharUnits getMaxAtomicAccessSize (CodeGenModule &CGM, llvm::Triple::ArchType arch)
 Return the maximum size that permits atomic accesses for the given architecture.
 
static bool hasTrivialGetExpr (const ObjCPropertyImplDecl *propImpl)
 
static void emitCPPObjectAtomicGetterCall (CodeGenFunction &CGF, llvm::Value *returnAddr, ObjCIvarDecl *ivar, llvm::Constant *AtomicHelperFn)
 emitCPPObjectAtomicGetterCall - Call the runtime function to copy the ivar into the resturn slot.
 
static llvm::ValueemitCmdValueForGetterSetterBody (CodeGenFunction &CGF, ObjCMethodDecl *MD)
 
static void emitStructSetterCall (CodeGenFunction &CGF, ObjCMethodDecl *OMD, ObjCIvarDecl *ivar)
 emitStructSetterCall - Call the runtime function to store the value from the first formal parameter into the given ivar.
 
static void emitCPPObjectAtomicSetterCall (CodeGenFunction &CGF, ObjCMethodDecl *OMD, ObjCIvarDecl *ivar, llvm::Constant *AtomicHelperFn)
 emitCPPObjectAtomicSetterCall - Call the runtime function to store the value from the first formal parameter into the given ivar, using the Cpp API for atomic Cpp objects with non-trivial copy assignment.
 
static bool hasTrivialSetExpr (const ObjCPropertyImplDecl *PID)
 
static bool UseOptimizedSetter (CodeGenModule &CGM)
 
static void destroyARCStrongWithStore (CodeGenFunction &CGF, Address addr, QualType type)
 Like CodeGenFunction::destroyARCStrong, but do it with a call.
 
static void emitCXXDestructMethod (CodeGenFunction &CGF, ObjCImplementationDecl *impl)
 
static void setARCRuntimeFunctionLinkage (CodeGenModule &CGM, llvm::Value *RTF)
 
static void setARCRuntimeFunctionLinkage (CodeGenModule &CGM, llvm::FunctionCallee RTF)
 
static llvm::Function * getARCIntrinsic (llvm::Intrinsic::ID IntID, CodeGenModule &CGM)
 
static llvm::ValueemitARCValueOperation (CodeGenFunction &CGF, llvm::Value *value, llvm::Type *returnType, llvm::Function *&fn, llvm::Intrinsic::ID IntID, llvm::CallInst::TailCallKind tailKind=llvm::CallInst::TCK_None)
 Perform an operation having the signature i8* (i8*) where a null input causes a no-op and returns null.
 
static llvm::ValueemitARCLoadOperation (CodeGenFunction &CGF, Address addr, llvm::Function *&fn, llvm::Intrinsic::ID IntID)
 Perform an operation having the following signature: i8* (i8**)
 
static llvm::ValueemitARCStoreOperation (CodeGenFunction &CGF, Address addr, llvm::Value *value, llvm::Function *&fn, llvm::Intrinsic::ID IntID, bool ignored)
 Perform an operation having the following signature: i8* (i8**, i8*)
 
static void emitARCCopyOperation (CodeGenFunction &CGF, Address dst, Address src, llvm::Function *&fn, llvm::Intrinsic::ID IntID)
 Perform an operation having the following signature: void (i8**, i8**)
 
static llvm::ValueemitObjCValueOperation (CodeGenFunction &CGF, llvm::Value *value, llvm::Type *returnType, llvm::FunctionCallee &fn, StringRef fnName)
 Perform an operation having the signature i8* (i8*) where a null input causes a no-op and returns null.
 
static void emitAutoreleasedReturnValueMarker (CodeGenFunction &CGF)
 
static llvm::ValueemitOptimizedARCReturnCall (llvm::Value *value, bool IsRetainRV, CodeGenFunction &CGF)
 
static bool shouldRetainObjCLifetime (Qualifiers::ObjCLifetime lifetime)
 
static TryEmitResult tryEmitARCRetainLoadOfScalar (CodeGenFunction &CGF, LValue lvalue, QualType type)
 
static TryEmitResult tryEmitARCRetainLoadOfScalar (CodeGenFunction &CGF, const Expr *e)
 
static llvm::ValueemitARCOperationAfterCall (CodeGenFunction &CGF, llvm::Value *value, ValueTransform doAfterCall, ValueTransform doFallback)
 Insert code immediately after a call.
 
static llvm::ValueemitARCRetainCallResult (CodeGenFunction &CGF, const Expr *e)
 Given that the given expression is some sort of call (which does not return retained), emit a retain following it.
 
static llvm::ValueemitARCUnsafeClaimCallResult (CodeGenFunction &CGF, const Expr *e)
 Given that the given expression is some sort of call (which does not return retained), perform an unsafeClaim following it.
 
static bool shouldEmitSeparateBlockRetain (const Expr *e)
 Determine whether it might be important to emit a separate objc_retain_block on the result of the given expression, or whether it's okay to just emit it in a +1 context.
 
static llvm::ValueemitARCUnsafeUnretainedScalarExpr (CodeGenFunction &CGF, const Expr *e)
 
static unsigned getBaseMachOPlatformID (const llvm::Triple &TT)
 
static llvm::ValueemitIsPlatformVersionAtLeast (CodeGenFunction &CGF, const VersionTuple &Version)
 
static bool isFoundationNeededForDarwinAvailabilityCheck (const llvm::Triple &TT, const VersionTuple &TargetVersion)
 

Typedef Documentation

◆ TryEmitResult

typedef llvm::PointerIntPair<llvm::Value*,1,bool> TryEmitResult

Definition at line 36 of file CGObjC.cpp.

◆ ValueTransform

typedef llvm::function_ref<llvm::Value *(CodeGenFunction &CGF, llvm::Value *value)> ValueTransform

Definition at line 2956 of file CGObjC.cpp.

Function Documentation

◆ AdjustObjCObjectType()

static RValue AdjustObjCObjectType ( CodeGenFunction CGF,
QualType  ET,
RValue  Result 
)
static

Adjust the type of an Objective-C object that doesn't match up due to type erasure at various points, e.g., related result types or the use of parameterized classes.

Definition at line 273 of file CGObjC.cpp.

References clang::CodeGen::CodeGenFunction::Builder, clang::CodeGen::CodeGenFunction::ConvertType(), clang::CodeGen::RValue::get(), clang::Type::isObjCRetainableType(), and clang::Result.

◆ AppendFirstImpliedRuntimeProtocols()

static void AppendFirstImpliedRuntimeProtocols ( const ObjCProtocolDecl PD,
llvm::UniqueVector< const ObjCProtocolDecl * > &  PDs 
)
static

◆ destroyARCStrongWithStore()

static void destroyARCStrongWithStore ( CodeGenFunction CGF,
Address  addr,
QualType  type 
)
static

Like CodeGenFunction::destroyARCStrong, but do it with a call.

Definition at line 1665 of file CGObjC.cpp.

References clang::CodeGen::CodeGenFunction::EmitARCStoreStrongCall(), and getNullForVariable().

Referenced by emitCXXDestructMethod().

◆ emitARCCopyOperation()

static void emitARCCopyOperation ( CodeGenFunction CGF,
Address  dst,
Address  src,
llvm::Function *&  fn,
llvm::Intrinsic::ID  IntID 
)
static

◆ emitARCLoadOperation()

static llvm::Value * emitARCLoadOperation ( CodeGenFunction CGF,
Address  addr,
llvm::Function *&  fn,
llvm::Intrinsic::ID  IntID 
)
static

Perform an operation having the following signature: i8* (i8**)

Definition at line 2192 of file CGObjC.cpp.

References clang::CodeGen::CodeGenFunction::CGM, clang::CodeGen::CodeGenFunction::EmitNounwindRuntimeCall(), clang::CodeGen::Address::emitRawPointer(), and getARCIntrinsic().

◆ emitARCOperationAfterCall()

static llvm::Value * emitARCOperationAfterCall ( CodeGenFunction CGF,
llvm::Value value,
ValueTransform  doAfterCall,
ValueTransform  doFallback 
)
static

Insert code immediately after a call.

Definition at line 2962 of file CGObjC.cpp.

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

Referenced by emitARCOperationAfterCall(), emitARCRetainCallResult(), and emitARCUnsafeClaimCallResult().

◆ emitARCRetainCallResult()

static llvm::Value * emitARCRetainCallResult ( CodeGenFunction CGF,
const Expr e 
)
static

Given that the given expression is some sort of call (which does not return retained), emit a retain following it.

Definition at line 3018 of file CGObjC.cpp.

References emitARCOperationAfterCall(), clang::CodeGen::CodeGenFunction::EmitARCRetainAutoreleasedReturnValue(), clang::CodeGen::CodeGenFunction::EmitARCRetainNonBlock(), and clang::CodeGen::CodeGenFunction::EmitScalarExpr().

◆ emitARCRetainLoadOfScalar()

static llvm::Value * emitARCRetainLoadOfScalar ( CodeGenFunction CGF,
LValue  lvalue,
QualType  type 
)
static

◆ emitARCStoreOperation()

static llvm::Value * emitARCStoreOperation ( CodeGenFunction CGF,
Address  addr,
llvm::Value value,
llvm::Function *&  fn,
llvm::Intrinsic::ID  IntID,
bool  ignored 
)
static

◆ emitARCUnsafeClaimCallResult()

static llvm::Value * emitARCUnsafeClaimCallResult ( CodeGenFunction CGF,
const Expr e 
)
static

Given that the given expression is some sort of call (which does not return retained), perform an unsafeClaim following it.

Definition at line 3032 of file CGObjC.cpp.

References emitARCOperationAfterCall(), clang::CodeGen::CodeGenFunction::EmitARCUnsafeClaimAutoreleasedReturnValue(), and clang::CodeGen::CodeGenFunction::EmitScalarExpr().

◆ emitARCUnsafeUnretainedScalarExpr()

static llvm::Value * emitARCUnsafeUnretainedScalarExpr ( CodeGenFunction CGF,
const Expr e 
)
static

Definition at line 3564 of file CGObjC.cpp.

◆ emitARCValueOperation()

static llvm::Value * emitARCValueOperation ( CodeGenFunction CGF,
llvm::Value value,
llvm::Type returnType,
llvm::Function *&  fn,
llvm::Intrinsic::ID  IntID,
llvm::CallInst::TailCallKind  tailKind = llvm::CallInst::TCK_None 
)
static

Perform an operation having the signature i8* (i8*) where a null input causes a no-op and returns null.

Definition at line 2168 of file CGObjC.cpp.

References clang::CodeGen::CodeGenFunction::Builder, clang::CodeGen::CodeGenFunction::CGM, clang::CodeGen::CodeGenFunction::EmitNounwindRuntimeCall(), getARCIntrinsic(), and clang::CodeGen::CodeGenTypeCache::Int8PtrTy.

Referenced by emitOptimizedARCReturnCall().

◆ emitAutoreleasedReturnValueMarker()

static void emitAutoreleasedReturnValueMarker ( CodeGenFunction CGF)
static

◆ emitCmdValueForGetterSetterBody()

static llvm::Value * emitCmdValueForGetterSetterBody ( CodeGenFunction CGF,
ObjCMethodDecl MD 
)
static

◆ emitCPPObjectAtomicGetterCall()

static void emitCPPObjectAtomicGetterCall ( CodeGenFunction CGF,
llvm::Value returnAddr,
ObjCIvarDecl ivar,
llvm::Constant *  AtomicHelperFn 
)
static

◆ emitCPPObjectAtomicSetterCall()

static void emitCPPObjectAtomicSetterCall ( CodeGenFunction CGF,
ObjCMethodDecl OMD,
ObjCIvarDecl ivar,
llvm::Constant *  AtomicHelperFn 
)
static

◆ emitCXXDestructMethod()

static void emitCXXDestructMethod ( CodeGenFunction CGF,
ObjCImplementationDecl impl 
)
static

◆ emitIsPlatformVersionAtLeast()

static llvm::Value * emitIsPlatformVersionAtLeast ( CodeGenFunction CGF,
const VersionTuple &  Version 
)
static

◆ emitObjCValueOperation()

static llvm::Value * emitObjCValueOperation ( CodeGenFunction CGF,
llvm::Value value,
llvm::Type returnType,
llvm::FunctionCallee &  fn,
StringRef  fnName 
)
static

◆ emitOptimizedARCReturnCall()

static llvm::Value * emitOptimizedARCReturnCall ( llvm::Value value,
bool  IsRetainRV,
CodeGenFunction CGF 
)
static

◆ emitStructGetterCall()

static void emitStructGetterCall ( CodeGenFunction CGF,
ObjCIvarDecl ivar,
bool  isAtomic,
bool  hasStrong 
)
static

◆ emitStructSetterCall()

static void emitStructSetterCall ( CodeGenFunction CGF,
ObjCMethodDecl OMD,
ObjCIvarDecl ivar 
)
static

◆ findWeakLValue()

static const Expr * findWeakLValue ( const Expr E)
static

Given an expression of ObjC pointer type, check whether it was immediately loaded from an ARC __weak l-value.

Definition at line 350 of file CGObjC.cpp.

References E, clang::Expr::getType(), clang::Expr::IgnoreParens(), clang::Type::isObjCRetainableType(), and clang::Qualifiers::OCL_Weak.

◆ getARCIntrinsic()

static llvm::Function * getARCIntrinsic ( llvm::Intrinsic::ID  IntID,
CodeGenModule CGM 
)
static

◆ getBaseMachOPlatformID()

static unsigned getBaseMachOPlatformID ( const llvm::Triple &  TT)
static

Definition at line 3932 of file CGObjC.cpp.

Referenced by emitIsPlatformVersionAtLeast().

◆ getMaxAtomicAccessSize()

static CharUnits getMaxAtomicAccessSize ( CodeGenModule CGM,
llvm::Triple::ArchType  arch 
)
static

Return the maximum size that permits atomic accesses for the given architecture.

Definition at line 856 of file CGObjC.cpp.

References clang::CharUnits::fromQuantity(), and clang::CodeGen::CodeGenTypeCache::PointerSizeInBytes.

◆ getNullForVariable()

static llvm::Constant * getNullForVariable ( Address  addr)
static

Given the address of a variable of pointer type, find the correct null to store into it.

Definition at line 45 of file CGObjC.cpp.

References clang::CodeGen::Address::getElementType(), and clang::ast_matchers::type.

Referenced by destroyARCStrongWithStore(), and tryEmitARCRetainLoadOfScalar().

◆ hasTrivialGetExpr()

static bool hasTrivialGetExpr ( const ObjCPropertyImplDecl propImpl)
static

◆ hasTrivialSetExpr()

static bool hasTrivialSetExpr ( const ObjCPropertyImplDecl PID)
static

◆ hasUnalignedAtomics()

static bool hasUnalignedAtomics ( llvm::Triple::ArchType  arch)
static

Determine whether the given architecture supports unaligned atomic accesses.

They don't have to be fast, just faster than a function call and a mutex.

Definition at line 848 of file CGObjC.cpp.

◆ isFoundationNeededForDarwinAvailabilityCheck()

static bool isFoundationNeededForDarwinAvailabilityCheck ( const llvm::Triple &  TT,
const VersionTuple &  TargetVersion 
)
static

Definition at line 4013 of file CGObjC.cpp.

References clang::TargetVersion.

◆ setARCRuntimeFunctionLinkage() [1/2]

static void setARCRuntimeFunctionLinkage ( CodeGenModule CGM,
llvm::FunctionCallee  RTF 
)
static

Definition at line 2153 of file CGObjC.cpp.

References setARCRuntimeFunctionLinkage().

◆ setARCRuntimeFunctionLinkage() [2/2]

static void setARCRuntimeFunctionLinkage ( CodeGenModule CGM,
llvm::Value RTF 
)
static

◆ shouldEmitSeparateBlockRetain()

static bool shouldEmitSeparateBlockRetain ( const Expr e)
static

Determine whether it might be important to emit a separate objc_retain_block on the result of the given expression, or whether it's okay to just emit it in a +1 context.

Definition at line 3058 of file CGObjC.cpp.

References clang::cast(), clang::Expr::getType(), clang::Expr::IgnoreParens(), clang::Type::isBlockPointerType(), and shouldEmitSeparateBlockRetain().

Referenced by shouldEmitSeparateBlockRetain().

◆ shouldExtendReceiverForInnerPointerMessage()

static bool shouldExtendReceiverForInnerPointerMessage ( const ObjCMessageExpr message)
static

◆ shouldRetainObjCLifetime()

static bool shouldRetainObjCLifetime ( Qualifiers::ObjCLifetime  lifetime)
static

◆ tryEmitARCRetainLoadOfScalar() [1/2]

static TryEmitResult tryEmitARCRetainLoadOfScalar ( CodeGenFunction CGF,
const Expr e 
)
static

◆ tryEmitARCRetainLoadOfScalar() [2/2]

static TryEmitResult tryEmitARCRetainLoadOfScalar ( CodeGenFunction CGF,
LValue  lvalue,
QualType  type 
)
static

◆ tryEmitARCRetainScalarExpr()

static TryEmitResult tryEmitARCRetainScalarExpr ( CodeGenFunction CGF,
const Expr e 
)
static

Definition at line 3430 of file CGObjC.cpp.

◆ tryEmitSpecializedAllocInit()

static std::optional< llvm::Value * > tryEmitSpecializedAllocInit ( CodeGenFunction CGF,
const ObjCMessageExpr OME 
)
static

◆ tryGenerateSpecializedMessageSend()

static std::optional< llvm::Value * > tryGenerateSpecializedMessageSend ( CodeGenFunction CGF,
QualType  ResultType,
llvm::Value Receiver,
const CallArgList Args,
Selector  Sel,
const ObjCMethodDecl method,
bool  isClassMessage 
)
static

The ObjC runtime may provide entrypoints that are likely to be faster than an ordinary message send of the appropriate selector.

The entrypoints are guaranteed to be equivalent to just sending the corresponding message. If the entrypoint is implemented naively as just a message send, using it is a trade-off: it sacrifices a few cycles of overhead to save a small amount of code. However, it's possible for runtimes to detect and special-case classes that use "standard" behavior; if that's dynamically a large proportion of all objects, using the entrypoint will also be faster than using a message send.

If the runtime does support a required entrypoint, then this method will generate a call and return the resulting value. Otherwise it will return std::nullopt and the caller can generate a msgSend instead.

Definition at line 377 of file CGObjC.cpp.

References clang::CodeGen::ARCPreciseLifetime, clang::CodeGen::CodeGenFunction::CGM, clang::CodeGen::CodeGenFunction::ConvertType(), clang::CodeGen::CodeGenFunction::EmitObjCAlloc(), clang::CodeGen::CodeGenFunction::EmitObjCAllocWithZone(), clang::CodeGen::CodeGenFunction::EmitObjCAutorelease(), clang::CodeGen::CodeGenFunction::EmitObjCRelease(), clang::CodeGen::CodeGenFunction::EmitObjCRetainNonBlock(), clang::Selector::getMethodFamily(), clang::Selector::getNameForSlot(), clang::Selector::getNumArgs(), clang::Selector::isKeywordSelector(), clang::Type::isObjCObjectPointerType(), clang::Selector::isUnarySelector(), clang::Type::isVoidType(), clang::LangOptionsBase::NonGC, clang::OMF_alloc, clang::OMF_autorelease, clang::OMF_release, and clang::OMF_retain.

Referenced by clang::CodeGen::CGObjCRuntime::GeneratePossiblySpecializedMessageSend().

◆ UseOptimizedSetter()

static bool UseOptimizedSetter ( CodeGenModule CGM)
static