LLVM  mainline
Namespaces | Defines | Functions | Variables
ObjCARCOpts.cpp File Reference
#include "ObjCARC.h"
#include "ARCRuntimeEntryPoints.h"
#include "BlotMapVector.h"
#include "DependencyAnalysis.h"
#include "ObjCARCAliasAnalysis.h"
#include "ProvenanceAnalysis.h"
#include "PtrState.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Include dependency graph for ObjCARCOpts.cpp:

Go to the source code of this file.

Namespaces

namespace  llvm
 

List of target independent CodeGen pass IDs.


Defines

#define DEBUG_TYPE   "objc-arc-opts"

Functions

static const ValueFindSingleUseIdentifiedObject (const Value *Arg)
 This is similar to GetRCIdentityRoot but it stops as soon as it finds a value with multiple uses.
static bool AreAnyUnderlyingObjectsAnAlloca (const Value *V, const DataLayout &DL)
 STATISTIC (NumNoops,"Number of no-op objc calls eliminated")
 STATISTIC (NumPartialNoops,"Number of partially no-op objc calls eliminated")
 STATISTIC (NumAutoreleases,"Number of autoreleases converted to releases")
 STATISTIC (NumRets,"Number of return value forwarding ""retain+autoreleases eliminated")
 STATISTIC (NumRRs,"Number of retain+release paths eliminated")
 STATISTIC (NumPeeps,"Number of calls peephole-optimized")
 STATISTIC (NumRetainsBeforeOpt,"Number of retains before optimization")
 STATISTIC (NumReleasesBeforeOpt,"Number of releases before optimization")
 STATISTIC (NumRetainsAfterOpt,"Number of retains after optimization")
 STATISTIC (NumReleasesAfterOpt,"Number of releases after optimization")
