LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions | Variables
ARC Optimization.

Macros

#define ARC_ANNOTATIONS
 
#define ANNOTATE_BOTTOMUP(inst, ptr, old, new)
 
#define ANNOTATE_TOPDOWN(inst, ptr, old, new)
 
#define ANNOTATE_BB(_states, _bb, _name, _type, _direction)
 
#define ANNOTATE_BOTTOMUP_BBSTART(_states, _basicblock)
 
#define ANNOTATE_BOTTOMUP_BBEND(_states, _basicblock)
 
#define ANNOTATE_TOPDOWN_BBSTART(_states, _basicblock)
 
#define ANNOTATE_TOPDOWN_BBEND(_states, _basicblock)
 

Functions

 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")
 
static Sequence MergeSeqs (Sequence A, Sequence B, bool TopDown)
 
static MDStringAppendMDNodeToSourcePtr (unsigned NodeId, Value *Ptr)
 
static std::string SequenceToString (Sequence A)
 
static MDStringSequenceToMDString (LLVMContext &Context, Sequence A)
 
static void AppendMDNodeToInstForPtr (unsigned NodeId, Instruction *Inst, Value *Ptr, MDString *PtrSourceMDNodeID, Sequence OldSeq, Sequence NewSeq)
 
static void GenerateARCBBEntranceAnnotation (const char *Name, BasicBlock *BB, Value *Ptr, Sequence Seq)
 
static void GenerateARCBBTerminatorAnnotation (const char *Name, BasicBlock *BB, Value *Ptr, Sequence Seq)
 
static void GenerateARCAnnotation (unsigned InstMDId, unsigned PtrMDId, Instruction *Inst, Value *Ptr, Sequence OldSeq, Sequence NewSeq)
 
 INITIALIZE_PASS_BEGIN (ObjCARCOpt,"objc-arc","ObjC ARC optimization", false, false) INITIALIZE_PASS_END(ObjCARCOpt
 
static void CheckForUseCFGHazard (const Sequence SuccSSeq, const bool SuccSRRIKnownSafe, PtrState &S, bool &SomeSuccHasSame, bool &AllSuccsHaveSame, bool &NotAllSeqEqualButKnownSafe, bool &ShouldContinue)
 
static void CheckForCanReleaseCFGHazard (const Sequence SuccSSeq, const bool SuccSRRIKnownSafe, PtrState &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, SmallPtrSet< Instruction *, 4 > &DepInsts, SmallPtrSet< const BasicBlock *, 4 > &Visited, ProvenanceAnalysis &PA)
 
static CallInstFindPredecessorRetainWithSafePath (const Value *Arg, BasicBlock *BB, Instruction *Autorelease, SmallPtrSet< Instruction *, 4 > &DepInsts, SmallPtrSet< const BasicBlock *, 4 > &Visited, ProvenanceAnalysis &PA)
 
static CallInstFindPredecessorAutoreleaseWithSafePath (const Value *Arg, BasicBlock *BB, ReturnInst *Ret, SmallPtrSet< Instruction *, 4 > &DepInsts, SmallPtrSet< const BasicBlock *, 4 > &V, ProvenanceAnalysis &PA)
 
Passllvm::createObjCARCOptPass ()
 

Variables

static cl::opt< boolEnableARCAnnotations ("enable-objc-arc-annotations", cl::init(false), cl::desc("Enable emission of arc data flow analysis ""annotations"))
 Enable/disable ARC sequence annotations. More...
 
static cl::opt< boolDisableCheckForCFGHazards ("disable-objc-arc-checkforcfghazards", cl::init(false), cl::desc("Disable check for cfg hazards when ""annotating"))
 
static cl::opt< std::string > ARCAnnotationTargetIdentifier ("objc-arc-annotation-target-identifier", cl::init(""), cl::desc("filter out all data flow annotations ""but those that apply to the given ""target llvm identifier."))
 
objc arc
 
objc ObjC ARC optimization
 
objc ObjC ARC false
 
static char ObjCARCOpt::ID = 0
 

Detailed Description

Macro Definition Documentation

#define ANNOTATE_BB (   _states,
  _bb,
  _name,
  _type,
  _direction 
)
Value:
do { \
for(BBState::ptr_const_iterator I = (_states)._direction##_ptr_begin(), \
E = (_states)._direction##_ptr_end(); I != E; ++I) { \
Value *Ptr = const_cast<Value*>(I->first); \
Sequence Seq = I->second.GetSeq(); \
GenerateARCBB ## _type ## Annotation(_name, (_bb), Ptr, Seq); \
} \
} \
} while (0)
Sequence
A sequence of states that a pointer may go through in which an objc_retain and objc_release are actua...
* if(!EatIfPresent(lltok::kw_thread_local)) return false
static cl::opt< bool > EnableARCAnnotations("enable-objc-arc-annotations", cl::init(false), cl::desc("Enable emission of arc data flow analysis ""annotations"))
Enable/disable ARC sequence annotations.
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
#define I(x, y, z)
Definition: MD5.cpp:54
LLVM Value Representation.
Definition: Value.h:66

