LLVM 20.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"
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.
32 /// True if type sanitizer is enabled. When TypeSanitizer is used, don't use
33 /// TBAA information for alias analysis as this might cause us to remove
34 /// memory accesses that we need to verify at runtime.
35 bool UsingTypeSanitizer;
36
37public:
38 TypeBasedAAResult(bool UsingTypeSanitizer)
39 : UsingTypeSanitizer(UsingTypeSanitizer) {}
40
41 /// Handle invalidation events from the new pass manager.
42 ///
43 /// By definition, this result is stateless and so remains valid.
46 return false;
47 }
48
49 AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB,
50 AAQueryInfo &AAQI, const Instruction *CtxI);
52 bool IgnoreLocals);
53
56 ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc,
57 AAQueryInfo &AAQI);
58 ModRefInfo getModRefInfo(const CallBase *Call1, const CallBase *Call2,
59 AAQueryInfo &AAQI);
60
61private:
62 bool Aliases(const MDNode *A, const MDNode *B) const;
63
64 /// Returns true if TBAA metadata should be used, that is if TBAA is enabled
65 /// and type sanitizer is not used.
66 bool shouldUseTBAA() const;
67};
68
69/// Analysis pass providing a never-invalidated alias analysis result.
70class TypeBasedAA : public AnalysisInfoMixin<TypeBasedAA> {
72
73 static AnalysisKey Key;
74
75public:
77
79};
80
81/// Legacy wrapper pass to provide the TypeBasedAAResult object.
83 std::unique_ptr<TypeBasedAAResult> Result;
84
85public:
86 static char ID;
87
89
90 TypeBasedAAResult &getResult() { return *Result; }
91 const TypeBasedAAResult &getResult() const { return *Result; }
92
93 bool doInitialization(Module &M) override;
94 bool doFinalization(Module &M) override;
95 void getAnalysisUsage(AnalysisUsage &AU) const override;
96};
97
98//===--------------------------------------------------------------------===//
99//
100// createTypeBasedAAWrapperPass - This pass implements metadata-based
101// type-based alias analysis.
102//
104
105} // end namespace llvm
106
107#endif // LLVM_ANALYSIS_TYPEBASEDALIASANALYSIS_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition: MD5.cpp:55
This class stores info we want to provide to or retain within an alias query.
A base class to help implement the function alias analysis results concept.
The possible results of an alias query.
Definition: AliasAnalysis.h:77
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:292
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
Represent the analysis usage information of a pass.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1120
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:281
Metadata node.
Definition: Metadata.h:1069
Representation for a specific memory location.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
A simple AA result that uses TBAA metadata to answer queries.
bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
Handle invalidation events from the new pass manager.
TypeBasedAAResult(bool UsingTypeSanitizer)
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI, const Instruction *CtxI)
ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool IgnoreLocals)
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
MemoryEffects getMemoryEffects(const CallBase *Call, AAQueryInfo &AAQI)
Legacy wrapper pass to provide the TypeBasedAAResult object.
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
const TypeBasedAAResult & getResult() const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Analysis pass providing a never-invalidated alias analysis result.
TypeBasedAAResult run(Function &F, FunctionAnalysisManager &AM)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
Definition: ModRef.h:27
ImmutablePass * createTypeBasedAAWrapperPass()
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28