LLVM  13.0.0git
DependencyAnalysis.h
Go to the documentation of this file.
1 //===- DependencyAnalysis.h - ObjC ARC Optimization ---*- C++ -*-----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This file declares special dependency analysis routines used in Objective C
11 /// ARC Optimizations.
12 ///
13 /// WARNING: This file knows about certain library functions. It recognizes them
14 /// by name, and hardwires knowledge of their semantics.
15 ///
16 /// WARNING: This file knows about how certain Objective-C library functions are
17 /// used. Naive LLVM IR transformations which would otherwise be
18 /// behavior-preserving may break these assumptions.
19 ///
20 //===----------------------------------------------------------------------===//
21 
22 #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
23 #define LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
24 
25 #include "llvm/ADT/SmallPtrSet.h"
27 
28 namespace llvm {
29  class BasicBlock;
30  class Instruction;
31  class Value;
32 }
33 
34 namespace llvm {
35 namespace objcarc {
36 
37 class ProvenanceAnalysis;
38 
39 /// \enum DependenceKind
40 /// Defines different dependence kinds among various ARC constructs.
41 ///
42 /// There are several kinds of dependence-like concepts in use here.
43 ///
48  RetainAutoreleaseDep, ///< Blocks objc_retainAutorelease.
49  RetainAutoreleaseRVDep, ///< Blocks objc_retainAutoreleaseReturnValue.
50  RetainRVDep ///< Blocks objc_retainAutoreleasedReturnValue.
51 };
52 
53 /// Find dependent instructions. If there is exactly one dependent instruction,
54 /// return it. Otherwise, return null.
56  BasicBlock *StartBB,
57  Instruction *StartInst,
58  ProvenanceAnalysis &PA);
59 
60 bool
61 Depends(DependenceKind Flavor, Instruction *Inst, const Value *Arg,
62  ProvenanceAnalysis &PA);
63 
64 /// Test whether the given instruction can "use" the given pointer's object in a
65 /// way that requires the reference count to be positive.
66 bool CanUse(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA,
68 
69 /// Test whether the given instruction can result in a reference count
70 /// modification (positive or negative) for the pointer's object.
71 bool CanAlterRefCount(const Instruction *Inst, const Value *Ptr,
72  ProvenanceAnalysis &PA, ARCInstKind Class);
73 
74 /// Returns true if we can not conservatively prove that Inst can not decrement
75 /// the reference count of Ptr. Returns false if we can.
76 bool CanDecrementRefCount(const Instruction *Inst, const Value *Ptr,
77  ProvenanceAnalysis &PA, ARCInstKind Class);
78 
79 static inline bool CanDecrementRefCount(const Instruction *Inst,
80  const Value *Ptr,
81  ProvenanceAnalysis &PA) {
82  return CanDecrementRefCount(Inst, Ptr, PA, GetARCInstKind(Inst));
83 }
84 
85 } // namespace objcarc
86 } // namespace llvm
87 
88 #endif
llvm::objcarc::CanUse
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
llvm
Definition: AllocatorList.h:23
llvm::objcarc::NeedsPositiveRetainCount
@ NeedsPositiveRetainCount
Definition: DependencyAnalysis.h:45
llvm::objcarc::RetainAutoreleaseDep
@ RetainAutoreleaseDep
Blocks objc_retainAutorelease.
Definition: DependencyAnalysis.h:48
llvm::objcarc::RetainRVDep
@ RetainRVDep
Blocks objc_retainAutoreleasedReturnValue.
Definition: DependencyAnalysis.h:50
llvm::objcarc::ProvenanceAnalysis
This is similar to BasicAliasAnalysis, and it uses many of the same techniques, except it uses specia...
Definition: ProvenanceAnalysis.h:51
llvm::objcarc::GetARCInstKind
ARCInstKind GetARCInstKind(const Value *V)
Map V to its ARCInstKind equivalence class.
Definition: ObjCARCInstKind.cpp:213
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:58
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:206
llvm::Instruction
Definition: Instruction.h:45
llvm::objcarc::DependenceKind
DependenceKind
Definition: DependencyAnalysis.h:44
SmallPtrSet.h
llvm::objcarc::ARCInstKind
ARCInstKind
Definition: ObjCARCInstKind.h:28
ObjCARCInstKind.h
llvm::objcarc::Depends
bool Depends(DependenceKind Flavor, Instruction *Inst, const Value *Arg, ProvenanceAnalysis &PA)
Test if there can be dependencies on Inst through Arg.
Definition: DependencyAnalysis.cpp:124
llvm::objcarc::CanChangeRetainCount
@ CanChangeRetainCount
Definition: DependencyAnalysis.h:47
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:64
llvm::objcarc::RetainAutoreleaseRVDep
@ RetainAutoreleaseRVDep
Blocks objc_retainAutoreleaseReturnValue.
Definition: DependencyAnalysis.h:49
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::objcarc::findSingleDependency
llvm::Instruction * findSingleDependency(DependenceKind Flavor, const Value *Arg, BasicBlock *StartBB, Instruction *StartInst, ProvenanceAnalysis &PA)
Find dependent instructions.
Definition: DependencyAnalysis.cpp:263
llvm::objcarc::CanDecrementRefCount
bool CanDecrementRefCount(ARCInstKind Kind)
Returns false if conservatively we can prove that any instruction mapped to this kind can not decreme...
Definition: ObjCARCInstKind.cpp:668
llvm::tgtok::Class
@ Class
Definition: TGLexer.h:50
llvm::objcarc::CanAlterRefCount
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
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::objcarc::AutoreleasePoolBoundary
@ AutoreleasePoolBoundary
Definition: DependencyAnalysis.h:46