2013-07-11 02:49:00 +08:00
|
|
|
//===- DependencyAnalysis.h - ObjC ARC Optimization ---*- C++ -*-----------===//
|
2013-01-29 11:03:03 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-01-29 11:03:03 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
///
|
|
|
|
/// This file declares special dependency analysis routines used in Objective C
|
|
|
|
/// ARC Optimizations.
|
|
|
|
///
|
|
|
|
/// WARNING: This file knows about certain library functions. It recognizes them
|
|
|
|
/// by name, and hardwires knowledge of their semantics.
|
|
|
|
///
|
|
|
|
/// WARNING: This file knows about how certain Objective-C library functions are
|
|
|
|
/// used. Naive LLVM IR transformations which would otherwise be
|
|
|
|
/// behavior-preserving may break these assumptions.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
|
|
|
|
#define LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
|
2013-01-29 11:03:03 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2016-01-28 02:03:37 +08:00
|
|
|
#include "llvm/Analysis/ObjCARCInstKind.h"
|
2013-01-29 11:03:03 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class BasicBlock;
|
|
|
|
class Instruction;
|
|
|
|
class Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace objcarc {
|
|
|
|
|
|
|
|
class ProvenanceAnalysis;
|
|
|
|
|
|
|
|
/// \enum DependenceKind
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Defines different dependence kinds among various ARC constructs.
|
2013-01-29 11:03:03 +08:00
|
|
|
///
|
|
|
|
/// There are several kinds of dependence-like concepts in use here.
|
|
|
|
///
|
|
|
|
enum DependenceKind {
|
|
|
|
NeedsPositiveRetainCount,
|
|
|
|
AutoreleasePoolBoundary,
|
|
|
|
CanChangeRetainCount,
|
|
|
|
RetainAutoreleaseDep, ///< Blocks objc_retainAutorelease.
|
|
|
|
RetainAutoreleaseRVDep, ///< Blocks objc_retainAutoreleaseReturnValue.
|
|
|
|
RetainRVDep ///< Blocks objc_retainAutoreleasedReturnValue.
|
|
|
|
};
|
|
|
|
|
|
|
|
void FindDependencies(DependenceKind Flavor,
|
|
|
|
const Value *Arg,
|
|
|
|
BasicBlock *StartBB, Instruction *StartInst,
|
2014-08-21 13:55:13 +08:00
|
|
|
SmallPtrSetImpl<Instruction *> &DependingInstructions,
|
|
|
|
SmallPtrSetImpl<const BasicBlock *> &Visited,
|
2013-01-29 11:03:03 +08:00
|
|
|
ProvenanceAnalysis &PA);
|
|
|
|
|
|
|
|
bool
|
|
|
|
Depends(DependenceKind Flavor, Instruction *Inst, const Value *Arg,
|
|
|
|
ProvenanceAnalysis &PA);
|
|
|
|
|
|
|
|
/// Test whether the given instruction can "use" the given pointer's object in a
|
|
|
|
/// way that requires the reference count to be positive.
|
2015-02-20 03:51:32 +08:00
|
|
|
bool CanUse(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA,
|
|
|
|
ARCInstKind Class);
|
2013-01-29 11:03:03 +08:00
|
|
|
|
|
|
|
/// Test whether the given instruction can result in a reference count
|
|
|
|
/// modification (positive or negative) for the pointer's object.
|
2015-02-20 03:51:32 +08:00
|
|
|
bool CanAlterRefCount(const Instruction *Inst, const Value *Ptr,
|
|
|
|
ProvenanceAnalysis &PA, ARCInstKind Class);
|
2013-01-29 11:03:03 +08:00
|
|
|
|
2015-02-20 08:02:45 +08:00
|
|
|
/// Returns true if we can not conservatively prove that Inst can not decrement
|
|
|
|
/// the reference count of Ptr. Returns false if we can.
|
|
|
|
bool CanDecrementRefCount(const Instruction *Inst, const Value *Ptr,
|
|
|
|
ProvenanceAnalysis &PA, ARCInstKind Class);
|
|
|
|
|
2015-02-20 08:02:49 +08:00
|
|
|
static inline bool CanDecrementRefCount(const Instruction *Inst,
|
|
|
|
const Value *Ptr,
|
|
|
|
ProvenanceAnalysis &PA) {
|
|
|
|
return CanDecrementRefCount(Inst, Ptr, PA, GetARCInstKind(Inst));
|
|
|
|
}
|
|
|
|
|
2013-01-29 11:03:03 +08:00
|
|
|
} // namespace objcarc
|
|
|
|
} // namespace llvm
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#endif
|