ScalarEvolutionAliasAnalysis.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/Analysis/ScalarEvolutionExpressions.h"
  21. #include "llvm/IR/Function.h"
  22. #include "llvm/IR/Module.h"
  23. #include "llvm/Pass.h"
  24. namespace llvm {
  25. /// A simple alias analysis implementation that uses ScalarEvolution to answer
  26. /// queries.
  27. class SCEVAAResult : public AAResultBase<SCEVAAResult> {
  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);
  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