[llvm-dev] Difference between “uses” and “user”
Michael Kruse via llvm-dev
llvm-dev at lists.llvm.org
Tue Feb 16 04:01:00 PST 2016
2016-02-16 10:24 GMT+01:00 Carlos Alba via llvm-dev <llvm-dev at lists.llvm.org>:
> Hi everyone,
> Instruction and Value classes have "Uses" and "User". What is the difference
> between them?
> I think that "Uses" gives all the instructions/values that a particular
> Value depends on and "User" gives all the instructions/values that depend on
> that particular value. Is that right?
Given as example the instruction %add in
%add = add i32 %1, 1
%sub = sub i32 %add, 1
You can think of an llvm::Use as a tuple (Instruction,ArgumentNo)
Take for example the first argument of the add: (%add,0)
Use::getUser() returns that Instruction (%add)
Use::getOperandNo() returns that ArgumentNo (0)
Use::get() returns the argument itself (%1); llvm::Use operator
overloads may make the llvm::Use appear like it is the argument's
add->operands() enumerates the llvm::Use(s), i.e. (%add,0) for the
first argument (which is "%1") and (%add,1) for the second (which is
add->uses() enumerates where %add is used, i.e. (%sub,0) in this example.
add->users() enumerates only the instructions which use %add, i.e.
%sub in this example (without specifying the ArgumentNo)
llvm::User is a base class of llvm::Instruction that implements the
argument list mechanism (Lists of llvm::Value(s)).
Hope that helps any corrections/additions are welcome.
More information about the llvm-dev