> -----Original Message----- > From: Jakub Jelinek [mailto:ja...@redhat.com] > Sent: Wednesday, December 18, 2013 11:28 AM > To: Iyer, Balaji V > Cc: Jason Merrill (ja...@redhat.com); 'gcc@gcc.gnu.org' > Subject: Re: Question about omp-low.c > > 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)); >
Hi Jakub, I looked into this, but the issue I have is, for the following code: Int main (void) { _Cilk_for (int ii = W; ii < (X+Y); ii = ii + (q+z)) } It will gimplify X+Y and q+z and put it in a new variable that is stored in pre_body and replace the above code like this: Int main (void { _Cilk_for (int ii = W; ii < D1234 ; ii = ii + D1235) } The pre_body will have something like this: D1234 = X + Y; D1235 = q + z; Finally, I need to replace the _Cilk_for with something like this in the main function: Int main (void) { __cilkrts_cilk_for_64 (main.cilk_for_fn.0, &cilk_for_data, <loop_count>, grain); } During the expand_omp_for stage (or at any stage after gimplification), if I calculate the loop count, I should get something like this: Loop_count = (D1234 - W) / D1235 Now, the pre_body is pushed into the child function and thus the values calculated for D1234 and D1235 will be in the child function and not in main which will result in getting the wrong loop count. This is why I need to have a loop count field to calculate and then store this value from the pre-gimplification phase. Now, if I can somehow make it push the pre-body into the main function and not in the child function, I won't have this issue anymore. Can you please suggest me where the pre-body is being pushed into the child function and/or how I could stop it? I tried to warlk through the code by putting a break point in gimple_omp_for_pre_body_ptr and I am still not finding this... In most OMP code I have seen, the loop count is inserted/used in the child function and thus this is not an issue. Thanks, Balaji V. Iyer. > Jakub