Since Instruction
is derived from Value
it inherits both functions users
and uses
. The difference is that a user of Value
has the Value
as one of its operands.
When you are calling uses
you get a list of all Use
instances holding a reference from the Value
to each of the users of the particular Value
. Calling users
gives you a list of User
directly. The following code shows how to use users
and uses
.
for(auto U : V->users()){ // U is of type User*
if (auto I = dyn_cast<Instruction>(U)){
// an instruction uses V
}
}
You can see users
as a shortcut because you can do the same with uses:
for(auto U : V->uses()){ // U is of type Use*
if (auto I = dyn_cast<Instruction>(U.getUser())){
// an instruction uses V
}
}
Commonly it is enough to use users
to get all dependencies of a Value
.
All Values used by a Value
are the operands. This direction of dependency is not part of a Value
's use list.
To the second question regarding instructions producing a value: there is no guarantee that the absence of uses results from not producing a value. A dead instruction can produce a value and has no users. Additionally, an instruction not producing a value can be used by metadata .