136static bool isNewFormatTypeNode(
const MDNode *
N) {
137 if (
N->getNumOperands() < 3)
140 if (!isa<MDNode>(
N->getOperand(0)))
148template<
typename MDNodeTy>
150 MDNodeTy *
Node =
nullptr;
153 TBAANodeImpl() =
default;
154 explicit TBAANodeImpl(MDNodeTy *
N) :
Node(
N) {}
157 MDNodeTy *getNode()
const {
return Node; }
161 bool isNewFormat()
const {
return isNewFormatTypeNode(
Node); }
164 TBAANodeImpl<MDNodeTy>
getParent()
const {
166 return TBAANodeImpl(cast<MDNodeTy>(
Node->getOperand(0)));
168 if (
Node->getNumOperands() < 2)
169 return TBAANodeImpl<MDNodeTy>();
170 MDNodeTy *
P = dyn_cast_or_null<MDNodeTy>(
Node->getOperand(1));
172 return TBAANodeImpl<MDNodeTy>();
174 return TBAANodeImpl<MDNodeTy>(
P);
180 bool isTypeImmutable()
const {
181 if (
Node->getNumOperands() < 3)
183 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(
Node->getOperand(2));
193using TBAANode = TBAANodeImpl<const MDNode>;
194using MutableTBAANode = TBAANodeImpl<MDNode>;
200template<
typename MDNodeTy>
201class TBAAStructTagNodeImpl {
206 explicit TBAAStructTagNodeImpl(MDNodeTy *
N) :
Node(
N) {}
209 MDNodeTy *getNode()
const {
return Node; }
213 bool isNewFormat()
const {
214 if (
Node->getNumOperands() < 4)
217 if (!TBAANodeImpl<MDNodeTy>(AccessType).isNewFormat())
223 return dyn_cast_or_null<MDNode>(
Node->getOperand(0));
227 return dyn_cast_or_null<MDNode>(
Node->getOperand(1));
231 return mdconst::extract<ConstantInt>(
Node->getOperand(2))->getZExtValue();
237 return mdconst::extract<ConstantInt>(
Node->getOperand(3))->getZExtValue();
243 bool isTypeImmutable()
const {
244 unsigned OpNo = isNewFormat() ? 4 : 3;
245 if (
Node->getNumOperands() < OpNo + 1)
247 ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(
Node->getOperand(OpNo));
257using TBAAStructTagNode = TBAAStructTagNodeImpl<const MDNode>;
258using MutableTBAAStructTagNode = TBAAStructTagNodeImpl<MDNode>;
264class TBAAStructTypeNode {
269 TBAAStructTypeNode() =
default;
270 explicit TBAAStructTypeNode(
const MDNode *
N) :
Node(
N) {}
273 const MDNode *getNode()
const {
return Node; }
277 bool isNewFormat()
const {
return isNewFormatTypeNode(
Node); }
280 return getNode() ==
Other.getNode();
285 return Node->getOperand(isNewFormat() ? 2 : 0);
288 unsigned getNumFields()
const {
289 unsigned FirstFieldOpNo = isNewFormat() ? 3 : 1;
290 unsigned NumOpsPerField = isNewFormat() ? 3 : 2;
291 return (getNode()->getNumOperands() - FirstFieldOpNo) / NumOpsPerField;
294 TBAAStructTypeNode getFieldType(
unsigned FieldIndex)
const {
295 unsigned FirstFieldOpNo = isNewFormat() ? 3 : 1;
296 unsigned NumOpsPerField = isNewFormat() ? 3 : 2;
297 unsigned OpIndex = FirstFieldOpNo + FieldIndex * NumOpsPerField;
298 auto *TypeNode = cast<MDNode>(getNode()->getOperand(
OpIndex));
299 return TBAAStructTypeNode(TypeNode);
305 bool NewFormat = isNewFormat();
307 const unsigned NumOperands =
Operands.size();
312 return TBAAStructTypeNode();
316 return TBAAStructTypeNode();
320 if (NumOperands <= 3) {
324 : mdconst::extract<ConstantInt>(
Operands[2])->getZExtValue();
328 return TBAAStructTypeNode();
329 return TBAAStructTypeNode(
P);
335 unsigned FirstFieldOpNo = NewFormat ? 3 : 1;
336 unsigned NumOpsPerField = NewFormat ? 3 : 2;
339 for (
unsigned Idx = FirstFieldOpNo;
Idx < NumOperands;
340 Idx += NumOpsPerField) {
342 mdconst::extract<ConstantInt>(
Operands[
Idx + 1])->getZExtValue();
344 assert(
Idx >= FirstFieldOpNo + NumOpsPerField &&
345 "TBAAStructTypeNode::getField should have an offset match!");
346 TheIdx =
Idx - NumOpsPerField;
352 TheIdx = NumOperands - NumOpsPerField;
354 mdconst::extract<ConstantInt>(
Operands[TheIdx + 1])->getZExtValue();
358 return TBAAStructTypeNode();
359 return TBAAStructTypeNode(
P);
413 if (
const MDNode *M = Call->getMetadata(LLVMContext::MD_tbaa))
433 if (
const MDNode *M = Call->getMetadata(LLVMContext::MD_tbaa))
448 if (!Aliases(
M1, M2))
459 if (Tag1->getString() ==
"vtable pointer")
466 TBAAStructTagNode
Tag(
this);
467 TBAAStructTypeNode AccessType(
Tag.getAccessType());
468 if(
auto *Id = dyn_cast<MDString>(AccessType.getId()))
469 if (Id->getString() ==
"vtable pointer")
475 const MDNode **GenericTag =
nullptr);
480 return const_cast<MDNode*
>(GenericTag);
492 while (TA.getNode()) {
493 if (!PathA.
insert(TA.getNode()))
500 while (TB.getNode()) {
501 if (!PathB.
insert(TB.getNode()))
506 int IA = PathA.
size() - 1;
507 int IB = PathB.
size() - 1;
509 const MDNode *Ret =
nullptr;
510 while (IA >= 0 && IB >= 0) {
511 if (PathA[IA] == PathB[IB])
525 Result.TBAAStruct =
nullptr;
533 Result.TBAA = Result.TBAAStruct =
nullptr;
548 if (TBAAStructTypeNode(AccessType).isNewFormat()) {
555 const_cast<MDNode*
>(AccessType),
556 OffsetNode, SizeNode};
561 const_cast<MDNode*
>(AccessType),
567 TBAAStructTypeNode FieldType) {
568 for (
unsigned I = 0,
E =
BaseType.getNumFields();
I !=
E; ++
I) {
569 TBAAStructTypeNode
T =
BaseType.getFieldType(
I);
584 TBAAStructTagNode SubobjectTag,
586 const MDNode **GenericTag,
590 if (BaseTag.getAccessType() == BaseTag.getBaseType() &&
591 BaseTag.getAccessType() == CommonType) {
603 bool NewFormat = BaseTag.isNewFormat();
604 TBAAStructTypeNode
BaseType(BaseTag.getBaseType());
605 uint64_t OffsetInBase = BaseTag.getOffset();
611 assert(!NewFormat &&
"Did not see access type in access path!");
615 if (
BaseType.getNode() == SubobjectTag.getBaseType()) {
616 bool SameMemberAccess = OffsetInBase == SubobjectTag.getOffset();
618 *GenericTag = SameMemberAccess ? SubobjectTag.getNode() :
621 MayAlias = SameMemberAccess;
626 if (NewFormat &&
BaseType.getNode() == BaseTag.getAccessType())
639 TBAAStructTypeNode FieldType(SubobjectTag.getBaseType());
655 const MDNode **GenericTag) {
665 *GenericTag =
nullptr;
674 TBAAStructTagNode TagA(
A), TagB(
B);
676 TagB.getAccessType());
682 *GenericTag =
nullptr;
690 CommonType, GenericTag, MayAlias) ||
692 CommonType, GenericTag, MayAlias))
703bool TypeBasedAAResult::Aliases(
const MDNode *
A,
const MDNode *
B)
const {
766 mdconst::extract<ConstantInt>(MD->
getOperand(i + 1));
798 TBAAStructTagNode
Tag(MD);
801 if (!
Tag.isNewFormat())
811 ConstantInt *PreviousSize = mdconst::extract<ConstantInt>(NextNodes[3]);
static const Function * getParent(const Value *V)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::optional< std::vector< StOtherPiece > > Other
static MemAccessTy getAccessType(const TargetTransformInfo &TTI, Instruction *Inst, Value *OperandVal)
Return the type of the memory being accessed.
mir Rename Register Operands
This file provides utility analysis objects describing memory locations.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null,...
This file implements a set that has insertion order iteration characteristics.
static bool matchAccessTags(const MDNode *A, const MDNode *B, const MDNode **GenericTag=nullptr)
matchTags - Return true if the given couple of accesses are allowed to overlap.
static cl::opt< bool > EnableTBAA("enable-tbaa", cl::init(true), cl::Hidden)
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...
static bool mayBeAccessToSubobjectOf(TBAAStructTagNode BaseTag, TBAAStructTagNode SubobjectTag, const MDNode *CommonType, const MDNode **GenericTag, bool &MayAlias)
Return true if for two given accesses, one of the accessed objects may be a subobject of the other.
static bool hasField(TBAAStructTypeNode BaseType, TBAAStructTypeNode FieldType)
static const MDNode * createAccessTag(const MDNode *AccessType)
static const MDNode * getLeastCommonType(const MDNode *A, const MDNode *B)
This is the interface for a metadata-based TBAA.
static unsigned getSize(unsigned Kind)
This class stores info we want to provide to or retain within an alias query.
MemoryEffects getMemoryEffects(const CallBase *Call, AAQueryInfo &AAQI)
ModRefInfo getModRefInfoMask(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool IgnoreLocals)
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI, const Instruction *I)
The possible results of an alias query.
@ NoAlias
The two locations do not alias at all.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This is the shared class of boolean and integer constants.
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
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.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
bool equalsInt(uint64_t V) const
A helper method that can be used to determine if the constant contained within is equal to a constant...
const APInt & getValue() const
Return the constant as an APInt value reference.
ImmutablePass class - This class is used to provide information that does not need to be run.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
bool isTBAAVtableAccess() const
Check whether MDNode is a vtable access.
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
const MDOperand & getOperand(unsigned I) const
ArrayRef< MDOperand > operands() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
static MDNode * intersect(MDNode *A, MDNode *B)
LLVMContext & getContext() const
Summary of how a function affects memory in the program.
static MemoryEffects none()
Create MemoryEffects that cannot read or write any memory.
Representation for a specific memory location.
AAMDNodes AATags
The metadata nodes which describes the aliasing of the location (each member is null if that kind of ...
A Module instance is used to store all the information related to an LLVM module.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
size_type size() const
Determine the number of elements in the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A simple AA result that uses TBAA metadata to answer queries.
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 ...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
TypeBasedAAResult run(Function &F, FunctionAnalysisManager &AM)
The instances of the Type class are immutable: once they are created, they are never changed.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
void initializeTypeBasedAAWrapperPassPass(PassRegistry &)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
unsigned M1(unsigned Val)
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
@ NoModRef
The access neither references nor modifies the value stored in memory.
ImmutablePass * createTypeBasedAAWrapperPass()
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
AAMDNodes concat(const AAMDNodes &Other) const
Determine the best AAMDNodes after concatenating two different locations together.
static MDNode * shiftTBAAStruct(MDNode *M, size_t off)
MDNode * Scope
The tag for alias scope specification (used with noalias).
static MDNode * extendToTBAA(MDNode *TBAA, ssize_t len)
MDNode * TBAA
The tag for type-based alias analysis.
AAMDNodes merge(const AAMDNodes &Other) const
Given two sets of AAMDNodes applying to potentially different locations, determine the best AAMDNodes...
MDNode * NoAlias
The tag specifying the noalias scope.
static MDNode * shiftTBAA(MDNode *M, size_t off)
A special type used by analysis passes to provide an address that identifies that particular analysis...