17 #ifndef LLVM_ANALYSIS_ALIASSETTRACKER_H
18 #define LLVM_ANALYSIS_ALIASSETTRACKER_H
33 class AliasSetTracker;
41 PointerRec **PrevInList, *NextInList;
47 : Val(V), PrevInList(nullptr), NextInList(nullptr), AS(nullptr), Size(0),
50 Value *getValue()
const {
return Val; }
52 PointerRec *getNext()
const {
return NextInList; }
53 bool hasAliasSet()
const {
return AS !=
nullptr; }
55 PointerRec** setPrevInList(PointerRec **PIL) {
60 void updateSizeAndAAInfo(uint64_t NewSize,
const AAMDNodes &NewAAInfo) {
61 if (NewSize > Size) Size = NewSize;
66 else if (AAInfo != NewAAInfo)
71 uint64_t getSize()
const {
return Size; }
75 AAMDNodes getAAInfo()
const {
84 assert(AS &&
"No AliasSet yet!");
87 AS = OldAS->getForwardedTarget(AST);
94 void setAliasSet(AliasSet *as) {
95 assert(!AS &&
"Already have an alias set!");
99 void eraseFromList() {
100 if (NextInList) NextInList->PrevInList = PrevInList;
101 *PrevInList = NextInList;
102 if (AS->PtrListEnd == &NextInList) {
103 AS->PtrListEnd = PrevInList;
104 assert(*AS->PtrListEnd ==
nullptr &&
"List not terminated right!");
110 PointerRec *PtrList, **PtrListEnd;
114 std::vector<AssertingVH<Instruction> > UnknownInsts;
118 unsigned RefCount : 28;
130 ModRefAccess = RefAccess | ModAccess
141 SetMustAlias = 0, SetMayAlias = 1
148 void addRef() { ++RefCount; }
150 assert(RefCount >= 1 &&
"Invalid reference count detected!");
152 removeFromTracker(AST);
155 Instruction *getUnknownInst(
unsigned i)
const {
156 assert(i < UnknownInsts.size());
157 return UnknownInsts[i];
162 bool isRef()
const {
return Access & RefAccess; }
163 bool isMod()
const {
return Access & ModAccess; }
184 bool empty()
const {
return PtrList ==
nullptr; }
190 class iterator :
public std::iterator<std::forward_iterator_tag,
191 PointerRec, ptrdiff_t> {
194 explicit iterator(PointerRec *CN =
nullptr) : CurNode(CN) {}
197 return CurNode == x.CurNode;
202 assert(CurNode &&
"Dereferencing AliasSet.end()!");
208 uint64_t
getSize()
const {
return CurNode->getSize(); }
212 assert(CurNode &&
"Advancing past AliasSet.end()!");
213 CurNode = CurNode->getNext();
217 iterator tmp = *
this; ++*
this;
return tmp;
226 : PtrList(nullptr), PtrListEnd(&PtrList), Forward(nullptr), RefCount(0),
227 Access(NoAccess), Alias(SetMustAlias), Volatile(
false) {
231 void operator=(
const AliasSet &AS) =
delete;
233 PointerRec *getSomePointer()
const {
241 if (!Forward)
return this;
243 AliasSet *Dest = Forward->getForwardedTarget(AST);
244 if (Dest != Forward) {
246 Forward->dropRef(AST);
254 void addPointer(
AliasSetTracker &AST, PointerRec &Entry, uint64_t Size,
255 const AAMDNodes &AAInfo,
256 bool KnownMustAlias =
false);
259 bool WasEmpty = UnknownInsts.empty();
260 for (
size_t i = 0, e = UnknownInsts.size(); i != e; ++i)
261 if (UnknownInsts[i] == I) {
262 UnknownInsts[i] = UnknownInsts.back();
263 UnknownInsts.pop_back();
266 if (!WasEmpty && UnknownInsts.empty())
269 void setVolatile() { Volatile =
true; }
275 bool aliasesPointer(
const Value *Ptr, uint64_t Size,
const AAMDNodes &AAInfo,
291 void deleted()
override;
292 void allUsesReplacedWith(
Value *)
override;
295 ASTCallbackVH &operator=(
Value *V);
299 struct ASTCallbackVHDenseMapInfo :
public DenseMapInfo<Value *> {};
304 typedef DenseMap<ASTCallbackVH, AliasSet::PointerRec*,
305 ASTCallbackVHDenseMapInfo>
363 bool *New =
nullptr);
369 return findAliasSetForPointer(P, Size, AAInfo);
420 AliasSet::PointerRec &getEntryFor(
Value *V) {
421 AliasSet::PointerRec *&Entry = PointerMap[ASTCallbackVH(V,
this)];
423 Entry =
new AliasSet::PointerRec(V);
428 AliasSet::AccessLattice E,
435 AliasSet *findAliasSetForPointer(
const Value *Ptr, uint64_t Size,
436 const AAMDNodes &AAInfo);
438 AliasSet *findAliasSetForUnknownInst(Instruction *Inst);
bool operator==(const iterator &x) const
void mergeSetIn(AliasSet &AS, AliasSetTracker &AST)
mergeSetIn - Merge the specified alias set into this alias set...
bool operator!=(const iterator &x) const
bool isForwardingAliasSet() const
isForwardingAliasSet - Return true if this alias set should be ignored as part of the AliasSetTracker...
const ilist< AliasSet > & getAliasSets() const
getAliasSets - Return the alias sets that are active.
Define an iterator for alias sets... this is just a forward iterator.
ilist< AliasSet >::const_iterator const_iterator
LoadInst - an instruction for reading from memory.
bool add(Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo)
add methods - These methods are used to add different types of instructions to the alias sets...
AliasSet & getAliasSetForPointer(Value *P, uint64_t Size, const AAMDNodes &AAInfo, bool *New=nullptr)
getAliasSetForPointer - Return the alias set that the specified pointer lives in. ...
static AAMDNodes getEmptyKey()
const_iterator end() const
bool aliasesPointer(const Value *Ptr, uint64_t Size, const AAMDNodes &AAInfo, AliasAnalysis &AA) const
aliasesPointer - Return true if the specified pointer "may" (or must) alias one of the members in the...
const_iterator begin() const
bool isRef() const
Accessors...
friend class AliasSetTracker
value_type * operator->() const
StoreInst - an instruction for storing to memory.
bool aliasesUnknownInst(const Instruction *Inst, AliasAnalysis &AA) const
LLVM Basic Block Representation.
ilist_sentinel_traits - A fragment for template traits for intrusive list that provides default senti...
AliasSetTracker(AliasAnalysis &aa)
AliasSetTracker ctor - Create an empty collection of AliasSets, and use the specified alias analysis ...
VAArgInst - This class represents the va_arg llvm instruction, which returns an argument of the speci...
void print(raw_ostream &OS) const
AliasSet * getAliasSetForPointerIfExists(const Value *P, uint64_t Size, const AAMDNodes &AAInfo)
getAliasSetForPointerIfExists - Return the alias set containing the location specified if one exists...
bool removeUnknown(Instruction *I)
AliasAnalysis & getAliasAnalysis() const
getAliasAnalysis - Return the underlying alias analysis object used by this tracker.
void copyValue(Value *From, Value *To)
copyValue - This method should be used whenever a preexisting value in the program is copied or clone...
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 print(raw_ostream &OS) const
AAMDNodes getAAInfo() const
ilist< AliasSet >::iterator iterator
Value * getPointer() const
bool addUnknown(Instruction *I)
static AAMDNodes getTombstoneKey()
ilist_node - Base class that provides next/prev services for nodes that use ilist_nextprev_traits or ...
value_type & operator*() const
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
iterator(PointerRec *CN=nullptr)
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 deleteValue(Value *PtrVal)
deleteValue method - This method is used to remove a pointer value from the AliasSetTracker entirely...
bool containsPointer(const Value *P, uint64_t Size, const AAMDNodes &AAInfo) const
containsPointer - Return true if the specified location is represented by this alias set...