ScopedNoAliasAA.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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<ScopedNoAliasAAResult> {
  30. friend AAResultBase<ScopedNoAliasAAResult>;
  31. public:
  32. /// Handle invalidation events from the new pass manager.
  33. ///
  34. /// By definition, this result is stateless and so remains valid.
  35. bool invalidate(Function &, const PreservedAnalyses &,
  36. FunctionAnalysisManager::Invalidator &) {
  37. return false;
  38. }
  39. AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
  40. AAQueryInfo &AAQI);
  41. ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
  42. AAQueryInfo &AAQI);
  43. ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
  44. AAQueryInfo &AAQI);
  45. private:
  46. bool mayAliasInScopes(const MDNode *Scopes, const MDNode *NoAlias) const;
  47. };
  48. /// Analysis pass providing a never-invalidated alias analysis result.
  49. class ScopedNoAliasAA : public AnalysisInfoMixin<ScopedNoAliasAA> {
  50. friend AnalysisInfoMixin<ScopedNoAliasAA>;
  51. static AnalysisKey Key;
  52. public:
  53. using Result = ScopedNoAliasAAResult;
  54. ScopedNoAliasAAResult run(Function &F, FunctionAnalysisManager &AM);
  55. };
  56. /// Legacy wrapper pass to provide the ScopedNoAliasAAResult object.
  57. class ScopedNoAliasAAWrapperPass : public ImmutablePass {
  58. std::unique_ptr<ScopedNoAliasAAResult> Result;
  59. public:
  60. static char ID;
  61. ScopedNoAliasAAWrapperPass();
  62. ScopedNoAliasAAResult &getResult() { return *Result; }
  63. const ScopedNoAliasAAResult &getResult() const { return *Result; }
  64. bool doInitialization(Module &M) override;
  65. bool doFinalization(Module &M) override;
  66. void getAnalysisUsage(AnalysisUsage &AU) const override;
  67. };
  68. //===--------------------------------------------------------------------===//
  69. //
  70. // createScopedNoAliasAAWrapperPass - This pass implements metadata-based
  71. // scoped noalias analysis.
  72. //
  73. ImmutablePass *createScopedNoAliasAAWrapperPass();
  74. } // end namespace llvm
  75. #endif // LLVM_ANALYSIS_SCOPEDNOALIASAA_H
  76. #ifdef __GNUC__
  77. #pragma GCC diagnostic pop
  78. #endif