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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev
Hi all,
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?

Thanks

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev
The LoadInst is %5. I'm not sure what you mean by reference though.

On 12/12, Alberto Barbaro via llvm-dev wrote:
> Hi all,
> 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?
>
> Thanks

> _______________________________________________
> LLVM Developers mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


--

Johannes Doerfert
Researcher

Argonne National Laboratory
Lemont, IL 60439, USA

[hidden email]

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

signature.asc (235 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev
Hi,
I would like to get the '5'. I would like to know where the loaded value is stored. I don't know which method I should use of the LoadInst class.

Hope this clarifies

Thanks

On Wed, Dec 12, 2018, 20:37 Doerfert, Johannes Rudolf <[hidden email] wrote:
The LoadInst is %5. I'm not sure what you mean by reference though.

On 12/12, Alberto Barbaro via llvm-dev wrote:
> Hi all,
> 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?
>
> Thanks

> _______________________________________________
> LLVM Developers mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


--

Johannes Doerfert
Researcher

Argonne National Laboratory
Lemont, IL 60439, USA

[hidden email]

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev


> On Dec 12, 2018, at 13:57, Alberto Barbaro via llvm-dev <[hidden email]> wrote:
>
> Hi,
> I would like to get the '5'. I would like to know where the loaded value is stored. I don't know which method I should use of the LoadInst class.

Take a look at the users of the load instruction: http://llvm.org/docs/ProgrammersManual.html#iterating-over-def-use-use-def-chains

Is this what you are looking for?

Cheers,
Florian
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev
Thanks Florian,
I'm not sure yet but tomorrow I'll try. At the moment I don't see why I should iterate on a list just for getting the 5 out that LoadInst CTI on but I'm.sure I'm missing something :)

Thanks a lot


On Wed, Dec 12, 2018, 22:05 Florian Hahn <[hidden email] wrote:


> On Dec 12, 2018, at 13:57, Alberto Barbaro via llvm-dev <[hidden email]> wrote:
>
> Hi,
> I would like to get the '5'. I would like to know where the loaded value is stored. I don't know which method I should use of the LoadInst class.

Take a look at the users of the load instruction: http://llvm.org/docs/ProgrammersManual.html#iterating-over-def-use-use-def-chains

Is this what you are looking for?

Cheers,
Florian

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev
On Wed, Dec 12, 2018 at 2:13 PM Alberto Barbaro via llvm-dev
<[hidden email]> wrote:
>
> Thanks Florian,
> I'm not sure yet but tomorrow I'll try. At the moment I don't see why I should iterate on a list just for getting the 5 out that LoadInst CTI on but I'm.sure I'm missing something :)

In LLVM an instruction and its result are the same thing. Instruction
is a subclass of Value. LoadInst is %5.

>
> Thanks a lot
>
>
> On Wed, Dec 12, 2018, 22:05 Florian Hahn <[hidden email] wrote:
>>
>>
>>
>> > On Dec 12, 2018, at 13:57, Alberto Barbaro via llvm-dev <[hidden email]> wrote:
>> >
>> > Hi,
>> > I would like to get the '5'. I would like to know where the loaded value is stored. I don't know which method I should use of the LoadInst class.
>>
>> Take a look at the users of the load instruction: http://llvm.org/docs/ProgrammersManual.html#iterating-over-def-use-use-def-chains
>>
>> Is this what you are looking for?
>>
>> Cheers,
>> Florian
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev
In reply to this post by Finkel, Hal J. via llvm-dev

I suspect you have some confusion as to how LLVM works.

 

In LLVM terms, an Instruction is essentially an opcode, some opcode-specific flags, and a list of Value operands that it uses. Instructions are themselves Values, so that means that to use the result of an instruction, you pass the Instruction itself to the method that accepts a Value. There is no “destination” of an Instruction in structural terms.

 

In the textual format of LLVM, Instructions are represented by printing out %<name> = <textual representation of an instruction>, and subsequent uses of the instruction are referred to in the %<name> format. Names of instructions (and a few other values) must be unique, with the exception of the empty string. The %<name> representation for an empty name string is replaced with a unique autoincrementing integer that is not readily accessible via the APIs (you need to go through the ModuleSlotTracker to get to it). If you’re really trying to get that exact string for an instruction, you are generally doing something wrong and there is an easier way to go about whatever it is you want to do.

 

From: llvm-dev [mailto:[hidden email]] On Behalf Of Alberto Barbaro via llvm-dev
Sent: Wednesday, December 12, 2018 13:24
To: [hidden email]
Subject: [llvm-dev] How to get the destination in a LoadInst

 

Hi all,

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?

 

Thanks


_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev
In reply to this post by Finkel, Hal J. via llvm-dev
Am Mi., 12. Dez. 2018 um 12:24 Uhr schrieb Alberto Barbaro via
llvm-dev <[hidden email]>:
> 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
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev
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 <[hidden email] wrote:
Am Mi., 12. Dez. 2018 um 12:24 Uhr schrieb Alberto Barbaro via
llvm-dev <[hidden email]>:
> 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

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev
Am Mi., 12. Dez. 2018 um 17:05 Uhr schrieb Alberto Barbaro
<[hidden email]>:
> 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
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev
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 <[hidden email] wrote:
Am Mi., 12. Dez. 2018 um 17:05 Uhr schrieb Alberto Barbaro
<[hidden email]>:
> 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

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev
In reply to this post by Finkel, Hal J. via llvm-dev
"Doerfert, Johannes Rudolf via llvm-dev" <[hidden email]>
writes:

> The LoadInst is %5. I'm not sure what you mean by reference though.

This is a common misunderstanding, one that I think is encouraged by the
textual form of IR.  "%5 = load" makes it looks like %5 is a destination
operand in LoadInst.  LLVM IR looks like assembly and in (most) assembly
syntax, destinations are instruction operands.

Something like "%5 -> load" might have made things more clear, but of
course it's too late for that.  :)

                            -David
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

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

Finkel, Hal J. via llvm-dev
Hi,
Honestly a bit yes but now all should be fine :)

Thanks

On Thu, Dec 13, 2018, 15:39 David Greene <[hidden email] wrote:
"Doerfert, Johannes Rudolf via llvm-dev" <[hidden email]>
writes:

> The LoadInst is %5. I'm not sure what you mean by reference though.

This is a common misunderstanding, one that I think is encouraged by the
textual form of IR.  "%5 = load" makes it looks like %5 is a destination
operand in LoadInst.  LLVM IR looks like assembly and in (most) assembly
syntax, destinations are instruction operands.

Something like "%5 -> load" might have made things more clear, but of
course it's too late for that.  :)

                            -David

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev