1//===- TypeBasedAliasAnalysis.h - Type-Based Alias Analysis -----*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// This is the interface for a metadata-based TBAA. See the source file for
11/// details on the algorithm.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
16#define LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
17
18#include "llvm/Analysis/AliasAnalysis.h"
19#include "llvm/IR/PassManager.h"
20#include "llvm/Pass.h"
21#include <memory>
22
23namespace llvm {
24
25class CallBase;
26class Function;
27class MDNode;
28class MemoryLocation;
29
30/// A simple AA result that uses TBAA metadata to answer queries.
31class TypeBasedAAResult : public AAResultBase {
32public:
33 /// Handle invalidation events from the new pass manager.
34 ///
35 /// By definition, this result is stateless and so remains valid.
36 bool invalidate(Function &, const PreservedAnalyses &,
37 FunctionAnalysisManager::Invalidator &) {
38 return false;
39 }
40
41 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
42 AAQueryInfo &AAQI, const Instruction *CtxI);
43 ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI,
44 bool IgnoreLocals);
45
46 MemoryEffects getMemoryEffects(const CallBase *Call, AAQueryInfo &AAQI);
47 MemoryEffects getMemoryEffects(const Function *F);
48 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
49 AAQueryInfo &AAQI);
50 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
51 AAQueryInfo &AAQI);
52
53private:
54 bool Aliases(const MDNode *A, const MDNode *B) const;
55};
56
57/// Analysis pass providing a never-invalidated alias analysis result.
58class TypeBasedAA : public AnalysisInfoMixin<TypeBasedAA> {
59 friend AnalysisInfoMixin<TypeBasedAA>;
60
61 static AnalysisKey Key;
62
63public:
64 using Result = TypeBasedAAResult;
65
66 TypeBasedAAResult run(Function &F, FunctionAnalysisManager &AM);
67};
68
69/// Legacy wrapper pass to provide the TypeBasedAAResult object.
70class TypeBasedAAWrapperPass : public ImmutablePass {
71 std::unique_ptr<TypeBasedAAResult> Result;
72
73public:
74 static char ID;
75
76 TypeBasedAAWrapperPass();
77
78 TypeBasedAAResult &getResult() { return *Result; }
79 const TypeBasedAAResult &getResult() const { return *Result; }
80
81 bool doInitialization(Module &M) override;
82 bool doFinalization(Module &M) override;
83 void getAnalysisUsage(AnalysisUsage &AU) const override;
84};
85
86//===--------------------------------------------------------------------===//
87//
88// createTypeBasedAAWrapperPass - This pass implements metadata-based
89// type-based alias analysis.
90//
91ImmutablePass *createTypeBasedAAWrapperPass();
92
93} // end namespace llvm
94
95#endif // LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
96

source code of llvm/include/llvm/Analysis/TypeBasedAliasAnalysis.h