Go to the documentation of this file.
125 using namespace llvm;
136 static bool isNewFormatTypeNode(
const MDNode *
N) {
137 if (
N->getNumOperands() < 3)
140 if (!isa<MDNode>(
N->getOperand(0)))
148 template<
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));
193 using TBAANode = TBAANodeImpl<const MDNode>;
194 using MutableTBAANode = TBAANodeImpl<MDNode>;
200 template<
typename MDNodeTy>
201 class 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));
257 using TBAAStructTagNode = TBAAStructTagNodeImpl<const MDNode>;
258 using MutableTBAAStructTagNode = TBAAStructTagNodeImpl<MDNode>;
264 class TBAAStructTypeNode {
266 const MDNode *Node =
nullptr;
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); }
279 bool operator==(
const TBAAStructTypeNode &Other)
const {
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);
304 TBAAStructTypeNode getField(
uint64_t &Offset)
const {
305 bool NewFormat = isNewFormat();
308 if (Node->getNumOperands() < 6)
309 return TBAAStructTypeNode();
312 if (Node->getNumOperands() < 2)
313 return TBAAStructTypeNode();
317 if (Node->getNumOperands() <= 3) {
318 uint64_t Cur = Node->getNumOperands() == 2
320 : mdconst::extract<ConstantInt>(Node->getOperand(2))
323 MDNode *
P = dyn_cast_or_null<MDNode>(Node->getOperand(1));
325 return TBAAStructTypeNode();
326 return TBAAStructTypeNode(
P);
332 unsigned FirstFieldOpNo = NewFormat ? 3 : 1;
333 unsigned NumOpsPerField = NewFormat ? 3 : 2;
335 for (
unsigned Idx = FirstFieldOpNo; Idx < Node->getNumOperands();
336 Idx += NumOpsPerField) {
337 uint64_t Cur = mdconst::extract<ConstantInt>(Node->getOperand(Idx + 1))
340 assert(Idx >= FirstFieldOpNo + NumOpsPerField &&
341 "TBAAStructTypeNode::getField should have an offset match!");
342 TheIdx = Idx - NumOpsPerField;
348 TheIdx = Node->getNumOperands() - NumOpsPerField;
349 uint64_t Cur = mdconst::extract<ConstantInt>(Node->getOperand(TheIdx + 1))
352 MDNode *
P = dyn_cast_or_null<MDNode>(Node->getOperand(TheIdx));
354 return TBAAStructTypeNode();
355 return TBAAStructTypeNode(
P);
412 if (
const MDNode *
M = Call->getMetadata(LLVMContext::MD_tbaa))
432 if (
const MDNode *
M = Call->getMetadata(LLVMContext::MD_tbaa))
447 if (!Aliases(
M1, M2))
458 if (Tag1->getString() ==
"vtable pointer")
465 TBAAStructTagNode
Tag(
this);
466 TBAAStructTypeNode AccessType(
Tag.getAccessType());
467 if(
auto *
Id = dyn_cast<MDString>(AccessType.getId()))
468 if (
Id->getString() ==
"vtable pointer")
474 const MDNode **GenericTag =
nullptr);
479 return const_cast<MDNode*
>(GenericTag);
491 while (
TA.getNode()) {
500 while (
TB.getNode()) {
507 int IA = PathA.
size() - 1;
508 int IB = PathB.
size() - 1;
511 while (IA >= 0 && IB >= 0) {
512 if (PathA[IA] == PathB[IB])
526 Result.TBAAStruct =
nullptr;
534 Result.TBAA = Result.TBAAStruct =
nullptr;
549 if (TBAAStructTypeNode(AccessType).isNewFormat()) {
556 const_cast<MDNode*
>(AccessType),
557 OffsetNode, SizeNode};
562 const_cast<MDNode*
>(AccessType),
568 TBAAStructTypeNode FieldType) {
569 for (
unsigned I = 0,
E =
BaseType.getNumFields();
I !=
E; ++
I) {
570 TBAAStructTypeNode
T =
BaseType.getFieldType(
I);
585 TBAAStructTagNode SubobjectTag,
587 const MDNode **GenericTag,
591 if (BaseTag.getAccessType() == BaseTag.getBaseType() &&
592 BaseTag.getAccessType() == CommonType) {
604 bool NewFormat = BaseTag.isNewFormat();
605 TBAAStructTypeNode
BaseType(BaseTag.getBaseType());
606 uint64_t OffsetInBase = BaseTag.getOffset();
612 assert(!NewFormat &&
"Did not see access type in access path!");
616 if (
BaseType.getNode() == SubobjectTag.getBaseType()) {
617 bool SameMemberAccess = OffsetInBase == SubobjectTag.getOffset();
619 *GenericTag = SameMemberAccess ? SubobjectTag.getNode() :
622 MayAlias = SameMemberAccess;
627 if (NewFormat &&
BaseType.getNode() == BaseTag.getAccessType())
640 TBAAStructTypeNode FieldType(SubobjectTag.getBaseType());
656 const MDNode **GenericTag) {
666 *GenericTag =
nullptr;
675 TBAAStructTagNode TagA(A), TagB(
B);
677 TagB.getAccessType());
683 *GenericTag =
nullptr;
691 CommonType, GenericTag, MayAlias) ||
693 CommonType, GenericTag, MayAlias))
704 bool TypeBasedAAResult::Aliases(
const MDNode *A,
const MDNode *
B)
const {
767 mdconst::extract<ConstantInt>(MD->
getOperand(
i + 1));
799 TBAAStructTagNode
Tag(MD);
802 if (!
Tag.isNewFormat())
811 ConstantInt *PreviousSize = mdconst::extract<ConstantInt>(NextNodes[3]);
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
@ NoModRef
The access neither references nor modifies the value stored in memory.
This is an optimization pass for GlobalISel generic memory operations.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
static const MDNode * createAccessTag(const MDNode *AccessType)
static MDNode * extendToTBAA(MDNode *TBAA, ssize_t len)
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
ImmutablePass class - This class is used to provide information that does not need to be run.
TypeBasedAAResult run(Function &F, FunctionAnalysisManager &AM)
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
size_type size() const
Determine the number of elements in the SetVector.
const APInt & getValue() const
Return the constant as an APInt value reference.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
The instances of the Type class are immutable: once they are created, they are never changed.
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.
A simple AA result that uses TBAA metadata to answer queries.
The possible results of an alias query.
static bool hasField(TBAAStructTypeNode BaseType, TBAAStructTypeNode FieldType)
MDNode * Scope
The tag for alias scope specification (used with noalias).
@ FMRB_UnknownModRefBehavior
This indicates that the function could not be classified into one of the behaviors above.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
bool doInitialization(Module &M) override
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null,...
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
op_range operands() const
unsigned getNumOperands() const
Return number of MDNode operands.
static MDNode * shiftTBAA(MDNode *M, size_t off)
This class stores info we want to provide to or retain within an alias query.
AAMDNodes AATags
The metadata nodes which describes the aliasing of the location (each member is null if that kind of ...
This is the shared class of boolean and integer constants.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Represent the analysis usage information of a pass.
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...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI)
const MDOperand & getOperand(unsigned I) const
Legacy wrapper pass to provide the TypeBasedAAResult object.
static const MDNode * getLeastCommonType(const MDNode *A, const MDNode *B)
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
static MDNode * intersect(MDNode *A, MDNode *B)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
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...
A special type used by analysis passes to provide an address that identifies that particular analysis...
initializer< Ty > init(const Ty &Val)
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI)
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator==(uint64_t V1, const APInt &V2)
ImmutablePass * createTypeBasedAAWrapperPass()
A Module instance is used to store all the information related to an LLVM module.
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
bool insert(const value_type &X)
Insert a new element into the SetVector.
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
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.
void initializeTypeBasedAAWrapperPassPass(PassRegistry &)
AAMDNodes merge(const AAMDNodes &Other) const
Given two sets of AAMDNodes applying to potentially different locations, determine the best AAMDNodes...
static const Function * getParent(const Value *V)
@ FMRB_OnlyReadsMemory
This function does not perform any non-local stores or volatile loads, but may read from any memory l...
@ NoAlias
The two locations do not alias at all.
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
FunctionModRefBehavior
Summary of how a function affects memory in the program.
bool isTBAAVtableAccess() const
Check whether MDNode is a vtable access.
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
LLVMContext & getContext() const
INITIALIZE_PASS(TypeBasedAAWrapperPass, "tbaa", "Type-Based Alias Analysis", false, true) ImmutablePass *llvm
void setPreservesAll()
Set by analyses that do not transform their input at all.
MDNode * NoAlias
The tag specifying the noalias scope.
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.
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal)
MDNode * TBAA
The tag for type-based alias analysis.
AAMDNodes concat(const AAMDNodes &Other) const
Determine the best AAMDNodes after concatenating two different locations together.
bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
A SetVector that performs no allocations if smaller than a certain size.
A container for analyses that lazily runs them and caches their results.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
static cl::opt< bool > EnableTBAA("enable-tbaa", cl::init(true), cl::Hidden)
unsigned M1(unsigned Val)
static MDNode * shiftTBAAStruct(MDNode *M, size_t off)
static MemAccessTy getAccessType(const TargetTransformInfo &TTI, Instruction *Inst, Value *OperandVal)
Return the type of the memory being accessed.
Representation for a specific memory location.
Optional< std::vector< StOtherPiece > > Other