raw_ostreamllvm::operator<< (raw_ostream &OS, BBState &BBState) LLVM_ATTRIBUTE_UNUSED
 INITIALIZE_PASS_BEGIN (ObjCARCOpt,"objc-arc","ObjC ARC optimization", false, false) INITIALIZE_PASS_END(ObjCARCOpt
static void CheckForUseCFGHazard (const Sequence SuccSSeq, const bool SuccSRRIKnownSafe, TopDownPtrState &S, bool &SomeSuccHasSame, bool &AllSuccsHaveSame, bool &NotAllSeqEqualButKnownSafe, bool &ShouldContinue)
static void CheckForCanReleaseCFGHazard (const Sequence SuccSSeq, const bool SuccSRRIKnownSafe, TopDownPtrState &S, bool &SomeSuccHasSame, bool &AllSuccsHaveSame, bool &NotAllSeqEqualButKnownSafe)
static void ComputePostOrders (Function &F, SmallVectorImpl< BasicBlock * > &PostOrder, SmallVectorImpl< BasicBlock * > &ReverseCFGPostOrder, unsigned NoObjCARCExceptionsMDKind, DenseMap< const BasicBlock *, BBState > &BBStates)
static bool HasSafePathToPredecessorCall (const Value *Arg, Instruction *Retain, SmallPtrSetImpl< Instruction * > &DepInsts, SmallPtrSetImpl< const BasicBlock * > &Visited, ProvenanceAnalysis &PA)
static CallInstFindPredecessorRetainWithSafePath (const Value *Arg, BasicBlock *BB, Instruction *Autorelease, SmallPtrSetImpl< Instruction * > &DepInsts, SmallPtrSetImpl< const BasicBlock * > &Visited, ProvenanceAnalysis &PA)
static CallInstFindPredecessorAutoreleaseWithSafePath (const Value *Arg, BasicBlock *BB, ReturnInst *Ret, SmallPtrSetImpl< Instruction * > &DepInsts, SmallPtrSetImpl< const BasicBlock * > &V, ProvenanceAnalysis &PA)

Variables

objc arc
objc ObjC ARC optimization
objc ObjC ARC false

Detailed Description

This file defines ObjC ARC optimizations. ARC stands for Automatic Reference Counting and is a system for managing reference counts for objects in Objective C.

The optimizations performed include elimination of redundant, partially redundant, and inconsequential reference count operations, elimination of redundant weak pointer operations, and numerous minor simplifications.

WARNING: This file knows about certain library functions. It recognizes them by name, and hardwires knowledge of their semantics.

WARNING: This file knows about how certain Objective-C library functions are used. Naive LLVM IR transformations which would otherwise be behavior-preserving may break these assumptions.

Definition in file ObjCARCOpts.cpp.


Define Documentation

#define DEBUG_TYPE   "objc-arc-opts"

Definition at line 48 of file ObjCARCOpts.cpp.


Function Documentation

static void CheckForCanReleaseCFGHazard ( const Sequence  SuccSSeq,
const bool  SuccSRRIKnownSafe,
TopDownPtrState S,
bool SomeSuccHasSame,
bool AllSuccsHaveSame,
bool NotAllSeqEqualButKnownSafe 
) [static]

If we have a Top Down pointer in the S_CanRelease state, make sure that there are no CFG hazards by checking the states of various bottom up pointers.

Definition at line 970 of file ObjCARCOpts.cpp.

References llvm::objcarc::PtrState::IsKnownSafe(), llvm_unreachable, llvm::objcarc::S_CanRelease, llvm::objcarc::S_MovableRelease, llvm::objcarc::S_None, llvm::objcarc::S_Release, llvm::objcarc::S_Retain, llvm::objcarc::S_Stop, and llvm::objcarc::S_Use.

static void CheckForUseCFGHazard ( const Sequence  SuccSSeq,
const bool  SuccSRRIKnownSafe,
TopDownPtrState S,
bool SomeSuccHasSame,
bool AllSuccsHaveSame,
bool NotAllSeqEqualButKnownSafe,
bool ShouldContinue 
) [static]
static void ComputePostOrders ( Function F,
SmallVectorImpl< BasicBlock * > &  PostOrder,
SmallVectorImpl< BasicBlock * > &  ReverseCFGPostOrder,
unsigned  NoObjCARCExceptionsMDKind,
DenseMap< const BasicBlock *, BBState > &  BBStates 
) [static]

The visited set, for doing DFS walks.

Definition at line 1358 of file ObjCARCOpts.cpp.

static CallInst* FindPredecessorAutoreleaseWithSafePath ( const Value Arg,
BasicBlock BB,
ReturnInst Ret,
SmallPtrSetImpl< Instruction * > &  DepInsts,
SmallPtrSetImpl< const BasicBlock * > &  V,
ProvenanceAnalysis PA 
) [static]

Look for an ``autorelease'' instruction dependent on Arg such that there are no instructions dependent on Arg that need a positive ref count in between the autorelease and the ret.

Definition at line 2043 of file ObjCARCOpts.cpp.

References llvm::objcarc::Autorelease, llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::objcarc::FindDependencies(), llvm::objcarc::GetArgRCIdentityRoot(), llvm::objcarc::GetBasicARCInstKind(), llvm::objcarc::IsAutorelease(), llvm::objcarc::NeedsPositiveRetainCount, and llvm::SmallPtrSetImplBase::size().

static CallInst* FindPredecessorRetainWithSafePath ( const Value Arg,
BasicBlock BB,
Instruction Autorelease,
SmallPtrSetImpl< Instruction * > &  DepInsts,
SmallPtrSetImpl< const BasicBlock * > &  Visited,
ProvenanceAnalysis PA 
) [static]

Find a dependent retain that precedes the given autorelease for which there is nothing in between the two instructions that can affect the ref count of Arg.

Definition at line 2018 of file ObjCARCOpts.cpp.

References llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::objcarc::CanChangeRetainCount, llvm::objcarc::FindDependencies(), llvm::objcarc::GetArgRCIdentityRoot(), llvm::objcarc::GetBasicARCInstKind(), llvm::objcarc::IsRetain(), llvm::objcarc::Retain, and llvm::SmallPtrSetImplBase::size().

static bool HasSafePathToPredecessorCall ( const Value Arg,
Instruction Retain,
SmallPtrSetImpl< Instruction * > &  DepInsts,
SmallPtrSetImpl< const BasicBlock * > &  Visited,
ProvenanceAnalysis PA 
) [static]

Check if there is a dependent call earlier that does not have anything in between the Retain and the call that can affect the reference count of their shared pointer argument. Note that Retain need not be in BB.

Definition at line 1991 of file ObjCARCOpts.cpp.

References llvm::Call, llvm::objcarc::CallOrUser, llvm::objcarc::CanChangeRetainCount, llvm::objcarc::FindDependencies(), llvm::objcarc::GetBasicARCInstKind(), llvm::Instruction::getParent(), and llvm::objcarc::Retain.

INITIALIZE_PASS_BEGIN ( ObjCARCOpt  ,
"objc-arc ,
"ObjC ARC optimization ,
false  ,
false   
)
STATISTIC ( NumNoops  ,
"Number of no-op objc calls eliminated"   
)
STATISTIC ( NumPartialNoops  ,
"Number of partially no-op objc calls eliminated"   
)
STATISTIC ( NumAutoreleases  ,
"Number of autoreleases converted to releases"   
)
STATISTIC ( NumRets  ,
"Number of return value forwarding ""retain+autoreleases eliminated"   
)
STATISTIC ( NumRRs  ,
"Number of retain+release paths eliminated"   
)
STATISTIC ( NumPeeps  ,
"Number of calls peephole-optimized"   
)
STATISTIC ( NumRetainsBeforeOpt  ,
"Number of retains before optimization  
)
STATISTIC ( NumReleasesBeforeOpt  ,
"Number of releases before optimization  
)
STATISTIC ( NumRetainsAfterOpt  ,
"Number of retains after optimization  
)
STATISTIC ( NumReleasesAfterOpt  ,
"Number of releases after optimization  
)

Variable Documentation

objc arc

Definition at line 558 of file ObjCARCOpts.cpp.

objc ObjC ARC false

Definition at line 558 of file ObjCARCOpts.cpp.

objc ObjC ARC optimization

Definition at line 558 of file ObjCARCOpts.cpp.