Skip to content

Commit 852a46c

Browse files
Do not expand ILM instructions for second nest level
Pragma target teams distribute parallel do consists of two levels of parallelism (teams and threads). Threads from one team should be launched in parallel via __kmpc_parallel_51 function. The code which is executed by threads should be outlined to separate function. Signed-off-by: Dominik Adamski <[email protected]>
1 parent f11437c commit 852a46c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tools/flang2/flang2exe/expand.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ eval_ilm_check_if_skip(int ilmx, int *skip_expand, int *process_expanded)
558558
tmp, /* temporary */
559559
op1; /* operand 1 */
560560
ILM_OP opcx; /**< ILM opcode of the ILM */
561+
static int mp_loop_nest_level;
562+
const int mp_loop_second_nest_level = 2;
563+
static bool omit_loop_nesting;
561564

562565
int first_op = 0;
563566

@@ -582,6 +585,24 @@ eval_ilm_check_if_skip(int ilmx, int *skip_expand, int *process_expanded)
582585
if (EXPDBG(8, 2))
583586
fprintf(gbl.dbgfil, "---------- eval ilm %d\n", ilmx);
584587

588+
if (flg.omptarget && gbl.ompaccel_intarget && !ll_ilm_is_rewriting()) {
589+
if (opcx == IM_MPLOOP) {
590+
if (++mp_loop_nest_level == mp_loop_second_nest_level) {
591+
omit_loop_nesting = true;
592+
}
593+
}
594+
else if ((opcx == IM_MPLOOPFINI) &&
595+
(mp_loop_nest_level == mp_loop_second_nest_level)) {
596+
if (omit_loop_nesting) {
597+
omit_loop_nesting = false;
598+
}
599+
}
600+
else if (omit_loop_nesting)
601+
{
602+
//Do not expand ilm instructions for 2nd level of parallelism
603+
return sptr1;
604+
}
605+
}
585606
if (!ll_ilm_is_rewriting())
586607
{
587608
#ifdef OMP_OFFLOAD_LLVM

0 commit comments

Comments
 (0)