blob: 0f13b02c806f2559a9eb52a444f19f5ba79a6e7c [file] [log] [blame]
Michael Gottesman6eb95dc2013-07-10 18:49:00 +00001//===- DependencyAnalysis.h - ObjC ARC Optimization ---*- C++ -*-----------===//
Michael Gottesman778138e2013-01-29 03:03:03 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9/// \file
10///
11/// This file declares special dependency analysis routines used in Objective C
12/// ARC Optimizations.
13///
14/// WARNING: This file knows about certain library functions. It recognizes them
15/// by name, and hardwires knowledge of their semantics.
16///
17/// WARNING: This file knows about how certain Objective-C library functions are
18/// used. Naive LLVM IR transformations which would otherwise be
19/// behavior-preserving may break these assumptions.
20///
21//===----------------------------------------------------------------------===//
22
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000023#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
24#define LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
Michael Gottesman778138e2013-01-29 03:03:03 +000025
26#include "llvm/ADT/SmallPtrSet.h"
Benjamin Kramer45275a42016-01-27 18:03:37 +000027#include "llvm/Analysis/ObjCARCInstKind.h"
Michael Gottesman778138e2013-01-29 03:03:03 +000028
29namespace llvm {
30 class BasicBlock;
31 class Instruction;
32 class Value;
33}
34
35namespace llvm {
36namespace objcarc {
37
38class ProvenanceAnalysis;
39
40/// \enum DependenceKind
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000041/// Defines different dependence kinds among various ARC constructs.
Michael Gottesman778138e2013-01-29 03:03:03 +000042///
43/// There are several kinds of dependence-like concepts in use here.
44///
45enum DependenceKind {
46 NeedsPositiveRetainCount,
47 AutoreleasePoolBoundary,
48 CanChangeRetainCount,
49 RetainAutoreleaseDep, ///< Blocks objc_retainAutorelease.
50 RetainAutoreleaseRVDep, ///< Blocks objc_retainAutoreleaseReturnValue.
51 RetainRVDep ///< Blocks objc_retainAutoreleasedReturnValue.
52};
53
54void FindDependencies(DependenceKind Flavor,
55 const Value *Arg,
56 BasicBlock *StartBB, Instruction *StartInst,
Craig Topper71b7b682014-08-21 05:55:13 +000057 SmallPtrSetImpl<Instruction *> &DependingInstructions,
58 SmallPtrSetImpl<const BasicBlock *> &Visited,
Michael Gottesman778138e2013-01-29 03:03:03 +000059 ProvenanceAnalysis &PA);
60
61bool
62Depends(DependenceKind Flavor, Instruction *Inst, const Value *Arg,
63 ProvenanceAnalysis &PA);
64
65/// Test whether the given instruction can "use" the given pointer's object in a
66/// way that requires the reference count to be positive.
Michael Gottesman6f729fa2015-02-19 19:51:32 +000067bool CanUse(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA,
68 ARCInstKind Class);
Michael Gottesman778138e2013-01-29 03:03:03 +000069
70/// Test whether the given instruction can result in a reference count
71/// modification (positive or negative) for the pointer's object.
Michael Gottesman6f729fa2015-02-19 19:51:32 +000072bool CanAlterRefCount(const Instruction *Inst, const Value *Ptr,
73 ProvenanceAnalysis &PA, ARCInstKind Class);
Michael Gottesman778138e2013-01-29 03:03:03 +000074
Michael Gottesman5ab64de2015-02-20 00:02:45 +000075/// Returns true if we can not conservatively prove that Inst can not decrement
76/// the reference count of Ptr. Returns false if we can.
77bool CanDecrementRefCount(const Instruction *Inst, const Value *Ptr,
78 ProvenanceAnalysis &PA, ARCInstKind Class);
79
Michael Gottesman0fc2acc2015-02-20 00:02:49 +000080static inline bool CanDecrementRefCount(const Instruction *Inst,
81 const Value *Ptr,
82 ProvenanceAnalysis &PA) {
83 return CanDecrementRefCount(Inst, Ptr, PA, GetARCInstKind(Inst));
84}
85
Michael Gottesman778138e2013-01-29 03:03:03 +000086} // namespace objcarc
87} // namespace llvm
88
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000089#endif