133 using namespace llvm;
148 TBAANode() : Node(nullptr) {}
149 explicit TBAANode(
const MDNode *
N) : Node(N) {}
152 const MDNode *getNode()
const {
return Node; }
156 if (Node->getNumOperands() < 2)
158 MDNode *
P = dyn_cast_or_null<MDNode>(Node->getOperand(1));
168 bool TypeIsImmutable()
const {
169 if (Node->getNumOperands() < 3)
171 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Node->getOperand(2));
181 class TBAAStructTagNode {
186 explicit TBAAStructTagNode(
const MDNode *
N) : Node(N) {}
189 const MDNode *getNode()
const {
return Node; }
191 const MDNode *getBaseType()
const {
192 return dyn_cast_or_null<MDNode>(Node->getOperand(0));
195 return dyn_cast_or_null<MDNode>(Node->getOperand(1));
198 return mdconst::extract<ConstantInt>(Node->getOperand(2))->getZExtValue();
203 bool TypeIsImmutable()
const {
204 if (Node->getNumOperands() < 4)
206 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Node->getOperand(3));
216 class TBAAStructTypeNode {
221 TBAAStructTypeNode() : Node(nullptr) {}
222 explicit TBAAStructTypeNode(
const MDNode *
N) : Node(N) {}
225 const MDNode *getNode()
const {
return Node; }
229 TBAAStructTypeNode
getParent(uint64_t &Offset)
const {
231 if (Node->getNumOperands() < 2)
232 return TBAAStructTypeNode();
236 if (Node->getNumOperands() <= 3) {
239 : mdconst::extract<ConstantInt>(Node->getOperand(2))
242 MDNode *P = dyn_cast_or_null<MDNode>(Node->getOperand(1));
244 return TBAAStructTypeNode();
245 return TBAAStructTypeNode(P);
251 for (
unsigned Idx = 1; Idx < Node->getNumOperands(); Idx += 2) {
252 uint64_t Cur = mdconst::extract<ConstantInt>(Node->getOperand(Idx + 1))
256 "TBAAStructTypeNode::getParent should have an offset match!");
263 TheIdx = Node->getNumOperands() - 2;
264 uint64_t Cur = mdconst::extract<ConstantInt>(Node->getOperand(TheIdx + 1))
267 MDNode *P = dyn_cast_or_null<MDNode>(Node->getOperand(TheIdx));
269 return TBAAStructTypeNode();
270 return TBAAStructTypeNode(P);
286 bool doInitialization(
Module &M)
override;
292 void *getAdjustedAnalysisPointer(
const void *PI)
override {
306 bool OrLocal)
override;
319 "Type-Based Alias Analysis",
false,
true,
false)
322 return new TypeBasedAliasAnalysis();
325 bool TypeBasedAliasAnalysis::doInitialization(
Module &M) {
331 TypeBasedAliasAnalysis::getAnalysisUsage(
AnalysisUsage &AU)
const {
348 TypeBasedAliasAnalysis::Aliases(
const MDNode *
A,
352 return PathAliases(A, B);
355 TBAANode RootA, RootB;
358 for (TBAANode
T(A); ; ) {
359 if (
T.getNode() == B)
370 for (TBAANode
T(B); ; ) {
371 if (
T.getNode() ==
A)
385 if (RootA.getNode() != RootB.getNode())
395 TypeBasedAliasAnalysis::PathAliases(
const MDNode *A,
402 TBAAStructTypeNode RootA, RootB;
403 TBAAStructTagNode TagA(A), TagB(B);
414 const MDNode *BaseA = TagA.getBaseType();
415 const MDNode *BaseB = TagB.getBaseType();
416 uint64_t OffsetA = TagA.getOffset(), OffsetB = TagB.getOffset();
417 for (TBAAStructTypeNode
T(BaseA); ; ) {
418 if (
T.getNode() == BaseB)
420 return OffsetA == OffsetB;
425 T =
T.getParent(OffsetA);
432 OffsetA = TagA.getOffset();
433 for (TBAAStructTypeNode
T(BaseB); ; ) {
434 if (
T.getNode() == BaseA)
436 return OffsetA == OffsetB;
441 T =
T.getParent(OffsetB);
450 if (RootA.getNode() != RootB.getNode())
477 bool TypeBasedAliasAnalysis::pointsToConstantMemory(
const MemoryLocation &Loc,
506 Min = OnlyReadsMemory;
512 TypeBasedAliasAnalysis::getModRefBehavior(
const Function *
F) {
542 if (!Aliases(M1, M2))
552 if (Tag1->getString() ==
"vtable pointer")
return true;
560 if (!Tag)
return false;
562 if (Tag1->getString() ==
"vtable pointer")
return true;
578 if (!A)
return nullptr;
580 if (!B)
return nullptr;
603 int IA = PathA.
size() - 1;
604 int IB = PathB.
size() - 1;
607 while (IA >= 0 && IB >=0) {
608 if (PathA[IA] == PathB[IB])
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
MDNode * Scope
The tag for alias scope specification (used with noalias).
MDNode * TBAA
The tag for type-based alias analysis.
A Module instance is used to store all the information related to an LLVM module. ...
InstrTy * getInstruction() const
unsigned getNumOperands() const
unsigned getNumOperands() const
Return number of MDNode operands.
ModRefBehavior
ModRefBehavior - Summary of how a function affects memory in the program.
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
The two locations do not alias at all.
static std::error_code getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
size_type size() const
Determine the number of elements in the SetVector.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
virtual bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal=false)
pointsToConstantMemory - If the specified memory location is known to be constant, return true.
void initializeTypeBasedAliasAnalysisPass(PassRegistry &)
const APInt & getValue() const
Return the constant as an APInt value reference.
bool isTBAAVtableAccess() const
Check whether MDNode is a vtable access.
bool insert(const value_type &X)
Insert a new element into the SetVector.
static MDNode * intersect(MDNode *A, MDNode *B)
initializer< Ty > init(const Ty &Val)
ImmutablePass * createTypeBasedAliasAnalysisPass()
The instances of the Type class are immutable: once they are created, they are never changed...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
AliasResult
The possible results of an alias query.
Represent the analysis usage information of a pass.
static Type * getAccessType(const Instruction *Inst)
getAccessType - Return the type of the memory being accessed.
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
virtual ModRefBehavior getModRefBehavior(ImmutableCallSite CS)
getModRefBehavior - Return the behavior when calling the given call site.
Representation for a specific memory location.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
const MDOperand & getOperand(unsigned I) const
A SetVector that performs no allocations if smaller than a certain size.
This is the shared class of boolean and integer constants.
ImmutablePass class - This class is used to provide information that does not need to be run...
virtual AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
Alias Queries...
Module.h This file contains the declarations for the Module class.
MDNode * getMetadata(unsigned KindID) const
getMetadata - Get the metadata of given kind attached to this Instruction.
ModRefResult getModRefInfo(const Instruction *I)
getModRefInfo - Return information about whether or not an instruction may read or write memory (with...
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
MDNode * NoAlias
The tag specifying the noalias scope.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
INITIALIZE_AG_PASS(TypeBasedAliasAnalysis, AliasAnalysis,"tbaa","Type-Based Alias Analysis", false, true, false) ImmutablePass *llvm
void setPreservesAll()
Set by analyses that do not transform their input at all.
static cl::opt< bool > EnableTBAA("enable-tbaa", cl::init(true))
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
AAMDNodes AATags
The metadata nodes which describes the aliasing of the location (each member is null if that kind of ...
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
getAAMetadata - Fills the AAMDNodes structure with AA metadata from this instruction.
ImmutableCallSite - establish a view to a call site for examination.
LLVMContext & getContext() const
ModRefResult
Simple mod/ref information...
static const Function * getParent(const Value *V)
virtual void getAnalysisUsage(AnalysisUsage &AU) const
getAnalysisUsage - All alias analysis implementations should invoke this directly (using AliasAnalysi...
static bool isStructPathTBAA(const MDNode *MD)
Check the first operand of the tbaa tag node, if it is a MDNode, we treat it as struct-path aware TBA...