Index: llvm/include/llvm/Analysis/MemoryLocation.h =================================================================== --- llvm/include/llvm/Analysis/MemoryLocation.h +++ llvm/include/llvm/Analysis/MemoryLocation.h @@ -16,9 +16,9 @@ #define LLVM_ANALYSIS_MEMORYLOCATION_H #include "llvm/ADT/DenseMapInfo.h" +#include "llvm/ADT/Hashing.h" #include "llvm/IR/Metadata.h" #include "llvm/Support/TypeSize.h" - #include namespace llvm { @@ -218,6 +218,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. /// @@ -231,7 +235,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. @@ -286,11 +297,18 @@ return T.isScalable() ? UnknownSize : T.getFixedValue(); } - MemoryLocation() : Ptr(nullptr), Size(LocationSize::beforeOrAfterPointer()) {} + MemoryLocation() + : Ptr(nullptr), PtrProvenance(nullptr), + Size(LocationSize::beforeOrAfterPointer()) {} 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); @@ -298,6 +316,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; @@ -311,7 +335,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; } }; @@ -334,16 +359,19 @@ 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.Size) ^ - DenseMapInfo::getHashValue(Val.AATags); + return DenseMapInfo::getHashValue(static_cast( + llvm::hash_combine(Val.Ptr, Val.PtrProvenance, + DenseMapInfo::getHashValue(Val.Size), + DenseMapInfo::getHashValue(Val.AATags)))); } static bool isEqual(const MemoryLocation &LHS, const MemoryLocation &RHS) { return LHS == RHS; Index: llvm/lib/Analysis/MemoryLocation.cpp =================================================================== --- llvm/lib/Analysis/MemoryLocation.cpp +++ llvm/lib/Analysis/MemoryLocation.cpp @@ -37,7 +37,7 @@ const auto &DL = LI->getModule()->getDataLayout(); return MemoryLocation( - LI->getPointerOperand(), + LI->getPointerOperand(), LI->getPtrProvenance(), LocationSize::precise(DL.getTypeStoreSize(LI->getType())), LI->getAAMetadata()); } @@ -45,7 +45,7 @@ MemoryLocation MemoryLocation::get(const StoreInst *SI) { const auto &DL = SI->getModule()->getDataLayout(); - return MemoryLocation(SI->getPointerOperand(), + return MemoryLocation(SI->getPointerOperand(), SI->getPtrProvenance(), LocationSize::precise(DL.getTypeStoreSize( SI->getValueOperand()->getType())), SI->getAAMetadata());