ScopedNoAliasAA.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ScopedNoAliasAA.h - Scoped No-Alias 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. //
  14. /// \file
  15. /// This is the interface for a metadata-based scoped no-alias analysis.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_ANALYSIS_SCOPEDNOALIASAA_H
  19. #define LLVM_ANALYSIS_SCOPEDNOALIASAA_H
  20. #include "llvm/Analysis/AliasAnalysis.h"
  21. #include "llvm/IR/PassManager.h"
  22. #include "llvm/Pass.h"
  23. #include <memory>
  24. namespace llvm {
  25. class Function;
  26. class MDNode;
  27. class MemoryLocation;
  28. /// A simple AA result which uses scoped-noalias metadata to answer queries.
  29. class ScopedNoAliasAAResult : public AAResultBase {
  30. public:
  31. /// Handle invalidation events from the new pass manager.
  32. ///
  33. /// By definition, this result is stateless and so remains valid.
  34. bool invalidate(Function &, const PreservedAnalyses &,
  35. FunctionAnalysisManager::Invalidator &) {
  36. return false;
  37. }
  38. AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
  39. AAQueryInfo &AAQI, const Instruction *CtxI);
  40. ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
  41. AAQueryInfo &AAQI);
  42. ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
  43. AAQueryInfo &AAQI);
  44. private:
  45. bool mayAliasInScopes(const MDNode *Scopes, const MDNode *NoAlias) const;
  46. };
  47. /// Analysis pass providing a never-invalidated alias analysis result.
  48. class ScopedNoAliasAA : public AnalysisInfoMixin<ScopedNoAliasAA> {
  49. friend AnalysisInfoMixin<ScopedNoAliasAA>;
  50. static AnalysisKey Key;
  51. public:
  52. using Result = ScopedNoAliasAAResult;
  53. ScopedNoAliasAAResult run(Function &F, FunctionAnalysisManager &AM);
  54. };
  55. /// Legacy wrapper pass to provide the ScopedNoAliasAAResult object.
  56. class ScopedNoAliasAAWrapperPass : public ImmutablePass {
  57. std::unique_ptr<ScopedNoAliasAAResult> Result;
  58. public:
  59. static char ID;
  60. ScopedNoAliasAAWrapperPass();
  61. ScopedNoAliasAAResult &getResult() { return *Result; }
  62. const ScopedNoAliasAAResult &getResult() const { return *Result; }
  63. bool doInitialization(Module &M) override;
  64. bool doFinalization(Module &M) override;
  65. void getAnalysisUsage(AnalysisUsage &AU) const override;
  66. };
  67. //===--------------------------------------------------------------------===//
  68. //
  69. // createScopedNoAliasAAWrapperPass - This pass implements metadata-based
  70. // scoped noalias analysis.
  71. //
  72. ImmutablePass *createScopedNoAliasAAWrapperPass();
  73. } // end namespace llvm
  74. #endif // LLVM_ANALYSIS_SCOPEDNOALIASAA_H
  75. #ifdef __GNUC__
  76. #pragma GCC diagnostic pop
  77. #endif