Alberto Barbaro via llvm-dev
2018-Dec-12 23:05 UTC
[llvm-dev] How to get the destination in a LoadInst
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 :) Thanks again On Wed, Dec 12, 2018, 22:41 Michael Kruse <llvmdev at meinersbur.de wrote:> Am Mi., 12. Dez. 2018 um 12:24 Uhr schrieb Alberto Barbaro via > llvm-dev <llvm-dev at lists.llvm.org>: > > I have %5 = load i32, i32* %3, align 4 LoadInst and I would like to get > reference to the destination ( in this case %5 ). How can I do that? > > Once you have a 'reference to %5' what do you intend to do with it? > This might help to understand question. > > Michael >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181212/88b5fea3/attachment.html>
Michael Kruse via llvm-dev
2018-Dec-12 23:28 UTC
[llvm-dev] How to get the destination in a LoadInst
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
Alberto Barbaro via llvm-dev
2018-Dec-13 06:54 UTC
[llvm-dev] How to get the destination in a LoadInst
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>