ObjCARCAliasAnalysis.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ObjCARCAliasAnalysis.h - ObjC ARC Alias Analysis ---------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. /// \file
  14. /// This file declares a simple ARC-aware AliasAnalysis using special knowledge
  15. /// of Objective C to enhance other optimization passes which rely on the Alias
  16. /// Analysis infrastructure.
  17. ///
  18. /// WARNING: This file knows about certain library functions. It recognizes them
  19. /// by name, and hardwires knowledge of their semantics.
  20. ///
  21. /// WARNING: This file knows about how certain Objective-C library functions are
  22. /// used. Naive LLVM IR transformations which would otherwise be
  23. /// behavior-preserving may break these assumptions.
  24. ///
  25. //===----------------------------------------------------------------------===//
  26. #ifndef LLVM_ANALYSIS_OBJCARCALIASANALYSIS_H
  27. #define LLVM_ANALYSIS_OBJCARCALIASANALYSIS_H
  28. #include "llvm/Analysis/AliasAnalysis.h"
  29. #include "llvm/Pass.h"
  30. namespace llvm {
  31. namespace objcarc {
  32. /// This is a simple alias analysis implementation that uses knowledge
  33. /// of ARC constructs to answer queries.
  34. ///
  35. /// TODO: This class could be generalized to know about other ObjC-specific
  36. /// tricks. Such as knowing that ivars in the non-fragile ABI are non-aliasing
  37. /// even though their offsets are dynamic.
  38. class ObjCARCAAResult : public AAResultBase<ObjCARCAAResult> {
  39. friend AAResultBase<ObjCARCAAResult>;
  40. const DataLayout &DL;
  41. public:
  42. explicit ObjCARCAAResult(const DataLayout &DL) : AAResultBase(), DL(DL) {}
  43. ObjCARCAAResult(ObjCARCAAResult &&Arg)
  44. : AAResultBase(std::move(Arg)), DL(Arg.DL) {}
  45. /// Handle invalidation events from the new pass manager.
  46. ///
  47. /// By definition, this result is stateless and so remains valid.
  48. bool invalidate(Function &, const PreservedAnalyses &,
  49. FunctionAnalysisManager::Invalidator &) {
  50. return false;
  51. }
  52. AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
  53. AAQueryInfo &AAQI);
  54. bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI,
  55. bool OrLocal);
  56. using AAResultBase::getModRefBehavior;
  57. FunctionModRefBehavior getModRefBehavior(const Function *F);
  58. using AAResultBase::getModRefInfo;
  59. ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
  60. AAQueryInfo &AAQI);
  61. };
  62. /// Analysis pass providing a never-invalidated alias analysis result.
  63. class ObjCARCAA : public AnalysisInfoMixin<ObjCARCAA> {
  64. friend AnalysisInfoMixin<ObjCARCAA>;
  65. static AnalysisKey Key;
  66. public:
  67. typedef ObjCARCAAResult Result;
  68. ObjCARCAAResult run(Function &F, FunctionAnalysisManager &AM);
  69. };
  70. /// Legacy wrapper pass to provide the ObjCARCAAResult object.
  71. class ObjCARCAAWrapperPass : public ImmutablePass {
  72. std::unique_ptr<ObjCARCAAResult> Result;
  73. public:
  74. static char ID;
  75. ObjCARCAAWrapperPass();
  76. ObjCARCAAResult &getResult() { return *Result; }
  77. const ObjCARCAAResult &getResult() const { return *Result; }
  78. bool doInitialization(Module &M) override;
  79. bool doFinalization(Module &M) override;
  80. void getAnalysisUsage(AnalysisUsage &AU) const override;
  81. };
  82. } // namespace objcarc
  83. } // namespace llvm
  84. #endif
  85. #ifdef __GNUC__
  86. #pragma GCC diagnostic pop
  87. #endif