LLVM: lib/Transforms/ObjCARC/DependencyAnalysis.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

27

28using namespace llvm;

30

31#define DEBUG_TYPE "objc-arc-dependency"

32

33

34

38 switch (Class) {

43

44 return false;

45 default: break;

46 }

47

49

50

53 return false;

57 return true;

58 }

59 return false;

60 }

61

62

63 return true;

64}

65

70

72 return false;

73

74

76}

77

78

79

82

83

85 return false;

86

87

88

90

91

92

94 return false;

96

97 for (const Value *Op : CS->args())

99 return true;

100 return false;

102

103

105

106

108 }

109

110

114 return true;

115 }

116 return false;

117}

118

119

120

121bool

124

125 if (Inst == Arg)

126 return true;

127

128 switch (Flavor) {

131 switch (Class) {

135 return false;

136 default:

137 return CanUse(Inst, Arg, PA, Class);

138 }

139 }

140

143 switch (Class) {

146

147 return true;

148 default:

149

150 return false;

151 }

152 }

153

156 switch (Class) {

158

159 return true;

162 return false;

163 default:

165 }

166 }

167

172

173

174 return true;

177

179 default:

180

181 return false;

182 }

183

186 switch (Class) {

189

191 default:

192

193

195 }

196 }

197 }

198

200}

201

202

203

204

205

211

214 Worklist.push_back(std::make_pair(StartBB, StartPos));

215 do {

216 std::pair<BasicBlock *, BasicBlock::iterator> Pair =

218 BasicBlock *LocalStartBB = Pair.first;

221 for (;;) {

222 if (LocalStartPos == StartBBBegin) {

224

225 return false;

226

228 if (Visited.insert(PredBB).second)

229 Worklist.push_back(std::make_pair(PredBB, PredBB->end()));

230 break;

231 }

232

234 if (Depends(Flavor, Inst, Arg, PA)) {

235 DependingInsts.insert(Inst);

236 break;

237 }

238 }

239 } while (!Worklist.empty());

240

241

242

243

244 for (const BasicBlock *BB : Visited) {

245 if (BB == StartBB)

246 continue;

248 if (Succ != StartBB && !Visited.count(Succ))

249 return false;

250 }

251

252 return true;

253}

254

256 const Value *Arg,

261

262 if (findDependencies(Flavor, Arg, StartBB, StartInst, DependingInsts, PA) ||

263 DependingInsts.size() != 1)

264 return nullptr;

265 return *DependingInsts.begin();

266}

static bool findDependencies(DependenceKind Flavor, const Value *Arg, BasicBlock *StartBB, Instruction *StartInst, SmallPtrSetImpl< Instruction * > &DependingInsts, ProvenanceAnalysis &PA)

Walk up the CFG from StartPos (which is in StartBB) and find local and non-local dependencies on Arg.

Definition DependencyAnalysis.cpp:206

This file declares special dependency analysis routines used in Objective C ARC Optimizations.

This file provides various utilities for inspecting and working with the control flow graph in LLVM I...

This file declares a special form of Alias Analysis called Provenance / Analysis''.

bool related(const Value *A, const Value *B)

AAResults * getAA() const

LLVM_ABI MemoryEffects getMemoryEffects(const CallBase *Call)

Return the behavior of the given call site.

LLVM Basic Block Representation.

iterator begin()

Instruction iterator methods.

InstListType::iterator iterator

Instruction iterators...

This instruction compares its operands according to the predicate given to the constructor.

bool onlyAccessesArgPointees() const

Whether this function only (at most) accesses argument memory.

bool onlyReadsMemory() const

Whether this function only (at most) reads memory.

A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...

size_type count(ConstPtrType Ptr) const

count - Return 1 if the specified pointer is in the set, 0 otherwise.

std::pair< iterator, bool > insert(PtrType Ptr)

Inserts Ptr if and only if there is no element in the container equal to Ptr.

SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

An instruction for storing to memory.

A Use represents the edge between a Value definition and its users.

LLVM Value Representation.

self_iterator getIterator()

This file defines common definitions/declarations used by the ObjC ARC Optimizer.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

bool IsPotentialRetainableObjPtr(const Value *Op)

Test whether the given value is possible a retainable object pointer.

bool CanAlterRefCount(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)

Test whether the given instruction can result in a reference count modification (positive or negative...

Definition DependencyAnalysis.cpp:35

DependenceKind

Defines different dependence kinds among various ARC constructs.

@ RetainAutoreleaseDep

Blocks objc_retainAutorelease.

@ AutoreleasePoolBoundary

@ NeedsPositiveRetainCount

@ RetainAutoreleaseRVDep

Blocks objc_retainAutoreleaseReturnValue.

ARCInstKind

Equivalence classes of instructions in the ARC Model.

@ AutoreleasepoolPop

objc_autoreleasePoolPop

@ AutoreleasepoolPush

objc_autoreleasePoolPush

@ Autorelease

objc_autorelease

@ None

anything that is inert from an ARC perspective.

@ User

could "use" a pointer

@ RetainRV

objc_retainAutoreleasedReturnValue

@ AutoreleaseRV

objc_autoreleaseReturnValue

@ Call

could call objc_release

@ IntrinsicUser

llvm.objc.clang.arc.use

llvm::Instruction * findSingleDependency(DependenceKind Flavor, const Value *Arg, BasicBlock *StartBB, Instruction *StartInst, ProvenanceAnalysis &PA)

Find dependent instructions.

Definition DependencyAnalysis.cpp:255

ARCInstKind GetBasicARCInstKind(const Value *V)

Determine which objc runtime call instruction class V belongs to.

ARCInstKind GetARCInstKind(const Value *V)

Map V to its ARCInstKind equivalence class.

bool Depends(DependenceKind Flavor, Instruction *Inst, const Value *Arg, ProvenanceAnalysis &PA)

Test if there can be dependencies on Inst through Arg.

Definition DependencyAnalysis.cpp:122

bool CanInterruptRV(ARCInstKind Class)

Test whether the given instruction can autorelease any pointer or cause an autoreleasepool pop.

Value * GetArgRCIdentityRoot(Value *Inst)

Assuming the given instruction is one of the special calls such as objc_retain or objc_release,...

bool CanDecrementRefCount(ARCInstKind Kind)

Returns false if conservatively we can prove that any instruction mapped to this kind can not decreme...

const Value * GetUnderlyingObjCPtr(const Value *V)

This is a wrapper around getUnderlyingObject which also knows how to look through objc_retain and obj...

bool CanUse(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA, ARCInstKind Class)

Test whether the given instruction can "use" the given pointer's object in a way that requires the re...

Definition DependencyAnalysis.cpp:80

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

auto successors(const MachineBasicBlock *BB)

MemoryEffectsBase< IRMemLocation > MemoryEffects

Summary of how a function affects memory in the program.

DWARFExpression::Operation Op

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

auto predecessors(const MachineBasicBlock *BB)

bool pred_empty(const BasicBlock *BB)