Hello LLVM developers,<br><br>I have a few questions regarding analysis and transformation of Machine IRs.<br><br>I am writing a scheduling pass that transforms single basic block loops. Details of the pass can be found in an email I sent two weeks ago.<br>

<a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-August/033808.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/llvmdev/2010-August/033808.html</a><br>I have changed my pass to run before Live Variable Analysis since then.<br>

<br>1, Induction variable recognition<br>I need to find which SSA value is used as the induction variable that controls a loop. Currently I determine that a value is the induction variable I am looking for if the following conditions are met:<br>

<br>1) it is an operand of either the branch instruction or the instruction that sets the condition code for the branch<br>2) the instruction that defines the value uses an operand defined by a phi instruction<br>3) the phi instruction uses the value <br>

<br>For example, in the code below which loops n times,<br><br>(begin)<br>...<br>(I0) v3 := n<br>
(I1) v0 := 0<br>
...<br>
_LoopBody_:<br>
(I2) v1 := phi(v0, v2)<br>
...<br>
(I3) v2 := v1 + 1<br>
...<br>
(I4) cmp v2, v3<br>
(I5) brne _Loopbody_ <br>
...<br>(end)<br><br>v2 is the induction variable because,<br>1) v2 is an operand of I4<br>2) I3 uses v1, which is defined by a phi instruction<br>3) the phi instruction I2 uses v2 <br><br>Is there a better way to do what I am trying to do?<br>

Are there libraries I can use that work on Machine IRs?<br><br>2. Insertion of add/sub instructions.<br>I need to change the number of times a loop is executed. In order to do that, I am considering modifying the value of the induction variable or the exit value before entering the loop. For example, if I wanted to execute the loop (n - 3) times in the code above, I could modify it in the following ways: <br>

<br>1) add 3 to v0 <br>(I1) v0 := <br>


(I1_1) v0_1 := v0 + 3  <= add inserted here<br>


...<br>(I2) v1 := phi(v0_1, v2) <= change operand<br>

<br> 2) subtract 3 from v3. <br>(I0) v3 := <br>



(I0.a) v3_1 := v3 - 3 <= sub inserted here<br>...<br>

(I4) cmp v2, v3_1 <= change operand<br>

<br>Is there a class or function that generates an add or sub instruction in a target-independent manner? I am looking for something similar to TargetInstrInfo::copyRegTpReg but one that creates other types of instructions.  <br>
 <br>Any advice, comments and suggestions are appreciated.<br>
<br>

Thank you in advance.<br><br>