On Wed, Dec 18, 2013 at 04:16:57PM +0000, Iyer, Balaji V wrote:
> > Don't do this, compute loop count during omp expansion (there is already
> > code that does that for you, after all, for #pragma omp for the loop count
> > is
> > typically (unless static schedule) passed as parameter to the runtime as
> > well.
>
> Where does this happen? Is there a routine that you can point me to that will
> compute the loop-count?
E.g. extract_omp_for_data (that does that only for collapse>1 though),
otherwise you get from that routine just n1, n2, step and cond_code
and from that you can easily compute it as extract_omp_for_data does:
tree itype = TREE_TYPE (loop->v);
if (POINTER_TYPE_P (itype))
itype = signed_type_for (itype);
t = build_int_cst (itype, (loop->cond_code == LT_EXPR ? -1 : 1));
t = fold_build2_loc (loc,
PLUS_EXPR, itype,
fold_convert_loc (loc, itype, loop->step), t);
t = fold_build2_loc (loc, PLUS_EXPR, itype, t,
fold_convert_loc (loc, itype, loop->n2));
t = fold_build2_loc (loc, MINUS_EXPR, itype, t,
fold_convert_loc (loc, itype, loop->n1));
if (TYPE_UNSIGNED (itype) && loop->cond_code == GT_EXPR)
t = fold_build2_loc (loc, TRUNC_DIV_EXPR, itype,
fold_build1_loc (loc, NEGATE_EXPR, itype, t),
fold_build1_loc (loc, NEGATE_EXPR, itype,
fold_convert_loc (loc, itype,
loop->step)));
else
t = fold_build2_loc (loc, TRUNC_DIV_EXPR, itype, t,
fold_convert_loc (loc, itype, loop->step));
Jakub