Thanks for the suggestions!<div>These were very extremely helpful.</div><div><br></div><div>Malveeka<br><div><br><div class="gmail_quote">On Fri, May 6, 2011 at 5:24 PM, Andrew Trick <span dir="ltr"><<a href="mailto:atrick@apple.com">atrick@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><br>
On May 5, 2011, at 5:11 AM, Rotem, Nadav wrote:<br>
<br>
> Malveeka,<br>
><br>
> You can use the LoopInfo analysis to find the induction variable.<br>
><br>
> <a href="http://llvm.org/docs/doxygen/html/classllvm_1_1Loop.html#a72bbf45d2e00971f56bf8cfe4e1df01c" target="_blank">http://llvm.org/docs/doxygen/html/classllvm_1_1Loop.html#a72bbf45d2e00971f56bf8cfe4e1df01c</a><br>
><br>
> Cheers,<br>
> Nadav<br>
<br>
</div>getCanonicalInductionVariable is a good example of finding IVs without iterating over instructions. But you may need to generalize it a bit for your purpose.<br>
<br>
A completely general approach to IV analysis is ScalarEvolution. You can query the expression for a loop header phi using ScalarEvolution::getSCEV. If it returns SCEVAddRecExpr with getLoop() == ThisLoop, then you've found an IV. You can build a new IV by replacing the "step" with SCEVAddExpr(1 + OrigStep). To materialize it in IR, you need to use a SCEVExpander. ...probably more complicated than you need.<br>
<br>
-Andy<br>
<div class="im"><br>
<br>
><br>
><br>
> From: <a href="mailto:llvmdev-bounces@cs.uiuc.edu">llvmdev-bounces@cs.uiuc.edu</a> [mailto:<a href="mailto:llvmdev-bounces@cs.uiuc.edu">llvmdev-bounces@cs.uiuc.edu</a>] On Behalf Of Malveeka Tewari<br>
> Sent: Thursday, May 05, 2011 14:51<br>
> To: <a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a><br>
> Subject: [LLVMdev] Loop transformations using LLVM<br>
><br>
> Hi<br>
><br>
> I am trying to write up a transformation for the following code where instead of incrementing the loop variable by 1, I increment it by 2 ie.<br>
><br>
> for (i=0; i < THRES; i++) {<br>
> //do something<br>
> }<br>
><br>
> gets transformed to<br>
><br>
> for (i=0; i < THRES; i+=2) {<br>
> //do something<br>
> }<br>
><br>
> I am thinking of transforming the llvm bit-code in the following way.<br>
> Iterate over the function for the original code till I get the basicBlock for the for loop, then iterate over the instructions till I get the increment instruction and then add the same increment instruction so that the increment happens twice.<br>
><br>
> I am still getting familiar with the llvm infrastructure and I am not sure if the above approach is even going to work. It'll be great if someone can suggest a better or more concrete way of doing the above transformation ? Is there already something similar in the source tree that can I look up for ideas ?<br>
><br>
> Thanks!<br>
> Malveeka<br>
> ---------------------------------------------------------------------<br>
> Intel Israel (74) Limited<br>
><br>
> This e-mail and any attachments may contain confidential material for<br>
> the sole use of the intended recipient(s). Any review or distribution<br>
> by others is strictly prohibited. If you are not the intended<br>
> recipient, please contact the sender and delete all copies.<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>
</blockquote></div><br></div></div>