ScalarEvolutionAliasAnalysis.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ScalarEvolutionAliasAnalysis.h - SCEV-based AA -----------*- 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 is the interface for a SCEV-based alias analysis.
  15. ///
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_ANALYSIS_SCALAREVOLUTIONALIASANALYSIS_H
  18. #define LLVM_ANALYSIS_SCALAREVOLUTIONALIASANALYSIS_H
  19. #include "llvm/Analysis/AliasAnalysis.h"
  20. #include "llvm/Pass.h"
  21. namespace llvm {
  22. class Function;
  23. class ScalarEvolution;
  24. class SCEV;
  25. /// A simple alias analysis implementation that uses ScalarEvolution to answer
  26. /// queries.
  27. class SCEVAAResult : public AAResultBase {
  28. ScalarEvolution &SE;
  29. public:
  30. explicit SCEVAAResult(ScalarEvolution &SE) : SE(SE) {}
  31. SCEVAAResult(SCEVAAResult &&Arg) : AAResultBase(std::move(Arg)), SE(Arg.SE) {}
  32. AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
  33. AAQueryInfo &AAQI, const Instruction *CtxI);
  34. bool invalidate(Function &F, const PreservedAnalyses &PA,
  35. FunctionAnalysisManager::Invalidator &Inv);
  36. private:
  37. Value *GetBaseValue(const SCEV *S);
  38. };
  39. /// Analysis pass providing a never-invalidated alias analysis result.
  40. class SCEVAA : public AnalysisInfoMixin<SCEVAA> {
  41. friend AnalysisInfoMixin<SCEVAA>;
  42. static AnalysisKey Key;
  43. public:
  44. typedef SCEVAAResult Result;
  45. SCEVAAResult run(Function &F, FunctionAnalysisManager &AM);
  46. };
  47. /// Legacy wrapper pass to provide the SCEVAAResult object.
  48. class SCEVAAWrapperPass : public FunctionPass {
  49. std::unique_ptr<SCEVAAResult> Result;
  50. public:
  51. static char ID;
  52. SCEVAAWrapperPass();
  53. SCEVAAResult &getResult() { return *Result; }
  54. const SCEVAAResult &getResult() const { return *Result; }
  55. bool runOnFunction(Function &F) override;
  56. void getAnalysisUsage(AnalysisUsage &AU) const override;
  57. };
  58. /// Creates an instance of \c SCEVAAWrapperPass.
  59. FunctionPass *createSCEVAAWrapperPass();
  60. }
  61. #endif
  62. #ifdef __GNUC__
  63. #pragma GCC diagnostic pop
  64. #endif