Hi all, I'm playing with intrinsics and I was wondering how to lower an intrinsic that should return, for example, an int1? More precisely, how to return the value when working with MachineInst? First, I have defined an instrinsic in "Intrinsics.td": _def int_antivm : Intrinsic<[llvm_i1_ty], [], [], "llvm.antivm">;_ Then I want to lower it in the X86 backend, so I defined a pseudo instruction in "X86InstrCompiler.td": _let usesCustomInserter = 1, Defs = [EFLAGS] in {_ _def ANTIVM : PseudoI<(outs), (ins), [(int_antivm)]>;_ _}_ I wrote my custom inserter: _MachineBasicBlock *_ _X86TargetLowering::EmitANTIVMWithCustomInserter(_ _ MachineInstr *MI,_ _ MachineBasicBlock *MBB) const {_ _ // Some stuff, _ _ MI->eraseFromParent(); // The pseudo is gone now._ _ return BB;_ _}_ Should I put the return value to EAX (like for a standard function) ? Thank you for your help. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150428/be81034a/attachment.html>
> On Apr 28, 2015, at 1:18 AM, Jobin, Gaël <gael.jobin at switzerlandmail.ch> wrote: > > Hi all, > > I'm playing with intrinsics and I was wondering how to lower an intrinsic that should return, for example, an int1? More precisely, how to return the value when working with MachineInst? > > > First, I have defined an instrinsic in "Intrinsics.td": > > def int_antivm : Intrinsic<[llvm_i1_ty], [], [], "llvm.antivm">; > > > Then I want to lower it in the X86 backend, so I defined a pseudo instruction in "X86InstrCompiler.td": > > let usesCustomInserter = 1, Defs = [EFLAGS] in { >I think pseudo-instructions should also define isPseudo = 1> def ANTIVM : PseudoI<(outs), (ins), [(int_antivm)]>; > } > > > I wrote my custom inserter: > > MachineBasicBlock * > X86TargetLowering::EmitANTIVMWithCustomInserter( > MachineInstr *MI, > MachineBasicBlock *MBB) const { > > // Some stuff, > > MI->eraseFromParent(); // The pseudo is gone now. > return BB; > } > > Should I put the return value to EAX (like for a standard function) ? >I expect that before your custom inserter, the value produced by your pseudo instruction was in a vreg. You just have to reuse this vreg to put the result of your “stuff”. If you run llc with —print-before-all, you should be able to see the actual sequence. — Mehdi -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150428/e0eac556/attachment.html>
> I think pseudo-instructions should also define isPseudo = 1Ah yes, thank you.> I expect that before your custom inserter, the value produced by your pseudo instruction was in a vreg. You just have to reuse this vreg to put the result of your "stuff". > If you run llc with --print-before-all, you should be able to see the actual sequence.That's exactly my problem. How to know before my custom inserter where the produced value will be? I found some documentation about the x86 target saying that the operand 0 is always the destination value, is it right? Also, sometimes I saw _getOperand(0).getReg()_, but how can I be sure that the destination will be in a vreg? Should I specify it explicitly in the TableGen definition? I admit being a bit lost inside the backend... Thank you for your help -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150428/dcc7c9ce/attachment.html>