[PATCH] D107357: [getUnderlyingObject] support ptr_provenance
Jeroen Dobbelaere via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 29 06:04:50 PDT 2022
jeroen.dobbelaere updated this revision to Diff 440972.
jeroen.dobbelaere added a comment.
Rebased to ffe262a198a9f9030991df6d3ddd812e74fa3523 <https://reviews.llvm.org/rGffe262a198a9f9030991df6d3ddd812e74fa3523>
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107357/new/
https://reviews.llvm.org/D107357
Files:
llvm/include/llvm/Analysis/ValueTracking.h
llvm/lib/Analysis/ValueTracking.cpp
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -4447,7 +4447,8 @@
return true;
}
-const Value *llvm::getUnderlyingObject(const Value *V, unsigned MaxLookup) {
+const Value *llvm::getUnderlyingObject(const Value *V, unsigned MaxLookup,
+ bool FollowProvenance) {
if (!V->getType()->isPointerTy())
return V;
for (unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
@@ -4470,6 +4471,11 @@
continue;
}
} else if (auto *Call = dyn_cast<CallBase>(V)) {
+ if (Call->getIntrinsicID() == Intrinsic::experimental_ptr_provenance) {
+ V = Call->getArgOperand(FollowProvenance ? 1 : 0);
+ continue;
+ }
+
// CaptureTracking can know about special capturing properties of some
// intrinsics like launder.invariant.group, that can't be expressed with
// the attributes, but have properties like returning aliasing pointer.
@@ -4494,13 +4500,14 @@
void llvm::getUnderlyingObjects(const Value *V,
SmallVectorImpl<const Value *> &Objects,
- LoopInfo *LI, unsigned MaxLookup) {
+ LoopInfo *LI, unsigned MaxLookup,
+ bool FollowProvenance) {
SmallPtrSet<const Value *, 4> Visited;
SmallVector<const Value *, 4> Worklist;
Worklist.push_back(V);
do {
const Value *P = Worklist.pop_back_val();
- P = getUnderlyingObject(P, MaxLookup);
+ P = getUnderlyingObject(P, MaxLookup, FollowProvenance);
if (!Visited.insert(P).second)
continue;
Index: llvm/include/llvm/Analysis/ValueTracking.h
===================================================================
--- llvm/include/llvm/Analysis/ValueTracking.h
+++ llvm/include/llvm/Analysis/ValueTracking.h
@@ -368,9 +368,14 @@
/// the specified value, returning the original object being addressed. Note
/// that the returned value has pointer type if the specified value does. If
/// the MaxLookup value is non-zero, it limits the number of instructions to
- /// be stripped off.
- const Value *getUnderlyingObject(const Value *V, unsigned MaxLookup = 6);
- inline Value *getUnderlyingObject(Value *V, unsigned MaxLookup = 6) {
+ /// be stripped off. When FollowProvenance is set, the provenance side of
+ /// llvm.experimental.ptr.provenance is taken. For provenance,
+ /// `UnknownProvenance` indicates that any valid object can be the underlying
+ /// object.
+ const Value *getUnderlyingObject(const Value *V, unsigned MaxLookup = 6,
+ bool FollowProvenance = false);
+ inline Value *getUnderlyingObject(Value *V, unsigned MaxLookup = 6,
+ bool FollowProvenance = false) {
// Force const to avoid infinite recursion.
const Value *VConst = V;
return const_cast<Value *>(getUnderlyingObject(VConst, MaxLookup));
@@ -404,9 +409,12 @@
/// Since A[i] and A[i-1] are independent pointers, getUnderlyingObjects
/// should not assume that Curr and Prev share the same underlying object thus
/// it shouldn't look through the phi above.
+ /// When FollowProvenance is set, the provenance side of
+ /// llvm.experimental.ptr.provenance is taken.
void getUnderlyingObjects(const Value *V,
SmallVectorImpl<const Value *> &Objects,
- LoopInfo *LI = nullptr, unsigned MaxLookup = 6);
+ LoopInfo *LI = nullptr, unsigned MaxLookup = 6,
+ bool FollowProvenance = false);
/// This is a wrapper around getUnderlyingObjects and adds support for basic
/// ptrtoint+arithmetic+inttoptr sequences.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107357.440972.patch
Type: text/x-patch
Size: 3902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220629/87151c57/attachment.bin>
More information about the llvm-commits
mailing list