Thanks for reply. I have used AllocaInst, it's working but i think it's only for allocating some memory for new variable. And CallInst creates a call instruction. I am looking for creating a add or sub instruction. I used function instruction(), which gives me error "error: cannot allocate an object of abstract type ‘llvm::Instruction’" and also "Instruction.h:28: note: because the following virtual functions are pure within ‘llvm::Instruction’:", "Instruction.h:50: note: virtual llvm::Instruction* llvm::Instruction::clone(llvm::LLVMContext&) const" Also i have used BinaryOperator::create(), but it gives error that there is no function called create(). Thanks again for your reply. John Criswell-2 wrote:> > help__me_please wrote: >> Can you please give an example of creating an instruction (for example >> add >> instructions with two operand a and b)? I am trying instruction() for a >> while, but no success yet. >> > > You need to look for the appropriate subclass of llvm::Instruction and > find the method for creating a new instruction. The method is usually a > static method and takes arguments pointing to the values to use as > operands. Doxygen is your best resource for finding these methods. > > For example, if you look at > http://llvm.org/doxygen/classllvm_1_1AllocaInst.html, you can see that > the AllocaInst class (which represents an alloca instruction) has a > standard constructor method that takes the type of object to allocate, > the name of the new alloca instruction, an instruction before which to > insert the alloca instruction, etc. > > As another example, the CallInst class > (http://llvm.org/doxygen/classllvm_1_1CallInst.html) represents a call > instruction and has a static Create() method that you can use to create > a new call instruction. > > -- John T. > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-- View this message in context: http://old.nabble.com/Operand%2C-instruction-tp21961718p28238512.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
There's an entire tutorial at http://llvm.org/docs/tutorial which includes covers the IRBuilder to generate all sorts of IR, including the add instruction. You can skip ahead to chapter 3 if you just want to see LLVM API, but I suggest you read the whole tutorial if you have the time. Nick help__me_please wrote:> > Thanks for reply. > I have used AllocaInst, it's working but i think it's only for allocating > some memory for new variable. And CallInst creates a call instruction. I am > looking for creating a add or sub instruction. > > I used function instruction(), which gives me error "error: cannot allocate > an object of abstract type ‘llvm::Instruction’" and also "Instruction.h:28: > note: because the following virtual functions are pure within > ‘llvm::Instruction’:", "Instruction.h:50: note: virtual llvm::Instruction* > llvm::Instruction::clone(llvm::LLVMContext&) const" > > Also i have used BinaryOperator::create(), but it gives error that there is > no function called create(). > > Thanks again for your reply. > > > John Criswell-2 wrote: >> >> help__me_please wrote: >>> Can you please give an example of creating an instruction (for example >>> add >>> instructions with two operand a and b)? I am trying instruction() for a >>> while, but no success yet. >>> >> >> You need to look for the appropriate subclass of llvm::Instruction and >> find the method for creating a new instruction. The method is usually a >> static method and takes arguments pointing to the values to use as >> operands. Doxygen is your best resource for finding these methods. >> >> For example, if you look at >> http://llvm.org/doxygen/classllvm_1_1AllocaInst.html, you can see that >> the AllocaInst class (which represents an alloca instruction) has a >> standard constructor method that takes the type of object to allocate, >> the name of the new alloca instruction, an instruction before which to >> insert the alloca instruction, etc. >> >> As another example, the CallInst class >> (http://llvm.org/doxygen/classllvm_1_1CallInst.html) represents a call >> instruction and has a static Create() method that you can use to create >> a new call instruction. >> >> -- John T. >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >
help__me_please wrote:> Thanks for reply. > I have used AllocaInst, it's working but i think it's only for allocating > some memory for new variable. And CallInst creates a call instruction. I am > looking for creating a add or sub instruction. > > I used function instruction(), which gives me error "error: cannot allocate > an object of abstract type ‘llvm::Instruction’" and also "Instruction.h:28: > note: because the following virtual functions are pure within > ‘llvm::Instruction’:", "Instruction.h:50: note: virtual llvm::Instruction* > llvm::Instruction::clone(llvm::LLVMContext&) const" >An add or sub should be a BinaryOperator, if memory serves me correctly. Looking at mainline doxygen, there's a whole bunch of CreateNSWAdd, CreateNSWMul, etc. methods. It's one of those that you want. -- John T.> Also i have used BinaryOperator::create(), but it gives error that there is > no function called create(). > > Thanks again for your reply. > > > John Criswell-2 wrote: > >> help__me_please wrote: >> >>> Can you please give an example of creating an instruction (for example >>> add >>> instructions with two operand a and b)? I am trying instruction() for a >>> while, but no success yet. >>> >>> >> You need to look for the appropriate subclass of llvm::Instruction and >> find the method for creating a new instruction. The method is usually a >> static method and takes arguments pointing to the values to use as >> operands. Doxygen is your best resource for finding these methods. >> >> For example, if you look at >> http://llvm.org/doxygen/classllvm_1_1AllocaInst.html, you can see that >> the AllocaInst class (which represents an alloca instruction) has a >> standard constructor method that takes the type of object to allocate, >> the name of the new alloca instruction, an instruction before which to >> insert the alloca instruction, etc. >> >> As another example, the CallInst class >> (http://llvm.org/doxygen/classllvm_1_1CallInst.html) represents a call >> instruction and has a static Create() method that you can use to create >> a new call instruction. >> >> -- John T. >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >> > >
Thanks for the reply. You are correct, sometimes ago i found myself this functions. I was searching for just this functions. Still one problem is there, adding a instruction in another basic block, error shows that basic block has no terminator inst, but that's not true. Thanks again for help. John Criswell-2 wrote:> > help__me_please wrote: >> Thanks for reply. >> I have used AllocaInst, it's working but i think it's only for allocating >> some memory for new variable. And CallInst creates a call instruction. I >> am >> looking for creating a add or sub instruction. >> >> I used function instruction(), which gives me error "error: cannot >> allocate >> an object of abstract type ‘llvm::Instruction’" and also >> "Instruction.h:28: >> note: because the following virtual functions are pure within >> ‘llvm::Instruction’:", "Instruction.h:50: note: virtual >> llvm::Instruction* >> llvm::Instruction::clone(llvm::LLVMContext&) const" >> > > An add or sub should be a BinaryOperator, if memory serves me > correctly. Looking at mainline doxygen, there's a whole bunch of > CreateNSWAdd, CreateNSWMul, etc. methods. It's one of those that you > want. > > -- John T. > >> Also i have used BinaryOperator::create(), but it gives error that there >> is >> no function called create(). >> >> Thanks again for your reply. >> >> >> John Criswell-2 wrote: >> >>> help__me_please wrote: >>> >>>> Can you please give an example of creating an instruction (for example >>>> add >>>> instructions with two operand a and b)? I am trying instruction() for a >>>> while, but no success yet. >>>> >>>> >>> You need to look for the appropriate subclass of llvm::Instruction and >>> find the method for creating a new instruction. The method is usually a >>> static method and takes arguments pointing to the values to use as >>> operands. Doxygen is your best resource for finding these methods. >>> >>> For example, if you look at >>> http://llvm.org/doxygen/classllvm_1_1AllocaInst.html, you can see that >>> the AllocaInst class (which represents an alloca instruction) has a >>> standard constructor method that takes the type of object to allocate, >>> the name of the new alloca instruction, an instruction before which to >>> insert the alloca instruction, etc. >>> >>> As another example, the CallInst class >>> (http://llvm.org/doxygen/classllvm_1_1CallInst.html) represents a call >>> instruction and has a static Create() method that you can use to create >>> a new call instruction. >>> >>> -- John T. >>> >>> >>> _______________________________________________ >>> LLVM Developers mailing list >>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >>> >>> >>> >> >> > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-- View this message in context: http://old.nabble.com/Operand%2C-instruction-tp21961718p28239236.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Thanks for the reply. Nick Lewycky wrote:> > There's an entire tutorial at http://llvm.org/docs/tutorial which > includes covers the IRBuilder to generate all sorts of IR, including the > add instruction. You can skip ahead to chapter 3 if you just want to see > LLVM API, but I suggest you read the whole tutorial if you have the time. > > Nick > > help__me_please wrote: >> >> Thanks for reply. >> I have used AllocaInst, it's working but i think it's only for allocating >> some memory for new variable. And CallInst creates a call instruction. I >> am >> looking for creating a add or sub instruction. >> >> I used function instruction(), which gives me error "error: cannot >> allocate >> an object of abstract type ‘llvm::Instruction’" and also >> "Instruction.h:28: >> note: because the following virtual functions are pure within >> ‘llvm::Instruction’:", "Instruction.h:50: note: virtual >> llvm::Instruction* >> llvm::Instruction::clone(llvm::LLVMContext&) const" >> >> Also i have used BinaryOperator::create(), but it gives error that there >> is >> no function called create(). >> >> Thanks again for your reply. >> >> >> John Criswell-2 wrote: >>> >>> help__me_please wrote: >>>> Can you please give an example of creating an instruction (for example >>>> add >>>> instructions with two operand a and b)? I am trying instruction() for a >>>> while, but no success yet. >>>> >>> >>> You need to look for the appropriate subclass of llvm::Instruction and >>> find the method for creating a new instruction. The method is usually a >>> static method and takes arguments pointing to the values to use as >>> operands. Doxygen is your best resource for finding these methods. >>> >>> For example, if you look at >>> http://llvm.org/doxygen/classllvm_1_1AllocaInst.html, you can see that >>> the AllocaInst class (which represents an alloca instruction) has a >>> standard constructor method that takes the type of object to allocate, >>> the name of the new alloca instruction, an instruction before which to >>> insert the alloca instruction, etc. >>> >>> As another example, the CallInst class >>> (http://llvm.org/doxygen/classllvm_1_1CallInst.html) represents a call >>> instruction and has a static Create() method that you can use to create >>> a new call instruction. >>> >>> -- John T. >>> >>> >>> _______________________________________________ >>> LLVM Developers mailing list >>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >>> >>> >> > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-- View this message in context: http://old.nabble.com/Operand%2C-instruction-tp21961718p28239244.html Sent from the LLVM - Dev mailing list archive at Nabble.com.