10b57cec5SDimitry Andric //===- DependencyAnalysis.h - ObjC ARC Optimization ---*- C++ -*-----------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric /// \file
90b57cec5SDimitry Andric ///
100b57cec5SDimitry Andric /// This file declares special dependency analysis routines used in Objective C
110b57cec5SDimitry Andric /// ARC Optimizations.
120b57cec5SDimitry Andric ///
130b57cec5SDimitry Andric /// WARNING: This file knows about certain library functions. It recognizes them
140b57cec5SDimitry Andric /// by name, and hardwires knowledge of their semantics.
150b57cec5SDimitry Andric ///
160b57cec5SDimitry Andric /// WARNING: This file knows about how certain Objective-C library functions are
170b57cec5SDimitry Andric /// used. Naive LLVM IR transformations which would otherwise be
180b57cec5SDimitry Andric /// behavior-preserving may break these assumptions.
190b57cec5SDimitry Andric ///
200b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
210b57cec5SDimitry Andric
220b57cec5SDimitry Andric #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
230b57cec5SDimitry Andric #define LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
240b57cec5SDimitry Andric
250b57cec5SDimitry Andric #include "llvm/Analysis/ObjCARCInstKind.h"
260b57cec5SDimitry Andric
270b57cec5SDimitry Andric namespace llvm {
280b57cec5SDimitry Andric class BasicBlock;
290b57cec5SDimitry Andric class Instruction;
300b57cec5SDimitry Andric class Value;
310b57cec5SDimitry Andric }
320b57cec5SDimitry Andric
330b57cec5SDimitry Andric namespace llvm {
340b57cec5SDimitry Andric namespace objcarc {
350b57cec5SDimitry Andric
360b57cec5SDimitry Andric class ProvenanceAnalysis;
370b57cec5SDimitry Andric
380b57cec5SDimitry Andric /// \enum DependenceKind
390b57cec5SDimitry Andric /// Defines different dependence kinds among various ARC constructs.
400b57cec5SDimitry Andric ///
410b57cec5SDimitry Andric /// There are several kinds of dependence-like concepts in use here.
420b57cec5SDimitry Andric ///
430b57cec5SDimitry Andric enum DependenceKind {
440b57cec5SDimitry Andric NeedsPositiveRetainCount,
450b57cec5SDimitry Andric AutoreleasePoolBoundary,
460b57cec5SDimitry Andric CanChangeRetainCount,
470b57cec5SDimitry Andric RetainAutoreleaseDep, ///< Blocks objc_retainAutorelease.
48*04eeddc0SDimitry Andric RetainAutoreleaseRVDep ///< Blocks objc_retainAutoreleaseReturnValue.
490b57cec5SDimitry Andric };
500b57cec5SDimitry Andric
51e8d8bef9SDimitry Andric /// Find dependent instructions. If there is exactly one dependent instruction,
52e8d8bef9SDimitry Andric /// return it. Otherwise, return null.
53e8d8bef9SDimitry Andric llvm::Instruction *findSingleDependency(DependenceKind Flavor, const Value *Arg,
54e8d8bef9SDimitry Andric BasicBlock *StartBB,
55e8d8bef9SDimitry Andric Instruction *StartInst,
560b57cec5SDimitry Andric ProvenanceAnalysis &PA);
570b57cec5SDimitry Andric
580b57cec5SDimitry Andric bool
590b57cec5SDimitry Andric Depends(DependenceKind Flavor, Instruction *Inst, const Value *Arg,
600b57cec5SDimitry Andric ProvenanceAnalysis &PA);
610b57cec5SDimitry Andric
620b57cec5SDimitry Andric /// Test whether the given instruction can "use" the given pointer's object in a
630b57cec5SDimitry Andric /// way that requires the reference count to be positive.
640b57cec5SDimitry Andric bool CanUse(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA,
650b57cec5SDimitry Andric ARCInstKind Class);
660b57cec5SDimitry Andric
670b57cec5SDimitry Andric /// Test whether the given instruction can result in a reference count
680b57cec5SDimitry Andric /// modification (positive or negative) for the pointer's object.
690b57cec5SDimitry Andric bool CanAlterRefCount(const Instruction *Inst, const Value *Ptr,
700b57cec5SDimitry Andric ProvenanceAnalysis &PA, ARCInstKind Class);
710b57cec5SDimitry Andric
720b57cec5SDimitry Andric /// Returns true if we can not conservatively prove that Inst can not decrement
730b57cec5SDimitry Andric /// the reference count of Ptr. Returns false if we can.
740b57cec5SDimitry Andric bool CanDecrementRefCount(const Instruction *Inst, const Value *Ptr,
750b57cec5SDimitry Andric ProvenanceAnalysis &PA, ARCInstKind Class);
760b57cec5SDimitry Andric
CanDecrementRefCount(const Instruction * Inst,const Value * Ptr,ProvenanceAnalysis & PA)770b57cec5SDimitry Andric static inline bool CanDecrementRefCount(const Instruction *Inst,
780b57cec5SDimitry Andric const Value *Ptr,
790b57cec5SDimitry Andric ProvenanceAnalysis &PA) {
800b57cec5SDimitry Andric return CanDecrementRefCount(Inst, Ptr, PA, GetARCInstKind(Inst));
810b57cec5SDimitry Andric }
820b57cec5SDimitry Andric
830b57cec5SDimitry Andric } // namespace objcarc
840b57cec5SDimitry Andric } // namespace llvm
850b57cec5SDimitry Andric
860b57cec5SDimitry Andric #endif
87