Retrieving DbgInfoIntrinsics for a given value


If I have an llvm value “<16 x float> addrspace(1)* %in”, and in the LLVM IR, there is a @llvm.dbg.value like:

call void @llvm.dbg.value(metadata <16 x float> addrspace(1)* %in, i64 0, metadata !216, metadata !28), !dbg !217

How I can retrieve this @llvm.dbg.value when I have “%in”?

Since Metadata is not a part of the uselist anymore, is there some way rather than iterate over every instructions in the function to get this @llvm.dbg.value?


Check out llvm::findDbgValues:

void llvm::findDbgValues(SmallVectorImpl<DbgValueInst *> &DbgValues, Value *V) {
if (auto *L = LocalAsMetadata::getIfExists(V))
if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L))
for (User *U : MDV->users())
if (DbgValueInst *DVI = dyn_cast(U))

Basically, there is a DenseMap of all values used by debug intrinsics in the LLVM context.

Thanks, this is very useful