Definition at line 1036 of file ObjCARCOpts.cpp.

#define ANNOTATE_BOTTOMUP (   inst,
  ptr,
  old,
  new 
)
Value:
GenerateARCAnnotation(ARCAnnotationBottomUpMDKind, \
ARCAnnotationProvenanceSourceMDKind, (inst), \
const_cast<Value*>(ptr), (old), (new))
static void GenerateARCAnnotation(unsigned InstMDId, unsigned PtrMDId, Instruction *Inst, Value *Ptr, Sequence OldSeq, Sequence NewSeq)

Use this macro to annotate a sequence state change when processing instructions bottom up,

Definition at line 1025 of file ObjCARCOpts.cpp.

#define ANNOTATE_BOTTOMUP_BBEND (   _states,
  _basicblock 
)
Value:
ANNOTATE_BB(_states, _basicblock, "llvm.arc.annotation.bottomup.bbend", \
Terminator, bottom_up)
#define ANNOTATE_BB(_states, _bb, _name, _type, _direction)

Definition at line 1051 of file ObjCARCOpts.cpp.

#define ANNOTATE_BOTTOMUP_BBSTART (   _states,
  _basicblock 
)
Value:
ANNOTATE_BB(_states, _basicblock, "llvm.arc.annotation.bottomup.bbstart", \
Entrance, bottom_up)
#define ANNOTATE_BB(_states, _bb, _name, _type, _direction)

Definition at line 1048 of file ObjCARCOpts.cpp.

#define ANNOTATE_TOPDOWN (   inst,
  ptr,
  old,
  new 
)
Value:
GenerateARCAnnotation(ARCAnnotationTopDownMDKind, \
ARCAnnotationProvenanceSourceMDKind, (inst), \
const_cast<Value*>(ptr), (old), (new))
static void GenerateARCAnnotation(unsigned InstMDId, unsigned PtrMDId, Instruction *Inst, Value *Ptr, Sequence OldSeq, Sequence NewSeq)

Use this macro to annotate a sequence state change when processing instructions top down.

Definition at line 1031 of file ObjCARCOpts.cpp.

#define ANNOTATE_TOPDOWN_BBEND (   _states,
  _basicblock 
)
Value:
ANNOTATE_BB(_states, _basicblock, "llvm.arc.annotation.topdown.bbend", \
Terminator, top_down)
#define ANNOTATE_BB(_states, _bb, _name, _type, _direction)

Definition at line 1057 of file ObjCARCOpts.cpp.

#define ANNOTATE_TOPDOWN_BBSTART (   _states,
  _basicblock 
)
Value:
ANNOTATE_BB(_states, _basicblock, "llvm.arc.annotation.topdown.bbstart", \
Entrance, top_down)
#define ANNOTATE_BB(_states, _bb, _name, _type, _direction)

Definition at line 1054 of file ObjCARCOpts.cpp.

#define ARC_ANNOTATIONS

Definition at line 793 of file ObjCARCOpts.cpp.

Function Documentation

static void AppendMDNodeToInstForPtr ( unsigned  NodeId,
Instruction Inst,
Value Ptr,
MDString PtrSourceMDNodeID,
Sequence  OldSeq,
Sequence  NewSeq 
)
static

A simple function to generate a MDNode which describes the change in state for Value *Ptr caused by Instruction *Inst.

Definition at line 880 of file ObjCARCOpts.cpp.

References llvm::MDNode::get(), llvm::Value::getContext(), SequenceToMDString(), and llvm::Instruction::setMetadata().

Referenced by GenerateARCAnnotation().

static MDString* AppendMDNodeToSourcePtr ( unsigned  NodeId,
Value Ptr 
)
static

This function appends a unique ARCAnnotationProvenanceSourceMDKind id to an instruction so that we can track backwards when post processing via the llvm arc annotation processor tool. If the function is an

Definition at line 822 of file ObjCARCOpts.cpp.

References llvm::MDString::get(), llvm::MDNode::get(), llvm::Value::getContext(), llvm::Value::getName(), llvm::MDNode::getNumOperands(), llvm::MDNode::getOperand(), and llvm::raw_string_ostream::str().

Referenced by GenerateARCAnnotation().

