ObjCARCAliasAnalysis.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //===- ObjCARCAliasAnalysis.h - ObjC ARC Alias Analysis ---------*- 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. /// This file declares a simple ARC-aware AliasAnalysis using special knowledge
  10. /// of Objective C to enhance other optimization passes which rely on the Alias
  11. /// Analysis infrastructure.
  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_ANALYSIS_OBJCARCALIASANALYSIS_H
  22. #define LLVM_ANALYSIS_OBJCARCALIASANALYSIS_H
  23. #include "llvm/Analysis/AliasAnalysis.h"
  24. #include "llvm/Pass.h"
  25. namespace llvm {
  26. namespace objcarc {
  27. /// This is a simple alias analysis implementation that uses knowledge
  28. /// of ARC constructs to answer queries.
  29. ///
  30. /// TODO: This class could be generalized to know about other ObjC-specific
  31. /// tricks. Such as knowing that ivars in the non-fragile ABI are non-aliasing
  32. /// even though their offsets are dynamic.
  33. class ObjCARCAAResult : public AAResultBase<ObjCARCAAResult> {
  34. friend AAResultBase<ObjCARCAAResult>;
  35. const DataLayout &DL;
  36. public:
  37. explicit ObjCARCAAResult(const DataLayout &DL) : AAResultBase(), DL(DL) {}
  38. ObjCARCAAResult(ObjCARCAAResult &&Arg)
  39. : AAResultBase(std::move(Arg)), DL(Arg.DL) {}
  40. /// Handle invalidation events from the new pass manager.
  41. ///
  42. /// By definition, this result is stateless and so remains valid.
  43. bool invalidate(Function &, const PreservedAnalyses &,
  44. FunctionAnalysisManager::Invalidator &) {
  45. return false;
  46. }
  47. AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
  48. AAQueryInfo &AAQI);
  49. bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
  50. bool OrLocal);
  51. using AAResultBase::getModRefBehavior;
  52. FunctionModRefBehavior getModRefBehavior(const Function *F);
  53. using AAResultBase::getModRefInfo;
  54. ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
  55. AAQueryInfo &AAQI);
  56. };
  57. /// Analysis pass providing a never-invalidated alias analysis result.
  58. class ObjCARCAA : public AnalysisInfoMixin<ObjCARCAA> {
  59. friend AnalysisInfoMixin<ObjCARCAA>;
  60. static AnalysisKey Key;
  61. public:
  62. typedef ObjCARCAAResult Result;
  63. ObjCARCAAResult run(Function &F, FunctionAnalysisManager &AM);
  64. };
  65. /// Legacy wrapper pass to provide the ObjCARCAAResult object.
  66. class ObjCARCAAWrapperPass : public ImmutablePass {
  67. std::unique_ptr<ObjCARCAAResult> Result;
  68. public:
  69. static char ID;
  70. ObjCARCAAWrapperPass();
  71. ObjCARCAAResult &getResult() { return *Result; }
  72. const ObjCARCAAResult &getResult() const { return *Result; }
  73. bool doInitialization(Module &M) override;
  74. bool doFinalization(Module &M) override;
  75. void getAnalysisUsage(AnalysisUsage &AU) const override;
  76. };
  77. } // namespace objcarc
  78. } // namespace llvm
  79. #endif