ProvenanceAnalysis.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //===- ProvenanceAnalysis.h - ObjC ARC Optimization ---*- C++ -*-----------===//
  2. //
  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 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. namespace llvm {
  28. class Value;
  29. class AliasAnalysis;
  30. class DataLayout;
  31. class PHINode;
  32. class SelectInst;
  33. }
  34. namespace llvm {
  35. namespace objcarc {
  36. /// \brief This is similar to BasicAliasAnalysis, and it uses many of the same
  37. /// techniques, except it uses special ObjC-specific reasoning about pointer
  38. /// relationships.
  39. ///
  40. /// In this context ``Provenance'' is defined as the history of an object's
  41. /// ownership. Thus ``Provenance Analysis'' is defined by using the notion of
  42. /// an ``independent provenance source'' of a pointer to determine whether or
  43. /// not two pointers have the same provenance source and thus could
  44. /// potentially be related.
  45. class ProvenanceAnalysis {
  46. AliasAnalysis *AA;
  47. typedef std::pair<const Value *, const Value *> ValuePairTy;
  48. typedef DenseMap<ValuePairTy, bool> CachedResultsTy;
  49. CachedResultsTy CachedResults;
  50. bool relatedCheck(const Value *A, const Value *B, const DataLayout &DL);
  51. bool relatedSelect(const SelectInst *A, const Value *B);
  52. bool relatedPHI(const PHINode *A, const Value *B);
  53. void operator=(const ProvenanceAnalysis &) = delete;
  54. ProvenanceAnalysis(const ProvenanceAnalysis &) = delete;
  55. public:
  56. ProvenanceAnalysis() {}
  57. void setAA(AliasAnalysis *aa) { AA = aa; }
  58. AliasAnalysis *getAA() const { return AA; }
  59. bool related(const Value *A, const Value *B, const DataLayout &DL);
  60. void clear() {
  61. CachedResults.clear();
  62. }
  63. };
  64. } // end namespace objcarc
  65. } // end namespace llvm
  66. #endif