Index: llvm/include/llvm/Analysis/MemoryLocation.h =================================================================== --- llvm/include/llvm/Analysis/MemoryLocation.h +++ llvm/include/llvm/Analysis/MemoryLocation.h @@ -216,6 +216,10 @@ /// The address of the start of the location. const Value *Ptr; + /// The provenance of the location. A nullptr or a ConstantPointerNull + /// indicate that the provenance can be from anywhere. + const Value *PtrProvenance = nullptr; + /// The maximum size of the location, in address-units, or /// UnknownSize if the size is not known. /// @@ -229,7 +233,14 @@ /// member is null if that kind of information is unavailable). AAMDNodes AATags; - void print(raw_ostream &OS) const { OS << *Ptr << " " << Size << "\n"; } + void print(raw_ostream &OS) const { + OS << *Ptr; + if (PtrProvenance) + OS << "(" << *PtrProvenance << ") "; + else + OS << "(nullptr) "; + OS << Size << "\n"; + } /// Return a location with information about the memory reference by the given /// instruction. @@ -283,11 +294,17 @@ } MemoryLocation() - : Ptr(nullptr), Size(LocationSize::beforeOrAfterPointer()), AATags() {} + : Ptr(nullptr), PtrProvenance(nullptr), + Size(LocationSize::beforeOrAfterPointer()), AATags() {} explicit MemoryLocation(const Value *Ptr, LocationSize Size, const AAMDNodes &AATags = AAMDNodes()) - : Ptr(Ptr), Size(Size), AATags(AATags) {} + : Ptr(Ptr), PtrProvenance(Ptr), Size(Size), AATags(AATags) {} + + explicit MemoryLocation(const Value *Ptr, const Value *PtrProvenance, + LocationSize Size, + const AAMDNodes &AATags = AAMDNodes()) + : Ptr(Ptr), PtrProvenance(PtrProvenance), Size(Size), AATags(AATags) {} MemoryLocation getWithNewPtr(const Value *NewPtr) const { MemoryLocation Copy(*this); @@ -295,6 +312,12 @@ return Copy; } + MemoryLocation getWithNewPtrProvenance(const Value *NewPtrProvenance) const { + MemoryLocation Copy(*this); + Copy.PtrProvenance = NewPtrProvenance; + return Copy; + } + MemoryLocation getWithNewSize(LocationSize NewSize) const { MemoryLocation Copy(*this); Copy.Size = NewSize; @@ -308,7 +331,8 @@ } bool operator==(const MemoryLocation &Other) const { - return Ptr == Other.Ptr && Size == Other.Size && AATags == Other.AATags; + return Ptr == Other.Ptr && PtrProvenance == Other.PtrProvenance && + Size == Other.Size && AATags == Other.AATags; } }; @@ -331,14 +355,17 @@ template <> struct DenseMapInfo { static inline MemoryLocation getEmptyKey() { return MemoryLocation(DenseMapInfo::getEmptyKey(), + DenseMapInfo::getEmptyKey(), DenseMapInfo::getEmptyKey()); } static inline MemoryLocation getTombstoneKey() { return MemoryLocation(DenseMapInfo::getTombstoneKey(), + DenseMapInfo::getTombstoneKey(), DenseMapInfo::getTombstoneKey()); } static unsigned getHashValue(const MemoryLocation &Val) { return DenseMapInfo::getHashValue(Val.Ptr) ^ + DenseMapInfo::getHashValue(Val.PtrProvenance) ^ DenseMapInfo::getHashValue(Val.Size) ^ DenseMapInfo::getHashValue(Val.AATags); } Index: llvm/lib/Analysis/MemoryLocation.cpp =================================================================== --- llvm/lib/Analysis/MemoryLocation.cpp +++ llvm/lib/Analysis/MemoryLocation.cpp @@ -41,6 +41,7 @@ return MemoryLocation( LI->getPointerOperand(), + LI->getPtrProvenance(), LocationSize::precise(DL.getTypeStoreSize(LI->getType())), AATags); } @@ -50,6 +51,7 @@ const auto &DL = SI->getModule()->getDataLayout(); return MemoryLocation(SI->getPointerOperand(), + SI->getPtrProvenance(), LocationSize::precise(DL.getTypeStoreSize( SI->getValueOperand()->getType())), AATags);