DependencyAnalysis.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
  22. #define LLVM_LIB_TRANSFORMS_OBJCARC_DEPENDENCYANALYSIS_H
  23. #include "llvm/ADT/SmallPtrSet.h"
  24. #include "llvm/Analysis/ObjCARCInstKind.h"
  25. namespace llvm {
  26. class BasicBlock;
  27. class Instruction;
  28. class Value;
  29. }
  30. namespace llvm {
  31. namespace objcarc {
  32. class ProvenanceAnalysis;
  33. /// \enum DependenceKind
  34. /// Defines different dependence kinds among various ARC constructs.
  35. ///
  36. /// There are several kinds of dependence-like concepts in use here.
  37. ///
  38. enum DependenceKind {
  39. NeedsPositiveRetainCount,
  40. AutoreleasePoolBoundary,
  41. CanChangeRetainCount,
  42. RetainAutoreleaseDep, ///< Blocks objc_retainAutorelease.
  43. RetainAutoreleaseRVDep, ///< Blocks objc_retainAutoreleaseReturnValue.
  44. RetainRVDep ///< Blocks objc_retainAutoreleasedReturnValue.
  45. };
  46. /// Find dependent instructions. If there is exactly one dependent instruction,
  47. /// return it. Otherwise, return null.
  48. llvm::Instruction *findSingleDependency(DependenceKind Flavor, const Value *Arg,
  49. BasicBlock *StartBB,
  50. Instruction *StartInst,
  51. ProvenanceAnalysis &PA);
  52. bool
  53. Depends(DependenceKind Flavor, Instruction *Inst, const Value *Arg,
  54. ProvenanceAnalysis &PA);
  55. /// Test whether the given instruction can "use" the given pointer's object in a
  56. /// way that requires the reference count to be positive.
  57. bool CanUse(const Instruction *Inst, const Value *Ptr, ProvenanceAnalysis &PA,
  58. ARCInstKind Class);
  59. /// Test whether the given instruction can result in a reference count
  60. /// modification (positive or negative) for the pointer's object.
  61. bool CanAlterRefCount(const Instruction *Inst, const Value *Ptr,
  62. ProvenanceAnalysis &PA, ARCInstKind Class);
  63. /// Returns true if we can not conservatively prove that Inst can not decrement
  64. /// the reference count of Ptr. Returns false if we can.
  65. bool CanDecrementRefCount(const Instruction *Inst, const Value *Ptr,
  66. ProvenanceAnalysis &PA, ARCInstKind Class);
  67. static inline bool CanDecrementRefCount(const Instruction *Inst,
  68. const Value *Ptr,
  69. ProvenanceAnalysis &PA) {
  70. return CanDecrementRefCount(Inst, Ptr, PA, GetARCInstKind(Inst));
  71. }
  72. } // namespace objcarc
  73. } // namespace llvm
  74. #endif