1 //===- TypeBasedAliasAnalysis.h - Type-Based Alias Analysis -----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// This is the interface for a metadata-based TBAA. See the source file for
11 /// details on the algorithm.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
16 #define LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
18 #include "llvm/Analysis/AliasAnalysis.h"
19 #include "llvm/IR/InstrTypes.h"
20 #include "llvm/IR/PassManager.h"
21 #include "llvm/Pass.h"
30 /// A simple AA result that uses TBAA metadata to answer queries.
31 class TypeBasedAAResult
: public AAResultBase
<TypeBasedAAResult
> {
32 friend AAResultBase
<TypeBasedAAResult
>;
35 /// Handle invalidation events from the new pass manager.
37 /// By definition, this result is stateless and so remains valid.
38 bool invalidate(Function
&, const PreservedAnalyses
&,
39 FunctionAnalysisManager::Invalidator
&) {
43 AliasResult
alias(const MemoryLocation
&LocA
, const MemoryLocation
&LocB
);
44 bool pointsToConstantMemory(const MemoryLocation
&Loc
, bool OrLocal
);
45 FunctionModRefBehavior
getModRefBehavior(const CallBase
*Call
);
46 FunctionModRefBehavior
getModRefBehavior(const Function
*F
);
47 ModRefInfo
getModRefInfo(const CallBase
*Call
, const MemoryLocation
&Loc
);
48 ModRefInfo
getModRefInfo(const CallBase
*Call1
, const CallBase
*Call2
);
51 bool Aliases(const MDNode
*A
, const MDNode
*B
) const;
52 bool PathAliases(const MDNode
*A
, const MDNode
*B
) const;
55 /// Analysis pass providing a never-invalidated alias analysis result.
56 class TypeBasedAA
: public AnalysisInfoMixin
<TypeBasedAA
> {
57 friend AnalysisInfoMixin
<TypeBasedAA
>;
59 static AnalysisKey Key
;
62 using Result
= TypeBasedAAResult
;
64 TypeBasedAAResult
run(Function
&F
, FunctionAnalysisManager
&AM
);
67 /// Legacy wrapper pass to provide the TypeBasedAAResult object.
68 class TypeBasedAAWrapperPass
: public ImmutablePass
{
69 std::unique_ptr
<TypeBasedAAResult
> Result
;
74 TypeBasedAAWrapperPass();
76 TypeBasedAAResult
&getResult() { return *Result
; }
77 const TypeBasedAAResult
&getResult() const { return *Result
; }
79 bool doInitialization(Module
&M
) override
;
80 bool doFinalization(Module
&M
) override
;
81 void getAnalysisUsage(AnalysisUsage
&AU
) const override
;
84 //===--------------------------------------------------------------------===//
86 // createTypeBasedAAWrapperPass - This pass implements metadata-based
87 // type-based alias analysis.
89 ImmutablePass
*createTypeBasedAAWrapperPass();
91 } // end namespace llvm
93 #endif // LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H