[llvm-dev] Difference between “uses” and “user”

Carlos Alba via llvm-dev llvm-dev at lists.llvm.org
Wed Feb 17 02:03:54 PST 2016


So, according to your explanation, do you think that it is possible to get
the value produced by an instruction? something like the following
(roughly):

for(auto operand : instruction->getOperandList())
      if( operand -> getUser == instruction )
           return true;
      else
           continue;

Best,
Carlo


On Tue, Feb 16, 2016 at 1:01 PM, Michael Kruse <llvmdev at meinersbur.de>
wrote:

> 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
> llvm::Value itself
>
> 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
> "1")
> 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.
>
> Michael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160217/149ca9c1/attachment.html>


More information about the llvm-dev mailing list