LLVM 19.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
26
27namespace llvm {
28 class BasicBlock;
29 class Instruction;
30 class Value;
31}
32
33namespace llvm {
34namespace objcarc {
35
36class ProvenanceAnalysis;
37
38/// \enum DependenceKind
39/// Defines different dependence kinds among various ARC constructs.
40///
41/// There are several kinds of dependence-like concepts in use here.
42///
47 RetainAutoreleaseDep, ///< Blocks objc_retainAutorelease.
48 RetainAutoreleaseRVDep ///< Blocks objc_retainAutoreleaseReturnValue.
49};
50
51/// Find dependent instructions. If there is exactly one dependent instruction,
52/// return it. Otherwise, return null.
54 BasicBlock *StartBB,
55 Instruction *StartInst,
56 ProvenanceAnalysis &PA);
57
58bool
59Depends(DependenceKind Flavor, Instruction *Inst, const Value *Arg,
60 ProvenanceAnalysis &PA);
61
62/// Test whether the given instruction can "use" the given pointer's object in a
63/// way that requires the reference count to be positive.
64bool CanUse(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA,
65 ARCInstKind Class);
66
67/// Test whether the given instruction can result in a reference count
68/// modification (positive or negative) for the pointer's object.
69bool CanAlterRefCount(const Instruction *Inst, const Value *Ptr,
70 ProvenanceAnalysis &PA, ARCInstKind Class);
71
72/// Returns true if we can not conservatively prove that Inst can not decrement
73/// the reference count of Ptr. Returns false if we can.
74bool CanDecrementRefCount(const Instruction *Inst, const Value *Ptr,
75 ProvenanceAnalysis &PA, ARCInstKind Class);
76
77static inline bool CanDecrementRefCount(const Instruction *Inst,
78 const Value *Ptr,
80 return CanDecrementRefCount(Inst, Ptr, PA, GetARCInstKind(Inst));
81}
82
83} // namespace objcarc
84} // namespace llvm
85
86#endif
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
LLVM Value Representation.
Definition: Value.h:74
This is similar to BasicAliasAnalysis, and it uses many of the same techniques, except it uses specia...
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
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...
DependenceKind
Defines different dependence kinds among various ARC constructs.
@ RetainAutoreleaseDep
Blocks objc_retainAutorelease.
@ RetainAutoreleaseRVDep
Blocks objc_retainAutoreleaseReturnValue.
ARCInstKind
Equivalence classes of instructions in the ARC Model.
llvm::Instruction * findSingleDependency(DependenceKind Flavor, const Value *Arg, BasicBlock *StartBB, Instruction *StartInst, ProvenanceAnalysis &PA)
Find dependent instructions.
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.
bool CanDecrementRefCount(ARCInstKind Kind)
Returns false if conservatively we can prove that any instruction mapped to this kind can not decreme...
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...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18