Search for other instructions that depend on an instruction using LLVM API

Hello, I have a question that I would appreciate if you could answer.

I would like to know if there is an API in LLVM that allows me to search for other instructions that depend on an instruction. For example, I would like to know what instruction uses the result loaded by a LOAD instruction. We assume the following IR.

%16 = load i16, i16* %14, align 2, !tbaa !4
%17 = add nuw nsw i64 %16, 1
%18 = mul i16, %17, %16

I want to do like the following.

Instruction* LoadInstruction = ~~  // %16
std::vector<Instruction*> DI = Function(LoadInstruction);  // DI = [%17, %18]

What LLVM API should I use to do something like Function() above? Or do I have to implement it by myself?

This information is really important for many optimizations so LLVM maintains a list to query it. You get at it from the Value::users API (or associated iterators), since Instruction is a subclass of Value.

I didn’t know until you told me about it.
Thank you!