ProvenanceAnalysis.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //===- ProvenanceAnalysis.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. //
  9. /// \file
  10. ///
  11. /// This file declares a special form of Alias Analysis called ``Provenance
  12. /// Analysis''. The word ``provenance'' refers to the history of the ownership
  13. /// of an object. Thus ``Provenance Analysis'' is an analysis which attempts to
  14. /// use various techniques to determine if locally
  15. ///
  16. /// WARNING: This file knows about certain library functions. It recognizes them
  17. /// by name, and hardwires knowledge of their semantics.
  18. ///
  19. /// WARNING: This file knows about how certain Objective-C library functions are
  20. /// used. Naive LLVM IR transformations which would otherwise be
  21. /// behavior-preserving may break these assumptions.
  22. //
  23. //===----------------------------------------------------------------------===//
  24. #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
  25. #define LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H
  26. #include "llvm/ADT/DenseMap.h"
  27. #include "llvm/IR/ValueHandle.h"
  28. #include <utility>
  29. namespace llvm {
  30. class AAResults;
  31. class PHINode;
  32. class SelectInst;
  33. class Value;
  34. namespace objcarc {
  35. /// This is similar to BasicAliasAnalysis, and it uses many of the same
  36. /// techniques, except it uses special ObjC-specific reasoning about pointer
  37. /// relationships.
  38. ///
  39. /// In this context ``Provenance'' is defined as the history of an object's
  40. /// ownership. Thus ``Provenance Analysis'' is defined by using the notion of
  41. /// an ``independent provenance source'' of a pointer to determine whether or
  42. /// not two pointers have the same provenance source and thus could
  43. /// potentially be related.
  44. class ProvenanceAnalysis {
  45. AAResults *AA;
  46. using ValuePairTy = std::pair<const Value *, const Value *>;
  47. using CachedResultsTy = DenseMap<ValuePairTy, bool>;
  48. CachedResultsTy CachedResults;
  49. DenseMap<const Value *, std::pair<WeakVH, WeakTrackingVH>>
  50. UnderlyingObjCPtrCache;
  51. bool relatedCheck(const Value *A, const Value *B);
  52. bool relatedSelect(const SelectInst *A, const Value *B);
  53. bool relatedPHI(const PHINode *A, const Value *B);
  54. public:
  55. ProvenanceAnalysis() = default;
  56. ProvenanceAnalysis(const ProvenanceAnalysis &) = delete;
  57. ProvenanceAnalysis &operator=(const ProvenanceAnalysis &) = delete;
  58. void setAA(AAResults *aa) { AA = aa; }
  59. AAResults *getAA() const { return AA; }
  60. bool related(const Value *A, const Value *B);
  61. void clear() {
  62. CachedResults.clear();
  63. UnderlyingObjCPtrCache.clear();
  64. }
  65. };
  66. } // end namespace objcarc
  67. } // end namespace llvm
  68. #endif // LLVM_LIB_TRANSFORMS_OBJCARC_PROVENANCEANALYSIS_H