9b83f8d347300e33f8acfdf36444d45ef758deb2
[oota-llvm.git] / include / llvm / Analysis / ScalarEvolutionAliasAnalysis.h
1 //===- ScalarEvolutionAliasAnalysis.h - SCEV-based AA -----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 /// This is the interface for a SCEV-based alias analysis.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_ANALYSIS_SCALAREVOLUTIONALIASANALYSIS_H
15 #define LLVM_ANALYSIS_SCALAREVOLUTIONALIASANALYSIS_H
16
17 #include "llvm/Analysis/AliasAnalysis.h"
18 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/Pass.h"
22
23 namespace llvm {
24
25 /// A simple alias analysis implementation that uses ScalarEvolution to answer
26 /// queries.
27 class ScalarEvolutionAliasAnalysis : public FunctionPass, public AliasAnalysis {
28   ScalarEvolution *SE;
29
30 public:
31   static char ID; // Class identification, replacement for typeinfo
32   ScalarEvolutionAliasAnalysis() : FunctionPass(ID), SE(nullptr) {
33     initializeScalarEvolutionAliasAnalysisPass(
34         *PassRegistry::getPassRegistry());
35   }
36
37   /// This method is used when a pass implements an analysis interface through
38   /// multiple inheritance.
39   ///
40   /// If needed, it should override this to adjust the this pointer as needed
41   /// for the specified pass info.
42   void *getAdjustedAnalysisPointer(AnalysisID PI) override {
43     if (PI == &AliasAnalysis::ID)
44       return (AliasAnalysis *)this;
45     return this;
46   }
47
48 private:
49   void getAnalysisUsage(AnalysisUsage &AU) const override;
50   bool runOnFunction(Function &F) override;
51   AliasResult alias(const MemoryLocation &LocA,
52                     const MemoryLocation &LocB) override;
53
54   Value *GetBaseValue(const SCEV *S);
55 };
56
57 /// Creates an instance of \c ScalarEvolutionAliasAnalysis.
58 FunctionPass *createScalarEvolutionAliasAnalysisPass();
59
60 }
61
62 #endif