Thank you! I wanted to use the right part of the instruction , %a = alloca i32, align 4 - %a here , but I don't quite understand the difference between Instruction object and Value object of a, which is used further , and in this case : %1 = alloca i32, align 4 - I also wanted to use %1 and in this case the only possibility is Instruction object. 2017-07-20 15:32 GMT+02:00 Evgeny Astigeevich <Evgeny.Astigeevich at arm.com>:> Hi Anastasiya, > > > What do you mean 'identifiable'? You have Module, Function, BasicBlock > etc. You can access Values and Users. They form a data-flow graph. You can > store pointers to Values and Users if you wish. If you want a name for any > Value there is ValueSymbolTable (http://www.llvm.org/docs/ > ProgrammersManual.html#advanced-topics) which provides a symbol table > that the Function and Module classes use for naming value definitions. You > should take into account that some Values might not have names and passes > can change names of Values. > > > Thanks, > > Evgeny Astigevich > ------------------------------ > *From:* llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of > Anastasiya Ruzhanskaya via llvm-dev <llvm-dev at lists.llvm.org> > *Sent:* Thursday, July 20, 2017 2:21:44 PM > *To:* LLVM Developers Mailing List > *Subject:* [llvm-dev] Value > > Hello, > I am trying to write my own pass for some purposes, and found out that > there is no way to work with such variables as %1 and so on. How they are > identifiable? Only by the Value object, without any possibility for visual > representation as for example %a, %b values? >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170720/5214fefc/attachment.html>
On 20 July 2017 at 07:02, Anastasiya Ruzhanskaya via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Thank you! I wanted to use the right part of the instruction , > %a = alloca i32, align 4 - %a here , but I don't quite understand the > difference between Instruction object and Value object of a,Instruction is a subclass of Value so if you know your Value was defined by an instruction you can just use "cast<Instruction>(MyValue)" to access the instruction methods (more usually you cast to a particular kind of instruction). But be careful of Values that aren't defined by instructions: @globals_arent_instructions = extern global i32 define void @foo(i32 %not_an_Instruction) { %rhs_instruction = load i32, i32* @globals_arent_instructions %sum_instruction = add i32 %not_an_instruction, %rhs_instruction %res_instruction = add i32 %sum_instruction, 1 ret i32 %res_instruction } So generally you don't want to use "cast", which asserts when the cast is invalid. Most places use "dyn_cast" instead, which returns nullptr when invalid; then you can check that return value. If you look at the hierarchy diagram on https://llvm.org/doxygen/classllvm_1_1Value.html, you can see the full range of Values that aren't Instructions. Depending on what you're doing you may be able to simply ignore those cases. The most common ones that can crop up when you're not expecting them are Constants and Arguments (as in my example above), the others tend to be obvious from context (it's obvious a branch will have a BasicBlock destination for example). Cheers. Tim.
You think in terms of the textual representation of IR and are trying to work on IR in these terms. See: http://www.llvm.org/docs/ProgrammersManual.html#coreclasses http://llvm.org/doxygen/classllvm_1_1Value.html In the LLVM representation Value is a thing which can be used as an operand to instructions. In API there is no such thing as the named right part. An instruction itself is a value which is produced as result of execution of the instruction. Look at the example: Instr 1: add i32 1, 2 Instr 2: add i32 <result of Instr1>, 10 We have a def-use connection between Instr 2 and Instr 1. We don't need names. We can traverse def-use connection in this way (http://www.llvm.org/docs/ProgrammersManual.html#helpful-hints-for-common-operations): Instruction *pi = ...; for (Use &U : pi->operands()) { Value *v = U.get(); // ... } Your case:> %a = alloca i32, align 4 - %a here>, but I don't quite understand the difference between Instruction object and Value object of a, which is used further , and in this case :Instr1: alloca i32, align 4 If there are users of Instr1 then can access them calling user_begin() on Instr1. You can access Instr1 from users as in the example above. Of course you need to keep the pointer to Instr1 somewhere to check that it's used.> %1 = alloca i32, align 4 - I also wanted to use %1 and in this case the only possibility is Instruction object.You traverse basic blocks and process the instructions. Processing can include any type of actions: analysis, optimization etc. So what is your use case? -Evgeny ________________________________ From: Anastasiya Ruzhanskaya <anastasiya.ruzhanskaya at frtk.ru> Sent: Thursday, July 20, 2017 3:02:26 PM To: Evgeny Astigeevich Cc: llvm-dev at lists.llvm.org; nd Subject: Re: [llvm-dev] Value Thank you! I wanted to use the right part of the instruction , %a = alloca i32, align 4 - %a here , but I don't quite understand the difference between Instruction object and Value object of a, which is used further , and in this case : %1 = alloca i32, align 4 - I also wanted to use %1 and in this case the only possibility is Instruction object. 2017-07-20 15:32 GMT+02:00 Evgeny Astigeevich <Evgeny.Astigeevich at arm.com<mailto:Evgeny.Astigeevich at arm.com>>: Hi Anastasiya, What do you mean 'identifiable'? You have Module, Function, BasicBlock etc. You can access Values and Users. They form a data-flow graph. You can store pointers to Values and Users if you wish. If you want a name for any Value there is ValueSymbolTable (http://www.llvm.org/docs/ProgrammersManual.html#advanced-topics) which provides a symbol table that the Function and Module classes use for naming value definitions. You should take into account that some Values might not have names and passes can change names of Values. Thanks, Evgeny Astigevich ________________________________ From: llvm-dev <llvm-dev-bounces at lists.llvm.org<mailto:llvm-dev-bounces at lists.llvm.org>> on behalf of Anastasiya Ruzhanskaya via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> Sent: Thursday, July 20, 2017 2:21:44 PM To: LLVM Developers Mailing List Subject: [llvm-dev] Value Hello, I am trying to write my own pass for some purposes, and found out that there is no way to work with such variables as %1 and so on. How they are identifiable? Only by the Value object, without any possibility for visual representation as for example %a, %b values? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170720/a8fff547/attachment-0001.html>
I am performing the bit analysis, so actually I want to propagate information about bits from operands to the instruction (the result of instruction), and every time I access the Instruction first , than get the operands, then access to the next instruction. That was the only problem, that I keep a map from Instruction to bit info and was confused, is Instruction, that I am putting to map, is the same object as the Value, that will be used later, as here %a = alloca i32, align 4 ...%b= mul %a, 2. Now seems to be, that yes. 2017-07-20 16:43 GMT+02:00 Evgeny Astigeevich <Evgeny.Astigeevich at arm.com>:> You think in terms of the textual representation of IR and are trying to > work on IR in these terms. > > See: > > http://www.llvm.org/docs/ProgrammersManual.html#coreclasses > > http://llvm.org/doxygen/classllvm_1_1Value.html > > > In the LLVM representation Value is a thing which can be used as an > operand to instructions. In API there is no such thing as the named right > part. An instruction itself is a value which is produced as result of > execution of the instruction. Look at the example: > > > Instr 1: add i32 1, 2 > > > > Instr 2: add i32 <result of Instr1>, 10 > > > We have a def-use connection between Instr 2 and Instr 1. We don't need > names. We can traverse def-use connection in this way ( > http://www.llvm.org/docs/ProgrammersManual.html#helpful-hints-for-common- > operations): > > > Instruction *pi = ...; > for (Use &U : pi->operands()) { > Value *v = U.get(); > // ...} > > > Your case: > > > > %a = alloca i32, align 4 - %a here > > >, but I don't quite understand the difference between Instruction object > and Value object of a, which is used further , and in this case : > > Instr1: alloca i32, align 4 > > If there are users of Instr1 then can access them calling user_begin() > on Instr1. You can access Instr1 from users as in the example above. Of > course you need to keep the pointer to Instr1 somewhere to check that it's > used. > > > > %1 = alloca i32, align 4 - I also wanted to use %1 and in this case the > only possibility is Instruction object. > > > You traverse basic blocks and process the instructions. Processing can > include any type of actions: analysis, optimization etc. > > So what is your use case? > > > -Evgeny > > ------------------------------ > *From:* Anastasiya Ruzhanskaya <anastasiya.ruzhanskaya at frtk.ru> > *Sent:* Thursday, July 20, 2017 3:02:26 PM > *To:* Evgeny Astigeevich > *Cc:* llvm-dev at lists.llvm.org; nd > *Subject:* Re: [llvm-dev] Value > > Thank you! I wanted to use the right part of the instruction , > %a = alloca i32, align 4 - %a here , but I don't quite understand the > difference between Instruction object and Value object of a, which is used > further , and in this case : > %1 = alloca i32, align 4 - I also wanted to use %1 and in this case the > only possibility is Instruction object. > > 2017-07-20 15:32 GMT+02:00 Evgeny Astigeevich <Evgeny.Astigeevich at arm.com> > : > >> Hi Anastasiya, >> >> >> What do you mean 'identifiable'? You have Module, Function, BasicBlock >> etc. You can access Values and Users. They form a data-flow graph. You can >> store pointers to Values and Users if you wish. If you want a name for any >> Value there is ValueSymbolTable (http://www.llvm.org/docs/Prog >> rammersManual.html#advanced-topics) which provides a symbol table that >> the Function and Module classes use for naming value definitions. You >> should take into account that some Values might not have names and passes >> can change names of Values. >> >> >> Thanks, >> >> Evgeny Astigevich >> ------------------------------ >> *From:* llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of >> Anastasiya Ruzhanskaya via llvm-dev <llvm-dev at lists.llvm.org> >> *Sent:* Thursday, July 20, 2017 2:21:44 PM >> *To:* LLVM Developers Mailing List >> *Subject:* [llvm-dev] Value >> >> Hello, >> I am trying to write my own pass for some purposes, and found out that >> there is no way to work with such variables as %1 and so on. How they are >> identifiable? Only by the Value object, without any possibility for visual >> representation as for example %a, %b values? >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170720/f02f2c2a/attachment.html>