130 using namespace llvm;
141 template<
typename MDNodeTy>
146 TBAANodeImpl() : Node(nullptr) {}
147 explicit TBAANodeImpl(MDNodeTy *
N) : Node(N) {}
150 MDNodeTy *getNode()
const {
return Node; }
153 TBAANodeImpl<MDNodeTy>
getParent()
const {
154 if (Node->getNumOperands() < 2)
155 return TBAANodeImpl<MDNodeTy>();
156 MDNodeTy *
P = dyn_cast_or_null<MDNodeTy>(Node->getOperand(1));
158 return TBAANodeImpl<MDNodeTy>();
160 return TBAANodeImpl<MDNodeTy>(
P);
166 bool isTypeImmutable()
const {
167 if (Node->getNumOperands() < 3)
169 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Node->getOperand(2));
179 typedef TBAANodeImpl<const MDNode> TBAANode;
180 typedef TBAANodeImpl<MDNode> MutableTBAANode;
186 template<
typename MDNodeTy>
187 class TBAAStructTagNodeImpl {
192 explicit TBAAStructTagNodeImpl(MDNodeTy *
N) : Node(N) {}
195 MDNodeTy *getNode()
const {
return Node; }
197 MDNodeTy *getBaseType()
const {
198 return dyn_cast_or_null<MDNode>(Node->getOperand(0));
201 return dyn_cast_or_null<MDNode>(Node->getOperand(1));
204 return mdconst::extract<ConstantInt>(Node->getOperand(2))->getZExtValue();
209 bool isTypeImmutable()
const {
210 if (Node->getNumOperands() < 4)
212 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Node->getOperand(3));
222 typedef TBAAStructTagNodeImpl<const MDNode> TBAAStructTagNode;
223 typedef TBAAStructTagNodeImpl<MDNode> MutableTBAAStructTagNode;
229 class TBAAStructTypeNode {
234 TBAAStructTypeNode() : Node(nullptr) {}
235 explicit TBAAStructTypeNode(
const MDNode *
N) : Node(N) {}
238 const MDNode *getNode()
const {
return Node; }
244 if (Node->getNumOperands() < 2)
245 return TBAAStructTypeNode();
249 if (Node->getNumOperands() <= 3) {
252 : mdconst::extract<ConstantInt>(Node->getOperand(2))
255 MDNode *P = dyn_cast_or_null<MDNode>(Node->getOperand(1));
257 return TBAAStructTypeNode();
258 return TBAAStructTypeNode(P);
264 for (
unsigned Idx = 1; Idx < Node->getNumOperands(); Idx += 2) {
265 uint64_t Cur = mdconst::extract<ConstantInt>(Node->getOperand(Idx + 1))
269 "TBAAStructTypeNode::getParent should have an offset match!");
276 TheIdx = Node->getNumOperands() - 2;
277 uint64_t Cur = mdconst::extract<ConstantInt>(Node->getOperand(TheIdx + 1))
280 MDNode *P = dyn_cast_or_null<MDNode>(Node->getOperand(TheIdx));
282 return TBAAStructTypeNode();
283 return TBAAStructTypeNode(P);
382 if (!Aliases(M1, M2))
393 if (Tag1->getString() ==
"vtable pointer")
406 if (Tag1->getString() ==
"vtable pointer")
421 "Auto upgrade should have taken care of this!");
422 A = cast_or_null<MDNode>(MutableTBAAStructTagNode(A).getAccessType());
425 B = cast_or_null<MDNode>(MutableTBAAStructTagNode(B).getAccessType());
430 MutableTBAANode
TA(A);
431 while (TA.getNode()) {
432 if (PathA.
count(TA.getNode()))
434 PathA.
insert(TA.getNode());
439 MutableTBAANode
TB(B);
440 while (TB.getNode()) {
441 if (PathB.
count(TB.getNode()))
443 PathB.
insert(TB.getNode());
447 int IA = PathA.
size() - 1;
448 int IB = PathB.
size() - 1;
451 while (IA >= 0 && IB >= 0) {
452 if (PathA[IA] == PathB[IB])
495 bool TypeBasedAAResult::Aliases(
const MDNode *
A,
const MDNode *
B)
const {
502 TBAAStructTypeNode RootA, RootB;
503 TBAAStructTagNode TagA(A), TagB(B);
514 const MDNode *BaseA = TagA.getBaseType();
515 const MDNode *BaseB = TagB.getBaseType();
516 uint64_t OffsetA = TagA.getOffset(), OffsetB = TagB.getOffset();
517 for (TBAAStructTypeNode
T(BaseA);;) {
518 if (
T.getNode() == BaseB)
520 return OffsetA == OffsetB;
525 T =
T.getParent(OffsetA);
532 OffsetA = TagA.getOffset();
533 for (TBAAStructTypeNode
T(BaseB);;) {
534 if (
T.getNode() == BaseA)
536 return OffsetA == OffsetB;
541 T =
T.getParent(OffsetB);
550 if (RootA.getNode() != RootB.getNode())
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).
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
MDNode * TBAA
The tag for type-based alias analysis.
A Module instance is used to store all the information related to an LLVM module. ...
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
unsigned getNumOperands() const
unsigned getNumOperands() const
Return number of MDNode operands.
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
INITIALIZE_PASS(TypeBasedAAWrapperPass,"tbaa","Type-Based Alias Analysis", false, true) ImmutablePass *llvm
The two locations do not alias at all.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
size_type size() const
Determine the number of elements in the SetVector.
void initializeTypeBasedAAWrapperPassPass(PassRegistry &)
TypeBasedAAResult run(Function &F, FunctionAnalysisManager &AM)
This indicates that the function could not be classified into one of the behaviors above...
Legacy wrapper pass to provide the TypeBasedAAResult object.
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
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.
FunctionModRefBehavior
Summary of how a function affects memory in the program.
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS)
static MDNode * intersect(MDNode *A, MDNode *B)
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS)
The access neither references nor modifies the value stored in memory.
initializer< Ty > init(const Ty &Val)
This is the interface for a metadata-based TBAA.
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.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
A simple AA result that uses TBAA metadata to answer queries.
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc)
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.
static void Merge(const std::string &Input, const std::vector< std::string > Result, size_t NumNewFeatures)
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...
InstrTy * getInstruction() const
Module.h This file contains the declarations for the Module class.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
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.
This function does not perform any non-local stores or volatile loads, but may read from any memory l...
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)
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
Fills the AAMDNodes structure with AA metadata from this instruction.
ImmutableCallSite - establish a view to a call site for examination.
static MemAccessTy getAccessType(const Instruction *Inst)
Return the type of the memory being accessed.
LLVMContext & getContext() const
ImmutablePass * createTypeBasedAAWrapperPass()
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const Function * getParent(const Value *V)
A container for analyses that lazily runs them and caches their results.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
A special type used by analysis passes to provide an address that identifies that particular analysis...
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
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...