[LLVMdev] How to find the first block of each loop

Eric Lu eirc.lew at gmail.com
Tue May 21 00:41:23 PDT 2013

  I want to insert a control-block before every outermost loop. My current
solution is: 1) find each outermost loop in some function; 2) find the loop
header with Loop->getHeader() APIs, and then insert the controller block
before the header block of current loop.

But I encounters problems when there multi subsequent loops in the
following example, where there is no code between loops:

for( i = 0 ; i < N; i++){
   arrayA[i] = i + 1;

for( j = 0 ; j < N; j++){
   arrayA[j] = j + 1;

for( k = 0 ; k < N; k++){
   arrayC[k] = k + 1;

In this case, these loops have the same header block, so the previous
method failed.  And it seems the method of block_begin() returns the same
value as getHeader().
Are there some other methods to implement this ?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130521/20db76c1/attachment.html>

More information about the llvm-dev mailing list