ObjCARCAliasAnalysis.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //===- ObjCARCAliasAnalysis.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. /// This file declares a simple ARC-aware AliasAnalysis using special knowledge
  11. /// of Objective C to enhance other optimization passes which rely on the Alias
  12. /// Analysis infrastructure.
  13. ///
  14. /// WARNING: This file knows about certain library functions. It recognizes them
  15. /// by name, and hardwires knowledge of their semantics.
  16. ///
  17. /// WARNING: This file knows about how certain Objective-C library functions are
  18. /// used. Naive LLVM IR transformations which would otherwise be
  19. /// behavior-preserving may break these assumptions.
  20. ///
  21. //===----------------------------------------------------------------------===//
  22. #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_OBJCARCALIASANALYSIS_H
  23. #define LLVM_LIB_TRANSFORMS_OBJCARC_OBJCARCALIASANALYSIS_H
  24. #include "llvm/Analysis/AliasAnalysis.h"
  25. #include "llvm/Pass.h"
  26. namespace llvm {
  27. namespace objcarc {
  28. /// \brief This is a simple alias analysis implementation that uses knowledge
  29. /// of ARC constructs to answer queries.
  30. ///
  31. /// TODO: This class could be generalized to know about other ObjC-specific
  32. /// tricks. Such as knowing that ivars in the non-fragile ABI are non-aliasing
  33. /// even though their offsets are dynamic.
  34. class ObjCARCAliasAnalysis : public ImmutablePass,
  35. public AliasAnalysis {
  36. public:
  37. static char ID; // Class identification, replacement for typeinfo
  38. ObjCARCAliasAnalysis() : ImmutablePass(ID) {
  39. initializeObjCARCAliasAnalysisPass(*PassRegistry::getPassRegistry());
  40. }
  41. private:
  42. bool doInitialization(Module &M) override;
  43. /// This method is used when a pass implements an analysis interface through
  44. /// multiple inheritance. If needed, it should override this to adjust the
  45. /// this pointer as needed for the specified pass info.
  46. void *getAdjustedAnalysisPointer(const void *PI) override {
  47. if (PI == &AliasAnalysis::ID)
  48. return static_cast<AliasAnalysis *>(this);
  49. return this;
  50. }
  51. void getAnalysisUsage(AnalysisUsage &AU) const override;
  52. AliasResult alias(const MemoryLocation &LocA,
  53. const MemoryLocation &LocB) override;
  54. bool pointsToConstantMemory(const MemoryLocation &Loc,
  55. bool OrLocal) override;
  56. ModRefBehavior getModRefBehavior(ImmutableCallSite CS) override;
  57. ModRefBehavior getModRefBehavior(const Function *F) override;
  58. ModRefResult getModRefInfo(ImmutableCallSite CS,
  59. const MemoryLocation &Loc) override;
  60. ModRefResult getModRefInfo(ImmutableCallSite CS1,
  61. ImmutableCallSite CS2) override;
  62. };
  63. } // namespace objcarc
  64. } // namespace llvm
  65. #endif