Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- ScalarEvolutionAliasAnalysis.h - SCEV-based AA -----------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// \file |
| 9 | /// This is the interface for a SCEV-based alias analysis. |
| 10 | /// |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_ANALYSIS_SCALAREVOLUTIONALIASANALYSIS_H |
| 14 | #define LLVM_ANALYSIS_SCALAREVOLUTIONALIASANALYSIS_H |
| 15 | |
| 16 | #include "llvm/Analysis/AliasAnalysis.h" |
| 17 | #include "llvm/Analysis/ScalarEvolutionExpressions.h" |
| 18 | #include "llvm/IR/Function.h" |
| 19 | #include "llvm/IR/Module.h" |
| 20 | #include "llvm/Pass.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | /// A simple alias analysis implementation that uses ScalarEvolution to answer |
| 25 | /// queries. |
| 26 | class SCEVAAResult : public AAResultBase<SCEVAAResult> { |
| 27 | ScalarEvolution &SE; |
| 28 | |
| 29 | public: |
| 30 | explicit SCEVAAResult(ScalarEvolution &SE) : AAResultBase(), SE(SE) {} |
| 31 | SCEVAAResult(SCEVAAResult &&Arg) : AAResultBase(std::move(Arg)), SE(Arg.SE) {} |
| 32 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 33 | AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, |
| 34 | AAQueryInfo &AAQI); |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 35 | |
| 36 | private: |
| 37 | Value *GetBaseValue(const SCEV *S); |
| 38 | }; |
| 39 | |
| 40 | /// Analysis pass providing a never-invalidated alias analysis result. |
| 41 | class SCEVAA : public AnalysisInfoMixin<SCEVAA> { |
| 42 | friend AnalysisInfoMixin<SCEVAA>; |
| 43 | static AnalysisKey Key; |
| 44 | |
| 45 | public: |
| 46 | typedef SCEVAAResult Result; |
| 47 | |
| 48 | SCEVAAResult run(Function &F, FunctionAnalysisManager &AM); |
| 49 | }; |
| 50 | |
| 51 | /// Legacy wrapper pass to provide the SCEVAAResult object. |
| 52 | class SCEVAAWrapperPass : public FunctionPass { |
| 53 | std::unique_ptr<SCEVAAResult> Result; |
| 54 | |
| 55 | public: |
| 56 | static char ID; |
| 57 | |
| 58 | SCEVAAWrapperPass(); |
| 59 | |
| 60 | SCEVAAResult &getResult() { return *Result; } |
| 61 | const SCEVAAResult &getResult() const { return *Result; } |
| 62 | |
| 63 | bool runOnFunction(Function &F) override; |
| 64 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 65 | }; |
| 66 | |
| 67 | /// Creates an instance of \c SCEVAAWrapperPass. |
| 68 | FunctionPass *createSCEVAAWrapperPass(); |
| 69 | |
| 70 | } |
| 71 | |
| 72 | #endif |