<div dir="ltr"><div><div>Thank you for pointing to the PPCCTRLoops. That's a good idea. Yes I understand that OPT passes will have problems with my intrinsic, since they do not know that it's a terminator instruction. However in the backend, I have defined the instruction with "isBranch=1, isTerminator=1". This can prevent the backend from reordering the instruction. Just out of curiosity, why can't we have an intrinsicProperty that says "this intrinsic is a terminator or a branch" and allow it to take a label ?. Such an intrinsicProperty will allow all the OPT passes to understand any new branch or loop kind of intrinsics.<br>
<br></div>Thanks<br></div>Ravi.<br><div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Feb 27, 2014 at 2:13 AM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="">----- Original Message -----<br>
> From: "RAVI KORSA" <<a href="mailto:ravi.korsa@gmail.com">ravi.korsa@gmail.com</a>><br>
> To: <a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a><br>
> Sent: Wednesday, February 26, 2014 2:14:25 PM<br>
> Subject: [LLVMdev] How to 'define and use' a LOOP intrinsic that takes "iteration count" and the "label" to jump to ?<br>
><br>
><br>
><br>
><br>
> I have defined the intrinsic as<br>
> def int_loop: Intrinsic<[],[llvm_i8_ty, llvm_empty_ty],[]>;<br>
><br>
><br>
> and also got the Codegen backend support in Instructioninfo.td file.<br>
><br>
><br>
> Then created a .ll file to test it.<br>
><br>
> The .ll file is like this<br>
><br>
> declare void @llvm.loop(i8, label)<br>
><br>
> define void @fn() nounwind readnone {<br>
> entry:<br>
> .....<br>
> .....<br>
> call void @llvm.loop(i8 10, label %entry)<br>
> ret void<br>
> }<br>
<br>
</div>I suspect that you'll run into several problems doing this. For one thing, LLVM has builtin assumptions about what kinds of instructions act as block terminators, and your intrinsic call is not one of them. I recommend looking at how the PowerPC counter-based loops are implemented. PowerPC uses a special intrinsic (inserted by the target-specific late IR-level pass lib/Target/PowerPC/PPCCTRLoops.cpp):<br>
def int_ppc_is_decremented_ctr_nonzero : Intrinsic<[llvm_i1_ty], [], []>;<br>
along with:<br>
def int_ppc_mtctr : Intrinsic<[], [llvm_anyint_ty], []>;<br>
<br>
and the first intrinsic is used with the regular loop branching instructions at the IR level. In the backend, loop branching instructions that are fed by that intrinsic are transformed into target-specific SDAG nodes (and, then, to the appropriate instructions).<br>
<br>
If you have any further questions, please feel free to ask.<br>
<br>
-Hal<br>
<div class=""><br>
><br>
><br>
> But when I run it with llc, I get the following error message<br>
><br>
> Intrinsic has incorrect argument type!<br>
> void (i8, label)* @llvm.loop<br>
> Broken module found, compilation aborted!<br>
><br>
><br>
> The 'Module Verifier' is complaining about the 'label' type. Any<br>
> suggestions on how I go about doing this ? Would appreciate your<br>
> help.<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
</div>> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
><br>
<span class=""><font color="#888888"><br>
--<br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
</font></span></blockquote></div><br></div></div></div></div></div>