[llvm-dev] How to get the destination in a LoadInst

Alberto Barbaro via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 12 22:54:03 PST 2018


Thanks Michael,
Indeed as you said the Instruction.getName() returns an empty string. I
think I should have mentioned that I'm trying to print it from the
visitLoadInst() method of my class that extends Interpreter.

Anyway I'll try as you suggested and get back to you.

Thanks again


On Wed, Dec 12, 2018, 23:29 Michael Kruse <llvmdev at meinersbur.de wrote:

> Am Mi., 12. Dez. 2018 um 17:05 Uhr schrieb Alberto Barbaro
> <barbaro.alberto at gmail.com>:
> > Thanks Joshua and Michael,
> > Just to to clarify, I'm experimenting with the Interpreter class and
> observing the instructions that are executed by it. Just for becoming more
> confident with LLVM in general I'd like for each instruction to access to
> the various parts of it. In this instance I would like to access to the
> %Name that is shown in the textual representation. When I call
> Instruction.dump() all is printed correctly so I thought there was a way to
> get the %Name ( in my case 5). So my final goal is to obtain it. I
> understand that is dinamically generated based on. The execution but I
> think that in my case I could access to it. Am I wrong? I hope now all is
> more clear :)
>
> As Joshua and others already explained, the instruction and the value
> it computes are both the same object: the 'Instruction' you are
> calling dump() on. For instance, to enumerate where this values is
> used, try:
>
>     for (auto &U : Instruction.uses()) { ... }
>
> If you want the name of the value/instruction as string, as it appears
> on stdout when calling Instruction::dump()?
>
> Short version: Use Instruction.getName()
>
> Long version: In you example, getName() will return the empty string,
> i.e. it has no name. There is some disambiguation going on to print
> unique names. You can get the uniqued name using
> Instruction.printAsOperand(). You will have to pass a string stream
> (such as llvm::raw_string_ostream) and extract the string using
> raw_string_ostream::str().
>
> Michael
>
> Michael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181213/032308b2/attachment.html>


More information about the llvm-dev mailing list