17 #ifndef LLVM_ANALYSIS_ALIASSETTRACKER_H
18 #define LLVM_ANALYSIS_ALIASSETTRACKER_H
32 class AliasSetTracker;
40 PointerRec **PrevInList, *NextInList;
46 : Val(V), PrevInList(0), NextInList(0), AS(0), Size(0),
49 Value *getValue()
const {
return Val; }
51 PointerRec *getNext()
const {
return NextInList; }
52 bool hasAliasSet()
const {
return AS != 0; }
54 PointerRec** setPrevInList(PointerRec **PIL) {
59 void updateSizeAndTBAAInfo(uint64_t NewSize,
const MDNode *NewTBAAInfo) {
60 if (NewSize > Size) Size = NewSize;
62 if (TBAAInfo == DenseMapInfo<const MDNode *>::getEmptyKey())
64 TBAAInfo = NewTBAAInfo;
65 else if (TBAAInfo != NewTBAAInfo)
67 TBAAInfo = DenseMapInfo<const MDNode *>::getTombstoneKey();
70 uint64_t getSize()
const {
return Size; }
74 const MDNode *getTBAAInfo()
const {
76 if (TBAAInfo == DenseMapInfo<const MDNode *>::getEmptyKey() ||
77 TBAAInfo == DenseMapInfo<const MDNode *>::getTombstoneKey())
83 assert(AS &&
"No AliasSet yet!");
86 AS = OldAS->getForwardedTarget(AST);
93 void setAliasSet(AliasSet *as) {
94 assert(AS == 0 &&
"Already have an alias set!");
98 void eraseFromList() {
99 if (NextInList) NextInList->PrevInList = PrevInList;
100 *PrevInList = NextInList;
101 if (AS->PtrListEnd == &NextInList) {
102 AS->PtrListEnd = PrevInList;
103 assert(*AS->PtrListEnd == 0 &&
"List not terminated right!");
109 PointerRec *PtrList, **PtrListEnd;
113 std::vector<AssertingVH<Instruction> > UnknownInsts;
117 unsigned RefCount : 28;
125 NoModRef = 0, Refs = 1,
128 unsigned AccessTy : 2;
134 MustAlias = 0, MayAlias = 1
136 unsigned AliasTy : 1;
141 void addRef() { ++RefCount; }
143 assert(RefCount >= 1 &&
"Invalid reference count detected!");
145 removeFromTracker(AST);
148 Instruction *getUnknownInst(
unsigned i)
const {
149 assert(i < UnknownInsts.size());
150 return UnknownInsts[i];
155 bool isRef()
const {
return AccessTy & Refs; }
156 bool isMod()
const {
return AccessTy & Mods; }
177 bool empty()
const {
return PtrList == 0; }
183 class iterator :
public std::iterator<std::forward_iterator_tag,
184 PointerRec, ptrdiff_t> {
187 explicit iterator(PointerRec *CN = 0) : CurNode(CN) {}
190 return CurNode == x.CurNode;
200 assert(CurNode &&
"Dereferencing AliasSet.end()!");
206 uint64_t
getSize()
const {
return CurNode->getSize(); }
210 assert(CurNode &&
"Advancing past AliasSet.end()!");
211 CurNode = CurNode->getNext();
215 iterator tmp = *
this; ++*
this;
return tmp;
223 AliasSet() : PtrList(0), PtrListEnd(&PtrList), Forward(0), RefCount(0),
224 AccessTy(NoModRef), AliasTy(MustAlias), Volatile(
false) {
230 PointerRec *getSomePointer()
const {
238 if (!Forward)
return this;
240 AliasSet *Dest = Forward->getForwardedTarget(AST);
241 if (Dest != Forward) {
243 Forward->dropRef(AST);
251 void addPointer(
AliasSetTracker &AST, PointerRec &Entry, uint64_t Size,
252 const MDNode *TBAAInfo,
253 bool KnownMustAlias =
false);
255 void removeUnknownInst(Instruction *
I) {
256 for (
size_t i = 0, e = UnknownInsts.size(); i != e; ++i)
257 if (UnknownInsts[i] == I) {
258 UnknownInsts[i] = UnknownInsts.back();
259 UnknownInsts.pop_back();
263 void setVolatile() { Volatile =
true; }
269 bool aliasesPointer(
const Value *Ptr, uint64_t Size,
const MDNode *TBAAInfo,
285 virtual void deleted();
286 virtual void allUsesReplacedWith(
Value *);
289 ASTCallbackVH &operator=(
Value *V);
293 struct ASTCallbackVHDenseMapInfo :
public DenseMapInfo<Value *> {};
298 typedef DenseMap<ASTCallbackVH, AliasSet::PointerRec*,
299 ASTCallbackVHDenseMapInfo>
337 bool remove(
Value *Ptr, uint64_t Size,
const MDNode *TBAAInfo);
363 return findAliasSetForPointer(P, Size, TBAAInfo);
409 AliasSet::PointerRec &getEntryFor(
Value *V) {
410 AliasSet::PointerRec *&Entry = PointerMap[ASTCallbackVH(V,
this)];
412 Entry =
new AliasSet::PointerRec(V);
417 AliasSet::AccessType E,
424 AliasSet *findAliasSetForPointer(
const Value *Ptr, uint64_t Size,
425 const MDNode *TBAAInfo);
427 AliasSet *findAliasSetForUnknownInst(Instruction *Inst);
bool operator==(const iterator &x) const
void mergeSetIn(AliasSet &AS, AliasSetTracker &AST)
bool operator!=(const iterator &x) const
bool isForwardingAliasSet() const
const ilist< AliasSet > & getAliasSets() const
Define an iterator for alias sets... this is just a forward iterator.
ilist< AliasSet >::const_iterator const_iterator
MDNode - a tuple of other values.
LoopInfoBase< BlockT, LoopT > * LI
const_iterator end() const
const iterator & operator=(const iterator &I)
AliasSet * getAliasSetForPointerIfExists(Value *P, uint64_t Size, const MDNode *TBAAInfo)
const_iterator begin() const
bool isRef() const
Accessors...
friend class AliasSetTracker
value_type * operator->() const
bool containsPointer(Value *P, uint64_t Size, const MDNode *TBAAInfo) const
const MDNode * getTBAAInfo() const
LLVM Basic Block Representation.
bool aliasesUnknownInst(Instruction *Inst, AliasAnalysis &AA) const
AliasSetTracker(AliasAnalysis &aa)
void print(raw_ostream &OS) const
bool removeUnknown(Instruction *I)
AliasAnalysis & getAliasAnalysis() const
void copyValue(Value *From, Value *To)
iterator(PointerRec *CN=0)
#define LLVM_DELETED_FUNCTION
AliasSet & getAliasSetForPointer(Value *P, uint64_t Size, const MDNode *TBAAInfo, bool *New=0)
void print(raw_ostream &OS) const
ilist< AliasSet >::iterator iterator
Value * getPointer() const
bool addUnknown(Instruction *I)
value_type & operator*() const
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
bool add(Value *Ptr, uint64_t Size, const MDNode *TBAAInfo)
LLVM Value Representation.
bool aliasesPointer(const Value *Ptr, uint64_t Size, const MDNode *TBAAInfo, AliasAnalysis &AA) const
void deleteValue(Value *PtrVal)