1! REQUIRES: openmp_runtime 2 3!RUN: %flang_fc1 -emit-hlfir %openmp_flags %s -o - | FileCheck %s 4 5!CHECK: omp.critical.declare @help2 6!CHECK: omp.critical.declare @help1 hint(contended) 7 8subroutine omp_critical() 9 use omp_lib 10 integer :: x, y 11!CHECK: omp.critical(@help1) 12!$OMP CRITICAL(help1) HINT(omp_lock_hint_contended) 13 x = x + y 14!CHECK: omp.terminator 15!$OMP END CRITICAL(help1) 16 17! Test that the same name can be used again 18! Also test with the zero hint expression 19!CHECK: omp.critical(@help2) 20!$OMP CRITICAL(help2) HINT(omp_lock_hint_none) 21 x = x - y 22!CHECK: omp.terminator 23!$OMP END CRITICAL(help2) 24 25!CHECK: omp.critical 26!$OMP CRITICAL 27 y = x + y 28!CHECK: omp.terminator 29!$OMP END CRITICAL 30end subroutine omp_critical 31 32 33! Tests that privatization for pre-determined variables (here `i`) is properly 34! handled. 35subroutine predetermined_privatization() 36 integer :: a(10), i 37 38 !CHECK: omp.parallel 39 !$omp parallel do 40 41 !CHECK: %[[PRIV_I_ALLOC:.*]] = fir.alloca i32 {bindc_name = "i", pinned, {{.*}}} 42 !CHECK: %[[PRIV_I_DECL:.*]]:2 = hlfir.declare %[[PRIV_I_ALLOC]] 43 do i = 2, 10 44 !CHECK: omp.wsloop 45 !CHECK: omp.loop_nest (%[[IV:[^[:space:]]+]]) 46 !CHECK: fir.store %[[IV]] to %[[PRIV_I_DECL]]#1 47 !CHECK: omp.critical 48 !$omp critical 49 a(i) = a(i-1) + 1 50 !$omp end critical 51 end do 52 !$omp end parallel do 53end 54 55! https://github.com/llvm/llvm-project/issues/75767 56!CHECK-LABEL: func @_QPparallel_critical_privatization( 57subroutine parallel_critical_privatization() 58 integer :: i 59 60 !CHECK: %[[I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFparallel_critical_privatizationEi"} 61 !CHECK: %[[I_DECL:.*]]:2 = hlfir.declare %[[I]] {uniq_name = "_QFparallel_critical_privatizationEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) 62 !CHECK: omp.parallel private(@{{.*}} %[[I_DECL]]#0 -> %[[PRIV_I:.*]] : !fir.ref<i32>) { 63 !CHECK: %[[PRIV_I_DECL:.*]]:2 = hlfir.declare %[[PRIV_I]] {uniq_name = "_QFparallel_critical_privatizationEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) 64 !$omp parallel default(firstprivate) 65 !CHECK: omp.critical { 66 !$omp critical 67 !CHECK: %[[C200:.*]] = arith.constant 200 : i32 68 !CHECK: hlfir.assign %[[C200]] to %[[PRIV_I_DECL]]#0 : i32, !fir.ref<i32> 69 i = 200 70 !CHECK: } 71 !$omp end critical 72 !CHECK: } 73 !$omp end parallel 74end subroutine 75