LLVM 24.0.0git
TypeBasedAliasAnalysis.h
Go to the documentation of this file.
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
19#include "llvm/IR/PassManager.h"
20#include "llvm/Pass.h"
22#include <memory>
23
24namespace llvm {
25
26struct AnalysisOptions;
27class CallBase;
28class Function;
29class LLVMContext;
30class MDNode;
31class MemoryLocation;
32
33/// A simple AA result that uses TBAA metadata to answer queries.
35 const AnalysisOptions &Opts;
36 /// True if type sanitizer is enabled. When TypeSanitizer is used, don't use
37 /// TBAA information for alias analysis as this might cause us to remove
38 /// memory accesses that we need to verify at runtime.
39 bool UsingTypeSanitizer;
40
41public:
42 LLVM_ABI TypeBasedAAResult(const LLVMContext &C, bool UsingTypeSanitizer);
43
44 /// Handle invalidation events from the new pass manager.
45 ///
46 /// By definition, this result is stateless and so remains valid.
48 FunctionAnalysisManager::Invalidator &) {
49 return false;
50 }
51
53 const MemoryLocation &LocB, AAQueryInfo &AAQI,
54 const Instruction *CtxI);
56 const Instruction *CtxI);
58 AAQueryInfo &AAQI, bool IgnoreLocals);
59
61 AAQueryInfo &AAQI);
65 const MemoryLocation &Loc,
66 AAQueryInfo &AAQI);
68 const CallBase *Call2, AAQueryInfo &AAQI);
69
70private:
71 bool Aliases(const MDNode *A, const MDNode *B) const;
72
73 /// Returns true if TBAA metadata should be used, that is if TBAA is enabled
74 /// and type sanitizer is not used.
75 bool shouldUseTBAA() const;
76};
77
78/// Analysis pass providing a never-invalidated alias analysis result.
79class TypeBasedAA : public AnalysisInfoMixin<TypeBasedAA> {
81
82 LLVM_ABI static AnalysisKey Key;
83
84public:
86
88};
89
90/// Legacy wrapper pass to provide the TypeBasedAAResult object.
92 std::unique_ptr<TypeBasedAAResult> Result;
93
94public:
95 static char ID;
96
98
99 TypeBasedAAResult &getResult() { return *Result; }
100 const TypeBasedAAResult &getResult() const { return *Result; }
101
102 bool doInitialization(Module &M) override;
103 bool doFinalization(Module &M) override;
104 void getAnalysisUsage(AnalysisUsage &AU) const override;
105};
106
107//===--------------------------------------------------------------------===//
108//
109// createTypeBasedAAWrapperPass - This pass implements metadata-based
110// type-based alias analysis.
111//
113
114} // end namespace llvm
115
116#endif // LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:54
This class stores info we want to provide to or retain within an alias query.
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
AAResultBase()=default
The possible results of an alias query.
Represent the analysis usage information of a pass.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition Pass.h:283
ImmutablePass(char &pid)
Definition Pass.h:285
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
Metadata node.
Definition Metadata.h:1081
Representation for a specific memory location.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
A simple AA result that uses TBAA metadata to answer queries.
LLVM_ABI AliasResult aliasErrno(const MemoryLocation &Loc, const Instruction *CtxI)
bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
Handle invalidation events from the new pass manager.
LLVM_ABI AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI, const Instruction *CtxI)
LLVM_ABI TypeBasedAAResult(const LLVMContext &C, bool UsingTypeSanitizer)
LLVM_ABI ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool IgnoreLocals)
LLVM_ABI ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
LLVM_ABI MemoryEffects getMemoryEffects(const CallBase *Call, AAQueryInfo &AAQI)
const TypeBasedAAResult & getResult() const
Analysis pass providing a never-invalidated alias analysis result.
LLVM_ABI TypeBasedAAResult run(Function &F, FunctionAnalysisManager &AM)
TypeBasedAAResult Result
CallInst * Call
This is an optimization pass for GlobalISel generic memory operations.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:356
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
Definition ModRef.h:28
LLVM_ABI ImmutablePass * createTypeBasedAAWrapperPass()
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29