Hello everybody, What I am trying to do is to create a vector <4 x i32> and save some values to initialize the vector. However, I am using the insertElementInst() and the errors I get are the following; error: within this context Instruction *Insert = new InsertElementInst(instr, emptyVec, index0, "test"); and error: ‘llvm::InsertElementInst::InsertElementInst(llvm::Value*, llvm::Value*, llvm::Value*, const llvm::Twine&, llvm::Instruction*)’ is private The code I have used is the following: Type *Instr_vector = VectorType::get(Int32, 4); Value *emptyVec = UndefValue::get(Instr_vector); Constant* index0 = Constant::getIntegerValue(u32Ty, llvm::APInt(32, 0)); Instruction *Insert = new InsertElementInst(instr, emptyVec, index0, "test"); b->getInstList().insertAfter(Xor_flip, Insert); Do you have any suggestions for these errors? Thanks in Advance, Vasilis -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140720/adf4b191/attachment.html>
Hi Vasilis, On 20 July 2014 12:57, Vasilis Koutsoumpos <bill_koutsoumpos at hotmail.com> wrote:> Do you have any suggestions for these errors?It looks like the constructor is private to make sure the type of the vector and the overall instruction match up properly. You should use InsertElementInst::Create instead (see http://llvm.org/docs/doxygen/html/classllvm_1_1InsertElementInst.html). Actually, it's usually better to create your instructions using the IRBuilder class rather than directly. It handles inserting them into a basic block more conveniently, and smooths out some of the differences between various instructions (like this one). Cheers. Tim.
Hello Tim, Thanks for the help, just a silly mistake...It works now perfectly! Regards, Vasilis On Jul 20, 2014, at 2:20 PM, Tim Northover <t.p.northover at gmail.com> wrote:> Hi Vasilis, > > On 20 July 2014 12:57, Vasilis Koutsoumpos <bill_koutsoumpos at hotmail.com> wrote: >> Do you have any suggestions for these errors? > > It looks like the constructor is private to make sure the type of the > vector and the overall instruction match up properly. You should use > InsertElementInst::Create instead (see > http://llvm.org/docs/doxygen/html/classllvm_1_1InsertElementInst.html). > > Actually, it's usually better to create your instructions using the > IRBuilder class rather than directly. It handles inserting them into a > basic block more conveniently, and smooths out some of the differences > between various instructions (like this one). > > Cheers. > > Tim. >