Thanks Jonathan. I knew this document. But I didn't understand the "unsigned iType, Use *Ops" fields. Could you please help how I can create a new instruction to do the example I was giving? Thanks for your time in advance. Best, Zhi On Thu, Apr 16, 2015 at 5:48 PM, Jonathan Roelofs <jonathan at codesourcery.com> wrote:> You're probably looking for this method: > https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Instruction.h#L395 > > Jon > > On 4/16/15 6:38 PM, zhi chen wrote: > >> I read the tutorial document, but I didn't understand the it and Ops >> fields of instruction class well. Can any one give me an example? >> >> Instruction *newInstr = new Instruction(Type *ty, unsigned it, Use *Ops, >> unsigned NumOps, Instruction *InsertBefore); >> >> For example, I have an *instruction *pInst *without no the type of >> operation in advance. If I want to create a new instruction which is >> similar to the *pInst. *How can I do it? >> >> Any help will be appreciated. Thanks. >> >> Best, >> Zhi >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> > -- > Jon Roelofs > jonathan at codesourcery.com > CodeSourcery / Mentor Embedded >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150416/66855770/attachment.html>
On 16 April 2015 at 17:53, zhi chen <zchenhn at gmail.com> wrote:> Thanks Jonathan. I knew this document. But I didn't understand the "unsigned > iType, Use *Ops" fields. Could you please help how I can create a new > instruction to do the example I was giving? Thanks for your time in advance.You can't. Instruction's constructor is protected so you can't use it outside implementing a new Instruction no matter how well you understood its parameters. But, for the record: + "it" is to support LLVM's runtime type identification substitutes (cast<Ty>, dyn_cast<Ty> and isa<Ty> mostly). I don't think the permitted values are documented in one place, they're mostly an implementation detail. + "Ops" are the operands: in "add %2, %3" they'd be "%2" and "%3" (or rather, pointers to instances of Value with those names). What are you really trying to do (and why)? It's entirely possible Instruction::clone isn't what you want, but we can't give better advice without more details. Cheers. Tim.
Thanks, Tim. What I want to do is to change the scalar instructions to scalar ones. For example, if I have to the following one: %3 = fadd double %1, double %2 I want to change it into %6 = fadd <2 x double> %4, double %2. I understand that I can detect the operation first, and use "create" to create for each of them. But I don't if there is a generic way to do this because if might be add/sub/mul... operations. Clone is not gonna be helpful here because the result type (it is vectortype) should be different to the one being cloned (it is scalar). Any idea about how to do this? Thanks again. Best, Zhi On Thu, Apr 16, 2015 at 6:16 PM, Tim Northover <t.p.northover at gmail.com> wrote:> On 16 April 2015 at 17:53, zhi chen <zchenhn at gmail.com> wrote: > > Thanks Jonathan. I knew this document. But I didn't understand the > "unsigned > > iType, Use *Ops" fields. Could you please help how I can create a new > > instruction to do the example I was giving? Thanks for your time in > advance. > > You can't. Instruction's constructor is protected so you can't use it > outside implementing a new Instruction no matter how well you > understood its parameters. > > But, for the record: > + "it" is to support LLVM's runtime type identification substitutes > (cast<Ty>, dyn_cast<Ty> and isa<Ty> mostly). I don't think the > permitted values are documented in one place, they're mostly an > implementation detail. > + "Ops" are the operands: in "add %2, %3" they'd be "%2" and "%3" > (or rather, pointers to instances of Value with those names). > > What are you really trying to do (and why)? It's entirely possible > Instruction::clone isn't what you want, but we can't give better > advice without more details. > > Cheers. > > Tim. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150416/21915152/attachment.html>