|
| 1 | +! RUN: bbc -emit-hlfir -fopenmp %s -o - | FileCheck %s |
| 2 | +! RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s |
| 3 | + |
| 4 | +! --- Check that with shared(i) the variable outside the parallel section |
| 5 | +! --- is updated. |
| 6 | +! CHECK-LABEL: func.func @_QPomploop() |
| 7 | +! CHECK: %[[ALLOC_I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFomploopEi"} |
| 8 | +! CHECK: %[[DECL_I:.*]]:2 = hlfir.declare %[[ALLOC_I]] {uniq_name = "_QFomploopEi"} : |
| 9 | +! CHECK: omp.parallel { |
| 10 | +! CHECK: omp.sections { |
| 11 | +! CHECK: omp.section { |
| 12 | +! CHECK: %[[RES:.*]]:2 = fir.do_loop %[[ARG0:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%[[ARG1:.*]] = |
| 13 | +! CHECK: fir.store %[[ARG1]] to %[[DECL_I]]#1 |
| 14 | +! CHECK: %[[UPDATE_ITER:.*]] = arith.addi %[[ARG0]], %{{.*}} |
| 15 | +! CHECK: %[[LOAD_I:.*]] = fir.load %[[DECL_I]]#1 |
| 16 | +! CHECK: %[[RES_I:.*]] = arith.addi %[[LOAD_I]], %{{.*}} |
| 17 | +! CHECK: fir.result %[[UPDATE_ITER]], %[[RES_I]] |
| 18 | +! CHECK: } |
| 19 | +! CHECK: fir.store %[[RES]]#1 to %[[DECL_I]]#1 |
| 20 | +! CHECK: omp.terminator |
| 21 | +! CHECK: } |
| 22 | +! CHECK: omp.terminator |
| 23 | +! CHECK: } |
| 24 | +! CHECK: return |
| 25 | +! CHECK: } |
| 26 | +subroutine omploop |
| 27 | + implicit none |
| 28 | + integer :: i, j |
| 29 | + i = 1 |
| 30 | + j = 0 |
| 31 | + !$omp parallel shared(i) |
| 32 | + !$omp sections |
| 33 | + do i=1,10 |
| 34 | + j = j + i |
| 35 | + end do |
| 36 | + !$omp end sections |
| 37 | + !$omp end parallel |
| 38 | +end subroutine |
| 39 | + |
| 40 | +! --- Check that with default(shared) the variable outside the parallel section |
| 41 | +! --- is NOT updated (i is private to the omp.parallel code) |
| 42 | +! CHECK-LABEL: func.func @_QPomploop2() |
| 43 | +! CHECK: %[[ALLOC_I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFomploop2Ei"} |
| 44 | +! CHECK: %[[DECL_I:.*]]:2 = hlfir.declare %[[ALLOC_I]] {uniq_name = "_QFomploop2Ei"} : |
| 45 | +! CHECK: omp.parallel { |
| 46 | +! CHECK: %[[ALLOC_PRIV_I:.*]] = fir.alloca i32 {bindc_name = "i", pinned} |
| 47 | +! CHECK: %[[DECL_PRIV_I:.*]]:2 = hlfir.declare %[[ALLOC_PRIV_I]] |
| 48 | +! CHECK: omp.sections { |
| 49 | +! CHECK: omp.section { |
| 50 | +! CHECK: %[[RES:.*]]:2 = fir.do_loop %[[ARG0:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%[[ARG1:.*]] = |
| 51 | +! CHECK-NOT: fir.store %[[ARG1]] to %[[DECL_I]]#1 |
| 52 | +! CHECK: fir.store %[[ARG1]] to %[[DECL_PRIV_I]]#1 |
| 53 | +! CHECK: %[[UPDATE_ITER:.*]] = arith.addi %[[ARG0]], %{{.*}} |
| 54 | +! CHECK: %[[LOAD_I:.*]] = fir.load %[[DECL_PRIV_I]]#1 |
| 55 | +! CHECK: %[[RES_I:.*]] = arith.addi %[[LOAD_I]], %{{.*}} |
| 56 | +! CHECK: fir.result %[[UPDATE_ITER]], %[[RES_I]] |
| 57 | +! CHECK: } |
| 58 | +! CHECK: fir.store %[[RES]]#1 to %[[DECL_PRIV_I]]#1 |
| 59 | +! CHECK: omp.terminator |
| 60 | +! CHECK: } |
| 61 | +! CHECK: omp.terminator |
| 62 | +! CHECK: } |
| 63 | +! CHECK: return |
| 64 | +! CHECK: } |
| 65 | +subroutine omploop2 |
| 66 | + implicit none |
| 67 | + integer :: i, j |
| 68 | + i = 1 |
| 69 | + j = 0 |
| 70 | + !$omp parallel default(shared) |
| 71 | + !$omp sections |
| 72 | + do i=1,10 |
| 73 | + j = j + i |
| 74 | + end do |
| 75 | + !$omp end sections |
| 76 | + !$omp end parallel |
| 77 | +end subroutine |
| 78 | + |
| 79 | + |
| 80 | +! --- Check that with no data-sharing the variable outside the parallel section |
| 81 | +! --- is NOT updated (i is private to the omp.parallel code) |
| 82 | +! CHECK-LABEL: func.func @_QPomploop3() |
| 83 | +! CHECK: %[[ALLOC_I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFomploop3Ei"} |
| 84 | +! CHECK: %[[DECL_I:.*]]:2 = hlfir.declare %[[ALLOC_I]] {uniq_name = "_QFomploop3Ei"} : |
| 85 | +! CHECK: omp.parallel { |
| 86 | +! CHECK: %[[ALLOC_PRIV_I:.*]] = fir.alloca i32 {bindc_name = "i", pinned} |
| 87 | +! CHECK: %[[DECL_PRIV_I:.*]]:2 = hlfir.declare %[[ALLOC_PRIV_I]] |
| 88 | +! CHECK: omp.sections { |
| 89 | +! CHECK: omp.section { |
| 90 | +! CHECK: %[[RES:.*]]:2 = fir.do_loop %[[ARG0:.*]] = %{{.*}} to %{{.*}} step %{{.*}} iter_args(%[[ARG1:.*]] = |
| 91 | +! CHECK-NOT: fir.store %[[ARG1]] to %[[DECL_I]]#1 |
| 92 | +! CHECK: fir.store %[[ARG1]] to %[[DECL_PRIV_I]]#1 |
| 93 | +! CHECK: %[[UPDATE_ITER:.*]] = arith.addi %[[ARG0]], %{{.*}} |
| 94 | +! CHECK: %[[LOAD_I:.*]] = fir.load %[[DECL_PRIV_I]]#1 |
| 95 | +! CHECK: %[[RES_I:.*]] = arith.addi %[[LOAD_I]], %{{.*}} |
| 96 | +! CHECK: fir.result %[[UPDATE_ITER]], %[[RES_I]] |
| 97 | +! CHECK: } |
| 98 | +! CHECK: fir.store %[[RES]]#1 to %[[DECL_PRIV_I]]#1 |
| 99 | +! CHECK: omp.terminator |
| 100 | +! CHECK: } |
| 101 | +! CHECK: omp.terminator |
| 102 | +! CHECK: } |
| 103 | +! CHECK: return |
| 104 | +! CHECK: } |
| 105 | +subroutine omploop3 |
| 106 | + implicit none |
| 107 | + integer :: i, j |
| 108 | + i = 1 |
| 109 | + j = 0 |
| 110 | + !$omp parallel |
| 111 | + !$omp sections |
| 112 | + do i=1,10 |
| 113 | + j = j + i |
| 114 | + end do |
| 115 | + !$omp end sections |
| 116 | + !$omp end parallel |
| 117 | +end subroutine |
| 118 | + |
| 119 | + |
| 120 | + |
0 commit comments