static void CheckForCanReleaseCFGHazard ( const Sequence  SuccSSeq,
const bool  SuccSRRIKnownSafe,
PtrState &  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 1597 of file ObjCARCOpts.cpp.

References llvm_unreachable.

static void CheckForUseCFGHazard ( const Sequence  SuccSSeq,
const bool  SuccSRRIKnownSafe,
PtrState &  S,
bool SomeSuccHasSame,
bool AllSuccsHaveSame,
bool NotAllSeqEqualButKnownSafe,
bool ShouldContinue 
)
static

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

Definition at line 1559 of file ObjCARCOpts.cpp.

References llvm_unreachable.

static void ComputePostOrders ( Function F,
SmallVectorImpl< BasicBlock * > &  PostOrder,
SmallVectorImpl< BasicBlock * > &  ReverseCFGPostOrder,
unsigned  NoObjCARCExceptionsMDKind,
DenseMap< const BasicBlock *, BBState > &  BBStates 
)
static
objc ObjC ARC false Pass * llvm::createObjCARCOptPass ( )

Definition at line 1186 of file ObjCARCOpts.cpp.

static CallInst* FindPredecessorAutoreleaseWithSafePath ( const Value Arg,
BasicBlock BB,
ReturnInst Ret,
SmallPtrSet< Instruction *, 4 > &  DepInsts,
SmallPtrSet< const BasicBlock *, 4 > &  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 2913 of file ObjCARCOpts.cpp.

References llvm::SmallPtrSet< PtrType, SmallSize >::begin(), llvm::objcarc::FindDependencies(), llvm::objcarc::GetBasicInstructionClass(), llvm::objcarc::GetObjCArg(), llvm::objcarc::IsAutorelease(), llvm::objcarc::NeedsPositiveRetainCount, and llvm::SmallPtrSetImpl::size().

static CallInst* FindPredecessorRetainWithSafePath ( const Value Arg,
BasicBlock BB,
Instruction Autorelease,
SmallPtrSet< Instruction *, 4 > &  DepInsts,
SmallPtrSet< const BasicBlock *, 4 > &  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 2886 of file ObjCARCOpts.cpp.

References llvm::SmallPtrSet< PtrType, SmallSize >::begin(), llvm::objcarc::CanChangeRetainCount, llvm::objcarc::FindDependencies(), llvm::objcarc::GetBasicInstructionClass(), llvm::objcarc::GetObjCArg(), llvm::objcarc::IsRetain(), and llvm::SmallPtrSetImpl::size().

static void GenerateARCAnnotation ( unsigned  InstMDId,
unsigned  PtrMDId,
Instruction Inst,
Value Ptr,
Sequence  OldSeq,
Sequence  NewSeq 
)
static

Adds a source annotation to pointer and a state change annotation to Inst referencing the source annotation and the old/new state of pointer.

Definition at line 985 of file ObjCARCOpts.cpp.

References AppendMDNodeToInstForPtr(), AppendMDNodeToSourcePtr(), ARCAnnotationTargetIdentifier, EnableARCAnnotations, llvm::StringRef::equals(), and llvm::Value::getName().

static void GenerateARCBBEntranceAnnotation ( const char *  Name,
BasicBlock BB,
Value Ptr,
Sequence  Seq 
)
static
static void GenerateARCBBTerminatorAnnotation ( const char *  Name,
BasicBlock BB,
Value Ptr,
Sequence  Seq 
)
static
static bool HasSafePathToPredecessorCall ( const Value Arg,
Instruction Retain,
SmallPtrSet< Instruction *, 4 > &  DepInsts,
SmallPtrSet< const BasicBlock *, 4 > &  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 2858 of file ObjCARCOpts.cpp.

References llvm::objcarc::CanChangeRetainCount, llvm::objcarc::FindDependencies(), llvm::objcarc::GetBasicInstructionClass(), llvm::Instruction::getParent(), llvm::objcarc::IC_Call, and llvm::objcarc::IC_CallOrUser.

INITIALIZE_PASS_BEGIN ( ObjCARCOpt  ,
"objc-arc ,
"ObjC ARC optimization ,
false  ,
false   
)
static Sequence MergeSeqs ( Sequence  A,
Sequence  B,
bool  TopDown 
)
static

Definition at line 312 of file ObjCARCOpts.cpp.

References llvm::ARM_PROC::A, and std::swap().

static MDString* SequenceToMDString ( LLVMContext Context,
Sequence  A 
)
static

Helper function to change a Sequence into a String object using our overload for raw_ostream so we only have printing code in one location.

Definition at line 873 of file ObjCARCOpts.cpp.

References llvm::MDString::get(), and SequenceToString().

Referenced by AppendMDNodeToInstForPtr().

static std::string SequenceToString ( Sequence  A)
static
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 1184 of file ObjCARCOpts.cpp.

cl::opt<std::string> ARCAnnotationTargetIdentifier("objc-arc-annotation-target-identifier", cl::init(""), cl::desc("filter out all data flow annotations ""but those that apply to the given ""target llvm identifier."))
static
cl::opt<bool> DisableCheckForCFGHazards("disable-objc-arc-checkforcfghazards", cl::init(false), cl::desc("Disable check for cfg hazards when ""annotating"))
static
cl::opt<bool> EnableARCAnnotations("enable-objc-arc-annotations", cl::init(false), cl::desc("Enable emission of arc data flow analysis ""annotations"))
static

Enable/disable ARC sequence annotations.

Referenced by GenerateARCAnnotation().

objc ObjC ARC false

Definition at line 1184 of file ObjCARCOpts.cpp.

char ObjCARCOpt::ID = 0
static

Definition at line 1172 of file ObjCARCOpts.cpp.

objc ObjC ARC optimization

Definition at line 1184 of file ObjCARCOpts.cpp.