6a93b004501542395b6a903350c4900017b656ab
[oota-llvm.git] / include / llvm / Analysis / LibCallAliasAnalysis.h
1 //===- LibCallAliasAnalysis.h - Implement AliasAnalysis for libcalls ------===//
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 //
10 // This file defines the LibCallAliasAnalysis class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_ANALYSIS_LIBCALLALIASANALYSIS_H
15 #define LLVM_ANALYSIS_LIBCALLALIASANALYSIS_H
16
17 #include "llvm/Analysis/AliasAnalysis.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/Pass.h"
20
21 namespace llvm {
22
23 class LibCallInfo;
24 struct LibCallFunctionInfo;
25
26 /// LibCallAliasAnalysis - Alias analysis driven from LibCallInfo.
27 struct LibCallAliasAnalysis : public FunctionPass, public AliasAnalysis {
28   static char ID; // Class identification
29
30   LibCallInfo *LCI;
31
32   explicit LibCallAliasAnalysis(LibCallInfo *LC = nullptr)
33       : FunctionPass(ID), LCI(LC) {
34     initializeLibCallAliasAnalysisPass(*PassRegistry::getPassRegistry());
35   }
36   explicit LibCallAliasAnalysis(char &ID, LibCallInfo *LC)
37       : FunctionPass(ID), LCI(LC) {
38     initializeLibCallAliasAnalysisPass(*PassRegistry::getPassRegistry());
39   }
40   ~LibCallAliasAnalysis() override;
41
42   ModRefInfo getModRefInfo(ImmutableCallSite CS,
43                            const MemoryLocation &Loc) override;
44
45   ModRefInfo getModRefInfo(ImmutableCallSite CS1,
46                            ImmutableCallSite CS2) override {
47     // TODO: Could compare two direct calls against each other if we cared to.
48     return AliasAnalysis::getModRefInfo(CS1, CS2);
49   }
50
51   void getAnalysisUsage(AnalysisUsage &AU) const override;
52
53   bool runOnFunction(Function &F) override;
54
55   /// getAdjustedAnalysisPointer - This method is used when a pass implements
56   /// an analysis interface through multiple inheritance.  If needed, it
57   /// should override this to adjust the this pointer as needed for the
58   /// specified pass info.
59   void *getAdjustedAnalysisPointer(const void *PI) override {
60     if (PI == &AliasAnalysis::ID)
61       return (AliasAnalysis *)this;
62     return this;
63   }
64
65 private:
66   ModRefInfo AnalyzeLibCallDetails(const LibCallFunctionInfo *FI,
67                                    ImmutableCallSite CS,
68                                    const MemoryLocation &Loc);
69 };
70
71 /// createLibCallAliasAnalysisPass - Create an alias analysis pass that knows
72 /// about the semantics of a set of libcalls specified by LCI.  The newly
73 /// constructed pass takes ownership of the pointer that is provided.
74 ///
75 FunctionPass *createLibCallAliasAnalysisPass(LibCallInfo *LCI);
76
77 } // End of llvm namespace
78
79 #endif