[llvm-dev] Detecting "openmp" loop and its original bounds.

Venkataramanan Kumar via llvm-dev llvm-dev at lists.llvm.org
Thu Oct 18 01:12:45 PDT 2018


Hi,

I am trying to do a transformation pass in "opt".
---Snip--
#pragma omp parallel for
          for (int j=0; j<1000000; j++)
                b[j] = a[j]*scalar;
---Snip----
 For the above  loop under -fopenmp:
1.  How to check if the loop I am working is a parallel loop (i.e. discover
the       "openmp" hint)
      I tired  Loop->isAnnotatedParallel(),  but  it is returning false.
2.   Is there some way to discover the original bounds of the loop?
      I could see the original bounds are passed at the start of the
"@.omp_outlined" function.
       ---Snip----
     %0 = bitcast i32* %.omp.lb to i8*
     call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %0) #4
     store i32 0, i32* %.omp.lb, align 4, !tbaa !7  <== lower bound
     %1 = bitcast i32* %.omp.ub to i8*
     call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %1) #4
     store i32 999999, i32* %.omp.ub, align 4, !tbaa !7 <== upper bound.
      ---Snip----

    Now the loop is
     ---Snip----
    omp.inner.for.body:                               ; preds =
%omp.inner.for.body.preheader, %omp.inner.for.body
    %indvars.iv = phi i64 [ %8, %omp.inner.for.body.preheader ], [
%indvars.iv.next, %omp.inner.for.body ]
    .......
    %cmp1 = icmp slt i64 %indvars.iv, %9
    br i1 %cmp1, label %omp.inner.for.body, label %omp.loop.exit
    ---Snip----

%8  is lower bound
%9 is maximum of upper bound and 999999.

   I could do a backward walk and figure out what the bounds are initially
set to?
   Are there a better ways for doing it example using SCEV ?

regards,
Venkat.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181018/e462178c/attachment.html>


More information about the llvm-dev mailing list