17 #ifndef LLVM_ANALYSIS_ALIASSETTRACKER_H
18 #define LLVM_ANALYSIS_ALIASSETTRACKER_H
34 class AliasSetTracker;
42 PointerRec **PrevInList, *NextInList;
49 : Val(V), PrevInList(nullptr), NextInList(nullptr), AS(nullptr),
Size(0),
52 Value *getValue()
const {
return Val; }
54 PointerRec *getNext()
const {
return NextInList; }
55 bool hasAliasSet()
const {
return AS !=
nullptr; }
57 PointerRec** setPrevInList(PointerRec **PIL) {
62 bool updateSizeAndAAInfo(uint64_t NewSize,
const AAMDNodes &NewAAInfo) {
63 bool SizeChanged =
false;
73 AAMDNodes Intersection(AAInfo.intersect(NewAAInfo));
79 AAInfo = Intersection;
84 uint64_t getSize()
const {
return Size; }
88 AAMDNodes getAAInfo()
const {
97 assert(AS &&
"No AliasSet yet!");
100 AS = OldAS->getForwardedTarget(AST);
107 void setAliasSet(AliasSet *as) {
108 assert(!AS &&
"Already have an alias set!");
112 void eraseFromList() {
113 if (NextInList) NextInList->PrevInList = PrevInList;
114 *PrevInList = NextInList;
115 if (AS->PtrListEnd == &NextInList) {
116 AS->PtrListEnd = PrevInList;
117 assert(*AS->PtrListEnd ==
nullptr &&
"List not terminated right!");
124 PointerRec *PtrList, **PtrListEnd;
132 std::vector<WeakVH> UnknownInsts;
136 unsigned RefCount : 27;
140 unsigned AliasAny : 1;
152 ModRefAccess = RefAccess | ModAccess
163 SetMustAlias = 0, SetMayAlias = 1
168 unsigned Volatile : 1;
172 void addRef() { ++RefCount; }
175 assert(RefCount >= 1 &&
"Invalid reference count detected!");
177 removeFromTracker(AST);
180 Instruction *getUnknownInst(
unsigned i)
const {
181 assert(i < UnknownInsts.size());
182 return cast_or_null<Instruction>(UnknownInsts[i]);
187 bool isRef()
const {
return Access & RefAccess; }
188 bool isMod()
const {
return Access & ModAccess; }
207 bool empty()
const {
return PtrList ==
nullptr; }
211 unsigned size() {
return SetSize; }
217 class iterator :
public std::iterator<std::forward_iterator_tag,
218 PointerRec, ptrdiff_t> {
222 explicit iterator(PointerRec *CN =
nullptr) : CurNode(CN) {}
225 return CurNode == x.CurNode;
230 assert(CurNode &&
"Dereferencing AliasSet.end()!");
236 uint64_t
getSize()
const {
return CurNode->getSize(); }
240 assert(CurNode &&
"Advancing past AliasSet.end()!");
241 CurNode = CurNode->getNext();
245 iterator tmp = *
this; ++*
this;
return tmp;
252 : PtrList(nullptr), PtrListEnd(&PtrList), Forward(nullptr), RefCount(0),
253 AliasAny(
false), Access(NoAccess), Alias(SetMustAlias),
254 Volatile(
false), SetSize(0) {}
256 AliasSet(
const AliasSet &AS) =
delete;
257 void operator=(
const AliasSet &AS) =
delete;
259 PointerRec *getSomePointer()
const {
267 if (!Forward)
return this;
269 AliasSet *Dest = Forward->getForwardedTarget(AST);
270 if (Dest != Forward) {
272 Forward->dropRef(AST);
281 const AAMDNodes &AAInfo,
282 bool KnownMustAlias =
false);
285 bool WasEmpty = UnknownInsts.empty();
286 for (
size_t i = 0, e = UnknownInsts.size(); i != e; ++i)
287 if (UnknownInsts[i] == I) {
288 UnknownInsts[i] = UnknownInsts.back();
289 UnknownInsts.pop_back();
292 if (!WasEmpty && UnknownInsts.empty())
295 void setVolatile() { Volatile =
true; }
313 class ASTCallbackVH final :
public CallbackVH {
315 void deleted()
override;
316 void allUsesReplacedWith(
Value *)
override;
320 ASTCallbackVH &operator=(
Value *V);
324 struct ASTCallbackVHDenseMapInfo :
public DenseMapInfo<Value *> {};
329 typedef DenseMap<ASTCallbackVH, AliasSet::PointerRec*,
330 ASTCallbackVHDenseMapInfo>
340 : AA(aa), TotalMayAliasSetSize(0), AliasAnyAS(nullptr) {}
382 return mergeAliasSetsForPointer(P, Size, AAInfo);
420 unsigned TotalMayAliasSetSize;
430 AliasSet::PointerRec &getEntryFor(
Value *V) {
431 AliasSet::PointerRec *&Entry = PointerMap[ASTCallbackVH(V,
this)];
433 Entry =
new AliasSet::PointerRec(V);
438 AliasSet::AccessLattice
E);
bool operator==(const iterator &x) const
void mergeSetIn(AliasSet &AS, AliasSetTracker &AST)
Merge the specified alias set into this alias set.
bool operator!=(const iterator &x) const
bool isForwardingAliasSet() const
Return true if this alias set should be ignored as part of the AliasSetTracker object.
AAResults AliasAnalysis
Temporary typedef for legacy code that uses a generic AliasAnalysis pointer or reference.
const ilist< AliasSet > & getAliasSets() const
Return the alias sets that are active.
Define an iterator for alias sets... this is just a forward iterator.
This class wraps the llvm.memset intrinsic.
ilist< AliasSet >::const_iterator const_iterator
An instruction for reading from memory.
static AAMDNodes getEmptyKey()
const_iterator end() const
bool aliasesPointer(const Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo, AliasAnalysis &AA) const
Return true if the specified pointer "may" (or must) alias one of the members in the set...
const_iterator begin() const
bool isRef() const
Accessors...
friend class AliasSetTracker
value_type * operator->() const
An instruction for storing to memory.
bool aliasesUnknownInst(const Instruction *Inst, AliasAnalysis &AA) const
Function Alias Analysis false
LLVM Basic Block Representation.
bool isVolatile() const
Return true if this alias set contains volatile loads or stores.
AliasSetTracker(AliasAnalysis &aa)
Create an empty collection of AliasSets, and use the specified alias analysis object to disambiguate ...
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
void print(raw_ostream &OS) const
An intrusive list with ownership and callbacks specified/controlled by ilist_traits, only with API safe for polymorphic types.
AliasSet * getAliasSetForPointerIfExists(const Value *P, uint64_t Size, const AAMDNodes &AAInfo)
Return the alias set containing the location specified if one exists, otherwise return null...
Iterator for intrusive lists based on ilist_node.
AliasAnalysis & getAliasAnalysis() const
Return the underlying alias analysis object used by this tracker.
void copyValue(Value *From, Value *To)
This method should be used whenever a preexisting value in the program is copied or cloned...
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
bool containsUnknown(const Instruction *I) const
Return true if the specified instruction "may" (or must) alias one of the members in any of the sets...
void add(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo)
These methods are used to add different types of instructions to the alias sets.
void print(raw_ostream &OS) const
AAMDNodes getAAInfo() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
ilist< AliasSet >::iterator iterator
Value * getPointer() const
This class wraps the llvm.memcpy/memmove intrinsics.
AliasSet & getAliasSetForPointer(Value *P, uint64_t Size, const AAMDNodes &AAInfo)
Return the alias set that the specified pointer lives in.
static AAMDNodes getTombstoneKey()
value_type & operator*() const
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
iterator(PointerRec *CN=nullptr)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
Value handle with callbacks on RAUW and destruction.
void addUnknown(Instruction *I)
void deleteValue(Value *PtrVal)
This method is used to remove a pointer value from the AliasSetTracker entirely.