[llvm-dev] Get Source Code Location of a Loop

Arnamoy Bhattacharyya via llvm-dev llvm-dev at lists.llvm.org
Fri Jan 8 11:21:28 PST 2021


Hello;

I was wondering what is the proper way to extract the source code line
info for a loop e.g. where it begins.  I was using the getStartLoc()
method from the Loop class.  But for the following loop nest:

do k=1,nz     <----------- Should report this line
  do i=2,nx
    Dzold = Dz_jlow(i,j,k)
    Dz_jlow(i,j,k) = axe(i) * Dz_jlow(i,j,k) +                                &
                     bxe(i) * ((Hy(i,j,k  )-Hy(i-1,j,k))*dxinv +              &
                               (Hx(i,j-1,k)-Hx(i,j,k  ))*dyinv)
    Ez(i,j,k) = aye(j) * Ez(i,j,k) +                                          &
                bye(j) * (czh(k)*Dz_jlow(i,j,k) - fzh(k)*Dzold) * epsinv
  end do <------------------ reports this line
end do

If I want to know where in the source code the "k-loop" begins, it
reports the "end do" statement of the inner loop (see above), which is
confusing.

How to get the proper beginning line in the source?

Thanks a lot.


More information about the llvm-dev mailing list