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;
72 else if (AAInfo != NewAAInfo)
79 uint64_t getSize()
const {
return Size; }
83 AAMDNodes getAAInfo()
const {
92 assert(AS &&
"No AliasSet yet!");
95 AS = OldAS->getForwardedTarget(AST);
102 void setAliasSet(AliasSet *as) {
103 assert(!AS &&
"Already have an alias set!");
107 void eraseFromList() {
108 if (NextInList) NextInList->PrevInList = PrevInList;
109 *PrevInList = NextInList;
110 if (AS->PtrListEnd == &NextInList) {
111 AS->PtrListEnd = PrevInList;
112 assert(*AS->PtrListEnd ==
nullptr &&
"List not terminated right!");
119 PointerRec *PtrList, **PtrListEnd;
124 std::vector<AssertingVH<Instruction> > UnknownInsts;
128 unsigned RefCount : 27;
132 unsigned AliasAny : 1;
144 ModRefAccess = RefAccess | ModAccess
155 SetMustAlias = 0, SetMayAlias = 1
160 unsigned Volatile : 1;
164 void addRef() { ++RefCount; }
167 assert(RefCount >= 1 &&
"Invalid reference count detected!");
169 removeFromTracker(AST);
172 Instruction *getUnknownInst(
unsigned i)
const {
173 assert(i < UnknownInsts.size());
174 return UnknownInsts[
i];
179 bool isRef()
const {
return Access & RefAccess; }
180 bool isMod()
const {
return Access & ModAccess; }
199 bool empty()
const {
return PtrList ==
nullptr; }
203 unsigned size() {
return SetSize; }
209 class iterator :
public std::iterator<std::forward_iterator_tag,
210 PointerRec, ptrdiff_t> {
214 explicit iterator(PointerRec *CN =
nullptr) : CurNode(CN) {}
217 return CurNode == x.CurNode;
222 assert(CurNode &&
"Dereferencing AliasSet.end()!");
228 uint64_t
getSize()
const {
return CurNode->getSize(); }
232 assert(CurNode &&
"Advancing past AliasSet.end()!");
233 CurNode = CurNode->getNext();
237 iterator tmp = *
this; ++*
this;
return tmp;
244 : PtrList(nullptr), PtrListEnd(&PtrList), Forward(nullptr), RefCount(0),
245 AliasAny(
false), Access(NoAccess), Alias(SetMustAlias),
246 Volatile(
false), SetSize(0) {}
248 AliasSet(
const AliasSet &AS) =
delete;
249 void operator=(
const AliasSet &AS) =
delete;
251 PointerRec *getSomePointer()
const {
259 if (!Forward)
return this;
261 AliasSet *Dest = Forward->getForwardedTarget(AST);
262 if (Dest != Forward) {
264 Forward->dropRef(AST);
272 void addPointer(
AliasSetTracker &AST, PointerRec &Entry, uint64_t Size,
273 const AAMDNodes &AAInfo,
274 bool KnownMustAlias =
false);
277 bool WasEmpty = UnknownInsts.empty();
278 for (
size_t i = 0, e = UnknownInsts.size(); i != e; ++
i)
279 if (UnknownInsts[i] == I) {
280 UnknownInsts[
i] = UnknownInsts.back();
281 UnknownInsts.pop_back();
284 if (!WasEmpty && UnknownInsts.empty())
287 void setVolatile() { Volatile =
true; }
305 class ASTCallbackVH final :
public CallbackVH {
307 void deleted()
override;
308 void allUsesReplacedWith(
Value *)
override;
312 ASTCallbackVH &operator=(
Value *V);
316 struct ASTCallbackVHDenseMapInfo :
public DenseMapInfo<Value *> {};
321 typedef DenseMap<ASTCallbackVH, AliasSet::PointerRec*,
322 ASTCallbackVHDenseMapInfo>
332 : AA(aa), TotalMayAliasSetSize(0), AliasAnyAS(nullptr) {}
374 return mergeAliasSetsForPointer(P, Size, AAInfo);
412 unsigned TotalMayAliasSetSize;
422 AliasSet::PointerRec &getEntryFor(
Value *V) {
423 AliasSet::PointerRec *&Entry = PointerMap[ASTCallbackVH(V,
this)];
425 Entry =
new AliasSet::PointerRec(V);
430 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
Function Alias Analysis false
An instruction for storing to memory.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
bool aliasesUnknownInst(const Instruction *Inst, AliasAnalysis &AA) const
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
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.