ObjCARCAliasAnalysis.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 {
  39. const DataLayout &DL;
  40. public:
  41. explicit ObjCARCAAResult(const DataLayout &DL) : DL(DL) {}
  42. ObjCARCAAResult(ObjCARCAAResult &&Arg)
  43. : AAResultBase(std::move(Arg)), DL(Arg.DL) {}
  44. /// Handle invalidation events from the new pass manager.
  45. ///
  46. /// By definition, this result is stateless and so remains valid.
  47. bool invalidate(Function &, const PreservedAnalyses &,
  48. FunctionAnalysisManager::Invalidator &) {
  49. return false;
  50. }
  51. AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
  52. AAQueryInfo &AAQI, const Instruction *CtxI);
  53. ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI,
  54. bool IgnoreLocals);
  55. using AAResultBase::getMemoryEffects;
  56. MemoryEffects getMemoryEffects(const Function *F);
  57. using AAResultBase::getModRefInfo;
  58. ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
  59. AAQueryInfo &AAQI);
  60. };
  61. /// Analysis pass providing a never-invalidated alias analysis result.
  62. class ObjCARCAA : public AnalysisInfoMixin<ObjCARCAA> {
  63. friend AnalysisInfoMixin<ObjCARCAA>;
  64. static AnalysisKey Key;
  65. public:
  66. typedef ObjCARCAAResult Result;
  67. ObjCARCAAResult run(Function &F, FunctionAnalysisManager &AM);
  68. };
  69. } // namespace objcarc
  70. } // namespace llvm
  71. #endif
  72. #ifdef __GNUC__
  73. #pragma GCC diagnostic pop
  74. #endif