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

Michael Kruse via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 12 15:28:57 PST 2018


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


More information about the llvm-dev mailing list